Search in sources :

Example 1 with Bulk

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

Bulk (com.jcabi.github.Bulk)1 Comment (com.jcabi.github.Comment)1 Printable (io.wring.agents.Printable)1 Pattern (java.util.regex.Pattern)1