├── .gitignore ├── Jenkinsfile ├── LICENSE ├── LICENSE_HEADER ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── main ├── java │ └── net │ │ └── coding │ │ ├── api │ │ ├── Coding.java │ │ ├── CodingBuilder.java │ │ ├── CodingEmail.java │ │ ├── CodingMyself.java │ │ ├── CodingObject.java │ │ ├── CodingOrganization.java │ │ ├── CodingPerson.java │ │ ├── CodingPersonSet.java │ │ ├── CodingRepository.java │ │ ├── CodingTeam.java │ │ ├── CodingUser.java │ │ ├── HttpConnector.java │ │ ├── HttpException.java │ │ ├── PagedIterable.java │ │ ├── PagedIterator.java │ │ ├── Requester.java │ │ ├── SkipFromToString.java │ │ └── extras │ │ │ ├── ImpatientHttpConnector.java │ │ │ └── OkHttpConnector.java │ │ └── jenkins │ │ └── plugin │ │ ├── CodingPushTrigger.java │ │ ├── Utils.java │ │ ├── bean │ │ └── WebHookTask.java │ │ ├── cause │ │ ├── CauseData.java │ │ └── CodingWebHookCause.java │ │ ├── common │ │ └── gson │ │ │ └── JSON.java │ │ ├── listener │ │ ├── BuildResultListener.java │ │ └── MergeRequestRunListener.java │ │ ├── model │ │ ├── Commit.java │ │ ├── Hook.java │ │ ├── MergeRequest.java │ │ ├── PersonIdent.java │ │ ├── Ref.java │ │ ├── Repository.java │ │ ├── User.java │ │ └── event │ │ │ ├── CodingBaseEvent.java │ │ │ ├── MergeRequest.java │ │ │ └── Push.java │ │ ├── oauth │ │ ├── CodingAccessTokenProperty.java │ │ ├── CodingAuthenticationToken.java │ │ ├── CodingAuthorizationStrategy.java │ │ ├── CodingLogoutAction.java │ │ ├── CodingOAuthGroupDetails.java │ │ ├── CodingOAuthScope.java │ │ ├── CodingOAuthUserDetails.java │ │ ├── CodingRepositoryName.java │ │ ├── CodingRequireOrganizationMembershipACL.java │ │ ├── CodingSecretStorage.java │ │ ├── CodingSecurityRealm.java │ │ └── CodingUtil.java │ │ ├── v1 │ │ └── model │ │ │ ├── Commit.java │ │ │ ├── Committer.java │ │ │ ├── MergeRequest.java │ │ │ ├── PullRequest.java │ │ │ ├── Repository.java │ │ │ ├── User.java │ │ │ └── WebHook.java │ │ └── webhook │ │ ├── CodingWebHook.java │ │ ├── IWebHookHelper.java │ │ ├── TriggerHandler.java │ │ ├── WebHookEnvironmentContributor.java │ │ ├── WebHookHelperV1.java │ │ ├── WebHookHelperV2.java │ │ └── filter │ │ ├── AllBranchesFilter.java │ │ ├── BranchFilter.java │ │ ├── BranchFilterConfig.java │ │ ├── BranchFilterFactory.java │ │ ├── BranchFilterType.java │ │ ├── NameBasedFilter.java │ │ └── RegexBasedFilter.java ├── resources │ ├── index.jelly │ └── net │ │ └── coding │ │ └── jenkins │ │ └── plugin │ │ ├── CodingPushTrigger │ │ ├── config.jelly │ │ ├── config.properties │ │ ├── config_zh_CN.properties │ │ ├── help.jelly │ │ ├── help.properties │ │ └── help_zh_CN.properties │ │ ├── Messages.properties │ │ ├── Messages_zh_CN.properties │ │ ├── cause │ │ ├── Messages.properties │ │ └── Messages_zh_CN.properties │ │ └── oauth │ │ ├── CodingAuthorizationStrategy │ │ ├── config.jelly │ │ ├── config.properties │ │ └── config_zh_CN.properties │ │ ├── CodingLogoutAction │ │ ├── index.jelly │ │ ├── index.properties │ │ └── index_zh_CN.properties │ │ ├── CodingSecurityRealm │ │ ├── config.jelly │ │ ├── config.properties │ │ └── config_zh_CN.properties │ │ ├── Messages.properties │ │ └── Messages_zh_CN.properties └── webapp │ └── help │ ├── help-allowedBranches.html │ ├── help-allowedBranches_zh_CN.html │ ├── help-ci-skip.html │ ├── help-ci-skip_zh_CN.html │ ├── help-filterBranchesByRegex.html │ ├── help-filterBranchesByRegex_zh_CN.html │ ├── help-merge-request.html │ ├── help-merge-request_zh_CN.html │ ├── help-mrpr-action.html │ ├── help-mrpr-action_zh_CN.html │ ├── help-noBranchFiltering.html │ ├── help-noBranchFiltering_zh_CN.html │ ├── help-webhook-api-personal-token.html │ ├── help-webhook-api-personal-token_zh_CN.html │ ├── help-webhook-apitoken.html │ ├── help-webhook-apitoken_zh_CN.html │ ├── help-webhook-token.html │ ├── help-webhook-token_zh_CN.html │ └── oauth │ ├── aaa.sh │ ├── auth │ ├── admin-user-names-help.html │ ├── admin-user-names-help_zh_CN.html │ ├── grant-create-job-to-authenticated-help.html │ ├── grant-create-job-to-authenticated-help_zh_CN.html │ ├── grant-read-to-anonymous-help.html │ ├── grant-read-to-anonymous-help_zh_CN.html │ ├── grant-read-to-authenticated-help.html │ ├── grant-read-to-authenticated-help_zh_CN.html │ ├── grant-read-to-cctray-help.html │ ├── grant-read-to-cctray-help_zh_CN.html │ ├── grant-read-to-coding-webhook-help.html │ ├── grant-read-to-coding-webhook-help_zh_CN.html │ ├── grant-viewstatus-to-anonymous-help.html │ ├── grant-viewstatus-to-anonymous-help_zh_CN.html │ ├── organization-names-help.html │ ├── organization-names-help_zh_CN.html │ ├── use-repository-permissions-help.html │ └── use-repository-permissions-help_zh_CN.html │ ├── help-authorization-strategy.html │ ├── help-authorization-strategy_zh_CN.html │ ├── help-security-realm.html │ ├── help-security-realm_zh_CN.html │ └── realm │ ├── client-id-help.html │ ├── client-id-help_zh_CN.html │ ├── client-secret-help.html │ ├── client-secret-help_zh_CN.html │ ├── coding-api-uri-help.html │ ├── coding-api-uri-help_zh_CN.html │ ├── coding-web-uri-help.html │ ├── coding-web-uri-help_zh_CN.html │ ├── oauth-scopes-help.html │ └── oauth-scopes-help_zh_CN.html └── test └── java └── net └── coding └── jenkins └── plugin └── v1 └── model └── RepositoryTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle Files 2 | .gradle 3 | build/ 4 | 5 | # IntelliJ metadata. 6 | *.iml 7 | *.ipr 8 | *.iws 9 | .idea/ 10 | 11 | # Jenkins files 12 | work/ 13 | out/ 14 | 15 | # mac 16 | .DS_Store 17 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | buildPluginWithGradle(platforms: ['linux']) 2 | -------------------------------------------------------------------------------- /LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | Jenkins plugin for Coding https://coding.net 2 | 3 | Copyright (c) 2016-2018 Shuanglei Tao 4 | Copyright (c) 2016-present, Coding, Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project is archived in favor of coding's [official jenkins integration](https://help.coding.net/docs/project-settings/service-hook/service.html#jenkins). 2 | 3 | ------------- 4 | # Jenkins Coding Webhook Plugin [![Build Status](https://ci.jenkins.io/buildStatus/icon?job=Plugins%2Fcoding-webhook-plugin%2Fmaster)](https://ci.jenkins.io/job/Plugins/job/coding-webhook-plugin/job/master/) 5 | 6 | This plugin integrates [Coding][1] with Jenkins. It handles [WebHook][2] request and triggers 7 | builds for pushes and merge/pull requests. 8 | 9 | ## Installation 10 | 11 | This plugin has been published to the official [Plugins Index][4], follow the [Managing Plugins][5] 12 | document to install it. 13 | 14 | ## Usage 15 | 16 | See (Chinese) 17 | 18 | ## Development 19 | 20 | Run `./gradlew server` to start the development server. 21 | 22 | You may want to disable debug options to get faster page load time: 23 | 24 | ``` 25 | ./gradlew -Dstapler.jelly.noCache=false -Dstapler.trace=false -Ddebug.YUI=false server 26 | ``` 27 | 28 | ## Acknowledgements 29 | 30 | This project is started and based on the [gitlab-plugin][3], thanks for the great project. 31 | The coding-api module follows [github-api][6], and coding-auth module follows [github-oauth-plugin][7], thanks for them. 32 | 33 | [1]: https://coding.net 34 | [2]: https://open.coding.net/webhooks 35 | [3]: https://github.com/jenkinsci/gitlab-plugin 36 | [4]: https://plugins.jenkins.io 37 | [5]: https://jenkins.io/doc/book/managing/plugins 38 | [6]: https://github.com/kohsuke/github-api 39 | [7]: https://github.com/jenkinsci/github-oauth-plugin 40 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.jenkins-ci.jpi' version '0.39.0' 3 | id 'com.github.hierynomus.license' version '0.15.0' 4 | id 'idea' 5 | } 6 | 7 | dependencies { 8 | compileOnly 'org.projectlombok:lombok:1.18.12' 9 | annotationProcessor 'org.projectlombok:lombok:1.18.12' 10 | 11 | implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.0' 12 | implementation 'com.google.code.gson:gson:2.8.6' 13 | implementation 'com.squareup.okhttp:okhttp-urlconnection:2.7.5' 14 | implementation 'commons-codec:commons-codec:1.14' 15 | implementation 'org.jenkins-ci.plugins:branch-api:2.0.19' 16 | implementation 'org.jenkins-ci.plugins:git:3.9.4' 17 | } 18 | 19 | group = 'org.jenkins-ci.plugins' 20 | description = 'Webhook trigger for Coding (https://coding.net)' 21 | version = '1.4.3' 22 | 23 | wrapper { 24 | gradleVersion = '6.5' 25 | } 26 | 27 | java { 28 | sourceCompatibility = JavaVersion.VERSION_1_8 29 | } 30 | 31 | tasks.withType(Javadoc).all { 32 | enabled = false 33 | } 34 | 35 | license { 36 | header project.file('LICENSE_HEADER') 37 | excludes(["**/webhook/filter/*.java", "**/Messages.java", "**/net/coding/jenkins/plugin/oauth/**", "**/net/coding/api/**"]) 38 | } 39 | 40 | jenkinsPlugin { 41 | coreVersion = '2.60.3' 42 | shortName = 'coding-webhook' 43 | displayName = 'Coding Webhook Plugin' 44 | url = 'https://wiki.jenkins.io/display/JENKINS/Coding+Webhook+Plugin' 45 | gitHubUrl = 'https://github.com/jenkinsci/coding-webhook-plugin' 46 | disabledTestInjection = true 47 | 48 | developers { 49 | developer { 50 | id 'tsl0922' 51 | name 'Shuanglei Tao' 52 | email 'tsl0922@gmail.com' 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/coding-webhook-plugin/20e1449513628ad24476b47331ea7bd6a2e82583/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import java.io.IOException; 29 | import java.util.Locale; 30 | import java.util.Map; 31 | import java.util.Properties; 32 | 33 | public class CodingBuilder { 34 | 35 | /* private */ String endpoint = Coding.CODING_URL; 36 | /* private */ String user; 37 | /* private */ String password; 38 | /* private */ String oauthToken; 39 | 40 | private HttpConnector connector; 41 | 42 | public static CodingBuilder fromEnvironment() throws IOException { 43 | Properties props = new Properties(); 44 | for (Map.Entry e : System.getenv().entrySet()) { 45 | String name = e.getKey().toLowerCase(Locale.ENGLISH); 46 | if (name.startsWith("github_")) name=name.substring(7); 47 | props.put(name,e.getValue()); 48 | } 49 | return fromProperties(props); 50 | } 51 | 52 | public static CodingBuilder fromProperties(Properties props) { 53 | CodingBuilder self = new CodingBuilder(); 54 | self.withOAuthToken(props.getProperty("net/coding/jenkins/plugin/oauth"), props.getProperty("login")); 55 | self.withPassword(props.getProperty("login"), props.getProperty("password")); 56 | self.withEndpoint(props.getProperty("endpoint", Coding.CODING_URL)); 57 | return self; 58 | } 59 | 60 | public CodingBuilder withEndpoint(String endpoint) { 61 | this.endpoint = endpoint; 62 | return this; 63 | } 64 | public CodingBuilder withPassword(String user, String password) { 65 | this.user = user; 66 | this.password = password; 67 | return this; 68 | } 69 | public CodingBuilder withOAuthToken(String oauthToken) { 70 | return withOAuthToken(oauthToken, null); 71 | } 72 | public CodingBuilder withOAuthToken(String oauthToken, String user) { 73 | this.oauthToken = oauthToken; 74 | this.user = user; 75 | return this; 76 | } 77 | 78 | public CodingBuilder withConnector(HttpConnector connector) { 79 | this.connector = connector; 80 | return this; 81 | } 82 | 83 | public Coding build() throws IOException { 84 | return new Coding(endpoint, user, oauthToken, password, connector); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingEmail.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 29 | 30 | @SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", 31 | "NP_UNWRITTEN_FIELD", "NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD"}, justification = "JSON API") 32 | public class CodingEmail { 33 | 34 | protected String email; 35 | protected boolean primary; 36 | protected boolean verified; 37 | 38 | public String getEmail() { 39 | return email; 40 | } 41 | 42 | public boolean isPrimary() { 43 | return primary; 44 | } 45 | 46 | public boolean isVerified() { 47 | return verified; 48 | } 49 | 50 | 51 | @Override 52 | public String toString() { 53 | return "Email:"+email; 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return email.hashCode(); 59 | } 60 | 61 | @Override 62 | public boolean equals(Object obj) { 63 | if (obj instanceof CodingEmail) { 64 | CodingEmail that = (CodingEmail) obj; 65 | return this.email.equals(that.email); 66 | } 67 | return false; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingMyself.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import java.io.IOException; 29 | import java.util.Collections; 30 | import java.util.List; 31 | import java.util.Map; 32 | import java.util.TreeMap; 33 | 34 | public class CodingMyself extends CodingUser { 35 | 36 | /** 37 | * Type of repositories returned during listing. 38 | */ 39 | public enum RepositoryListFilter { 40 | /** 41 | * All public and private repositories that current user has access or collaborates to 42 | */ 43 | ALL, 44 | /** 45 | * Public and private repositories owned by current user 46 | */ 47 | OWNER, 48 | /** 49 | * Public repositories that current user has access or collaborates to 50 | */ 51 | PUBLIC, 52 | /** 53 | * Private repositories that current user has access or collaborates to 54 | */ 55 | PRIVATE, 56 | /** 57 | * Public and private repositories that current user is a member 58 | */ 59 | MEMBER; 60 | } 61 | 62 | /** 63 | * Lists up all repositories this user owns (public and private). 64 | * 65 | * Unlike {@link #getAllRepositories()}, this does not wait until all the repositories are returned. 66 | * Repositories are returned by GitHub API with a 30 items per page. 67 | */ 68 | @Override 69 | public PagedIterable listRepositories() { 70 | return listRepositories(30); 71 | } 72 | 73 | /** 74 | * Gets the all repositories this user owns (public and private). 75 | */ 76 | public synchronized Map getAllRepositories() throws IOException { 77 | Map repositories = new TreeMap(); 78 | for (CodingRepository r : listAllRepositories()) { 79 | repositories.put(r.getName(),r); 80 | } 81 | return Collections.unmodifiableMap(repositories); 82 | } 83 | 84 | /** 85 | * @deprecated 86 | * Use {@link #listRepositories()} 87 | */ 88 | public PagedIterable listAllRepositories() { 89 | return listRepositories(); 90 | } 91 | 92 | /** 93 | * Gets the organization that this user belongs to. 94 | */ 95 | public CodingPersonSet getAllOrganizations() throws IOException { 96 | CodingPersonSet orgs = new CodingPersonSet(); 97 | // Set names = new HashSet(); 98 | // for (CodingOrganization o : root.retrieve().to("/user/orgs", CodingOrganization[].class)) { 99 | // if (names.add(o.getLogin())) // in case of rumoured duplicates in the data 100 | // orgs.add(root.getOrganization(o.getLogin())); 101 | // } 102 | 103 | orgs.add(root.getOrganization(null)); 104 | return orgs; 105 | } 106 | 107 | /** 108 | * List repositories that are accessible to the authenticated user (public and private) using the specified page size. 109 | * 110 | * This includes repositories owned by the authenticated user, repositories that belong to other users 111 | * where the authenticated user is a collaborator, and other organizations' repositories that the authenticated 112 | * user has access to through an organization membership. 113 | * 114 | * @param pageSize size for each page of items returned by GitHub. Maximum page size is 100. 115 | * 116 | * Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned. 117 | */ 118 | public PagedIterable listRepositories(final int pageSize) { 119 | return listRepositories(pageSize, RepositoryListFilter.ALL); 120 | } 121 | 122 | /** 123 | * List repositories of a certain type that are accessible by current authenticated user using the specified page size. 124 | * 125 | * @param pageSize size for each page of items returned by GitHub. Maximum page size is 100. 126 | * @param repoType type of repository returned in the listing 127 | */ 128 | public PagedIterable listRepositories(final int pageSize, final RepositoryListFilter repoType) { 129 | return new PagedIterable() { 130 | public PagedIterator _iterator(int pageSize) { 131 | return new PagedIterator(root.retrieve().with("type",repoType).asIterator("/user/repos", CodingRepository[].class, pageSize)) { 132 | @Override 133 | protected void wrapUp(CodingRepository[] page) { 134 | for (CodingRepository c : page) 135 | c.wrap(root); 136 | } 137 | }; 138 | } 139 | }.withPageSize(pageSize); 140 | } 141 | 142 | /** 143 | * Returns the read-only list of e-mail addresses configured for you. 144 | * 145 | * This corresponds to the stuff you configure in https://github.com/settings/emails, 146 | * and not to be confused with {@link #getEmail()} that shows your public e-mail address 147 | * set in https://github.com/settings/profile 148 | * 149 | * @return 150 | * Always non-null. 151 | */ 152 | public List getEmails2() throws IOException { 153 | String fetchEmail = root.retrieve().to("/api/account/email", String.class); 154 | email = fetchEmail; 155 | CodingEmail codingEmail = new CodingEmail(); 156 | codingEmail.email = fetchEmail; 157 | codingEmail.primary = true; 158 | return Collections.unmodifiableList(Collections.singletonList(codingEmail)); 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import org.apache.commons.lang.builder.ReflectionToStringBuilder; 29 | import org.apache.commons.lang.builder.ToStringStyle; 30 | 31 | import java.lang.reflect.Field; 32 | 33 | public class CodingObject { 34 | 35 | protected String url; 36 | protected int id; 37 | protected String created_at; 38 | protected String updated_at; 39 | 40 | /** 41 | * String representation to assist debugging and inspection. The output format of this string 42 | * is not a committed part of the API and is subject to change. 43 | */ 44 | @Override 45 | public String toString() { 46 | return new ReflectionToStringBuilder(this, TOSTRING_STYLE, null, null, false, false) { 47 | @Override 48 | protected boolean accept(Field field) { 49 | return super.accept(field) && !field.isAnnotationPresent(SkipFromToString.class); 50 | } 51 | }.toString(); 52 | } 53 | 54 | private static final ToStringStyle TOSTRING_STYLE = new ToStringStyle() { 55 | { 56 | this.setUseShortClassName(true); 57 | } 58 | 59 | @Override 60 | public void append(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail) { 61 | // skip unimportant properties. '_' is a heuristics as important properties tend to have short names 62 | if (fieldName.contains("_")) 63 | return; 64 | // avoid recursing other GHObject 65 | if (value instanceof CodingObject) 66 | return; 67 | // likewise no point in showing root 68 | if (value instanceof Coding) 69 | return; 70 | 71 | super.append(buffer,fieldName,value,fullDetail); 72 | } 73 | }; 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingOrganization.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import java.io.IOException; 29 | 30 | public class CodingOrganization extends CodingPerson { 31 | protected String avatar_url, gravatar_id; 32 | 33 | /*package*/ CodingOrganization wrapUp(Coding root) { 34 | return (CodingOrganization)super.wrapUp(root); 35 | } 36 | 37 | /** 38 | * Finds a team that has the given name in its {@link CodingTeam#getName()} 39 | */ 40 | public CodingTeam getTeamByName(String name) throws IOException { 41 | for (CodingTeam t : listTeams()) { 42 | if(t.getName().equals(name)) 43 | return t; 44 | } 45 | return null; 46 | } 47 | 48 | /** 49 | * List up all the teams. 50 | */ 51 | public PagedIterable listTeams() throws IOException { 52 | return new PagedIterable() { 53 | public PagedIterator _iterator(int pageSize) { 54 | return new PagedIterator(root.retrieve().asIterator(String.format("/orgs/%s/teams", getLogin()), CodingTeam[].class, pageSize)) { 55 | @Override 56 | protected void wrapUp(CodingTeam[] page) { 57 | for (CodingTeam c : page) 58 | c.wrapUp(CodingOrganization.this); 59 | } 60 | }; 61 | } 62 | }; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingPerson.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import java.io.IOException; 29 | import java.util.Collections; 30 | import java.util.Map; 31 | import java.util.TreeMap; 32 | 33 | public class CodingPerson extends CodingObject { 34 | 35 | /*package almost final*/ Coding root; 36 | 37 | protected String avatar_url, global_key; 38 | 39 | protected String location,blog,email,name,company; 40 | 41 | protected String html_url; 42 | 43 | /** 44 | * Gets the login ID of this user, like 'kohsuke' 45 | */ 46 | public String getLogin() { 47 | return global_key; 48 | } 49 | 50 | /*package*/ CodingPerson wrapUp(Coding root) { 51 | this.root = root; 52 | return this; 53 | } 54 | 55 | /** 56 | * Gets the e-mail address of the user. 57 | */ 58 | public String getEmail() throws IOException { 59 | populate(); 60 | return email; 61 | } 62 | 63 | /** 64 | * Fully populate the data by retrieving missing data. 65 | * 66 | * Depending on the original API call where this object is created, it may not contain everything. 67 | */ 68 | protected synchronized void populate() throws IOException { 69 | if (created_at!=null) return; // already populated 70 | 71 | root.retrieve().to(url, this); 72 | } 73 | 74 | /** 75 | * Lists up all the repositories using a 30 items page size. 76 | * 77 | * Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned. 78 | */ 79 | public PagedIterable listRepositories() { 80 | return listRepositories(30); 81 | } 82 | 83 | /** 84 | * Lists up all the repositories using the specified page size. 85 | * 86 | * @param pageSize size for each page of items returned by GitHub. Maximum page size is 100. 87 | * 88 | * Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned. 89 | */ 90 | public PagedIterable listRepositories(final int pageSize) { 91 | return new PagedIterable() { 92 | public PagedIterator _iterator(int pageSize) { 93 | return new PagedIterator(root.retrieve().asIterator("/users/" + getLogin() + "/repos?per_page=" + pageSize, CodingRepository[].class, pageSize)) { 94 | @Override 95 | protected void wrapUp(CodingRepository[] page) { 96 | for (CodingRepository c : page) 97 | c.wrap(root); 98 | } 99 | }; 100 | } 101 | }; 102 | } 103 | 104 | /** 105 | * Gets the public repositories this user owns. 106 | * 107 | *

108 | * To list your own repositories, including private repositories, 109 | * use {@link CodingMyself#listRepositories()} 110 | */ 111 | public synchronized Map getRepositories() throws IOException { 112 | Map repositories = new TreeMap(); 113 | for (CodingRepository r : listRepositories()) { 114 | repositories.put(r.getName(),r); 115 | } 116 | return Collections.unmodifiableMap(repositories); 117 | } 118 | 119 | /** 120 | * Gets the human-readable name of the user, like "Kohsuke Kawaguchi" 121 | */ 122 | public String getName() throws IOException { 123 | populate(); 124 | return name; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingPersonSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import java.util.Arrays; 29 | import java.util.Collection; 30 | import java.util.HashSet; 31 | 32 | public class CodingPersonSet extends HashSet { 33 | private static final long serialVersionUID = 1L; 34 | 35 | public CodingPersonSet() { 36 | } 37 | 38 | public CodingPersonSet(Collection c) { 39 | super(c); 40 | } 41 | 42 | public CodingPersonSet(T... c) { 43 | super(Arrays.asList(c)); 44 | } 45 | 46 | public CodingPersonSet(int initialCapacity, float loadFactor) { 47 | super(initialCapacity, loadFactor); 48 | } 49 | 50 | public CodingPersonSet(int initialCapacity) { 51 | super(initialCapacity); 52 | } 53 | 54 | /** 55 | * Finds the item by its login. 56 | */ 57 | public T byLogin(String login) { 58 | for (T t : this) 59 | if (t.getLogin().equals(login)) 60 | return t; 61 | return null; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import java.io.IOException; 29 | 30 | public class CodingRepository { 31 | /*package almost final*/ Coding root; 32 | 33 | private String description, homepage, name, full_name; 34 | private String html_url; // this is the UI 35 | 36 | private CodingUser owner; // not fully populated. beware. 37 | 38 | private boolean _private; 39 | private boolean permissions_pull; 40 | private boolean permissions_push; 41 | private boolean permissions_admin; 42 | 43 | /** 44 | * Short repository name without the owner. For example 'jenkins' in case of http://github.com/jenkinsci/jenkins 45 | */ 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | /*package*/ CodingRepository wrap(Coding root) { 51 | this.root = root; 52 | return this; 53 | } 54 | 55 | public CodingUser getOwner() throws IOException { 56 | return root.getUser(owner.getLogin()); // because 'owner' isn't fully populated 57 | } 58 | 59 | public boolean isPrivate() { 60 | return _private; 61 | } 62 | 63 | public boolean hasPullAccess() { 64 | return permissions_pull; 65 | } 66 | 67 | public boolean hasPushAccess() { 68 | return permissions_push; 69 | } 70 | 71 | public boolean hasAdminAccess() { 72 | return permissions_admin; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingTeam.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | public class CodingTeam { 29 | 30 | private String name,permission,slug; 31 | 32 | private CodingOrganization organization; 33 | 34 | protected /*final*/ CodingOrganization org; 35 | 36 | private String global_key, avatar; 37 | 38 | private Integer id; 39 | 40 | public CodingOrganization getOrganization() { 41 | return org; 42 | } 43 | 44 | /*package*/ CodingTeam wrapUp(CodingOrganization owner) { 45 | this.org = owner; 46 | return this; 47 | } 48 | 49 | /*package*/ CodingTeam wrapUp(Coding root) { // auto-wrapUp when organization is known from GET /user/teams 50 | if (this.organization == null) { 51 | this.organization = new CodingOrganization(); 52 | this.organization.global_key = "coding_dot_net"; 53 | } 54 | this.organization.wrapUp(root); 55 | return wrapUp(organization); 56 | } 57 | 58 | public String getName() { 59 | return name; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/CodingUser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | public class CodingUser extends CodingPerson { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/HttpConnector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import net.coding.api.extras.ImpatientHttpConnector; 29 | 30 | import java.io.IOException; 31 | import java.net.HttpURLConnection; 32 | import java.net.URL; 33 | 34 | /** 35 | * Pluggability for customizing HTTP request behaviors or using altogether different library. 36 | * 37 | *

38 | * For example, you can implement this to st custom timeouts. 39 | * 40 | * @author Kohsuke Kawaguchi 41 | */ 42 | public interface HttpConnector { 43 | /** 44 | * Opens a connection to the given URL. 45 | */ 46 | HttpURLConnection connect(URL url) throws IOException; 47 | 48 | /** 49 | * Default implementation that uses {@link URL#openConnection()}. 50 | */ 51 | HttpConnector DEFAULT = new ImpatientHttpConnector(new HttpConnector() { 52 | public HttpURLConnection connect(URL url) throws IOException { 53 | return (HttpURLConnection) url.openConnection(); 54 | } 55 | }); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/HttpException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import javax.annotation.CheckForNull; 29 | import java.io.IOException; 30 | import java.net.URL; 31 | 32 | public class HttpException extends IOException { 33 | 34 | private final int responseCode; 35 | private final String responseMessage; 36 | private final String url; 37 | 38 | public HttpException(int responseCode, String responseMessage, String url, Throwable cause) { 39 | super("Server returned HTTP response code: " + responseCode + ", message: '" + responseMessage + "'" + 40 | " for URL: " + url); 41 | initCause(cause); 42 | this.responseCode = responseCode; 43 | this.responseMessage = responseMessage; 44 | this.url = url; 45 | } 46 | 47 | public HttpException(int responseCode, String responseMessage, @CheckForNull URL url, Throwable cause) { 48 | this(responseCode, responseMessage, url == null ? null : url.toString(), cause); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/PagedIterable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import java.util.ArrayList; 29 | import java.util.LinkedHashSet; 30 | import java.util.List; 31 | import java.util.Set; 32 | 33 | public abstract class PagedIterable implements Iterable { 34 | /** 35 | * Page size. 0 is default. 36 | */ 37 | private int size = 0; 38 | 39 | /** 40 | * Sets the pagination size. 41 | * 42 | *

43 | * When set to non-zero, each API call will retrieve this many entries. 44 | */ 45 | public PagedIterable withPageSize(int size) { 46 | this.size = size; 47 | return this; 48 | } 49 | 50 | public final PagedIterator iterator() { 51 | return _iterator(size); 52 | } 53 | 54 | public abstract PagedIterator _iterator(int pageSize); 55 | 56 | /** 57 | * Eagerly walk {@link Iterable} and return the result in a list. 58 | */ 59 | public List asList() { 60 | List r = new ArrayList(); 61 | for(PagedIterator i = iterator(); i.hasNext();) { 62 | r.addAll(i.nextPage()); 63 | } 64 | return r; 65 | } 66 | 67 | /** 68 | * Eagerly walk {@link Iterable} and return the result in a set. 69 | */ 70 | public Set asSet() { 71 | LinkedHashSet r = new LinkedHashSet(); 72 | for(PagedIterator i = iterator(); i.hasNext();) { 73 | r.addAll(i.nextPage()); 74 | } 75 | return r; 76 | } 77 | } -------------------------------------------------------------------------------- /src/main/java/net/coding/api/PagedIterator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import java.util.Arrays; 29 | import java.util.Iterator; 30 | import java.util.List; 31 | import java.util.NoSuchElementException; 32 | 33 | public abstract class PagedIterator implements Iterator { 34 | private final Iterator base; 35 | 36 | /** 37 | * Current batch that we retrieved but haven't returned to the caller. 38 | */ 39 | private T[] current; 40 | private int pos; 41 | 42 | /*package*/ PagedIterator(Iterator base) { 43 | this.base = base; 44 | } 45 | 46 | protected abstract void wrapUp(T[] page); 47 | 48 | public boolean hasNext() { 49 | fetch(); 50 | return current!=null; 51 | } 52 | 53 | public T next() { 54 | fetch(); 55 | if (current==null) throw new NoSuchElementException(); 56 | return current[pos++]; 57 | } 58 | 59 | private void fetch() { 60 | while (current==null || current.length<=pos) { 61 | if (!base.hasNext()) {// no more to retrieve 62 | current = null; 63 | pos = 0; 64 | return; 65 | } 66 | 67 | current = base.next(); 68 | wrapUp(current); 69 | pos = 0; 70 | } 71 | // invariant at the end: there's some data to retrieve 72 | } 73 | 74 | public void remove() { 75 | throw new UnsupportedOperationException(); 76 | } 77 | 78 | /** 79 | * Gets the next page worth of data. 80 | */ 81 | public List nextPage() { 82 | fetch(); 83 | List r = Arrays.asList(current); 84 | r = r.subList(pos,r.size()); 85 | current = null; 86 | pos = 0; 87 | return r; 88 | } 89 | } -------------------------------------------------------------------------------- /src/main/java/net/coding/api/SkipFromToString.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api; 27 | 28 | import java.lang.annotation.ElementType; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.RetentionPolicy; 31 | import java.lang.annotation.Target; 32 | 33 | @Target(ElementType.FIELD) 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @interface SkipFromToString { 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/coding/api/extras/ImpatientHttpConnector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api.extras; 27 | 28 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 29 | import net.coding.api.HttpConnector; 30 | 31 | import java.io.IOException; 32 | import java.net.HttpURLConnection; 33 | import java.net.URL; 34 | import java.util.concurrent.TimeUnit; 35 | 36 | public class ImpatientHttpConnector implements HttpConnector { 37 | private final HttpConnector base; 38 | private final int readTimeout, connectTimeout; 39 | 40 | /** 41 | * @param connectTimeout 42 | * HTTP connection timeout in milliseconds 43 | * @param readTimeout 44 | * HTTP read timeout in milliseconds 45 | */ 46 | public ImpatientHttpConnector(HttpConnector base, int connectTimeout, int readTimeout) { 47 | this.base = base; 48 | this.connectTimeout = connectTimeout; 49 | this.readTimeout = readTimeout; 50 | } 51 | 52 | public ImpatientHttpConnector(HttpConnector base, int timeout) { 53 | this(base,timeout,timeout); 54 | } 55 | 56 | public ImpatientHttpConnector(HttpConnector base) { 57 | this(base,CONNECT_TIMEOUT,READ_TIMEOUT); 58 | } 59 | 60 | public HttpURLConnection connect(URL url) throws IOException { 61 | HttpURLConnection con = base.connect(url); 62 | con.setConnectTimeout(connectTimeout); 63 | con.setReadTimeout(readTimeout); 64 | return con; 65 | } 66 | 67 | /** 68 | * Default connection timeout in milliseconds 69 | */ 70 | @SuppressFBWarnings("MS_SHOULD_BE_FINAL") 71 | public static int CONNECT_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); 72 | 73 | /** 74 | * Default read timeout in milliseconds 75 | */ 76 | @SuppressFBWarnings("MS_SHOULD_BE_FINAL") 77 | public static int READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); 78 | } -------------------------------------------------------------------------------- /src/main/java/net/coding/api/extras/OkHttpConnector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011- Kohsuke Kawaguchi and other contributors 3 | * Copyright (c) 2016-present, Coding, Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | * OTHER DEALINGS IN THE SOFTWARE. 25 | */ 26 | package net.coding.api.extras; 27 | 28 | import com.squareup.okhttp.OkUrlFactory; 29 | import net.coding.api.HttpConnector; 30 | 31 | import java.io.IOException; 32 | import java.net.HttpURLConnection; 33 | import java.net.URL; 34 | 35 | public class OkHttpConnector implements HttpConnector { 36 | private final OkUrlFactory urlFactory; 37 | 38 | public OkHttpConnector(OkUrlFactory urlFactory) { 39 | this.urlFactory = urlFactory; 40 | } 41 | 42 | public HttpURLConnection connect(URL url) throws IOException { 43 | return urlFactory.open(url); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/CodingPushTrigger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin; 21 | 22 | import com.google.gson.Gson; 23 | import hudson.Extension; 24 | import hudson.Util; 25 | import hudson.model.Item; 26 | import hudson.model.Job; 27 | import hudson.triggers.Trigger; 28 | import hudson.triggers.TriggerDescriptor; 29 | import jenkins.model.Jenkins; 30 | import jenkins.model.ParameterizedJobMixIn; 31 | import jenkins.triggers.SCMTriggerItem; 32 | import lombok.AccessLevel; 33 | import lombok.Data; 34 | import lombok.EqualsAndHashCode; 35 | import lombok.Getter; 36 | import lombok.Setter; 37 | import net.coding.jenkins.plugin.bean.WebHookTask; 38 | import net.coding.jenkins.plugin.webhook.CodingWebHook; 39 | import net.coding.jenkins.plugin.webhook.IWebHookHelper; 40 | import net.coding.jenkins.plugin.webhook.TriggerHandler; 41 | import net.coding.jenkins.plugin.webhook.filter.BranchFilterConfig; 42 | import net.coding.jenkins.plugin.webhook.filter.BranchFilterFactory; 43 | import net.coding.jenkins.plugin.webhook.filter.BranchFilterType; 44 | import org.kohsuke.stapler.Ancestor; 45 | import org.kohsuke.stapler.DataBoundConstructor; 46 | import org.kohsuke.stapler.Stapler; 47 | import org.kohsuke.stapler.StaplerRequest; 48 | 49 | import java.io.ObjectStreamException; 50 | import java.util.logging.Level; 51 | import java.util.logging.Logger; 52 | 53 | /** 54 | * @author tsl0922 55 | */ 56 | @EqualsAndHashCode(callSuper = false) 57 | @Data 58 | public class CodingPushTrigger extends Trigger> { 59 | private static final Logger LOGGER = Logger.getLogger(CodingPushTrigger.class.getName()); 60 | 61 | private String webHookToken; 62 | private String apiToken; 63 | private String personalToken; 64 | private boolean triggerOnPush; 65 | private boolean triggerOnMergeRequest; 66 | private String mergeRequestTriggerAction; 67 | private boolean addResultNote; 68 | private boolean ciSkip; 69 | private BranchFilterType branchFilterType; 70 | private String includeBranchesSpec; 71 | private String excludeBranchesSpec; 72 | private String targetBranchRegex; 73 | 74 | @Getter(AccessLevel.NONE) 75 | @Setter(AccessLevel.NONE) 76 | private transient TriggerHandler triggerHandler; 77 | 78 | @DataBoundConstructor 79 | public CodingPushTrigger(String webHookToken, String apiToken, String personalToken, 80 | boolean triggerOnMergeRequest, String mergeRequestTriggerAction, 81 | boolean triggerOnPush, boolean addResultNote, boolean ciSkip, 82 | BranchFilterType branchFilterType, String includeBranchesSpec, 83 | String excludeBranchesSpec, String targetBranchRegex) { 84 | this.webHookToken = webHookToken; 85 | this.apiToken = apiToken; 86 | this.personalToken = personalToken; 87 | this.triggerOnPush = triggerOnPush; 88 | this.triggerOnMergeRequest = triggerOnMergeRequest; 89 | this.mergeRequestTriggerAction = mergeRequestTriggerAction; 90 | this.addResultNote = addResultNote; 91 | this.ciSkip = ciSkip; 92 | this.branchFilterType = branchFilterType; 93 | this.includeBranchesSpec = includeBranchesSpec; 94 | this.excludeBranchesSpec = excludeBranchesSpec; 95 | this.targetBranchRegex = targetBranchRegex; 96 | 97 | initializeTriggerHandler(); 98 | } 99 | 100 | private void initializeTriggerHandler() { 101 | if (this.branchFilterType == null) { 102 | this.branchFilterType = BranchFilterType.All; 103 | } 104 | BranchFilterConfig branchFilterConfig = new BranchFilterConfig( 105 | branchFilterType, includeBranchesSpec, excludeBranchesSpec, targetBranchRegex); 106 | this.triggerHandler = new TriggerHandler( 107 | this.triggerOnPush, this.triggerOnMergeRequest, mergeRequestTriggerAction, 108 | BranchFilterFactory.newBranchFilter(branchFilterConfig) 109 | ); 110 | } 111 | 112 | @Override 113 | protected Object readResolve() throws ObjectStreamException { 114 | initializeTriggerHandler(); 115 | return super.readResolve(); 116 | } 117 | 118 | public void onPost(WebHookTask task) { 119 | IWebHookHelper helper = CodingWebHook.webHookHelper(task.getVersion()); 120 | if (helper == null) { 121 | throw hudson.util.HttpResponses.error(400, "Bad Request"); 122 | } 123 | if (helper.isSignatureValid(task, webHookToken)) { 124 | triggerHandler.handle(job, task, ciSkip); 125 | } else { 126 | LOGGER.log(Level.INFO, "Skipping due to invalid Signature for webHookTask: {0}", new Gson().toJson(task)); 127 | throw hudson.util.HttpResponses.error(401, "Signature Invalid"); 128 | } 129 | } 130 | 131 | public static CodingPushTrigger getFromJob(Job job) { 132 | CodingPushTrigger trigger = null; 133 | if (job instanceof ParameterizedJobMixIn.ParameterizedJob) { 134 | ParameterizedJobMixIn.ParameterizedJob p = (ParameterizedJobMixIn.ParameterizedJob) job; 135 | for (Object t : p.getTriggers().values()) { 136 | if (t instanceof CodingPushTrigger) { 137 | trigger = (CodingPushTrigger) t; 138 | } 139 | } 140 | } 141 | return trigger; 142 | } 143 | 144 | @Extension 145 | public static class DescriptorImpl extends TriggerDescriptor { 146 | 147 | @Override 148 | public boolean isApplicable(Item item) { 149 | return item instanceof Job 150 | && SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(item) != null 151 | && item instanceof ParameterizedJobMixIn.ParameterizedJob; 152 | } 153 | 154 | @Override 155 | public String getDisplayName() { 156 | Job project = retrieveCurrentJob(); 157 | if (project != null) { 158 | try { 159 | return Messages.coding_trigger_title(retrieveProjectUrl(project)); 160 | } catch (IllegalStateException ignored) { 161 | } 162 | } 163 | return Messages.coding_trigger_title_unknown(); 164 | } 165 | 166 | private StringBuilder retrieveProjectUrl(Job project) { 167 | return new StringBuilder() 168 | .append(Jenkins.getInstance().getRootUrl()) 169 | .append(CodingWebHook.WEBHOOK_URL) 170 | .append(retrieveParentUrl(project)) 171 | .append('/').append(Util.rawEncode(project.getName())); 172 | } 173 | 174 | private StringBuilder retrieveParentUrl(Item item) { 175 | if (item.getParent() instanceof Item) { 176 | Item parent = (Item) item.getParent(); 177 | return retrieveParentUrl(parent).append('/').append(Util.rawEncode(parent.getName())); 178 | } else { 179 | return new StringBuilder(); 180 | } 181 | } 182 | 183 | private Job retrieveCurrentJob() { 184 | StaplerRequest request = Stapler.getCurrentRequest(); 185 | if (request != null) { 186 | Ancestor ancestor = request.findAncestor(Job.class); 187 | return ancestor == null ? null : (Job) ancestor.getObject(); 188 | } 189 | return null; 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/Utils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin; 21 | 22 | import org.apache.commons.io.IOUtils; 23 | import org.kohsuke.stapler.HttpResponses; 24 | 25 | import javax.servlet.http.HttpServletRequest; 26 | import java.io.IOException; 27 | import java.nio.charset.Charset; 28 | 29 | import static java.nio.charset.StandardCharsets.UTF_8; 30 | 31 | public class Utils { 32 | public static String getRequestBody(HttpServletRequest request) { 33 | String requestBody; 34 | try { 35 | Charset charset = request.getCharacterEncoding() == null ? UTF_8 : Charset.forName(request.getCharacterEncoding()); 36 | requestBody = IOUtils.toString(request.getInputStream(), charset); 37 | } catch (IOException e) { 38 | throw HttpResponses.error(500, "Failed to read request body"); 39 | } 40 | return requestBody; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/bean/WebHookTask.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.bean; 21 | 22 | import lombok.Data; 23 | import net.coding.jenkins.plugin.model.Repository; 24 | import net.coding.jenkins.plugin.model.User; 25 | import net.coding.jenkins.plugin.model.event.CodingBaseEvent; 26 | import net.coding.jenkins.plugin.model.event.MergeRequest; 27 | import net.coding.jenkins.plugin.model.event.Push; 28 | 29 | @Data 30 | public class WebHookTask { 31 | 32 | public static final String EVENT_PUSH = "push"; 33 | public static final String EVENT_MERGE_REQUEST = "merge request"; 34 | 35 | private Push push; 36 | private MergeRequest mergeRequest; 37 | private String event; 38 | private String signature; 39 | private String version; 40 | private String requestBody; 41 | private boolean parseSuccess = false; 42 | 43 | public Repository getRepository() { 44 | CodingBaseEvent baseEvent = getBaseEvent(); 45 | if (baseEvent == null) { 46 | return null; 47 | } 48 | return baseEvent.getRepository(); 49 | } 50 | 51 | public User getSender() { 52 | return getBaseEvent().getSender(); 53 | } 54 | 55 | public CodingBaseEvent getBaseEvent() { 56 | switch (event) { 57 | case EVENT_PUSH: 58 | return push; 59 | case EVENT_MERGE_REQUEST: 60 | return mergeRequest; 61 | default: 62 | return null; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/cause/CauseData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.cause; 21 | 22 | import org.apache.commons.lang.StringUtils; 23 | 24 | import lombok.Data; 25 | 26 | /** 27 | * @author tsl0922 28 | */ 29 | @Data 30 | public class CauseData { 31 | private ActionType actionType; 32 | 33 | private String token; 34 | private String userGK; 35 | private String userName; 36 | private String userUrl; 37 | 38 | // private String projectApiUrl; 39 | private String projectHtmlUrl; 40 | private String fullName; 41 | private String ref; 42 | private String before; 43 | private String after; 44 | private String repoUrl; 45 | private String commitId; 46 | 47 | private Long mergeRequestId; 48 | private Long mergeRequestIid; 49 | private String mergeRequestTitle; 50 | private String mergeRequestUrl; 51 | private String mergeRequestBody; 52 | 53 | private String sourceProjectPath; 54 | private String sourceBranch; 55 | private String sourceRepoUrl; 56 | private String sourceUser; 57 | private String targetBranch; 58 | 59 | String getShortDescription() { 60 | return actionType.getShortDescription(this); 61 | } 62 | 63 | public enum ActionType { 64 | PUSH { 65 | @Override 66 | String getShortDescription(CauseData data) { 67 | String pushedBy = data.getUserName(); 68 | if (pushedBy == null) { 69 | return Messages.coding_action_push(); 70 | } else { 71 | return String.format(Messages.coding_action_push_by(), pushedBy); 72 | } 73 | } 74 | }, MR { 75 | @Override 76 | String getShortDescription(CauseData data) { 77 | String user = StringUtils.isEmpty(data.getUserName()) ? "Unknown" : data.getUserName(); 78 | return String.format(Messages.coding_action_merge_request(), 79 | user, data.getMergeRequestIid(), data.getMergeRequestTitle(), 80 | data.getSourceBranch(), data.getTargetBranch()); 81 | } 82 | }, PR { 83 | @Override 84 | String getShortDescription(CauseData data) { 85 | String user = StringUtils.isEmpty(data.getUserName()) ? "Unknown" : data.getUserName(); 86 | return String.format(Messages.coding_action_pull_request(), 87 | user, data.getMergeRequestIid(), data.getMergeRequestTitle(), 88 | data.getSourceUser(), data.getSourceBranch(), data.getTargetBranch()); 89 | } 90 | }; 91 | 92 | abstract String getShortDescription(CauseData data); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/cause/CodingWebHookCause.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.cause; 21 | 22 | import hudson.triggers.SCMTrigger; 23 | 24 | import static com.google.common.base.Preconditions.checkNotNull; 25 | 26 | /** 27 | * @author tsl0922 28 | */ 29 | public class CodingWebHookCause extends SCMTrigger.SCMTriggerCause { 30 | private final CauseData data; 31 | 32 | public CodingWebHookCause(CauseData data) { 33 | super(""); 34 | this.data = checkNotNull(data, "data must not be null"); 35 | } 36 | 37 | public CauseData getData() { 38 | return data; 39 | } 40 | 41 | @Override 42 | public String getShortDescription() { 43 | return data.getShortDescription(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/common/gson/JSON.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.common.gson; 21 | 22 | import com.google.gson.Gson; 23 | import com.google.gson.GsonBuilder; 24 | import com.google.gson.JsonElement; 25 | 26 | import java.lang.reflect.Type; 27 | import java.util.Map; 28 | 29 | public class JSON { 30 | 31 | public static Gson getGson() { 32 | return getGsonBuilder().create(); 33 | } 34 | 35 | public static GsonBuilder getGsonBuilder() { 36 | return new GsonBuilder(); 37 | } 38 | 39 | public static String toJson(Object obj) { 40 | return getGson().toJson(obj); 41 | } 42 | 43 | public static Map fromJson(String json) { 44 | return getGson().fromJson(json, Map.class); 45 | } 46 | 47 | // Note: GSON fromJson is written the same way. 48 | @SuppressWarnings("TypeParameterUnusedInFormals") 49 | public static T fromJson(String json, Type typeOfT) { 50 | return getGson().fromJson(json, typeOfT); 51 | } 52 | 53 | public static T fromJson(String json, Class classOfT) { 54 | return getGson().fromJson(json, classOfT); 55 | } 56 | 57 | public static T fromJson(JsonElement json, Class classOfT) { 58 | return getGson().fromJson(json, classOfT); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/listener/BuildResultListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.listener; 21 | 22 | import net.coding.jenkins.plugin.cause.CodingWebHookCause; 23 | 24 | import java.io.IOException; 25 | 26 | import hudson.Extension; 27 | import hudson.model.AbstractBuild; 28 | import hudson.model.BuildStepListener; 29 | import hudson.model.Result; 30 | import hudson.tasks.BuildStep; 31 | 32 | /** 33 | * @author tsl0922 34 | */ 35 | @Extension 36 | public class BuildResultListener extends BuildStepListener { 37 | @Override 38 | public void started(AbstractBuild build, BuildStep bs, hudson.model.BuildListener listener) { 39 | 40 | } 41 | 42 | @Override 43 | public void finished(AbstractBuild build, BuildStep bs, hudson.model.BuildListener listener, boolean canContinue) { 44 | if (build.getCause(CodingWebHookCause.class) != null 45 | && build.getResult() == Result.FAILURE 46 | && isCommitAmbiguous(build)) { 47 | build.setResult(Result.NOT_BUILT); 48 | } 49 | } 50 | 51 | private boolean isCommitAmbiguous(AbstractBuild build) { 52 | try { 53 | for (Object log : build.getLog(500)) { 54 | String str = log.toString(); 55 | if (str.contains("stderr: fatal: ambiguous argument") 56 | && str.contains("unknown revision or path not in the working tree")) { 57 | return true; 58 | } 59 | } 60 | return false; 61 | } catch (IOException e) { 62 | return false; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/Commit.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model; 21 | 22 | import lombok.Data; 23 | 24 | import java.io.Serializable; 25 | import java.util.List; 26 | 27 | @Data 28 | public class Commit implements Serializable { 29 | 30 | private static final long serialVersionUID = -1811302245094462653L; 31 | 32 | private String id; 33 | private String tree_id; 34 | private boolean distinct; 35 | private String message; 36 | private String url; 37 | private PersonIdent author; 38 | private PersonIdent committer; 39 | private List added; 40 | private List removed; 41 | private List modified; 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/Hook.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model; 21 | 22 | import lombok.Data; 23 | 24 | import java.io.Serializable; 25 | import java.util.List; 26 | 27 | @Data 28 | public class Hook implements Serializable { 29 | 30 | private static final long serialVersionUID = -6249104108788941131L; 31 | 32 | private int id; 33 | private String name; 34 | private String type; 35 | private boolean active; 36 | private List events; 37 | private Config config; 38 | 39 | @Data 40 | public static class Config implements Serializable { 41 | 42 | private static final long serialVersionUID = -497411814487832323L; 43 | 44 | private String content_type; 45 | private String secret; 46 | private String url; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/MergeRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model; 21 | 22 | import lombok.Data; 23 | 24 | import java.io.Serializable; 25 | 26 | @Data 27 | public class MergeRequest implements Serializable { 28 | 29 | private static final long serialVersionUID = -8632601797141226063L; 30 | 31 | private long id; 32 | private String url; 33 | private String html_url; 34 | private String patch_url; 35 | private String diff_url; 36 | private long number; 37 | private String state; 38 | private String title; 39 | private String body; 40 | private User user; 41 | private String merge_commit_sha; 42 | 43 | private Ref head; 44 | private Ref base; 45 | private boolean merged; 46 | private User merged_by; 47 | private int comments; 48 | private int commits; 49 | private int additions; 50 | private int deletions; 51 | private int changed_files; 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/PersonIdent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model; 21 | 22 | import lombok.Data; 23 | 24 | import java.io.Serializable; 25 | 26 | @Data 27 | public class PersonIdent implements Serializable { 28 | 29 | private static final long serialVersionUID = 4646040930652004500L; 30 | 31 | private String name; 32 | private String email; 33 | private String username; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/Ref.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model; 21 | 22 | import lombok.Data; 23 | 24 | import java.io.Serializable; 25 | 26 | @Data 27 | public class Ref implements Serializable { 28 | 29 | private static final long serialVersionUID = -4853752378517375885L; 30 | 31 | private String label; 32 | private String ref; 33 | private String sha; 34 | private User user; 35 | private Repository repo; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/Repository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model; 21 | 22 | import com.google.gson.annotations.SerializedName; 23 | import lombok.Data; 24 | 25 | import java.io.Serializable; 26 | 27 | @Data 28 | public class Repository implements Serializable { 29 | 30 | private static final long serialVersionUID = -4958159118706816396L; 31 | 32 | private int id; 33 | private String name; 34 | private String full_name; 35 | private User owner; 36 | @SerializedName("private") 37 | private boolean is_private; 38 | private String html_url; 39 | private String description; 40 | private boolean fork; 41 | private String url; 42 | private String clone_url; 43 | private String ssh_url; 44 | private String default_branch; 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model; 21 | 22 | import lombok.Data; 23 | 24 | import java.io.Serializable; 25 | 26 | @Data 27 | public class User implements Serializable { 28 | 29 | private static final long serialVersionUID = -9183217379960904944L; 30 | 31 | private int id; 32 | private String login; 33 | private String avatar_url; 34 | 35 | private String url; 36 | private String html_url; 37 | 38 | private String name; 39 | private String name_pinyin; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/event/CodingBaseEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model.event; 21 | 22 | import lombok.Data; 23 | import lombok.EqualsAndHashCode; 24 | import net.coding.jenkins.plugin.model.Repository; 25 | import net.coding.jenkins.plugin.model.User; 26 | 27 | @EqualsAndHashCode 28 | @Data 29 | public abstract class CodingBaseEvent { 30 | private User sender; 31 | private Repository repository; 32 | 33 | public abstract String action(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/event/MergeRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model.event; 21 | 22 | import lombok.Data; 23 | import lombok.EqualsAndHashCode; 24 | 25 | import java.io.Serializable; 26 | 27 | @Data 28 | @EqualsAndHashCode(callSuper = false) 29 | public class MergeRequest extends CodingBaseEvent implements Serializable { 30 | 31 | private static final long serialVersionUID = -101752450737183314L; 32 | 33 | private String action; 34 | private long number; 35 | private net.coding.jenkins.plugin.model.MergeRequest mergeRequest; 36 | 37 | @Override 38 | public String action() { 39 | return "merge request"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/model/event/Push.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.model.event; 21 | 22 | import lombok.Data; 23 | import lombok.EqualsAndHashCode; 24 | import net.coding.jenkins.plugin.model.Commit; 25 | import net.coding.jenkins.plugin.model.PersonIdent; 26 | 27 | import java.io.Serializable; 28 | import java.util.List; 29 | 30 | @Data 31 | @EqualsAndHashCode(callSuper = false) 32 | public class Push extends CodingBaseEvent implements Serializable { 33 | 34 | private static final long serialVersionUID = 3750761687807284636L; 35 | 36 | private String ref; 37 | private String before; 38 | private String after; 39 | private String base_ref; 40 | private String compare; 41 | private List commits; 42 | private Commit head_commit; 43 | private PersonIdent pusher; 44 | 45 | @Override 46 | public String action() { 47 | return "push"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/oauth/CodingAccessTokenProperty.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011 Michael O'Cleirigh 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | package net.coding.jenkins.plugin.oauth; 25 | 26 | import hudson.Extension; 27 | import hudson.model.User; 28 | import hudson.model.UserProperty; 29 | import hudson.model.UserPropertyDescriptor; 30 | import hudson.util.Secret; 31 | import org.jenkinsci.Symbol; 32 | 33 | import javax.annotation.Nonnull; 34 | 35 | /** 36 | * Remembers the access token used to connect to the Coding server 37 | * 38 | * @since TODO 39 | */ 40 | public class CodingAccessTokenProperty extends UserProperty { 41 | private final Secret accessToken; 42 | 43 | public CodingAccessTokenProperty(String accessToken) { 44 | this.accessToken = Secret.fromString(accessToken); 45 | } 46 | 47 | public @Nonnull 48 | Secret getAccessToken() { 49 | return accessToken; 50 | } 51 | 52 | @Extension 53 | @Symbol("codingAccessToken") 54 | public static final class DescriptorImpl extends UserPropertyDescriptor { 55 | @Override 56 | public boolean isEnabled() { 57 | // does not show elements in //configure/ 58 | return false; 59 | } 60 | 61 | @Override 62 | public UserProperty newInstance(User user) { 63 | // no default property 64 | return null; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/oauth/CodingLogoutAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011 Michael O'Cleirigh 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | package net.coding.jenkins.plugin.oauth; 25 | 26 | import hudson.Extension; 27 | import hudson.model.UnprotectedRootAction; 28 | import hudson.security.SecurityRealm; 29 | import jenkins.model.Jenkins; 30 | import org.kohsuke.accmod.Restricted; 31 | import org.kohsuke.accmod.restrictions.NoExternalUse; 32 | 33 | /** 34 | * A page that shows a simple message when the user logs out. 35 | * This prevents a logout -> login loop when using this security realm and Anonymous does not have {@code Overall.READ} permission. 36 | */ 37 | @Extension 38 | public class CodingLogoutAction implements UnprotectedRootAction { 39 | 40 | /** The URL of the action. */ 41 | static final String POST_LOGOUT_URL = "codingLogout"; 42 | 43 | @Override 44 | public String getDisplayName() { 45 | return "Coding Logout"; 46 | } 47 | 48 | @Override 49 | public String getIconFileName() { 50 | // hide it 51 | return null; 52 | } 53 | 54 | @Override 55 | public String getUrlName() { 56 | return POST_LOGOUT_URL; 57 | } 58 | 59 | @Restricted(NoExternalUse.class) // jelly only 60 | public String getCodingURL() { 61 | Jenkins j = Jenkins.getInstance(); 62 | assert j != null; 63 | SecurityRealm r = j.getSecurityRealm(); 64 | if (r instanceof CodingSecurityRealm) { 65 | CodingSecurityRealm ghsr = (CodingSecurityRealm) r; 66 | return ghsr.getCodingWebUri(); 67 | } 68 | // only called from the Jelly if the CodingSecurityRealm is set... 69 | return ""; 70 | } 71 | 72 | @Restricted(NoExternalUse.class) // jelly only 73 | public String getCodingText() { 74 | Jenkins j = Jenkins.getInstance(); 75 | assert j != null; 76 | SecurityRealm r = j.getSecurityRealm(); 77 | if (r instanceof CodingSecurityRealm) { 78 | CodingSecurityRealm ghsr = (CodingSecurityRealm) r; 79 | return (ghsr.getDescriptor().getDefaultCodingWebUri().equals(ghsr.getCodingWebUri()))? "Coding" : "Coding Enterprise"; 80 | } 81 | // only called from the Jelly if the CodingSecurityRealm is set... 82 | return ""; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/oauth/CodingOAuthGroupDetails.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011 Michael O'Cleirigh 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | package net.coding.jenkins.plugin.oauth; 25 | 26 | import hudson.security.GroupDetails; 27 | import net.coding.api.CodingOrganization; 28 | import net.coding.api.CodingTeam; 29 | 30 | /** 31 | * @author Mike 32 | * 33 | */ 34 | public class CodingOAuthGroupDetails extends GroupDetails { 35 | 36 | private final CodingOrganization org; 37 | private final CodingTeam team; 38 | static final String ORG_TEAM_SEPARATOR = "*"; 39 | 40 | /** 41 | * Group based on organization name 42 | * @param org the coding organization 43 | */ 44 | public CodingOAuthGroupDetails(CodingOrganization org) { 45 | super(); 46 | this.org = org; 47 | this.team = null; 48 | } 49 | 50 | /** 51 | * Group based on team name 52 | * @param team the coding team 53 | */ 54 | public CodingOAuthGroupDetails(CodingTeam team) { 55 | super(); 56 | this.org = team.getOrganization(); 57 | this.team = team; 58 | } 59 | 60 | /* (non-Javadoc) 61 | * @see hudson.security.GroupDetails#getName() 62 | */ 63 | @Override 64 | public String getName() { 65 | if (team != null) 66 | return org.getLogin() + ORG_TEAM_SEPARATOR + team.getName(); 67 | if (org != null) 68 | return org.getLogin(); 69 | return null; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/oauth/CodingOAuthScope.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011 Michael O'Cleirigh 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | 25 | package net.coding.jenkins.plugin.oauth; 26 | 27 | import hudson.ExtensionPoint; 28 | 29 | import java.util.Collection; 30 | 31 | /** 32 | * Extension point to be implemented by plugins to request additional scopes. 33 | * @author Kohsuke Kawaguchi 34 | */ 35 | public abstract class CodingOAuthScope implements ExtensionPoint { 36 | /** 37 | * Returns a collection of scopes to request. 38 | * See https://open.coding.net/references/personal-access-token/#%E8%AE%BF%E9%97%AE%E4%BB%A4%E7%89%8C%E7%9A%84%E6%9D%83%E9%99%90 39 | */ 40 | public abstract Collection getScopesToRequest(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/oauth/CodingOAuthUserDetails.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011 Michael O'Cleirigh 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | package net.coding.jenkins.plugin.oauth; 25 | 26 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 27 | import net.coding.api.CodingUser; 28 | import org.acegisecurity.GrantedAuthority; 29 | import org.acegisecurity.userdetails.User; 30 | import org.acegisecurity.userdetails.UserDetails; 31 | 32 | import javax.annotation.Nonnull; 33 | import java.io.IOException; 34 | 35 | /** 36 | * @author Mike 37 | * 38 | */ 39 | @SuppressFBWarnings("EQ_DOESNT_OVERRIDE_EQUALS") 40 | public class CodingOAuthUserDetails extends User implements UserDetails { 41 | 42 | private static final long serialVersionUID = 1L; 43 | 44 | private boolean hasGrantedAuthorities; 45 | 46 | private final CodingAuthenticationToken authenticationToken; 47 | 48 | public CodingOAuthUserDetails(@Nonnull String login, @Nonnull GrantedAuthority[] authorities) { 49 | super(login, "", true, true, true, true, authorities); 50 | this.authenticationToken = null; 51 | this.hasGrantedAuthorities = true; 52 | } 53 | 54 | public CodingOAuthUserDetails(@Nonnull String login, @Nonnull CodingAuthenticationToken authenticationToken) { 55 | super(login, "", true, true, true, true, new GrantedAuthority[0]); 56 | this.authenticationToken = authenticationToken; 57 | this.hasGrantedAuthorities = false; 58 | } 59 | 60 | @Override 61 | public GrantedAuthority[] getAuthorities() { 62 | if (!hasGrantedAuthorities) { 63 | try { 64 | CodingUser user = authenticationToken.loadUser(getUsername()); 65 | if(user != null) { 66 | setAuthorities(authenticationToken.getAuthorities()); 67 | } 68 | } catch (IOException e) { 69 | throw new RuntimeException(e); 70 | } 71 | } 72 | return super.getAuthorities(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/oauth/CodingRepositoryName.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011 Michael O'Cleirigh 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | package net.coding.jenkins.plugin.oauth; 25 | 26 | import java.util.logging.Level; 27 | import java.util.logging.Logger; 28 | import java.util.regex.Matcher; 29 | import java.util.regex.Pattern; 30 | 31 | /** 32 | * Uniquely identifies a repository on Coding. 33 | * 34 | * This is a simplified version of the file 35 | * https://github.com/jenkinsci/github-plugin/blob/master/src/main/java/com/cloudbees/jenkins/GitHubRepositoryName.java 36 | * 37 | * It has been duplicated to avoid introducing a dependency on "coding-plugin" 38 | * 39 | * @author Kohsuke Kawaguchi 40 | */ 41 | public class CodingRepositoryName { 42 | 43 | private static final Pattern[] URL_PATTERNS = { 44 | /** 45 | * The first set of patterns extract the host, owner and repository names 46 | * from URLs that include a '.git' suffix, removing the suffix from the 47 | * repository name. 48 | */ 49 | Pattern.compile("git@(.+):([^/]+)/([^/]+)\\.git"), 50 | Pattern.compile("https?://[^/]+@([^/]+)/([^/]+)/([^/]+)\\.git"), 51 | Pattern.compile("https?://([^/]+)/([^/]+)/([^/]+)\\.git"), 52 | Pattern.compile("git://([^/]+)/([^/]+)/([^/]+)\\.git"), 53 | Pattern.compile("ssh://git@([^/]+)/([^/]+)/([^/]+)\\.git"), 54 | /** 55 | * The second set of patterns extract the host, owner and repository names 56 | * from all other URLs. Note that these patterns must be processed *after* 57 | * the first set, to avoid any '.git' suffix that may be present being included 58 | * in the repository name. 59 | */ 60 | Pattern.compile("git@(.+):([^/]+)/([^/]+)/?"), 61 | Pattern.compile("https?://[^/]+@([^/]+)/([^/]+)/([^/]+)/?"), 62 | Pattern.compile("https?://([^/]+)/([^/]+)/([^/]+)/?"), 63 | Pattern.compile("git://([^/]+)/([^/]+)/([^/]+)/?"), 64 | Pattern.compile("ssh://git@([^/]+)/([^/]+)/([^/]+)/?") 65 | }; 66 | 67 | /** 68 | * Create {@link CodingRepositoryName} from URL 69 | * 70 | * @param url 71 | * must be non-null 72 | * @return parsed {@link CodingRepositoryName} or null if it cannot be 73 | * parsed from the specified URL 74 | */ 75 | public static CodingRepositoryName create(final String url) { 76 | LOGGER.log(Level.FINE, "Constructing from URL {0}", url); 77 | for (Pattern p : URL_PATTERNS) { 78 | Matcher m = p.matcher(url.trim()); 79 | if (m.matches()) { 80 | LOGGER.log(Level.FINE, "URL matches {0}", m); 81 | CodingRepositoryName ret = new CodingRepositoryName(m.group(1), m.group(2), 82 | m.group(3)); 83 | LOGGER.log(Level.FINE, "Object is {0}", ret); 84 | return ret; 85 | } 86 | } 87 | LOGGER.log(Level.WARNING, "Could not match URL {0}", url); 88 | return null; 89 | } 90 | 91 | public final String host, userName, repositoryName; 92 | 93 | public CodingRepositoryName(String host, String userName, String repositoryName) { 94 | this.host = host; 95 | this.userName = userName; 96 | this.repositoryName = repositoryName; 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return "CodingRepository[host="+host+",username="+userName+",repository="+repositoryName+"]"; 102 | } 103 | 104 | private static final Logger LOGGER = Logger.getLogger(CodingRepositoryName.class.getName()); 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/oauth/CodingSecretStorage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011 Michael O'Cleirigh 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | package net.coding.jenkins.plugin.oauth; 25 | 26 | import hudson.model.User; 27 | import org.jfree.util.Log; 28 | 29 | import javax.annotation.CheckForNull; 30 | import javax.annotation.Nonnull; 31 | import java.io.IOException; 32 | 33 | public class CodingSecretStorage { 34 | 35 | private CodingSecretStorage(){ 36 | // no accessible constructor 37 | } 38 | 39 | public static boolean contains(@Nonnull User user) { 40 | return user.getProperty(CodingAccessTokenProperty.class) != null; 41 | } 42 | 43 | public static @CheckForNull String retrieve(@Nonnull User user) { 44 | CodingAccessTokenProperty property = user.getProperty(CodingAccessTokenProperty.class); 45 | if (property == null) { 46 | Log.debug("Cache miss for username: " + user.getId()); 47 | return null; 48 | } else { 49 | Log.debug("Token retrieved using cache for username: " + user.getId()); 50 | return property.getAccessToken().getPlainText(); 51 | } 52 | } 53 | 54 | public static void put(@Nonnull User user, @Nonnull String accessToken) { 55 | Log.debug("Populating the cache for username: " + user.getId()); 56 | try { 57 | user.addProperty(new CodingAccessTokenProperty(accessToken)); 58 | } catch (IOException e) { 59 | Log.warn("Received an exception when trying to add the Coding access token to the user: " + user.getId(), e); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/oauth/CodingUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011 Michael O'Cleirigh 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | package net.coding.jenkins.plugin.oauth; 25 | 26 | public class CodingUtil { 27 | public static String fixEndwithSlash(String uri) { 28 | if (uri == null || uri.length() == 0) { 29 | return ""; 30 | } 31 | if (uri.endsWith("/")) { 32 | return uri.substring(0, uri.length() - 1); 33 | } 34 | return uri; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/v1/model/Commit.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.v1.model; 21 | 22 | import lombok.Data; 23 | 24 | /** 25 | * @author tsl0922 26 | */ 27 | @Data 28 | public class Commit { 29 | private Committer committer; 30 | private String web_url; 31 | private String short_message; 32 | private String sha; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/v1/model/Committer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.v1.model; 21 | 22 | import lombok.Data; 23 | 24 | /** 25 | * @author tsl0922 26 | */ 27 | @Data 28 | public class Committer { 29 | private String name; 30 | private String email; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/v1/model/MergeRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.v1.model; 21 | 22 | import lombok.Data; 23 | 24 | /** 25 | * @author tsl0922 26 | */ 27 | @Data 28 | public class MergeRequest { 29 | private Integer id; 30 | private String title; 31 | private String body; 32 | private String merge_commit_sha; 33 | private String status; 34 | private String action; 35 | private Integer number; 36 | private String target_branch; 37 | private String source_branch; 38 | private String web_url; 39 | private User user; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/v1/model/PullRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.v1.model; 21 | 22 | import lombok.Data; 23 | import lombok.EqualsAndHashCode; 24 | 25 | /** 26 | * @author tsl0922 27 | */ 28 | @EqualsAndHashCode(callSuper = true) 29 | @Data 30 | public class PullRequest extends MergeRequest { 31 | private Repository source_repository; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/v1/model/Repository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.v1.model; 21 | 22 | import java.net.URI; 23 | import java.util.regex.Matcher; 24 | import java.util.regex.Pattern; 25 | 26 | import lombok.Data; 27 | 28 | /** 29 | * @author tsl0922 30 | */ 31 | @Data 32 | public class Repository { 33 | private String project_id; 34 | private String ssh_url; 35 | private String https_url; 36 | private String git_url; 37 | private String name; 38 | private String description; 39 | private String web_url; 40 | private User owner; 41 | 42 | public String projectPath() { 43 | Pattern pattern = Pattern.compile("https?://[^/]+/[ut]/([^/]+)/p/([^/]+).*"); 44 | Matcher matcher = pattern.matcher(web_url); 45 | if (matcher.matches()) { 46 | // is professional 47 | return String.format("%s/%s", matcher.group(1), matcher.group(2)); 48 | } 49 | pattern = Pattern.compile("https?://([^./]+)\\.[^/]+/p/([^/]+).*"); 50 | matcher = pattern.matcher(web_url); 51 | if (matcher.matches()) { 52 | // is enterprise 53 | return String.format("%s/%s", matcher.group(1), matcher.group(2)); 54 | } 55 | return ""; 56 | } 57 | 58 | public String projectApiUrl() { 59 | Pattern pattern = Pattern.compile("(https?://[^/]+)/[ut]/([^/]+)/p/([^/]+).*"); 60 | Matcher matcher = pattern.matcher(web_url); 61 | if (matcher.matches()) { 62 | // is professional 63 | return String.format("%s/api/user/%s/project/%s", matcher.group(1), matcher.group(2), matcher.group(3)); 64 | } 65 | pattern = Pattern.compile("(https?://[^/]+)/p/([^/]+).*"); 66 | matcher = pattern.matcher(web_url); 67 | if (matcher.matches()) { 68 | // is enterprise 69 | String host = matcher.group(1); 70 | String projectName = matcher.group(2); 71 | try { 72 | String path = new URI(https_url).getPath(); 73 | path = path.substring(1).replace(".git", ""); 74 | String teamName = path.split("/")[0]; 75 | return String.format("%s/api/user/%s/project/%s", host, teamName, projectName); 76 | } catch (Exception ignored) { 77 | // Fallback 78 | Matcher enterprise = Pattern.compile("https?://([^.]+).*").matcher(host); 79 | if (enterprise.matches()) { 80 | return String.format("%s/api/user/%s/project/%s", host, enterprise.group(1), projectName); 81 | } 82 | } 83 | } 84 | return ""; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/v1/model/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.v1.model; 21 | 22 | import lombok.Data; 23 | 24 | /** 25 | * @author tsl0922 26 | */ 27 | @Data 28 | public class User { 29 | private String name; 30 | private String global_key; 31 | private String path; 32 | private String avatar; 33 | private String web_url; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/v1/model/WebHook.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.v1.model; 21 | 22 | import java.util.List; 23 | 24 | import lombok.Data; 25 | 26 | /** 27 | * @author tsl0922 28 | */ 29 | @Data 30 | public class WebHook { 31 | private String ref; 32 | private List commits; 33 | private String before; 34 | private String after; 35 | private Repository repository; 36 | private String event; 37 | private String token; 38 | private MergeRequest merge_request; 39 | private PullRequest pull_request; 40 | private User user; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/IWebHookHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.webhook; 21 | 22 | import net.coding.jenkins.plugin.bean.WebHookTask; 23 | 24 | import javax.servlet.http.HttpServletRequest; 25 | 26 | public interface IWebHookHelper { 27 | 28 | WebHookTask parseTaskFromRequest(final HttpServletRequest request); 29 | 30 | boolean isSignatureValid(WebHookTask task, String webHookToken); 31 | 32 | String parseEventHeader(String eventHeader); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/WebHookEnvironmentContributor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.webhook; 21 | 22 | import net.coding.jenkins.plugin.cause.CauseData; 23 | import net.coding.jenkins.plugin.cause.CodingWebHookCause; 24 | 25 | import java.io.IOException; 26 | 27 | import javax.annotation.Nonnull; 28 | 29 | import hudson.EnvVars; 30 | import hudson.Extension; 31 | import hudson.model.EnvironmentContributor; 32 | import hudson.model.Run; 33 | import hudson.model.TaskListener; 34 | 35 | /** 36 | * @author tsl0922 37 | */ 38 | @Extension 39 | public class WebHookEnvironmentContributor extends EnvironmentContributor { 40 | private static final String WEBHOOK_USER = "WEBHOOK_USER"; 41 | private static final String WEBHOOK_USER_URL = "WEBHOOK_USER_URL"; 42 | private static final String WEBHOOK_REPO_URL = "WEBHOOK_REPO_URL"; 43 | private static final String WEBHOOK_COMMIT = "WEBHOOK_COMMIT"; 44 | 45 | private static final String WEBHOOK_PUSH_REF = "WEBHOOK_PUSH_REF"; 46 | private static final String WEBHOOK_PUSH_BEFORE = "WEBHOOK_PUSH_BEFORE"; 47 | private static final String WEBHOOK_PUSH_AFTER = "WEBHOOK_PUSH_AFTER"; 48 | 49 | private static final String WEBHOOK_MR_ID = "WEBHOOK_MR_ID"; 50 | private static final String WEBHOOK_MR_IID = "WEBHOOK_MR_IID"; 51 | private static final String WEBHOOK_MR_URL = "WEBHOOK_MR_URL"; 52 | private static final String WEBHOOK_MR_TITLE = "WEBHOOK_MR_TITLE"; 53 | private static final String WEBHOOK_MR_SOURCE_REPO_URL = "WEBHOOK_MR_SOURCE_REPO_URL"; 54 | private static final String WEBHOOK_MR_SOURCE_BRANCH = "WEBHOOK_MR_SOURCE_BRANCH"; 55 | private static final String WEBHOOK_MR_TARGET_BRANCH = "WEBHOOK_MR_TARGET_BRANCH"; 56 | 57 | @Override 58 | public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException { 59 | CodingWebHookCause cause = (CodingWebHookCause) r.getCause(CodingWebHookCause.class); 60 | if (cause == null) { 61 | return; 62 | } 63 | 64 | CauseData data = cause.getData(); 65 | 66 | envs.putIfNotNull(WEBHOOK_USER, data.getUserGK()); 67 | envs.putIfNotNull(WEBHOOK_USER_URL, data.getUserUrl()); 68 | envs.putIfNotNull(WEBHOOK_REPO_URL, data.getRepoUrl()); 69 | envs.putIfNotNull(WEBHOOK_COMMIT, data.getCommitId()); 70 | 71 | switch (data.getActionType()) { 72 | case PUSH: 73 | envs.putIfNotNull(WEBHOOK_PUSH_REF, data.getRef()); 74 | envs.putIfNotNull(WEBHOOK_PUSH_BEFORE, data.getBefore()); 75 | envs.putIfNotNull(WEBHOOK_PUSH_AFTER, data.getAfter()); 76 | break; 77 | case MR: 78 | case PR: 79 | envs.putIfNotNull(WEBHOOK_MR_ID, String.valueOf(data.getMergeRequestId())); 80 | envs.putIfNotNull(WEBHOOK_MR_IID, String.valueOf(data.getMergeRequestIid())); 81 | envs.putIfNotNull(WEBHOOK_MR_URL, data.getMergeRequestUrl()); 82 | envs.putIfNotNull(WEBHOOK_MR_TITLE, data.getMergeRequestTitle()); 83 | envs.putIfNotNull(WEBHOOK_MR_SOURCE_BRANCH, data.getSourceBranch()); 84 | envs.putIfNotNull(WEBHOOK_MR_TARGET_BRANCH, data.getTargetBranch()); 85 | if (data.getActionType() == CauseData.ActionType.PR) { 86 | envs.putIfNotNull(WEBHOOK_MR_SOURCE_REPO_URL, data.getSourceProjectPath()); 87 | } 88 | break; 89 | default:break; 90 | } 91 | 92 | super.buildEnvironmentFor(r, envs, listener); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/WebHookHelperV2.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.webhook; 21 | 22 | import net.coding.jenkins.plugin.Utils; 23 | import net.coding.jenkins.plugin.bean.WebHookTask; 24 | import net.coding.jenkins.plugin.common.gson.JSON; 25 | import net.coding.jenkins.plugin.model.event.MergeRequest; 26 | import net.coding.jenkins.plugin.model.event.Push; 27 | import org.apache.commons.codec.digest.HmacUtils; 28 | import org.apache.commons.lang.StringUtils; 29 | 30 | import javax.servlet.http.HttpServletRequest; 31 | import java.text.MessageFormat; 32 | import java.util.logging.Level; 33 | import java.util.logging.Logger; 34 | 35 | public class WebHookHelperV2 implements IWebHookHelper { 36 | public static final String version = "v2"; 37 | 38 | private static Logger LOGGER = Logger.getLogger(WebHookHelperV2.class.getName()); 39 | 40 | @Override 41 | public WebHookTask parseTaskFromRequest(HttpServletRequest request) { 42 | WebHookTask task = new WebHookTask(); 43 | task.setVersion(version); 44 | String json = Utils.getRequestBody(request); 45 | LOGGER.log(Level.INFO, "WebHook payload: {0}", json); 46 | task.setRequestBody(json); 47 | String action = request.getHeader("X-Coding-Event"); 48 | task.setEvent(action); 49 | switch (action) { 50 | case WebHookTask.EVENT_PUSH: 51 | Push push = JSON.fromJson(json, Push.class); 52 | task.setPush(push); 53 | task.setParseSuccess(true); 54 | break; 55 | case WebHookTask.EVENT_MERGE_REQUEST: 56 | MergeRequest mr = JSON.fromJson(json, MergeRequest.class); 57 | task.setMergeRequest(mr); 58 | task.setParseSuccess(true); 59 | break; 60 | default: 61 | break; 62 | } 63 | if (task.isParseSuccess()) { 64 | String signature = request.getHeader("X-Coding-Signature"); 65 | task.setSignature(signature); 66 | } 67 | return task; 68 | } 69 | 70 | @Override 71 | public boolean isSignatureValid(WebHookTask task, String webHookToken) { 72 | if (StringUtils.isEmpty(webHookToken)) { 73 | return true; 74 | } 75 | String signature = HmacUtils.hmacSha1Hex(webHookToken, task.getRequestBody()); 76 | String gotSignature = task.getSignature(); 77 | if (StringUtils.isEmpty(gotSignature)) { 78 | LOGGER.log(Level.FINE, "Got Empty signature"); 79 | return false; 80 | } 81 | if (!StringUtils.startsWith(gotSignature, "sha1=")) { 82 | LOGGER.log(Level.FINE, 83 | MessageFormat.format("Invalid signature, should start with while sha1=, got {0}", gotSignature)); 84 | return false; 85 | } 86 | boolean valid = StringUtils.equals("sha1=" + signature, gotSignature); 87 | if (!valid) { 88 | LOGGER.log(Level.FINE, 89 | MessageFormat.format("Invalid signature, should be {0}, while got {1}", signature, gotSignature)); 90 | } 91 | return valid; 92 | } 93 | 94 | @Override 95 | public String parseEventHeader(String eventHeader) { 96 | if ("merge request".equals(eventHeader)) { 97 | return "merge_request"; 98 | } 99 | return eventHeader; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/filter/AllBranchesFilter.java: -------------------------------------------------------------------------------- 1 | package net.coding.jenkins.plugin.webhook.filter; 2 | 3 | /** 4 | * @author Robin Müller 5 | */ 6 | class AllBranchesFilter implements BranchFilter { 7 | @Override 8 | public boolean isBranchAllowed(String branchName) { 9 | return true; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/filter/BranchFilter.java: -------------------------------------------------------------------------------- 1 | package net.coding.jenkins.plugin.webhook.filter; 2 | 3 | /** 4 | * @author Robin Müller 5 | */ 6 | public interface BranchFilter { 7 | 8 | boolean isBranchAllowed(String branchName); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/filter/BranchFilterConfig.java: -------------------------------------------------------------------------------- 1 | package net.coding.jenkins.plugin.webhook.filter; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | /** 7 | * @author Robin Müller 8 | */ 9 | @Data 10 | @AllArgsConstructor 11 | public class BranchFilterConfig { 12 | private BranchFilterType type; 13 | private String includeBranchesSpec; 14 | private String excludeBranchesSpec; 15 | private String targetBranchRegex; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/filter/BranchFilterFactory.java: -------------------------------------------------------------------------------- 1 | package net.coding.jenkins.plugin.webhook.filter; 2 | 3 | /** 4 | * @author Robin Müller 5 | */ 6 | public final class BranchFilterFactory { 7 | 8 | private BranchFilterFactory() { } 9 | 10 | public static BranchFilter newBranchFilter(BranchFilterConfig config) { 11 | switch (config.getType()) { 12 | case NameBasedFilter: 13 | return new NameBasedFilter(config.getIncludeBranchesSpec(), config.getExcludeBranchesSpec()); 14 | case RegexBasedFilter: 15 | return new RegexBasedFilter(config.getTargetBranchRegex()); 16 | default: 17 | return new AllBranchesFilter(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/filter/BranchFilterType.java: -------------------------------------------------------------------------------- 1 | package net.coding.jenkins.plugin.webhook.filter; 2 | 3 | /** 4 | * @author Robin Müller 5 | */ 6 | public enum BranchFilterType { 7 | All, 8 | NameBasedFilter, 9 | RegexBasedFilter 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/filter/NameBasedFilter.java: -------------------------------------------------------------------------------- 1 | package net.coding.jenkins.plugin.webhook.filter; 2 | 3 | import com.google.common.base.Splitter; 4 | 5 | import org.springframework.util.AntPathMatcher; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * @author Robin Müller 12 | */ 13 | class NameBasedFilter implements BranchFilter { 14 | 15 | private final List includedBranches; 16 | private final List excludedBranches; 17 | 18 | public NameBasedFilter(String includedBranches, String excludedBranches) { 19 | this.includedBranches = convert(includedBranches); 20 | this.excludedBranches = convert(excludedBranches); 21 | } 22 | 23 | @Override 24 | public boolean isBranchAllowed(String branchName) { 25 | return hasNoBranchSpecs() || (isBranchNotExcluded(branchName) && isBranchIncluded(branchName)); 26 | } 27 | 28 | private boolean hasNoBranchSpecs() { 29 | return includedBranches.isEmpty() && excludedBranches.isEmpty(); 30 | } 31 | 32 | private boolean isBranchNotExcluded(String branchName) { 33 | AntPathMatcher matcher = new AntPathMatcher(); 34 | for (String excludePattern : excludedBranches) { 35 | if (matcher.match(excludePattern, branchName)) { 36 | return false; 37 | } 38 | } 39 | return true; 40 | } 41 | 42 | private boolean isBranchIncluded(String branchName) { 43 | AntPathMatcher matcher = new AntPathMatcher(); 44 | for (String includePattern : includedBranches) { 45 | if (matcher.match(includePattern, branchName)) { 46 | return true; 47 | } 48 | } 49 | return includedBranches.isEmpty(); 50 | } 51 | 52 | private List convert(String commaSeparatedString) { 53 | ArrayList result = new ArrayList<>(); 54 | for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(commaSeparatedString)) { 55 | result.add(s); 56 | } 57 | return result; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/net/coding/jenkins/plugin/webhook/filter/RegexBasedFilter.java: -------------------------------------------------------------------------------- 1 | package net.coding.jenkins.plugin.webhook.filter; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | 5 | /** 6 | * @author Robin Müller 7 | */ 8 | class RegexBasedFilter implements BranchFilter { 9 | 10 | private final String regex; 11 | 12 | public RegexBasedFilter(String regex) { 13 | this.regex = regex; 14 | } 15 | 16 | @Override 17 | public boolean isBranchAllowed(String branchName) { 18 | return StringUtils.isEmpty(branchName) || StringUtils.isEmpty(regex) || branchName.matches(regex); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 |

3 | This plugin integrates 4 | Coding 5 | with Jenkins. 6 |
7 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/CodingPushTrigger/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 | 37 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 |
61 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/CodingPushTrigger/config.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.webhook.token=WebHook token 22 | coding.webhook.token.hint=Optional, Used to verify WebHook request 23 | coding.webhook.apitoken=(Deprecated) Private access token 24 | coding.webhook.apitoken.hint=Required for publishing result comment 25 | coding.webhook.api.personal.token=Personal access token 26 | coding.webhook.api.personal.token.hint=Required for publishing result comment 27 | coding.webhook.build.on.mrpr=Build on Merge Request Events 28 | coding.webhook.build.on.mrpr.action=Actions 29 | coding.webhook.build.on.mrpr.action.hint=Separated by comma, default: create,synchronize 30 | coding.webhook.build.on.push=Build on Push Events 31 | coding.webhook.build.note=Report build result via comment 32 | coding.webhook.build.ciskip=Enable [ci-skip] 33 | coding.webhook.build.branch.all=Allow all branches to trigger this job 34 | coding.webhook.build.branch.filter.name=Filter branches by name 35 | coding.webhook.build.branch.filter.include=Include 36 | coding.webhook.build.branch.filter.exclude=Exclude 37 | coding.webhook.build.branch.filter.regex=Filter branches by regex 38 | coding.webhook.build.branch.filter.regex.value=Target Branch Regex 39 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/CodingPushTrigger/config_zh_CN.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.webhook.token=WebHook \u4EE4\u724C 22 | coding.webhook.token.hint=\u53EF\u9009\uFF0C\u7528\u4E8E\u9A8C\u8BC1 WebHook \u8BF7\u6C42 23 | coding.webhook.apitoken=\uFF08\u5E9F\u5F03\uFF09\u8BBF\u95EE\u4EE4\u724C 24 | coding.webhook.apitoken.hint=\u5FC5\u987B\u4E3A\u53D1\u5E03\u8BC4\u8BBA\u586B\u5199\u6B64\u9009\u9879 25 | coding.webhook.api.personal.token=\u8BBF\u95EE\u4EE4\u724C 26 | coding.webhook.api.personal.token.hint=\u5FC5\u987B\u4E3A\u53D1\u5E03\u8BC4\u8BBA\u586B\u5199\u6B64\u9009\u9879 27 | coding.webhook.build.on.mrpr=\u6536\u5230 Merge/Pull Request \u4E8B\u4EF6\u65F6\u89E6\u53D1\u6784\u5EFA 28 | coding.webhook.build.on.mrpr.action=\u52A8\u4F5C (action) 29 | coding.webhook.build.on.mrpr.action.hint=\u4EE5\u9017\u53F7\uFF08,\uFF09\u5206\u9694\uFF0C\u9ED8\u8BA4\u503C\uFF1Acreate,synchronize 30 | coding.webhook.build.on.push=\u6536\u5230\u4EE3\u7801\u63A8\u9001\u4E8B\u4EF6\u65F6\u89E6\u53D1\u6784\u5EFA 31 | coding.webhook.build.note=\u4EE5\u8BC4\u8BBA\u7684\u5F62\u5F0F\u53CD\u9988\u6784\u5EFA\u7ED3\u679C 32 | coding.webhook.build.ciskip=\u5F00\u542F [ci-skip] \u652F\u6301 33 | coding.webhook.build.branch.all=\u5141\u8BB8\u6240\u6709\u5206\u652F\u89E6\u53D1\u6B64\u4EFB\u52A1 34 | coding.webhook.build.branch.filter.name=\u6309\u540D\u79F0\u8FC7\u6EE4\u53EF\u4EE5\u89E6\u53D1\u6B64\u4EFB\u52A1\u7684\u5206\u652F 35 | coding.webhook.build.branch.filter.include=\u5305\u62EC 36 | coding.webhook.build.branch.filter.exclude=\u6392\u9664 37 | coding.webhook.build.branch.filter.regex=\u6309\u6B63\u5219\u8FC7\u6EE4\u53EF\u4EE5\u89E6\u53D1\u6B64\u4EFB\u52A1\u7684\u5206\u652F 38 | coding.webhook.build.branch.filter.regex.value=\u76EE\u6807\u5206\u652F\u540D\u6B63\u5219\u8868\u8FBE\u5F0F 39 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/CodingPushTrigger/help.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | ${%coding.trigger.help} 4 | 5 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/CodingPushTrigger/help.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.trigger.help=\ 22 |
\ 23 |

\ 24 | Configure your Jenkins instance to handle \ 25 | WebHook \ 26 | request sent by Coding and triggers \ 27 | builds for pushes and merge/pull requests.\ 28 |

\ 29 | To getting started, you need to create an WebHook on Coding using the WebHook URL \ 30 | shown by this option, and fill the WebHook token field with the token value used \ 31 | when creating the WebHook.\ 32 |
33 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/CodingPushTrigger/help_zh_CN.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.trigger.help=\ 22 |
\ 23 |

\ 24 | \u4E3A Jenkins \u5B9E\u4F8B\u6DFB\u52A0\u5904\u7406 Coding \ 25 | \u53D1\u9001\u8FC7\u6765\u7684 WebHook \ 26 | \u8BF7\u6C42\u652F\u6301, \u5E76\u5728\u6536\u5230\u4EE3\u7801\u63A8\u9001\u548C Merge/Pull request \u65F6\u89E6\u53D1\u6784\u5EFA\u3002\ 27 |

\ 28 | \u8981\u4F7F\u7528\u6B64\u529F\u80FD, \u5FC5\u987B\u4F7F\u7528\u6B64\u9009\u9879\u7ED3\u5C3E\u663E\u793A\u7684 WebHook \u5730\u5740 \u5148\u5728 Coding \u4E0A\u521B\u5EFA\u4E00\u4E2A WebHook, \ 29 | \u5E76\u628A\u521B\u5EFA WebHook \u65F6\u586B\u5199\u7684\u4EE4\u724C\u503C\u914D\u7F6E\u5230\u4E0B\u9762\u7684 WebHook \u4EE4\u724C \u914D\u7F6E\u91CC\u3002\ 30 |
31 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/Messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.trigger.title=Build when a change is pushed to Coding, WebHook URL: {0} 22 | coding.trigger.title.unknown=Build when a change is pushed to Coding, unknown URL(this should not happen) 23 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/Messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.trigger.title=\u6536\u5230 Coding \u53D1\u9001\u8FC7\u6765\u7684\u8BF7\u6C42\u65F6\u89E6\u53D1\u6784\u5EFA, WebHook \u5730\u5740: {0} 22 | coding.trigger.title.unknown=\u6536\u5230 Coding \u53D1\u9001\u8FC7\u6765\u7684\u8BF7\u6C42\u65F6\u89E6\u53D1\u6784\u5EFA, \u65E0\u6CD5\u89E3\u6790\u5730\u5740(\u8FD9\u4E0D\u5E94\u8BE5\u53D1\u751F) 23 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/cause/Messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.action.push=Started by Coding push 22 | coding.action.push.by="Started by Coding push by %s" 23 | coding.action.merge.request="Started by %s's Merge Request #%d: %s(%s => %s) at Coding" 24 | coding.action.pull.request="Started by %s's Pull Request #%d: %s(%s:%s => %s) at Coding" 25 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/cause/Messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.action.push=\u7531 Coding \u4EE3\u7801\u63A8\u9001\u89E6\u53D1 22 | coding.action.push.by="\u7531 %s \u5728 Coding \u7684\u4EE3\u7801\u63A8\u9001\u89E6\u53D1" 23 | coding.action.merge.request="\u7531 %s \u5728 Coding \u7684 Merge Request #%d: %s(%s => %s) \u89E6\u53D1" 24 | coding.action.pull.request="\u7531 %s \u5728 Coding \u7684 Pull Request #%d: %s(%s:%s => %s) \u89E6\u53D1" 25 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/CodingAuthorizationStrategy/config.jelly: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/CodingAuthorizationStrategy/config.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.oauth.authorization.codingAuthorizationSettings=Coding Authorization Settings 22 | coding.oauth.authorization.adminUserNames=Admin User Names 23 | coding.oauth.authorization.organizationNames=Participant in Organization 24 | coding.oauth.authorization.useRepositoryPermissions=Use Coding repository permissions 25 | coding.oauth.authorization.authenticatedUserReadPermission=Grant READ permissions to all Authenticated Users 26 | coding.oauth.authorization.authenticatedUserCreateJobPermission=Grant CREATE Job permissions to all Authenticated Users 27 | coding.oauth.authorization.allowCodingWebHookPermission=Grant READ permissions for /coding-webhook 28 | coding.oauth.authorization.allowCcTrayPermission=Grant READ permissions for .*/cc.xml 29 | coding.oauth.authorization.allowAnonymousReadPermission=Grant READ permissions for Anonymous Users 30 | coding.oauth.authorization.allowAnonymousJobStatusPermission=Grant ViewStatus permissions for Anonymous Users 31 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/CodingAuthorizationStrategy/config_zh_CN.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.oauth.authorization.codingAuthorizationSettings=Coding \u6388\u6743\u8BBE\u7F6E 22 | coding.oauth.authorization.adminUserNames=\u7BA1\u7406\u5458\u7528\u6237\u540D\u5217\u8868 23 | coding.oauth.authorization.organizationNames=\u53C2\u4E0E\u7EC4\u7EC7 24 | coding.oauth.authorization.useRepositoryPermissions=\u4F7F\u7528 Coding \u4ED3\u5E93\u6743\u9650 25 | coding.oauth.authorization.authenticatedUserReadPermission=\u5BF9\u6240\u6709\u767B\u5F55\u7528\u6237\u6388\u4E88\u53EA\u8BFB\u6743\u9650 26 | coding.oauth.authorization.authenticatedUserCreateJobPermission=\u5BF9\u6240\u6709\u767B\u5F55\u7528\u6237\u6388\u4E88\u521B\u5EFA\u9879\u76EE\u6743\u9650 27 | coding.oauth.authorization.allowCodingWebHookPermission=\u5BF9 /coding-webhook \u6388\u6743 28 | coding.oauth.authorization.allowCcTrayPermission=\u5BF9 .*/cc.xml \u6388\u6743 29 | coding.oauth.authorization.allowAnonymousReadPermission=\u5BF9\u533F\u540D\u7528\u6237\u6388\u4E88\u53EA\u8BFB\u6743\u9650 30 | coding.oauth.authorization.allowAnonymousJobStatusPermission=\u5BF9\u533F\u540D\u7528\u6237\u6388\u4E88 ViewStatus \u6743\u9650 -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/CodingLogoutAction/index.jelly: -------------------------------------------------------------------------------- 1 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |

${%coding.oauth.logoutSucceed}${it.codingText}.

32 |

${%coding.oauth.niceDay}

33 |
34 | 35 |

${%coding.oauth.whoaThere}

36 |

${%coding.oauth.notLogoutYet}

37 |

${%coding.oauth.pressLogoutAgain}

38 |
39 |
40 |
41 |
42 |
43 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/CodingLogoutAction/index.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.oauth.logoutSucceed=You are now logged out of Jenkins. However, you have not been logged out of 22 | coding.oauth.niceDay=Have a nice day! 23 | coding.oauth.whoaThere=Whoa there... 24 | coding.oauth.notLogoutYet=You are not logged out - don't run away! 25 | coding.oauth.pressLogoutAgain=Whilst you should have been logged out, you are not actually logged out. Press the logout button to try logging out again. 26 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/CodingLogoutAction/index_zh_CN.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.oauth.logoutSucceed=\u4F60\u73B0\u5728\u5DF2\u7ECF\u9000\u51FA Jenkins \u4E86\u3002\u4F46\u662F\uFF0C\u60A8\u5C1A\u672A\u767B\u51FA 22 | coding.oauth.niceDay=\u795D\u60A8\u6709\u4E2A\u7F8E\u597D\u7684\u4E00\u5929\uFF01 23 | coding.oauth.whoaThere=\u54C7\u54E6\u2026 24 | coding.oauth.notLogoutYet=\u522B\u6025\u7740\u8D70\uFF01\u4F60\u5C1A\u672A\u767B\u51FA\u3002 25 | coding.oauth.pressLogoutAgain=\u5C1D\u8BD5\u767B\u51FA\u8D26\u53F7\uFF0C\u4F46\u5E76\u672A\u6210\u529F\u3002\u8BF7\u4F60\u6309\u4E0B\u767B\u51FA\u6309\u94AE\u518D\u6B21\u5C1D\u8BD5\u3002 26 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/CodingSecurityRealm/config.jelly: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/CodingSecurityRealm/config.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.oauth.globalOauthSetting=Global Coding OAuth Settings 22 | coding.oauth.codingWebUri=Coding Web URI 23 | coding.oauth.codingApiUri=Coding API URI 24 | coding.oauth.clientID=Client ID 25 | coding.oauth.clientSecret=Client Secret 26 | coding.oauth.oauthScopes=OAuth Scope(s) -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/CodingSecurityRealm/config_zh_CN.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.oauth.globalOauthSetting=\u5168\u5C40 Coding \u5B89\u5168\u8BBE\u7F6E 22 | coding.oauth.codingWebUri=Coding Web URI 23 | coding.oauth.codingApiUri=Coding API URI 24 | coding.oauth.clientID=Client ID 25 | coding.oauth.clientSecret=Client Secret 26 | coding.oauth.oauthScopes=OAuth \u6388\u6743\u8303\u56F4 -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/Messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.oauth.codingAuthenticationPlugin=Coding Authentication Plugin 22 | coding.oauth.codingAuthorizationStrategy=Coding Authorization Strategy 23 | -------------------------------------------------------------------------------- /src/main/resources/net/coding/jenkins/plugin/oauth/Messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Jenkins plugin for Coding https://coding.net 3 | # 4 | # Copyright (c) 2016-2018 Shuanglei Tao 5 | # Copyright (c) 2016-present, Coding, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | coding.oauth.codingAuthenticationPlugin=Coding \u5B89\u5168\u63D2\u4EF6 22 | coding.oauth.codingAuthorizationStrategy=Coding \u6388\u6743\u7B56\u7565 23 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-allowedBranches.html: -------------------------------------------------------------------------------- 1 |
2 | Comma-separated list of source branches allowed to trigger a build from a Push event or a Merge Request event. 3 | If both fields are left empty, all branches are allowed to trigger this job. 4 | For Merge Request events only the target branch name is filtered out by the include and exclude lists. 5 |
6 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-allowedBranches_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 设置哪些分支名可以触发构建任务, 分支名以逗号分隔, 此选项对 代码推送事件 和 3 | Merge/Pull Request 事件 均有效, 如果包括和排除的分支名选项都为空, 4 | 则所有分支都允许触发构建任务。对于 Merge/Pull Request, 事件, 分支名规则仅应用在目标分支上。 5 |
6 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-ci-skip.html: -------------------------------------------------------------------------------- 1 |
2 | Skip build if the commit message or merge/pull request title contains [ci-skip]. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-ci-skip_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 如果提交的信息或 merge/pull request 的标题里包含 [ci-skip], 则跳过构建。 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-filterBranchesByRegex.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | The target branch regex allows to limit the execution of this job to certain branches. Any 4 | branch matching the specified pattern triggers 5 | the job. No filtering is performed if the field is left empty. 6 |

Examples:

7 |
    8 |
  • Allow execution for debug and release branches: (.*debug.*|.*release.*)
  • 9 |
  • Ignore any branch with `Release` or `release` as subword: ^(?:(?![R|r]elease).)*$
  • 10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-filterBranchesByRegex_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 使用目标分支正则表达式可以限制哪些分支能够触发构建任务。所有匹配此正则的分支都可以触发构建任务, 如果此正则为空则所有分支都可以触发。 4 |

例子:

5 |
    6 |
  • 允许 debug 和 release 分支触发任务: (.*debug.*|.*release.*)
  • 7 |
  • 忽略所有名称里包含 Release 或 release 的分支: ^(?:(?![R|r]elease).)*$
  • 8 |
9 |
10 |
11 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-merge-request.html: -------------------------------------------------------------------------------- 1 |
2 |

Trigger builds on merge/pull request events.

3 | NOTE: This option requires additional git scm configuration for the job:
4 |
    5 |
  • 1. Goto job Configure page
  • 6 |
  • 2. Goto Source Code Management
  • 7 |
  • 8 | 3. Select Git, under Advanced, set Name to origin and: 9 |
      10 |
    • If the project is private, set refspec to 11 | +refs/heads/*:refs/remotes/origin/* +refs/merge/*/MERGE:refs/remotes/origin/merge/* 12 |
    • 13 |
    • If the project is public, set refspec to 14 | +refs/heads/*:refs/remotes/origin/* +refs/pull/*/MERGE:refs/remotes/origin/pull/* 15 |
    • 16 |
    17 |
  • 18 |
  • 4. Click Apply
  • 19 |
20 |
21 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-merge-request_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 |

收到 merge/pull request 事件时触发构建。

3 | 注意: 这个选项需要一些额外的配置才能工作:
4 |
    5 |
  • 1. 打开任务的 配置 页面
  • 6 |
  • 2. 进入 源码管理
  • 7 |
  • 8 | 3. 选择 Git, 进入 高级, 设置 Nameorigin, 然后: 9 |
      10 |
    • 如果是私有项目, 设置 refspec 为 11 | +refs/heads/*:refs/remotes/origin/* +refs/merge/*/MERGE:refs/remotes/origin/merge/* 12 |
    • 13 |
    • 如果是公开项目, 设置 refspec to 14 | +refs/heads/*:refs/remotes/origin/* +refs/pull/*/MERGE:refs/remotes/origin/pull/* 15 |
    • 16 |
    17 |
  • 18 |
  • 4. 点击 应用
  • 19 |
20 |
21 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-mrpr-action.html: -------------------------------------------------------------------------------- 1 |
2 | Only trigger build for the specified actions (separated by comma), Supported actions: 3 |
    4 |
  • create: Create
  • 5 |
  • merge: Merge
  • 6 |
  • refuse: Refuse
  • 7 |
  • cancel: Cancel
  • 8 |
  • synchronize: Code update
  • 9 |
10 |

Empty value will make it trigger for ALL actions.

11 |
12 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-mrpr-action_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 |

只对配置的动作(action)触发构建(使用逗号分隔多个 action),支持的 action 列表:

3 |
    4 |
  • create: 创建
  • 5 |
  • merge:合并
  • 6 |
  • refuse:拒绝
  • 7 |
  • cancel:取消
  • 8 |
  • synchronize:代码更新
  • 9 |
10 |

留空则所有 action 都会触发构建。

11 | 12 |
13 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-noBranchFiltering.html: -------------------------------------------------------------------------------- 1 |
2 | All branches are allowed to trigger this job. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-noBranchFiltering_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 对所有分支的代码推送都可以触发此任务。 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-webhook-api-personal-token.html: -------------------------------------------------------------------------------- 1 |
2 | Personal token is required for publishing comment and project tweet, you can enable and get it from the 3 | Personal Token 4 | setting page. 5 |
6 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-webhook-api-personal-token_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 访问令牌用于发布评论和项目内冒泡的认证,你可以在 3 | 访问令牌 4 | 设置页面开启和获取到它。 5 |
6 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-webhook-apitoken.html: -------------------------------------------------------------------------------- 1 |
2 | (Deprecated) Private token is required for publishing comment and project tweet, you can enable and get it from the 3 | Access Token 4 | setting page. 5 |
6 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-webhook-apitoken_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | (废弃)访问令牌用于发布评论和项目内冒泡的认证,你可以在 3 | 访问令牌 4 | 设置页面开启和获取到它。 5 |
6 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-webhook-token.html: -------------------------------------------------------------------------------- 1 |
2 | WebHook token will be used by Jenkins to verify if the WebHook request it received 3 | is legal, this value must be the same as the value used when creating the WebHook. 4 |
5 | -------------------------------------------------------------------------------- /src/main/webapp/help/help-webhook-token_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | Jenkins 通过 WebHook 令牌来验证它收到的 WebHook 请求是否合法, 这个值必须和创建 WebHook 时 3 | 所使用的一致。 4 |
5 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/aaa.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | for i in `find . -name '*.zh_CN.html'` 4 | do 5 | ii=`echo $i | cut -f2 -d '.'` 6 | mv .$ii.zh_CN.html .${ii}_zh_CN.html 7 | done -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/admin-user-names-help.html: -------------------------------------------------------------------------------- 1 |
2 | Comma Separated list of user names that when authenticated should be given administrator rights. 3 |
-------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/admin-user-names-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 用英文逗号分隔的管理员用户名列表。 3 |
-------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-create-job-to-authenticated-help.html: -------------------------------------------------------------------------------- 1 |
2 | If checked will grant the create job permission to all authenticated coding users even those that aren't members of the declared organizations. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-create-job-to-authenticated-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 若勾选,将授予所有登录用户创建项目的权利,即使该用户不属于设定的企业中。 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-read-to-anonymous-help.html: -------------------------------------------------------------------------------- 1 |
2 | If checked will grant the READ permission to everyone that connects to the Jenkins instance. Anyone will be able to see all the jobs and related state but only authenticated users will be able to BUILD the jobs. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-read-to-anonymous-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 若勾选,将授予所有用户只读权限。任何人都将能看到所有任务及其状态,不过只有登录用户能够构建项目。 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-read-to-authenticated-help.html: -------------------------------------------------------------------------------- 1 |
2 | If checked will grant the read permission to all authenticated coding users even those that aren't members of the declared organizations. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-read-to-authenticated-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 若勾选,将授予所有 Coding OAuth 登录用户只读权限,即使该用户不属于设定的企业中。 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-read-to-cctray-help.html: -------------------------------------------------------------------------------- 1 |
2 | Open a hole in security to allow unauthenticated access to URLs ending with /cc.xml. 3 | This URI provides monitoring capability 4 | to a range of desktop clients. 5 | 6 | Enabling this option reveals limited information about your build to the whole world. Use with care. 7 |
-------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-read-to-cctray-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 在安全防护上开一个洞,对 /cc.xml 结尾的未鉴权请求予以访问权限。 3 | 这个链接为众多桌面程序提供了 监控能力。 4 | 开启这个选项,将有限度地暴露你的构建信息给全世界。请小心使用。 5 |
6 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-read-to-coding-webhook-help.html: -------------------------------------------------------------------------------- 1 |
2 | The coding-webhook has a web hook trigger that can be used to notify Jenkins when a push has occurred and that a build should also happen.
By enabling this permission you grant anonymous external READ access to the /coding/* URL so that the request can be received. 3 |

4 | The coding-webhook checks that a change has actually occurred so this should be safe to enable. 5 | 6 |

-------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-read-to-coding-webhook-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | The coding-webhook has a web hook trigger that can be used to notify Jenkins when a push has occurred and that a build should also happen.
By enabling this permission you grant anonymous external READ access to the /coding/* URL so that the request can be received. 3 |

4 | The coding-webhook checks that a change has actually occurred so this should be safe to enable. 5 | 6 |

-------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-viewstatus-to-anonymous-help.html: -------------------------------------------------------------------------------- 1 |
2 | If checked will grant the ViewStatus permission to everyone that connects to the Jenkins instance. Anyone will be able to see the status of a job, but nothing else. 3 | This is useful especially for plugins like Embeddable Build Status Plugin. 4 |
-------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/grant-viewstatus-to-anonymous-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 若勾选,将对所有人授予 ViewStatus 权限。任何人讲可以看到一个任务的状态,不过也就只能看到这么多。 3 | 这对于一些插件很有用,特别如 Embeddable Build Status Plugin。 4 |
-------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/organization-names-help.html: -------------------------------------------------------------------------------- 1 |
2 | Comma Separated list of organization names that if a user is registered with will have job view and build rights. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/organization-names-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 用英文逗号分隔的组织名列表。在这些组织中的用户,将有查看项目和构建的权限。 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/use-repository-permissions-help.html: -------------------------------------------------------------------------------- 1 |
2 | If checked will use coding repository permissions to determine jenkins permissions for each project. 3 |
    4 |
  • Public projects - all authenticated users can READ. Only collaborators can BUILD, EDIT, CONFIGURE, CANCEL or DELETE. 5 |
  • Private projects, only collaborators can READ, BUILD, EDIT, CONFIGURE, CANCEL or DELETE 6 |
7 |
8 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/auth/use-repository-permissions-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | If checked will use coding repository permissions to determine jenkins permissions for each project. 3 |
    4 |
  • Public projects - all authenticated users can READ. Only collaborators can BUILD, EDIT, CONFIGURE, CANCEL or DELETE. 5 |
  • Private projects, only collaborators can READ, BUILD, EDIT, CONFIGURE, CANCEL or DELETE 6 |
7 |
8 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/help-authorization-strategy.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | Requires the Coding Webhook Plugin to be used as the authentication source. 4 |

5 | We use the OAuth token for each authenticated coding user to interact with the Coding API to determine the level of access each user should have. 6 | 7 |

8 | 9 | We grant READ and BUILD job permissions to an authenticated user if they are a member in at least one named organization.

10 | 11 | We also support defining a set of Jenkins Admin users and whether or not any authenticated user can have READ access to the jobs. 12 | 13 |

14 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/help-authorization-strategy_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 使用 Coding Webhook Plugin 作为鉴权手段。 4 |

5 | 我们使用 Coding 用户的 OAuth token 从 Coding API 获取数据,以提供合适的用户权限。 6 | 7 |

8 | 9 | 如果用户属于配置许可的组织,则对次用户授予读取和构建作业权限。

10 | 11 | 12 | 我们也支持设置一系列 Jenkins 管理员 账户,以及设置允许或不允许任何登录用户拥有只读权限。 13 | 14 |

15 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/help-security-realm.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | Authentication requires a valid OAuth application to be registered with Coding.net. 4 |
5 | Using your Coding account you can create a new application registration using this link: 6 | https://coding.net/user/account/setting/applications/add 7 |
8 | 9 | You can use any name you want but bear in mind this is what coding will show to the users when they authenticate and authorize this plugin to act on their behalf. 10 |
11 | 12 | The entry should look like this: 13 | 14 | 15 | 16 | 17 |
Main URLhttp://127.0.0.1:8080
Callback URLhttp://127.0.0.1:8080/securityRealm/finishLogin
18 | 19 | With 127.0.0.1:8080 replaced with the public hostname and port of your jenkins instance. 20 | 21 |

22 | 23 |

24 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/help-security-realm_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 需要在 Coding.net 注册一个有效 OAuth 应用,以提供身份验证功能 4 |
5 | 你可以使用你的 Coding 账号,点击这个链接创建一个新的 OAuth 应用: 6 | https://coding.net/user/account/setting/applications/add 7 |
8 | 9 | 你可以使用任何你想要的名称。但请注意,Coding 将把这个名称显示给用户,并请他们确认和授权这个插件获取他们的信息。 10 |
11 | 12 | 创建时,你将需要输入如下信息: 13 | 14 | 15 | 16 | 17 |
应用主页http://127.0.0.1:8080
回调地址http://127.0.0.1:8080/securityRealm/finishLogin
18 | 19 | 请把 127.0.0.1:8080 替换为 Jenkins 的域名和端口。 20 | 21 |

22 | 23 |

24 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/client-id-help.html: -------------------------------------------------------------------------------- 1 |
2 | The Client ID hash from the Coding application entry being configured. See https://coding.net/user/account/setting/applications. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/client-id-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 配置 Coding OAuth 应用里的 Client ID。 查看 https://coding.net/user/account/setting/applications. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/client-secret-help.html: -------------------------------------------------------------------------------- 1 |
2 | The Client Secret hash from the Coding application entry being configured. See https://coding.net/user/account/setting/applications. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/client-secret-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 配置 Coding OAuth 应用里的 Client Secret。 查看 https://coding.net/user/account/setting/applications. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/coding-api-uri-help.html: -------------------------------------------------------------------------------- 1 |
2 |

3 | Normally this value stays as-is. If you are using Coding Enterprise 4 | then you should enter the URI to the API root of your Coding installation 5 | (e.g. https://democorp.coding.net). 6 |

7 | 8 | Notes: 9 | 10 |

    11 |
  1. The https:// / http:// part needs to be specified.
  2. 12 |
  3. There should not be any trailing slash (/)
  4. 13 |
  5. For Coding Enterprise, the API URI is usually the same as the Web URI.
  6. 14 |
15 |
16 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/coding-api-uri-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 |

3 | 通常这个值保持不变就行了。 如果你使用的是 Coding 企业版 4 | 那么你需要输入你 Coding 企业版的 API 地址。 5 | (例如: https://democorp.coding.net). 6 |

7 | 8 | 注意: 9 | 10 |

    11 |
  1. 需要填写 https:// / http:// 部分
  2. 12 |
  3. 地址 应该有斜线 (/) 结尾
  4. 13 |
  5. 对于 Coding 企业版而已, API 地址 通常 跟 Web 地址一致。
  6. 14 |
15 |
16 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/coding-web-uri-help.html: -------------------------------------------------------------------------------- 1 |
2 |

3 | Normally this value stays as-is. If you are using Coding Enterprise 4 | then you should enter the URI to the Web root of your Coding installation 5 | (e.g. https://democorp.coding.net). 6 |

7 | 8 | Notes: 9 | 10 |

    11 |
  1. The https:// / http:// part needs to be specified.
  2. 12 |
  3. There should not be any trailing slash (/)
  4. 13 |
14 |
-------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/coding-web-uri-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 |

3 | 通常这个值保持不变就行了。 如果你使用的是 Coding 企业版 4 | 那么你需要输入你 Coding 企业版的 Web 地址。 5 | (例如: https://democorp.coding.net). 6 |

7 | 8 | 注意: 9 | 10 |

    11 |
  1. 需要填写 https:// / http:// 部分
  2. 12 |
  3. 地址 应该有斜线 (/) 结尾
  4. 13 |
14 |
15 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/oauth-scopes-help.html: -------------------------------------------------------------------------------- 1 |
2 | A comma separated list of OAuth Scopes to request access to. See https://open.coding.net/references/personal-access-token/. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help/oauth/realm/oauth-scopes-help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 用英文逗号分隔的 OAuth 权限列表。 查看 https://open.coding.net/references/personal-access-token/。 3 |
4 | -------------------------------------------------------------------------------- /src/test/java/net/coding/jenkins/plugin/v1/model/RepositoryTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Jenkins plugin for Coding https://coding.net 3 | * 4 | * Copyright (c) 2016-2018 Shuanglei Tao 5 | * Copyright (c) 2016-present, Coding, Inc. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | package net.coding.jenkins.plugin.v1.model; 21 | 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.*; 25 | 26 | public class RepositoryTest { 27 | @Test 28 | public void projectApiUrl() throws Exception { 29 | Repository repository = new Repository(); 30 | repository.setWeb_url("https://codingcorp.coding.net/p/Demo"); 31 | assertEquals("https://codingcorp.coding.net/api/user/codingcorp/project/Demo", repository.projectApiUrl()); 32 | repository.setWeb_url("https://coding.net/u/wusisu/p/screeps"); 33 | assertEquals("https://coding.net/api/user/wusisu/project/screeps", repository.projectApiUrl()); 34 | } 35 | } 36 | --------------------------------------------------------------------------------