Skip to content

Commit

Permalink
feat(core): assign merger and requested reviewers as new reviewer (#14)
Browse files Browse the repository at this point in the history
* fix a bug where the output was not set properly due to early exit.

Signed-off-by: Joshua Schmid <[email protected]>
  • Loading branch information
jschmid1 authored Mar 7, 2024
1 parent d9f52f8 commit 9d2ead0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
25 changes: 20 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CherryPick {
this.git = git;
}
run() {
var _a, _b, _c, _d;
var _a, _b, _c, _d, _e;
return __awaiter(this, void 0, void 0, function* () {
try {
const payload = this.github.getPayload();
Expand Down Expand Up @@ -177,6 +177,7 @@ class CherryPick {
});
}
else {
core.setFailed("An unexpected error occured. Please check the logs for details");
throw error;
}
}
Expand All @@ -197,6 +198,7 @@ class CherryPick {
});
}
else {
core.setFailed("An unexpected error occured. Please check the logs for details");
throw error;
}
}
Expand All @@ -216,6 +218,7 @@ class CherryPick {
issue_number: pull_number,
body: message,
});
this.createOutput(successByTarget);
return;
}
try {
Expand All @@ -231,6 +234,7 @@ class CherryPick {
issue_number: pull_number,
body: message,
});
this.createOutput(successByTarget);
return;
}
console.info(`Push branch ${branchname} to remote ${upstream_name}`);
Expand All @@ -245,6 +249,7 @@ class CherryPick {
issue_number: pull_number,
body: message,
});
this.createOutput(successByTarget);
return;
}
const [upstream_owner, upstream_repo] = this.extractOwnerRepoFromUpstreamRepo(this.config.upstream_repo);
Expand All @@ -269,16 +274,23 @@ class CherryPick {
issue_number: pull_number,
body: message,
});
this.createOutput(successByTarget);
return;
}
const new_pr = new_pr_response.data;
const reviewer = mainpr.merged_by ? mainpr.merged_by.login : null;
if (reviewer) {
console.info("Setting reviewer " + reviewer);
// get the merger of the main pr
const merger = mainpr.merged_by ? mainpr.merged_by.login : null;
// also copy the assigned reviewers over
const requested_reviewers = (_e = mainpr.requested_reviewers) === null || _e === void 0 ? void 0 : _e.map((reviewer) => reviewer.login);
// merge reviewer and requested_reviewers
const reviewers = [merger, ...(requested_reviewers || [])].filter((reviewer) => typeof reviewer === "string");
if (reviewers) {
console.info("Setting reviewers for the new PR");
const reviewRequest = {
owner: upstream_owner,
repo: upstream_repo,
pull_number: new_pr.number,
reviewers: [reviewer],
reviewers: reviewers || [],
};
const set_reviewers_response = yield this.github.requestReviewers(reviewRequest);
if (set_reviewers_response.status != 201) {
Expand All @@ -304,8 +316,11 @@ class CherryPick {
issue_number: pull_number,
body: error.message,
});
this.createOutput(successByTarget);
return;
}
else {
core.setFailed("An unexpected error occured. Please check the logs for details");
throw error;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

35 changes: 31 additions & 4 deletions src/cherrypick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ export class CherryPick {
body: error.message,
});
} else {
core.setFailed(
"An unexpected error occured. Please check the logs for details",
);
throw error;
}
}
Expand All @@ -240,6 +243,9 @@ export class CherryPick {
body: message,
});
} else {
core.setFailed(
"An unexpected error occured. Please check the logs for details",
);
throw error;
}
}
Expand Down Expand Up @@ -273,6 +279,7 @@ export class CherryPick {
issue_number: pull_number,
body: message,
});
this.createOutput(successByTarget);
return;
}

Expand All @@ -296,6 +303,7 @@ export class CherryPick {
issue_number: pull_number,
body: message,
});
this.createOutput(successByTarget);
return;
}

Expand All @@ -319,6 +327,7 @@ export class CherryPick {
issue_number: pull_number,
body: message,
});
this.createOutput(successByTarget);
return;
}

Expand Down Expand Up @@ -353,17 +362,30 @@ export class CherryPick {
issue_number: pull_number,
body: message,
});
this.createOutput(successByTarget);
return;
}
const new_pr = new_pr_response.data;

const reviewer = mainpr.merged_by ? mainpr.merged_by.login : null;
if (reviewer) {
console.info("Setting reviewer " + reviewer);
// get the merger of the main pr
const merger = mainpr.merged_by ? mainpr.merged_by.login : null;

// also copy the assigned reviewers over
const requested_reviewers = mainpr.requested_reviewers?.map(
(reviewer) => reviewer.login,
);
// merge reviewer and requested_reviewers
const reviewers = [merger, ...(requested_reviewers || [])].filter(
(reviewer): reviewer is string => typeof reviewer === "string",
);

if (reviewers) {
console.info("Setting reviewers for the new PR");
const reviewRequest = {
owner: upstream_owner,
repo: upstream_repo,
pull_number: new_pr.number,
reviewers: [reviewer],
reviewers: reviewers || [],
};
const set_reviewers_response =
await this.github.requestReviewers(reviewRequest);
Expand Down Expand Up @@ -394,7 +416,12 @@ export class CherryPick {
issue_number: pull_number,
body: error.message,
});
this.createOutput(successByTarget);
return;
} else {
core.setFailed(
"An unexpected error occured. Please check the logs for details",
);
throw error;
}
}
Expand Down

0 comments on commit 9d2ead0

Please sign in to comment.