forked from quarkusio/quarkusio.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchpub.java
executable file
·82 lines (62 loc) · 2.78 KB
/
fetchpub.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
75
76
77
78
79
80
81
82
//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS info.picocli:picocli:4.2.0
//DEPS org.kohsuke:github-api:1.101
//DEPS com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.9
//DEPS com.fasterxml.jackson.core:jackson-databind:2.9.9
import static java.lang.System.out;
import static java.util.Arrays.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.kohsuke.github.*;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
import java.io.File;
import java.util.*;
import java.util.concurrent.Callable;
@Command(name = "fetchpub", mixinStandardHelpOptions = true, version = "fetchpub 0.1",
description = "fetchpub made with jbang")
class fetchpub implements Callable<Integer> {
@Parameters(index = "0", description = "Location of publications", defaultValue = "_data/publications.yaml")
private File pubfile;
public static void main(String... args) {
int exitCode = new CommandLine(new fetchpub()).execute(args);
System.exit(exitCode);
}
@JsonIgnoreProperties(ignoreUnknown = true)
static public class Publication {
public String url;
}
@Override
public Integer call() throws Exception { // your business logic goes here...
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
List<Publication> publications = mapper.readValue(pubfile, new TypeReference<List<Publication>>(){});
Set<String> urls = new HashSet<>();
for(var pub:publications) {
urls.add(pub.url);
}
GitHub github = GitHub.connectAnonymously();
var ghRepo = github.getRepository("quarkusio/quarkus");
var list = github.searchIssues().isOpen().q("repo:quarkusio/quarkusio.github.io").q("label:publication").list().asList();
list.sort((GHIssue issue1, GHIssue issue2) -> Integer.compare(issue1.getNumber(), issue2.getNumber()));
var included = new ArrayList<GHIssue>();
for(GHIssue issue:list) {
String snippet = issue.getBody().replace("```", "");
Publication p = mapper.readValue(snippet, Publication[].class)[0];
if(urls.contains(p.url)) {
out.println("#" + issue.getNumber() + " already included");
} else {
out.println("#" + issue.getNumber() );
out.println(issue.getBody().replace("```", ""));
included.add(issue);
}
}
out.println();
for(GHIssue issue:included) {
out.println(issue.getTitle() + ", Fixes #" + issue.getNumber());
}
return 0;
}
}