Skip to content

Commit

Permalink
Merge pull request #2396 from hborawski/pr-body-labels-remove-fix
Browse files Browse the repository at this point in the history
only remove labels if they exist on the PR
  • Loading branch information
hipstersmoothie committed Sep 10, 2023
2 parents 6e35c33 + db0f6cc commit 3fb2bee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions plugins/pr-body-labels/__tests__/pr-body-labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Pr-Body-Labels Plugin", () => {
} as any);

await hooks.prCheck.promise({
pr: { body: "- [x] `unknown-label`" },
pr: { body: "- [x] `unknown-label`", labels: [{ name: "patch" }] },
} as any);
expect(addLabelToPr).not.toHaveBeenCalled();
});
Expand All @@ -32,7 +32,7 @@ describe("Pr-Body-Labels Plugin", () => {
} as any);

await hooks.prCheck.promise({
pr: { body: "- [x] `patch`", number: 1 },
pr: { body: "- [x] `patch`", number: 1, labels: [{ name: "patch" }] },
} as any);
expect(addLabelToPr).toHaveBeenCalledWith(1, "patch");
});
Expand All @@ -49,7 +49,7 @@ describe("Pr-Body-Labels Plugin", () => {
} as any);

await hooks.prCheck.promise({
pr: { body: "- [X] `patch`", number: 1 },
pr: { body: "- [X] `patch`", number: 1, labels: [{ name: "patch" }] },
} as any);
expect(addLabelToPr).toHaveBeenCalledWith(1, "patch");
});
Expand All @@ -66,7 +66,7 @@ describe("Pr-Body-Labels Plugin", () => {
} as any);

await hooks.prCheck.promise({
pr: { body: "- [ ] `patch`", number: 1 },
pr: { body: "- [ ] `patch`", number: 1, labels: [{ name: "patch" }] },
} as any);
expect(removeLabel).toHaveBeenCalledWith(1, "patch");
});
Expand All @@ -83,7 +83,7 @@ describe("Pr-Body-Labels Plugin", () => {
} as any);

await hooks.prCheck.promise({
pr: { body: "- [ ] `patch`", number: 1 },
pr: { body: "- [ ] `patch`", number: 1, labels: [{ name: "patch" }] },
} as any);
expect(removeLabel).not.toHaveBeenCalledWith(1, "patch");
});
Expand All @@ -100,7 +100,7 @@ describe("Pr-Body-Labels Plugin", () => {
} as any);

await hooks.prCheck.promise({
pr: { body: "- [x] `patch`", number: 1 },
pr: { body: "- [x] `patch`", number: 1, labels: [{ name: "patch" }] },
} as any);
expect(addLabelToPr).not.toHaveBeenCalled();
});
Expand Down
5 changes: 4 additions & 1 deletion plugins/pr-body-labels/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default class PrBodyLabelsPlugin implements IPlugin {

await Promise.all(
auto.labels.map(async (label) => {
const hasLabelOnPr = pr.labels
.map((l) => l.name)
.includes(label.name);
const hasUnchecked = pr.body?.includes(`- [ ] \`${label.name}\``);
const hasCheckedLabel =
pr.body?.includes(`- [x] \`${label.name}\``) ||
Expand All @@ -47,7 +50,7 @@ export default class PrBodyLabelsPlugin implements IPlugin {
await auto.git?.addLabelToPr(pr.number, label.name);
}

if (hasUnchecked && this.options.removeStaleLabels) {
if (hasUnchecked && this.options.removeStaleLabels && hasLabelOnPr) {
await auto.git?.removeLabel(pr.number, label.name);
}
})
Expand Down

0 comments on commit 3fb2bee

Please sign in to comment.