@shipfox/api-integration-github 12.7.0 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/api/client.d.ts +13 -3
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +83 -4
- package/dist/api/client.js.map +1 -1
- package/dist/core/agent-tools.d.ts.map +1 -1
- package/dist/core/agent-tools.js +2 -6
- package/dist/core/agent-tools.js.map +1 -1
- package/dist/core/bot-identity.d.ts +4 -0
- package/dist/core/bot-identity.d.ts.map +1 -0
- package/dist/core/bot-identity.js +15 -0
- package/dist/core/bot-identity.js.map +1 -0
- package/dist/core/source-control.d.ts +2 -1
- package/dist/core/source-control.d.ts.map +1 -1
- package/dist/core/source-control.js +15 -10
- package/dist/core/source-control.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/api/client.test.ts +206 -18
- package/src/api/client.ts +130 -8
- package/src/core/agent-tools.ts +2 -9
- package/src/core/bot-identity.test.ts +19 -0
- package/src/core/bot-identity.ts +19 -0
- package/src/core/source-control.test.ts +87 -1
- package/src/core/source-control.ts +27 -11
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -25,21 +25,23 @@ import {
|
|
|
25
25
|
type TriggerReference,
|
|
26
26
|
} from '@shipfox/api-integration-spi';
|
|
27
27
|
import type {GithubApiClient, GithubRepository} from '#api/client.js';
|
|
28
|
-
import {config} from '#config.js';
|
|
29
28
|
import {getGithubInstallationByConnectionId} from '#db/installations.js';
|
|
29
|
+
import {configuredGithubAppBotLogin} from './bot-identity.js';
|
|
30
30
|
import {GithubIntegrationProviderError} from './errors.js';
|
|
31
31
|
|
|
32
32
|
type GithubIntegrationConnection = IntegrationConnection<'github'>;
|
|
33
33
|
|
|
34
34
|
const GITHUB_PROVIDER = 'github';
|
|
35
|
-
const GITHUB_APP_BOT_SUFFIX = '[bot]';
|
|
36
35
|
const SEARCH_PAGE_SIZE = 100;
|
|
37
36
|
const SEARCH_MAX_PAGES_PER_REQUEST = 5;
|
|
38
37
|
|
|
39
38
|
export class GithubSourceControlProvider
|
|
40
39
|
implements SourceControlProvider<GithubIntegrationConnection>
|
|
41
40
|
{
|
|
42
|
-
constructor(
|
|
41
|
+
constructor(
|
|
42
|
+
private readonly github: GithubApiClient,
|
|
43
|
+
private readonly appBotLogin: () => string | undefined = configuredGithubAppBotLogin,
|
|
44
|
+
) {}
|
|
43
45
|
|
|
44
46
|
async listRepositories(
|
|
45
47
|
input: ListRepositoriesInput<GithubIntegrationConnection>,
|
|
@@ -204,7 +206,11 @@ export class GithubSourceControlProvider
|
|
|
204
206
|
repositoryId,
|
|
205
207
|
permissions: input.permissions,
|
|
206
208
|
});
|
|
207
|
-
const
|
|
209
|
+
const botLogin = this.appBotLogin();
|
|
210
|
+
const gitAuthor =
|
|
211
|
+
botLogin && input.permissions?.contents === 'write'
|
|
212
|
+
? await githubAppGitAuthor(this.github, token, botLogin)
|
|
213
|
+
: undefined;
|
|
208
214
|
|
|
209
215
|
return {
|
|
210
216
|
repositoryUrl: repository.cloneUrl,
|
|
@@ -250,13 +256,23 @@ function sameGithubRepository(
|
|
|
250
256
|
return Boolean(firstName && secondName && firstName.toLowerCase() === secondName.toLowerCase());
|
|
251
257
|
}
|
|
252
258
|
|
|
253
|
-
function githubAppGitAuthor(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
259
|
+
async function githubAppGitAuthor(
|
|
260
|
+
github: GithubApiClient,
|
|
261
|
+
installationAccessToken: string,
|
|
262
|
+
name: string,
|
|
263
|
+
): Promise<CheckoutSpec['gitAuthor']> {
|
|
264
|
+
if (!github.getBotUser) {
|
|
265
|
+
throw new GithubIntegrationProviderError(
|
|
266
|
+
'provider-unavailable',
|
|
267
|
+
'GitHub bot identity resolution is unavailable',
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const botUser = await github.getBotUser({username: name, installationAccessToken});
|
|
272
|
+
return {
|
|
273
|
+
name: botUser.login,
|
|
274
|
+
email: `${botUser.id}+${botUser.login}@users.noreply.github.com`,
|
|
275
|
+
};
|
|
260
276
|
}
|
|
261
277
|
|
|
262
278
|
function toRepositorySnapshot(repository: GithubRepository): RepositorySnapshot {
|