From 4a6ffbf3adc3629f141b702952b9ddbf816687b7 Mon Sep 17 00:00:00 2001 From: Talita Gregory Nunes Freire Date: Wed, 27 Apr 2022 11:15:26 +0200 Subject: [PATCH] feat: add support for custom github apiBaseUrl Signed-off-by: Talita Gregory Nunes Freire --- .../src/api/useOctokitGraphQl.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins/github-pull-requests-board/src/api/useOctokitGraphQl.ts b/plugins/github-pull-requests-board/src/api/useOctokitGraphQl.ts index 2460588987..91ce559ed2 100644 --- a/plugins/github-pull-requests-board/src/api/useOctokitGraphQl.ts +++ b/plugins/github-pull-requests-board/src/api/useOctokitGraphQl.ts @@ -14,23 +14,34 @@ * limitations under the License. */ import { Octokit } from '@octokit/rest'; -import { useApi, githubAuthApiRef } from '@backstage/core-plugin-api'; +import { + useApi, + githubAuthApiRef, + configApiRef, +} from '@backstage/core-plugin-api'; +import { readGitHubIntegrationConfigs } from '@backstage/integration'; let octokit: any; export const useOctokitGraphQl = () => { const auth = useApi(githubAuthApiRef); + const config = useApi(configApiRef); + + const baseUrl = readGitHubIntegrationConfigs( + config.getOptionalConfigArray('providers.github') ?? [], + )[0].apiBaseUrl; return (path: string, options?: any): Promise => - auth.getAccessToken(['repo']) + auth + .getAccessToken(['repo']) .then((token: string) => { - if(!octokit) { - octokit = new Octokit({ auth: token }) + if (!octokit) { + octokit = new Octokit({ auth: token, ...(baseUrl && { baseUrl }) }); } - return octokit + return octokit; }) .then(octokitInstance => { - return octokitInstance.graphql(path, options) + return octokitInstance.graphql(path, options); }); };