use of com.jcabi.github.Coordinates in project wring by yegor256.
the class BoCommit method text.
/**
* Collect all important texts from the issue.
* @param coords Coords
* @return Body text
* @throws IOException If fails
* @checkstyle ExecutableStatementCountCheck (100 lines)
*/
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public String text(final Coordinates coords) throws IOException {
final Iterator<JsonObject> comments = new RtPagination<>(this.commit.repo().github().entry().uri().path("repos").path(coords.user()).path(coords.repo()).path("commits").path(this.commit.sha()).path("comments").back(), object -> object).iterator();
final String self = this.commit.repo().github().users().self().login();
int seen = this.seen();
Logger.info(this, "Last seen comment in %s is #%d", this.commit.sha(), seen);
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);
final StringBuilder body = new StringBuilder();
while (comments.hasNext()) {
final JsonObject comment = comments.next();
final int number = comment.getInt("id");
if (number <= seen) {
continue;
}
final String author = comment.getJsonObject("user").getString("login");
if (author.equals(self)) {
Logger.info(this, "%s/%d ignored since you're the author", this.commit.sha(), number);
continue;
}
final String cmt = comment.getString("body");
if (ptn.matcher(cmt).matches()) {
body.append('@').append(author).append(" at [").append(comment.getString("updated_at")).append("](").append(comment.getString("html_url")).append("): ").append(StringEscapeUtils.escapeHtml4(cmt)).append("\n\n");
Logger.info(this, "%s/%d accepted: %s", this.commit.sha(), number, new Printable(cmt));
} else {
Logger.info(this, "%s/%d ignored: %s", this.commit.sha(), number, new Printable(cmt));
}
seen = number;
}
this.base.vault().save(this.key(), Optional.of(Integer.toString(seen)));
Logger.info(this, "Seen comment set to %d for %s", seen, this.commit.sha());
return body.toString();
}
use of com.jcabi.github.Coordinates in project wring by yegor256.
the class BoIssue method push.
@Override
public void push(final Events events) throws IOException {
final String body = this.text();
final Coordinates coords = this.issue.repo().coordinates();
if (body.isEmpty()) {
Logger.info(this, "%s#%d ignored", coords, this.issue.number());
} else {
events.post(String.format("[%s#%d] %s", coords, this.issue.number(), this.issue.title()), body);
Logger.info(this, "New event in %s#%d", coords, this.issue.number());
}
}
Aggregations