Use GerritNav.navigateToDiff from js plugin?

46 views
Skip to first unread message

Erik ht

unread,
Jan 19, 2022, 9:25:50 AM1/19/22
to Repo and Gerrit Discussion
Hi.
I would like to make a checks-plugin where one can click a link on a CheckRun to jump straight to the diff of affected source code, with path, and line-no.

Every line of a change has a url like changenr/PS/file#linenoe, so i tried using url attribute of a CheckRun but they always open in new tab.
I've also tried using action attribute and in the callback write straight to document.location, which sortof works but it reloads the whole page and is not as fast as normal navigation in the Gerrit UI.

Browsing through the source code i found a function GerritNav.navigateToDiff, but didn't find any way to access this via the plugins API. Is this possible or is there any other way one should do this? There was also a window["page"].show possible to use, which seems to be what GerritNav uses under the hood but it also seem to reload the whole page and doesn't provide the convenience url builder functions..

Ben Rohlfs

unread,
Jan 19, 2022, 3:38:36 PM1/19/22
to Erik ht, Repo and Gerrit Discussion
You can associate check results with code pointers. That was implemented for exactly the use case that you have in mind - if I understand correctly.

Note that we are considering to just support *1* code pointer per result going forward. Making this an array was a design mishap.

Note also that we have a change in flight that makes check results show up in the diff when they have a code pointer: https://gerrit-review.googlesource.com/c/gerrit/+/326625

Navigation from plugins is not very well supported. We are kind of hesitant to open up the entire GerritNav functionality to plugins, because that would be a large API surface with little usage. But if you don't mind doing something fragile, at the moment you should be able to get at GerritNav and its methods by `window.Gerrit.Nav`.

HTH Ben

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/128f4bb8-d478-4e94-93e9-57898b18db8an%40googlegroups.com.

Erik ht

unread,
Jan 24, 2022, 4:04:54 AM1/24/22
to Repo and Gerrit Discussion
Thanks for the info. That new rendering of checks in the diff looks great. Do you have any estimate for when it will be available in any release?

Unfortunately i can't seem to get the existing codePointers to have any effect at all. Are they supposed to show up anywhere as links on the checks page?  I'm on Gerrit 3.5.0.

Also would it be possible to make links to files that are not part of the change? A common scenario for example is modifying a header-file but the compile-error shows up in the c-file.

Thanks for the pointer to window.Gerrit.Nav.navigateToDiff, it worked great and we are ready if it moves on upgrades.

Ben Rohlfs

unread,
Jan 24, 2022, 4:15:34 AM1/24/22
to Erik ht, Repo and Gerrit Discussion
On Mon, 24 Jan 2022 at 10:04, Erik ht <er...@haleytek.com> wrote:
Thanks for the info. That new rendering of checks in the diff looks great. Do you have any estimate for when it will be available in any release?

It will be available in the next release: 3.6. That should happen ~May.

Unfortunately i can't seem to get the existing codePointers to have any effect at all. Are they supposed to show up anywhere as links on the checks page?  I'm on Gerrit 3.5.0.

That is expected. You will have to wait for 3.6.

Also would it be possible to make links to files that are not part of the change? A common scenario for example is modifying a header-file but the compile-error shows up in the c-file.


That should work, even in 3.5. It will just not be a Gerrit diff page that you are pointing to, just your normal code browsing tool (gitiles, gitweb, ...?).

Thanks for the pointer to window.Gerrit.Nav.navigateToDiff, it worked great and we are ready if it moves on upgrades.

Cool, glad that it worked for you.

-Ben



 
Reply all
Reply to author
Forward
0 new messages