!4 支持commit评论触发

* 支持commit评论触发
This commit is contained in:
silverballer 2020-12-30 16:20:58 +08:00 committed by Yashin
parent f21f90e061
commit 896007e193
6 changed files with 97 additions and 26 deletions

View File

@ -531,6 +531,11 @@ public final class CauseData {
data.getTargetProjectUrl());
}
}
}, COMMIT_COMMENT {
@Override
String getShortDescription(CauseData data) {
return Messages.GiteeWebHookCause_ShortDescription_Commit_comment(data.getTriggeredByUser());
}
}, PIPELINE {
@Override
String getShortDescription(CauseData data) {

View File

@ -58,6 +58,11 @@ public class NoteHook extends WebHook {
}
public String getWebHookDescription() {
// 兼容commit评论
if (pullRequest == null) {
return getHookName() + " commit sha = " + comment.getCommitId();
}
return getHookName() + " iid = " + pullRequest.getNumber() + " merge commit sha = " + pullRequest.getMergeCommitSha();
}

View File

@ -20,6 +20,8 @@ public class NoteObjectAttributes {
private Date createdAt;
private Date updatedAt;
private String htmlUrl;
private String commitId;
private User user;
public Integer getId() {
return id;
@ -77,6 +79,22 @@ public class NoteObjectAttributes {
this.htmlUrl = htmlUrl;
}
public String getCommitId() {
return commitId;
}
public void setCommitId(String commitId) {
this.commitId = commitId;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -87,39 +105,45 @@ public class NoteObjectAttributes {
}
NoteObjectAttributes that = (NoteObjectAttributes) o;
return new EqualsBuilder()
.append(id, that.id)
.append(body, that.body)
.append(projectId, that.projectId)
.append(authorId, that.authorId)
.append(createdAt, that.createdAt)
.append(updatedAt, that.updatedAt)
.append(htmlUrl, that.htmlUrl)
.isEquals();
.append(id, that.id)
.append(body, that.body)
.append(projectId, that.projectId)
.append(authorId, that.authorId)
.append(createdAt, that.createdAt)
.append(updatedAt, that.updatedAt)
.append(htmlUrl, that.htmlUrl)
.append(commitId, that.commitId)
.append(user, that.user)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(id)
.append(body)
.append(projectId)
.append(authorId)
.append(createdAt)
.append(updatedAt)
.append(htmlUrl)
.toHashCode();
.append(id)
.append(body)
.append(projectId)
.append(authorId)
.append(createdAt)
.append(updatedAt)
.append(htmlUrl)
.append(commitId)
.append(user)
.toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("id", id)
.append("body", body)
.append("projectId", projectId)
.append("authorId", authorId)
.append("createdAt", createdAt)
.append("updatedAt", updatedAt)
.append("htmlUrl", htmlUrl)
.toString();
.append("id", id)
.append("body", body)
.append("projectId", projectId)
.append("authorId", authorId)
.append("createdAt", createdAt)
.append("updatedAt", updatedAt)
.append("htmlUrl", htmlUrl)
.append("commitId", commitId)
.append("user", user)
.toString();
}
}

View File

@ -135,6 +135,35 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
@Override
protected CauseData retrieveCauseData(NoteHook hook) {
// 兼容来自commit的评论
if (hook.getPullRequest() == null) {
return causeData()
.withActionType(CauseData.ActionType.COMMIT_COMMENT)
.withUserName(hook.getComment().getUser().getUsername())
.withUserEmail(hook.getComment().getUser().getEmail())
.withPullRequestTitle("")
.withBranch("")
.withSourceBranch("")
.withSourceProjectId(hook.getProject().getId())
.withSourceRepoHomepage(hook.getProject().getHomepage())
.withSourceRepoName(hook.getProject().getName())
.withSourceNamespace(hook.getProject().getNamespace())
.withSourceRepoUrl(hook.getProject().getUrl())
.withSourceRepoSshUrl(hook.getProject().getSshUrl())
.withSourceRepoHttpUrl(hook.getProject().getGitHttpUrl())
.withTargetBranch("")
.withTargetProjectId(hook.getProject().getId())
.withTargetRepoName(hook.getProject().getName())
.withTargetNamespace(hook.getProject().getNamespace())
.withTargetRepoSshUrl(hook.getProject().getSshUrl())
.withTargetRepoHttpUrl(hook.getProject().getGitHttpUrl())
.withTriggeredByUser(hook.getComment().getUser().getName())
.withTriggerPhrase(hook.getComment().getBody())
.withSha(hook.getComment().getCommitId())
.withPathWithNamespace(hook.getProject().getPathWithNamespace())
.build();
}
return causeData()
.withActionType(CauseData.ActionType.NOTE)
.withSourceProjectId(hook.getPullRequest().getSourceProjectId())
@ -188,9 +217,15 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
if (hook.getPullRequest() != null
&& hook.getPullRequest().getMergeReferenceName() != null) {
return hook.getPullRequest().getMergeReferenceName();
} else {
throw new NoRevisionToBuildException();
}
// 兼容来自commit的评论
if (hook.getComment() != null
&& StringUtils.isNotBlank(hook.getComment().getCommitId())) {
return hook.getComment().getCommitId();
}
throw new NoRevisionToBuildException();
}
private boolean isValidTrigger(NoteHook hook) {

View File

@ -4,5 +4,6 @@ GiteeWebHookCause.ShortDescription.PullRequestHook_html=Triggered by <a href="{3
GiteeWebHookCause.ShortDescription.PullRequestHook_plain=Triggered by Gitee Pull Request #{0}: {1} => {2}
GiteeWebHookCause.ShortDescription.NoteHook_html=Triggered by {0} <a href="{4}/pulls/{1}" target="_blank">Gitee Pull Request #{1}</a>: {2} => {3}
GiteeWebHookCause.ShortDescription.NoteHook_plain=Triggered by {0} Gitee Pull Request #{1}: {2} => {3}
GiteeWebHookCause.ShortDescription.Commit_comment=Started by Gitee comment by {0}
GiteeWebHookCause.ShortDescription.PipelineHook_noStatus=Started by Gitee Pipeline event
GiteeWebHookCause.ShortDescription.PipelineHook=Started by Gitee Pipeline event {0}

View File

@ -4,5 +4,6 @@ GiteeWebHookCause.ShortDescription.PullRequestHook_html=\u7531 <a href="{3}/pull
GiteeWebHookCause.ShortDescription.PullRequestHook_plain=\u7531 Gitee Pull Request #{0}: {1} => {2} \u89E6\u53D1
GiteeWebHookCause.ShortDescription.NoteHook_html=\u7531 {0} <a href="{4}/pulls/{1}" target="_blank">Gitee Pull Request #{1}</a>: {2} => {3} \u89E6\u53D1
GiteeWebHookCause.ShortDescription.NoteHook_plain=\u7531 {0} Gitee Pull Request #{1}: {2} => {3} \u89E6\u53D1
GiteeWebHookCause.ShortDescription.Commit_comment=Gitee \u7528\u6237 {0} \u8BC4\u8BBA\u63D0\u4EA4\u89E6\u53D1\u6784\u5EFA
GiteeWebHookCause.ShortDescription.PipelineHook_noStatus=\u7531 Gitee Pipeline \u89E6\u53D1
GiteeWebHookCause.ShortDescription.PipelineHook=\u7531 Gitee Pipeline {0} \u89E6\u53D1