properly fetch "login" when using Actions tokens instead of a PAT

This commit is contained in:
GrantBirki 2023-11-28 13:20:16 -07:00
Родитель 245059b04a
Коммит 9070ff72e2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 9029BBCCC15C6F8C
3 изменённых файлов: 53 добавлений и 7 удалений

29
dist/index.js сгенерированный поставляемый
Просмотреть файл

@ -37665,9 +37665,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

2
dist/index.js.map сгенерированный поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -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