chore(catalog-backend): updating to use msw + cross-fetch

This commit is contained in:
blam
2020-10-08 22:38:06 +02:00
parent 813504018e
commit d30ef3924b
6 changed files with 19 additions and 23 deletions
+4 -6
View File
@@ -23,10 +23,8 @@
"@backstage/backend-common": "^0.1.1-alpha.24",
"@backstage/catalog-model": "^0.1.1-alpha.24",
"@backstage/config": "^0.1.1-alpha.24",
"@backstage/test-utils": "^0.1.1-alpha.24",
"@octokit/graphql": "^4.5.6",
"@types/express": "^4.17.6",
"@types/node-fetch": "^2.5.7",
"codeowners-utils": "^1.0.2",
"core-js": "^3.6.5",
"express": "^4.17.1",
@@ -36,8 +34,8 @@
"knex": "^0.21.1",
"ldapjs": "^2.2.0",
"lodash": "^4.17.15",
"cross-fetch": "^3.0.6",
"morgan": "^1.10.0",
"node-fetch": "^2.6.0",
"sqlite3": "^5.0.0",
"uuid": "^8.0.0",
"winston": "^3.2.1",
@@ -54,9 +52,9 @@
"@types/supertest": "^2.0.8",
"@types/uuid": "^8.0.0",
"@types/yup": "^0.28.2",
"jest-fetch-mock": "^3.0.3",
"msw": "^0.20.5",
"supertest": "^4.0.2"
"@backstage/test-utils": "^0.1.1-alpha.24",
"supertest": "^4.0.2",
"msw": "^0.21.2"
},
"files": [
"dist",
@@ -15,7 +15,7 @@
*/
import { LocationSpec } from '@backstage/catalog-model';
import fetch, { RequestInit, HeadersInit } from 'node-fetch';
import fetch from 'cross-fetch';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { Config } from '@backstage/config';
@@ -44,11 +44,9 @@ export class AzureApiReaderProcessor implements LocationProcessor {
).toString('base64')}`;
}
const requestOptions: RequestInit = {
return {
headers,
};
return requestOptions;
}
async readLocation(
@@ -67,7 +65,7 @@ export class AzureApiReaderProcessor implements LocationProcessor {
// for private repos when PAT is not valid, Azure API returns a http status code 203 with sign in page html
if (response.ok && response.status !== 203) {
const data = await response.buffer();
const data = Buffer.from(await response.text());
emit(result.data(location, data));
} else {
const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`;
@@ -15,7 +15,7 @@
*/
import { LocationSpec } from '@backstage/catalog-model';
import fetch, { RequestInit, HeadersInit } from 'node-fetch';
import fetch from 'cross-fetch';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { Config } from '@backstage/config';
@@ -70,8 +70,8 @@ export class BitbucketApiReaderProcessor implements LocationProcessor {
const response = await fetch(url.toString(), this.getRequestOptions());
if (response.ok) {
const data = await response.buffer();
emit(result.data(location, data));
const data = await response.text();
emit(result.data(location, Buffer.from(data)));
} else {
const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`;
if (response.status === 404) {
@@ -17,7 +17,7 @@
import { LocationSpec } from '@backstage/catalog-model';
import { Config } from '@backstage/config';
import parseGitUri from 'git-url-parse';
import fetch, { HeadersInit, RequestInit } from 'node-fetch';
import fetch from 'cross-fetch';
import { Logger } from 'winston';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
@@ -252,8 +252,8 @@ export class GithubReaderProcessor implements LocationProcessor {
const response = await fetch(url.toString(), options);
if (response.ok) {
const data = await response.buffer();
emit(result.data(location, data));
const data = await response.text();
emit(result.data(location, Buffer.from(data)));
} else {
const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`;
if (response.status === 404) {
@@ -15,7 +15,7 @@
*/
import { LocationSpec } from '@backstage/catalog-model';
import fetch, { RequestInit, HeadersInit } from 'node-fetch';
import fetch from 'cross-fetch';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
import { Config } from '@backstage/config';
@@ -61,8 +61,8 @@ export class GitlabApiReaderProcessor implements LocationProcessor {
const url = this.buildRawUrl(location.target, projectID);
const response = await fetch(url.toString(), this.getRequestOptions());
if (response.ok) {
const data = await response.buffer();
emit(result.data(location, data));
const data = await response.text();
emit(result.data(location, Buffer.from(data)));
} else {
const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`;
if (response.status === 404) {
@@ -15,7 +15,7 @@
*/
import { LocationSpec } from '@backstage/catalog-model';
import fetch from 'node-fetch';
import fetch from 'cross-fetch';
import * as result from './results';
import { LocationProcessor, LocationProcessorEmit } from './types';
@@ -40,8 +40,8 @@ export class GitlabReaderProcessor implements LocationProcessor {
const response = await fetch(url.toString());
if (response.ok) {
const data = await response.buffer();
emit(result.data(location, data));
const data = await response.text();
emit(result.data(location, Buffer.from(data)));
} else {
const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`;
if (response.status === 404) {