chore: activate gerrit editURL by default

Signed-off-by: Andy LADJADJ <andy.ladjadj@adevinta.com>
This commit is contained in:
Andy LADJADJ
2025-03-24 15:25:13 +01:00
parent 86decb69d1
commit f56ee49904
7 changed files with 30 additions and 28 deletions
+3 -5
View File
@@ -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
+4 -2
View File
@@ -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.
+1 -1
View File
@@ -392,7 +392,7 @@ export type GerritIntegrationConfig = {
host: string;
baseUrl?: string;
cloneUrl?: string;
enableEditUrl?: boolean;
disableEditUrl?: boolean;
gitilesBaseUrl: string;
username?: string;
password?: string;
@@ -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(
@@ -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,
);
}
}
@@ -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,
+4 -4
View File
@@ -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,