@backstage/integration 1.20.0 → 2.0.0-next.1
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/CHANGELOG.md +30 -0
- package/config.d.ts +25 -60
- package/dist/ScmIntegrations.cjs.js +1 -17
- package/dist/ScmIntegrations.cjs.js.map +1 -1
- package/dist/ScmIntegrations.esm.js +1 -17
- package/dist/ScmIntegrations.esm.js.map +1 -1
- package/dist/azure/config.cjs.js +14 -35
- package/dist/azure/config.cjs.js.map +1 -1
- package/dist/azure/config.esm.js +14 -35
- package/dist/azure/config.esm.js.map +1 -1
- package/dist/gerrit/core.cjs.js +6 -33
- package/dist/gerrit/core.cjs.js.map +1 -1
- package/dist/gerrit/core.esm.js +7 -32
- package/dist/gerrit/core.esm.js.map +1 -1
- package/dist/github/core.cjs.js +0 -11
- package/dist/github/core.cjs.js.map +1 -1
- package/dist/github/core.esm.js +1 -11
- package/dist/github/core.esm.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.cjs.js +69 -0
- package/dist/gitlab/GitLabIntegration.cjs.js.map +1 -1
- package/dist/gitlab/GitLabIntegration.esm.js +65 -1
- package/dist/gitlab/GitLabIntegration.esm.js.map +1 -1
- package/dist/gitlab/config.cjs.js +27 -1
- package/dist/gitlab/config.cjs.js.map +1 -1
- package/dist/gitlab/config.esm.js +27 -1
- package/dist/gitlab/config.esm.js.map +1 -1
- package/dist/gitlab/core.cjs.js +14 -42
- package/dist/gitlab/core.cjs.js.map +1 -1
- package/dist/gitlab/core.esm.js +14 -38
- package/dist/gitlab/core.esm.js.map +1 -1
- package/dist/index.cjs.js +61 -76
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +30 -225
- package/dist/index.esm.js +2 -6
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -6
- package/dist/azure/deprecated.cjs.js +0 -26
- package/dist/azure/deprecated.cjs.js.map +0 -1
- package/dist/azure/deprecated.esm.js +0 -24
- package/dist/azure/deprecated.esm.js.map +0 -1
- package/dist/bitbucket/BitbucketIntegration.cjs.js +0 -65
- package/dist/bitbucket/BitbucketIntegration.cjs.js.map +0 -1
- package/dist/bitbucket/BitbucketIntegration.esm.js +0 -59
- package/dist/bitbucket/BitbucketIntegration.esm.js.map +0 -1
- package/dist/bitbucket/config.cjs.js +0 -48
- package/dist/bitbucket/config.cjs.js.map +0 -1
- package/dist/bitbucket/config.esm.js +0 -45
- package/dist/bitbucket/config.esm.js.map +0 -1
- package/dist/bitbucket/core.cjs.js +0 -95
- package/dist/bitbucket/core.cjs.js.map +0 -1
- package/dist/bitbucket/core.esm.js +0 -85
- package/dist/bitbucket/core.esm.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitLabIntegration.cjs.js","sources":["../../src/gitlab/GitLabIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\
|
|
1
|
+
{"version":3,"file":"GitLabIntegration.cjs.js","sources":["../../src/gitlab/GitLabIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\nimport pThrottle from 'p-throttle';\n\ntype FetchFunction = typeof fetch;\n\n/**\n * A GitLab based integration.\n *\n * @public\n */\nexport class GitLabIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GitLabIntegration> = ({ config }) => {\n const configs = readGitLabIntegrationConfigs(\n config.getOptionalConfigArray('integrations.gitlab') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GitLabIntegration(c)),\n i => i.config.host,\n );\n };\n\n private readonly fetchImpl: FetchFunction;\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {\n // Configure fetch strategy based on configuration\n this.fetchImpl = this.createFetchStrategy();\n }\n\n get type(): string {\n return 'gitlab';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GitLabIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return replaceGitLabUrlType(url, 'edit');\n }\n\n fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n return this.fetchImpl(input, init);\n }\n\n private createFetchStrategy(): FetchFunction {\n let fetchFn: FetchFunction = async (url, options) => {\n return fetch(url, { ...options, mode: 'same-origin' });\n };\n\n const retryConfig = this.integrationConfig.retry;\n if (retryConfig) {\n // Apply retry wrapper if configured\n fetchFn = this.withRetry(fetchFn, retryConfig);\n\n // Apply throttling wrapper if configured\n if (\n retryConfig.maxApiRequestsPerMinute &&\n retryConfig.maxApiRequestsPerMinute > 0\n ) {\n fetchFn = pThrottle({\n limit: retryConfig.maxApiRequestsPerMinute,\n interval: 60_000,\n })(fetchFn);\n }\n }\n\n return fetchFn;\n }\n\n private withRetry(\n fetchFn: FetchFunction,\n retryConfig: { maxRetries?: number; retryStatusCodes?: number[] },\n ): FetchFunction {\n const maxRetries = retryConfig?.maxRetries ?? 0;\n const retryStatusCodes = retryConfig?.retryStatusCodes ?? [];\n if (maxRetries <= 0 || retryStatusCodes.length === 0) {\n return fetchFn;\n }\n\n return async (url, options) => {\n const abortSignal = options?.signal;\n let response: Response;\n let attempt = 0;\n for (;;) {\n response = await fetchFn(url, options);\n // If response is not retryable, return immediately\n if (!retryStatusCodes.includes(response.status)) {\n break;\n }\n\n // If this was the last allowed attempt, return response\n if (attempt++ >= maxRetries) {\n break;\n }\n // Determine delay from Retry-After header if present, otherwise exponential backoff\n const retryAfter = response.headers.get('Retry-After');\n const delay = retryAfter\n ? parseInt(retryAfter, 10) * 1000\n : Math.min(100 * Math.pow(2, attempt - 1), 10000); // Exponential backoff, cap at 10 seconds\n\n await sleep(delay, abortSignal);\n }\n\n return response;\n };\n }\n}\n\nexport async function sleep(\n durationMs: number,\n abortSignal: AbortSignal | null | undefined,\n): Promise<void> {\n if (abortSignal?.aborted) {\n return;\n }\n\n await new Promise<void>(resolve => {\n let timeoutHandle: NodeJS.Timeout | undefined = undefined;\n\n const done = () => {\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n abortSignal?.removeEventListener('abort', done);\n resolve();\n };\n\n timeoutHandle = setTimeout(done, durationMs);\n abortSignal?.addEventListener('abort', done);\n });\n}\n\n/**\n * Takes a GitLab URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. 'blob', 'tree', 'edit'\n * @public\n */\nexport function replaceGitLabUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(/\\/\\-\\/(blob|tree|edit)\\//, `/-/${type}/`);\n}\n"],"names":["config","readGitLabIntegrationConfigs","basicIntegrations","defaultScmResolveUrl","pThrottle"],"mappings":";;;;;;;;;;AA8BO,MAAM,iBAAA,CAA4C;AAAA,EAavD,YAA6B,iBAAA,EAA4C;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAE3B,IAAA,IAAA,CAAK,SA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,EAAG,OAAA,GAAU,CAAC,GAAG,GAAK,CAAA;AAElD,QAAA,MAAM,KAAA,CAAM,OAAO,WAAW,CAAA;AAAA,MAChC;AAEA,MAAA,OAAO,QAAA;AAAA,IACT,CAAA;AAAA,EACF;AACF;AAEA,eAAsB,KAAA,CACpB,YACA,WAAA,EACe;AACf,EAAA,IAAI,aAAa,OAAA,EAAS;AACxB,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,IAAI,QAAc,CAAA,OAAA,KAAW;AACjC,IAAA,IAAI,aAAA,GAA4C,MAAA;AAEhD,IAAA,MAAM,OAAO,MAAM;AACjB,MAAA,IAAI,aAAA,EAAe;AACjB,QAAA,YAAA,CAAa,aAAa,CAAA;AAAA,MAC5B;AACA,MAAA,WAAA,EAAa,mBAAA,CAAoB,SAAS,IAAI,CAAA;AAC9C,MAAA,OAAA,EAAQ;AAAA,IACV,CAAA;AAEA,IAAA,aAAA,GAAgB,UAAA,CAAW,MAAM,UAAU,CAAA;AAC3C,IAAA,WAAA,EAAa,gBAAA,CAAiB,SAAS,IAAI,CAAA;AAAA,EAC7C,CAAC,CAAA;AACH;AASO,SAAS,oBAAA,CACd,KACA,IAAA,EACQ;AACR,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,0BAAA,EAA4B,CAAA,GAAA,EAAM,IAAI,CAAA,CAAA,CAAG,CAAA;AAC9D;;;;;;"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { basicIntegrations, defaultScmResolveUrl } from '../helpers.esm.js';
|
|
2
2
|
import { readGitLabIntegrationConfigs } from './config.esm.js';
|
|
3
|
+
import pThrottle from 'p-throttle';
|
|
3
4
|
|
|
4
5
|
class GitLabIntegration {
|
|
5
6
|
constructor(integrationConfig) {
|
|
6
7
|
this.integrationConfig = integrationConfig;
|
|
8
|
+
this.fetchImpl = this.createFetchStrategy();
|
|
7
9
|
}
|
|
8
10
|
static factory = ({ config }) => {
|
|
9
11
|
const configs = readGitLabIntegrationConfigs(
|
|
@@ -14,6 +16,7 @@ class GitLabIntegration {
|
|
|
14
16
|
(i) => i.config.host
|
|
15
17
|
);
|
|
16
18
|
};
|
|
19
|
+
fetchImpl;
|
|
17
20
|
get type() {
|
|
18
21
|
return "gitlab";
|
|
19
22
|
}
|
|
@@ -29,10 +32,71 @@ class GitLabIntegration {
|
|
|
29
32
|
resolveEditUrl(url) {
|
|
30
33
|
return replaceGitLabUrlType(url, "edit");
|
|
31
34
|
}
|
|
35
|
+
fetch(input, init) {
|
|
36
|
+
return this.fetchImpl(input, init);
|
|
37
|
+
}
|
|
38
|
+
createFetchStrategy() {
|
|
39
|
+
let fetchFn = async (url, options) => {
|
|
40
|
+
return fetch(url, { ...options, mode: "same-origin" });
|
|
41
|
+
};
|
|
42
|
+
const retryConfig = this.integrationConfig.retry;
|
|
43
|
+
if (retryConfig) {
|
|
44
|
+
fetchFn = this.withRetry(fetchFn, retryConfig);
|
|
45
|
+
if (retryConfig.maxApiRequestsPerMinute && retryConfig.maxApiRequestsPerMinute > 0) {
|
|
46
|
+
fetchFn = pThrottle({
|
|
47
|
+
limit: retryConfig.maxApiRequestsPerMinute,
|
|
48
|
+
interval: 6e4
|
|
49
|
+
})(fetchFn);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return fetchFn;
|
|
53
|
+
}
|
|
54
|
+
withRetry(fetchFn, retryConfig) {
|
|
55
|
+
const maxRetries = retryConfig?.maxRetries ?? 0;
|
|
56
|
+
const retryStatusCodes = retryConfig?.retryStatusCodes ?? [];
|
|
57
|
+
if (maxRetries <= 0 || retryStatusCodes.length === 0) {
|
|
58
|
+
return fetchFn;
|
|
59
|
+
}
|
|
60
|
+
return async (url, options) => {
|
|
61
|
+
const abortSignal = options?.signal;
|
|
62
|
+
let response;
|
|
63
|
+
let attempt = 0;
|
|
64
|
+
for (; ; ) {
|
|
65
|
+
response = await fetchFn(url, options);
|
|
66
|
+
if (!retryStatusCodes.includes(response.status)) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (attempt++ >= maxRetries) {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
73
|
+
const delay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : Math.min(100 * Math.pow(2, attempt - 1), 1e4);
|
|
74
|
+
await sleep(delay, abortSignal);
|
|
75
|
+
}
|
|
76
|
+
return response;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function sleep(durationMs, abortSignal) {
|
|
81
|
+
if (abortSignal?.aborted) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
await new Promise((resolve) => {
|
|
85
|
+
let timeoutHandle = void 0;
|
|
86
|
+
const done = () => {
|
|
87
|
+
if (timeoutHandle) {
|
|
88
|
+
clearTimeout(timeoutHandle);
|
|
89
|
+
}
|
|
90
|
+
abortSignal?.removeEventListener("abort", done);
|
|
91
|
+
resolve();
|
|
92
|
+
};
|
|
93
|
+
timeoutHandle = setTimeout(done, durationMs);
|
|
94
|
+
abortSignal?.addEventListener("abort", done);
|
|
95
|
+
});
|
|
32
96
|
}
|
|
33
97
|
function replaceGitLabUrlType(url, type) {
|
|
34
98
|
return url.replace(/\/\-\/(blob|tree|edit)\//, `/-/${type}/`);
|
|
35
99
|
}
|
|
36
100
|
|
|
37
|
-
export { GitLabIntegration, replaceGitLabUrlType };
|
|
101
|
+
export { GitLabIntegration, replaceGitLabUrlType, sleep };
|
|
38
102
|
//# sourceMappingURL=GitLabIntegration.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitLabIntegration.esm.js","sources":["../../src/gitlab/GitLabIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\
|
|
1
|
+
{"version":3,"file":"GitLabIntegration.esm.js","sources":["../../src/gitlab/GitLabIntegration.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { basicIntegrations, defaultScmResolveUrl } from '../helpers';\nimport { ScmIntegration, ScmIntegrationsFactory } from '../types';\nimport {\n GitLabIntegrationConfig,\n readGitLabIntegrationConfigs,\n} from './config';\nimport pThrottle from 'p-throttle';\n\ntype FetchFunction = typeof fetch;\n\n/**\n * A GitLab based integration.\n *\n * @public\n */\nexport class GitLabIntegration implements ScmIntegration {\n static factory: ScmIntegrationsFactory<GitLabIntegration> = ({ config }) => {\n const configs = readGitLabIntegrationConfigs(\n config.getOptionalConfigArray('integrations.gitlab') ?? [],\n );\n return basicIntegrations(\n configs.map(c => new GitLabIntegration(c)),\n i => i.config.host,\n );\n };\n\n private readonly fetchImpl: FetchFunction;\n\n constructor(private readonly integrationConfig: GitLabIntegrationConfig) {\n // Configure fetch strategy based on configuration\n this.fetchImpl = this.createFetchStrategy();\n }\n\n get type(): string {\n return 'gitlab';\n }\n\n get title(): string {\n return this.integrationConfig.host;\n }\n\n get config(): GitLabIntegrationConfig {\n return this.integrationConfig;\n }\n\n resolveUrl(options: {\n url: string;\n base: string;\n lineNumber?: number;\n }): string {\n return defaultScmResolveUrl(options);\n }\n\n resolveEditUrl(url: string): string {\n return replaceGitLabUrlType(url, 'edit');\n }\n\n fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n return this.fetchImpl(input, init);\n }\n\n private createFetchStrategy(): FetchFunction {\n let fetchFn: FetchFunction = async (url, options) => {\n return fetch(url, { ...options, mode: 'same-origin' });\n };\n\n const retryConfig = this.integrationConfig.retry;\n if (retryConfig) {\n // Apply retry wrapper if configured\n fetchFn = this.withRetry(fetchFn, retryConfig);\n\n // Apply throttling wrapper if configured\n if (\n retryConfig.maxApiRequestsPerMinute &&\n retryConfig.maxApiRequestsPerMinute > 0\n ) {\n fetchFn = pThrottle({\n limit: retryConfig.maxApiRequestsPerMinute,\n interval: 60_000,\n })(fetchFn);\n }\n }\n\n return fetchFn;\n }\n\n private withRetry(\n fetchFn: FetchFunction,\n retryConfig: { maxRetries?: number; retryStatusCodes?: number[] },\n ): FetchFunction {\n const maxRetries = retryConfig?.maxRetries ?? 0;\n const retryStatusCodes = retryConfig?.retryStatusCodes ?? [];\n if (maxRetries <= 0 || retryStatusCodes.length === 0) {\n return fetchFn;\n }\n\n return async (url, options) => {\n const abortSignal = options?.signal;\n let response: Response;\n let attempt = 0;\n for (;;) {\n response = await fetchFn(url, options);\n // If response is not retryable, return immediately\n if (!retryStatusCodes.includes(response.status)) {\n break;\n }\n\n // If this was the last allowed attempt, return response\n if (attempt++ >= maxRetries) {\n break;\n }\n // Determine delay from Retry-After header if present, otherwise exponential backoff\n const retryAfter = response.headers.get('Retry-After');\n const delay = retryAfter\n ? parseInt(retryAfter, 10) * 1000\n : Math.min(100 * Math.pow(2, attempt - 1), 10000); // Exponential backoff, cap at 10 seconds\n\n await sleep(delay, abortSignal);\n }\n\n return response;\n };\n }\n}\n\nexport async function sleep(\n durationMs: number,\n abortSignal: AbortSignal | null | undefined,\n): Promise<void> {\n if (abortSignal?.aborted) {\n return;\n }\n\n await new Promise<void>(resolve => {\n let timeoutHandle: NodeJS.Timeout | undefined = undefined;\n\n const done = () => {\n if (timeoutHandle) {\n clearTimeout(timeoutHandle);\n }\n abortSignal?.removeEventListener('abort', done);\n resolve();\n };\n\n timeoutHandle = setTimeout(done, durationMs);\n abortSignal?.addEventListener('abort', done);\n });\n}\n\n/**\n * Takes a GitLab URL and replaces the type part (blob, tree etc).\n *\n * @param url - The original URL\n * @param type - The desired type, e.g. 'blob', 'tree', 'edit'\n * @public\n */\nexport function replaceGitLabUrlType(\n url: string,\n type: 'blob' | 'tree' | 'edit',\n): string {\n return url.replace(/\\/\\-\\/(blob|tree|edit)\\//, `/-/${type}/`);\n}\n"],"names":[],"mappings":";;;;AA8BO,MAAM,iBAAA,CAA4C;AAAA,EAavD,YAA6B,iBAAA,EAA4C;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAE3B,IAAA,IAAA,CAAK,SAAA,GAAY,KAAK,mBAAA,EAAoB;AAAA,EAC5C;AAAA,EAfA,OAAO,OAAA,GAAqD,CAAC,EAAE,QAAO,KAAM;AAC1E,IAAA,MAAM,OAAA,GAAU,4BAAA;AAAA,MACd,MAAA,CAAO,sBAAA,CAAuB,qBAAqB,CAAA,IAAK;AAAC,KAC3D;AACA,IAAA,OAAO,iBAAA;AAAA,MACL,QAAQ,GAAA,CAAI,CAAA,CAAA,KAAK,IAAI,iBAAA,CAAkB,CAAC,CAAC,CAAA;AAAA,MACzC,CAAA,CAAA,KAAK,EAAE,MAAA,CAAO;AAAA,KAChB;AAAA,EACF,CAAA;AAAA,EAEiB,SAAA;AAAA,EAOjB,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,QAAA;AAAA,EACT;AAAA,EAEA,IAAI,KAAA,GAAgB;AAClB,IAAA,OAAO,KAAK,iBAAA,CAAkB,IAAA;AAAA,EAChC;AAAA,EAEA,IAAI,MAAA,GAAkC;AACpC,IAAA,OAAO,IAAA,CAAK,iBAAA;AAAA,EACd;AAAA,EAEA,WAAW,OAAA,EAIA;AACT,IAAA,OAAO,qBAAqB,OAAO,CAAA;AAAA,EACrC;AAAA,EAEA,eAAe,GAAA,EAAqB;A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A,CAAQ,0BAAA,EAA4B,CAAA,GAAA,EAAM,IAAI,CAAA,CAAA,CAAG,CAAA;AAC9D;;;;"}
|
|
@@ -5,6 +5,25 @@ var helpers = require('../helpers.cjs.js');
|
|
|
5
5
|
|
|
6
6
|
const GITLAB_HOST = "gitlab.com";
|
|
7
7
|
const GITLAB_API_BASE_URL = "https://gitlab.com/api/v4";
|
|
8
|
+
function readOptionalNumberArray(config, key) {
|
|
9
|
+
const value = config.getOptional(key);
|
|
10
|
+
if (value === void 0) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
if (!Array.isArray(value)) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`Invalid ${key} config: expected an array, got ${typeof value}`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return value.map((item, index) => {
|
|
19
|
+
if (typeof item !== "number") {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Invalid ${key} config: all values must be numbers, got ${typeof item} at index ${index}`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return item;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
8
27
|
function readGitLabIntegrationConfig(config) {
|
|
9
28
|
const host = config.getString("host");
|
|
10
29
|
let apiBaseUrl = config.getOptionalString("apiBaseUrl");
|
|
@@ -33,12 +52,19 @@ function readGitLabIntegrationConfig(config) {
|
|
|
33
52
|
`Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`
|
|
34
53
|
);
|
|
35
54
|
}
|
|
55
|
+
const retryConfig = config.getOptionalConfig("retry");
|
|
56
|
+
const retry = retryConfig ? {
|
|
57
|
+
maxRetries: retryConfig.getOptionalNumber("maxRetries") ?? 0,
|
|
58
|
+
retryStatusCodes: readOptionalNumberArray(retryConfig, "retryStatusCodes") ?? [],
|
|
59
|
+
maxApiRequestsPerMinute: retryConfig.getOptionalNumber("maxApiRequestsPerMinute") ?? -1
|
|
60
|
+
} : void 0;
|
|
36
61
|
return {
|
|
37
62
|
host,
|
|
38
63
|
token,
|
|
39
64
|
apiBaseUrl,
|
|
40
65
|
baseUrl,
|
|
41
|
-
commitSigningKey: config.getOptionalString("commitSigningKey")
|
|
66
|
+
commitSigningKey: config.getOptionalString("commitSigningKey"),
|
|
67
|
+
retry
|
|
42
68
|
};
|
|
43
69
|
}
|
|
44
70
|
function readGitLabIntegrationConfigs(configs) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs.js","sources":["../../src/gitlab/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\nconst GITLAB_HOST = 'gitlab.com';\nconst GITLAB_API_BASE_URL = 'https://gitlab.com/api/v4';\n\n/**\n * The configuration parameters for a single GitLab integration.\n *\n * @public\n */\nexport type GitLabIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. `gitlab.com`.\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g.\n * `https://gitlab.com/api/v4`, with no trailing slash.\n *\n * May be omitted specifically for public GitLab; then it will be deduced.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed\n * into the GitLab client.\n *\n * If no baseUrl is provided, it will default to `https://${host}`\n */\n baseUrl: string;\n\n /**\n * Signing key to sign commits\n */\n commitSigningKey?: string;\n};\n\n/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n };\n}\n\n/**\n * Reads a set of GitLab integration configs, and inserts some defaults for\n * public GitLab if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readGitLabIntegrationConfigs(\n configs: Config[],\n): GitLabIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readGitLabIntegrationConfig);\n\n // As a convenience we always make sure there's at least an unauthenticated\n // reader for public gitlab repos.\n if (!result.some(c => c.host === GITLAB_HOST)) {\n result.push({\n host: GITLAB_HOST,\n apiBaseUrl: GITLAB_API_BASE_URL,\n baseUrl: `https://${GITLAB_HOST}`,\n });\n }\n\n return result;\n}\n\n/**\n * Reads a GitLab integration config, and returns\n * relative path.\n *\n * @param config - GitLabIntegrationConfig object\n * @public\n */\nexport function getGitLabIntegrationRelativePath(\n config: GitLabIntegrationConfig,\n): string {\n let relativePath = '';\n if (config.host !== GITLAB_HOST) {\n relativePath = new URL(config.baseUrl).pathname;\n }\n return trimEnd(relativePath, '/');\n}\n"],"names":["trimEnd","isValidHost","isValidUrl"],"mappings":";;;;;AAoBA,MAAM,WAAA,GAAc,YAAA;AACpB,MAAM,mBAAA,GAAsB,2BAAA;
|
|
1
|
+
{"version":3,"file":"config.cjs.js","sources":["../../src/gitlab/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\nconst GITLAB_HOST = 'gitlab.com';\nconst GITLAB_API_BASE_URL = 'https://gitlab.com/api/v4';\n\n/**\n * Reads an optional number array from config\n */\nfunction readOptionalNumberArray(\n config: Config,\n key: string,\n): number[] | undefined {\n const value = config.getOptional(key);\n if (value === undefined) {\n return undefined;\n }\n if (!Array.isArray(value)) {\n throw new Error(\n `Invalid ${key} config: expected an array, got ${typeof value}`,\n );\n }\n return value.map((item, index) => {\n if (typeof item !== 'number') {\n throw new Error(\n `Invalid ${key} config: all values must be numbers, got ${typeof item} at index ${index}`,\n );\n }\n return item;\n });\n}\n\n/**\n * The configuration parameters for a single GitLab integration.\n *\n * @public\n */\nexport type GitLabIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. `gitlab.com`.\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g.\n * `https://gitlab.com/api/v4`, with no trailing slash.\n *\n * May be omitted specifically for public GitLab; then it will be deduced.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed\n * into the GitLab client.\n *\n * If no baseUrl is provided, it will default to `https://${host}`\n */\n baseUrl: string;\n\n /**\n * Signing key to sign commits\n */\n commitSigningKey?: string;\n\n /**\n * Retry configuration for failed requests.\n */\n retry?: {\n /**\n * Maximum number of retries for failed requests\n * @defaultValue 0\n */\n maxRetries?: number;\n\n /**\n * HTTP status codes that should trigger a retry\n * @defaultValue []\n */\n retryStatusCodes?: number[];\n\n /**\n * Rate limit for requests per minute\n * @defaultValue -1\n */\n maxApiRequestsPerMinute?: number;\n };\n};\n\n/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n const retryConfig = config.getOptionalConfig('retry');\n\n const retry = retryConfig\n ? {\n maxRetries: retryConfig.getOptionalNumber('maxRetries') ?? 0,\n retryStatusCodes:\n readOptionalNumberArray(retryConfig, 'retryStatusCodes') ?? [],\n maxApiRequestsPerMinute:\n retryConfig.getOptionalNumber('maxApiRequestsPerMinute') ?? -1,\n }\n : undefined;\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n retry,\n };\n}\n\n/**\n * Reads a set of GitLab integration configs, and inserts some defaults for\n * public GitLab if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readGitLabIntegrationConfigs(\n configs: Config[],\n): GitLabIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readGitLabIntegrationConfig);\n\n // As a convenience we always make sure there's at least an unauthenticated\n // reader for public gitlab repos.\n if (!result.some(c => c.host === GITLAB_HOST)) {\n result.push({\n host: GITLAB_HOST,\n apiBaseUrl: GITLAB_API_BASE_URL,\n baseUrl: `https://${GITLAB_HOST}`,\n });\n }\n\n return result;\n}\n\n/**\n * Reads a GitLab integration config, and returns\n * relative path.\n *\n * @param config - GitLabIntegrationConfig object\n * @public\n */\nexport function getGitLabIntegrationRelativePath(\n config: GitLabIntegrationConfig,\n): string {\n let relativePath = '';\n if (config.host !== GITLAB_HOST) {\n relativePath = new URL(config.baseUrl).pathname;\n }\n return trimEnd(relativePath, '/');\n}\n"],"names":["trimEnd","isValidHost","isValidUrl"],"mappings":";;;;;AAoBA,MAAM,WAAA,GAAc,YAAA;AACpB,MAAM,mBAAA,GAAsB,2BAAA;AAK5B,SAAS,uBAAA,CACP,QACA,GAAA,EACsB;AACtB,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,WAAA,CAAY,GAAG,CAAA;AACpC,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,QAAA,EAAW,GAAG,CAAA,gCAAA,EAAmC,OAAO,KAAK,CAAA;AAAA,KAC/D;AAAA,EACF;AACA,EAAA,OAAO,KAAA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CAAO,OAAO,CAAA,CAAE,QAAA;AAAA,EACzC;AACA,EAAA,OAAOF,cAAA,CAAQ,cAAc,GAAG,CAAA;AAClC;;;;;;"}
|
|
@@ -3,6 +3,25 @@ import { isValidHost, isValidUrl } from '../helpers.esm.js';
|
|
|
3
3
|
|
|
4
4
|
const GITLAB_HOST = "gitlab.com";
|
|
5
5
|
const GITLAB_API_BASE_URL = "https://gitlab.com/api/v4";
|
|
6
|
+
function readOptionalNumberArray(config, key) {
|
|
7
|
+
const value = config.getOptional(key);
|
|
8
|
+
if (value === void 0) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
if (!Array.isArray(value)) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Invalid ${key} config: expected an array, got ${typeof value}`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return value.map((item, index) => {
|
|
17
|
+
if (typeof item !== "number") {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`Invalid ${key} config: all values must be numbers, got ${typeof item} at index ${index}`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return item;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
6
25
|
function readGitLabIntegrationConfig(config) {
|
|
7
26
|
const host = config.getString("host");
|
|
8
27
|
let apiBaseUrl = config.getOptionalString("apiBaseUrl");
|
|
@@ -31,12 +50,19 @@ function readGitLabIntegrationConfig(config) {
|
|
|
31
50
|
`Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`
|
|
32
51
|
);
|
|
33
52
|
}
|
|
53
|
+
const retryConfig = config.getOptionalConfig("retry");
|
|
54
|
+
const retry = retryConfig ? {
|
|
55
|
+
maxRetries: retryConfig.getOptionalNumber("maxRetries") ?? 0,
|
|
56
|
+
retryStatusCodes: readOptionalNumberArray(retryConfig, "retryStatusCodes") ?? [],
|
|
57
|
+
maxApiRequestsPerMinute: retryConfig.getOptionalNumber("maxApiRequestsPerMinute") ?? -1
|
|
58
|
+
} : void 0;
|
|
34
59
|
return {
|
|
35
60
|
host,
|
|
36
61
|
token,
|
|
37
62
|
apiBaseUrl,
|
|
38
63
|
baseUrl,
|
|
39
|
-
commitSigningKey: config.getOptionalString("commitSigningKey")
|
|
64
|
+
commitSigningKey: config.getOptionalString("commitSigningKey"),
|
|
65
|
+
retry
|
|
40
66
|
};
|
|
41
67
|
}
|
|
42
68
|
function readGitLabIntegrationConfigs(configs) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.esm.js","sources":["../../src/gitlab/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\nconst GITLAB_HOST = 'gitlab.com';\nconst GITLAB_API_BASE_URL = 'https://gitlab.com/api/v4';\n\n/**\n * The configuration parameters for a single GitLab integration.\n *\n * @public\n */\nexport type GitLabIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. `gitlab.com`.\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g.\n * `https://gitlab.com/api/v4`, with no trailing slash.\n *\n * May be omitted specifically for public GitLab; then it will be deduced.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed\n * into the GitLab client.\n *\n * If no baseUrl is provided, it will default to `https://${host}`\n */\n baseUrl: string;\n\n /**\n * Signing key to sign commits\n */\n commitSigningKey?: string;\n};\n\n/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n };\n}\n\n/**\n * Reads a set of GitLab integration configs, and inserts some defaults for\n * public GitLab if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readGitLabIntegrationConfigs(\n configs: Config[],\n): GitLabIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readGitLabIntegrationConfig);\n\n // As a convenience we always make sure there's at least an unauthenticated\n // reader for public gitlab repos.\n if (!result.some(c => c.host === GITLAB_HOST)) {\n result.push({\n host: GITLAB_HOST,\n apiBaseUrl: GITLAB_API_BASE_URL,\n baseUrl: `https://${GITLAB_HOST}`,\n });\n }\n\n return result;\n}\n\n/**\n * Reads a GitLab integration config, and returns\n * relative path.\n *\n * @param config - GitLabIntegrationConfig object\n * @public\n */\nexport function getGitLabIntegrationRelativePath(\n config: GitLabIntegrationConfig,\n): string {\n let relativePath = '';\n if (config.host !== GITLAB_HOST) {\n relativePath = new URL(config.baseUrl).pathname;\n }\n return trimEnd(relativePath, '/');\n}\n"],"names":[],"mappings":";;;AAoBA,MAAM,WAAA,GAAc,YAAA;AACpB,MAAM,mBAAA,GAAsB,2BAAA;
|
|
1
|
+
{"version":3,"file":"config.esm.js","sources":["../../src/gitlab/config.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { trimEnd } from 'lodash';\nimport { isValidHost, isValidUrl } from '../helpers';\n\nconst GITLAB_HOST = 'gitlab.com';\nconst GITLAB_API_BASE_URL = 'https://gitlab.com/api/v4';\n\n/**\n * Reads an optional number array from config\n */\nfunction readOptionalNumberArray(\n config: Config,\n key: string,\n): number[] | undefined {\n const value = config.getOptional(key);\n if (value === undefined) {\n return undefined;\n }\n if (!Array.isArray(value)) {\n throw new Error(\n `Invalid ${key} config: expected an array, got ${typeof value}`,\n );\n }\n return value.map((item, index) => {\n if (typeof item !== 'number') {\n throw new Error(\n `Invalid ${key} config: all values must be numbers, got ${typeof item} at index ${index}`,\n );\n }\n return item;\n });\n}\n\n/**\n * The configuration parameters for a single GitLab integration.\n *\n * @public\n */\nexport type GitLabIntegrationConfig = {\n /**\n * The host of the target that this matches on, e.g. `gitlab.com`.\n */\n host: string;\n\n /**\n * The base URL of the API of this provider, e.g.\n * `https://gitlab.com/api/v4`, with no trailing slash.\n *\n * May be omitted specifically for public GitLab; then it will be deduced.\n */\n apiBaseUrl: string;\n\n /**\n * The authorization token to use for requests to this provider.\n *\n * If no token is specified, anonymous access is used.\n */\n token?: string;\n\n /**\n * The baseUrl of this provider, e.g. `https://gitlab.com`, which is passed\n * into the GitLab client.\n *\n * If no baseUrl is provided, it will default to `https://${host}`\n */\n baseUrl: string;\n\n /**\n * Signing key to sign commits\n */\n commitSigningKey?: string;\n\n /**\n * Retry configuration for failed requests.\n */\n retry?: {\n /**\n * Maximum number of retries for failed requests\n * @defaultValue 0\n */\n maxRetries?: number;\n\n /**\n * HTTP status codes that should trigger a retry\n * @defaultValue []\n */\n retryStatusCodes?: number[];\n\n /**\n * Rate limit for requests per minute\n * @defaultValue -1\n */\n maxApiRequestsPerMinute?: number;\n };\n};\n\n/**\n * Reads a single GitLab integration config.\n *\n * @param config - The config object of a single integration\n * @public\n */\nexport function readGitLabIntegrationConfig(\n config: Config,\n): GitLabIntegrationConfig {\n const host = config.getString('host');\n let apiBaseUrl = config.getOptionalString('apiBaseUrl');\n const token = config.getOptionalString('token')?.trim();\n let baseUrl = config.getOptionalString('baseUrl');\n if (apiBaseUrl) {\n apiBaseUrl = trimEnd(apiBaseUrl, '/');\n } else if (host === GITLAB_HOST) {\n apiBaseUrl = GITLAB_API_BASE_URL;\n }\n\n if (baseUrl) {\n baseUrl = trimEnd(baseUrl, '/');\n } else {\n baseUrl = `https://${host}`;\n }\n\n if (!isValidHost(host)) {\n throw new Error(\n `Invalid GitLab integration config, '${host}' is not a valid host`,\n );\n } else if (!apiBaseUrl || !isValidUrl(apiBaseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`,\n );\n } else if (!isValidUrl(baseUrl)) {\n throw new Error(\n `Invalid GitLab integration config, '${baseUrl}' is not a valid baseUrl`,\n );\n }\n\n const retryConfig = config.getOptionalConfig('retry');\n\n const retry = retryConfig\n ? {\n maxRetries: retryConfig.getOptionalNumber('maxRetries') ?? 0,\n retryStatusCodes:\n readOptionalNumberArray(retryConfig, 'retryStatusCodes') ?? [],\n maxApiRequestsPerMinute:\n retryConfig.getOptionalNumber('maxApiRequestsPerMinute') ?? -1,\n }\n : undefined;\n\n return {\n host,\n token,\n apiBaseUrl,\n baseUrl,\n commitSigningKey: config.getOptionalString('commitSigningKey'),\n retry,\n };\n}\n\n/**\n * Reads a set of GitLab integration configs, and inserts some defaults for\n * public GitLab if not specified.\n *\n * @param configs - All of the integration config objects\n * @public\n */\nexport function readGitLabIntegrationConfigs(\n configs: Config[],\n): GitLabIntegrationConfig[] {\n // First read all the explicit integrations\n const result = configs.map(readGitLabIntegrationConfig);\n\n // As a convenience we always make sure there's at least an unauthenticated\n // reader for public gitlab repos.\n if (!result.some(c => c.host === GITLAB_HOST)) {\n result.push({\n host: GITLAB_HOST,\n apiBaseUrl: GITLAB_API_BASE_URL,\n baseUrl: `https://${GITLAB_HOST}`,\n });\n }\n\n return result;\n}\n\n/**\n * Reads a GitLab integration config, and returns\n * relative path.\n *\n * @param config - GitLabIntegrationConfig object\n * @public\n */\nexport function getGitLabIntegrationRelativePath(\n config: GitLabIntegrationConfig,\n): string {\n let relativePath = '';\n if (config.host !== GITLAB_HOST) {\n relativePath = new URL(config.baseUrl).pathname;\n }\n return trimEnd(relativePath, '/');\n}\n"],"names":[],"mappings":";;;AAoBA,MAAM,WAAA,GAAc,YAAA;AACpB,MAAM,mBAAA,GAAsB,2BAAA;AAK5B,SAAS,uBAAA,CACP,QACA,GAAA,EACsB;AACtB,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,WAAA,CAAY,GAAG,CAAA;AACpC,EAAA,IAAI,UAAU,MAAA,EAAW;AACvB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACzB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,QAAA,EAAW,GAAG,CAAA,gCAAA,EAAmC,OAAO,KAAK,CAAA;AAAA,KAC/D;AAAA,EACF;AACA,EAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CA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A;AAAA,EACzC;AACA,EAAA,OAAO,OAAA,CAAQ,cAAc,GAAG,CAAA;AAClC;;;;"}
|
package/dist/gitlab/core.cjs.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fetch = require('cross-fetch');
|
|
4
3
|
var config = require('./config.cjs.js');
|
|
5
4
|
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
async function getGitLabFileFetchUrl(url, config, token) {
|
|
11
|
-
const projectID = await getProjectId(url, config, token);
|
|
12
|
-
return buildProjectUrl(url, projectID, config).toString();
|
|
5
|
+
function getGitLabFileFetchUrl(url, config, _token) {
|
|
6
|
+
const projectPath = extractProjectPath(url, config);
|
|
7
|
+
return Promise.resolve(buildProjectUrl(url, projectPath, config).toString());
|
|
13
8
|
}
|
|
14
9
|
function getGitLabRequestOptions(config, token) {
|
|
15
10
|
const headers = {};
|
|
@@ -19,16 +14,17 @@ function getGitLabRequestOptions(config, token) {
|
|
|
19
14
|
}
|
|
20
15
|
return { headers };
|
|
21
16
|
}
|
|
22
|
-
function buildProjectUrl(target,
|
|
17
|
+
function buildProjectUrl(target, projectPathOrID, config$1) {
|
|
23
18
|
try {
|
|
24
19
|
const url = new URL(target);
|
|
25
20
|
const branchAndFilePath = url.pathname.split("/blob/").slice(1).join("/blob/");
|
|
26
21
|
const [branch, ...filePath] = branchAndFilePath.split("/");
|
|
27
22
|
const relativePath = config.getGitLabIntegrationRelativePath(config$1);
|
|
23
|
+
const projectIdentifier = encodeURIComponent(String(projectPathOrID));
|
|
28
24
|
url.pathname = [
|
|
29
25
|
...relativePath ? [relativePath] : [],
|
|
30
26
|
"api/v4/projects",
|
|
31
|
-
|
|
27
|
+
projectIdentifier,
|
|
32
28
|
"repository/files",
|
|
33
29
|
encodeURIComponent(decodeURIComponent(filePath.join("/"))),
|
|
34
30
|
"raw"
|
|
@@ -39,47 +35,23 @@ function buildProjectUrl(target, projectID, config$1) {
|
|
|
39
35
|
throw new Error(`Incorrect url: ${target}, ${e}`);
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
|
-
|
|
38
|
+
function extractProjectPath(target, config$1) {
|
|
43
39
|
const url = new URL(target);
|
|
44
40
|
if (!url.pathname.includes("/blob/")) {
|
|
45
41
|
throw new Error(
|
|
46
|
-
`Failed
|
|
42
|
+
`Failed extracting project path from ${url.pathname}. Url path must include /blob/.`
|
|
47
43
|
);
|
|
48
44
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
repo = repo.replace(relativePath, "");
|
|
54
|
-
}
|
|
55
|
-
const repoIDLookup = new URL(
|
|
56
|
-
`${url.origin}${relativePath}/api/v4/projects/${encodeURIComponent(
|
|
57
|
-
repo.replace(/^\//, "")
|
|
58
|
-
)}`
|
|
59
|
-
);
|
|
60
|
-
const response = await fetch__default.default(
|
|
61
|
-
repoIDLookup.toString(),
|
|
62
|
-
getGitLabRequestOptions(config$1, token)
|
|
63
|
-
);
|
|
64
|
-
const data = await response.json();
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
if (response.status === 401) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
"GitLab Error: 401 - Unauthorized. The access token used is either expired, or does not have permission to read the project"
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
throw new Error(
|
|
72
|
-
`GitLab Error '${data.error}', ${data.error_description}`
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
return Number(data.id);
|
|
76
|
-
} catch (e) {
|
|
77
|
-
throw new Error(`Could not get GitLab project ID for: ${target}, ${e}`);
|
|
45
|
+
let repo = url.pathname.split("/-/blob/")[0].split("/blob/")[0];
|
|
46
|
+
const relativePath = config.getGitLabIntegrationRelativePath(config$1);
|
|
47
|
+
if (relativePath) {
|
|
48
|
+
repo = repo.replace(relativePath, "");
|
|
78
49
|
}
|
|
50
|
+
return repo.replace(/^\//, "");
|
|
79
51
|
}
|
|
80
52
|
|
|
81
53
|
exports.buildProjectUrl = buildProjectUrl;
|
|
54
|
+
exports.extractProjectPath = extractProjectPath;
|
|
82
55
|
exports.getGitLabFileFetchUrl = getGitLabFileFetchUrl;
|
|
83
56
|
exports.getGitLabRequestOptions = getGitLabRequestOptions;
|
|
84
|
-
exports.getProjectId = getProjectId;
|
|
85
57
|
//# sourceMappingURL=core.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.js","sources":["../../src/gitlab/core.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport
|
|
1
|
+
{"version":3,"file":"core.cjs.js","sources":["../../src/gitlab/core.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n getGitLabIntegrationRelativePath,\n GitLabIntegrationConfig,\n} from './config';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitlab.example.com/a/b/blob/master/c.yaml\n * to: https://gitlab.com/api/v4/projects/a%2Fb/repository/files/c.yaml/raw?ref=master\n * -or-\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @param token - An optional auth token (not used in path extraction, kept for compatibility)\n * @public\n */\nexport function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n _token?: string,\n): Promise<string> {\n // Use project path directly instead of making an API call to get project ID\n // Note: _token parameter kept for backward compatibility but not used for path extraction\n const projectPath = extractProjectPath(url, config);\n return Promise.resolve(buildProjectUrl(url, projectPath, config).toString());\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @param token - An optional auth token to use for communicating with GitLab. By default uses the integration token\n * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n const accessToken = token || config.token;\n if (accessToken) {\n // OAuth, Personal, Project, and Group access tokens can all be passed via\n // a bearer authorization header\n // https://docs.gitlab.com/api/rest/authentication/#personalprojectgroup-access-tokens\n headers.Authorization = `Bearer ${accessToken}`;\n }\n\n return { headers };\n}\n\n// Converts\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectPathOrID: string | Number,\n config: GitLabIntegrationConfig,\n): URL {\n try {\n const url = new URL(target);\n\n const branchAndFilePath = url.pathname\n .split('/blob/')\n .slice(1)\n .join('/blob/');\n const [branch, ...filePath] = branchAndFilePath.split('/');\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n const projectIdentifier = encodeURIComponent(String(projectPathOrID));\n\n url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectIdentifier,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = `?ref=${branch}`;\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n/**\n * Extracts the project path from a GitLab URL\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: groupA/teams/teamA/subgroupA/repoA\n */\nexport function extractProjectPath(\n target: string,\n config: GitLabIntegrationConfig,\n): string {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must include /blob/.`,\n );\n }\n\n let repo = url.pathname.split('/-/blob/')[0].split('/blob/')[0];\n\n // Get gitlab relative path\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n // Check relative path exist and replace it if it's the case.\n if (relativePath) {\n repo = repo.replace(relativePath, '');\n }\n\n // Remove leading slash\n return repo.replace(/^\\//, '');\n}\n"],"names":["config","getGitLabIntegrationRelativePath"],"mappings":";;;;AAuCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,MAAA,EACiB;AAGjB,EAAA,MAAM,WAAA,GAAc,kBAAA,CAAmB,GAAA,EAAK,MAAM,CAAA;AAClD,EAAA,OAAO,OAAA,CAAQ,QAAQ,eAAA,CAAgB,GAAA,EAAK,aAAa,MAAM,CAAA,CAAE,UAAU,CAAA;AAC7E;AASO,SAAS,uBAAA,CACd,QACA,KAAA,EACqC;AACrC,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAA,MAAM,WAAA,GAAc,SAAS,MAAA,CAAO,KAAA;AACpC,EAAA,IAAI,WAAA,EAAa;AAIf,IAAA,OAAA,CAAQ,aAAA,GAAgB,UAAU,WAAW,CAAA,CAAA;AAAA,EAC/C;AAEA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB;AAKO,SAAS,eAAA,CACd,MAAA,EACA,eAAA,EACAA,QAAA,EACK;AACL,EAAA,IA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,EAAA,IAAI,IAAA,GAAO,GAAA,CAAI,QAAA,CAAS,KAAA,CAAM,UAAU,CAAA,CAAE,CAAC,CAAA,CAAE,KAAA,CAAM,QAAQ,CAAA,CAAE,CAAC,CAAA;AAG9D,EAAA,MAAM,YAAA,GAAeC,wCAAiCD,QAAM,CAAA;AAG5D,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,IAAA,GAAO,IAAA,CAAK,OAAA,CAAQ,YAAA,EAAc,EAAE,CAAA;AAAA,EACtC;AAGA,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAC/B;;;;;;;"}
|
package/dist/gitlab/core.esm.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import fetch from 'cross-fetch';
|
|
2
1
|
import { getGitLabIntegrationRelativePath } from './config.esm.js';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
return buildProjectUrl(url,
|
|
3
|
+
function getGitLabFileFetchUrl(url, config, _token) {
|
|
4
|
+
const projectPath = extractProjectPath(url, config);
|
|
5
|
+
return Promise.resolve(buildProjectUrl(url, projectPath, config).toString());
|
|
7
6
|
}
|
|
8
7
|
function getGitLabRequestOptions(config, token) {
|
|
9
8
|
const headers = {};
|
|
@@ -13,16 +12,17 @@ function getGitLabRequestOptions(config, token) {
|
|
|
13
12
|
}
|
|
14
13
|
return { headers };
|
|
15
14
|
}
|
|
16
|
-
function buildProjectUrl(target,
|
|
15
|
+
function buildProjectUrl(target, projectPathOrID, config) {
|
|
17
16
|
try {
|
|
18
17
|
const url = new URL(target);
|
|
19
18
|
const branchAndFilePath = url.pathname.split("/blob/").slice(1).join("/blob/");
|
|
20
19
|
const [branch, ...filePath] = branchAndFilePath.split("/");
|
|
21
20
|
const relativePath = getGitLabIntegrationRelativePath(config);
|
|
21
|
+
const projectIdentifier = encodeURIComponent(String(projectPathOrID));
|
|
22
22
|
url.pathname = [
|
|
23
23
|
...relativePath ? [relativePath] : [],
|
|
24
24
|
"api/v4/projects",
|
|
25
|
-
|
|
25
|
+
projectIdentifier,
|
|
26
26
|
"repository/files",
|
|
27
27
|
encodeURIComponent(decodeURIComponent(filePath.join("/"))),
|
|
28
28
|
"raw"
|
|
@@ -33,44 +33,20 @@ function buildProjectUrl(target, projectID, config) {
|
|
|
33
33
|
throw new Error(`Incorrect url: ${target}, ${e}`);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
function extractProjectPath(target, config) {
|
|
37
37
|
const url = new URL(target);
|
|
38
38
|
if (!url.pathname.includes("/blob/")) {
|
|
39
39
|
throw new Error(
|
|
40
|
-
`Failed
|
|
40
|
+
`Failed extracting project path from ${url.pathname}. Url path must include /blob/.`
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
repo = repo.replace(relativePath, "");
|
|
48
|
-
}
|
|
49
|
-
const repoIDLookup = new URL(
|
|
50
|
-
`${url.origin}${relativePath}/api/v4/projects/${encodeURIComponent(
|
|
51
|
-
repo.replace(/^\//, "")
|
|
52
|
-
)}`
|
|
53
|
-
);
|
|
54
|
-
const response = await fetch(
|
|
55
|
-
repoIDLookup.toString(),
|
|
56
|
-
getGitLabRequestOptions(config, token)
|
|
57
|
-
);
|
|
58
|
-
const data = await response.json();
|
|
59
|
-
if (!response.ok) {
|
|
60
|
-
if (response.status === 401) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
"GitLab Error: 401 - Unauthorized. The access token used is either expired, or does not have permission to read the project"
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
throw new Error(
|
|
66
|
-
`GitLab Error '${data.error}', ${data.error_description}`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
return Number(data.id);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
throw new Error(`Could not get GitLab project ID for: ${target}, ${e}`);
|
|
43
|
+
let repo = url.pathname.split("/-/blob/")[0].split("/blob/")[0];
|
|
44
|
+
const relativePath = getGitLabIntegrationRelativePath(config);
|
|
45
|
+
if (relativePath) {
|
|
46
|
+
repo = repo.replace(relativePath, "");
|
|
72
47
|
}
|
|
48
|
+
return repo.replace(/^\//, "");
|
|
73
49
|
}
|
|
74
50
|
|
|
75
|
-
export { buildProjectUrl, getGitLabFileFetchUrl, getGitLabRequestOptions
|
|
51
|
+
export { buildProjectUrl, extractProjectPath, getGitLabFileFetchUrl, getGitLabRequestOptions };
|
|
76
52
|
//# sourceMappingURL=core.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.esm.js","sources":["../../src/gitlab/core.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport
|
|
1
|
+
{"version":3,"file":"core.esm.js","sources":["../../src/gitlab/core.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n getGitLabIntegrationRelativePath,\n GitLabIntegrationConfig,\n} from './config';\n\n/**\n * Given a URL pointing to a file on a provider, returns a URL that is suitable\n * for fetching the contents of the data.\n *\n * @remarks\n *\n * Converts\n * from: https://gitlab.example.com/a/b/blob/master/c.yaml\n * to: https://gitlab.com/api/v4/projects/a%2Fb/repository/files/c.yaml/raw?ref=master\n * -or-\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @param token - An optional auth token (not used in path extraction, kept for compatibility)\n * @public\n */\nexport function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n _token?: string,\n): Promise<string> {\n // Use project path directly instead of making an API call to get project ID\n // Note: _token parameter kept for backward compatibility but not used for path extraction\n const projectPath = extractProjectPath(url, config);\n return Promise.resolve(buildProjectUrl(url, projectPath, config).toString());\n}\n\n/**\n * Gets the request options necessary to make requests to a given provider.\n *\n * @param config - The relevant provider config\n * @param token - An optional auth token to use for communicating with GitLab. By default uses the integration token\n * @public\n */\nexport function getGitLabRequestOptions(\n config: GitLabIntegrationConfig,\n token?: string,\n): { headers: Record<string, string> } {\n const headers: Record<string, string> = {};\n\n const accessToken = token || config.token;\n if (accessToken) {\n // OAuth, Personal, Project, and Group access tokens can all be passed via\n // a bearer authorization header\n // https://docs.gitlab.com/api/rest/authentication/#personalprojectgroup-access-tokens\n headers.Authorization = `Bearer ${accessToken}`;\n }\n\n return { headers };\n}\n\n// Converts\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FteamA%2FsubgroupA%2FrepoA/repository/files/filepath/raw?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectPathOrID: string | Number,\n config: GitLabIntegrationConfig,\n): URL {\n try {\n const url = new URL(target);\n\n const branchAndFilePath = url.pathname\n .split('/blob/')\n .slice(1)\n .join('/blob/');\n const [branch, ...filePath] = branchAndFilePath.split('/');\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n const projectIdentifier = encodeURIComponent(String(projectPathOrID));\n\n url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectIdentifier,\n 'repository/files',\n encodeURIComponent(decodeURIComponent(filePath.join('/'))),\n 'raw',\n ].join('/');\n\n url.search = `?ref=${branch}`;\n\n return url;\n } catch (e) {\n throw new Error(`Incorrect url: ${target}, ${e}`);\n }\n}\n\n/**\n * Extracts the project path from a GitLab URL\n * from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n * to: groupA/teams/teamA/subgroupA/repoA\n */\nexport function extractProjectPath(\n target: string,\n config: GitLabIntegrationConfig,\n): string {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed extracting project path from ${url.pathname}. Url path must include /blob/.`,\n );\n }\n\n let repo = url.pathname.split('/-/blob/')[0].split('/blob/')[0];\n\n // Get gitlab relative path\n const relativePath = getGitLabIntegrationRelativePath(config);\n\n // Check relative path exist and replace it if it's the case.\n if (relativePath) {\n repo = repo.replace(relativePath, '');\n }\n\n // Remove leading slash\n return repo.replace(/^\\//, '');\n}\n"],"names":[],"mappings":";;AAuCO,SAAS,qBAAA,CACd,GAAA,EACA,MAAA,EACA,MAAA,EACiB;AAGjB,EAAA,MAAM,WAAA,GAAc,kBAAA,CAAmB,GAAA,EAAK,MAAM,CAAA;AAClD,EAAA,OAAO,OAAA,CAAQ,QAAQ,eAAA,CAAgB,GAAA,EAAK,aAAa,MAAM,CAAA,CAAE,UAAU,CAAA;AAC7E;AASO,SAAS,uBAAA,CACd,QACA,KAAA,EACqC;AACrC,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAA,MAAM,WAAA,GAAc,SAAS,MAAA,CAAO,KAAA;AACpC,EAAA,IAAI,WAAA,EAAa;AAIf,IAAA,OAAA,CAAQ,aAAA,GAAgB,UAAU,WAAW,CAAA,CAAA;AAAA,EAC/C;AAEA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB;AAKO,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