@backstage/integration 1.17.0-next.3 → 1.17.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/dist/gitlab/core.cjs.js +14 -13
- package/dist/gitlab/core.cjs.js.map +1 -1
- package/dist/gitlab/core.esm.js +14 -13
- package/dist/gitlab/core.esm.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @backstage/integration
|
|
2
2
|
|
|
3
|
+
## 1.17.1-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e0189b8: UrlReader: Fix handling of access tokens for GitLab readURL requests
|
|
8
|
+
- d1e4a6d: Fixed bug where the GitLab user token and GitLab integration token were being merged together
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @backstage/config@1.3.2
|
|
11
|
+
- @backstage/errors@1.2.7
|
|
12
|
+
|
|
13
|
+
## 1.17.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- d945206: Added support for federated credentials using managed identities in the Azure DevOps integration. Federated credentials are only available for Azure DevOps organizations that have been configured to use Entra ID for authentication.
|
|
18
|
+
|
|
19
|
+
```diff
|
|
20
|
+
integrations:
|
|
21
|
+
azure:
|
|
22
|
+
- host: dev.azure.com
|
|
23
|
+
credentials:
|
|
24
|
+
+ - clientId: ${APP_REGISTRATION_CLIENT_ID}
|
|
25
|
+
+ managedIdentityClientId: system-assigned
|
|
26
|
+
+ tenantId: ${AZURE_TENANT_ID}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This also adds support for automatically using the system-assigned managed identity of an Azure resource by specifying `system-assigned` as the client ID of the managed identity.
|
|
30
|
+
|
|
31
|
+
```diff
|
|
32
|
+
integrations:
|
|
33
|
+
azure:
|
|
34
|
+
- host: dev.azure.com
|
|
35
|
+
credentials:
|
|
36
|
+
- - clientId: ${AZURE_CLIENT_ID}
|
|
37
|
+
+ - clientId: system-assigned
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- f134cea: Implement Edit URL feature for Gerrit 3.9+.
|
|
41
|
+
|
|
42
|
+
It's possible to disable the edit url by adding the `disableEditUrl: true` config in the Gerrit integration.
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- f3381d3: Added missing `organizations` property to `azure` section in `config.d.ts` file
|
|
47
|
+
- acea1d4: update documentation
|
|
48
|
+
- Updated dependencies
|
|
49
|
+
- @backstage/config@1.3.2
|
|
50
|
+
- @backstage/errors@1.2.7
|
|
51
|
+
|
|
3
52
|
## 1.17.0-next.3
|
|
4
53
|
|
|
5
54
|
### Minor Changes
|
package/dist/gitlab/core.cjs.js
CHANGED
|
@@ -7,21 +7,17 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
7
7
|
|
|
8
8
|
var fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
|
|
9
9
|
|
|
10
|
-
async function getGitLabFileFetchUrl(url, config) {
|
|
11
|
-
const projectID = await getProjectId(url, config);
|
|
10
|
+
async function getGitLabFileFetchUrl(url, config, token) {
|
|
11
|
+
const projectID = await getProjectId(url, config, token);
|
|
12
12
|
return buildProjectUrl(url, projectID, config).toString();
|
|
13
13
|
}
|
|
14
14
|
function getGitLabRequestOptions(config, token) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
15
|
+
const headers = {};
|
|
16
|
+
const accessToken = token || config.token;
|
|
17
|
+
if (accessToken) {
|
|
18
|
+
headers.Authorization = `Bearer ${accessToken}`;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
headers: { "PRIVATE-TOKEN": configToken }
|
|
24
|
-
};
|
|
20
|
+
return { headers };
|
|
25
21
|
}
|
|
26
22
|
function buildProjectUrl(target, projectID, config$1) {
|
|
27
23
|
try {
|
|
@@ -43,7 +39,7 @@ function buildProjectUrl(target, projectID, config$1) {
|
|
|
43
39
|
throw new Error(`Incorrect url: ${target}, ${e}`);
|
|
44
40
|
}
|
|
45
41
|
}
|
|
46
|
-
async function getProjectId(target, config$1) {
|
|
42
|
+
async function getProjectId(target, config$1, token) {
|
|
47
43
|
const url = new URL(target);
|
|
48
44
|
if (!url.pathname.includes("/blob/")) {
|
|
49
45
|
throw new Error(
|
|
@@ -63,10 +59,15 @@ async function getProjectId(target, config$1) {
|
|
|
63
59
|
);
|
|
64
60
|
const response = await fetch__default.default(
|
|
65
61
|
repoIDLookup.toString(),
|
|
66
|
-
getGitLabRequestOptions(config$1)
|
|
62
|
+
getGitLabRequestOptions(config$1, token)
|
|
67
63
|
);
|
|
68
64
|
const data = await response.json();
|
|
69
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
|
+
}
|
|
70
71
|
throw new Error(
|
|
71
72
|
`GitLab Error '${data.error}', ${data.error_description}`
|
|
72
73
|
);
|
|
@@ -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 fetch from 'cross-fetch';\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/projectId/repository/c.yaml?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/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n): Promise<string> {\n const projectID = await getProjectId(url, config);\n return buildProjectUrl(url, projectID, 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 if (
|
|
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 fetch from 'cross-fetch';\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/projectId/repository/c.yaml?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/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<string> {\n const projectID = await getProjectId(url, config, token);\n return buildProjectUrl(url, projectID, 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/projectId/repository/files/filepath?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectID: 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 url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectID,\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// Convert\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: The project ID that corresponds to the URL\nexport async function getProjectId(\n target: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<number> {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed converting ${url.pathname} to a project id. Url path must include /blob/.`,\n );\n }\n\n try {\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 // Convert\n // to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FsubgroupA%2FteamA%2Frepo\n const repoIDLookup = new URL(\n `${url.origin}${relativePath}/api/v4/projects/${encodeURIComponent(\n repo.replace(/^\\//, ''),\n )}`,\n );\n\n const response = await fetch(\n repoIDLookup.toString(),\n getGitLabRequestOptions(config, token),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n if (response.status === 401) {\n throw new Error(\n 'GitLab Error: 401 - Unauthorized. The access token used is either expired, or does not have permission to read the project',\n );\n }\n\n throw new Error(\n `GitLab Error '${data.error}', ${data.error_description}`,\n );\n }\n\n return Number(data.id);\n } catch (e) {\n throw new Error(`Could not get GitLab project ID for: ${target}, ${e}`);\n }\n}\n"],"names":["config","getGitLabIntegrationRelativePath","fetch"],"mappings":";;;;;;;;;AAuCsB,eAAA,qBAAA,CACpB,GACA,EAAA,MAAA,EACA,KACiB,EAAA;AACjB,EAAA,MAAM,SAAY,GAAA,MAAM,YAAa,CAAA,GAAA,EAAK,QAAQ,KAAK,CAAA;AACvD,EAAA,OAAO,eAAgB,CAAA,GAAA,EAAK,SAAW,EAAA,MAAM,EAAE,QAAS,EAAA;AAC1D;AASgB,SAAA,uBAAA,CACd,QACA,KACqC,EAAA;AACrC,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAM,MAAA,WAAA,GAAc,SAAS,MAAO,CAAA,KAAA;AACpC,EAAA,IAAI,WAAa,EAAA;AAIf,IAAQ,OAAA,CAAA,aAAA,G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CAAE,CAAA,CAAA;AAAA;AAE1E;;;;;;;"}
|
package/dist/gitlab/core.esm.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import fetch from 'cross-fetch';
|
|
2
2
|
import { getGitLabIntegrationRelativePath } from './config.esm.js';
|
|
3
3
|
|
|
4
|
-
async function getGitLabFileFetchUrl(url, config) {
|
|
5
|
-
const projectID = await getProjectId(url, config);
|
|
4
|
+
async function getGitLabFileFetchUrl(url, config, token) {
|
|
5
|
+
const projectID = await getProjectId(url, config, token);
|
|
6
6
|
return buildProjectUrl(url, projectID, config).toString();
|
|
7
7
|
}
|
|
8
8
|
function getGitLabRequestOptions(config, token) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
9
|
+
const headers = {};
|
|
10
|
+
const accessToken = token || config.token;
|
|
11
|
+
if (accessToken) {
|
|
12
|
+
headers.Authorization = `Bearer ${accessToken}`;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
headers: { "PRIVATE-TOKEN": configToken }
|
|
18
|
-
};
|
|
14
|
+
return { headers };
|
|
19
15
|
}
|
|
20
16
|
function buildProjectUrl(target, projectID, config) {
|
|
21
17
|
try {
|
|
@@ -37,7 +33,7 @@ function buildProjectUrl(target, projectID, config) {
|
|
|
37
33
|
throw new Error(`Incorrect url: ${target}, ${e}`);
|
|
38
34
|
}
|
|
39
35
|
}
|
|
40
|
-
async function getProjectId(target, config) {
|
|
36
|
+
async function getProjectId(target, config, token) {
|
|
41
37
|
const url = new URL(target);
|
|
42
38
|
if (!url.pathname.includes("/blob/")) {
|
|
43
39
|
throw new Error(
|
|
@@ -57,10 +53,15 @@ async function getProjectId(target, config) {
|
|
|
57
53
|
);
|
|
58
54
|
const response = await fetch(
|
|
59
55
|
repoIDLookup.toString(),
|
|
60
|
-
getGitLabRequestOptions(config)
|
|
56
|
+
getGitLabRequestOptions(config, token)
|
|
61
57
|
);
|
|
62
58
|
const data = await response.json();
|
|
63
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
|
+
}
|
|
64
65
|
throw new Error(
|
|
65
66
|
`GitLab Error '${data.error}', ${data.error_description}`
|
|
66
67
|
);
|
|
@@ -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 fetch from 'cross-fetch';\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/projectId/repository/c.yaml?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/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n): Promise<string> {\n const projectID = await getProjectId(url, config);\n return buildProjectUrl(url, projectID, 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 if (
|
|
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 fetch from 'cross-fetch';\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/projectId/repository/c.yaml?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/projectId/repository/files/filepath?ref=branch\n *\n * @param url - A URL pointing to a file\n * @param config - The relevant provider config\n * @public\n */\nexport async function getGitLabFileFetchUrl(\n url: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<string> {\n const projectID = await getProjectId(url, config, token);\n return buildProjectUrl(url, projectID, 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/projectId/repository/files/filepath?ref=branch\nexport function buildProjectUrl(\n target: string,\n projectID: 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 url.pathname = [\n ...(relativePath ? [relativePath] : []),\n 'api/v4/projects',\n projectID,\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// Convert\n// from: https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n// to: The project ID that corresponds to the URL\nexport async function getProjectId(\n target: string,\n config: GitLabIntegrationConfig,\n token?: string,\n): Promise<number> {\n const url = new URL(target);\n\n if (!url.pathname.includes('/blob/')) {\n throw new Error(\n `Failed converting ${url.pathname} to a project id. Url path must include /blob/.`,\n );\n }\n\n try {\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 // Convert\n // to: https://gitlab.com/api/v4/projects/groupA%2Fteams%2FsubgroupA%2FteamA%2Frepo\n const repoIDLookup = new URL(\n `${url.origin}${relativePath}/api/v4/projects/${encodeURIComponent(\n repo.replace(/^\\//, ''),\n )}`,\n );\n\n const response = await fetch(\n repoIDLookup.toString(),\n getGitLabRequestOptions(config, token),\n );\n\n const data = await response.json();\n\n if (!response.ok) {\n if (response.status === 401) {\n throw new Error(\n 'GitLab Error: 401 - Unauthorized. The access token used is either expired, or does not have permission to read the project',\n );\n }\n\n throw new Error(\n `GitLab Error '${data.error}', ${data.error_description}`,\n );\n }\n\n return Number(data.id);\n } catch (e) {\n throw new Error(`Could not get GitLab project ID for: ${target}, ${e}`);\n }\n}\n"],"names":[],"mappings":";;;AAuCsB,eAAA,qBAAA,CACpB,GACA,EAAA,MAAA,EACA,KACiB,EAAA;AACjB,EAAA,MAAM,SAAY,GAAA,MAAM,YAAa,CAAA,GAAA,EAAK,QAAQ,KAAK,CAAA;AACvD,EAAA,OAAO,eAAgB,CAAA,GAAA,EAAK,SAAW,EAAA,MAAM,EAAE,QAAS,EAAA;AAC1D;AASgB,SAAA,uBAAA,CACd,QACA,KACqC,EAAA;AACrC,EAAA,MAAM,UAAkC,EAAC;AAEzC,EAAM,MAAA,WAAA,GAAc,SAAS,MAAO,CAAA,KAAA;AACpC,EAAA,IAAI,WAAa,EAAA;AAIf,IAAQ,OAAA,CAAA,aAAA,GAAgB,UAAU,WAAW,CAAA,CAAA;AAAA;AAG/C,EAAA,OAAO,EAAE,OAAQ,EAAA;AACnB;AAKgB,SAAA,eAAA,CACd,MACA,EAAA,SAAA,EACA,MACK,EAAA;AACL,EAAI,IAAA;AACF,IAAM,MAAA,GAAA,GAAM,IAAI,GAAA,CAAI,MAAM,CAAA;AAE1B,IAAM,MAAA,iBAAA,GAAoB,GAAI,CAAA,QAAA,CAC3B,KAAM,CAAA,QAAQ,EACd,KAAM,CAAA,CAAC,CACP,CAAA,IAAA,CAAK,QAAQ,CAAA;AAChB,IAAA,MAAM,CAAC,MAAQ,EAAA,GAAG,QAAQ,CAAI,GAAA,iBAAA,CAAkB,MAAM,GAAG,CAAA;AACzD,IAAM,MAAA,YAAA,GAAe,iCAAiC,MAAM,CAAA;AAE5D,IAAA,GAAA,CAAI,QAAW,GAAA;AAAA,MACb,GAAI,Y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AAA,KAAA,EAAO,EAAE;AAAA,OACvB,CAAA;AAAA,KACH;AAEA,IAAA,MAAM,WAAW,MAAM,KAAA;AAAA,MACrB,aAAa,QAAS,EAAA;AAAA,MACtB,uBAAA,CAAwB,QAAQ,KAAK;AAAA,KACvC;AAEA,IAAM,MAAA,IAAA,GAAO,MAAM,QAAA,CAAS,IAAK,EAAA;AAEjC,IAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,MAAI,IAAA,QAAA,CAAS,WAAW,GAAK,EAAA;AAC3B,QAAA,MAAM,IAAI,KAAA;AAAA,UACR;AAAA,SACF;AAAA;AAGF,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAiB,cAAA,EAAA,IAAA,CAAK,KAAK,CAAA,GAAA,EAAM,KAAK,iBAAiB,CAAA;AAAA,OACzD;AAAA;AAGF,IAAO,OAAA,MAAA,CAAO,KAAK,EAAE,CAAA;AAAA,WACd,CAAG,EAAA;AACV,IAAA,MAAM,IAAI,KAAM,CAAA,CAAA,qCAAA,EAAwC,MAAM,CAAA,EAAA,EAAK,CAAC,CAAE,CAAA,CAAA;AAAA;AAE1E;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1818,7 +1818,7 @@ declare class SingleInstanceGithubCredentialsProvider implements GithubCredentia
|
|
|
1818
1818
|
* @param config - The relevant provider config
|
|
1819
1819
|
* @public
|
|
1820
1820
|
*/
|
|
1821
|
-
declare function getGitLabFileFetchUrl(url: string, config: GitLabIntegrationConfig): Promise<string>;
|
|
1821
|
+
declare function getGitLabFileFetchUrl(url: string, config: GitLabIntegrationConfig, token?: string): Promise<string>;
|
|
1822
1822
|
/**
|
|
1823
1823
|
* Gets the request options necessary to make requests to a given provider.
|
|
1824
1824
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/integration",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.1-next.0",
|
|
4
4
|
"description": "Helpers for managing integrations towards external systems",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "common-library"
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"luxon": "^3.0.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@backstage/cli": "0.
|
|
53
|
-
"@backstage/config-loader": "1.10.1
|
|
52
|
+
"@backstage/cli": "0.33.1-next.0",
|
|
53
|
+
"@backstage/config-loader": "1.10.1",
|
|
54
54
|
"@types/luxon": "^3.0.0",
|
|
55
55
|
"msw": "^1.0.0"
|
|
56
56
|
},
|