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/02/02 14:52:16 UTC
[ignite-teamcity-bot] branch ignite-11105-alias updated:
IGNITE-11105: TC servers aliases support: PR-less tickets matching fixed
This is an automated email from the ASF dual-hosted git repository.
dpavlov pushed a commit to branch ignite-11105-alias
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git
The following commit(s) were added to refs/heads/ignite-11105-alias by this push:
new d361998 IGNITE-11105: TC servers aliases support: PR-less tickets matching fixed
d361998 is described below
commit d3619985502d7a29aac441a1a2644da4303f88d7
Author: Dmitriy Pavlov <dp...@apache.org>
AuthorDate: Sat Feb 2 17:52:11 2019 +0300
IGNITE-11105: TC servers aliases support: PR-less tickets matching fixed
---
.../ci/github/ignited/GitHubConnIgnitedImpl.java | 9 ++-
.../ci/github/ignited/IGitHubConnIgnited.java | 3 +
.../ci/github/pure/GitHubConnectionImpl.java | 9 ++-
.../ignite/ci/github/pure/IGitHubConnection.java | 3 +
.../ignite/ci/tcbot/visa/BranchTicketMatcher.java | 79 ++++++++++++----------
.../tcbot/visa/TcBotTriggerAndSignOffService.java | 7 +-
6 files changed, 69 insertions(+), 41 deletions(-)
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 a6b54d1..65d704f 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
@@ -37,6 +37,7 @@ import org.apache.ignite.ci.di.MonitoredTask;
import org.apache.ignite.ci.di.scheduler.IScheduler;
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;
/**
@@ -85,8 +86,14 @@ class GitHubConnIgnitedImpl implements IGitHubConnIgnited {
conn.notifyGit(url, body);
}
+ /** {@inheritDoc} */
@Override public String gitBranchPrefix() {
- return conn.gitBranchPrefix();
+ return config().gitBranchPrefix();
+ }
+ /** {@inheritDoc} */
+ @Override
+ public IGitHubConfig config() {
+ return conn.config();
}
/** {@inheritDoc} */
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 ca7b91b..ae405f8 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
@@ -18,12 +18,15 @@ package org.apache.ignite.ci.github.ignited;
import java.util.List;
import org.apache.ignite.ci.github.PullRequest;
+import org.apache.ignite.ci.tcbot.conf.IGitHubConfig;
import org.apache.ignite.ci.tcbot.conf.IJiraServerConfig;
/**
*
*/
public interface IGitHubConnIgnited {
+ IGitHubConfig config();
+
/**
* @return list of open pull requests
*/
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 3de8dcb..ff0bc52 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
@@ -34,9 +34,9 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.ignite.ci.HelperConfig;
import org.apache.ignite.ci.di.AutoProfiling;
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;
@@ -186,6 +186,11 @@ class GitHubConnectionImpl implements IGitHubConnection {
/** {@inheritDoc} */
@Override public String gitBranchPrefix() {
- return config.getGitConfig(srvCode).gitBranchPrefix();
+ return config().gitBranchPrefix();
+ }
+
+ /** {@inheritDoc} */
+ @Override public IGitHubConfig config() {
+ return config.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 2eb2d09..5a1e594 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
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicReference;
import com.google.common.base.Strings;
import org.apache.ignite.ci.github.PullRequest;
+import org.apache.ignite.ci.tcbot.conf.IGitHubConfig;
import org.jetbrains.annotations.Nullable;
/**
@@ -82,4 +83,6 @@ public interface IGitHubConnection {
*
*/
public String gitBranchPrefix();
+
+ IGitHubConfig config();
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/BranchTicketMatcher.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/BranchTicketMatcher.java
index 7d0cdb3..6cd746e 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/BranchTicketMatcher.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/BranchTicketMatcher.java
@@ -20,10 +20,8 @@ package org.apache.ignite.ci.tcbot.visa;
import com.google.common.base.Strings;
import org.apache.ignite.ci.di.cache.GuavaCached;
import org.apache.ignite.ci.github.PullRequest;
-import org.apache.ignite.ci.github.ignited.IGitHubConnIgnited;
import org.apache.ignite.ci.github.ignited.IGitHubConnIgnitedProvider;
import org.apache.ignite.ci.github.pure.IGitHubConnection;
-import org.apache.ignite.ci.jira.ignited.IJiraIgnited;
import org.apache.ignite.ci.jira.ignited.IJiraIgnitedProvider;
import org.apache.ignite.ci.jira.ignited.TicketCompacted;
import org.apache.ignite.ci.jira.pure.Ticket;
@@ -37,7 +35,6 @@ import javax.inject.Inject;
import javax.ws.rs.QueryParam;
import java.util.Collection;
import java.util.Objects;
-import java.util.Set;
public class BranchTicketMatcher {
/** Config. */
@@ -50,40 +47,40 @@ public class BranchTicketMatcher {
@Inject private IJiraIgnitedProvider jiraIgnProv;
@Nullable
- public String resolveTcBranch(IGitHubConnIgnited gitHubConnIgnited,
- Ticket ticket, IJiraServerConfig jiraCfg) {
+ public String resolveTcBranchForPrLess(Ticket ticket,
+ IJiraServerConfig jiraCfg,
+ IGitHubConfig gitHubConfig) {
String branchNumPrefix = jiraCfg.branchNumPrefix();
if (Strings.isNullOrEmpty(branchNumPrefix)) {
//an easy way, no special branch and ticket mappings specified, use project code.
int ticketId = ticket.keyWithoutProject(jiraCfg.projectCodeForVisa());
- return gitHubConnIgnited.gitBranchPrefix() + ticketId;
+ return gitHubConfig.gitBranchPrefix() + ticketId;
}
- String branchJiraIdentification = findFixPrefixedNumber(ticket.fields.summary, branchNumPrefix);
+ String branchJiraIdentification = findFixPrefixedNoInValues(branchNumPrefix,
+ ticket.key,
+ ticket.fields.summary,
+ ticket.fields.customfield_11050);
- if (!Strings.isNullOrEmpty(branchJiraIdentification))
- return convertJiraToGit(branchJiraIdentification, gitHubConnIgnited, branchNumPrefix);
-
- String branchJiraIdentification2 = findFixPrefixedNumber(ticket.fields.customfield_11050, branchNumPrefix);
-
- return convertJiraToGit(branchJiraIdentification2, gitHubConnIgnited, branchNumPrefix);
+ return convertJiraToGit(branchJiraIdentification, branchNumPrefix, gitHubConfig);
}
/**
* Converts JIRA notation branch name to actual git branch name. Usually it is just lower-casing, but any mapping may be configured.
* @param branchJiraIdentification Branch jira identification.
- * @param gitHubConnIgnited Git hub connection ignited.
* @param branchNumPrefix Branch number prefix.
+ * @param gitHubConfig GH connection config.
*/
- public String convertJiraToGit(String branchJiraIdentification, IGitHubConnIgnited gitHubConnIgnited,
- String branchNumPrefix) {
+ private String convertJiraToGit(String branchJiraIdentification,
+ String branchNumPrefix,
+ IGitHubConfig gitHubConfig) {
if (Strings.isNullOrEmpty(branchJiraIdentification))
return null;
- return gitHubConnIgnited.gitBranchPrefix() + branchJiraIdentification.substring(branchNumPrefix.length());
+ return gitHubConfig.gitBranchPrefix() + branchJiraIdentification.substring(branchNumPrefix.length());
}
/**
@@ -91,7 +88,7 @@ public class BranchTicketMatcher {
* @param pr Pr.
* @param jiraCfg Jira config.
*/
- @Nullable public String determineJiraId(Collection<Ticket> tickets, PullRequest pr, IJiraServerConfig jiraCfg) {
+ @Nullable public String resolveTicketIdForPrBasedContrib(Collection<Ticket> tickets, PullRequest pr, IJiraServerConfig jiraCfg) {
String branchNumPrefix = jiraCfg.branchNumPrefix();
if (Strings.isNullOrEmpty(branchNumPrefix)) {
@@ -143,7 +140,7 @@ public class BranchTicketMatcher {
* @param branchName Full branch name in jira.
* @param ticket Ticket.
*/
- public boolean mentionsBranch(String branchName, Ticket ticket) {
+ private boolean mentionsBranch(String branchName, Ticket ticket) {
String summary = ticket.fields.summary;
if (summary != null && summary.contains(branchName))
return true;
@@ -156,16 +153,27 @@ public class BranchTicketMatcher {
}
+ @Nullable
+ private String findFixPrefixedNoInValues(@NotNull String prefix, String... values) {
+ for (String value : values) {
+ String fixPrefixedNumber = findFixPrefixedNumber(value, prefix);
+
+ if (fixPrefixedNumber != null)
+ return fixPrefixedNumber;
+ }
+ return null;
+ }
/**
- * @param prTitle Pull Request title prefix or other text to find constant-prefix text.
+ * @param value Pull Request/Ticket title prefix or other text to find constant-prefix text.
* @param prefix Ticket prefix.
* @return Branch number or null.
*/
- @Nullable public static String findFixPrefixedNumber(@Nullable String prTitle, @NotNull String prefix) {
- if(Strings.isNullOrEmpty(prTitle))
+ @Nullable
+ private String findFixPrefixedNumber(@Nullable String value, @NotNull String prefix) {
+ if(Strings.isNullOrEmpty(value))
return null;
- int idxOfBranchNum = prTitle.toUpperCase().indexOf(prefix.toUpperCase());
+ int idxOfBranchNum = value.toUpperCase().indexOf(prefix.toUpperCase());
if (idxOfBranchNum < 0)
return null;
@@ -173,21 +181,21 @@ public class BranchTicketMatcher {
int beginIdx = prefix.length() + idxOfBranchNum;
int endIdx = beginIdx;
- while (endIdx < prTitle.length() && Character.isDigit(prTitle.charAt(endIdx)))
+ while (endIdx < value.length() && Character.isDigit(value.charAt(endIdx)))
endIdx++;
if (endIdx == beginIdx)
return null;
- return prefix + prTitle.substring(beginIdx, endIdx);
+ return prefix + value.substring(beginIdx, endIdx);
}
public static class TicketNotFoundException extends Exception {
- public TicketNotFoundException(String msg) {
+ TicketNotFoundException(String msg) {
super(msg);
}
- public TicketNotFoundException(String msg, Exception e) {
+ TicketNotFoundException(String msg, Exception e) {
super(msg, e);
}
}
@@ -206,8 +214,8 @@ public class BranchTicketMatcher {
try {
String branchNumPrefix = jiraCfg.branchNumPrefix();
- ticketPrefix = Strings.isNullOrEmpty(branchNumPrefix) ?
- jiraCfg.projectCodeForVisa() + TicketCompacted.PROJECT_DELIM
+ ticketPrefix = Strings.isNullOrEmpty(branchNumPrefix)
+ ? jiraCfg.projectCodeForVisa() + TicketCompacted.PROJECT_DELIM
: branchNumPrefix;
String prLessTicket = prLessTicket(branchForTc, ticketPrefix, gitConfig);
@@ -227,16 +235,16 @@ public class BranchTicketMatcher {
pr = findPrForBranch(srvCode, branchForTc);
if (pr != null) {
+ String jiraPrefixInPr = findFixPrefixedNumber(pr.getTitle(), ticketPrefix);
+
String ticketFromPr;
if (Strings.isNullOrEmpty(branchNumPrefix)) {
//Default, simple case, branch name matching gives us a ticket
- ticketFromPr = findFixPrefixedNumber(pr.getTitle(), ticketPrefix);
+ ticketFromPr = jiraPrefixInPr;
} else {
- String jiraBranchNum = findFixPrefixedNumber(pr.getTitle(), branchNumPrefix);
-
- ticketFromPr = Strings.isNullOrEmpty(jiraBranchNum)
+ ticketFromPr = Strings.isNullOrEmpty(jiraPrefixInPr)
? null
- : findTicketMentions(srvCode, jiraBranchNum);
+ : findTicketMentions(srvCode, jiraPrefixInPr);
}
if (!Strings.isNullOrEmpty(ticketFromPr))
@@ -254,7 +262,8 @@ public class BranchTicketMatcher {
" or use branch name according ticket name.");
}
- @Nullable public PullRequest findPrForBranch(
+ @Nullable
+ private PullRequest findPrForBranch(
@Nullable @QueryParam("serverId") String srvId,
@Nullable @QueryParam("branchName") String branchForTc) {
Integer prId = IGitHubConnection.convertBranchToPrId(branchForTc);
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 001fe6e..79fa55e 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
@@ -41,7 +41,6 @@ import org.apache.ignite.ci.github.GitHubUser;
import org.apache.ignite.ci.github.PullRequest;
import org.apache.ignite.ci.github.ignited.IGitHubConnIgnited;
import org.apache.ignite.ci.github.ignited.IGitHubConnIgnitedProvider;
-import org.apache.ignite.ci.github.pure.IGitHubConnection;
import org.apache.ignite.ci.jira.pure.Ticket;
import org.apache.ignite.ci.jira.ignited.IJiraIgnited;
import org.apache.ignite.ci.jira.ignited.IJiraIgnitedProvider;
@@ -378,7 +377,7 @@ public class TcBotTriggerAndSignOffService {
IJiraServerConfig jiraCfg = jiraIntegration.config();
- check.jiraIssueId = ticketMatcher.determineJiraId(tickets, pr, jiraCfg);
+ check.jiraIssueId = ticketMatcher.resolveTicketIdForPrBasedContrib(tickets, pr, jiraCfg);
if (!Strings.isNullOrEmpty(check.jiraIssueId))
check.jiraIssueUrl = jiraIntegration.generateTicketUrl(check.jiraIssueId);
@@ -389,7 +388,9 @@ public class TcBotTriggerAndSignOffService {
ITeamcityIgnited tcIgn = tcIgnitedProv.server(srvId, credsProv);
paTickets.forEach(ticket -> {
- String branch = ticketMatcher.resolveTcBranch(gitHubConnIgnited, ticket, jiraIntegration.config());
+ String branch = ticketMatcher.resolveTcBranchForPrLess(ticket,
+ jiraIntegration.config(),
+ gitHubConnIgnited.config());
if (branch == null)
return; // nothing to do if branch was not resolved