1717
1818package org .clebert ;
1919
20+ import javax .json .Json ;
21+ import javax .json .JsonObject ;
22+ import javax .json .JsonString ;
2023import java .io .ByteArrayOutputStream ;
2124import java .io .File ;
2225import java .io .IOException ;
2326import java .io .InputStream ;
2427import java .io .OutputStream ;
2528import java .io .PrintStream ;
29+ import java .net .URL ;
2630import java .text .DateFormat ;
2731import java .text .SimpleDateFormat ;
2832import java .util .ArrayList ;
4852import org .eclipse .jgit .treewalk .CanonicalTreeParser ;
4953import org .eclipse .jgit .util .io .DisabledOutputStream ;
5054
55+ import org .apache .johnzon .core .*;
56+
5157/**
5258 * @author Clebert Suconic
5359 */
@@ -59,9 +65,11 @@ public class GitParser {
5965 final String jira ;
6066 final String jiraBrowseURI ;
6167 final String githubURI ;
68+ String restLocation ;
6269 String [] sourceSuffix ;
6370 // JQL used to list all JIRAs here
6471 String sampleJQL ;
72+ String [] currentJiras ;
6573
6674 final HashSet <String > totalJiras = new HashSet <>();
6775
@@ -101,6 +109,15 @@ public GitParser setSourceSuffix(String... sourceSuffix) {
101109 return this ;
102110 }
103111
112+ public String getRestLocation () {
113+ return restLocation ;
114+ }
115+
116+ public GitParser setRestLocation (String restLocation ) {
117+ this .restLocation = restLocation ;
118+ return this ;
119+ }
120+
104121 private String makeALink (String text , String uri ) {
105122 return "<a href='" + uri + "'>" + text + "</a>" ;
106123 }
@@ -132,10 +149,10 @@ public static String[] extractJIRAs(String jira, String message) {
132149 }
133150
134151 public String prettyCommitMessage (String message ) {
135- String [] jiras = extractJIRAs (jira , message );
136- for (int i = 0 ; i < jiras .length ; i ++) {
137- totalJiras .add (jiras [i ]);
138- message = message .replace (jiras [i ], makeALink (jiras [i ], jiraBrowseURI + jiras [i ]));
152+ currentJiras = extractJIRAs (jira , message );
153+ for (int i = 0 ; i < currentJiras .length ; i ++) {
154+ totalJiras .add (currentJiras [i ]);
155+ message = message .replace (currentJiras [i ], makeALink (currentJiras [i ], jiraBrowseURI + currentJiras [i ]));
139156 }
140157
141158 return message ;
@@ -159,6 +176,35 @@ private String readString(String fileName) throws Exception {
159176 return new String (out .toByteArray ());
160177 }
161178
179+ JsonObject lastJIRAObject ;
180+ String lastJIRA ;
181+
182+ private JsonObject restJIRA (String JIRA ) throws Exception {
183+
184+ System .out .println ("Inspecting " + JIRA );
185+ if (lastJIRA != null && lastJIRA .equals (JIRA )) {
186+ return lastJIRAObject ;
187+ }
188+ if (restLocation != null ) {
189+ URL url = new URL (restLocation + JIRA );
190+ InputStream stream = url .openStream ();
191+
192+ lastJIRA = JIRA ;
193+ lastJIRAObject = Json .createReader (stream ).readObject ();
194+ return lastJIRAObject ;
195+ }
196+ return null ;
197+ }
198+
199+ private String getField (JsonObject object , String name ) {
200+
201+ try {
202+ return object .getJsonObject ("fields" ).getJsonObject (name ).getString ("name" );
203+ } catch (Throwable e ) {
204+ return " " ;
205+ }
206+ }
207+
162208 public void parse (PrintStream output , String from , String to ) throws Exception {
163209 Git git = Git .open (folder );
164210 RevWalk walk = new RevWalk (git .getRepository ());
@@ -196,7 +242,7 @@ public void parse(PrintStream output, String from, String to) throws Exception {
196242
197243 StringBuffer interestingChanges [] = new StringBuffer [interestingFolder .size ()];
198244
199- output .print ("<thead><tr><th>#</th><th>Commit</th><th>Date</th><th>Author</th><th>Short Message</th><th>Adds</th><th>Updates</th><th>Deletes</th>" );
245+ output .print ("<thead><tr><th>#</th><th>Commit</th><th>Date</th><th>Author</th><th>Short Message</th><th>Jira Status</th><th> Adds</th><th>Updates</th><th>Deletes</th>" );
200246
201247 for (int i = 0 ; i < interestingFolder .size (); i ++) {
202248 output .print ("<th>" + interestingFolder .get (i ) + "</th>" );
@@ -225,6 +271,29 @@ public void parse(PrintStream output, String from, String to) throws Exception {
225271 output .print ("<td>" + commit .getAuthorIdent ().getName () + "</td>" );
226272 output .print ("<td>" + prettyCommitMessage (commit .getShortMessage ()) + "</td>" );
227273
274+ StringBuffer bufferJIRA = new StringBuffer ();
275+ if (currentJiras != null ) {
276+ for (int i = 0 ; i < currentJiras .length ; i ++) {
277+
278+ String jiraIteration = currentJiras [i ];
279+ if (restLocation != null ) {
280+ JsonObject object = restJIRA (jiraIteration );
281+ String issuetype = getField (object , "issuetype" );
282+ String status = getField (object , "status" );
283+ String resolution = getField (object , "resolution" );
284+ bufferJIRA .append (makeALink (issuetype + "/" + resolution + "/" + status , jiraBrowseURI + jiraIteration ));
285+ } else {
286+ bufferJIRA .append (makeALink (jiraIteration , jiraBrowseURI + jiraIteration ));
287+ }
288+
289+ if (i < currentJiras .length -1 ) {
290+ bufferJIRA .append ("," );
291+ }
292+ }
293+
294+ }
295+ output .println ("<td>" + bufferJIRA .toString () + "</td>" );
296+
228297 oldTreeIter .reset (reader , commit .getParent (0 ).getTree ());
229298 newTreeIter .reset (reader , commit .getTree ());
230299
0 commit comments