Merge branch 'master' of github.com:backstage/backstage into blam/move-scaffolder-to-integrations

* 'master' of github.com:backstage/backstage: (75 commits)
  backend-common: Move definition of etag property inside constructor
  docs: Fix url links in well known annotations
  bitbucket casing
  integration: take over the config
  More review comments
  Address some final review coments about cross-fetch and type-casting
  chore(deps): bump sucrase from 3.16.0 to 3.17.0
  chore(deps-dev): bump @types/webpack from 4.41.22 to 4.41.26
  core-api: remove deprecated registerRoute and deprecate addRoute
  Update README
  Support GHE
  app,create-app: switch to using FlatRoutes
  Make breaking 'minor' change'
  Add codefences to changeset
  Add changeset
  Remove InfoCard :height100" variant
  scripts/check-if-release: fix diff and tweak to handle new and removed packages
  Update with review comments
  docs: Run prettier on techdocs ci/cd tutorial
  remove adr status header
  ...
This commit is contained in:
blam
2021-01-20 16:22:58 +01:00
122 changed files with 2857 additions and 1030 deletions
+56
View File
@@ -108,6 +108,62 @@ export function getAzureDownloadUrl(url: string): string {
return `${protocol}://${resource}/${organization}/${project}/_apis/git/repositories/${repoName}/items?recursionLevel=full&download=true&api-version=6.0${scopePath}`;
}
/**
* Given a URL, return the API URL to fetch commits on the branch.
*
* @param url A URL pointing to a repository or a sub-path
*/
export function getAzureCommitsUrl(url: string): string {
try {
const parsedUrl = new URL(url);
const [
empty,
userOrOrg,
project,
srcKeyword,
repoName,
] = parsedUrl.pathname.split('/');
// Remove the "GB" from "GBmain" for example.
const ref = parsedUrl.searchParams.get('version')?.substr(2);
if (
!!empty ||
!userOrOrg ||
!project ||
srcKeyword !== '_git' ||
!repoName
) {
throw new Error('Wrong Azure Devops URL');
}
// transform to commits api
parsedUrl.pathname = [
empty,
userOrOrg,
project,
'_apis',
'git',
'repositories',
repoName,
'commits',
].join('/');
const queryParams = [];
if (ref) {
queryParams.push(`searchCriteria.itemVersion.version=${ref}`);
}
parsedUrl.search = queryParams.join('&');
parsedUrl.protocol = 'https';
return parsedUrl.toString();
} catch (e) {
throw new Error(`Incorrect URL: ${url}, ${e}`);
}
}
/**
* Gets the request options necessary to make requests to a given provider.
*
+1
View File
@@ -23,4 +23,5 @@ export {
getAzureDownloadUrl,
getAzureFileFetchUrl,
getAzureRequestOptions,
getAzureCommitsUrl,
} from './core';
@@ -51,6 +51,17 @@ describe('readGitLabIntegrationConfig', () => {
});
});
it('injects the correct GitLab API base URL when missing', () => {
const output = readGitLabIntegrationConfig(
buildConfig({ host: 'gitlab.com' }),
);
expect(output).toEqual({
host: 'gitlab.com',
apiBaseUrl: 'https://gitlab.com/api/v4',
});
});
it('rejects funky configs', () => {
const valid: any = {
host: 'a.com',
@@ -91,6 +102,7 @@ describe('readGitLabIntegrationConfigs', () => {
expect(output).toEqual([
{
host: 'gitlab.com',
apiBaseUrl: 'https://gitlab.com/api/v4',
},
]);
});
+3 -3
View File
@@ -18,7 +18,8 @@ import { Config } from '@backstage/config';
import { isValidHost } from '../helpers';
const GITLAB_HOST = 'gitlab.com';
const GITLAB_API_BASE_URL = 'gitlab.com/api/v4';
const GITLAB_API_BASE_URL = 'https://gitlab.com/api/v4';
/**
* The configuration parameters for a single GitLab integration.
*/
@@ -29,7 +30,6 @@ 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.
*
@@ -99,7 +99,7 @@ export function readGitLabIntegrationConfigs(
// As a convenience we always make sure there's at least an unauthenticated
// reader for public gitlab repos.
if (!result.some(c => c.host === GITLAB_HOST)) {
result.push({ host: GITLAB_HOST });
result.push({ host: GITLAB_HOST, apiBaseUrl: GITLAB_API_BASE_URL });
}
return result;