SomeFire closed pull request #22: IGNITE-9697 [TC Bot] Autocomplete branch for 
TC field
URL: https://github.com/apache/ignite-teamcity-bot/pull/22
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServer.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServer.java
index fc61c75..325327f 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServer.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServer.java
@@ -32,6 +32,12 @@
     /** Suite identifier by teamcity identification for root chain. */
     @Nonnull public String suiteId;
 
+    /** URL for git integration. */
+    @Nullable public String gitApiUrl;
+
+    /** URL for JIRA integration. */
+    @Nullable public String jiraApiUrl;
+
     public ChainAtServer() {
 
     }
@@ -39,6 +45,8 @@ public ChainAtServer() {
     public ChainAtServer(ChainAtServer o) {
         this.serverId = o.serverId;
         this.suiteId = o.suiteId;
+        this.gitApiUrl = o.gitApiUrl;
+        this.jiraApiUrl = o.jiraApiUrl;
     }
 
     /** {@inheritDoc} */
@@ -52,12 +60,14 @@ public ChainAtServer(ChainAtServer o) {
         ChainAtServer srv = (ChainAtServer)o;
 
         return Objects.equals(serverId, srv.serverId) &&
-            Objects.equals(suiteId, srv.suiteId);
+            Objects.equals(suiteId, srv.suiteId)&&
+            Objects.equals(gitApiUrl, srv.gitApiUrl)&&
+            Objects.equals(jiraApiUrl, srv.jiraApiUrl);
     }
 
     /** {@inheritDoc} */
     @Override public int hashCode() {
-        return Objects.hash(serverId, suiteId);
+        return Objects.hash(serverId, suiteId, gitApiUrl, jiraApiUrl);
     }
 
     /**
diff --git a/ignite-tc-helper-web/src/main/webapp/index.html 
b/ignite-tc-helper-web/src/main/webapp/index.html
index 1dc6eba..73cfb07 100644
--- a/ignite-tc-helper-web/src/main/webapp/index.html
+++ b/ignite-tc-helper-web/src/main/webapp/index.html
@@ -78,23 +78,29 @@
 
 function showSuitesForPrCheckData(result) {
     var res = "";
+
     for (var i = 0; i < result.length; i++) {
         var chainAtServer = result[i];
         //res+="<a 
href='pr.html?serverId=private&branchForTc=ignite-gg-12790-1&suiteId=id8xIgniteGridGainTests_RunAll="+id+"'>Check
 PR</a><br>";
 
+        gitUrls.set(chainAtServer.serverId, chainAtServer.gitApiUrl);
+
         res += "<form action='pr.html'>";
         res += "Server: <input type='text' name='serverId' value=" + 
chainAtServer.serverId + " readonly>";
         res += "Chain: <input type='text' name='suiteId' value=" + 
chainAtServer.suiteId + ">";
         res += "Base branch: <input type='text' name='baseBranchForTc'  
title='Etalon branch,e.g refs/heads/master'> ";
-        res += "<b>Branch:</b> <input type='text' name='branchForTc' 
title='Tested branch, e.g. pull/4790/head or ignite-9349' required> ";
+        res += "<b>Branch:</b> <input class='branchForTc" + 
chainAtServer.serverId + "' type='text' name='branchForTc'" +
+            " title='Tested branch, e.g. pull/4790/head or ignite-9349' 
required> ";
         res += "<input type='submit' name='action' value='Latest' title='Show 
latest runs'>";
         // res+="<input type='submit' name='action' value='Chain'>";
         res += "<input type='submit' name='action' value='History' title='Show 
last 10 runs merged'>";
         res += "</form>";
     }
+
     $("#suitesForPrCheck").html(res);
-}
 
+    sendRequestsToFillAutocompleteLists();
+}
 
 function showBuildsOnServers(result) {
     var res = "";
diff --git a/ignite-tc-helper-web/src/main/webapp/js/common-1.6.js 
b/ignite-tc-helper-web/src/main/webapp/js/common-1.6.js
index 6ef59d0..7487c2f 100644
--- a/ignite-tc-helper-web/src/main/webapp/js/common-1.6.js
+++ b/ignite-tc-helper-web/src/main/webapp/js/common-1.6.js
@@ -202,3 +202,95 @@ function tcHelperLogout() {
     } catch (e) {
     }
 }
+
+/**
+ * Change autocomplete filter to show results only when they starts from 
written text.
+ */
+$.ui.autocomplete.filter = function (array, term) {
+    var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(term), "i");
+
+    return $.grep(array, function (value) {
+        return matcher.test(value.label || value.value || value);
+    });
+};
+
+var callbackRegistry = {};
+
+/**
+ * Send request to another site.
+ *
+ * @param url URL.
+ * @param onSuccess Function for success response.
+ * @param onError Function for fail response.
+ */
+function scriptRequest(url, onSuccess, onError) {
+    var scriptOk = false;
+
+    var callbackName = 'cb' + String(Math.random()).slice(-6);
+
+    url += ~url.indexOf('?') ? '&' : '?';
+    url += 'callback=callbackRegistry.' + callbackName;
+
+    callbackRegistry[callbackName] = function(data) {
+        scriptOk = true;
+
+        delete callbackRegistry[callbackName];
+
+        onSuccess(data);
+    };
+
+    function checkCallback() {
+        if (scriptOk)
+            return;
+
+        delete callbackRegistry[callbackName];
+
+        onError(url);
+    }
+
+    var script = document.createElement('script');
+
+    script.onload = script.onerror = checkCallback;
+    script.src = url;
+
+    document.body.appendChild(script);
+}
+
+/**
+ * Key - server id.
+ * Value - url to git api.
+ *
+ * @type {Map<String, String>}
+ */
+var gitUrls = new Map();
+
+/**
+ * Send requests to the git to get pull requests for the branch autocomplete 
lists.
+ */
+function sendRequestsToFillAutocompleteLists() {
+    for (var entry of gitUrls.entries())
+        scriptRequest(entry[1] + "pulls?sort=updated&direction=desc", 
fillBranchAutocompleteList);
+}
+
+/**
+ * Takes all "branchForTc<server>" and add autocomplete list to them.
+ *
+ * @param result Response from git.
+ */
+function fillBranchAutocompleteList(result) {
+    if (!result.data || !result.data[0])
+        return;
+
+    for (var entry of gitUrls.entries()) {
+        if (result.data[0].url.startsWith(entry[1])) {
+            var branches = [{label:"master", value:"refs/heads/master"}];
+
+            for (let pr of result.data)
+                branches.push({label: pr.number, value: "pull/" + pr.number + 
"/head"});
+
+            $(".branchForTc" + entry[0]).autocomplete({source: branches});
+
+            break;
+        }
+    }
+}
diff --git a/ignite-tc-helper-web/src/main/webapp/services.html 
b/ignite-tc-helper-web/src/main/webapp/services.html
index 17746f0..2521f74 100644
--- a/ignite-tc-helper-web/src/main/webapp/services.html
+++ b/ignite-tc-helper-web/src/main/webapp/services.html
@@ -38,6 +38,7 @@
             $("#loadStatus").html("");
             showSuitesForTeamCityRunData(result);
             showCommentJiraForm(result);
+            setAutocompleteList(result);
         },
         error: showErrInLoadStatus
     });
@@ -55,7 +56,8 @@
 
         res += "Server: <input type='text' name='serverId' value='" + 
chainAtServer.serverId + "' readonly>";
         res += "Chain: <input type='text' name='suiteId' value='" + 
chainAtServer.suiteId + "' readonly>";
-        res += "Branch: <input type='text' name='branchForTc' required> ";
+        res += "Branch: <input type='text' name='branchForTc' 
class='branchForTc" + chainAtServer.serverId +
+            "' required> ";
         res += "Ticket: <input type='text' name='ticketId'>";
         res += "<button name='jira' type='button' 
onclick='trigBuild(\"tests\")'>Start tests</button>";
         res += "<button name='jira' onclick='trigBuild(\"tests+jira\")'>Start 
tests and comment JIRA ticket on ready</button>";
@@ -85,7 +87,8 @@
 
         res += "Server: <input type='text' name='serverId' value=" + 
chainAtServer.serverId +" readonly>" ;
         res += "Chain: <input type='text' name='suiteId' value='" + 
chainAtServer.suiteId + "' readonly>";
-        res += "Branch: <input type='text' name='branchForTc' required> ";
+        res += "Branch: <input type='text' name='branchForTc' 
class='branchForTc" + chainAtServer.serverId +
+            "' required> ";
         res += "Ticket: <input type='text' name='ticketId'> ";
         res += "<button name='action' onclick='notifyJira()'>Notify</button>";
     }
@@ -94,6 +97,21 @@
     $("#notifyJira").html(res);
 }
 
+/**
+ * Fill git URLs and send requests to them.
+ *
+ * @param result - Set of ChainAtServer objects.
+ */
+function setAutocompleteList(result) {
+    for (var i = 0; i < result.length; i++) {
+        var chainAtServer = result[i];
+
+        gitUrls.set(chainAtServer.serverId, chainAtServer.gitApiUrl);
+    }
+
+    sendRequestsToFillAutocompleteLists();
+}
+
 /**
  * Start Run All build on TeamCity and comment in JIRA ticket when build will 
be finished.
  */


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to