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/04/13 10:05:24 UTC
[ignite-teamcity-bot] branch master updated: TC Bot config
refactored to avoid a number of properties files. Now it can be configured
only using branches.json;
Branches scan implemented so it is now possible to see PR-less contributions
without starting build. - Fixes #117.
This is an automated email from the ASF dual-hosted git repository.
dpavlov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git
The following commit(s) were added to refs/heads/master by this push:
new 27aa503 TC Bot config refactored to avoid a number of properties files. Now it can be configured only using branches.json; Branches scan implemented so it is now possible to see PR-less contributions without starting build. - Fixes #117.
27aa503 is described below
commit 27aa50321c306ec49e6655001ea4fbb3565d3ecd
Author: Dmitriy Pavlov <dp...@apache.org>
AuthorDate: Sat Apr 13 13:05:12 2019 +0300
TC Bot config refactored to avoid a number of properties files. Now it can be configured only using branches.json; Branches scan implemented so it is now possible to see PR-less contributions without starting build. - Fixes #117.
Signed-off-by: Dmitriy Pavlov <dp...@apache.org>
---
conf/branches.json | 5 +-
.../java/org/apache/ignite/ci/HelperConfig.java | 63 ++-------
.../main/java/org/apache/ignite/ci/ITeamcity.java | 4 -
.../apache/ignite/ci/IgnitePersistentTeamcity.java | 5 -
.../apache/ignite/ci/IgniteTeamcityConnection.java | 7 +-
.../org/apache/ignite/ci/di/cache/GuavaCached.java | 3 +
.../org/apache/ignite/ci/github/GitHubBranch.java | 2 +
.../{GitHubBranch.java => GitHubBranchKey.java} | 58 ++++++---
.../{GitHubBranch.java => GitHubBranchShort.java} | 40 +++---
.../{GitHubBranch.java => GitHubCommit.java} | 28 +---
.../org/apache/ignite/ci/github/GitHubUser.java | 2 +
.../ci/github/ignited/GitHubConnIgnitedImpl.java | 142 ++++++++++++++++++---
.../ci/github/ignited/GitHubIgnitedProvImpl.java | 14 +-
.../ci/github/ignited/IGitHubConnIgnited.java | 9 ++
.../ci/github/pure/GitHubCachingProvider.java | 14 +-
.../ci/github/pure/GitHubConnectionImpl.java | 92 +++++++------
.../ignite/ci/github/pure/IGitHubConnection.java | 26 ++--
.../ci/jira/ignited/IJiraIgnitedProvider.java | 4 +-
.../ci/jira/ignited/JiraIgnitedProvider.java | 6 +-
.../ignite/ci/jira/pure/IJiraIntegration.java | 4 +-
.../java/org/apache/ignite/ci/jira/pure/Jira.java | 14 +-
.../ci/jira/pure/JiraIntegrationProvider.java | 6 +-
.../org/apache/ignite/ci/jira/pure/Status.java | 11 ++
.../org/apache/ignite/ci/jira/pure/Ticket.java | 9 +-
.../apache/ignite/ci/runners/ClientTmpHelper.java | 26 +++-
.../ignite/ci/tcbot/chain/PrChainsProcessor.java | 14 +-
.../ignite/ci/tcbot/conf/BranchesTracked.java | 2 +-
.../apache/ignite/ci/tcbot/conf/GitHubConfig.java | 89 ++++++++++---
.../apache/ignite/ci/tcbot/conf/IGitHubConfig.java | 29 ++++-
.../ignite/ci/tcbot/conf/IJiraServerConfig.java | 5 +
.../apache/ignite/ci/tcbot/conf/ITcBotConfig.java | 1 +
.../ignite/ci/tcbot/conf/ITcServerConfig.java | 3 +
.../ignite/ci/tcbot/conf/JiraServerConfig.java | 13 +-
.../ci/tcbot/conf/LocalFilesBasedConfig.java | 16 ++-
.../ignite/ci/tcbot/conf/TcServerConfig.java | 22 ++--
.../tcbot/visa/TcBotTriggerAndSignOffService.java | 36 +++---
.../ignite/ci/teamcity/pure/TcLoginImpl.java | 5 +-
.../restcached/InitializingServerFactory.java | 6 +-
.../org/apache/ignite/ci/web/model/Version.java | 2 +-
.../ignite/ci/web/model/current/UpdateInfo.java | 2 +-
.../apache/ignite/ci/web/rest/TriggerBuilds.java | 2 +-
.../ci/tcbot/chain/MockBasedTcBotModule.java | 4 +-
42 files changed, 543 insertions(+), 302 deletions(-)
diff --git a/conf/branches.json b/conf/branches.json
index a9df1bd..56f4112 100644
--- a/conf/branches.json
+++ b/conf/branches.json
@@ -1,10 +1,13 @@
{
+ // Default server (service) code, internal identification
"primaryServerCode": "apache",
"tcServers": [
{
+ //code of current server
"code": "public",
+
+ // reference to another TC server service code to be used instead.
"reference": "apache"
- // reference to another TC server to be used instead.
}
],
"jiraServers": [
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java
index 579ffb9..ee5fedc 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java
@@ -21,14 +21,12 @@ import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import java.io.File;
import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Properties;
-
-import org.apache.ignite.ci.tcbot.conf.BranchesTracked;
import org.apache.ignite.ci.conf.PasswordEncoder;
import org.apache.ignite.ci.tcbot.TcBotSystemProperties;
+import org.apache.ignite.ci.tcbot.conf.BranchesTracked;
import org.apache.ignite.ci.util.Base64Util;
import org.apache.ignite.ci.util.ExceptionUtil;
import org.jetbrains.annotations.NotNull;
@@ -56,7 +54,7 @@ public class HelperConfig {
/** JIRA authorization token property name. */
public static final String JIRA_AUTH_TOKEN = "jira.auth_token";
- /** JIRA authorization token property name. */
+ /** Github API url for the project. */
public static final String GIT_API_URL = "git.api_url";
/** JIRA URL to build links to tickets. */
@@ -83,16 +81,11 @@ public class HelperConfig {
private static Properties loadAuthPropertiesX(File workDir, String cfgFileName) throws IOException {
File file = new File(workDir, cfgFileName);
- if (!(file.exists())) {
-
- try (FileWriter writer = new FileWriter(file)) {
- writer.write(HOST + "=" + "http://ci.ignite.apache.org/" + ENDL);
- writer.write(USERNAME + "=" + ENDL);
- writer.write(ENCODED_PASSWORD + "=" + ENDL);
- }
- throw new IllegalStateException("Please setup parameters for service in config file [" +
- file.getCanonicalPath() + "]");
- }
+
+ Preconditions.checkState(file.exists(),
+ "Please setup parameters for service in config file [branches.json]. " +
+ "See conf directory for examples");
+
return loadProps(file);
}
@@ -136,43 +129,6 @@ public class HelperConfig {
return ensureDirExist(workDir);
}
- /**
- * Extract GitHub authorization token from properties.
- *
- * @param props Properties, where token is placed.
- * @return Null or decoded auth token for Github.
- */
- @Nullable public static String prepareGithubHttpAuthToken(Properties props) {
- String tok = props.getProperty(GITHUB_AUTH_TOKEN);
-
- if (isNullOrEmpty(tok))
- return null;
-
- tok = PasswordEncoder.decode(tok);
-
- return tok;
- }
-
- /**
- * Extract TeamCity authorization token from properties.
- *
- * @param props Properties, where token is placed.
- * @param cfgName Configuration name.
- * @return Null or decoded auth token for Github.
- */
- @Nullable static String prepareBasicHttpAuthToken(Properties props, String cfgName) {
- final String user = getMandatoryProperty(props, USERNAME, cfgName);
-
- String enc = props.getProperty(ENCODED_PASSWORD);
-
- if (isNullOrEmpty(enc))
- return null;
-
- String pwd = PasswordEncoder.decode(enc);
-
- return userPwdToToken(user, pwd);
- }
-
@NotNull public static String userPwdToToken(String user, String pwd) {
return Base64Util.encodeUtf8String(user + ":" + pwd);
}
@@ -187,9 +143,10 @@ public class HelperConfig {
final File workDir = resolveWorkDir();
final File file = new File(workDir, "branches.json");
- try(final FileReader json = new FileReader(file)) {
+ try (FileReader json = new FileReader(file)) {
return new Gson().fromJson(json, BranchesTracked.class);
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw ExceptionUtil.propagateException(e);
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITeamcity.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITeamcity.java
index 1f002b8..c9be5dc 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITeamcity.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITeamcity.java
@@ -72,14 +72,10 @@ public interface ITeamcity extends ITeamcityConn {
*/
boolean isTeamCityTokenAvailable();
-
default void setAuthData(String user, String pwd) {
setAuthToken(
Base64Util.encodeUtf8String(user + ":" + pwd));
}
- void init(String serverId);
-
User getUserByUsername(String username);
-
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
index b40f24a..b297196 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
@@ -89,11 +89,6 @@ public class IgnitePersistentTeamcity implements IAnalyticsEnabledTeamcity, ITea
}
/** {@inheritDoc} */
- @Override public void init(String srvId) {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
@Override public User getUserByUsername(String username) {
return teamcity.getUserByUsername(username);
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
index a8d004a..da570d6 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
@@ -94,7 +94,7 @@ public class IgniteTeamcityConnection implements ITeamcity {
/** Teamcity http connection. */
@Inject private ITeamcityHttpConnection teamcityHttpConn;
- @Inject private ITcBotConfig config;
+ @Inject private ITcBotConfig cfg;
private String srvCode;
@@ -105,15 +105,14 @@ public class IgniteTeamcityConnection implements ITeamcity {
return executor;
}
- /** {@inheritDoc} */
- @Override public void init(@Nullable String srvCode) {
+ public void init(@Nullable String srvCode) {
this.srvCode = srvCode;
this.executor = MoreExecutors.directExecutor();
}
public ITcServerConfig config() {
- return this.config.getTeamcityConfig(this.srvCode );
+ return cfg.getTeamcityConfig(this.srvCode);
}
/** {@inheritDoc} */
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/cache/GuavaCached.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/cache/GuavaCached.java
index a1a0226..126ed93 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/cache/GuavaCached.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/cache/GuavaCached.java
@@ -21,6 +21,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * <b>Note: </b> this cachind annotation ignores object called, may be used only for siglenton-scope classes.
+ */
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD)
public @interface GuavaCached {
/**
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java
index 931dd30..98e0d07 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java
@@ -17,7 +17,9 @@
package org.apache.ignite.ci.github;
import java.util.Objects;
+import org.apache.ignite.ci.db.Persisted;
+@Persisted
public class GitHubBranch {
/** Label. */
private String label;
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranchKey.java
similarity index 52%
copy from ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java
copy to ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranchKey.java
index 931dd30..2eb1d00 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranchKey.java
@@ -16,40 +16,58 @@
*/
package org.apache.ignite.ci.github;
+import com.google.common.base.Strings;
import java.util.Objects;
+import org.apache.ignite.ci.db.Persisted;
+import org.jetbrains.annotations.NotNull;
-public class GitHubBranch {
- /** Label. */
- private String label;
+@Persisted
+public class GitHubBranchKey implements Comparable<GitHubBranchKey> {
+ int srvId;
+ String branchName;
- /** Branch name. */
- private String ref;
-
- /** Sha of latest commit. */
- private String sha;
-
- /** {@inheritDoc} */
@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
- GitHubBranch branch = (GitHubBranch)o;
- return Objects.equals(label, branch.label) &&
- Objects.equals(ref, branch.ref) &&
- Objects.equals(sha, branch.sha);
+ GitHubBranchKey key = (GitHubBranchKey)o;
+ return srvId == key.srvId &&
+ Objects.equals(branchName, key.branchName);
}
- /** {@inheritDoc} */
@Override public int hashCode() {
- return Objects.hash(label, ref, sha);
+ return Objects.hash(srvId, branchName);
+ }
+
+ public GitHubBranchKey branchName(String name) {
+ this.branchName = name;
+
+ return this;
}
- public String ref() {
- return ref;
+ public GitHubBranchKey srvId(int high) {
+ this.srvId = high;
+
+ return this;
+ }
+
+ /** */
+ public int srvId() {
+ return srvId;
}
- public String sha() {
- return sha;
+ /** */
+ public String branchName() {
+ return branchName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int compareTo(@NotNull GitHubBranchKey o) {
+ int compare = Integer.compare(srvId, o.srvId());
+ if (compare != 0)
+ return compare;
+
+ return Strings.nullToEmpty(branchName).compareTo(o.branchName());
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranchShort.java
similarity index 69%
copy from ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java
copy to ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranchShort.java
index 931dd30..e2ee268 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranchShort.java
@@ -17,16 +17,21 @@
package org.apache.ignite.ci.github;
import java.util.Objects;
+import org.apache.ignite.ci.db.Persisted;
-public class GitHubBranch {
- /** Label. */
- private String label;
-
- /** Branch name. */
- private String ref;
-
- /** Sha of latest commit. */
- private String sha;
+/**
+ *
+ */
+@Persisted
+public class GitHubBranchShort {
+ /** Name. */
+ String name;
+ /** Commit. */
+ GitHubCommit commit;
+
+ public String name() {
+ return name;
+ }
/** {@inheritDoc} */
@Override public boolean equals(Object o) {
@@ -34,22 +39,13 @@ public class GitHubBranch {
return true;
if (o == null || getClass() != o.getClass())
return false;
- GitHubBranch branch = (GitHubBranch)o;
- return Objects.equals(label, branch.label) &&
- Objects.equals(ref, branch.ref) &&
- Objects.equals(sha, branch.sha);
+ GitHubBranchShort aShort = (GitHubBranchShort)o;
+ return Objects.equals(name, aShort.name) &&
+ Objects.equals(commit, aShort.commit);
}
/** {@inheritDoc} */
@Override public int hashCode() {
- return Objects.hash(label, ref, sha);
- }
-
- public String ref() {
- return ref;
- }
-
- public String sha() {
- return sha;
+ return Objects.hash(name, commit);
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubCommit.java
similarity index 70%
copy from ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java
copy to ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubCommit.java
index 931dd30..e13e8e0 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubBranch.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubCommit.java
@@ -17,15 +17,11 @@
package org.apache.ignite.ci.github;
import java.util.Objects;
+import org.apache.ignite.ci.db.Persisted;
-public class GitHubBranch {
- /** Label. */
- private String label;
-
- /** Branch name. */
- private String ref;
-
- /** Sha of latest commit. */
+@Persisted
+public class GitHubCommit {
+ /** Sha of the commit. */
private String sha;
/** {@inheritDoc} */
@@ -34,22 +30,12 @@ public class GitHubBranch {
return true;
if (o == null || getClass() != o.getClass())
return false;
- GitHubBranch branch = (GitHubBranch)o;
- return Objects.equals(label, branch.label) &&
- Objects.equals(ref, branch.ref) &&
- Objects.equals(sha, branch.sha);
+ GitHubCommit commit = (GitHubCommit)o;
+ return Objects.equals(sha, commit.sha);
}
/** {@inheritDoc} */
@Override public int hashCode() {
- return Objects.hash(label, ref, sha);
- }
-
- public String ref() {
- return ref;
- }
-
- public String sha() {
- return sha;
+ return Objects.hash(sha);
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubUser.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubUser.java
index 44f7594..d43b0a2 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubUser.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/GitHubUser.java
@@ -18,7 +18,9 @@ package org.apache.ignite.ci.github;
import com.google.gson.annotations.SerializedName;
import java.util.Objects;
+import org.apache.ignite.ci.db.Persisted;
+@Persisted
public class GitHubUser {
@SerializedName("login") private String login;
@SerializedName("avatar_url") private String avatarUrl;
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubConnIgnitedImpl.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubConnIgnitedImpl.java
index e17e7bb..e1375c5 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubConnIgnitedImpl.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubConnIgnitedImpl.java
@@ -34,20 +34,25 @@ import org.apache.ignite.ci.db.TcHelperDb;
import org.apache.ignite.ci.di.AutoProfiling;
import org.apache.ignite.ci.di.MonitoredTask;
import org.apache.ignite.ci.di.scheduler.IScheduler;
+import org.apache.ignite.ci.github.GitHubBranchKey;
+import org.apache.ignite.ci.github.GitHubBranchShort;
import org.apache.ignite.ci.github.PullRequest;
import org.apache.ignite.ci.github.pure.IGitHubConnection;
import org.apache.ignite.ci.tcbot.conf.IGitHubConfig;
import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
*/
class GitHubConnIgnitedImpl implements IGitHubConnIgnited {
- /** Cache name. */
- public static final String GIT_HUB_PR = "gitHubPr";
+ /** Logger. */
+ private static final Logger logger = LoggerFactory.getLogger(GitHubConnIgnitedImpl.class);
+
/** Server id. */
- private String srvId;
+ private String srvCode;
/** Pure HTTP Connection API. */
private IGitHubConnection conn;
@@ -59,18 +64,30 @@ class GitHubConnIgnitedImpl implements IGitHubConnIgnited {
@Inject IScheduler scheduler;
/** Server ID mask for cache Entries. */
- private long srvIdMaskHigh;
+ private int srvIdMaskHigh;
/** PPs cache. */
private IgniteCache<Long, PullRequest> prCache;
- public void init(String srvId, IGitHubConnection conn) {
- this.srvId = srvId;
+
+ /** PPs cache. */
+ private IgniteCache<GitHubBranchKey, GitHubBranchShort> branchCache;
+
+ /**
+ * @param conn Connection.
+ */
+ public void init(IGitHubConnection conn) {
this.conn = conn;
+ srvCode = conn.config().code();
+
+ logger.info("Init of GitHub server: srvCode=" + srvCode+ ", API Url=" +
+ config().gitApiUrl() + " " + config().code());
- srvIdMaskHigh = Math.abs(srvId.hashCode());
+ srvIdMaskHigh = Math.abs(srvCode.hashCode());
- prCache = igniteProvider.get().getOrCreateCache(TcHelperDb.getCache8PartsConfig(GIT_HUB_PR));
+ Ignite ignite = igniteProvider.get();
+ prCache = ignite.getOrCreateCache(TcHelperDb.getCache8PartsConfig(GIT_HUB_PR));
+ branchCache = ignite.getOrCreateCache(TcHelperDb.getCache8PartsConfig(GIT_HUB_BRANCHES));
}
/** {@inheritDoc} */
@@ -107,17 +124,33 @@ class GitHubConnIgnitedImpl implements IGitHubConnIgnited {
.collect(Collectors.toList());
}
+ /** {@inheritDoc} */
+ @AutoProfiling
+ @Override public List<String> getBranches() {
+ scheduler.sheduleNamed(taskName("actualizeBranches"), this::actualizeBranches, 2, TimeUnit.HOURS);
+
+ return StreamSupport.stream(branchCache.spliterator(), false)
+ .filter(entry -> entry.getKey().srvId() == srvIdMaskHigh)
+ .map(javax.cache.Cache.Entry::getKey)
+ .map(GitHubBranchKey::branchName)
+ .collect(Collectors.toList());
+ }
+
+ private void actualizeBranches() {
+ runActualizeBranches(srvCode, true);
+ }
+
/**
* @param taskName Task name.
* @return Task name concatenated with server name.
*/
@NotNull
private String taskName(String taskName) {
- return IGitHubConnIgnited.class.getSimpleName() + "." + taskName + "." + srvId;
+ return IGitHubConnIgnited.class.getSimpleName() + "." + taskName + "." + srvCode;
}
private void actualizePrs() {
- runActualizePrs(srvId, false);
+ runActualizePrs(srvCode, false);
// schedule full resync later
scheduler.invokeLater(
@@ -129,7 +162,7 @@ class GitHubConnIgnitedImpl implements IGitHubConnIgnited {
*
*/
private void fullReindex() {
- runActualizePrs(srvId, true);
+ runActualizePrs(srvCode, true);
}
/**
@@ -142,16 +175,16 @@ class GitHubConnIgnitedImpl implements IGitHubConnIgnited {
protected String runActualizePrs(String srvId, boolean fullReindex) {
AtomicReference<String> outLinkNext = new AtomicReference<>();
- List<PullRequest> ghData = conn.getPullRequests(null, outLinkNext);
+ List<PullRequest> ghData = conn.getPullRequestsPage(null, outLinkNext);
Set<Integer> actualPrs = new HashSet<>();
- int cntSaved = saveChunk(ghData);
+ int cntSaved = savePrsChunk(ghData);
int totalChecked = ghData.size();
while (outLinkNext.get() != null) {
String nextPageUrl = outLinkNext.get();
- ghData = conn.getPullRequests(nextPageUrl, outLinkNext);
- int savedThisChunk = saveChunk(ghData);
+ ghData = conn.getPullRequestsPage(nextPageUrl, outLinkNext);
+ int savedThisChunk = savePrsChunk(ghData);
cntSaved += savedThisChunk;
totalChecked += ghData.size();
@@ -186,7 +219,10 @@ class GitHubConnIgnitedImpl implements IGitHubConnIgnited {
return "PRs updated for " + srvId + ": " + cnt + " from " + prCache.size();
}
- private int saveChunk(List<PullRequest> ghData) {
+ /**
+ * @param ghData GitHub data to save.
+ */
+ private int savePrsChunk(List<PullRequest> ghData) {
Set<Long> ids = ghData.stream().map(PullRequest::getNumber)
.map(this::prNumberToCacheKey)
.collect(Collectors.toSet());
@@ -203,12 +239,82 @@ class GitHubConnIgnitedImpl implements IGitHubConnIgnited {
}
int size = entriesToPut.size();
+
if (size != 0)
prCache.putAll(entriesToPut);
+
+ return size;
+ }
+
+ private long prNumberToCacheKey(int prNum) {
+ return (long)prNum | (long)srvIdMaskHigh << 32;
+ }
+
+ /**
+ * @param srvId Server id.
+ * @param fullReindex Reindex all open PRs
+ */
+ @SuppressWarnings({"WeakerAccess", "UnusedReturnValue"})
+ @MonitoredTask(name = "Actualize GitHub Branches(srv, full resync)", nameExtArgsIndexes = {0, 1})
+ @AutoProfiling
+ protected String runActualizeBranches(String srvId, boolean fullReindex) {
+ AtomicReference<String> outLinkNext = new AtomicReference<>();
+
+ List<GitHubBranchShort> ghData = conn.getBranchesPage(null, outLinkNext);
+
+ Set<Integer> actualPrs = new HashSet<>();
+
+ int cntSaved = saveBranchesChunk(ghData);
+ int totalChecked = ghData.size();
+ while (outLinkNext.get() != null) {
+ String nextPageUrl = outLinkNext.get();
+ ghData = conn.getBranchesPage(nextPageUrl, outLinkNext);
+ int savedThisChunk = saveBranchesChunk(ghData);
+ cntSaved += savedThisChunk;
+ totalChecked += ghData.size();
+
+ if (!fullReindex && savedThisChunk == 0)
+ break;
+ }
+
+ if (fullReindex)
+ refreshOutdatedPrs(srvId, actualPrs);
+
+ return "Entries saved " + cntSaved + " Branches checked " + totalChecked;
+ }
+
+
+ /**
+ * @param ghData GitHub data to save.
+ */
+ private int saveBranchesChunk(List<GitHubBranchShort> ghData) {
+ Set<GitHubBranchKey> ids = ghData.stream()
+ .map(this::branchToKey)
+ .collect(Collectors.toSet());
+
+ Map<GitHubBranchKey, GitHubBranchShort> existingEntries = branchCache.getAll(ids);
+ Map<GitHubBranchKey, GitHubBranchShort> entriesToPut = new TreeMap<>();
+
+ for (GitHubBranchShort next : ghData) {
+ GitHubBranchKey cacheKey = branchToKey(next);
+ GitHubBranchShort prPersisted = existingEntries.get(cacheKey);
+
+ if (prPersisted == null || !prPersisted.equals(next))
+ entriesToPut.put(cacheKey, next);
+ }
+
+ int size = entriesToPut.size();
+
+ if (size != 0)
+ branchCache.putAll(entriesToPut);
+
return size;
}
- private long prNumberToCacheKey(int prNumber) {
- return (long)prNumber | srvIdMaskHigh << 32;
+ private GitHubBranchKey branchToKey(GitHubBranchShort b) {
+ GitHubBranchKey key = new GitHubBranchKey();
+ key.branchName(b.name()).srvId(srvIdMaskHigh);
+ return key;
}
+
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubIgnitedProvImpl.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubIgnitedProvImpl.java
index bba2356..fe23792 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubIgnitedProvImpl.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubIgnitedProvImpl.java
@@ -16,6 +16,7 @@
*/
package org.apache.ignite.ci.github.ignited;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
@@ -39,12 +40,17 @@ class GitHubIgnitedProvImpl implements IGitHubConnIgnitedProvider {
.build();
/** {@inheritDoc} */
- @Override public IGitHubConnIgnited server(String srvId) {
+ @Override public IGitHubConnIgnited server(String srvCode) {
try {
- return srvs.get(Strings.nullToEmpty(srvId), () -> {
- IGitHubConnection srv = pureConnProv.server(srvId);
+ return srvs.get(Strings.nullToEmpty(srvCode), () -> {
+ IGitHubConnection srv = pureConnProv.server(srvCode);
+
+ Preconditions.checkState(srv.config().code().equals(srvCode));
+
GitHubConnIgnitedImpl ignited = ignitedProvider.get();
- ignited.init(srvId, srv);
+ ignited.init(srv);
+
+ Preconditions.checkState(ignited.config().code().equals(srvCode));
return ignited;
});
}
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 10d14aa..e40800a 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
@@ -25,6 +25,12 @@ import org.apache.ignite.ci.tcbot.conf.IJiraServerConfig;
*
*/
public interface IGitHubConnIgnited {
+ /** Cache name for storing GitHub Prs. */
+ public static final String GIT_HUB_PR = "gitHubPr";
+
+ /** Cache name for storing GitHub Branches. */
+ public static final String GIT_HUB_BRANCHES = "gitHubBranch";
+
/**
* @return Config of GH project.
*/
@@ -38,6 +44,9 @@ public interface IGitHubConnIgnited {
/** */
public PullRequest getPullRequest(int prNum);
+ /** {@inheritDoc} */
+ public List<String> getBranches();
+
/**
* Send POST request with given body.
*
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubCachingProvider.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubCachingProvider.java
index 67adcae..2a082df 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubCachingProvider.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubCachingProvider.java
@@ -16,6 +16,7 @@
*/
package org.apache.ignite.ci.github.pure;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
@@ -26,7 +27,8 @@ import javax.inject.Provider;
import org.apache.ignite.ci.util.ExceptionUtil;
class GitHubCachingProvider implements IGitHubConnectionProvider {
- @Inject Provider<IGitHubConnection> factory;
+ @Inject private Provider<IGitHubConnection> factory;
+
private final Cache<String, IGitHubConnection> srvs
= CacheBuilder.newBuilder()
.maximumSize(100)
@@ -35,11 +37,15 @@ class GitHubCachingProvider implements IGitHubConnectionProvider {
.build();
/** {@inheritDoc} */
- @Override public IGitHubConnection server(String srvId) {
+ @Override public IGitHubConnection server(String srvCode) {
try {
- return srvs.get(Strings.nullToEmpty(srvId), () -> {
+ return srvs.get(Strings.nullToEmpty(srvCode), () -> {
IGitHubConnection conn = factory.get();
- conn.init(srvId);
+
+ conn.init(srvCode);
+
+ Preconditions.checkState(conn.config().code().equals(srvCode));
+
return conn;
});
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubConnectionImpl.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubConnectionImpl.java
index ddfce1c..0d5feec 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubConnectionImpl.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubConnectionImpl.java
@@ -19,7 +19,6 @@ package org.apache.ignite.ci.github.pure;
import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -28,16 +27,16 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import java.util.Properties;
import java.util.StringTokenizer;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
-import org.apache.ignite.ci.HelperConfig;
import org.apache.ignite.ci.di.AutoProfiling;
+import org.apache.ignite.ci.github.GitHubBranchShort;
import org.apache.ignite.ci.github.PullRequest;
import org.apache.ignite.ci.tcbot.conf.IGitHubConfig;
import org.apache.ignite.ci.tcbot.conf.ITcBotConfig;
import org.apache.ignite.ci.util.HttpUtil;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,20 +47,19 @@ class GitHubConnectionImpl implements IGitHubConnection {
/** Logger. */
private static final Logger logger = LoggerFactory.getLogger(GitHubConnectionImpl.class);
- /** URL for git integration. */
- private String gitApiUrl;
-
- /** GitHub authorization token. */
- private String gitAuthTok;
-
+ /** Config. */
@Inject
- ITcBotConfig config;
+ private ITcBotConfig cfg;
+ /** Service (server) code. */
private String srvCode;
- @Nullable public static String parseNextLinkFromLinkRspHeader(String s) {
+ /**
+ * @param linkRspHdrVal Value of Link response HTTP header.
+ */
+ @Nullable public static String parseNextLinkFromLinkRspHeader(String linkRspHdrVal) {
String nextLink = null;
- StringTokenizer tokenizer = new StringTokenizer(s, ",");
+ StringTokenizer tokenizer = new StringTokenizer(linkRspHdrVal, ",");
for (; tokenizer.hasMoreTokens(); ) {
String tok = tokenizer.nextToken();
@@ -90,26 +88,19 @@ class GitHubConnectionImpl implements IGitHubConnection {
/** {@inheritDoc} */
@Override public void init(String srvCode) {
- this.srvCode = srvCode;
- final File workDir = HelperConfig.resolveWorkDir();
-
- String cfgName = HelperConfig.prepareConfigName(srvCode);
-
- final Properties props = HelperConfig.loadAuthProperties(workDir, cfgName);
-
- gitAuthTok = HelperConfig.prepareGithubHttpAuthToken(props);
- gitApiUrl = props.getProperty(HelperConfig.GIT_API_URL);
+ Preconditions.checkState(this.srvCode == null, "Server re-init is not supported");
+ this.srvCode = srvCode;
}
/** {@inheritDoc} */
@AutoProfiling
@Override public PullRequest getPullRequest(Integer id) {
- Preconditions.checkState(!isNullOrEmpty(gitApiUrl), "Git API URL is not configured for this server.");
+ String gitApiUrl = getApiUrlMandatory();
String pr = gitApiUrl + "pulls/" + id;
- try (InputStream is = HttpUtil.sendGetToGit(gitAuthTok, pr, null)) {
+ try (InputStream is = HttpUtil.sendGetToGit(config().gitAuthTok(), pr, null)) {
InputStreamReader reader = new InputStreamReader(is);
return new Gson().fromJson(reader, PullRequest.class);
@@ -123,7 +114,7 @@ class GitHubConnectionImpl implements IGitHubConnection {
@AutoProfiling
@Override public boolean notifyGit(String url, String body) {
try {
- HttpUtil.sendPostAsStringToGit(gitAuthTok, url, body);
+ HttpUtil.sendPostAsStringToGit(config().gitAuthTok(), url, body);
return true;
}
@@ -135,25 +126,37 @@ class GitHubConnectionImpl implements IGitHubConnection {
}
/** {@inheritDoc} */
- @Override public boolean isGitTokenAvailable() {
- return gitAuthTok != null;
+ @AutoProfiling
+ @Override public List<PullRequest> getPullRequestsPage(@Nullable String fullUrl,
+ @Nullable AtomicReference<String> outLinkNext) {
+ String gitApiUrl = getApiUrlMandatory();
+
+ String url = fullUrl != null ? fullUrl : gitApiUrl + "pulls?sort=updated&direction=desc";
+
+ HashMap<String, String> rspHeaders = new HashMap<>();
+ if (outLinkNext != null) {
+ outLinkNext.set(null);
+ rspHeaders.put("Link", null); // requesting header
+ }
+
+ TypeToken<ArrayList<PullRequest>> tok = new TypeToken<ArrayList<PullRequest>>() {
+ };
+
+ return readOnePage(outLinkNext, url, rspHeaders, tok);
}
- /** {@inheritDoc} */
- @Override public String gitApiUrl() {
- if (gitApiUrl == null)
- return null;
+ @NotNull public String getApiUrlMandatory() {
+ String gitApiUrl = config().gitApiUrl();
- return gitApiUrl.endsWith("/") ? gitApiUrl : gitApiUrl + "/";
+ Preconditions.checkState(!isNullOrEmpty(gitApiUrl), "Git API URL is not configured for this server.");
+ return gitApiUrl;
}
/** {@inheritDoc} */
@AutoProfiling
- @Override public List<PullRequest> getPullRequests(@Nullable String fullUrl,
+ @Override public List<GitHubBranchShort> getBranchesPage(@Nullable String fullUrl,
@Nullable AtomicReference<String> outLinkNext) {
- Preconditions.checkState(!isNullOrEmpty(gitApiUrl), "Git API URL is not configured for this server.");
-
- String url = fullUrl != null ? fullUrl : gitApiUrl() + "pulls?sort=updated&direction=desc";
+ String url = fullUrl != null ? fullUrl : getApiUrlMandatory() + "branches";
HashMap<String, String> rspHeaders = new HashMap<>();
if (outLinkNext != null) {
@@ -161,12 +164,17 @@ class GitHubConnectionImpl implements IGitHubConnection {
rspHeaders.put("Link", null); // requesting header
}
- try (InputStream stream = HttpUtil.sendGetToGit(gitAuthTok, url, rspHeaders)) {
- InputStreamReader reader = new InputStreamReader(stream);
- Type listType = new TypeToken<ArrayList<PullRequest>>() {
- }.getType();
+ TypeToken<ArrayList<GitHubBranchShort>> tok = new TypeToken<ArrayList<GitHubBranchShort>>() {
+ };
- List<PullRequest> list = new Gson().fromJson(reader, listType);
+ return this. readOnePage(outLinkNext, url, rspHeaders, tok);
+ }
+
+ public <T> List<T> readOnePage(@Nullable AtomicReference<String> outLinkNext,
+ String url, HashMap<String, String> rspHeaders, TypeToken<ArrayList<T>> typeTok) {
+ try (InputStream stream = HttpUtil.sendGetToGit(config().gitAuthTok(), url, rspHeaders)) {
+ InputStreamReader reader = new InputStreamReader(stream);
+ List<T> list = new Gson().fromJson(reader, typeTok.getType());
String link = rspHeaders.get("Link");
if (link != null) {
@@ -187,6 +195,8 @@ class GitHubConnectionImpl implements IGitHubConnection {
/** {@inheritDoc} */
@Override public IGitHubConfig config() {
- return config.getGitConfig(srvCode);
+ Preconditions.checkNotNull(srvCode);
+
+ return cfg.getGitConfig(srvCode);
}
}
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 f02fc8c..477580b 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
@@ -20,18 +20,19 @@ import com.google.common.base.Strings;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.ci.github.GitHubBranchShort;
import org.apache.ignite.ci.github.PullRequest;
import org.apache.ignite.ci.tcbot.conf.IGitHubConfig;
import org.jetbrains.annotations.Nullable;
/**
- *
+ * GitHub pure connection
*/
public interface IGitHubConnection {
- void init(String srvCode);
+ public void init(String srvCode);
/** */
- PullRequest getPullRequest(Integer id);
+ public PullRequest getPullRequest(Integer id);
/**
* Send POST request with given body.
@@ -40,19 +41,19 @@ public interface IGitHubConnection {
* @param body Request body.
* @return {@code True} - if GitHub was notified. {@code False} - otherwise.
*/
- boolean notifyGit(String url, String body);
+ public boolean notifyGit(String url, String body);
/**
- * @return {@code True} if GitHub authorization token is available.
+ * @param fullUrl Full url - null for first page, not null for next page.
+ * @param outLinkNext Out link for return next page full url.
*/
- boolean isGitTokenAvailable();
+ public List<PullRequest> getPullRequestsPage(@Nullable String fullUrl, @Nullable AtomicReference<String> outLinkNext);
/**
- * @return URL for git integration.
+ * @param fullUrl Full url - null for first page, not null for next page.
+ * @param outLinkNext Out link for return next page full url.
*/
- String gitApiUrl();
-
- List<PullRequest> getPullRequests(@Nullable String fullUrl, @Nullable AtomicReference<String> outLinkNext);
+ public List<GitHubBranchShort> getBranchesPage(@Nullable String fullUrl, @Nullable AtomicReference<String> outLinkNext);
/**
* @return PR id from string "pull/XXXX/head"
@@ -78,5 +79,8 @@ public interface IGitHubConnection {
return Strings.isNullOrEmpty(id) ? null : Integer.parseInt(id);
}
- IGitHubConfig config();
+ /**
+ *
+ */
+ public IGitHubConfig config();
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/ignited/IJiraIgnitedProvider.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/ignited/IJiraIgnitedProvider.java
index 8ca0db5..f1620a2 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/ignited/IJiraIgnitedProvider.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/ignited/IJiraIgnitedProvider.java
@@ -21,7 +21,7 @@ package org.apache.ignite.ci.jira.ignited;
*/
public interface IJiraIgnitedProvider {
/**
- * @param srvId Server id.
+ * @param srvCode Server (service) code, internal identification.
*/
- public IJiraIgnited server(String srvId);
+ public IJiraIgnited server(String srvCode);
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/ignited/JiraIgnitedProvider.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/ignited/JiraIgnitedProvider.java
index 451c75f..b08d095 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/ignited/JiraIgnitedProvider.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/ignited/JiraIgnitedProvider.java
@@ -46,10 +46,10 @@ public class JiraIgnitedProvider implements IJiraIgnitedProvider {
.build();
/** */
- @Override public IJiraIgnited server(String srvId) {
+ @Override public IJiraIgnited server(String srvCode) {
try {
- return srvs.get(Strings.nullToEmpty(srvId), () -> {
- IJiraIntegration pure = pureProv.server(srvId);
+ return srvs.get(Strings.nullToEmpty(srvCode), () -> {
+ IJiraIntegration pure = pureProv.server(srvCode);
JiraIgnited ignited = factory.get();
ignited.init(pure);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/IJiraIntegration.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/IJiraIntegration.java
index 891997a..2b9a0dc 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/IJiraIntegration.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/IJiraIntegration.java
@@ -26,9 +26,9 @@ import org.apache.ignite.ci.tcbot.conf.IJiraServerConfig;
*/
public interface IJiraIntegration {
/**
- * @return Internal identified service ID.
+ * @param srvCode Internal identification service code.
*/
- public void init(String srvId);
+ public void init(String srvCode);
/**
* @param ticket JIRA ticket full name. E.g 'IGNITE-5555'.
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Jira.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Jira.java
index 87a7d57..8bc948c 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Jira.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Jira.java
@@ -19,8 +19,6 @@ package org.apache.ignite.ci.jira.pure;
import com.google.common.base.Preconditions;
import com.google.gson.Gson;
-import java.io.IOException;
-import javax.inject.Inject;
import org.apache.ignite.ci.di.AutoProfiling;
import org.apache.ignite.ci.jira.Tickets;
import org.apache.ignite.ci.tcbot.conf.IJiraServerConfig;
@@ -30,6 +28,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.inject.Inject;
+import java.io.IOException;
+
import static com.google.common.base.Strings.isNullOrEmpty;
/**
@@ -40,15 +41,14 @@ class Jira implements IJiraIntegration {
private static final Logger logger = LoggerFactory.getLogger(Jira.class);
/** Server id. */
- private String srvId;
+ private String srvCode;
/** Config. */
@Inject ITcBotConfig cfg;
/** {@inheritDoc} */
- @Override public void init(String srvId) {
- this.srvId = srvId;
-
+ @Override public void init(String srvCode) {
+ this.srvCode = srvCode;
}
/** {@inheritDoc} */
@@ -85,7 +85,7 @@ class Jira implements IJiraIntegration {
/** {@inheritDoc} */
@Override public IJiraServerConfig config() {
- return cfg.getJiraConfig(srvId);
+ return cfg.getJiraConfig(srvCode);
}
/** {@inheritDoc} */
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/JiraIntegrationProvider.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/JiraIntegrationProvider.java
index e3b4100..0aaac76 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/JiraIntegrationProvider.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/JiraIntegrationProvider.java
@@ -43,12 +43,12 @@ class JiraIntegrationProvider implements IJiraIntegrationProvider {
.build();
/** */
- @Override public IJiraIntegration server(String srvId) {
+ @Override public IJiraIntegration server(String srvCode) {
try {
- return srvs.get(Strings.nullToEmpty(srvId), () -> {
+ return srvs.get(Strings.nullToEmpty(srvCode), () -> {
IJiraIntegration jiraIntegration = factory.get();
- jiraIntegration.init(srvId);
+ jiraIntegration.init(srvCode);
return jiraIntegration;
});
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Status.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Status.java
index 1821c5f..c1ad37a 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Status.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Status.java
@@ -19,8 +19,19 @@ package org.apache.ignite.ci.jira.pure;
/**
* Status for Jira ticket.
+ *
+ * "Closed" "Open" "Backlog" "Resolved" "In Progress" "Pending" "Patch Available" "Reopened" "Patch Reviewed"
*/
public class Status {
+ /** Open status name. */
+ public static final String OPEN_NAME = "Open";
+
+ /** Reopened status name. */
+ public static final String REOPENED_NAME = "Reopened";
+
+ /** Backlog status name. */
+ public static final String BACKLOG_NAME = "Backlog";
+
/** Patch Available status name. */
public static final String PA_NAME = "Patch Available";
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Ticket.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Ticket.java
index 48ca735..2209705 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Ticket.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/pure/Ticket.java
@@ -63,7 +63,12 @@ public class Ticket {
* Checks if ticket relates to some Active (In progress/Patch Available) Contribution.
*/
public boolean isActiveContribution() {
- return Status.PA_NAME.equals(status())
- || Status.IP_NAME.equals(status());
+ String status = status();
+
+ return Status.PA_NAME.equals(status)
+ || Status.IP_NAME.equals(status)
+ || Status.OPEN_NAME.equals(status)
+ || Status.BACKLOG_NAME.equals(status)
+ || Status.REOPENED_NAME.equals(status);
}
}
\ No newline at end of file
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/runners/ClientTmpHelper.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/runners/ClientTmpHelper.java
index 89912f7..e799ed2 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/runners/ClientTmpHelper.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/runners/ClientTmpHelper.java
@@ -20,8 +20,10 @@ package org.apache.ignite.ci.runners;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.ci.db.TcHelperDb;
+import org.apache.ignite.ci.github.ignited.IGitHubConnIgnited;
import org.apache.ignite.ci.issue.Issue;
import org.apache.ignite.ci.issue.IssuesStorage;
+import org.apache.ignite.ci.jira.ignited.JiraTicketDao;
/**
* Utility class for local connection to TC helper DB (server) and any manipulations with data needed.
@@ -30,7 +32,7 @@ public class ClientTmpHelper {
/**
* @param args Args.
*/
- public static void main(String[] args) {
+ public static void mainConsistCheck(String[] args) {
int inconsistent;
try (Ignite ignite = TcHelperDb.startClient()) {
RemoteClientTmpHelper.DUMPS = "dumpsLocal";
@@ -62,4 +64,26 @@ public class ClientTmpHelper {
ignite.close();
}
+
+ public static void mainDeletePRs(String[] args) {
+ Ignite ignite = TcHelperDb.startClient();
+
+ IgniteCache<Object, Object> cache = ignite.cache(IGitHubConnIgnited.GIT_HUB_PR);
+
+ cache.clear();
+ ignite.close();
+ }
+
+ public static void main(String[] args) {
+ mainDeleteTickets(args);
+ }
+
+ public static void mainDeleteTickets(String[] args) {
+ Ignite ignite = TcHelperDb.startClient();
+
+ IgniteCache<Object, Object> cache = ignite.cache(JiraTicketDao.TEAMCITY_JIRA_TICKET_CACHE_NAME);
+
+ cache.clear();
+ ignite.close();
+ }
}
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 61dfd9f..0fd6a0b 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
@@ -76,7 +76,7 @@ public class PrChainsProcessor {
/**
* @param creds Credentials.
- * @param srvId Server id.
+ * @param srvCode Server id.
* @param suiteId Suite id.
* @param branchForTc Branch name in TC identification.
* @param act Action.
@@ -89,7 +89,7 @@ public class PrChainsProcessor {
@AutoProfiling
public TestFailuresSummary getTestFailuresSummary(
ICredentialsProv creds,
- String srvId,
+ String srvCode,
String suiteId,
String branchForTc,
String act,
@@ -101,14 +101,14 @@ public class PrChainsProcessor {
final AtomicInteger runningUpdates = new AtomicInteger();
//using here non persistent TC allows to skip update statistic
- IAnalyticsEnabledTeamcity teamcity = tcSrvProvider.server(srvId, creds);
- ITeamcityIgnited tcIgnited = tcIgnitedProvider.server(srvId, creds);
+ IAnalyticsEnabledTeamcity teamcity = tcSrvProvider.server(srvCode, creds);
+ ITeamcityIgnited tcIgnited = tcIgnitedProvider.server(srvCode, creds);
- IGitHubConnection gitHubConn = gitHubConnProvider.server(srvId);
+ IGitHubConnection gitHubConn = gitHubConnProvider.server(srvCode);
- IGitHubConnIgnited gitHubConnIgnited = gitHubConnIgnitedProvider.server(srvId);
+ IGitHubConnIgnited gitHubConnIgnited = gitHubConnIgnitedProvider.server(srvCode);
- IJiraIgnited jiraIntegration = jiraIgnProv.server(srvId);
+ IJiraIgnited jiraIntegration = jiraIgnProv.server(srvCode);
res.setJavaFlags(teamcity, gitHubConn, jiraIntegration);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/BranchesTracked.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/BranchesTracked.java
index dfe7cd1..e20b6f0 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/BranchesTracked.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/BranchesTracked.java
@@ -109,6 +109,6 @@ public class BranchesTracked {
}
public Optional<GitHubConfig> getGitHubConfig(String code) {
- return gitHubConfigs.stream().filter(s -> code.equals(s.getCode())).findAny();
+ return gitHubConfigs.stream().filter(s -> code.equals(s.code())).findAny();
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/GitHubConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/GitHubConfig.java
index 369de2b..00c0215 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/GitHubConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/GitHubConfig.java
@@ -18,34 +18,38 @@ package org.apache.ignite.ci.tcbot.conf;
import com.google.common.base.Strings;
import java.util.Properties;
+import javax.annotation.Nullable;
import org.apache.ignite.ci.HelperConfig;
+import org.apache.ignite.ci.conf.PasswordEncoder;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
/**
*
*/
public class GitHubConfig implements IGitHubConfig {
public static final String DEFAULT_BRANCH_PREFIX = "ignite-";
- /**
- * Service (server) Name.
- */
+
+ /** Service (server) code. */
private String code;
- /** */
+ /** GitHub Api URL */
private String apiUrl;
- /** */
+ /** Branch prefix for ticket related feature branches. */
private String branchPrefix;
+ /**
+ * Git Auth token encoded to access non-public git repos, use {@link org.apache.ignite.ci.conf.PasswordEncoder#encodeJiraTok(String,
+ * String)} to set up value in a config.
+ */
+ private String authTok;
+
private Properties props;
public GitHubConfig() {
}
- public GitHubConfig(String code, Properties props) {
- this.code = code;
- this.props = props;
- }
-
public String getCode() {
return code;
}
@@ -70,11 +74,64 @@ public class GitHubConfig implements IGitHubConfig {
/** {@inheritDoc} */
@Override public String gitBranchPrefix() {
- if (Strings.isNullOrEmpty(branchPrefix)) {
- return props != null
- ? props.getProperty(HelperConfig.GIT_BRANCH_PREFIX, DEFAULT_BRANCH_PREFIX)
- : DEFAULT_BRANCH_PREFIX;
- }
- return branchPrefix;
+ if (!Strings.isNullOrEmpty(branchPrefix))
+ return branchPrefix;
+
+ return props != null
+ ? props.getProperty(HelperConfig.GIT_BRANCH_PREFIX, DEFAULT_BRANCH_PREFIX)
+ : DEFAULT_BRANCH_PREFIX;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable
+ @Override public String gitAuthTok() {
+ String encAuth = gitAuthTokenEncoded();
+
+ if (isNullOrEmpty(encAuth))
+ return null;
+
+ return PasswordEncoder.decode(encAuth);
+}
+
+ /** {@inheritDoc} */
+ @Override public String gitApiUrl() {
+ String gitApiUrl = getGitApiConfigured();
+
+ if (isNullOrEmpty(gitApiUrl))
+ return gitApiUrl;
+
+ return gitApiUrl.endsWith("/") ? gitApiUrl : gitApiUrl + "/";
+
+ }
+
+ @Override public String code() {
+ return code;
+ }
+
+ /**
+ * @return Github API url configured, probably without ending slash.
+ */
+ @Nullable
+ public String getGitApiConfigured() {
+ if (!Strings.isNullOrEmpty(apiUrl))
+ return apiUrl;
+
+ return props != null
+ ? props.getProperty(HelperConfig.GIT_API_URL)
+ : null;
+ }
+
+ /**
+ *
+ */
+ @Nullable
+ public String gitAuthTokenEncoded() {
+ if (!Strings.isNullOrEmpty(authTok))
+ return authTok;
+
+ return props != null
+ ? props.getProperty(HelperConfig.GITHUB_AUTH_TOKEN)
+ : null;
+
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/IGitHubConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/IGitHubConfig.java
index 6dbcb4c..7ba002a 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/IGitHubConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/IGitHubConfig.java
@@ -16,10 +16,37 @@
*/
package org.apache.ignite.ci.tcbot.conf;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
*
*/
public interface IGitHubConfig {
- /** Git branch prefix for search TC runs in PR-less contributions. */
+ /**
+ * @return server (service) code.
+ */
+ public String code();
+
+ /** Git branch prefix for search ticket-related TC runs in PR-less contributions. */
+ @Nonnull
public String gitBranchPrefix();
+
+ /**
+ * Extracts and returns GitHub authorization token from properties.
+ *
+ * @return Null or decoded auth token for Github.
+ */
+ @Nullable
+ public String gitAuthTok();
+
+ /**
+ * @return GitHub Api URL, if specified always ends with '/'
+ */
+ @Nullable
+ public String gitApiUrl();
+
+ default boolean isGitTokenAvailable() {
+ return gitAuthTok() != null;
+ }
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/IJiraServerConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/IJiraServerConfig.java
index c8d07db..b4d719b 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/IJiraServerConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/IJiraServerConfig.java
@@ -45,6 +45,11 @@ public interface IJiraServerConfig {
*/
@Nullable public String branchNumPrefix();
+ /**
+ * Extracted JIRA basic authorization token from properties.
+ *
+ * @return Null or decoded auth token for JIRA.
+ */
@Nullable public String decodedHttpAuthToken();
/**
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcBotConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcBotConfig.java
index 213835f..2d904bf 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcBotConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcBotConfig.java
@@ -26,6 +26,7 @@ public interface ITcBotConfig {
/** Default server code. */
String DEFAULT_SERVER_CODE = "apache";
+ /** */
public String primaryServerCode();
/**
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcServerConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcServerConfig.java
index 1d07f25..3bc4763 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcServerConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcServerConfig.java
@@ -34,6 +34,9 @@ public interface ITcServerConfig {
*/
@NotNull public String host();
+ /**
+ * @return Directory for downloading build logs (will contain ZIP files).
+ */
@NotNull public String logsDirectory();
/**
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/JiraServerConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/JiraServerConfig.java
index 57a7fa9..9b7e563 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/JiraServerConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/JiraServerConfig.java
@@ -17,11 +17,9 @@
package org.apache.ignite.ci.tcbot.conf;
import com.google.common.base.Strings;
-import java.util.ArrayList;
import java.util.Properties;
import org.apache.ignite.ci.HelperConfig;
import org.apache.ignite.ci.conf.PasswordEncoder;
-import org.apache.ignite.ci.jira.pure.Fields;
import org.apache.ignite.ci.jira.pure.Ticket;
import org.jetbrains.annotations.Nullable;
@@ -54,7 +52,8 @@ public class JiraServerConfig implements IJiraServerConfig {
private Properties props;
/**
- * JIRA Auth token to access, use {@link org.apache.ignite.ci.conf.PasswordEncoder#encodeJiraTok(String, String)}
+ * JIRA Auth token encoded to access JIRA, use {@link org.apache.ignite.ci.conf.PasswordEncoder#encodeJiraTok(String,
+ * String)} to set up value in a config.
*/
private String authTok;
@@ -118,15 +117,13 @@ public class JiraServerConfig implements IJiraServerConfig {
return Strings.emptyToNull(branchNumPrefix);
}
- /**
- * Extracts JIRA basic authorization token from properties.
- *
- * @return Null or decoded auth token for Github.
- */
+
+ /** {@inheritDoc} */
@Nullable
@Override
public String decodedHttpAuthToken() {
String tok;
+
if (Strings.isNullOrEmpty(authTok) && props != null)
tok = props.getProperty(HelperConfig.JIRA_AUTH_TOKEN);
else
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/LocalFilesBasedConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/LocalFilesBasedConfig.java
index 45988a6..0aef665 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/LocalFilesBasedConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/LocalFilesBasedConfig.java
@@ -16,8 +16,10 @@
*/
package org.apache.ignite.ci.tcbot.conf;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.io.File;
+import java.util.Objects;
import java.util.Properties;
import org.apache.ignite.ci.HelperConfig;
import org.apache.ignite.ci.di.cache.GuavaCached;
@@ -48,6 +50,7 @@ public class LocalFilesBasedConfig implements ITcBotConfig {
});
}
+ /** {@inheritDoc} */
@Override public IJiraServerConfig getJiraConfig(String srvCode) {
return getTrackedBranches().getJiraConfig(srvCode)
.orElseGet(() -> new JiraServerConfig()
@@ -55,12 +58,16 @@ public class LocalFilesBasedConfig implements ITcBotConfig {
.properties(loadOldAuthProps(srvCode)));
}
- @Override
- public IGitHubConfig getGitConfig(String srvCode) {
- return getTrackedBranches().getGitHubConfig(srvCode)
+ /** {@inheritDoc} */
+ @Override public IGitHubConfig getGitConfig(String srvCode) {
+ GitHubConfig cfg = getTrackedBranches().getGitHubConfig(srvCode)
.orElseGet(() -> new GitHubConfig()
.code(srvCode)
.properties(loadOldAuthProps(srvCode)));
+
+ Preconditions.checkState(Objects.equals(cfg.code(), srvCode));
+
+ return cfg;
}
/** {@inheritDoc} */
@@ -70,7 +77,8 @@ public class LocalFilesBasedConfig implements ITcBotConfig {
return Strings.isNullOrEmpty(srvCode) ? ITcBotConfig.DEFAULT_SERVER_CODE : srvCode;
}
- private Properties loadOldAuthProps(String srvCode) {
+ @GuavaCached(softValues = true, expireAfterWriteSecs = 3 * 60)
+ protected Properties loadOldAuthProps(String srvCode) {
File workDir = HelperConfig.resolveWorkDir();
String cfgName = HelperConfig.prepareConfigName(srvCode);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/TcServerConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/TcServerConfig.java
index c7d3688..fe078ee 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/TcServerConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/TcServerConfig.java
@@ -45,19 +45,14 @@ public class TcServerConfig implements ITcServerConfig {
/** Downloaded build logs relative path. */
@Nullable private String logsDir;
- /** Default tracked branch. */
+ /** Default tracked branch name in internal identification of TC bot. */
@Nullable private String defaultTrackedBranch;
public TcServerConfig() {
}
- public TcServerConfig(String code, Properties properties) {
- this.code = code;
- this.props = properties;
- }
-
- public String getCode() {
+ @NotNull public String getCode() {
return code;
}
@@ -75,15 +70,14 @@ public class TcServerConfig implements ITcServerConfig {
/** {@inheritDoc} */
@Override public String logsDirectory() {
- String dfltLogs = (Strings.isNullOrEmpty(getCode()) ? "" : code + "_") + "logs";
-
if (!Strings.isNullOrEmpty(logsDir))
return logsDir;
+ String dfltLogs = (Strings.isNullOrEmpty(getCode()) ? "" : code + "_") + "logs";
+
return props != null
? props.getProperty(HelperConfig.LOGS, dfltLogs)
: dfltLogs;
-
}
/**
@@ -112,11 +106,15 @@ public class TcServerConfig implements ITcServerConfig {
/**
* @param props Properties.
*/
- public void properties(Properties props) {
+ public TcServerConfig properties(Properties props) {
this.props = props;
+
+ return this;
}
- public void code(String srvCode) {
+ public TcServerConfig code(String srvCode) {
this.code = srvCode;
+
+ return this;
}
}
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 89c0241..469d709 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;
@@ -363,21 +364,23 @@ public class TcBotTriggerAndSignOffService {
}
/**
- * @param srvIdOrAlias Server id.
+ * @param srvCodeOrAlias Server id.
* @param credsProv Credentials
*/
- public List<ContributionToCheck> getContributionsToCheck(String srvIdOrAlias,
+ public List<ContributionToCheck> getContributionsToCheck(String srvCodeOrAlias,
ICredentialsProv credsProv) {
- IJiraIgnited jiraIntegration = jiraIgnProv.server(srvIdOrAlias);
+ IJiraIgnited jiraIntegration = jiraIgnProv.server(srvCodeOrAlias);
- IGitHubConnIgnited gitHubConnIgnited = gitHubConnIgnitedProvider.server(srvIdOrAlias);
+ IGitHubConnIgnited gitHubConnIgnited = gitHubConnIgnitedProvider.server(srvCodeOrAlias);
List<PullRequest> requests = gitHubConnIgnited.getPullRequests();
if (requests == null)
return null;
Set<Ticket> tickets = jiraIntegration.getTickets();
- List<Ticket> paTickets = tickets.stream().filter(Ticket::isActiveContribution).collect(Collectors.toList());
+ List<String> branches = gitHubConnIgnited.getBranches();
+
+ List<Ticket> activeTickets = tickets.stream().filter(Ticket::isActiveContribution).collect(Collectors.toList());
IJiraServerConfig jiraCfg = jiraIntegration.config();
IGitHubConfig ghCfg = gitHubConnIgnited.config();
@@ -408,9 +411,9 @@ public class TcBotTriggerAndSignOffService {
return check;
}).collect(Collectors.toList());
- ITeamcityIgnited tcIgn = tcIgnitedProv.server(srvIdOrAlias, credsProv);
+ ITeamcityIgnited tcIgn = tcIgnitedProv.server(srvCodeOrAlias, credsProv);
- paTickets.forEach(ticket -> {
+ activeTickets.forEach(ticket -> {
String branch = ticketMatcher.resolveTcBranchForPrLess(ticket,
jiraCfg,
ghCfg);
@@ -418,9 +421,10 @@ public class TcBotTriggerAndSignOffService {
if (Strings.isNullOrEmpty(branch))
return; // nothing to do if branch was not resolved
- String defBtForMaster = findDefaultBuildType(srvIdOrAlias);
+ String defBtForMaster = findDefaultBuildType(srvCodeOrAlias);
- if (tcIgn.getAllBuildsCompacted(defBtForMaster, branch).isEmpty())
+ if (!branches.contains(branch)
+ && tcIgn.getAllBuildsCompacted(defBtForMaster, branch).isEmpty())
return; //Skipping contributions without builds
ContributionToCheck contribution = new ContributionToCheck();
@@ -520,27 +524,29 @@ public class TcBotTriggerAndSignOffService {
}
/**
- * @param srvId Server id.
+ * @param srvCode Server (service) internal code.
* @param prov Prov.
* @param prId Pr id from {@link ContributionToCheck#prNumber}. Negative value imples branch number (with
* appropriate prefix from GH config).
*/
- public Set<ContributionCheckStatus> contributionStatuses(String srvId, ICredentialsProv prov,
+ public Set<ContributionCheckStatus> contributionStatuses(String srvCode, ICredentialsProv prov,
String prId) {
Set<ContributionCheckStatus> statuses = new LinkedHashSet<>();
- ITeamcityIgnited teamcity = tcIgnitedProv.server(srvId, prov);
+ ITeamcityIgnited teamcity = tcIgnitedProv.server(srvCode, prov);
+
+ IGitHubConnIgnited ghConn = gitHubConnIgnitedProvider.server(srvCode);
- IGitHubConnIgnited ghConn = gitHubConnIgnitedProvider.server(srvId);
+ Preconditions.checkState(ghConn.config().code().equals(srvCode));
- List<String> compositeBuildTypeIds = findApplicableBuildTypes(srvId, teamcity);
+ List<String> compositeBuildTypeIds = findApplicableBuildTypes(srvCode, teamcity);
for (String btId : compositeBuildTypeIds) {
List<BuildRefCompacted> compBuilds = findBuildsForPr(btId, prId, ghConn, teamcity);
statuses.add(compBuilds.isEmpty()
? new ContributionCheckStatus(btId, branchForTcDefault(prId, ghConn))
- : contributionStatus(srvId, btId, compBuilds, teamcity, ghConn, prId));
+ : contributionStatus(srvCode, btId, compBuilds, teamcity, ghConn, prId));
}
return statuses;
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/TcLoginImpl.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/TcLoginImpl.java
index bacc4b2..0ae875b 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/TcLoginImpl.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/TcLoginImpl.java
@@ -17,6 +17,7 @@
package org.apache.ignite.ci.teamcity.pure;
import org.apache.ignite.ci.ITeamcity;
+import org.apache.ignite.ci.IgniteTeamcityConnection;
import org.apache.ignite.ci.tcmodel.user.User;
import org.apache.ignite.ci.web.rest.exception.ServiceUnauthorizedException;
import org.slf4j.Logger;
@@ -33,12 +34,12 @@ class TcLoginImpl implements ITcLogin {
private static final Logger logger = LoggerFactory.getLogger(TcLoginImpl.class);
/** Teamcity connection non-caching factory. */
- @Inject private Provider<ITeamcity> tcFactory;
+ @Inject private Provider<IgniteTeamcityConnection> tcFactory;
/** {@inheritDoc} */
@Override public User checkServiceUserAndPassword(String srvId, String username, String pwd) {
try {
- ITeamcity tcConn = tcFactory.get();
+ IgniteTeamcityConnection tcConn = tcFactory.get();
tcConn.init(srvId);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/restcached/InitializingServerFactory.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/restcached/InitializingServerFactory.java
index 413c99f..06a6f4a 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/restcached/InitializingServerFactory.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/restcached/InitializingServerFactory.java
@@ -20,7 +20,7 @@ import com.google.common.base.Strings;
import javax.inject.Inject;
import javax.inject.Provider;
import org.apache.ignite.ci.IAnalyticsEnabledTeamcity;
-import org.apache.ignite.ci.ITeamcity;
+import org.apache.ignite.ci.IgniteTeamcityConnection;
import org.apache.ignite.ci.web.TcUpdatePool;
class InitializingServerFactory implements ITcServerFactory {
@@ -28,14 +28,14 @@ import org.apache.ignite.ci.web.TcUpdatePool;
Provider<IAnalyticsEnabledTeamcity> tcPersistProv;
@Inject
- Provider<ITeamcity> tcConnProv;
+ Provider<IgniteTeamcityConnection> tcConnProv;
@Inject
private TcUpdatePool tcUpdatePool;
/** {@inheritDoc} */
@Override public IAnalyticsEnabledTeamcity createServer(String srvId) {
- ITeamcity tcConn = tcConnProv.get();
+ IgniteTeamcityConnection tcConn = tcConnProv.get();
tcConn.init(Strings.emptyToNull(srvId));
IAnalyticsEnabledTeamcity instance = tcPersistProv.get();
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
index f561e75..e0e6a24 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
@@ -28,7 +28,7 @@ package org.apache.ignite.ci.web.model;
public static final String GITHUB_REF = "https://github.com/apache/ignite-teamcity-bot";
/** TC Bot Version. */
- public static final String VERSION = "20190312";
+ public static final String VERSION = "20190413";
/** Java version, where Web App is running. */
public String javaVer;
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/current/UpdateInfo.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/current/UpdateInfo.java
index 16ff4e5..9d51e28 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/current/UpdateInfo.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/current/UpdateInfo.java
@@ -62,7 +62,7 @@ import org.apache.ignite.ci.jira.pure.IJiraIntegration;
if (teamcity.isTeamCityTokenAvailable())
javaFlags |= TEAMCITY_FLAG;
- if (gitHubConn.isGitTokenAvailable())
+ if (gitHubConn.config().isGitTokenAvailable())
javaFlags |= GITHUB_FLAG;
if (jiraIntegration.config().isJiraTokenAvailable())
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuilds.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuilds.java
index b9a7235..791351b 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuilds.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuilds.java
@@ -133,7 +133,7 @@ public class TriggerBuilds {
IJiraServerConfig jiraCfg = cfg.getJiraConfig(srvCode);
- return new ServerIntegrationLinks(srvCode, gh.gitApiUrl(), jiraCfg.restApiUrl());
+ return new ServerIntegrationLinks(srvCode, gh.config().gitApiUrl(), jiraCfg.restApiUrl());
}).filter(Objects::nonNull).collect(Collectors.toSet());
}
}
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 38a91a3..0284b13 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
@@ -102,7 +102,7 @@ public class MockBasedTcBotModule extends AbstractModule {
/** {@inheritDoc} */
@Override public ITcServerConfig getTeamcityConfig(String srvCode) {
- return new TcServerConfig(srvCode, loadOldProps(srvCode));
+ return new TcServerConfig().code(srvCode).properties(loadOldProps(srvCode));
}
@Override public IJiraServerConfig getJiraConfig(String srvCode) {
@@ -110,7 +110,7 @@ public class MockBasedTcBotModule extends AbstractModule {
}
@Override public IGitHubConfig getGitConfig(String srvCode) {
- return new GitHubConfig(srvCode, loadOldProps(srvCode));
+ return new GitHubConfig().code(srvCode).properties(loadOldProps(srvCode));
}
private Properties loadOldProps(String srvCode) {