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 created_pull_numbers output #404

Merged
merged 6 commits into from
Dec 16, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,6 @@ The action provides the following [outputs](https://docs.github.com/en/actions/u

Output | Description
-------|------------
`created_pull_numbers` | Space-separated list containing the identifying number of each created pull request. Or empty when the action created no pull requests. For example, `123` or `123 124 125`.
`was_successful` | Whether or not the changes could be backported successfully to all targets. Either `true` or `false`.
`was_successful_by_target` | Whether or not the changes could be backported successfully to all targets - broken down by target. Follows the pattern `{{label}}=true\|false`.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ inputs:
By default, only backport labels are used to specify the target branches.

outputs:
created_pull_numbers:
description: >
Space-separated list containing the identifying number of each created pull request.
Or empty when the action created no pull requests.
For example, '123' or '123 124 125'.
was_successful:
description: >
Whether or not the changes could be backported successfully to all targets.
Expand Down
9 changes: 7 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var Output;
(function (Output) {
Output["wasSuccessful"] = "was_successful";
Output["wasSuccessfulByTarget"] = "was_successful_by_target";
Output["created_pull_numbers"] = "created_pull_numbers";
})(Output || (Output = {}));
class Backport {
constructor(github, config, git) {
Expand Down Expand Up @@ -162,6 +163,7 @@ class Backport {
}
console.log(`Will copy labels matching ${this.config.copy_labels_pattern}. Found matching labels: ${labelsToCopy}`);
const successByTarget = new Map();
const createdPullRequestNumbers = new Array();
for (const target of target_branches) {
console.log(`Backporting to target branch '${target}...'`);
try {
Expand Down Expand Up @@ -295,6 +297,7 @@ class Backport {
}
const message = this.composeMessageForSuccess(new_pr.number, target);
successByTarget.set(target, true);
createdPullRequestNumbers.push(new_pr.number);
yield this.github.createComment({
owner,
repo,
Expand All @@ -318,7 +321,7 @@ class Backport {
}
}
}
this.createOutput(successByTarget);
this.createOutput(successByTarget, createdPullRequestNumbers);
}
catch (error) {
if (error instanceof Error) {
Expand Down Expand Up @@ -384,11 +387,13 @@ class Backport {
return (0, dedent_1.default) `Successfully created backport PR for \`${target}\`:
- #${pr_number}`;
}
createOutput(successByTarget) {
createOutput(successByTarget, createdPullRequestNumbers) {
const anyTargetFailed = Array.from(successByTarget.values()).includes(false);
core.setOutput(Output.wasSuccessful, !anyTargetFailed);
const byTargetOutput = Array.from(successByTarget.entries()).reduce((i, [target, result]) => `${i}${target}=${result}\n`, "");
core.setOutput(Output.wasSuccessfulByTarget, byTargetOutput);
const createdPullNumbersOutput = createdPullRequestNumbers.join(" ");
core.setOutput(Output.created_pull_numbers, createdPullNumbersOutput);
}
}
exports.Backport = Backport;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export { experimentalDefaults };
enum Output {
wasSuccessful = "was_successful",
wasSuccessfulByTarget = "was_successful_by_target",
created_pull_numbers = "created_pull_numbers",
}

export class Backport {
Expand Down Expand Up @@ -209,6 +210,7 @@ export class Backport {
);

const successByTarget = new Map<string, boolean>();
const createdPullRequestNumbers = new Array<number>();
for (const target of target_branches) {
console.log(`Backporting to target branch '${target}...'`);

Expand Down Expand Up @@ -382,6 +384,7 @@ export class Backport {

const message = this.composeMessageForSuccess(new_pr.number, target);
successByTarget.set(target, true);
createdPullRequestNumbers.push(new_pr.number);
await this.github.createComment({
owner,
repo,
Expand All @@ -404,7 +407,7 @@ export class Backport {
}
}

this.createOutput(successByTarget);
this.createOutput(successByTarget, createdPullRequestNumbers);
} catch (error) {
if (error instanceof Error) {
console.error(error.message);
Expand Down Expand Up @@ -512,7 +515,10 @@ export class Backport {
- #${pr_number}`;
}

private createOutput(successByTarget: Map<string, boolean>) {
private createOutput(
successByTarget: Map<string, boolean>,
createdPullRequestNumbers: Array<number>,
) {
const anyTargetFailed = Array.from(successByTarget.values()).includes(
false,
);
Expand All @@ -523,6 +529,9 @@ export class Backport {
"",
);
core.setOutput(Output.wasSuccessfulByTarget, byTargetOutput);

const createdPullNumbersOutput = createdPullRequestNumbers.join(" ");
core.setOutput(Output.created_pull_numbers, createdPullNumbersOutput);
}
}

Expand Down
Loading