Skip to content

Commit

Permalink
fix(pr): make reviewer a different token input
Browse files Browse the repository at this point in the history
since protected branches can't be reviewed by the pr author, we need an option to provide a
different token for the review user
  • Loading branch information
thatkookooguy committed Aug 9, 2022
1 parent 75f322c commit d42c8b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
token: # change this
required: true
description: github token to run the action against
reviewerToken:
required: false
description: github token to use for the review approval
hotfixAgainstBranch:
required: true
description: 1st branch (usually master\main)
Expand Down
22 changes: 15 additions & 7 deletions src/github-communicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum StatusMessage {

export interface IGithubInput {
githubToken: string;
reviewerToken: string;
hotfixAgainstBranch: string;
openPrAgainstBranch: string;
jobName: string;
Expand Down Expand Up @@ -44,12 +45,17 @@ export interface IGithubPullRequest {
export class GithubCommunicator {
options: IGithubInput;
octokit;
octokitReviewer;
context: Context;
statusCheckName = 'gitflow-hotfix';
constructor(options: IGithubInput) {
this.options = options;
this.context = options.context;
this.octokit = getOctokit(this.options.githubToken);

if (this.options.reviewerToken) {
this.octokitReviewer = getOctokit(this.options.reviewerToken);
}
}

async openPRIfHotfix() {
Expand Down Expand Up @@ -132,13 +138,15 @@ export class GithubCommunicator {
issue_number: createdPR.number,
assignees: existingPR.user?.login ? [ existingPR.user.login ] : []
});
await this.octokit.rest.pulls.createReview({
owner: this.context.repo.owner,
repo: this.context.repo.repo,
pull_number: createdPR.number,
event: 'APPROVE',
body: 'Auto approved by [gitflow-hotfix](https://github.com/marketplace/actions/kibibit-gitflow-hotfix)'
});
if (this.options.reviewerToken && this.octokitReviewer) {
await this.octokitReviewer.rest.pulls.createReview({
owner: this.context.repo.owner,
repo: this.context.repo.repo,
pull_number: createdPR.number,
event: 'APPROVE',
body: 'Auto approved by [gitflow-hotfix](https://github.com/marketplace/actions/kibibit-gitflow-hotfix)'
});
}
await this.octokit.rest.issues.addLabels({
owner: this.context.repo.owner,
issue_number: createdPR.number,
Expand Down

0 comments on commit d42c8b5

Please sign in to comment.