Skip to content

Instantly share code, notes, and snippets.

@anon767
Last active September 13, 2017 19:01
Show Gist options
  • Save anon767/ca7b4e58be811f2e2920cbcc7fe8bd58 to your computer and use it in GitHub Desktop.
Save anon767/ca7b4e58be811f2e2920cbcc7fe8bd58 to your computer and use it in GitHub Desktop.
[Java] small script to get the amount of views and unique visitors of all of your github repos using kohsuke github API
/**
* Created by tom on 13.09.2017.
*/
import org.kohsuke.github.*;
import java.io.IOException;
public class Main {
private static final String userid = "username";
private static final String oauth = "token";
public static void main(String[] args) {
GitHub gitHub = login();
if (gitHub != null)
System.out.println("connected");
else
System.out.println("connection failed");
PagedSearchIterable<GHRepository> repos = gitHub.searchRepositories().user(userid).list();
for (GHRepository repo : repos) {
try {
System.out.println(repo.getUrl() + " Views:" + repo.getViewTraffic().getCount() + " unique:" + repo.getViewTraffic().getUniques());
} catch (IOException e) {
System.out.println("Failed to query " + repo.getUrl());
}
}
}
private static GitHub login() {
GitHub github = null;
try {
github = GitHub.connect(userid, oauth);
} catch (IOException e) {
e.printStackTrace();
}
return github;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment