From 416f7ad38f420aeb24707489686e99e33448ae10 Mon Sep 17 00:00:00 2001 From: Guixian Zhang Date: Thu, 7 Jan 2021 17:11:38 +0800 Subject: [PATCH 1/3] feat: Add Ignore Pull Request conflicts option --- .../jenkins/trigger/GiteePushTrigger.java | 19 ++++++++++++++++--- .../note/NoteHookTriggerHandlerFactory.java | 4 ++-- .../note/NoteHookTriggerHandlerImpl.java | 6 ++++-- .../PullRequestHookTriggerHandlerFactory.java | 6 ++++-- .../PullRequestHookTriggerHandlerImpl.java | 10 ++++++---- .../trigger/GiteePushTrigger/config.jelly | 4 ++++ .../GiteePushTrigger/config.properties | 1 + .../GiteePushTrigger/config_zh_CN.properties | 1 + .../help-ignore-pull-request-conflicts.html | 3 +++ ...p-ignore-pull-request-conflicts_zh_CN.html | 3 +++ 10 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 src/main/webapp/help/help-ignore-pull-request-conflicts.html create mode 100644 src/main/webapp/help/help-ignore-pull-request-conflicts_zh_CN.html diff --git a/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java b/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java index 86c67ab..9117a6f 100644 --- a/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java +++ b/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java @@ -95,6 +95,7 @@ public class GiteePushTrigger extends Trigger> { private String pendingBuildName; private boolean cancelPendingBuildsOnUpdate; private boolean cancelIncompleteBuildOnSamePullRequest; + private boolean ignorePullRequestConflicts; private transient BranchFilter branchFilter; private transient PushHookTriggerHandler pushHookTriggerHandler; @@ -123,7 +124,8 @@ public class GiteePushTrigger extends Trigger> { String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex, PullRequestLabelFilterConfig pullRequestLabelFilterConfig, String secretToken, boolean triggerOnPipelineEvent, boolean triggerOnApprovedPullRequest, String pendingBuildName, boolean cancelPendingBuildsOnUpdate, - boolean cancelIncompleteBuildOnSamePullRequest) { + boolean cancelIncompleteBuildOnSamePullRequest, + boolean ignorePullRequestConflicts) { this.triggerOnPush = triggerOnPush; this.triggerOnCommitComment = triggerOnCommitComment; this.triggerOnOpenPullRequest = triggerOnOpenPullRequest; @@ -151,6 +153,7 @@ public class GiteePushTrigger extends Trigger> { this.pendingBuildName = pendingBuildName; this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate; this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest; + this.ignorePullRequestConflicts = ignorePullRequestConflicts; initializeTriggerHandler(); initializeBranchFilter(); @@ -334,6 +337,10 @@ public class GiteePushTrigger extends Trigger> { return cancelIncompleteBuildOnSamePullRequest; } + public boolean isIgnorePullRequestConflicts() { + return ignorePullRequestConflicts; + } + @DataBoundSetter public void setTriggerOnPush(boolean triggerOnPush) { this.triggerOnPush = triggerOnPush; @@ -491,6 +498,11 @@ public class GiteePushTrigger extends Trigger> { this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest; } + @DataBoundSetter + public void setIgnorePullRequestConflicts(boolean ignorePullRequestConflicts) { + this.ignorePullRequestConflicts = ignorePullRequestConflicts; + } + // executes when the Trigger receives a push request public void onPost(final PushHook hook) { if (branchFilter == null) { @@ -545,9 +557,10 @@ public class GiteePushTrigger extends Trigger> { pullRequestHookTriggerHandler = newPullRequestHookTriggerHandler(triggerOnOpenPullRequest, triggerOnUpdatePullRequest, triggerOnAcceptedPullRequest, triggerOnClosedPullRequest, skipWorkInProgressPullRequest, triggerOnApprovedPullRequest, triggerOnTestedPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired, - cancelIncompleteBuildOnSamePullRequest + cancelIncompleteBuildOnSamePullRequest, + ignorePullRequestConflicts ); - noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest); + noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest, ignorePullRequestConflicts); 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 d6560b5..63b27f3 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 triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) { + public static NoteHookTriggerHandler newNoteHookTriggerHandler(boolean triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) { if (triggerOnCommitComment || triggerOnNoteRequest) { - return new NoteHookTriggerHandlerImpl(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest); + return new NoteHookTriggerHandlerImpl(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest, ignorePullRequestConflicts); } 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 22108c0..f5945ed 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 @@ -40,13 +40,15 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler private final String noteRegex; private final boolean ciSkipFroTestNotRequired; private final boolean cancelIncompleteBuildOnSamePullRequest; + private boolean ignorePullRequestConflicts; - NoteHookTriggerHandlerImpl(boolean triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) { + NoteHookTriggerHandlerImpl(boolean triggerOnCommitComment, boolean triggerOnNoteRequest, String noteRegex, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) { this.triggerOnCommitComment = triggerOnCommitComment; this.triggerOnNoteRequest = triggerOnNoteRequest; this.noteRegex = noteRegex; this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired; this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest; + this.ignorePullRequestConflicts = ignorePullRequestConflicts; } @Override @@ -54,7 +56,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler if (isValidTrigger(hook)) { // 若pr不可自动合并则评论至pr PullRequestObjectAttributes objectAttributes = hook.getPullRequest(); - if (objectAttributes != null && !objectAttributes.isMergeable()) { + if (!ignorePullRequestConflicts && objectAttributes != null && !objectAttributes.isMergeable()) { LOGGER.log(Level.INFO, "This pull request can not be merge"); // fixme 无法获取 publisher // java.lang.ClassCastException: org.jenkinsci.plugins.workflow.job.WorkflowJob cannot be cast to hudson.model.AbstractProject 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 2a2e1d8..fd76b25 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 @@ -23,7 +23,8 @@ public final class PullRequestHookTriggerHandlerFactory { boolean triggerOnTestedPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, - boolean cancelIncompleteBuildOnSamePullRequest) { + boolean cancelIncompleteBuildOnSamePullRequest, + boolean ignorePullRequestConflicts) { if (triggerOnOpenPullRequest || !("0".equals(triggerOnUpdatePullRequest) || "false".equals(triggerOnUpdatePullRequest)) || triggerOnAcceptedPullRequest @@ -48,7 +49,8 @@ public final class PullRequestHookTriggerHandlerFactory { skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired, - cancelIncompleteBuildOnSamePullRequest); + cancelIncompleteBuildOnSamePullRequest, + ignorePullRequestConflicts); } 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 4899f89..e1ecc3d 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 @@ -48,12 +48,13 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler allowedActionDesces; private final boolean cancelPendingBuildsOnUpdate; private final boolean cancelIncompleteBuildOnSamePullRequest; + private boolean ignorePullRequestConflicts; - PullRequestHookTriggerHandlerImpl(Collection allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) { - this(allowedStates, EnumSet.allOf(Action.class), EnumSet.allOf(ActionDesc.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest); + PullRequestHookTriggerHandlerImpl(Collection allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) { + this(allowedStates, EnumSet.allOf(Action.class), EnumSet.allOf(ActionDesc.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest, ignorePullRequestConflicts); } - PullRequestHookTriggerHandlerImpl(Collection allowedStates, Collection allowedActions, Collection allowedActionDesces, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) { + PullRequestHookTriggerHandlerImpl(Collection allowedStates, Collection allowedActions, Collection allowedActionDesces, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) { this.allowedStates = allowedStates; this.allowedActions = allowedActions; this.allowedActionDesces = allowedActionDesces; @@ -61,6 +62,7 @@ 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 e447966..390c563 100644 --- a/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties +++ b/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties @@ -39,6 +39,7 @@ Exclude=Exclude Include=Include Ignore.Last.Commit.Has.Build=Ignore last commit has been build Cancel.Same.Pull.Request.Incomplete.Build=Cancel incomplete build on same Pull Requests +Ignore.Pull.Request.Conflicts=Ignore Pull Request conflicts Comments=Comment Pull Requests Comment.Regex=Comment (regex) for triggering a build Retry.Text=Jenkins please retry a build 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 b4ca987..4a1e266 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 @@ -39,6 +39,7 @@ Exclude=\u6392\u9664 Include=\u5305\u62EC Ignore.Last.Commit.Has.Build=\u8FC7\u6EE4\u5DF2\u7ECF\u6784\u5EFA\u7684 Commit \u7248\u672C Cancel.Same.Pull.Request.Incomplete.Build=\u53D6\u6D88\u76F8\u540C Pull Requests \u672A\u5B8C\u6210\u6784\u5EFA +Ignore.Pull.Request.Conflicts=\u5FFD\u7565 Pull Request \u51B2\u7A81 Comments=\u8BC4\u8BBA Pull Requests Comment.Regex=\u8BC4\u8BBA\u5185\u5BB9\u7684\u6B63\u5219\u8868\u8FBE\u5F0F Retry.Text=Jenkins please retry a build diff --git a/src/main/webapp/help/help-ignore-pull-request-conflicts.html b/src/main/webapp/help/help-ignore-pull-request-conflicts.html new file mode 100644 index 0000000..16e5345 --- /dev/null +++ b/src/main/webapp/help/help-ignore-pull-request-conflicts.html @@ -0,0 +1,3 @@ +
+ Ignore the Pull Request conflict to trigger the build +
diff --git a/src/main/webapp/help/help-ignore-pull-request-conflicts_zh_CN.html b/src/main/webapp/help/help-ignore-pull-request-conflicts_zh_CN.html new file mode 100644 index 0000000..8a5bb47 --- /dev/null +++ b/src/main/webapp/help/help-ignore-pull-request-conflicts_zh_CN.html @@ -0,0 +1,3 @@ +
+ 是否忽略 Pull Request 冲突触发构建 +
From 73ae3794a33808ab39e52d61869c166e99a84fbe Mon Sep 17 00:00:00 2001 From: silverballer <66757495@qq.com> Date: Thu, 7 Jan 2021 17:23:47 +0800 Subject: [PATCH 2/3] update README_zh_CN.md --- README_zh_CN.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README_zh_CN.md b/README_zh_CN.md index 71e7895..4f5a816 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -135,11 +135,11 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc - `[ci-build] trigger build` :commit message 或者 PR 说明包含 `[ci-build]` 时,触发构建。 3. `Ignore last commit has build` 该选项可以跳过已经构建过的 Commit 版本。 4. `Cancel incomplete build on same Pull Requests` 该选项在 PR 触发构建时,会判断是否存在相同 PR 且未完成的构建,有则取消未完成构建,再进行当前构建。 -5. `Allowed branches` 可以配置允许构建的分支,目前支持分支名和正则表达式的方式进行过滤。 -6. `Secret Token for Gitee WebHook` 该选项可以配置 WebHook 的密码,该密码需要与码云 WebHook配置的密码一致方可触发构建。 -7. 注意:若 PR 状态为不可自动合并,则不触发构建。 -![触发器配置](https://images.gitee.com/uploads/images/2020/1231/093554_e4c48be9_2102225.png "屏幕截图.png") - +5. `Ignore Pull Request conflicts` 该选项在 PR 触发构建时,会根据 PR 冲突情况选择是否进行构建。 +6. `Allowed branches` 可以配置允许构建的分支,目前支持分支名和正则表达式的方式进行过滤。 +7. `Secret Token for Gitee WebHook` 该选项可以配置 WebHook 的密码,该密码需要与码云 WebHook配置的密码一致方可触发构建。 +8. 注意:若 PR 状态为不可自动合并,则不触发构建。 +![触发器配置](https://images.gitee.com/uploads/images/2021/0107/171932_e25c8359_2102225.png "屏幕截图.png") ### 构建后步骤配置 前往任务配置的构建后配置: Configure -> Post-build Actions 选项卡 From e1da6195ce400b27ce2d3ce5682481705a9d10c7 Mon Sep 17 00:00:00 2001 From: Guixian Zhang Date: Thu, 7 Jan 2021 17:37:28 +0800 Subject: [PATCH 3/3] help update --- src/main/webapp/help/help-ignore-pull-request-conflicts.html | 4 +++- .../webapp/help/help-ignore-pull-request-conflicts_zh_CN.html | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/help/help-ignore-pull-request-conflicts.html b/src/main/webapp/help/help-ignore-pull-request-conflicts.html index 16e5345..a12af4f 100644 --- a/src/main/webapp/help/help-ignore-pull-request-conflicts.html +++ b/src/main/webapp/help/help-ignore-pull-request-conflicts.html @@ -1,3 +1,5 @@
- Ignore the Pull Request conflict to trigger the build + If this option is selected, + the build will be triggered regardless of whether the Pull Request conflicts or not, + otherwise the Pull Request conflict will not trigger the build.
diff --git a/src/main/webapp/help/help-ignore-pull-request-conflicts_zh_CN.html b/src/main/webapp/help/help-ignore-pull-request-conflicts_zh_CN.html index 8a5bb47..29d23d2 100644 --- a/src/main/webapp/help/help-ignore-pull-request-conflicts_zh_CN.html +++ b/src/main/webapp/help/help-ignore-pull-request-conflicts_zh_CN.html @@ -1,3 +1,3 @@
- 是否忽略 Pull Request 冲突触发构建 + 若勾选此选项,则无论 Pull Request 是否冲突都将触发构建,否则 Pull Request 冲突即不触发构建