This commit is contained in:
Shivangi Shree
2026-08-10 17:51:43 +05:30
parent 268067b63b
commit 5700ef6818
+17 -25
View File
@@ -7,48 +7,40 @@ on:
permissions: permissions:
pull-requests: read pull-requests: read
issues: read issues: read # timeline API is served via the issues endpoint
jobs: jobs:
notify-bdu: notify-bdu:
name: Notify Teams when A/N BDU label is added name: Notify Teams when A/N BDU label is added
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 5 timeout-minutes: 5
if: >-
github.event.label.name == 'A/N BDU' &&
github.event.pull_request.state == 'open'
steps: steps:
- name: Check if label was added after PR creation (with time threshold) - name: Was the label added after PR creation?
id: check_label_timing id: check
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
const prCreatedAt = new Date('${{ github.event.pull_request.created_at }}'); const prCreatedAt = new Date(context.payload.pull_request.created_at).getTime();
const events = await github.paginate(github.rest.issues.listEventsForTimeline, {
const timeline = await github.rest.issues.listEvents({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.issue.number, issue_number: context.payload.pull_request.number,
per_page: 100
}); });
const labeled = events.filter(e => e.event === 'labeled' && e.label?.name === 'A/N BDU');
const labelEvent = timeline.data.reverse().find(event => if (labeled.length === 0) {
event.event === 'labeled' && core.setOutput('notify', 'false');
event.label.name === 'A/N BDU'
);
if (!labelEvent) {
core.setOutput('should_notify', 'false');
return; return;
} }
const labeledAt = new Date(labeled[labeled.length - 1].created_at).getTime();
const labelAddedAt = new Date(labelEvent.created_at); // labels applied within 30s of opening are treated as "added at creation"
const timeDiffSeconds = (labelAddedAt - prCreatedAt) / 1000; core.setOutput('notify', (labeledAt - prCreatedAt) > 15000 ? 'true' : 'false');
if (timeDiffSeconds > 0) {
core.setOutput('should_notify', 'true');
} else {
core.setOutput('should_notify', 'false');
}
- name: Send Teams notification - name: Send Teams notification
if: steps.check_label_timing.outputs.should_notify == 'true' if: steps.check.outputs.notify == 'true'
uses: Alfresco/alfresco-build-tools/.github/actions/send-teams-notification@1d671f8f10336861c89c67be57c6648d98876103 # v18.19.0 uses: Alfresco/alfresco-build-tools/.github/actions/send-teams-notification@1d671f8f10336861c89c67be57c6648d98876103 # v18.19.0
with: with:
webhook-url: ${{ secrets.TEAMS_NOTIFICATION_ADF_BDU_WEBHOOK }} webhook-url: ${{ secrets.TEAMS_NOTIFICATION_ADF_BDU_WEBHOOK }}