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
@@ -32,7 +32,7 @@ const mockTemplate = (): TemplateEntityV1alpha1 => ({
metadata: {
annotations: {
[LOCATION_ANNOTATION]:
'gitlab:https://gitlab.com/benjdlambert/backstage-graphql-template/-/blob/master/template.yaml',
'url:https://gitlab.com/benjdlambert/backstage-graphql-template/-/blob/master/template.yaml',
},
name: 'graphql-starter',
title: 'GraphQL Service',
@@ -19,7 +19,7 @@ import { IGitApi } from 'azure-devops-node-api/GitApi';
import { GitRepositoryCreateOptions } from 'azure-devops-node-api/interfaces/GitInterfaces';
import { initRepoAndPush } from './helpers';
import { AzureIntegrationConfig } from '@backstage/integration';
import gitUrlParse from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { getPersonalAccessTokenHandler, WebApi } from 'azure-devops-node-api';
export class AzurePublisher implements PublisherBase {
@@ -43,7 +43,7 @@ export class AzurePublisher implements PublisherBase {
directory,
logger,
}: PublisherOptions): Promise<PublisherResult> {
const { owner, name } = gitUrlParse(values.storePath);
const { owner, name } = parseGitUrl(values.storePath);
const remoteUrl = await this.createRemote({
project: owner,
@@ -18,7 +18,7 @@ import { PublisherBase, PublisherOptions, PublisherResult } from './types';
import { initRepoAndPush } from './helpers';
import fetch from 'cross-fetch';
import { BitbucketIntegrationConfig } from '@backstage/integration';
import gitUrlParse from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
// TODO(blam): We should probably start to use a bitbucket client here that we can change
// the baseURL to point at on-prem or public bitbucket versions like we do for
@@ -46,7 +46,7 @@ export class BitbucketPublisher implements PublisherBase {
directory,
logger,
}: PublisherOptions): Promise<PublisherResult> {
const { owner: project, name } = gitUrlParse(values.storePath);
const { owner: project, name } = parseGitUrl(values.storePath);
const description = values.description as string;
const result = await this.createRemote({
@@ -17,7 +17,7 @@
import { PublisherBase, PublisherOptions, PublisherResult } from './types';
import { initRepoAndPush } from './helpers';
import { GitHubIntegrationConfig } from '@backstage/integration';
import gitUrlParse from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { Octokit } from '@octokit/rest';
export type RepoVisibilityOptions = 'private' | 'internal' | 'public';
@@ -48,7 +48,7 @@ export class GithubPublisher implements PublisherBase {
directory,
logger,
}: PublisherOptions): Promise<PublisherResult> {
const { owner, name } = gitUrlParse(values.storePath);
const { owner, name } = parseGitUrl(values.storePath);
const description = values.description as string;
const access = values.access as string;
@@ -18,7 +18,7 @@ import { PublisherBase, PublisherOptions, PublisherResult } from './types';
import { Gitlab } from '@gitbeaker/node';
import { Gitlab as GitlabClient } from '@gitbeaker/core';
import { initRepoAndPush } from './helpers';
import gitUrlParse from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { GitLabIntegrationConfig } from '@backstage/integration';
@@ -28,7 +28,7 @@ export class GitlabPublisher implements PublisherBase {
return undefined;
}
const client = new Gitlab({ host: config.apiBaseUrl, token: config.token });
const client = new Gitlab({ host: config.baseUrl, token: config.token });
return new GitlabPublisher(config.token, client);
}
@@ -42,7 +42,7 @@ export class GitlabPublisher implements PublisherBase {
directory,
logger,
}: PublisherOptions): Promise<PublisherResult> {
const { owner, name } = gitUrlParse(values.storePath);
const { owner, name } = parseGitUrl(values.storePath);
const remoteUrl = await this.createRemote({
owner,
@@ -65,7 +65,7 @@ describe('createRouter - working directory', () => {
kind: 'Template',
metadata: {
annotations: {
'backstage.io/managed-by-location': 'azure:https://dev.azure.com',
'backstage.io/managed-by-location': 'url:https://dev.azure.com',
},
},
spec: {
@@ -39,7 +39,7 @@ import { rootRoute } from '../../routes';
import { JobStatusModal } from '../JobStatusModal';
import { MultistepJsonForm } from '../MultistepJsonForm';
import { useJobPolling } from '../hooks/useJobPolling';
import gitParse from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
const useTemplate = (
templateName: string,
@@ -180,22 +180,28 @@ export const TemplatePage = () => {
schema: OWNER_REPO_SCHEMA,
validate: (formData, errors) => {
const { storePath } = formData;
const parsedUrl = gitParse(storePath);
try {
const parsedUrl = parseGitUrl(storePath);
if (
!parsedUrl.resource ||
!parsedUrl.owner ||
!parsedUrl.name
) {
if (parsedUrl.resource === 'dev.azure.com') {
errors.storePath.addError(
"The store path should be formatted like https://dev.azure.com/{org}/{project}/_git/{repo} for Azure URL's",
);
} else {
errors.storePath.addError(
'The store path should be a complete Git URL to the new repository location. For example: https://github.com/{owner}/{repo}',
);
if (
!parsedUrl.resource ||
!parsedUrl.owner ||
!parsedUrl.name
) {
if (parsedUrl.resource === 'dev.azure.com') {
errors.storePath.addError(
"The store path should be formatted like https://dev.azure.com/{org}/{project}/_git/{repo} for Azure URL's",
);
} else {
errors.storePath.addError(
'The store path should be a complete Git URL to the new repository location. For example: https://github.com/{owner}/{repo}',
);
}
}
} catch (ex) {
errors.storePath.addError(
`Failed validation of the store pathn with message ${ex.message}`,
);
}
return errors;