Created
June 19, 2020 08:28
-
-
Save timja/a939f198752b218c3270ac043eb0813f to your computer and use it in GitHub Desktop.
org github issues report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.time.LocalDateTime; | |
import java.util.Collection; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import org.kohsuke.github.GHIssueState; | |
import org.kohsuke.github.GHOrganization; | |
import org.kohsuke.github.GHRepository; | |
import org.kohsuke.github.GitHub; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
GitHub github = GitHub.connect(); | |
System.out.println(LocalDateTime.now()); | |
Data organisationSummary = getOrganisationSummary(github, "jenkinsci"); | |
System.out.println(LocalDateTime.now()); | |
System.out.println("Org report: " + organisationSummary.orgName); | |
System.out.println("Total repositories: " + organisationSummary.repoCount); | |
System.out.println("Number with GitHub issues enabled: " + organisationSummary.hasIssuesCount()); | |
System.out.println("Total issues open: " + organisationSummary.getOpenIssuesCount()); | |
System.out.println("Total issues closed: " + organisationSummary.getClosedIssuesCount()); | |
System.out.println("Total issues: " + organisationSummary.getTotalIssuesCount()); | |
} | |
private static Data getOrganisationSummary(GitHub github, String orgName) throws IOException { | |
GHOrganization jenkinsci = github.getOrganization(orgName); | |
Collection<GHRepository> values = jenkinsci.getRepositories() | |
.values(); | |
List<RepoSummary> repoSummaries = values | |
.stream() | |
.filter(GHRepository::hasIssues) | |
.map(repo -> { | |
try { | |
return new RepoSummary(repo.getName(), repo.getOpenIssueCount(), repo.getIssues(GHIssueState.CLOSED).size()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return null; | |
} | |
}) | |
.collect(Collectors.toList()); | |
return new Data(orgName, values.size(), repoSummaries); | |
} | |
public static class RepoSummary { | |
String name; | |
int openIssues; | |
int closedIssues; | |
public RepoSummary(String name, int openIssues, int closedIssues) { | |
this.name = name; | |
this.openIssues = openIssues; | |
this.closedIssues = closedIssues; | |
} | |
} | |
public static class Data { | |
String orgName; | |
int repoCount; | |
final List<RepoSummary> repoSummaries; | |
int openIssuesCount; | |
int closedIssuesCount; | |
public Data(String orgName, int repoCount, List<RepoSummary> repoSummaries) { | |
this.orgName = orgName; | |
this.repoCount = repoCount; | |
this.repoSummaries = repoSummaries; | |
openIssuesCount = repoSummaries.stream() | |
.map(repoSummary -> repoSummary.openIssues) | |
.reduce(0, Integer::sum); | |
closedIssuesCount = repoSummaries.stream() | |
.map(repoSummary -> repoSummary.closedIssues) | |
.reduce(0, Integer::sum); | |
} | |
public int getOpenIssuesCount() { | |
return openIssuesCount; | |
} | |
public int getClosedIssuesCount() { | |
return closedIssuesCount; | |
} | |
public int hasIssuesCount() { | |
return repoSummaries.size(); | |
} | |
public int getTotalIssuesCount() { | |
return getOpenIssuesCount() + getClosedIssuesCount(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment