Go back to using node-fetch for gitlab

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-12-23 12:50:36 +01:00
parent f8e386f40d
commit 575613f560
5 changed files with 23 additions and 2 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-catalog-backend-module-gitlab': patch
'@backstage/backend-defaults': patch
---
Go back to using `node-fetch` for gitlab
@@ -14,6 +14,9 @@
* limitations under the License.
*/
// NOTE(freben): Intentionally uses node-fetch because of https://github.com/backstage/backstage/issues/28190
import fetch, { Response } from 'node-fetch';
import {
UrlReaderService,
UrlReaderServiceReadTreeOptions,
@@ -34,8 +37,10 @@ import {
import parseGitUrl from 'git-url-parse';
import { trimEnd, trimStart } from 'lodash';
import { Minimatch } from 'minimatch';
import { Readable } from 'stream';
import { ReadUrlResponseFactory } from './ReadUrlResponseFactory';
import { ReadTreeResponseFactory, ReaderFactory } from './types';
import { parseLastModified } from './util';
/**
* Implements a {@link @backstage/backend-plugin-api#UrlReaderService} for files on GitLab.
@@ -98,7 +103,12 @@ export class GitlabUrlReader implements UrlReaderService {
}
if (response.ok) {
return ReadUrlResponseFactory.fromResponse(response);
return ReadUrlResponseFactory.fromNodeJSReadable(response.body, {
etag: response.headers.get('ETag') ?? undefined,
lastModifiedAt: parseLastModified(
response.headers.get('Last-Modified'),
),
});
}
const message = `${url} could not be read as ${builtUrl}, ${response.status} ${response.statusText}`;
@@ -220,7 +230,7 @@ export class GitlabUrlReader implements UrlReaderService {
}
return await this.deps.treeResponseFactory.fromTarArchive({
response: archiveGitLabResponse,
stream: Readable.from(archiveGitLabResponse.body),
subpath: filepath,
etag: commitSha,
filter: options?.filter,
@@ -61,6 +61,7 @@
"@backstage/plugin-events-node": "workspace:^",
"@gitbeaker/rest": "^40.0.3",
"lodash": "^4.17.21",
"node-fetch": "^2.7.0",
"uuid": "^11.0.0"
},
"devDependencies": {
@@ -14,6 +14,9 @@
* limitations under the License.
*/
// NOTE(freben): Intentionally uses node-fetch because of https://github.com/backstage/backstage/issues/28190
import fetch from 'node-fetch';
import {
getGitLabRequestOptions,
GitLabIntegrationConfig,
+1
View File
@@ -5643,6 +5643,7 @@ __metadata:
lodash: ^4.17.21
luxon: ^3.0.0
msw: ^1.0.0
node-fetch: ^2.7.0
uuid: ^11.0.0
languageName: unknown
linkType: soft