mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-10175] check if pr createdAt and label addedAt is different
This commit is contained in:
@@ -7,52 +7,50 @@ on:
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
pull-requests: read
|
pull-requests: read
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-label-timing:
|
notify-bdu:
|
||||||
name: Check if label was added after PR creation
|
name: Notify Teams when A/N BDU label is added
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
timeout-minutes: 5
|
||||||
should-notify: ${{ steps.check.outputs.should-notify }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check label timing
|
- name: Check if label was added after PR creation
|
||||||
id: check
|
id: check_label_timing
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const pr = context.payload.pull_request;
|
const prCreatedAt = new Date('${{ github.event.pull_request.created_at }}');
|
||||||
const timeline = await github.rest.issues.listEventsForTimeline({
|
|
||||||
|
// Get PR timeline to find when label was added
|
||||||
|
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: pr.number
|
issue_number: context.issue.number,
|
||||||
});
|
});
|
||||||
|
|
||||||
const createdTime = new Date(pr.created_at);
|
// Find the most recent 'labeled' event for "A/N BDU"
|
||||||
const labelEvent = timeline.data.find(event =>
|
const labelEvent = timeline.data.reverse().find(event =>
|
||||||
event.event === 'labeled' && event.label.name === 'A/N BDU'
|
event.event === 'labeled' &&
|
||||||
|
event.label.name === 'A/N BDU'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (labelEvent) {
|
if (!labelEvent) {
|
||||||
const labelTime = new Date(labelEvent.created_at);
|
core.setOutput('should_notify', 'false');
|
||||||
// If label was added more than 1 second after PR creation, notify
|
return;
|
||||||
const shouldNotify = (labelTime - createdTime) > 1000;
|
}
|
||||||
core.setOutput('should-notify', shouldNotify.toString());
|
|
||||||
|
const labelAddedAt = new Date(labelEvent.created_at);
|
||||||
|
|
||||||
|
// Only proceed if label was added AFTER PR was created
|
||||||
|
if (labelAddedAt > prCreatedAt) {
|
||||||
|
core.setOutput('should_notify', 'true');
|
||||||
} else {
|
} else {
|
||||||
core.setOutput('should-notify', 'false');
|
core.setOutput('should_notify', 'false');
|
||||||
}
|
}
|
||||||
|
|
||||||
notify-bdu:
|
|
||||||
name: Notify Teams when A/N BDU label is added
|
|
||||||
needs: check-label-timing
|
|
||||||
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' &&
|
|
||||||
needs.check-label-timing.outputs.should-notify == 'true'
|
|
||||||
steps:
|
|
||||||
- name: Send Teams notification
|
- 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
|
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 }}
|
||||||
@@ -65,3 +63,4 @@ jobs:
|
|||||||
- **Repository:** ${{ github.repository }}
|
- **Repository:** ${{ github.repository }}
|
||||||
- **PR:** [#${{ github.event.pull_request.number }} ${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})
|
- **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 }}
|
||||||
|
|
||||||
Reference in New Issue
Block a user