mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-12 14:14:55 +00:00
Implement merge conflict handling in PR updates
Added logic to handle merge conflicts in PRs, including labeling and commenting.
This commit is contained in:
1 parent
d30e97287d
commit
f4041fd70b
1 file changed
+54
@@ -26,6 +26,8 @@ jobs:
|
||||
with:
|
||||
github-token: ${{ secrets.BOT }}
|
||||
script: |
|
||||
const marker = "<!-- is-a-dev-bot: merge-conflict -->";
|
||||
|
||||
const prs = await github.paginate(
|
||||
github.rest.pulls.list,
|
||||
{
|
||||
@@ -49,5 +51,57 @@ jobs:
|
||||
console.log(`Updated #${pr.number} (${pr.head.ref})`);
|
||||
} catch (error) {
|
||||
console.log(`Could not update #${pr.number}: ${error.message}`);
|
||||
|
||||
const { data: updatedPr } = await github.rest.pulls.get({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: pr.number
|
||||
});
|
||||
|
||||
if (updatedPr.mergeable !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await github.rest.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: pr.number,
|
||||
labels: ["reason: merge conflict"]
|
||||
});
|
||||
|
||||
const comments = await github.paginate(
|
||||
github.rest.issues.listComments,
|
||||
{
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: pr.number
|
||||
}
|
||||
);
|
||||
|
||||
const alreadyCommented = comments.some(
|
||||
(comment) =>
|
||||
comment.user?.login === "is-a-dev-bot" &&
|
||||
comment.body?.includes(marker)
|
||||
);
|
||||
|
||||
if (!alreadyCommented) {
|
||||
const body = [
|
||||
marker,
|
||||
"## ❌ Merge conflict",
|
||||
"",
|
||||
"This pull request can not be merged because it has merge conflicts with `main`.",
|
||||
"",
|
||||
"***Please resolve the merge conflicts before this PR can be merged!***"
|
||||
].join("\n");
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: pr.number,
|
||||
body
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Marked #${pr.number} as having merge conflicts`);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user