Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mwpw-152624: improve stage PR communication #2474

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions .github/workflows/merge-to-stage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {

Check warning on line 1 in .github/workflows/merge-to-stage.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,
isWithinRCP,
Expand Down Expand Up @@ -55,6 +55,28 @@
name !== 'merge-to-stage' && conclusion === 'failure'
);

const commentOnPR = async (comment, prNumber) => {
console.log(comment); // Logs for debugging the action.
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: prNumber,
});

const dayAgo = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
const hasRecentComment = comments
.filter(({ created_at }) => new Date(created_at) > dayAgo)
.some(({ body }) => body === comment);
if (hasRecentComment) return console.log('Comment exists for', prNumber);

await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: comment,
});
};

const getPRs = async () => {
let prs = await github.rest.pulls
.list({ owner, repo, state: 'open', per_page: 100, base: STAGE })
Expand All @@ -69,13 +91,19 @@

prs = prs.filter(({ checks, reviews, number, title }) => {
if (hasFailingChecks(checks)) {
console.log(`Skipping ${number}: ${title} due to failing checks`);
commentOnPR(
`Skipped merging ${number}: ${title} due to failing checks`,
number
);
return false;
}

const approvals = reviews.filter(({ state }) => state === 'APPROVED');
if (approvals.length < REQUIRED_APPROVALS) {
console.log(`Skipping ${number}: ${title} due to insufficient approvals`);
commentOnPR(
`Skipped merging ${number}: ${title} due to insufficient approvals. Required: ${REQUIRED_APPROVALS} approvals`,
number
);
return false;
}

Expand Down Expand Up @@ -103,7 +131,10 @@
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.`);
commentOnPR(
`Skipped ${number}: ${title} due to file overlap. Merging will be attempted in the next batch`,
number
);
continue;
}
if (type !== LABELS.zeroImpact) {
Expand All @@ -130,7 +161,7 @@
);
await new Promise((resolve) => setTimeout(resolve, 5000));
} catch (error) {
console.log(`Error merging ${number}: ${title}`, error.message);
commentOnPR(`Error merging ${number}: ${title} ` + error.message, number);
}
}
};
Expand Down Expand Up @@ -187,6 +218,10 @@
});

await slackNotification(SLACK.openedSyncPr({ html_url, number }));
await slackNotification(
SLACK.openedSyncPr({ html_url, number }),
process.env.MILO_STAGE_SLACK_WH
);
} catch (error) {
if (error.message.includes('No commits between main and stage'))
return console.log('No new commits, no stage->main PR opened');
Expand Down
Loading