Last week I worked a task to print most starred repositories and its last commit message. I want to share my experience with you.
To achieve this I implemented an API named jcabi-github. Its an Object Oriented Github API which provide a solution to use github API in easier way. This implementation has some advantage like this:

  • All classes are private and implement public interfaces.
  • Out-of-the-box in-memory mock of Github server.
  • All classes are truly immutable and thread-safe.
  • Every Github object gives GET/PATCH access to its raw JSON
  • HTTP request is accessible for modifications.
  • Entire Github API is available, at least through a configurable HTTP request
  • For more information and documenation you can go through

    Now here is a scenario how we use this API. Suppose you want to get most starred repositories of java. Then you need to follow this syntax.

    final Github github = new RtGithub(".. your OAuth token ..");
    // You can generate OAuth token from here.
    Map map = ['q': 'java', 'sort': 'stars', 'order': 'desc', 'per_page': '20'] // Where q is a search keyword as well as any qualifier. sort use to sort field from one of stars, forks or updated. Order is use for set order either ascending or descending order. Default is descending.
    final JsonResponse resp = github.entry()
    .uri().path("/search/repositories") // API request for search repository.
    .queryParams(map).back() // Additional parameter with request.
    You can find out API documentation for search repository from here.
    final List<JsonObject> items = resp.json().readObject()
    .getJsonArray("items") // get response in json format.
    for (final JsonObject item : items) {
    Repos repos = github.repos()
    System.out.println("Repository Name  " + item.get("full_name").toString().replaceAll(""", ""))
    String repoName =  item.get("full_name").toString().replaceAll(""", "")
    Coordinates coordinates = new Coordinates.Simple(repoName) // get coordinates for repository.
    Repo repo = repos.get(coordinates);
    RepoCommits repoCommits = repo.commits() // get collection of commits for repository.
    HttpURLConnection conn;
    BufferedReader bufferedReader;
    String line;
    StringBuilder sb = new StringBuilder();
    if (repoCommits) {
    Iterator<RepoCommit> repoCommitIterator = repoCommits.iterate(new HashMap<String, String>()).iterator()
    URL url = new URL( // url for latest commit. You can found all commits from iterator if you want.
    conn = (HttpURLConnection) url.openConnection();
    if (conn.getResponseCode() == 200) {
    bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    while ((line = bufferedReader.readLine()) != null) {
    sb.append(line + "n");
    bufferedReader.close() root = ( new JsonParser().parse(sb.toString());

    To find last commit from repository we need to find out latest commit link for this at first using given syntax.

    Repos repos = github.repos()
    Coordinates coordinates = new Coordinates.Simple("Repository name")
    Repo repo = repos.get(coordinates);
    RepoCommits repoCommits = repo.commits()
    Iterator<RepoCommit> repoCommitIterator = repoCommits.iterate(new HashMap<String, String>()).iterator()
    String latestCommit  = // latest commit link.

    To fetch information for last commit we need to send request for latest commit.

    URL url = new URL(
    conn = (HttpURLConnection) url.openConnection();
    bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

    It will provide you a response for related to latest commit. To change it in json format we can use this syntax. root = ( new JsonParser().parse(sb.toString());
    println "Latest commit message    :   ${gitReporoot.message.toString().replaceAll(""", "")}"

    I have write my code in groovy language. If you are using java, please modify it according to java code. This is all what I researched to get starred repository and its latest commit. I hope it will help you.