Skip to content

Commit 010cbca

Browse files
Fixed code to work with milestone closing
1 parent 2958117 commit 010cbca

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/main/java/io/micrometer/release/single/MilestoneMigrator.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ class MilestoneMigrator {
2929

3030
private final ProcessRunner processRunner;
3131

32-
private final String ghRepo;
32+
private final String ghOrgRepo;
3333

3434
private final MilestoneIssueReassigner milestoneIssueReassigner;
3535

3636
MilestoneMigrator(ProcessRunner processRunner, String ghRepo, MilestoneIssueReassigner milestoneIssueReassigner) {
3737
this.processRunner = processRunner;
38-
this.ghRepo = ghRepo;
38+
this.ghOrgRepo = ghRepo;
3939
this.milestoneIssueReassigner = milestoneIssueReassigner;
4040
}
4141

@@ -88,8 +88,8 @@ private MilestoneWithDeadline reassignIssues(String refName, Milestone genericMi
8888
return milestoneIssueReassigner.reassignIssues(concreteMilestone, refName, closedIssues, openIssues);
8989
}
9090

91-
private Milestone findMilestone(String title) {
92-
List<String> lines = processRunner.run("gh", "api", "/repos/" + ghRepo + "/milestones", "--jq",
91+
Milestone findMilestone(String title) {
92+
List<String> lines = processRunner.run("gh", "api", "/repos/" + ghOrgRepo + "/milestones", "--jq",
9393
String.format(".[] | select(.title == \"%s\") | {number: .number, title: .title}", title));
9494
if (lines.isEmpty()) {
9595
throw new IllegalStateException("No response from gh cli for version <" + title + ">");
@@ -106,7 +106,7 @@ private Milestone findMilestone(String title) {
106106

107107
private List<Issue> getIssuesForMilestone(int milestoneNumber) {
108108
List<String> lines = processRunner.run("gh", "api",
109-
String.format("/repos/%s/issues?milestone=%d&state=all", ghRepo, milestoneNumber), "--jq",
109+
String.format("/repos/%s/issues?milestone=%d&state=all", ghOrgRepo, milestoneNumber), "--jq",
110110
".[] | {number: .number, state: .state}");
111111
List<Issue> issues = new ArrayList<>();
112112
for (String line : lines) {

src/main/java/io/micrometer/release/single/MilestoneUpdater.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
package io.micrometer.release.single;
1717

1818
import io.micrometer.release.common.ProcessRunner;
19+
import io.micrometer.release.single.MilestoneMigrator.Milestone;
1920
import org.slf4j.Logger;
2021
import org.slf4j.LoggerFactory;
2122

22-
import java.util.List;
23-
2423
class MilestoneUpdater {
2524

2625
private static final Logger log = LoggerFactory.getLogger(MilestoneUpdater.class);
@@ -51,13 +50,11 @@ MilestoneWithDeadline updateMilestones(String githubRefName) {
5150
void closeMilestone(String githubRefName) {
5251
log.info("Closing milestone...");
5352
String milestoneName = githubRefName.replace("v", "");
54-
List<String> output = processRunner.run("gh", "api", "/repos/" + githubRepository + "/milestones?state=open",
55-
"--jq", "\".[] | select(.title == \\\"" + milestoneName + "\\\").number\"");
53+
Milestone milestone = milestoneMigrator.findMilestone(milestoneName);
5654

57-
if (!output.isEmpty()) {
58-
String milestoneNumber = output.get(0);
55+
if (milestone != null) {
5956
processRunner.run("gh", "api", "-X", "PATCH",
60-
"/repos/" + githubRepository + "/milestones/" + milestoneNumber, "-f", "state=closed");
57+
"/repos/" + githubRepository + "/milestones/" + milestone.number(), "-f", "state=closed");
6158
log.info("Successfully closed milestone {}", milestoneName);
6259
}
6360
else {

src/test/java/io/micrometer/release/single/MilestoneUpdaterTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ class MilestoneUpdaterTests {
3030
@Test
3131
void should_call_gh_api_to_close_a_milestone() {
3232
ProcessRunner processRunner = mock();
33-
given(processRunner.run("gh", "api", "/repos/micrometer-metrics/milestones?state=open", "--jq",
34-
"\".[] | select(.title == \\\"1.2.3\\\").number\""))
35-
.willReturn(List.of("100"));
36-
String ghRepo = "micrometer-metrics";
33+
given(processRunner.run("gh", "api", "/repos/micrometer-metrics/micrometer/milestones", "--jq",
34+
String.format(".[] | select(.title == \"%s\") | {number: .number, title: .title}", "1.2.3")))
35+
.willReturn(List.of("{\"number\":100,\"title\":\"1.2.3\"}"));
36+
String ghRepo = "micrometer-metrics/micrometer";
3737
MilestoneUpdater milestoneUpdater = new MilestoneUpdater(processRunner, ghRepo,
3838
new MilestoneMigrator(processRunner, ghRepo, new MilestoneIssueReassigner(processRunner, ghRepo)));
3939

4040
milestoneUpdater.closeMilestone("v1.2.3");
4141

42-
verify(processRunner).run("gh", "api", "-X", "PATCH", "/repos/micrometer-metrics/milestones/100", "-f",
43-
"state=closed");
42+
verify(processRunner).run("gh", "api", "-X", "PATCH", "/repos/micrometer-metrics/micrometer/milestones/100",
43+
"-f", "state=closed");
4444
}
4545

4646
}

0 commit comments

Comments
 (0)