Skip to content

Commit

Permalink
Add conflict_reminder action for backport PR
Browse files Browse the repository at this point in the history
In order not to forget to resolve conflicts in backport PRs, we should add some reminders to the PR author so it will not be forgotten

the new action will run twice a week and will send a reminder only for
PR opened with conflicts for 3 days or more

Fixes: scylladb#21448
  • Loading branch information
yaronkaikov committed Nov 5, 2024
1 parent ee92784 commit 275e820
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/conflict_reminder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Notify PR Authors of Conflicts

on:
schedule:
- cron: '0 10 * * 1,4' # Runs every Monday and Thursday at 10:00am
workflow_dispatch: # Manual trigger for testing

jobs:
notify_conflict_prs:
runs-on: ubuntu-latest

steps:
- name: Notify PR Authors of Conflicts
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const conflictLabel = 'conflicts';
const branchPrefix = 'branch-';
const daysOpenThreshold = 3;
const allPRs = [];
let page = 1;
while (true) {
// Fetch open pull requests with pagination
const response = await github.rest.pulls.list({
owner,
repo,
state: 'open',
per_page: 100,
page: page,
});
// Log the response for debugging
console.log(`Page ${page} response:`, response.data);
if (response.data.length === 0) break;
allPRs.push(...response.data);
page++;
}
const now = new Date();
for (const pr of allPRs) {
const createdAt = new Date(pr.created_at);
const daysOpen = (now - createdAt) / (1000 * 60 * 60 * 24);
// Check if PR has the 'conflicts' label, targets a branch with the specified prefix, and has been open for more than the threshold
const hasConflictLabel = pr.labels.some(label => label.name === conflictLabel);
const targetsBranchPrefix = pr.base.ref.startsWith(branchPrefix);
if (hasConflictLabel && targetsBranchPrefix && daysOpen > daysOpenThreshold) {
const assignee = pr.assignee ? pr.assignee.login : null;
if (assignee) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: pr.number,
body: `@${assignee}, this PR has been open with conflicts for more than ${daysOpenThreshold} days. Please resolve the conflicts to allow merging.`,
});
console.log(`Notified @${assignee} for PR #${pr.number}`);
}
}
}
console.log(`Total PRs checked: ${allPRs.length}`);

0 comments on commit 275e820

Please sign in to comment.