plugin-git-manager 1.2.27 → 1.2.28
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/README.md +133 -108
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +3 -3
- package/client.js +1 -1
- package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
- package/dist/client/900.a48beac7e2ebee7d.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
- package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
- package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
- package/dist/client-v2/900.e6155002a9c97e7f.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +307 -297
- package/dist/locale/vi-VN.json +295 -292
- package/dist/locale/zh-CN.json +61 -51
- package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/git-actions.js +90 -36
- package/dist/server/actions/gitlab-api.js +4 -2
- package/dist/server/actions/poller.js +5 -2
- package/dist/server/actions/review.js +20 -10
- package/dist/server/plugin.js +6 -4
- package/dist/server/poller.js +46 -45
- package/dist/server/request-method-policy.js +75 -0
- package/dist/server/services/registry-content-service.js +4 -3
- package/dist/server/utils/get-repo-account.js +3 -2
- package/dist/server/utils/url-security.js +24 -0
- package/package.json +61 -43
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +374 -374
- package/src/client/components/FileExplorer.tsx +386 -386
- package/src/client/components/GitAccounts.tsx +179 -179
- package/src/client/components/GitManagerSettings.tsx +160 -160
- package/src/client/components/GitOperations.tsx +220 -220
- package/src/client/components/LLMModelSelect.tsx +63 -63
- package/src/client/components/LLMServiceSelect.tsx +58 -58
- package/src/client/components/MarkdownView.tsx +80 -80
- package/src/client/components/MergeRequests.tsx +790 -790
- package/src/client/components/PollingStatus.tsx +225 -225
- package/src/client/components/RepositoryConfig.tsx +335 -335
- package/src/client/components/RepositoryPermissions.tsx +123 -123
- package/src/client/components/ReviewFlows.tsx +303 -303
- package/src/client/components/ReviewHistory.tsx +566 -566
- package/src/client/components/RunReviewButton.tsx +63 -55
- package/src/client/context/GitManagerContext.tsx +92 -92
- package/src/client/index.tsx +91 -82
- package/src/client/locale.ts +9 -9
- package/src/client/promptTemplates.ts +31 -31
- package/src/client-v2/ai-context.tsx +99 -0
- package/src/client-v2/components/SubtreeSplits.tsx +547 -547
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/locale.ts +8 -8
- package/src/client-v2/plugin.tsx +67 -39
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +307 -297
- package/src/locale/vi-VN.json +295 -292
- package/src/locale/zh-CN.json +61 -51
- package/src/server/__tests__/git-actions.test.ts +24 -24
- package/src/server/__tests__/git-security.test.ts +170 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -17
- package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
- package/src/server/__tests__/poller.test.ts +37 -37
- package/src/server/__tests__/repository-access.test.ts +752 -752
- package/src/server/__tests__/review.test.ts +137 -137
- package/src/server/__tests__/role-permissions.test.ts +147 -147
- package/src/server/__tests__/smoke.test.ts +139 -17
- package/src/server/__tests__/subtree.test.ts +85 -85
- package/src/server/actions/git-actions.ts +540 -480
- package/src/server/actions/gitlab-api.ts +422 -411
- package/src/server/actions/poller.ts +39 -27
- package/src/server/actions/review.ts +1388 -1369
- package/src/server/actions/role-permissions.ts +321 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +319 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +199 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewFlows.ts +108 -108
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +2 -2
- package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
- package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
- package/src/server/plugin.ts +372 -361
- package/src/server/poller.ts +351 -352
- package/src/server/repository-access.ts +773 -773
- package/src/server/request-method-policy.ts +55 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/registry-content-service.ts +495 -484
- package/src/server/utils/__tests__/redact.test.ts +56 -56
- package/src/server/utils/__tests__/url-security.test.ts +85 -85
- package/src/server/utils/get-repo-account.ts +51 -41
- package/src/server/utils/gitlab-url.ts +38 -38
- package/src/server/utils/redact.ts +87 -87
- package/src/server/utils/url-security.ts +128 -95
- package/dist/client/900.acf7d1fa22f95e71.js +0 -10
- package/dist/client-v2/434.7a27051db18526c0.js +0 -10
- package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { isGitManagerResourceResponse, REDACTED_PAT, redactCredentialFields } from '../redact';
|
|
3
|
-
|
|
4
|
-
describe('Git Manager credential response redaction', () => {
|
|
5
|
-
it('redacts PATs recursively through nested associations and dataValues', () => {
|
|
6
|
-
const response = {
|
|
7
|
-
data: [
|
|
8
|
-
{
|
|
9
|
-
gitAccount: {
|
|
10
|
-
pat: 'top-level-secret',
|
|
11
|
-
dataValues: { pat: 'top-level-data-values-secret' },
|
|
12
|
-
},
|
|
13
|
-
dataValues: {
|
|
14
|
-
gitAccount: {
|
|
15
|
-
pat: 'nested-secret',
|
|
16
|
-
dataValues: { pat: 'nested-data-values-secret' },
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
redactCredentialFields(response);
|
|
24
|
-
|
|
25
|
-
expect(response.data[0].gitAccount.pat).toBe(REDACTED_PAT);
|
|
26
|
-
expect(response.data[0].gitAccount.dataValues.pat).toBe(REDACTED_PAT);
|
|
27
|
-
expect(response.data[0].dataValues.gitAccount.pat).toBe(REDACTED_PAT);
|
|
28
|
-
expect(response.data[0].dataValues.gitAccount.dataValues.pat).toBe(REDACTED_PAT);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('handles circular response objects without leaving a PAT exposed', () => {
|
|
32
|
-
const response: { pat: string; self?: unknown } = { pat: 'secret' };
|
|
33
|
-
response.self = response;
|
|
34
|
-
|
|
35
|
-
redactCredentialFields(response);
|
|
36
|
-
|
|
37
|
-
expect(response.pat).toBe(REDACTED_PAT);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it.each([
|
|
41
|
-
'gitManager',
|
|
42
|
-
'gitRepositories',
|
|
43
|
-
'gitReviewFlows',
|
|
44
|
-
'gitCodeReviews',
|
|
45
|
-
'gitSubtreeConfigs',
|
|
46
|
-
'gitSubtreeRuns',
|
|
47
|
-
'gitAccounts.1.repositories',
|
|
48
|
-
'gitRepositories.10.gitAccount',
|
|
49
|
-
])('recognizes nested Git Manager response route %s', (resourceName) => {
|
|
50
|
-
expect(isGitManagerResourceResponse(resourceName)).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('does not scrub unrelated resource responses', () => {
|
|
54
|
-
expect(isGitManagerResourceResponse('users')).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { isGitManagerResourceResponse, REDACTED_PAT, redactCredentialFields } from '../redact';
|
|
3
|
+
|
|
4
|
+
describe('Git Manager credential response redaction', () => {
|
|
5
|
+
it('redacts PATs recursively through nested associations and dataValues', () => {
|
|
6
|
+
const response = {
|
|
7
|
+
data: [
|
|
8
|
+
{
|
|
9
|
+
gitAccount: {
|
|
10
|
+
pat: 'top-level-secret',
|
|
11
|
+
dataValues: { pat: 'top-level-data-values-secret' },
|
|
12
|
+
},
|
|
13
|
+
dataValues: {
|
|
14
|
+
gitAccount: {
|
|
15
|
+
pat: 'nested-secret',
|
|
16
|
+
dataValues: { pat: 'nested-data-values-secret' },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
redactCredentialFields(response);
|
|
24
|
+
|
|
25
|
+
expect(response.data[0].gitAccount.pat).toBe(REDACTED_PAT);
|
|
26
|
+
expect(response.data[0].gitAccount.dataValues.pat).toBe(REDACTED_PAT);
|
|
27
|
+
expect(response.data[0].dataValues.gitAccount.pat).toBe(REDACTED_PAT);
|
|
28
|
+
expect(response.data[0].dataValues.gitAccount.dataValues.pat).toBe(REDACTED_PAT);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('handles circular response objects without leaving a PAT exposed', () => {
|
|
32
|
+
const response: { pat: string; self?: unknown } = { pat: 'secret' };
|
|
33
|
+
response.self = response;
|
|
34
|
+
|
|
35
|
+
redactCredentialFields(response);
|
|
36
|
+
|
|
37
|
+
expect(response.pat).toBe(REDACTED_PAT);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it.each([
|
|
41
|
+
'gitManager',
|
|
42
|
+
'gitRepositories',
|
|
43
|
+
'gitReviewFlows',
|
|
44
|
+
'gitCodeReviews',
|
|
45
|
+
'gitSubtreeConfigs',
|
|
46
|
+
'gitSubtreeRuns',
|
|
47
|
+
'gitAccounts.1.repositories',
|
|
48
|
+
'gitRepositories.10.gitAccount',
|
|
49
|
+
])('recognizes nested Git Manager response route %s', (resourceName) => {
|
|
50
|
+
expect(isGitManagerResourceResponse(resourceName)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('does not scrub unrelated resource responses', () => {
|
|
54
|
+
expect(isGitManagerResourceResponse('users')).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { validateRepoUrl } from '../../actions/git-actions';
|
|
4
|
-
import { parseGitLabProject } from '../gitlab-url';
|
|
5
|
-
import { redactCredentialFields } from '../redact';
|
|
6
|
-
import {
|
|
7
|
-
assertUrlHasNoUserInfo,
|
|
8
|
-
containsCredentialBearingUrlField,
|
|
9
|
-
hasUrlUserInfo,
|
|
10
|
-
redactUrlUserInfo,
|
|
11
|
-
URL_USERINFO_NOT_ALLOWED,
|
|
12
|
-
} from '../url-security';
|
|
13
|
-
|
|
14
|
-
const CREDENTIAL_URL = 'https://user:secret@example.test/group/repository.git';
|
|
15
|
-
const USERNAME_ONLY_URL = 'https://user@example.test/group/repository.git';
|
|
16
|
-
const REPOSITORY_URL_FIELDS = new Set(['repoUrl']);
|
|
17
|
-
const ACCOUNT_URL_FIELDS = new Set(['baseUrl']);
|
|
18
|
-
const GIT_CONFIGURATION_URL_FIELDS = new Set(['repoUrl', 'baseUrl']);
|
|
19
|
-
|
|
20
|
-
describe('Git Manager URL credential security', () => {
|
|
21
|
-
it('rejects URLs with a username or password', () => {
|
|
22
|
-
expect(hasUrlUserInfo(CREDENTIAL_URL)).toBe(true);
|
|
23
|
-
expect(hasUrlUserInfo(USERNAME_ONLY_URL)).toBe(true);
|
|
24
|
-
expect(() => assertUrlHasNoUserInfo(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
25
|
-
expect(() => assertUrlHasNoUserInfo(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it.each([
|
|
29
|
-
['direct repository URL', { repoUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
|
|
30
|
-
['dotted repository URL', { 'values.repoUrl': CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
|
|
31
|
-
['bracket account URL', { 'values[baseUrl]': USERNAME_ONLY_URL }, ACCOUNT_URL_FIELDS],
|
|
32
|
-
['nested account URL', { values: { updateAssociationValues: { baseUrl: CREDENTIAL_URL } } }, ACCOUNT_URL_FIELDS],
|
|
33
|
-
[
|
|
34
|
-
'repository association account URL',
|
|
35
|
-
{ values: { gitAccount: { baseUrl: CREDENTIAL_URL } } },
|
|
36
|
-
GIT_CONFIGURATION_URL_FIELDS,
|
|
37
|
-
],
|
|
38
|
-
[
|
|
39
|
-
'account association repository URL',
|
|
40
|
-
{ values: { repositories: [{ repoUrl: CREDENTIAL_URL }] } },
|
|
41
|
-
GIT_CONFIGURATION_URL_FIELDS,
|
|
42
|
-
],
|
|
43
|
-
['serialized query values', JSON.stringify({ values: { repoUrl: CREDENTIAL_URL } }), REPOSITORY_URL_FIELDS],
|
|
44
|
-
])('finds a credential-bearing URL in %s', (_source, value, fields) => {
|
|
45
|
-
expect(containsCredentialBearingUrlField(value, fields)).toBe(true);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('allows clean URLs and ignores other field names', () => {
|
|
49
|
-
expect(
|
|
50
|
-
containsCredentialBearingUrlField(
|
|
51
|
-
{ values: { repoUrl: 'https://example.test/group/repository.git' } },
|
|
52
|
-
REPOSITORY_URL_FIELDS,
|
|
53
|
-
),
|
|
54
|
-
).toBe(false);
|
|
55
|
-
expect(containsCredentialBearingUrlField({ otherUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS)).toBe(false);
|
|
56
|
-
expect(() => validateRepoUrl('https://example.test/group/repository.git')).not.toThrow();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('rejects credential-bearing URLs in Git entry points', () => {
|
|
60
|
-
expect(() => validateRepoUrl(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
61
|
-
expect(() => parseGitLabProject(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('redacts userinfo from nested repository and account responses', () => {
|
|
65
|
-
const response = {
|
|
66
|
-
data: {
|
|
67
|
-
repoUrl: CREDENTIAL_URL,
|
|
68
|
-
gitAccount: {
|
|
69
|
-
baseUrl: USERNAME_ONLY_URL,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
redactCredentialFields(response);
|
|
75
|
-
|
|
76
|
-
expect(response.data.repoUrl).toBe('https://***:***@example.test/group/repository.git');
|
|
77
|
-
expect(response.data.gitAccount.baseUrl).toBe('https://***:***@example.test/group/repository.git');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('does not leak a password segment when legacy userinfo contains another at sign', () => {
|
|
81
|
-
expect(redactUrlUserInfo('https://user:secret@still-secret@example.test/repository.git')).toBe(
|
|
82
|
-
'https://***:***@example.test/repository.git',
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { validateRepoUrl } from '../../actions/git-actions';
|
|
4
|
+
import { parseGitLabProject } from '../gitlab-url';
|
|
5
|
+
import { redactCredentialFields } from '../redact';
|
|
6
|
+
import {
|
|
7
|
+
assertUrlHasNoUserInfo,
|
|
8
|
+
containsCredentialBearingUrlField,
|
|
9
|
+
hasUrlUserInfo,
|
|
10
|
+
redactUrlUserInfo,
|
|
11
|
+
URL_USERINFO_NOT_ALLOWED,
|
|
12
|
+
} from '../url-security';
|
|
13
|
+
|
|
14
|
+
const CREDENTIAL_URL = 'https://user:secret@example.test/group/repository.git';
|
|
15
|
+
const USERNAME_ONLY_URL = 'https://user@example.test/group/repository.git';
|
|
16
|
+
const REPOSITORY_URL_FIELDS = new Set(['repoUrl']);
|
|
17
|
+
const ACCOUNT_URL_FIELDS = new Set(['baseUrl']);
|
|
18
|
+
const GIT_CONFIGURATION_URL_FIELDS = new Set(['repoUrl', 'baseUrl']);
|
|
19
|
+
|
|
20
|
+
describe('Git Manager URL credential security', () => {
|
|
21
|
+
it('rejects URLs with a username or password', () => {
|
|
22
|
+
expect(hasUrlUserInfo(CREDENTIAL_URL)).toBe(true);
|
|
23
|
+
expect(hasUrlUserInfo(USERNAME_ONLY_URL)).toBe(true);
|
|
24
|
+
expect(() => assertUrlHasNoUserInfo(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
25
|
+
expect(() => assertUrlHasNoUserInfo(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it.each([
|
|
29
|
+
['direct repository URL', { repoUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
|
|
30
|
+
['dotted repository URL', { 'values.repoUrl': CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
|
|
31
|
+
['bracket account URL', { 'values[baseUrl]': USERNAME_ONLY_URL }, ACCOUNT_URL_FIELDS],
|
|
32
|
+
['nested account URL', { values: { updateAssociationValues: { baseUrl: CREDENTIAL_URL } } }, ACCOUNT_URL_FIELDS],
|
|
33
|
+
[
|
|
34
|
+
'repository association account URL',
|
|
35
|
+
{ values: { gitAccount: { baseUrl: CREDENTIAL_URL } } },
|
|
36
|
+
GIT_CONFIGURATION_URL_FIELDS,
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
'account association repository URL',
|
|
40
|
+
{ values: { repositories: [{ repoUrl: CREDENTIAL_URL }] } },
|
|
41
|
+
GIT_CONFIGURATION_URL_FIELDS,
|
|
42
|
+
],
|
|
43
|
+
['serialized query values', JSON.stringify({ values: { repoUrl: CREDENTIAL_URL } }), REPOSITORY_URL_FIELDS],
|
|
44
|
+
])('finds a credential-bearing URL in %s', (_source, value, fields) => {
|
|
45
|
+
expect(containsCredentialBearingUrlField(value, fields)).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('allows clean URLs and ignores other field names', () => {
|
|
49
|
+
expect(
|
|
50
|
+
containsCredentialBearingUrlField(
|
|
51
|
+
{ values: { repoUrl: 'https://example.test/group/repository.git' } },
|
|
52
|
+
REPOSITORY_URL_FIELDS,
|
|
53
|
+
),
|
|
54
|
+
).toBe(false);
|
|
55
|
+
expect(containsCredentialBearingUrlField({ otherUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS)).toBe(false);
|
|
56
|
+
expect(() => validateRepoUrl('https://example.test/group/repository.git')).not.toThrow();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('rejects credential-bearing URLs in Git entry points', () => {
|
|
60
|
+
expect(() => validateRepoUrl(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
61
|
+
expect(() => parseGitLabProject(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('redacts userinfo from nested repository and account responses', () => {
|
|
65
|
+
const response = {
|
|
66
|
+
data: {
|
|
67
|
+
repoUrl: CREDENTIAL_URL,
|
|
68
|
+
gitAccount: {
|
|
69
|
+
baseUrl: USERNAME_ONLY_URL,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
redactCredentialFields(response);
|
|
75
|
+
|
|
76
|
+
expect(response.data.repoUrl).toBe('https://***:***@example.test/group/repository.git');
|
|
77
|
+
expect(response.data.gitAccount.baseUrl).toBe('https://***:***@example.test/group/repository.git');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('does not leak a password segment when legacy userinfo contains another at sign', () => {
|
|
81
|
+
expect(redactUrlUserInfo('https://user:secret@still-secret@example.test/repository.git')).toBe(
|
|
82
|
+
'https://***:***@example.test/repository.git',
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -1,41 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { assertAccountRepositoryUrl } from './url-security';
|
|
11
|
+
|
|
12
|
+
export interface GitAccountCredentials {
|
|
13
|
+
pat: string;
|
|
14
|
+
username: string;
|
|
15
|
+
baseUrl: string | null;
|
|
16
|
+
provider: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type RecordGetter = {
|
|
20
|
+
get(attribute: string): unknown;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type GitAccountDatabase = {
|
|
24
|
+
getRepository(name: 'gitAccounts'): {
|
|
25
|
+
findOne(input: { filterByTk: number | string }): Promise<RecordGetter | null>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export async function getRepoAccount(
|
|
30
|
+
db: GitAccountDatabase,
|
|
31
|
+
repo: RecordGetter,
|
|
32
|
+
): Promise<GitAccountCredentials | null> {
|
|
33
|
+
const gitAccountId = repo.get('gitAccountId');
|
|
34
|
+
if (typeof gitAccountId !== 'number' && typeof gitAccountId !== 'string') return null;
|
|
35
|
+
|
|
36
|
+
const account = await db.getRepository('gitAccounts').findOne({
|
|
37
|
+
filterByTk: gitAccountId,
|
|
38
|
+
});
|
|
39
|
+
if (!account) return null;
|
|
40
|
+
|
|
41
|
+
const baseUrl = ((account.get('baseUrl') as string) || '').trim() || null;
|
|
42
|
+
const provider = ((account.get('provider') as string) || 'gitlab').trim();
|
|
43
|
+
assertAccountRepositoryUrl(String(repo.get('repoUrl') || ''), baseUrl, provider);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
pat: ((account.get('pat') as string) || '').trim(),
|
|
47
|
+
username: ((account.get('username') as string) || '').trim(),
|
|
48
|
+
baseUrl,
|
|
49
|
+
provider,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { assertUrlHasNoUserInfo } from './url-security';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shared utility for parsing GitLab repository URLs.
|
|
5
|
-
* Extracted to avoid duplicating URL-parsing logic across
|
|
6
|
-
* gitlab-api.ts, poller.ts, and review.ts.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export interface GitLabProject {
|
|
10
|
-
/** Full API base URL, e.g. https://gitlab.com/api/v4 */
|
|
11
|
-
apiBase: string;
|
|
12
|
-
/** Raw project path, e.g. group/sub/project */
|
|
13
|
-
projectPath: string;
|
|
14
|
-
/** URL-encoded project path for use in API endpoints */
|
|
15
|
-
encodedProject: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Extract GitLab API base URL and project path from a repository URL.
|
|
20
|
-
* Supports: https://gitlab.com/group/project.git
|
|
21
|
-
* https://self-hosted.gitlab.com/group/sub/project.git
|
|
22
|
-
*
|
|
23
|
-
* @throws Error if the URL cannot be parsed or has no project path
|
|
24
|
-
*/
|
|
25
|
-
export function parseGitLabProject(repoUrl: string): GitLabProject {
|
|
26
|
-
assertUrlHasNoUserInfo(repoUrl);
|
|
27
|
-
const url = new URL(repoUrl);
|
|
28
|
-
// Remove .git suffix and leading slash
|
|
29
|
-
const projectPath = url.pathname.replace(/\.git$/, '').replace(/^\//, '');
|
|
30
|
-
if (!projectPath) {
|
|
31
|
-
throw new Error('Cannot extract project path from repository URL');
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
apiBase: `${url.protocol}//${url.host}/api/v4`,
|
|
35
|
-
projectPath,
|
|
36
|
-
encodedProject: encodeURIComponent(projectPath),
|
|
37
|
-
};
|
|
38
|
-
}
|
|
1
|
+
import { assertUrlHasNoUserInfo } from './url-security';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared utility for parsing GitLab repository URLs.
|
|
5
|
+
* Extracted to avoid duplicating URL-parsing logic across
|
|
6
|
+
* gitlab-api.ts, poller.ts, and review.ts.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface GitLabProject {
|
|
10
|
+
/** Full API base URL, e.g. https://gitlab.com/api/v4 */
|
|
11
|
+
apiBase: string;
|
|
12
|
+
/** Raw project path, e.g. group/sub/project */
|
|
13
|
+
projectPath: string;
|
|
14
|
+
/** URL-encoded project path for use in API endpoints */
|
|
15
|
+
encodedProject: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Extract GitLab API base URL and project path from a repository URL.
|
|
20
|
+
* Supports: https://gitlab.com/group/project.git
|
|
21
|
+
* https://self-hosted.gitlab.com/group/sub/project.git
|
|
22
|
+
*
|
|
23
|
+
* @throws Error if the URL cannot be parsed or has no project path
|
|
24
|
+
*/
|
|
25
|
+
export function parseGitLabProject(repoUrl: string): GitLabProject {
|
|
26
|
+
assertUrlHasNoUserInfo(repoUrl);
|
|
27
|
+
const url = new URL(repoUrl);
|
|
28
|
+
// Remove .git suffix and leading slash
|
|
29
|
+
const projectPath = url.pathname.replace(/\.git$/, '').replace(/^\//, '');
|
|
30
|
+
if (!projectPath) {
|
|
31
|
+
throw new Error('Cannot extract project path from repository URL');
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
apiBase: `${url.protocol}//${url.host}/api/v4`,
|
|
35
|
+
projectPath,
|
|
36
|
+
encodedProject: encodeURIComponent(projectPath),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import { redactUrlUserInfo } from './url-security';
|
|
2
|
-
|
|
3
|
-
export const REDACTED_PAT = '••••••••';
|
|
4
|
-
|
|
5
|
-
const GIT_MANAGER_RESOURCE_SEGMENTS = new Set([
|
|
6
|
-
'gitManager',
|
|
7
|
-
'gitRepositories',
|
|
8
|
-
'gitAccounts',
|
|
9
|
-
'gitReviewFlows',
|
|
10
|
-
'gitCodeReviews',
|
|
11
|
-
'gitSubtreeConfigs',
|
|
12
|
-
'gitSubtreeRuns',
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Association routes use names such as `gitAccounts.1.repositories`, not the
|
|
17
|
-
* raw collection name. Redact every Git Manager resource response so those
|
|
18
|
-
* routes cannot bypass credential scrubbing merely because their name is
|
|
19
|
-
* nested.
|
|
20
|
-
*/
|
|
21
|
-
export function isGitManagerResourceResponse(resourceName: unknown): boolean {
|
|
22
|
-
return (
|
|
23
|
-
typeof resourceName === 'string' &&
|
|
24
|
-
resourceName.split(/[.[\],:/()=\s]+/).some((segment) => GIT_MANAGER_RESOURCE_SEGMENTS.has(segment))
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Redact embedded credentials from URLs in arbitrary strings.
|
|
30
|
-
* Matches `scheme://user:password@host` and replaces with `scheme://***:***@host`.
|
|
31
|
-
* Used to scrub error messages before persisting them to the DB or
|
|
32
|
-
* returning them to the client, since simple-git often echoes the
|
|
33
|
-
* authenticated remote URL in stderr.
|
|
34
|
-
*/
|
|
35
|
-
export function redactPat(s: unknown): string {
|
|
36
|
-
if (typeof s !== 'string') return s == null ? '' : String(s);
|
|
37
|
-
return redactUrlUserInfo(s);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Mutate `err.message` (and common fields where simple-git stashes stderr)
|
|
42
|
-
* to remove any embedded PAT before the error propagates further.
|
|
43
|
-
*/
|
|
44
|
-
export function redactError<T>(err: T): T {
|
|
45
|
-
if (!err || typeof err !== 'object') return err;
|
|
46
|
-
const error = err as { message?: unknown; stderr?: unknown; stdout?: unknown };
|
|
47
|
-
if (typeof error.message === 'string') error.message = redactPat(error.message);
|
|
48
|
-
if (typeof error.stderr === 'string') error.stderr = redactPat(error.stderr);
|
|
49
|
-
if (typeof error.stdout === 'string') error.stdout = redactPat(error.stdout);
|
|
50
|
-
return err;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Redact PAT fields anywhere in a serializable API response. Repository
|
|
55
|
-
* responses can contain a nested `gitAccount` (and Sequelize's nested
|
|
56
|
-
* `dataValues`), so a shallow top-level scrub is not sufficient.
|
|
57
|
-
*/
|
|
58
|
-
export function redactCredentialFields(value: unknown): void {
|
|
59
|
-
const visited = new WeakSet<object>();
|
|
60
|
-
|
|
61
|
-
const visit = (current: unknown): void => {
|
|
62
|
-
if (!current || typeof current !== 'object' || visited.has(current)) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
visited.add(current);
|
|
66
|
-
|
|
67
|
-
if (Array.isArray(current)) {
|
|
68
|
-
current.forEach(visit);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const record = current as Record<string, unknown>;
|
|
73
|
-
for (const [key, nestedValue] of Object.entries(record)) {
|
|
74
|
-
if (key === 'pat') {
|
|
75
|
-
record[key] = REDACTED_PAT;
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if ((key === 'repoUrl' || key === 'baseUrl') && typeof nestedValue === 'string') {
|
|
79
|
-
record[key] = redactUrlUserInfo(nestedValue);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
visit(nestedValue);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
visit(value);
|
|
87
|
-
}
|
|
1
|
+
import { redactUrlUserInfo } from './url-security';
|
|
2
|
+
|
|
3
|
+
export const REDACTED_PAT = '••••••••';
|
|
4
|
+
|
|
5
|
+
const GIT_MANAGER_RESOURCE_SEGMENTS = new Set([
|
|
6
|
+
'gitManager',
|
|
7
|
+
'gitRepositories',
|
|
8
|
+
'gitAccounts',
|
|
9
|
+
'gitReviewFlows',
|
|
10
|
+
'gitCodeReviews',
|
|
11
|
+
'gitSubtreeConfigs',
|
|
12
|
+
'gitSubtreeRuns',
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Association routes use names such as `gitAccounts.1.repositories`, not the
|
|
17
|
+
* raw collection name. Redact every Git Manager resource response so those
|
|
18
|
+
* routes cannot bypass credential scrubbing merely because their name is
|
|
19
|
+
* nested.
|
|
20
|
+
*/
|
|
21
|
+
export function isGitManagerResourceResponse(resourceName: unknown): boolean {
|
|
22
|
+
return (
|
|
23
|
+
typeof resourceName === 'string' &&
|
|
24
|
+
resourceName.split(/[.[\],:/()=\s]+/).some((segment) => GIT_MANAGER_RESOURCE_SEGMENTS.has(segment))
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Redact embedded credentials from URLs in arbitrary strings.
|
|
30
|
+
* Matches `scheme://user:password@host` and replaces with `scheme://***:***@host`.
|
|
31
|
+
* Used to scrub error messages before persisting them to the DB or
|
|
32
|
+
* returning them to the client, since simple-git often echoes the
|
|
33
|
+
* authenticated remote URL in stderr.
|
|
34
|
+
*/
|
|
35
|
+
export function redactPat(s: unknown): string {
|
|
36
|
+
if (typeof s !== 'string') return s == null ? '' : String(s);
|
|
37
|
+
return redactUrlUserInfo(s);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Mutate `err.message` (and common fields where simple-git stashes stderr)
|
|
42
|
+
* to remove any embedded PAT before the error propagates further.
|
|
43
|
+
*/
|
|
44
|
+
export function redactError<T>(err: T): T {
|
|
45
|
+
if (!err || typeof err !== 'object') return err;
|
|
46
|
+
const error = err as { message?: unknown; stderr?: unknown; stdout?: unknown };
|
|
47
|
+
if (typeof error.message === 'string') error.message = redactPat(error.message);
|
|
48
|
+
if (typeof error.stderr === 'string') error.stderr = redactPat(error.stderr);
|
|
49
|
+
if (typeof error.stdout === 'string') error.stdout = redactPat(error.stdout);
|
|
50
|
+
return err;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Redact PAT fields anywhere in a serializable API response. Repository
|
|
55
|
+
* responses can contain a nested `gitAccount` (and Sequelize's nested
|
|
56
|
+
* `dataValues`), so a shallow top-level scrub is not sufficient.
|
|
57
|
+
*/
|
|
58
|
+
export function redactCredentialFields(value: unknown): void {
|
|
59
|
+
const visited = new WeakSet<object>();
|
|
60
|
+
|
|
61
|
+
const visit = (current: unknown): void => {
|
|
62
|
+
if (!current || typeof current !== 'object' || visited.has(current)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
visited.add(current);
|
|
66
|
+
|
|
67
|
+
if (Array.isArray(current)) {
|
|
68
|
+
current.forEach(visit);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const record = current as Record<string, unknown>;
|
|
73
|
+
for (const [key, nestedValue] of Object.entries(record)) {
|
|
74
|
+
if (key === 'pat') {
|
|
75
|
+
record[key] = REDACTED_PAT;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if ((key === 'repoUrl' || key === 'baseUrl') && typeof nestedValue === 'string') {
|
|
79
|
+
record[key] = redactUrlUserInfo(nestedValue);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
visit(nestedValue);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
visit(value);
|
|
87
|
+
}
|