Search in sources :

Example 1 with Github

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

the class MkIssueEvents method create.

/**
 * Creates a new issue event.
 * This has no equivalent in GitHub's public API, since GitHub generates
 * events automatically in response to some other API calls.
 * @param type Type of event
 * @param issue ID number of issue the event is regarding
 * @param login Username of actor who caused the event
 * @param label Label added or removed
 * @return The newly created issue event
 * @throws IOException If there is any I/O problem
 * @todo #1063:30min Make it possible to set the "assignee" field for
 *  "assigned"/"unassigned" events. Make it possible to set the
 *  "milestone" field for "milestoned"/"demilestoned" events. Make it
 *  possible to set the "rename" field for "renamed" events. Make it
 *  possible to set the "commit_id" field for events related to commits.
 *  See https://developer.github.com/v3/issues/events/ for details.
 * @checkstyle ParameterNumberCheck (4 lines)
 */
public Event create(final String type, final int issue, final String login, final Optional<String> label) throws IOException {
    final String created = new Github.Time().toString();
    this.storage.lock();
    final int number;
    try {
        number = 1 + this.storage.xml().xpath(String.format("%s/issue-event/number/text()", this.xpath())).size();
        Directives directives = new Directives().xpath(this.xpath()).add("issue-event").add("issue").set(Integer.toString(issue)).up().add("number").set(Integer.toString(number)).up().add("event").set(type).up().add("created_at").set(created).up().add("login").set(login).up();
        if (label.isPresent()) {
            directives = directives.add("label").set(label.get()).up();
        }
        this.storage.apply(directives);
    } finally {
        this.storage.unlock();
    }
    Logger.info(MkEvent.class, "issue event #%d of type %s created in %s for issue #%d by %s", number, type, this.self, issue, login);
    return this.get(number);
}
Also used : Github(com.jcabi.github.Github) Directives(org.xembly.Directives) ToString(lombok.ToString)

Example 2 with Github

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

the class MkIssuesTest method createsMultipleIssues.

/**
 * MkIssues can create a multiple issues.
 * @throws Exception If some problem inside
 */
@Test
public void createsMultipleIssues() throws Exception {
    final Github github = new MkGithub("jeff");
    final Repo repo = github.repos().create(new Repos.RepoCreate("test-3", false));
    for (int idx = 1; idx < Tv.TEN; ++idx) {
        repo.issues().create("title", "body");
    }
}
Also used : Repos(com.jcabi.github.Repos) Repo(com.jcabi.github.Repo) Github(com.jcabi.github.Github) Test(org.junit.Test)

Example 3 with Github

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

the class MkIssueTest method canRememberItsAuthor.

/**
 * MkIssue can remember it's author.
 * @throws Exception when a problem occurs.
 */
@Test
public void canRememberItsAuthor() throws Exception {
    final MkGithub first = new MkGithub("first");
    final Github second = first.relogin("second");
    final Repo repo = first.randomRepo();
    final int number = second.repos().get(repo.coordinates()).issues().create("", "").number();
    final Issue issue = first.repos().get(repo.coordinates()).issues().get(number);
    MatcherAssert.assertThat(new Issue.Smart(issue).author().login(), Matchers.is("second"));
}
Also used : Issue(com.jcabi.github.Issue) Repo(com.jcabi.github.Repo) Github(com.jcabi.github.Github) Test(org.junit.Test)

Example 4 with Github

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

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

the class MkGithubTest method retrievesMarkdown.

/**
 * MkGithub can retrieve the markdown.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void retrievesMarkdown() throws Exception {
    final Github github = new MkGithub();
    MatcherAssert.assertThat(github.markdown(), Matchers.notNullValue());
}
Also used : Github(com.jcabi.github.Github) Test(org.junit.Test)

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