Skip to content
Permalink
Browse files
Showing JIRA status in contributions table
  • Loading branch information
dspavlov committed Apr 27, 2019
1 parent 1489ffc commit db1abc42da0f5e13e233be4007d697c1a71a3c8e
Showing 6 changed files with 63 additions and 21 deletions.
@@ -20,6 +20,8 @@
import com.google.common.base.MoreObjects;
import org.apache.ignite.ci.jira.ignited.TicketCompacted;

import javax.annotation.Nullable;

/**
* See example of GSON here https://issues.apache.org/jira/rest/api/2/issue/IGNITE-123
*/
@@ -33,6 +35,13 @@ public class Ticket {
/** Fields. */
public Fields fields;

public Ticket() {}

public Ticket(String ticketKey) {
this.key = ticketKey;
}


/**
* @param projectCode JIRA project code to be removed from ticket key.
* @return Ignite ticket Number ignoring project code (like 123 in IGNITE-123).
@@ -46,7 +55,11 @@ public int keyWithoutProject(String projectCode) {
/**
* @return Ticket status (open, resolved, etc);
*/
@Nullable
public String status() {
if (fields == null || fields.status == null)
return null;

return fields.status.name;
}

@@ -18,10 +18,6 @@
package org.apache.ignite.ci.tcbot.visa;

import com.google.common.base.Strings;
import java.util.Collection;
import java.util.Objects;
import javax.inject.Inject;
import javax.ws.rs.QueryParam;
import org.apache.ignite.ci.di.cache.GuavaCached;
import org.apache.ignite.ci.github.PullRequest;
import org.apache.ignite.ci.github.ignited.IGitHubConnIgnitedProvider;
@@ -35,6 +31,11 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.inject.Inject;
import javax.ws.rs.QueryParam;
import java.util.Collection;
import java.util.Objects;

/**
*
*/
@@ -91,15 +92,20 @@ private String convertJiraToGit(String branchJiraIdentification,
* @param pr Pr.
* @param jiraCfg Jira config.
*/
@Nullable public String resolveTicketIdForPrBasedContrib(Collection<Ticket> tickets, PullRequest pr,
IJiraServerConfig jiraCfg) {
@Nullable public Ticket resolveTicketIdForPrBasedContrib(Collection<Ticket> tickets, PullRequest pr,
IJiraServerConfig jiraCfg) {
String branchNumPrefix = jiraCfg.branchNumPrefix();

if (Strings.isNullOrEmpty(branchNumPrefix)) {
//an easy way, no special branch and ticket mappings specified, use project code.
String jiraPrefix = jiraCfg.projectCodeForVisa() + TicketCompacted.PROJECT_DELIM;

return findFixPrefixedNumber(pr.getTitle(), jiraPrefix);
final String ticketKey = findFixPrefixedNumber(pr.getTitle(), jiraPrefix);

return tickets.stream()
.filter(t -> Objects.equals(t.key, ticketKey))
.findFirst()
.orElseGet(()->new Ticket(ticketKey));
}

String prTitle = pr.getTitle();
@@ -118,21 +124,21 @@ private String convertJiraToGit(String branchJiraIdentification,
*/
@SuppressWarnings("WeakerAccess")
@GuavaCached(maximumSize = 3000, expireAfterWriteSecs = 60, cacheNullRval = true)
protected String findTicketMentions(String srvCode, @Nullable String branchNum) {
@Nullable
protected Ticket findTicketMentions(String srvCode, @Nullable String branchNum) {
return findTicketMentions(jiraIgnProv.server(srvCode).getTickets(), branchNum);
}

/**
* @param tickets Tickets.
* @param branchNum Branch number to be checked.
*/
@Nullable private String findTicketMentions(Collection<Ticket> tickets, @Nullable String branchNum) {
@Nullable private Ticket findTicketMentions(Collection<Ticket> tickets, @Nullable String branchNum) {
if (Strings.isNullOrEmpty(branchNum))
return null;

return tickets.stream()
.map(t -> t.key)
.filter(k -> Objects.equals(k, branchNum))
.filter(t -> Objects.equals(t.key, branchNum))
.findFirst()
.orElseGet(() -> findTicketMentionsInSupplementaryFields(tickets, branchNum));
}
@@ -141,14 +147,13 @@ protected String findTicketMentions(String srvCode, @Nullable String branchNum)
* @param tickets Tickets.
* @param branchNum Branch number to be checked.
*/
@Nullable private String findTicketMentionsInSupplementaryFields(Collection<Ticket> tickets, String branchNum) {
@Nullable private Ticket findTicketMentionsInSupplementaryFields(Collection<Ticket> tickets, String branchNum) {
if (Strings.isNullOrEmpty(branchNum))
return null;

return tickets.stream()
.filter(t -> mentionsBranch(branchNum, t))
.findFirst()
.map(t -> t.key)
.orElse(null);
}

@@ -244,10 +249,10 @@ public String resolveTicketFromBranch(String srvCode, String ticketFullName,
}
else {
// PR less ticket only mentioned in real ticket
String ticket = findTicketMentions(srvCode, prLessTicket);
Ticket ticket = findTicketMentions(srvCode, prLessTicket);

if (!Strings.isNullOrEmpty(ticket))
return ticket; // found real JIRA ticket for comment
if (ticket != null && !Strings.isNullOrEmpty(ticket.key))
return ticket.key; // found real JIRA ticket for comment
}
}

@@ -261,9 +266,13 @@ public String resolveTicketFromBranch(String srvCode, String ticketFullName,
ticketFromPr = jiraPrefixInPr;
}
else {
ticketFromPr = Strings.isNullOrEmpty(jiraPrefixInPr)
? null
: findTicketMentions(srvCode, jiraPrefixInPr);
if (Strings.isNullOrEmpty(jiraPrefixInPr)) {
ticketFromPr = null;
} else {
Ticket ticketMentions = findTicketMentions(srvCode, jiraPrefixInPr);

ticketFromPr = ticketMentions == null ? null : ticketMentions.key;
}
}

if (!Strings.isNullOrEmpty(ticketFromPr))
@@ -50,6 +50,9 @@
/** JIRA issue without server URL, but with project name */
public String jiraIssueId;

/** JIRA issue statusName */
public String jiraStatusName;

/** Pr time update. */
public String prTimeUpdate;

@@ -389,7 +389,10 @@ public List<ContributionToCheck> getContributionsToCheck(String srvCodeOrAlias,
c.prAuthorAvatarUrl = "";
}

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

c.jiraIssueId = ticket == null ? null : ticket.key;
c.jiraStatusName = ticket == null ? null : ticket.status();

if (!Strings.isNullOrEmpty(c.jiraIssueId)
&& jiraCfg.getUrl() != null)
@@ -425,6 +428,7 @@ public List<ContributionToCheck> getContributionsToCheck(String srvCodeOrAlias,
ContributionToCheck contribution = new ContributionToCheck();

contribution.jiraIssueId = ticket.key;
contribution.jiraStatusName = ticket.status();
contribution.jiraIssueUrl = jiraIntegration.generateTicketUrl(ticket.key);
contribution.tcBranchName = branch;

@@ -28,7 +28,7 @@
public static final String GITHUB_REF = "https://github.com/apache/ignite-teamcity-bot";

/** TC Bot Version. */
public static final String VERSION = "20190423";
public static final String VERSION = "20190427";

/** Java version, where Web App is running. */
public String javaVer;
@@ -28,6 +28,7 @@ function drawTable(srvId, element) {
" <th>...</th>\n" +
" <th>.</th>\n" +
" <th>.</th>\n" +
" <th>.</th>\n" +
" </tr>\n" +
" </thead>\n" +
" </table>\n");
@@ -151,6 +152,18 @@ function showContributionsTable(result, srvId, suiteId) {
return data;
}
},
{
"data": "jiraStatusName",
title: "JIRA Status",
"render": function (data, type, row, meta) {
if (type === 'display') {
if (data != null && row.jiraIssueUrl != null)
data = "<a href='" + row.jiraIssueUrl + "'>" + data + "</a>";
}

return data;
}
},
{
"data": "tcBranchName",
title: "Resolved Branch Name",

0 comments on commit db1abc4

Please sign in to comment.