TechDocs Backend: Replace hardcoded github api by configuration value (#3004)

* replace hardcoded  by configuration value

* use integrations configuration to read github apiBaseUrl

Co-authored-by: Emre Konar <emre.konar@zalando.de>
This commit is contained in:
Emre Konar
2020-10-21 11:03:05 +02:00
committed by GitHub
parent c5ef12926b
commit 22ff8fba5e
2 changed files with 10 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-backend': patch
---
Replacing the hard coded `baseApiUrl` by reading the value from configuration to enable private GitHub setup for TechDocs.
@@ -42,9 +42,11 @@ interface IGitlabBranch {
};
}
function getGithubApiUrl(url: string): URL {
function getGithubApiUrl(config: Config, url: string): URL {
const { protocol, owner, name } = parseGitUrl(url);
const apiBaseUrl = 'api.github.com';
const apiBaseUrl =
config.getOptionalString('integrations.github.apiBaseUrl') ||
'api.github.com';
const apiRepos = 'repos';
return new URL(`${protocol}://${apiBaseUrl}/${apiRepos}/${owner}/${name}`);
@@ -133,7 +135,7 @@ async function getGithubDefaultBranch(
repositoryUrl: string,
config: Config,
): Promise<string> {
const path = getGithubApiUrl(repositoryUrl).toString();
const path = getGithubApiUrl(config, repositoryUrl).toString();
const options = getGithubRequestOptions(config);
try {