diff --git a/docs/integrations/gerrit/locations.md b/docs/integrations/gerrit/locations.md deleted file mode 100644 index 747e3f2404..0000000000 --- a/docs/integrations/gerrit/locations.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -id: locations -title: Gerrit Locations -sidebar_label: Locations -description: Integrating source code stored in Gerrit into the Backstage catalog ---- - -The Gerrit integration supports loading catalog entities from Gerrit hosted gits. Entities can -be added to [static catalog configuration](../../features/software-catalog/configuration.md), -or registered with the -[catalog-import](https://github.com/backstage/backstage/tree/master/plugins/catalog-import) -plugin. - -## Configuration - -To use this integration, add configuration to your root `app-config.yaml`: - -```yaml -integrations: - gerrit: - - host: gerrit.company.com - apiBaseUrl: gerrit.company.com/gerrit - username: ${GERRIT_USERNAME} - password: ${GERRIT_PASSWORD} -``` - -Directly under the `gerrit` key is a list of provider configurations, where -you can list the Gerrit instances you want to fetch data from. Each entry is -a structure with up to four elements: - -- `host`: The host of the Gerrit instance, e.g. `gerrit.company.com`. -- `apiBaseUrl` (optional): Needed if the Gerrit instance is not reachable at - the base of the `host` option (e.g. `https://gerrit.company.com`). This is - the address that you would open in a browser. -- `username` (optional): The Gerrit username to use in API requests. If - neither a username nor password are supplied, anonymous access will be used. -- `password` (optional): The password or http token for the Gerrit user. diff --git a/mkdocs.yml b/mkdocs.yml index 05c492a077..4671a10b7a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -97,8 +97,6 @@ nav: - Discovery: 'integrations/bitbucket/discovery.md' - Datadog: - Installation: 'integrations/datadog-rum/installation.md' - - Gerrit: - - Locations: 'integrations/gerrit/locations.md' - GitHub: - Locations: 'integrations/github/locations.md' - Discovery: 'integrations/github/discovery.md' diff --git a/packages/integration/api-report.md b/packages/integration/api-report.md index 9a93c30316..84bca54a90 100644 --- a/packages/integration/api-report.md +++ b/packages/integration/api-report.md @@ -136,7 +136,7 @@ export class GerritIntegration implements ScmIntegration { // @public export type GerritIntegrationConfig = { host: string; - apiBaseUrl?: string; + baseUrl?: string; username?: string; password?: string; }; diff --git a/packages/integration/config.d.ts b/packages/integration/config.d.ts index 90b8b9b759..dc62695385 100644 --- a/packages/integration/config.d.ts +++ b/packages/integration/config.d.ts @@ -71,7 +71,7 @@ export interface Config { * The base url for the Gerrit instance. * @visibility frontend */ - apiBaseUrl?: string; + baseUrl?: string; /** * The username to use for authenticated requests. * @visibility secret @@ -80,7 +80,6 @@ export interface Config { /** * Gerrit password used to authenticate requests. This can be either a password * or a generated access token. - * . * @visibility secret */ password?: string; diff --git a/packages/integration/src/gerrit/GerritIntegration.test.ts b/packages/integration/src/gerrit/GerritIntegration.test.ts index 5b31b975f3..6b5e228bb6 100644 --- a/packages/integration/src/gerrit/GerritIntegration.test.ts +++ b/packages/integration/src/gerrit/GerritIntegration.test.ts @@ -26,7 +26,7 @@ describe('GerritIntegration', () => { { host: 'gerrit-review.example.com', username: 'gerrituser', - apiBaseUrl: 'https://gerrit-review.example.com/gerrit', + baseUrl: 'https://gerrit-review.example.com/gerrit', password: '1234', }, ], @@ -37,12 +37,14 @@ describe('GerritIntegration', () => { expect(integrations.list()[0].config.host).toBe( 'gerrit-review.example.com', ); + expect(integrations.list()[0].config.baseUrl).toBe( + 'https://gerrit-review.example.com/gerrit', + ); }); it('returns the basics', () => { const integration = new GerritIntegration({ host: 'gerrit-review.example.com', - apiBaseUrl: 'https://gerrit-review.example.com/gerrit', } as any); expect(integration.type).toBe('gerrit'); expect(integration.title).toBe('gerrit-review.example.com'); @@ -52,7 +54,6 @@ describe('GerritIntegration', () => { it('works for valid urls', () => { const integration = new GerritIntegration({ host: 'gerrit-review.example.com', - apiBaseUrl: 'https://gerrit-review.example.com/gerrit', } as any); expect( @@ -63,13 +64,26 @@ describe('GerritIntegration', () => { }), ).toBe('https://gerrit-review.example.com/catalog-info.yaml#9'); }); + + it('handles line numbers', () => { + const integration = new GerritIntegration({ + host: 'gerrit-review.example.com', + } as any); + + expect( + integration.resolveUrl({ + url: '', + base: 'https://gerrit-review.example.com/catalog-info.yaml#4', + lineNumber: 9, + }), + ).toBe('https://gerrit-review.example.com/catalog-info.yaml#9'); + }); }); describe('resolves with a relative url', () => { it('works for valid urls', () => { const integration = new GerritIntegration({ host: 'gerrit-review.example.com', - apiBaseUrl: 'https://gerrit-review.example.com/gerrit', } as any); expect( @@ -86,7 +100,6 @@ describe('GerritIntegration', () => { it('resolve edit URL', () => { const integration = new GerritIntegration({ host: 'gerrit-review.example.com', - apiBaseUrl: 'https://gerrit-review.example.com/gerrit', } as any); // Resolve edit URLs is not applicable for gerrit. Return the input diff --git a/packages/integration/src/gerrit/GerritIntegration.ts b/packages/integration/src/gerrit/GerritIntegration.ts index 791adc318d..97eb9372c0 100644 --- a/packages/integration/src/gerrit/GerritIntegration.ts +++ b/packages/integration/src/gerrit/GerritIntegration.ts @@ -33,7 +33,7 @@ export class GerritIntegration implements ScmIntegration { ); return basicIntegrations( configs.map(c => new GerritIntegration(c)), - i => i.config.host ?? '', + i => i.config.host, ); }; @@ -59,14 +59,14 @@ export class GerritIntegration implements ScmIntegration { const { url, base, lineNumber } = options; let updated; if (url) { - updated = new URL(url, base).toString(); + updated = new URL(url, base); } else { - updated = base; + updated = new URL(base); } if (lineNumber) { - return `${updated}#${lineNumber}`; + updated.hash = lineNumber.toString(); } - return updated; + return updated.toString(); } resolveEditUrl(url: string): string { diff --git a/packages/integration/src/gerrit/config.test.ts b/packages/integration/src/gerrit/config.test.ts index f448b76b0b..ce1ddccd75 100644 --- a/packages/integration/src/gerrit/config.test.ts +++ b/packages/integration/src/gerrit/config.test.ts @@ -55,14 +55,14 @@ describe('readGerritIntegrationConfig', () => { const output = readGerritIntegrationConfig( buildConfig({ host: 'a.com', - apiBaseUrl: 'https://a.com/api', + baseUrl: 'https://a.com/api', username: 'u', password: 'p', }), ); expect(output).toEqual({ host: 'a.com', - apiBaseUrl: 'https://a.com/api', + baseUrl: 'https://a.com/api', username: 'u', password: 'p', }); @@ -76,7 +76,7 @@ describe('readGerritIntegrationConfig', () => { ); expect(output).toEqual({ host: 'a.com', - apiBaseUrl: 'https://a.com', + baseUrl: 'https://a.com', username: undefined, password: undefined, }); @@ -90,8 +90,8 @@ describe('readGerritIntegrationConfig', () => { readGerritIntegrationConfig(buildConfig({ ...valid, host: 2 })), ).toThrow(/host/); expect(() => - readGerritIntegrationConfig(buildConfig({ ...valid, apiBaseUrl: 2 })), - ).toThrow(/apiBaseUrl/); + readGerritIntegrationConfig(buildConfig({ ...valid, baseUrl: 2 })), + ).toThrow(/baseUrl/); }); it('works on the frontend', async () => { @@ -99,14 +99,14 @@ describe('readGerritIntegrationConfig', () => { readGerritIntegrationConfig( await buildFrontendConfig({ host: 'a.com', - apiBaseUrl: 'https://a.com/gerrit', + baseUrl: 'https://a.com/gerrit', username: 'u', password: 'p', }), ), ).toEqual({ host: 'a.com', - apiBaseUrl: 'https://a.com/gerrit', + baseUrl: 'https://a.com/gerrit', }); }); }); @@ -121,26 +121,26 @@ describe('readGerritIntegrationConfigs', () => { buildConfig([ { host: 'a.com', - apiBaseUrl: 'https://a.com/api', + baseUrl: 'https://a.com/api', username: 'u', password: 'p', }, { host: 'b.com', - apiBaseUrl: 'https://b.com/api', + baseUrl: 'https://b.com/api', }, ]), ); expect(output).toEqual([ { host: 'a.com', - apiBaseUrl: 'https://a.com/api', + baseUrl: 'https://a.com/api', username: 'u', password: 'p', }, { host: 'b.com', - apiBaseUrl: 'https://b.com/api', + baseUrl: 'https://b.com/api', username: undefined, password: undefined, }, diff --git a/packages/integration/src/gerrit/config.ts b/packages/integration/src/gerrit/config.ts index c376aef98f..339b590c11 100644 --- a/packages/integration/src/gerrit/config.ts +++ b/packages/integration/src/gerrit/config.ts @@ -36,7 +36,7 @@ export type GerritIntegrationConfig = { * "https://gerrit-review.com/gerrit". This is the url that you would open * in a browser. */ - apiBaseUrl?: string; + baseUrl?: string; /** * The username to use for requests to gerrit. @@ -60,7 +60,7 @@ export function readGerritIntegrationConfig( config: Config, ): GerritIntegrationConfig { const host = config.getString('host'); - let apiBaseUrl = config.getOptionalString('apiBaseUrl'); + let baseUrl = config.getOptionalString('baseUrl'); const username = config.getOptionalString('username'); const password = config.getOptionalString('password'); @@ -68,20 +68,20 @@ export function readGerritIntegrationConfig( throw new Error( `Invalid Gerrit integration config, '${host}' is not a valid host`, ); - } else if (apiBaseUrl && !isValidUrl(apiBaseUrl)) { + } else if (baseUrl && !isValidUrl(baseUrl)) { throw new Error( - `Invalid Gerrit integration config, '${apiBaseUrl}' is not a valid apiBaseUrl`, + `Invalid Gerrit integration config, '${baseUrl}' is not a valid baseUrl`, ); } - if (apiBaseUrl) { - apiBaseUrl = trimEnd(apiBaseUrl, '/'); + if (baseUrl) { + baseUrl = trimEnd(baseUrl, '/'); } else { - apiBaseUrl = `https://${host}`; + baseUrl = `https://${host}`; } return { host, - apiBaseUrl, + baseUrl, username, password, };