Search in sources :

Example 6 with Github

use of com.jcabi.github.Github 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 7 with Github

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

the class MkUserOrganizationsTest method iteratesUserOrganizations.

/**
 * MkUserOrganizations can list user organizations.
 * @throws Exception If some problem inside
 */
@Test
public void iteratesUserOrganizations() throws Exception {
    final String login = "orgTestIterate";
    final Github github = new MkGithub(login);
    final UserOrganizations userOrgs = github.users().get(login).organizations();
    github.organizations().get(login);
    MatcherAssert.assertThat(userOrgs.iterate(), Matchers.<Organization>iterableWithSize(1));
}
Also used : Github(com.jcabi.github.Github) UserOrganizations(com.jcabi.github.UserOrganizations) Test(org.junit.Test)

Example 8 with Github

use of com.jcabi.github.Github 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)8 Test (org.junit.Test)5 Repo (com.jcabi.github.Repo)3 RtGithub (com.jcabi.github.RtGithub)3 JsonObject (javax.json.JsonObject)2 Coordinates (com.jcabi.github.Coordinates)1 Issue (com.jcabi.github.Issue)1 Repos (com.jcabi.github.Repos)1 RtPagination (com.jcabi.github.RtPagination)1 UserOrganizations (com.jcabi.github.UserOrganizations)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 ToString (lombok.ToString)1 Directives (org.xembly.Directives)1