Compare commits

...
+44 -4
View File
@@ -7,18 +7,57 @@ on:
permissions:
pull-requests: read
contents: read
jobs:
notify-bdu:
name: Notify Teams when A/N BDU label is added
runs-on: ubuntu-latest
timeout-minutes: 5
if: >-
github.event.action == 'labeled' &&
github.event.label.name == 'A/N BDU' &&
github.event.pull_request.state == 'open'
steps:
- name: Check if label was added after PR creation (with time threshold)
id: check_label_timing
uses: actions/github-script@v7
with:
script: |
const prCreatedAt = new Date('${{ github.event.pull_request.created_at }}');
// Get PR timeline to find when label was added
const timeline = await github.rest.issues.listEvents({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
// Find the most recent 'labeled' event for "A/N BDU"
const labelEvent = timeline.data.reverse().find(event =>
event.event === 'labeled' &&
event.label.name === 'A/N BDU'
);
if (!labelEvent) {
core.setOutput('should_notify', 'false');
return;
}
const labelAddedAt = new Date(labelEvent.created_at);
const timeDiffSeconds = (labelAddedAt - prCreatedAt) / 1000;
console.log(`PR created at: ${prCreatedAt}`);
console.log(`Label added at: ${labelAddedAt}`);
console.log(`Time difference: ${timeDiffSeconds} seconds`);
// Only notify if label was added MORE than 2 seconds after PR creation
// Labels added during PR creation happen within 1 second
// Manual label additions have a noticeable gap (minutes/hours/days)
if (timeDiffSeconds > 2) {
core.setOutput('should_notify', 'true');
} else {
core.setOutput('should_notify', 'false');
}
- name: Send Teams notification
if: steps.check_label_timing.outputs.should_notify == 'true'
uses: Alfresco/alfresco-build-tools/.github/actions/send-teams-notification@1d671f8f10336861c89c67be57c6648d98876103 # v18.19.0
with:
webhook-url: ${{ secrets.TEAMS_NOTIFICATION_ADF_BDU_WEBHOOK }}
@@ -31,3 +70,4 @@ jobs:
- **Repository:** ${{ github.repository }}
- **PR:** [#${{ github.event.pull_request.number }} ${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})
- **Author:** ${{ github.event.pull_request.user.login }}