From 83d83eb882607b90ae361fcf9f918d1fb1b5db23 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Tue, 30 Aug 2022 14:01:59 +0100 Subject: [PATCH] add fromConfig to stack overflow api Signed-off-by: Brian Fletcher --- plugins/stack-overflow/src/api/StackOverflowClient.ts | 9 +++++++++ plugins/stack-overflow/src/plugin.ts | 7 +------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/stack-overflow/src/api/StackOverflowClient.ts b/plugins/stack-overflow/src/api/StackOverflowClient.ts index ff24b658b0..609af9dfd4 100644 --- a/plugins/stack-overflow/src/api/StackOverflowClient.ts +++ b/plugins/stack-overflow/src/api/StackOverflowClient.ts @@ -21,6 +21,7 @@ import { StackOverflowQuestion, StackOverflowQuestionsRequestParams, } from '../types'; +import { Config } from '@backstage/config'; export class StackOverflowClient implements StackOverflowApi { private baseUrl: string; @@ -29,6 +30,14 @@ export class StackOverflowClient implements StackOverflowApi { this.baseUrl = baseUrl; } + static fromConfig(config: Config) { + return new StackOverflowClient({ + baseUrl: + config.getOptionalString('stackoverflow.baseUrl') || + 'https://api.stackexchange.com/2.2', + }); + } + /** * List Questions in the StackOverflow instance * diff --git a/plugins/stack-overflow/src/plugin.ts b/plugins/stack-overflow/src/plugin.ts index ea52c6844a..a837846708 100644 --- a/plugins/stack-overflow/src/plugin.ts +++ b/plugins/stack-overflow/src/plugin.ts @@ -35,12 +35,7 @@ export const stackOverflowPlugin = createPlugin({ createApiFactory({ api: stackOverflowApiRef, deps: { configApi: configApiRef }, - factory: ({ configApi }) => - new StackOverflowClient({ - baseUrl: - configApi.getOptionalString('stackoverflow.baseUrl') || - 'https://api.stackexchange.com/2.2', - }), + factory: ({ configApi }) => StackOverflowClient.fromConfig(configApi), }), ], });