Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions src/main/java/com/rultor/agents/github/qtn/QnByArchitect.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.jcabi.aspects.Immutable;
import com.jcabi.github.Comment;
import com.jcabi.github.Issue;
import com.jcabi.github.Repo;
import com.rultor.agents.github.Answer;
import com.rultor.agents.github.Question;
Expand All @@ -25,16 +26,17 @@
* Question by architect only (if configured).
*
* @since 1.45
* @todo #1246:30min PR by ARC merge shouldn't require confirmation by ARC.
* Implement the asked in #1246. The tests have already been implemented in
* QnByArchitectTest.acceptsIfMergeArchitectPull. After resolving this
* issue, uncomment the test.
*/
@Immutable
@ToString
@EqualsAndHashCode(of = { "profile", "xpath", "origin" })
public final class QnByArchitect implements Question {

/**
* Mention prefix in command.
*/
private static final String MENTION = "^@[^\\s,:]+[\\s,:]*";

/**
* Message bundle.
*/
Expand Down Expand Up @@ -82,7 +84,10 @@ public Req understand(final Comment.Smart comment,
final String author = comment.author()
.login()
.toLowerCase(Locale.ENGLISH);
if (logins.contains(author)) {
if (
logins.contains(author)
|| QnByArchitect.isMergeByArchitectPull(comment, logins)
) {
req = this.origin.understand(comment, home);
} else if (logins.isEmpty()) {
if (QnByArchitect.allowed(comment.issue().repo(), author)) {
Expand All @@ -109,6 +114,43 @@ public Req understand(final Comment.Smart comment,
return req;
}

/**
* Is this a merge command in a pull request created by architect.
* @param comment Comment
* @param logins Configured architect logins
* @return TRUE if command can pass for non-architect
* @throws IOException If fails
*/
private static boolean isMergeByArchitectPull(final Comment.Smart comment,
final List<String> logins) throws IOException {
final Issue issue = comment.issue();
final Issue.Smart smart;
if (issue instanceof Issue.Smart) {
smart = (Issue.Smart) issue;
} else {
smart = new Issue.Smart(issue);
}
return !logins.isEmpty()
&& smart.isPull()
&& logins.contains(
smart.author().login().toLowerCase(Locale.ENGLISH)
)
&& QnByArchitect.isMerge(comment.body());
}

/**
* Is this text a merge command.
* @param body Body of comment
* @return TRUE if it starts with merge command
*/
private static boolean isMerge(final String body) {
final String text = body.trim().toLowerCase(Locale.ENGLISH);
return text.startsWith("merge")
|| text.replaceFirst(QnByArchitect.MENTION, "")
.trim()
.startsWith("merge");
}

/**
* This repository allows this author to write into it.
* @param repo The repo
Expand Down