Skip to content

Bi 168 add a way to get to jira tickets from GitHub #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

tungledao
Copy link
Collaborator

No description provided.

LOG.debug("Pull request title " + branch_name + " does not contain any ticket of Cozmo project");
}
while (cozmo_matcher.find()){
String coz_id = cozmo_matcher.group().replaceAll("coz", jira_link + "coz-");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is coz- here? I think it is cozmo-


Pattern cozmo_pattern = Pattern.compile(cozmo);
Matcher cozmo_matcher = cozmo_pattern.matcher(name);
if (!od_matcher.matches()){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a space between ) and {

if (!od_matcher.matches()){
LOG.debug("Pull request title " + branch_name + " does not contain any ticket of Cozmo project");
}
while (cozmo_matcher.find()){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a space between ) and {

final String vcsBranch = version.getVcsBranch();
String title = "";
try {
title = api.getPullRequestTitle(repositoryOwner, repositoryName, vcsBranch);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should follow 2 space instead of 4

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class GetJiraTickets {
private static final Logger LOG = Logger.getInstance(GetJiraTickets.class.getName());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should follow 2 space instead of 4


Pattern bi_pattern = Pattern.compile(bi);
Matcher bi_matcher = bi_pattern.matcher(name);
if (!od_matcher.matches()){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a space between ) and {

if (!od_matcher.matches()){
LOG.debug("Pull request title " + branch_name + " does not contain any ticket of BI project");
}
while (bi_matcher.find()){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a space between ) and {

String bi_id = bi_matcher.group().replaceAll("bi", jira_link + "bi-");
list_jira_link.add(bi_id);
}
if (!(list_jira_link.size()>0)){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a space between ) and {

*/
@Nullable
String getPullRequestTitle(@NotNull String repoOwner,
@NotNull String repoName,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please line up the @NotNull vertically so it's easier to read

- Merge master into branch
- Pass JIRA_LINK_CONF_NAME system parameter into script. Please add a new system parameter JIRA_LINK_CONF_NAME with value "https://ankiinc.atlassian.net/browse/" if using script GetJiraTickets.java
- The script support for all of patterns of ticket id (od 123, od-123, od123)
- The script works on the branch name
@manhtran1609
Copy link
Collaborator

@lip please help me to review


public class GetJiraTickets {
private static final Logger LOG = Logger.getInstance(GetJiraTickets.class.getName());
private static final String od = "od\\d*";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use upper case for constant

comment.append(ticketLink);
comment.append(")\n");
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this as a function.

while (odMatcher.find()) {
String odId = odMatcher.group().replaceAll("od", jiraLink + "od-");
listJiraLink.add(odId);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make it as a function, then reuse for cozmo, bi

String biId = biMatcher.group().replaceAll("bi", jiraLink + "bi-");
listJiraLink.add(biId);
}
if (!(listJiraLink.size()>0)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just check size == 0

@NotNull String repoName,
@NotNull String branchName) throws IOException {
final String pullRequestId = getPullRequestId(repoName, branchName);
if (pullRequestId == null) return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use if (condition) {
//code
} as standard


final RepoInfo head = pullRequestInfo.head;
if (head != null) {
return head.ref;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should declare a variable to hold return value, and using return at the end of method only


public class GetJiraTickets {
private static final Logger LOG = Logger.getInstance(GetJiraTickets.class.getName());
private static final String od = "od\\d*";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pattern will match all candidate that contain od, we need a pattern to match od d+ or od-d+

for (int i = 0; i < listTicketLink.size(); i++) {
String ticketLink = listTicketLink.get(i);
String ticketId = ticketLink.substring(ticketLink.lastIndexOf("/") + 1).toUpperCase();
String commentLine = "[" + ticketId + "](" + ticketLink + ")\n";
Copy link
Collaborator

@sonnguyen-logigear sonnguyen-logigear Aug 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should a space instead of "\n" as : OD-1 OD-2

public static List<String> getListTicketLink(@NotNull String branchName,
@NotNull String jiraLink) {

String name = branchName.toLowerCase().replaceAll("[^\\da-z]", "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only support patterns : od-123 and od 123, no need to replaceAll here

}
if (listTicketLink.size() == 0) {
LOG.debug("Pull request title " + branchName + " does not contain any ticket id");
listTicketLink = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no need to assign listTicketLink to null, we can check by get size of it.


private StringBuilder getJiraTicketComment(@NotNull List<String> listTicketLink) {
StringBuilder jiraLinksComment = new StringBuilder();
for (int i = 0; i < listTicketLink.size(); i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using for (String ticketLink : listTicketLink) as our standard

final String jiraLink = getJiraLink(build);
final List<String> listTicketLink = GetJiraTickets.getListTicketLink(refBranch, jiraLink);
if (listTicketLink.size() != 0) {
StringBuilder ticketLinkComment = getJiraTicketComment(listTicketLink);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just need to you String instead of StringBuilder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants