Skip to content

Commit

Permalink
High Impact Alert Workflow (#2346)
Browse files Browse the repository at this point in the history
* High Impact Alert Workflow

* [MWPW-148268] Update workflow conditional
  • Loading branch information
overmyheadandbody authored May 23, 2024
1 parent 62c25ff commit 29d0a16
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 17 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/high-impact-alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const {

Check warning on line 1 in .github/workflows/high-impact-alert.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'") to override. Raw Output: {"fatal":false,"severity":1,"message":"File ignored by default. Use a negated ignore pattern (like \"--ignore-pattern '!<relative/path/to/filename>'\") to override."}
slackNotification,
getLocalConfigs,
} = require('./helpers.js');

const main = async (params) => {
const { context } = params;

try {
if (context.payload.label.name !== 'high-impact') {
console.log('No high impact label detected');
return;
}

const { html_url, number, title } = context.payload.pull_request;
console.log('High impact label detected, sending Slack notification');
slackNotification(`:alert: High Impact PR has been opened: <${html_url}|#${number}: ${title}>.` +
` Please prioritize testing the proposed changes.`, process.env.SLACK_HIGH_IMPACT_PR_WEBHOOK);
} catch (error) {
console.error(error);
}
};

if (process.env.LOCAL_RUN) {
const { context } = getLocalConfigs();
main({ context });
}

module.exports = main;
24 changes: 24 additions & 0 deletions .github/workflows/high-impact-alert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: High Impact Alert

on:
pull_request:
types:
- labeled

env:
SLACK_HIGH_IMPACT_PR_WEBHOOK: ${{ secrets.SLACK_HIGH_IMPACT_PR_WEBHOOK }}

jobs:
send_alert:
if: github.repository_owner == 'adobecom'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4.1.4

- name: Send Slack message for high impact PRs
uses: actions/github-script@v7.0.1
with:
script: |
const main = require('./.github/workflows/high-impact-alert.js')
main({ github, context })
1 change: 1 addition & 0 deletions .github/workflows/mark-stale-prs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
stale:
if: github.repository_owner == 'adobecom'
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
Expand Down
21 changes: 4 additions & 17 deletions .github/workflows/merge-to-stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const LABELS = {
highPriority: 'high priority',
readyForStage: 'Ready for Stage',
SOTPrefix: 'SOT',
highImpact: 'high-impact',
};
const TEAM_MENTIONS = [
'@adobecom/miq-sot',
Expand All @@ -24,8 +23,8 @@ const TEAM_MENTIONS = [
'@adobecom/document-cloud-sot',
];
const SLACK = {
merge: ({ html_url, number, title, highImpact }) =>
`:merged:${highImpact} PR merged to stage: <${html_url}|${number}: ${title}>.`,
merge: ({ html_url, number, title }) =>
`:merged: PR merged to stage: <${html_url}|${number}: ${title}>.`,
openedSyncPr: ({ html_url, number }) =>
`:fast_forward: Created <${html_url}|Stage to Main PR ${number}>`,
};
Expand Down Expand Up @@ -124,7 +123,8 @@ const getPRs = async () => {

const merge = async ({ prs }) => {
console.log(`Merging ${prs.length || 0} PRs that are ready... `);
for await (const { number, files, html_url, title, labels } of prs) {

for await (const { number, files, html_url, title } of prs) {
try {
if (files.some((file) => SEEN[file])) {
console.log(`Skipping ${number}: ${title} due to overlap in files.`);
Expand All @@ -140,24 +140,11 @@ const merge = async ({ prs }) => {
});
}
body = `- ${html_url}\n${body}`;
const isHighImpact = labels.includes(LABELS.highImpact);
if (isHighImpact && process.env.SLACK_HIGH_IMPACT_PR_WEBHOOK) {
await slackNotification(
SLACK.merge({
html_url,
number,
title,
highImpact: ' :alert: High impact',
}),
process.env.SLACK_HIGH_IMPACT_PR_WEBHOOK
);
}
await slackNotification(
SLACK.merge({
html_url,
number,
title,
highImpact: isHighImpact ? ' :alert: High impact' : '',
})
);
await new Promise((resolve) => setTimeout(resolve, 5000));
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/merge-to-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:

jobs:
merge-to-stage:
if: github.repository_owner == 'adobecom'
runs-on: ubuntu-latest
environment: milo_pr_merge

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-reminders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
update:
if: github.repository_owner == 'adobecom'
runs-on: ubuntu-latest

steps:
Expand Down

0 comments on commit 29d0a16

Please sign in to comment.