forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conflict_reminder action for backport PR
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
1 parent
ee92784
commit 275e820
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); |