You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/07/13 16:15:44 UTC

[49/50] [abbrv] incubator-ignite git commit: # ignite-1099

# ignite-1099


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/8a0dbc21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8a0dbc21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8a0dbc21

Branch: refs/heads/ignite-1099
Commit: 8a0dbc21cabc8e69266602312edc56b815fec5fc
Parents: bc336d9
Author: ashutak <as...@gridgain.com>
Authored: Mon Jul 13 16:59:16 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Mon Jul 13 16:59:16 2015 +0300

----------------------------------------------------------------------
 .../tools/jirabranches/JiraBranchesToHtml.java  | 250 +++++++++++--------
 scripts/jira-branches.sh                        |   4 +-
 2 files changed, 142 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8a0dbc21/modules/tools/src/main/java/org/apache/ignite/tools/jirabranches/JiraBranchesToHtml.java
----------------------------------------------------------------------
diff --git a/modules/tools/src/main/java/org/apache/ignite/tools/jirabranches/JiraBranchesToHtml.java b/modules/tools/src/main/java/org/apache/ignite/tools/jirabranches/JiraBranchesToHtml.java
index 1e5b8bd..a705d23 100644
--- a/modules/tools/src/main/java/org/apache/ignite/tools/jirabranches/JiraBranchesToHtml.java
+++ b/modules/tools/src/main/java/org/apache/ignite/tools/jirabranches/JiraBranchesToHtml.java
@@ -37,22 +37,13 @@ import java.util.regex.*;
  */
 public class JiraBranchesToHtml {
     /** */
-    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("MM/dd/yyyy");
-
-    /** Jira url. */
-    private String jiraUrl;
-
-    /** Script path. */
-    private String scriptPath;
+    public static final String OUTPUT_FILE = U.getIgniteHome() + "/scripts/jira-branches-results.html";
 
-    /** Input file. */
-    private String inputFile;
-
-    /** Output file. */
-    private String outputFile;
+    /** */
+    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("MM/dd/yyyy");
 
     /** */
-    private static final Pattern TICKET_PATTERN = Pattern.compile("\\d{5}|\\d{4}");
+    private static final Pattern TICKET_PATTERN = Pattern.compile("\\d{5}|\\d{4}|\\d{3}");
 
     /** */
     private static final Comparator<Result> COMP = new Comparator<Result>() {
@@ -68,28 +59,67 @@ public class JiraBranchesToHtml {
                 return o1.issue == null ? 1 : -1;
         }
     };
-    private String prefix;
 
     /**
      * @param args Arguments.
      * @throws Exception If failed.
      */
     public static void main(String[] args) throws Exception {
-        new JiraBranchesToHtml()
-            .setJiraUrl("https://issues.apache.org/jira")
-            .setPrefix("IGNITE")
-            .setScriptPath(U.getIgniteHome() + "/scripts/jira-branches.sh")
-            .setInputFile(U.getIgniteHome() + "/scripts/jira-branches.js")
-            .setOutputFile(U.getIgniteHome() + "/scripts/jira-branches-results.html")
-            .generateReport();
+        System.out.print("Report 'Closed' issues only [y/N]: ");
+
+        BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
+
+        boolean closedOnly = "y".equalsIgnoreCase(rdr.readLine());
+
+        List<String> branches = getBranches();
+
+        Credentials cred = askForJiraCredentials("https://issues.apache.org/jira");
+
+        List<Result> res = new ArrayList<>();
+
+        try (JiraRestClient restClient = new AsynchronousJiraRestClientFactory().
+            createWithBasicHttpAuthentication(URI.create(cred.jiraUrl), cred.name, cred.pswd)) {
+            for (String branchName : branches) {
+                if (branchName.toLowerCase().startsWith("IGNITE".toLowerCase())) {
+                    Result r = result(restClient, branchName, cred.jiraUrl);
+
+                    if (r.issue == null || !closedOnly || "Closed".equalsIgnoreCase(r.issue.getStatus().getName())) {
+                        System.out.println("Added issue: " + r);
+
+                        res.add(r);
+                    }
+                }
+            }
+        }
+
+        makeReport(res);
+    }
+
+    /**
+     * @param res Results.
+     * @throws IOException
+     */
+    public static void makeReport(List<Result> res) throws IOException {
+        String s = printIssueDetails(res);
+
+        System.out.println(s);
+
+        try (OutputStreamWriter bw = new OutputStreamWriter(new FileOutputStream(OUTPUT_FILE))) {
+            bw.write(s);
+        }
+
+        if (Desktop.isDesktopSupported())
+            Desktop.getDesktop().open(new File(OUTPUT_FILE));
+        else
+            System.out.println("Results have been written to: " + OUTPUT_FILE);
     }
 
     /**
-     * Generate report about git branches and related Jira issues.
-     *
-     * @throws Exception
+     * @param jiraUrl Jira URL.
+     * @return Credentials/
+     * @throws Exception If failed.
      */
-    public void generateReport() throws Exception {
+    public static Credentials askForJiraCredentials(String jiraUrl) throws Exception{
         System.out.println("Need to enter credentials for JIRA [" + jiraUrl + "]");
         System.out.print("JIRA user: ");
 
@@ -108,9 +138,16 @@ public class JiraBranchesToHtml {
         if (F.isEmpty(pswd))
             throw new IllegalStateException("JIRA password cannot be empty.");
 
-        System.out.print("Report 'Closed' issues only [y/N]: ");
+        return new Credentials(jiraUrl, user, pswd);
+    }
 
-        boolean closedOnly = "y".equalsIgnoreCase(rdr.readLine());
+    /**
+     * @return All branches from origin repository.
+     * @throws Exception if failed.
+     */
+    public static List<String> getBranches() throws Exception {
+        String scriptPath = U.getIgniteHome() + "/scripts/jira-branches.sh";
+        String inputFile = U.getIgniteHome() + "/scripts/jira-branches.js";
 
         System.out.println();
         System.out.println(">>> Executing script: " + scriptPath);
@@ -133,109 +170,81 @@ public class JiraBranchesToHtml {
             throw new Exception("Failed to run script [script=" + scriptPath +
                 ", exitCode=" + proc.exitValue() + ']');
 
-        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
-             JiraRestClient restClient = new AsynchronousJiraRestClientFactory().
-                 createWithBasicHttpAuthentication(URI.create(jiraUrl), user, pswd)) {
-            List<Result> res = new ArrayList<>();
+        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)))) {
+            List<String> branches = new ArrayList<>();
 
             for (String line; (line = br.readLine()) != null; ) {
-                String branchName = line.replace("\\", "").trim();
-
-                if (branchName.startsWith(prefix)) {
-                    Result r = result(restClient, branchName);
-
-                    if (r.error != null) {
-                        Matcher m = TICKET_PATTERN.matcher(branchName);
+                String branch = line.replace("\\", "").trim();
 
-                        if (m.find()) {
-                            Result r0 = result(restClient, prefix + "-" + m.group(0));
-
-                            if (r0.error == null)
-                                r = new Result(branchName, r0.issue, null);
-                        }
-                    }
-
-                    if (r.issue == null || !closedOnly || "Closed".equalsIgnoreCase(r.issue.getStatus().getName())) {
-                        System.out.println("Added issue: " + r);
-
-                        res.add(r);
-                    }
-                }
-            }
-
-            String s = printIssueDetails(res);
-
-            System.out.println(s);
-
-            try (OutputStreamWriter bw = new OutputStreamWriter(new FileOutputStream(outputFile))) {
-                bw.write(s);
+                if (branch.startsWith("remotes/origin/"))
+                    branches.add(branch.substring("remotes/origin/".length()));
             }
 
-            if (Desktop.isDesktopSupported())
-                Desktop.getDesktop().open(new File(outputFile));
-            else
-                System.out.println("Results have been written to: " + outputFile);
+            return branches;
         }
     }
 
     /**
-     * @param jiraUrl Jira url.
-     */
-    public JiraBranchesToHtml setJiraUrl(String jiraUrl) {
-        this.jiraUrl = jiraUrl;
-
-        return this;
-    }
-
-    /**
-     * @param scriptPath Script path.
+     * @param restClient Rest client.
+     * @param branchName Branch name.
+     * @param jiraUrl
+     * @return Result.
      */
-    public JiraBranchesToHtml setScriptPath(String scriptPath) {
-        this.scriptPath = scriptPath;
+    protected static Result result(JiraRestClient restClient, String branchName, String jiraUrl) {
+        int idx1 = branchName.indexOf('-');
 
-        return this;
-    }
+        if (idx1 == -1)
+            return new Result(branchName, null, "Unknown branch name pattern.", jiraUrl);
 
-    /**
-     * @param inputFile Input file.
-     */
-    public JiraBranchesToHtml setInputFile(String inputFile) {
-        this.inputFile = inputFile;
+        int idx2 = branchName.indexOf('-', idx1 + 1);
 
-        return this;
-    }
+        System.out.println(">>>>> " + branchName + " " + idx1 + " " + idx2);
 
-    /**
-     * @param outputFile Output file.
-     */
-    public JiraBranchesToHtml setOutputFile(String outputFile) {
-        this.outputFile = outputFile;
+        if (idx2 == -1)
+            // For branches like "IGNITE-xxx"
+            try {
+                Issue issue = restClient.getIssueClient().getIssue(branchName).claim();
 
-        return this;
-    }
+                return new Result(branchName, issue, null, jiraUrl);
+            }
+            catch (RestClientException e) {
+                return new Result(branchName, null, e.getMessage(), jiraUrl);
+            }
+        else {
+            // For branches like "IGNITE-xxx-<description>".
+            try {
+                Integer.valueOf(branchName.substring(idx1+1, idx2));
 
-    /**
-     * @param prefix Jira prefix.
-     */
-    public JiraBranchesToHtml setPrefix(String prefix) {
-        this.prefix = prefix;
+                try {
+                    Issue issue = restClient.getIssueClient().getIssue(branchName.substring(0, idx2)).claim();
 
-        return this;
+                    return new Result(branchName, issue, null, jiraUrl);
+                }
+                catch (RestClientException e) {
+                    return new Result(branchName, null, e.getMessage(), jiraUrl);
+                }
+            }
+            catch (NumberFormatException ignore) {
+                return new Result(branchName, null, "Unknown branch name pattern. " +
+                    "Expected that '" + branchName.substring(idx1+1, idx2) + "' is a number.", jiraUrl);
+            }
+        }
     }
 
     /**
      * @param restClient Rest client.
      * @param branchName Branch name.
+     * @param jiraUrl
      * @return Result.
      */
-    private static Result result(JiraRestClient restClient, String branchName) {
+    private static Result result0(String branchName, JiraRestClient restClient, String jiraName, String jiraUrl) {
         try {
-            Issue issue = restClient.getIssueClient().getIssue(branchName).claim();
+            Issue issue = restClient.getIssueClient().getIssue(jiraName).claim();
 
-            return new Result(branchName, issue, null);
+            return new Result(branchName, issue, null, jiraUrl);
         }
         catch (RestClientException e) {
-            return new Result(branchName, null, e.getMessage());
+            return new Result(branchName, null, e.getMessage(), jiraUrl);
         }
     }
 
@@ -243,7 +252,7 @@ public class JiraBranchesToHtml {
      * @param res Results.
      * @return Output.
      */
-    private String printIssueDetails(List<Result> res) {
+    private static String printIssueDetails(List<Result> res) {
         StringBuilder sb = new StringBuilder();
 
         println(sb, "<html>\n<head></head>\n<body>");
@@ -262,7 +271,7 @@ public class JiraBranchesToHtml {
             }
 
             print(sb, "<th colspan=7 align=\"left\">" +
-                "<a href=" + URI.create(jiraUrl) + "/browse/" + r.issue.getKey() + ">" +
+                "<a href=" + URI.create(r.jiraUrl) + "/browse/" + r.issue.getKey() + ">" +
                 r.issueKey + ' ' + r.issue.getSummary() + "<a></th>");
 
             print(sb, "</tr><tr>");
@@ -322,21 +331,25 @@ public class JiraBranchesToHtml {
     }
 
     /** */
-    private static class Result {
+    public static class Result {
+        /** */
+        public final String issueKey;
+
         /** */
-        private final String issueKey;
+        public final Issue issue;
 
         /** */
-        private final Issue issue;
+        public final String error;
 
         /** */
-        private final String error;
+        public final String jiraUrl;
 
         /** */
-        Result(String issueKey, Issue issue, String error) {
+        public Result(String issueKey, Issue issue, String error, String url) {
             this.issueKey = issueKey;
             this.issue = issue;
             this.error = error;
+            jiraUrl = url;
         }
 
         /** {@inheritDoc} */
@@ -348,4 +361,23 @@ public class JiraBranchesToHtml {
                 ']';
         }
     }
+
+    /** */
+    public static class Credentials {
+        /** */
+        public final String jiraUrl;
+
+        /** */
+        public final String name;
+
+        /** */
+        public final String pswd;
+
+        /** */
+        Credentials(String jiraUrl, String name, String pswd) {
+            this.jiraUrl = jiraUrl;
+            this.name = name;
+            this.pswd = pswd;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8a0dbc21/scripts/jira-branches.sh
----------------------------------------------------------------------
diff --git a/scripts/jira-branches.sh b/scripts/jira-branches.sh
index d97a141..2d16ced 100755
--- a/scripts/jira-branches.sh
+++ b/scripts/jira-branches.sh
@@ -9,10 +9,8 @@ echo Update git branches list file.
 
 echo "var \$branches = \"\\" > $FILE
 
-git branch -a | grep remotes/origin/ignite- | sed 's/remotes\/origin\/ignite\-\(.*\)$/IGNITE-\1 \\/g' >> $FILE
+git branch -a >> $FILE
 
 echo '";' >> $FILE
 
 echo "var \$branchesDate = '$(date +"%Y-%m-%d")';" >> $FILE
-
-echo Open in browser $(dirname $FILE)/jira-branches.html