name: "Sends notification when A/N BDU label is attached to PR" on: pull_request: types: [labeled] branches: [develop] permissions: pull-requests: read issues: 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@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | const prCreatedAt = new Date('${{ github.event.pull_request.created_at }}'); const timeline = await github.rest.issues.listEvents({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }); 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; if (timeDiffSeconds > 15) { 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@98bcfbe06aafffdc0e9a790f352602316f82303b # v18.23.0 with: webhook-url: ${{ secrets.TEAMS_NOTIFICATION_ADF_BDU_WEBHOOK }} skip_checkout: true status: success title: "A/N BDU PR: ${{ github.event.pull_request.title }}" message: | A pull request has been marked with the **A/N BDU** label. - **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 }}