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 option to add original author as assignee #445

Merged
merged 2 commits into from
Feb 23, 2025
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ Controls whether to copy the requested reviewers from the original pull request
Note that this does not request reviews from those users who already reviewed the original pull request.
By default, the requested reviewers are not copied.

### `add_author_as_assignee`

Default: `false` (disabled)

Controls whether to set the author of the original pull request as an assignee on the backport pull request.
By default, the original author is not made an assignee.

### `experimental`

Default:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ inputs:
Note that this does not request reviews from those users who already reviewed the original pull request.
By default, the requested reviewers are not copied.
default: false
add_author_as_assignee:
description: >
Controls whether to set the author of the original pull request as an assignee on the backport pull request.
By default, the original author is not made an assignee.
experimental:
description: >
Configure experimental features by passing a JSON object.
Expand Down
21 changes: 17 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ class Backport {
const assignees = mainpr.assignees.map((label) => label.login);
if (assignees.length > 0) {
console.info("Setting assignees " + assignees);
const set_assignee_response = yield this.github.setAssignees(new_pr.number, assignees, {
const add_assignee_response = yield this.github.addAssignees(new_pr.number, assignees, {
owner,
repo,
});
if (set_assignee_response.status != 201) {
console.error(JSON.stringify(set_assignee_response));
if (add_assignee_response.status != 201) {
console.error(JSON.stringify(add_assignee_response));
}
}
}
Expand Down Expand Up @@ -336,6 +336,17 @@ class Backport {
// The PR was still created so let's still comment on the original.
}
}
if (this.config.add_author_as_assignee == true) {
const author = mainpr.user.login;
console.info("Setting " + author + " as assignee");
const add_assignee_response = yield this.github.addAssignees(new_pr.number, [author], {
owner,
repo,
});
if (add_assignee_response.status != 201) {
console.error(JSON.stringify(add_assignee_response));
}
}
// post success message to original pr
{
const message = uncommitedShas !== null
Expand Down Expand Up @@ -846,7 +857,7 @@ class Github {
return __classPrivateFieldGet(this, _Github_octokit, "f").rest.issues.addLabels(Object.assign(Object.assign({}, repo), { issue_number: pr, labels }));
});
}
setAssignees(pr, assignees, repo) {
addAssignees(pr, assignees, repo) {
return __awaiter(this, void 0, void 0, function* () {
console.log(`Set Assignees ${assignees} to #${pr}`);
return __classPrivateFieldGet(this, _Github_octokit, "f").rest.issues.addAssignees(Object.assign(Object.assign({}, repo), { issue_number: pr, assignees }));
Expand Down Expand Up @@ -1079,6 +1090,7 @@ function run() {
const copy_assignees = core.getInput("copy_assignees");
const copy_milestone = core.getInput("copy_milestone");
const copy_requested_reviewers = core.getInput("copy_requested_reviewers");
const add_author_as_assignee = core.getInput("add_author_as_assignee");
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") {
Expand Down Expand Up @@ -1126,6 +1138,7 @@ function run() {
copy_assignees: copy_assignees === "true",
copy_milestone: copy_milestone === "true",
copy_requested_reviewers: copy_requested_reviewers === "true",
add_author_as_assignee: add_author_as_assignee === "true",
experimental: Object.assign(Object.assign({}, backport_1.experimentalDefaults), experimental),
source_pr_number: source_pr_number === "" ? undefined : parseInt(source_pr_number),
};
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type Config = {
copy_milestone: boolean;
copy_assignees: boolean;
copy_requested_reviewers: boolean;
add_author_as_assignee: boolean;
experimental: Experimental;
};

Expand Down Expand Up @@ -404,16 +405,16 @@ export class Backport {
const assignees = mainpr.assignees.map((label) => label.login);
if (assignees.length > 0) {
console.info("Setting assignees " + assignees);
const set_assignee_response = await this.github.setAssignees(
const add_assignee_response = await this.github.addAssignees(
new_pr.number,
assignees,
{
owner,
repo,
},
);
if (set_assignee_response.status != 201) {
console.error(JSON.stringify(set_assignee_response));
if (add_assignee_response.status != 201) {
console.error(JSON.stringify(add_assignee_response));
}
}
}
Expand Down Expand Up @@ -453,6 +454,22 @@ export class Backport {
}
}

if (this.config.add_author_as_assignee == true) {
const author = mainpr.user.login;
console.info("Setting " + author + " as assignee");
const add_assignee_response = await this.github.addAssignees(
new_pr.number,
[author],
{
owner,
repo,
},
);
if (add_assignee_response.status != 201) {
console.error(JSON.stringify(add_assignee_response));
}
}

// post success message to original pr
{
const message =
Expand Down
4 changes: 2 additions & 2 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface GithubApi {
repo: Repo,
): Promise<LabelPullRequestResponse>;
requestReviewers(request: ReviewRequest): Promise<RequestReviewersResponse>;
setAssignees(
addAssignees(
pr: number,
assignees: string[],
repo: Repo,
Expand Down Expand Up @@ -142,7 +142,7 @@ export class Github implements GithubApi {
});
}

public async setAssignees(pr: number, assignees: string[], repo: Repo) {
public async addAssignees(pr: number, assignees: string[], repo: Repo) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Good change!

console.log(`Set Assignees ${assignees} to #${pr}`);
return this.#octokit.rest.issues.addAssignees({
...repo,
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function run(): Promise<void> {
const copy_assignees = core.getInput("copy_assignees");
const copy_milestone = core.getInput("copy_milestone");
const copy_requested_reviewers = core.getInput("copy_requested_reviewers");
const add_author_as_assignee = core.getInput("add_author_as_assignee");
const experimental = JSON.parse(core.getInput("experimental"));
const source_pr_number = core.getInput("source_pr_number");

Expand Down Expand Up @@ -85,6 +86,7 @@ async function run(): Promise<void> {
copy_assignees: copy_assignees === "true",
copy_milestone: copy_milestone === "true",
copy_requested_reviewers: copy_requested_reviewers === "true",
add_author_as_assignee: add_author_as_assignee === "true",
experimental: { ...experimentalDefaults, ...experimental },
source_pr_number:
source_pr_number === "" ? undefined : parseInt(source_pr_number),
Expand Down
Loading