Skip to content

Commit

Permalink
Helpful error message for 404 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hmarr committed Mar 15, 2021
1 parent e21ecf1 commit eeecb82
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5897,6 +5897,11 @@ function approve(token, context) {
"from `pull_request` events are read-only, which can cause this problem. " +
"Switching to the `pull_request_target` event typically resolves this issue.");
break;
case 404:
core.setFailed(`${error.message}. This typically means the token you're using doesn't have ` +
"access to this repository. Use the built-in `${{ secrets.GITHUB_TOKEN }}` token " +
"or review the scopes assigned to your personal access token.");
break;
case 422:
core.setFailed(`${error.message}. This typically happens when you try to approve the pull ` +
"request with the same user account that created the pull request. Try using " +
Expand Down
12 changes: 12 additions & 0 deletions src/approve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ test("when a user tries to approve their own pull request", async () => {
);
});

test("when the token doesn't have access to the repository", async () => {
nock("https://api.github.com")
.post("/repos/hmarr/test/pulls/101/reviews")
.reply(404, { message: "Not Found" });

await approve("gh-tok", ghContext());

expect(core.setFailed).toHaveBeenCalledWith(
expect.stringContaining("doesn't have access")
);
});

function ghContext(): Context {
const ctx = new Context();
ctx.payload = {
Expand Down
7 changes: 7 additions & 0 deletions src/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export async function approve(token: string, context: Context) {
"Switching to the `pull_request_target` event typically resolves this issue."
);
break;
case 404:
core.setFailed(
`${error.message}. This typically means the token you're using doesn't have ` +
"access to this repository. Use the built-in `${{ secrets.GITHUB_TOKEN }}` token " +
"or review the scopes assigned to your personal access token."
);
break;
case 422:
core.setFailed(
`${error.message}. This typically happens when you try to approve the pull ` +
Expand Down

0 comments on commit eeecb82

Please sign in to comment.