From 4b6f91c17abeb4f68d697a3e56f5cc7aad8b697a Mon Sep 17 00:00:00 2001 From: Guixian Zhang Date: Fri, 19 Feb 2021 16:41:57 +0800 Subject: [PATCH 1/2] fix: comment trigger name error --- .../com/gitee/jenkins/gitee/hook/model/NoteHook.java | 12 ++++++++++++ .../handler/note/NoteHookTriggerHandlerImpl.java | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) 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 75571a5..d625be4 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 @@ -17,6 +17,7 @@ public class NoteHook extends WebHook { private PullRequestObjectAttributes pullRequest; private NoteObjectAttributes comment; private NoteAction action; + private User sender; public NoteAction getAction() { return action; @@ -57,6 +58,14 @@ public class NoteHook extends WebHook { this.pullRequest = pullRequest; } + public User getSender() { + return sender; + } + + public void setSender(User sender) { + this.sender = sender; + } + public String getWebHookDescription() { // 兼容commit评论 if (pullRequest == null) { @@ -81,6 +90,7 @@ public class NoteHook extends WebHook { .append(project, that.project) .append(comment, that.comment) .append(pullRequest, that.pullRequest) + .append(sender, that.sender) .isEquals(); } @@ -92,6 +102,7 @@ public class NoteHook extends WebHook { .append(project) .append(comment) .append(pullRequest) + .append(sender) .toHashCode(); } @@ -103,6 +114,7 @@ public class NoteHook extends WebHook { .append("project", project) .append("comment", comment) .append("pullRequest", pullRequest) + .append("sender", sender) .toString(); } } 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 4eb48f7..2713762 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 @@ -170,7 +170,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler .withTargetNamespace(hook.getProject().getNamespace()) .withTargetRepoSshUrl(hook.getProject().getSshUrl()) .withTargetRepoHttpUrl(hook.getProject().getGitHttpUrl()) - .withTriggeredByUser(hook.getComment().getUser().getName()) + .withTriggeredByUser(hook.getSender().getName()) .withTriggerPhrase(hook.getComment().getBody()) .withSha(hook.getComment().getCommitId()) .withPathWithNamespace(hook.getProject().getPathWithNamespace()) @@ -201,7 +201,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler .withTargetNamespace(hook.getPullRequest().getTarget().getNamespace()) .withTargetRepoSshUrl(hook.getPullRequest().getTarget().getSshUrl()) .withTargetRepoHttpUrl(hook.getPullRequest().getTarget().getGitHttpUrl()) - .withTriggeredByUser(hook.getPullRequest().getHead().getUser().getName()) + .withTriggeredByUser(hook.getSender().getName()) .withLastCommit(hook.getPullRequest().getMergeCommitSha()) .withSha(hook.getPullRequest().getMergeCommitSha()) .withAfter(hook.getPullRequest().getMergeCommitSha()) From 7141908ccb86d01cf58b3c7de7619db9ab8b9d4d Mon Sep 17 00:00:00 2001 From: Guixian Zhang Date: Fri, 19 Feb 2021 17:11:38 +0800 Subject: [PATCH 2/2] fix: trigger name error --- .../com/gitee/jenkins/gitee/hook/model/NoteHook.java | 12 ------------ .../com/gitee/jenkins/gitee/hook/model/WebHook.java | 12 ++++++++++++ .../pull/PullRequestHookTriggerHandlerImpl.java | 2 +- .../handler/push/PushHookTriggerHandlerImpl.java | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) 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 d625be4..75571a5 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 @@ -17,7 +17,6 @@ public class NoteHook extends WebHook { private PullRequestObjectAttributes pullRequest; private NoteObjectAttributes comment; private NoteAction action; - private User sender; public NoteAction getAction() { return action; @@ -58,14 +57,6 @@ public class NoteHook extends WebHook { this.pullRequest = pullRequest; } - public User getSender() { - return sender; - } - - public void setSender(User sender) { - this.sender = sender; - } - public String getWebHookDescription() { // 兼容commit评论 if (pullRequest == null) { @@ -90,7 +81,6 @@ public class NoteHook extends WebHook { .append(project, that.project) .append(comment, that.comment) .append(pullRequest, that.pullRequest) - .append(sender, that.sender) .isEquals(); } @@ -102,7 +92,6 @@ public class NoteHook extends WebHook { .append(project) .append(comment) .append(pullRequest) - .append(sender) .toHashCode(); } @@ -114,7 +103,6 @@ public class NoteHook extends WebHook { .append("project", project) .append("comment", comment) .append("pullRequest", pullRequest) - .append("sender", sender) .toString(); } } diff --git a/src/main/java/com/gitee/jenkins/gitee/hook/model/WebHook.java b/src/main/java/com/gitee/jenkins/gitee/hook/model/WebHook.java index 60abcde..dd23323 100644 --- a/src/main/java/com/gitee/jenkins/gitee/hook/model/WebHook.java +++ b/src/main/java/com/gitee/jenkins/gitee/hook/model/WebHook.java @@ -14,6 +14,7 @@ public abstract class WebHook { private String objectKind; private String hookName; private String jsonBody; + private User sender; public String getJsonBody() { return this.jsonBody; } @@ -43,6 +44,14 @@ public abstract class WebHook { this.repository = repository; } + public User getSender() { + return sender; + } + + public void setSender(User sender) { + this.sender = sender; + } + public String getWebHookDescription() { return hookName; } @@ -60,6 +69,7 @@ public abstract class WebHook { .append(repository, webHook.repository) .append(objectKind, webHook.objectKind) .append(hookName, webHook.hookName) + .append(sender, webHook.sender) .isEquals(); } @@ -69,6 +79,7 @@ public abstract class WebHook { .append(repository) .append(hookName) .append(objectKind) + .append(sender) .toHashCode(); } @@ -78,6 +89,7 @@ public abstract class WebHook { .append("repository", repository) .append("hookName", hookName) .append("objectKind", objectKind) + .append("sender", sender) .toString(); } } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/pull/PullRequestHookTriggerHandlerImpl.java b/src/main/java/com/gitee/jenkins/trigger/handler/pull/PullRequestHookTriggerHandlerImpl.java index 0b0a193..285a6ff 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/pull/PullRequestHookTriggerHandlerImpl.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/pull/PullRequestHookTriggerHandlerImpl.java @@ -228,7 +228,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler .withTargetNamespace("") .withTargetRepoSshUrl("") .withTargetRepoHttpUrl("") - .withTriggeredByUser(retrievePushedBy(hook)) + .withTriggeredByUser(hook.getSender().getName()) .withBefore(hook.getBefore()) .withAfter(hook.getAfter()) .withRef(hook.getRef())