Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source_pr_number input #434

Merged
merged 8 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ Placeholders can be used to define variable values.
These are indicated by a dollar sign and curly braces (`${placeholder}`).
Please refer to this action's README for all available [placeholders](#placeholders).

### `source_pr_number`

Default: `''` (not set)

Specifies the pull request (by its number) to backport, i.e. the source pull request.
When set, the action will backport the specified pull request to each target branch.
When not set, the action determines the source pull request from the event payload.

### `target_branches`

Default: `''` (disabled)
Expand Down
17 changes: 11 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ author: korthout
inputs:
branch_name:
description: >
Template used as the name for branches created by this action.
Template used as the name for branches created by this action.
Placeholders can be used to define variable values.
These are indicated by a dollar sign and curly braces (`${placeholder}`).
Please refer to this action's README for all available placeholders.
Expand Down Expand Up @@ -52,23 +52,23 @@ inputs:

#### `conflict_resolution`

Specifies how the action will handle a conflict occuring during the cherry-pick.
Specifies how the action will handle a conflict occuring during the cherry-pick.
In all cases, the action will stop the cherry-pick at the first conflict encountered.

Behavior is defined by the option selected.
- When set to `fail` the backport fails when the cherry-pick encounters a conflict.
- When set to `draft_commit_conflicts` the backport will always create a draft pull request with the first conflict encountered committed.

Instructions are provided on the original pull request on how to resolve the conflict and continue the cherry-pick.

#### `downstream_repo`

Define if you want to backport to a repository other than where the workflow runs.

By default, the action always backports to the repository in which the workflow runs.

#### `downstream_owner`

Define if you want to backport to another owner than the owner of the repository the workflow runs on.
Only takes effect if the `downstream_repo` property is also defined.

Expand Down Expand Up @@ -116,6 +116,11 @@ inputs:
Please refer to this action's README for all available placeholders.
default: >-
[Backport ${target_branch}] ${pull_title}
source_pr_number:
description: >
Specifies the pull request (by its number) to backport, i.e. the source pull request.
When set, the action will backport the specified pull request to each target branch.
When not set, the action determines the source pull request from the event payload.
target_branches:
description: >
The action will backport the pull request to each specified target branch (space-delimited).
Expand Down
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class Backport {
: workflowRepo;
if (repo === undefined)
throw new Error("No repository defined!");
const pull_number = this.github.getPullNumber();
const pull_number = this.config.source_pr_number === undefined
? this.github.getPullNumber()
: this.config.source_pr_number;
const mainpr = yield this.github.getPullRequest(pull_number);
if (!(yield this.github.isMerged(mainpr))) {
const message = "Only merged pull requests can be backported.";
Expand Down Expand Up @@ -467,7 +469,7 @@ class Backport {
const suggestionToResolve = this.composeMessageToResolveCommittedConflicts(target, branchname, commitShasToCherryPick, conflictResolution);
return (0, dedent_1.default) `Created backport PR for \`${target}\`:
- ${downstream}#${pr_number} with remaining conflicts!

${suggestionToResolve}`;
}
createOutput(successByTarget, createdPullRequestNumbers) {
Expand Down Expand Up @@ -1078,6 +1080,7 @@ function run() {
const copy_milestone = core.getInput("copy_milestone");
const copy_requested_reviewers = core.getInput("copy_requested_reviewers");
const experimental = JSON.parse(core.getInput("experimental"));
const source_pr_number = core.getInput("source_pr_number");
if (cherry_picking !== "auto" && cherry_picking !== "pull_request_head") {
const message = `Expected input 'cherry_picking' to be either 'auto' or 'pull_request_head', but was '${cherry_picking}'`;
console.error(message);
Expand Down Expand Up @@ -1124,6 +1127,7 @@ function run() {
copy_milestone: copy_milestone === "true",
copy_requested_reviewers: copy_requested_reviewers === "true",
experimental: Object.assign(Object.assign({}, backport_1.experimentalDefaults), experimental),
source_pr_number: source_pr_number === "" ? undefined : parseInt(source_pr_number),
};
const backport = new backport_1.Backport(github, config, git);
return backport.run();
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type Config = {
labels: {
pattern?: RegExp;
};
source_pr_number?: number;
pull: {
description: string;
title: string;
Expand Down Expand Up @@ -104,7 +105,10 @@ export class Backport {

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

const pull_number = this.github.getPullNumber();
const pull_number =
this.config.source_pr_number === undefined
? this.github.getPullNumber()
: this.config.source_pr_number;
const mainpr = await this.github.getPullRequest(pull_number);

if (!(await this.github.isMerged(mainpr))) {
Expand Down Expand Up @@ -677,7 +681,7 @@ export class Backport {
);
return dedent`Created backport PR for \`${target}\`:
- ${downstream}#${pr_number} with remaining conflicts!

${suggestionToResolve}`;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function run(): Promise<void> {
const copy_milestone = core.getInput("copy_milestone");
const copy_requested_reviewers = core.getInput("copy_requested_reviewers");
const experimental = JSON.parse(core.getInput("experimental"));
const source_pr_number = core.getInput("source_pr_number");

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

Expand Down
Loading