!8 合并Github分支
Merge pull request !8 from silverballer/20201231-github-merge
This commit is contained in:
commit
a11c8b9201
|
@ -208,6 +208,9 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
|
|||
variables.put("giteeTargetRepoHttpUrl", targetRepoHttpUrl);
|
||||
variables.put("giteeBefore", before);
|
||||
variables.put("giteeAfter", after);
|
||||
variables.put("giteeBeforeCommitSha", before);
|
||||
variables.put("giteeAfterCommitSha", after);
|
||||
variables.put("giteeRef", ref);
|
||||
variables.put("ref", ref);
|
||||
variables.put("beforeSha", beforeSha);
|
||||
variables.put("isTag", isTag);
|
||||
|
@ -217,9 +220,12 @@ Gitee Jenkins Plugin 是码云基于 [GitLab Plugin](https://github.com/jenkinsc
|
|||
variables.put("createdAt", createdAt);
|
||||
variables.put("finishedAt", finishedAt);
|
||||
variables.put("duration", buildDuration);
|
||||
variables.put("jsonBody", jsonBody);
|
||||
variables.put("noteBody", noteBody);
|
||||
variables.putIfNotNull("giteeTriggerPhrase", triggerPhrase);
|
||||
return variables;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
# 用户支持
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -14,7 +14,7 @@
|
|||
</properties>
|
||||
|
||||
<artifactId>gitee</artifactId>
|
||||
<version>1.1.12-SNAPSHOT</version>
|
||||
<version>1.1.16-SNAPSHOT</version>
|
||||
<name>Gitee Plugin</name>
|
||||
<description>This plugin integrates Gitee to Jenkins by faking a Gitee CI Server. This plugin allows Gitee to trigger builds in Jenkins when code is committed or pull requests are opened/updated. It can also send build status back to Gitee.</description>
|
||||
<url>https://wiki.jenkins.io/display/JENKINS/Gitee+Plugin</url>
|
||||
|
|
|
@ -59,6 +59,8 @@ public final class CauseData {
|
|||
private final String createdAt;
|
||||
private final String finishedAt;
|
||||
private final String buildDuration;
|
||||
private final String jsonBody;
|
||||
private final String noteBody;
|
||||
private final boolean created;
|
||||
private final boolean deleted;
|
||||
|
||||
|
@ -70,7 +72,7 @@ public final class CauseData {
|
|||
String targetRepoSshUrl, String targetRepoHttpUrl, String triggeredByUser, String before, String after, String lastCommit,
|
||||
String targetProjectUrl, String triggerPhrase, String pullRequestState, String mergedByUser, String pullRequestAssignee,
|
||||
String ref, String isTag, String sha, String beforeSha, String status, String stages, String createdAt, String finishedAt,
|
||||
String buildDuration, String pathWithNamespace, boolean created, boolean deleted) {
|
||||
String buildDuration, String pathWithNamespace, boolean created, boolean deleted, String jsonBody, String noteBody) {
|
||||
this.actionType = checkNotNull(actionType, "actionType must not be null.");
|
||||
this.sourceProjectId = checkNotNull(sourceProjectId, "sourceProjectId must not be null.");
|
||||
this.targetProjectId = checkNotNull(targetProjectId, "targetProjectId must not be null.");
|
||||
|
@ -117,6 +119,8 @@ public final class CauseData {
|
|||
this.pathWithNamespace = pathWithNamespace;
|
||||
this.created = created;
|
||||
this.deleted = deleted;
|
||||
this.jsonBody = jsonBody;
|
||||
this.noteBody = noteBody;
|
||||
}
|
||||
|
||||
public Map<String, String> getBuildVariables() {
|
||||
|
@ -162,6 +166,8 @@ public final class CauseData {
|
|||
variables.put("createdAt", createdAt);
|
||||
variables.put("finishedAt", finishedAt);
|
||||
variables.put("duration", buildDuration);
|
||||
variables.put("jsonBody", jsonBody);
|
||||
variables.put("noteBody", noteBody);
|
||||
variables.putIfNotNull("giteeTriggerPhrase", triggerPhrase);
|
||||
return variables;
|
||||
}
|
||||
|
@ -298,6 +304,10 @@ public final class CauseData {
|
|||
|
||||
public String getBuildDuration() { return buildDuration; }
|
||||
|
||||
public String getJsonBody() { return jsonBody; }
|
||||
|
||||
public String getNoteBody() { return noteBody; }
|
||||
|
||||
|
||||
String getShortDescription() {
|
||||
return actionType.getShortDescription(this);
|
||||
|
@ -386,6 +396,8 @@ public final class CauseData {
|
|||
.append(pathWithNamespace, causeData.getPathWithNamespace())
|
||||
.append(created, causeData.getCreated())
|
||||
.append(deleted, causeData.getDeleted())
|
||||
.append(jsonBody, causeData.getJsonBody())
|
||||
.append(noteBody, causeData.getNoteBody())
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
|
@ -435,6 +447,8 @@ public final class CauseData {
|
|||
.append(pathWithNamespace)
|
||||
.append(created)
|
||||
.append(deleted)
|
||||
.append(jsonBody)
|
||||
.append(noteBody)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
|
@ -484,6 +498,8 @@ public final class CauseData {
|
|||
.append("pathWithNamespace", pathWithNamespace)
|
||||
.append("created", created)
|
||||
.append("deleted", deleted)
|
||||
.append("jsonBody", jsonBody)
|
||||
.append("noteBody", noteBody)
|
||||
.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,11 @@ public abstract class WebHook {
|
|||
private Repository repository;
|
||||
private String objectKind;
|
||||
private String hookName;
|
||||
private String jsonBody;
|
||||
|
||||
public String getJsonBody() { return this.jsonBody; }
|
||||
|
||||
public void setJsonBody(String json) { this.jsonBody = json; }
|
||||
|
||||
public String getHookName() {
|
||||
return this.hookName;
|
||||
|
|
|
@ -22,7 +22,8 @@ import org.eclipse.jgit.transport.URIish;
|
|||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -89,24 +90,19 @@ public abstract class AbstractWebHookTriggerHandler<H extends WebHook> implement
|
|||
protected abstract BuildStatusUpdate retrieveBuildStatusUpdate(H hook);
|
||||
|
||||
protected URIish retrieveUrIish(WebHook hook, GitSCM gitSCM) {
|
||||
if (hook.getRepository() == null) {
|
||||
if (hook.getRepository() == null || gitSCM == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
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()));
|
||||
Set<URIish> set = new HashSet<>();
|
||||
set.add(new URIish(hook.getRepository().getUrl()));
|
||||
set.add(new URIish(hook.getRepository().getGitHttpUrl()));
|
||||
set.add(new URIish(hook.getRepository().getGitSshUrl()));
|
||||
// uri 需与当前项目仓库个url一致,避免触发多个构建
|
||||
for (RemoteConfig remote : gitSCM.getRepositories()) {
|
||||
for (URIish remoteURL : remote.getURIs()) {
|
||||
for (URIish uri : uris) {
|
||||
if (remoteURL.equals(uri)) {
|
||||
return uri;
|
||||
}
|
||||
if (set.contains(remoteURL)) {
|
||||
return remoteURL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import hudson.model.*;
|
|||
import hudson.plugins.git.GitSCM;
|
||||
import hudson.plugins.git.RevisionParameterAction;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jgit.transport.URIish;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
|
@ -55,6 +56,10 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
|
|||
PullRequestObjectAttributes objectAttributes = hook.getPullRequest();
|
||||
if (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
|
||||
// at com.gitee.jenkins.publisher.GiteeMessagePublisher.getFromJob(GiteeMessagePublisher.java:65)
|
||||
// at com.gitee.jenkins.trigger.handler.note.NoteHookTriggerHandlerImpl.handle(NoteHookTriggerHandlerImpl.java:47)
|
||||
GiteeMessagePublisher publisher = GiteeMessagePublisher.getFromJob(job);
|
||||
GiteeClient client = getClient(job);
|
||||
if (publisher != null && client != null) {
|
||||
|
@ -202,12 +207,23 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
|
|||
.withTargetProjectUrl(hook.getPullRequest().getTarget().getUrl())
|
||||
.withTriggerPhrase(hook.getComment().getBody())
|
||||
.withPathWithNamespace(hook.getPullRequest().getBase().getRepo().getPathWithNamespace())
|
||||
.withJsonBody(hook.getJsonBody())
|
||||
.withNoteBody(hook.getComment().getBody())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RevisionParameterAction createRevisionParameter(NoteHook hook, GitSCM gitSCM) throws NoRevisionToBuildException {
|
||||
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook, gitSCM));
|
||||
// 没有配置git源码管理
|
||||
if (gitSCM == null) {
|
||||
return new RevisionParameterAction(retrieveRevisionToBuild(hook));
|
||||
}
|
||||
URIish urIish = retrieveUrIish(hook, gitSCM);
|
||||
// webhook与git源码管理仓库对不上
|
||||
if (urIish == null) {
|
||||
return new RevisionParameterAction(retrieveRevisionToBuild2(hook));
|
||||
}
|
||||
return new RevisionParameterAction(retrieveRevisionToBuild(hook), urIish);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -224,6 +240,13 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
|
|||
if (hook.getPullRequest().getMergeCommitSha() != null) {
|
||||
return hook.getPullRequest().getMergeCommitSha();
|
||||
}
|
||||
}
|
||||
|
||||
return retrieveRevisionToBuild2(hook);
|
||||
}
|
||||
|
||||
private String retrieveRevisionToBuild2(NoteHook hook) throws NoRevisionToBuildException {
|
||||
if (hook.getPullRequest() != null) {
|
||||
if (hook.getPullRequest().getMergeReferenceName() != null) {
|
||||
return hook.getPullRequest().getMergeReferenceName();
|
||||
}
|
||||
|
|
|
@ -127,6 +127,7 @@ class PipelineHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pipel
|
|||
.withCreatedAt(hook.getObjectAttributes().getCreatedAt()==null?"":hook.getObjectAttributes().getCreatedAt().toString())
|
||||
.withFinishedAt(hook.getObjectAttributes().getFinishedAt()==null?"":hook.getObjectAttributes().getFinishedAt().toString())
|
||||
.withBuildDuration(String.valueOf(hook.getObjectAttributes().getDuration()))
|
||||
.withJsonBody(hook.getJsonBody())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import hudson.model.*;
|
|||
import hudson.plugins.git.GitSCM;
|
||||
import hudson.plugins.git.RevisionParameterAction;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jgit.transport.URIish;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
|
@ -232,12 +233,22 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
|
|||
.withRef(hook.getPullRequest().getMergeReferenceName())
|
||||
.withTargetProjectUrl(hook.getPullRequest().getTarget().getUrl())
|
||||
.withPathWithNamespace(hook.getRepo().getPathWithNamespace())
|
||||
.withJsonBody(hook.getJsonBody())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RevisionParameterAction createRevisionParameter(PullRequestHook hook, GitSCM gitSCM) throws NoRevisionToBuildException {
|
||||
return new RevisionParameterAction(retrieveRevisionToBuild(hook), retrieveUrIish(hook, gitSCM));
|
||||
// 没有配置git源码管理
|
||||
if (gitSCM == null) {
|
||||
return new RevisionParameterAction(retrieveRevisionToBuild(hook));
|
||||
}
|
||||
URIish urIish = retrieveUrIish(hook, gitSCM);
|
||||
// webhook与git源码管理仓库对不上
|
||||
if (urIish == null) {
|
||||
return new RevisionParameterAction(retrieveRevisionToBuild2(hook));
|
||||
}
|
||||
return new RevisionParameterAction(retrieveRevisionToBuild(hook), urIish);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -254,6 +265,12 @@ class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<Pu
|
|||
if (hook.getPullRequest().getMergeCommitSha() != null) {
|
||||
return hook.getPullRequest().getMergeCommitSha();
|
||||
}
|
||||
}
|
||||
return retrieveRevisionToBuild2(hook);
|
||||
}
|
||||
|
||||
private String retrieveRevisionToBuild2(PullRequestHook hook) throws NoRevisionToBuildException {
|
||||
if (hook.getPullRequest() != null) {
|
||||
if (hook.getPullRequest().getMergeReferenceName() != null) {
|
||||
return hook.getPullRequest().getMergeReferenceName();
|
||||
}
|
||||
|
|
|
@ -101,6 +101,7 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
|
|||
.withCreated(hook.getCreated())
|
||||
.withDeleted(hook.getDeleted())
|
||||
.withTargetProjectUrl(hook.getProject().getUrl())
|
||||
.withJsonBody(hook.getJsonBody())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ public class NoteBuildAction extends BuildWebHookAction {
|
|||
LOGGER.log(Level.FINE, "Note: {0}", toPrettyPrint(json));
|
||||
this.project = project;
|
||||
this.noteHook = JsonUtil.read(json, NoteHook.class);
|
||||
this.noteHook.setJsonBody(json);
|
||||
this.secretToken = secretToken;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ public class PipelineBuildAction extends BuildWebHookAction {
|
|||
LOGGER.log(Level.FINE, "Pipeline event: {0}", toPrettyPrint(json));
|
||||
this.project = project;
|
||||
this.pipelineBuildHook = JsonUtil.read(json, PipelineHook.class);
|
||||
this.pipelineBuildHook.setJsonBody(json);
|
||||
this.secretToken = secretToken;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ public class PullRequestBuildAction extends BuildWebHookAction {
|
|||
LOGGER.log(Level.FINE, "PullRequest: {0}", toPrettyPrint(json));
|
||||
this.project = project;
|
||||
this.pullRequestHook = JsonUtil.read(json, PullRequestHook.class);
|
||||
this.pullRequestHook.setJsonBody(json);
|
||||
this.secretToken = secretToken;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ public class PushBuildAction extends BuildWebHookAction {
|
|||
LOGGER.log(Level.FINE, "Push: {0}", toPrettyPrint(json));
|
||||
this.project = project;
|
||||
this.pushHook = JsonUtil.read(json, PushHook.class);
|
||||
this.pushHook.setJsonBody(json);
|
||||
this.secretToken = secretToken;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue