From f56ee499043feeaf147fb7d04b2858eb7658c4fa Mon Sep 17 00:00:00 2001 From: Andy LADJADJ Date: Mon, 24 Mar 2025 15:25:13 +0100 Subject: [PATCH] chore: activate gerrit editURL by default Signed-off-by: Andy LADJADJ --- .changeset/ten-spies-explode.md | 8 +++----- docs/integrations/gerrit/locations.md | 6 ++++-- packages/integration/report.api.md | 2 +- .../src/gerrit/GerritIntegration.test.ts | 5 +++-- .../src/gerrit/GerritIntegration.ts | 19 ++++++++++--------- .../integration/src/gerrit/config.test.ts | 10 +++++----- packages/integration/src/gerrit/config.ts | 8 ++++---- 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/.changeset/ten-spies-explode.md b/.changeset/ten-spies-explode.md index ba7d406398..6e6dac205a 100644 --- a/.changeset/ten-spies-explode.md +++ b/.changeset/ten-spies-explode.md @@ -2,10 +2,8 @@ '@backstage/integration': minor --- -Add Gerrit option to activate the edit mode for version >= 3.9 +Implement Edit URL feature for Gerrit 3.9+. Enabled by default due to 3.8 EOL -``` - enableEditUrl: true -``` +Details: - The Edit URL feature allows for direct editing of files in Gerrit through a specific URL pattern. - URL pattern: `^\/admin\/repos\/edit\/repo\/(.+)\/branch\/(.+)\/file\/(.+)$` -The url pattern is `^\/admin\/repos\/edit\/repo\/(.+)\/branch\/(.+)\/file\/(.+)$` +Caution: - To turn off this functionality, you can add the configuration `disableEditUrl: true` in the Gerrit integration section of your settings diff --git a/docs/integrations/gerrit/locations.md b/docs/integrations/gerrit/locations.md index a0c48692a8..16827dbf09 100644 --- a/docs/integrations/gerrit/locations.md +++ b/docs/integrations/gerrit/locations.md @@ -11,6 +11,8 @@ or registered with the [catalog-import](https://github.com/backstage/backstage/tree/master/plugins/catalog-import) plugin. +Gerrit 3.9+ supports inline editing via URL. the integration enables this by default, following Gerrit's [official URL pattern](https://gerrit-review.googlesource.com/Documentation/user-inline-edit.html#create_from_url) for inline edits. + ## Configuration To use this integration, add at least one Gerrit configuration to your root `app-config.yaml`: @@ -22,7 +24,7 @@ integrations: gitilesBaseUrl: https://gerrit.company.com/gitiles baseUrl: https://gerrit.company.com/gerrit cloneUrl: https://gerrit.company.com/clone - enableEditUrl: true + disableEditUrl: false username: ${GERRIT_USERNAME} password: ${GERRIT_PASSWORD} ``` @@ -38,7 +40,7 @@ a structure with up to six elements: address here. This is the address that you would open in a browser. - `cloneUrl` (optional): The base URL for HTTP clones. Will default to `baseUrl` if not set. The address used to clone a repo is the `cloneUrl` plus the repo name. -- `enableEditUrl` (optional): Activate the edit mode for Gerrit >= 3.9 following the [official pattern](https://gerrit-review.googlesource.com/Documentation/user-inline-edit.html#create_from_url) +- `disableEditUrl` (optional): Disable the edit mode for Gerrit < 3.9 - `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/packages/integration/report.api.md b/packages/integration/report.api.md index ecf46b10f1..9baabdd6ce 100644 --- a/packages/integration/report.api.md +++ b/packages/integration/report.api.md @@ -392,7 +392,7 @@ export type GerritIntegrationConfig = { host: string; baseUrl?: string; cloneUrl?: string; - enableEditUrl?: boolean; + disableEditUrl?: boolean; gitilesBaseUrl: string; username?: string; password?: string; diff --git a/packages/integration/src/gerrit/GerritIntegration.test.ts b/packages/integration/src/gerrit/GerritIntegration.test.ts index b415636072..0d4058d47e 100644 --- a/packages/integration/src/gerrit/GerritIntegration.test.ts +++ b/packages/integration/src/gerrit/GerritIntegration.test.ts @@ -138,9 +138,10 @@ describe('GerritIntegration', () => { }); }); - it('resolve edit URL', () => { + it('resolve Url when editUrl is disabled', () => { const integration = new GerritIntegration({ host: 'gerrit-review.example.com', + disableEditUrl: true, } as any); // Resolve edit URLs is not applicable for gerrit. Return the input @@ -158,8 +159,8 @@ describe('GerritIntegration', () => { const integration = new GerritIntegration({ host: 'gerrit-review.example.com', baseUrl: 'https://gerrit-review.example.com', - enableEditUrl: true, gitilesBaseUrl: 'https://gerrit-review.example.com/gitiles', + disableEditUrl: false, } as any); expect( diff --git a/packages/integration/src/gerrit/GerritIntegration.ts b/packages/integration/src/gerrit/GerritIntegration.ts index adca205ac7..ba2153c817 100644 --- a/packages/integration/src/gerrit/GerritIntegration.ts +++ b/packages/integration/src/gerrit/GerritIntegration.ts @@ -75,15 +75,16 @@ export class GerritIntegration implements ScmIntegration { } resolveEditUrl(url: string): string { - if (this.config.enableEditUrl) { - const parsed = parseGitilesUrlRef(this.config, url); - return buildGerritEditUrl( - this.config, - parsed.project, - parsed.ref, - parsed.path, - ); + if (this.config.disableEditUrl) { + return url; } - return url; + + const parsed = parseGitilesUrlRef(this.config, url); + return buildGerritEditUrl( + this.config, + parsed.project, + parsed.ref, + parsed.path, + ); } } diff --git a/packages/integration/src/gerrit/config.test.ts b/packages/integration/src/gerrit/config.test.ts index 8bf1a3d44c..7b6dc01e7e 100644 --- a/packages/integration/src/gerrit/config.test.ts +++ b/packages/integration/src/gerrit/config.test.ts @@ -57,7 +57,7 @@ describe('readGerritIntegrationConfig', () => { host: 'a.com', baseUrl: 'https://a.com/api', cloneUrl: 'https:a.com/clone', - enableEditUrl: false, + disableEditUrl: true, gitilesBaseUrl: 'https://a.com/git', username: 'u', password: ' p ', @@ -67,7 +67,7 @@ describe('readGerritIntegrationConfig', () => { host: 'a.com', baseUrl: 'https://a.com/api', cloneUrl: 'https:a.com/clone', - enableEditUrl: false, + disableEditUrl: true, gitilesBaseUrl: 'https://a.com/git', username: 'u', password: 'p', @@ -78,7 +78,7 @@ describe('readGerritIntegrationConfig', () => { const output = readGerritIntegrationConfig( buildConfig({ host: 'a.com', - enableEditUrl: true, + disableEditUrl: false, gitilesBaseUrl: 'https://a.com/gerrit/plugins/gitiles', }), ); @@ -86,7 +86,7 @@ describe('readGerritIntegrationConfig', () => { host: 'a.com', baseUrl: 'https://a.com', cloneUrl: 'https://a.com', - enableEditUrl: true, + disableEditUrl: false, gitilesBaseUrl: 'https://a.com/gerrit/plugins/gitiles', username: undefined, password: undefined, @@ -177,7 +177,7 @@ describe('readGerritIntegrationConfigs', () => { host: 'b.com', baseUrl: 'https://b.com/api', cloneUrl: 'https://b.com/api', - enableEditUrl: undefined, + disableEditUrl: undefined, gitilesBaseUrl: 'https://b.com/gerrit/plugins/gitiles', username: undefined, password: undefined, diff --git a/packages/integration/src/gerrit/config.ts b/packages/integration/src/gerrit/config.ts index 710e2847de..549842da9e 100644 --- a/packages/integration/src/gerrit/config.ts +++ b/packages/integration/src/gerrit/config.ts @@ -45,9 +45,9 @@ export type GerritIntegrationConfig = { cloneUrl?: string; /** - * Activate the edit url feature available since Gerrit 3.9 + * Disable the edit url feature for Gerrit <= 3.8. */ - enableEditUrl?: boolean; + disableEditUrl?: boolean; /** * Base url for Gitiles. This is needed for creating a valid @@ -80,7 +80,7 @@ export function readGerritIntegrationConfig( const host = config.getString('host'); let baseUrl = config.getOptionalString('baseUrl'); let cloneUrl = config.getOptionalString('cloneUrl'); - const enableEditUrl = config.getOptionalBoolean('enableEditUrl'); + const disableEditUrl = config.getOptionalBoolean('disableEditUrl'); let gitilesBaseUrl = config.getString('gitilesBaseUrl'); const username = config.getOptionalString('username'); const password = config.getOptionalString('password')?.trim(); @@ -119,7 +119,7 @@ export function readGerritIntegrationConfig( host, baseUrl, cloneUrl, - enableEditUrl, + disableEditUrl, gitilesBaseUrl, username, password,