Skip to content

Commit 26d435c

Browse files
committed
refactor: rename isAuthorizedUser to isAuthorizedElectronRepoUser
Address review feedback from dsanders11: the authorization check is now hardcoded to evaluate permissions against electron/electron, so the generic name was misleading. Rename it to reflect that it specifically authorizes users against the electron/electron repository. No behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LL7ZzLv5mo4Wqf3BiWk8HB
1 parent e67a9aa commit 26d435c

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { handleChromiumCheck } from './chromium-handler.js';
55
import { handleBuildImagesCheck } from './build-images-handler.js';
66
import { handleBuildImagesChromiumDepsCheck } from './build-images-chromium-deps-handler.js';
77
import { REPOS, ROLL_TARGETS } from './constants.js';
8-
import { isAuthorizedUser } from './utils/is-authorized-user.js';
8+
import { isAuthorizedElectronRepoUser } from './utils/is-authorized-user.js';
99

1010
const handler = (robot: Probot) => {
1111
robot.on('pull_request.closed', async (context) => {
@@ -83,7 +83,7 @@ const handler = (robot: Probot) => {
8383
}
8484

8585
// Allow all users with push access to run commands
86-
if (!(await isAuthorizedUser(context, comment.user.login))) {
86+
if (!(await isAuthorizedElectronRepoUser(context, comment.user.login))) {
8787
d(`@${comment.user.login} is not authorized to run roller commands - stopping`);
8888
await context.octokit.rest.issues.createComment(
8989
context.repo({

src/utils/is-authorized-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Context } from 'probot';
22

33
import { REPOS } from '../constants.js';
44

5-
export async function isAuthorizedUser(
5+
export async function isAuthorizedElectronRepoUser(
66
context: Context<'issue_comment.created'>,
77
username: string,
88
) {

tests/index.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
55
import handler from '../src/index.js';
66
import { handleChromiumCheck } from '../src/chromium-handler.js';
77
import { handleNodeCheck } from '../src/node-handler.js';
8-
import { isAuthorizedUser } from '../src/utils/is-authorized-user.js';
8+
import { isAuthorizedElectronRepoUser } from '../src/utils/is-authorized-user.js';
99

1010
import issueCommentRollCreatedEvent from './fixtures/issue_comment_roll.created.json' with { type: 'json' };
1111

@@ -44,7 +44,7 @@ describe('roller', () => {
4444
});
4545

4646
it('rolls Chromium when an authorized user comments /roll main', async () => {
47-
vi.mocked(isAuthorizedUser).mockResolvedValue(true);
47+
vi.mocked(isAuthorizedElectronRepoUser).mockResolvedValue(true);
4848

4949
nock(GH_API)
5050
.post('/repos/electron/electron/issues/0/comments', ({ body }) => {
@@ -59,7 +59,7 @@ describe('roller', () => {
5959
});
6060

6161
it('rolls Node.js when an authorized user comments /roll main', async () => {
62-
vi.mocked(isAuthorizedUser).mockResolvedValue(true);
62+
vi.mocked(isAuthorizedElectronRepoUser).mockResolvedValue(true);
6363

6464
nock(GH_API)
6565
.post('/repos/electron/electron/issues/0/comments', ({ body }) => {
@@ -76,20 +76,20 @@ describe('roller', () => {
7676
});
7777

7878
it('ignores roll commands from repositories other than electron/electron', async () => {
79-
vi.mocked(isAuthorizedUser).mockResolvedValue(true);
79+
vi.mocked(isAuthorizedElectronRepoUser).mockResolvedValue(true);
8080

8181
const event = JSON.parse(JSON.stringify(issueCommentRollCreatedEvent));
8282
event.payload.repository.name = 'other-repo';
8383
event.payload.repository.full_name = 'electron/other-repo';
8484
await probot.receive(event as Parameters<typeof probot.receive>[0]);
8585

86-
expect(isAuthorizedUser).not.toHaveBeenCalled();
86+
expect(isAuthorizedElectronRepoUser).not.toHaveBeenCalled();
8787
expect(handleChromiumCheck).not.toHaveBeenCalled();
8888
expect(handleNodeCheck).not.toHaveBeenCalled();
8989
});
9090

9191
it('blocks unauthorized users from triggering a roll', async () => {
92-
vi.mocked(isAuthorizedUser).mockResolvedValue(false);
92+
vi.mocked(isAuthorizedElectronRepoUser).mockResolvedValue(false);
9393

9494
nock(GH_API)
9595
.post('/repos/electron/electron/issues/0/comments', ({ body }) => {

0 commit comments

Comments
 (0)