Skip to content

Commit 6610ffe

Browse files
authored
Merge pull request #434 from chancez/pr/chancez/workflow_dispatch_support
Add source_pr_number input for use with workflow_dispatch events.
2 parents 0fe1534 + bb1878b commit 6610ffe

6 files changed

Lines changed: 35 additions & 11 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ Placeholders can be used to define variable values.
263263
These are indicated by a dollar sign and curly braces (`${placeholder}`).
264264
Please refer to this action's README for all available [placeholders](#placeholders).
265265

266+
### `source_pr_number`
267+
268+
Default: `''` (not set)
269+
270+
Specifies the pull request (by its number) to backport, i.e. the source pull request.
271+
When set, the action will backport the specified pull request to each target branch.
272+
When not set, the action determines the source pull request from the event payload.
273+
266274
### `target_branches`
267275

268276
Default: `''` (disabled)

action.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: korthout
55
inputs:
66
branch_name:
77
description: >
8-
Template used as the name for branches created by this action.
8+
Template used as the name for branches created by this action.
99
Placeholders can be used to define variable values.
1010
These are indicated by a dollar sign and curly braces (`${placeholder}`).
1111
Please refer to this action's README for all available placeholders.
@@ -52,23 +52,23 @@ inputs:
5252
5353
#### `conflict_resolution`
5454
55-
Specifies how the action will handle a conflict occuring during the cherry-pick.
55+
Specifies how the action will handle a conflict occuring during the cherry-pick.
5656
In all cases, the action will stop the cherry-pick at the first conflict encountered.
5757
5858
Behavior is defined by the option selected.
5959
- When set to `fail` the backport fails when the cherry-pick encounters a conflict.
6060
- When set to `draft_commit_conflicts` the backport will always create a draft pull request with the first conflict encountered committed.
6161
6262
Instructions are provided on the original pull request on how to resolve the conflict and continue the cherry-pick.
63-
63+
6464
#### `downstream_repo`
65-
65+
6666
Define if you want to backport to a repository other than where the workflow runs.
6767
6868
By default, the action always backports to the repository in which the workflow runs.
69-
69+
7070
#### `downstream_owner`
71-
71+
7272
Define if you want to backport to another owner than the owner of the repository the workflow runs on.
7373
Only takes effect if the `downstream_repo` property is also defined.
7474
@@ -116,6 +116,11 @@ inputs:
116116
Please refer to this action's README for all available placeholders.
117117
default: >-
118118
[Backport ${target_branch}] ${pull_title}
119+
source_pr_number:
120+
description: >
121+
Specifies the pull request (by its number) to backport, i.e. the source pull request.
122+
When set, the action will backport the specified pull request to each target branch.
123+
When not set, the action determines the source pull request from the event payload.
119124
target_branches:
120125
description: >
121126
The action will backport the pull request to each specified target branch (space-delimited).

dist/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ class Backport {
9494
: workflowRepo;
9595
if (repo === undefined)
9696
throw new Error("No repository defined!");
97-
const pull_number = this.github.getPullNumber();
97+
const pull_number = this.config.source_pr_number === undefined
98+
? this.github.getPullNumber()
99+
: this.config.source_pr_number;
98100
const mainpr = yield this.github.getPullRequest(pull_number);
99101
if (!(yield this.github.isMerged(mainpr))) {
100102
const message = "Only merged pull requests can be backported.";
@@ -467,7 +469,7 @@ class Backport {
467469
const suggestionToResolve = this.composeMessageToResolveCommittedConflicts(target, branchname, commitShasToCherryPick, conflictResolution);
468470
return (0, dedent_1.default) `Created backport PR for \`${target}\`:
469471
- ${downstream}#${pr_number} with remaining conflicts!
470-
472+
471473
${suggestionToResolve}`;
472474
}
473475
createOutput(successByTarget, createdPullRequestNumbers) {
@@ -1078,6 +1080,7 @@ function run() {
10781080
const copy_milestone = core.getInput("copy_milestone");
10791081
const copy_requested_reviewers = core.getInput("copy_requested_reviewers");
10801082
const experimental = JSON.parse(core.getInput("experimental"));
1083+
const source_pr_number = core.getInput("source_pr_number");
10811084
if (cherry_picking !== "auto" && cherry_picking !== "pull_request_head") {
10821085
const message = `Expected input 'cherry_picking' to be either 'auto' or 'pull_request_head', but was '${cherry_picking}'`;
10831086
console.error(message);
@@ -1124,6 +1127,7 @@ function run() {
11241127
copy_milestone: copy_milestone === "true",
11251128
copy_requested_reviewers: copy_requested_reviewers === "true",
11261129
experimental: Object.assign(Object.assign({}, backport_1.experimentalDefaults), experimental),
1130+
source_pr_number: source_pr_number === "" ? undefined : parseInt(source_pr_number),
11271131
};
11281132
const backport = new backport_1.Backport(github, config, git);
11291133
return backport.run();

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backport.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type Config = {
2020
labels: {
2121
pattern?: RegExp;
2222
};
23+
source_pr_number?: number;
2324
pull: {
2425
description: string;
2526
title: string;
@@ -104,7 +105,10 @@ export class Backport {
104105

105106
if (repo === undefined) throw new Error("No repository defined!");
106107

107-
const pull_number = this.github.getPullNumber();
108+
const pull_number =
109+
this.config.source_pr_number === undefined
110+
? this.github.getPullNumber()
111+
: this.config.source_pr_number;
108112
const mainpr = await this.github.getPullRequest(pull_number);
109113

110114
if (!(await this.github.isMerged(mainpr))) {
@@ -677,7 +681,7 @@ export class Backport {
677681
);
678682
return dedent`Created backport PR for \`${target}\`:
679683
- ${downstream}#${pr_number} with remaining conflicts!
680-
684+
681685
${suggestionToResolve}`;
682686
}
683687

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async function run(): Promise<void> {
3030
const copy_milestone = core.getInput("copy_milestone");
3131
const copy_requested_reviewers = core.getInput("copy_requested_reviewers");
3232
const experimental = JSON.parse(core.getInput("experimental"));
33+
const source_pr_number = core.getInput("source_pr_number");
3334

3435
if (cherry_picking !== "auto" && cherry_picking !== "pull_request_head") {
3536
const message = `Expected input 'cherry_picking' to be either 'auto' or 'pull_request_head', but was '${cherry_picking}'`;
@@ -85,6 +86,8 @@ async function run(): Promise<void> {
8586
copy_milestone: copy_milestone === "true",
8687
copy_requested_reviewers: copy_requested_reviewers === "true",
8788
experimental: { ...experimentalDefaults, ...experimental },
89+
source_pr_number:
90+
source_pr_number === "" ? undefined : parseInt(source_pr_number),
8891
};
8992
const backport = new Backport(github, config, git);
9093

0 commit comments

Comments
 (0)