From 7095e8bc03ccbc05551d1f38563ce2e0b9fd9aea Mon Sep 17 00:00:00 2001 From: Alisson Fabiano Date: Fri, 14 Oct 2022 11:47:16 +0100 Subject: [PATCH 1/4] Fixed bug that when sending data by Post Signed-off-by: Alisson Fabiano --- .changeset/brown-days-pretend.md | 5 +++++ plugins/tech-insights/src/api/TechInsightsClient.ts | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/brown-days-pretend.md diff --git a/.changeset/brown-days-pretend.md b/.changeset/brown-days-pretend.md new file mode 100644 index 0000000000..5f45349a55 --- /dev/null +++ b/.changeset/brown-days-pretend.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-tech-insights': minor +--- + +Fixed bug that when sending data by Post, the default context type used was `plain/text` diff --git a/plugins/tech-insights/src/api/TechInsightsClient.ts b/plugins/tech-insights/src/api/TechInsightsClient.ts index 9bdeb119f9..afd214d581 100644 --- a/plugins/tech-insights/src/api/TechInsightsClient.ts +++ b/plugins/tech-insights/src/api/TechInsightsClient.ts @@ -82,6 +82,9 @@ export class TechInsightsClient implements TechInsightsApi { { method: 'POST', body: JSON.stringify(requestBody), + headers: { + 'Content-Type': 'application/json', + }, }, ); } @@ -98,6 +101,9 @@ export class TechInsightsClient implements TechInsightsApi { return this.api('/checks/run', { method: 'POST', body: JSON.stringify(requestBody), + headers: { + 'Content-Type': 'application/json', + }, }); } From d7f7f6faac34ccc7749ee1c76cc2cc63ffc3e9fb Mon Sep 17 00:00:00 2001 From: Alisson Fabiano Date: Fri, 14 Oct 2022 11:51:42 +0100 Subject: [PATCH 2/4] Adjust description changeset Signed-off-by: Alisson Fabiano --- .changeset/brown-days-pretend.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/brown-days-pretend.md b/.changeset/brown-days-pretend.md index 5f45349a55..de4363e5aa 100644 --- a/.changeset/brown-days-pretend.md +++ b/.changeset/brown-days-pretend.md @@ -2,4 +2,4 @@ '@backstage/plugin-tech-insights': minor --- -Fixed bug that when sending data by Post, the default context type used was `plain/text` +Fixed bug when sending data by Post in `runChecks` and `runBulkChecks` functions of the `TechInsightsClient` class, the default `Content-Type` used was `plain/text` From e8cb790b1f5a4f9ecde132d6ec0d60811a8a0886 Mon Sep 17 00:00:00 2001 From: alissonfabiano <56898864+alissonfabiano@users.noreply.github.com> Date: Mon, 17 Oct 2022 18:45:43 +0100 Subject: [PATCH 3/4] Update .changeset/brown-days-pretend.md Co-authored-by: Johan Haals Signed-off-by: alissonfabiano <56898864+alissonfabiano@users.noreply.github.com> --- .changeset/brown-days-pretend.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/brown-days-pretend.md b/.changeset/brown-days-pretend.md index de4363e5aa..4b6a328724 100644 --- a/.changeset/brown-days-pretend.md +++ b/.changeset/brown-days-pretend.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-tech-insights': minor +'@backstage/plugin-tech-insights': patch --- Fixed bug when sending data by Post in `runChecks` and `runBulkChecks` functions of the `TechInsightsClient` class, the default `Content-Type` used was `plain/text` From b8d4ab0e12a810b0f0e330575878421c604ab4be Mon Sep 17 00:00:00 2001 From: Alisson Fabiano Date: Wed, 19 Oct 2022 10:40:28 +0100 Subject: [PATCH 4/4] fixed reading headers Signed-off-by: Alisson Fabiano --- .../src/api/TechInsightsClient.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/tech-insights/src/api/TechInsightsClient.ts b/plugins/tech-insights/src/api/TechInsightsClient.ts index afd214d581..6e85769b34 100644 --- a/plugins/tech-insights/src/api/TechInsightsClient.ts +++ b/plugins/tech-insights/src/api/TechInsightsClient.ts @@ -82,9 +82,6 @@ export class TechInsightsClient implements TechInsightsApi { { method: 'POST', body: JSON.stringify(requestBody), - headers: { - 'Content-Type': 'application/json', - }, }, ); } @@ -101,9 +98,6 @@ export class TechInsightsClient implements TechInsightsApi { return this.api('/checks/run', { method: 'POST', body: JSON.stringify(requestBody), - headers: { - 'Content-Type': 'application/json', - }, }); } @@ -111,14 +105,18 @@ export class TechInsightsClient implements TechInsightsApi { const url = await this.discoveryApi.getBaseUrl('tech-insights'); const { token } = await this.identityApi.getCredentials(); - const request = new Request(`${url}${path}`, init); - if (!request.headers.has('content-type')) { - request.headers.set('content-type', 'application/json'); - } - if (token && !request.headers.has('authorization')) { - request.headers.set('authorization', `Bearer ${token}`); + const headers: HeadersInit = new Headers(init?.headers); + if (!headers.has('content-type')) + headers.set('content-type', 'application/json'); + if (token && !headers.has('authorization')) { + headers.set('authorization', `Bearer ${token}`); } + const request = new Request(`${url}${path}`, { + ...init, + headers, + }); + return fetch(request).then(async response => { if (!response.ok) { throw await ResponseError.fromResponse(response);