Skip to content

Commit

Permalink
Merge pull request #126 from github/actions-bot-user-fixes
Browse files Browse the repository at this point in the history
properly fetch "login" when using Actions tokens instead of a PAT
  • Loading branch information
GrantBirki authored Nov 28, 2023
2 parents 245059b + 9070ff7 commit 365f527
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
29 changes: 26 additions & 3 deletions dist/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/index.js.map

Large diffs are not rendered by default.

29 changes: 26 additions & 3 deletions src/github-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,32 @@ class GitHubProvider {
}

async getCurrentUser() {
const { data: currentUser } =
await this.octokit.rest.users.getAuthenticated();
return currentUser.login;
let login;
try {
core.debug(
`attempting to get current user via octokit.rest.users.getAuthenticated()`,
);
const { data: currentUser } =
await this.octokit.rest.users.getAuthenticated();
login = currentUser.login;
core.debug(
"obtained current user via octokit.rest.users.getAuthenticated()",
);
} catch (error) {
core.debug(error);
core.debug(
`octokit.rest.users.getAuthenticated() failed, trying with octokit.rest.apps.getAuthenticated() instead`,
);
const { data: currentApp } =
await this.octokit.rest.apps.getAuthenticated();
login = currentApp.slug;
core.debug(
"obtained current user via octokit.rest.apps.getAuthenticated()",
);
}

core.debug(`current user: ${login}`);
return login;
}

// check if the current authenticated user (login) has an active APPROVED review on the PR
Expand Down

0 comments on commit 365f527

Please sign in to comment.