!6 修复不同WebHook相同序号的 PR 请求,并发触发的构建被判断为相同构建取消问题

Merge pull request !6 from silverballer/ISSUE#I2BALI
This commit is contained in:
Yashin 2020-12-30 16:40:44 +08:00 committed by Gitee
commit ba9dc1aa7b
3 changed files with 22 additions and 14 deletions

View File

@ -89,16 +89,17 @@ public abstract class AbstractWebHookTriggerHandler<H extends WebHook> implement
protected abstract BuildStatusUpdate retrieveBuildStatusUpdate(H hook);
protected URIish retrieveUrIish(WebHook hook, GitSCM gitSCM) {
if (gitSCM == null) {
if (hook.getRepository() == null) {
return null;
}
List<URIish> uris = new ArrayList<URIish>();
try {
if (hook.getRepository() != null) {
uris.add(new URIish(hook.getRepository().getUrl()));
uris.add(new URIish(hook.getRepository().getGitHttpUrl()));
uris.add(new URIish(hook.getRepository().getGitSshUrl()));
if (gitSCM == null) {
return new URIish(hook.getRepository().getGitHttpUrl());
}
List<URIish> uris = new ArrayList<URIish>();
uris.add(new URIish(hook.getRepository().getUrl()));
uris.add(new URIish(hook.getRepository().getGitHttpUrl()));
uris.add(new URIish(hook.getRepository().getGitSshUrl()));
// uri 需与当前项目仓库个url一致避免触发多个构建
for (RemoteConfig remote : gitSCM.getRepositories()) {
for (URIish remoteURL : remote.getURIs()) {

View File

@ -213,9 +213,13 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
}
private String retrieveRevisionToBuild(NoteHook hook) throws NoRevisionToBuildException {
if (hook.getPullRequest() != null
&& hook.getPullRequest().getMergeReferenceName() != null) {
return hook.getPullRequest().getMergeReferenceName();
if (hook.getPullRequest() != null) {
if (hook.getPullRequest().getMergeCommitSha() != null) {
return hook.getPullRequest().getMergeCommitSha();
}
if (hook.getPullRequest().getMergeReferenceName() != null) {
return hook.getPullRequest().getMergeReferenceName();
}
}
// 兼容来自commit的评论

View File

@ -246,12 +246,15 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
}
private String retrieveRevisionToBuild(PullRequestHook hook) throws NoRevisionToBuildException {
if (hook.getPullRequest() != null
&& hook.getPullRequest().getMergeReferenceName() != null) {
return hook.getPullRequest().getMergeReferenceName();
} else {
throw new NoRevisionToBuildException();
if (hook.getPullRequest() != null) {
if (hook.getPullRequest().getMergeCommitSha() != null) {
return hook.getPullRequest().getMergeCommitSha();
}
if (hook.getPullRequest().getMergeReferenceName() != null) {
return hook.getPullRequest().getMergeReferenceName();
}
}
throw new NoRevisionToBuildException();
}
private String getTargetBranchFromBuild(Run<?, ?> mergeBuild) {