Skip to content

Commit e09ab84

Browse files
Guard github app skip on found repos
1 parent f40071c commit e09ab84

4 files changed

Lines changed: 78 additions & 6 deletions

File tree

dist/index.js

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

src/api/client.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import test from 'node:test';
2+
import assert from 'node:assert/strict';
3+
import {
4+
shouldSkipLegacyActionForIntegration,
5+
RepositoryIntegrationModeResponse,
6+
} from './client';
7+
8+
function createIntegrationModeResponse(
9+
overrides: Partial<RepositoryIntegrationModeResponse> = {}
10+
): RepositoryIntegrationModeResponse {
11+
return {
12+
repository_id: 'repo_123',
13+
found: true,
14+
integration_mode: 'legacy_action',
15+
...overrides,
16+
};
17+
}
18+
19+
test('skips the legacy action only for found github_app repositories', () => {
20+
assert.equal(
21+
shouldSkipLegacyActionForIntegration(
22+
createIntegrationModeResponse({ integration_mode: 'github_app' })
23+
),
24+
true
25+
);
26+
27+
assert.equal(
28+
shouldSkipLegacyActionForIntegration(
29+
createIntegrationModeResponse({ found: false, integration_mode: 'github_app' })
30+
),
31+
false
32+
);
33+
34+
assert.equal(
35+
shouldSkipLegacyActionForIntegration(createIntegrationModeResponse()),
36+
false
37+
);
38+
});

src/api/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ export interface RepositoryIntegrationModeResponse {
2323
integration_mode: 'legacy_action' | 'github_app';
2424
}
2525

26+
export function shouldSkipLegacyActionForIntegration(
27+
integration: RepositoryIntegrationModeResponse
28+
): boolean {
29+
return integration.found && integration.integration_mode === 'github_app';
30+
}
31+
2632
export class AsymptoteClient {
2733
private apiKey: string;
2834
private baseUrl: string;

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import * as core from '@actions/core';
22
import * as github from '@actions/github';
33
import { getConfig } from './config';
4-
import { AsymptoteClient, RateLimitError, TimeoutError } from './api/client';
4+
import {
5+
AsymptoteClient,
6+
RateLimitError,
7+
shouldSkipLegacyActionForIntegration,
8+
TimeoutError,
9+
} from './api/client';
510
import { getPRDiff, getIncrementalDiff } from './github/diff';
611
import { postViolationComments, resolveOutdatedThreads } from './github.qkg1.topments';
712
import { createCheckRun } from './github/checks';
@@ -44,7 +49,7 @@ async function run(): Promise<void> {
4449
github.context.repo.owner,
4550
github.context.repo.repo
4651
);
47-
if (integration.integration_mode === 'github_app') {
52+
if (shouldSkipLegacyActionForIntegration(integration)) {
4853
core.info(
4954
'Repository is configured for GitHub App PR reviews; exiting legacy action without posting comments or checks.'
5055
);

0 commit comments

Comments
 (0)