You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dp...@apache.org on 2019/01/17 14:11:16 UTC

[ignite-teamcity-bot] branch ignite-10930 updated: IGNITE-10930: PR-less contributions: handle PR less contributions branch naming

This is an automated email from the ASF dual-hosted git repository.

dpavlov pushed a commit to branch ignite-10930
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git


The following commit(s) were added to refs/heads/ignite-10930 by this push:
     new 88a16f3  IGNITE-10930: PR-less contributions: handle PR less contributions branch naming
88a16f3 is described below

commit 88a16f3c05dd3bde49bd95787c21db3804621c79
Author: Dmitriy Pavlov <dp...@apache.org>
AuthorDate: Thu Jan 17 17:11:11 2019 +0300

    IGNITE-10930: PR-less contributions: handle PR less contributions branch naming
---
 .../ci/github/ignited/IGitHubConnIgnited.java      |  11 ---
 .../ignite/ci/github/pure/IGitHubConnection.java   |   2 +-
 .../ignite/ci/tcbot/chain/PrChainsProcessor.java   |   2 +-
 .../tcbot/visa/TcBotTriggerAndSignOffService.java  | 101 ++++++++++++++++-----
 .../model/current/ChainAtServerCurrentStatus.java  |  16 +++-
 .../ignite/ci/web/rest/pr/GetPrTestFailures.java   |   9 +-
 ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js |  13 ++-
 .../ci/tcbot/chain/MockBasedTcBotModule.java       |   7 +-
 8 files changed, 114 insertions(+), 47 deletions(-)

diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/IGitHubConnIgnited.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/IGitHubConnIgnited.java
index 81d36c9..c61619b 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/IGitHubConnIgnited.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/IGitHubConnIgnited.java
@@ -35,17 +35,6 @@ public interface IGitHubConnIgnited {
     /** */
     public PullRequest getPullRequest(int prNum);
 
-    /** */
-    @AutoProfiling
-    @Nullable
-    public default PullRequest getPullRequest(String branchForTc) {
-        Integer prId = IGitHubConnection.convertBranchToId(branchForTc);
-
-        Preconditions.checkNotNull(prId, "Invalid TC branch name");
-
-        return getPullRequest(prId);
-    }
-
     /**
      * Send POST request with given body.
      *
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/IGitHubConnection.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/IGitHubConnection.java
index 2bf08ca..b2ab22a 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/IGitHubConnection.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/IGitHubConnection.java
@@ -55,7 +55,7 @@ public interface IGitHubConnection {
     /**
      * @return PR id from string "pull/XXXX/head"
      */
-    public @Nullable static Integer convertBranchToId(String branchForTc) {
+    @Nullable public static Integer convertBranchToId(String branchForTc) {
         Integer res = null;
 
         if (Objects.isNull(branchForTc))
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/chain/PrChainsProcessor.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/chain/PrChainsProcessor.java
index 6d84015..8c280e9 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/chain/PrChainsProcessor.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/chain/PrChainsProcessor.java
@@ -160,7 +160,7 @@ public class PrChainsProcessor {
             //fail rate reference is always default (master)
             chainStatus.initFromContext(tcIgnited, teamcity, ctx, teamcity, baseBranch);
 
-            chainStatus.initJiraAndGitInfo(jiraIntegration, gitHubConnIgnited);
+            chainStatus.initJiraAndGitInfo(tcIgnited, jiraIntegration, gitHubConnIgnited);
         }
 
         res.addChainOnServer(chainStatus);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/TcBotTriggerAndSignOffService.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/TcBotTriggerAndSignOffService.java
index 7c99b59..d47933b 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/TcBotTriggerAndSignOffService.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/TcBotTriggerAndSignOffService.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.ci.tcbot.visa;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.inject.Provider;
 import java.text.DateFormat;
@@ -26,7 +27,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Objects;
@@ -44,6 +44,7 @@ import org.apache.ignite.ci.github.GitHubUser;
 import org.apache.ignite.ci.github.PullRequest;
 import org.apache.ignite.ci.github.ignited.IGitHubConnIgnited;
 import org.apache.ignite.ci.github.ignited.IGitHubConnIgnitedProvider;
+import org.apache.ignite.ci.github.pure.IGitHubConnection;
 import org.apache.ignite.ci.jira.Ticket;
 import org.apache.ignite.ci.jira.ignited.IJiraIgnited;
 import org.apache.ignite.ci.jira.ignited.IJiraIgnitedProvider;
@@ -309,18 +310,24 @@ public class TcBotTriggerAndSignOffService {
 
         if (F.isEmpty(ticketFullName)) {
             try {
-                IGitHubConnIgnited gitHubConn = gitHubConnIgnitedProvider.server(srvId);
+                ticketFullName = prLessTicket(srvId, branchForTc, prov, prefix);
 
-                PullRequest pr = gitHubConn.getPullRequest(branchForTc);
+                PullRequest pr = null;
 
-                ticketFullName = getTicketFullName(pr, prefix);
+                if (Strings.isNullOrEmpty(ticketFullName)) {
+                    pr = findPrForBranch(srvId, branchForTc);
 
-                if (ticketFullName.isEmpty()) {
-                    return "JIRA ticket will not be notified after the tests are completed - " +
-                        "PR title \"" + pr.getTitle() + "\" should starts with \"" + prefix + "NNNNN\"." +
+                    if (pr != null)
+                        ticketFullName = getTicketFullName(pr, prefix);
+                }
+
+                if (Strings.isNullOrEmpty(ticketFullName)) {
+                    return "JIRA ticket will not be notified - " +
+                        "PR title \"" + (pr == null ? "" : pr.getTitle()) + "\" should starts with \"" + prefix + "NNNNN\"." +
                         " Please, rename PR according to the" +
                         " <a href='https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute" +
-                        "#HowtoContribute-1.CreateGitHubpull-request'>contributing guide</a>.";
+                        "#HowtoContribute-1.CreateGitHubpull-request'>contributing guide</a>" +
+                        " or use branch name according ticket name.";
                 }
             }
             catch (Exception e) {
@@ -357,24 +364,28 @@ public class TcBotTriggerAndSignOffService {
         ICredentialsProv prov) {
         String jiraRes = "";
 
-        IJiraIgnited jiraIntegration = jiraIgnProv.server(srvId);
-
-        String prefix = jiraIntegration.ticketPrefix();
+        String prefix = jiraIgnProv.server(srvId).ticketPrefix();
 
         if (Strings.isNullOrEmpty(ticketFullName)) {
             try {
-                IGitHubConnIgnited gitHubConn = gitHubConnIgnitedProvider.server(srvId);
-                PullRequest pr = gitHubConn.getPullRequest(branchForTc);
+                ticketFullName = prLessTicket(srvId, branchForTc, prov, prefix);
+
+                PullRequest pr = null;
 
-                ticketFullName = getTicketFullName(pr, prefix);
+                if (Strings.isNullOrEmpty(ticketFullName)) {
+                    pr = findPrForBranch(srvId, branchForTc);
+
+                    if (pr != null)
+                        ticketFullName = getTicketFullName(pr, prefix);
+                }
 
-                if (ticketFullName.isEmpty()) {
+                if (Strings.isNullOrEmpty(ticketFullName)) {
                     jiraRes = "JIRA ticket can't be commented - " +
-                        "PR title \"" + pr.getTitle() + "\" should starts with \"" + prefix + "NNNNN\"." +
+                        "PR title \"" + (pr == null ? "" : pr.getTitle()) + "\" should starts with \"" + prefix + "NNNNN\"." +
                         " Please, rename PR according to the" +
                         " <a href='https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute" +
                         "#HowtoContribute-1.CreateGitHubpull-request'>contributing guide</a>" +
-                        " or enter ticket id in the form.";
+                        " or use branch name according ticket name.";
                 }
             }
             catch (RuntimeException e) {
@@ -405,6 +416,51 @@ public class TcBotTriggerAndSignOffService {
             return new SimpleResult("JIRA wasn't commented." + (!jiraRes.isEmpty() ? "<br>" + jiraRes : ""));
     }
 
+    @Nullable public PullRequest findPrForBranch(
+        @Nullable @QueryParam("serverId") String srvId,
+        @Nullable @QueryParam("branchName") String branchForTc) {
+        Integer prId = IGitHubConnection.convertBranchToId(branchForTc);
+
+        if (prId == null)
+            return null;
+
+        IGitHubConnIgnited gh = gitHubConnIgnitedProvider.server(srvId);
+
+        return gh.getPullRequest(prId);
+    }
+
+    /**
+     * @param srvId Server id.
+     * @param branchForTc Branch for tc.
+     * @param prov Credentials Prov.
+     * @param ticketPrefix Ticket prefix.
+     */
+    @Nullable public String prLessTicket(@Nullable @QueryParam("serverId") String srvId,
+        String branchForTc, ICredentialsProv prov, String ticketPrefix) {
+        return prLessTicket(branchForTc, ticketPrefix, tcIgnitedProv.server(srvId, prov));
+    }
+
+    /**
+     * @param branchForTc Branch for tc.
+     * @param ticketPrefix Ticket prefix.
+     * @param tcIgn Tc ign.
+     */
+    @Nullable public static String prLessTicket(String branchForTc, String ticketPrefix, ITeamcityIgnited tcIgn) {
+        String branchPrefix = tcIgn.gitBranchPrefix();
+
+        if (!branchForTc.startsWith(branchPrefix))
+            return null;
+
+        try {
+            int ticketNum = Integer.parseInt(branchForTc.substring(branchPrefix.length()));
+
+            return ticketPrefix + ticketNum;
+        }
+        catch (NumberFormatException ignored) {
+        }
+        return null;
+    }
+
     /**
      * @param srvId Server id.
      * @param credsProv Credentials
@@ -489,10 +545,8 @@ public class TcBotTriggerAndSignOffService {
             return buildHist;
 
         Integer prNum = Integer.valueOf(prId);
-        if (prNum < 0) {
+        if (prNum < 0)
             return buildHist; // Don't iterate for other options if PR ID is absent
-        }
-
 
         buildHist = srv.getAllBuildsCompacted(suiteId, branchForTcB(prId));
 
@@ -573,10 +627,11 @@ public class TcBotTriggerAndSignOffService {
 
 
         for (String btId : compositeBuildTypeIds) {
-            List<BuildRefCompacted> forTests = findBuildsForPr(btId, prId, ghConn, teamcity);
+            List<BuildRefCompacted> compBuilds = findBuildsForPr(btId, prId, ghConn, teamcity);
 
-            statuses.add(forTests.isEmpty() ? new ContributionCheckStatus(btId, branchForTcDefault(prId, teamcity)) :
-                contributionStatus(srvId, btId, forTests, teamcity, prId));
+            statuses.add(compBuilds.isEmpty()
+                ? new ContributionCheckStatus(btId, branchForTcDefault(prId, teamcity))
+                : contributionStatus(srvId, btId, compBuilds, teamcity, prId));
         }
 
         return statuses;
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/current/ChainAtServerCurrentStatus.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/current/ChainAtServerCurrentStatus.java
index b75cc30..5d4402b 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/current/ChainAtServerCurrentStatus.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/current/ChainAtServerCurrentStatus.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.ci.web.model.current;
 
 import com.google.common.base.Objects;
+import com.google.common.base.Strings;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
@@ -126,7 +127,8 @@ public class ChainAtServerCurrentStatus {
     }
 
     /** */
-    public void initJiraAndGitInfo(IJiraIntegration jiraIntegration, IGitHubConnIgnited gitHubConnIgnited) {
+    public void initJiraAndGitInfo(ITeamcityIgnited tcIgnited,
+        IJiraIntegration jiraIntegration, IGitHubConnIgnited gitHubConnIgnited) {
         Integer prNum = IGitHubConnection.convertBranchToId(branchName);
 
         String prUrl = null;
@@ -135,18 +137,22 @@ public class ChainAtServerCurrentStatus {
 
         String ticketUrl = null;
 
+        String ticketPrefix = jiraIntegration.ticketPrefix();
+
         if (prNum != null) {
             PullRequest pullReq = gitHubConnIgnited.getPullRequest(prNum);
 
             if (pullReq != null && pullReq.getTitle() != null) {
                 prUrl = pullReq.htmlUrl();
 
-                ticketFullName = TcBotTriggerAndSignOffService.getTicketFullName(pullReq, jiraIntegration.ticketPrefix());
-
-                if (!ticketFullName.isEmpty())
-                    ticketUrl = jiraIntegration.generateTicketUrl(ticketFullName);
+                ticketFullName = TcBotTriggerAndSignOffService.getTicketFullName(pullReq, ticketPrefix);
             }
         }
+        else
+            ticketFullName = TcBotTriggerAndSignOffService.prLessTicket(branchName, ticketPrefix, tcIgnited);
+
+        if (!Strings.isNullOrEmpty(ticketFullName))
+            ticketUrl = jiraIntegration.generateTicketUrl(ticketFullName);
 
         setPrInfo(prNum, prUrl);
         setJiraTicketInfo(ticketFullName, ticketUrl);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/pr/GetPrTestFailures.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/pr/GetPrTestFailures.java
index 88d9d30..7745e73 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/pr/GetPrTestFailures.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/pr/GetPrTestFailures.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.ci.web.rest.pr;
 
+import com.google.common.base.Preconditions;
 import com.google.inject.Injector;
 import javax.annotation.Nonnull;
 import javax.servlet.ServletContext;
@@ -32,6 +33,7 @@ import javax.ws.rs.core.MediaType;
 import org.apache.ignite.ci.github.PullRequest;
 import org.apache.ignite.ci.github.ignited.IGitHubConnIgnited;
 import org.apache.ignite.ci.github.ignited.IGitHubConnIgnitedProvider;
+import org.apache.ignite.ci.github.pure.IGitHubConnection;
 import org.apache.ignite.ci.tcbot.chain.PrChainsProcessor;
 import org.apache.ignite.ci.teamcity.ignited.SyncMode;
 import org.apache.ignite.ci.user.ICredentialsProv;
@@ -140,7 +142,12 @@ public class GetPrTestFailures {
         PullRequest pr;
 
         try {
-            pr = srv.getPullRequest(branchForTc);
+            Integer prId = IGitHubConnection.convertBranchToId(branchForTc);
+
+            if (prId == null)
+                return "Invalid TC branch name: [" + branchForTc + "]";
+
+            pr = srv.getPullRequest(prId);
         }
         catch (RuntimeException e) {
             return "Exception happened - " + e.getMessage();
diff --git a/ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js b/ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js
index 3675175..2ecb6fc 100644
--- a/ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js
+++ b/ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js
@@ -96,7 +96,7 @@ function showContributionsTable(result, srvId, suiteId) {
                 "data": "prHtmlUrl",
                 title: "PR Number",
                 "render": function (data, type, row, meta) {
-                    if (type === 'display' && row.prNumber>0) {
+                    if (type === 'display' && row.prNumber > 0) {
                         data = "<a href='" + data + "'>#" + row.prNumber + "</a>";
                     }
 
@@ -256,9 +256,14 @@ function formatContributionDetails(row, srvId) {
         "           </tr>";
 
     //References
-    res += "        <tr>\n" +
-        "            <td>Edit PR: " + "<a href='" + row.prHtmlUrl + "'>#" + row.prNumber + "</a>" + "</td>\n" +
-        "            <td id='viewQueuedBuildsFor" + prId + "'></td>\n" +
+    res += "        <tr>\n";
+
+    if (row.prNumber > 0)
+        res += "            <td>Edit PR: " + "<a href='" + row.prHtmlUrl + "'>#" + row.prNumber + "</a>" + "</td>\n";
+    else
+        res += "            <td></td>\n";
+
+    res += "            <td id='viewQueuedBuildsFor" + prId + "'></td>\n" +
         "            <td></td>\n" +
         "            <td></td>\n" +
         "        </tr>";
diff --git a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/MockBasedTcBotModule.java b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/MockBasedTcBotModule.java
index 4fa11cd..4b4b1d0 100644
--- a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/MockBasedTcBotModule.java
+++ b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/MockBasedTcBotModule.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.ci.tcbot.chain;
 
+import com.google.common.base.Preconditions;
 import com.google.inject.AbstractModule;
 import com.google.inject.internal.SingletonScope;
 import org.apache.ignite.ci.IAnalyticsEnabledTeamcity;
@@ -76,7 +77,11 @@ public class MockBasedTcBotModule extends AbstractModule {
 
         when(pullReq.getTitle()).thenReturn("");
 
-        when(gitHubConnIgnited.getPullRequest(anyString())).thenReturn(pullReq);
+        Integer prId = IGitHubConnection.convertBranchToId(anyString());
+
+        Preconditions.checkNotNull(prId, "Invalid TC branch name");
+
+        when(gitHubConnIgnited.getPullRequest(prId)).thenReturn(pullReq);
 
         when(gitHubConnIgnitedProvider.server(anyString())).thenReturn(gitHubConnIgnited);