forked from yardenshoham/gitea-backporter
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to update PR by adding a label (#102)
This feature allows a maintainer to update a PR's branch by adding the `giteabot/update-branch` label. It is being removed after the update. Co-authored-by: silverwind <[email protected]>
- Loading branch information
1 parent
e86156f
commit 70a19bf
Showing
5 changed files
with
60 additions
and
31 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
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 |
---|---|---|
|
@@ -12,7 +12,8 @@ import { debounce } from "https://deno.land/[email protected]/async/mod.ts"; | |
// manage backports or any other label that causes the bot to act on | ||
// detection, such as reviewed/* or backport/* | ||
export const isRelevantLabel = (label: string): boolean => { | ||
return label.startsWith("reviewed/") || label.startsWith("backport/"); | ||
return label.startsWith("reviewed/") || label.startsWith("backport/") || | ||
label.startsWith("giteabot/"); | ||
}; | ||
|
||
const maintain = async () => { | ||
|
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 |
---|---|---|
@@ -1,10 +1,5 @@ | ||
import { | ||
addComment, | ||
fetchPendingMerge, | ||
needsUpdate, | ||
removeLabel, | ||
updatePr, | ||
} from "./github.ts"; | ||
import { fetchPendingMerge, removeLabel } from "./github.ts"; | ||
import * as prActions from "./prActions.ts"; | ||
import { debounce } from "https://deno.land/[email protected]/async/mod.ts"; | ||
|
||
const updateBranch = async () => { | ||
|
@@ -13,31 +8,12 @@ const updateBranch = async () => { | |
|
||
// update all PRs pending merge (only if they need an update) | ||
for (const pr of pendingMerge.items) { | ||
if (!await needsUpdate(pr.number)) continue; | ||
const response = await updatePr(pr.number); | ||
if (response.ok) { | ||
console.info(`Synced PR #${pr.number} in merge queue`); | ||
continue; | ||
} | ||
const err = await prActions.updateBranch(pr); | ||
|
||
const body = await response.json(); | ||
if (body.message !== "merge conflict between base and head") { | ||
console.error(`Failed to sync PR #${pr.number} in merge queue`); | ||
console.error(JSON.stringify(body)); | ||
continue; | ||
if (err?.message == "merge conflicts in PR") { | ||
// if there is a merge conflict, we'll remove the reviewed/wait-merge label | ||
await removeLabel(pr.number, "reviewed/wait-merge"); | ||
} | ||
|
||
console.info( | ||
`Merge conflict detected in PR #${pr.number} in merge queue`, | ||
); | ||
// if there is a merge conflict, we'll add a comment to fix the conflicts and remove the reviewed/wait-merge label | ||
await Promise.all([ | ||
addComment( | ||
pr.number, | ||
`@${pr.user.login} please fix the merge conflicts. :tea:`, | ||
), | ||
removeLabel(pr.number, "reviewed/wait-merge"), | ||
]); | ||
} | ||
}; | ||
|
||
|
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,45 @@ | ||
import { addComment, needsUpdate, removeLabel, updatePr } from "./github.ts"; | ||
import { debounce } from "https://deno.land/[email protected]/async/mod.ts"; | ||
|
||
const execute = async ( | ||
label: string, | ||
pr: { number: number; user: { login: string } }, | ||
) => { | ||
if (label === "giteabot/update-branch") { | ||
await updateBranch(pr); | ||
await removeLabel(pr.number, "giteabot/update-branch"); | ||
} | ||
}; | ||
|
||
export const updateBranch = async ( | ||
pr: { number: number; user: { login: string } }, | ||
) => { | ||
if (await needsUpdate(pr.number)) { | ||
const response = await updatePr(pr.number); | ||
if (response.ok) { | ||
console.info(`Synced PR #${pr.number}`); | ||
return; | ||
} | ||
|
||
const body = await response.json(); | ||
if (body.message !== "merge conflict between base and head") { | ||
console.error( | ||
`Failed to sync PR #${pr.number}`, | ||
); | ||
console.error(JSON.stringify(body)); | ||
} | ||
|
||
console.info( | ||
`Merge conflict detected in PR #${pr.number}`, | ||
); | ||
// if there is a merge conflict, we'll add a comment to fix the conflicts | ||
await addComment( | ||
pr.number, | ||
`@${pr.user.login} please fix the merge conflicts. :tea:`, | ||
); | ||
return Error("merge conflicts in PR"); | ||
} | ||
}; | ||
|
||
// make sure we don't trigger too often | ||
export const run = debounce(execute, 8000); |
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