支持配置 PR 不要求必须测试时过滤触发构建
This commit is contained in:
parent
9f9721f228
commit
210df20d7a
|
@ -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. 在线安装
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
|
|||
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<Job<?, ?>> {
|
|||
return ciSkip;
|
||||
}
|
||||
|
||||
public boolean getCiSkipFroTestNotRequired() {
|
||||
return ciSkipFroTestNotRequired;
|
||||
}
|
||||
|
||||
public boolean getSkipLastCommitHasBeenBuild() {
|
||||
return skipLastCommitHasBeenBuild;
|
||||
}
|
||||
|
@ -250,6 +255,10 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
|
|||
return skipLastCommitHasBeenBuild;
|
||||
}
|
||||
|
||||
public boolean isSkipFroTestNotRequired() {
|
||||
return ciSkipFroTestNotRequired;
|
||||
}
|
||||
|
||||
public BranchFilterType getBranchFilterType() {
|
||||
return branchFilterType;
|
||||
}
|
||||
|
@ -327,6 +336,11 @@ public class GiteePushTrigger extends Trigger<Job<?, ?>> {
|
|||
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<Job<?, ?>> {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -33,9 +33,11 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
|
|||
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<NoteHook>
|
|||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -39,18 +39,20 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
|
|||
|
||||
private final Collection<State> allowedStates;
|
||||
private final boolean skipWorkInProgressPullRequest;
|
||||
private final boolean ciSkipFroTestNotRequired;
|
||||
private final Collection<Action> allowedActions;
|
||||
private final boolean cancelPendingBuildsOnUpdate;
|
||||
|
||||
PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate) {
|
||||
this(allowedStates, EnumSet.allOf(Action.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate);
|
||||
PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate, boolean ciSkipFroTestNotRequired) {
|
||||
this(allowedStates, EnumSet.allOf(Action.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate, ciSkipFroTestNotRequired);
|
||||
}
|
||||
|
||||
PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, Collection<Action> allowedActions, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate) {
|
||||
PullRequestHookTriggerHandlerImpl(Collection<State> allowedStates, Collection<Action> 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<Pu
|
|||
if (!objectAttributes.isMergeable()) {
|
||||
LOGGER.log(Level.INFO, "This pull request can not be merge");
|
||||
GiteeMessagePublisher publisher = GiteeMessagePublisher.getFromJob(job);
|
||||
if (publisher != null) {
|
||||
GiteeClient client = getClient(job);
|
||||
GiteeClient client = getClient(job);
|
||||
|
||||
if (publisher != null && client != null) {
|
||||
PullRequest pullRequest = new PullRequest(objectAttributes);
|
||||
LOGGER.log(Level.INFO, "sending message to gitee.....");
|
||||
client.createPullRequestNote(pullRequest, ":bangbang: This pull request can not be merge! The build will not be triggered. Please manual merge conflict.");
|
||||
}
|
||||
return;
|
||||
} else if (pullRequestLabelFilter.isPullRequestAllowed(labelsNames)) {
|
||||
}
|
||||
|
||||
// 若PR不需要测试,且有设定值,则跳过构建
|
||||
if ( ciSkipFroTestNotRequired && !objectAttributes.getNeedTest()) {
|
||||
LOGGER.log(Level.INFO, "Skip because this pull don't need test.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pullRequestLabelFilter.isPullRequestAllowed(labelsNames)) {
|
||||
super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
<f:entry title="${%Enable.CI.Skip}" field="ciSkip" help="/plugin/gitee/help/help-ci-skip.html">
|
||||
<f:checkbox default="true"/>
|
||||
</f:entry>
|
||||
<f:entry title="${%Enable.CI.SkipFroTestNotRequired}" field="ciSkipFroTestNotRequired" help="/plugin/gitee/help/help-ci-skip-test.html">
|
||||
<f:checkbox default="true"/>
|
||||
</f:entry>
|
||||
|
||||
<f:entry title="${%Ignore.Last.Commit.Has.Build}" field="skipLastCommitHasBeenBuild" help="/plugin/gitee/help/help-skip-last-commit.html">
|
||||
<f:checkbox default="true"/>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue