Skip to content

Commit

Permalink
Pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
coverbeck committed Sep 4, 2024
1 parent d08918d commit 08f4c91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
5 changes: 1 addition & 4 deletions jira_automation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>topicGeneratorClient</id>
<id>milestoneResolverId</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
Expand All @@ -86,9 +86,6 @@
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<!-- not sure why this results in error unline our other repos if not excluded -->
<exclude>migrations.xml</exclude>
<exclude>migrations.*.xml</exclude>
</excludes>
</filter>
</filters>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ private MilestoneResolver() { }
public static void main(String[] args) throws IOException {
final List<JiraAndGithub> mismatchedIssues = findMismatchedIssues();
if (mismatchedIssues.isEmpty()) {
System.out.println("The JIRA fix version and GitHub milestone are in sync for all DOCK issues");
LOG.info("The JIRA fix version and GitHub milestone are in sync for all DOCK issues");
} else {
System.out.println("The following issues are mismatched:");
LOG.info("The following issues are mismatched:");
mismatchedIssues.forEach(MilestoneResolver::printMismatchedIssue);
}
mismatchedIssues.forEach(issue -> {
Expand All @@ -64,7 +64,7 @@ public static void main(String[] args) throws IOException {
final JiraIssue jiraIssue = Utils.getJiraIssue(issue.jiraIssueId);
final GHMilestone ghMilestone = gitHubIssue.getMilestone();
final String jiraIssueUrl = getJiraIssueUrl(jiraIssue.key());
System.out.println("Processing JIRA issue %s".formatted(jiraIssueUrl));
LOG.info("Processing JIRA issue {}", jiraIssueUrl);
final FixVersion[] fixVersions = jiraIssue.fields().fixVersions();
if (fixVersions.length == 0) {
// There is GitHub milestone but no JIRA fix version
Expand All @@ -73,31 +73,29 @@ public static void main(String[] args) throws IOException {
// There's a JIRA fix version, but no GitHub milestone, set the GitHub milestone
updateGitHubMilestone(gitHubIssue.getNumber(), fixVersions[0].name());
} else {
System.out.println("The fix version and milestone mismatch must be resolved manually for: %s".formatted(getJiraIssueUrl(issue.jiraIssueId)));
LOG.info("The fix version and milestone mismatch must be resolved manually for: {}}", getJiraIssueUrl(issue.jiraIssueId));
}
} catch (URISyntaxException | IOException | InterruptedException e) {
LOG.error("Error resolving %s".formatted(issue), e);
throw new RuntimeException(e);
}
});
}

private static void updateGitHubMilestone(int gitHubIssue, String jiraFixVersion) {
if (Utils.updateGitHubMilestone(gitHubIssue, jiraFixVersion)) {
System.out.println("Updated GitHub milestone in %s to %s".formatted(gitHubIssue, jiraFixVersion));
LOG.info("Updated GitHub milestone in {} to {}", gitHubIssue, jiraFixVersion);
} else {
System.err.println("Failed to update GitHub milestone in %s".formatted(gitHubIssue));
LOG.error("Failed to update GitHub milestone in {}", gitHubIssue);
}
}

private static void updateJiraIssue(String jiraIssue, String gitHubMilestone)
throws URISyntaxException, IOException, InterruptedException {
final String jiraIssueUrl = getJiraIssueUrl(jiraIssue);
if (Utils.updateJiraFixVersion(jiraIssue, gitHubMilestone)) {
System.out.println("Updated fix version in %s to %s".formatted(jiraIssueUrl,
gitHubMilestone));
LOG.info("Updated fix version in {} to {}", jiraIssueUrl, gitHubMilestone);
} else {
System.err.println("Failed to update fix version in %s".formatted(jiraIssueUrl));
LOG.error("Failed to update fix version in {}", jiraIssueUrl);
}
}

Expand All @@ -107,12 +105,12 @@ private static void printMismatchedIssue(final MilestoneResolver.JiraAndGithub i
final String notSet = "<not set>";
final String milestone = ghMilestone != null ? ghMilestone.getTitle() : notSet;
final String jiraFixVersion = findJiraFixVersion(ghIssue.getBody()).orElse(notSet);
System.out.println(
"GitHub %s, milestone %s; JIRA %s, fix version %s".formatted(
LOG.info(
"GitHub {}, milestone {}; JIRA {}, fix version {}",
ghIssue.getNumber(),
milestone,
issue.jiraIssueId,
jiraFixVersion));
jiraFixVersion);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions jira_automation/src/main/java/io/dockstore/jira/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class Utils {
private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
private static final String JIRA_USERNAME = "JIRA_USERNAME";
private static final String JIRA_TOKEN = "JIRA_TOKEN";
private static final Gson GSON = new Gson();

private static final Logger LOG = LoggerFactory.getLogger(Utils.class);

Expand All @@ -51,9 +52,8 @@ public static JiraIssue getJiraIssue(String issueId)
.uri(uri)
.build();
final HttpResponse<String> response = HTTP_CLIENT.send(httpRequest, BodyHandlers.ofString());
final Gson gson = new Gson();
final String body = response.body();
final JiraIssue jiraIssue = gson.fromJson(body, JiraIssue.class);
final JiraIssue jiraIssue = GSON.fromJson(body, JiraIssue.class);
return jiraIssue;
}

Expand Down

0 comments on commit 08f4c91

Please sign in to comment.