Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-19788

Add SCM repository browser links to Jelly templates

      It would be great if list of SCM changes would link to repository browser, just like what's available at http://jenkins/job/JOB_NAME/changes.

      Obviously this would need to take into account the repository browser configuration from the job.

          [JENKINS-19788] Add SCM repository browser links to Jelly templates

          Alex Earl added a comment -

          If you want thus, please create a pull request.

          Alex Earl added a comment - If you want thus, please create a pull request.

          Verbitan added a comment -

          Yup this is almost exactly what I'm after!

          Ideally I would like the diff links in there as well, but I could probably work it out from here.

          Out of interest, is there any documentation for what's available via Jelly? For instance how did you know 'build.parent.scm.effectiveBrowser.getChangeSetLink' was available?

          Verbitan added a comment - Yup this is almost exactly what I'm after! Ideally I would like the diff links in there as well, but I could probably work it out from here. Out of interest, is there any documentation for what's available via Jelly? For instance how did you know 'build.parent.scm.effectiveBrowser.getChangeSetLink' was available?

          Alex Earl added a comment -

          The whole Jenkins API is available, build is usually an AbstractBuild, so you can start there to see what is available.

          http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html

          Alex Earl added a comment - The whole Jenkins API is available, build is usually an AbstractBuild, so you can start there to see what is available. http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html

          Mathieu Gervais added a comment - - edited

          Sorry, can't create a pull request at the moment for a silly reason, but anyone is welcome to create one based on this code (could be polished a bit first).
          This includes the diff as provided by the respective SCM plugin Repository browser implementation (e.g. https://github.com/jenkinsci/git-plugin/blob/e7a66a51d648c167096f0f37facd8d1e2af589b3/src/main/java/hudson/plugins/git/browser/Stash.java ). I only tested with SCMs that do have this capability, so not sure if it will gracely fail if the repository browser doesn't provide that feature:

          <j:set var="changeSet" value="${build.changeSet}" />
          <j:if test="${changeSet!=null}">
            <j:set var="hadChanges" value="false" />
            <TABLE width="100%">
              <TR><TD class="bg1" colspan="2"><B>Changes</B></TD></TR>
              <j:forEach var="cs" items="${changeSet}" varStatus="loop">
                <j:set var="hadChanges" value="true" />
                <j:set var="aUser" value="${cs.hudsonUser}"/>
                <TR>
                  <TD colspan="2" class="bg2">${spc}Revision <B><A href="${build.parent.scm.effectiveBrowser.getChangeSetLink(cs)}">${cs.commitId?:cs.revision?:cs.changeNumber}</A></B> by
                    <j:set var="userName" value="${aUser!=null?aUser.displayName:cs.author.displayName}"/>
                    <B>${userName}: </B>
                    <B>(${cs.msgAnnotated})</B>
                   </TD>
                </TR>
                <j:forEach var="p" items="${cs.affectedFiles}">
                  <TR>
                    <TD width="10%">${spc}${p.editType.name}</TD>
                    <TD><A HREF="${build.parent.scm.effectiveBrowser.getFileLink(p)}">${p.path}</A>&#160;
                                          <j:choose>
                                              <j:when test="${p.revision!=null}">
                                                  #${p.revision}
                                              </j:when>
                                          </j:choose>
          &#160;
                                          <j:set var="diff" value="${build.parent.scm.effectiveBrowser.getDiffLink(p)}"/>
                                          <j:choose>
                                              <j:when test="${diff!=null}">
                                                  <a href="${diff}">Diff</a>
                                              </j:when>
                                          </j:choose>
                    </TD>
                  </TR>
                </j:forEach>
              </j:forEach>
              <j:if test="${!hadChanges}">
                <TR><TD colspan="2">No Changes</TD></TR>
              </j:if>
            </TABLE>
          <BR/>
          </j:if>
          

          Mathieu Gervais added a comment - - edited Sorry, can't create a pull request at the moment for a silly reason, but anyone is welcome to create one based on this code (could be polished a bit first). This includes the diff as provided by the respective SCM plugin Repository browser implementation (e.g. https://github.com/jenkinsci/git-plugin/blob/e7a66a51d648c167096f0f37facd8d1e2af589b3/src/main/java/hudson/plugins/git/browser/Stash.java ). I only tested with SCMs that do have this capability, so not sure if it will gracely fail if the repository browser doesn't provide that feature: <j:set var = "changeSet" value= "${build.changeSet}" /> <j: if test= "${changeSet!= null }" > <j:set var = "hadChanges" value= " false " /> <TABLE width= "100%" > <TR><TD class= "bg1" colspan= "2" ><B>Changes</B></TD></TR> <j:forEach var = "cs" items= "${changeSet}" varStatus= "loop" > <j:set var = "hadChanges" value= " true " /> <j:set var = "aUser" value= "${cs.hudsonUser}" /> <TR> <TD colspan= "2" class= "bg2" >${spc}Revision <B><A href= "${build.parent.scm.effectiveBrowser.getChangeSetLink(cs)}" >${cs.commitId?:cs.revision?:cs.changeNumber}</A></B> by <j:set var = "userName" value= "${aUser!= null ?aUser.displayName:cs.author.displayName}" /> <B>${userName}: </B> <B>(${cs.msgAnnotated})</B> </TD> </TR> <j:forEach var = "p" items= "${cs.affectedFiles}" > <TR> <TD width= "10%" >${spc}${p.editType.name}</TD> <TD><A HREF= "${build.parent.scm.effectiveBrowser.getFileLink(p)}" >${p.path}</A>&#160; <j:choose> <j:when test= "${p.revision!= null }" > #${p.revision} </j:when> </j:choose> &#160; <j:set var = "diff" value= "${build.parent.scm.effectiveBrowser.getDiffLink(p)}" /> <j:choose> <j:when test= "${diff!= null }" > <a href= "${diff}" >Diff</a> </j:when> </j:choose> </TD> </TR> </j:forEach> </j:forEach> <j: if test= "${!hadChanges}" > <TR><TD colspan= "2" >No Changes</TD></TR> </j: if > </TABLE> <BR/> </j: if >

          Alex Earl added a comment -

          I'm hoping that the URL's in there are not your actual company URL's...you may want to edit and sanitize.

          Alex Earl added a comment - I'm hoping that the URL's in there are not your actual company URL's...you may want to edit and sanitize.

          Thanks Alex. Yes, one was. Sorry about that .. I did hint that the patch needed to be cleaned up...

          Mathieu Gervais added a comment - Thanks Alex. Yes, one was. Sorry about that .. I did hint that the patch needed to be cleaned up...

          Verbitan added a comment -

          Thanks Mathieu for that. That's given me exactly what I needed to set it up how I wanted.

          I'm more that willing to submit a pull request if you don't mind. I'll do it properly tonight or tomorrow.

          Thanks again guys.

          Verbitan added a comment - Thanks Mathieu for that. That's given me exactly what I needed to set it up how I wanted. I'm more that willing to submit a pull request if you don't mind. I'll do it properly tonight or tomorrow. Thanks again guys.

          Alex Earl added a comment -

          Haven't seen a pull request for this. You still have one coming?

          Alex Earl added a comment - Haven't seen a pull request for this. You still have one coming?

          Verbitan added a comment -

          I haven't gotten around to actually submitting anything to GitHub atm I'm afraid. I'm currently just running what Mathieu Gervais posted above.

          Verbitan added a comment - I haven't gotten around to actually submitting anything to GitHub atm I'm afraid. I'm currently just running what Mathieu Gervais posted above.

          Alex Earl added a comment -

          Someone will need to do a pull request if they are still interested in this.

          Alex Earl added a comment - Someone will need to do a pull request if they are still interested in this.

            slide_o_mix Alex Earl
            verbitan Verbitan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: