-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpostcorerelease.java
executable file
·74 lines (61 loc) · 2.53 KB
/
postcorerelease.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.quarkus.platform:quarkus-bom:3.2.2.Final@pom
//DEPS io.quarkus:quarkus-picocli
//DEPS org.kohsuke:github-api:1.315
//JAVA 21
//JAVAC_OPTIONS -parameters
//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager
//Q:CONFIG quarkus.log.level=SEVERE
//Q:CONFIG quarkus.banner.enabled=false
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHMilestone;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.GitHubBuilder;
import picocli.CommandLine.Command;
@Command(name = "postcorerelease", mixinStandardHelpOptions = true)
public class postcorerelease implements Runnable {
@Override
public void run() {
try {
GitHub github;
String releaseGitHubToken = System.getenv("RELEASE_GITHUB_TOKEN");
if (releaseGitHubToken != null && !releaseGitHubToken.isBlank()) {
github = new GitHubBuilder().withOAuthToken(releaseGitHubToken).build();
} else {
github = GitHubBuilder.fromPropertyFile().build();
}
GHRepository repository = getProject(github);
String version = getVersion();
Optional<GHMilestone> milestoneOptional = repository.listMilestones(GHIssueState.OPEN).toList().stream()
.filter(m -> version.equals(m.getTitle()))
.findFirst();
if (milestoneOptional.isEmpty()) {
fail("Cannot find the milestone " + version);
}
closeOldMilestone(milestoneOptional.get(), version);
} catch (IOException e) {
e.printStackTrace();
fail("IOException was thrown, please see above");
}
}
private static void closeOldMilestone(GHMilestone milestone, String version) throws IOException {
milestone.close();
System.out.println("Milestone " + version + " closed - " + milestone.getHtmlUrl());
}
private static String getVersion() throws IOException {
return Files.readString(Path.of("work", "newVersion"), StandardCharsets.UTF_8).trim();
}
private static GHRepository getProject(GitHub github) throws IOException {
return github.getRepository("quarkusio/quarkus");
}
private static void fail(String message) {
System.err.println(message);
System.exit(2);
}
}