|
| 1 | +package io.github.stianst.gh; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.databind.JsonNode; |
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 5 | + |
| 6 | +import java.io.File; |
| 7 | +import java.io.IOException; |
| 8 | +import java.util.Iterator; |
| 9 | +import java.util.LinkedList; |
| 10 | +import java.util.List; |
| 11 | +import java.util.Spliterator; |
| 12 | +import java.util.Spliterators; |
| 13 | +import java.util.stream.StreamSupport; |
| 14 | + |
| 15 | +public class IssuesWithDuplicatedKindLabels { |
| 16 | + |
| 17 | + public static void main(String[] args) throws IOException { |
| 18 | + File file = new File("gh/all-issues.json"); |
| 19 | + System.out.println(file.getAbsolutePath()); |
| 20 | + ObjectMapper om = new ObjectMapper(); |
| 21 | + JsonNode jsonNode = om.readValue(file, JsonNode.class); |
| 22 | + |
| 23 | + List<Issue> issues = new LinkedList<>(); |
| 24 | + |
| 25 | + Iterator<JsonNode> elements = jsonNode.elements(); |
| 26 | + while (elements.hasNext()) { |
| 27 | + JsonNode next = elements.next(); |
| 28 | + String url = next.get("html_url").asText(); |
| 29 | + String type = !next.get("type").isNull() ? next.get("type").get("name").asText() : null; |
| 30 | + JsonNode labels = next.get("labels"); |
| 31 | + List<String> labelStrings = StreamSupport.stream(Spliterators.spliteratorUnknownSize(labels.elements(), Spliterator.ORDERED), false) |
| 32 | + .map(n -> n.get("name").asText()) |
| 33 | + .filter(k -> k.startsWith("kind/")) |
| 34 | + .filter(k -> !k.equals("kind/performance")) |
| 35 | + .filter(k -> !k.equals("kind/weakness")) |
| 36 | + .filter(k -> !k.equals("kind/cve")) |
| 37 | + .toList(); |
| 38 | + issues.add(new Issue(url, labelStrings, type)); |
| 39 | + } |
| 40 | + |
| 41 | + System.out.println("Issues with multiple kind labels:"); |
| 42 | + issues.stream().filter(i -> i.labels().size() > 1).forEach(i -> System.out.println(i.url() + " --> " + i.labels())); |
| 43 | + |
| 44 | + /* (labelStrings.size() > 1) { |
| 45 | +// System.out.println(url + " --> " + labelStrings); |
| 46 | + } else if (type != null) { |
| 47 | + if (labelStrings.get(0).equals("kind/" + type)) { |
| 48 | + System.out.println(url + " --> " + labelStrings + " == " + type); |
| 49 | + } |
| 50 | + }*/ |
| 51 | + |
| 52 | + System.out.println(""); |
| 53 | + System.out.println("Issues with miss-matching type and kind labels:"); |
| 54 | + issues.stream().filter(i -> i.type() != null && i.labels().size() == 1 && !i.labels().get(0).equals("kind/" + i.type())).forEach(i -> System.out.println(i.url() + " --> " + i.type() + " != " + i.labels())); |
| 55 | + } |
| 56 | + |
| 57 | + private record Issue(String url, List<String> labels, String type) {} |
| 58 | + |
| 59 | +} |
0 commit comments