Search in sources :

Example 6 with Issue

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

the class MkIssueLabelsTest method addingLabelGeneratesEvent.

/**
 * MkIssueLabels creates a "labeled" event when a label is added.
 * @throws Exception If some problem inside
 */
@Test
public void addingLabelGeneratesEvent() throws Exception {
    final Repo repo = new MkGithub().randomRepo();
    final String name = "confirmed";
    repo.labels().create(name, "663399");
    final Issue issue = repo.issues().create("Titular", "Corpus");
    issue.labels().add(Collections.singletonList(name));
    MatcherAssert.assertThat(issue.events(), Matchers.<Event>iterableWithSize(1));
    final Event.Smart labeled = new Event.Smart(issue.events().iterator().next());
    MatcherAssert.assertThat(labeled.type(), Matchers.equalTo(Event.LABELED));
    MatcherAssert.assertThat(labeled.author().login(), Matchers.equalTo(USER));
    MatcherAssert.assertThat(labeled.repo(), Matchers.equalTo(repo));
    MatcherAssert.assertThat(labeled.label().get().name(), Matchers.equalTo(name));
}
Also used : Issue(com.jcabi.github.Issue) Repo(com.jcabi.github.Repo) Event(com.jcabi.github.Event) Test(org.junit.Test)

Example 7 with Issue

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

the class MkIssueLabelsTest method createsLabelsThroughDecorator.

/**
 * MkIssueLabels can create labels through Smart decorator.
 * @throws Exception If some problem inside
 */
@Test
public void createsLabelsThroughDecorator() throws Exception {
    final Repo repo = new MkGithub().randomRepo();
    final Issue issue = repo.issues().create("how are you?", "");
    final String name = "task";
    new IssueLabels.Smart(issue.labels()).addIfAbsent(name, "f0f0f0");
    MatcherAssert.assertThat(issue.labels().iterate(), Matchers.<Label>iterableWithSize(1));
}
Also used : Issue(com.jcabi.github.Issue) Repo(com.jcabi.github.Repo) IssueLabels(com.jcabi.github.IssueLabels) Test(org.junit.Test)

Example 8 with Issue

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

the class MkGithubTest method canRelogin.

/**
 * MkGithub can relogin.
 *
 * @throws Exception if some problem inside
 */
@Test
public void canRelogin() throws Exception {
    final String login = "mark";
    final MkGithub github = new MkGithub();
    final Repo repo = github.repos().create(NEW_REPO_SETTINGS);
    final Issue issue = repo.issues().create("title", "Found a bug");
    final Comment comment = github.relogin(login).repos().get(repo.coordinates()).issues().get(issue.number()).comments().post("Nice change");
    MatcherAssert.assertThat(new User.Smart(new Comment.Smart(comment).author()).login(), Matchers.not(Matchers.equalTo(new User.Smart(repo.github().users().self()).login())));
    MatcherAssert.assertThat(new User.Smart(new Comment.Smart(comment).author()).login(), Matchers.equalTo(login));
}
Also used : Comment(com.jcabi.github.Comment) Issue(com.jcabi.github.Issue) Repo(com.jcabi.github.Repo) Test(org.junit.Test)

Example 9 with Issue

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

the class MkPulls method create.

@Override
public Pull create(final String title, final String head, final String base) throws IOException {
    if (head.isEmpty()) {
        throw new IllegalArgumentException("head cannot be empty!");
    }
    if (base.isEmpty()) {
        throw new IllegalArgumentException("base cannot be empty!");
    }
    final String canonical;
    if (head.contains(MkPulls.USER_BRANCH_SEP)) {
        canonical = head;
    } else {
        canonical = String.format("%s%s%s", this.coords.user(), MkPulls.USER_BRANCH_SEP, head);
    }
    this.storage.lock();
    final int number;
    try {
        final Issue issue = this.repo().issues().create(title, "some body");
        number = issue.number();
        this.storage.apply(new Directives().xpath(this.xpath()).add("pull").add("number").set(Integer.toString(number)).up().add("head").set(canonical).up().add("base").set(base).up().add("user").add("login").set(this.self).up());
    } finally {
        this.storage.unlock();
    }
    return this.get(number);
}
Also used : Issue(com.jcabi.github.Issue) Directives(org.xembly.Directives) ToString(lombok.ToString)

Example 10 with Issue

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

the class MkGithubTest method worksWithMockedData.

/**
 * MkGithub can work.
 * @throws Exception If some problem inside
 */
@Test
public void worksWithMockedData() throws Exception {
    final Repo repo = new MkGithub().repos().create(NEW_REPO_SETTINGS);
    final Issue issue = repo.issues().create("hey", "how are you?");
    final Comment comment = issue.comments().post("hey, works?");
    MatcherAssert.assertThat(new Comment.Smart(comment).body(), Matchers.startsWith("hey, "));
    MatcherAssert.assertThat(repo.issues().get(issue.number()).comments().iterate(new Date(0L)), Matchers.<Comment>iterableWithSize(1));
    MatcherAssert.assertThat(new User.Smart(new Comment.Smart(comment).author()).login(), Matchers.equalTo(new User.Smart(repo.github().users().self()).login()));
}
Also used : Comment(com.jcabi.github.Comment) Issue(com.jcabi.github.Issue) User(com.jcabi.github.User) Repo(com.jcabi.github.Repo) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Issue (com.jcabi.github.Issue)17 Test (org.junit.Test)16 Repo (com.jcabi.github.Repo)10 Comment (com.jcabi.github.Comment)2 Event (com.jcabi.github.Event)2 Github (com.jcabi.github.Github)1 IssueLabels (com.jcabi.github.IssueLabels)1 Labels (com.jcabi.github.Labels)1 Pull (com.jcabi.github.Pull)1 User (com.jcabi.github.User)1 Date (java.util.Date)1 ToString (lombok.ToString)1 CustomMatcher (org.hamcrest.CustomMatcher)1 Directives (org.xembly.Directives)1