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