diff --git a/README_zh_CN.md b/README_zh_CN.md index d26b040..ef1832e 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -37,14 +37,11 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc - 构建后操作可配置 PR 触发的构建成功后可自动合并对应PR。 - 对于 PR 相关的所有事件,若 PR 代码冲突不可自动合并,则不触发构建;且若配置了评论到PR的功能,则评论到 PR 提示冲突。 - PR 评论可通过 WebHook 触发构建(可用于 PR 触发构建失败是便于从码云平台评论重新触发构建) +- 支持配置 PR 不要求必须测试时过滤触发构建。(可用于不需测试则不构建部署测试环境) ## 计划中特性 1. PR 审查并测试通过触发构建(可用户触发部署,且可配合自动合并 PR 的特性完善工作流。) -2. 过滤 PR - - 支持 [ci-skip] 指令过滤 - - Gitee 新建 PR 不勾选必须测试选项,则过滤 - -3. 勾选触发方式自动添加WebHook至码云。 +2. 勾选触发方式自动添加WebHook至码云。 # 插件安装 1. 在线安装 diff --git a/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestObjectAttributes.java b/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestObjectAttributes.java index 355504f..cc78785 100644 --- a/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestObjectAttributes.java +++ b/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestObjectAttributes.java @@ -26,9 +26,11 @@ public class PullRequestObjectAttributes { private BranchData base; private String mergeStatus; private boolean mergeable; + private boolean needReview; + private boolean needTest; private String mergeCommitSha; private String mergeReferenceName; - private String url; + private String htmlUrl; private Boolean workInProgress; public Integer getId() { @@ -135,6 +137,21 @@ public class PullRequestObjectAttributes { return base.getRepo(); } + public boolean getNeedTest() { + return needTest; + } + + public void setNeedTest(boolean needTest) { + this.needTest = needTest; + } + + public boolean getNeedReview() { + return needReview; + } + + public void setNeedReview(boolean needReview) { + this.needReview = needReview; + } public String getMergeCommitSha() { return mergeCommitSha; @@ -160,12 +177,12 @@ public class PullRequestObjectAttributes { this.mergeStatus = mergeStatus; } - public String getUrl() { - return url; + public String getHtmlUrl() { + return htmlUrl; } - public void setUrl(String url) { - this.url = url; + public void setHtmlUrl(String htmlUrl) { + this.htmlUrl = htmlUrl; } public Boolean getWorkInProgress() { @@ -212,7 +229,9 @@ public class PullRequestObjectAttributes { .append(mergeReferenceName, that.mergeReferenceName) .append(mergeStatus, that.mergeStatus) .append(mergeable, that.mergeable) - .append(url, that.url) + .append(needReview, that.needReview) + .append(needTest, that.needTest) + .append(htmlUrl, that.htmlUrl) .append(workInProgress, that.workInProgress) .isEquals(); } @@ -232,9 +251,11 @@ public class PullRequestObjectAttributes { .append(base) .append(mergeStatus) .append(mergeable) + .append(needReview) + .append(needTest) .append(mergeCommitSha) .append(mergeReferenceName) - .append(url) + .append(htmlUrl) .append(workInProgress) .toHashCode(); } @@ -256,7 +277,9 @@ public class PullRequestObjectAttributes { .append("mergeReferenceName", mergeReferenceName) .append("mergeStatus", mergeStatus) .append("mergeable", mergeable) - .append("url", url) + .append("needReview", needReview) + .append("needTest", needTest) + .append("htmlUrl", htmlUrl) .append("workInProgress", workInProgress) .toString(); } diff --git a/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java b/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java index 192f8aa..c5b680e 100644 --- a/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java +++ b/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java @@ -76,6 +76,7 @@ public class GiteePushTrigger extends Trigger> { private String noteRegex = ""; private boolean ciSkip = true; private boolean skipWorkInProgressPullRequest; + private boolean ciSkipFroTestNotRequired; private boolean skipLastCommitHasBeenBuild; private boolean setBuildDescription = true; private transient boolean addNoteOnPullRequest; @@ -238,6 +239,10 @@ public class GiteePushTrigger extends Trigger> { return ciSkip; } + public boolean getCiSkipFroTestNotRequired() { + return ciSkipFroTestNotRequired; + } + public boolean getSkipLastCommitHasBeenBuild() { return skipLastCommitHasBeenBuild; } @@ -250,6 +255,10 @@ public class GiteePushTrigger extends Trigger> { return skipLastCommitHasBeenBuild; } + public boolean isSkipFroTestNotRequired() { + return ciSkipFroTestNotRequired; + } + public BranchFilterType getBranchFilterType() { return branchFilterType; } @@ -327,6 +336,11 @@ public class GiteePushTrigger extends Trigger> { this.ciSkip = ciSkip; } + @DataBoundSetter + public void setCiSkipFroTestNotRequired(boolean ciSkipFroTestNotRequired) { + this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired; + } + @DataBoundSetter public void setSkipWorkInProgressPullRequest(boolean skipWorkInProgressPullRequest) { this.skipWorkInProgressPullRequest = skipWorkInProgressPullRequest; @@ -471,8 +485,8 @@ public class GiteePushTrigger extends Trigger> { private void initializeTriggerHandler() { pullRequestHookTriggerHandler = newPullRequestHookTriggerHandler(triggerOnOpenPullRequest, triggerOnUpdatePullRequest, triggerOnAcceptedPullRequest, triggerOnClosedPullRequest, - skipWorkInProgressPullRequest, triggerOnApprovedPullRequest, triggerOnTestedPullRequest, cancelPendingBuildsOnUpdate); - noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnNoteRequest, noteRegex); + skipWorkInProgressPullRequest, triggerOnApprovedPullRequest, triggerOnTestedPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired); + noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired); pushHookTriggerHandler = newPushHookTriggerHandler(triggerOnPush, skipWorkInProgressPullRequest); pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent); } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerFactory.java b/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerFactory.java index 7d8f627..bf392dc 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerFactory.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerFactory.java @@ -7,9 +7,9 @@ public final class NoteHookTriggerHandlerFactory { private NoteHookTriggerHandlerFactory() {} - public static NoteHookTriggerHandler newNoteHookTriggerHandler(boolean triggerOnNoteRequest, String noteRegex) { + public static NoteHookTriggerHandler newNoteHookTriggerHandler(boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired) { if (triggerOnNoteRequest) { - return new NoteHookTriggerHandlerImpl(noteRegex); + return new NoteHookTriggerHandlerImpl(noteRegex, ciSkipFroTestNotRequired); } else { return new NopNoteHookTriggerHandler(); } 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 08848a7..3a63b87 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 @@ -33,9 +33,11 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler private static final Logger LOGGER = Logger.getLogger(NoteHookTriggerHandlerImpl.class.getName()); private final String noteRegex; + private final boolean ciSkipFroTestNotRequired; - NoteHookTriggerHandlerImpl(String noteRegex) { + NoteHookTriggerHandlerImpl(String noteRegex, boolean ciSkipFroTestNotRequired) { this.noteRegex = noteRegex; + this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired; } @Override @@ -54,6 +56,14 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler } return; } + + // 若PR不需要测试,且有设定值,则跳过构建 + if (objectAttributes != null && ciSkipFroTestNotRequired && !objectAttributes.getNeedTest()) { + LOGGER.log(Level.INFO, "Skip because this pull don't need test."); + return; + } + + super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter); } } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/pull/PullRequestHookTriggerHandlerFactory.java b/src/main/java/com/gitee/jenkins/trigger/handler/pull/PullRequestHookTriggerHandlerFactory.java index db1ffc8..8715a67 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/pull/PullRequestHookTriggerHandlerFactory.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/pull/PullRequestHookTriggerHandlerFactory.java @@ -20,7 +20,8 @@ public final class PullRequestHookTriggerHandlerFactory { boolean skipWorkInProgressPullRequest, boolean triggerOnApprovedPullRequest, boolean triggerOnTestedPullRequest, - boolean cancelPendingBuildsOnUpdate) { + boolean cancelPendingBuildsOnUpdate, + boolean ciSkipFroTestNotRequired) { if (triggerOnOpenPullRequest || triggerOnUpdatePullRequest || triggerOnAcceptedPullRequest @@ -42,7 +43,8 @@ public final class PullRequestHookTriggerHandlerFactory { triggerOnApprovedPullRequest, triggerOnTestedPullRequest), skipWorkInProgressPullRequest, - cancelPendingBuildsOnUpdate); + cancelPendingBuildsOnUpdate, + ciSkipFroTestNotRequired); } else { return new NopPullRequestHookTriggerHandler(); } 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 93c3e02..c538f28 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 @@ -39,18 +39,20 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler allowedStates; private final boolean skipWorkInProgressPullRequest; + private final boolean ciSkipFroTestNotRequired; private final Collection allowedActions; private final boolean cancelPendingBuildsOnUpdate; - PullRequestHookTriggerHandlerImpl(Collection allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate) { - this(allowedStates, EnumSet.allOf(Action.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate); + PullRequestHookTriggerHandlerImpl(Collection allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired) { + this(allowedStates, EnumSet.allOf(Action.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired); } - PullRequestHookTriggerHandlerImpl(Collection allowedStates, Collection allowedActions, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate) { + PullRequestHookTriggerHandlerImpl(Collection allowedStates, Collection allowedActions, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired) { this.allowedStates = allowedStates; this.allowedActions = allowedActions; this.skipWorkInProgressPullRequest = skipWorkInProgressPullRequest; this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate; + this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired; } @Override @@ -72,14 +74,23 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler + + + diff --git a/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties b/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties index b338a95..6917f8b 100644 --- a/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties +++ b/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties @@ -3,6 +3,7 @@ Generate=Generate Clear=Clear Push=Push Events Enable.CI.Skip=Enable [ci-skip] +Enable.CI.SkipFroTestNotRequired=Skip ci when test not required Enabled.Gitee.Triggers=Enabled Gitee triggers Approved.Pull.Request=Approved Pull Requests Tested.Pull.Request=Tested Pull Requests diff --git a/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config_zh_CN.properties b/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config_zh_CN.properties index 49b9ca7..686a850 100644 --- a/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config_zh_CN.properties +++ b/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config_zh_CN.properties @@ -2,7 +2,8 @@ Secret.Token=Gitee WebHook \u5BC6\u7801 Generate=\u751F\u6210 Clear=\u6E05\u9664 Push=\u63A8\u9001\u4EE3\u7801 -Enable.CI.Skip=\u652F\u6301 [ci-skip] \u6307\u4EE4 +Enable.CI.Skip=\u652F\u6301 [ci-skip] \u6307\u4EE4\u8FC7\u6EE4\u6784\u5EFA +Enable.CI.SkipFroTestNotRequired=PR \u4E0D\u8981\u6C42\u5FC5\u987B\u6D4B\u8BD5\u65F6\u8FC7\u6EE4\u6784\u5EFA Enabled.Gitee.Triggers=Gitee \u89E6\u53D1\u6784\u5EFA\u7B56\u7565 Approved.Pull.Request=\u5BA1\u67E5\u901A\u8FC7 Pull Requests Tested.Pull.Request=\u6D4B\u8BD5\u901A\u8FC7 Pull Requests