Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronkaikov committed Nov 6, 2024
1 parent 275e820 commit e8425c0
Showing 1 changed file with 24 additions and 45 deletions.
69 changes: 24 additions & 45 deletions .github/workflows/conflict_reminder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,31 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const conflictLabel = 'conflicts';
const prs = await github.paginate(github.rest.pulls.list, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100
});
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 threeDaysAgo = new Date();
const conflictLabel = 'conflicts';
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3);
for (const pr of prs) {
if (!pr.base.ref.startsWith(branchPrefix)) continue;
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}`);
}
}
if (!hasConflictLabel) continue;
const updatedDate = new Date(pr.updated_at);
if (updatedDate >= threeDaysAgo) continue;
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 so we can merge it.`,
});
console.log(`Notified @${assignee} for PR #${pr.number}`);
}
}
console.log(`Total PRs checked: ${allPRs.length}`);

0 comments on commit e8425c0

Please sign in to comment.