diff --git a/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteAction.java b/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteAction.java new file mode 100644 index 0000000..88d9774 --- /dev/null +++ b/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteAction.java @@ -0,0 +1,8 @@ +package com.gitee.jenkins.gitee.hook.model; + +/** + * @author Yashin Luo + */ +public enum NoteAction { + comment, edited, deleted +} diff --git a/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteHook.java b/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteHook.java index f89f690..c5288bc 100644 --- a/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteHook.java +++ b/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteHook.java @@ -16,11 +16,19 @@ public class NoteHook extends WebHook { private Project project; private PullRequestObjectAttributes pullRequest; private NoteObjectAttributes comment; + private NoteAction action; + + public NoteAction getAction() { + return action; + } + + public void setAction(NoteAction action) { + this.action = action; + } public User getUser() { return user; } - public void setUser(User user) { this.user = user; } @@ -64,6 +72,7 @@ public class NoteHook extends WebHook { NoteHook that = (NoteHook) o; return new EqualsBuilder() .append(user, that.user) + .append(action, that.action) .append(project, that.project) .append(comment, that.comment) .append(pullRequest, that.pullRequest) @@ -74,6 +83,7 @@ public class NoteHook extends WebHook { public int hashCode() { return new HashCodeBuilder(17, 37) .append(user) + .append(action) .append(project) .append(comment) .append(pullRequest) @@ -84,6 +94,7 @@ public class NoteHook extends WebHook { public String toString() { return new ToStringBuilder(this) .append("user", user) + .append("action", action) .append("project", project) .append("comment", comment) .append("pullRequest", pullRequest) diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerImpl.java b/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerImpl.java index 3a63b87..a6c2854 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerImpl.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerImpl.java @@ -3,9 +3,7 @@ package com.gitee.jenkins.trigger.handler.note; import com.gitee.jenkins.cause.CauseData; import com.gitee.jenkins.gitee.api.GiteeClient; import com.gitee.jenkins.gitee.api.model.PullRequest; -import com.gitee.jenkins.gitee.hook.model.NoteHook; -import com.gitee.jenkins.gitee.hook.model.PullRequestHook; -import com.gitee.jenkins.gitee.hook.model.PullRequestObjectAttributes; +import com.gitee.jenkins.gitee.hook.model.*; import com.gitee.jenkins.publisher.GiteeMessagePublisher; import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException; import com.gitee.jenkins.trigger.filter.BranchFilter; @@ -15,7 +13,6 @@ import hudson.model.Job; import hudson.plugins.git.GitSCM; import hudson.plugins.git.RevisionParameterAction; import org.apache.commons.lang.StringUtils; - import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -42,7 +39,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler @Override public void handle(Job job, NoteHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { - if (isValidTriggerPhrase(hook.getComment().getBody())) { + if (isValidTrigger(hook)) { // 若pr不可自动合并则评论至pr PullRequestObjectAttributes objectAttributes = hook.getPullRequest(); if (objectAttributes != null && !objectAttributes.isMergeable()) { @@ -146,6 +143,14 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler } } + private boolean isValidTrigger(NoteHook hook) { + return (isValidTriggerPhrase(hook.getComment().getBody()) && isValidTriggerAction(hook.getAction())); + } + + private boolean isValidTriggerAction(NoteAction action) { + return action == NoteAction.comment; + } + private boolean isValidTriggerPhrase(String note) { if (StringUtils.isEmpty(this.noteRegex)) { return false;