Fix GitHub OAuth format (#3036)

* Fix GitHub OAuth format

* Fix extraction of apiBaseUrl from config

* Add 'x-oauth-basic' as password
This commit is contained in:
Sachin Tewari
2020-10-22 20:14:53 +05:30
committed by GitHub
parent 06df0eba4c
commit df94d7edda
2 changed files with 11 additions and 11 deletions
@@ -51,8 +51,14 @@ interface IGitlabBranch {
function getGithubApiUrl(config: Config, url: string): URL {
const { protocol, owner, name } = parseGitUrl(url);
const providerConfigs =
config.getOptionalConfigArray('integrations.github') ?? [];
// TODO: Maybe we need to filter by host in the array, not sure about GHE
const targetProviderConfig = providerConfigs[0];
const apiBaseUrl =
config.getOptionalString('integrations.github.apiBaseUrl') ||
targetProviderConfig?.getOptionalString('integrations.github.apiBaseUrl') ??
'api.github.com';
const apiRepos = 'repos';
+4 -10
View File
@@ -20,7 +20,7 @@ import parseGitUrl from 'git-url-parse';
import NodeGit, { Clone, Repository } from 'nodegit';
import fs from 'fs-extra';
import { getDefaultBranch } from './default-branch';
import { getTokenForGitRepo } from './git-auth';
import { getGitRepoType, getTokenForGitRepo } from './git-auth';
import { Entity } from '@backstage/catalog-model';
import { InputError } from '@backstage/backend-common';
import { RemoteProtocol } from './techdocs/stages/prepare/types';
@@ -121,14 +121,6 @@ export const checkoutGitRepository = async (
): Promise<string> => {
const parsedGitLocation = parseGitUrl(repoUrl);
const repositoryTmpPath = await getGitRepositoryTempFolder(repoUrl);
// TODO: Should propably not be hardcoded names of env variables, but seems too hard to access config down here
const user =
process.env.GITHUB_PRIVATE_TOKEN_USER ||
process.env.GITLAB_PRIVATE_TOKEN_USER ||
process.env.AZURE_PRIVATE_TOKEN_USER ||
'';
const token = await getTokenForGitRepo(repoUrl);
if (fs.existsSync(repositoryTmpPath)) {
@@ -152,7 +144,9 @@ export const checkoutGitRepository = async (
}
if (token) {
parsedGitLocation.token = `${user}:${token}`;
const type = getGitRepoType(repoUrl);
const auth = type === 'github' ? `${token}:x-oauth-basic` : `:${token}`;
parsedGitLocation.token = auth;
}
const repositoryCheckoutUrl = parsedGitLocation.toString('https');