Skip to content
Permalink
Browse files
IGNITE-11740: Add search for full branch name in contributions table,… (
  • Loading branch information
dspavlov committed Apr 13, 2019
1 parent 396cd39 commit 0abee7f2fea331c144069cb5481805a234603816
Showing 9 changed files with 156 additions and 113 deletions.
@@ -1,6 +1,7 @@
{
// Default server (service) code, internal identification
"primaryServerCode": "apache",
/**/
"tcServers": [
{
//code of current server
@@ -10,6 +11,7 @@
"reference": "apache"
}
],
/* Set of JIRA servers/projects configured */
"jiraServers": [
{
/* Server code will be referenced in all tracked branches, URLs, etc */
@@ -24,6 +26,22 @@
"authTok": "" //todo specify
}
],
/* Set of GitHub services configured */
"gitHubConfigs": [
{
"code": "apache",
/* More for preffering branches gives branch for PR to be default branch for triggering builds on TC. */
"preferBranches": false,

/*
Git Auth token encoded to access non-public GitHub repos, use {@link org.apache.ignite.ci.conf.PasswordEncoder#encodeJiraTok
to set up value in a config. For public GitHub repos token gives more velocity
*/
"authTok": "",
//todo specify token
"apiUrl": "https://api.github.com/repos/apache/ignite/"
}
],
"branches": [
{
"id": "master",
@@ -127,7 +127,11 @@ public void init(IGitHubConnection conn) {
/** {@inheritDoc} */
@AutoProfiling
@Override public List<String> getBranches() {
scheduler.sheduleNamed(taskName("actualizeBranches"), this::actualizeBranches, 2, TimeUnit.HOURS);
final int rescanIntervalMins = config().isPreferBranches() ? 5 : 120;

scheduler.sheduleNamed(taskName("actualizeBranches"),
this::actualizeBranches,
rescanIntervalMins, TimeUnit.MINUTES);

return StreamSupport.stream(branchCache.spliterator(), false)
.filter(entry -> entry.getKey().srvId() == srvIdMaskHigh)
@@ -21,6 +21,7 @@
import javax.annotation.Nullable;
import org.apache.ignite.ci.HelperConfig;
import org.apache.ignite.ci.conf.PasswordEncoder;
import org.jetbrains.annotations.NotNull;

import static com.google.common.base.Strings.isNullOrEmpty;

@@ -47,6 +48,13 @@ public class GitHubConfig implements IGitHubConfig {

private Properties props;

/**
* Prefer branches contributions. If null or false then PRs have priority.
* If set to true that means branch scanning preformed more often, and default triggering option is branch.
*/
@Nullable
private Boolean preferBranches;

public GitHubConfig() {
}

@@ -73,6 +81,7 @@ public GitHubConfig code(String code) {
}

/** {@inheritDoc} */
@NotNull
@Override public String gitBranchPrefix() {
if (!Strings.isNullOrEmpty(branchPrefix))
return branchPrefix;
@@ -104,6 +113,11 @@ public GitHubConfig code(String code) {

}

@Override
public boolean isPreferBranches() {
return Boolean.TRUE.equals(preferBranches);
}

@Override public String code() {
return code;
}
@@ -132,6 +146,5 @@ public String gitAuthTokenEncoded() {
return props != null
? props.getProperty(HelperConfig.GITHUB_AUTH_TOKEN)
: null;

}
}
@@ -49,4 +49,6 @@ public interface IGitHubConfig {
default boolean isGitTokenAvailable() {
return gitAuthTok() != null;
}

boolean isPreferBranches();
}
@@ -41,7 +41,10 @@
/** Pr head commit hash (first 7 hexes). */
public String prHeadCommit;

/** Branch Name for team city */
/**
* Branch Name for Team City. Always a branch for PR_less contribution,
* for PRs filled only if there are builds found for TC.
*/
public String tcBranchName;

/** JIRA issue without server URL, but with project name */
@@ -21,21 +21,6 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.inject.Provider;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.ws.rs.QueryParam;
import org.apache.ignite.ci.ITeamcity;
import org.apache.ignite.ci.github.GitHubBranch;
import org.apache.ignite.ci.github.GitHubUser;
@@ -55,20 +40,12 @@
import org.apache.ignite.ci.tcbot.conf.ITcServerConfig;
import org.apache.ignite.ci.tcmodel.mute.MuteInfo;
import org.apache.ignite.ci.tcmodel.result.Build;
import org.apache.ignite.ci.teamcity.ignited.BuildRefCompacted;
import org.apache.ignite.ci.teamcity.ignited.IStringCompactor;
import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnited;
import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnitedProvider;
import org.apache.ignite.ci.teamcity.ignited.SyncMode;
import org.apache.ignite.ci.teamcity.ignited.*;
import org.apache.ignite.ci.teamcity.ignited.buildtype.BuildTypeCompacted;
import org.apache.ignite.ci.teamcity.ignited.buildtype.BuildTypeRefCompacted;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted;
import org.apache.ignite.ci.user.ICredentialsProv;
import org.apache.ignite.ci.web.model.ContributionKey;
import org.apache.ignite.ci.web.model.JiraCommentResponse;
import org.apache.ignite.ci.web.model.SimpleResult;
import org.apache.ignite.ci.web.model.Visa;
import org.apache.ignite.ci.web.model.VisaRequest;
import org.apache.ignite.ci.web.model.*;
import org.apache.ignite.ci.web.model.current.SuiteCurrentStatus;
import org.apache.ignite.ci.web.model.current.TestFailure;
import org.apache.ignite.ci.web.model.hist.FailureSummary;
@@ -79,9 +56,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.ignite.ci.observer.BuildsInfo.CANCELLED_STATUS;
import static org.apache.ignite.ci.observer.BuildsInfo.FINISHED_STATUS;
import static org.apache.ignite.ci.observer.BuildsInfo.RUNNING_STATUS;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.ws.rs.QueryParam;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.apache.ignite.ci.observer.BuildsInfo.*;
import static org.apache.ignite.ci.util.XmlUtil.xmlEscapeText;

/**
@@ -372,46 +356,58 @@ public List<ContributionToCheck> getContributionsToCheck(String srvCodeOrAlias,
IJiraIgnited jiraIntegration = jiraIgnProv.server(srvCodeOrAlias);

IGitHubConnIgnited gitHubConnIgnited = gitHubConnIgnitedProvider.server(srvCodeOrAlias);
List<PullRequest> requests = gitHubConnIgnited.getPullRequests();
if (requests == null)
return null;

Set<Ticket> tickets = jiraIntegration.getTickets();
ITeamcityIgnited tcIgn = tcIgnitedProv.server(srvCodeOrAlias, credsProv);

List<String> branches = gitHubConnIgnited.getBranches();
List<PullRequest> prs = gitHubConnIgnited.getPullRequests();

List<Ticket> activeTickets = tickets.stream().filter(Ticket::isActiveContribution).collect(Collectors.toList());
Set<Ticket> tickets = jiraIntegration.getTickets();

IJiraServerConfig jiraCfg = jiraIntegration.config();
IGitHubConfig ghCfg = gitHubConnIgnited.config();

List<ContributionToCheck> contribsList = requests.stream().map(pr -> {
ContributionToCheck check = new ContributionToCheck();
check.prNumber = pr.getNumber();
check.prTitle = pr.getTitle();
check.prHtmlUrl = pr.htmlUrl();
check.prHeadCommit = pr.lastCommitShaShort();
check.prTimeUpdate = pr.getTimeUpdate();

GitHubUser user = pr.gitHubUser();
if (user != null) {
check.prAuthor = user.login();
check.prAuthorAvatarUrl = user.avatarUrl();
}
else {
check.prAuthor = "";
check.prAuthorAvatarUrl = "";
}
String defBtForTcServ = findDefaultBuildType(srvCodeOrAlias);

check.jiraIssueId = ticketMatcher.resolveTicketIdForPrBasedContrib(tickets, pr, jiraCfg);
List<ContributionToCheck> contribsList = new ArrayList<>();

if (!Strings.isNullOrEmpty(check.jiraIssueId))
check.jiraIssueUrl = jiraIntegration.generateTicketUrl(check.jiraIssueId);
if (prs != null) {
prs.forEach(pr -> {
ContributionToCheck c = new ContributionToCheck();

return check;
}).collect(Collectors.toList());
c.prNumber = pr.getNumber();
c.prTitle = pr.getTitle();
c.prHtmlUrl = pr.htmlUrl();
c.prHeadCommit = pr.lastCommitShaShort();
c.prTimeUpdate = pr.getTimeUpdate();

ITeamcityIgnited tcIgn = tcIgnitedProv.server(srvCodeOrAlias, credsProv);
GitHubUser user = pr.gitHubUser();
if (user != null) {
c.prAuthor = user.login();
c.prAuthorAvatarUrl = user.avatarUrl();
} else {
c.prAuthor = "";
c.prAuthorAvatarUrl = "";
}

c.jiraIssueId = ticketMatcher.resolveTicketIdForPrBasedContrib(tickets, pr, jiraCfg);

if (!Strings.isNullOrEmpty(c.jiraIssueId)
&& jiraCfg.getUrl() != null)
c.jiraIssueUrl = jiraIntegration.generateTicketUrl(c.jiraIssueId);

findBuildsForPr(defBtForTcServ, Integer.toString(pr.getNumber()), gitHubConnIgnited, tcIgn)
.stream()
.map(buildRefCompacted -> buildRefCompacted.branchName(compactor))
.findAny()
.ifPresent(bName -> c.tcBranchName = bName);

contribsList.add(c);
});
}

List<String> branches = gitHubConnIgnited.getBranches();

List<Ticket> activeTickets = tickets.stream().filter(Ticket::isActiveContribution).collect(Collectors.toList());

activeTickets.forEach(ticket -> {
String branch = ticketMatcher.resolveTcBranchForPrLess(ticket,
@@ -421,10 +417,9 @@ public List<ContributionToCheck> getContributionsToCheck(String srvCodeOrAlias,
if (Strings.isNullOrEmpty(branch))
return; // nothing to do if branch was not resolved

String defBtForMaster = findDefaultBuildType(srvCodeOrAlias);

if (!branches.contains(branch)
&& tcIgn.getAllBuildsCompacted(defBtForMaster, branch).isEmpty())
&& tcIgn.getAllBuildsCompacted(defBtForTcServ, branch).isEmpty())
return; //Skipping contributions without builds

ContributionToCheck contribution = new ContributionToCheck();
@@ -470,7 +465,8 @@ private List<BuildRefCompacted> findBuildsForPr(String suiteId,
IGitHubConnIgnited ghConn,
ITeamcityIgnited srv) {

List<BuildRefCompacted> buildHist = srv.getAllBuildsCompacted(suiteId, branchForTcDefault(prId, ghConn));
List<BuildRefCompacted> buildHist = srv.getAllBuildsCompacted(suiteId,
branchForTcDefault(prId, ghConn));

if (!buildHist.isEmpty())
return buildHist;
@@ -484,33 +480,49 @@ private List<BuildRefCompacted> findBuildsForPr(String suiteId,
if (!buildHist.isEmpty())
return buildHist;

PullRequest pr = ghConn.getPullRequest(prNum);
String bracnhToCheck =
ghConn.config().isPreferBranches()
? branchForTcA(prId) // for prefer branches mode it was already checked in default
: getPrBranch(ghConn, prNum);

if (pr != null) {
GitHubBranch head = pr.head();
if (bracnhToCheck == null)
return Collections.emptyList();

if (head != null) {
String ref = head.ref();
buildHist = srv.getAllBuildsCompacted(suiteId, bracnhToCheck);

buildHist = srv.getAllBuildsCompacted(suiteId, ref);
return buildHist;
}

if (!buildHist.isEmpty())
return buildHist;
}
}
@Nullable
private String getPrBranch(IGitHubConnIgnited ghConn, Integer prNum) {
PullRequest pr = ghConn.getPullRequest(prNum);

if (pr == null)
return null;

GitHubBranch head = pr.head();

return Collections.emptyList();
if (head == null)
return null;

return head.ref();
}

/**
* @param prId Pr id from {@link ContributionToCheck#prNumber}. Negative value imples branch number to be used for
* PR-less contributions.
* @param srv Github integration.
* @param ghConn Github integration.
*/
private String branchForTcDefault(String prId, IGitHubConnIgnited srv) {
private String branchForTcDefault(String prId, IGitHubConnIgnited ghConn) {
Integer prNum = Integer.valueOf(prId);
if (prNum < 0)
return srv.gitBranchPrefix() + (-prNum); // Checking "ignite-10930" builds only
return ghConn.gitBranchPrefix() + (-prNum); // Checking "ignite-10930" builds only

if (ghConn.config().isPreferBranches()) {
String ref = getPrBranch(ghConn, prNum);
if (ref != null)
return ref;
}

return branchForTcA(prId);
}
@@ -542,11 +554,11 @@ public Set<ContributionCheckStatus> contributionStatuses(String srvCode, ICreden
List<String> compositeBuildTypeIds = findApplicableBuildTypes(srvCode, teamcity);

for (String btId : compositeBuildTypeIds) {
List<BuildRefCompacted> compBuilds = findBuildsForPr(btId, prId, ghConn, teamcity);
List<BuildRefCompacted> buildsForBt = findBuildsForPr(btId, prId, ghConn, teamcity);

statuses.add(compBuilds.isEmpty()
statuses.add(buildsForBt.isEmpty()
? new ContributionCheckStatus(btId, branchForTcDefault(prId, ghConn))
: contributionStatus(srvCode, btId, compBuilds, teamcity, ghConn, prId));
: contributionStatus(srvCode, btId, buildsForBt, teamcity, ghConn, prId));
}

return statuses;
@@ -590,7 +602,8 @@ public List<String> findApplicableBuildTypes(String srvIdOrAlias, ITeamcityIgnit
* @param srvIdOrAlias Server id. May be weak reference to TC
* @return Some build type included into tracked branches with default branch.
*/
@NotNull public String findDefaultBuildType(String srvIdOrAlias) {
@NotNull
private String findDefaultBuildType(String srvIdOrAlias) {
StringBuilder buildTypeId = new StringBuilder();

ITcServerConfig tcCfg = cfg.getTeamcityConfig(srvIdOrAlias);

0 comments on commit 0abee7f

Please sign in to comment.