Skip to content

feat(gerrit): Add gitUrl support#42672

Open
spmiller wants to merge 5 commits intorenovatebot:mainfrom
spmiller:feat-gerrit-gitUrl
Open

feat(gerrit): Add gitUrl support#42672
spmiller wants to merge 5 commits intorenovatebot:mainfrom
spmiller:feat-gerrit-gitUrl

Conversation

@spmiller
Copy link
Copy Markdown

@spmiller spmiller commented Apr 15, 2026

Changes

This change adds support for the existing gitUrl parameter to the gerrit platform.

The existing behaviour (when gitUrl is not specified) is left unchanged, and is mapped to the default and endpoint values of gitUrl.

Context

Please select one of the following:

  • This closes an existing Issue, Closes: #
  • This doesn't close an Issue, but I accept the risk that this PR may be closed if maintainers disagree with its opening or implementation

AI assistance disclosure

Did you use AI tools to create any part of this pull request?

Please select one option and, if yes, briefly describe how AI was used (e.g., code, tests, docs) and which tool(s) you used.

  • No — I did not use AI for this contribution.
  • Yes — minimal assistance (e.g., IDE autocomplete, small code completions, grammar fixes).
  • Yes — substantive assistance (AI-generated non‑trivial portions of code, tests, or documentation).
  • Yes — other (please describe):
    I asked Claude which API provided the download schemes in Gerrit. No AI was used for the coding.

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

I added Gerrit as a supported platform for the parameter gitUrl in config/options/index.ts

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests, but ran on a real repository, or
  • Both unit tests + ran on a real repository

My Gerrit server is not publicly available, but with my changes Renovate was able to clone the repo over SSH.

spmiller and others added 2 commits April 15, 2026 17:43
This change adds support for the gitUrl parameter to the gerrit platform.

It queries the gerrit server to check what download options are available. If ssh is selected but not available, it will throw an error.
@github-actions github-actions bot requested a review from viceice April 15, 2026 23:37
This removes support for querying the supported download schemes and
instead hard-codes the default ssh port.
@spmiller spmiller changed the title Add gitUrl support to Gerrit platform feat(gerrit): Add gitUrl support Apr 16, 2026
Copy link
Copy Markdown
Contributor

@felipecrs felipecrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, LGTM.

Comment thread lib/modules/platform/gerrit/utils.ts Outdated
);

const sshUrl = new URL(
`ssh://${endpointUrl.host}:29418${joinUrlParts(endpointUrl.pathname, repository)}`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please extract the port number to a constant?

Comment thread lib/modules/platform/gerrit/utils.ts Outdated
url.password = opts.password;
url.pathname = joinUrlParts(
url.pathname,
const httpUrl = new URL(endpointUrl.toString());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but maybe using clone from util/clone.ts would be nicer.

encodeURIComponent(repository),
);

const sshUrl = new URL(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably use parseUrl here too.

@felipecrs
Copy link
Copy Markdown
Contributor

@spmiller, this reminded me of a very old discussion:

In that discussion, the Gerrit URL would be something like <host>/gerrit/<projectPath>, as well as the HTTP clone URL, while the SSH clone URL would be something like <host>/<projectPath>, without the path prefix.

Maybe you can extract the prefix from the configured platform URL and "subtract" it from the generated SSH URL?

@spmiller
Copy link
Copy Markdown
Author

@spmiller, this reminded me of a very old discussion:

Maybe you can extract the prefix from the configured platform URL and "subtract" it from the generated SSH URL?

Hey @felipecrs, this old discussion is gold! Having some actual config examples makes it much easier to solve the problem. I think the behaviour in my PR would not work for their server.

It got me thinking, maybe my original approach (query the server to get the download schemes) wasn't so bad after all? It was an extra API call (config/server/info) but I could Promise.all them quite easily to get it in parallel. We wouldn't have to have extra logic to extract the prefix.

The trade-off is more code in the client/types files. Perhaps it's worth it?

This is the original commit I made in case you want to compare:
spmiller@bb187fa#diff-9e28b3970977a05aec269cd0b4fb67427dc51bdb6a1e10281f1dc214c69c56f8

@marquisesenior383-ctrl
Copy link
Copy Markdown

marquisesenior383-ctrl commented Apr 17, 2026 via email

@felipecrs
Copy link
Copy Markdown
Contributor

felipecrs commented Apr 17, 2026

@spmiller, you only need to make these changes:

diff --git a/lib/modules/platform/gerrit/utils.spec.ts b/lib/modules/platform/gerrit/utils.spec.ts
index a6f7b7a72..7515b781f 100644
--- a/lib/modules/platform/gerrit/utils.spec.ts
+++ b/lib/modules/platform/gerrit/utils.spec.ts
@@ -100,7 +100,7 @@ describe('modules/platform/gerrit/utils', () => {
           'https://gerrit.example.com/context',
           'ssh',
         );
-        expect(repoUrl).toBe('ssh://gerrit.example.com:29418/context/web/apps');
+        expect(repoUrl).toBe('ssh://gerrit.example.com:29418/web/apps');
       });
     });
   });
diff --git a/lib/modules/platform/gerrit/utils.ts b/lib/modules/platform/gerrit/utils.ts
index 5f24e3635..9d7ffde83 100644
--- a/lib/modules/platform/gerrit/utils.ts
+++ b/lib/modules/platform/gerrit/utils.ts
@@ -62,7 +62,7 @@ export function getGerritRepoUrl(
   );
 
   const sshUrl = new URL(
-    `ssh://${endpointUrl.host}:29418${joinUrlParts(endpointUrl.pathname, repository)}`,
+    `ssh://${endpointUrl.host}:29418/${repository}`,
   );
 
   const url = pickUrlFromGitUrl(gitUrl, sshUrl, httpUrl);

Addresses feedback left in review:
- constants for ports
- better SSH url creation
- more consistent util method usage
Copy link
Copy Markdown
Contributor

@felipecrs felipecrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Comment thread lib/modules/platform/gerrit/utils.ts Outdated
Comment on lines 67 to 78
const sshUrl = parseUrl(
`ssh://${endpointUrl.host}:${DEFAULT_SSH_PORT}/${repository}`,
);
if (!sshUrl) {
throw new Error(CONFIG_GIT_URL_UNAVAILABLE);
}

const url = pickUrlFromGitUrl(gitUrl, sshUrl, httpUrl);
logger.trace(
{ url: url.toString() },
'using URL based on configured endpoint',
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage is now failing because of the change I asked (to use parseUrl). Sorry about that.

https://app.codecov.io/gh/renovatebot/renovate/pull/42672?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=checks&utm_campaign=pr+comments&utm_term=renovatebot#598202c3fbcb3052e676a66671afb2ec-R71

Feel free to change it back to new URL() for now, then let's see what the maintainers think.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to change it back to new URL() for now, then let's see what the maintainers think.

Thanks, I think that's the pragmatic option. I rewrote the method to allow testing the coverage and it looked dreadful!

Addresses feedback left in review:
- Reverts SSH URL creation to ensure coverage target
@spmiller
Copy link
Copy Markdown
Author

@spmiller, you only need to make these changes:

Okay, I've made those changes and addressed your other review comments. Thanks for your help so far!

case 'ssh':
return sshUrl.toString();
case 'endpoint':
return httpUrl.toString();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return httpUrl.toString();

let fall through when same

url.password = opts.password;
url.pathname = joinUrlParts(
url.pathname,
const httpUrl = clone(endpointUrl);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why cloning? the endpointUrl is only used in this function, so use it here again?

better do the switch case here and don't compute multiple urls to later throw the other away. only compute ssh when gitUrl=ssh, use current otherwise. will make the code much simpler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants