Search in sources :

Example 1 with Comment

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

use of com.jcabi.github.Comment 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)

Example 3 with Comment

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

the class MkCommentTest method changesBody.

/**
 * MkComment can change body.
 * @throws Exception If some problem inside
 */
@Test
public void changesBody() throws Exception {
    final Comment comment = this.comment("hey buddy");
    new Comment.Smart(comment).body("hello, this is a new body");
    MatcherAssert.assertThat(new Comment.Smart(comment).body(), Matchers.startsWith("hello, this "));
}
Also used : Comment(com.jcabi.github.Comment) Test(org.junit.Test)

Example 4 with Comment

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

the class MkCommentTest method dataStoredProperly.

/**
 * MkComment should store all its data properly.
 * We should get the proper data back when accessing its properties.
 * @throws Exception when a problem occurs.
 */
@Test
public void dataStoredProperly() throws Exception {
    final String cmt = "what's up?";
    final long before = MkCommentTest.now();
    final Comment comment = this.comment(cmt);
    final long after = MkCommentTest.now();
    MatcherAssert.assertThat(comment.number(), Matchers.greaterThan(0));
    final Comment.Smart smart = new Comment.Smart(comment);
    MatcherAssert.assertThat(smart.issue().number(), Matchers.greaterThan(0));
    MatcherAssert.assertThat(smart.author().login(), Matchers.equalTo("jeff"));
    MatcherAssert.assertThat(smart.body(), Matchers.equalTo(cmt));
    MatcherAssert.assertThat(smart.url(), Matchers.equalTo(new URL(// @checkstyle LineLength (1 line)
    "https://api.jcabi-github.invalid/repos/jeff/blueharvest/issues/comments/1")));
    MatcherAssert.assertThat(smart.createdAt().getTime(), Matchers.greaterThanOrEqualTo(before));
    MatcherAssert.assertThat(smart.createdAt().getTime(), Matchers.lessThanOrEqualTo(after));
    MatcherAssert.assertThat(smart.updatedAt().getTime(), Matchers.greaterThanOrEqualTo(before));
    MatcherAssert.assertThat(smart.updatedAt().getTime(), Matchers.lessThanOrEqualTo(after));
}
Also used : Comment(com.jcabi.github.Comment) URL(java.net.URL) Test(org.junit.Test)

Example 5 with Comment

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

the class BoIssue method text.

/**
 * Collect all important texts from the issue.
 * @return Body text
 * @throws IOException If fails
 * @checkstyle ExecutableStatementCountCheck (100 lines)
 */
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public String text() throws IOException {
    final Iterator<Comment.Smart> comments = new Smarts<Comment.Smart>(new Bulk<>(this.issue.comments().iterate())).iterator();
    final String self = this.issue.repo().github().users().self().login();
    final Pattern ptn = Pattern.compile(String.format(".*(?<![a-zA -Z0-9-])%s(?![a-zA-Z0-9-]).*", Pattern.quote(String.format("@%s", self))), Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
    int seen = this.seen();
    Logger.info(this, "Last seen comment in %s#%d is #%d", this.issue.repo().coordinates(), this.issue.number(), seen);
    final StringBuilder body = new StringBuilder();
    while (comments.hasNext()) {
        final Comment.Smart comment = comments.next();
        if (comment.number() <= seen) {
            continue;
        }
        // @checkstyle MagicNumber (1 line)
        if (comment.number() < 188060467) {
            Logger.info(this, "%s#%d/%d ignored since too old", this.issue.repo().coordinates(), this.issue.number(), comment.number());
            continue;
        }
        if (comment.author().login().equals(self)) {
            Logger.info(this, "%s#%d/%d ignored since you're the author", this.issue.repo().coordinates(), this.issue.number(), comment.number());
            continue;
        }
        final String cmt = comment.body();
        if (ptn.matcher(cmt).matches()) {
            body.append('@').append(comment.author().login()).append(" at [").append(String.format("%te-%<tb-%<tY", comment.createdAt())).append("](").append(this.issue.htmlUrl()).append("#issuecomment-").append(comment.number()).append("): ").append(StringEscapeUtils.escapeHtml4(cmt)).append("\n\n");
            Logger.info(this, "%s#%d/%d accepted: %s", this.issue.repo().coordinates(), this.issue.number(), comment.number(), new Printable(cmt));
        } else {
            Logger.info(this, "%s#%d/%d ignored: %s", this.issue.repo().coordinates(), this.issue.number(), comment.number(), new Printable(cmt));
        }
        seen = comment.number();
    }
    this.base.vault().save(this.key(), Optional.of(Integer.toString(seen)));
    Logger.info(this, "Seen comment set to %d for %s#%d", seen, this.issue.repo().coordinates(), this.issue.number());
    return body.toString();
}
Also used : Pattern(java.util.regex.Pattern) Comment(com.jcabi.github.Comment) Printable(io.wring.agents.Printable) Bulk(com.jcabi.github.Bulk)

Aggregations

Comment (com.jcabi.github.Comment)5 Test (org.junit.Test)4 Issue (com.jcabi.github.Issue)2 Repo (com.jcabi.github.Repo)2 Bulk (com.jcabi.github.Bulk)1 User (com.jcabi.github.User)1 Printable (io.wring.agents.Printable)1 URL (java.net.URL)1 Date (java.util.Date)1 Pattern (java.util.regex.Pattern)1