Skip to content

Commit

Permalink
Support adding specific labels to PRs
Browse files Browse the repository at this point in the history
Not all labels for backports will be copied, add support to add
labels beyond the ones that can be copied by copy_labels_pattern

Signed-off-by: Chance Zibolski <[email protected]>
  • Loading branch information
chancez committed Jul 23, 2024
1 parent 8f74ddf commit 2ea7883
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ inputs:
Note that the pull request's headref is excluded automatically.
Can be used in addition to backport labels.
By default, only backport labels are used to specify the target branches.
labels:
description: >
A space separted list of labels to add to the pull request.
outputs:
created_pull_numbers:
Expand Down
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ class Backport {
}
}
}
if (labelsToCopy.length > 0) {
const label_response = yield this.github.labelPR(new_pr.number, labelsToCopy, {
// Combine the labels to be copied with the static labels and deduplicate them using a Set
const labels = [...new Set([...labelsToCopy, ...this.config.labels])];
if (labels.length > 0) {
const label_response = yield this.github.labelPR(new_pr.number, labels, {
owner,
repo,
});
Expand Down Expand Up @@ -1070,6 +1072,7 @@ function run() {
const description = core.getInput("pull_description");
const title = core.getInput("pull_title");
const branch_name = core.getInput("branch_name");
const labels = core.getInput("labels");
const copy_labels_pattern = core.getInput("copy_labels_pattern");
const target_branches = core.getInput("target_branches");
const cherry_picking = core.getInput("cherry_picking");
Expand Down Expand Up @@ -1118,6 +1121,7 @@ function run() {
source_labels_pattern: pattern === "" ? undefined : new RegExp(pattern),
pull: { description, title, branch_name },
copy_labels_pattern: copy_labels_pattern === "" ? undefined : new RegExp(copy_labels_pattern),
labels: labels === "" ? [] : labels.split(/[ ]/),
target_branches: target_branches === "" ? undefined : target_branches,
commits: { cherry_picking, merge_commits },
copy_assignees: copy_assignees === "true",
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type Config = {
branch_name: string;
};
copy_labels_pattern?: RegExp;
labels: string[];
target_branches?: string;
commits: {
cherry_picking: "auto" | "pull_request_head";
Expand Down Expand Up @@ -432,10 +433,12 @@ export class Backport {
}
}

if (labelsToCopy.length > 0) {
// Combine the labels to be copied with the static labels and deduplicate them using a Set
const labels = [...new Set([...labelsToCopy, ...this.config.labels])];
if (labels.length > 0) {
const label_response = await this.github.labelPR(
new_pr.number,
labelsToCopy,
labels,
{
owner,
repo,
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function run(): Promise<void> {
const description = core.getInput("pull_description");
const title = core.getInput("pull_title");
const branch_name = core.getInput("branch_name");
const labels = core.getInput("labels");
const copy_labels_pattern = core.getInput("copy_labels_pattern");
const target_branches = core.getInput("target_branches");
const cherry_picking = core.getInput("cherry_picking");
Expand Down Expand Up @@ -79,6 +80,7 @@ async function run(): Promise<void> {
pull: { description, title, branch_name },
copy_labels_pattern:
copy_labels_pattern === "" ? undefined : new RegExp(copy_labels_pattern),
labels: labels === "" ? [] : labels.split(/[ ]/),
target_branches: target_branches === "" ? undefined : target_branches,
commits: { cherry_picking, merge_commits },
copy_assignees: copy_assignees === "true",
Expand Down

0 comments on commit 2ea7883

Please sign in to comment.