Skip to content

Commit 2190fc9

Browse files
fix: use GraphQL viewer query for authenticated user detection (#194)
REST endpoints users.getAuthenticated and apps.getAuthenticated both fail for GitHub App installation tokens. The GraphQL viewer query works for both PATs and App installation tokens, returning the correct login (e.g., {app-slug}[bot] for Apps). Bump to v2.9.2.
1 parent 088fdb3 commit 2190fc9

5 files changed

Lines changed: 10 additions & 17 deletions

File tree

__tests__/index.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ const mockOctokit = {
8282
}
8383
},
8484
request: jest.fn(),
85-
paginate: jest.fn()
85+
paginate: jest.fn(),
86+
graphql: jest.fn()
8687
};
8788

8889
// Mock fs module - use a real implementation that tracks test content

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bulk-github-repo-settings-sync-action",
33
"description": "Update repository settings in bulk for multiple GitHub repositories",
4-
"version": "2.9.1",
4+
"version": "2.9.2",
55
"type": "module",
66
"author": {
77
"name": "Josh Johanning",

src/index.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4845,19 +4845,11 @@ export async function run() {
48454845
// Get authenticated user/app login for stale PR author matching
48464846
let authenticatedLogin = '';
48474847
try {
4848-
const { data: authUser } = await octokit.rest.users.getAuthenticated();
4849-
authenticatedLogin = authUser.login;
4848+
const { viewer } = await octokit.graphql('{ viewer { login } }');
4849+
authenticatedLogin = viewer.login;
48504850
core.debug(`Authenticated as: ${authenticatedLogin}`);
4851-
} catch (userError) {
4852-
// GitHub App installation tokens don't support users.getAuthenticated
4853-
// Try the app endpoint to get the bot login ({app-slug}[bot])
4854-
try {
4855-
const { data: app } = await octokit.rest.apps.getAuthenticated();
4856-
authenticatedLogin = `${app.slug}[bot]`;
4857-
core.debug(`Authenticated as GitHub App: ${authenticatedLogin}`);
4858-
} catch (appError) {
4859-
core.debug(`Could not determine authenticated user (${userError.message}) or app (${appError.message})`);
4860-
}
4851+
} catch (error) {
4852+
core.debug(`Could not determine authenticated user: ${error.message}`);
48614853
}
48624854

48634855
// Parse repository list

0 commit comments

Comments
 (0)