删除test文件
This commit is contained in:
parent
2f8da3aefa
commit
21a51f87df
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
|
|
@ -1,236 +0,0 @@
|
|||
#!/bin/sh
|
||||
# ----------------------------------------------------------------------------
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Maven2 Start Up Batch script
|
||||
#
|
||||
# Required ENV vars:
|
||||
# ------------------
|
||||
# JAVA_HOME - location of a JDK home dir
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# M2_HOME - location of maven2's installed home dir
|
||||
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
# e.g. to debug Maven itself, use
|
||||
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||
|
||||
if [ -f /etc/mavenrc ] ; then
|
||||
. /etc/mavenrc
|
||||
fi
|
||||
|
||||
if [ -f "$HOME/.mavenrc" ] ; then
|
||||
. "$HOME/.mavenrc"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# OS specific support. $var _must_ be set to either true or false.
|
||||
cygwin=false;
|
||||
darwin=false;
|
||||
mingw=false
|
||||
case "`uname`" in
|
||||
CYGWIN*) cygwin=true ;;
|
||||
MINGW*) mingw=true;;
|
||||
Darwin*) darwin=true
|
||||
#
|
||||
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
|
||||
# for the new JDKs provided by Oracle.
|
||||
#
|
||||
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
|
||||
#
|
||||
# Apple JDKs
|
||||
#
|
||||
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
|
||||
#
|
||||
# Apple JDKs
|
||||
#
|
||||
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
|
||||
#
|
||||
# Oracle JDKs
|
||||
#
|
||||
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
|
||||
#
|
||||
# Apple JDKs
|
||||
#
|
||||
export JAVA_HOME=`/usr/libexec/java_home`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
if [ -r /etc/gentoo-release ] ; then
|
||||
JAVA_HOME=`java-config --jre-home`
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$M2_HOME" ] ; then
|
||||
## resolve links - $0 may be a link to maven's home
|
||||
PRG="$0"
|
||||
|
||||
# need this for relative symlinks
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG="`dirname "$PRG"`/$link"
|
||||
fi
|
||||
done
|
||||
|
||||
saveddir=`pwd`
|
||||
|
||||
M2_HOME=`dirname "$PRG"`/..
|
||||
|
||||
# make it fully qualified
|
||||
M2_HOME=`cd "$M2_HOME" && pwd`
|
||||
|
||||
cd "$saveddir"
|
||||
# echo Using m2 at $M2_HOME
|
||||
fi
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||
if $cygwin ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --unix "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||
fi
|
||||
|
||||
# For Migwn, ensure paths are in UNIX format before anything is touched
|
||||
if $mingw ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||
# TODO classpath?
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
javaExecutable="`which javac`"
|
||||
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
|
||||
# readlink(1) is not available as standard on Solaris 10.
|
||||
readLink=`which readlink`
|
||||
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
|
||||
if $darwin ; then
|
||||
javaHome="`dirname \"$javaExecutable\"`"
|
||||
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
|
||||
else
|
||||
javaExecutable="`readlink -f \"$javaExecutable\"`"
|
||||
fi
|
||||
javaHome="`dirname \"$javaExecutable\"`"
|
||||
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
|
||||
JAVA_HOME="$javaHome"
|
||||
export JAVA_HOME
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$JAVACMD" ] ; then
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
else
|
||||
JAVACMD="`which java`"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
echo "Error: JAVA_HOME is not defined correctly." >&2
|
||||
echo " We cannot execute $JAVACMD" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
echo "Warning: JAVA_HOME environment variable is not set."
|
||||
fi
|
||||
|
||||
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
||||
|
||||
# traverses directory structure from process work directory to filesystem root
|
||||
# first directory with .mvn subdirectory is considered project base directory
|
||||
find_maven_basedir() {
|
||||
local basedir=$(pwd)
|
||||
local wdir=$(pwd)
|
||||
while [ "$wdir" != '/' ] ; do
|
||||
if [ -d "$wdir"/.mvn ] ; then
|
||||
basedir=$wdir
|
||||
break
|
||||
fi
|
||||
wdir=$(cd "$wdir/.."; pwd)
|
||||
done
|
||||
echo "${basedir}"
|
||||
}
|
||||
|
||||
# concatenates all lines of a file
|
||||
concat_lines() {
|
||||
if [ -f "$1" ]; then
|
||||
echo "$(tr -s '\n' ' ' < "$1")"
|
||||
fi
|
||||
}
|
||||
|
||||
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
|
||||
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||
fi
|
||||
|
||||
# Provide a "standardized" way to retrieve the CLI args that will
|
||||
# work with both Windows and non-Windows executions.
|
||||
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
|
||||
export MAVEN_CMD_LINE_ARGS
|
||||
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
# avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in $@
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
|
@ -1,146 +0,0 @@
|
|||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Maven2 Start Up Batch script
|
||||
@REM
|
||||
@REM Required ENV vars:
|
||||
@REM JAVA_HOME - location of a JDK home dir
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM M2_HOME - location of maven2's installed home dir
|
||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
|
||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
@REM e.g. to debug Maven itself, use
|
||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||
@echo off
|
||||
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
|
||||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||
|
||||
@REM set %HOME% to equivalent of $HOME
|
||||
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||
|
||||
@REM Execute a user defined script before this one
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
|
||||
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
|
||||
:skipRcPre
|
||||
|
||||
@setlocal
|
||||
|
||||
set ERROR_CODE=0
|
||||
|
||||
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||
@setlocal
|
||||
|
||||
@REM ==== START VALIDATION ====
|
||||
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME not found in your environment. >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
:OkJHome
|
||||
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
@REM ==== END VALIDATION ====
|
||||
|
||||
:init
|
||||
|
||||
set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %*
|
||||
|
||||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||
@REM Fallback to current working directory if not found.
|
||||
|
||||
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||
|
||||
set EXEC_DIR=%CD%
|
||||
set WDIR=%EXEC_DIR%
|
||||
:findBaseDir
|
||||
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||
cd ..
|
||||
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||
set WDIR=%CD%
|
||||
goto findBaseDir
|
||||
|
||||
:baseDirFound
|
||||
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||
cd "%EXEC_DIR%"
|
||||
goto endDetectBaseDir
|
||||
|
||||
:baseDirNotFound
|
||||
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||
cd "%EXEC_DIR%"
|
||||
|
||||
:endDetectBaseDir
|
||||
|
||||
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||
|
||||
@setlocal EnableExtensions EnableDelayedExpansion
|
||||
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||
|
||||
:endReadAdditionalConfig
|
||||
|
||||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||
|
||||
set WRAPPER_JAR=""%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar""
|
||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
@REM avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in %*
|
||||
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||
if ERRORLEVEL 1 goto error
|
||||
goto end
|
||||
|
||||
:error
|
||||
set ERROR_CODE=1
|
||||
|
||||
:end
|
||||
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
|
||||
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
|
||||
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
|
||||
:skipRcPost
|
||||
|
||||
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||
if "%MAVEN_BATCH_PAUSE%" == "on" pause
|
||||
|
||||
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
|
||||
|
||||
exit /B %ERROR_CODE%
|
|
@ -1,102 +0,0 @@
|
|||
package com.gitee.jenkins.connection;
|
||||
|
||||
|
||||
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.domains.Domain;
|
||||
import hudson.util.FormValidation;
|
||||
import hudson.util.Secret;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockserver.socket.PortFactory;
|
||||
import org.mortbay.jetty.Connector;
|
||||
import org.mortbay.jetty.HttpConnection;
|
||||
import org.mortbay.jetty.Request;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.handler.AbstractHandler;
|
||||
import org.mortbay.jetty.security.SslSocketConnector;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class GiteeConnectionConfigSSLTest {
|
||||
|
||||
private static final String API_TOKEN_ID = "apiTokenId";
|
||||
|
||||
private static int port;
|
||||
|
||||
private static Server server;
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@BeforeClass
|
||||
public static void startJetty() throws Exception {
|
||||
port = PortFactory.findFreePort();
|
||||
server = new Server();
|
||||
SslSocketConnector sslSocketConnector = new SslSocketConnector();
|
||||
sslSocketConnector.setKeystore("src/test/resources/keystore");
|
||||
sslSocketConnector.setKeyPassword("password");
|
||||
sslSocketConnector.setPort(port);
|
||||
server.setConnectors(new Connector[]{sslSocketConnector});
|
||||
server.addHandler(new AbstractHandler() {
|
||||
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
|
||||
response.setStatus(Response.Status.OK.getStatusCode());
|
||||
Request base_request = request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
|
||||
base_request.setHandled(true);
|
||||
}
|
||||
});
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stopJetty() throws Exception {
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
|
||||
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
|
||||
List<Domain> domains = credentialsStore.getDomains();
|
||||
credentialsStore.addCredentials(domains.get(0),
|
||||
new StringCredentialsImpl(CredentialsScope.SYSTEM, API_TOKEN_ID, "Gitee API Token", Secret.fromString(API_TOKEN_ID)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doCheckConnection_ignoreCertificateErrors() {
|
||||
GiteeConnectionConfig connectionConfig = jenkins.get(GiteeConnectionConfig.class);
|
||||
|
||||
FormValidation formValidation = connectionConfig.doTestConnection("https://localhost:" + port + "/gitee", API_TOKEN_ID, "v3", true, 10, 10);
|
||||
assertThat(formValidation.getMessage(), is(Messages.connection_success()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doCheckConnection_certificateError() throws IOException {
|
||||
GiteeConnectionConfig connectionConfig = jenkins.get(GiteeConnectionConfig.class);
|
||||
|
||||
FormValidation formValidation = connectionConfig.doTestConnection("https://localhost:" + port + "/gitee", API_TOKEN_ID, "v3", false, 10, 10);
|
||||
assertThat(formValidation.getMessage(), containsString(Messages.connection_error("")));
|
||||
}
|
||||
}
|
|
@ -1,214 +0,0 @@
|
|||
package com.gitee.jenkins.connection;
|
||||
|
||||
|
||||
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.domains.Domain;
|
||||
import com.gitee.jenkins.trigger.GiteePushTrigger;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import hudson.ProxyConfiguration;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.model.Item;
|
||||
import hudson.security.GlobalMatrixAuthorizationStrategy;
|
||||
import hudson.util.FormValidation;
|
||||
import hudson.util.Secret;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockserver.client.server.MockServerClient;
|
||||
import org.mockserver.junit.MockServerRule;
|
||||
import org.mockserver.model.HttpRequest;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gitee.jenkins.connection.Messages.connection_error;
|
||||
import static com.gitee.jenkins.connection.Messages.connection_success;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertSame;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
import static org.mockserver.model.HttpResponse.response;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class GiteeConnectionConfigTest {
|
||||
|
||||
private static final String API_TOKEN = "secret";
|
||||
private static final String API_TOKEN_ID = "apiTokenId";
|
||||
|
||||
@Rule
|
||||
public MockServerRule mockServer = new MockServerRule(this);
|
||||
@Rule
|
||||
public JenkinsRule jenkins = new JenkinsRule();
|
||||
private MockServerClient mockServerClient;
|
||||
private String gitLabUrl;
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
gitLabUrl = "http://localhost:" + mockServer.getPort() + "/gitee";
|
||||
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
|
||||
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
|
||||
List<Domain> domains = credentialsStore.getDomains();
|
||||
credentialsStore.addCredentials(domains.get(0),
|
||||
new StringCredentialsImpl(CredentialsScope.SYSTEM, API_TOKEN_ID, "Gitee API Token", Secret.fromString(API_TOKEN)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doCheckConnection_success() {
|
||||
String expected = connection_success();
|
||||
assertThat(doCheckConnection("v3", Response.Status.OK), is(expected));
|
||||
assertThat(doCheckConnection("v4", Response.Status.OK), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doCheckConnection_forbidden() {
|
||||
String expected = connection_error("HTTP 403 Forbidden");
|
||||
assertThat(doCheckConnection("v3", Response.Status.FORBIDDEN), is(expected));
|
||||
assertThat(doCheckConnection("v4", Response.Status.FORBIDDEN), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doCheckConnection_proxy() {
|
||||
jenkins.getInstance().proxy = new ProxyConfiguration("0.0.0.0", 80);
|
||||
GiteeConnectionConfig connectionConfig = jenkins.get(GiteeConnectionConfig.class);
|
||||
FormValidation result = connectionConfig.doTestConnection(gitLabUrl, API_TOKEN_ID, "v3", false, 10, 10);
|
||||
assertThat(result.getMessage(), containsString("Connection refused"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doCheckConnection_noProxy() {
|
||||
jenkins.getInstance().proxy = new ProxyConfiguration("0.0.0.0", 80, "", "", "localhost");
|
||||
assertThat(doCheckConnection("v3", Response.Status.OK), is(connection_success()));
|
||||
}
|
||||
|
||||
|
||||
private String doCheckConnection(String clientBuilderId, Response.Status status) {
|
||||
HttpRequest request = request().withPath("/gitee/api/" + clientBuilderId + "/.*").withHeader("PRIVATE-TOKEN", API_TOKEN);
|
||||
mockServerClient.when(request).respond(response().withStatusCode(status.getStatusCode()));
|
||||
|
||||
GiteeConnectionConfig connectionConfig = jenkins.get(GiteeConnectionConfig.class);
|
||||
FormValidation formValidation = connectionConfig.doTestConnection(gitLabUrl, API_TOKEN_ID, clientBuilderId, false, 10, 10);
|
||||
mockServerClient.verify(request);
|
||||
return formValidation.getMessage();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void authenticationEnabled_anonymous_forbidden() throws IOException {
|
||||
Boolean defaultValue = jenkins.get(GiteeConnectionConfig.class).isUseAuthenticatedEndpoint();
|
||||
assertTrue(defaultValue);
|
||||
jenkins.getInstance().setAuthorizationStrategy(new GlobalMatrixAuthorizationStrategy());
|
||||
URL jenkinsURL = jenkins.getURL();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject("test");
|
||||
GiteePushTrigger trigger = mock(GiteePushTrigger.class);
|
||||
project.addTrigger(trigger);
|
||||
|
||||
CloseableHttpClient client = HttpClientBuilder.create().build();
|
||||
HttpPost request = new HttpPost(jenkinsURL.toExternalForm() + "project/test");
|
||||
request.addHeader("X-Gitee-Event", "Push Hook");
|
||||
request.setEntity(new StringEntity("{}"));
|
||||
|
||||
CloseableHttpResponse response = client.execute(request);
|
||||
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(403));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authenticationEnabled_registered_success() throws Exception {
|
||||
String username = "test-user";
|
||||
jenkins.getInstance().setSecurityRealm(jenkins.createDummySecurityRealm());
|
||||
GlobalMatrixAuthorizationStrategy authorizationStrategy = new GlobalMatrixAuthorizationStrategy();
|
||||
authorizationStrategy.add(Item.BUILD, username);
|
||||
jenkins.getInstance().setAuthorizationStrategy(authorizationStrategy);
|
||||
URL jenkinsURL = jenkins.getURL();
|
||||
jenkins.createFreeStyleProject("test");
|
||||
|
||||
CloseableHttpClient client = HttpClientBuilder.create().build();
|
||||
HttpPost request = new HttpPost(jenkinsURL.toExternalForm() + "project/test");
|
||||
request.addHeader("X-Gitee-Event", "Push Hook");
|
||||
String auth = username + ":" + username;
|
||||
request.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encodeBase64(auth.getBytes(Charset.forName("ISO-8859-1")))));
|
||||
request.setEntity(new StringEntity("{}"));
|
||||
|
||||
CloseableHttpResponse response = client.execute(request);
|
||||
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authenticationDisabled_anonymous_success() throws IOException, URISyntaxException {
|
||||
jenkins.get(GiteeConnectionConfig.class).setUseAuthenticatedEndpoint(false);
|
||||
jenkins.getInstance().setAuthorizationStrategy(new GlobalMatrixAuthorizationStrategy());
|
||||
URL jenkinsURL = jenkins.getURL();
|
||||
jenkins.createFreeStyleProject("test");
|
||||
|
||||
CloseableHttpClient client = HttpClientBuilder.create().build();
|
||||
HttpPost request = new HttpPost(jenkinsURL.toExternalForm() + "project/test");
|
||||
request.addHeader("X-Gitee-Event", "Push Hook");
|
||||
request.setEntity(new StringEntity("{}"));
|
||||
|
||||
CloseableHttpResponse response = client.execute(request);
|
||||
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setConnectionsTest() {
|
||||
GiteeConnection connection1 = new GiteeConnection("1", "http://localhost", null, new V3GiteeClientBuilder(), false, 10, 10);
|
||||
GiteeConnection connection2 = new GiteeConnection("2", "http://localhost", null, new V3GiteeClientBuilder(), false, 10, 10);
|
||||
GiteeConnectionConfig config = jenkins.get(GiteeConnectionConfig.class);
|
||||
List<GiteeConnection> connectionList1 = new ArrayList<>();
|
||||
connectionList1.add(connection1);
|
||||
|
||||
config.setConnections(connectionList1);
|
||||
assertThat(config.getConnections(), is(connectionList1));
|
||||
|
||||
List<GiteeConnection> connectionList2 = new ArrayList<>();
|
||||
connectionList2.add(connection1);
|
||||
connectionList2.add(connection2);
|
||||
|
||||
config.setConnections(connectionList2);
|
||||
assertThat(config.getConnections(), is(connectionList2));
|
||||
|
||||
config.setConnections(connectionList1);
|
||||
assertThat(config.getConnections(), is(connectionList1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getClient_is_cached() {
|
||||
GiteeConnection connection = new GiteeConnection("test", "http://localhost", API_TOKEN_ID, new V3GiteeClientBuilder(), false, 10, 10);
|
||||
GiteeConnectionConfig config = jenkins.get(GiteeConnectionConfig.class);
|
||||
List<GiteeConnection> connectionList1 = new ArrayList<>();
|
||||
connectionList1.add(connection);
|
||||
config.setConnections(connectionList1);
|
||||
|
||||
GiteeClient client = config.getClient(connection.getName());
|
||||
assertNotNull(client);
|
||||
assertSame(client, config.getClient(connection.getName()));
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
package com.gitee.jenkins.environment;
|
||||
|
||||
import com.gitee.jenkins.cause.CauseData;
|
||||
import com.gitee.jenkins.cause.GiteeWebHookCause;
|
||||
import hudson.EnvVars;
|
||||
import hudson.matrix.AxisList;
|
||||
import hudson.matrix.MatrixBuild;
|
||||
import hudson.matrix.MatrixProject;
|
||||
import hudson.matrix.MatrixRun;
|
||||
import hudson.matrix.TextAxis;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.model.FreeStyleBuild;
|
||||
import hudson.model.StreamBuildListener;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gitee.jenkins.cause.CauseDataBuilder.causeData;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* @author Evgeni Golov
|
||||
*/
|
||||
public class GiteeEnvironmentContributorTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
private BuildListener listener;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
listener = new StreamBuildListener(jenkins.createTaskListener().getLogger(), Charset.defaultCharset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freeStyleProjectTest() throws IOException, InterruptedException, ExecutionException {
|
||||
FreeStyleProject p = jenkins.createFreeStyleProject();
|
||||
GiteeWebHookCause cause = new GiteeWebHookCause(generateCauseData());
|
||||
FreeStyleBuild b = p.scheduleBuild2(0, cause).get();
|
||||
EnvVars env = b.getEnvironment(listener);
|
||||
|
||||
assertEnv(env);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matrixProjectTest() throws IOException, InterruptedException, ExecutionException {
|
||||
EnvVars env;
|
||||
MatrixProject p = jenkins.jenkins.createProject(MatrixProject.class, "matrixbuild");
|
||||
GiteeWebHookCause cause = new GiteeWebHookCause(generateCauseData());
|
||||
// set up 2x2 matrix
|
||||
AxisList axes = new AxisList();
|
||||
axes.add(new TextAxis("db","mysql","oracle"));
|
||||
axes.add(new TextAxis("direction","north","south"));
|
||||
p.setAxes(axes);
|
||||
|
||||
MatrixBuild build = p.scheduleBuild2(0, cause).get();
|
||||
List<MatrixRun> runs = build.getRuns();
|
||||
assertEquals(4,runs.size());
|
||||
for (MatrixRun run : runs) {
|
||||
env = run.getEnvironment(listener);
|
||||
assertNotNull(env.get("db"));
|
||||
assertEnv(env);
|
||||
}
|
||||
}
|
||||
|
||||
private CauseData generateCauseData() {
|
||||
return causeData()
|
||||
.withActionType(CauseData.ActionType.MERGE)
|
||||
.withSourceProjectId(1)
|
||||
.withTargetProjectId(1)
|
||||
.withBranch("feature")
|
||||
.withSourceBranch("feature")
|
||||
.withUserName("")
|
||||
.withSourceRepoHomepage("https://gitee.org/test")
|
||||
.withSourceRepoName("test")
|
||||
.withSourceNamespace("test-namespace")
|
||||
.withSourceRepoUrl("git@gitee.org:test.git")
|
||||
.withSourceRepoSshUrl("git@gitee.org:test.git")
|
||||
.withSourceRepoHttpUrl("https://gitee.org/test.git")
|
||||
.withMergeRequestTitle("Test")
|
||||
.withMergeRequestId(1)
|
||||
.withMergeRequestIid(1)
|
||||
.withTargetBranch("master")
|
||||
.withTargetRepoName("test")
|
||||
.withTargetNamespace("test-namespace")
|
||||
.withTargetRepoSshUrl("git@gitee.org:test.git")
|
||||
.withTargetRepoHttpUrl("https://gitee.org/test.git")
|
||||
.withTriggeredByUser("test")
|
||||
.withLastCommit("123")
|
||||
.withTargetProjectUrl("https://gitee.org/test")
|
||||
.build();
|
||||
}
|
||||
|
||||
private void assertEnv(EnvVars env) {
|
||||
assertEquals("1", env.get("gitlabMergeRequestId"));
|
||||
assertEquals("git@gitee.org:test.git", env.get("gitlabSourceRepoUrl"));
|
||||
assertEquals("master", env.get("gitlabTargetBranch"));
|
||||
assertEquals("test", env.get("gitlabTargetRepoName"));
|
||||
assertEquals("feature", env.get("gitlabSourceBranch"));
|
||||
assertEquals("test", env.get("gitlabSourceRepoName"));
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api;
|
||||
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static com.gitee.jenkins.gitee.api.GiteeClientBuilder.getAllGiteeClientBuilders;
|
||||
import static com.gitee.jenkins.gitee.api.GiteeClientBuilder.getGiteeClientBuilderById;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
|
||||
|
||||
public class GiteeClientBuilderTest {
|
||||
@Rule
|
||||
public JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Test
|
||||
public void getAllGiteeClientBuilders_list_is_sorted_by_ordinal() {
|
||||
List<GiteeClientBuilder> builders = getAllGiteeClientBuilders();
|
||||
assertThat(builders.get(0), instanceOf(AutodetectGiteeClientBuilder.class));
|
||||
assertThat(builders.get(1), instanceOf(V4GiteeClientBuilder.class));
|
||||
assertThat(builders.get(2), instanceOf(V3GiteeClientBuilder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGiteeClientBuilderById_success() {
|
||||
assertThat(getGiteeClientBuilderById(new V3GiteeClientBuilder().id()), instanceOf(V3GiteeClientBuilder.class));
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException.class)
|
||||
public void getGiteeClientBuilderById_no_match() {
|
||||
getGiteeClientBuilderById("unknown");
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.impl;
|
||||
|
||||
import com.gitee.jenkins.gitee.api.GiteeClientBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockserver.client.server.MockServerClient;
|
||||
import org.mockserver.junit.MockServerRule;
|
||||
import org.mockserver.model.HttpRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static com.gitee.jenkins.gitee.api.impl.TestUtility.*;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockserver.matchers.Times.exactly;
|
||||
import static org.mockserver.matchers.Times.once;
|
||||
|
||||
public class AutodetectingGiteeClientTest {
|
||||
@Rule
|
||||
public MockServerRule mockServer = new MockServerRule(this);
|
||||
@Rule
|
||||
public JenkinsRule jenkins = new JenkinsRule();
|
||||
private MockServerClient mockServerClient;
|
||||
private String gitLabUrl;
|
||||
private GiteeClientBuilder clientBuilder;
|
||||
private AutodetectingGiteeClient api;
|
||||
private HttpRequest v3Request;
|
||||
private HttpRequest v4Request;
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
gitLabUrl = "http://localhost:" + mockServer.getPort() + "/gitee";
|
||||
addGiteeApiToken();
|
||||
|
||||
List<GiteeClientBuilder> builders = Arrays.<GiteeClientBuilder>asList(new V3GiteeClientBuilder(), new V4GiteeClientBuilder());
|
||||
api = new AutodetectingGiteeClient(builders, gitLabUrl, API_TOKEN, true, 10, 10);
|
||||
|
||||
v3Request = versionRequest(V3GiteeApiProxy.ID);
|
||||
v4Request = versionRequest(V4GiteeApiProxy.ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildClient_success_v3() throws Exception {
|
||||
mockServerClient.when(v3Request).respond(responseOk());
|
||||
api.getCurrentUser();
|
||||
assertApiImpl(api, V3GiteeApiProxy.class);
|
||||
mockServerClient.verify(v3Request, v3Request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildClient_success_v4() throws Exception {
|
||||
mockServerClient.when(v3Request).respond(responseNotFound());
|
||||
mockServerClient.when(v4Request).respond(responseOk());
|
||||
api.getCurrentUser();
|
||||
assertApiImpl(api, V4GiteeApiProxy.class);
|
||||
mockServerClient.verify(v3Request, v4Request, v4Request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildClient_success_switching_apis() throws Exception {
|
||||
mockServerClient.when(v3Request, once()).respond(responseNotFound());
|
||||
mockServerClient.when(v4Request, exactly(2)).respond(responseOk());
|
||||
api.getCurrentUser();
|
||||
assertApiImpl(api, V4GiteeApiProxy.class);
|
||||
|
||||
mockServerClient.when(v4Request, once()).respond(responseNotFound());
|
||||
mockServerClient.when(v3Request, exactly(2)).respond(responseOk());
|
||||
api.getCurrentUser();
|
||||
assertApiImpl(api, V3GiteeApiProxy.class);
|
||||
|
||||
mockServerClient.verify(v3Request, v4Request, v4Request, v3Request, v3Request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildClient_no_match() {
|
||||
mockServerClient.when(v3Request).respond(responseNotFound());
|
||||
mockServerClient.when(v4Request).respond(responseNotFound());
|
||||
try {
|
||||
api.getCurrentUser();
|
||||
fail("endpoint should throw exception when no matching delegate is found");
|
||||
} catch (NoSuchElementException e) {
|
||||
mockServerClient.verify(v3Request, v4Request);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.impl;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.api.GiteeClientBuilder;
|
||||
import hudson.ProxyConfiguration;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockserver.junit.MockServerRule;
|
||||
|
||||
import static com.gitee.jenkins.gitee.api.impl.TestUtility.assertApiImpl;
|
||||
import static com.gitee.jenkins.gitee.api.impl.TestUtility.buildClientWithDefaults;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
|
||||
|
||||
public class ResteasyGiteeClientBuilderTest {
|
||||
@Rule
|
||||
public MockServerRule mockServer = new MockServerRule(this);
|
||||
@Rule
|
||||
public JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Test
|
||||
public void buildClient() throws Exception {
|
||||
GiteeClientBuilder clientBuilder = new ResteasyGiteeClientBuilder("test", 0, V3GiteeApiProxy.class, null);
|
||||
assertApiImpl(buildClientWithDefaults(clientBuilder, "http://localhost/"), V3GiteeApiProxy.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildClientWithProxy() throws Exception {
|
||||
jenkins.getInstance().proxy = new ProxyConfiguration("example.com", 8080, "test", "test", "*localhost*");
|
||||
GiteeClientBuilder clientBuilder = new ResteasyGiteeClientBuilder("test", 0, V3GiteeApiProxy.class, null);
|
||||
assertNotNull(buildClientWithDefaults(clientBuilder, "http://localhost"));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package com.gitee.jenkins.gitee.api.impl;
|
||||
|
||||
|
||||
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.domains.Domain;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClientBuilder;
|
||||
import hudson.util.Secret;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
|
||||
import org.mockserver.model.HttpRequest;
|
||||
import org.mockserver.model.HttpResponse;
|
||||
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.ws.rs.HttpMethod.GET;
|
||||
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
|
||||
import static javax.ws.rs.core.Response.Status.OK;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
import static org.mockserver.model.HttpResponse.response;
|
||||
|
||||
|
||||
class TestUtility {
|
||||
static final String API_TOKEN = "secret";
|
||||
private static final String API_TOKEN_ID = "apiTokenId";
|
||||
private static final boolean IGNORE_CERTIFICATE_ERRORS = true;
|
||||
private static final int CONNECTION_TIMEOUT = 10;
|
||||
private static final int READ_TIMEOUT = 10;
|
||||
|
||||
static void addGiteeApiToken() throws IOException {
|
||||
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
|
||||
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
|
||||
List<Domain> domains = credentialsStore.getDomains();
|
||||
credentialsStore.addCredentials(domains.get(0),
|
||||
new StringCredentialsImpl(CredentialsScope.SYSTEM, API_TOKEN_ID, "Gitee API Token", Secret.fromString(API_TOKEN)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static HttpRequest versionRequest(String id) {
|
||||
return request().withMethod(GET).withPath("/gitee/api/" + id + "/.*").withHeader("PRIVATE-TOKEN", API_TOKEN);
|
||||
}
|
||||
|
||||
static HttpResponse responseOk() {
|
||||
return responseWithStatus(OK);
|
||||
}
|
||||
|
||||
static HttpResponse responseNotFound() {
|
||||
return responseWithStatus(NOT_FOUND);
|
||||
}
|
||||
|
||||
private static HttpResponse responseWithStatus(Status status) {
|
||||
return response().withStatusCode(status.getStatusCode());
|
||||
}
|
||||
|
||||
static GiteeClient buildClientWithDefaults(GiteeClientBuilder clientBuilder, String url) {
|
||||
return clientBuilder.buildClient(url, API_TOKEN, IGNORE_CERTIFICATE_ERRORS, CONNECTION_TIMEOUT, READ_TIMEOUT);
|
||||
}
|
||||
|
||||
static void assertApiImpl(GiteeClient client, Class<? extends GiteeApiProxy> apiImplClass) throws Exception {
|
||||
Field apiField = ((ResteasyGiteeClient) client).getClass().getDeclaredField("api");
|
||||
apiField.setAccessible(true);
|
||||
assertThat(apiField.get(client), instanceOf(apiImplClass));
|
||||
}
|
||||
|
||||
static void assertApiImpl(AutodetectingGiteeClient api, Class<? extends GiteeApiProxy> apiImplClass) throws Exception {
|
||||
Field delegate = api.getClass().getDeclaredField("delegate");
|
||||
delegate.setAccessible(true);
|
||||
assertApiImpl((GiteeClient) delegate.get(api), apiImplClass);
|
||||
}
|
||||
|
||||
private TestUtility() { /* utility class */ }
|
||||
}
|
|
@ -1,431 +0,0 @@
|
|||
package com.gitee.jenkins.publisher;
|
||||
|
||||
|
||||
import com.gitee.jenkins.connection.GiteeConnectionProperty;
|
||||
import com.gitee.jenkins.gitee.api.model.BuildState;
|
||||
import hudson.EnvVars;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.StreamBuildListener;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.plugins.git.Revision;
|
||||
import hudson.plugins.git.util.Build;
|
||||
import hudson.plugins.git.util.BuildData;
|
||||
import jenkins.plugins.git.AbstractGitSCMSource;
|
||||
import jenkins.scm.api.SCMRevisionAction;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.mockserver.client.server.MockServerClient;
|
||||
import org.mockserver.junit.MockServerRule;
|
||||
import org.mockserver.model.HttpRequest;
|
||||
import org.mockserver.model.HttpResponse;
|
||||
import org.mockserver.verify.VerificationTimes;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.gitee.jenkins.publisher.TestUtility.BUILD_URL;
|
||||
import static com.gitee.jenkins.publisher.TestUtility.GITEE_CONNECTION_V3;
|
||||
import static com.gitee.jenkins.publisher.TestUtility.GITEE_CONNECTION_V4;
|
||||
import static com.gitee.jenkins.publisher.TestUtility.PROJECT_ID;
|
||||
import static com.gitee.jenkins.publisher.TestUtility.setupGiteeConnections;
|
||||
import static com.gitee.jenkins.publisher.TestUtility.verifyMatrixAggregatable;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
import static org.mockserver.model.HttpResponse.response;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class GiteeCommitStatusPublisherTest {
|
||||
private static final String SHA1 = "0616d12a3a24068691027a1e113147e3c1cfa2f4";
|
||||
|
||||
@ClassRule
|
||||
public static MockServerRule mockServer = new MockServerRule(new Object());
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
private MockServerClient mockServerClient;
|
||||
private BuildListener listener;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupClass() throws IOException {
|
||||
setupGiteeConnections(jenkins, mockServer);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
listener = new StreamBuildListener(jenkins.createTaskListener().getLogger(), Charset.defaultCharset());
|
||||
mockServerClient = new MockServerClient("localhost", mockServer.getPort());
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
mockServerClient.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matrixAggregatable() throws InterruptedException, IOException {
|
||||
verifyMatrixAggregatable(GiteeCommitStatusPublisher.class, listener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void running_v3() throws UnsupportedEncodingException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V3, null, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v3", build, BuildState.running);
|
||||
|
||||
prebuildAndVerify(build, listener, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void running_v4() throws UnsupportedEncodingException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, null, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.running);
|
||||
|
||||
prebuildAndVerify(build, listener, requests);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void runningWithLibrary() throws UnsupportedEncodingException {
|
||||
AbstractBuild build = mockBuildWithLibrary(GITEE_CONNECTION_V4, null, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.running);
|
||||
|
||||
prebuildAndVerify(build, listener, requests);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void runningWithDotInProjectId() throws IOException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, null, "test/project.test.git");
|
||||
HttpRequest[] requests = new HttpRequest[] {
|
||||
prepareGetProjectResponse("test/project.test"),
|
||||
prepareExistsCommitWithSuccessResponse("v4", String.valueOf(PROJECT_ID)),
|
||||
prepareUpdateCommitStatusWithSuccessResponse("v4", String.valueOf(PROJECT_ID), build, BuildState.running)
|
||||
};
|
||||
|
||||
prebuildAndVerify(build, listener, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canceled_v3() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V3, Result.ABORTED, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v3", build, BuildState.canceled);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canceled_v4() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.ABORTED, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.canceled);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canceledWithLibrary() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuildWithLibrary(GITEE_CONNECTION_V4, Result.ABORTED, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.canceled);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void success_v3() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V3, Result.SUCCESS, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v3", build, BuildState.success);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void success_v4() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.SUCCESS, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.success);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successWithLibrary() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuildWithLibrary(GITEE_CONNECTION_V4, Result.SUCCESS, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.success);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failed_v3() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V3, Result.FAILURE, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v3", build, BuildState.failed);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failed_v4() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V3, Result.FAILURE, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v3", build, BuildState.failed);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedWithLibrary() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuildWithLibrary(GITEE_CONNECTION_V4, Result.FAILURE, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.failed);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstable() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.UNSTABLE, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.failed);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstableWithLibrary() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuildWithLibrary(GITEE_CONNECTION_V4, Result.UNSTABLE, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.failed);
|
||||
|
||||
performAndVerify(build, false, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstableAsSuccess() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.UNSTABLE, "test/project.git");
|
||||
HttpRequest[] requests = prepareCheckCommitAndUpdateStatusRequests("v4", build, BuildState.success);
|
||||
|
||||
performAndVerify(build, true, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void running_multipleRepos() throws UnsupportedEncodingException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, null, "test/project-1.git", "test/project-2.git");
|
||||
HttpRequest[] requests = new HttpRequest[] {
|
||||
prepareExistsCommitWithSuccessResponse("v4", "test/project-1"),
|
||||
prepareUpdateCommitStatusWithSuccessResponse("v4", "test/project-1", build, BuildState.running),
|
||||
prepareExistsCommitWithSuccessResponse("v4", "test/project-2"),
|
||||
prepareUpdateCommitStatusWithSuccessResponse("v4", "test/project-2", build, BuildState.running)
|
||||
};
|
||||
|
||||
prebuildAndVerify(build, listener, requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void running_commitNotExists() throws UnsupportedEncodingException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, null, "test/project.git");
|
||||
HttpRequest updateCommitStatus = prepareUpdateCommitStatusWithSuccessResponse("v4", "test/project", build, BuildState.running);
|
||||
|
||||
new GiteeCommitStatusPublisher("jenkins", false).prebuild(build, listener);
|
||||
mockServerClient.verify(updateCommitStatus, VerificationTimes.exactly(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void running_failToUpdate() throws UnsupportedEncodingException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, null, "test/project.git");
|
||||
BuildListener buildListener = mock(BuildListener.class);
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
when(buildListener.getLogger()).thenReturn(new PrintStream(outputStream));
|
||||
|
||||
prepareExistsCommitWithSuccessResponse("v4", "test/project");
|
||||
HttpRequest updateCommitStatus = prepareUpdateCommitStatus("v4", "test/project", build, BuildState.running);
|
||||
mockServerClient.when(updateCommitStatus).respond(response().withStatusCode(403));
|
||||
|
||||
prebuildAndVerify(build, buildListener, updateCommitStatus);
|
||||
assertThat(outputStream.toString(), CoreMatchers.containsString("Failed to update Gitee commit status for project 'test/project': HTTP 403 Forbidden"));
|
||||
}
|
||||
|
||||
private void prebuildAndVerify(AbstractBuild build, BuildListener listener, HttpRequest... requests) {
|
||||
new GiteeCommitStatusPublisher("jenkins", false).prebuild(build, listener);
|
||||
mockServerClient.verify(requests);
|
||||
}
|
||||
|
||||
private void performAndVerify(AbstractBuild build, boolean markUnstableAsSuccess, HttpRequest... requests) throws InterruptedException, IOException {
|
||||
new GiteeCommitStatusPublisher("jenkins", markUnstableAsSuccess).perform(build, null, listener);
|
||||
mockServerClient.verify(requests);
|
||||
}
|
||||
|
||||
private HttpRequest[] prepareCheckCommitAndUpdateStatusRequests(String apiLevel, Run<?, ?> build, BuildState buildState) throws UnsupportedEncodingException {
|
||||
return new HttpRequest[] {
|
||||
prepareExistsCommitWithSuccessResponse(apiLevel, "test/project"),
|
||||
prepareUpdateCommitStatusWithSuccessResponse(apiLevel, "test/project", build, buildState)
|
||||
};
|
||||
}
|
||||
|
||||
private HttpRequest prepareUpdateCommitStatusWithSuccessResponse(String apiLevel, String projectName, Run<?, ?> build, BuildState state) throws UnsupportedEncodingException {
|
||||
HttpRequest updateCommitStatus = prepareUpdateCommitStatus(apiLevel, projectName, build, state);
|
||||
mockServerClient.when(updateCommitStatus).respond(response().withStatusCode(200));
|
||||
return updateCommitStatus;
|
||||
}
|
||||
|
||||
|
||||
private HttpRequest prepareUpdateCommitStatus(final String apiLevel, String projectName, Run<?, ?> build, BuildState state) throws UnsupportedEncodingException {
|
||||
return request()
|
||||
.withPath("/gitee/api/" + apiLevel + "/projects/" + URLEncoder.encode(projectName, "UTF-8") + "/statuses/" + SHA1)
|
||||
.withMethod("POST")
|
||||
.withHeader("PRIVATE-TOKEN", "secret")
|
||||
.withBody("state=" + URLEncoder.encode(state.name(), "UTF-8") + "&context=jenkins&" + "target_url=" + URLEncoder.encode(DisplayURLProvider.get().getRunURL(build), "UTF-8") + "&description=" + URLEncoder.encode(state.name(), "UTF-8"));
|
||||
}
|
||||
|
||||
private HttpRequest prepareExistsCommitWithSuccessResponse(String apiLevel, String projectName) throws UnsupportedEncodingException {
|
||||
HttpRequest existsCommit = prepareExistsCommit(apiLevel, projectName);
|
||||
mockServerClient.when(existsCommit).respond(response().withStatusCode(200));
|
||||
return existsCommit;
|
||||
}
|
||||
|
||||
private HttpRequest prepareExistsCommit(String apiLevel, String projectName) throws UnsupportedEncodingException {
|
||||
return request()
|
||||
.withPath("/gitee/api/" + apiLevel + "/projects/" + URLEncoder.encode(projectName, "UTF-8") + "/repository/commits/" + SHA1)
|
||||
.withMethod("GET")
|
||||
.withHeader("PRIVATE-TOKEN", "secret");
|
||||
}
|
||||
|
||||
private HttpRequest prepareGetProjectResponse(String projectName) throws IOException {
|
||||
HttpRequest request= request()
|
||||
.withPath("/gitee/api/v4/projects/" + URLEncoder.encode(projectName, "UTF-8"))
|
||||
.withMethod("GET")
|
||||
. withHeader("PRIVATE-TOKEN", "secret");
|
||||
|
||||
HttpResponse response = response().withBody(getSingleProjectJson("GetSingleProject.json", projectName, PROJECT_ID));
|
||||
|
||||
response.withHeader("Content-Type", "application/json");
|
||||
mockServerClient.when(request).respond(response.withStatusCode(200));
|
||||
return request;
|
||||
}
|
||||
|
||||
private AbstractBuild mockBuild(String gitLabConnection, Result result, String... remoteUrls) {
|
||||
AbstractBuild build = mock(AbstractBuild.class);
|
||||
List<BuildData> buildDatas = new ArrayList<>();
|
||||
BuildData buildData = mock(BuildData.class);
|
||||
Revision revision = mock(Revision.class);
|
||||
when(revision.getSha1String()).thenReturn(SHA1);
|
||||
when(buildData.getLastBuiltRevision()).thenReturn(revision);
|
||||
when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
|
||||
Build gitBuild = mock(Build.class);
|
||||
when(gitBuild.getMarked()).thenReturn(revision);
|
||||
when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
|
||||
buildDatas.add(buildData);
|
||||
when(build.getActions(BuildData.class)).thenReturn(buildDatas);
|
||||
when(build.getAction(BuildData.class)).thenReturn(buildData);
|
||||
when(build.getResult()).thenReturn(result);
|
||||
when(build.getUrl()).thenReturn(BUILD_URL);
|
||||
AbstractProject<?, ?> project = mock(AbstractProject.class);
|
||||
when(project.getProperty(GiteeConnectionProperty.class)).thenReturn(new GiteeConnectionProperty(gitLabConnection));
|
||||
when(build.getProject()).thenReturn(project);
|
||||
EnvVars environment = mock(EnvVars.class);
|
||||
when(environment.expand(anyString())).thenAnswer(new Answer<String>() {
|
||||
@Override
|
||||
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (String) invocation.getArguments()[0];
|
||||
}
|
||||
});
|
||||
try {
|
||||
when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return build;
|
||||
}
|
||||
|
||||
private AbstractBuild mockBuildWithLibrary(String gitLabConnection, Result result, String... remoteUrls) {
|
||||
AbstractBuild build = mock(AbstractBuild.class);
|
||||
List<BuildData> buildDatas = new ArrayList<>();
|
||||
BuildData buildData = mock(BuildData.class);
|
||||
SCMRevisionAction scmRevisionAction = mock(SCMRevisionAction.class);
|
||||
AbstractGitSCMSource.SCMRevisionImpl revisionImpl = mock(AbstractGitSCMSource.SCMRevisionImpl.class);
|
||||
|
||||
when(build.getAction(SCMRevisionAction.class)).thenReturn(scmRevisionAction);
|
||||
when(scmRevisionAction.getRevision()).thenReturn(revisionImpl);
|
||||
when(revisionImpl.getHash()).thenReturn(SHA1);
|
||||
|
||||
Revision revision = mock(Revision.class);
|
||||
when(revision.getSha1String()).thenReturn(SHA1);
|
||||
when(buildData.getLastBuiltRevision()).thenReturn(revision);
|
||||
when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
|
||||
|
||||
Build gitBuild = mock(Build.class);
|
||||
|
||||
when(gitBuild.getMarked()).thenReturn(revision);
|
||||
when(gitBuild.getSHA1()).thenReturn(ObjectId.fromString(SHA1));
|
||||
when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
|
||||
Map<String, Build> buildsByBranchName = new HashMap<>();
|
||||
buildsByBranchName.put("develop", gitBuild);
|
||||
when(buildData.getBuildsByBranchName()).thenReturn(buildsByBranchName);
|
||||
buildDatas.add(buildData);
|
||||
|
||||
//Second build data (@librabry)
|
||||
BuildData buildDataLib = mock(BuildData.class);
|
||||
Revision revisionLib = mock(Revision.class);
|
||||
when(revisionLib.getSha1String()).thenReturn("SHALIB");
|
||||
when(buildDataLib.getLastBuiltRevision()).thenReturn(revisionLib);
|
||||
Build gitBuildLib = mock(Build.class);
|
||||
when(gitBuildLib.getMarked()).thenReturn(revisionLib);
|
||||
when(buildDataLib.getLastBuild(any(ObjectId.class))).thenReturn(gitBuildLib);
|
||||
buildDatas.add(buildDataLib);
|
||||
|
||||
when(build.getActions(BuildData.class)).thenReturn(buildDatas);
|
||||
when(build.getResult()).thenReturn(result);
|
||||
when(build.getUrl()).thenReturn(BUILD_URL);
|
||||
|
||||
AbstractProject<?, ?> project = mock(AbstractProject.class);
|
||||
when(project.getProperty(GiteeConnectionProperty.class)).thenReturn(new GiteeConnectionProperty(gitLabConnection));
|
||||
when(build.getProject()).thenReturn(project);
|
||||
EnvVars environment = mock(EnvVars.class);
|
||||
when(environment.expand(anyString())).thenAnswer(new Answer<String>() {
|
||||
@Override
|
||||
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (String) invocation.getArguments()[0];
|
||||
}
|
||||
});
|
||||
try {
|
||||
when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return build;
|
||||
}
|
||||
|
||||
private String getSingleProjectJson(String name,String projectNameWithNamespace, int projectId) throws IOException {
|
||||
String nameSpace = projectNameWithNamespace.split("/")[0];
|
||||
String projectName = projectNameWithNamespace.split("/")[1];
|
||||
return IOUtils.toString(getClass().getResourceAsStream(name))
|
||||
.replace("${projectId}", projectId + "")
|
||||
.replace("${nameSpace}", nameSpace)
|
||||
.replace("${projectName}", projectName);
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
package com.gitee.jenkins.publisher;
|
||||
|
||||
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.StreamBuildListener;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockserver.client.server.MockServerClient;
|
||||
import org.mockserver.junit.MockServerRule;
|
||||
import org.mockserver.model.HttpRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static com.gitee.jenkins.publisher.TestUtility.*;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
import static org.mockserver.model.HttpResponse.response;
|
||||
|
||||
/**
|
||||
* @author Nikolay Ustinov
|
||||
*/
|
||||
public class GiteeAcceptMergeRequestPublisherTest {
|
||||
@ClassRule
|
||||
public static MockServerRule mockServer = new MockServerRule(new Object());
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
private MockServerClient mockServerClient;
|
||||
private BuildListener listener;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupClass() throws IOException {
|
||||
setupGiteeConnections(jenkins, mockServer);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
listener = new StreamBuildListener(jenkins.createTaskListener().getLogger(), Charset.defaultCharset());
|
||||
mockServerClient = new MockServerClient("localhost", mockServer.getPort());
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
mockServerClient.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matrixAggregatable() throws InterruptedException, IOException {
|
||||
verifyMatrixAggregatable(GiteeAcceptMergeRequestPublisher.class, listener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void success() throws IOException, InterruptedException {
|
||||
publish(mockSimpleBuild(GITEE_CONNECTION_V3, Result.SUCCESS));
|
||||
publish(mockSimpleBuild(GITEE_CONNECTION_V4, Result.SUCCESS));
|
||||
|
||||
mockServerClient.verify(
|
||||
prepareAcceptMergeRequestWithSuccessResponse("v3", MERGE_REQUEST_ID),
|
||||
prepareAcceptMergeRequestWithSuccessResponse("v4", MERGE_REQUEST_IID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failed() throws IOException, InterruptedException {
|
||||
publish(mockSimpleBuild(GITEE_CONNECTION_V3, Result.FAILURE));
|
||||
publish(mockSimpleBuild(GITEE_CONNECTION_V4, Result.FAILURE));
|
||||
|
||||
mockServerClient.verifyZeroInteractions();
|
||||
}
|
||||
|
||||
private void publish(AbstractBuild build) throws InterruptedException, IOException {
|
||||
GiteeAcceptMergeRequestPublisher publisher = preparePublisher(new GiteeAcceptMergeRequestPublisher(), build);
|
||||
publisher.perform(build, null, listener);
|
||||
}
|
||||
|
||||
private HttpRequest prepareAcceptMergeRequestWithSuccessResponse(String apiLevel, int mergeRequestId) throws UnsupportedEncodingException {
|
||||
HttpRequest updateCommitStatus = prepareAcceptMergeRequest(apiLevel, mergeRequestId);
|
||||
mockServerClient.when(updateCommitStatus).respond(response().withStatusCode(200));
|
||||
return updateCommitStatus;
|
||||
}
|
||||
|
||||
private HttpRequest prepareAcceptMergeRequest(String apiLevel, int mergeRequestId) throws UnsupportedEncodingException {
|
||||
return request()
|
||||
.withPath("/gitee/api/" + apiLevel + "/projects/" + PROJECT_ID + "/merge_requests/" + mergeRequestId + "/merge")
|
||||
.withMethod("PUT")
|
||||
.withHeader("PRIVATE-TOKEN", "secret")
|
||||
.withBody("merge_commit_message=Merge+Request+accepted+by+jenkins+build+success&should_remove_source_branch=false");
|
||||
}
|
||||
}
|
|
@ -1,250 +0,0 @@
|
|||
package com.gitee.jenkins.publisher;
|
||||
|
||||
|
||||
import com.gitee.jenkins.connection.GiteeConnectionProperty;
|
||||
import hudson.EnvVars;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.StreamBuildListener;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.plugins.git.util.BuildData;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.mockserver.client.server.MockServerClient;
|
||||
import org.mockserver.junit.MockServerRule;
|
||||
import org.mockserver.model.HttpRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static com.gitee.jenkins.publisher.TestUtility.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockserver.model.HttpRequest.request;
|
||||
import static org.mockserver.model.HttpResponse.response;
|
||||
|
||||
/**
|
||||
* @author Nikolay Ustinov
|
||||
*/
|
||||
public class GiteeMessagePublisherTest {
|
||||
@ClassRule
|
||||
public static MockServerRule mockServer = new MockServerRule(new Object());
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
private MockServerClient mockServerClient;
|
||||
private BuildListener listener;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupClass() throws IOException {
|
||||
setupGiteeConnections(jenkins, mockServer);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
listener = new StreamBuildListener(jenkins.createTaskListener().getLogger(), Charset.defaultCharset());
|
||||
mockServerClient = new MockServerClient("localhost", mockServer.getPort());
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
mockServerClient.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matrixAggregatable() throws InterruptedException, IOException {
|
||||
verifyMatrixAggregatable(GiteeMessagePublisher.class, listener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canceled_v3() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V3, Result.ABORTED);
|
||||
String defaultNote = formatNote(build, ":point_up: Jenkins Build {0}\n\nResults available at: [Jenkins [{1} #{2}]]({3})");
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v3", MERGE_REQUEST_ID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canceled_v4() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.ABORTED);
|
||||
String defaultNote = formatNote(build, ":point_up: Jenkins Build {0}\n\nResults available at: [Jenkins [{1} #{2}]]({3})");
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void success_v3() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V3, Result.SUCCESS);
|
||||
String defaultNote = formatNote(build, ":white_check_mark: Jenkins Build {0}\n\nResults available at: [Jenkins [{1} #{2}]]({3})");
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v3", MERGE_REQUEST_ID, defaultNote));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void success_v4() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.SUCCESS);
|
||||
String defaultNote = formatNote(build, ":white_check_mark: Jenkins Build {0}\n\nResults available at: [Jenkins [{1} #{2}]]({3})");
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void success_withOnlyForFailure() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.SUCCESS);
|
||||
|
||||
performAndVerify(build, "test", true, false, false, false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failed_v3() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V3, Result.FAILURE);
|
||||
String defaultNote = formatNote(build, ":negative_squared_cross_mark: Jenkins Build {0}\n\nResults available at: [Jenkins [{1} #{2}]]({3})");
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v3", MERGE_REQUEST_ID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failed_v4() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.FAILURE);
|
||||
String defaultNote = formatNote(build, ":negative_squared_cross_mark: Jenkins Build {0}\n\nResults available at: [Jenkins [{1} #{2}]]({3})");
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void failed_withOnlyForFailed() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.FAILURE);
|
||||
String defaultNote = formatNote(build, ":negative_squared_cross_mark: Jenkins Build {0}\n\nResults available at: [Jenkins [{1} #{2}]]({3})");
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, true, false, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canceledWithCustomNote() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.ABORTED);
|
||||
String defaultNote = "abort";
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, true, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successWithCustomNote() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.SUCCESS);
|
||||
String defaultNote = "success";
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, true, false, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedWithCustomNote() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.FAILURE);
|
||||
String defaultNote = "failure";
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, true, false, false,
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstableWithCustomNote() throws IOException, InterruptedException {
|
||||
AbstractBuild build = mockBuild(GITEE_CONNECTION_V4, Result.UNSTABLE);
|
||||
String defaultNote = "unstable";
|
||||
|
||||
performAndVerify(
|
||||
build, defaultNote, false, false, false, false, true,
|
||||
prepareSendMessageWithSuccessResponse("v4", MERGE_REQUEST_IID, defaultNote));
|
||||
}
|
||||
|
||||
private void performAndVerify(AbstractBuild build, String note, boolean onlyForFailure, boolean replaceSuccessNote, boolean replaceFailureNote, boolean replaceAbortNote, boolean replaceUnstableNote, HttpRequest... requests) throws InterruptedException, IOException {
|
||||
String successNoteText = replaceSuccessNote ? note : null;
|
||||
String failureNoteText = replaceFailureNote ? note : null;
|
||||
String abortNoteText = replaceAbortNote ? note : null;
|
||||
String unstableNoteText = replaceUnstableNote ? note : null;
|
||||
GiteeMessagePublisher publisher = preparePublisher(new GiteeMessagePublisher(onlyForFailure, replaceSuccessNote, replaceFailureNote, replaceAbortNote, replaceUnstableNote, successNoteText, failureNoteText, abortNoteText, unstableNoteText), build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
||||
if (requests.length > 0) {
|
||||
mockServerClient.verify(requests);
|
||||
} else {
|
||||
mockServerClient.verifyZeroInteractions();
|
||||
}
|
||||
}
|
||||
|
||||
private HttpRequest prepareSendMessageWithSuccessResponse(String apiLevel, int mergeRequestId, String body) throws UnsupportedEncodingException {
|
||||
HttpRequest updateCommitStatus = prepareSendMessageStatus(apiLevel, mergeRequestId, body);
|
||||
mockServerClient.when(updateCommitStatus).respond(response().withStatusCode(200));
|
||||
return updateCommitStatus;
|
||||
}
|
||||
|
||||
private HttpRequest prepareSendMessageStatus(final String apiLevel, int mergeRequestId, String body) throws UnsupportedEncodingException {
|
||||
return request()
|
||||
.withPath("/gitee/api/" + apiLevel + "/projects/" + PROJECT_ID + "/merge_requests/" + mergeRequestId + "/notes")
|
||||
.withMethod("POST")
|
||||
.withHeader("PRIVATE-TOKEN", "secret")
|
||||
.withBody("body=" + URLEncoder.encode(body, "UTF-8"));
|
||||
}
|
||||
|
||||
private AbstractBuild mockBuild(String gitLabConnection, Result result, String... remoteUrls) {
|
||||
AbstractBuild build = mock(AbstractBuild.class);
|
||||
BuildData buildData = mock(BuildData.class);
|
||||
when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
|
||||
when(build.getAction(BuildData.class)).thenReturn(buildData);
|
||||
when(build.getResult()).thenReturn(result);
|
||||
when(build.getUrl()).thenReturn(BUILD_URL);
|
||||
when(build.getResult()).thenReturn(result);
|
||||
when(build.getNumber()).thenReturn(BUILD_NUMBER);
|
||||
|
||||
AbstractProject<?, ?> project = mock(AbstractProject.class);
|
||||
when(project.getProperty(GiteeConnectionProperty.class)).thenReturn(new GiteeConnectionProperty(gitLabConnection));
|
||||
when(build.getProject()).thenReturn(project);
|
||||
EnvVars environment = mock(EnvVars.class);
|
||||
when(environment.expand(anyString())).thenAnswer(new Answer<String>() {
|
||||
@Override
|
||||
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||
return (String) invocation.getArguments()[0];
|
||||
}
|
||||
});
|
||||
try {
|
||||
when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return build;
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package com.gitee.jenkins.publisher;
|
||||
|
||||
|
||||
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.domains.Domain;
|
||||
import com.gitee.jenkins.connection.GiteeConnection;
|
||||
import com.gitee.jenkins.connection.GiteeConnectionConfig;
|
||||
import com.gitee.jenkins.connection.GiteeConnectionProperty;
|
||||
import com.gitee.jenkins.gitee.api.model.MergeRequest;
|
||||
import hudson.Launcher;
|
||||
import hudson.matrix.MatrixAggregatable;
|
||||
import hudson.matrix.MatrixAggregator;
|
||||
import hudson.matrix.MatrixBuild;
|
||||
import hudson.matrix.MatrixConfiguration;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Result;
|
||||
import hudson.plugins.git.util.BuildData;
|
||||
import hudson.tasks.Notifier;
|
||||
import hudson.util.Secret;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockserver.junit.MockServerRule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
|
||||
final class TestUtility {
|
||||
static final String GITEE_CONNECTION_V3 = "GiteeV3";
|
||||
static final String GITEE_CONNECTION_V4 = "GiteeV4";
|
||||
static final String BUILD_URL = "/build/123";
|
||||
static final int BUILD_NUMBER = 1;
|
||||
static final int PROJECT_ID = 3;
|
||||
static final int MERGE_REQUEST_ID = 1;
|
||||
static final int MERGE_REQUEST_IID = 2;
|
||||
|
||||
private static final String API_TOKEN = "secret";
|
||||
|
||||
static void setupGiteeConnections(JenkinsRule jenkins, MockServerRule mockServer) throws IOException {
|
||||
GiteeConnectionConfig connectionConfig = jenkins.get(GiteeConnectionConfig.class);
|
||||
String apiTokenId = "apiTokenId";
|
||||
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
|
||||
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
|
||||
List<Domain> domains = credentialsStore.getDomains();
|
||||
credentialsStore.addCredentials(domains.get(0),
|
||||
new StringCredentialsImpl(CredentialsScope.SYSTEM, apiTokenId, "Gitee API Token", Secret.fromString(TestUtility.API_TOKEN)));
|
||||
}
|
||||
}
|
||||
connectionConfig.addConnection(new GiteeConnection(TestUtility.GITEE_CONNECTION_V3, "http://localhost:" + mockServer.getPort() + "/gitee", apiTokenId, new V3GiteeClientBuilder(), false, 10, 10));
|
||||
connectionConfig.addConnection(new GiteeConnection(TestUtility.GITEE_CONNECTION_V4, "http://localhost:" + mockServer.getPort() + "/gitee", apiTokenId, new V4GiteeClientBuilder(), false, 10, 10));
|
||||
|
||||
}
|
||||
|
||||
static <T extends Notifier & MatrixAggregatable> void verifyMatrixAggregatable(Class<T> publisherClass, BuildListener listener) throws InterruptedException, IOException {
|
||||
AbstractBuild build = mock(AbstractBuild.class);
|
||||
AbstractProject project = mock(MatrixConfiguration.class);
|
||||
Notifier publisher = mock(publisherClass);
|
||||
MatrixBuild parentBuild = mock(MatrixBuild.class);
|
||||
|
||||
when(build.getParent()).thenReturn(project);
|
||||
when(((MatrixAggregatable) publisher).createAggregator(any(MatrixBuild.class), any(Launcher.class), any(BuildListener.class))).thenCallRealMethod();
|
||||
when(publisher.perform(any(AbstractBuild.class), any(Launcher.class), any(BuildListener.class))).thenReturn(true);
|
||||
|
||||
MatrixAggregator aggregator = ((MatrixAggregatable) publisher).createAggregator(parentBuild, null, listener);
|
||||
aggregator.startBuild();
|
||||
aggregator.endBuild();
|
||||
verify(publisher).perform(parentBuild, null, listener);
|
||||
}
|
||||
|
||||
static AbstractBuild mockSimpleBuild(String gitLabConnection, Result result, String... remoteUrls) {
|
||||
AbstractBuild build = mock(AbstractBuild.class);
|
||||
BuildData buildData = mock(BuildData.class);
|
||||
when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
|
||||
when(build.getAction(BuildData.class)).thenReturn(buildData);
|
||||
when(build.getResult()).thenReturn(result);
|
||||
when(build.getUrl()).thenReturn(BUILD_URL);
|
||||
when(build.getResult()).thenReturn(result);
|
||||
when(build.getNumber()).thenReturn(BUILD_NUMBER);
|
||||
|
||||
AbstractProject<?, ?> project = mock(AbstractProject.class);
|
||||
when(project.getProperty(GiteeConnectionProperty.class)).thenReturn(new GiteeConnectionProperty(gitLabConnection));
|
||||
when(build.getProject()).thenReturn(project);
|
||||
return build;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
static String formatNote(AbstractBuild build, String note) {
|
||||
String buildUrl = Jenkins.getInstance().getRootUrl() + build.getUrl();
|
||||
return MessageFormat.format(note, build.getResult(), build.getParent().getDisplayName(), BUILD_NUMBER, buildUrl);
|
||||
}
|
||||
|
||||
static <P extends MergeRequestNotifier> P preparePublisher(P publisher, AbstractBuild build) {
|
||||
P spyPublisher = spy(publisher);
|
||||
MergeRequest mergeRequest = new MergeRequest(MERGE_REQUEST_ID, MERGE_REQUEST_IID, "", "", "", PROJECT_ID, PROJECT_ID, "", "");
|
||||
doReturn(mergeRequest).when(spyPublisher).getMergeRequest(build);
|
||||
return spyPublisher;
|
||||
}
|
||||
|
||||
private TestUtility() { /* contains only static utility-methods */ }
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package com.gitee.jenkins.service;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.api.model.Branch;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gitee.jenkins.gitee.api.model.builder.generated.BranchBuilder.branch;
|
||||
import static java.util.Arrays.asList;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
|
||||
public class GiteeProjectBranchesServiceTest {
|
||||
private final static List<String> BRANCH_NAMES_PROJECT_B = asList("master", "B-branch-1", "B-branch-2");
|
||||
|
||||
private GiteeProjectBranchesService branchesService;
|
||||
|
||||
private GiteeClientStub clientStub;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
clientStub = new GiteeClientStub();
|
||||
clientStub.addBranches("groupOne/A", convert(asList("master", "A-branch-1")));
|
||||
clientStub.addBranches("groupOne/B", convert(BRANCH_NAMES_PROJECT_B));
|
||||
|
||||
|
||||
// never expire cache for tests
|
||||
branchesService = new GiteeProjectBranchesService();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnBranchNamesFromGiteeApi() {
|
||||
// when
|
||||
List<String> actualBranchNames = branchesService.getBranches(clientStub, "git@git.example.com:groupOne/B.git");
|
||||
|
||||
// then
|
||||
assertThat(actualBranchNames, is(BRANCH_NAMES_PROJECT_B));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotMakeUnnecessaryCallsToGiteeApiGetBranches() {
|
||||
// when
|
||||
branchesService.getBranches(clientStub, "git@git.example.com:groupOne/A.git");
|
||||
|
||||
// then
|
||||
assertEquals(1, clientStub.calls("groupOne/A", Branch.class));
|
||||
assertEquals(0, clientStub.calls("groupOne/B", Branch.class));
|
||||
}
|
||||
|
||||
private List<Branch> convert(List<String> branchNames) {
|
||||
ArrayList<Branch> result = new ArrayList<>();
|
||||
for (String branchName : branchNames) {
|
||||
result.add(branch().withName(branchName).build());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package com.gitee.jenkins.service;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.api.model.Label;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gitee.jenkins.gitee.api.model.builder.generated.LabelBuilder.label;
|
||||
import static java.util.Arrays.asList;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
|
||||
public class GiteeProjectLabelsServiceTest {
|
||||
|
||||
private final static List<String> LABELS_PROJECT_B = asList("label1", "label2", "label3");
|
||||
|
||||
private GiteeProjectLabelsService labelsService;
|
||||
|
||||
private GiteeClientStub clientStub;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
clientStub = new GiteeClientStub();
|
||||
clientStub.addLabels("groupOne/A", convert(asList("label1", "label2")));
|
||||
clientStub.addLabels("groupOne/B", convert(LABELS_PROJECT_B));
|
||||
|
||||
// never expire cache for tests
|
||||
labelsService = new GiteeProjectLabelsService();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnLabelsFromGiteeApi() {
|
||||
// when
|
||||
List<String> actualLabels = labelsService.getLabels(clientStub, "git@git.example.com:groupOne/B.git");
|
||||
|
||||
// then
|
||||
assertThat(actualLabels, is(LABELS_PROJECT_B));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotMakeUnnecessaryCallsToGiteeApiGetLabels() {
|
||||
// when
|
||||
labelsService.getLabels(clientStub, "git@git.example.com:groupOne/A.git");
|
||||
|
||||
// then
|
||||
assertEquals(1, clientStub.calls("groupOne/A", Label.class));
|
||||
assertEquals(0, clientStub.calls("groupOne/B", Label.class));
|
||||
}
|
||||
|
||||
private List<Label> convert(List<String> labels) {
|
||||
ArrayList<Label> result = new ArrayList<>();
|
||||
for (String label : labels) {
|
||||
result.add(label().withName(label).build());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
package com.gitee.jenkins.service;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.model.*;
|
||||
import com.gitee.jenkins.gitee.hook.model.State;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
|
||||
class GiteeClientStub implements GiteeClient {
|
||||
private final Map<Pair<String, Class>, List<?>> data;
|
||||
private final Map<Pair<String, Class>, Integer> calls;
|
||||
|
||||
GiteeClientStub() {
|
||||
data = new HashMap<>();
|
||||
calls = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostUrl() {
|
||||
return "";
|
||||
}
|
||||
|
||||
void addBranches(String project, List<Branch> branches) {
|
||||
addData(project, Branch.class, branches);
|
||||
}
|
||||
|
||||
void addLabels(String project, List<Label> labels) {
|
||||
addData(project, Label.class, labels);
|
||||
}
|
||||
|
||||
int calls(String projectId, Class dataClass) {
|
||||
Pair<String, Class> key = createKey(projectId, dataClass);
|
||||
return calls.containsKey(key) ? calls.get(key) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Branch> getBranches(String projectId) {
|
||||
return getData(projectId, Branch.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Label> getLabels(String projectId) {
|
||||
return getData(projectId, Label.class);
|
||||
}
|
||||
|
||||
private void addData(String projectId, Class dataClass, List<?> datas) {
|
||||
data.put(createKey(projectId, dataClass), datas);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> List<T> getData(String projectId, Class dataClass) {
|
||||
Pair<String, Class> key = createKey(projectId, dataClass);
|
||||
if (!calls.containsKey(key)) {
|
||||
calls.put(key, 0);
|
||||
}
|
||||
|
||||
calls.put(key, calls.get(key) + 1);
|
||||
|
||||
return (List<T>) data.get(key);
|
||||
}
|
||||
|
||||
private Pair<String, Class> createKey(String projectId, Class dataClass) {
|
||||
return new ImmutablePair<>(projectId, dataClass);
|
||||
}
|
||||
|
||||
|
||||
/************** no implementation below ********************************/
|
||||
|
||||
@Override
|
||||
public Project createProject(String projectName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject(String projectName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project updateProject(String projectId, String name, String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProject(String projectId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProjectHook(String projectId, String url, Boolean pushEvents, Boolean mergeRequestEvents, Boolean noteEvents) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(String projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(Integer projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getCommit(String projectId, String sha) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptMergeRequest(MergeRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMergeRequestNote(MergeRequest mr, String body) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MergeRequest> getMergeRequests(String projectId, State state, int page, int perPage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Branch getBranch(String projectId, String branch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User addUser(String email, String username, String name, String password) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User updateUser(String userId, String email, String username, String name, String password) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pipeline> getPipelines(String projectName) {
|
||||
return emptyList();
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.gitee.jenkins.testhelpers;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.PushHook;
|
||||
|
||||
public interface GiteePushRequestSamples {
|
||||
PushHook pushBrandNewMasterBranchRequest();
|
||||
|
||||
PushHook pushNewBranchRequest();
|
||||
|
||||
PushHook pushCommitRequest();
|
||||
|
||||
PushHook mergePushRequest();
|
||||
|
||||
PushHook pushNewTagRequest();
|
||||
|
||||
PushHook deleteBranchRequest();
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
package com.gitee.jenkins.testhelpers;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.PushHook;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.CommitBuilder.commit;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.PushHookBuilder.pushHook;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.RepositoryBuilder.repository;
|
||||
|
||||
public class GiteePushRequestSamples_7_10_5_489b413 implements GiteePushRequestSamples {
|
||||
|
||||
private static final String ZERO_SHA = "0000000000000000000000000000000000000000";
|
||||
private static final String COMMIT_7A = "7a5db3baf5d42b4218a2a501c88f745559b1d24c";
|
||||
private static final String COMMIT_21 = "21d67fe28097b49a1a6fb5c82cbfe03d389e8685";
|
||||
private static final String COMMIT_9d = "9dbdd7a128a2789d0f436222ce116f1d8229e083";
|
||||
|
||||
public PushHook pushBrandNewMasterBranchRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/master")
|
||||
.withBefore(ZERO_SHA)
|
||||
.withAfter(COMMIT_7A)
|
||||
// no commit on new branches
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook pushNewBranchRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/test-new-branch1")
|
||||
.withBefore(ZERO_SHA).withAfter(COMMIT_7A)
|
||||
// no commit on new branches
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook pushCommitRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/test-new-branch1")
|
||||
.withBefore(COMMIT_7A)
|
||||
.withAfter(COMMIT_21)
|
||||
.withCommits(Collections.singletonList(commit().withId(COMMIT_21).build()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook mergePushRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/master")
|
||||
.withBefore("ca84f96a846b0e241808ea7b75dfa3bf4cd3b98b")
|
||||
.withAfter(COMMIT_9d)
|
||||
.withCommits(Arrays.asList(
|
||||
commit().withId(COMMIT_21).build(),
|
||||
commit().withId("c04c8822d1df397fb7e6dd3dd133018a0af567a8").build(),
|
||||
commit().withId(COMMIT_9d).build())
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook pushNewTagRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/tags/test-tag-1")
|
||||
.withBefore(ZERO_SHA)
|
||||
.withAfter(COMMIT_21)
|
||||
.withCommits(Collections.singletonList(commit().withId(COMMIT_21).build()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook deleteBranchRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/test-branch-3-delete")
|
||||
.withBefore("c34984ff6ed9935b3d843237947adbaaa85fc5f9").withAfter(ZERO_SHA)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
package com.gitee.jenkins.testhelpers;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.PushHook;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.CommitBuilder.commit;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.PushHookBuilder.pushHook;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.RepositoryBuilder.repository;
|
||||
|
||||
public class GiteePushRequestSamples_7_5_1_36679b5 implements GiteePushRequestSamples {
|
||||
|
||||
private static final String ZERO_SHA = "0000000000000000000000000000000000000000";
|
||||
|
||||
public PushHook pushBrandNewMasterBranchRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/master")
|
||||
.withBefore(ZERO_SHA)
|
||||
.withAfter("d91a0f248625f6dc808fb7cda75c4ee01516b609")
|
||||
// no checkout_sha and no commit on new branches
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook pushNewBranchRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/test-new-branch1")
|
||||
.withBefore(ZERO_SHA)
|
||||
.withAfter("2bf4170829aedd706d7485d40091a01637b9abf4")
|
||||
// no checkout_sha and no commit on new branches
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook pushCommitRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/test-new-branch1")
|
||||
.withBefore("2bf4170829aedd706d7485d40091a01637b9abf4")
|
||||
.withAfter("4bf0fcd937085dc2f69dcbe31f2ef960ec9ca7eb")
|
||||
// no checkout_sha
|
||||
.withCommits(Collections.singletonList(commit().withId("4bf0fcd937085dc2f69dcbe31f2ef960ec9ca7eb").build()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook mergePushRequest() {
|
||||
return pushHook().withRef("refs/heads/master")
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withBefore("27548e742f40971f75c715aaa7920404eeff6616")
|
||||
.withAfter("3ebb6927ad4afbe8a11830938b3584cdaf4d657b")
|
||||
// no checkout_sha
|
||||
.withCommits(Arrays.asList(
|
||||
commit().withId("4bf0fcd937085dc2f69dcbe31f2ef960ec9ca7eb").build(),
|
||||
commit().withId("be473fcc670b920cc9795581a5cd8f00fa7afddd").build(),
|
||||
commit().withId("3ebb6927ad4afbe8a11830938b3584cdaf4d657b").build())
|
||||
)
|
||||
.build();
|
||||
// and afterwards the "delete branch" request comes in
|
||||
}
|
||||
|
||||
public PushHook pushNewTagRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/tags/test-tag-2")
|
||||
.withBefore(ZERO_SHA).withAfter("f10d9d7b648e5a3e55fe8fe865aba5aa7404df7c")
|
||||
// no checkout_sha and no commit on new branches
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook deleteBranchRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/test-branch-delete-1")
|
||||
.withBefore("3ebb6927ad4afbe8a11830938b3584cdaf4d657b").withAfter(ZERO_SHA)
|
||||
// no checkout_sha and no commit on new branches
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
package com.gitee.jenkins.testhelpers;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.PushHook;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.CommitBuilder.commit;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.PushHookBuilder.pushHook;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.RepositoryBuilder.repository;
|
||||
|
||||
public class GiteePushRequestSamples_8_1_2_8c8af7b implements GiteePushRequestSamples {
|
||||
|
||||
private static final String ZERO_SHA = "0000000000000000000000000000000000000000";
|
||||
private static final String COMMIT_25 = "258d6f6e21e6dda343f6e9f8e78c38f12bb81c87";
|
||||
private static final String COMMIT_63 = "63b30060be89f0338123f2d8975588e7d40a1874";
|
||||
private static final String COMMIT_64 = "64ed77c360ee7ac900c68292775bee2184c1e593";
|
||||
private static final String COMMIT_74 = "742d8d0b4b16792c38c6798b28ba1fa754da165e";
|
||||
private static final String COMMIT_E5 = "e5a46665b80965724b45fe921788105258b3ec5c";
|
||||
|
||||
public PushHook pushBrandNewMasterBranchRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/master")
|
||||
.withBefore(ZERO_SHA)
|
||||
.withAfter(COMMIT_63)
|
||||
// no commit on new branches
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook pushNewBranchRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/test-new-branch1")
|
||||
.withBefore(ZERO_SHA)
|
||||
.withAfter(COMMIT_25)
|
||||
// no commit on new branches
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook pushCommitRequest() {
|
||||
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/test-new-branch1")
|
||||
.withBefore(COMMIT_25)
|
||||
.withAfter(COMMIT_74)
|
||||
.withCommits(Collections.singletonList(commit().withId(COMMIT_74).build()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook mergePushRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/master")
|
||||
.withBefore("e8b9327c9704e308949f9d31dd0fae6abfac3798")
|
||||
.withAfter(COMMIT_E5)
|
||||
.withCommits(Arrays.asList(
|
||||
commit().withId(COMMIT_74).build(),
|
||||
commit().withId("ab569fa9c51fa80d6509b277a6b587faf8e7cb72").build(),
|
||||
commit().withId(COMMIT_E5).build())
|
||||
)
|
||||
.build();
|
||||
|
||||
// and afterwards the "delete branch" request comes in
|
||||
}
|
||||
|
||||
public PushHook pushNewTagRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/tags/test-tag-2")
|
||||
.withBefore(ZERO_SHA)
|
||||
.withAfter(COMMIT_64)
|
||||
.withCommits(Collections.singletonList(commit().withId(COMMIT_64).build()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public PushHook deleteBranchRequest() {
|
||||
return pushHook()
|
||||
.withUserId(123)
|
||||
.withUserName("admin@example")
|
||||
.withProjectId(345)
|
||||
.withRepository(repository()
|
||||
.withName("test-repo")
|
||||
.withUrl("git@gitlabserver.example.com:test-group/test-repo.git")
|
||||
.withHomepage("http://gitlabserver.example.com/test-group/test-repo")
|
||||
.build())
|
||||
.withRef("refs/heads/test-branch-delete-1")
|
||||
.withBefore("784c5ca7814aa7ea1913ae8e64187c31322946f0")
|
||||
.withAfter(ZERO_SHA)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
package com.gitee.jenkins.testing.gitlab.rule;
|
||||
|
||||
|
||||
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.domains.Domain;
|
||||
import com.gitee.jenkins.connection.GiteeConnection;
|
||||
import com.gitee.jenkins.connection.GiteeConnectionConfig;
|
||||
import com.gitee.jenkins.connection.GiteeConnectionProperty;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.model.MergeRequest;
|
||||
import com.gitee.jenkins.gitee.api.model.Pipeline;
|
||||
import com.gitee.jenkins.gitee.api.model.Project;
|
||||
import com.gitee.jenkins.gitee.api.model.User;
|
||||
import hudson.util.Secret;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class GiteeRule implements TestRule {
|
||||
private static final String API_TOKEN_ID = "apiTokenId";
|
||||
private static final String PASSWORD = "integration-test";
|
||||
|
||||
private final String url;
|
||||
private final int postgresPort;
|
||||
|
||||
private GiteeClient clientCache;
|
||||
|
||||
private List<String> projectIds = new ArrayList<>();
|
||||
|
||||
public GiteeRule(String url, int postgresPort) {
|
||||
this.url = url;
|
||||
this.postgresPort = postgresPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
return new GiteeStatement(base);
|
||||
}
|
||||
|
||||
public Project getProject(final String projectName) {
|
||||
return client().getProject(projectName);
|
||||
}
|
||||
|
||||
public List<Pipeline> getPipelines(int projectId) {
|
||||
return client().getPipelines(String.valueOf(projectId));
|
||||
}
|
||||
|
||||
public List<String> getProjectIds() {
|
||||
return projectIds;
|
||||
}
|
||||
|
||||
public String createProject(ProjectRequest request) {
|
||||
Project project = client().createProject(request.getName());
|
||||
projectIds.add(project.getId().toString());
|
||||
if (request.getWebHookUrl() != null && (request.isPushHook() || request.isMergeRequestHook() || request.isNoteHook())) {
|
||||
client().addProjectHook(project.getId().toString(), request.getWebHookUrl(), request.isPushHook(), request.isMergeRequestHook(), request.isNoteHook());
|
||||
}
|
||||
return project.getHttpUrlToRepo();
|
||||
}
|
||||
|
||||
public GiteeConnectionProperty createGiteeConnectionProperty() throws IOException {
|
||||
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
|
||||
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
|
||||
List<Domain> domains = credentialsStore.getDomains();
|
||||
credentialsStore.addCredentials(domains.get(0),
|
||||
new StringCredentialsImpl(CredentialsScope.SYSTEM, API_TOKEN_ID, "Gitee API Token", Secret.fromString(getApiToken())));
|
||||
}
|
||||
}
|
||||
|
||||
GiteeConnectionConfig config = Jenkins.getInstance().getDescriptorByType(GiteeConnectionConfig.class);
|
||||
GiteeConnection connection = new GiteeConnection("test", url, API_TOKEN_ID, new V3GiteeClientBuilder(), true,10, 10);
|
||||
config.addConnection(connection);
|
||||
config.save();
|
||||
return new GiteeConnectionProperty(connection.getName());
|
||||
}
|
||||
|
||||
public MergeRequest createMergeRequest(final Integer projectId,
|
||||
final String sourceBranch,
|
||||
final String targetBranch,
|
||||
final String title) {
|
||||
return client().createMergeRequest(projectId, sourceBranch, targetBranch, title);
|
||||
}
|
||||
|
||||
public void createMergeRequestNote(MergeRequest mr, String body) {
|
||||
client().createMergeRequestNote(mr, body);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return client().getCurrentUser().getUsername();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return PASSWORD;
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
for (String projectId : projectIds) {
|
||||
String randomProjectName = UUID.randomUUID().toString();
|
||||
// rename the project before deleting as the deletion will take a while
|
||||
client().updateProject(projectId, randomProjectName, randomProjectName);
|
||||
client().deleteProject(projectId);
|
||||
}
|
||||
}
|
||||
|
||||
private String getApiToken() {
|
||||
try {
|
||||
Class.forName("org.postgresql.Driver");
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:" + postgresPort + "/gitlabhq_production", "gitee", "password")) {
|
||||
ResultSet resultSet = connection.createStatement().executeQuery("SELECT authentication_token FROM users WHERE username = 'root'");
|
||||
resultSet.next();
|
||||
return resultSet.getString("authentication_token");
|
||||
}
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private GiteeClient client() {
|
||||
if (clientCache == null) {
|
||||
clientCache = new V3GiteeClientBuilder().buildClient(url, getApiToken(), false, -1, -1);
|
||||
User user = clientCache.getCurrentUser();
|
||||
client().updateUser(user.getId().toString(), user.getEmail(), user.getUsername(), user.getName(), PASSWORD);
|
||||
}
|
||||
return clientCache;
|
||||
}
|
||||
|
||||
private class GiteeStatement extends Statement {
|
||||
private final Statement next;
|
||||
|
||||
private GiteeStatement(Statement next) {
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
try {
|
||||
next.evaluate();
|
||||
} finally {
|
||||
GiteeRule.this.cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package com.gitee.jenkins.testing.gitlab.rule;
|
||||
|
||||
import net.karneim.pojobuilder.GeneratePojoBuilder;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class ProjectRequest {
|
||||
|
||||
private final String name;
|
||||
private final String webHookUrl;
|
||||
private final boolean pushHook;
|
||||
private final boolean mergeRequestHook;
|
||||
private final boolean noteHook;
|
||||
private final boolean pipelineHook;
|
||||
|
||||
@GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*")
|
||||
public ProjectRequest(String name, String webHookUrl, boolean pushHook, boolean mergeRequestHook, boolean noteHook,
|
||||
boolean pipelineHook) {
|
||||
this.name = name;
|
||||
this.webHookUrl = webHookUrl;
|
||||
this.pushHook = pushHook;
|
||||
this.mergeRequestHook = mergeRequestHook;
|
||||
this.noteHook = noteHook;
|
||||
this.pipelineHook = pipelineHook;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getWebHookUrl() {
|
||||
return webHookUrl;
|
||||
}
|
||||
|
||||
public boolean isPushHook() {
|
||||
return pushHook;
|
||||
}
|
||||
|
||||
public boolean isMergeRequestHook() {
|
||||
return mergeRequestHook;
|
||||
}
|
||||
|
||||
public boolean isNoteHook() {
|
||||
return noteHook;
|
||||
}
|
||||
|
||||
public boolean isPipelineHook() {
|
||||
return pipelineHook;
|
||||
}
|
||||
}
|
|
@ -1,272 +0,0 @@
|
|||
package com.gitee.jenkins.testing.integration;
|
||||
|
||||
|
||||
import com.gitee.jenkins.trigger.GiteePushTrigger;
|
||||
import com.gitee.jenkins.gitee.api.model.MergeRequest;
|
||||
import com.gitee.jenkins.gitee.api.model.Pipeline;
|
||||
import com.gitee.jenkins.testing.gitlab.rule.GiteeRule;
|
||||
import com.gitee.jenkins.trigger.filter.BranchFilterType;
|
||||
import hudson.Launcher;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Descriptor;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.tasks.Publisher;
|
||||
import hudson.util.DescribableList;
|
||||
import hudson.util.OneShotEvent;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.StoredConfig;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.jvnet.hudson.test.SleepBuilder;
|
||||
import org.jvnet.hudson.test.TestBuilder;
|
||||
import org.jvnet.hudson.test.TestNotifier;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gitee.jenkins.builder.generated.GiteePushTriggerBuilder.giteePushTrigger;
|
||||
import static com.gitee.jenkins.testing.gitlab.rule.builder.generated.ProjectRequestBuilder.projectRequest;
|
||||
import static java.lang.Integer.parseInt;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
||||
import static org.hamcrest.collection.IsEmptyCollection.empty;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class GiteeIT {
|
||||
private static final String GITEE_URL = "http://localhost:" + System.getProperty("gitee.http.port", "10080");
|
||||
|
||||
@Rule
|
||||
public GiteeRule gitlab = new GiteeRule(GITEE_URL, parseInt(System.getProperty("postgres.port", "5432")));
|
||||
|
||||
@Rule
|
||||
public JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void buildOnPush() throws IOException, InterruptedException, GitAPIException {
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject("test");
|
||||
GiteePushTrigger trigger = giteePushTrigger().withTriggerOnPush(true).withBranchFilterType(BranchFilterType.All).build();
|
||||
project.addTrigger(trigger);
|
||||
trigger.start(project, true);
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
|
||||
createGiteeProject(false,true, true, false);
|
||||
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void buildOnMergeRequest() throws IOException, InterruptedException, GitAPIException {
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject("test");
|
||||
GiteePushTrigger trigger = giteePushTrigger().withTriggerOnOpenMergeRequest(true).withBranchFilterType(BranchFilterType.All).build();
|
||||
project.addTrigger(trigger);
|
||||
trigger.start(project, true);
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
|
||||
Pair<Integer, String> gitlabData = createGiteeProject(true,false, false, true);
|
||||
|
||||
gitlab.createMergeRequest(gitlabData.getLeft(), "feature", "master", "Merge feature branch to master.");
|
||||
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildOnNote() throws IOException, InterruptedException, GitAPIException {
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject("test");
|
||||
GiteePushTrigger trigger = giteePushTrigger()
|
||||
.withTriggerOnNoteRequest(true)
|
||||
.withNoteRegex(".*test.*")
|
||||
.withBranchFilterType(BranchFilterType.All).build();
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
|
||||
Pair<Integer, String> gitlabData = createGiteeProject(true, false, true, false);
|
||||
|
||||
// create merge-request
|
||||
MergeRequest mr = gitlab.createMergeRequest(gitlabData.getLeft(), "feature", "master", "Merge feature branch to master.");
|
||||
|
||||
// add trigger after push/merge-request so it may only receive the note-hook
|
||||
project.addTrigger(trigger);
|
||||
trigger.start(project, true);
|
||||
|
||||
gitlab.createMergeRequestNote(mr, "this is a test note");
|
||||
|
||||
buildTriggered.block(20000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reportBuildStatus() throws IOException, InterruptedException, GitAPIException {
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
final OneShotEvent buildReported = new OneShotEvent();
|
||||
|
||||
GiteePushTrigger trigger = giteePushTrigger()
|
||||
.withTriggerOnPush(true)
|
||||
.withBranchFilterType(BranchFilterType.All)
|
||||
.build();
|
||||
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject("test");
|
||||
project.addProperty(gitlab.createGiteeConnectionProperty());
|
||||
project.addTrigger(trigger);
|
||||
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.getBuildersList().add(new SleepBuilder(20000));
|
||||
|
||||
DescribableList<Publisher, Descriptor<Publisher>> publishers = project.getPublishersList();
|
||||
publishers.add(new GiteeCommitStatusPublisher("integration-test", false));
|
||||
publishers.add(new TestNotifier() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildReported.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
trigger.start(project, true);
|
||||
project.setQuietPeriod(0);
|
||||
|
||||
|
||||
Pair<Integer, String> gitlabData = createGiteeProject(false,true, true, false);
|
||||
assertThat(gitlab.getPipelines(gitlabData.getLeft()), empty());
|
||||
|
||||
buildTriggered.block(20000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
assertPipelineStatus(gitlabData, "running");
|
||||
|
||||
buildReported.block(40000);
|
||||
assertThat(buildReported.isSignaled(), is(true));
|
||||
|
||||
Thread.sleep(5000); // wait for gitee to update
|
||||
assertPipelineStatus(gitlabData, "success");
|
||||
}
|
||||
|
||||
private void assertPipelineStatus(Pair<Integer, String> gitlabData, String status) {
|
||||
List<Pipeline> pipelines = gitlab.getPipelines(gitlabData.getLeft());
|
||||
assertThat(pipelines, hasSize(1));
|
||||
|
||||
Pipeline pipeline = pipelines.get(0);
|
||||
assertEquals(gitlabData.getRight(), pipeline.getSha());
|
||||
assertEquals(status, pipeline.getStatus());
|
||||
}
|
||||
|
||||
private Pair<Integer, String> createGiteeProject(boolean addFeatureBranch, boolean withPushHook, boolean withNoteHook, boolean withMergeRequestHook) throws IOException, GitAPIException {
|
||||
// check for clean slate
|
||||
assertTrue(gitlab.getProjectIds().isEmpty());
|
||||
|
||||
String url = gitlab.createProject(projectRequest()
|
||||
.withName("test")
|
||||
.withWebHookUrl("http://" + getDocker0Ip() + ":" + jenkins.getURL().getPort() + "/jenkins/project/test")
|
||||
.withPushHook(withPushHook)
|
||||
.withNoteHook(withNoteHook)
|
||||
.withMergeRequestHook(withMergeRequestHook)
|
||||
.build());
|
||||
|
||||
String sha = initGiteeProject(url, addFeatureBranch);
|
||||
|
||||
// Fix: Hack to get the project id
|
||||
// A preferable approach would be here to get the target project by name using getProject function of the
|
||||
// GiteeRule and to use the id from the project instance. However, due to a bug in Gitee (tested on 8.6.1)
|
||||
// retrieving the project by name is not properly working.
|
||||
// (see issue https://github.com/gitlabhq/gitlabhq/issues/4921).
|
||||
// Once the issue is resolved, replace this implementation.
|
||||
List<String> projectIds = gitlab.getProjectIds();
|
||||
assertSame(projectIds.size(), 1);
|
||||
return new ImmutablePair<>(parseInt(projectIds.get(0)), sha);
|
||||
}
|
||||
|
||||
private String initGiteeProject(String url, boolean addFeatureBranch) throws GitAPIException, IOException {
|
||||
// Setup git repository
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
StoredConfig config = git.getRepository().getConfig();
|
||||
config.setString("remote", "origin", "url", url);
|
||||
config.save();
|
||||
|
||||
// Setup remote master branch
|
||||
tmp.newFile("test");
|
||||
git.add().addFilepattern("test");
|
||||
RevCommit commit = git.commit().setMessage("test").call();
|
||||
git.push()
|
||||
.setRemote("origin").add("master")
|
||||
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitlab.getUsername(), gitlab.getPassword()))
|
||||
.call();
|
||||
|
||||
if (addFeatureBranch) {
|
||||
// Setup remote feature branch
|
||||
git.checkout().setName("feature").setCreateBranch(true).call();
|
||||
tmp.newFile("feature");
|
||||
commit = git.commit().setMessage("feature").call();
|
||||
git.push().setRemote("origin").add("feature").setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitlab.getUsername(), gitlab.getPassword()))
|
||||
.call();
|
||||
}
|
||||
|
||||
return commit.getName();
|
||||
}
|
||||
|
||||
private String getDocker0Ip() {
|
||||
try {
|
||||
Enumeration<InetAddress> docker0Addresses = NetworkInterface.getByName("docker0").getInetAddresses();
|
||||
while (docker0Addresses.hasMoreElements()) {
|
||||
InetAddress inetAddress = docker0Addresses.nextElement();
|
||||
if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
|
||||
return inetAddress.getHostAddress();
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("docker0 not available");
|
||||
} catch (SocketException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.filter;
|
||||
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class AllBranchesFilterTest {
|
||||
|
||||
@Test
|
||||
public void isRandomBranchNameAllowed() {
|
||||
String randomBranchName = RandomStringUtils.random(10, true, false);
|
||||
|
||||
assertThat(new AllBranchesFilter().isBranchAllowed(randomBranchName), is(true));
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.filter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.gitee.jenkins.trigger.filter.BranchFilterConfig.BranchFilterConfigBuilder.branchFilterConfig;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class BranchFilterFactoryTest {
|
||||
|
||||
@Test
|
||||
public void getAllBranchesFilter() {
|
||||
BranchFilter branchFilter = BranchFilterFactory.newBranchFilter(branchFilterConfig()
|
||||
.withIncludeBranchesSpec("master")
|
||||
.withExcludeBranchesSpec("develop")
|
||||
.withTargetBranchRegex(".*")
|
||||
.build(BranchFilterType.All));
|
||||
|
||||
assertThat(branchFilter, instanceOf(AllBranchesFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameBasedFilterFilter() {
|
||||
BranchFilter branchFilter = BranchFilterFactory.newBranchFilter(branchFilterConfig()
|
||||
.withIncludeBranchesSpec("master")
|
||||
.withExcludeBranchesSpec("develop")
|
||||
.withTargetBranchRegex(".*")
|
||||
.build(BranchFilterType.NameBasedFilter));
|
||||
|
||||
assertThat(branchFilter, instanceOf(NameBasedFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRegexBasedFilterFilter() {
|
||||
BranchFilter branchFilter = BranchFilterFactory.newBranchFilter(branchFilterConfig()
|
||||
.withIncludeBranchesSpec("master")
|
||||
.withExcludeBranchesSpec("develop")
|
||||
.withTargetBranchRegex(".*")
|
||||
.build(BranchFilterType.RegexBasedFilter));
|
||||
|
||||
assertThat(branchFilter, instanceOf(RegexBasedFilter.class));
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.filter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class MergeRequestLabelFilterImplTest {
|
||||
|
||||
@Test
|
||||
public void includeLabels() {
|
||||
MergeRequestLabelFilterImpl mergeRequestLabelFilter = new MergeRequestLabelFilterImpl("include, include2", "");
|
||||
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("include")), is(true));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("include2")), is(true));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("other-label")), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludeLabels() {
|
||||
MergeRequestLabelFilterImpl mergeRequestLabelFilter = new MergeRequestLabelFilterImpl("", "exclude, exclude2");
|
||||
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("exclude")), is(false));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("exclude2")), is(false));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("other-label")), is(true));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.<String>emptySet()), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includeAndExcludeLabels() {
|
||||
MergeRequestLabelFilterImpl mergeRequestLabelFilter = new MergeRequestLabelFilterImpl("include, include2", "exclude, exclude2");
|
||||
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("include")), is(true));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("include2")), is(true));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("exclude")), is(false));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("exclude2")), is(false));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Collections.singleton("other-label")), is(false));
|
||||
assertThat(mergeRequestLabelFilter.isMergeRequestAllowed(Arrays.asList("include", "exclude")), is(false));
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.filter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class NameBasedFilterTest {
|
||||
|
||||
@Test
|
||||
public void includeBranches() {
|
||||
NameBasedFilter nameBasedFilter = new NameBasedFilter("master, develop", "");
|
||||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(true));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(true));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("not-included-branch"), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void excludeBranches() {
|
||||
NameBasedFilter nameBasedFilter = new NameBasedFilter("", "master, develop");
|
||||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(false));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(false));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("not-excluded-branch"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includeAndExcludeBranches() {
|
||||
NameBasedFilter nameBasedFilter = new NameBasedFilter("master", "develop");
|
||||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(true));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(false));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("not-excluded-and-not-included-branch"), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowIncludeAndExcludeToBeNull() {
|
||||
NameBasedFilter nameBasedFilter = new NameBasedFilter(null, null);
|
||||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowIncludeToBeNull() {
|
||||
NameBasedFilter nameBasedFilter = new NameBasedFilter(null, "master, develop");
|
||||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(false));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(false));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("not-excluded-branch"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowExcludeToBeNull() {
|
||||
NameBasedFilter nameBasedFilter = new NameBasedFilter("master, develop", null);
|
||||
|
||||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(true));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(true));
|
||||
assertThat(nameBasedFilter.isBranchAllowed("not-included-branch"), is(false));
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.filter;
|
||||
|
||||
import org.junit.experimental.theories.DataPoints;
|
||||
import org.junit.experimental.theories.FromDataPoints;
|
||||
import org.junit.experimental.theories.Theories;
|
||||
import org.junit.experimental.theories.Theory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@RunWith(Theories.class)
|
||||
public class RegexBasedFilterTest {
|
||||
|
||||
@DataPoints("matching-branches")
|
||||
public static String[] matchingBranchNames = {"feature/test", "feature/awesome-feature"};
|
||||
|
||||
@DataPoints("not-matching-branches")
|
||||
public static String[] notMatchingBranchNames = {"hotfix/test", "hotfix/awesome-feature", "master", "develop"};
|
||||
|
||||
@Theory
|
||||
public void isRegexBranchAllowed(@FromDataPoints("matching-branches") String branchName) {
|
||||
RegexBasedFilter featureBranches = new RegexBasedFilter("feature/.*");
|
||||
|
||||
assertThat(featureBranches.isBranchAllowed(branchName), is(true));
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void isRegexBranchNotAllowed(@FromDataPoints("not-matching-branches") String branchName) {
|
||||
RegexBasedFilter featureBranches = new RegexBasedFilter("feature/.*");
|
||||
|
||||
assertThat(featureBranches.isBranchAllowed(branchName), is(false));
|
||||
}
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.handler;
|
||||
|
||||
import com.gitee.jenkins.trigger.GiteePushTrigger;
|
||||
import com.gitee.jenkins.connection.GiteeConnectionProperty;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.model.BuildState;
|
||||
import com.gitee.jenkins.gitee.hook.model.*;
|
||||
import com.gitee.jenkins.gitee.hook.model.builder.generated.*;
|
||||
import com.gitee.jenkins.trigger.filter.BranchFilterType;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.model.ItemGroup;
|
||||
import hudson.model.Project;
|
||||
import hudson.model.Queue;
|
||||
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.CommitBuilder.commit;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.MergeRequestObjectAttributesBuilder.mergeRequestObjectAttributes;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.UserBuilder.user;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PendingBuildsHandlerTest {
|
||||
|
||||
private static final String GITEE_BUILD_NAME = "Jenkins";
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Mock
|
||||
private GiteeClient giteeClient;
|
||||
|
||||
@Mock
|
||||
private GiteeConnectionProperty giteeConnectionProperty;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
when(giteeConnectionProperty.getClient()).thenReturn(giteeClient);
|
||||
}
|
||||
|
||||
@After
|
||||
public void clearQueue() {
|
||||
Queue queue = jenkins.getInstance().getQueue();
|
||||
for (Queue.Item item : queue.getItems()) {
|
||||
queue.cancel(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void projectCanBeConfiguredToSendPendingBuildStatusWhenTriggered() throws IOException {
|
||||
Project project = freestyleProject("freestyleProject1", new GiteeCommitStatusPublisher(GITEE_BUILD_NAME, false));
|
||||
|
||||
GiteePushTrigger giteePushTrigger = giteePushTrigger(project);
|
||||
|
||||
giteePushTrigger.onPost(pushHook(1, "branch1", "commit1"));
|
||||
|
||||
verify(giteeClient).changeBuildStatus(eq(1), eq("commit1"), eq(BuildState.pending), eq("branch1"), eq(GITEE_BUILD_NAME),
|
||||
contains("/freestyleProject1/"), eq(BuildState.pending.name()));
|
||||
verifyNoMoreInteractions(giteeClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workflowJobCanConfiguredToSendToPendingBuildStatusWhenTriggered() throws IOException {
|
||||
WorkflowJob workflowJob = workflowJob();
|
||||
|
||||
GiteePushTrigger giteePushTrigger = giteePushTrigger(workflowJob);
|
||||
giteePushTrigger.setPendingBuildName(GITEE_BUILD_NAME);
|
||||
|
||||
giteePushTrigger.onPost(mergeRequestHook(1, "branch1", "commit1"));
|
||||
|
||||
verify(giteeClient).changeBuildStatus(eq(1), eq("commit1"), eq(BuildState.pending), eq("branch1"), eq(GITEE_BUILD_NAME),
|
||||
contains("/workflowJob/"), eq(BuildState.pending.name()));
|
||||
verifyNoMoreInteractions(giteeClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queuedMergeRequestBuildsCanBeCancelledOnMergeRequestUpdate() throws IOException {
|
||||
Project project = freestyleProject("project1", new GiteeCommitStatusPublisher(GITEE_BUILD_NAME, false));
|
||||
|
||||
GiteePushTrigger giteePushTrigger = giteePushTrigger(project);
|
||||
giteePushTrigger.setCancelPendingBuildsOnUpdate(true);
|
||||
|
||||
assertThat(jenkins.getInstance().getQueue().getItems().length, is(0));
|
||||
|
||||
giteePushTrigger.onPost(mergeRequestHook(1, "sourceBranch", "commit1")); // Will be cancelled
|
||||
giteePushTrigger.onPost(mergeRequestHook(1, "sourceBranch", "commit2")); // Will be cancelled
|
||||
giteePushTrigger.onPost(mergeRequestHook(1, "sourceBranch", "commit3"));
|
||||
giteePushTrigger.onPost(mergeRequestHook(1, "anotherBranch", "commit4"));
|
||||
giteePushTrigger.onPost(mergeRequestHook(2, "sourceBranch", "commit5"));
|
||||
|
||||
verify(giteeClient).changeBuildStatus(eq(1), eq("commit1"), eq(BuildState.canceled), eq("sourceBranch"),
|
||||
eq("Jenkins"), contains("project1"), eq(BuildState.canceled.name()));
|
||||
verify(giteeClient).changeBuildStatus(eq(1), eq("commit2"), eq(BuildState.canceled), eq("sourceBranch"),
|
||||
eq("Jenkins"), contains("project1"), eq(BuildState.canceled.name()));
|
||||
|
||||
assertThat(jenkins.getInstance().getQueue().getItems().length, is(3));
|
||||
}
|
||||
|
||||
private GiteePushTrigger giteePushTrigger(Project project) throws IOException {
|
||||
GiteePushTrigger giteePushTrigger = giteePushTrigger();
|
||||
project.addTrigger(giteePushTrigger);
|
||||
giteePushTrigger.start(project,true);
|
||||
return giteePushTrigger;
|
||||
}
|
||||
|
||||
private GiteePushTrigger giteePushTrigger(WorkflowJob workflowJob) {
|
||||
GiteePushTrigger giteePushTrigger = giteePushTrigger();
|
||||
workflowJob.addTrigger(giteePushTrigger);
|
||||
giteePushTrigger.start(workflowJob,true);
|
||||
return giteePushTrigger;
|
||||
}
|
||||
|
||||
private GiteePushTrigger giteePushTrigger() {
|
||||
GiteePushTrigger giteePushTrigger = new GiteePushTrigger();
|
||||
giteePushTrigger.setTriggerOnPush(true);
|
||||
giteePushTrigger.setTriggerOnOpenMergeRequest(true);
|
||||
giteePushTrigger.setPendingBuildName(GITEE_BUILD_NAME);
|
||||
giteePushTrigger.setBranchFilterType(BranchFilterType.NameBasedFilter);
|
||||
giteePushTrigger.setBranchFilterName("");
|
||||
return giteePushTrigger;
|
||||
}
|
||||
|
||||
private MergeRequestHook mergeRequestHook(int projectId, String branch, String commitId) {
|
||||
return MergeRequestHookBuilder.mergeRequestHook()
|
||||
.withObjectAttributes(mergeRequestObjectAttributes()
|
||||
.withAction(Action.update)
|
||||
.withState(State.updated)
|
||||
.withIid(1)
|
||||
.withTitle("test")
|
||||
.withTargetProjectId(1)
|
||||
.withTargetBranch("targetBranch")
|
||||
.withSourceBranch(branch)
|
||||
.withSourceProjectId(projectId)
|
||||
.withLastCommit(commit().withAuthor(user().withName("author").build()).withId(commitId).build())
|
||||
.withSource(ProjectBuilder.project()
|
||||
.withName("test")
|
||||
.withNamespace("test-namespace")
|
||||
.withHomepage("https://gitee.org/test")
|
||||
.withUrl("git@gitee.org:test.git")
|
||||
.withSshUrl("git@gitee.org:test.git")
|
||||
.withHttpUrl("https://gitee.org/test.git")
|
||||
.build())
|
||||
.withTarget(ProjectBuilder.project()
|
||||
.withName("test")
|
||||
.withNamespace("test-namespace")
|
||||
.withHomepage("https://gitee.org/test")
|
||||
.withUrl("git@gitee.org:test.git")
|
||||
.withSshUrl("git@gitee.org:test.git")
|
||||
.withHttpUrl("https://gitee.org/test.git")
|
||||
.build())
|
||||
.build())
|
||||
.withProject(ProjectBuilder.project()
|
||||
.withWebUrl("https://gitee.org/test.git")
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private PushHook pushHook(int projectId, String branch, String commitId) {
|
||||
User user = new UserBuilder()
|
||||
.withName("username")
|
||||
.build();
|
||||
|
||||
Repository repository = new RepositoryBuilder()
|
||||
.withName("repository")
|
||||
.withGitSshUrl("sshUrl")
|
||||
.withGitHttpUrl("httpUrl")
|
||||
.build();
|
||||
|
||||
return new PushHookBuilder()
|
||||
.withProjectId(projectId)
|
||||
.withRef(branch)
|
||||
.withAfter(commitId)
|
||||
.withRepository(new Repository())
|
||||
.withProject(ProjectBuilder.project().withNamespace("namespace").build())
|
||||
.withCommits(Arrays.asList(CommitBuilder.commit().withId(commitId).withAuthor(user).build()))
|
||||
.withRepository(repository)
|
||||
.withObjectKind("push")
|
||||
.withUserName("username")
|
||||
.build();
|
||||
}
|
||||
|
||||
private Project freestyleProject(String name, GiteeCommitStatusPublisher gitLabCommitStatusPublisher) throws IOException {
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject(name);
|
||||
project.setQuietPeriod(5000);
|
||||
project.getPublishersList().add(gitLabCommitStatusPublisher);
|
||||
project.addProperty(giteeConnectionProperty);
|
||||
return project;
|
||||
}
|
||||
|
||||
private WorkflowJob workflowJob() throws IOException {
|
||||
ItemGroup itemGroup = mock(ItemGroup.class);
|
||||
when(itemGroup.getFullName()).thenReturn("parent");
|
||||
when(itemGroup.getUrlChildPrefix()).thenReturn("prefix");
|
||||
|
||||
WorkflowJob workflowJob = new WorkflowJob(itemGroup, "workflowJob");
|
||||
when(itemGroup.getRootDirFor(workflowJob)).thenReturn(new File("work"));
|
||||
|
||||
workflowJob.addProperty(giteeConnectionProperty);
|
||||
workflowJob.setQuietPeriod(5000);
|
||||
workflowJob.onCreatedFromScratch();
|
||||
return workflowJob;
|
||||
}
|
||||
}
|
|
@ -1,233 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.handler.merge;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.Action;
|
||||
import com.gitee.jenkins.gitee.hook.model.State;
|
||||
import com.gitee.jenkins.gitee.hook.model.builder.generated.MergeRequestObjectAttributesBuilder;
|
||||
import com.gitee.jenkins.trigger.filter.BranchFilterFactory;
|
||||
import com.gitee.jenkins.trigger.filter.BranchFilterType;
|
||||
import hudson.Launcher;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.plugins.git.GitSCM;
|
||||
import hudson.util.OneShotEvent;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.api.errors.NoHeadException;
|
||||
import org.eclipse.jgit.api.errors.NoMessageException;
|
||||
import org.eclipse.jgit.api.errors.UnmergedPathsException;
|
||||
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
|
||||
import org.eclipse.jgit.errors.AmbiguousObjectException;
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.jvnet.hudson.test.TestBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.CommitBuilder.commit;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.MergeRequestHookBuilder.mergeRequestHook;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.MergeRequestObjectAttributesBuilder.mergeRequestObjectAttributes;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.ProjectBuilder.project;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.UserBuilder.user;
|
||||
import static com.gitee.jenkins.trigger.filter.BranchFilterConfig.BranchFilterConfigBuilder.branchFilterConfig;
|
||||
import static com.gitee.jenkins.trigger.filter.MergeRequestLabelFilterFactory.newMergeRequestLabelFilter;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class MergeRequestHookTriggerHandlerImplTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void mergeRequest_ciSkip() throws IOException, InterruptedException {
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject();
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(Arrays.asList(State.opened, State.reopened), false, false);
|
||||
mergeRequestHookTriggerHandler.handle(project, mergeRequestHook()
|
||||
.withObjectAttributes(mergeRequestObjectAttributes().withDescription("[ci-skip]").build())
|
||||
.build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
|
||||
newMergeRequestLabelFilter(null));
|
||||
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_build() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(Arrays.asList(State.opened, State.reopened), false, false);
|
||||
OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.opened);
|
||||
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_build_when_accepted() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(Arrays.asList(State.merged), false, false);
|
||||
OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.merged);
|
||||
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_build_when_closed() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(Arrays.asList(State.closed), false, false);
|
||||
OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.closed);
|
||||
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_do_not_build_when_accepted() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(Arrays.asList(State.opened, State.updated), false, false);
|
||||
OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.merged);
|
||||
|
||||
assertThat(buildTriggered.isSignaled(), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_do_not_build_when_closed() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(Arrays.asList(State.opened, State.updated), false, false);
|
||||
OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.closed);
|
||||
|
||||
assertThat(buildTriggered.isSignaled(), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_build_when_approved() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(EnumSet.allOf(State.class), EnumSet.of(Action.approved), false, false);
|
||||
|
||||
OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, Action.approved);
|
||||
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_do_not_build_when_when_approved() throws Exception {
|
||||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(EnumSet.allOf(State.class), EnumSet.of(Action.update), false, false);
|
||||
OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, defaultMergeRequestObjectAttributes().withState(State.opened).withAction(Action.approved));
|
||||
|
||||
assertThat(buildTriggered.isSignaled(), is (false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_build_only_when_approved_and_not_when_opened() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
mergeRequest_build_only_when_approved(Action.open);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeRequest_build_only_when_approved_and_not_when_updated() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
mergeRequest_build_only_when_approved(Action.update);
|
||||
}
|
||||
|
||||
|
||||
private void mergeRequest_build_only_when_approved(Action action)
|
||||
throws GitAPIException, IOException, InterruptedException {
|
||||
MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(EnumSet.allOf(State.class), EnumSet.of(Action.approved), false, false);
|
||||
OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, action);
|
||||
|
||||
assertThat(buildTriggered.isSignaled(), is(false));
|
||||
}
|
||||
|
||||
private OneShotEvent doHandle(MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler, Action action) throws GitAPIException, IOException, InterruptedException {
|
||||
return doHandle(mergeRequestHookTriggerHandler, defaultMergeRequestObjectAttributes().withAction(action));
|
||||
}
|
||||
|
||||
private OneShotEvent doHandle(MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler, State state) throws GitAPIException, IOException, InterruptedException {
|
||||
return doHandle(mergeRequestHookTriggerHandler, defaultMergeRequestObjectAttributes().withState(state));
|
||||
}
|
||||
|
||||
private OneShotEvent doHandle(MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler,
|
||||
MergeRequestObjectAttributesBuilder objectAttributes) throws GitAPIException, IOException, NoHeadException,
|
||||
NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException,
|
||||
AmbiguousObjectException, IncorrectObjectTypeException, MissingObjectException, InterruptedException {
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
tmp.newFile("test");
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
git.add().addFilepattern("test");
|
||||
RevCommit commit = git.commit().setMessage("test").call();
|
||||
ObjectId head = git.getRepository().resolve(Constants.HEAD);
|
||||
String repositoryUrl = tmp.getRoot().toURI().toString();
|
||||
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject();
|
||||
project.setScm(new GitSCM(repositoryUrl));
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
mergeRequestHookTriggerHandler.handle(project, mergeRequestHook()
|
||||
.withObjectAttributes(objectAttributes
|
||||
.withTargetBranch("refs/heads/" + git.nameRev().add(head).call().get(head))
|
||||
.withLastCommit(commit().withAuthor(user().withName("test").build()).withId(commit.getName()).build())
|
||||
.build())
|
||||
.withProject(project()
|
||||
.withWebUrl("https://gitee.org/test.git")
|
||||
.build()
|
||||
)
|
||||
.build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
|
||||
newMergeRequestLabelFilter(null));
|
||||
|
||||
buildTriggered.block(10000);
|
||||
return buildTriggered;
|
||||
}
|
||||
|
||||
private MergeRequestObjectAttributesBuilder defaultMergeRequestObjectAttributes() {
|
||||
return mergeRequestObjectAttributes()
|
||||
.withIid(1)
|
||||
.withAction(Action.update)
|
||||
.withState(State.opened)
|
||||
.withTitle("test")
|
||||
.withTargetProjectId(1)
|
||||
.withSourceProjectId(1)
|
||||
.withSourceBranch("feature")
|
||||
.withTargetBranch("master")
|
||||
.withSource(project()
|
||||
.withName("test")
|
||||
.withNamespace("test-namespace")
|
||||
.withHomepage("https://gitee.org/test")
|
||||
.withUrl("git@gitee.org:test.git")
|
||||
.withSshUrl("git@gitee.org:test.git")
|
||||
.withHttpUrl("https://gitee.org/test.git")
|
||||
.build())
|
||||
.withTarget(project()
|
||||
.withName("test")
|
||||
.withNamespace("test-namespace")
|
||||
.withHomepage("https://gitee.org/test")
|
||||
.withUrl("git@gitee.org:test.git")
|
||||
.withSshUrl("git@gitee.org:test.git")
|
||||
.withHttpUrl("https://gitee.org/test.git")
|
||||
.build());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.handler.note;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.State;
|
||||
import com.gitee.jenkins.trigger.filter.BranchFilterFactory;
|
||||
import com.gitee.jenkins.trigger.filter.BranchFilterType;
|
||||
import hudson.Launcher;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.plugins.git.GitSCM;
|
||||
import hudson.util.OneShotEvent;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.jvnet.hudson.test.TestBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.CommitBuilder.commit;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.MergeRequestObjectAttributesBuilder.mergeRequestObjectAttributes;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.NoteHookBuilder.noteHook;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.NoteObjectAttributesBuilder.noteObjectAttributes;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.ProjectBuilder.project;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.UserBuilder.user;
|
||||
import static com.gitee.jenkins.trigger.filter.BranchFilterConfig.BranchFilterConfigBuilder.branchFilterConfig;
|
||||
import static com.gitee.jenkins.trigger.filter.MergeRequestLabelFilterFactory.newMergeRequestLabelFilter;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Nikolay Ustinov
|
||||
*/
|
||||
public class NoteHookTriggerHandlerImplTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder();
|
||||
|
||||
private NoteHookTriggerHandler noteHookTriggerHandler;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
noteHookTriggerHandler = new NoteHookTriggerHandlerImpl("ci-run");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void note_ciSkip() throws IOException, InterruptedException {
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject();
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
Date currentDate = new Date();
|
||||
project.setQuietPeriod(0);
|
||||
noteHookTriggerHandler.handle(project, noteHook()
|
||||
.withObjectAttributes(noteObjectAttributes()
|
||||
.withId(1)
|
||||
.withNote("ci-run")
|
||||
.withAuthorId(1)
|
||||
.withProjectId(1)
|
||||
.withCreatedAt(currentDate)
|
||||
.withUpdatedAt(currentDate)
|
||||
.withUrl("https://gitee.org/test/merge_requests/1#note_1")
|
||||
.build())
|
||||
.withMergeRequest(mergeRequestObjectAttributes().withDescription("[ci-skip]").build())
|
||||
.build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
|
||||
newMergeRequestLabelFilter(null));
|
||||
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void note_build() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
tmp.newFile("test");
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
git.add().addFilepattern("test");
|
||||
RevCommit commit = git.commit().setMessage("test").call();
|
||||
ObjectId head = git.getRepository().resolve(Constants.HEAD);
|
||||
String repositoryUrl = tmp.getRoot().toURI().toString();
|
||||
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject();
|
||||
project.setScm(new GitSCM(repositoryUrl));
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
Date currentDate = new Date();
|
||||
project.setQuietPeriod(0);
|
||||
noteHookTriggerHandler.handle(project, noteHook()
|
||||
.withObjectAttributes(noteObjectAttributes()
|
||||
.withId(1)
|
||||
.withNote("ci-run")
|
||||
.withAuthorId(1)
|
||||
.withProjectId(1)
|
||||
.withCreatedAt(currentDate)
|
||||
.withUpdatedAt(currentDate)
|
||||
.withUrl("https://gitee.org/test/merge_requests/1#note_1")
|
||||
.build())
|
||||
.withMergeRequest(mergeRequestObjectAttributes()
|
||||
.withTargetBranch("refs/heads/" + git.nameRev().add(head).call().get(head))
|
||||
.withState(State.opened)
|
||||
.withIid(1)
|
||||
.withTitle("test")
|
||||
.withTargetProjectId(1)
|
||||
.withSourceProjectId(1)
|
||||
.withSourceBranch("feature")
|
||||
.withTargetBranch("master")
|
||||
.withLastCommit(commit().withAuthor(user().withName("test").build()).withId(commit.getName()).build())
|
||||
.withSource(project()
|
||||
.withName("test")
|
||||
.withNamespace("test-namespace")
|
||||
.withHomepage("https://gitee.org/test")
|
||||
.withUrl("git@gitee.org:test.git")
|
||||
.withSshUrl("git@gitee.org:test.git")
|
||||
.withHttpUrl("https://gitee.org/test.git")
|
||||
.build())
|
||||
.withTarget(project()
|
||||
.withName("test")
|
||||
.withNamespace("test-namespace")
|
||||
.withHomepage("https://gitee.org/test")
|
||||
.withUrl("git@gitee.org:test.git")
|
||||
.withSshUrl("git@gitee.org:test.git")
|
||||
.withHttpUrl("https://gitee.org/test.git")
|
||||
.withWebUrl("https://gitee.org/test.git")
|
||||
.build())
|
||||
.build())
|
||||
.build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
|
||||
newMergeRequestLabelFilter(null));
|
||||
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.handler.pipeline;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.PipelineHook;
|
||||
import com.gitee.jenkins.gitee.hook.model.User;
|
||||
import com.gitee.jenkins.trigger.filter.BranchFilterType;
|
||||
import hudson.Launcher;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.util.OneShotEvent;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.jvnet.hudson.test.TestBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.PipelineEventObjectAttributesBuilder.pipelineEventObjectAttributes;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.PipelineHookBuilder.pipelineHook;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.ProjectBuilder.project;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.RepositoryBuilder.repository;
|
||||
import static com.gitee.jenkins.trigger.filter.BranchFilterConfig.BranchFilterConfigBuilder.branchFilterConfig;
|
||||
import static com.gitee.jenkins.trigger.filter.BranchFilterFactory.newBranchFilter;
|
||||
import static com.gitee.jenkins.trigger.filter.MergeRequestLabelFilterFactory.newMergeRequestLabelFilter;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class PipelineHookTriggerHandlerImplTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder();
|
||||
|
||||
private PipelineHookTriggerHandler pipelineHookTriggerHandler;
|
||||
private PipelineHook pipelineHook;
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException, GitAPIException {
|
||||
|
||||
List<String> allowedStates = new ArrayList<>();
|
||||
allowedStates.add("success");
|
||||
|
||||
User user = new User();
|
||||
user.setName("test");
|
||||
user.setId(1);
|
||||
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
tmp.newFile("test");
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
git.add().addFilepattern("test");
|
||||
git.commit().setMessage("test").call();
|
||||
ObjectId head = git.getRepository().resolve(Constants.HEAD);
|
||||
|
||||
pipelineHookTriggerHandler = new PipelineHookTriggerHandlerImpl(allowedStates);
|
||||
pipelineHook = pipelineHook()
|
||||
.withProjectId(1)
|
||||
.withUser(user)
|
||||
.withRepository(repository()
|
||||
.withName("test")
|
||||
.withHomepage("https://gitee.org/test")
|
||||
.withUrl("git@gitee.org:test.git")
|
||||
.withGitSshUrl("git@gitee.org:test.git")
|
||||
.withGitHttpUrl("https://gitee.org/test.git")
|
||||
.build())
|
||||
.withProject(project()
|
||||
.withNamespace("test-namespace")
|
||||
.withWebUrl("https://gitee.org/test")
|
||||
.withId(1)
|
||||
.build())
|
||||
.withObjectAttributes(pipelineEventObjectAttributes()
|
||||
.withId(1)
|
||||
.withStatus("success")
|
||||
.withSha("bcbb5ec396a2c0f828686f14fac9b80b780504f2")
|
||||
.withStages(new ArrayList<String>())
|
||||
.withRef("refs/heads/" + git.nameRev().add(head).call().get(head))
|
||||
.build())
|
||||
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* always triggers since pipeline events do not contain ci skip message
|
||||
*/
|
||||
public void pipeline_ciSkip() throws IOException, InterruptedException {
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject();
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
pipelineHookTriggerHandler.handle(project, pipelineHook , true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
|
||||
newMergeRequestLabelFilter(null));
|
||||
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipeline_build() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject();
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
|
||||
pipelineHookTriggerHandler.handle(project, pipelineHook, false, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
|
||||
newMergeRequestLabelFilter(null));
|
||||
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.handler.push;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.PushHook;
|
||||
import com.gitee.jenkins.testhelpers.GiteePushRequestSamples;
|
||||
import com.gitee.jenkins.testhelpers.GiteePushRequestSamples_7_10_5_489b413;
|
||||
import com.gitee.jenkins.testhelpers.GiteePushRequestSamples_7_5_1_36679b5;
|
||||
import com.gitee.jenkins.testhelpers.GiteePushRequestSamples_8_1_2_8c8af7b;
|
||||
import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException;
|
||||
import hudson.plugins.git.BranchSpec;
|
||||
import hudson.plugins.git.GitSCM;
|
||||
import hudson.plugins.git.RevisionParameterAction;
|
||||
import hudson.plugins.git.SubmoduleConfig;
|
||||
import hudson.plugins.git.UserRemoteConfig;
|
||||
import org.eclipse.jgit.transport.RemoteConfig;
|
||||
import org.junit.Rule;
|
||||
import org.junit.experimental.theories.DataPoints;
|
||||
import org.junit.experimental.theories.Theories;
|
||||
import org.junit.experimental.theories.Theory;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(Theories.class)
|
||||
public class PushHookTriggerHandlerGiteeServerTest {
|
||||
|
||||
@DataPoints
|
||||
public static GiteePushRequestSamples[] samples = {
|
||||
new GiteePushRequestSamples_7_5_1_36679b5(),
|
||||
new GiteePushRequestSamples_7_10_5_489b413(),
|
||||
new GiteePushRequestSamples_8_1_2_8c8af7b()
|
||||
};
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Theory
|
||||
public void createRevisionParameterAction_pushBrandNewMasterBranchRequest(GiteePushRequestSamples samples) throws Exception {
|
||||
PushHook hook = samples.pushBrandNewMasterBranchRequest();
|
||||
|
||||
RevisionParameterAction revisionParameterAction = new PushHookTriggerHandlerImpl().createRevisionParameter(hook, null);
|
||||
|
||||
assertThat(revisionParameterAction, is(notNullValue()));
|
||||
assertThat(revisionParameterAction.commit, is(hook.getAfter()));
|
||||
assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList<RemoteConfig>()));
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void createRevisionParameterAction_mergeRequestMergePushRequest(GiteePushRequestSamples samples) throws Exception {
|
||||
PushHook hook = samples.mergePushRequest();
|
||||
|
||||
RevisionParameterAction revisionParameterAction = new PushHookTriggerHandlerImpl().createRevisionParameter(hook, null);
|
||||
|
||||
assertThat(revisionParameterAction, is(notNullValue()));
|
||||
assertThat(revisionParameterAction.commit, is(hook.getAfter()));
|
||||
assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList<RemoteConfig>()));
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void createRevisionParameterAction_pushCommitRequest(GiteePushRequestSamples samples) throws Exception {
|
||||
PushHook hook = samples.pushCommitRequest();
|
||||
|
||||
RevisionParameterAction revisionParameterAction = new PushHookTriggerHandlerImpl().createRevisionParameter(hook, null);
|
||||
|
||||
assertThat(revisionParameterAction, is(notNullValue()));
|
||||
assertThat(revisionParameterAction.commit, is(hook.getAfter()));
|
||||
assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList<RemoteConfig>()));
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void createRevisionParameterAction_pushNewBranchRequest(GiteePushRequestSamples samples) throws Exception {
|
||||
PushHook hook = samples.pushNewBranchRequest();
|
||||
|
||||
RevisionParameterAction revisionParameterAction = new PushHookTriggerHandlerImpl().createRevisionParameter(hook, null);
|
||||
|
||||
assertThat(revisionParameterAction, is(notNullValue()));
|
||||
assertThat(revisionParameterAction.commit, is(hook.getAfter()));
|
||||
assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList<RemoteConfig>()));
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void createRevisionParameterAction_pushNewTagRequest(GiteePushRequestSamples samples) throws Exception {
|
||||
PushHook hook = samples.pushNewTagRequest();
|
||||
|
||||
RevisionParameterAction revisionParameterAction = new PushHookTriggerHandlerImpl().createRevisionParameter(hook, null);
|
||||
|
||||
assertThat(revisionParameterAction, is(notNullValue()));
|
||||
assertThat(revisionParameterAction.commit, is(hook.getAfter()));
|
||||
assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList<RemoteConfig>()));
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void doNotCreateRevisionParameterAction_deleteBranchRequest(GiteePushRequestSamples samples) throws Exception {
|
||||
PushHook hook = samples.deleteBranchRequest();
|
||||
|
||||
exception.expect(NoRevisionToBuildException.class);
|
||||
new PushHookTriggerHandlerImpl().createRevisionParameter(hook, null);
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void createRevisionParameterAction_pushCommitRequestWithGitScm(GiteePushRequestSamples samples) throws Exception {
|
||||
PushHook hook = samples.pushCommitRequest();
|
||||
|
||||
GitSCM gitSCM = new GitSCM("git@test.tld:test.git");
|
||||
RevisionParameterAction revisionParameterAction = new PushHookTriggerHandlerImpl().createRevisionParameter(hook, gitSCM);
|
||||
|
||||
assertThat(revisionParameterAction, is(notNullValue()));
|
||||
assertThat(revisionParameterAction.commit, is(hook.getRef().replaceFirst("^refs/heads", "remotes/origin")));
|
||||
assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList<RemoteConfig>()));
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void createRevisionParameterAction_pushCommitRequestWith2Remotes(GiteePushRequestSamples samples) throws Exception {
|
||||
PushHook hook = samples.pushCommitRequest();
|
||||
|
||||
GitSCM gitSCM = new GitSCM(Arrays.asList(new UserRemoteConfig("git@test.tld:test.git", null, null, null),
|
||||
new UserRemoteConfig("git@test.tld:fork.git", "fork", null, null)),
|
||||
Collections.singletonList(new BranchSpec("")),
|
||||
false, Collections.<SubmoduleConfig>emptyList(),
|
||||
null, null, null);
|
||||
RevisionParameterAction revisionParameterAction = new PushHookTriggerHandlerImpl().createRevisionParameter(hook, gitSCM);
|
||||
|
||||
assertThat(revisionParameterAction, is(notNullValue()));
|
||||
assertThat(revisionParameterAction.commit, is(hook.getAfter()));
|
||||
assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList<RemoteConfig>()));
|
||||
}
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
package com.gitee.jenkins.trigger.handler.push;
|
||||
|
||||
import com.gitee.jenkins.gitee.hook.model.builder.generated.PushHookBuilder;
|
||||
import com.gitee.jenkins.trigger.filter.BranchFilterType;
|
||||
import hudson.Launcher;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.plugins.git.GitSCM;
|
||||
import hudson.util.OneShotEvent;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.jvnet.hudson.test.TestBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.CommitBuilder.commit;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.ProjectBuilder.project;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.PushHookBuilder.pushHook;
|
||||
import static com.gitee.jenkins.gitee.hook.model.builder.generated.RepositoryBuilder.repository;
|
||||
import static com.gitee.jenkins.trigger.filter.BranchFilterConfig.BranchFilterConfigBuilder.branchFilterConfig;
|
||||
import static com.gitee.jenkins.trigger.filter.BranchFilterFactory.newBranchFilter;
|
||||
import static com.gitee.jenkins.trigger.filter.MergeRequestLabelFilterFactory.newMergeRequestLabelFilter;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class PushHookTriggerHandlerImplTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder();
|
||||
|
||||
private PushHookTriggerHandler pushHookTriggerHandler;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
pushHookTriggerHandler = new PushHookTriggerHandlerImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void push_ciSkip() throws IOException, InterruptedException {
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject();
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
pushHookTriggerHandler.handle(project, pushHook()
|
||||
.withCommits(Arrays.asList(commit().withMessage("some message").build(),
|
||||
commit().withMessage("[ci-skip]").build()))
|
||||
.build(), true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
|
||||
newMergeRequestLabelFilter(null));
|
||||
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void push_build() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
tmp.newFile("test");
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
git.add().addFilepattern("test");
|
||||
RevCommit commit = git.commit().setMessage("test").call();
|
||||
ObjectId head = git.getRepository().resolve(Constants.HEAD);
|
||||
String repositoryUrl = tmp.getRoot().toURI().toString();
|
||||
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject();
|
||||
project.setScm(new GitSCM(repositoryUrl));
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildTriggered.signal();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
pushHookTriggerHandler.handle(project, pushHook()
|
||||
.withBefore("0000000000000000000000000000000000000000")
|
||||
.withProjectId(1)
|
||||
.withUserName("test")
|
||||
.withObjectKind("tag_push")
|
||||
.withRepository(repository()
|
||||
.withName("test")
|
||||
.withHomepage("https://gitee.org/test")
|
||||
.withUrl("git@gitee.org:test.git")
|
||||
.withGitSshUrl("git@gitee.org:test.git")
|
||||
.withGitHttpUrl("https://gitee.org/test.git")
|
||||
.build())
|
||||
.withProject(project()
|
||||
.withNamespace("test-namespace")
|
||||
.withWebUrl("https://gitee.org/test")
|
||||
.build())
|
||||
.withAfter(commit.name())
|
||||
.withRef("refs/heads/" + git.nameRev().add(head).call().get(head))
|
||||
.build(), true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
|
||||
newMergeRequestLabelFilter(null));
|
||||
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void push_build2DifferentBranchesButSameCommit() throws IOException, InterruptedException, GitAPIException, ExecutionException {
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
tmp.newFile("test");
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
git.add().addFilepattern("test");
|
||||
RevCommit commit = git.commit().setMessage("test").call();
|
||||
ObjectId head = git.getRepository().resolve(Constants.HEAD);
|
||||
String repositoryUrl = tmp.getRoot().toURI().toString();
|
||||
|
||||
final AtomicInteger buildCount = new AtomicInteger(0);
|
||||
|
||||
final OneShotEvent buildTriggered = new OneShotEvent();
|
||||
FreeStyleProject project = jenkins.createFreeStyleProject();
|
||||
project.setScm(new GitSCM(repositoryUrl));
|
||||
project.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
int count = buildCount.incrementAndGet();
|
||||
if (count == 2) {
|
||||
buildTriggered.signal();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
project.setQuietPeriod(0);
|
||||
PushHookBuilder pushHookBuilder = pushHook()
|
||||
.withBefore("0000000000000000000000000000000000000000")
|
||||
.withProjectId(1)
|
||||
.withUserName("test")
|
||||
.withObjectKind("push")
|
||||
.withRepository(repository()
|
||||
.withName("test")
|
||||
.withHomepage("https://gitee.org/test")
|
||||
.withUrl("git@gitee.org:test.git")
|
||||
.withGitSshUrl("git@gitee.org:test.git")
|
||||
.withGitHttpUrl("https://gitee.org/test.git")
|
||||
.build())
|
||||
.withProject(project()
|
||||
.withNamespace("test-namespace")
|
||||
.withWebUrl("https://gitee.org/test")
|
||||
.build())
|
||||
.withAfter(commit.name())
|
||||
.withRef("refs/heads/" + git.nameRev().add(head).call().get(head));
|
||||
pushHookTriggerHandler.handle(project, pushHookBuilder.build(), true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
|
||||
newMergeRequestLabelFilter(null));
|
||||
pushHookTriggerHandler.handle(project, pushHookBuilder
|
||||
.but().withRef("refs/heads/" + git.nameRev().add(head).call().get(head) + "-2").build(), true,
|
||||
newBranchFilter(branchFilterConfig().build(BranchFilterType.All)), newMergeRequestLabelFilter(null));
|
||||
buildTriggered.block(10000);
|
||||
assertThat(buildTriggered.isSignaled(), is(true));
|
||||
assertThat(buildCount.intValue(), is(2));
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
package com.gitee.jenkins.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import hudson.model.Job;
|
||||
import hudson.model.Run;
|
||||
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.plugins.git.Revision;
|
||||
import hudson.plugins.git.util.Build;
|
||||
import hudson.plugins.git.util.BuildData;
|
||||
import hudson.util.RunList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* @author Joshua Barker
|
||||
*/
|
||||
|
||||
public class BuildUtilTest {
|
||||
|
||||
private static final String SHA1 = "0616d12a3a24068691027a1e113147e3c1cfa2f4";
|
||||
private static final String SHALIB = "a53131154f6dfc0d1642451679fb977c5ecf31c0";
|
||||
private static final String WRONGSHA = "5f106d47c2ce17dd65774c12c0826785d16b26f7";
|
||||
|
||||
public void getBuildBySHA1WithoutMergeBuilds_sha_found(){
|
||||
Job<?,?> project = createProject(SHA1);
|
||||
|
||||
Run<?, ?> build = BuildUtil.getBuildBySHA1WithoutMergeBuilds(project, SHA1);
|
||||
assertThat(build, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBuildBySHA1WithoutMergeBuilds_sha_missing(){
|
||||
Job<?,?> project = createProject(SHA1);
|
||||
|
||||
Run<?, ?> build = BuildUtil.getBuildBySHA1WithoutMergeBuilds(project, WRONGSHA);
|
||||
assertThat(build, is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBuildBySHA1WithoutMergeBuilds_libraryFirst(){
|
||||
Job<?,?> project = createProject(SHA1, SHALIB);
|
||||
|
||||
Run<?, ?> build = BuildUtil.getBuildBySHA1WithoutMergeBuilds(project, SHA1);
|
||||
assertThat(build, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBuildBySHA1WithoutMergeBuilds_libraryLast(){
|
||||
Job<?,?> project = createProject(SHA1, SHALIB);
|
||||
|
||||
Run<?, ?> build = BuildUtil.getBuildBySHA1WithoutMergeBuilds(project, SHA1);
|
||||
assertThat(build, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBuildBySHA1IncludingMergeBuilds_sha_found(){
|
||||
Job<?,?> project = createProject(SHA1);
|
||||
|
||||
Run<?, ?> build = BuildUtil.getBuildBySHA1IncludingMergeBuilds(project, SHA1);
|
||||
assertThat(build, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBuildBySHA1IncludingMergeBuilds_sha_missing(){
|
||||
Job<?,?> project = createProject(SHA1);
|
||||
|
||||
Run<?, ?> build = BuildUtil.getBuildBySHA1IncludingMergeBuilds(project, WRONGSHA);
|
||||
assertThat(build, is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBuildBySHA1IncludingMergeBuilds_libraryFirst(){
|
||||
Job<?,?> project = createProject(SHA1, SHALIB);
|
||||
|
||||
Run<?, ?> build = BuildUtil.getBuildBySHA1IncludingMergeBuilds(project, SHA1);
|
||||
assertThat(build, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBuildBySHA1IncludingMergeBuilds_libraryLast(){
|
||||
Job<?,?> project = createProject(SHA1, SHALIB);
|
||||
|
||||
Run<?, ?> build = BuildUtil.getBuildBySHA1IncludingMergeBuilds(project, SHA1);
|
||||
assertThat(build, is(notNullValue()));
|
||||
}
|
||||
|
||||
private AbstractProject<?,?> createProject(String... shas) {
|
||||
AbstractBuild build = mock(AbstractBuild.class);
|
||||
List<BuildData> buildDatas = new ArrayList<BuildData>();
|
||||
for(String sha : shas) {
|
||||
BuildData buildData = createBuildData(sha);
|
||||
buildDatas.add(buildData);
|
||||
}
|
||||
|
||||
when(build.getAction(BuildData.class)).thenReturn(buildDatas.get(0));
|
||||
when(build.getActions(BuildData.class)).thenReturn(buildDatas);
|
||||
|
||||
AbstractProject<?, ?> project = mock(AbstractProject.class);
|
||||
when(build.getProject()).thenReturn(project);
|
||||
|
||||
RunList list = mock(RunList.class);
|
||||
when(list.iterator()).thenReturn(Arrays.asList(build).iterator());
|
||||
when(project.getBuilds()).thenReturn(list);
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
private BuildData createBuildData(String sha) {
|
||||
|
||||
BuildData buildData = mock(BuildData.class);
|
||||
Revision revision = mock(Revision.class);
|
||||
when(revision.getSha1String()).thenReturn(sha);
|
||||
when(buildData.getLastBuiltRevision()).thenReturn(revision);
|
||||
|
||||
Build gitBuild = mock(Build.class);
|
||||
when(gitBuild.getMarked()).thenReturn(revision);
|
||||
when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
|
||||
when(gitBuild.getRevision()).thenReturn(revision);
|
||||
when(gitBuild.isFor(sha)).thenReturn(true);
|
||||
buildData.lastBuild = gitBuild;
|
||||
|
||||
return buildData;
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
package com.gitee.jenkins.util;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import static com.gitee.jenkins.cause.CauseDataBuilder.causeData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import com.gitee.jenkins.cause.CauseData;
|
||||
import com.gitee.jenkins.cause.GiteeWebHookCause;
|
||||
import com.gitee.jenkins.connection.GiteeConnectionProperty;
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.model.BuildState;
|
||||
|
||||
import hudson.EnvVars;
|
||||
import hudson.model.Cause;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.model.Cause.UpstreamCause;
|
||||
import hudson.plugins.git.Revision;
|
||||
import hudson.plugins.git.util.Build;
|
||||
import hudson.plugins.git.util.BuildData;
|
||||
import jenkins.model.Jenkins;
|
||||
|
||||
/**
|
||||
* @author Daumantas Stulgis
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({GiteeConnectionProperty.class, Jenkins.class})
|
||||
public class CommitStatusUpdaterTest {
|
||||
|
||||
private static final int PROJECT_ID = 1;
|
||||
private static final String BUILD_URL = "job/Test-Job";
|
||||
private static final String STAGE = "test";
|
||||
private static final String REVISION = "1111111";
|
||||
private static final String JENKINS_URL = "https://gitee.org/jenkins/";
|
||||
|
||||
@Mock Run<?, ?> build;
|
||||
@Mock TaskListener taskListener;
|
||||
@Mock
|
||||
GiteeClient client;
|
||||
@Mock GiteeWebHookCause gitlabCause;
|
||||
@Mock BuildData action;
|
||||
@Mock Revision lastBuiltRevision;
|
||||
@Mock Build lastBuild;
|
||||
@Mock Revision revision;
|
||||
@Mock EnvVars environment;
|
||||
@Mock UpstreamCause upCauseLevel1;
|
||||
@Mock UpstreamCause upCauseLevel2;
|
||||
@Mock Jenkins jenkins;
|
||||
|
||||
CauseData causeData;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
PowerMockito.mockStatic(GiteeConnectionProperty.class);
|
||||
PowerMockito.mockStatic(Jenkins.class);
|
||||
when(Jenkins.getInstance()).thenReturn(jenkins);
|
||||
when(jenkins.getRootUrl()).thenReturn(JENKINS_URL);
|
||||
when(GiteeConnectionProperty.getClient(any(Run.class))).thenReturn(client);
|
||||
when(build.getAction(BuildData.class)).thenReturn(action);
|
||||
when(action.getLastBuiltRevision()).thenReturn(lastBuiltRevision);
|
||||
when(action.getLastBuild(any(ObjectId.class))).thenReturn(lastBuild);
|
||||
when(lastBuild.getMarked()).thenReturn(revision);
|
||||
when(revision.getSha1String()).thenReturn(REVISION);
|
||||
when(build.getUrl()).thenReturn(BUILD_URL);
|
||||
when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
|
||||
when(build.getCauses()).thenReturn(new ArrayList<Cause>(Collections.singletonList(upCauseLevel1)));
|
||||
when(upCauseLevel1.getUpstreamCauses()).thenReturn(new ArrayList<Cause>(Collections.singletonList(upCauseLevel2)));
|
||||
when(upCauseLevel2.getUpstreamCauses()).thenReturn(new ArrayList<Cause>(Collections.singletonList(gitlabCause)));
|
||||
|
||||
causeData = causeData()
|
||||
.withActionType(CauseData.ActionType.NOTE)
|
||||
.withSourceProjectId(PROJECT_ID)
|
||||
.withTargetProjectId(PROJECT_ID)
|
||||
.withBranch("feature")
|
||||
.withSourceBranch("feature")
|
||||
.withUserName("")
|
||||
.withSourceRepoHomepage("https://gitee.org/test")
|
||||
.withSourceRepoName("test")
|
||||
.withSourceNamespace("test-namespace")
|
||||
.withSourceRepoUrl("git@gitee.org:test.git")
|
||||
.withSourceRepoSshUrl("git@gitee.org:test.git")
|
||||
.withSourceRepoHttpUrl("https://gitee.org/test.git")
|
||||
.withMergeRequestTitle("Test")
|
||||
.withMergeRequestId(1)
|
||||
.withMergeRequestIid(1)
|
||||
.withTargetBranch("master")
|
||||
.withTargetRepoName("test")
|
||||
.withTargetNamespace("test-namespace")
|
||||
.withTargetRepoSshUrl("git@gitee.org:test.git")
|
||||
.withTargetRepoHttpUrl("https://gitee.org/test.git")
|
||||
.withTriggeredByUser("test")
|
||||
.withLastCommit(REVISION)
|
||||
.withTargetProjectUrl("https://gitee.org/test")
|
||||
.build();
|
||||
|
||||
when(gitlabCause.getData()).thenReturn(causeData);
|
||||
PowerMockito.spy(client);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
CommitStatusUpdater.updateCommitStatus(build, taskListener, BuildState.success, STAGE);
|
||||
|
||||
verify(client).changeBuildStatus(Integer.toString(PROJECT_ID), REVISION, BuildState.success, null, STAGE, DisplayURLProvider.get().getRunURL(build), BuildState.success.name());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
package com.gitee.jenkins.util;
|
||||
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import com.gitee.jenkins.gitee.api.model.*;
|
||||
import com.gitee.jenkins.gitee.hook.model.State;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class GiteeClientStub implements GiteeClient {
|
||||
private final String url;
|
||||
|
||||
GiteeClientStub(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project createProject(String projectName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject(String projectName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project updateProject(String projectId, String name, String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProject(String projectId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProjectHook(String projectId, String url, Boolean pushEvents, Boolean mergeRequestEvents, Boolean noteEvents) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(String projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBuildStatus(Integer projectId, String sha, BuildState state, String ref, String context, String targetUrl, String description) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getCommit(String projectId, String sha) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptMergeRequest(MergeRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMergeRequestNote(MergeRequest mr, String body) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MergeRequest> getMergeRequests(String projectId, State state, int page, int perPage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Branch> getBranches(String projectId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Branch getBranch(String projectId, String branch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User addUser(String email, String username, String name, String password) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User updateUser(String userId, String email, String username, String name, String password) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Label> getLabels(String projectId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pipeline> getPipelines(String projectName) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package com.gitee.jenkins.util;
|
||||
|
||||
|
||||
import com.gitee.jenkins.gitee.api.GiteeClient;
|
||||
import org.junit.experimental.theories.DataPoints;
|
||||
import org.junit.experimental.theories.Theories;
|
||||
import org.junit.experimental.theories.Theory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static com.gitee.jenkins.util.ProjectIdUtilTest.TestData.forRemoteUrl;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@RunWith(Theories.class)
|
||||
public class ProjectIdUtilTest {
|
||||
|
||||
@DataPoints
|
||||
public static TestData[] testData = {
|
||||
forRemoteUrl("git@gitee.com", "git@gitee.com:test/project.git").expectProjectId("test/project"),
|
||||
forRemoteUrl("https://gitee.com", "https://gitee.com/test/project.git").expectProjectId("test/project"),
|
||||
forRemoteUrl("https://myurl.com/gitee", "https://myurl.com/gitee/group/project.git").expectProjectId("group/project"),
|
||||
forRemoteUrl("git@gitee.com", "git@gitee.com:group/subgroup/project.git").expectProjectId("group/subgroup/project"),
|
||||
forRemoteUrl("https://myurl.com/gitee", "https://myurl.com/gitee/group/subgroup/project.git").expectProjectId("group/subgroup/project"),
|
||||
forRemoteUrl("https://myurl.com", "https://myurl.com/group/subgroup/project.git").expectProjectId("group/subgroup/project"),
|
||||
forRemoteUrl("https://myurl.com", "https://myurl.com/group/subgroup/subsubgroup/project.git").expectProjectId("group/subgroup/subsubgroup/project"),
|
||||
forRemoteUrl("git@gitee.com", "git@gitee.com:group/subgroup/subsubgroup/project.git").expectProjectId("group/subgroup/subsubgroup/project"),
|
||||
};
|
||||
|
||||
@Theory
|
||||
public void retrieveProjectId(TestData testData) throws ProjectIdUtil.ProjectIdResolutionException {
|
||||
GiteeClient client = new GiteeClientStub(testData.hostUrl);
|
||||
|
||||
String projectId = ProjectIdUtil.retrieveProjectId(client, testData.remoteUrl);
|
||||
|
||||
assertThat(projectId, is(testData.expectedProjectId));
|
||||
}
|
||||
|
||||
|
||||
static final class TestData {
|
||||
|
||||
private final String hostUrl;
|
||||
private final String remoteUrl;
|
||||
private String expectedProjectId;
|
||||
|
||||
private TestData(String hostUrl, String remoteUrl) {
|
||||
this.hostUrl = hostUrl;
|
||||
this.remoteUrl = remoteUrl;
|
||||
}
|
||||
|
||||
private TestData expectProjectId(String expectedProjectId) {
|
||||
this.expectedProjectId = expectedProjectId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return remoteUrl;
|
||||
}
|
||||
|
||||
static TestData forRemoteUrl(String baseUrl, String remoteUrl) {
|
||||
return new TestData(baseUrl, remoteUrl);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,213 +0,0 @@
|
|||
package com.gitee.jenkins.webhook;
|
||||
|
||||
import com.gitee.jenkins.webhook.ActionResolver.NoopAction;
|
||||
import com.gitee.jenkins.webhook.build.MergeRequestBuildAction;
|
||||
import com.gitee.jenkins.webhook.build.NoteBuildAction;
|
||||
import com.gitee.jenkins.webhook.build.PushBuildAction;
|
||||
import com.gitee.jenkins.webhook.status.BranchBuildPageRedirectAction;
|
||||
import com.gitee.jenkins.webhook.status.BranchStatusPngAction;
|
||||
import com.gitee.jenkins.webhook.status.CommitBuildPageRedirectAction;
|
||||
import com.gitee.jenkins.webhook.status.CommitStatusPngAction;
|
||||
import com.gitee.jenkins.webhook.status.StatusJsonAction;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import javax.servlet.ServletInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ActionResolverTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Mock
|
||||
private StaplerRequest request;
|
||||
|
||||
@Test
|
||||
public void getBranchBuildPageRedirect() throws IOException {
|
||||
String projectName = "getBranchBuildPageRedirect";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("");
|
||||
when(request.hasParameter("ref")).thenReturn(true);
|
||||
when(request.getMethod()).thenReturn("GET");
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(BranchBuildPageRedirectAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCommitStatus() throws IOException {
|
||||
String projectName = "getCommitStatus";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("builds/1234abcd/status.json");
|
||||
when(request.getMethod()).thenReturn("GET");
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(StatusJsonAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCommitBuildPageRedirect_builds() throws IOException {
|
||||
String projectName = "getCommitBuildPageRedirect_builds";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("builds/1234abcd");
|
||||
when(request.getMethod()).thenReturn("GET");
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(CommitBuildPageRedirectAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCommitBuildPageRedirect_commits() throws IOException {
|
||||
String projectName = "getCommitBuildPageRedirect_commits";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("commits/7890efab");
|
||||
when(request.getMethod()).thenReturn("GET");
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(CommitBuildPageRedirectAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBranchStatusPng() throws IOException {
|
||||
String projectName = "getBranchStatusPng";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("builds/status.png");
|
||||
when(request.hasParameter("ref")).thenReturn(true);
|
||||
when(request.getMethod()).thenReturn("GET");
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(BranchStatusPngAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCommitStatusPng() throws IOException {
|
||||
String projectName = "getCommitStatusPng";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("builds/status.png");
|
||||
when(request.hasParameter("ref")).thenReturn(false);
|
||||
when(request.getMethod()).thenReturn("GET");
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(CommitStatusPngAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postMergeRequest() throws IOException {
|
||||
String projectName = "postMergeRequest";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("");
|
||||
when(request.getMethod()).thenReturn("POST");
|
||||
when(request.getHeader("X-Gitee-Event")).thenReturn("Merge Request Hook");
|
||||
when(request.getInputStream()).thenReturn(new ResourceServletInputStream("ActionResolverTest_postMergeRequest.json"));
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(MergeRequestBuildAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postNote() throws IOException {
|
||||
String projectName = "postNote";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("");
|
||||
when(request.getMethod()).thenReturn("POST");
|
||||
when(request.getHeader("X-Gitee-Event")).thenReturn("Note Hook");
|
||||
when(request.getInputStream()).thenReturn(new ResourceServletInputStream("ActionResolverTest_postNote.json"));
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(NoteBuildAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postPush() throws IOException {
|
||||
String projectName = "postPush";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("");
|
||||
when(request.getMethod()).thenReturn("POST");
|
||||
when(request.getHeader("X-Gitee-Event")).thenReturn("Push Hook");
|
||||
when(request.getInputStream()).thenReturn(new ResourceServletInputStream("ActionResolverTest_postPush.json"));
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(PushBuildAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postPushTag() throws IOException {
|
||||
String projectName = "postPushTag";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("");
|
||||
when(request.getMethod()).thenReturn("POST");
|
||||
when(request.getHeader("X-Gitee-Event")).thenReturn("Tag Push Hook");
|
||||
when(request.getInputStream()).thenReturn(new ResourceServletInputStream("ActionResolverTest_postPushTag.json"));
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(PushBuildAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postPushMissingEventHeader() throws IOException {
|
||||
String projectName = "postPushMissingEventHeader";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("");
|
||||
when(request.getMethod()).thenReturn("POST");
|
||||
when(request.getHeader("X-Gitee-Event")).thenReturn(null);
|
||||
when(request.getInputStream()).thenReturn(new ResourceServletInputStream("ActionResolverTest_postPush.json"));
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(NoopAction.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postPushUnsupportedEventHeader() throws IOException {
|
||||
String projectName = "postPushUnsupportedEventHeader";
|
||||
jenkins.createFreeStyleProject(projectName);
|
||||
when(request.getRestOfPath()).thenReturn("");
|
||||
when(request.getMethod()).thenReturn("POST");
|
||||
when(request.getHeader("X-Gitee-Event")).thenReturn("__Not Supported Header__");
|
||||
when(request.getInputStream()).thenReturn(new ResourceServletInputStream("ActionResolverTest_postPush.json"));
|
||||
|
||||
WebHookAction resolvedAction = new ActionResolver().resolve(projectName, request);
|
||||
|
||||
assertThat(resolvedAction, instanceOf(NoopAction.class));
|
||||
}
|
||||
|
||||
|
||||
private static class ResourceServletInputStream extends ServletInputStream {
|
||||
|
||||
private final InputStream input;
|
||||
|
||||
private ResourceServletInputStream(String classResourceName) {
|
||||
this.input = getClass().getResourceAsStream(classResourceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return input.read();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.build;
|
||||
|
||||
import com.gitee.jenkins.trigger.GiteePushTrigger;
|
||||
import com.gitee.jenkins.cause.CauseData;
|
||||
import com.gitee.jenkins.cause.GiteeWebHookCause;
|
||||
import com.gitee.jenkins.gitee.hook.model.MergeRequestHook;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.model.ParametersAction;
|
||||
import hudson.model.StringParameterValue;
|
||||
import hudson.model.queue.QueueTaskFuture;
|
||||
import hudson.plugins.git.GitSCM;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.kohsuke.stapler.HttpResponses;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static com.gitee.jenkins.cause.CauseDataBuilder.causeData;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MergeRequestBuildActionTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder();
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private StaplerResponse response;
|
||||
|
||||
@Mock
|
||||
private GiteePushTrigger trigger;
|
||||
|
||||
private String gitRepoUrl;
|
||||
private String commitSha1;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
tmp.newFile("test");
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
git.add().addFilepattern("test");
|
||||
RevCommit commit = git.commit().setMessage("test").call();
|
||||
commitSha1 = commit.getId().getName();
|
||||
gitRepoUrl = tmp.getRoot().toURI().toString();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void build() throws IOException {
|
||||
try {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new MergeRequestBuildAction(testProject, getJson("MergeRequestEvent.json"), null).execute(response);
|
||||
} finally {
|
||||
ArgumentCaptor<MergeRequestHook> pushHookArgumentCaptor = ArgumentCaptor.forClass(MergeRequestHook.class);
|
||||
verify(trigger).onPost(pushHookArgumentCaptor.capture());
|
||||
assertThat(pushHookArgumentCaptor.getValue().getProject(), is(notNullValue()));
|
||||
assertThat(pushHookArgumentCaptor.getValue().getProject().getWebUrl(), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skip_closedMR() throws IOException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new MergeRequestBuildAction(testProject, getJson("MergeRequestEvent_closedMR.json"), null).execute(response);
|
||||
|
||||
verify(trigger, never()).onPost(any(MergeRequestHook.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skip_approvedMR() throws IOException, ExecutionException, InterruptedException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new ParametersAction(new StringParameterValue("gitlabTargetBranch", "master")));
|
||||
future.get();
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new MergeRequestBuildAction(testProject, getJson("MergeRequestEvent_approvedMR.json"), null).execute(response);
|
||||
|
||||
verify(trigger, never()).onPost(any(MergeRequestHook.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skip_alreadyBuiltMR() throws IOException, ExecutionException, InterruptedException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new ParametersAction(new StringParameterValue("gitlabTargetBranch", "master")));
|
||||
future.get();
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new MergeRequestBuildAction(testProject, getJson("MergeRequestEvent_alreadyBuiltMR.json"), null).execute(response);
|
||||
|
||||
verify(trigger, never()).onPost(any(MergeRequestHook.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void build_alreadyBuiltMR_differentTargetBranch() throws IOException, ExecutionException, InterruptedException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new GiteeWebHookCause(causeData()
|
||||
.withActionType(CauseData.ActionType.MERGE)
|
||||
.withSourceProjectId(1)
|
||||
.withTargetProjectId(1)
|
||||
.withBranch("feature")
|
||||
.withSourceBranch("feature")
|
||||
.withUserName("")
|
||||
.withSourceRepoHomepage("https://gitee.org/test")
|
||||
.withSourceRepoName("test")
|
||||
.withSourceNamespace("test-namespace")
|
||||
.withSourceRepoUrl("git@gitee.org:test.git")
|
||||
.withSourceRepoSshUrl("git@gitee.org:test.git")
|
||||
.withSourceRepoHttpUrl("https://gitee.org/test.git")
|
||||
.withMergeRequestTitle("Test")
|
||||
.withMergeRequestId(1)
|
||||
.withMergeRequestIid(1)
|
||||
.withTargetBranch("master")
|
||||
.withTargetRepoName("test")
|
||||
.withTargetNamespace("test-namespace")
|
||||
.withTargetRepoSshUrl("git@gitee.org:test.git")
|
||||
.withTargetRepoHttpUrl("https://gitee.org/test.git")
|
||||
.withTriggeredByUser("test")
|
||||
.withLastCommit("123")
|
||||
.withTargetProjectUrl("https://gitee.org/test")
|
||||
.build()));
|
||||
future.get();
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new MergeRequestBuildAction(testProject, getJson("MergeRequestEvent_alreadyBuiltMR.json"), null).execute(response);
|
||||
|
||||
verify(trigger).onPost(any(MergeRequestHook.class));
|
||||
}
|
||||
|
||||
private String getJson(String name) throws IOException {
|
||||
return IOUtils.toString(getClass().getResourceAsStream(name)).replace("${commitSha1}", commitSha1);
|
||||
}
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.build;
|
||||
|
||||
import com.gitee.jenkins.trigger.GiteePushTrigger;
|
||||
import com.gitee.jenkins.cause.CauseData;
|
||||
import com.gitee.jenkins.cause.GiteeWebHookCause;
|
||||
import com.gitee.jenkins.gitee.hook.model.NoteHook;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.model.ParametersAction;
|
||||
import hudson.model.StringParameterValue;
|
||||
import hudson.model.queue.QueueTaskFuture;
|
||||
import hudson.plugins.git.GitSCM;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.kohsuke.stapler.HttpResponses;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static com.gitee.jenkins.cause.CauseDataBuilder.causeData;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Nikolay Ustinov
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class NoteBuildActionTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder();
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private StaplerResponse response;
|
||||
|
||||
@Mock
|
||||
private GiteePushTrigger trigger;
|
||||
|
||||
private String gitRepoUrl;
|
||||
private String commitSha1;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
tmp.newFile("test");
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
git.add().addFilepattern("test");
|
||||
RevCommit commit = git.commit().setMessage("test").call();
|
||||
commitSha1 = commit.getId().getName();
|
||||
gitRepoUrl = tmp.getRoot().toURI().toString();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void build() throws IOException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new NoteBuildAction(testProject, getJson("NoteEvent.json"), null).execute(response);
|
||||
|
||||
verify(trigger).onPost(any(NoteHook.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void build_alreadyBuiltMR_alreadyBuiltMR() throws IOException, ExecutionException, InterruptedException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new ParametersAction(new StringParameterValue("gitlabTargetBranch", "master")));
|
||||
future.get();
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new NoteBuildAction(testProject, getJson("NoteEvent_alreadyBuiltMR.json"), null).execute(response);
|
||||
|
||||
verify(trigger).onPost(any(NoteHook.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void build_alreadyBuiltMR_differentTargetBranch() throws IOException, ExecutionException, InterruptedException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new GiteeWebHookCause(causeData()
|
||||
.withActionType(CauseData.ActionType.NOTE)
|
||||
.withSourceProjectId(1)
|
||||
.withTargetProjectId(1)
|
||||
.withBranch("feature")
|
||||
.withSourceBranch("feature")
|
||||
.withUserName("")
|
||||
.withSourceRepoHomepage("https://gitee.org/test")
|
||||
.withSourceRepoName("test")
|
||||
.withSourceNamespace("test-namespace")
|
||||
.withSourceRepoUrl("git@gitee.org:test.git")
|
||||
.withSourceRepoSshUrl("git@gitee.org:test.git")
|
||||
.withSourceRepoHttpUrl("https://gitee.org/test.git")
|
||||
.withMergeRequestTitle("Test")
|
||||
.withMergeRequestId(1)
|
||||
.withMergeRequestIid(1)
|
||||
.withTargetBranch("master")
|
||||
.withTargetRepoName("test")
|
||||
.withTargetNamespace("test-namespace")
|
||||
.withTargetRepoSshUrl("git@gitee.org:test.git")
|
||||
.withTargetRepoHttpUrl("https://gitee.org/test.git")
|
||||
.withTriggeredByUser("test")
|
||||
.withLastCommit("123")
|
||||
.withTargetProjectUrl("https://gitee.org/test")
|
||||
.build()));
|
||||
future.get();
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new NoteBuildAction(testProject, getJson("NoteEvent_alreadyBuiltMR.json"), null).execute(response);
|
||||
|
||||
verify(trigger).onPost(any(NoteHook.class));
|
||||
}
|
||||
|
||||
private String getJson(String name) throws IOException {
|
||||
return IOUtils.toString(getClass().getResourceAsStream(name)).replace("${commitSha1}", commitSha1);
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.build;
|
||||
|
||||
import com.gitee.jenkins.trigger.GiteePushTrigger;
|
||||
import com.gitee.jenkins.gitee.hook.model.PipelineHook;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.kohsuke.stapler.HttpResponses;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.gitee.jenkins.cause.CauseDataBuilder.causeData;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Milena Zachow
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PipelineBuildActionTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private StaplerResponse response;
|
||||
|
||||
@Mock
|
||||
private GiteePushTrigger trigger;
|
||||
|
||||
FreeStyleProject testProject;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException{
|
||||
testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildOnSuccess () throws IOException {
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new PipelineBuildAction(testProject, getJson("PipelineEvent.json"), null).execute(response);
|
||||
|
||||
verify(trigger).onPost(any(PipelineHook.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doNotBuildOnFailure() throws IOException {
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new PipelineBuildAction(testProject, getJson("PipelineFailureEvent.json"), null).execute(response);
|
||||
|
||||
verify(trigger, never()).onPost(any(PipelineHook.class));
|
||||
}
|
||||
|
||||
private String getJson(String name) throws IOException {
|
||||
return IOUtils.toString(getClass().getResourceAsStream(name));
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.build;
|
||||
|
||||
import com.gitee.jenkins.trigger.GiteePushTrigger;
|
||||
import com.gitee.jenkins.gitee.hook.model.PushHook;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.kohsuke.stapler.HttpResponses;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PushBuildActionTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private StaplerResponse response;
|
||||
|
||||
@Mock
|
||||
private GiteePushTrigger trigger;
|
||||
|
||||
@Test
|
||||
public void skip_missingRepositoryUrl() throws IOException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
|
||||
new PushBuildAction(testProject, getJson("PushEvent_missingRepositoryUrl.json"), null).execute(response);
|
||||
|
||||
verify(trigger, never()).onPost(any(PushHook.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void build() throws IOException {
|
||||
try {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.addTrigger(trigger);
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new PushBuildAction(testProject, getJson("PushEvent.json"), null).execute(response);
|
||||
} finally {
|
||||
ArgumentCaptor<PushHook> pushHookArgumentCaptor = ArgumentCaptor.forClass(PushHook.class);
|
||||
verify(trigger).onPost(pushHookArgumentCaptor.capture());
|
||||
assertThat(pushHookArgumentCaptor.getValue().getProject(), is(notNullValue()));
|
||||
assertThat(pushHookArgumentCaptor.getValue().getProject().getWebUrl(), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidToken() throws IOException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
when(trigger.getSecretToken()).thenReturn("secret");
|
||||
testProject.addTrigger(trigger);
|
||||
|
||||
exception.expect(HttpResponses.HttpResponseException.class);
|
||||
new PushBuildAction(testProject, getJson("PushEvent.json"), "wrong-secret").execute(response);
|
||||
|
||||
verify(trigger, never()).onPost(any(PushHook.class));
|
||||
}
|
||||
|
||||
private String getJson(String name) throws IOException {
|
||||
return IOUtils.toString(getClass().getResourceAsStream(name));
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.status;
|
||||
|
||||
import hudson.model.FreeStyleProject;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class BranchBuildPageRedirectActionTest extends BuildPageRedirectActionTest {
|
||||
@Override
|
||||
protected BuildPageRedirectAction getBuildPageRedirectAction(FreeStyleProject project) {
|
||||
return new BranchBuildPageRedirectAction(project, branch);
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.status;
|
||||
|
||||
import hudson.model.FreeStyleProject;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class BranchStatusPngActionTest extends StatusPngActionTest {
|
||||
@Override
|
||||
protected BuildStatusAction getBuildStatusAction(FreeStyleProject project) {
|
||||
return new BranchStatusPngAction(project, branch);
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.status;
|
||||
|
||||
import hudson.model.FreeStyleBuild;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.model.queue.QueueTaskFuture;
|
||||
import hudson.plugins.git.GitSCM;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public abstract class BuildPageRedirectActionTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder();
|
||||
protected String commitSha1;
|
||||
protected String branch = "master";
|
||||
@Mock
|
||||
private StaplerResponse response;
|
||||
private String gitRepoUrl;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
tmp.newFile("test");
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
git.add().addFilepattern("test");
|
||||
RevCommit commit = git.commit().setMessage("test").call();
|
||||
commitSha1 = commit.getId().getName();
|
||||
gitRepoUrl = tmp.getRoot().toURI().toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redirectToBuildUrl() throws IOException, ExecutionException, InterruptedException, TimeoutException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
testProject.setQuietPeriod(0);
|
||||
QueueTaskFuture<FreeStyleBuild> future = testProject.scheduleBuild2(0);
|
||||
FreeStyleBuild build = future.get(15, TimeUnit.SECONDS);
|
||||
|
||||
getBuildPageRedirectAction(testProject).execute(response);
|
||||
|
||||
verify(response).sendRedirect2(jenkins.getInstance().getRootUrl() + build.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redirectToBuildStatusUrl() throws IOException, ExecutionException, InterruptedException, TimeoutException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
testProject.setQuietPeriod(0);
|
||||
QueueTaskFuture<FreeStyleBuild> future = testProject.scheduleBuild2(0);
|
||||
FreeStyleBuild build = future.get(5, TimeUnit.SECONDS);
|
||||
|
||||
doThrow(IOException.class).when(response).sendRedirect2(jenkins.getInstance().getRootUrl() + build.getUrl());
|
||||
getBuildPageRedirectAction(testProject).execute(response);
|
||||
|
||||
verify(response).sendRedirect2(jenkins.getInstance().getRootUrl() + build.getBuildStatusUrl());
|
||||
}
|
||||
|
||||
protected abstract BuildPageRedirectAction getBuildPageRedirectAction(FreeStyleProject project);
|
||||
}
|
|
@ -1,204 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.status;
|
||||
|
||||
import hudson.Launcher;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.FreeStyleBuild;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.model.Result;
|
||||
import hudson.plugins.git.GitSCM;
|
||||
import hudson.util.OneShotEvent;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.jvnet.hudson.test.TestBuilder;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public abstract class BuildStatusActionTest {
|
||||
|
||||
@ClassRule
|
||||
public static JenkinsRule jenkins = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tmp = new TemporaryFolder();
|
||||
|
||||
protected String commitSha1;
|
||||
protected String branch = "master";
|
||||
|
||||
@Mock
|
||||
private StaplerResponse response;
|
||||
|
||||
private String gitRepoUrl;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Git.init().setDirectory(tmp.getRoot()).call();
|
||||
tmp.newFile("test");
|
||||
Git git = Git.open(tmp.getRoot());
|
||||
git.add().addFilepattern("test");
|
||||
RevCommit commit = git.commit().setMessage("test").call();
|
||||
commitSha1 = commit.getId().getName();
|
||||
gitRepoUrl = tmp.getRoot().toURI().toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successfulBuild() throws IOException, ExecutionException, InterruptedException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
FreeStyleBuild build = testProject.scheduleBuild2(0).get();
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
mockResponse(out);
|
||||
getBuildStatusAction(testProject).execute(response);
|
||||
|
||||
assertSuccessfulBuild(build, out, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedBuild() throws IOException, ExecutionException, InterruptedException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
testProject.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
build.setResult(Result.FAILURE);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
FreeStyleBuild build = testProject.scheduleBuild2(0).get();
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
mockResponse(out);
|
||||
getBuildStatusAction(testProject).execute(response);
|
||||
|
||||
assertFailedBuild(build, out, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runningBuild() throws IOException, ExecutionException, InterruptedException {
|
||||
final OneShotEvent buildStarted = new OneShotEvent();
|
||||
final OneShotEvent keepRunning = new OneShotEvent();
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
testProject.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
buildStarted.signal();
|
||||
keepRunning.block();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
FreeStyleBuild build = testProject.scheduleBuild2(0).waitForStart();
|
||||
buildStarted.block();
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
mockResponse(out);
|
||||
getBuildStatusAction(testProject).execute(response);
|
||||
keepRunning.signal();
|
||||
|
||||
assertRunningBuild(build, out, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canceledBuild() throws IOException, ExecutionException, InterruptedException, ServletException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
testProject.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
try {
|
||||
build.doStop();
|
||||
} catch (ServletException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
FreeStyleBuild build = testProject.scheduleBuild2(0).get();
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
mockResponse(out);
|
||||
getBuildStatusAction(testProject).execute(response);
|
||||
|
||||
assertCanceledBuild(build, out, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstableBuild() throws IOException, ExecutionException, InterruptedException, ServletException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
testProject.getBuildersList().add(new TestBuilder() {
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
|
||||
build.setResult(Result.UNSTABLE);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
FreeStyleBuild build = testProject.scheduleBuild2(0).get();
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
mockResponse(out);
|
||||
getBuildStatusAction(testProject).execute(response);
|
||||
|
||||
assertUnstableBuild(build, out, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notFoundBuild() throws IOException, ExecutionException, InterruptedException {
|
||||
FreeStyleProject testProject = jenkins.createFreeStyleProject();
|
||||
testProject.setScm(new GitSCM(gitRepoUrl));
|
||||
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
mockResponse(out);
|
||||
getBuildStatusAction(testProject).execute(response);
|
||||
|
||||
assertNotFoundBuild(out, response);
|
||||
}
|
||||
|
||||
protected abstract BuildStatusAction getBuildStatusAction(FreeStyleProject project);
|
||||
|
||||
protected abstract void assertSuccessfulBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException;
|
||||
|
||||
protected abstract void assertFailedBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException;
|
||||
|
||||
protected abstract void assertRunningBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException;
|
||||
|
||||
protected abstract void assertCanceledBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException;
|
||||
|
||||
protected abstract void assertUnstableBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException;
|
||||
|
||||
protected abstract void assertNotFoundBuild(ByteArrayOutputStream out, StaplerResponse response) throws IOException;
|
||||
|
||||
private void mockResponse(final ByteArrayOutputStream out) throws IOException {
|
||||
ServletOutputStream servletOutputStream = new ServletOutputStream() {
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
out.write(b);
|
||||
}
|
||||
};
|
||||
when(response.getOutputStream()).thenReturn(servletOutputStream);
|
||||
when(response.getWriter()).thenReturn(new PrintWriter(servletOutputStream));
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.status;
|
||||
|
||||
import hudson.model.FreeStyleProject;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class CommitBuildPageRedirectActionTest extends BuildPageRedirectActionTest {
|
||||
@Override
|
||||
protected BuildPageRedirectAction getBuildPageRedirectAction(FreeStyleProject project) {
|
||||
return new CommitBuildPageRedirectAction(project, commitSha1);
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.status;
|
||||
|
||||
import hudson.model.FreeStyleProject;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class CommitStatusPngActionTest extends StatusPngActionTest {
|
||||
@Override
|
||||
protected BuildStatusAction getBuildStatusAction(FreeStyleProject project) {
|
||||
return new CommitStatusPngAction(project, commitSha1);
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.status;
|
||||
|
||||
import hudson.model.FreeStyleBuild;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class StatusJsonActionTest extends BuildStatusActionTest {
|
||||
|
||||
@Override
|
||||
protected BuildStatusAction getBuildStatusAction(FreeStyleProject project) {
|
||||
return new StatusJsonAction(project, commitSha1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertSuccessfulBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) {
|
||||
JSONObject object = JSONObject.fromObject(new String(out.toByteArray()));
|
||||
assertThat(object.getString("sha"), is(commitSha1));
|
||||
assertThat(object.getInt("id"), is(build.getNumber()));
|
||||
assertThat(object.getString("status"), is("success"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertFailedBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) {
|
||||
JSONObject object = JSONObject.fromObject(new String(out.toByteArray()));
|
||||
assertThat(object.getString("sha"), is(commitSha1));
|
||||
assertThat(object.getInt("id"), is(build.getNumber()));
|
||||
assertThat(object.getString("status"), is("failed"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertRunningBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) {
|
||||
JSONObject object = JSONObject.fromObject(new String(out.toByteArray()));
|
||||
assertThat(object.getString("sha"), is(commitSha1));
|
||||
assertThat(object.getInt("id"), is(build.getNumber()));
|
||||
assertThat(object.getString("status"), is("running"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertCanceledBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) {
|
||||
JSONObject object = JSONObject.fromObject(new String(out.toByteArray()));
|
||||
assertThat(object.getString("sha"), is(commitSha1));
|
||||
assertThat(object.getInt("id"), is(build.getNumber()));
|
||||
assertThat(object.getString("status"), is("canceled"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertUnstableBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException {
|
||||
JSONObject object = JSONObject.fromObject(new String(out.toByteArray()));
|
||||
assertThat(object.getString("sha"), is(commitSha1));
|
||||
assertThat(object.getInt("id"), is(build.getNumber()));
|
||||
assertThat(object.getString("status"), is("failed"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertNotFoundBuild(ByteArrayOutputStream out, StaplerResponse response) {
|
||||
JSONObject object = JSONObject.fromObject(new String(out.toByteArray()));
|
||||
assertThat(object.getString("sha"), is(commitSha1));
|
||||
assertThat(object.getString("status"), is("not_found"));
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package com.gitee.jenkins.webhook.status;
|
||||
|
||||
import hudson.model.FreeStyleBuild;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public abstract class StatusPngActionTest extends BuildStatusActionTest {
|
||||
|
||||
@Override
|
||||
protected void assertSuccessfulBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException {
|
||||
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
|
||||
verify(response).setHeader("Cache-Control", "no-cache, private");
|
||||
verify(response).setHeader("Content-Type", "image/png");
|
||||
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("success.png"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertFailedBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException {
|
||||
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
|
||||
verify(response).setHeader("Cache-Control", "no-cache, private");
|
||||
verify(response).setHeader("Content-Type", "image/png");
|
||||
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("failed.png"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertRunningBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException {
|
||||
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
|
||||
verify(response).setHeader("Cache-Control", "no-cache, private");
|
||||
verify(response).setHeader("Content-Type", "image/png");
|
||||
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("running.png"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertCanceledBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException {
|
||||
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
|
||||
verify(response).setHeader("Cache-Control", "no-cache, private");
|
||||
verify(response).setHeader("Content-Type", "image/png");
|
||||
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("unknown.png"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertUnstableBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse response) throws IOException {
|
||||
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
|
||||
verify(response).setHeader("Cache-Control", "no-cache, private");
|
||||
verify(response).setHeader("Content-Type", "image/png");
|
||||
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("unstable.png"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertNotFoundBuild(ByteArrayOutputStream out, StaplerResponse response) throws IOException {
|
||||
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
|
||||
verify(response).setHeader("Cache-Control", "no-cache, private");
|
||||
verify(response).setHeader("Content-Type", "image/png");
|
||||
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("unknown.png"))));
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
{
|
||||
"id": "${projectId}",
|
||||
"description": "",
|
||||
"default_branch": "master",
|
||||
"tag_list": [],
|
||||
"public": false,
|
||||
"archived": false,
|
||||
"visibility_level": 10,
|
||||
"ssh_url_to_repo": "git@localhost:${nameSpace}/${projectName}.git",
|
||||
"http_url_to_repo": "https://localhost/${nameSpace}/${projectName}.git",
|
||||
"web_url": "https://localhost/${nameSpace}/${projectName}",
|
||||
"name": "${projectName}",
|
||||
"name_with_namespace": "${nameSpace} / ${projectName}",
|
||||
"path": "${projectName}",
|
||||
"path_with_namespace": "${nameSpace}/${projectName}",
|
||||
"issues_enabled": true,
|
||||
"merge_requests_enabled": true,
|
||||
"wiki_enabled": true,
|
||||
"builds_enabled": true,
|
||||
"snippets_enabled": false,
|
||||
"created_at": "2016-04-08T13:20:40.951Z",
|
||||
"last_activity_at": "2016-05-18T12:55:15.322Z",
|
||||
"shared_runners_enabled": true,
|
||||
"creator_id": 1,
|
||||
"namespace": {
|
||||
"id": 159,
|
||||
"name": "${nameSpace}",
|
||||
"path": "${nameSpace}",
|
||||
"owner_id": null,
|
||||
"created_at": "2016-04-08T13:18:08.233Z",
|
||||
"updated_at": "2016-04-08T13:18:08.233Z",
|
||||
"description": "",
|
||||
"avatar": {
|
||||
"url": null
|
||||
},
|
||||
"share_with_group_lock": false,
|
||||
"visibility_level": 20
|
||||
},
|
||||
"avatar_url": null,
|
||||
"star_count": 2,
|
||||
"forks_count": 0,
|
||||
"open_issues_count": 0,
|
||||
"runners_token": "nR-uhvbge5MTFyBimJ7D",
|
||||
"public_builds": true,
|
||||
"permissions": {
|
||||
"project_access": {
|
||||
"access_level": 40,
|
||||
"notification_level": 3
|
||||
},
|
||||
"group_access": null
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
{
|
||||
"object_kind": "merge_request",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 99,
|
||||
"target_branch": "master",
|
||||
"source_branch": "ms-viewport",
|
||||
"source_project_id": 14,
|
||||
"author_id": 51,
|
||||
"assignee_id": 6,
|
||||
"title": "MS-Viewport",
|
||||
"created_at": "2013-12-03T17:23:34.123Z",
|
||||
"updated_at": "2013-12-03T17:23:34.123Z",
|
||||
"st_commits": null,
|
||||
"st_diffs": null,
|
||||
"milestone_id": null,
|
||||
"state": "opened",
|
||||
"merge_status": "unchecked",
|
||||
"target_project_id": 14,
|
||||
"iid": 1,
|
||||
"description": "",
|
||||
"source": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"target": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
||||
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "Gitee dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"url": "http://example.com/diaspora/merge_requests/1",
|
||||
"action": "open",
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
{
|
||||
"object_kind": "note",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"project_id": 5,
|
||||
"project":{
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"repository":{
|
||||
"name": "Gitee Test",
|
||||
"url": "http://localhost/gitlab-org/gitlab-test.git",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"homepage": "http://example.com/gitlab-org/gitlab-test"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 1244,
|
||||
"note": "This MR needs work.",
|
||||
"noteable_type": "MergeRequest",
|
||||
"author_id": 1,
|
||||
"created_at": "2015-05-17 18:21:36 UTC",
|
||||
"updated_at": "2015-05-17 18:21:36 UTC",
|
||||
"project_id": 5,
|
||||
"attachment": null,
|
||||
"line_code": null,
|
||||
"commit_id": "",
|
||||
"noteable_id": 7,
|
||||
"system": false,
|
||||
"st_diff": null,
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/merge_requests/1#note_1244"
|
||||
},
|
||||
"merge_request": {
|
||||
"id": 7,
|
||||
"target_branch": "markdown",
|
||||
"source_branch": "master",
|
||||
"source_project_id": 5,
|
||||
"author_id": 8,
|
||||
"assignee_id": 28,
|
||||
"title": "Tempora et eos debitis quae laborum et.",
|
||||
"created_at": "2015-03-01 20:12:53 UTC",
|
||||
"updated_at": "2015-03-21 18:27:27 UTC",
|
||||
"milestone_id": 11,
|
||||
"state": "opened",
|
||||
"merge_status": "cannot_be_merged",
|
||||
"target_project_id": 5,
|
||||
"iid": 1,
|
||||
"description": "Et voluptas corrupti assumenda temporibus. Architecto cum animi eveniet amet asperiores. Vitae numquam voluptate est natus sit et ad id.",
|
||||
"position": 0,
|
||||
"locked_at": null,
|
||||
"source":{
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"target": {
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "562e173be03b8ff2efb05345d12df18815438a4b",
|
||||
"message": "Merge branch 'another-branch' into 'master'\n\nCheck in this test\n",
|
||||
"timestamp": "2015-04-08T21: 00:25-07:00",
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/commit/562e173be03b8ff2efb05345d12df18815438a4b",
|
||||
"author": {
|
||||
"name": "John Smith",
|
||||
"email": "john@example.com"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
{
|
||||
"object_kind": "push",
|
||||
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
|
||||
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"ref": "refs/heads/master",
|
||||
"user_id": 4,
|
||||
"user_name": "John Smith",
|
||||
"user_email": "john@example.com",
|
||||
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
|
||||
"project_id": 15,
|
||||
"project": {
|
||||
"name": "Diaspora",
|
||||
"description": "",
|
||||
"web_url": "http://example.com/mike/diaspora",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:mike/diaspora.git",
|
||||
"git_http_url": "http://example.com/mike/diaspora.git",
|
||||
"namespace": "Mike",
|
||||
"visibility_level": 0,
|
||||
"path_with_namespace": "mike/diaspora",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/mike/diaspora",
|
||||
"url": "git@example.com:mike/diasporadiaspora.git",
|
||||
"ssh_url": "git@example.com:mike/diaspora.git",
|
||||
"http_url": "http://example.com/mike/diaspora.git"
|
||||
},
|
||||
"repository": {
|
||||
"name": "Diaspora",
|
||||
"url": "git@example.com:mike/diasporadiaspora.git",
|
||||
"description": "",
|
||||
"homepage": "http://example.com/mike/diaspora",
|
||||
"git_http_url": "http://example.com/mike/diaspora.git",
|
||||
"git_ssh_url": "git@example.com:mike/diaspora.git",
|
||||
"visibility_level": 0
|
||||
},
|
||||
"commits": [
|
||||
{
|
||||
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
|
||||
"message": "Update Catalan translation to e38cb41.",
|
||||
"timestamp": "2011-12-12T14:27:31+02:00",
|
||||
"url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
|
||||
"author": {
|
||||
"name": "Jordi Mallach",
|
||||
"email": "jordi@softcatala.org"
|
||||
},
|
||||
"added": [
|
||||
"CHANGELOG"
|
||||
],
|
||||
"modified": [
|
||||
"app/controller/application.rb"
|
||||
],
|
||||
"removed": []
|
||||
},
|
||||
{
|
||||
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
||||
"url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "Gitee dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
},
|
||||
"added": [
|
||||
"CHANGELOG"
|
||||
],
|
||||
"modified": [
|
||||
"app/controller/application.rb"
|
||||
],
|
||||
"removed": []
|
||||
}
|
||||
],
|
||||
"total_commits_count": 4
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
{
|
||||
"object_kind": "tag_push",
|
||||
"before": "0000000000000000000000000000000000000000",
|
||||
"after": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7",
|
||||
"ref": "refs/tags/v1.0.0",
|
||||
"checkout_sha": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7",
|
||||
"user_id": 1,
|
||||
"user_name": "John Smith",
|
||||
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
|
||||
"project_id": 1,
|
||||
"project":{
|
||||
"name":"Example",
|
||||
"description":"",
|
||||
"web_url":"http://example.com/jsmith/example",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:jsmith/example.git",
|
||||
"git_http_url":"http://example.com/jsmith/example.git",
|
||||
"namespace":"Jsmith",
|
||||
"visibility_level":0,
|
||||
"path_with_namespace":"jsmith/example",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/jsmith/example",
|
||||
"url":"git@example.com:jsmith/example.git",
|
||||
"ssh_url":"git@example.com:jsmith/example.git",
|
||||
"http_url":"http://example.com/jsmith/example.git"
|
||||
},
|
||||
"repository":{
|
||||
"name": "Example",
|
||||
"url": "ssh://git@example.com/jsmith/example.git",
|
||||
"description": "",
|
||||
"homepage": "http://example.com/jsmith/example",
|
||||
"git_http_url":"http://example.com/jsmith/example.git",
|
||||
"git_ssh_url":"git@example.com:jsmith/example.git",
|
||||
"visibility_level":0
|
||||
},
|
||||
"commits": [],
|
||||
"total_commits_count": 0
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
{
|
||||
"object_kind": "merge_request",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 99,
|
||||
"target_branch": "master",
|
||||
"source_branch": "ms-viewport",
|
||||
"source_project_id": 14,
|
||||
"author_id": 51,
|
||||
"assignee_id": 6,
|
||||
"title": "MS-Viewport",
|
||||
"created_at": "2013-12-03T17:23:34.123Z",
|
||||
"updated_at": "2013-12-03T17:23:34.123Z",
|
||||
"st_commits": null,
|
||||
"st_diffs": null,
|
||||
"milestone_id": null,
|
||||
"state": "opened",
|
||||
"merge_status": "unchecked",
|
||||
"target_project_id": 14,
|
||||
"iid": 1,
|
||||
"description": "",
|
||||
"source": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"target": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
||||
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "Gitee dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"url": "http://example.com/diaspora/merge_requests/1",
|
||||
"action": "open",
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
{
|
||||
"object_kind": "merge_request",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 99,
|
||||
"target_branch": "master",
|
||||
"source_branch": "ms-viewport",
|
||||
"source_project_id": 14,
|
||||
"author_id": 51,
|
||||
"assignee_id": 6,
|
||||
"title": "MS-Viewport",
|
||||
"created_at": "2013-12-03T17:23:34.123Z",
|
||||
"updated_at": "2013-12-03T17:23:34.123Z",
|
||||
"st_commits": null,
|
||||
"st_diffs": null,
|
||||
"milestone_id": null,
|
||||
"state": "opened",
|
||||
"merge_status": "unchecked",
|
||||
"target_project_id": 14,
|
||||
"iid": 1,
|
||||
"description": "",
|
||||
"source": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"target": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "${commitSha1}",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
||||
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "Gitee dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"url": "http://example.com/diaspora/merge_requests/1",
|
||||
"action": "open",
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
{
|
||||
"object_kind": "merge_request",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 99,
|
||||
"target_branch": "develop",
|
||||
"source_branch": "ms-viewport",
|
||||
"source_project_id": 14,
|
||||
"author_id": 51,
|
||||
"assignee_id": 6,
|
||||
"title": "MS-Viewport",
|
||||
"created_at": "2013-12-03T17:23:34.123Z",
|
||||
"updated_at": "2013-12-03T17:23:34.123Z",
|
||||
"st_commits": null,
|
||||
"st_diffs": null,
|
||||
"milestone_id": null,
|
||||
"state": "opened",
|
||||
"merge_status": "unchecked",
|
||||
"target_project_id": 14,
|
||||
"iid": 1,
|
||||
"description": "",
|
||||
"source": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"target": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "${commitSha1}",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
||||
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "Gitee dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"url": "http://example.com/diaspora/merge_requests/1",
|
||||
"action": "open",
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
{
|
||||
"object_kind": "merge_request",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 99,
|
||||
"target_branch": "master",
|
||||
"source_branch": "ms-viewport",
|
||||
"source_project_id": 14,
|
||||
"author_id": 51,
|
||||
"assignee_id": 6,
|
||||
"title": "MS-Viewport",
|
||||
"created_at": "2013-12-03T17:23:34.123Z",
|
||||
"updated_at": "2013-12-03T17:23:34.123Z",
|
||||
"st_commits": null,
|
||||
"st_diffs": null,
|
||||
"milestone_id": null,
|
||||
"state": "opened",
|
||||
"merge_status": "unchecked",
|
||||
"target_project_id": 14,
|
||||
"iid": 1,
|
||||
"description": "",
|
||||
"source": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"target": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "${commitSha1}",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
||||
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "Gitee dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"url": "http://example.com/diaspora/merge_requests/1",
|
||||
"action": "approved",
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
{
|
||||
"object_kind": "merge_request",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 99,
|
||||
"target_branch": "master",
|
||||
"source_branch": "ms-viewport",
|
||||
"source_project_id": 14,
|
||||
"author_id": 51,
|
||||
"assignee_id": 6,
|
||||
"title": "MS-Viewport",
|
||||
"created_at": "2013-12-03T17:23:34.123Z",
|
||||
"updated_at": "2013-12-03T17:23:34.123Z",
|
||||
"st_commits": null,
|
||||
"st_diffs": null,
|
||||
"milestone_id": null,
|
||||
"state": "closed",
|
||||
"merge_status": "unchecked",
|
||||
"target_project_id": 14,
|
||||
"iid": 1,
|
||||
"description": "",
|
||||
"source": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"target": {
|
||||
"name": "Awesome Project",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"web_url": "http://example.com/awesome_space/awesome_project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"git_http_url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"namespace": "Awesome Space",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "awesome_space/awesome_project",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/awesome_space/awesome_project",
|
||||
"url": "http://example.com/awesome_space/awesome_project.git",
|
||||
"ssh_url": "git@example.com:awesome_space/awesome_project.git",
|
||||
"http_url": "http://example.com/awesome_space/awesome_project.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
||||
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "Gitee dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"url": "http://example.com/diaspora/merge_requests/1",
|
||||
"action": "open",
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
{
|
||||
"object_kind": "note",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"project_id": 5,
|
||||
"project":{
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"repository":{
|
||||
"name": "Gitee Test",
|
||||
"url": "http://localhost/gitlab-org/gitlab-test.git",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"homepage": "http://example.com/gitlab-org/gitlab-test"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 1244,
|
||||
"note": "This MR needs work.",
|
||||
"noteable_type": "MergeRequest",
|
||||
"author_id": 1,
|
||||
"created_at": "2015-05-17 18:21:36 UTC",
|
||||
"updated_at": "2015-05-17 18:21:36 UTC",
|
||||
"project_id": 5,
|
||||
"attachment": null,
|
||||
"line_code": null,
|
||||
"commit_id": "",
|
||||
"noteable_id": 7,
|
||||
"system": false,
|
||||
"st_diff": null,
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/merge_requests/1#note_1244"
|
||||
},
|
||||
"merge_request": {
|
||||
"id": 7,
|
||||
"target_branch": "markdown",
|
||||
"source_branch": "master",
|
||||
"source_project_id": 5,
|
||||
"author_id": 8,
|
||||
"assignee_id": 28,
|
||||
"title": "Tempora et eos debitis quae laborum et.",
|
||||
"created_at": "2015-03-01 20:12:53 UTC",
|
||||
"updated_at": "2015-03-21 18:27:27 UTC",
|
||||
"milestone_id": 11,
|
||||
"state": "opened",
|
||||
"merge_status": "cannot_be_merged",
|
||||
"target_project_id": 5,
|
||||
"iid": 1,
|
||||
"description": "Et voluptas corrupti assumenda temporibus. Architecto cum animi eveniet amet asperiores. Vitae numquam voluptate est natus sit et ad id.",
|
||||
"position": 0,
|
||||
"locked_at": null,
|
||||
"source":{
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"target": {
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "562e173be03b8ff2efb05345d12df18815438a4b",
|
||||
"message": "Merge branch 'another-branch' into 'master'\n\nCheck in this test\n",
|
||||
"timestamp": "2015-04-08T21: 00:25-07:00",
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/commit/562e173be03b8ff2efb05345d12df18815438a4b",
|
||||
"author": {
|
||||
"name": "John Smith",
|
||||
"email": "john@example.com"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
{
|
||||
"object_kind": "note",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"project_id": 5,
|
||||
"project":{
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"repository":{
|
||||
"name": "Gitee Test",
|
||||
"url": "http://localhost/gitlab-org/gitlab-test.git",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"homepage": "http://example.com/gitlab-org/gitlab-test"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 1244,
|
||||
"note": "This MR needs work.",
|
||||
"noteable_type": "MergeRequest",
|
||||
"author_id": 1,
|
||||
"created_at": "2015-05-17 18:21:36 UTC",
|
||||
"updated_at": "2015-05-17 18:21:36 UTC",
|
||||
"project_id": 5,
|
||||
"attachment": null,
|
||||
"line_code": null,
|
||||
"commit_id": "",
|
||||
"noteable_id": 7,
|
||||
"system": false,
|
||||
"st_diff": null,
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/merge_requests/1#note_1244"
|
||||
},
|
||||
"merge_request": {
|
||||
"id": 7,
|
||||
"target_branch": "markdown",
|
||||
"source_branch": "master",
|
||||
"source_project_id": 5,
|
||||
"author_id": 8,
|
||||
"assignee_id": 28,
|
||||
"title": "Tempora et eos debitis quae laborum et.",
|
||||
"created_at": "2015-03-01 20:12:53 UTC",
|
||||
"updated_at": "2015-03-21 18:27:27 UTC",
|
||||
"milestone_id": 11,
|
||||
"state": "opened",
|
||||
"merge_status": "cannot_be_merged",
|
||||
"target_project_id": 5,
|
||||
"iid": 1,
|
||||
"description": "Et voluptas corrupti assumenda temporibus. Architecto cum animi eveniet amet asperiores. Vitae numquam voluptate est natus sit et ad id.",
|
||||
"position": 0,
|
||||
"locked_at": null,
|
||||
"source":{
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"target": {
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "${commitSha1}",
|
||||
"message": "Merge branch 'another-branch' into 'master'\n\nCheck in this test\n",
|
||||
"timestamp": "2015-04-08T21: 00:25-07:00",
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/commit/562e173be03b8ff2efb05345d12df18815438a4b",
|
||||
"author": {
|
||||
"name": "John Smith",
|
||||
"email": "john@example.com"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
{
|
||||
"object_kind": "note",
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
},
|
||||
"project_id": 5,
|
||||
"project":{
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"repository":{
|
||||
"name": "Gitee Test",
|
||||
"url": "http://localhost/gitlab-org/gitlab-test.git",
|
||||
"description": "Aut reprehenderit ut est.",
|
||||
"homepage": "http://example.com/gitlab-org/gitlab-test"
|
||||
},
|
||||
"object_attributes": {
|
||||
"id": 1244,
|
||||
"note": "This MR needs work.",
|
||||
"noteable_type": "MergeRequest",
|
||||
"author_id": 1,
|
||||
"created_at": "2015-05-17 18:21:36 UTC",
|
||||
"updated_at": "2015-05-17 18:21:36 UTC",
|
||||
"project_id": 5,
|
||||
"attachment": null,
|
||||
"line_code": null,
|
||||
"commit_id": "",
|
||||
"noteable_id": 7,
|
||||
"system": false,
|
||||
"st_diff": null,
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/merge_requests/1#note_1244"
|
||||
},
|
||||
"merge_request": {
|
||||
"id": 7,
|
||||
"target_branch": "develop",
|
||||
"source_branch": "master",
|
||||
"source_project_id": 5,
|
||||
"author_id": 8,
|
||||
"assignee_id": 28,
|
||||
"title": "Tempora et eos debitis quae laborum et.",
|
||||
"created_at": "2015-03-01 20:12:53 UTC",
|
||||
"updated_at": "2015-03-21 18:27:27 UTC",
|
||||
"milestone_id": 11,
|
||||
"state": "opened",
|
||||
"merge_status": "cannot_be_merged",
|
||||
"target_project_id": 5,
|
||||
"iid": 1,
|
||||
"description": "Et voluptas corrupti assumenda temporibus. Architecto cum animi eveniet amet asperiores. Vitae numquam voluptate est natus sit et ad id.",
|
||||
"position": 0,
|
||||
"locked_at": null,
|
||||
"source":{
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"target": {
|
||||
"name":"Gitee Test",
|
||||
"description":"Aut reprehenderit ut est.",
|
||||
"web_url":"http://example.com/gitlab-org/gitlab-test",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"namespace":"Gitee Org",
|
||||
"visibility_level":10,
|
||||
"path_with_namespace":"gitlab-org/gitlab-test",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/gitlab-org/gitlab-test",
|
||||
"url":"http://example.com/gitlab-org/gitlab-test.git",
|
||||
"ssh_url":"git@example.com:gitlab-org/gitlab-test.git",
|
||||
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
|
||||
},
|
||||
"last_commit": {
|
||||
"id": "${commitSha1}",
|
||||
"message": "Merge branch 'another-branch' into 'master'\n\nCheck in this test\n",
|
||||
"timestamp": "2015-04-08T21: 00:25-07:00",
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/commit/562e173be03b8ff2efb05345d12df18815438a4b",
|
||||
"author": {
|
||||
"name": "John Smith",
|
||||
"email": "john@example.com"
|
||||
}
|
||||
},
|
||||
"work_in_progress": false,
|
||||
"assignee": {
|
||||
"name": "User1",
|
||||
"username": "user1",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
{ "object_kind": "pipeline",
|
||||
"object_attributes": {
|
||||
"id": 31,
|
||||
"ref": "master",
|
||||
"tag": false,
|
||||
"sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
|
||||
"before_sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
|
||||
"status": "success",
|
||||
"stages": [
|
||||
"build",
|
||||
"test",
|
||||
"deploy"
|
||||
],
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"finished_at": "2016-08-12 15:26:29 UTC",
|
||||
"duration": 63
|
||||
},
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"project": {
|
||||
"name": "Gitee Test",
|
||||
"description": "Atque in sunt eos similique dolores voluptatem.",
|
||||
"web_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git",
|
||||
"git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git",
|
||||
"namespace": "Gitee Org",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "gitlab-org/gitlab-test",
|
||||
"default_branch": "master"
|
||||
},
|
||||
"commit": {
|
||||
"id": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
|
||||
"message": "test\n",
|
||||
"timestamp": "2016-08-12T17:23:21+02:00",
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/commit/bcbb5ec396a2c0f828686f14fac9b80b780504f2",
|
||||
"author": {
|
||||
"name": "User",
|
||||
"email": "user@gitlab.com"
|
||||
}
|
||||
},
|
||||
"builds": [
|
||||
{
|
||||
"id": 380,
|
||||
"stage": "deploy",
|
||||
"name": "production",
|
||||
"status": "skipped",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": null,
|
||||
"finished_at": null,
|
||||
"when": "manual",
|
||||
"manual": true,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 377,
|
||||
"stage": "test",
|
||||
"name": "test-image",
|
||||
"status": "success",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": "2016-08-12 15:26:12 UTC",
|
||||
"finished_at": null,
|
||||
"when": "on_success",
|
||||
"manual": false,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 378,
|
||||
"stage": "test",
|
||||
"name": "test-build",
|
||||
"status": "success",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": "2016-08-12 15:26:12 UTC",
|
||||
"finished_at": "2016-08-12 15:26:29 UTC",
|
||||
"when": "on_success",
|
||||
"manual": false,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 376,
|
||||
"stage": "build",
|
||||
"name": "build-image",
|
||||
"status": "success",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": "2016-08-12 15:24:56 UTC",
|
||||
"finished_at": "2016-08-12 15:25:26 UTC",
|
||||
"when": "on_success",
|
||||
"manual": false,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 379,
|
||||
"stage": "deploy",
|
||||
"name": "staging",
|
||||
"status": "created",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": null,
|
||||
"finished_at": null,
|
||||
"when": "on_success",
|
||||
"manual": false,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
{ "object_kind": "pipeline",
|
||||
"object_attributes": {
|
||||
"id": 31,
|
||||
"ref": "master",
|
||||
"tag": false,
|
||||
"sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
|
||||
"before_sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
|
||||
"status": "failure",
|
||||
"stages": [
|
||||
"build",
|
||||
"test",
|
||||
"deploy"
|
||||
],
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"finished_at": "2016-08-12 15:26:29 UTC",
|
||||
"duration": 63
|
||||
},
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"project": {
|
||||
"name": "Gitee Test",
|
||||
"description": "Atque in sunt eos similique dolores voluptatem.",
|
||||
"web_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git",
|
||||
"git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git",
|
||||
"namespace": "Gitee Org",
|
||||
"visibility_level": 20,
|
||||
"path_with_namespace": "gitlab-org/gitlab-test",
|
||||
"default_branch": "master"
|
||||
},
|
||||
"commit": {
|
||||
"id": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
|
||||
"message": "test\n",
|
||||
"timestamp": "2016-08-12T17:23:21+02:00",
|
||||
"url": "http://example.com/gitlab-org/gitlab-test/commit/bcbb5ec396a2c0f828686f14fac9b80b780504f2",
|
||||
"author": {
|
||||
"name": "User",
|
||||
"email": "user@gitlab.com"
|
||||
}
|
||||
},
|
||||
"builds": [
|
||||
{
|
||||
"id": 380,
|
||||
"stage": "deploy",
|
||||
"name": "production",
|
||||
"status": "skipped",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": null,
|
||||
"finished_at": null,
|
||||
"when": "manual",
|
||||
"manual": true,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 377,
|
||||
"stage": "test",
|
||||
"name": "test-image",
|
||||
"status": "success",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": "2016-08-12 15:26:12 UTC",
|
||||
"finished_at": null,
|
||||
"when": "on_success",
|
||||
"manual": false,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 378,
|
||||
"stage": "test",
|
||||
"name": "test-build",
|
||||
"status": "success",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": "2016-08-12 15:26:12 UTC",
|
||||
"finished_at": "2016-08-12 15:26:29 UTC",
|
||||
"when": "on_success",
|
||||
"manual": false,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 376,
|
||||
"stage": "build",
|
||||
"name": "build-image",
|
||||
"status": "success",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": "2016-08-12 15:24:56 UTC",
|
||||
"finished_at": "2016-08-12 15:25:26 UTC",
|
||||
"when": "on_success",
|
||||
"manual": false,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 379,
|
||||
"stage": "deploy",
|
||||
"name": "staging",
|
||||
"status": "created",
|
||||
"created_at": "2016-08-12 15:23:28 UTC",
|
||||
"started_at": null,
|
||||
"finished_at": null,
|
||||
"when": "on_success",
|
||||
"manual": false,
|
||||
"user": {
|
||||
"name": "Administrator",
|
||||
"username": "root",
|
||||
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
|
||||
},
|
||||
"runner": null,
|
||||
"artifacts_file": {
|
||||
"filename": null,
|
||||
"size": null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
{
|
||||
"object_kind": "push",
|
||||
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
|
||||
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"ref": "refs/heads/master",
|
||||
"user_id": 4,
|
||||
"user_name": "John Smith",
|
||||
"user_email": "john@example.com",
|
||||
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
|
||||
"project_id": 15,
|
||||
"project": {
|
||||
"name": "Diaspora",
|
||||
"description": "",
|
||||
"web_url": "http://example.com/mike/diaspora",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:mike/diaspora.git",
|
||||
"git_http_url": "http://example.com/mike/diaspora.git",
|
||||
"namespace": "Mike",
|
||||
"visibility_level": 0,
|
||||
"path_with_namespace": "mike/diaspora",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/mike/diaspora",
|
||||
"url": "git@example.com:mike/diasporadiaspora.git",
|
||||
"ssh_url": "git@example.com:mike/diaspora.git",
|
||||
"http_url": "http://example.com/mike/diaspora.git"
|
||||
},
|
||||
"repository": {
|
||||
"name": "Diaspora",
|
||||
"url": "git@example.com:mike/diasporadiaspora.git",
|
||||
"description": "",
|
||||
"homepage": "http://example.com/mike/diaspora",
|
||||
"git_http_url": "http://example.com/mike/diaspora.git",
|
||||
"git_ssh_url": "git@example.com:mike/diaspora.git",
|
||||
"visibility_level": 0
|
||||
},
|
||||
"commits": [
|
||||
{
|
||||
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
|
||||
"message": "Update Catalan translation to e38cb41.",
|
||||
"timestamp": "2011-12-12T14:27:31+02:00",
|
||||
"url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
|
||||
"author": {
|
||||
"name": "Jordi Mallach",
|
||||
"email": "jordi@softcatala.org"
|
||||
},
|
||||
"added": [
|
||||
"CHANGELOG"
|
||||
],
|
||||
"modified": [
|
||||
"app/controller/application.rb"
|
||||
],
|
||||
"removed": []
|
||||
},
|
||||
{
|
||||
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
||||
"url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "Gitee dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
},
|
||||
"added": [
|
||||
"CHANGELOG"
|
||||
],
|
||||
"modified": [
|
||||
"app/controller/application.rb"
|
||||
],
|
||||
"removed": []
|
||||
}
|
||||
],
|
||||
"total_commits_count": 4
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
{
|
||||
"object_kind": "push",
|
||||
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
|
||||
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"ref": "refs/heads/master",
|
||||
"user_id": 4,
|
||||
"user_name": "John Smith",
|
||||
"user_email": "john@example.com",
|
||||
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
|
||||
"project_id": 15,
|
||||
"project": {
|
||||
"name": "Diaspora",
|
||||
"description": "",
|
||||
"web_url": "http://example.com/mike/diaspora",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@example.com:mike/diaspora.git",
|
||||
"git_http_url": "http://example.com/mike/diaspora.git",
|
||||
"namespace": "Mike",
|
||||
"visibility_level": 0,
|
||||
"path_with_namespace": "mike/diaspora",
|
||||
"default_branch": "master",
|
||||
"homepage": "http://example.com/mike/diaspora",
|
||||
"url": "git@example.com:mike/diasporadiaspora.git",
|
||||
"ssh_url": "git@example.com:mike/diaspora.git",
|
||||
"http_url": "http://example.com/mike/diaspora.git"
|
||||
},
|
||||
"repository": {
|
||||
"name": "Diaspora",
|
||||
"description": "",
|
||||
"homepage": "http://example.com/mike/diaspora",
|
||||
"git_http_url": "http://example.com/mike/diaspora.git",
|
||||
"git_ssh_url": "git@example.com:mike/diaspora.git",
|
||||
"visibility_level": 0
|
||||
},
|
||||
"commits": [
|
||||
{
|
||||
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
|
||||
"message": "Update Catalan translation to e38cb41.",
|
||||
"timestamp": "2011-12-12T14:27:31+02:00",
|
||||
"url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
|
||||
"author": {
|
||||
"name": "Jordi Mallach",
|
||||
"email": "jordi@softcatala.org"
|
||||
},
|
||||
"added": [
|
||||
"CHANGELOG"
|
||||
],
|
||||
"modified": [
|
||||
"app/controller/application.rb"
|
||||
],
|
||||
"removed": []
|
||||
},
|
||||
{
|
||||
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"message": "fixed readme",
|
||||
"timestamp": "2012-01-03T23:36:29+02:00",
|
||||
"url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
"author": {
|
||||
"name": "Gitee dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
},
|
||||
"added": [
|
||||
"CHANGELOG"
|
||||
],
|
||||
"modified": [
|
||||
"app/controller/application.rb"
|
||||
],
|
||||
"removed": []
|
||||
}
|
||||
],
|
||||
"total_commits_count": 4
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue