Skip to content

Commit

Permalink
fix: support personal access token input (#53)
Browse files Browse the repository at this point in the history
danadajian authored Jan 4, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b2fb12b commit 6eec2ac
Showing 45 changed files with 147 additions and 81 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/manage-merge-queue.yml
Original file line number Diff line number Diff line change
@@ -17,5 +17,4 @@ jobs:
helper: manage-merge-queue
sha: ${{ github.event.pull_request.head.sha }}
github_token: ${{ secrets.GITHUB_TOKEN }}

permissions: write-all
personal_access_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} # must have repo:write permission
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 12.20.1

- name: Install Dependencies
run: npm ci
@@ -43,8 +43,8 @@ jobs:
exit 1
fi
# If dist/ was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v2
- name: If dist/ was different than expected, upload the expected output as an artifact
uses: actions/upload-artifact@v2
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,9 @@ inputs:
github_token:
description: 'The github token'
required: true
personal_access_token:
description: 'A personal access token to be used for triggering github events that trigger other workflows'
required: false
body:
description: 'The comment body'
required: false
7 changes: 5 additions & 2 deletions dist/0.index.js

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

2 changes: 1 addition & 1 deletion dist/0.index.js.map

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

7 changes: 5 additions & 2 deletions dist/101.index.js

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

2 changes: 1 addition & 1 deletion dist/101.index.js.map
7 changes: 5 additions & 2 deletions dist/124.index.js
2 changes: 1 addition & 1 deletion dist/124.index.js.map
7 changes: 5 additions & 2 deletions dist/154.index.js
2 changes: 1 addition & 1 deletion dist/154.index.js.map
7 changes: 5 additions & 2 deletions dist/209.index.js
2 changes: 1 addition & 1 deletion dist/209.index.js.map
7 changes: 5 additions & 2 deletions dist/263.index.js
2 changes: 1 addition & 1 deletion dist/263.index.js.map
17 changes: 10 additions & 7 deletions dist/4.index.js
2 changes: 1 addition & 1 deletion dist/4.index.js.map
7 changes: 5 additions & 2 deletions dist/420.index.js
2 changes: 1 addition & 1 deletion dist/420.index.js.map
7 changes: 5 additions & 2 deletions dist/461.index.js
2 changes: 1 addition & 1 deletion dist/461.index.js.map
17 changes: 10 additions & 7 deletions dist/473.index.js
2 changes: 1 addition & 1 deletion dist/473.index.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions dist/522.index.js
2 changes: 1 addition & 1 deletion dist/522.index.js.map
7 changes: 5 additions & 2 deletions dist/533.index.js
2 changes: 1 addition & 1 deletion dist/533.index.js.map
7 changes: 5 additions & 2 deletions dist/61.index.js
2 changes: 1 addition & 1 deletion dist/61.index.js.map
7 changes: 5 additions & 2 deletions dist/794.index.js
2 changes: 1 addition & 1 deletion dist/794.index.js.map
7 changes: 5 additions & 2 deletions dist/807.index.js
2 changes: 1 addition & 1 deletion dist/807.index.js.map
7 changes: 5 additions & 2 deletions dist/905.index.js
2 changes: 1 addition & 1 deletion dist/905.index.js.map
7 changes: 5 additions & 2 deletions dist/913.index.js
2 changes: 1 addition & 1 deletion dist/913.index.js.map
7 changes: 5 additions & 2 deletions dist/939.index.js
2 changes: 1 addition & 1 deletion dist/939.index.js.map
7 changes: 5 additions & 2 deletions dist/956.index.js
2 changes: 1 addition & 1 deletion dist/956.index.js.map
3 changes: 3 additions & 0 deletions dist/action.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,9 @@ inputs:
github_token:
description: 'The github token'
required: true
personal_access_token:
description: 'A personal access token to be used for triggering github events that trigger other workflows'
required: false
body:
description: 'The comment body'
required: false
4 changes: 2 additions & 2 deletions src/helpers/prepare-queued-pr-for-merge.ts
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@ limitations under the License.
import * as core from '@actions/core';
import { FIRST_QUEUED_PR_LABEL, JUMP_THE_QUEUE_PR_LABEL, READY_FOR_MERGE_PR_LABEL } from '../constants';
import { PullRequest, PullRequestListResponse, SimplePullRequest } from '../types';
import { octokit, octokitWithPat } from '../octokit';
import { context } from '@actions/github';
import { octokit } from '../octokit';

export const prepareQueuedPrForMerge = () =>
octokit.pulls
@@ -39,7 +39,7 @@ const hasRequiredLabels = (pr: SimplePullRequest, requiredLabels: string[]) =>
requiredLabels.every(mergeQueueLabel => pr.labels.some(label => label.name === mergeQueueLabel));

export const updatePrWithMainline = (pullRequest: PullRequest | SimplePullRequest) =>
octokit.repos
octokitWithPat.repos
.merge({
base: pullRequest.head.ref,
head: 'HEAD',
6 changes: 5 additions & 1 deletion src/octokit.ts
Original file line number Diff line number Diff line change
@@ -15,4 +15,8 @@ import * as core from '@actions/core';
import { Octokit } from '@octokit/rest';
import { getOctokit } from '@actions/github';

export const octokit = getOctokit(core.getInput('github_token', { required: true })).rest as unknown as Octokit;
const githubToken = core.getInput('github_token', { required: true });

export const octokit = getOctokit(githubToken).rest as unknown as Octokit;

export const octokitWithPat = getOctokit(core.getInput('personal_access_token') || githubToken).rest as unknown as Octokit;
12 changes: 6 additions & 6 deletions test/helpers/prepare-queued-pr-for-merge.test.ts
Original file line number Diff line number Diff line change
@@ -13,9 +13,9 @@ limitations under the License.

import * as core from '@actions/core';
import { FIRST_QUEUED_PR_LABEL, JUMP_THE_QUEUE_PR_LABEL, READY_FOR_MERGE_PR_LABEL } from '../../src/constants';
import { octokit, octokitWithPat } from '../../src/octokit';
import { Mocktokit } from '../types';
import { context } from '@actions/github';
import { octokit } from '../../src/octokit';
import { prepareQueuedPrForMerge } from '../../src/helpers/prepare-queued-pr-for-merge';

jest.mock('@actions/core');
@@ -32,7 +32,7 @@ jest.mock('@actions/github', () => ({
}
}))
}));
(octokit.repos.merge as unknown as Mocktokit).mockImplementation(async () => ({ some: 'response' }));
(octokitWithPat.repos.merge as unknown as Mocktokit).mockImplementation(async () => ({ some: 'response' }));

describe('prepareQueuedPrForMerge', () => {
const ref = 'branch name';
@@ -80,7 +80,7 @@ describe('prepareQueuedPrForMerge', () => {
});

it('should call repos.merge with correct params', () => {
expect(octokit.repos.merge).toHaveBeenCalledWith({
expect(octokitWithPat.repos.merge).toHaveBeenCalledWith({
base: ref,
head: 'HEAD',
...context.repo
@@ -146,7 +146,7 @@ describe('prepareQueuedPrForMerge', () => {
});

it('should call repos.merge with correct params', () => {
expect(octokit.repos.merge).toHaveBeenCalledWith({
expect(octokitWithPat.repos.merge).toHaveBeenCalledWith({
base: jumpQueueBranch,
head: 'HEAD',
...context.repo
@@ -183,7 +183,7 @@ describe('prepareQueuedPrForMerge', () => {
});

it('should not call repos.merge', () => {
expect(octokit.repos.merge).not.toHaveBeenCalled();
expect(octokitWithPat.repos.merge).not.toHaveBeenCalled();
});
});

@@ -219,7 +219,7 @@ describe('prepareQueuedPrForMerge', () => {
}
]
}));
(octokit.repos.merge as unknown as Mocktokit).mockRejectedValue({ status: 409 });
(octokitWithPat.repos.merge as unknown as Mocktokit).mockRejectedValue({ status: 409 });
prepareQueuedPrForMerge();
});

0 comments on commit 6eec2ac

Please sign in to comment.