From 5bed4601612e1afa27192f0e32b552bde259ee72 Mon Sep 17 00:00:00 2001 From: yashin Date: Wed, 1 Apr 2020 21:24:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=A0=E9=99=A4?= =?UTF-8?q?=EF=BC=8C=E4=BE=BF=E6=8D=B7PR=E7=9A=84=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E8=AF=84=E8=AE=BA=E7=AC=A6=E5=90=88=E6=AD=A3?= =?UTF-8?q?=E5=88=99=E8=A6=81=E6=B1=82=E6=97=B6=E4=B9=9F=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jenkins/gitee/hook/model/NoteAction.java | 8 ++++++++ .../gitee/jenkins/gitee/hook/model/NoteHook.java | 13 ++++++++++++- .../handler/note/NoteHookTriggerHandlerImpl.java | 15 ++++++++++----- 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/gitee/jenkins/gitee/hook/model/NoteAction.java 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;