This is an automated email from the ASF dual-hosted git repository.
dpavlov pushed a commit to branch ignite-9800
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git
The following commit(s) were added to refs/heads/ignite-9800 by this push:
new b232b4b IGNITE-9800: More for skeleton for contributions to check list
b232b4b is described below
commit b232b4ba3424e63cbbcf339e0038049510261161
Author: Dmitriy Pavlov <[email protected]>
AuthorDate: Fri Oct 5 19:05:51 2018 +0300
IGNITE-9800: More for skeleton for contributions to check list
---
.../ignite/ci/github/GitHubConnectionImpl.java | 25 ++++++++-
.../apache/ignite/ci/github/IGitHubConnection.java | 2 +
.../ContributionToCheck.java} | 35 +++---------
.../ci/visa/TcBotTriggerAndSignOffService.java | 22 ++++----
.../apache/ignite/ci/web/rest/TriggerBuild.java | 23 ++++----
.../ignite/ci/web/rest/visa/TcBotVisaService.java | 62 ++++++++++++++++++++++
ignite-tc-helper-web/src/main/webapp/prs.html | 60 +++++++++++++++++++--
7 files changed, 172 insertions(+), 57 deletions(-)
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubConnectionImpl.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubConnectionImpl.java
index adb7fc1..4f6a098 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubConnectionImpl.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubConnectionImpl.java
@@ -16,12 +16,15 @@
*/
package org.apache.ignite.ci.github;
+import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import org.apache.ignite.ci.HelperConfig;
import org.apache.ignite.ci.di.AutoProfiling;
@@ -56,8 +59,7 @@ class GitHubConnectionImpl implements IGitHubConnection {
/** {@inheritDoc} */
@AutoProfiling
@Override public PullRequest getPullRequest(String branchForTc) {
- if (isNullOrEmpty(gitApiUrl))
- throw new IllegalStateException("Git API URL is not configured for
this server.");
+ Preconditions.checkState( !isNullOrEmpty(gitApiUrl) , "Git API URL is
not configured for this server.");
String id = null;
@@ -110,4 +112,23 @@ class GitHubConnectionImpl implements IGitHubConnection {
public String gitApiUrl() {
return gitApiUrl;
}
+
+ @Override public void getPullRequests() {
+ Preconditions.checkState( !isNullOrEmpty(gitApiUrl) , "Git API URL is
not configured for this server.");
+
+ String s = gitApiUrl + "pulls?sort=updated&direction=desc";
+
+ if(s!=null)
+ return;
+ try( InputStream stream = HttpUtil.sendGetToGit(gitAuthTok, s )){
+ ;
+ InputStreamReader reader = new InputStreamReader(stream);
+ HashMap<String, Object> map = new Gson().fromJson(reader, HashMap
.class);
+
+ System.out.println(map);
+ }
+ catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
}
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/IGitHubConnection.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/IGitHubConnection.java
index a510c73..a0b7461 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/IGitHubConnection.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/IGitHubConnection.java
@@ -44,4 +44,6 @@ public interface IGitHubConnection {
* @return URL for git integration.
*/
String gitApiUrl();
+
+ void getPullRequests();
}
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/IGitHubConnection.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/visa/ContributionToCheck.java
similarity index 52%
copy from
ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/IGitHubConnection.java
copy to
ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/visa/ContributionToCheck.java
index a510c73..09bebef 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/IGitHubConnection.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/visa/ContributionToCheck.java
@@ -14,34 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.ignite.ci.github;
+package org.apache.ignite.ci.visa;
-public interface IGitHubConnection {
-
- void init(String srvId);
-
- /**
- * @param branch TeamCity's branch name. Looks like "pull/123/head".
- * @return Pull Request.
- */
- PullRequest getPullRequest(String branch);
-
- /**
- * Send POST request with given body.
- *
- * @param url Url.
- * @param body Request body.
- * @return {@code True} - if GitHub was notified. {@code False} -
otherwise.
- */
- boolean notifyGit(String url, String body);
-
- /**
- * @return {@code True} if GitHub authorization token is available.
- */
- boolean isGitTokenAvailable();
-
- /**
- * @return URL for git integration.
- */
- String gitApiUrl();
+/**
+ *
+ */
+public class ContributionToCheck {
+ public String prNumber;
}
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/visa/TcBotTriggerAndSignOffService.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/visa/TcBotTriggerAndSignOffService.java
index 9c620a7..d4bca2c 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/visa/TcBotTriggerAndSignOffService.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/visa/TcBotTriggerAndSignOffService.java
@@ -18,11 +18,11 @@
package org.apache.ignite.ci.visa;
import com.google.common.base.Strings;
-import com.google.inject.Injector;
import com.google.inject.Provider;
+import java.util.Collections;
+import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.QueryParam;
-import org.apache.ignite.ci.ITcHelper;
import org.apache.ignite.ci.ITcServerProvider;
import org.apache.ignite.ci.ITeamcity;
import org.apache.ignite.ci.github.IGitHubConnection;
@@ -77,12 +77,10 @@ public class TcBotTriggerAndSignOffService {
@Nullable Boolean top,
@Nullable Boolean observe,
@Nullable String ticketId,
- ICredentialsProv prov,
- Injector injector) {
+ ICredentialsProv prov) {
String jiraRes = "";
- ITcHelper helper = injector.getInstance(ITcHelper.class);
- final ITeamcity teamcity = helper.server(srvId, prov);
+ final ITeamcity teamcity = tcServerProvider.server(srvId, prov);
Build build = teamcity.triggerBuild(suiteId, branchForTc, false, top
!= null && top);
@@ -144,15 +142,12 @@ public class TcBotTriggerAndSignOffService {
@QueryParam("suiteId") @Nullable String suiteId,
@QueryParam("ticketId") @Nullable String ticketId,
ICredentialsProv prov) {
-
-
String jiraRes = "";
- final ITeamcity teamcity = tcServerProvider.server(srvId, prov);
if (Strings.isNullOrEmpty(ticketId)) {
try {
- IGitHubConnection gitHubConnection =
gitHubConnectionProvider.server(srvId, prov);
- PullRequest pr = gitHubConnection.getPullRequest(branchForTc);
+ IGitHubConnection gitHubConn =
gitHubConnectionProvider.server(srvId, prov);
+ PullRequest pr = gitHubConn.getPullRequest(branchForTc);
ticketId = TcBotTriggerAndSignOffService.getTicketId(pr);
@@ -179,5 +174,10 @@ public class TcBotTriggerAndSignOffService {
return new SimpleResult("JIRA wasn't commented." +
(!jiraRes.isEmpty() ? "<br>" + jiraRes : ""));
}
+ public List<ContributionToCheck> getContributionsToCheck(String srvId) {
+ IGitHubConnection gitHubConn = gitHubConnectionProvider.server(srvId,
null);
+ gitHubConn.getPullRequests();
+ return Collections.singletonList(new ContributionToCheck());
+ }
}
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuild.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuild.java
index 49e921f..5514a72 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuild.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuild.java
@@ -47,9 +47,11 @@ import org.jetbrains.annotations.Nullable;
@Path("build")
@Produces(MediaType.APPLICATION_JSON)
public class TriggerBuild {
+ /** Servlet Context. */
@Context
- private ServletContext context;
+ private ServletContext ctx;
+ /** Current Request. */
@Context
private HttpServletRequest req;
@@ -69,10 +71,9 @@ public class TriggerBuild {
if (!prov.hasAccess(srvId))
throw ServiceUnauthorizedException.noCreds(srvId);
- Injector injector = CtxListener.getInjector(context);
- TcBotTriggerAndSignOffService triggerAndSignOffSvc =
injector.getInstance(TcBotTriggerAndSignOffService.class);
-
- String jiraRes = triggerAndSignOffSvc. triggerBuildAndObserve(srvId,
branchForTc, suiteId, top, observe, ticketId, prov, injector);
+ String jiraRes = CtxListener.getInjector(ctx)
+ .getInstance(TcBotTriggerAndSignOffService.class)
+ .triggerBuildAndObserve(srvId, branchForTc, suiteId, top, observe,
ticketId, prov);
return new SimpleResult("Tests started." + (!jiraRes.isEmpty() ?
"<br>" + jiraRes : ""));
}
@@ -91,11 +92,9 @@ public class TriggerBuild {
if (!prov.hasAccess(srvId))
throw ServiceUnauthorizedException.noCreds(srvId);
- Injector injector = CtxListener.getInjector(context);
-
- TcBotTriggerAndSignOffService signOffSvc =
injector.getInstance(TcBotTriggerAndSignOffService.class);
-
- return signOffSvc.commentJiraEx(srvId, branchForTc, suiteId, ticketId,
prov);
+ return CtxListener.getInjector(ctx)
+ .getInstance(TcBotTriggerAndSignOffService.class)
+ .commentJiraEx(srvId, branchForTc, suiteId, ticketId, prov);
}
@GET
@@ -115,7 +114,7 @@ public class TriggerBuild {
if (strings.isEmpty())
return new SimpleResult("Error: nothing to run");
- final ITeamcity helper =
CtxListener.getTcHelper(context).server(serverId, prov);
+ final ITeamcity helper = CtxListener.getTcHelper(ctx).server(serverId,
prov);
boolean queueToTop = top != null && top;
@@ -139,7 +138,7 @@ public class TriggerBuild {
if (!prov.hasAccess(srvId))
return null;
- Injector injector = CtxListener.getInjector(context);
+ Injector injector = CtxListener.getInjector(ctx);
ITcHelper tcHelper = injector.getInstance(ITcHelper.class);
final ICredentialsProv creds = ICredentialsProv.get(req);
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/visa/TcBotVisaService.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/visa/TcBotVisaService.java
new file mode 100644
index 0000000..033ac2b
--- /dev/null
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/visa/TcBotVisaService.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.ci.web.rest.visa;
+
+import java.util.List;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import org.apache.ignite.ci.user.ICredentialsProv;
+import org.apache.ignite.ci.visa.ContributionToCheck;
+import org.apache.ignite.ci.visa.TcBotTriggerAndSignOffService;
+import org.apache.ignite.ci.web.CtxListener;
+import org.apache.ignite.ci.web.rest.exception.ServiceUnauthorizedException;
+import org.jetbrains.annotations.Nullable;
+
+@Path("visa")
+@Produces(MediaType.APPLICATION_JSON)
+public class TcBotVisaService {
+ /** Servlet Context. */
+ @Context
+ private ServletContext ctx;
+
+ /** Current Request. */
+ @Context
+ private HttpServletRequest req;
+
+ @GET
+ @Path("contributions")
+ public List<ContributionToCheck> contributions(
+ @Nullable @QueryParam("serverId") String srvId
+ ) {
+
+ final ICredentialsProv prov = ICredentialsProv.get(req);
+
+ if (!prov.hasAccess(srvId))
+ throw ServiceUnauthorizedException.noCreds(srvId);
+
+ TcBotTriggerAndSignOffService instance = CtxListener.getInjector(ctx)
+ .getInstance(TcBotTriggerAndSignOffService.class);
+
+ return instance.getContributionsToCheck(srvId);
+ }
+}
diff --git a/ignite-tc-helper-web/src/main/webapp/prs.html
b/ignite-tc-helper-web/src/main/webapp/prs.html
index be80561..bbe01fb 100644
--- a/ignite-tc-helper-web/src/main/webapp/prs.html
+++ b/ignite-tc-helper-web/src/main/webapp/prs.html
@@ -55,7 +55,52 @@
$.ajax({
url: "rest/branches/getServerIds",
- success: setupAutocompleteList
+ success:
+ function (result) {
+ setupAutocompleteList(result);
+ for (let srvId of result)
+ requestTableForServer(srvId, "");
+ }
+ });
+ }
+
+ function requestTableForServer(srvId) {
+ // TODO multiple servers
+ if (srvId != "apache")
+ return;
+
+ let tableForSrv = $('#serverContributions-' + srvId);
+ $.ajax({
+ url: "rest/visa/contributions?serverId="+srvId,
+ success:
+ function (result) {
+ showTable(tableForSrv, result)
+ }
+ });
+ }
+
+ function showTable(tableForSrv, result) {
+
+ tableForSrv.dataTable().fnDestroy();
+
+ tableForSrv.DataTable({
+ data: result,
+ bSort: false,
+ order: [[0, 'asc']],
+ columns: [{
+ "data": "prNumber",
+ title: "PR Number"
+ }
+ //,
+ /* {
+ "data": "serviceLogin",
+ title: "login"
+ },
+ {
+ "data": "servicePassword",
+ title: "Password"
+ }*/
+ ]
});
}
@@ -195,8 +240,17 @@
<div id="accordion" style="height: 500px">
<h3>Select PR</h3>
- <div>
-
+ <div id="contributionsToCheck">
+ <table id="serverContributions-apache" class="ui-widget
ui-widget-content">
+ <thead>
+ <tr class="ui-widget-header ">
+ <th>PR number</th>
+ <!--
+ <th>Login</th>
+ <th>Password</th>-->
+ </tr>
+ </thead>
+ </table>
</div>