refactor:
1、升级Jenkins Plugin Pom版本、Jenkins版本、以及其他Jenkins相关依赖版本 2、重构WebHook解析处理代码 3、替换Http客户端及建造者生成等工具类 4、删除无用代码
This commit is contained in:
parent
3dde5acd67
commit
2dcdf80ea6
344
pom.xml
344
pom.xml
|
@ -3,14 +3,20 @@
|
|||
<parent>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<version>4.15</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<jenkins.version>1.609.3</jenkins.version>
|
||||
<hpi-plugin.version>1.115</hpi-plugin.version>
|
||||
<jenkins-test-harness.version>${jenkins.version}</jenkins-test-harness.version>
|
||||
<findbugs.failOnError>false</findbugs.failOnError>
|
||||
<java.level>8</java.level>
|
||||
<jenkins.version>2.275</jenkins.version>
|
||||
<workflow-aggregator.version>2.5</workflow-aggregator.version>
|
||||
<jenkins-maven.version>3.7</jenkins-maven.version>
|
||||
<jenkins-envinject.version>2.4.0</jenkins-envinject.version>
|
||||
<lombok.version>1.18.16</lombok.version>
|
||||
<commons-lang3.version>3.11</commons-lang3.version>
|
||||
<jackson.version>2.12.0</jackson.version>
|
||||
<okhttp.version>4.9.0</okhttp.version>
|
||||
</properties>
|
||||
|
||||
<artifactId>gitee</artifactId>
|
||||
|
@ -27,6 +33,13 @@
|
|||
</license>
|
||||
</licenses>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:ssh://github.com:jenkinsci/gitee-plugin.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:jenkinsci/gitee-plugin.git</developerConnection>
|
||||
<url>https://github.com/jenkinsci/gitee-plugin</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>Yashin</id>
|
||||
|
@ -48,13 +61,130 @@
|
|||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:ssh://github.com:jenkinsci/gitee-plugin.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:jenkinsci/gitee-plugin.git</developerConnection>
|
||||
<url>https://github.com/jenkinsci/gitee-plugin</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
<!--get every artifact through repo.jenkins-ci.org, which proxies all the artifacts that we need-->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.jenkins.tools.bom</groupId>
|
||||
<artifactId>bom-2.263.x</artifactId>
|
||||
<version>20</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>structs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins.workflow</groupId>
|
||||
<artifactId>workflow-job</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>credentials</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>plain-credentials</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci</groupId>
|
||||
<artifactId>symbol-annotation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>matrix-project</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>git</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>git-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins.workflow</groupId>
|
||||
<artifactId>workflow-cps</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins.workflow</groupId>
|
||||
<artifactId>workflow-basic-steps</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins.workflow</groupId>
|
||||
<artifactId>workflow-durable-task-step</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins.workflow</groupId>
|
||||
<artifactId>workflow-aggregator</artifactId>
|
||||
<version>${workflow-aggregator.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>jackson-datatype-json-org</artifactId>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.main</groupId>
|
||||
<artifactId>maven-plugin</artifactId>
|
||||
<version>${jenkins-maven.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>envinject</artifactId>
|
||||
<version>${jenkins-envinject.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- commons-lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- okhttp -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>${okhttp.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-common</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<!--get every artifact through repo.jenkins-ci.org, which proxies all the artifacts that we need-->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo.jenkins-ci.org</id>
|
||||
|
@ -74,194 +204,4 @@
|
|||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<directory>${project.basedir}/target</directory>
|
||||
<outputDirectory>${project.build.directory}/classes</outputDirectory>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
|
||||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||
<scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>${project.basedir}/src/test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>findbugs-maven-plugin</artifactId>
|
||||
<version>3.0.4</version>
|
||||
<configuration>
|
||||
<failOnError>false</failOnError>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Jenkins dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>git</artifactId>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>git-client</artifactId>
|
||||
<version>1.19.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins.workflow</groupId>
|
||||
<artifactId>workflow-step-api</artifactId>
|
||||
<version>1.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins.workflow</groupId>
|
||||
<artifactId>workflow-job</artifactId>
|
||||
<version>1.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>credentials</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>plain-credentials</artifactId>
|
||||
<version>1.1</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci</groupId>
|
||||
<artifactId>symbol-annotation</artifactId>
|
||||
<version>1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jgit</groupId>
|
||||
<artifactId>org.eclipse.jgit</artifactId>
|
||||
<version>3.5.2.201411120430-r</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>matrix-project</artifactId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>display-url-api</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- REST client dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.spec.javax.ws.rs</groupId>
|
||||
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
|
||||
<version>1.0.0.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-client</artifactId>
|
||||
<version>3.0.16.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
<version>2.9.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.9.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- util dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>18.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.karneim</groupId>
|
||||
<artifactId>pojobuilder</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.9.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.6.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.6.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mock-server</groupId>
|
||||
<artifactId>mockserver-netty</artifactId>
|
||||
<version>3.10.2</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcmail-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>9.4.1208</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
package com.gitee.jenkins;
|
||||
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.entity.WebHookAction;
|
||||
import com.gitee.jenkins.event.GiteeEventResolver;
|
||||
import com.gitee.jenkins.handler.GiteeWebHookHandler;
|
||||
import hudson.Extension;
|
||||
import hudson.model.UnprotectedRootAction;
|
||||
import hudson.security.csrf.CrumbExclusion;
|
||||
import org.kohsuke.stapler.HttpResponses;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.kohsuke.stapler.interceptor.RequirePOST;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Receives gitee hook
|
||||
*/
|
||||
@Extension
|
||||
public class GiteeWebHook implements UnprotectedRootAction {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(GiteeWebHook.class.getName());
|
||||
|
||||
public static final String WEBHOOK_URL = "gitee-project";
|
||||
|
||||
@Override
|
||||
public String getIconFileName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlName() {
|
||||
return WEBHOOK_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives the webhook call
|
||||
*
|
||||
* @param projectName 项目名
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@RequirePOST
|
||||
public void getDynamic(String projectName, StaplerRequest request, StaplerResponse response) {
|
||||
LOGGER.log(Level.INFO, "WebHook called with url: {0}", request.getRequestURIWithQueryString());
|
||||
WebHookAction webHookAction = GiteeEventResolver.resolve(projectName, request);
|
||||
GiteeWebHookHandler.handler(webHookAction);
|
||||
response(webHookAction.getWebHook());
|
||||
}
|
||||
|
||||
public static void response(WebHook webHook) {
|
||||
throw new HttpResponses.HttpResponseException() {
|
||||
@Override
|
||||
public void generateResponse(StaplerRequest staplerRequest, StaplerResponse staplerResponse, Object o) throws IOException, ServletException {
|
||||
staplerResponse.setContentType("text/plain;charset=UTF-8");
|
||||
staplerResponse.getWriter().println(webHook.getWebHookDescription() + " has been accepted.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static class GiteeWebHookCrumbExclusion extends CrumbExclusion {
|
||||
|
||||
@Override
|
||||
public boolean process(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
String pathInfo = request.getPathInfo();
|
||||
if (pathInfo != null && pathInfo.startsWith("/" + WEBHOOK_URL + "/")) {
|
||||
chain.doFilter(request, response);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.gitee.jenkins.api;
|
||||
|
||||
import com.gitee.jenkins.entity.User;
|
||||
import com.gitee.jenkins.excetion.GiteeClientRequestException;
|
||||
|
||||
public interface GiteeApi {
|
||||
|
||||
/**
|
||||
* 合并 PR 请求
|
||||
*
|
||||
* @param owner 使用者
|
||||
* @param repo 仓库
|
||||
* @param number PR 序号
|
||||
*/
|
||||
void mergerPullRequest(String owner, String repo, Integer number) throws GiteeClientRequestException;
|
||||
|
||||
/**
|
||||
* 创建 PR 评论
|
||||
*
|
||||
* @param owner 所有者
|
||||
* @param repo 仓库
|
||||
* @param number PR 序号
|
||||
* @param body 评论内容
|
||||
*/
|
||||
void submitPullRequestComments(String owner, String repo, Integer number, String body) throws GiteeClientRequestException;
|
||||
|
||||
/**
|
||||
* 获取当前用户(返回用户数据)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
User getUser() throws GiteeClientRequestException;
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.gitee.jenkins.api.client;
|
||||
|
||||
import com.gitee.jenkins.api.GiteeApi;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Restricted(NoExternalUse.class)
|
||||
public abstract class GiteeClient implements GiteeApi {
|
||||
|
||||
/**
|
||||
* gitee服务器地址
|
||||
*/
|
||||
String hostname;
|
||||
|
||||
/**
|
||||
* access token
|
||||
*/
|
||||
String accessToken;
|
||||
|
||||
/**
|
||||
* 是否忽略证书错误
|
||||
*/
|
||||
boolean ignoreCertificateErrors;
|
||||
|
||||
/**
|
||||
* 链接超时时间
|
||||
*/
|
||||
int connectionTimeout;
|
||||
|
||||
/**
|
||||
* 读取超时时间
|
||||
*/
|
||||
int readTimeout;
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.gitee.jenkins.api.client;
|
||||
|
||||
import com.gitee.jenkins.entity.User;
|
||||
import com.gitee.jenkins.excetion.GiteeClientRequestException;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class GiteeV5Client extends HttpGiteeClient {
|
||||
|
||||
private static final String ACCESS_TOKEN_PARAM_NAME = "access_token";
|
||||
|
||||
/**
|
||||
* /api/v5/repos/{owner}/{repo}/pulls/{number}/merge
|
||||
*/
|
||||
private static final String MERGE_PULL_REQUEST_URL = "/api/v5/repos/%s/%s/pulls/%s/merge";
|
||||
/**
|
||||
* /api/v5/repos/{owner}/{repo}/pulls/{number}/comments
|
||||
*/
|
||||
private static final String SUBMIT_PULL_REQUEST_COMMENTS_URL = "/api/v5/repos/%s/%s/pulls/%s/comments";
|
||||
private static final String GET_USER_URL = "/api/v5/user";
|
||||
|
||||
public GiteeV5Client(String url, String accessToken, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
super(url, accessToken, ignoreCertificateErrors, connectionTimeout, readTimeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergerPullRequest(String owner, String repo, Integer number) throws GiteeClientRequestException {
|
||||
Map<String, String> requestParamsMap = getRequestParamsMap();
|
||||
putJson(hostname + String.format(MERGE_PULL_REQUEST_URL, owner, repo, number), requestParamsMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitPullRequestComments(String owner, String repo, Integer number, String body) throws GiteeClientRequestException {
|
||||
Map<String, String> requestParamsMap = getRequestParamsMap();
|
||||
requestParamsMap.put("body", body);
|
||||
postJson(hostname + String.format(SUBMIT_PULL_REQUEST_COMMENTS_URL, owner, repo, number), requestParamsMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() throws GiteeClientRequestException {
|
||||
return getForEntity(hostname + GET_USER_URL, getRequestParamsMap(), User.class);
|
||||
}
|
||||
|
||||
private Map<String, String> getRequestParamsMap() {
|
||||
Map<String, String> map = new HashMap<>(4);
|
||||
map.put(ACCESS_TOKEN_PARAM_NAME, accessToken);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,221 @@
|
|||
package com.gitee.jenkins.api.client;
|
||||
|
||||
import com.gitee.jenkins.excetion.GiteeClientRequestException;
|
||||
import com.gitee.jenkins.util.JsonUtil;
|
||||
import okhttp3.*;
|
||||
import okhttp3.Request.Builder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.IOException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Restricted(NoExternalUse.class)
|
||||
public abstract class HttpGiteeClient extends GiteeClient {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(HttpGiteeClient.class.getName());
|
||||
|
||||
public static final MediaType APPLICATION_JSON_UTF8 = MediaType.get("application/json; charset=utf-8");
|
||||
|
||||
private static final String CONNECTION_TIMEOUT_HEADER = "connection_timeout";
|
||||
private static final String READ_TIMEOUT_HEADER = "read_timeout";
|
||||
|
||||
/**
|
||||
* 正常http客户端
|
||||
*/
|
||||
private static final OkHttpClient SAFE_HTTP_CLIENT;
|
||||
|
||||
/**
|
||||
* 忽略证书安全的http客户端
|
||||
*/
|
||||
private static final OkHttpClient UNSAFE_HTTP_CLIENT;
|
||||
|
||||
static {
|
||||
DynamicTimeoutsInterceptor dynamicTimeoutsInterceptor = new DynamicTimeoutsInterceptor();
|
||||
// 创建正常http客户端
|
||||
SAFE_HTTP_CLIENT = new OkHttpClient.Builder()
|
||||
.addInterceptor(dynamicTimeoutsInterceptor)
|
||||
.build();
|
||||
// 创建忽略证书安全得http客户端
|
||||
UNSAFE_HTTP_CLIENT = configureToIgnoreCertificate(new OkHttpClient.Builder())
|
||||
.addInterceptor(dynamicTimeoutsInterceptor)
|
||||
.build();
|
||||
}
|
||||
|
||||
protected HttpGiteeClient(String hostname,
|
||||
String accessToken,
|
||||
boolean ignoreCertificateErrors,
|
||||
int connectionTimeout,
|
||||
int readTimeout) {
|
||||
super(hostname, accessToken, ignoreCertificateErrors, connectionTimeout, readTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* get请求,解析结果
|
||||
*
|
||||
* @param url url
|
||||
* @param params 参数
|
||||
* @param clazz 结果解析类型
|
||||
* @param <T> 结果类泛型
|
||||
* @return 请求解析结果
|
||||
* @throws Exception 请求失败
|
||||
*/
|
||||
<T> T getForEntity(String url, Map<String, String> params, Class<T> clazz) throws GiteeClientRequestException {
|
||||
try (Response response = reqGet(url, params)) {
|
||||
return JsonUtil.string2Obj(response.body().string(), clazz);
|
||||
} catch (IOException e) {
|
||||
throw new GiteeClientRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* post json请求,不解析结果
|
||||
*
|
||||
* @param url url
|
||||
* @param params 参数
|
||||
* @throws Exception 请求失败
|
||||
*/
|
||||
void postJson(String url, Map<String, String> params) throws GiteeClientRequestException {
|
||||
try (Response response = reqPostJson(url, params)) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* put json请求,不解析结果
|
||||
*
|
||||
* @param url url
|
||||
* @param params 参数
|
||||
* @throws Exception 请求失败
|
||||
*/
|
||||
void putJson(String url, Map<String, String> params) throws GiteeClientRequestException {
|
||||
try (Response response = reqPutJson(url, params)) {
|
||||
}
|
||||
}
|
||||
|
||||
private Response reqGet(String url, Map<String, String> params) throws GiteeClientRequestException {
|
||||
Request request = getRequestBuilder(url, params).build();
|
||||
return getResponse(url, request);
|
||||
}
|
||||
|
||||
private Response reqPostJson(String url, Map<String, String> params) throws GiteeClientRequestException {
|
||||
Request request = getRequestBuilder(url)
|
||||
.post(RequestBody.create(JsonUtil.obj2String(params), APPLICATION_JSON_UTF8))
|
||||
.build();
|
||||
return getResponse(url, request);
|
||||
}
|
||||
|
||||
private Response reqPutJson(String url, Map<String, String> params) throws GiteeClientRequestException {
|
||||
Request request = getRequestBuilder(url)
|
||||
.put(RequestBody.create(JsonUtil.obj2String(params), APPLICATION_JSON_UTF8))
|
||||
.build();
|
||||
return getResponse(url, request);
|
||||
}
|
||||
|
||||
private Builder getRequestBuilder(String url) {
|
||||
return getRequestBuilder(url, null);
|
||||
}
|
||||
|
||||
private Builder getRequestBuilder(String url, Map<String, String> params) {
|
||||
HttpUrl.Builder httpUrlBuilder = HttpUrl.parse(url).newBuilder();
|
||||
if (Objects.nonNull(params)) {
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
httpUrlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return new Builder()
|
||||
.url(httpUrlBuilder.build())
|
||||
.header(CONNECTION_TIMEOUT_HEADER, String.valueOf(connectionTimeout))
|
||||
.header(READ_TIMEOUT_HEADER, String.valueOf(readTimeout));
|
||||
}
|
||||
|
||||
private Response getResponse(String url, Request request) throws GiteeClientRequestException {
|
||||
try {
|
||||
Response response = getHttpClient().newCall(request).execute();
|
||||
if (!response.isSuccessful()) {
|
||||
throw new GiteeClientRequestException(String.format("request %s error: %s", url, response.body().string()));
|
||||
}
|
||||
return response;
|
||||
} catch (IOException e) {
|
||||
throw new GiteeClientRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private OkHttpClient getHttpClient() {
|
||||
return ignoreCertificateErrors ? UNSAFE_HTTP_CLIENT : SAFE_HTTP_CLIENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 忽略https错误
|
||||
*
|
||||
* @param builder
|
||||
* @return
|
||||
*/
|
||||
private static OkHttpClient.Builder configureToIgnoreCertificate(OkHttpClient.Builder builder) {
|
||||
try {
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
final TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String authType) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String authType) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[]{};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Install the all-trusting trust manager
|
||||
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
// Create an ssl socket factory with our all-trusting manager
|
||||
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
|
||||
|
||||
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0])
|
||||
.hostnameVerifier((hostname, session) -> true);
|
||||
} catch (Exception e) {
|
||||
LOGGER.log(Level.WARNING, "Exception while configuring IgnoreSslCertificate" + e, e);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态配置超时时间拦截器
|
||||
*/
|
||||
private static class DynamicTimeoutsInterceptor implements Interceptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Response intercept(@NotNull Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
int connectionTimeout = Integer.parseInt(request.header(CONNECTION_TIMEOUT_HEADER));
|
||||
int readTimeout = Integer.parseInt(request.header(READ_TIMEOUT_HEADER));
|
||||
request = request.newBuilder()
|
||||
.removeHeader(CONNECTION_TIMEOUT_HEADER)
|
||||
.removeHeader(READ_TIMEOUT_HEADER)
|
||||
.build();
|
||||
|
||||
return chain.withConnectTimeout(connectionTimeout, TimeUnit.SECONDS)
|
||||
.withReadTimeout(readTimeout, TimeUnit.SECONDS)
|
||||
.proceed(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.gitee.jenkins.api.client.factory;
|
||||
|
||||
import com.gitee.jenkins.api.client.GiteeClient;
|
||||
import com.gitee.jenkins.enums.GiteeClientType;
|
||||
import hudson.ExtensionList;
|
||||
import hudson.ExtensionPoint;
|
||||
|
||||
public interface GiteeClientFactory extends ExtensionPoint {
|
||||
|
||||
GiteeClient getGiteeClient(String hostname,
|
||||
String accessToken,
|
||||
boolean ignoreCertificateErrors,
|
||||
int connectionTimeout,
|
||||
int readTimeout);
|
||||
|
||||
GiteeClientType getGiteeClientType();
|
||||
|
||||
static GiteeClientFactory getGiteeClientFactory(GiteeClientType giteeClientType) {
|
||||
return ExtensionList.lookup(GiteeClientFactory.class).stream()
|
||||
.filter(giteeClientFactory -> giteeClientFactory.getGiteeClientType() == giteeClientType)
|
||||
.findFirst()
|
||||
.orElse(ExtensionList.lookup(GiteeClientFactory.class).get(GiteeV5ClientFactory.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.gitee.jenkins.api.client.factory;
|
||||
|
||||
import com.gitee.jenkins.api.client.GiteeClient;
|
||||
import com.gitee.jenkins.api.client.GiteeV5Client;
|
||||
import com.gitee.jenkins.enums.GiteeClientType;
|
||||
import hudson.Extension;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class GiteeV5ClientFactory implements GiteeClientFactory {
|
||||
|
||||
@Override
|
||||
public GiteeClient getGiteeClient(String hostname, String accessToken, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
return new GiteeV5Client(hostname, accessToken, ignoreCertificateErrors, connectionTimeout, readTimeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GiteeClientType getGiteeClientType() {
|
||||
return GiteeClientType.V5;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,603 +0,0 @@
|
|||
package com.gitee.jenkins.cause;
|
||||
|
||||
import com.gitee.jenkins.gitee.api.model.PullRequest;
|
||||
import hudson.markup.EscapedMarkupFormatter;
|
||||
import jenkins.model.Jenkins;
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public final class CauseData {
|
||||
private final ActionType actionType;
|
||||
private final Integer sourceProjectId;
|
||||
private final Integer targetProjectId;
|
||||
private final String branch;
|
||||
private final String pathWithNamespace;
|
||||
private final String sourceBranch;
|
||||
private final String userName;
|
||||
private final String userEmail;
|
||||
private final String sourceRepoHomepage;
|
||||
private final String sourceRepoName;
|
||||
private final String sourceNamespace;
|
||||
private final String sourceRepoUrl;
|
||||
private final String sourceRepoSshUrl;
|
||||
private final String sourceRepoHttpUrl;
|
||||
private final String pullRequestTitle;
|
||||
private final String pullRequestDescription;
|
||||
private final Integer pullRequestId;
|
||||
private final Integer pullRequestIid;
|
||||
private final String pullRequestState;
|
||||
private final String mergedByUser;
|
||||
private final String pullRequestAssignee;
|
||||
private final Integer pullRequestTargetProjectId;
|
||||
private final String targetBranch;
|
||||
private final String targetRepoName;
|
||||
private final String targetNamespace;
|
||||
private final String targetRepoSshUrl;
|
||||
private final String targetRepoHttpUrl;
|
||||
private final String triggeredByUser;
|
||||
private final String before;
|
||||
private final String after;
|
||||
private final String lastCommit;
|
||||
private final String targetProjectUrl;
|
||||
private final String triggerPhrase;
|
||||
private final String ref;
|
||||
private final String beforeSha;
|
||||
private final String isTag;
|
||||
private final String sha;
|
||||
private final String status;
|
||||
private final String stages;
|
||||
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;
|
||||
|
||||
@GeneratePojoBuilder(withFactoryMethod = "*")
|
||||
CauseData(ActionType actionType, Integer sourceProjectId, Integer targetProjectId, String branch, String sourceBranch, String userName,
|
||||
String userEmail, String sourceRepoHomepage, String sourceRepoName, String sourceNamespace, String sourceRepoUrl,
|
||||
String sourceRepoSshUrl, String sourceRepoHttpUrl, String pullRequestTitle, String pullRequestDescription, Integer pullRequestId,
|
||||
Integer pullRequestIid, Integer pullRequestTargetProjectId, String targetBranch, String targetRepoName, String targetNamespace,
|
||||
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 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.");
|
||||
this.branch = checkNotNull(branch, "branch must not be null.");
|
||||
this.sourceBranch = checkNotNull(sourceBranch, "sourceBranch must not be null.");
|
||||
this.userName = checkNotNull(userName, "userName must not be null.");
|
||||
this.userEmail = userEmail == null ? "" : userEmail;
|
||||
this.sourceRepoHomepage = sourceRepoHomepage == null ? "" : sourceRepoHomepage;
|
||||
this.sourceRepoName = checkNotNull(sourceRepoName, "sourceRepoName must not be null.");
|
||||
this.sourceNamespace = checkNotNull(sourceNamespace, "sourceNamespace must not be null.");
|
||||
this.sourceRepoUrl = sourceRepoUrl == null ? sourceRepoSshUrl : sourceRepoUrl;
|
||||
this.sourceRepoSshUrl = checkNotNull(sourceRepoSshUrl, "sourceRepoSshUrl must not be null.");
|
||||
this.sourceRepoHttpUrl = checkNotNull(sourceRepoHttpUrl, "sourceRepoHttpUrl must not be null.");
|
||||
this.pullRequestTitle = checkNotNull(pullRequestTitle, "pullRequestTitle must not be null.");
|
||||
this.pullRequestDescription = pullRequestDescription == null ? "" : pullRequestDescription;
|
||||
this.pullRequestId = pullRequestId;
|
||||
this.pullRequestIid = pullRequestIid;
|
||||
this.pullRequestState = pullRequestState == null ? "" : pullRequestState;
|
||||
this.mergedByUser = mergedByUser == null ? "" : mergedByUser;
|
||||
this.pullRequestAssignee = pullRequestAssignee == null ? "" : pullRequestAssignee;
|
||||
this.pullRequestTargetProjectId = pullRequestTargetProjectId;
|
||||
this.targetBranch = checkNotNull(targetBranch, "targetBranch must not be null.");
|
||||
this.targetRepoName = checkNotNull(targetRepoName, "targetRepoName must not be null.");
|
||||
this.targetNamespace = checkNotNull(targetNamespace, "targetNamespace must not be null.");
|
||||
this.targetRepoSshUrl = checkNotNull(targetRepoSshUrl, "targetRepoSshUrl must not be null.");
|
||||
this.targetRepoHttpUrl = checkNotNull(targetRepoHttpUrl, "targetRepoHttpUrl must not be null.");
|
||||
this.triggeredByUser = checkNotNull(triggeredByUser, "triggeredByUser must not be null.");
|
||||
this.before = before == null ? "" : before;
|
||||
this.after = after == null ? "" : after;
|
||||
// this.lastCommit = checkNotNull(lastCommit, "lastCommit must not be null");
|
||||
// 直接checkout到分支,而非commit sha,暂时不需要确保lastCommit 非空
|
||||
this.lastCommit = lastCommit;
|
||||
this.targetProjectUrl = targetProjectUrl;
|
||||
this.triggerPhrase = triggerPhrase;
|
||||
this.ref = ref;
|
||||
this.isTag = isTag;
|
||||
this.sha = sha;
|
||||
this.beforeSha = beforeSha;
|
||||
this.status = status;
|
||||
this.stages = stages;
|
||||
this.createdAt = createdAt;
|
||||
this.finishedAt = finishedAt;
|
||||
this.buildDuration = buildDuration;
|
||||
this.pathWithNamespace = pathWithNamespace;
|
||||
this.created = created;
|
||||
this.deleted = deleted;
|
||||
this.jsonBody = jsonBody;
|
||||
this.noteBody = noteBody;
|
||||
}
|
||||
|
||||
public Map<String, String> getBuildVariables() {
|
||||
MapWrapper<String, String> variables = new MapWrapper<>(new HashMap<String, String>());
|
||||
variables.put("giteeBranch", branch);
|
||||
variables.put("giteeSourceBranch", sourceBranch);
|
||||
variables.put("giteeActionType", actionType.name());
|
||||
variables.put("giteeUserName", userName);
|
||||
variables.put("giteeUserEmail", userEmail);
|
||||
variables.put("giteeSourceRepoHomepage", sourceRepoHomepage);
|
||||
variables.put("giteeSourceRepoName", sourceRepoName);
|
||||
variables.put("giteeSourceNamespace", sourceNamespace);
|
||||
variables.put("giteeSourceRepoURL", sourceRepoUrl);
|
||||
variables.put("giteeSourceRepoSshUrl", sourceRepoSshUrl);
|
||||
variables.put("giteeSourceRepoHttpUrl", sourceRepoHttpUrl);
|
||||
variables.put("giteePullRequestTitle", pullRequestTitle);
|
||||
variables.put("giteePullRequestDescription", pullRequestDescription);
|
||||
variables.put("giteePullRequestId", pullRequestId == null ? "" : pullRequestId.toString());
|
||||
variables.put("giteePullRequestIid", pullRequestIid == null ? "" : pullRequestIid.toString());
|
||||
variables.put("giteePullRequestTargetProjectId", pullRequestTargetProjectId == null ? "" : pullRequestTargetProjectId.toString());
|
||||
variables.put("giteePullRequestLastCommit", lastCommit);
|
||||
variables.put("giteePushCreated", created ? "true" : "false");
|
||||
variables.put("giteePushDeleted", deleted ? "true" : "false");
|
||||
variables.putIfNotNull("giteePullRequestState", pullRequestState);
|
||||
variables.putIfNotNull("giteeMergedByUser", mergedByUser);
|
||||
variables.putIfNotNull("giteePullRequestAssignee", pullRequestAssignee);
|
||||
variables.put("giteeTargetBranch", targetBranch);
|
||||
variables.put("giteeTargetRepoName", targetRepoName);
|
||||
variables.put("giteeTargetNamespace", targetNamespace);
|
||||
variables.put("giteeTargetRepoSshUrl", targetRepoSshUrl);
|
||||
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);
|
||||
variables.put("sha", sha);
|
||||
variables.put("status", status);
|
||||
variables.put("stages", stages);
|
||||
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;
|
||||
}
|
||||
|
||||
public Integer getSourceProjectId() {
|
||||
return sourceProjectId;
|
||||
}
|
||||
|
||||
public Integer getTargetProjectId() {
|
||||
return targetProjectId;
|
||||
}
|
||||
|
||||
public String getBranch() {
|
||||
return branch;
|
||||
}
|
||||
|
||||
public String getSourceBranch() {
|
||||
return sourceBranch;
|
||||
}
|
||||
|
||||
public ActionType getActionType() {
|
||||
return actionType;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public String getUserEmail() {
|
||||
return userEmail;
|
||||
}
|
||||
|
||||
public String getSourceRepoHomepage() {
|
||||
return sourceRepoHomepage;
|
||||
}
|
||||
|
||||
public String getSourceRepoName() {
|
||||
return sourceRepoName;
|
||||
}
|
||||
|
||||
public String getSourceNamespace() {
|
||||
return sourceNamespace;
|
||||
}
|
||||
|
||||
public String getSourceRepoUrl() {
|
||||
return sourceRepoUrl;
|
||||
}
|
||||
|
||||
public String getSourceRepoSshUrl() {
|
||||
return sourceRepoSshUrl;
|
||||
}
|
||||
|
||||
public String getSourceRepoHttpUrl() {
|
||||
return sourceRepoHttpUrl;
|
||||
}
|
||||
|
||||
public String getPullRequestTitle() {
|
||||
return pullRequestTitle;
|
||||
}
|
||||
|
||||
public String getPullRequestDescription() {
|
||||
return pullRequestDescription;
|
||||
}
|
||||
|
||||
public String getPathWithNamespace() { return pathWithNamespace; }
|
||||
|
||||
public Integer getPullRequestId() {
|
||||
return pullRequestId;
|
||||
}
|
||||
|
||||
public Integer getPullRequestIid() {
|
||||
return pullRequestIid;
|
||||
}
|
||||
|
||||
public Integer getPullRequestTargetProjectId() {
|
||||
return pullRequestTargetProjectId;
|
||||
}
|
||||
|
||||
public String getTargetBranch() {
|
||||
return targetBranch;
|
||||
}
|
||||
|
||||
public String getTargetRepoName() {
|
||||
return targetRepoName;
|
||||
}
|
||||
|
||||
public String getTargetNamespace() {
|
||||
return targetNamespace;
|
||||
}
|
||||
|
||||
public String getTargetRepoSshUrl() {
|
||||
return targetRepoSshUrl;
|
||||
}
|
||||
|
||||
public String getTargetRepoHttpUrl() {
|
||||
return targetRepoHttpUrl;
|
||||
}
|
||||
|
||||
public String getTriggeredByUser() {
|
||||
return triggeredByUser;
|
||||
}
|
||||
|
||||
public String getBefore() {
|
||||
return before;
|
||||
}
|
||||
|
||||
public String getAfter() {
|
||||
return after;
|
||||
}
|
||||
|
||||
public String getLastCommit() {
|
||||
return lastCommit;
|
||||
}
|
||||
|
||||
public String getTargetProjectUrl() {
|
||||
return targetProjectUrl;
|
||||
}
|
||||
|
||||
public String getRef() { return ref; }
|
||||
|
||||
public String getIsTag() { return isTag; }
|
||||
|
||||
public String getSha() { return sha; }
|
||||
|
||||
public String getBeforeSha() {return beforeSha; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
|
||||
public String getStages() { return stages; }
|
||||
|
||||
public String getCreatedAt() { return createdAt; }
|
||||
|
||||
public String getFinishedAt() { return finishedAt; }
|
||||
|
||||
public String getBuildDuration() { return buildDuration; }
|
||||
|
||||
public String getJsonBody() { return jsonBody; }
|
||||
|
||||
public String getNoteBody() { return noteBody; }
|
||||
|
||||
|
||||
String getShortDescription() {
|
||||
return actionType.getShortDescription(this);
|
||||
}
|
||||
|
||||
public String getPullRequestState() {
|
||||
return pullRequestState;
|
||||
}
|
||||
|
||||
public String getMergedByUser() {
|
||||
return mergedByUser;
|
||||
}
|
||||
|
||||
public String getPullRequestAssignee() {
|
||||
return pullRequestAssignee;
|
||||
}
|
||||
|
||||
|
||||
public boolean getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public boolean getDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public PullRequest getPullRequest() {
|
||||
if (pullRequestId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PullRequest(pullRequestId, pullRequestIid, sourceBranch, targetBranch, pullRequestTitle,
|
||||
sourceProjectId, targetProjectId, pullRequestDescription, pullRequestState, pathWithNamespace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
CauseData causeData = (CauseData) o;
|
||||
return new EqualsBuilder()
|
||||
.append(actionType, causeData.actionType)
|
||||
.append(sourceProjectId, causeData.sourceProjectId)
|
||||
.append(targetProjectId, causeData.targetProjectId)
|
||||
.append(branch, causeData.branch)
|
||||
.append(sourceBranch, causeData.sourceBranch)
|
||||
.append(userName, causeData.userName)
|
||||
.append(userEmail, causeData.userEmail)
|
||||
.append(sourceRepoHomepage, causeData.sourceRepoHomepage)
|
||||
.append(sourceRepoName, causeData.sourceRepoName)
|
||||
.append(sourceNamespace, causeData.sourceNamespace)
|
||||
.append(sourceRepoUrl, causeData.sourceRepoUrl)
|
||||
.append(sourceRepoSshUrl, causeData.sourceRepoSshUrl)
|
||||
.append(sourceRepoHttpUrl, causeData.sourceRepoHttpUrl)
|
||||
.append(pullRequestTitle, causeData.pullRequestTitle)
|
||||
.append(pullRequestDescription, causeData.pullRequestDescription)
|
||||
.append(pullRequestId, causeData.pullRequestId)
|
||||
.append(pullRequestIid, causeData.pullRequestIid)
|
||||
.append(pullRequestState, causeData.pullRequestState)
|
||||
.append(mergedByUser, causeData.mergedByUser)
|
||||
.append(pullRequestAssignee, causeData.pullRequestAssignee)
|
||||
.append(pullRequestTargetProjectId, causeData.pullRequestTargetProjectId)
|
||||
.append(targetBranch, causeData.targetBranch)
|
||||
.append(targetRepoName, causeData.targetRepoName)
|
||||
.append(targetNamespace, causeData.targetNamespace)
|
||||
.append(targetRepoSshUrl, causeData.targetRepoSshUrl)
|
||||
.append(targetRepoHttpUrl, causeData.targetRepoHttpUrl)
|
||||
.append(triggeredByUser, causeData.triggeredByUser)
|
||||
.append(before, causeData.before)
|
||||
.append(after, causeData.after)
|
||||
.append(lastCommit, causeData.lastCommit)
|
||||
.append(targetProjectUrl, causeData.targetProjectUrl)
|
||||
.append(ref, causeData.getRef())
|
||||
.append(isTag, causeData.getIsTag())
|
||||
.append(sha, causeData.getSha())
|
||||
.append(beforeSha, causeData.getBeforeSha())
|
||||
.append(status, causeData.getStatus())
|
||||
.append(stages, causeData.getStages())
|
||||
.append(createdAt, causeData.getCreatedAt())
|
||||
.append(finishedAt, causeData.getFinishedAt())
|
||||
.append(buildDuration, causeData.getBuildDuration())
|
||||
.append(pathWithNamespace, causeData.getPathWithNamespace())
|
||||
.append(created, causeData.getCreated())
|
||||
.append(deleted, causeData.getDeleted())
|
||||
.append(jsonBody, causeData.getJsonBody())
|
||||
.append(noteBody, causeData.getNoteBody())
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(actionType)
|
||||
.append(sourceProjectId)
|
||||
.append(targetProjectId)
|
||||
.append(branch)
|
||||
.append(sourceBranch)
|
||||
.append(userName)
|
||||
.append(userEmail)
|
||||
.append(sourceRepoHomepage)
|
||||
.append(sourceRepoName)
|
||||
.append(sourceNamespace)
|
||||
.append(sourceRepoUrl)
|
||||
.append(sourceRepoSshUrl)
|
||||
.append(sourceRepoHttpUrl)
|
||||
.append(pullRequestTitle)
|
||||
.append(pullRequestDescription)
|
||||
.append(pullRequestId)
|
||||
.append(pullRequestIid)
|
||||
.append(pullRequestState)
|
||||
.append(mergedByUser)
|
||||
.append(pullRequestAssignee)
|
||||
.append(pullRequestTargetProjectId)
|
||||
.append(targetBranch)
|
||||
.append(targetRepoName)
|
||||
.append(targetNamespace)
|
||||
.append(targetRepoSshUrl)
|
||||
.append(targetRepoHttpUrl)
|
||||
.append(triggeredByUser)
|
||||
.append(before)
|
||||
.append(after)
|
||||
.append(lastCommit)
|
||||
.append(targetProjectUrl)
|
||||
.append(ref)
|
||||
.append(isTag)
|
||||
.append(sha)
|
||||
.append(beforeSha)
|
||||
.append(status)
|
||||
.append(stages)
|
||||
.append(createdAt)
|
||||
.append(finishedAt)
|
||||
.append(buildDuration)
|
||||
.append(pathWithNamespace)
|
||||
.append(created)
|
||||
.append(deleted)
|
||||
.append(jsonBody)
|
||||
.append(noteBody)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("actionType", actionType)
|
||||
.append("sourceProjectId", sourceProjectId)
|
||||
.append("targetProjectId", targetProjectId)
|
||||
.append("branch", branch)
|
||||
.append("sourceBranch", sourceBranch)
|
||||
.append("userName", userName)
|
||||
.append("userEmail", userEmail)
|
||||
.append("sourceRepoHomepage", sourceRepoHomepage)
|
||||
.append("sourceRepoName", sourceRepoName)
|
||||
.append("sourceNamespace", sourceNamespace)
|
||||
.append("sourceRepoUrl", sourceRepoUrl)
|
||||
.append("sourceRepoSshUrl", sourceRepoSshUrl)
|
||||
.append("sourceRepoHttpUrl", sourceRepoHttpUrl)
|
||||
.append("pullRequestTitle", pullRequestTitle)
|
||||
.append("pullRequestDescription", pullRequestDescription)
|
||||
.append("pullRequestId", pullRequestId)
|
||||
.append("pullRequestIid", pullRequestIid)
|
||||
.append("pullRequestState", pullRequestState)
|
||||
.append("mergedByUser", mergedByUser)
|
||||
.append("pullRequestAssignee", pullRequestAssignee)
|
||||
.append("pullRequestTargetProjectId", pullRequestTargetProjectId)
|
||||
.append("targetBranch", targetBranch)
|
||||
.append("targetRepoName", targetRepoName)
|
||||
.append("targetNamespace", targetNamespace)
|
||||
.append("targetRepoSshUrl", targetRepoSshUrl)
|
||||
.append("targetRepoHttpUrl", targetRepoHttpUrl)
|
||||
.append("triggeredByUser", triggeredByUser)
|
||||
.append("before", before)
|
||||
.append("after", after)
|
||||
.append("lastCommit", lastCommit)
|
||||
.append("targetProjectUrl", targetProjectUrl)
|
||||
.append("ref", ref)
|
||||
.append("isTag", isTag)
|
||||
.append("sha", sha)
|
||||
.append("beforeSha", beforeSha)
|
||||
.append("status", status)
|
||||
.append("stages", stages)
|
||||
.append("createdAt", createdAt)
|
||||
.append("finishedAt", finishedAt)
|
||||
.append("duration", buildDuration)
|
||||
.append("pathWithNamespace", pathWithNamespace)
|
||||
.append("created", created)
|
||||
.append("deleted", deleted)
|
||||
.append("jsonBody", jsonBody)
|
||||
.append("noteBody", noteBody)
|
||||
.toString();
|
||||
}
|
||||
|
||||
public enum ActionType {
|
||||
PUSH {
|
||||
@Override
|
||||
String getShortDescription(CauseData data) {
|
||||
return getShortDescriptionPush(data);
|
||||
}
|
||||
}, TAG_PUSH {
|
||||
@Override
|
||||
String getShortDescription(CauseData data) {
|
||||
return getShortDescriptionPush(data);
|
||||
}
|
||||
}, MERGE {
|
||||
@Override
|
||||
String getShortDescription(CauseData data) {
|
||||
String forkNamespace = StringUtils.equals(data.getSourceNamespace(), data.getTargetBranch()) ? "" : data.getSourceNamespace() + "/";
|
||||
if (Jenkins.getActiveInstance().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PullRequestHook_plain(String.valueOf(data.getPullRequestIid()),
|
||||
forkNamespace + data.getSourceBranch(),
|
||||
data.getTargetBranch());
|
||||
} else {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PullRequestHook_html(String.valueOf(data.getPullRequestIid()),
|
||||
forkNamespace + data.getSourceBranch(),
|
||||
data.getTargetBranch(),
|
||||
data.getTargetProjectUrl());
|
||||
}
|
||||
}
|
||||
}, NOTE {
|
||||
@Override
|
||||
String getShortDescription(CauseData data) {
|
||||
String triggeredBy = data.getTriggeredByUser();
|
||||
String forkNamespace = StringUtils.equals(data.getSourceNamespace(), data.getTargetBranch()) ? "" : data.getSourceNamespace() + "/";
|
||||
if (Jenkins.getActiveInstance().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_NoteHook_plain(triggeredBy,
|
||||
String.valueOf(data.getPullRequestIid()),
|
||||
forkNamespace + data.getSourceBranch(),
|
||||
data.getTargetBranch());
|
||||
} else {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_NoteHook_html(triggeredBy,
|
||||
String.valueOf(data.getPullRequestIid()),
|
||||
forkNamespace + data.getSourceBranch(),
|
||||
data.getTargetBranch(),
|
||||
data.getTargetProjectUrl());
|
||||
}
|
||||
}
|
||||
}, COMMIT_COMMENT {
|
||||
@Override
|
||||
String getShortDescription(CauseData data) {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_Commit_comment(data.getTriggeredByUser());
|
||||
}
|
||||
}, PIPELINE {
|
||||
@Override
|
||||
String getShortDescription(CauseData data) {
|
||||
String getStatus = data.getStatus();
|
||||
if (getStatus == null) {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PipelineHook_noStatus();
|
||||
} else {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PipelineHook(getStatus);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static String getShortDescriptionPush(CauseData data) {
|
||||
String pushedBy = data.getTriggeredByUser();
|
||||
if (pushedBy == null) {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PushHook_noUser();
|
||||
} else {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PushHook(pushedBy);
|
||||
}
|
||||
}
|
||||
|
||||
abstract String getShortDescription(CauseData data);
|
||||
}
|
||||
|
||||
private static class MapWrapper<K, V> extends AbstractMap<K, V> {
|
||||
|
||||
private final Map<K, V> map;
|
||||
|
||||
MapWrapper(Map<K, V> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
return map.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
return map.entrySet();
|
||||
}
|
||||
|
||||
void putIfNotNull(K key, V value) {
|
||||
if (value != null) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +1,20 @@
|
|||
package com.gitee.jenkins.cause;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import hudson.triggers.SCMTrigger;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
* @author Yashin
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
public class GiteeWebHookCause extends SCMTrigger.SCMTriggerCause {
|
||||
|
||||
private final CauseData data;
|
||||
private final GiteeWebHookCauseData data;
|
||||
|
||||
public GiteeWebHookCause(CauseData data) {
|
||||
public GiteeWebHookCause(GiteeWebHookCauseData giteeWebHookCauseData) {
|
||||
super("");
|
||||
this.data = checkNotNull(data, "data must not be null");
|
||||
this.data = Preconditions.checkNotNull(giteeWebHookCauseData, "data must not be null");
|
||||
}
|
||||
|
||||
public CauseData getData() {
|
||||
public GiteeWebHookCauseData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -25,4 +22,5 @@ public class GiteeWebHookCause extends SCMTrigger.SCMTriggerCause {
|
|||
public String getShortDescription() {
|
||||
return data.getShortDescription();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,210 @@
|
|||
package com.gitee.jenkins.cause;
|
||||
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.google.common.base.Preconditions;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
public class GiteeWebHookCauseData {
|
||||
|
||||
private WebHookType webHookType;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String userEmail;
|
||||
|
||||
private Integer sourceProjectId;
|
||||
|
||||
private Integer targetProjectId;
|
||||
|
||||
private String pathWithNamespace;
|
||||
|
||||
private String branch;
|
||||
|
||||
private String sourceBranch;
|
||||
|
||||
private String sourceRepoHomepage;
|
||||
|
||||
private String sourceRepoName;
|
||||
|
||||
private String sourceNamespace;
|
||||
|
||||
private String sourceRepoUrl;
|
||||
|
||||
private String sourceRepoSshUrl;
|
||||
|
||||
private String sourceRepoHttpUrl;
|
||||
|
||||
private String targetBranch;
|
||||
|
||||
private String targetRepoName;
|
||||
|
||||
private String targetNamespace;
|
||||
|
||||
private String targetProjectUrl;
|
||||
|
||||
private String targetRepoSshUrl;
|
||||
|
||||
private String targetRepoHttpUrl;
|
||||
|
||||
private String pullRequestTitle;
|
||||
|
||||
private String pullRequestDescription;
|
||||
|
||||
private Integer pullRequestId;
|
||||
|
||||
private Integer pullRequestIid;
|
||||
|
||||
private String pullRequestState;
|
||||
|
||||
private String mergedByUser;
|
||||
|
||||
private String pullRequestAssignee;
|
||||
|
||||
private Integer pullRequestTargetProjectId;
|
||||
|
||||
private String before;
|
||||
|
||||
private String after;
|
||||
|
||||
private String lastCommit;
|
||||
|
||||
private final String ref;
|
||||
|
||||
private final String beforeSha;
|
||||
|
||||
private final String sha;
|
||||
|
||||
private final String isTag;
|
||||
|
||||
private boolean created;
|
||||
|
||||
private boolean deleted;
|
||||
|
||||
private String status;
|
||||
|
||||
private String stages;
|
||||
|
||||
private String createdAt;
|
||||
|
||||
private String finishedAt;
|
||||
|
||||
private String buildDuration;
|
||||
|
||||
private String jsonBody;
|
||||
|
||||
private String noteBody;
|
||||
|
||||
private String triggerPhrase;
|
||||
|
||||
private String triggeredByUser;
|
||||
|
||||
@Builder
|
||||
private GiteeWebHookCauseData(WebHookType webHookType, String userName, String userEmail, Integer sourceProjectId, Integer targetProjectId, String pathWithNamespace, String branch, String sourceBranch, String sourceRepoHomepage, String sourceRepoName, String sourceNamespace, String sourceRepoUrl, String sourceRepoSshUrl, String sourceRepoHttpUrl, String targetBranch, String targetRepoName, String targetNamespace, String targetProjectUrl, String targetRepoSshUrl, String targetRepoHttpUrl, String pullRequestTitle, String pullRequestDescription, Integer pullRequestId, Integer pullRequestIid, String pullRequestState, String mergedByUser, String pullRequestAssignee, Integer pullRequestTargetProjectId, String before, String after, String lastCommit, String ref, String beforeSha, String sha, String isTag, boolean created, boolean deleted, String status, String stages, String createdAt, String finishedAt, String buildDuration, String jsonBody, String noteBody, String triggerPhrase, String triggeredByUser) {
|
||||
this.webHookType = Preconditions.checkNotNull(webHookType, "actionType must not be null.");
|
||||
this.userName = Preconditions.checkNotNull(userName, "userName must not be null.");
|
||||
this.userEmail = Optional.ofNullable(userEmail).orElse("");
|
||||
this.sourceProjectId = Preconditions.checkNotNull(sourceProjectId, "sourceProjectId must not be null.");
|
||||
this.targetProjectId = Preconditions.checkNotNull(targetProjectId, "targetProjectId must not be null.");
|
||||
this.pathWithNamespace = pathWithNamespace;
|
||||
this.branch = Preconditions.checkNotNull(branch, "branch must not be null.");
|
||||
this.sourceBranch = Preconditions.checkNotNull(sourceBranch, "sourceBranch must not be null.");
|
||||
this.sourceRepoHomepage = Optional.ofNullable(sourceRepoHomepage).orElse("");
|
||||
this.sourceRepoName = Preconditions.checkNotNull(sourceRepoName, "sourceRepoName must not be null.");
|
||||
this.sourceNamespace = Preconditions.checkNotNull(sourceNamespace, "sourceNamespace must not be null.");
|
||||
this.sourceRepoUrl = Optional.ofNullable(sourceRepoUrl).orElse(sourceRepoSshUrl);
|
||||
this.sourceRepoSshUrl = Preconditions.checkNotNull(sourceRepoSshUrl, "sourceRepoSshUrl must not be null.");
|
||||
this.sourceRepoHttpUrl = Preconditions.checkNotNull(sourceRepoHttpUrl, "sourceRepoHttpUrl must not be null.");
|
||||
this.targetBranch = Preconditions.checkNotNull(targetBranch, "targetBranch must not be null.");
|
||||
this.targetRepoName = Preconditions.checkNotNull(targetRepoName, "targetRepoName must not be null.");
|
||||
this.targetNamespace = Preconditions.checkNotNull(targetNamespace, "targetNamespace must not be null.");
|
||||
this.targetProjectUrl = targetProjectUrl;
|
||||
this.targetRepoSshUrl = Preconditions.checkNotNull(targetRepoSshUrl, "targetRepoSshUrl must not be null.");
|
||||
this.targetRepoHttpUrl = Preconditions.checkNotNull(targetRepoHttpUrl, "targetRepoHttpUrl must not be null.");
|
||||
this.pullRequestTitle = Preconditions.checkNotNull(pullRequestTitle, "pullRequestTitle must not be null.");
|
||||
this.pullRequestDescription = Optional.ofNullable(pullRequestDescription).orElse("");
|
||||
this.pullRequestId = pullRequestId;
|
||||
this.pullRequestIid = pullRequestIid;
|
||||
this.pullRequestState = Optional.ofNullable(pullRequestState).orElse("");
|
||||
this.mergedByUser = Optional.ofNullable(mergedByUser).orElse("");
|
||||
this.pullRequestAssignee = Optional.ofNullable(pullRequestAssignee).orElse("");
|
||||
this.pullRequestTargetProjectId = pullRequestTargetProjectId;
|
||||
this.before = Optional.ofNullable(before).orElse("");
|
||||
this.after = Optional.ofNullable(after).orElse("");
|
||||
this.lastCommit = lastCommit;
|
||||
this.ref = ref;
|
||||
this.beforeSha = beforeSha;
|
||||
this.sha = sha;
|
||||
this.isTag = isTag;
|
||||
this.created = created;
|
||||
this.deleted = deleted;
|
||||
this.status = status;
|
||||
this.stages = stages;
|
||||
this.createdAt = createdAt;
|
||||
this.finishedAt = finishedAt;
|
||||
this.buildDuration = buildDuration;
|
||||
this.jsonBody = jsonBody;
|
||||
this.noteBody = noteBody;
|
||||
this.triggerPhrase = triggerPhrase;
|
||||
this.triggeredByUser = Preconditions.checkNotNull(triggeredByUser, "triggeredByUser must not be null.");
|
||||
}
|
||||
|
||||
public Map<String, String> getBuildEnvironmentVariables() {
|
||||
Map<String, String> map = new HashMap<>(64);
|
||||
map.put("giteeActionType", webHookType.name());
|
||||
map.put("giteeUserName", userName);
|
||||
map.put("giteeUserEmail", userEmail);
|
||||
map.put("giteeBranch", branch);
|
||||
map.put("giteeSourceBranch", sourceBranch);
|
||||
map.put("giteeSourceRepoHomepage", sourceRepoHomepage);
|
||||
map.put("giteeSourceRepoName", sourceRepoName);
|
||||
map.put("giteeSourceNamespace", sourceNamespace);
|
||||
map.put("giteeSourceRepoURL", sourceRepoUrl);
|
||||
map.put("giteeSourceRepoSshUrl", sourceRepoSshUrl);
|
||||
map.put("giteeSourceRepoHttpUrl", sourceRepoHttpUrl);
|
||||
map.put("giteeTargetBranch", targetBranch);
|
||||
map.put("giteeTargetRepoName", targetRepoName);
|
||||
map.put("giteeTargetNamespace", targetNamespace);
|
||||
map.put("giteeTargetRepoSshUrl", targetRepoSshUrl);
|
||||
map.put("giteeTargetRepoHttpUrl", targetRepoHttpUrl);
|
||||
map.put("giteePullRequestTitle", pullRequestTitle);
|
||||
map.put("giteePullRequestDescription", pullRequestDescription);
|
||||
map.put("giteePullRequestId", Optional.ofNullable(pullRequestId).map(String::valueOf).orElse(""));
|
||||
map.put("giteePullRequestIid", Optional.ofNullable(pullRequestIid).map(String::valueOf).orElse(""));
|
||||
map.put("giteePullRequestTargetProjectId", Optional.ofNullable(pullRequestTargetProjectId).map(String::valueOf).orElse(""));
|
||||
map.compute("giteePullRequestState", (k, v) -> pullRequestState);
|
||||
map.compute("giteeMergedByUser", (k, v) -> mergedByUser);
|
||||
map.compute("giteePullRequestAssignee", (k, v) -> pullRequestAssignee);
|
||||
map.put("giteeBefore", before);
|
||||
map.put("giteeAfter", after);
|
||||
map.put("giteeBeforeCommitSha", before);
|
||||
map.put("giteeAfterCommitSha", after);
|
||||
map.put("giteePullRequestLastCommit", lastCommit);
|
||||
map.put("giteeRef", ref);
|
||||
map.put("ref", ref);
|
||||
map.put("beforeSha", beforeSha);
|
||||
map.put("sha", sha);
|
||||
map.put("isTag", isTag);
|
||||
map.put("giteePushCreated", String.valueOf(created));
|
||||
map.put("giteePushDeleted", String.valueOf(deleted));
|
||||
map.put("status", status);
|
||||
map.put("stages", stages);
|
||||
map.put("createdAt", createdAt);
|
||||
map.put("finishedAt", finishedAt);
|
||||
map.put("duration", buildDuration);
|
||||
map.put("jsonBody", jsonBody);
|
||||
map.put("noteBody", noteBody);
|
||||
map.compute("giteeTriggerPhrase", (k, v) -> triggerPhrase);
|
||||
return map;
|
||||
}
|
||||
|
||||
public String getShortDescription() {
|
||||
return webHookType.getShortDescription(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.gitee.jenkins.config;
|
||||
|
||||
import com.cloudbees.plugins.credentials.common.StandardCredentials;
|
||||
import hudson.util.Secret;
|
||||
|
||||
public interface ApiTokenConfig extends StandardCredentials {
|
||||
|
||||
/**
|
||||
* 获取 Api Token
|
||||
*
|
||||
* @return Api Token
|
||||
*/
|
||||
Secret getApiToken();
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.gitee.jenkins.config;
|
||||
|
||||
import com.cloudbees.plugins.credentials.CredentialsNameProvider;
|
||||
import com.cloudbees.plugins.credentials.CredentialsScope;
|
||||
import com.cloudbees.plugins.credentials.NameWith;
|
||||
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
|
||||
import hudson.Extension;
|
||||
import hudson.Util;
|
||||
import hudson.util.Secret;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@NameWith(GiteeApiTokenConfig.NameProvider.class)
|
||||
public final class GiteeApiTokenConfig extends BaseStandardCredentials implements ApiTokenConfig {
|
||||
|
||||
/**
|
||||
* gitee api token
|
||||
*/
|
||||
private Secret apiToken;
|
||||
|
||||
/**
|
||||
* 获取 gitee api token
|
||||
*
|
||||
* @return apiToken
|
||||
*/
|
||||
@Override
|
||||
public Secret getApiToken() {
|
||||
return apiToken;
|
||||
}
|
||||
|
||||
@DataBoundConstructor
|
||||
public GiteeApiTokenConfig(CredentialsScope scope, String id, String description, Secret apiToken) {
|
||||
super(scope, id, description);
|
||||
this.apiToken = apiToken;
|
||||
}
|
||||
|
||||
protected static class NameProvider extends CredentialsNameProvider<ApiTokenConfig> {
|
||||
@Override
|
||||
public String getName(ApiTokenConfig c) {
|
||||
String description = Util.fixEmptyAndTrim(c.getDescription());
|
||||
return Messages.GiteeApiToken_name()
|
||||
+ Optional.ofNullable(description).map(s -> String.join("(", description, ")")).orElse("");
|
||||
}
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return Messages.GiteeApiToken_name();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,281 @@
|
|||
package com.gitee.jenkins.config;
|
||||
|
||||
import com.cloudbees.plugins.credentials.*;
|
||||
import com.cloudbees.plugins.credentials.common.StandardCredentials;
|
||||
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
|
||||
import com.cloudbees.plugins.credentials.domains.Domain;
|
||||
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
|
||||
import com.gitee.jenkins.api.client.GiteeClient;
|
||||
import com.gitee.jenkins.api.client.factory.GiteeClientFactory;
|
||||
import com.gitee.jenkins.enums.GiteeClientType;
|
||||
import com.gitee.jenkins.excetion.GiteeClientRequestException;
|
||||
import hudson.Extension;
|
||||
import hudson.init.InitMilestone;
|
||||
import hudson.init.Initializer;
|
||||
import hudson.model.AbstractDescribableImpl;
|
||||
import hudson.model.Descriptor;
|
||||
import hudson.model.Item;
|
||||
import hudson.security.ACL;
|
||||
import hudson.util.FormValidation;
|
||||
import hudson.util.ListBoxModel;
|
||||
import hudson.util.Secret;
|
||||
import jenkins.model.Jenkins;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.QueryParameter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Gitee链接配置
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class GiteeConnectionConfig extends AbstractDescribableImpl<GiteeConnectionConfig> {
|
||||
|
||||
private static final GiteeClientType GITEE_CLIENT_TYPE = GiteeClientType.V5;
|
||||
|
||||
/**
|
||||
* 链接名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Gitee域名URL
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 证书令牌id
|
||||
*/
|
||||
private String apiTokenId;
|
||||
|
||||
/**
|
||||
* 证书令牌
|
||||
*
|
||||
* @deprecated 已废弃设置,现在不直接配置 apiToken,而是配置链接
|
||||
*/
|
||||
@Deprecated
|
||||
private transient String apiToken;
|
||||
|
||||
/**
|
||||
* 忽略 SSL 证书错误
|
||||
*/
|
||||
private final boolean ignoreCertificateErrors;
|
||||
|
||||
/**
|
||||
* 建立链接超时时间 单位:秒
|
||||
*/
|
||||
private Integer connectionTimeout;
|
||||
|
||||
/**
|
||||
* 读取超时时间 单位:秒
|
||||
*/
|
||||
private Integer readTimeout;
|
||||
|
||||
private transient GiteeClientFactory giteeClientFactory;
|
||||
|
||||
private transient GiteeClient giteeClient;
|
||||
|
||||
@DataBoundConstructor
|
||||
public GiteeConnectionConfig(String name, String url, String apiTokenId, boolean ignoreCertificateErrors, Integer connectionTimeout, Integer readTimeout) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.apiTokenId = apiTokenId;
|
||||
this.ignoreCertificateErrors = ignoreCertificateErrors;
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
this.readTimeout = readTimeout;
|
||||
this.giteeClientFactory = GiteeClientFactory.getGiteeClientFactory(GITEE_CLIENT_TYPE);
|
||||
}
|
||||
|
||||
@Restricted(NoExternalUse.class)
|
||||
public GiteeConnectionConfig(String url, String apiTokenId, boolean ignoreCertificateErrors) {
|
||||
this("", url, apiTokenId, ignoreCertificateErrors, 0, 0);
|
||||
}
|
||||
|
||||
public GiteeClient getGiteeClient() {
|
||||
if (giteeClient == null) {
|
||||
giteeClient = giteeClientFactory.getGiteeClient(url, getApiToken(apiTokenId), ignoreCertificateErrors, connectionTimeout, readTimeout);
|
||||
}
|
||||
return giteeClient;
|
||||
}
|
||||
|
||||
@Restricted(NoExternalUse.class)
|
||||
private String getApiToken(String apiTokenId) {
|
||||
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
|
||||
|
||||
StandardCredentials credentials = CredentialsMatchers.firstOrNull(
|
||||
CredentialsProvider.lookupCredentials(StandardCredentials.class, (Item) null, ACL.SYSTEM, Collections.emptyList()),
|
||||
CredentialsMatchers.withId(apiTokenId)
|
||||
);
|
||||
|
||||
if (credentials != null) {
|
||||
if (credentials instanceof GiteeApiTokenConfig) {
|
||||
return ((GiteeApiTokenConfig) credentials).getApiToken().getPlainText();
|
||||
}
|
||||
if (credentials instanceof StringCredentials) {
|
||||
return ((StringCredentials) credentials).getSecret().getPlainText();
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException("No credentials found for credentialsId: " + apiTokenId);
|
||||
}
|
||||
|
||||
protected GiteeConnectionConfig readResolve() {
|
||||
if (connectionTimeout == null || readTimeout == null) {
|
||||
return new GiteeConnectionConfig(name, url, apiTokenId, ignoreCertificateErrors, 10, 10);
|
||||
}
|
||||
giteeClientFactory = GiteeClientFactory.getGiteeClientFactory(GITEE_CLIENT_TYPE);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容直接输入token的场景
|
||||
*/
|
||||
@Initializer(after = InitMilestone.PLUGINS_STARTED)
|
||||
public static void compatibleProcessing() throws IOException {
|
||||
GiteeGlobalConfig giteeGlobalConfig = (GiteeGlobalConfig) Jenkins.get().getDescriptor(GiteeGlobalConfig.class);
|
||||
if (giteeGlobalConfig == null) {
|
||||
return;
|
||||
}
|
||||
for (GiteeConnectionConfig giteeConnectionConfig : giteeGlobalConfig.getGiteeConnectionConfigs()) {
|
||||
if (Objects.isNull(giteeConnectionConfig.apiTokenId) && Objects.nonNull(giteeConnectionConfig.apiToken)) {
|
||||
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.get())) {
|
||||
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
|
||||
List<Domain> domains = credentialsStore.getDomains();
|
||||
giteeConnectionConfig.apiTokenId = UUID.randomUUID().toString();
|
||||
credentialsStore.addCredentials(
|
||||
domains.get(0),
|
||||
new GiteeApiTokenConfig(CredentialsScope.SYSTEM, giteeConnectionConfig.apiTokenId, "Gitee API Token", Secret.fromString(giteeConnectionConfig.apiToken))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
giteeGlobalConfig.save();
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<GiteeConnectionConfig> {
|
||||
/**
|
||||
* 测试链接
|
||||
*
|
||||
* @param url
|
||||
* @param apiTokenId
|
||||
* @param ignoreCertificateErrors
|
||||
* @return
|
||||
*/
|
||||
public FormValidation doTestConnection(@QueryParameter String url,
|
||||
@QueryParameter String apiTokenId,
|
||||
@QueryParameter boolean ignoreCertificateErrors) {
|
||||
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
|
||||
|
||||
try {
|
||||
new GiteeConnectionConfig(url, apiTokenId, ignoreCertificateErrors)
|
||||
.getGiteeClient()
|
||||
.getUser();
|
||||
return FormValidation.ok(Messages.connection_success());
|
||||
} catch (GiteeClientRequestException e) {
|
||||
return FormValidation.error(Messages.connection_error(e.getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 名称校验
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public FormValidation doCheckName(@QueryParameter String id, @QueryParameter String value) {
|
||||
if (StringUtils.isBlank(value)) {
|
||||
return FormValidation.error(Messages.name_required());
|
||||
}
|
||||
boolean nameExist = Optional.ofNullable((GiteeGlobalConfig) Jenkins.get().getDescriptor(GiteeGlobalConfig.class))
|
||||
.map(giteeGlobalConfig -> giteeGlobalConfig.containsGiteeConnectionName(id, value))
|
||||
.orElse(false);
|
||||
if (nameExist) {
|
||||
return FormValidation.error(Messages.name_exists(value));
|
||||
}
|
||||
return FormValidation.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* url校验
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public FormValidation doCheckUrl(@QueryParameter String value) {
|
||||
if (StringUtils.isBlank(value)) {
|
||||
return FormValidation.error(Messages.url_required());
|
||||
}
|
||||
return FormValidation.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* api token id校验
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public FormValidation doCheckApiTokenId(@QueryParameter String value) {
|
||||
if (StringUtils.isBlank(value)) {
|
||||
return FormValidation.error(Messages.apiToken_required());
|
||||
}
|
||||
return FormValidation.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 链接超时时间校验
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public FormValidation doCheckConnectionTimeout(@QueryParameter Integer value) {
|
||||
if (Objects.isNull(value)) {
|
||||
return FormValidation.error(Messages.connectionTimeout_required());
|
||||
}
|
||||
return FormValidation.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取超时时间校验
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public FormValidation doCheckReadTimeout(@QueryParameter Integer value) {
|
||||
if (value == null) {
|
||||
return FormValidation.error(Messages.readTimeout_required());
|
||||
}
|
||||
return FormValidation.ok();
|
||||
}
|
||||
|
||||
public ListBoxModel doFillApiTokenIdItems(@QueryParameter String url, @QueryParameter String apiTokenId) {
|
||||
if (Jenkins.get().hasPermission(Item.CONFIGURE)) {
|
||||
new StandardListBoxModel()
|
||||
.includeEmptyValue()
|
||||
.includeCurrentValue(apiTokenId);
|
||||
return new StandardListBoxModel()
|
||||
.includeEmptyValue()
|
||||
.includeMatchingAs(
|
||||
ACL.SYSTEM,
|
||||
Jenkins.get(),
|
||||
StandardCredentials.class,
|
||||
URIRequirementBuilder.fromUri(url).build(),
|
||||
new GiteeCredentialMatcher()
|
||||
).includeCurrentValue(apiTokenId);
|
||||
}
|
||||
return new StandardListBoxModel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.gitee.jenkins.config;
|
||||
|
||||
import com.cloudbees.plugins.credentials.Credentials;
|
||||
import com.cloudbees.plugins.credentials.CredentialsMatcher;
|
||||
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
|
||||
|
||||
public class GiteeCredentialMatcher implements CredentialsMatcher {
|
||||
|
||||
@Override
|
||||
public boolean matches(Credentials credentials) {
|
||||
try {
|
||||
return credentials instanceof GiteeApiTokenConfig || credentials instanceof StringCredentials;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package com.gitee.jenkins.config;
|
||||
|
||||
import com.gitee.jenkins.api.client.GiteeClient;
|
||||
import hudson.Extension;
|
||||
import hudson.init.InitMilestone;
|
||||
import hudson.init.Initializer;
|
||||
import jenkins.model.GlobalConfiguration;
|
||||
import jenkins.model.Jenkins;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.DataBoundSetter;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Gitee全局配置
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Extension
|
||||
public class GiteeGlobalConfig extends GlobalConfiguration {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(GiteeGlobalConfig.class.getName());
|
||||
|
||||
private List<GiteeConnectionConfig> giteeConnectionConfigs;
|
||||
private transient Map<String, GiteeConnectionConfig> giteeConnectionConfigMap;
|
||||
|
||||
@DataBoundConstructor
|
||||
public GiteeGlobalConfig() {
|
||||
giteeConnectionConfigs = new ArrayList<>();
|
||||
// 加载持久化配置
|
||||
load();
|
||||
refreshGiteeConnectionConfigMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
|
||||
giteeConnectionConfigs = req.bindJSONToList(GiteeConnectionConfig.class, json.get("connections"));
|
||||
refreshGiteeConnectionConfigMap();
|
||||
save();
|
||||
return super.configure(req, json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重建Gitee链接配置映射
|
||||
*/
|
||||
private void refreshGiteeConnectionConfigMap() {
|
||||
giteeConnectionConfigMap = giteeConnectionConfigs.stream().collect(Collectors.toMap(GiteeConnectionConfig::getName, Function.identity()));
|
||||
}
|
||||
|
||||
@DataBoundSetter
|
||||
public void setGiteeConnectionConfigs(List<GiteeConnectionConfig> giteeConnectionConfigs) {
|
||||
this.giteeConnectionConfigs = giteeConnectionConfigs;
|
||||
refreshGiteeConnectionConfigMap();
|
||||
save();
|
||||
}
|
||||
|
||||
public GiteeClient getGiteeClient(String giteeConnectionName) {
|
||||
return Optional.ofNullable(giteeConnectionConfigMap.get(giteeConnectionName))
|
||||
.map(GiteeConnectionConfig::getGiteeClient)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public boolean containsGiteeConnectionName(String id, String giteeConnectionName) {
|
||||
return Optional.ofNullable(giteeConnectionConfigMap)
|
||||
.map(map -> map.get(giteeConnectionName))
|
||||
.map(giteeConnectionConfig -> !giteeConnectionConfig.toString().equals(id))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供一个空输入
|
||||
*/
|
||||
@Initializer(after = InitMilestone.SYSTEM_CONFIG_ADAPTED)
|
||||
public static void init() {
|
||||
GiteeGlobalConfig giteeGlobalConfig = (GiteeGlobalConfig) Jenkins.get().getDescriptor(GiteeGlobalConfig.class);
|
||||
if (giteeGlobalConfig != null && giteeGlobalConfig.getGiteeConnectionConfigs().isEmpty()) {
|
||||
giteeGlobalConfig.getGiteeConnectionConfigs().add(new GiteeConnectionConfig("", null, false));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.gitee.jenkins.config;
|
||||
|
||||
import com.gitee.jenkins.api.client.GiteeClient;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Job;
|
||||
import hudson.model.JobProperty;
|
||||
import hudson.model.JobPropertyDescriptor;
|
||||
import hudson.util.ListBoxModel;
|
||||
import jenkins.model.Jenkins;
|
||||
import lombok.Getter;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jenkinsci.Symbol;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 单个Item内Gitee配置
|
||||
*/
|
||||
@Getter
|
||||
public class GiteeItemConfig extends JobProperty<Job<?, ?>> {
|
||||
|
||||
private String giteeConnectionName;
|
||||
|
||||
@DataBoundConstructor
|
||||
public GiteeItemConfig(String giteeConnectionName) {
|
||||
this.giteeConnectionName = giteeConnectionName;
|
||||
}
|
||||
|
||||
public static GiteeClient getGiteeClient(Job<?, ?> job) {
|
||||
return Optional.ofNullable(job.getProperty(GiteeItemConfig.class))
|
||||
.map(GiteeItemConfig::getGiteeClient)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public GiteeClient getGiteeClient() {
|
||||
if (StringUtils.isNotBlank(giteeConnectionName)) {
|
||||
GiteeGlobalConfig giteeGlobalConfig = (GiteeGlobalConfig) Jenkins.get().getDescriptor(GiteeGlobalConfig.class);
|
||||
return giteeGlobalConfig == null ? null : giteeGlobalConfig.getGiteeClient(giteeConnectionName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Extension
|
||||
@Symbol("giteeConnectionName")
|
||||
public static class DescriptorImpl extends JobPropertyDescriptor {
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Gitee connection";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Class<? extends Job> jobType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
return req.bindJSON(GiteeItemConfig.class, formData);
|
||||
}
|
||||
|
||||
public ListBoxModel doFillGiteeConnectionNameItems() {
|
||||
ListBoxModel listBoxModel = new ListBoxModel();
|
||||
GiteeGlobalConfig giteeGlobalConfig = (GiteeGlobalConfig) Jenkins.get().getDescriptor(GiteeGlobalConfig.class);
|
||||
if (giteeGlobalConfig != null) {
|
||||
for (GiteeConnectionConfig giteeConnectionConfig : giteeGlobalConfig.getGiteeConnectionConfigs()) {
|
||||
listBoxModel.add(giteeConnectionConfig.getName(), giteeConnectionConfig.getName());
|
||||
}
|
||||
}
|
||||
return listBoxModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.gitee.jenkins.connection;
|
||||
|
||||
import com.cloudbees.plugins.credentials.CredentialsNameProvider;
|
||||
import com.cloudbees.plugins.credentials.NameWith;
|
||||
import com.cloudbees.plugins.credentials.common.StandardCredentials;
|
||||
import hudson.Util;
|
||||
import hudson.util.Secret;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@NameWith(GiteeApiToken.NameProvider.class)
|
||||
public interface GiteeApiToken extends StandardCredentials {
|
||||
|
||||
Secret getApiToken();
|
||||
|
||||
class NameProvider extends CredentialsNameProvider<GiteeApiToken> {
|
||||
@Override
|
||||
public String getName(GiteeApiToken c) {
|
||||
String description = Util.fixEmptyAndTrim(c.getDescription());
|
||||
return Messages.GiteeApiToken_name() + (description != null ? " (" + description + ")" : "");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.gitee.jenkins.connection;
|
||||
|
||||
import com.cloudbees.plugins.credentials.CredentialsScope;
|
||||
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
|
||||
import hudson.Extension;
|
||||
import hudson.util.Secret;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public final class GiteeApiTokenImpl extends BaseStandardCredentials implements GiteeApiToken {
|
||||
|
||||
private Secret apiToken;
|
||||
|
||||
@DataBoundConstructor
|
||||
public GiteeApiTokenImpl(CredentialsScope scope, String id, String description, Secret apiToken) {
|
||||
super(scope, id, description);
|
||||
this.apiToken = apiToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Secret getApiToken() {
|
||||
return apiToken;
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return Messages.GiteeApiToken_name();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
package com.gitee.jenkins.connection;
|
||||
|
||||
|
||||
import com.cloudbees.plugins.credentials.CredentialsMatchers;
|
||||
import com.cloudbees.plugins.credentials.CredentialsProvider;
|
||||
import com.cloudbees.plugins.credentials.CredentialsScope;
|
||||
import com.cloudbees.plugins.credentials.CredentialsStore;
|
||||
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
|
||||
import com.cloudbees.plugins.credentials.common.StandardCredentials;
|
||||
import com.cloudbees.plugins.credentials.domains.Domain;
|
||||
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClientBuilder;
|
||||
import com.gitee.jenkins.gitee.api.impl.GiteeV5ClientBuilder;
|
||||
import hudson.init.InitMilestone;
|
||||
import hudson.init.Initializer;
|
||||
import hudson.model.Item;
|
||||
import hudson.security.ACL;
|
||||
import hudson.util.Secret;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
|
||||
import static com.gitee.jenkins.gitee.api.GiteeClientBuilder.getGiteeClientBuilderById;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class GiteeConnection {
|
||||
private final String name;
|
||||
private final String url;
|
||||
private transient String apiToken;
|
||||
// TODO make final when migration code gets removed
|
||||
private String apiTokenId;
|
||||
private GiteeClientBuilder clientBuilder;
|
||||
private final boolean ignoreCertificateErrors;
|
||||
private final Integer connectionTimeout;
|
||||
private final Integer readTimeout;
|
||||
private transient GiteeClient apiCache;
|
||||
|
||||
public GiteeConnection(String name, String url, String apiTokenId, boolean ignoreCertificateErrors, Integer connectionTimeout, Integer readTimeout) {
|
||||
this(
|
||||
name,
|
||||
url,
|
||||
apiTokenId,
|
||||
new GiteeV5ClientBuilder(),
|
||||
ignoreCertificateErrors,
|
||||
connectionTimeout,
|
||||
readTimeout
|
||||
);
|
||||
}
|
||||
|
||||
@DataBoundConstructor
|
||||
public GiteeConnection(String name, String url, String apiTokenId, String clientBuilderId, boolean ignoreCertificateErrors, Integer connectionTimeout, Integer readTimeout) {
|
||||
this(
|
||||
name,
|
||||
url,
|
||||
apiTokenId,
|
||||
getGiteeClientBuilderById(clientBuilderId),
|
||||
ignoreCertificateErrors,
|
||||
connectionTimeout,
|
||||
readTimeout
|
||||
);
|
||||
}
|
||||
|
||||
@Restricted(NoExternalUse.class)
|
||||
public GiteeConnection(String name, String url, String apiTokenId, GiteeClientBuilder clientBuilder, boolean ignoreCertificateErrors, Integer connectionTimeout, Integer readTimeout) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.apiTokenId = apiTokenId;
|
||||
this.clientBuilder = clientBuilder;
|
||||
this.ignoreCertificateErrors = ignoreCertificateErrors;
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getApiTokenId() {
|
||||
return apiTokenId;
|
||||
}
|
||||
|
||||
public String getClientBuilderId() {
|
||||
return clientBuilder.id();
|
||||
}
|
||||
|
||||
public boolean isIgnoreCertificateErrors() {
|
||||
return ignoreCertificateErrors;
|
||||
}
|
||||
|
||||
public int getConnectionTimeout() {
|
||||
return connectionTimeout;
|
||||
}
|
||||
|
||||
public int getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
|
||||
public GiteeClient getClient() {
|
||||
if (apiCache == null) {
|
||||
apiCache = clientBuilder.buildClient(url, getApiToken(apiTokenId), ignoreCertificateErrors, connectionTimeout, readTimeout);
|
||||
}
|
||||
|
||||
return apiCache;
|
||||
}
|
||||
|
||||
private String getApiToken(String apiTokenId) {
|
||||
StandardCredentials credentials = CredentialsMatchers.firstOrNull(
|
||||
lookupCredentials(StandardCredentials.class, (Item) null, ACL.SYSTEM, new ArrayList<DomainRequirement>()),
|
||||
CredentialsMatchers.withId(apiTokenId));
|
||||
if (credentials != null) {
|
||||
if (credentials instanceof GiteeApiToken) {
|
||||
return ((GiteeApiToken) credentials).getApiToken().getPlainText();
|
||||
}
|
||||
if (credentials instanceof StringCredentials) {
|
||||
return ((StringCredentials) credentials).getSecret().getPlainText();
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("No credentials found for credentialsId: " + apiTokenId);
|
||||
}
|
||||
|
||||
|
||||
protected GiteeConnection readResolve() {
|
||||
if (connectionTimeout == null || readTimeout == null) {
|
||||
return new GiteeConnection(name, url, apiTokenId, new GiteeV5ClientBuilder(), ignoreCertificateErrors, 10, 10);
|
||||
}
|
||||
if (clientBuilder == null) {
|
||||
return new GiteeConnection(name, url, apiTokenId, new GiteeV5ClientBuilder(), ignoreCertificateErrors, connectionTimeout, readTimeout);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Initializer(after = InitMilestone.PLUGINS_STARTED)
|
||||
public static void migrate() throws IOException {
|
||||
GiteeConnectionConfig descriptor = (GiteeConnectionConfig) Jenkins.getInstance().getDescriptor(GiteeConnectionConfig.class);
|
||||
for (GiteeConnection connection : descriptor.getConnections()) {
|
||||
if (connection.apiTokenId == null && connection.apiToken != null) {
|
||||
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
|
||||
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
|
||||
List<Domain> domains = credentialsStore.getDomains();
|
||||
connection.apiTokenId = UUID.randomUUID().toString();
|
||||
credentialsStore.addCredentials(domains.get(0),
|
||||
new GiteeApiTokenImpl(CredentialsScope.SYSTEM, connection.apiTokenId, "Gitee API Token", Secret.fromString(connection.apiToken)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
descriptor.save();
|
||||
}
|
||||
}
|
|
@ -1,210 +0,0 @@
|
|||
package com.gitee.jenkins.connection;
|
||||
|
||||
|
||||
import com.cloudbees.plugins.credentials.Credentials;
|
||||
import com.cloudbees.plugins.credentials.CredentialsMatcher;
|
||||
import com.cloudbees.plugins.credentials.common.AbstractIdCredentialsListBoxModel;
|
||||
import com.cloudbees.plugins.credentials.common.StandardCredentials;
|
||||
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
|
||||
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClientBuilder;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Item;
|
||||
import hudson.security.ACL;
|
||||
import hudson.util.FormValidation;
|
||||
import hudson.util.ListBoxModel;
|
||||
import jenkins.model.GlobalConfiguration;
|
||||
import jenkins.model.Jenkins;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.eclipse.jgit.util.StringUtils;
|
||||
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
|
||||
import org.kohsuke.stapler.QueryParameter;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
import javax.ws.rs.ProcessingException;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.gitee.jenkins.gitee.api.GiteeClientBuilder.getAllGiteeClientBuilders;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@Extension
|
||||
public class GiteeConnectionConfig extends GlobalConfiguration {
|
||||
|
||||
private Boolean useAuthenticatedEndpoint = true;
|
||||
private List<GiteeConnection> connections = new ArrayList<>();
|
||||
private transient Map<String, GiteeConnection> connectionMap = new HashMap<>();
|
||||
|
||||
public GiteeConnectionConfig() {
|
||||
load();
|
||||
refreshConnectionMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
|
||||
connections = req.bindJSONToList(GiteeConnection.class, json.get("connections"));
|
||||
// useAuthenticatedEndpoint = json.getBoolean("useAuthenticatedEndpoint");
|
||||
refreshConnectionMap();
|
||||
save();
|
||||
return super.configure(req, json);
|
||||
}
|
||||
|
||||
public boolean isUseAuthenticatedEndpoint() {
|
||||
return useAuthenticatedEndpoint;
|
||||
}
|
||||
|
||||
void setUseAuthenticatedEndpoint(boolean useAuthenticatedEndpoint) {
|
||||
this.useAuthenticatedEndpoint = useAuthenticatedEndpoint;
|
||||
}
|
||||
|
||||
public List<GiteeConnection> getConnections() {
|
||||
return connections;
|
||||
}
|
||||
|
||||
public void addConnection(GiteeConnection connection) {
|
||||
connections.add(connection);
|
||||
connectionMap.put(connection.getName(), connection);
|
||||
}
|
||||
|
||||
public void setConnections(List<GiteeConnection> newConnections) {
|
||||
connections = new ArrayList<>();
|
||||
connectionMap = new HashMap<>();
|
||||
for (GiteeConnection connection: newConnections){
|
||||
addConnection(connection);
|
||||
}
|
||||
}
|
||||
|
||||
public GiteeClient getClient(String connectionName) {
|
||||
if (!connectionMap.containsKey(connectionName)) {
|
||||
return null;
|
||||
}
|
||||
return connectionMap.get(connectionName).getClient();
|
||||
}
|
||||
|
||||
public FormValidation doCheckName(@QueryParameter String id, @QueryParameter String value) {
|
||||
if (StringUtils.isEmptyOrNull(value)) {
|
||||
return FormValidation.error(Messages.name_required());
|
||||
} else if (connectionMap.containsKey(value) && !connectionMap.get(value).toString().equals(id)) {
|
||||
return FormValidation.error(Messages.name_exists(value));
|
||||
} else {
|
||||
return FormValidation.ok();
|
||||
}
|
||||
}
|
||||
|
||||
public FormValidation doCheckUrl(@QueryParameter String value) {
|
||||
if (StringUtils.isEmptyOrNull(value)) {
|
||||
return FormValidation.error(Messages.url_required());
|
||||
} else {
|
||||
return FormValidation.ok();
|
||||
}
|
||||
}
|
||||
|
||||
public FormValidation doCheckApiTokenId(@QueryParameter String value) {
|
||||
if (StringUtils.isEmptyOrNull(value)) {
|
||||
return FormValidation.error(Messages.apiToken_required());
|
||||
} else {
|
||||
return FormValidation.ok();
|
||||
}
|
||||
}
|
||||
|
||||
public FormValidation doCheckConnectionTimeout(@QueryParameter Integer value) {
|
||||
if (value == null) {
|
||||
return FormValidation.error(Messages.connectionTimeout_required());
|
||||
} else {
|
||||
return FormValidation.ok();
|
||||
}
|
||||
}
|
||||
|
||||
public FormValidation doCheckReadTimeout(@QueryParameter Integer value) {
|
||||
if (value == null) {
|
||||
return FormValidation.error(Messages.readTimeout_required());
|
||||
} else {
|
||||
return FormValidation.ok();
|
||||
}
|
||||
}
|
||||
|
||||
public FormValidation doTestConnection(@QueryParameter String url,
|
||||
@QueryParameter String apiTokenId,
|
||||
@QueryParameter String clientBuilderId,
|
||||
@QueryParameter boolean ignoreCertificateErrors,
|
||||
@QueryParameter int connectionTimeout,
|
||||
@QueryParameter int readTimeout) {
|
||||
try {
|
||||
if (clientBuilderId == null) {
|
||||
clientBuilderId = "v5";
|
||||
}
|
||||
|
||||
new GiteeConnection("", url, apiTokenId, clientBuilderId, ignoreCertificateErrors, connectionTimeout, readTimeout).getClient().getCurrentUser();
|
||||
return FormValidation.ok(Messages.connection_success());
|
||||
} catch (WebApplicationException e) {
|
||||
return FormValidation.error(Messages.connection_error(e.getMessage()));
|
||||
} catch (ProcessingException e) {
|
||||
return FormValidation.error(Messages.connection_error(e.getCause().getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public ListBoxModel doFillApiTokenIdItems(@QueryParameter String name, @QueryParameter String url) {
|
||||
if (Jenkins.getInstance().hasPermission(Item.CONFIGURE)) {
|
||||
AbstractIdCredentialsListBoxModel<StandardListBoxModel, StandardCredentials> options = new StandardListBoxModel()
|
||||
.includeEmptyValue()
|
||||
.includeMatchingAs(ACL.SYSTEM,
|
||||
Jenkins.getActiveInstance(),
|
||||
StandardCredentials.class,
|
||||
URIRequirementBuilder.fromUri(url).build(),
|
||||
new GiteeCredentialMatcher());
|
||||
if (name != null && connectionMap.containsKey(name)) {
|
||||
String apiTokenId = connectionMap.get(name).getApiTokenId();
|
||||
options.includeCurrentValue(apiTokenId);
|
||||
for (ListBoxModel.Option option : options) {
|
||||
if (option.value.equals(apiTokenId)) {
|
||||
option.selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
return new StandardListBoxModel();
|
||||
}
|
||||
|
||||
public ListBoxModel doFillClientBuilderIdItems() {
|
||||
ListBoxModel model = new ListBoxModel();
|
||||
for (GiteeClientBuilder builder : getAllGiteeClientBuilders()) {
|
||||
model.add(builder.id());
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private void refreshConnectionMap() {
|
||||
connectionMap.clear();
|
||||
for (GiteeConnection connection : connections) {
|
||||
connectionMap.put(connection.getName(), connection);
|
||||
}
|
||||
}
|
||||
|
||||
private static class GiteeCredentialMatcher implements CredentialsMatcher {
|
||||
@Override
|
||||
public boolean matches(@NonNull Credentials credentials) {
|
||||
try {
|
||||
return credentials instanceof GiteeApiToken || credentials instanceof StringCredentials;
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//For backwards compatibility. ReadResolve is called on startup
|
||||
protected GiteeConnectionConfig readResolve() {
|
||||
if (useAuthenticatedEndpoint == null) {
|
||||
setUseAuthenticatedEndpoint(false);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package com.gitee.jenkins.connection;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Job;
|
||||
import hudson.model.JobProperty;
|
||||
import hudson.model.JobPropertyDescriptor;
|
||||
import hudson.model.Run;
|
||||
import hudson.util.ListBoxModel;
|
||||
import jenkins.model.Jenkins;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jenkinsci.Symbol;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class GiteeConnectionProperty extends JobProperty<Job<?, ?>> {
|
||||
|
||||
private String giteeConnection;
|
||||
|
||||
@DataBoundConstructor
|
||||
public GiteeConnectionProperty(String giteeConnection) {
|
||||
this.giteeConnection = giteeConnection;
|
||||
}
|
||||
|
||||
public String getGiteeConnection() {
|
||||
return giteeConnection;
|
||||
}
|
||||
|
||||
public GiteeClient getClient() {
|
||||
if (StringUtils.isNotEmpty(giteeConnection)) {
|
||||
GiteeConnectionConfig connectionConfig = (GiteeConnectionConfig) Jenkins.getInstance().getDescriptor(GiteeConnectionConfig.class);
|
||||
return connectionConfig != null ? connectionConfig.getClient(giteeConnection) : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GiteeClient getClient(Run<?, ?> build) {
|
||||
final GiteeConnectionProperty connectionProperty = build.getParent().getProperty(GiteeConnectionProperty.class);
|
||||
if (connectionProperty != null) {
|
||||
return connectionProperty.getClient();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GiteeClient getClient(Job<?, ?> job) {
|
||||
final GiteeConnectionProperty connectionProperty = job.getProperty(GiteeConnectionProperty.class);
|
||||
if (connectionProperty != null) {
|
||||
return connectionProperty.getClient();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Extension
|
||||
@Symbol("giteeConnection")
|
||||
public static class DescriptorImpl extends JobPropertyDescriptor {
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Gitee connection";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Class<? extends Job> jobType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
return req.bindJSON(GiteeConnectionProperty.class, formData);
|
||||
}
|
||||
|
||||
public ListBoxModel doFillGiteeConnectionItems() {
|
||||
ListBoxModel options = new ListBoxModel();
|
||||
GiteeConnectionConfig descriptor = (GiteeConnectionConfig) Jenkins.getInstance().getDescriptor(GiteeConnectionConfig.class);
|
||||
for (GiteeConnection connection : descriptor.getConnections()) {
|
||||
options.add(connection.getName(), connection.getName());
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Branch {
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* 分支名称
|
||||
*/
|
||||
private String ref;
|
||||
|
||||
/**
|
||||
* sha
|
||||
*/
|
||||
private String sha;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
private User user;
|
||||
|
||||
/**
|
||||
* 仓库
|
||||
*/
|
||||
private Repository repo;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Commit {
|
||||
|
||||
private String id;
|
||||
|
||||
private String treeId;
|
||||
|
||||
private List<String> parentIds;
|
||||
|
||||
private String message;
|
||||
|
||||
private Date timestamp;
|
||||
|
||||
private String url;
|
||||
|
||||
private User author;
|
||||
|
||||
private User committer;
|
||||
|
||||
private Boolean distinct;
|
||||
|
||||
private List<String> added;
|
||||
|
||||
private List<String> removed;
|
||||
|
||||
private List<String> modified;
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CommitComment extends PullRequestComment {
|
||||
|
||||
private String position;
|
||||
|
||||
private String commitId;
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import com.gitee.jenkins.enums.PullRequestCommentAction;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CommitCommentWebHook extends WebHook {
|
||||
|
||||
private PullRequestCommentAction action;
|
||||
|
||||
private CommitComment comment;
|
||||
|
||||
private User author;
|
||||
|
||||
private String url;
|
||||
|
||||
private String note;
|
||||
|
||||
private String noteableType;
|
||||
|
||||
private Integer noteableId;
|
||||
|
||||
private String title;
|
||||
|
||||
private String perIid;
|
||||
|
||||
private String shortCommitId;
|
||||
|
||||
@Override
|
||||
public WebHookType getWebHookType() {
|
||||
return WebHookType.COMMIT_COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWebHookDescription() {
|
||||
return super.getHookName() + " commit sha = " + comment.getCommitId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetBranch() {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Enterprise {
|
||||
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import com.gitee.jenkins.enums.PullRequestState;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PullRequest {
|
||||
|
||||
/**
|
||||
* PR id
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* PR 序号
|
||||
*/
|
||||
private Integer number;
|
||||
|
||||
private PullRequestState state;
|
||||
|
||||
private String htmlUrl;
|
||||
|
||||
private String diffUrl;
|
||||
|
||||
private String patchUrl;
|
||||
|
||||
/**
|
||||
* PR 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* PR 内容
|
||||
*/
|
||||
private String body;
|
||||
|
||||
/**
|
||||
* PR 标签
|
||||
*/
|
||||
private List<String> labels;
|
||||
|
||||
private List<String> languages;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createdAt;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updatedAt;
|
||||
|
||||
/**
|
||||
* 关闭时间
|
||||
*/
|
||||
private Date closedAt;
|
||||
|
||||
/**
|
||||
* 合并时间
|
||||
*/
|
||||
private Date mergedAt;
|
||||
|
||||
/**
|
||||
* 合并sha
|
||||
*/
|
||||
private String mergeCommitSha;
|
||||
|
||||
/**
|
||||
* mergeReferenceName
|
||||
*/
|
||||
private String mergeReferenceName;
|
||||
|
||||
private User assignee;
|
||||
|
||||
private List<User> assignees;
|
||||
|
||||
private User tester;
|
||||
|
||||
private List<User> testers;
|
||||
|
||||
/**
|
||||
* 是否需要测试
|
||||
*/
|
||||
private Boolean needTest;
|
||||
|
||||
/**
|
||||
* 是否想要审核
|
||||
*/
|
||||
private Boolean needReview;
|
||||
|
||||
/**
|
||||
* 里程碑
|
||||
*/
|
||||
private String milestone;
|
||||
|
||||
/**
|
||||
* 是否合并
|
||||
*/
|
||||
private Boolean merged;
|
||||
|
||||
/**
|
||||
* 是否可以合并
|
||||
*/
|
||||
private Boolean mergeable;
|
||||
|
||||
/**
|
||||
* 合并状态
|
||||
*/
|
||||
private String mergeStatus;
|
||||
|
||||
/**
|
||||
* 评论数
|
||||
*/
|
||||
private Integer comments;
|
||||
|
||||
/**
|
||||
* 提交数
|
||||
*/
|
||||
private Integer commits;
|
||||
|
||||
/**
|
||||
* 增加文件数量
|
||||
*/
|
||||
private Integer additions;
|
||||
|
||||
/**
|
||||
* 删除文件数量
|
||||
*/
|
||||
private Integer deletions;
|
||||
|
||||
/**
|
||||
* 修改文件数
|
||||
*/
|
||||
private Integer changedFiles;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private User user;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private User updatedBy;
|
||||
|
||||
/**
|
||||
* 目标分支
|
||||
*/
|
||||
private Branch head;
|
||||
|
||||
/**
|
||||
* 源分支
|
||||
*/
|
||||
private Branch base;
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class PullRequestComment {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String body;
|
||||
|
||||
private User user;
|
||||
|
||||
private Date createdAt;
|
||||
|
||||
private Date updatedAt;
|
||||
|
||||
private String htmlUrl;
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import com.gitee.jenkins.enums.PullRequestCommentAction;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
public class PullRequestCommentWebHook extends WebHook {
|
||||
|
||||
private PullRequestCommentAction action;
|
||||
|
||||
private PullRequestComment comment;
|
||||
|
||||
private User author;
|
||||
|
||||
private String url;
|
||||
|
||||
private String note;
|
||||
|
||||
private String noteableType;
|
||||
|
||||
private Integer noteableId;
|
||||
|
||||
private String title;
|
||||
|
||||
private String perIid;
|
||||
|
||||
private String shortCommitId;
|
||||
|
||||
private PullRequest pullRequest;
|
||||
|
||||
@Override
|
||||
public WebHookType getWebHookType() {
|
||||
return WebHookType.PULL_REQUEST_COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWebHookDescription() {
|
||||
return super.getHookName() + " iid = " + pullRequest.getNumber() + " merge commit sha = " + pullRequest.getMergeCommitSha();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetBranch() {
|
||||
return Optional.ofNullable(pullRequest)
|
||||
.map(PullRequest::getBase)
|
||||
.map(Branch::getRef)
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import com.gitee.jenkins.enums.PullRequestAction;
|
||||
import com.gitee.jenkins.enums.PullRequestActionDesc;
|
||||
import com.gitee.jenkins.enums.PullRequestState;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
public class PullRequestWebHook extends WebHook {
|
||||
|
||||
private PullRequestAction action;
|
||||
|
||||
private PullRequestActionDesc actionDesc;
|
||||
|
||||
private PullRequest pullRequest;
|
||||
|
||||
private Integer number;
|
||||
|
||||
private Integer iid;
|
||||
|
||||
private String title;
|
||||
|
||||
private String body;
|
||||
|
||||
private List<String> languages;
|
||||
|
||||
private PullRequestState state;
|
||||
|
||||
private String mergeStatus;
|
||||
|
||||
private String mergeCommitSha;
|
||||
|
||||
private String url;
|
||||
|
||||
private String sourceBranch;
|
||||
|
||||
private TargetRepository sourceRepo;
|
||||
|
||||
private String targetBranch;
|
||||
|
||||
private TargetRepository targetRepo;
|
||||
|
||||
private User author;
|
||||
|
||||
private User updatedBy;
|
||||
|
||||
private User targetUser;
|
||||
|
||||
@Override
|
||||
public WebHookType getWebHookType() {
|
||||
return WebHookType.PULL_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWebHookDescription() {
|
||||
return super.getHookName() + " iid = " + pullRequest.getNumber() + " merge commit sha = " + pullRequest.getMergeCommitSha();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetBranch() {
|
||||
return Optional.ofNullable(pullRequest)
|
||||
.map(PullRequest::getBase)
|
||||
.map(Branch::getRef)
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
public class PushWebHook extends WebHook {
|
||||
|
||||
private String ref;
|
||||
|
||||
private String before;
|
||||
|
||||
private String after;
|
||||
|
||||
private Integer totalCommitsCount;
|
||||
|
||||
private Boolean commitsMoreThanTen;
|
||||
|
||||
private Boolean created;
|
||||
|
||||
private Boolean deleted;
|
||||
|
||||
private String compare;
|
||||
|
||||
private List<Commit> commits;
|
||||
|
||||
private Commit headCommit;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private String userName;
|
||||
|
||||
private User user;
|
||||
|
||||
private User pusher;
|
||||
|
||||
|
||||
@Override
|
||||
public WebHookType getWebHookType() {
|
||||
return WebHookType.PUSH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWebHookDescription() {
|
||||
return super.getHookName() + " ref = " + ref + " commit sha = " + after;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetBranch() {
|
||||
return Optional.ofNullable(ref)
|
||||
.map(s -> s.replaceFirst("^refs/heads/", ""))
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Repository {
|
||||
|
||||
/**
|
||||
* 仓库 id
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 仓库名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 仓库全名
|
||||
*/
|
||||
private String fullName;
|
||||
|
||||
/**
|
||||
* 仓库所有人
|
||||
*/
|
||||
private User owner;
|
||||
|
||||
/**
|
||||
* 是否私有
|
||||
*/
|
||||
@JsonProperty("private")
|
||||
private Boolean priv;
|
||||
|
||||
private String htmlUrl;
|
||||
|
||||
private String url;
|
||||
|
||||
private String description;
|
||||
|
||||
private Boolean fork;
|
||||
|
||||
private Date createdAt;
|
||||
|
||||
private Date updatedAt;
|
||||
|
||||
private Date pushedAt;
|
||||
|
||||
private String gitUrl;
|
||||
|
||||
private String sshUrl;
|
||||
|
||||
private String cloneUrl;
|
||||
|
||||
private String svnUrl;
|
||||
|
||||
private String gitHttpUrl;
|
||||
|
||||
private String gitSshUrl;
|
||||
|
||||
private String gitSvnUrl;
|
||||
|
||||
private String homepage;
|
||||
|
||||
private Integer stargazersCount;
|
||||
|
||||
private Integer watchersCount;
|
||||
|
||||
private Integer forksCount;
|
||||
|
||||
private String language;
|
||||
|
||||
private Boolean hasIssues;
|
||||
|
||||
private Boolean hasWiki;
|
||||
|
||||
private Boolean hasPages;
|
||||
|
||||
private String license;
|
||||
|
||||
private Integer openIssuesCount;
|
||||
|
||||
private String defaultBranch;
|
||||
|
||||
private String namespace;
|
||||
|
||||
private String nameWithNamespace;
|
||||
|
||||
private String pathWithNamespace;
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TargetRepository {
|
||||
|
||||
private Repository project;
|
||||
|
||||
private Repository repository;
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class User {
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
private String login;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
private String username;
|
||||
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 头像url
|
||||
*/
|
||||
private String avatarUrl;
|
||||
|
||||
/**
|
||||
* 主页url
|
||||
*/
|
||||
private String url;
|
||||
|
||||
private String htmlUrl;
|
||||
|
||||
private String followersUrl;
|
||||
|
||||
private String followingUrl;
|
||||
|
||||
private String gistsUrl;
|
||||
|
||||
private String starredUrl;
|
||||
|
||||
private String subscriptionsUrl;
|
||||
|
||||
private String organizationsUrl;
|
||||
|
||||
private String reposUrl;
|
||||
|
||||
private String eventsUrl;
|
||||
|
||||
private String receivedEventsUrl;
|
||||
|
||||
private String type;
|
||||
|
||||
private String blog;
|
||||
|
||||
private String weibo;
|
||||
|
||||
private String bio;
|
||||
|
||||
private Integer publicRepos;
|
||||
|
||||
private Integer publicGists;
|
||||
|
||||
private Integer followers;
|
||||
|
||||
private Integer following;
|
||||
|
||||
private Integer stared;
|
||||
|
||||
private Integer watched;
|
||||
|
||||
private Date createdAt;
|
||||
|
||||
private Date updatedAt;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 是否为网站管理员
|
||||
*/
|
||||
private Boolean siteAdmin;
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public abstract class WebHook {
|
||||
|
||||
private Repository project;
|
||||
|
||||
private Repository repository;
|
||||
|
||||
private User sender;
|
||||
|
||||
private Enterprise enterprise;
|
||||
|
||||
private String hookName;
|
||||
|
||||
private String hookId;
|
||||
|
||||
private String hookUrl;
|
||||
|
||||
private String password;
|
||||
|
||||
private Date timestamp;
|
||||
|
||||
private String sign;
|
||||
|
||||
private String jsonBody;
|
||||
|
||||
/**
|
||||
* WebHook 类型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract WebHookType getWebHookType();
|
||||
|
||||
/**
|
||||
* WebHook 说明
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getWebHookDescription();
|
||||
|
||||
/**
|
||||
* 获取构建目标分支
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getTargetBranch();
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.gitee.jenkins.entity;
|
||||
|
||||
import hudson.model.Job;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class WebHookAction {
|
||||
|
||||
private Job<?, ?> job;
|
||||
|
||||
private WebHook webHook;
|
||||
|
||||
private String secretToken;
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
/**
|
||||
* 分支名称过滤器类型
|
||||
*/
|
||||
public enum BranchNameFilterType {
|
||||
|
||||
/**
|
||||
* 允许所有分支触发构建
|
||||
*/
|
||||
ALL,
|
||||
/**
|
||||
* 通过分支名过滤
|
||||
*/
|
||||
NAME_FILTER,
|
||||
/**
|
||||
* 通过正则表达式过滤
|
||||
*/
|
||||
REGEX_FILTER
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 构建指令过滤器类型
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BuildInstructionFilterType {
|
||||
|
||||
/**
|
||||
* 无过滤
|
||||
*/
|
||||
NONE(""),
|
||||
/**
|
||||
* 包含 [ci-skip] 时跳过构建
|
||||
*/
|
||||
CI_SKIP("[ci-skip]"),
|
||||
/**
|
||||
* 包含 [ci-build] 时触发构建
|
||||
*/
|
||||
CI_BUILD("[ci-build]");
|
||||
|
||||
private String body;
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
/**
|
||||
* Gitee 客户端类型
|
||||
*/
|
||||
public enum GiteeClientType {
|
||||
|
||||
V5
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
|
||||
/**
|
||||
* PR 操作枚举
|
||||
*/
|
||||
public enum PullRequestAction {
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*/
|
||||
OPEN("open"),
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
UPDATE("update"),
|
||||
/**
|
||||
* 测试通过
|
||||
*/
|
||||
TESTED("tested"),
|
||||
/**
|
||||
* 审核通过
|
||||
*/
|
||||
APPROVED("approved"),
|
||||
/**
|
||||
* 合并
|
||||
*/
|
||||
MERGE("merge"),
|
||||
/**
|
||||
* 关闭
|
||||
*/
|
||||
CLOSE("close");
|
||||
|
||||
private final String value;
|
||||
|
||||
PullRequestAction(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static PullRequestAction parseJson(String str) {
|
||||
for (PullRequestAction pullRequestAction : values()) {
|
||||
if (pullRequestAction.value.equals(str)) {
|
||||
return pullRequestAction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否允许该操作触发构建
|
||||
*
|
||||
* @param giteeTrigger Gitee 触发器
|
||||
* @param pullRequestAction 操作
|
||||
* @return 是否允许触发构建
|
||||
*/
|
||||
public static boolean allowAction(GiteeTrigger giteeTrigger, PullRequestAction pullRequestAction, PullRequestActionDesc pullRequestActionDesc) {
|
||||
if (pullRequestAction == UPDATE) {
|
||||
if (giteeTrigger.getTriggerOnUpdatePullRequest() == PullRequestUpdateType.SOURCE_BRANCH_UPDATED) {
|
||||
return pullRequestActionDesc == PullRequestActionDesc.SOURCE_BRANCH_CHANGED;
|
||||
} else if (giteeTrigger.getTriggerOnUpdatePullRequest() == PullRequestUpdateType.TARGET_BRANCH_UPDATED) {
|
||||
return pullRequestActionDesc == PullRequestActionDesc.TARGET_BRANCH_CHANGED;
|
||||
} else {
|
||||
return giteeTrigger.getTriggerOnUpdatePullRequest() == PullRequestUpdateType.BOTH_SOURCE_AND_TARGET_BRANCH_UPDATED;
|
||||
}
|
||||
}
|
||||
return (pullRequestAction == OPEN && giteeTrigger.isTriggerOnOpenPullRequest())
|
||||
|| (pullRequestAction == TESTED && giteeTrigger.isTriggerOnTestedPullRequest())
|
||||
|| (pullRequestAction == APPROVED && giteeTrigger.isTriggerOnTestedPullRequest())
|
||||
|| (pullRequestAction == MERGE && giteeTrigger.isTriggerOnTestedPullRequest())
|
||||
|| (pullRequestAction == CLOSE && giteeTrigger.isTriggerOnTestedPullRequest());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
/**
|
||||
* PR 修改操作
|
||||
*/
|
||||
public enum PullRequestActionDesc {
|
||||
|
||||
TARGET_BRANCH_CHANGED("target_branch_changed"),
|
||||
SOURCE_BRANCH_CHANGED("source_branch_changed");
|
||||
|
||||
private String value;
|
||||
|
||||
PullRequestActionDesc(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static PullRequestActionDesc parseJson(String str) {
|
||||
for (PullRequestActionDesc pullRequestActionDesc : values()) {
|
||||
if (pullRequestActionDesc.value.equals(str)) {
|
||||
return pullRequestActionDesc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
/**
|
||||
* PR 评论操作类型
|
||||
*/
|
||||
public enum PullRequestCommentAction {
|
||||
|
||||
COMMENT("comment"),
|
||||
EDITED("edited"),
|
||||
DELETED("deleted");
|
||||
|
||||
private String value;
|
||||
|
||||
PullRequestCommentAction(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static PullRequestCommentAction parseJson(String str) {
|
||||
for (PullRequestCommentAction pullRequestCommentAction : values()) {
|
||||
if (pullRequestCommentAction.value.equals(str)) {
|
||||
return pullRequestCommentAction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* PR 状态枚举
|
||||
*/
|
||||
@Getter
|
||||
public enum PullRequestState {
|
||||
|
||||
/**
|
||||
* open
|
||||
*/
|
||||
OPEN("open"),
|
||||
/**
|
||||
* opened
|
||||
*/
|
||||
OPENED("opened"),
|
||||
/**
|
||||
* reopened
|
||||
*/
|
||||
REOPENED("reopened"),
|
||||
/**
|
||||
* updated
|
||||
*/
|
||||
UPDATED("updated"),
|
||||
/**
|
||||
* merged
|
||||
*/
|
||||
MERGED("merged"),
|
||||
/**
|
||||
* closed
|
||||
*/
|
||||
CLOSED("closed");
|
||||
|
||||
private String value;
|
||||
|
||||
PullRequestState(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static PullRequestState parseJson(String str) {
|
||||
for (PullRequestState pullRequestState : values()) {
|
||||
if (pullRequestState.value.equals(str)) {
|
||||
return pullRequestState;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 是否允许该状态触发构建
|
||||
*
|
||||
* @param giteeTrigger Gitee 触发器
|
||||
* @param pullRequestState PR 状态
|
||||
* @return 是否允许该状态触发构建
|
||||
*/
|
||||
public static boolean allowState(GiteeTrigger giteeTrigger, PullRequestState pullRequestState) {
|
||||
if (pullRequestState == OPEN || pullRequestState == OPENED || pullRequestState == REOPENED || pullRequestState == UPDATED) {
|
||||
return giteeTrigger.isTriggerOnOpenPullRequest()
|
||||
|| giteeTrigger.getTriggerOnUpdatePullRequest() != PullRequestUpdateType.NONE
|
||||
|| giteeTrigger.isTriggerOnTestedPullRequest()
|
||||
|| giteeTrigger.isTriggerOnApprovedPullRequest();
|
||||
}
|
||||
return (pullRequestState == MERGED && giteeTrigger.isTriggerOnAcceptedPullRequest())
|
||||
|| (pullRequestState == CLOSED && giteeTrigger.isTriggerOnClosedPullRequest());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
/**
|
||||
* 触发器 PR 修改操作类型
|
||||
*/
|
||||
public enum PullRequestUpdateType {
|
||||
|
||||
/**
|
||||
* 无
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* 原分支修改
|
||||
*/
|
||||
SOURCE_BRANCH_UPDATED,
|
||||
/**
|
||||
* 目标分支修改
|
||||
*/
|
||||
TARGET_BRANCH_UPDATED,
|
||||
/**
|
||||
* 原分支和目标分支修改
|
||||
*/
|
||||
BOTH_SOURCE_AND_TARGET_BRANCH_UPDATED;
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
/**
|
||||
* WebHook event
|
||||
*/
|
||||
public enum WebHookEvent {
|
||||
|
||||
/**
|
||||
* 代码推送
|
||||
*/
|
||||
PUSH("Push Hook"),
|
||||
TAG_PUSH("Tag Push Hook"),
|
||||
/**
|
||||
* PR
|
||||
*/
|
||||
PULL_REQUEST("Merge Request Hook"),
|
||||
/**
|
||||
* 评论
|
||||
*/
|
||||
NOTE("Note Hook");
|
||||
|
||||
private String value;
|
||||
|
||||
WebHookEvent(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static WebHookEvent getWebHookEvent(String event) {
|
||||
for (WebHookEvent webHookEvent : values()) {
|
||||
if (webHookEvent.value.equals(event)) {
|
||||
return webHookEvent;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package com.gitee.jenkins.enums;
|
||||
|
||||
import com.gitee.jenkins.cause.GiteeWebHookCauseData;
|
||||
import hudson.markup.EscapedMarkupFormatter;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* WebHook 类型
|
||||
*/
|
||||
public enum WebHookType {
|
||||
|
||||
/**
|
||||
* 代码推送
|
||||
*/
|
||||
PUSH {
|
||||
@Override
|
||||
public String getShortDescription(GiteeWebHookCauseData data) {
|
||||
String triggeredByUser = data.getTriggeredByUser();
|
||||
if (triggeredByUser == null) {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PushHook_noUser();
|
||||
} else {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PushHook(triggeredByUser);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* PR
|
||||
*/
|
||||
PULL_REQUEST {
|
||||
@Override
|
||||
public String getShortDescription(GiteeWebHookCauseData data) {
|
||||
String forkNamespace = StringUtils.equals(data.getSourceNamespace(), data.getTargetBranch()) ? "" : data.getSourceNamespace() + "/";
|
||||
if (Jenkins.get().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PullRequestHook_plain(
|
||||
String.valueOf(data.getPullRequestIid()),
|
||||
forkNamespace + data.getSourceBranch(),
|
||||
data.getTargetBranch()
|
||||
);
|
||||
} else {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_PullRequestHook_html(
|
||||
String.valueOf(data.getPullRequestIid()),
|
||||
forkNamespace + data.getSourceBranch(),
|
||||
data.getTargetBranch(),
|
||||
data.getTargetProjectUrl()
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* PR 评论
|
||||
*/
|
||||
PULL_REQUEST_COMMENT {
|
||||
@Override
|
||||
public String getShortDescription(GiteeWebHookCauseData data) {
|
||||
String triggeredByUser = data.getTriggeredByUser();
|
||||
String forkNamespace = StringUtils.equals(data.getSourceNamespace(), data.getTargetBranch()) ? "" : data.getSourceNamespace() + "/";
|
||||
if (Jenkins.get().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_NoteHook_plain(
|
||||
triggeredByUser,
|
||||
String.valueOf(data.getPullRequestIid()),
|
||||
forkNamespace + data.getSourceBranch(),
|
||||
data.getTargetBranch()
|
||||
);
|
||||
} else {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_NoteHook_html(
|
||||
triggeredByUser,
|
||||
String.valueOf(data.getPullRequestIid()),
|
||||
forkNamespace + data.getSourceBranch(),
|
||||
data.getTargetBranch(),
|
||||
data.getTargetProjectUrl()
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* commit 评论
|
||||
*/
|
||||
COMMIT_COMMENT {
|
||||
@Override
|
||||
public String getShortDescription(GiteeWebHookCauseData data) {
|
||||
return Messages.GiteeWebHookCause_ShortDescription_Commit_comment(data.getTriggeredByUser());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 构建说明
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public abstract String getShortDescription(GiteeWebHookCauseData data);
|
||||
|
||||
}
|
|
@ -3,33 +3,32 @@ package com.gitee.jenkins.environment;
|
|||
import com.gitee.jenkins.cause.GiteeWebHookCause;
|
||||
import hudson.EnvVars;
|
||||
import hudson.Extension;
|
||||
import hudson.matrix.MatrixRun;
|
||||
import hudson.matrix.MatrixBuild;
|
||||
import hudson.matrix.MatrixRun;
|
||||
import hudson.model.EnvironmentContributor;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.TaskListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@Extension
|
||||
public class GiteeEnvironmentContributor extends EnvironmentContributor {
|
||||
|
||||
@Override
|
||||
public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException {
|
||||
public void buildEnvironmentFor(@NotNull Run r, @NotNull EnvVars envs, @NotNull TaskListener listener) throws IOException, InterruptedException {
|
||||
GiteeWebHookCause cause = null;
|
||||
if (r instanceof MatrixRun) {
|
||||
MatrixBuild parent = ((MatrixRun)r).getParentBuild();
|
||||
MatrixBuild parent = ((MatrixRun) r).getParentBuild();
|
||||
if (parent != null) {
|
||||
cause = (GiteeWebHookCause) parent.getCause(GiteeWebHookCause.class);
|
||||
cause = parent.getCause(GiteeWebHookCause.class);
|
||||
}
|
||||
} else {
|
||||
cause = (GiteeWebHookCause) r.getCause(GiteeWebHookCause.class);
|
||||
}
|
||||
if (cause != null) {
|
||||
envs.overrideAll(cause.getData().getBuildVariables());
|
||||
envs.overrideAll(cause.getData().getBuildEnvironmentVariables());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
package com.gitee.jenkins.event;
|
||||
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.entity.WebHookAction;
|
||||
import com.gitee.jenkins.enums.WebHookEvent;
|
||||
import hudson.ExtensionList;
|
||||
import hudson.ExtensionPoint;
|
||||
import hudson.model.Item;
|
||||
import hudson.model.Job;
|
||||
import hudson.security.ACL;
|
||||
import hudson.security.ACLContext;
|
||||
import hudson.util.HttpResponses;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class GiteeEventResolver implements ExtensionPoint {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(GiteeEventResolver.class.getName());
|
||||
|
||||
private static final Map<WebHookEvent, GiteeEventResolver> GITEE_EVENT_RESOLVER_MAP;
|
||||
|
||||
static {
|
||||
GITEE_EVENT_RESOLVER_MAP = ExtensionList.lookup(GiteeEventResolver.class).stream()
|
||||
.collect(Collectors.toMap(GiteeEventResolver::resolveEvent, Function.identity()));
|
||||
}
|
||||
|
||||
public static WebHookAction resolve(String projectName, StaplerRequest request) {
|
||||
WebHookEvent webHookEvent = resolveEvent(request);
|
||||
return GITEE_EVENT_RESOLVER_MAP.get(webHookEvent)
|
||||
.process(projectName, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析请求
|
||||
*
|
||||
* @param projectName
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private WebHookAction process(String projectName, StaplerRequest request) {
|
||||
String requestBody = resolveRequestBody(request);
|
||||
WebHook webHook = resolveWebHook(requestBody);
|
||||
webHook.setJsonBody(requestBody);
|
||||
String secretToken = request.getHeader("X-Gitee-Token");
|
||||
|
||||
try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) {
|
||||
Job<?, ?> job = resolveProject(projectName);
|
||||
|
||||
return WebHookAction.builder()
|
||||
.job(job)
|
||||
.webHook(webHook)
|
||||
.secretToken(secretToken)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析请求事件
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private static WebHookEvent resolveEvent(StaplerRequest request) {
|
||||
WebHookEvent webHookEvent = WebHookEvent.getWebHookEvent(request.getHeader("X-Gitee-Event"));
|
||||
if (webHookEvent != null) {
|
||||
return webHookEvent;
|
||||
}
|
||||
LOGGER.log(Level.INFO, "Missing X-Gitee-Event header");
|
||||
throw HttpResponses.errorWithoutStack(HttpServletResponse.SC_BAD_REQUEST, "Unsupported event");
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析请求体
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private static String resolveRequestBody(StaplerRequest request) {
|
||||
try {
|
||||
Charset charset = request.getCharacterEncoding() == null ? StandardCharsets.UTF_8 : Charset.forName(request.getCharacterEncoding());
|
||||
return IOUtils.toString(request.getInputStream(), charset);
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.INFO, "Failed to read request body");
|
||||
throw HttpResponses.errorWithoutStack(HttpServletResponse.SC_BAD_REQUEST, "Failed to read request body");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目
|
||||
*
|
||||
* @param projectName
|
||||
* @return
|
||||
*/
|
||||
private static Job<?, ?> resolveProject(String projectName) {
|
||||
Item item = Jenkins.get().getItemByFullName(projectName);
|
||||
if (item instanceof Job<?, ?>) {
|
||||
return (Job<?, ?>) item;
|
||||
}
|
||||
LOGGER.log(Level.INFO, "No project found: {0}", projectName);
|
||||
throw HttpResponses.errorWithoutStack(HttpServletResponse.SC_BAD_REQUEST, "No project found");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Handler 处理 WebHook 类型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract WebHookEvent resolveEvent();
|
||||
|
||||
/**
|
||||
* 获取 WebHook
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract WebHook resolveWebHook(String requestBody);
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.gitee.jenkins.event;
|
||||
|
||||
import com.gitee.jenkins.entity.CommitCommentWebHook;
|
||||
import com.gitee.jenkins.entity.PullRequestCommentWebHook;
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.WebHookEvent;
|
||||
import com.gitee.jenkins.util.JsonUtil;
|
||||
import hudson.Extension;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class NoteEventResolver extends GiteeEventResolver {
|
||||
|
||||
@Override
|
||||
protected WebHookEvent resolveEvent() {
|
||||
return WebHookEvent.NOTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WebHook resolveWebHook(String requestBody) {
|
||||
if (JsonUtil.has(requestBody, "pull_request")) {
|
||||
return JsonUtil.string2Obj(requestBody, PullRequestCommentWebHook.class);
|
||||
} else {
|
||||
return JsonUtil.string2Obj(requestBody, CommitCommentWebHook.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.gitee.jenkins.event;
|
||||
|
||||
import com.gitee.jenkins.entity.PullRequestWebHook;
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.WebHookEvent;
|
||||
import com.gitee.jenkins.util.JsonUtil;
|
||||
import hudson.Extension;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class PullRequestEventResolver extends GiteeEventResolver {
|
||||
|
||||
@Override
|
||||
protected WebHookEvent resolveEvent() {
|
||||
return WebHookEvent.PULL_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WebHook resolveWebHook(String requestBody) {
|
||||
return JsonUtil.string2Obj(requestBody, PullRequestWebHook.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.gitee.jenkins.event;
|
||||
|
||||
import com.gitee.jenkins.entity.PushWebHook;
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.WebHookEvent;
|
||||
import com.gitee.jenkins.util.JsonUtil;
|
||||
import hudson.Extension;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class PushEventResolver extends GiteeEventResolver {
|
||||
|
||||
@Override
|
||||
protected WebHookEvent resolveEvent() {
|
||||
return WebHookEvent.PUSH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WebHook resolveWebHook(String requestBody) {
|
||||
return JsonUtil.string2Obj(requestBody, PushWebHook.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.gitee.jenkins.event;
|
||||
|
||||
import com.gitee.jenkins.enums.WebHookEvent;
|
||||
import hudson.Extension;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class TagPushEventResolver extends PushEventResolver {
|
||||
|
||||
@Override
|
||||
protected WebHookEvent resolveEvent() {
|
||||
return WebHookEvent.TAG_PUSH;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.gitee.jenkins.excetion;
|
||||
|
||||
public class GiteeClientRequestException extends Exception {
|
||||
|
||||
public GiteeClientRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public GiteeClientRequestException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.gitee.jenkins.excetion;
|
||||
|
||||
public class NoRevisionToBuildException extends Exception {
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.gitee.jenkins.filter;
|
||||
|
||||
import com.gitee.jenkins.entity.PullRequestWebHook;
|
||||
import com.gitee.jenkins.entity.PushWebHook;
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
import com.gitee.jenkins.util.BuildUtil;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Job;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* 已经构建 commit 过滤器
|
||||
*/
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class AlreadyBuildCommitFilter extends BuildFilter {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(AlreadyBuildCommitFilter.class.getName());
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter(WebHookType webHookType) {
|
||||
return webHookType == WebHookType.PUSH
|
||||
|| webHookType == WebHookType.PULL_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doFilter(Job<?, ?> job, GiteeTrigger giteeTrigger, WebHook webHook) {
|
||||
boolean allowBuild = !giteeTrigger.isSkipLastCommitHasBeenBuild()
|
||||
|| (webHook.getWebHookType() == WebHookType.PUSH && !BuildUtil.hasBeenBuilt(job, ((PushWebHook) webHook).getAfter()))
|
||||
|| (webHook.getWebHookType() == WebHookType.PULL_REQUEST && !BuildUtil.hasBeenBuilt(job, ((PullRequestWebHook) webHook).getMergeCommitSha()));
|
||||
|
||||
if (!allowBuild) {
|
||||
LOGGER.log(Level.INFO, "Skip the build because ignore last commit has been build");
|
||||
}
|
||||
|
||||
return allowBuild;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.gitee.jenkins.filter;
|
||||
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.BranchNameFilterType;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Job;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* 分支名称过滤器
|
||||
*/
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class BranchNameFilter extends BuildFilter {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(BranchNameFilter.class.getName());
|
||||
|
||||
private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter(WebHookType webHookType) {
|
||||
return webHookType == WebHookType.PUSH
|
||||
|| webHookType == WebHookType.PULL_REQUEST
|
||||
|| webHookType == WebHookType.PULL_REQUEST_COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doFilter(Job<?, ?> job, GiteeTrigger giteeTrigger, WebHook webHook) {
|
||||
if (giteeTrigger.getBranchNameFilterType() == BranchNameFilterType.ALL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean allowBuild = false;
|
||||
|
||||
if (giteeTrigger.getBranchNameFilterType() == BranchNameFilterType.NAME_FILTER) {
|
||||
List<String> includeBranchNameList = getNameList(giteeTrigger.getIncludeBranchNames());
|
||||
List<String> excludeBranchNameList = getNameList(giteeTrigger.getExcludeBranchNames());
|
||||
allowBuild = (includeBranchNameList.isEmpty() || includeBranchNameList.stream().anyMatch(name -> ANT_PATH_MATCHER.match(name, webHook.getTargetBranch())))
|
||||
&& excludeBranchNameList.stream().noneMatch(name -> ANT_PATH_MATCHER.match(name, webHook.getTargetBranch()));
|
||||
} else if (giteeTrigger.getBranchNameFilterType() == BranchNameFilterType.REGEX_FILTER) {
|
||||
allowBuild = StringUtils.isBlank(giteeTrigger.getBranchNameRegex())
|
||||
|| webHook.getTargetBranch().matches(giteeTrigger.getBranchNameRegex());
|
||||
}
|
||||
|
||||
if (!allowBuild) {
|
||||
LOGGER.log(Level.INFO, "Skip the build because branch name mismatch");
|
||||
}
|
||||
|
||||
return allowBuild;
|
||||
}
|
||||
|
||||
private List<String> getNameList(String names) {
|
||||
return StringUtils.isBlank(names) ? Collections.emptyList() : Arrays.asList(names.split(","));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.gitee.jenkins.filter;
|
||||
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
import hudson.ExtensionList;
|
||||
import hudson.ExtensionPoint;
|
||||
import hudson.model.Job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BuildFilter implements ExtensionPoint {
|
||||
|
||||
private static final List<BuildFilter> BUILD_FILTER_LIST;
|
||||
|
||||
static {
|
||||
BUILD_FILTER_LIST = ExtensionList.lookup(BuildFilter.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* WebHook类型是否需要过滤
|
||||
*
|
||||
* @param webHookType WebHook类型
|
||||
* @return
|
||||
*/
|
||||
abstract boolean shouldFilter(WebHookType webHookType);
|
||||
|
||||
/**
|
||||
* 是否允许构建
|
||||
*
|
||||
* @param job 项目
|
||||
* @param giteeTrigger gitee触发器
|
||||
* @param webHook webHook
|
||||
* @return 是否允许构建
|
||||
*/
|
||||
abstract boolean doFilter(Job<?, ?> job, GiteeTrigger giteeTrigger, WebHook webHook);
|
||||
|
||||
/**
|
||||
* 执行过滤
|
||||
*
|
||||
* @param job 项目
|
||||
* @param giteeTrigger gitee触发器
|
||||
* @param webHook webHook
|
||||
* @return
|
||||
*/
|
||||
public static boolean allowBuild(Job<?, ?> job, GiteeTrigger giteeTrigger, WebHook webHook) {
|
||||
// 获取所有过滤器
|
||||
for (BuildFilter buildFilter : BUILD_FILTER_LIST) {
|
||||
// 是否需要过滤、是否允许构建
|
||||
if (buildFilter.shouldFilter(webHook.getWebHookType())
|
||||
&& !buildFilter.doFilter(job, giteeTrigger, webHook)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.gitee.jenkins.filter;
|
||||
|
||||
import com.gitee.jenkins.entity.PullRequestCommentWebHook;
|
||||
import com.gitee.jenkins.entity.PullRequestWebHook;
|
||||
import com.gitee.jenkins.entity.PushWebHook;
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.BuildInstructionFilterType;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Job;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* 构建指令过滤器
|
||||
*/
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class BuildInstructionFilter extends BuildFilter {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(BuildInstructionFilter.class.getName());
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter(WebHookType webHookType) {
|
||||
return webHookType == WebHookType.PUSH
|
||||
|| webHookType == WebHookType.PULL_REQUEST
|
||||
|| webHookType == WebHookType.PULL_REQUEST_COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doFilter(Job<?, ?> job, GiteeTrigger giteeTrigger, WebHook webHook) {
|
||||
if (giteeTrigger.getBuildInstructionFilterType() == BuildInstructionFilterType.NONE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String body = "";
|
||||
if (webHook.getWebHookType() == WebHookType.PUSH) {
|
||||
PushWebHook pushWebHook = (PushWebHook) webHook;
|
||||
if (CollectionUtils.isNotEmpty(pushWebHook.getCommits())) {
|
||||
body = pushWebHook.getCommits().get(pushWebHook.getCommits().size() - 1).getMessage();
|
||||
}
|
||||
} else if (webHook.getWebHookType() == WebHookType.PULL_REQUEST) {
|
||||
body = ((PullRequestWebHook) webHook).getBody();
|
||||
} else if (webHook.getWebHookType() == WebHookType.PULL_REQUEST_COMMENT) {
|
||||
body = ((PullRequestCommentWebHook) webHook).getPullRequest().getBody();
|
||||
}
|
||||
|
||||
boolean allowBuild = false;
|
||||
if (giteeTrigger.getBuildInstructionFilterType() == BuildInstructionFilterType.CI_SKIP) {
|
||||
allowBuild = !body.contains(BuildInstructionFilterType.CI_SKIP.getBody());
|
||||
} else if (giteeTrigger.getBuildInstructionFilterType() == BuildInstructionFilterType.CI_BUILD) {
|
||||
allowBuild = body.contains(BuildInstructionFilterType.CI_BUILD.getBody());
|
||||
}
|
||||
|
||||
if (!allowBuild) {
|
||||
LOGGER.log(Level.INFO, "Skip the build because build instruction dissatisfy");
|
||||
}
|
||||
|
||||
return allowBuild;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.gitee.jenkins.filter;
|
||||
|
||||
import com.gitee.jenkins.entity.CommitCommentWebHook;
|
||||
import com.gitee.jenkins.entity.PullRequestCommentWebHook;
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Job;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* 评论过滤器
|
||||
*/
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class CommentFilter extends BuildFilter {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(CommentFilter.class.getName());
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter(WebHookType webHookType) {
|
||||
return webHookType == WebHookType.PULL_REQUEST_COMMENT
|
||||
|| webHookType == WebHookType.COMMIT_COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doFilter(Job<?, ?> job, GiteeTrigger giteeTrigger, WebHook webHook) {
|
||||
boolean allowBuild = (webHook.getWebHookType() == WebHookType.PULL_REQUEST_COMMENT && ((PullRequestCommentWebHook) webHook).getComment().getBody().matches(giteeTrigger.getNoteRegex()))
|
||||
|| (webHook.getWebHookType() == WebHookType.COMMIT_COMMENT && ((CommitCommentWebHook) webHook).getComment().getBody().matches(giteeTrigger.getNoteRegex()));
|
||||
|
||||
if (!allowBuild) {
|
||||
LOGGER.log(Level.INFO, "Skip the build because the comment mismatch");
|
||||
}
|
||||
|
||||
return allowBuild;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.gitee.jenkins.filter;
|
||||
|
||||
import com.gitee.jenkins.entity.PullRequestWebHook;
|
||||
import com.gitee.jenkins.entity.PushWebHook;
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.PullRequestAction;
|
||||
import com.gitee.jenkins.enums.PullRequestState;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Job;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* webhook 配置过滤器
|
||||
*/
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class ConfigFilter extends BuildFilter {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ConfigFilter.class.getName());
|
||||
|
||||
private static final String NO_COMMIT = "0000000000000000000000000000000000000000";
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter(WebHookType webHookType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doFilter(Job<?, ?> job, GiteeTrigger giteeTrigger, WebHook webHook) {
|
||||
boolean allowBuild = false;
|
||||
|
||||
if (webHook.getWebHookType() == WebHookType.PUSH) {
|
||||
PushWebHook pushWebHook = (PushWebHook) webHook;
|
||||
// 是否允许推送触发 且 不是删除推送
|
||||
allowBuild = giteeTrigger.isTriggerOnPush()
|
||||
&& !isRemoveBranchPush(pushWebHook);
|
||||
} else if (webHook.getWebHookType() == WebHookType.PULL_REQUEST) {
|
||||
PullRequestWebHook pullRequestWebHook = (PullRequestWebHook) webHook;
|
||||
// 是否允许 PR 相关操作触发
|
||||
allowBuild = PullRequestAction.allowAction(giteeTrigger, pullRequestWebHook.getAction(), pullRequestWebHook.getActionDesc())
|
||||
&& PullRequestState.allowState(giteeTrigger, pullRequestWebHook.getState());
|
||||
} else if (webHook.getWebHookType() == WebHookType.PULL_REQUEST_COMMENT) {
|
||||
// 是否允许评论触发:PR 评论
|
||||
allowBuild = giteeTrigger.isTriggerOnNoteRequest();
|
||||
} else if (webHook.getWebHookType() == WebHookType.COMMIT_COMMENT) {
|
||||
// commit 评论
|
||||
allowBuild = giteeTrigger.isTriggerOnCommitComment();
|
||||
}
|
||||
|
||||
if (!allowBuild) {
|
||||
LOGGER.log(Level.INFO, "Skip the build because the web hook type configuration is not turned on");
|
||||
}
|
||||
|
||||
return allowBuild;
|
||||
}
|
||||
|
||||
public static boolean isRemoveBranchPush(PushWebHook pushWebHook) {
|
||||
return pushWebHook.getRef() == null || NO_COMMIT.equals(pushWebHook.getRef());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.gitee.jenkins.filter;
|
||||
|
||||
import com.gitee.jenkins.api.client.GiteeClient;
|
||||
import com.gitee.jenkins.config.GiteeItemConfig;
|
||||
import com.gitee.jenkins.entity.PullRequest;
|
||||
import com.gitee.jenkins.entity.PullRequestCommentWebHook;
|
||||
import com.gitee.jenkins.entity.PullRequestWebHook;
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.gitee.jenkins.excetion.GiteeClientRequestException;
|
||||
import com.gitee.jenkins.publisher.PullRequestBuildStatusPublisher;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Job;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* PR 冲突过滤器
|
||||
*/
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class PullRequestConflictFilter extends BuildFilter {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(PullRequestConflictFilter.class.getName());
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter(WebHookType webHookType) {
|
||||
return webHookType == WebHookType.PULL_REQUEST || webHookType == WebHookType.PULL_REQUEST_COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doFilter(Job<?, ?> job, GiteeTrigger giteeTrigger, WebHook webHook) {
|
||||
if (giteeTrigger.isIgnorePullRequestConflicts()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PullRequest pullRequest = null;
|
||||
if (webHook.getWebHookType() == WebHookType.PULL_REQUEST) {
|
||||
pullRequest = ((PullRequestWebHook) webHook).getPullRequest();
|
||||
} else if (webHook.getWebHookType() == WebHookType.PULL_REQUEST_COMMENT) {
|
||||
pullRequest = ((PullRequestCommentWebHook) webHook).getPullRequest();
|
||||
}
|
||||
|
||||
boolean allowBuild = pullRequest == null ? false : pullRequest.getMergeable();
|
||||
|
||||
if (!allowBuild) {
|
||||
LOGGER.log(Level.INFO, "Skip the build because the Pull Request can\'t be merge");
|
||||
|
||||
// 发送 PR 冲突评论
|
||||
PullRequestBuildStatusPublisher pullRequestBuildStatusPublisher = PullRequestBuildStatusPublisher.getPullRequestBuildStatusPublisher(job);
|
||||
if (pullRequest != null && pullRequestBuildStatusPublisher != null && !pullRequestBuildStatusPublisher.isOnlyForFailure()) {
|
||||
GiteeClient giteeClient = GiteeItemConfig.getGiteeClient(job);
|
||||
if (giteeClient != null) {
|
||||
try {
|
||||
String[] path = pullRequest.getBase().getRepo().getPathWithNamespace().split("/");
|
||||
giteeClient.submitPullRequestComments(
|
||||
path[0],
|
||||
path[1],
|
||||
pullRequest.getNumber(),
|
||||
":bangbang: This pull request can not be merge! The build will not be triggered. Please manual merge conflict."
|
||||
);
|
||||
LOGGER.log(Level.INFO, "send Pull Request conflict message to gitee success");
|
||||
} catch (GiteeClientRequestException e) {
|
||||
LOGGER.log(Level.WARNING, "send Pull Request conflict message error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allowBuild;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.gitee.jenkins.filter;
|
||||
|
||||
import com.gitee.jenkins.entity.PullRequestCommentWebHook;
|
||||
import com.gitee.jenkins.entity.PullRequestWebHook;
|
||||
import com.gitee.jenkins.entity.WebHook;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.gitee.jenkins.trigger.GiteeTrigger;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Job;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* PR 是否测试过滤器
|
||||
*/
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class PullRequestTestFilter extends BuildFilter {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(PullRequestTestFilter.class.getName());
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter(WebHookType webHookType) {
|
||||
return webHookType == WebHookType.PULL_REQUEST
|
||||
|| webHookType == WebHookType.PULL_REQUEST_COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doFilter(Job<?, ?> job, GiteeTrigger giteeTrigger, WebHook webHook) {
|
||||
boolean allowBuild = !giteeTrigger.isCiSkipFroTestNotRequired()
|
||||
|| (webHook.getWebHookType() == WebHookType.PULL_REQUEST && ((PullRequestWebHook) webHook).getPullRequest().getNeedTest())
|
||||
|| (webHook.getWebHookType() == WebHookType.PULL_REQUEST_COMMENT && ((PullRequestCommentWebHook) webHook).getPullRequest().getNeedTest());
|
||||
|
||||
if (!allowBuild) {
|
||||
LOGGER.log(Level.INFO, "Skip the build because the Pull Request don\'t need test.");
|
||||
}
|
||||
|
||||
return allowBuild;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.gitee.jenkins.gitee;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.ext.ContextResolver;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@Provider
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class JacksonConfig implements ContextResolver<ObjectMapper> {
|
||||
public ObjectMapper getContext(Class<?> type) {
|
||||
return new ObjectMapper()
|
||||
.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api;
|
||||
|
||||
import com.gitee.jenkins.gitee.api.model.*;
|
||||
|
||||
public interface GiteeClient {
|
||||
String getHostUrl();
|
||||
|
||||
void acceptPullRequest(PullRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch);
|
||||
|
||||
void createPullRequestNote(PullRequest mr, String body);
|
||||
|
||||
User getCurrentUser();
|
||||
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api;
|
||||
|
||||
|
||||
import hudson.ExtensionPoint;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static java.util.Collections.sort;
|
||||
|
||||
@Restricted(NoExternalUse.class)
|
||||
public abstract class GiteeClientBuilder implements Comparable<GiteeClientBuilder>, ExtensionPoint, Serializable {
|
||||
public static GiteeClientBuilder getGiteeClientBuilderById(String id) {
|
||||
id = "v5";
|
||||
for (GiteeClientBuilder provider : getAllGiteeClientBuilders()) {
|
||||
if (provider.id().equals(id)) {
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NoSuchElementException("unknown client-builder-id: " + id);
|
||||
}
|
||||
|
||||
public static List<GiteeClientBuilder> getAllGiteeClientBuilders() {
|
||||
List<GiteeClientBuilder> builders = new ArrayList<>(Jenkins.getInstance().getExtensionList(GiteeClientBuilder.class));
|
||||
sort(builders);
|
||||
return builders;
|
||||
}
|
||||
|
||||
private final String id;
|
||||
private final int ordinal;
|
||||
|
||||
protected GiteeClientBuilder(String id, int ordinal) {
|
||||
this.id = id;
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public final String id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public abstract GiteeClient buildClient(String url, String token, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout);
|
||||
|
||||
@Override
|
||||
public final int compareTo(@Nonnull GiteeClientBuilder other) {
|
||||
int o = ordinal - other.ordinal;
|
||||
return o != 0 ? o : id().compareTo(other.id());
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.impl;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.api.model.*;
|
||||
|
||||
|
||||
|
||||
interface GiteeApiProxy {
|
||||
void createPullRequestNote(String owner, String repo, Integer pullRequestId, String body);
|
||||
void headCurrentUser();
|
||||
void acceptPullRequest(String owner, String repo, Integer pullRequestId);
|
||||
User getCurrentUser();
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.impl;
|
||||
|
||||
import com.gitee.jenkins.gitee.api.model.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
* @author Yashin Luo
|
||||
*
|
||||
*/
|
||||
@Path("/api/v5")
|
||||
interface GiteeV5ApiProxy extends GiteeApiProxy {
|
||||
String ID = "v5";
|
||||
@PUT
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
@Path("/repos/{ownerPath}/{repoPath}/pulls/{prNumber}/merge")
|
||||
void acceptPullRequest(@PathParam("ownerPath") String ownerPath,
|
||||
@PathParam("repoPath") String repoPath,
|
||||
@PathParam("prNumber") Integer prNumber);
|
||||
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
@Path("/repos/{ownerPath}/{repoPath}/pulls/{prNumber}/comments")
|
||||
void createPullRequestNote(@PathParam("ownerPath") String ownerPath,
|
||||
@PathParam("repoPath") String repoPath,
|
||||
@PathParam("prNumber") Integer prNumber,
|
||||
@FormParam("body") String body);
|
||||
|
||||
@HEAD
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/user")
|
||||
void headCurrentUser();
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/user")
|
||||
User getCurrentUser();
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.impl;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.api.model.PullRequest;
|
||||
import com.google.common.base.Function;
|
||||
import hudson.Extension;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public final class GiteeV5ClientBuilder extends ResteasyGiteeClientBuilder {
|
||||
private static final int ORDINAL = 3;
|
||||
private static final Function<PullRequest, Integer> MERGE_REQUEST_ID_PROVIDER = new Function<PullRequest, Integer>() {
|
||||
@Override
|
||||
public Integer apply(PullRequest pullRequest) {
|
||||
return pullRequest.getIid();
|
||||
}
|
||||
};
|
||||
|
||||
public GiteeV5ClientBuilder() {
|
||||
super(GiteeV5ApiProxy.ID, ORDINAL, GiteeV5ApiProxy.class, MERGE_REQUEST_ID_PROVIDER);
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.impl;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.model.*;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
||||
final class ResteasyGiteeClient implements GiteeClient {
|
||||
private final String hostUrl;
|
||||
private final GiteeApiProxy api;
|
||||
private final Function<PullRequest, Integer> pullRequestIdProvider;
|
||||
|
||||
|
||||
ResteasyGiteeClient(String hostUrl, GiteeApiProxy api, Function<PullRequest, Integer> pullRequestIdProvider) {
|
||||
this.hostUrl = hostUrl;
|
||||
this.api = api;
|
||||
this.pullRequestIdProvider = pullRequestIdProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getHostUrl() {
|
||||
return hostUrl;
|
||||
}
|
||||
|
||||
// Gitee v5 don't support commit message and remove source branch
|
||||
@Override
|
||||
public void acceptPullRequest(PullRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch) {
|
||||
api.acceptPullRequest(mr.getRepoOwner(), mr.getRepoPath(), mr.getIid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPullRequestNote(PullRequest mr, String body) {
|
||||
api.createPullRequestNote(mr.getRepoOwner(), mr.getRepoPath(), mr.getIid(), body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return api.getCurrentUser();
|
||||
}
|
||||
}
|
|
@ -1,255 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.impl;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.JacksonConfig;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClientBuilder;
|
||||
import com.gitee.jenkins.gitee.api.model.PullRequest;
|
||||
import com.gitee.jenkins.util.JsonUtil;
|
||||
import com.gitee.jenkins.util.LoggerUtil;
|
||||
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import hudson.ProxyConfiguration;
|
||||
import hudson.init.InitMilestone;
|
||||
import hudson.init.Initializer;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.jboss.resteasy.client.jaxrs.ClientHttpEngine;
|
||||
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine;
|
||||
import org.jboss.resteasy.plugins.providers.JaxrsFormProvider;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Priority;
|
||||
import javax.ws.rs.Priorities;
|
||||
import javax.ws.rs.client.ClientRequestContext;
|
||||
import javax.ws.rs.client.ClientRequestFilter;
|
||||
import javax.ws.rs.client.ClientResponseContext;
|
||||
import javax.ws.rs.client.ClientResponseFilter;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.ext.RuntimeDelegate;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.net.Proxy.Type.HTTP;
|
||||
|
||||
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class ResteasyGiteeClientBuilder extends GiteeClientBuilder {
|
||||
private static final Logger LOGGER = Logger.getLogger(ResteasyGiteeClientBuilder.class.getName());
|
||||
private static final String PRIVATE_TOKEN = "PRIVATE-TOKEN";
|
||||
|
||||
@Initializer(before = InitMilestone.PLUGINS_STARTED)
|
||||
public static void setRuntimeDelegate() {
|
||||
RuntimeDelegate.setInstance(new ResteasyProviderFactory());
|
||||
}
|
||||
|
||||
private final Class<? extends GiteeApiProxy> apiProxyClass;
|
||||
private final Function<PullRequest, Integer> pullRequestIdProvider;
|
||||
|
||||
ResteasyGiteeClientBuilder(String id, int ordinal, Class<? extends GiteeApiProxy> apiProxyClass, Function<PullRequest, Integer> pullRequestIdProvider) {
|
||||
super(id, ordinal);
|
||||
this.apiProxyClass = apiProxyClass;
|
||||
this.pullRequestIdProvider = pullRequestIdProvider;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final GiteeClient buildClient(String url, String apiToken, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
return buildClient(
|
||||
url,
|
||||
apiToken,
|
||||
Jenkins.getActiveInstance().proxy,
|
||||
ignoreCertificateErrors,
|
||||
connectionTimeout,
|
||||
readTimeout
|
||||
);
|
||||
}
|
||||
|
||||
private GiteeClient buildClient(String url, String apiToken, ProxyConfiguration httpProxyConfig, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) {
|
||||
ResteasyClientBuilder builder = new ResteasyClientBuilder();
|
||||
|
||||
if (ignoreCertificateErrors) {
|
||||
builder.hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY);
|
||||
builder.disableTrustManager();
|
||||
}
|
||||
|
||||
if (httpProxyConfig != null) {
|
||||
Proxy proxy = httpProxyConfig.createProxy(getHost(url));
|
||||
if (proxy.type() == HTTP) {
|
||||
InetSocketAddress address = (InetSocketAddress) proxy.address();
|
||||
builder.defaultProxy(address.getHostString().replaceFirst("^.*://", ""),
|
||||
address.getPort(),
|
||||
address.getHostName().startsWith("https") ? "https" : "http",
|
||||
httpProxyConfig.getUserName(),
|
||||
httpProxyConfig.getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
GiteeApiProxy apiProxy = builder
|
||||
.connectionPoolSize(60)
|
||||
.maxPooledPerRoute(30)
|
||||
.establishConnectionTimeout(connectionTimeout, TimeUnit.SECONDS)
|
||||
.socketTimeout(readTimeout, TimeUnit.SECONDS)
|
||||
.register(new JacksonJsonProvider())
|
||||
.register(new JacksonConfig())
|
||||
.register(new ApiHeaderTokenFilter(apiToken))
|
||||
.register(new LoggingFilter())
|
||||
.register(new RemoveAcceptEncodingFilter())
|
||||
.register(new JaxrsFormProvider())
|
||||
.build().target(url)
|
||||
.proxyBuilder(apiProxyClass)
|
||||
.classloader(apiProxyClass.getClassLoader())
|
||||
.build();
|
||||
|
||||
return new ResteasyGiteeClient(url, apiProxy, pullRequestIdProvider);
|
||||
}
|
||||
|
||||
private String getHost(String url) {
|
||||
try {
|
||||
return new URL(url).getHost();
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Priority(Priorities.HEADER_DECORATOR)
|
||||
private static class ApiHeaderTokenFilter implements ClientRequestFilter {
|
||||
private final String giteeApiToken;
|
||||
|
||||
ApiHeaderTokenFilter(String giteeApiToken) {
|
||||
this.giteeApiToken = giteeApiToken;
|
||||
}
|
||||
|
||||
public void filter(ClientRequestContext requestContext) {
|
||||
requestContext.getHeaders().putSingle(PRIVATE_TOKEN, giteeApiToken);
|
||||
}
|
||||
}
|
||||
|
||||
@Priority(Priorities.USER)
|
||||
private static class LoggingFilter implements ClientRequestFilter, ClientResponseFilter {
|
||||
@Override
|
||||
public void filter(ClientRequestContext context) {
|
||||
if (LOGGER.isLoggable(Level.FINEST)) {
|
||||
LOGGER.log(Level.FINEST, "Call Gitee:\nHTTP method: {0}\nURL: {1}\nRequest headers: [\n{2}\n]",
|
||||
LoggerUtil.toArray(context.getMethod(), context.getUri(), toFilteredString(context.getHeaders())));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void filter(ClientRequestContext request, ClientResponseContext response) {
|
||||
if (LOGGER.isLoggable(Level.FINEST)) {
|
||||
LOGGER.log(Level.FINEST, "Got response from Gitee:\nURL: {0}\nStatus: {1} {2}\nResponse headers: [\n{3}\n]\nResponse body: {4}",
|
||||
LoggerUtil.toArray(request.getUri(), response.getStatus(), response.getStatusInfo(), toString(response.getHeaders()),
|
||||
getPrettyPrintResponseBody(response)));
|
||||
}
|
||||
}
|
||||
|
||||
private String toFilteredString(MultivaluedMap<String, Object> headers) {
|
||||
return FluentIterable.from(headers.entrySet()).transform(new HeaderToFilteredString()).join(Joiner.on(",\n"));
|
||||
}
|
||||
|
||||
private String toString(MultivaluedMap<String, String> headers) {
|
||||
return FluentIterable.from(headers.entrySet()).transform(new HeaderToString()).join(Joiner.on(",\n"));
|
||||
}
|
||||
|
||||
private String getPrettyPrintResponseBody(ClientResponseContext responseContext) {
|
||||
String responseBody = getResponseBody(responseContext);
|
||||
if (StringUtils.isNotEmpty(responseBody) && responseContext.getMediaType().equals(MediaType.APPLICATION_JSON_TYPE)) {
|
||||
return JsonUtil.toPrettyPrint(responseBody);
|
||||
}
|
||||
return responseBody;
|
||||
}
|
||||
|
||||
private String getResponseBody(ClientResponseContext context) {
|
||||
try (InputStream entityStream = context.getEntityStream()) {
|
||||
if (entityStream != null) {
|
||||
byte[] bytes = IOUtils.toByteArray(entityStream);
|
||||
context.setEntityStream(new ByteArrayInputStream(bytes));
|
||||
return new String(bytes);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Failure during reading the response body", e);
|
||||
context.setEntityStream(new ByteArrayInputStream(new byte[0]));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static class HeaderToFilteredString implements Function<Map.Entry<String, List<Object>>, String> {
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(@Nullable Map.Entry<String, List<Object>> input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
} else if (input.getKey().equals(PRIVATE_TOKEN)) {
|
||||
return input.getKey() + " = [****FILTERED****]";
|
||||
} else {
|
||||
return input.getKey() + " = [" + Joiner.on(", ").join(input.getValue()) + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class HeaderToString implements Function<Map.Entry<String, List<String>>, String> {
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(@Nullable Map.Entry<String, List<String>> input) {
|
||||
return input == null ? null : input.getKey() + " = [" + Joiner.on(", ").join(input.getValue()) + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Priority(Priorities.HEADER_DECORATOR)
|
||||
private static class RemoveAcceptEncodingFilter implements ClientRequestFilter {
|
||||
RemoveAcceptEncodingFilter() {}
|
||||
@Override
|
||||
public void filter(ClientRequestContext clientRequestContext) {
|
||||
clientRequestContext.getHeaders().remove("Accept-Encoding");
|
||||
}
|
||||
}
|
||||
|
||||
private static class ResteasyClientBuilder extends org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder {
|
||||
private CredentialsProvider proxyCredentials;
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
ResteasyClientBuilder defaultProxy(String hostname, int port, final String scheme, String username, String password) {
|
||||
super.defaultProxy(hostname, port, scheme);
|
||||
if (username != null && password != null) {
|
||||
proxyCredentials = new BasicCredentialsProvider();
|
||||
proxyCredentials.setCredentials(new AuthScope(hostname, port), new UsernamePasswordCredentials(username, password));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected ClientHttpEngine initDefaultEngine() {
|
||||
ApacheHttpClient4Engine httpEngine = (ApacheHttpClient4Engine) super.initDefaultEngine();
|
||||
if (proxyCredentials != null) {
|
||||
((DefaultHttpClient) httpEngine.getHttpClient()).setCredentialsProvider(proxyCredentials);
|
||||
}
|
||||
return httpEngine;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Branch {
|
||||
|
||||
private String name;
|
||||
private Boolean protectedBranch;
|
||||
private Commit commit;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Boolean getProtectedBranch() {
|
||||
return protectedBranch;
|
||||
}
|
||||
|
||||
public void setProtectedBranch(Boolean protectedBranch) {
|
||||
this.protectedBranch = protectedBranch;
|
||||
}
|
||||
|
||||
public Commit getCommit() {
|
||||
return commit;
|
||||
}
|
||||
|
||||
public void setCommit(Commit commit) {
|
||||
this.commit = commit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Branch branch = (Branch) o;
|
||||
return new EqualsBuilder()
|
||||
.append(name, branch.name)
|
||||
.append(protectedBranch, branch.protectedBranch)
|
||||
.append(commit, branch.commit)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(name)
|
||||
.append(protectedBranch)
|
||||
.append(commit)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("name", name)
|
||||
.append("protectedBranch", protectedBranch)
|
||||
.append("commit", commit)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public enum BuildState {
|
||||
pending, running, canceled, success, failed
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Commit {
|
||||
|
||||
private String id;
|
||||
private String message;
|
||||
private Date authoredDate;
|
||||
private String authorName;
|
||||
private String authorEmail;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Date getAuthoredDate() {
|
||||
return authoredDate;
|
||||
}
|
||||
|
||||
public void setAuthoredDate(Date authoredDate) {
|
||||
this.authoredDate = authoredDate;
|
||||
}
|
||||
|
||||
public String getAuthorName() {
|
||||
return authorName;
|
||||
}
|
||||
|
||||
public void setAuthorName(String authorName) {
|
||||
this.authorName = authorName;
|
||||
}
|
||||
|
||||
public String getAuthorEmail() {
|
||||
return authorEmail;
|
||||
}
|
||||
|
||||
public void setAuthorEmail(String authorEmail) {
|
||||
this.authorEmail = authorEmail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Commit commit = (Commit) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, commit.id)
|
||||
.append(message, commit.message)
|
||||
.append(authoredDate, commit.authoredDate)
|
||||
.append(authorName, commit.authorName)
|
||||
.append(authorEmail, commit.authorEmail)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(message)
|
||||
.append(authoredDate)
|
||||
.append(authorName)
|
||||
.append(authorEmail)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("message", message)
|
||||
.append("authoredDate", authoredDate)
|
||||
.append("authorName", authorName)
|
||||
.append("authorEmail", authorEmail)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Label {
|
||||
/*
|
||||
"name" : "bug",
|
||||
"color" : "#d9534f",
|
||||
"description": "Bug reported by user",
|
||||
"open_issues_count": 1,
|
||||
"closed_issues_count": 0,
|
||||
"open_merge_requests_count": 1
|
||||
*/
|
||||
private String name;
|
||||
private String color;
|
||||
private String description;
|
||||
private long openIssuesCount;
|
||||
private long closedIssuesCount;
|
||||
private long openPullRequestsCount;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public long getOpenIssuesCount() {
|
||||
return openIssuesCount;
|
||||
}
|
||||
|
||||
public void setOpenIssuesCount(long openIssuesCount) {
|
||||
this.openIssuesCount = openIssuesCount;
|
||||
}
|
||||
|
||||
public long getClosedIssuesCount() {
|
||||
return closedIssuesCount;
|
||||
}
|
||||
|
||||
public void setClosedIssuesCount(long closedIssuesCount) {
|
||||
this.closedIssuesCount = closedIssuesCount;
|
||||
}
|
||||
|
||||
public long getOpenPullRequestsCount() {
|
||||
return openPullRequestsCount;
|
||||
}
|
||||
|
||||
public void setOpenPullRequestsCount(long openPullRequestsCount) {
|
||||
this.openPullRequestsCount = openPullRequestsCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Label label = (Label) o;
|
||||
return new EqualsBuilder()
|
||||
.append(openIssuesCount, label.openIssuesCount)
|
||||
.append(closedIssuesCount, label.closedIssuesCount)
|
||||
.append(openPullRequestsCount, label.openPullRequestsCount)
|
||||
.append(name, label.name)
|
||||
.append(color, label.color)
|
||||
.append(description, label.description)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(name)
|
||||
.append(color)
|
||||
.append(description)
|
||||
.append(openIssuesCount)
|
||||
.append(closedIssuesCount)
|
||||
.append(openPullRequestsCount)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("name", name)
|
||||
.append("color", color)
|
||||
.append("description", description)
|
||||
.append("openIssuesCount", openIssuesCount)
|
||||
.append("closedIssuesCount", closedIssuesCount)
|
||||
.append("openPullRequestsCount", openPullRequestsCount)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Namespace {
|
||||
|
||||
private String path;
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Namespace namespace = (Namespace) o;
|
||||
return new EqualsBuilder()
|
||||
.append(path, namespace.path)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(path)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("path", path)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Note {
|
||||
private Integer id;
|
||||
private Integer projectId;
|
||||
private User author;
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
private String body;
|
||||
|
||||
public Note() {}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public void setprojectId(Integer projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public User getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(User author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(Date updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Note that = (Note) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, that.id)
|
||||
.append(projectId, that.projectId)
|
||||
.append(author, that.author)
|
||||
.append(createdAt, that.createdAt)
|
||||
.append(updatedAt, that.updatedAt)
|
||||
.append(body, that.body)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(projectId)
|
||||
.append(author)
|
||||
.append(createdAt)
|
||||
.append(updatedAt)
|
||||
.append(body)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("projectId", projectId)
|
||||
.append("author", author)
|
||||
.append("createdAt", createdAt)
|
||||
.append("updatedAt", updatedAt)
|
||||
.append("body", body)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Pipeline {
|
||||
private Integer id;
|
||||
private String sha;
|
||||
private String status;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSha() {
|
||||
return sha;
|
||||
}
|
||||
|
||||
public void setSha(String sha) {
|
||||
this.sha = sha;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Project {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Namespace namespace;
|
||||
private String webUrl;
|
||||
private String sshUrlToRepo;
|
||||
private String httpUrlToRepo;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Namespace getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public void setNamespace(Namespace namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public String getWebUrl() {
|
||||
return webUrl;
|
||||
}
|
||||
|
||||
public void setWebUrl(String webUrl) {
|
||||
this.webUrl = webUrl;
|
||||
}
|
||||
|
||||
public String getSshUrlToRepo() {
|
||||
return sshUrlToRepo;
|
||||
}
|
||||
|
||||
public void setSshUrlToRepo(String sshUrlToRepo) {
|
||||
this.sshUrlToRepo = sshUrlToRepo;
|
||||
}
|
||||
|
||||
public String getHttpUrlToRepo() {
|
||||
return httpUrlToRepo;
|
||||
}
|
||||
|
||||
public void setHttpUrlToRepo(String httpUrlToRepo) {
|
||||
this.httpUrlToRepo = httpUrlToRepo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Project project = (Project) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, project.id)
|
||||
.append(name, project.name)
|
||||
.append(webUrl, project.webUrl)
|
||||
.append(sshUrlToRepo, project.sshUrlToRepo)
|
||||
.append(httpUrlToRepo, project.httpUrlToRepo)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(name)
|
||||
.append(webUrl)
|
||||
.append(sshUrlToRepo)
|
||||
.append(httpUrlToRepo)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("name", name)
|
||||
.append("webUrl", webUrl)
|
||||
.append("sshUrlToRepo", sshUrlToRepo)
|
||||
.append("httpUrlToRepo", httpUrlToRepo)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,339 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.PullRequestObjectAttributes;
|
||||
import com.gitee.jenkins.gitee.hook.model.State;
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class PullRequest {
|
||||
private Integer id;
|
||||
private Integer iid;
|
||||
private String sourceBranch;
|
||||
private String targetBranch;
|
||||
private Integer projectId;
|
||||
private String title;
|
||||
private State state;
|
||||
private Integer upvotes;
|
||||
private Integer downvotes;
|
||||
private User author;
|
||||
private User assignee;
|
||||
private Integer sourceProjectId;
|
||||
private Integer targetProjectId;
|
||||
private List<String> labels;
|
||||
private String description;
|
||||
private Boolean workInProgress;
|
||||
private Boolean mergeWhenBuildSucceeds;
|
||||
private String mergeStatus;
|
||||
private String repoOwner;
|
||||
private String repoPath;
|
||||
|
||||
public PullRequest() { /* default-constructor for Resteasy-based-api-proxies */ }
|
||||
|
||||
public PullRequest(int id, int iid, String sourceBranch, String targetBranch, String title,
|
||||
int sourceProjectId, int targetProjectId,
|
||||
String description, String mergeStatus) {
|
||||
this.id = id;
|
||||
this.iid= iid;
|
||||
this.sourceBranch = sourceBranch;
|
||||
this.targetBranch = targetBranch;
|
||||
this.title = title;
|
||||
this.sourceProjectId = sourceProjectId;
|
||||
this.projectId = targetProjectId;
|
||||
this.description = description;
|
||||
this.mergeStatus = mergeStatus;
|
||||
}
|
||||
|
||||
public PullRequest(PullRequestObjectAttributes objectAttributes) {
|
||||
this.id = objectAttributes.getId();
|
||||
this.iid= objectAttributes.getNumber();
|
||||
this.sourceBranch = objectAttributes.getSourceBranch();
|
||||
this.targetBranch = objectAttributes.getTargetBranch();
|
||||
this.title = objectAttributes.getTitle();
|
||||
this.sourceProjectId = objectAttributes.getSourceProjectId();
|
||||
this.projectId = objectAttributes.getTargetProjectId();
|
||||
this.description = objectAttributes.getBody();
|
||||
this.mergeStatus = objectAttributes.getMergeStatus();
|
||||
|
||||
// try {
|
||||
String[] path = objectAttributes.getTarget().getPathWithNamespace().split("/");
|
||||
this.repoOwner = path[0];
|
||||
this.repoPath = path[1];
|
||||
// } catch (Exception e) {
|
||||
// // do nothing
|
||||
// }
|
||||
}
|
||||
|
||||
public PullRequest(int id, int iid, String sourceBranch, String targetBranch, String title,
|
||||
int sourceProjectId, int targetProjectId,
|
||||
String description, String mergeStatus, String pathWithNamespace) {
|
||||
this.id = id;
|
||||
this.iid= iid;
|
||||
this.sourceBranch = sourceBranch;
|
||||
this.targetBranch = targetBranch;
|
||||
this.title = title;
|
||||
this.sourceProjectId = sourceProjectId;
|
||||
this.projectId = targetProjectId;
|
||||
this.description = description;
|
||||
this.mergeStatus = mergeStatus;
|
||||
try {
|
||||
String[] path = pathWithNamespace.split("/");
|
||||
this.repoOwner = path[0];
|
||||
this.repoPath = path[1];
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getIid() {
|
||||
return iid;
|
||||
}
|
||||
|
||||
public void setIid(Integer iid) {
|
||||
this.iid = iid;
|
||||
}
|
||||
|
||||
public String getSourceBranch() {
|
||||
return sourceBranch;
|
||||
}
|
||||
|
||||
public void setSourceBranch(String sourceBranch) {
|
||||
this.sourceBranch = sourceBranch;
|
||||
}
|
||||
|
||||
public String getTargetBranch() {
|
||||
return targetBranch;
|
||||
}
|
||||
|
||||
public void setTargetBranch(String targetBranch) {
|
||||
this.targetBranch = targetBranch;
|
||||
}
|
||||
|
||||
public Integer getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public void setProjectId(Integer projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Integer getUpvotes() {
|
||||
return upvotes;
|
||||
}
|
||||
|
||||
public void setUpvotes(Integer upvotes) {
|
||||
this.upvotes = upvotes;
|
||||
}
|
||||
|
||||
public Integer getDownvotes() {
|
||||
return downvotes;
|
||||
}
|
||||
|
||||
public void setDownvotes(Integer downvotes) {
|
||||
this.downvotes = downvotes;
|
||||
}
|
||||
|
||||
public User getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(User author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public User getAssignee() {
|
||||
return assignee;
|
||||
}
|
||||
|
||||
public void setAssignee(User assignee) {
|
||||
this.assignee = assignee;
|
||||
}
|
||||
|
||||
public Integer getSourceProjectId() {
|
||||
return sourceProjectId;
|
||||
}
|
||||
|
||||
public void setSourceProjectId(Integer sourceProjectId) {
|
||||
this.sourceProjectId = sourceProjectId;
|
||||
}
|
||||
|
||||
public Integer getTargetProjectId() {
|
||||
return targetProjectId;
|
||||
}
|
||||
|
||||
public void setTargetProjectId(Integer targetProjectId) {
|
||||
this.targetProjectId = targetProjectId;
|
||||
}
|
||||
|
||||
public List<String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public void setLabels(List<String> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Boolean getWorkInProgress() {
|
||||
return workInProgress;
|
||||
}
|
||||
|
||||
public void setWorkInProgress(Boolean workInProgress) {
|
||||
this.workInProgress = workInProgress;
|
||||
}
|
||||
|
||||
public Boolean getMergeWhenBuildSucceeds() {
|
||||
return mergeWhenBuildSucceeds;
|
||||
}
|
||||
|
||||
public void setMergeWhenBuildSucceeds(Boolean mergeWhenBuildSucceeds) {
|
||||
this.mergeWhenBuildSucceeds = mergeWhenBuildSucceeds;
|
||||
}
|
||||
|
||||
public String getMergeStatus() {
|
||||
return mergeStatus;
|
||||
}
|
||||
|
||||
public void setMergeStatus(String mergeStatus) {
|
||||
this.mergeStatus = mergeStatus;
|
||||
}
|
||||
|
||||
public String getRepoOwner() {
|
||||
return repoOwner;
|
||||
}
|
||||
|
||||
public void setRepoOwner(String repoOwner) {
|
||||
this.repoOwner = repoOwner;
|
||||
}
|
||||
|
||||
public String getRepoPath() {
|
||||
return repoPath;
|
||||
}
|
||||
|
||||
public void setRepoPath(String repoPath) {
|
||||
this.repoPath = repoPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PullRequest that = (PullRequest) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, that.id)
|
||||
.append(iid, that.iid)
|
||||
.append(sourceBranch, that.sourceBranch)
|
||||
.append(targetBranch, that.targetBranch)
|
||||
.append(projectId, that.projectId)
|
||||
.append(title, that.title)
|
||||
.append(state, that.state)
|
||||
.append(upvotes, that.upvotes)
|
||||
.append(downvotes, that.downvotes)
|
||||
.append(author, that.author)
|
||||
.append(assignee, that.assignee)
|
||||
.append(sourceProjectId, that.sourceProjectId)
|
||||
.append(targetProjectId, that.targetProjectId)
|
||||
.append(labels, that.labels)
|
||||
.append(description, that.description)
|
||||
.append(workInProgress, that.workInProgress)
|
||||
.append(mergeWhenBuildSucceeds, that.mergeWhenBuildSucceeds)
|
||||
.append(mergeStatus, that.mergeStatus)
|
||||
.append(repoPath, that.repoPath)
|
||||
.append(repoOwner, that.repoOwner)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(iid)
|
||||
.append(sourceBranch)
|
||||
.append(targetBranch)
|
||||
.append(projectId)
|
||||
.append(title)
|
||||
.append(state)
|
||||
.append(upvotes)
|
||||
.append(downvotes)
|
||||
.append(author)
|
||||
.append(assignee)
|
||||
.append(sourceProjectId)
|
||||
.append(targetProjectId)
|
||||
.append(labels)
|
||||
.append(description)
|
||||
.append(workInProgress)
|
||||
.append(mergeWhenBuildSucceeds)
|
||||
.append(mergeStatus)
|
||||
.append(repoOwner)
|
||||
.append(repoPath)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("iid", iid)
|
||||
.append("sourceBranch", sourceBranch)
|
||||
.append("targetBranch", targetBranch)
|
||||
.append("projectId", projectId)
|
||||
.append("title", title)
|
||||
.append("state", state)
|
||||
.append("upvotes", upvotes)
|
||||
.append("downvotes", downvotes)
|
||||
.append("author", author)
|
||||
.append("assignee", assignee)
|
||||
.append("sourceProjectId", sourceProjectId)
|
||||
.append("targetProjectId", targetProjectId)
|
||||
.append("labels", labels)
|
||||
.append("description", description)
|
||||
.append("workInProgress", workInProgress)
|
||||
.append("mergeWhenBuildSucceeds", mergeWhenBuildSucceeds)
|
||||
.append("mergeStatus", mergeStatus)
|
||||
.append("repoOwner", repoOwner)
|
||||
.append("repoPath", repoPath)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class User {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String username;
|
||||
private String email;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
User user = (User) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, user.id)
|
||||
.append(name, user.name)
|
||||
.append(username, user.username)
|
||||
.append(email, user.email)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(name)
|
||||
.append(username)
|
||||
.append(email)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("name", name)
|
||||
.append("username", username)
|
||||
.append("email", email)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public enum Action {
|
||||
open, update, approved, close, merge, tested
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
/**
|
||||
* @author Yashin Luo
|
||||
*/
|
||||
public enum ActionDesc {
|
||||
target_branch_changed, source_branch_changed
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Yashin
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class BranchData {
|
||||
|
||||
private String label;
|
||||
private String ref;
|
||||
private String sha;
|
||||
private User user;
|
||||
private Project repo;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getRef() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
public void setRef(String ref) {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
public String getSha() {
|
||||
return sha;
|
||||
}
|
||||
|
||||
public void setSha(String sha) {
|
||||
this.sha = sha;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Project getRepo() {
|
||||
return repo;
|
||||
}
|
||||
|
||||
public void setRepo(Project repo) {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
BranchData branchData = (BranchData) o;
|
||||
return new EqualsBuilder()
|
||||
.append(label, branchData.label)
|
||||
.append(sha, branchData.sha)
|
||||
.append(ref, branchData.ref)
|
||||
.append(user, branchData.user)
|
||||
.append(repo, branchData.repo)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(label)
|
||||
.append(sha)
|
||||
.append(ref)
|
||||
.append(user)
|
||||
.append(repo)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("label", label)
|
||||
.append("sha", sha)
|
||||
.append("ref", ref)
|
||||
.append("user", user)
|
||||
.append("repo", repo)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Commit {
|
||||
|
||||
private String id;
|
||||
private String message;
|
||||
private Date timestamp;
|
||||
private String url;
|
||||
private User author;
|
||||
private List<String> added;
|
||||
private List<String> modified;
|
||||
private List<String> removed;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Date getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Date timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public User getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(User author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public List<String> getAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
public void setAdded(List<String> added) {
|
||||
this.added = added;
|
||||
}
|
||||
|
||||
public List<String> getModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void setModified(List<String> modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
public List<String> getRemoved() {
|
||||
return removed;
|
||||
}
|
||||
|
||||
public void setRemoved(List<String> removed) {
|
||||
this.removed = removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Commit commit = (Commit) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, commit.id)
|
||||
.append(message, commit.message)
|
||||
.append(timestamp, commit.timestamp)
|
||||
.append(url, commit.url)
|
||||
.append(author, commit.author)
|
||||
.append(added, commit.added)
|
||||
.append(modified, commit.modified)
|
||||
.append(removed, commit.removed)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(message)
|
||||
.append(timestamp)
|
||||
.append(url)
|
||||
.append(author)
|
||||
.append(added)
|
||||
.append(modified)
|
||||
.append(removed)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("message", message)
|
||||
.append("timestamp", timestamp)
|
||||
.append("url", url)
|
||||
.append("author", author)
|
||||
.append("added", added)
|
||||
.append("modified", modified)
|
||||
.append("removed", removed)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
/**
|
||||
* @author Yashin Luo
|
||||
*/
|
||||
public enum NoteAction {
|
||||
comment, edited, deleted
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Nikolay Ustinov
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class NoteHook extends WebHook {
|
||||
|
||||
private User user;
|
||||
private Project project;
|
||||
private PullRequestObjectAttributes pullRequest;
|
||||
private NoteObjectAttributes comment;
|
||||
private NoteAction action;
|
||||
|
||||
public NoteAction getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(NoteAction action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public NoteObjectAttributes getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(NoteObjectAttributes comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public PullRequestObjectAttributes getPullRequest() {
|
||||
return pullRequest;
|
||||
}
|
||||
|
||||
public void setPullRequest(PullRequestObjectAttributes pullRequest) {
|
||||
this.pullRequest = pullRequest;
|
||||
}
|
||||
|
||||
public String getWebHookDescription() {
|
||||
// 兼容commit评论
|
||||
if (pullRequest == null) {
|
||||
return getHookName() + " commit sha = " + comment.getCommitId();
|
||||
}
|
||||
|
||||
return getHookName() + " iid = " + pullRequest.getNumber() + " merge commit sha = " + pullRequest.getMergeCommitSha();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
NoteHook that = (NoteHook) o;
|
||||
return new EqualsBuilder()
|
||||
.append(user, that.user)
|
||||
.append(action, that.action)
|
||||
.append(project, that.project)
|
||||
.append(comment, that.comment)
|
||||
.append(pullRequest, that.pullRequest)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(user)
|
||||
.append(action)
|
||||
.append(project)
|
||||
.append(comment)
|
||||
.append(pullRequest)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("user", user)
|
||||
.append("action", action)
|
||||
.append("project", project)
|
||||
.append("comment", comment)
|
||||
.append("pullRequest", pullRequest)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Nikolay Ustinov
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class NoteObjectAttributes {
|
||||
|
||||
private Integer id;
|
||||
private String body;
|
||||
private Integer authorId;
|
||||
private Integer projectId;
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
private String htmlUrl;
|
||||
private String commitId;
|
||||
private User user;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public void setProjectId(Integer projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public Integer getAuthorId() {
|
||||
return authorId;
|
||||
}
|
||||
|
||||
public void setAuthorId(Integer authorId) {
|
||||
this.authorId = authorId;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(Date updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public String getHtmlUrl() {
|
||||
return htmlUrl;
|
||||
}
|
||||
|
||||
public void setHtmlUrl(String htmlUrl) {
|
||||
this.htmlUrl = htmlUrl;
|
||||
}
|
||||
|
||||
public String getCommitId() {
|
||||
return commitId;
|
||||
}
|
||||
|
||||
public void setCommitId(String commitId) {
|
||||
this.commitId = commitId;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
NoteObjectAttributes that = (NoteObjectAttributes) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, that.id)
|
||||
.append(body, that.body)
|
||||
.append(projectId, that.projectId)
|
||||
.append(authorId, that.authorId)
|
||||
.append(createdAt, that.createdAt)
|
||||
.append(updatedAt, that.updatedAt)
|
||||
.append(htmlUrl, that.htmlUrl)
|
||||
.append(commitId, that.commitId)
|
||||
.append(user, that.user)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(body)
|
||||
.append(projectId)
|
||||
.append(authorId)
|
||||
.append(createdAt)
|
||||
.append(updatedAt)
|
||||
.append(htmlUrl)
|
||||
.append(commitId)
|
||||
.append(user)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("body", body)
|
||||
.append("projectId", projectId)
|
||||
.append("authorId", authorId)
|
||||
.append("createdAt", createdAt)
|
||||
.append("updatedAt", updatedAt)
|
||||
.append("htmlUrl", htmlUrl)
|
||||
.append("commitId", commitId)
|
||||
.append("user", user)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Milena Zachow
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class PipelineEventObjectAttributes {
|
||||
|
||||
private Integer id;
|
||||
private String ref;
|
||||
private boolean tag;
|
||||
private String sha;
|
||||
private String beforeSha;
|
||||
private String status;
|
||||
private List<String> stages;
|
||||
private Date createdAt;
|
||||
private Date finishedAt;
|
||||
private int duration;
|
||||
|
||||
public String getRef() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
public void setRef(String ref) {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
public boolean getIsTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(boolean tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getSha() {
|
||||
return sha;
|
||||
}
|
||||
|
||||
public void setSha(String sha) {
|
||||
this.sha = sha;
|
||||
}
|
||||
|
||||
public String getBeforeSha() {
|
||||
return beforeSha;
|
||||
}
|
||||
|
||||
public void setBeforeSha(String beforeSha) {
|
||||
this.beforeSha = beforeSha;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public List<String> getStages() {
|
||||
return stages;
|
||||
}
|
||||
|
||||
public void setStages(List<String> stages) {
|
||||
this.stages = stages;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getFinishedAt() {
|
||||
return finishedAt;
|
||||
}
|
||||
|
||||
public void setFinishedAt(Date finishedAt) {
|
||||
this.finishedAt = finishedAt;
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PipelineEventObjectAttributes that = (PipelineEventObjectAttributes) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, that.id)
|
||||
.append(ref, that.ref)
|
||||
.append(tag, that.tag)
|
||||
.append(sha, that.sha)
|
||||
.append(beforeSha, that.beforeSha)
|
||||
.append(status, that.status)
|
||||
.append(stages, that.stages)
|
||||
.append(createdAt, that.createdAt)
|
||||
.append(finishedAt, that.finishedAt)
|
||||
.append(duration, that.duration)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(ref)
|
||||
.append(tag)
|
||||
.append(sha)
|
||||
.append(beforeSha)
|
||||
.append(status)
|
||||
.append(stages)
|
||||
.append(createdAt)
|
||||
.append(finishedAt)
|
||||
.append(duration)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("ref", ref)
|
||||
.append("tag", tag)
|
||||
.append("sha", sha)
|
||||
.append("beforeSha", beforeSha)
|
||||
.append("status", status)
|
||||
.append("stages", stages)
|
||||
.append("createdAt", createdAt)
|
||||
.append("finishedAt", finishedAt)
|
||||
.append("duration", duration)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author Milena Zachow
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class PipelineHook extends WebHook {
|
||||
|
||||
private User user;
|
||||
public Integer projectId;
|
||||
private List<Commit> commits;
|
||||
private Project project;
|
||||
private PipelineEventObjectAttributes objectAttributes;
|
||||
|
||||
public Integer getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public void setProjectId(Integer projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public List<Commit> getCommits() {
|
||||
return commits;
|
||||
}
|
||||
|
||||
public void setCommits(List<Commit> commits) {
|
||||
this.commits = commits;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public PipelineEventObjectAttributes getObjectAttributes() {
|
||||
return objectAttributes;
|
||||
}
|
||||
|
||||
public void setObjectAttributes(PipelineEventObjectAttributes objectAttributes) {
|
||||
this.objectAttributes = objectAttributes;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PipelineHook that = (PipelineHook) o;
|
||||
return new EqualsBuilder()
|
||||
.append(user, that.user)
|
||||
.append(project, that.project)
|
||||
.append(projectId, that.projectId)
|
||||
.append(commits, that.commits)
|
||||
.append(objectAttributes, that.objectAttributes)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(user)
|
||||
.append(projectId)
|
||||
.append(project)
|
||||
.append(commits)
|
||||
.append(objectAttributes)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("user", user)
|
||||
.append("project", project)
|
||||
.append("projectId", projectId)
|
||||
.append("objectAttributes", objectAttributes)
|
||||
.append("commits", commits)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Project {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String webUrl;
|
||||
private String avatarUrl;
|
||||
private String namespace;
|
||||
// private Integer visibilityLevel;
|
||||
private String pathWithNamespace;
|
||||
private String defaultBranch;
|
||||
private String homepage;
|
||||
private String url;
|
||||
private String sshUrl;
|
||||
private String gitHttpUrl;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getWebUrl() {
|
||||
return webUrl;
|
||||
}
|
||||
|
||||
public void setWebUrl(String webUrl) {
|
||||
this.webUrl = webUrl;
|
||||
}
|
||||
|
||||
public String getAvatarUrl() {
|
||||
return avatarUrl;
|
||||
}
|
||||
|
||||
public void setAvatarUrl(String avatarUrl) {
|
||||
this.avatarUrl = avatarUrl;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
// public Integer getVisibilityLevel() {
|
||||
// return visibilityLevel;
|
||||
// }
|
||||
|
||||
// public void setVisibilityLevel(Integer visibilityLevel) {
|
||||
// this.visibilityLevel = visibilityLevel;
|
||||
// }
|
||||
|
||||
public String getPathWithNamespace() {
|
||||
return pathWithNamespace;
|
||||
}
|
||||
|
||||
public void setPathWithNamespace(String pathWithNamespace) {
|
||||
this.pathWithNamespace = pathWithNamespace;
|
||||
}
|
||||
|
||||
public String getDefaultBranch() {
|
||||
return defaultBranch;
|
||||
}
|
||||
|
||||
public void setDefaultBranch(String defaultBranch) {
|
||||
this.defaultBranch = defaultBranch;
|
||||
}
|
||||
|
||||
public String getHomepage() {
|
||||
return homepage;
|
||||
}
|
||||
|
||||
public void setHomepage(String homepage) {
|
||||
this.homepage = homepage;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getSshUrl() {
|
||||
return sshUrl;
|
||||
}
|
||||
|
||||
public void setSshUrl(String sshUrl) {
|
||||
this.sshUrl = sshUrl;
|
||||
}
|
||||
|
||||
public String getGitHttpUrl() {
|
||||
return gitHttpUrl;
|
||||
}
|
||||
|
||||
public void setGitHttpUrl(String gitHttpUrl) {
|
||||
this.gitHttpUrl = gitHttpUrl;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Project project = (Project) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, project.id)
|
||||
.append(name, project.name)
|
||||
.append(description, project.description)
|
||||
.append(webUrl, project.webUrl)
|
||||
.append(avatarUrl, project.avatarUrl)
|
||||
.append(namespace, project.namespace)
|
||||
// .append(visibilityLevel, project.visibilityLevel)
|
||||
.append(pathWithNamespace, project.pathWithNamespace)
|
||||
.append(defaultBranch, project.defaultBranch)
|
||||
.append(homepage, project.homepage)
|
||||
.append(url, project.url)
|
||||
.append(sshUrl, project.sshUrl)
|
||||
.append(gitHttpUrl, project.gitHttpUrl)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(name)
|
||||
.append(description)
|
||||
.append(webUrl)
|
||||
.append(avatarUrl)
|
||||
.append(namespace)
|
||||
// .append(visibilityLevel)
|
||||
.append(pathWithNamespace)
|
||||
.append(defaultBranch)
|
||||
.append(homepage)
|
||||
.append(url)
|
||||
.append(sshUrl)
|
||||
.append(gitHttpUrl)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("name", name)
|
||||
.append("description", description)
|
||||
.append("webUrl", webUrl)
|
||||
.append("avatarUrl", avatarUrl)
|
||||
.append("namespace", namespace)
|
||||
// .append("visibilityLevel", visibilityLevel)
|
||||
.append("pathWithNamespace", pathWithNamespace)
|
||||
.append("defaultBranch", defaultBranch)
|
||||
.append("homepage", homepage)
|
||||
.append("url", url)
|
||||
.append("sshUrl", sshUrl)
|
||||
.append("gitHttpUrl", gitHttpUrl)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
* @author Yashin Luo
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class PullRequestHook extends WebHook {
|
||||
|
||||
private User user;
|
||||
private User assignee;
|
||||
private Project repo;
|
||||
private Action action;
|
||||
private ActionDesc actionDesc;
|
||||
private State state;
|
||||
private PullRequestObjectAttributes pullRequest;
|
||||
private List<PullRequestLabel> labels;
|
||||
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public ActionDesc getActionDesc() {
|
||||
return actionDesc;
|
||||
}
|
||||
|
||||
public void setAction(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public void setActionDesc(ActionDesc actionDesc) {
|
||||
this.actionDesc = actionDesc;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public void setState(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getAssignee() {
|
||||
return assignee;
|
||||
}
|
||||
|
||||
public void setAssignee(User assignee) {
|
||||
this.assignee = assignee;
|
||||
}
|
||||
|
||||
public Project getRepo() {
|
||||
return repo;
|
||||
}
|
||||
|
||||
public void setRepo(Project repo) {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
public PullRequestObjectAttributes getPullRequest() {
|
||||
return pullRequest;
|
||||
}
|
||||
|
||||
public void setPullRequest(PullRequestObjectAttributes pullRequest) {
|
||||
this.pullRequest = pullRequest;
|
||||
}
|
||||
|
||||
public List<PullRequestLabel> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public void setLabels(List<PullRequestLabel> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
public String getWebHookDescription() {
|
||||
return getHookName() + " iid = " + pullRequest.getNumber() + " merge commit sha = " + pullRequest.getMergeCommitSha();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PullRequestHook that = (PullRequestHook) o;
|
||||
return new EqualsBuilder()
|
||||
.append(user, that.user)
|
||||
.append(assignee, that.assignee)
|
||||
.append(repo, that.repo)
|
||||
.append(action, that.action)
|
||||
.append(actionDesc, that.actionDesc)
|
||||
.append(state, that.state)
|
||||
.append(pullRequest, that.pullRequest)
|
||||
.append(labels, that.labels)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(user)
|
||||
.append(assignee)
|
||||
.append(repo)
|
||||
.append(pullRequest)
|
||||
.append(labels)
|
||||
.append(state)
|
||||
.append(action)
|
||||
.append(actionDesc)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("user", user)
|
||||
.append("assignee", assignee)
|
||||
.append("repo", repo)
|
||||
.append("state", state)
|
||||
.append("action", action)
|
||||
.append("actionDesc", actionDesc)
|
||||
.append("pullRequest", pullRequest)
|
||||
.append("labels", labels)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Benjamin ROBIN
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class PullRequestLabel {
|
||||
|
||||
/*
|
||||
"id": 206,
|
||||
"title": "API",
|
||||
"color": "#ffffff",
|
||||
"project_id": 14,
|
||||
"created_at": "2013-12-03T17:15:43Z",
|
||||
"updated_at": "2013-12-03T17:15:43Z",
|
||||
"template": false,
|
||||
"description": "API related issues",
|
||||
"type": "ProjectLabel",
|
||||
"group_id": 41
|
||||
*/
|
||||
private Integer id;
|
||||
private String title;
|
||||
private String color;
|
||||
private Integer projectId;
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
private Boolean template;
|
||||
private String description;
|
||||
private String type;
|
||||
private Integer groupId;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Integer getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public void setProjectId(Integer projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(Date updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public Boolean getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
public void setTemplate(Boolean template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(Integer groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PullRequestLabel that = (PullRequestLabel) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, that.id)
|
||||
.append(title, that.title)
|
||||
.append(color, that.color)
|
||||
.append(projectId, that.projectId)
|
||||
.append(createdAt, that.createdAt)
|
||||
.append(updatedAt, that.updatedAt)
|
||||
.append(template, that.template)
|
||||
.append(description, that.description)
|
||||
.append(type, that.type)
|
||||
.append(groupId, that.groupId)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(title)
|
||||
.append(color)
|
||||
.append(projectId)
|
||||
.append(createdAt)
|
||||
.append(updatedAt)
|
||||
.append(template)
|
||||
.append(description)
|
||||
.append(type)
|
||||
.append(groupId)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("title", title)
|
||||
.append("color", color)
|
||||
.append("projectId", projectId)
|
||||
.append("createdAt", createdAt)
|
||||
.append("updatedAt", updatedAt)
|
||||
.append("template", template)
|
||||
.append("description", description)
|
||||
.append("type", type)
|
||||
.append("groupId", groupId)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,286 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
* @author Yashin
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class PullRequestObjectAttributes {
|
||||
private Integer id;
|
||||
private Integer number;
|
||||
private Integer authorId;
|
||||
private Integer assigneeId;
|
||||
private String title;
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
private String body;
|
||||
private BranchData head;
|
||||
private BranchData base;
|
||||
private String mergeStatus;
|
||||
private boolean mergeable;
|
||||
private boolean needReview;
|
||||
private boolean needTest;
|
||||
private String mergeCommitSha;
|
||||
private String mergeReferenceName;
|
||||
private String htmlUrl;
|
||||
private Boolean workInProgress;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(Integer number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getSourceBranch() {
|
||||
return head.getRef();
|
||||
}
|
||||
|
||||
public String getTargetBranch() {
|
||||
return base.getRef();
|
||||
}
|
||||
|
||||
public Integer getSourceProjectId() {
|
||||
return head.getRepo().getId();
|
||||
}
|
||||
|
||||
public Integer getTargetProjectId() {
|
||||
return base.getRepo().getId();
|
||||
}
|
||||
|
||||
public Integer getAuthorId() {
|
||||
return authorId;
|
||||
}
|
||||
|
||||
public void setAuthorId(Integer authorId) {
|
||||
this.authorId = authorId;
|
||||
}
|
||||
|
||||
public Integer getAssigneeId() {
|
||||
return assigneeId;
|
||||
}
|
||||
|
||||
public void setAssigneeId(Integer assigneeId) {
|
||||
this.assigneeId = assigneeId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(Date updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public Project getSource() {
|
||||
return head.getRepo();
|
||||
}
|
||||
|
||||
public BranchData getHead() {
|
||||
return head;
|
||||
}
|
||||
|
||||
public void setHead(BranchData head) {
|
||||
this.head = head;
|
||||
}
|
||||
|
||||
public BranchData getBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
public void setBase(BranchData base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
public Project getTarget() {
|
||||
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;
|
||||
}
|
||||
|
||||
public void setMergeCommitSha(String mergeCommitSha) {
|
||||
this.mergeCommitSha = mergeCommitSha;
|
||||
}
|
||||
|
||||
public String getMergeReferenceName() {
|
||||
return mergeReferenceName;
|
||||
}
|
||||
|
||||
public void setMergeReferenceName(String mergeReferenceName) {
|
||||
this.mergeReferenceName = mergeReferenceName;
|
||||
}
|
||||
|
||||
public String getMergeStatus() {
|
||||
return mergeStatus;
|
||||
}
|
||||
|
||||
public void setMergeStatus(String mergeStatus) {
|
||||
this.mergeStatus = mergeStatus;
|
||||
}
|
||||
|
||||
public String getHtmlUrl() {
|
||||
return htmlUrl;
|
||||
}
|
||||
|
||||
public void setHtmlUrl(String htmlUrl) {
|
||||
this.htmlUrl = htmlUrl;
|
||||
}
|
||||
|
||||
public Boolean getWorkInProgress() {
|
||||
return workInProgress;
|
||||
}
|
||||
|
||||
public void setWorkInProgress(Boolean workInProgress) {
|
||||
this.workInProgress = workInProgress;
|
||||
}
|
||||
|
||||
public boolean getMergeable() {
|
||||
return mergeable;
|
||||
}
|
||||
|
||||
public void setMergeable(boolean mergeable) {
|
||||
this.mergeable = mergeable;
|
||||
}
|
||||
|
||||
public boolean isMergeable() {
|
||||
return mergeable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PullRequestObjectAttributes that = (PullRequestObjectAttributes) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, that.id)
|
||||
.append(number, that.number)
|
||||
.append(authorId, that.authorId)
|
||||
.append(assigneeId, that.assigneeId)
|
||||
.append(title, that.title)
|
||||
.append(createdAt, that.createdAt)
|
||||
.append(updatedAt, that.updatedAt)
|
||||
.append(body, that.body)
|
||||
.append(head, that.head)
|
||||
.append(base, that.base)
|
||||
.append(mergeCommitSha, that.mergeCommitSha)
|
||||
.append(mergeReferenceName, that.mergeReferenceName)
|
||||
.append(mergeStatus, that.mergeStatus)
|
||||
.append(mergeable, that.mergeable)
|
||||
.append(needReview, that.needReview)
|
||||
.append(needTest, that.needTest)
|
||||
.append(htmlUrl, that.htmlUrl)
|
||||
.append(workInProgress, that.workInProgress)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(number)
|
||||
.append(authorId)
|
||||
.append(assigneeId)
|
||||
.append(title)
|
||||
.append(createdAt)
|
||||
.append(updatedAt)
|
||||
.append(body)
|
||||
.append(head)
|
||||
.append(base)
|
||||
.append(mergeStatus)
|
||||
.append(mergeable)
|
||||
.append(needReview)
|
||||
.append(needTest)
|
||||
.append(mergeCommitSha)
|
||||
.append(mergeReferenceName)
|
||||
.append(htmlUrl)
|
||||
.append(workInProgress)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("number", number)
|
||||
.append("authorId", authorId)
|
||||
.append("assigneeId", assigneeId)
|
||||
.append("title", title)
|
||||
.append("createdAt", createdAt)
|
||||
.append("updatedAt", updatedAt)
|
||||
.append("body", body)
|
||||
.append("head", head)
|
||||
.append("base", base)
|
||||
.append("mergeCommitSha", mergeCommitSha)
|
||||
.append("mergeReferenceName", mergeReferenceName)
|
||||
.append("mergeStatus", mergeStatus)
|
||||
.append("mergeable", mergeable)
|
||||
.append("needReview", needReview)
|
||||
.append("needTest", needTest)
|
||||
.append("htmlUrl", htmlUrl)
|
||||
.append("workInProgress", workInProgress)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,194 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class PushHook extends WebHook {
|
||||
|
||||
private String before;
|
||||
private String after;
|
||||
private boolean created;
|
||||
private boolean deleted;
|
||||
private String ref;
|
||||
private Integer userId;
|
||||
private String userName;
|
||||
private String userEmail;
|
||||
private String userAvatar;
|
||||
private Project project;
|
||||
private List<Commit> commits;
|
||||
private Integer totalCommitsCount;
|
||||
|
||||
public String getBefore() {
|
||||
return before;
|
||||
}
|
||||
|
||||
public void setBefore(String before) {
|
||||
this.before = before;
|
||||
}
|
||||
|
||||
public boolean getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(boolean created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public boolean getDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
|
||||
public String getAfter() {
|
||||
return after;
|
||||
}
|
||||
|
||||
public void setAfter(String after) {
|
||||
this.after = after;
|
||||
}
|
||||
|
||||
public String getRef() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
public void setRef(String ref) {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getUserEmail() {
|
||||
return userEmail;
|
||||
}
|
||||
|
||||
public void setUserEmail(String userEmail) {
|
||||
this.userEmail = userEmail;
|
||||
}
|
||||
|
||||
public String getUserAvatar() {
|
||||
return userAvatar;
|
||||
}
|
||||
|
||||
public void setUserAvatar(String userAvatar) {
|
||||
this.userAvatar = userAvatar;
|
||||
}
|
||||
|
||||
public Integer getProjectId() {
|
||||
return getProject().getId();
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public List<Commit> getCommits() {
|
||||
return commits;
|
||||
}
|
||||
|
||||
public void setCommits(List<Commit> commits) {
|
||||
this.commits = commits;
|
||||
}
|
||||
|
||||
public Integer getTotalCommitsCount() {
|
||||
return totalCommitsCount;
|
||||
}
|
||||
|
||||
public void setTotalCommitsCount(Integer totalCommitsCount) {
|
||||
this.totalCommitsCount = totalCommitsCount;
|
||||
}
|
||||
|
||||
public String getWebHookDescription() {
|
||||
return getHookName() + " ref = " + ref + " commit sha = " + after;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PushHook pushHook = (PushHook) o;
|
||||
return new EqualsBuilder()
|
||||
.append(before, pushHook.before)
|
||||
.append(created, pushHook.created)
|
||||
.append(deleted, pushHook.deleted)
|
||||
.append(after, pushHook.after)
|
||||
.append(ref, pushHook.ref)
|
||||
.append(userId, pushHook.userId)
|
||||
.append(userName, pushHook.userName)
|
||||
.append(userEmail, pushHook.userEmail)
|
||||
.append(userAvatar, pushHook.userAvatar)
|
||||
.append(project, pushHook.project)
|
||||
.append(commits, pushHook.commits)
|
||||
.append(totalCommitsCount, pushHook.totalCommitsCount)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(before)
|
||||
.append(after)
|
||||
.append(ref)
|
||||
.append(created)
|
||||
.append(deleted)
|
||||
.append(userId)
|
||||
.append(userName)
|
||||
.append(userEmail)
|
||||
.append(userAvatar)
|
||||
.append(project)
|
||||
.append(commits)
|
||||
.append(totalCommitsCount)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("before", before)
|
||||
.append("after", after)
|
||||
.append("ref", ref)
|
||||
.append("created", created)
|
||||
.append("deleted", deleted)
|
||||
.append("userId", userId)
|
||||
.append("userName", userName)
|
||||
.append("userEmail", userEmail)
|
||||
.append("userAvatar", userAvatar)
|
||||
.append("project", project)
|
||||
.append("commits", commits)
|
||||
.append("totalCommitsCount", totalCommitsCount)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class Repository {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String url;
|
||||
private String homepage;
|
||||
private String gitSshUrl;
|
||||
private String gitHttpUrl;
|
||||
private Integer visibilityLevel;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getHomepage() {
|
||||
return homepage;
|
||||
}
|
||||
|
||||
public void setHomepage(String homepage) {
|
||||
this.homepage = homepage;
|
||||
}
|
||||
|
||||
public String getGitSshUrl() {
|
||||
return gitSshUrl;
|
||||
}
|
||||
|
||||
public void setGitSshUrl(String gitSshUrl) {
|
||||
this.gitSshUrl = gitSshUrl;
|
||||
}
|
||||
|
||||
public String getGitHttpUrl() {
|
||||
return gitHttpUrl;
|
||||
}
|
||||
|
||||
public void setGitHttpUrl(String gitHttpUrl) {
|
||||
this.gitHttpUrl = gitHttpUrl;
|
||||
}
|
||||
|
||||
public Integer getVisibilityLevel() {
|
||||
return visibilityLevel;
|
||||
}
|
||||
|
||||
public void setVisibilityLevel(Integer visibilityLevel) {
|
||||
this.visibilityLevel = visibilityLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Repository that = (Repository) o;
|
||||
return new EqualsBuilder()
|
||||
.append(name, that.name)
|
||||
.append(description, that.description)
|
||||
.append(url, that.url)
|
||||
.append(homepage, that.homepage)
|
||||
.append(gitSshUrl, that.gitSshUrl)
|
||||
.append(gitHttpUrl, that.gitHttpUrl)
|
||||
.append(visibilityLevel, that.visibilityLevel)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(name)
|
||||
.append(description)
|
||||
.append(url)
|
||||
.append(homepage)
|
||||
.append(gitSshUrl)
|
||||
.append(gitHttpUrl)
|
||||
.append(visibilityLevel)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("name", name)
|
||||
.append("description", description)
|
||||
.append("url", url)
|
||||
.append("homepage", homepage)
|
||||
.append("gitSshUrl", gitSshUrl)
|
||||
.append("gitHttpUrl", gitHttpUrl)
|
||||
.append("visibilityLevel", visibilityLevel)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public enum State {
|
||||
open, opened, reopened, updated, closed, merged
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public class User {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String username;
|
||||
private String email;
|
||||
private String avatarUrl;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getAvatarUrl() {
|
||||
return avatarUrl;
|
||||
}
|
||||
|
||||
public void setAvatarUrl(String avatarUrl) {
|
||||
this.avatarUrl = avatarUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
User user = (User) o;
|
||||
return new EqualsBuilder()
|
||||
.append(id, user.id)
|
||||
.append(name, user.name)
|
||||
.append(username, user.username)
|
||||
.append(email, user.email)
|
||||
.append(avatarUrl, user.avatarUrl)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(id)
|
||||
.append(name)
|
||||
.append(username)
|
||||
.append(email)
|
||||
.append(avatarUrl)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("name", name)
|
||||
.append("username", username)
|
||||
.append("email", email)
|
||||
.append("avatarUrl", avatarUrl)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.hook.model;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
* @author Yashin Luo
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
public void setHookName(String hookName) {
|
||||
this.hookName = hookName;
|
||||
}
|
||||
|
||||
public String getObjectKind() {
|
||||
return objectKind;
|
||||
}
|
||||
|
||||
public void setObjectKind(String objectKind) {
|
||||
this.objectKind = objectKind;
|
||||
}
|
||||
|
||||
public Repository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
public void setRepository(Repository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public String getWebHookDescription() {
|
||||
return hookName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
WebHook webHook = (WebHook) o;
|
||||
return new EqualsBuilder()
|
||||
.append(repository, webHook.repository)
|
||||
.append(objectKind, webHook.objectKind)
|
||||
.append(hookName, webHook.hookName)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(repository)
|
||||
.append(hookName)
|
||||
.append(objectKind)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("repository", repository)
|
||||
.append("hookName", hookName)
|
||||
.append("objectKind", objectKind)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.gitee.jenkins.handler;
|
||||
|
||||
import com.gitee.jenkins.cause.GiteeWebHookCauseData;
|
||||
import com.gitee.jenkins.entity.CommitComment;
|
||||
import com.gitee.jenkins.entity.CommitCommentWebHook;
|
||||
import com.gitee.jenkins.enums.WebHookType;
|
||||
import com.gitee.jenkins.excetion.NoRevisionToBuildException;
|
||||
import hudson.Extension;
|
||||
import hudson.plugins.git.GitSCM;
|
||||
import hudson.plugins.git.RevisionParameterAction;
|
||||
import org.eclipse.jgit.transport.URIish;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* commit comment handler
|
||||
*/
|
||||
@Extension
|
||||
@Restricted(NoExternalUse.class)
|
||||
public class CommitCommentHandler extends GiteeWebHookHandler<CommitCommentWebHook> {
|
||||
|
||||
@Override
|
||||
protected WebHookType handleWebHookType() {
|
||||
return WebHookType.COMMIT_COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RevisionParameterAction createRevisionParameterAction(GitSCM gitSCM, CommitCommentWebHook webHook) throws NoRevisionToBuildException {
|
||||
URIish urIish = retrieveUrIish(retrieveGitRepositoryRemoteConfig(gitSCM, webHook));
|
||||
return urIish == null ? new RevisionParameterAction(retrieveRevisionToBuild(webHook)) : new RevisionParameterAction(retrieveRevisionToBuild(webHook), urIish);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String retrieveRevisionToBuild(CommitCommentWebHook webHook) throws NoRevisionToBuildException {
|
||||
return Optional.ofNullable(webHook)
|
||||
.map(CommitCommentWebHook::getComment)
|
||||
.map(CommitComment::getCommitId)
|
||||
.orElseThrow(NoRevisionToBuildException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GiteeWebHookCauseData createGiteeWebHookCauseData(CommitCommentWebHook webHook) {
|
||||
return GiteeWebHookCauseData.builder()
|
||||
.webHookType(webHook.getWebHookType())
|
||||
.userName(webHook.getComment().getUser().getName())
|
||||
.userEmail(webHook.getComment().getUser().getEmail())
|
||||
.sourceProjectId(webHook.getProject().getId())
|
||||
.targetProjectId(webHook.getProject().getId())
|
||||
.pathWithNamespace(webHook.getProject().getPathWithNamespace())
|
||||
.branch("")
|
||||
.sourceBranch("")
|
||||
.sourceRepoHomepage(webHook.getProject().getHomepage())
|
||||
.sourceRepoName(webHook.getProject().getName())
|
||||
.sourceNamespace(webHook.getProject().getNamespace())
|
||||
.sourceRepoUrl(webHook.getProject().getUrl())
|
||||
.sourceRepoSshUrl(webHook.getProject().getSshUrl())
|
||||
.sourceRepoHttpUrl(webHook.getProject().getGitHttpUrl())
|
||||
.targetBranch("")
|
||||
.targetRepoName(webHook.getProject().getName())
|
||||
.targetNamespace(webHook.getProject().getNamespace())
|
||||
.targetProjectUrl(webHook.getProject().getUrl())
|
||||
.targetRepoSshUrl(webHook.getProject().getSshUrl())
|
||||
.targetRepoHttpUrl(webHook.getProject().getGitHttpUrl())
|
||||
.pullRequestTitle("")
|
||||
.sha(webHook.getComment().getCommitId())
|
||||
.jsonBody(webHook.getJsonBody())
|
||||
.noteBody(webHook.getComment().getBody())
|
||||
.triggerPhrase(webHook.getComment().getBody())
|
||||
.triggeredByUser(webHook.getComment().getUser().getName())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue