Display comments of a reviewer in a specific color

134 views
Skip to first unread message

Patrick Bruneton

unread,
Feb 3, 2015, 1:17:29 PM2/3/15
to repo-d...@googlegroups.com
Hi all,

We have a bot that add some comments in our reviews (about code quality).
We would like to show their comments in another color than the color of other reviewers.
I didn't find a way to do this through the UI or an existing plugin.
So my question is: do you think this is feasible with a custom plugin ?

Thanks
Patrick

Jan Kundrát

unread,
Feb 3, 2015, 2:32:12 PM2/3/15
to repo-d...@googlegroups.com
This is possible through custom JS code. We're using OpenStack's scripts
that use jQuery for interactively hiding Jenkins' comments are transforming
them to a pretty table. Rather than hiding, it is simple to assing a custom
CSS class and have a CSS stylesheet doing whatever you need to do.

See [1] for the JS code. You can inject this through [2].

Cheers,
Jan

[1]
https://git.openstack.org/cgit/openstack-infra/system-config/tree/modules/openstack_project/files/gerrit/hideci.js
[2]
https://gerrit-review.googlesource.com/Documentation/config-themes.html#_html_header_footer

--
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/

David Pursehouse

unread,
Feb 3, 2015, 8:30:23 PM2/3/15
to Patrick Bruneton, repo-d...@googlegroups.com
Further to Jan's answer, you might also be interested in the ongoing
work to separate bot reviews from human reviews:

https://gerrit-review.googlesource.com/#/q/project:gerrit+branch:master+topic:verification-notification-channel

Bertram Karch

unread,
Feb 10, 2015, 4:47:38 AM2/10/15
to repo-d...@googlegroups.com
Hi Jan,

we are very interested on this!

I took your JS code hideci.js from [1] and put this in a html file on etc/GerritSiteHeader.html
like this
<div>
<script language="javascript" type="text/javascript">
<!--
content of hideci.js
-->
</script>
...
</div>

but I don't see any effect in the review screen :-(.

What am I doing wrong?

Bertram

 

Jan Kundrát

unread,
Feb 10, 2015, 8:26:35 AM2/10/15
to repo-d...@googlegroups.com
On Tuesday, 10 February 2015 10:47:38 CEST, Bertram Karch wrote:
> but I don't see any effect in the review screen :-(.

Check whether this content is actually embedded into the generated web
pages. If not, restart Gerrit.

Cheers,
Jan

Bertram Karch

unread,
Feb 10, 2015, 5:44:30 PM2/10/15
to repo-d...@googlegroups.com


Am Dienstag, 10. Februar 2015 14:26:35 UTC+1 schrieb Jan Kundrát:
On Tuesday, 10 February 2015 10:47:38 CEST, Bertram Karch wrote:
> but I don't see any effect in the review screen :-(.

Check whether this content is actually embedded into the generated web
pages. If not, restart Gerrit.

Hi,

I restarted gerrit and now I got errors on parsing the html file:

Caused by: java.io.IOException: Error reading /opt/gerrit/site210/etc/GerritSiteHeader.html
at com.google.gerrit.httpd.HtmlDomUtil.parseFile(HtmlDomUtil.java:217)
... 46 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 81; columnNumber: 24; The content of elements must consist of well-formed character data or markup.

I tested with firefox and gerrit 2.10 on ubuntu 14.04.
My GerritSiteHeade.html looks like


<div>
<script language="javascript" type="text/javascript">
   
// Copyright (c) 2014 VMware, Inc.
// Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
/.... more javascript
// now line 87
for (var i = 0; i < comments.length; i++) {

// ......... more javascript

    observer.observe(document, {
        subtree: true,
        attributes: true
    });
};
</script>
myHeader
</div>

The line in red is the line with the SAXParseException.

Did I forget something in the javascript?

Regards,
Bertram


 

Jan Kundrát

unread,
Feb 11, 2015, 5:59:45 AM2/11/15
to repo-d...@googlegroups.com
On Tuesday, 10 February 2015 23:44:30 CEST, Bertram Karch wrote:
> I restarted gerrit and now I got errors on parsing the html file:

Seems that you're inlining the JS content into GerritSiteHeader.html, not
using a CDATA escaping, and that some of the JS content triggers an XML
parsing error.

There's no need to inline; just add a <script ... src=... /> and put the
.js file into $gerrit_site/static.

Bertram Karch

unread,
Feb 12, 2015, 7:43:39 AM2/12/15
to repo-d...@googlegroups.com


Am Mittwoch, 11. Februar 2015 11:59:45 UTC+1 schrieb Jan Kundrát:
On Tuesday, 10 February 2015 23:44:30 CEST, Bertram Karch wrote:
> I restarted gerrit and now I got errors on parsing the html file:

Seems that you're inlining the JS content into GerritSiteHeader.html, not
using a CDATA escaping, and that some of the JS content triggers an XML
parsing error.

There's no need to inline; just add a <script ... src=... /> and put the
.js file into $gerrit_site/static.

Cheers,
Jan

Hi,

I tried it with
<div>
<script language="javascript" type="text/javascript" src="hideci.js"/>
myHeaderJS3
</div>
but I saw no effect.
Then I tried inlining with CDATA with a first success, I saw the js in page source code.
But I got an error because auf $, so I downloaded jquery and inlined too.
Now I can see a toogle button in the main screen of a change and in the file diff screen :-).
With toogle on the comments from jenkins disappeared on the main screen, but on the file diff screen I saw now effect.

Does hideci.js also hide the comments of jenkins in the screen which shows the inline comments on the changed files?
This is our main goal, we use sputnik to generate findbugs/pmd comments during jenkins verify-build, and we want to have to possibility
to hide these many inline comments to better recognize the comments of the human reviewer.

Regards,
Bertram 
 

Martin Waitz

unread,
Feb 12, 2015, 10:34:39 AM2/12/15
to repo-d...@googlegroups.com

I tried it with

<script language="javascript" type="text/javascript" src="hideci.js"/>
but I saw no effect.

Maybe use src="static/hideci.js" ?
Did you see the request for the JS in your http log?

-- Martin

Jan Kundrát

unread,
Feb 12, 2015, 10:50:39 AM2/12/15
to repo-d...@googlegroups.com
On Thursday, 12 February 2015 13:43:39 CEST, Bertram Karch wrote:
> <script language="javascript" type="text/javascript" src="hideci.js"/>

As Martin said, it's "static/hideci.js".

> Does hideci.js also hide the comments of jenkins in the screen which shows
> the inline comments on the changed files?

Nope. You'll have to add proper pattern recognition and DOM manipulation.
Shouldn't be that hard.
Reply all
Reply to author
Forward
0 new messages