Merge pull request #4100 from backstage/freben/parseGitUrl

chore: consistent naming of parseGitUrl
This commit is contained in:
Fredrik Adelöw
2021-01-18 14:34:34 +01:00
committed by GitHub
12 changed files with 28 additions and 27 deletions
@@ -23,7 +23,7 @@ import {
readBitbucketIntegrationConfigs,
} from '@backstage/integration';
import fetch from 'cross-fetch';
import parseGitUri from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { Readable } from 'stream';
import { NotFoundError } from '../errors';
import { ReadTreeResponseFactory } from './tree';
@@ -101,8 +101,9 @@ export class BitbucketUrlReader implements UrlReader {
url: string,
options?: ReadTreeOptions,
): Promise<ReadTreeResponse> {
const gitUrl: parseGitUri.GitUrl = parseGitUri(url);
const { name: repoName, owner: project, resource, filepath } = gitUrl;
const { name: repoName, owner: project, resource, filepath } = parseGitUrl(
url,
);
const isHosted = resource === 'bitbucket.org';
@@ -142,7 +143,7 @@ export class BitbucketUrlReader implements UrlReader {
}
private async getLastCommitShortHash(url: string): Promise<String> {
const { name: repoName, owner: project, ref } = parseGitUri(url);
const { name: repoName, owner: project, ref } = parseGitUrl(url);
let branch = ref;
if (!branch) {
@@ -21,7 +21,7 @@ import {
GithubCredentialsProvider,
} from '@backstage/integration';
import fetch from 'cross-fetch';
import parseGitUri from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { Readable } from 'stream';
import { InputError, NotFoundError } from '../errors';
import { ReadTreeResponseFactory } from './tree';
@@ -105,7 +105,7 @@ export class GithubUrlReader implements UrlReader {
resource,
full_name,
filepath,
} = parseGitUri(url);
} = parseGitUrl(url);
if (!ref) {
// TODO(Rugvip): We should add support for defaulting to the default branch
@@ -29,7 +29,7 @@ import {
ReadTreeResponse,
UrlReader,
} from './types';
import parseGitUri from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { Readable } from 'stream';
export class GitlabUrlReader implements UrlReader {
@@ -85,7 +85,7 @@ export class GitlabUrlReader implements UrlReader {
resource,
full_name,
filepath,
} = parseGitUri(url);
} = parseGitUrl(url);
if (!ref) {
throw new InputError(
@@ -15,7 +15,7 @@
*/
import { Logger } from 'winston';
import parseGitUri from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import {
AnalyzeLocationRequest,
AnalyzeLocationResponse,
@@ -31,7 +31,7 @@ export class RepoLocationAnalyzer implements LocationAnalyzer {
async analyzeLocation(
request: AnalyzeLocationRequest,
): Promise<AnalyzeLocationResponse> {
const { owner, name, source } = parseGitUri(request.location.target);
const { owner, name, source } = parseGitUrl(request.location.target);
const entity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
@@ -20,7 +20,7 @@ import * as codeowners from 'codeowners-utils';
import { CodeOwnersEntry } from 'codeowners-utils';
// NOTE: This can be removed when ES2021 is implemented
import 'core-js/features/promise';
import parseGitUri from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { filter, get, head, pipe, reverse } from 'lodash/fp';
import { Logger } from 'winston';
import { CatalogProcessor } from './types';
@@ -123,7 +123,7 @@ export function buildCodeOwnerUrl(
basePath: string,
codeOwnersPath: string,
): string {
return buildUrl({ ...parseGitUri(basePath), codeOwnersPath });
return buildUrl({ ...parseGitUrl(basePath), codeOwnersPath });
}
export function parseCodeOwners(ownersText: string) {
+2 -2
View File
@@ -14,12 +14,12 @@
* limitations under the License.
*/
import parseGitUri from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
export type UrlType = 'file' | 'tree';
export function urlType(url: string): UrlType {
const { filepathtype, filepath } = parseGitUri(url);
const { filepathtype, filepath } = parseGitUrl(url);
if (filepathtype === 'tree' || filepathtype === 'file') {
return filepathtype;
@@ -18,7 +18,7 @@ import * as YAML from 'yaml';
import { useApi, configApiRef } from '@backstage/core';
import { catalogImportApiRef } from '../api/CatalogImportApi';
import { ConfigSpec } from '../components/ImportComponentPage';
import parseGitUri from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
// TODO: (O5ten) Refactor into a core API instead of direct usage like this
// https://github.com/backstage/backstage/pull/3613#issuecomment-7408929430
@@ -33,7 +33,7 @@ export function useGithubRepos() {
name: repoName,
owner: ownerName,
resource: hostname,
} = parseGitUri(selectedRepo.location);
} = parseGitUrl(selectedRepo.location);
const configs = readGitHubIntegrationConfigs(
config.getOptionalConfigArray('integrations.github') ?? [],
@@ -15,7 +15,7 @@
*/
import { LocationSpec } from '@backstage/catalog-model';
import gitUrlParse from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
/**
* Creates the edit link for components yaml file
@@ -26,7 +26,7 @@ import gitUrlParse from 'git-url-parse';
export const createEditLink = (location: LocationSpec): string | undefined => {
try {
const urlData = gitUrlParse(location.target);
const urlData = parseGitUrl(location.target);
const url = new URL(location.target);
switch (location.type) {
case 'github':
@@ -64,7 +64,7 @@ export const createEditLink = (location: LocationSpec): string | undefined => {
* @returns string representing type of icon to be used
*/
export const determineUrlType = (url: string): string => {
const urlData = gitUrlParse(url);
const urlData = parseGitUrl(url);
if (urlData.source === 'github.com') {
return 'github';
@@ -20,7 +20,7 @@ import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
import { parseLocationAnnotation } from '../helpers';
import { InputError, Git } from '@backstage/backend-common';
import { PreparerBase, PreparerOptions } from './types';
import GitUriParser from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { Config } from '@backstage/config';
export class AzurePreparer implements PreparerBase {
@@ -46,7 +46,7 @@ export class AzurePreparer implements PreparerBase {
}
const templateId = template.metadata.name;
const parsedGitLocation = GitUriParser(location);
const parsedGitLocation = parseGitUrl(location);
const repositoryCheckoutUrl = parsedGitLocation.toString('https');
const tempDir = await fs.promises.mkdtemp(
path.join(workingDirectory, templateId),
@@ -20,7 +20,7 @@ import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
import { parseLocationAnnotation } from '../helpers';
import { InputError, Git } from '@backstage/backend-common';
import { PreparerBase, PreparerOptions } from './types';
import GitUriParser from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import { Config } from '@backstage/config';
export class BitbucketPreparer implements PreparerBase {
@@ -49,7 +49,7 @@ export class BitbucketPreparer implements PreparerBase {
}
const templateId = template.metadata.name;
const repo = GitUriParser(location);
const repo = parseGitUrl(location);
const repositoryCheckoutUrl = repo.toString('https');
const tempDir = await fs.promises.mkdtemp(
@@ -20,7 +20,7 @@ import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
import { parseLocationAnnotation } from '../helpers';
import { InputError, Git } from '@backstage/backend-common';
import { PreparerBase, PreparerOptions } from './types';
import GitUriParser from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
export class GithubPreparer implements PreparerBase {
token?: string;
@@ -44,7 +44,7 @@ export class GithubPreparer implements PreparerBase {
}
const templateId = template.metadata.name;
const parsedGitLocation = GitUriParser(location);
const parsedGitLocation = parseGitUrl(location);
const repositoryCheckoutUrl = parsedGitLocation.toString('https');
const tempDir = await fs.promises.mkdtemp(
path.join(workingDirectory, templateId),
@@ -21,7 +21,7 @@ import {
readGitLabIntegrationConfigs,
} from '@backstage/integration';
import fs from 'fs-extra';
import GitUriParser from 'git-url-parse';
import parseGitUrl from 'git-url-parse';
import os from 'os';
import path from 'path';
import { parseLocationAnnotation } from '../helpers';
@@ -55,7 +55,7 @@ export class GitlabPreparer implements PreparerBase {
}
const templateId = template.metadata.name;
const parsedGitLocation = GitUriParser(location);
const parsedGitLocation = parseGitUrl(location);
const repositoryCheckoutUrl = parsedGitLocation.toString('https');
const tempDir = await fs.promises.mkdtemp(
path.join(workingDirectory, templateId),