chore: fixing some PR comments

This commit is contained in:
blam
2021-01-20 12:47:17 +01:00
parent 64826f9e2b
commit 13231e101b
10 changed files with 55 additions and 31 deletions
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import gitUrlParse from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { GithubAppConfig, GitHubIntegrationConfig } from './config';
import { createAppAuth } from '@octokit/auth-app';
import { Octokit, RestEndpointMethodTypes } from '@octokit/rest';
@@ -221,7 +221,7 @@ export class GithubCredentialsProvider {
* const { token, headers } = await getCredentials({url: 'github.com/backstage/foobar'})
*/
async getCredentials(opts: { url: string }): Promise<GithubCredentials> {
const parsed = gitUrlParse(opts.url);
const parsed = parseGitUrl(opts.url);
const owner = parsed.owner || parsed.name;
const repo = parsed.owner ? parsed.name : undefined;
@@ -31,11 +31,14 @@ describe('readGitLabIntegrationConfig', () => {
buildConfig({
host: 'a.com',
token: 't',
baseUrl: 'https://baseurl.for.me/gitlab',
}),
);
expect(output).toEqual({
host: 'a.com',
token: 't',
baseUrl: 'https://baseurl.for.me/gitlab',
});
});
@@ -43,7 +46,8 @@ describe('readGitLabIntegrationConfig', () => {
const output = readGitLabIntegrationConfig(buildConfig({}));
expect(output).toEqual({
host: 'gitlab.com',
apiBaseUrl: undefined,
apiBaseUrl: 'gitlab.com/api/v4',
baseUrl: 'https://gitlab.com',
});
});
@@ -78,6 +82,7 @@ describe('readGitLabIntegrationConfigs', () => {
expect(output).toContainEqual({
host: 'a.com',
token: 't',
baseUrl: 'https://a.com',
});
});
+15 -2
View File
@@ -18,7 +18,7 @@ import { Config } from '@backstage/config';
import { isValidHost } from '../helpers';
const GITLAB_HOST = 'gitlab.com';
const GITLAB_API_BASE_URL = 'gitlab.com/api/v4';
/**
* The configuration parameters for a single GitLab integration.
*/
@@ -29,6 +29,7 @@ export type GitLabIntegrationConfig = {
host: string;
/**
* @deprecated
* The base URL of the API of this provider, e.g. "https://gitlab.com/api/v4",
* with no trailing slash.
*
@@ -45,6 +46,14 @@ export type GitLabIntegrationConfig = {
* If no token is specified, anonymous access is used.
*/
token?: string;
/**
* The baseUrl of this provider, e.g "https://gitlab.com",
* which is passed into the gitlab client.
*
* If no baseUrl is provided, it will default to https://${host}
*/
baseUrl?: string;
};
/**
@@ -58,6 +67,7 @@ export function readGitLabIntegrationConfig(
const host = config.getOptionalString('host') ?? GITLAB_HOST;
let apiBaseUrl = config.getOptionalString('apiBaseUrl');
const token = config.getOptionalString('token');
const baseUrl = config.getOptionalString('baseUrl') ?? `https://${host}`;
if (!isValidHost(host)) {
throw new Error(
@@ -67,8 +77,11 @@ export function readGitLabIntegrationConfig(
if (apiBaseUrl) {
apiBaseUrl = apiBaseUrl.replace(/\/+$/, '');
} else if (host === GITLAB_HOST) {
apiBaseUrl = GITLAB_API_BASE_URL;
}
return { host, token, apiBaseUrl };
return { host, token, apiBaseUrl, baseUrl };
}
/**