Skip to content

Commit 1437aad

Browse files
yardenshohamdelvh
andauthored
Make sure PRs that include ## ⚠️ BREAKING in their body have the kind/breaking label (#79)
Just a small addition because this can be automated Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: delvh <[email protected]>
1 parent 76b63e0 commit 1437aad

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ The script will also look for merged pull requests that have the labels
2525
It will also search for pull requests that target release branches and remove
2626
any `backport/*` labels from them.
2727

28+
It will also make sure any pull requests that have `## :warning: BREAKING` in
29+
their description have the `kind/breaking` label.
30+
2831
### Merge queue synchronization
2932

3033
The script will also look for pull requests that have the label

src/github.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ export const fetchUnmergedClosedWithMilestone = async (
8181
return json;
8282
};
8383

84+
// returns a list of breaking PRs that don't have the label kind/breaking
85+
export const fetchBreakingWithoutLabel = async () => {
86+
const response = await fetch(
87+
`${GITHUB_API}/search/issues?q=` +
88+
encodeURIComponent(
89+
`is:pr "## :warning: BREAKING" -label:kind/breaking repo:go-gitea/gitea`,
90+
),
91+
{ headers: HEADERS },
92+
);
93+
const json = await response.json();
94+
return json;
95+
};
96+
8497
// update a given PR with the latest upstream changes by merging HEAD from
8598
// the base branch into the pull request branch
8699
export const updatePr = async (prNumber: number): Promise<Response> => {

src/labels.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { fetchMergedWithLabel, fetchTargeting, removeLabel } from "./github.ts";
1+
import {
2+
addLabels,
3+
fetchBreakingWithoutLabel,
4+
fetchMergedWithLabel,
5+
fetchTargeting,
6+
removeLabel,
7+
} from "./github.ts";
28
import { fetchGiteaVersions } from "./giteaVersion.ts";
39
import { debounce } from "https://deno.land/[email protected]/async/mod.ts";
410

@@ -17,9 +23,18 @@ const maintain = async () => {
1723
await Promise.all([
1824
removeLabelsFromMergedPr(labelsToRemoveAfterMerge),
1925
removeBackportLabelsFromPrsTargetingReleaseBranches(),
26+
addKindBreakingToBreakingPrs(),
2027
]);
2128
};
2229

30+
// add kind/breaking to all breaking PRs that don't have it
31+
const addKindBreakingToBreakingPrs = async () => {
32+
const breakingPrs = await fetchBreakingWithoutLabel();
33+
return Promise.all(breakingPrs.items.map(async (pr: { number: number }) => {
34+
await addLabels(pr.number, ["kind/breaking"]);
35+
}));
36+
};
37+
2338
const removeLabelFromMergedPr = async (
2439
pr: { title: string; number: number },
2540
label: string,

src/webhook.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ webhook.on(
4646
},
4747
);
4848

49+
// on pull request open, run the label maintenance
50+
webhook.on("pull_request.opened", () => {
51+
labels.run();
52+
});
53+
4954
// on pull request creation, we'll automatically set the milestone
5055
// according to the target branch (if it's a release branch)
5156
webhook.on("pull_request.opened", ({ payload }) => {

0 commit comments

Comments
 (0)