Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for vanilla Gerrit #1954

Merged
merged 1 commit into from
Apr 13, 2022
Merged

Conversation

felipecrs
Copy link
Contributor

@felipecrs felipecrs commented Apr 7, 2022

Description

I work with Gerrit every day, and today I realized how much time it could save if Gitlens worked for me. To my surprise, I found Gerrit in the list of supported providers, but when trying to use it, I stumbled upon some issues.

The current Gerrit provider implementation is very tied to Google Source, but Google Source is an implementation on top of the vanilla Gerrit, and many other orgs implements Gerrit in the vanilla way.

This PR turns the existing Gerrit provider into a generic/vanilla Gerrit one (not tied to Google Source), but adds back Google Source as its own provider, meant to be used in Android, Chromium, Gerrit itself, Golang, and other projects from them.

Also, the new provider comes with a new pre-configured domain, which is the GerritHub, a publicly known and freely available Gerrit instance.

Where I work, however, we host our own Gerrit instance, and I would configure Gitlens as follows:

"gitlens.remotes": [{ "domain": "gerrit.my-org.com", "type": "Gerrit" }]

Closes #1953
Closes #1787
Closes #1788
Closes #1902

Checklist

  • I have followed the guidelines in the Contributing document
  • My changes follow the coding style of this project
  • My changes build without any errors or warnings
  • My changes have been formatted and linted
  • My changes include any required corresponding changes to the documentation
  • My changes have been rebased and squashed to the minimal number (typically 1) of relevant commits
  • My changes have a descriptive commit message with a short title, including a Fixes $XXX - or Closes #XXX - prefix to auto-close the issue that your PR addresses

@felipecrs felipecrs changed the title Add support for vanilla Gerrit providers Adds support for vanilla Gerrit Apr 7, 2022
@felipecrs felipecrs force-pushed the vanilla-gerrit branch 2 times, most recently from 7e9dcd2 to 2531553 Compare April 7, 2022 16:13
@felipecrs felipecrs marked this pull request as ready for review April 7, 2022 16:19
@felipecrs
Copy link
Contributor Author

felipecrs commented Apr 7, 2022

I tested against both Google Source repositories and vanilla Gerrit repositories. Everything seems to be working as expected.

Also, I don't think this is going to be a practical breaking change, as I doubt anyone had ever added custom Gerrit providers to their settings (because if they did, it didn't work, as the implementation to-date is only valid for Google Source, which should be covered by the existing regex -- and therefore would not require one to set a custom provider for it).

@felipecrs felipecrs marked this pull request as draft April 7, 2022 16:22
@felipecrs felipecrs force-pushed the vanilla-gerrit branch 3 times, most recently from 6ffa581 to dcc37f0 Compare April 7, 2022 16:27
@felipecrs felipecrs marked this pull request as ready for review April 7, 2022 16:27
@felipecrs
Copy link
Contributor Author

felipecrs commented Apr 7, 2022

This is ready to review.

/cc @andrewsavage1 as you have worked in the previous Gerrit provider.

@andrewsavage1
Copy link
Contributor

No issues with this from me, thanks for the fix @felipecrs.

@felipecrs
Copy link
Contributor Author

@Levistator, @adambadura as you both reported similar issues, I would kindly ask if this would solve your issues.

And separates the existing Gerrit provider to a new GoogleSource one.

Closes gitkraken#1953
@felipecrs
Copy link
Contributor Author

If you would like to test, I built a vsix that you can install in your VS Code:

gitlens-12.0.5.vsix.zip

It's not a zip file, simply rename to remove the .zip suffix after downloading (GitHub only allows to upload certain extensions in comments).

README.md Show resolved Hide resolved
patches/tr46.js Show resolved Hide resolved
}

private get reviewDomain(): string {
const [subdomain, secondLevelDomain, topLevelDomain] = this.domain.split('.');

Choose a reason for hiding this comment

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

FWIW this doesn't work for domains with more than three levels.

e.g. project.git.source.company-tld.com

Can this just split and mutate the subdomain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only for GoogleSource. Are you sure this is applicable for you?

Copy link

@acarlson1029 acarlson1029 Apr 8, 2022

Choose a reason for hiding this comment

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

Upon double-checking, I guess it's not strictly necessary.
The domain I was using also resolves with project.googlesource.com

I had to update my git config remote URL and restart VS Code, but it worked 👍

Copy link
Contributor Author

@felipecrs felipecrs Apr 8, 2022

Choose a reason for hiding this comment

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

The domain I was using also resolves with project.googlesource.com

Not sure if I understood this part.

Anyway, after this PR, you would configure VS Code with:

"gitlens.remotes": [{ "domain": "project.git.source.company-tld.com", "type": "Gerrit" }]

@acarlson1029 If you have such an environment to test, I would advise you to test it before we merge. The .vsix is available here:

#1954 (comment)

@adambadura
Copy link

If you would like to test, I built a vsix that you can install in your VS Code:

Is there any document describing how to use your package? Especially in remote scenarios? I'm sorry, but I'm new to Visual Studio Code.

@adambadura
Copy link

If you would like to test, I built a vsix that you can install in your VS Code:

Is there any document describing how to use your package? Especially in remote scenarios? I'm sorry, but I'm new to Visual Studio Code.

Turns out on the "Extensions" tab, in the "..." menu there is "Install from VSIX..." and it works as expected, including my remote work scenario.

@adambadura
Copy link

@Levistator, @adambadura as you both reported similar issues, I would kindly ask if this would solve your issues.

The issue #1787 (on adding -review in domain) seems to indeed be closed.

However, my own issue #1902 is not closed. Now I have gerrit-wrsl1.int.net.nokia.com used as domain. This matches the remote of Git. However, links to changes etc. should (in our setup) be done for the main server (gerrit.ext.net.nokia.com) instead. Only fetching is done from the mirror server.

Or do I have to do some extra configuration in the plugin settings to have this covered?

Interestingly, this could perhaps be deduced (or wild-guessed) from Git configuration itself. My .gitconfig contains entries like:

[url "https://<USER>@gerrit-wrsl1.int.net.nokia.com:29418"]
        insteadOf = https://<USER>@gerrit.ext.net.nokia.com:29418
[url "https://<USER>@gerrit.ext.net.nokia.com:29418"]
        pushInsteadOf = https://<USER>@gerrit.ext.net.nokia.com:29418
        pushInsteadOf = https://<USER>@gerrit-wrsl1.int.net.nokia.com:29418

including also versions with ssh:// and without the <USER> (although I'm not sure if I indeed need all 4 variants...).

@adambadura
Copy link

For the record, my C:/Users/(...)/AppData/Roaming/Code/User/settings.json has the following:

    "gitlens.remotes": [
        {"domain": "gerrit.ext.net.nokia.com", "type": "Gerrit"},
        {"domain": "gerrit-wrsl1.int.net.nokia.com", "type": "Gerrit"}
    ],

@felipecrs
Copy link
Contributor Author

@adambadura Would you mind running:

git remote -v

From within your cloned project?

@felipecrs
Copy link
Contributor Author

felipecrs commented Apr 8, 2022

Where I work, we have a comparable situation. But there is one thing weird in your case, the protocol is set as HTTPS, but the port 29148 (which is Gerrit's known SSH port).

If my suspicious is correct, you are using SSH in the git remote. Internally, we also need to fetch from mirror and push to master, but only when using SSH. For HTTPS, the load balancing from Gerrit side happens transparently.

I have switched from SSH to HTTPS since a long time ago and I never looked back. With GCM, I don't need to re-type my password either.

Perhaps it can work for you too, although I don't deny we can improve the extension to support such a mirror/master scenario.

@adambadura
Copy link

git remote -v

Sure:

origin  ssh://<USER>@gerrit-wrsl1.int.net.nokia.com:29418/MN/5G/NB/gnb (fetch)
origin  ssh://<USER>@gerrit.ext.net.nokia.com:29418/MN/5G/NB/gnb (push)

@felipecrs
Copy link
Contributor Author

felipecrs commented Apr 8, 2022

@adambadura, I tested here, locally, and it seems to be working as expected. There is one point, however:

{
  "gitlens.remotes": [
    {"domain": "gerrit.ext.net.nokia.com", "type": "Gerrit"},
  ],
}

Do NOT add the mirror to the list of Gitlens Remotes. Can you please check if that works for you?

Code_VbrM0yfowG.mp4

@adambadura
Copy link

Can you please check if that works for you?

I will get back to you on this on Monday.

@Levistator
Copy link

Yep it works for me. Thanks @felipecrs !!

@adambadura
Copy link

Can you please check if that works for you?

I will get back to you on this on Monday.

Indeed, using only the main server:

    "gitlens.remotes": [
        {"domain": "gerrit.ext.net.nokia.com", "type": "Gerrit"}
     ],

helped in that the proper server is reached (at least from the Change-Id link).

However, as it turned out, this is not enough in my case. The server is OK, but the web access is done through gerrit.ext.net.nokia.com/gerrit/ instead. So, the Change-Id link should be

https://gerrit.ext.net.nokia.com/gerrit/q/<hash>

while the plugin makes it

https://gerrit.ext.net.nokia.com/q/<hash>

I know this goes beyond what I described in #1902 and I would close #1902 with this one and open a more specific issue afterward. However, perhaps you do know already how to address this configuration?

I did try using "gerrit.ext.net.nokia.com/gerrit" for the "domain", but unsurprisingly it didn't work. Moreover, the entire Change-Id linking functionality ceased to work (no link made at all), so I expect this must be some configuration error.

@felipecrs
Copy link
Contributor Author

felipecrs commented Apr 11, 2022

@adambadura
Copy link

@adambadura what would be the Gitiles homepage for your server then?

  1. https://gerrit.ext.net.nokia.com/
  2. https://gerrit.ext.net.nokia.com/plugins/gitiles
  3. https://gerrit.ext.net.nokia.com/gerrit/plugins/gitiles

Is it any of the above?

It is the last one, although I had to add the trailing / as otherwise I was getting "Not Found" error.

@felipecrs
Copy link
Contributor Author

felipecrs commented Apr 11, 2022

Got it. So, your Gerrit is running under a reverse proxy.

That's a little odd, because the domain itself has Gerrit in its name, so I wonder what the need for such an extra identifier in the URI was. Anyway, this does not change the fact that you run through a reverse proxy, and ideally this should be supported.

Having that said, it's a different feature than what this PR is trying to solve. So, I would suggest you open a different issue, targeting something like Support Git remote providers running behind a reverse proxy. I haven't checked, but I suspect this isn't only valid for Gerrit.

I have some ideas on how that can be solved, but an issue would be helpful so that we could discuss with the maintainers the preferred approach.

@adambadura
Copy link

OK then, let's close #1902 along with this one.

@felipecrs
Copy link
Contributor Author

OK then, let's close #1902 along with this one.

Right. I added #1902 back to the list of closable issues by this PR.

@felipecrs
Copy link
Contributor Author

@eamodio just to say this is ready to review now.

@eamodio eamodio self-assigned this Apr 13, 2022
@eamodio eamodio added this to the Soon™ milestone Apr 13, 2022
@eamodio eamodio merged commit 517e9f0 into gitkraken:main Apr 13, 2022
@eamodio
Copy link
Member

eamodio commented Apr 13, 2022

Wow, @felipecrs, this is awesome. Thank you so much for your contribution! And thank you to all the testers too!

Thank you!

@felipecrs felipecrs deleted the vanilla-gerrit branch April 13, 2022 13:43
@eamodio eamodio modified the milestones: Soon™, June 2022 May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants