Search in sources :

Example 1 with RtGithub

use of com.jcabi.github.RtGithub in project jcabi-github by jcabi.

the class Main method main.

/**
 * Main entry point.
 * @param args Command line arguments
 */
public static void main(final String[] args) throws Exception {
    final Github github = new RtGithub();
    final JsonResponse resp = github.entry().uri().path("/search/repositories").queryParam("q", "java").back().fetch().as(JsonResponse.class);
    final List<JsonObject> items = resp.json().readObject().getJsonArray("items").getValuesAs(JsonObject.class);
    for (final JsonObject item : items) {
        System.out.println(String.format("repository found: %s", item.get("full_name").toString()));
    }
}
Also used : RtGithub(com.jcabi.github.RtGithub) Github(com.jcabi.github.Github) JsonObject(javax.json.JsonObject) RtGithub(com.jcabi.github.RtGithub) JsonResponse(com.jcabi.http.response.JsonResponse)

Example 2 with RtGithub

use of com.jcabi.github.RtGithub in project jcabi-github by jcabi.

the class SampleTest method fetchesLabelsFromGithub.

/**
 * Fetches labels from Github.
 * @throws Exception If fails
 */
@Test
public void fetchesLabelsFromGithub() throws Exception {
    final Github github = new RtGithub();
    final Repo repo = github.repos().get(new Coordinates.Simple("jcabi/jcabi-github"));
    MatcherAssert.assertThat(repo.labels().iterate().iterator().hasNext(), Matchers.equalTo(true));
}
Also used : Repo(com.jcabi.github.Repo) RtGithub(com.jcabi.github.RtGithub) Github(com.jcabi.github.Github) Coordinates(com.jcabi.github.Coordinates) RtGithub(com.jcabi.github.RtGithub) Test(org.junit.Test)

Example 3 with RtGithub

use of com.jcabi.github.RtGithub in project wring by yegor256.

the class AgGithub method push.

@Override
public String push(final Events events) throws IOException {
    final Github github = new RtGithub(this.config.getString("token"));
    final String since = DateFormatUtils.formatUTC(DateUtils.addMinutes(new Date(), -Tv.THREE), "yyyy-MM-dd'T'HH:mm:ss'Z'");
    final Request req = github.entry().uri().path("/notifications").back();
    final Iterable<JsonObject> list = new RtPagination<>(req.uri().queryParam("participating", "true").queryParam("since", since).queryParam("all", Boolean.toString(true)).back(), RtPagination.COPYING);
    final Collection<String> done = new LinkedList<>();
    for (final JsonObject event : AgGithub.safe(list)) {
        final String reason = event.getString("reason");
        if (!"mention".equals(reason)) {
            continue;
        }
        this.push(github, event, events);
        done.add(event.getString("id"));
    }
    req.uri().queryParam("last_read_at", since).back().method(Request.PUT).body().set("{}").back().fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_RESET);
    if (!done.isEmpty()) {
        Logger.info(this, "%d GitHub events for @%s processed: %s", done.size(), github.users().self().login(), done);
    }
    return String.format("%d events for @%s at %s", done.size(), github.users().self().login(), DateFormatUtils.formatUTC(new Date(), "yyyy-MM-dd HH:mm:ss"));
}
Also used : RtGithub(com.jcabi.github.RtGithub) Github(com.jcabi.github.Github) RestResponse(com.jcabi.http.response.RestResponse) Request(com.jcabi.http.Request) JsonObject(javax.json.JsonObject) RtGithub(com.jcabi.github.RtGithub) Date(java.util.Date) LinkedList(java.util.LinkedList) RtPagination(com.jcabi.github.RtPagination)

Aggregations

Github (com.jcabi.github.Github)3 RtGithub (com.jcabi.github.RtGithub)3 JsonObject (javax.json.JsonObject)2 Coordinates (com.jcabi.github.Coordinates)1 Repo (com.jcabi.github.Repo)1 RtPagination (com.jcabi.github.RtPagination)1 Request (com.jcabi.http.Request)1 JsonResponse (com.jcabi.http.response.JsonResponse)1 RestResponse (com.jcabi.http.response.RestResponse)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1