Last active
September 13, 2017 19:01
-
-
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
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
/** | |
* 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