@backstage/plugin-catalog-backend-module-bitbucket-server 0.2.5-next.1 → 0.3.0-next.2
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
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-bitbucket-server
|
|
2
2
|
|
|
3
|
+
## 0.3.0-next.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3f34ea9: Throttles Bitbucket Server API calls
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @backstage/backend-plugin-api@1.1.0-next.2
|
|
13
|
+
- @backstage/errors@1.2.6-next.0
|
|
14
|
+
- @backstage/plugin-catalog-node@1.15.0-next.2
|
|
15
|
+
- @backstage/catalog-model@1.7.2-next.0
|
|
16
|
+
- @backstage/config@1.3.1-next.0
|
|
17
|
+
- @backstage/integration@1.16.0-next.1
|
|
18
|
+
|
|
3
19
|
## 0.2.5-next.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var integration = require('@backstage/integration');
|
|
4
|
+
var pThrottle = require('p-throttle');
|
|
4
5
|
|
|
6
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var pThrottle__default = /*#__PURE__*/_interopDefaultCompat(pThrottle);
|
|
9
|
+
|
|
10
|
+
const throttle = pThrottle__default.default({
|
|
11
|
+
limit: 1,
|
|
12
|
+
interval: 1e3
|
|
13
|
+
});
|
|
14
|
+
const throttledFetch = throttle(
|
|
15
|
+
async (url, options) => {
|
|
16
|
+
return await fetch(url, options);
|
|
17
|
+
}
|
|
18
|
+
);
|
|
5
19
|
class BitbucketServerClient {
|
|
6
20
|
config;
|
|
7
21
|
static fromConfig(options) {
|
|
@@ -26,14 +40,14 @@ class BitbucketServerClient {
|
|
|
26
40
|
}
|
|
27
41
|
async getFile(options) {
|
|
28
42
|
const base = new URL(this.config.apiBaseUrl);
|
|
29
|
-
return
|
|
43
|
+
return throttledFetch(
|
|
30
44
|
`${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,
|
|
31
45
|
integration.getBitbucketServerRequestOptions(this.config)
|
|
32
46
|
);
|
|
33
47
|
}
|
|
34
48
|
async getRepository(options) {
|
|
35
49
|
const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;
|
|
36
|
-
const response = await
|
|
50
|
+
const response = await throttledFetch(
|
|
37
51
|
request,
|
|
38
52
|
integration.getBitbucketServerRequestOptions(this.config)
|
|
39
53
|
);
|
|
@@ -63,16 +77,17 @@ class BitbucketServerClient {
|
|
|
63
77
|
return this.request(new Request(url.toString(), { method: "GET" }));
|
|
64
78
|
}
|
|
65
79
|
async request(req) {
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
return throttledFetch(
|
|
81
|
+
req,
|
|
82
|
+
integration.getBitbucketServerRequestOptions(this.config)
|
|
83
|
+
).then((response) => {
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`
|
|
87
|
+
);
|
|
74
88
|
}
|
|
75
|
-
|
|
89
|
+
return response;
|
|
90
|
+
});
|
|
76
91
|
}
|
|
77
92
|
}
|
|
78
93
|
async function* paginated(request, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitbucketServerClient.cjs.js","sources":["../../src/lib/BitbucketServerClient.ts"],"sourcesContent":["/*\n * Copyright 2022 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 BitbucketServerIntegrationConfig,\n getBitbucketServerRequestOptions,\n} from '@backstage/integration';\nimport { BitbucketServerProject, BitbucketServerRepository } from './types';\n\n/**\n * A client for interacting with a Bitbucket Server instance\n *\n * @public\n */\nexport class BitbucketServerClient {\n private readonly config: BitbucketServerIntegrationConfig;\n\n static fromConfig(options: {\n config: BitbucketServerIntegrationConfig;\n }): BitbucketServerClient {\n return new BitbucketServerClient(options);\n }\n\n constructor(options: { config: BitbucketServerIntegrationConfig }) {\n this.config = options.config;\n }\n\n async listProjects(options: {\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerProject>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects`,\n options.listOptions,\n );\n }\n\n async listRepositories(options: {\n projectKey: string;\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerRepository>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects/${encodeURIComponent(\n options.projectKey,\n )}/repos`,\n options.listOptions,\n );\n }\n\n async getFile(options: {\n projectKey: string;\n repo: string;\n path: string;\n }): Promise<Response> {\n const base = new URL(this.config.apiBaseUrl);\n return
|
|
1
|
+
{"version":3,"file":"BitbucketServerClient.cjs.js","sources":["../../src/lib/BitbucketServerClient.ts"],"sourcesContent":["/*\n * Copyright 2022 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 BitbucketServerIntegrationConfig,\n getBitbucketServerRequestOptions,\n} from '@backstage/integration';\nimport { BitbucketServerProject, BitbucketServerRepository } from './types';\nimport pThrottle from 'p-throttle';\n\n// 1 per second\nconst throttle = pThrottle({\n limit: 1,\n interval: 1000,\n});\n\nconst throttledFetch = throttle(\n async (url: RequestInfo, options?: RequestInit) => {\n return await fetch(url, options);\n },\n);\n\n/**\n * A client for interacting with a Bitbucket Server instance\n *\n * @public\n */\nexport class BitbucketServerClient {\n private readonly config: BitbucketServerIntegrationConfig;\n\n static fromConfig(options: {\n config: BitbucketServerIntegrationConfig;\n }): BitbucketServerClient {\n return new BitbucketServerClient(options);\n }\n\n constructor(options: { config: BitbucketServerIntegrationConfig }) {\n this.config = options.config;\n }\n\n async listProjects(options: {\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerProject>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects`,\n options.listOptions,\n );\n }\n\n async listRepositories(options: {\n projectKey: string;\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerRepository>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects/${encodeURIComponent(\n options.projectKey,\n )}/repos`,\n options.listOptions,\n );\n }\n\n async getFile(options: {\n projectKey: string;\n repo: string;\n path: string;\n }): Promise<Response> {\n const base = new URL(this.config.apiBaseUrl);\n return throttledFetch(\n `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,\n getBitbucketServerRequestOptions(this.config),\n );\n }\n\n async getRepository(options: {\n projectKey: string;\n repo: string;\n }): Promise<BitbucketServerRepository> {\n const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;\n const response = await throttledFetch(\n request,\n getBitbucketServerRequestOptions(this.config),\n );\n return response.json();\n }\n\n resolvePath(options: { projectKey: string; repo: string; path: string }): {\n path: string;\n } {\n const base = new URL(this.config.apiBaseUrl || '');\n\n return {\n path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`,\n };\n }\n\n private async pagedRequest(\n endpoint: string,\n options?: BitbucketServerListOptions,\n ): Promise<BitbucketServerPagedResponse<any>> {\n const request = new URL(endpoint);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n return this.getTypeMapped(request);\n }\n\n private async getTypeMapped<T = any>(url: URL): Promise<T> {\n return this.get(url).then((response: Response) => {\n return response.json() as Promise<T>;\n });\n }\n\n private async get(url: URL): Promise<Response> {\n return this.request(new Request(url.toString(), { method: 'GET' }));\n }\n\n private async request(req: Request): Promise<Response> {\n return throttledFetch(\n req,\n getBitbucketServerRequestOptions(this.config),\n ).then((response: Response) => {\n if (!response.ok) {\n throw new Error(\n `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`,\n );\n }\n return response;\n });\n }\n}\n\n/**\n * @public\n */\nexport type BitbucketServerListOptions = {\n [key: string]: number | undefined;\n limit?: number | undefined;\n start?: number | undefined;\n};\n\n/**\n * @public\n */\nexport type BitbucketServerPagedResponse<T> = {\n size: number;\n limit: number;\n start: number;\n isLastPage: boolean;\n values: T[];\n nextPageStart: number;\n};\n\nexport async function* paginated(\n request: (\n options: BitbucketServerListOptions,\n ) => Promise<BitbucketServerPagedResponse<any>>,\n options?: BitbucketServerListOptions,\n) {\n const opts = options || { start: 0 };\n let res;\n do {\n res = await request(opts);\n opts.start = res.nextPageStart;\n for (const item of res.values) {\n yield item;\n }\n } while (!res.isLastPage);\n}\n"],"names":["pThrottle","getBitbucketServerRequestOptions"],"mappings":";;;;;;;;;AAwBA,MAAM,WAAWA,0BAAU,CAAA;AAAA,EACzB,KAAO,EAAA,CAAA;AAAA,EACP,QAAU,E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,EAAA;AAC7C,IAAO,OAAA,IAAA,CAAK,OAAQ,CAAA,IAAI,OAAQ,CAAA,GAAA,CAAI,QAAS,EAAA,EAAG,EAAE,MAAA,EAAQ,KAAM,EAAC,CAAC,CAAA;AAAA;AACpE,EAEA,MAAc,QAAQ,GAAiC,EAAA;AACrD,IAAO,OAAA,cAAA;AAAA,MACL,GAAA;AAAA,MACAA,4CAAA,CAAiC,KAAK,MAAM;AAAA,KAC9C,CAAE,IAAK,CAAA,CAAC,QAAuB,KAAA;AAC7B,MAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAA,wBAAA,EAA2B,GAAI,CAAA,MAAM,CAAI,CAAA,EAAA,GAAA,CAAI,GAAG,CAAA,uBAAA,EAA0B,QAAS,CAAA,MAAM,CAAM,GAAA,EAAA,QAAA,CAAS,UAAU,CAAA;AAAA,SACpH;AAAA;AAEF,MAAO,OAAA,QAAA;AAAA,KACR,CAAA;AAAA;AAEL;AAuBuB,gBAAA,SAAA,CACrB,SAGA,OACA,EAAA;AACA,EAAA,MAAM,IAAO,GAAW,EAAE,KAAA,EAAO,CAAE,EAAA;AACnC,EAAI,IAAA,GAAA;AACJ,EAAG,GAAA;AACD,IAAM,GAAA,GAAA,MAAM,QAAQ,IAAI,CAAA;AACxB,IAAA,IAAA,CAAK,QAAQ,GAAI,CAAA,aAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAI,MAAQ,EAAA;AAC7B,MAAM,MAAA,IAAA;AAAA;AACR,GACF,QAAS,CAAC,GAAI,CAAA,UAAA;AAChB;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-backend-module-bitbucket-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-next.2",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "backend-plugin-module",
|
|
6
6
|
"pluginId": "catalog",
|
|
@@ -60,17 +60,18 @@
|
|
|
60
60
|
"test": "backstage-cli package test"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@backstage/backend-plugin-api": "1.1.0-next.
|
|
64
|
-
"@backstage/catalog-model": "1.7.
|
|
65
|
-
"@backstage/config": "1.3.0",
|
|
66
|
-
"@backstage/errors": "1.2.
|
|
67
|
-
"@backstage/integration": "1.16.0-next.
|
|
68
|
-
"@backstage/plugin-catalog-node": "1.15.0-next.
|
|
63
|
+
"@backstage/backend-plugin-api": "1.1.0-next.2",
|
|
64
|
+
"@backstage/catalog-model": "1.7.2-next.0",
|
|
65
|
+
"@backstage/config": "1.3.1-next.0",
|
|
66
|
+
"@backstage/errors": "1.2.6-next.0",
|
|
67
|
+
"@backstage/integration": "1.16.0-next.1",
|
|
68
|
+
"@backstage/plugin-catalog-node": "1.15.0-next.2",
|
|
69
|
+
"p-throttle": "^4.1.1",
|
|
69
70
|
"uuid": "^11.0.0"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
|
-
"@backstage/backend-test-utils": "1.2.0-next.
|
|
73
|
-
"@backstage/cli": "0.29.3-next.
|
|
73
|
+
"@backstage/backend-test-utils": "1.2.0-next.2",
|
|
74
|
+
"@backstage/cli": "0.29.3-next.2",
|
|
74
75
|
"luxon": "^3.0.0",
|
|
75
76
|
"msw": "^1.0.0"
|
|
76
77
|
},
|