feat: Add Ignore Pull Request conflicts option
This commit is contained in:
parent
9a8855fff2
commit
416f7ad38f
|
@ -95,6 +95,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
|
||||||
private String pendingBuildName;
|
private String pendingBuildName;
|
||||||
private boolean cancelPendingBuildsOnUpdate;
|
private boolean cancelPendingBuildsOnUpdate;
|
||||||
private boolean cancelIncompleteBuildOnSamePullRequest;
|
private boolean cancelIncompleteBuildOnSamePullRequest;
|
||||||
|
private boolean ignorePullRequestConflicts;
|
||||||
|
|
||||||
private transient BranchFilter branchFilter;
|
private transient BranchFilter branchFilter;
|
||||||
private transient PushHookTriggerHandler pushHookTriggerHandler;
|
private transient PushHookTriggerHandler pushHookTriggerHandler;
|
||||||
|
@ -123,7 +124,8 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
|
||||||
String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex,
|
String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex,
|
||||||
PullRequestLabelFilterConfig pullRequestLabelFilterConfig, String secretToken, boolean triggerOnPipelineEvent,
|
PullRequestLabelFilterConfig pullRequestLabelFilterConfig, String secretToken, boolean triggerOnPipelineEvent,
|
||||||
boolean triggerOnApprovedPullRequest, String pendingBuildName, boolean cancelPendingBuildsOnUpdate,
|
boolean triggerOnApprovedPullRequest, String pendingBuildName, boolean cancelPendingBuildsOnUpdate,
|
||||||
boolean cancelIncompleteBuildOnSamePullRequest) {
|
boolean cancelIncompleteBuildOnSamePullRequest,
|
||||||
|
boolean ignorePullRequestConflicts) {
|
||||||
this.triggerOnPush = triggerOnPush;
|
this.triggerOnPush = triggerOnPush;
|
||||||
this.triggerOnCommitComment = triggerOnCommitComment;
|
this.triggerOnCommitComment = triggerOnCommitComment;
|
||||||
this.triggerOnOpenPullRequest = triggerOnOpenPullRequest;
|
this.triggerOnOpenPullRequest = triggerOnOpenPullRequest;
|
||||||
|
@ -151,6 +153,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
|
||||||
this.pendingBuildName = pendingBuildName;
|
this.pendingBuildName = pendingBuildName;
|
||||||
this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate;
|
this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate;
|
||||||
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
|
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
|
||||||
|
this.ignorePullRequestConflicts = ignorePullRequestConflicts;
|
||||||
|
|
||||||
initializeTriggerHandler();
|
initializeTriggerHandler();
|
||||||
initializeBranchFilter();
|
initializeBranchFilter();
|
||||||
|
@ -334,6 +337,10 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
|
||||||
return cancelIncompleteBuildOnSamePullRequest;
|
return cancelIncompleteBuildOnSamePullRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isIgnorePullRequestConflicts() {
|
||||||
|
return ignorePullRequestConflicts;
|
||||||
|
}
|
||||||
|
|
||||||
@DataBoundSetter
|
@DataBoundSetter
|
||||||
public void setTriggerOnPush(boolean triggerOnPush) {
|
public void setTriggerOnPush(boolean triggerOnPush) {
|
||||||
this.triggerOnPush = triggerOnPush;
|
this.triggerOnPush = triggerOnPush;
|
||||||
|
@ -491,6 +498,11 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
|
||||||
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
|
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DataBoundSetter
|
||||||
|
public void setIgnorePullRequestConflicts(boolean ignorePullRequestConflicts) {
|
||||||
|
this.ignorePullRequestConflicts = ignorePullRequestConflicts;
|
||||||
|
}
|
||||||
|
|
||||||
// executes when the Trigger receives a push request
|
// executes when the Trigger receives a push request
|
||||||
public void onPost(final PushHook hook) {
|
public void onPost(final PushHook hook) {
|
||||||
if (branchFilter == null) {
|
if (branchFilter == null) {
|
||||||
|
@ -545,9 +557,10 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
|
||||||
pullRequestHookTriggerHandler = newPullRequestHookTriggerHandler(triggerOnOpenPullRequest,
|
pullRequestHookTriggerHandler = newPullRequestHookTriggerHandler(triggerOnOpenPullRequest,
|
||||||
triggerOnUpdatePullRequest, triggerOnAcceptedPullRequest, triggerOnClosedPullRequest,
|
triggerOnUpdatePullRequest, triggerOnAcceptedPullRequest, triggerOnClosedPullRequest,
|
||||||
skipWorkInProgressPullRequest, triggerOnApprovedPullRequest, triggerOnTestedPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired,
|
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);
|
pushHookTriggerHandler = newPushHookTriggerHandler(triggerOnPush, skipWorkInProgressPullRequest);
|
||||||
pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent);
|
pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@ public final class NoteHookTriggerHandlerFactory {
|
||||||
|
|
||||||
private 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) {
|
if (triggerOnCommitComment || triggerOnNoteRequest) {
|
||||||
return new NoteHookTriggerHandlerImpl(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest);
|
return new NoteHookTriggerHandlerImpl(triggerOnCommitComment, triggerOnNoteRequest, noteRegex, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest, ignorePullRequestConflicts);
|
||||||
} else {
|
} else {
|
||||||
return new NopNoteHookTriggerHandler();
|
return new NopNoteHookTriggerHandler();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,13 +40,15 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
|
||||||
private final String noteRegex;
|
private final String noteRegex;
|
||||||
private final boolean ciSkipFroTestNotRequired;
|
private final boolean ciSkipFroTestNotRequired;
|
||||||
private final boolean cancelIncompleteBuildOnSamePullRequest;
|
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.triggerOnCommitComment = triggerOnCommitComment;
|
||||||
this.triggerOnNoteRequest = triggerOnNoteRequest;
|
this.triggerOnNoteRequest = triggerOnNoteRequest;
|
||||||
this.noteRegex = noteRegex;
|
this.noteRegex = noteRegex;
|
||||||
this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired;
|
this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired;
|
||||||
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
|
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
|
||||||
|
this.ignorePullRequestConflicts = ignorePullRequestConflicts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,7 +56,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
|
||||||
if (isValidTrigger(hook)) {
|
if (isValidTrigger(hook)) {
|
||||||
// 若pr不可自动合并则评论至pr
|
// 若pr不可自动合并则评论至pr
|
||||||
PullRequestObjectAttributes objectAttributes = hook.getPullRequest();
|
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");
|
LOGGER.log(Level.INFO, "This pull request can not be merge");
|
||||||
// fixme 无法获取 publisher
|
// fixme 无法获取 publisher
|
||||||
// java.lang.ClassCastException: org.jenkinsci.plugins.workflow.job.WorkflowJob cannot be cast to hudson.model.AbstractProject
|
// java.lang.ClassCastException: org.jenkinsci.plugins.workflow.job.WorkflowJob cannot be cast to hudson.model.AbstractProject
|
||||||
|
|
|
@ -23,7 +23,8 @@ public final class PullRequestHookTriggerHandlerFactory {
|
||||||
boolean triggerOnTestedPullRequest,
|
boolean triggerOnTestedPullRequest,
|
||||||
boolean cancelPendingBuildsOnUpdate,
|
boolean cancelPendingBuildsOnUpdate,
|
||||||
boolean ciSkipFroTestNotRequired,
|
boolean ciSkipFroTestNotRequired,
|
||||||
boolean cancelIncompleteBuildOnSamePullRequest) {
|
boolean cancelIncompleteBuildOnSamePullRequest,
|
||||||
|
boolean ignorePullRequestConflicts) {
|
||||||
if (triggerOnOpenPullRequest
|
if (triggerOnOpenPullRequest
|
||||||
|| !("0".equals(triggerOnUpdatePullRequest) || "false".equals(triggerOnUpdatePullRequest))
|
|| !("0".equals(triggerOnUpdatePullRequest) || "false".equals(triggerOnUpdatePullRequest))
|
||||||
|| triggerOnAcceptedPullRequest
|
|| triggerOnAcceptedPullRequest
|
||||||
|
@ -48,7 +49,8 @@ public final class PullRequestHookTriggerHandlerFactory {
|
||||||
skipWorkInProgressPullRequest,
|
skipWorkInProgressPullRequest,
|
||||||
cancelPendingBuildsOnUpdate,
|
cancelPendingBuildsOnUpdate,
|
||||||
ciSkipFroTestNotRequired,
|
ciSkipFroTestNotRequired,
|
||||||
cancelIncompleteBuildOnSamePullRequest);
|
cancelIncompleteBuildOnSamePullRequest,
|
||||||
|
ignorePullRequestConflicts);
|
||||||
} else {
|
} else {
|
||||||
return new NopPullRequestHookTriggerHandler();
|
return new NopPullRequestHookTriggerHandler();
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,12 +48,13 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
|
||||||
private final Collection<ActionDesc> allowedActionDesces;
|
private final Collection<ActionDesc> allowedActionDesces;
|
||||||
private final boolean cancelPendingBuildsOnUpdate;
|
private final boolean cancelPendingBuildsOnUpdate;
|
||||||
private final boolean cancelIncompleteBuildOnSamePullRequest;
|
private final boolean cancelIncompleteBuildOnSamePullRequest;
|
||||||
|
private boolean ignorePullRequestConflicts;
|
||||||
|
|
||||||
PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) {
|
PullRequestHookTriggerHandlerImpl(Collection<State> 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);
|
this(allowedStates, EnumSet.allOf(Action.class), EnumSet.allOf(ActionDesc.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired, cancelIncompleteBuildOnSamePullRequest, ignorePullRequestConflicts);
|
||||||
}
|
}
|
||||||
|
|
||||||
PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, Collection<Action> allowedActions, Collection<ActionDesc> allowedActionDesces, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest) {
|
PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, Collection<Action> allowedActions, Collection<ActionDesc> allowedActionDesces, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired, boolean cancelIncompleteBuildOnSamePullRequest, boolean ignorePullRequestConflicts) {
|
||||||
this.allowedStates = allowedStates;
|
this.allowedStates = allowedStates;
|
||||||
this.allowedActions = allowedActions;
|
this.allowedActions = allowedActions;
|
||||||
this.allowedActionDesces = allowedActionDesces;
|
this.allowedActionDesces = allowedActionDesces;
|
||||||
|
@ -61,6 +62,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
|
||||||
this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate;
|
this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate;
|
||||||
this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired;
|
this.ciSkipFroTestNotRequired = ciSkipFroTestNotRequired;
|
||||||
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
|
this.cancelIncompleteBuildOnSamePullRequest = cancelIncompleteBuildOnSamePullRequest;
|
||||||
|
this.ignorePullRequestConflicts = ignorePullRequestConflicts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,7 +81,7 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
|
||||||
}
|
}
|
||||||
|
|
||||||
// 若pr不可自动合并则评论至pr
|
// 若pr不可自动合并则评论至pr
|
||||||
if (!objectAttributes.isMergeable()) {
|
if (!ignorePullRequestConflicts && !objectAttributes.isMergeable()) {
|
||||||
LOGGER.log(Level.INFO, "This pull request can not be merge");
|
LOGGER.log(Level.INFO, "This pull request can not be merge");
|
||||||
GiteeMessagePublisher publisher = GiteeMessagePublisher.getFromJob(job);
|
GiteeMessagePublisher publisher = GiteeMessagePublisher.getFromJob(job);
|
||||||
GiteeClient client = getClient(job);
|
GiteeClient client = getClient(job);
|
||||||
|
|
|
@ -80,6 +80,10 @@
|
||||||
<f:checkbox default="false"/>
|
<f:checkbox default="false"/>
|
||||||
</f:entry>
|
</f:entry>
|
||||||
|
|
||||||
|
<f:entry title="${%Ignore.Pull.Request.Conflicts}" field="ignorePullRequestConflicts" help="/plugin/gitee/help/help-ignore-pull-request-conflicts.html">
|
||||||
|
<f:checkbox default="false"/>
|
||||||
|
</f:entry>
|
||||||
|
|
||||||
<f:entry title="${%Allowed.branches}">
|
<f:entry title="${%Allowed.branches}">
|
||||||
<table>
|
<table>
|
||||||
<!--<f:section title="">-->
|
<!--<f:section title="">-->
|
||||||
|
|
|
@ -39,6 +39,7 @@ Exclude=Exclude
|
||||||
Include=Include
|
Include=Include
|
||||||
Ignore.Last.Commit.Has.Build=Ignore last commit has been build
|
Ignore.Last.Commit.Has.Build=Ignore last commit has been build
|
||||||
Cancel.Same.Pull.Request.Incomplete.Build=Cancel incomplete build on same Pull Requests
|
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
|
Comments=Comment Pull Requests
|
||||||
Comment.Regex=Comment (regex) for triggering a build
|
Comment.Regex=Comment (regex) for triggering a build
|
||||||
Retry.Text=Jenkins please retry a build
|
Retry.Text=Jenkins please retry a build
|
||||||
|
|
|
@ -39,6 +39,7 @@ Exclude=\u6392\u9664
|
||||||
Include=\u5305\u62EC
|
Include=\u5305\u62EC
|
||||||
Ignore.Last.Commit.Has.Build=\u8FC7\u6EE4\u5DF2\u7ECF\u6784\u5EFA\u7684 Commit \u7248\u672C
|
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
|
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
|
Comments=\u8BC4\u8BBA Pull Requests
|
||||||
Comment.Regex=\u8BC4\u8BBA\u5185\u5BB9\u7684\u6B63\u5219\u8868\u8FBE\u5F0F
|
Comment.Regex=\u8BC4\u8BBA\u5185\u5BB9\u7684\u6B63\u5219\u8868\u8FBE\u5F0F
|
||||||
Retry.Text=Jenkins please retry a build
|
Retry.Text=Jenkins please retry a build
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
Ignore the Pull Request conflict to trigger the build
|
||||||
|
</div>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
是否忽略 Pull Request 冲突触发构建
|
||||||
|
</div>
|
Loading…
Reference in New Issue