├── .github ├── dependabot.yml ├── release-drafter.yml └── workflows │ ├── cd.yaml │ └── jenkins-security-scan.yml ├── .gitignore ├── .mvn ├── checkstyle-suppressions.xml ├── checkstyle.xml ├── extensions.xml └── maven.config ├── .vscode └── settings.json ├── CHANGES.md ├── CONTRIBUTING.md ├── Jenkinsfile ├── LICENSE.txt ├── README.md ├── docs └── README.md ├── pom.xml └── src ├── images ├── gitea-branch.svg ├── gitea-org.svg ├── gitea-repo.svg ├── gitea.svg └── make-inkscape.sh ├── main ├── java │ └── org │ │ └── jenkinsci │ │ └── plugin │ │ └── gitea │ │ ├── AbstractGiteaSCMHeadEvent.java │ │ ├── AbstractGiteaSCMSourceEvent.java │ │ ├── BranchDiscoveryTrait.java │ │ ├── BranchSCMHead.java │ │ ├── BranchSCMRevision.java │ │ ├── ExcludeArchivedRepositoriesTrait.java │ │ ├── ForkPullRequestDiscoveryTrait.java │ │ ├── GiteaAvatar.java │ │ ├── GiteaBrowser.java │ │ ├── GiteaCreateSCMEvent.java │ │ ├── GiteaDeleteSCMEvent.java │ │ ├── GiteaLink.java │ │ ├── GiteaNotifier.java │ │ ├── GiteaPullSCMEvent.java │ │ ├── GiteaPushSCMEvent.java │ │ ├── GiteaReleaseNotifier.java │ │ ├── GiteaReleaseSCMEvent.java │ │ ├── GiteaRepositorySCMEvent.java │ │ ├── GiteaSCMBuilder.java │ │ ├── GiteaSCMFile.java │ │ ├── GiteaSCMFileSystem.java │ │ ├── GiteaSCMNavigator.java │ │ ├── GiteaSCMNavigatorContext.java │ │ ├── GiteaSCMNavigatorRequest.java │ │ ├── GiteaSCMSource.java │ │ ├── GiteaSCMSourceBuilder.java │ │ ├── GiteaSCMSourceContext.java │ │ ├── GiteaSCMSourceRequest.java │ │ ├── GiteaWebhookAction.java │ │ ├── GiteaWebhookHandler.java │ │ ├── GiteaWebhookListener.java │ │ ├── MergeWithGitSCMExtension.java │ │ ├── OriginPullRequestDiscoveryTrait.java │ │ ├── PullRequestSCMHead.java │ │ ├── PullRequestSCMRevision.java │ │ ├── ReleaseDiscoveryTrait.java │ │ ├── ReleaseSCMHead.java │ │ ├── ReleaseSCMHeadCategory.java │ │ ├── ReleaseSCMRevision.java │ │ ├── SSHCheckoutTrait.java │ │ ├── TagDiscoveryTrait.java │ │ ├── TagSCMHead.java │ │ ├── TagSCMRevision.java │ │ ├── WebhookRegistration.java │ │ ├── WebhookRegistrationTrait.java │ │ ├── authentication │ │ ├── GiteaAuthTokenSource.java │ │ ├── GiteaAuthUserSource.java │ │ └── package-info.java │ │ ├── client │ │ ├── api │ │ │ ├── Gitea.java │ │ │ ├── GiteaAnnotatedTag.java │ │ │ ├── GiteaAuth.java │ │ │ ├── GiteaAuthNone.java │ │ │ ├── GiteaAuthToken.java │ │ │ ├── GiteaAuthUser.java │ │ │ ├── GiteaBranch.java │ │ │ ├── GiteaCommit.java │ │ │ ├── GiteaCommitDetail.java │ │ │ ├── GiteaCommitHash.java │ │ │ ├── GiteaCommitState.java │ │ │ ├── GiteaCommitStatus.java │ │ │ ├── GiteaConnection.java │ │ │ ├── GiteaCreateEvent.java │ │ │ ├── GiteaDeleteEvent.java │ │ │ ├── GiteaEvent.java │ │ │ ├── GiteaEventType.java │ │ │ ├── GiteaHook.java │ │ │ ├── GiteaHookType.java │ │ │ ├── GiteaHttpStatusException.java │ │ │ ├── GiteaIssue.java │ │ │ ├── GiteaIssueState.java │ │ │ ├── GiteaLabel.java │ │ │ ├── GiteaMilestone.java │ │ │ ├── GiteaObject.java │ │ │ ├── GiteaOrganization.java │ │ │ ├── GiteaOwner.java │ │ │ ├── GiteaPayloadType.java │ │ │ ├── GiteaPullRequest.java │ │ │ ├── GiteaPullRequestEvent.java │ │ │ ├── GiteaPullRequestEventType.java │ │ │ ├── GiteaPushEvent.java │ │ │ ├── GiteaRelease.java │ │ │ ├── GiteaReleaseEvent.java │ │ │ ├── GiteaReleaseEventType.java │ │ │ ├── GiteaRepository.java │ │ │ ├── GiteaRepositoryEvent.java │ │ │ ├── GiteaTag.java │ │ │ ├── GiteaUser.java │ │ │ ├── GiteaVersion.java │ │ │ └── package-info.java │ │ ├── impl │ │ │ ├── DefaultGiteaConnection.java │ │ │ ├── DefaultGiteaConnectionFactory.java │ │ │ └── package-info.java │ │ └── spi │ │ │ ├── GiteaConnectionFactory.java │ │ │ └── package-info.java │ │ ├── credentials │ │ ├── PersonalAccessToken.java │ │ ├── PersonalAccessTokenImpl.java │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── servers │ │ ├── GiteaServer.java │ │ ├── GiteaServers.java │ │ └── package-info.java │ │ └── tasks │ │ └── GiteaAssetPublisher.java ├── resources │ ├── META-INF │ │ └── services │ │ │ └── org.jenkinsci.plugin.gitea.client.spi.GiteaConnectionFactory │ ├── index.jelly │ └── org │ │ └── jenkinsci │ │ └── plugin │ │ └── gitea │ │ ├── BranchDiscoveryTrait │ │ ├── config.jelly │ │ ├── help-strategyId.html │ │ └── help.html │ │ ├── ExcludeArchivedTrait │ │ └── config.jelly │ │ ├── ForkPullRequestDiscoveryTrait │ │ ├── config.jelly │ │ ├── help-strategyId.html │ │ ├── help-trust.html │ │ └── help.html │ │ ├── GiteaBrowser │ │ ├── config.jelly │ │ └── help-repoUrl.html │ │ ├── GiteaSCMNavigator │ │ ├── config.jelly │ │ └── help.html │ │ ├── GiteaSCMSource │ │ └── config-detail.jelly │ │ ├── Messages.properties │ │ ├── OriginPullRequestDiscoveryTrait │ │ ├── config.jelly │ │ ├── help-strategyId.html │ │ └── help.html │ │ ├── ReleaseDiscoveryTrait │ │ ├── config.jelly │ │ ├── help-artifactToAssetMappingEnabled.html │ │ ├── help-includePreReleases.html │ │ └── help.html │ │ ├── SSHCheckoutTrait │ │ ├── config.jelly │ │ ├── help-credentialsId.html │ │ └── help.html │ │ ├── TagDiscoverTrait │ │ ├── config.jelly │ │ └── help.html │ │ ├── WebhookRegistrationTrait │ │ ├── config.jelly │ │ ├── help-mode.html │ │ └── help.html │ │ ├── credentials │ │ ├── Messages.properties │ │ └── PersonalAccessTokenImpl │ │ │ └── credentials.jelly │ │ ├── servers │ │ ├── GiteaServer │ │ │ ├── config.jelly │ │ │ ├── help-aliasUrl.html │ │ │ ├── help-credentialsId.html │ │ │ ├── help-displayName.html │ │ │ ├── help-manageHooks.html │ │ │ └── help-serverUrl.html │ │ ├── GiteaServers │ │ │ └── config.jelly │ │ └── Messages.properties │ │ └── tasks │ │ └── GiteaAssetPublisher │ │ └── config.jelly └── webapp │ └── images │ ├── 16x16 │ ├── gitea-branch.png │ ├── gitea-org.png │ ├── gitea-repo.png │ └── gitea.png │ ├── 24x24 │ ├── gitea-branch.png │ ├── gitea-org.png │ ├── gitea-repo.png │ └── gitea.png │ ├── 32x32 │ ├── gitea-branch.png │ ├── gitea-org.png │ ├── gitea-repo.png │ └── gitea.png │ └── 48x48 │ ├── gitea-branch.png │ ├── gitea-org.png │ ├── gitea-repo.png │ └── gitea.png └── test ├── java └── org │ └── jenkinsci │ └── plugin │ └── gitea │ ├── GiteaBrowserTest.java │ ├── GiteaCreateSCMEventTest.java │ ├── GiteaDeleteSCMEventTest.java │ ├── authentication │ └── GiteaAuthSourceTest.java │ ├── client │ ├── api │ │ ├── GiteaConnectionBuilderJenkinsTest.java │ │ └── GiteaConnectionBuilderTest.java │ ├── impl │ │ ├── DefaultGiteaConnectionTest.java │ │ ├── DefaultGiteaConnection_PagedRequests_Test.java │ │ ├── GiteaConnection_DisabledPR_Issues.java │ │ └── GiteaConnection_PagedRequests.java │ └── mock │ │ ├── MockGiteaConnection.java │ │ └── MockGiteaConnectionFactory.java │ └── credentials │ └── PersonalAccessTokenImplTest.java └── resources ├── META-INF └── services │ └── org.jenkinsci.plugin.gitea.client.spi.GiteaConnectionFactory └── org └── jenkinsci └── plugin └── gitea ├── client └── impl │ ├── branchesResponse.json │ ├── commitStatusResponse.json │ ├── hooksResponse.json │ ├── issuesResponse.json │ ├── pullRequestsResponse.json │ ├── repoResponse.json │ ├── tagsResponse.json │ └── usersResponse.json ├── credentials └── PersonalAccessTokenImplTest │ └── CredentialsBuilder │ └── config.jelly ├── rawchangelog └── rawchangelog-with-deleted-file /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates 2 | 3 | version: 2 4 | updates: 5 | - package-ecosystem: maven 6 | directory: / 7 | schedule: 8 | interval: monthly 9 | - package-ecosystem: github-actions 10 | directory: / 11 | schedule: 12 | interval: monthly 13 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | _extends: .github 2 | -------------------------------------------------------------------------------- /.github/workflows/cd.yaml: -------------------------------------------------------------------------------- 1 | name: cd 2 | on: 3 | workflow_dispatch: 4 | check_run: 5 | types: 6 | - completed 7 | 8 | permissions: 9 | checks: read 10 | contents: write 11 | 12 | jobs: 13 | maven-cd: 14 | uses: jenkins-infra/github-reusable-workflows/.github/workflows/maven-cd.yml@v1 15 | secrets: 16 | MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} 17 | MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }} 18 | -------------------------------------------------------------------------------- /.github/workflows/jenkins-security-scan.yml: -------------------------------------------------------------------------------- 1 | name: Jenkins Security Scan 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | types: [ opened, synchronize, reopened ] 9 | workflow_dispatch: 10 | 11 | permissions: 12 | security-events: write 13 | contents: read 14 | actions: read 15 | 16 | jobs: 17 | security-scan: 18 | uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2 19 | with: 20 | java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate. 21 | # java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | work*/ 3 | 4 | # IntelliJ project files 5 | *.iml 6 | *.ipr 7 | *.iws 8 | .idea/ 9 | 10 | # eclipse project file 11 | .settings 12 | .classpath 13 | .project 14 | build/ 15 | 16 | # vscode 17 | bin/ 18 | /.factorypath 19 | 20 | /nb-configuration.xml 21 | -------------------------------------------------------------------------------- /.mvn/checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.mvn/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | io.jenkins.tools.incrementals 4 | git-changelist-maven-extension 5 | 1.8 6 | 7 | 8 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Pconsume-incrementals 2 | -Pmight-produce-incrementals 3 | -Dchangelist.format=%d.v%s 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "gitea", 4 | "repos" 5 | ], 6 | "java.configuration.updateBuildConfiguration": "interactive" 7 | } -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | /* 2 | See the documentation for more options: 3 | https://github.com/jenkins-infra/pipeline-library/ 4 | */ 5 | buildPlugin( 6 | useContainerAgent: true, 7 | configurations: [ 8 | [platform: 'linux', jdk: 21], 9 | [platform: 'windows', jdk: 17], 10 | ]) 11 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2017, CloudBees, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gitea Plugin 2 | 3 | [![Version](https://img.shields.io/jenkins/plugin/v/gitea.svg?label=version)](https://plugins.jenkins.io/gitea) 4 | [![Changelog](https://img.shields.io/github/v/release/jenkinsci/gitea-plugin.svg?label=changelog)](https://github.com/jenkinsci/gitea-plugin/releases/latest) 5 | [![Installs](https://img.shields.io/jenkins/plugin/i/gitea.svg?color=blue)](https://plugins.jenkins.io/gitea) 6 | 7 | This plugin provides the Jenkins integrations for [Gitea](https://gitea.com). 8 | 9 | For details on the plugin see [plugins.jenkins.io/gitea](https://plugins.jenkins.io/gitea). 10 | 11 | For open issues on the plugin see [the Jenkins JIRA under component `gitea-plugin`](https://issues.jenkins-ci.org/issues/?jql=status%20in%20(Untriaged%2C%20Open%2C%20%22In%20Progress%22%2C%20Reopened%2C%20%22To%20Do%22)%20AND%20component%20%3D%20gitea-plugin). 12 | 13 | Build using something like: 14 | 15 | ```bash 16 | export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64/" 17 | export MAVEN_HOME="/opt/apache-maven-3.8.4/" 18 | "${MAVEN_HOME}/bin/mvn" package 19 | ``` 20 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Gitea Plugin documentation 2 | 3 | > ℹ️ Gitea plugin depends on the `multibranch pipeline` plugin. 4 | 5 | 6 | 7 | ## Initial Setup 8 | 9 | 1. Go to **Manage Jenkins -> Configure System** and scroll down to **Gitea Servers** 10 | 2. Add a new server by name and URL, your URL field should be an accessible location of your Gitea instance via HTTP(s) 11 | 3. Optionally enable the "manage hooks" checkbox, this will allow Jenkins to configure your webhooks using an account of your choosing. 12 | - It is recommended to use a personal access token, you can do this by selecting "Add" next to the credentials dropdown and changing it's "Kind" to **Gitea Personal Access Token** and "Scope" to **System**. 13 | 14 | > ℹ️ Hint: you can ignore a "HTTP 403/Forbidden" error here in case your Gitea instance is private. 15 | 16 | ## Setup Gitea user 17 | 18 | 1. login to your Gitea instance with an administrator account (optional, you can also register a new user). 19 | 2. create a new user, e.g. "jenkins". Set password to something secure - you will not need it for login. 20 | 3. add the jenkins user to the organization you want to build projects for in jenkins (either by adding him to an existing team or adding a new "ci"-team). Make sure that team is associated to the repositories you want to build. 21 | 3. log out of Gitea. 22 | 4. log back in as the new "jenkins" user. 23 | 5. in user profile settings, go to "application" and add a new access token. Make sure to note the token shown. 24 | 25 | > ℹ️ Hint: As of [Gitea version 1.16.9](https://github.com/go-gitea/gitea/releases/tag/v1.16.9) the user requires **Write permissions** to repository code. Otherwise, status checks cannot be submitted anymore causing "HTTP 403/Forbidden" errors during builds. 26 | 27 | ## Map your Gitea organization/user 28 | 29 | ### Create an item inside Jenkins 30 | 31 | 1. In main menu, click "New Item" 32 | 33 | **Using `branch-api` plugin version <2.7.0** 34 | 35 | 2. Select "Gitea organization" as the item type 36 | 37 | **Using `branch-api` plugin version >=2.7.0** 38 | 39 | 2. Select "Organization Folder" as the item type 40 | 41 | ### Configure the item 42 | 43 | 1. When configuring the new item, select "Repository Sources" 44 | 45 | ℹ️ **This is only necessary when using `branch-api` plugin version >=2.7.0** 46 | 47 | 2. In the "Gitea organzations" section, add a new credential of type "Gitea personal access token". 48 | 3. Add the access token created before for the jenkins user in Gitea. Ignore the error about the token not having the correct length. 49 | 4. In the "Owner" field, add the name of the organization in Gitea you want to build projects for (**not** the full name). 50 | 5. Fill the rest of the form as required. Click "Save". The following scan should list the repositories that the jenkins user can see in the organization selected. 51 | -------------------------------------------------------------------------------- /src/images/gitea-branch.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 57 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/images/gitea-repo.svg: -------------------------------------------------------------------------------- 1 | 2 | 16 | 18 | 19 | 21 | image/svg+xml 22 | 24 | 25 | 26 | 27 | 29 | 49 | 53 | 54 | -------------------------------------------------------------------------------- /src/images/make-inkscape.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | for src in "$dir"/*.svg 5 | do 6 | echo "Processing $(basename "$src")..." 7 | file=$(basename "$src" | sed -e s/.svg/.png/ ) 8 | for sz in 16 24 32 48 9 | do 10 | mkdir -p "${dir}/../../src/main/webapp/images/${sz}x${sz}" 11 | dst="${dir}/../../src/main/webapp/images/${sz}x${sz}/${file}" 12 | if [ ! -e "$dst" -o "$src" -nt "$dst" ] 13 | then 14 | echo -n " generating ${sz}x${sz}..." 15 | mkdir "${dir}/../../src/main/webapp/images/${sz}x${sz}" > /dev/null 2>&1 || true 16 | inkscape -z -C -w ${sz} -h ${sz} -e "$dst" "$src" 2>&1 | grep "Bitmap saved as" 17 | fi 18 | done 19 | done 20 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/AbstractGiteaSCMSourceEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.CheckForNull; 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import jenkins.scm.api.SCMHeadEvent; 29 | import jenkins.scm.api.SCMNavigator; 30 | import jenkins.scm.api.SCMSource; 31 | import jenkins.scm.api.SCMSourceEvent; 32 | import org.apache.commons.lang.StringUtils; 33 | import org.jenkinsci.plugin.gitea.client.api.GiteaEvent; 34 | import org.jenkinsci.plugin.gitea.servers.GiteaServers; 35 | 36 | /** 37 | * Base class for {@link SCMHeadEvent} from Gitea. 38 | * 39 | * @param the {@link GiteaEvent}. 40 | */ 41 | public abstract class AbstractGiteaSCMSourceEvent extends SCMSourceEvent { 42 | /** 43 | * Constructor. 44 | * 45 | * @param type the type of event. 46 | * @param payload the payload. 47 | * @param origin the origin. 48 | */ 49 | public AbstractGiteaSCMSourceEvent(@NonNull Type type, @NonNull E payload, @CheckForNull String origin) { 50 | super(type, payload, origin); 51 | } 52 | 53 | /** 54 | * {@inheritDoc} 55 | */ 56 | @Override 57 | public boolean isMatch(@NonNull SCMNavigator navigator) { 58 | if (navigator instanceof GiteaSCMNavigator) { 59 | GiteaSCMNavigator nav = (GiteaSCMNavigator) navigator; 60 | return StringUtils.equalsIgnoreCase(getPayload().getRepository().getOwner().getUsername(), nav.getRepoOwner()) 61 | && GiteaServers.isEventFor(nav.getServerUrl(), getPayload().getRepository().getHtmlUrl()); 62 | } 63 | return false; 64 | } 65 | 66 | /** 67 | * {@inheritDoc} 68 | */ 69 | @NonNull 70 | @Override 71 | public String getSourceName() { 72 | return getPayload().getRepository().getName(); 73 | } 74 | 75 | /** 76 | * {@inheritDoc} 77 | */ 78 | @Override 79 | public boolean isMatch(@NonNull SCMSource source) { 80 | if (!(source instanceof GiteaSCMSource)) { 81 | return false; 82 | } 83 | GiteaSCMSource src = (GiteaSCMSource) source; 84 | return StringUtils.equalsIgnoreCase(getPayload().getRepository().getOwner().getUsername(), src.getRepoOwner()) 85 | && StringUtils.equalsIgnoreCase(getPayload().getRepository().getName(), src.getRepository()) 86 | && GiteaServers.isEventFor(src.getServerUrl(), getPayload().getRepository().getHtmlUrl()); 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/BranchSCMHead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import jenkins.scm.api.SCMHead; 28 | 29 | /** 30 | * Our {@link SCMHead} for Gitea branches. 31 | */ 32 | public class BranchSCMHead extends SCMHead { 33 | /** 34 | * Constructor. 35 | * 36 | * @param name the name. 37 | */ 38 | public BranchSCMHead(@NonNull String name) { 39 | super(name); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/BranchSCMRevision.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import jenkins.plugins.git.AbstractGitSCMSource; 27 | import jenkins.scm.api.SCMRevision; 28 | 29 | /** 30 | * Our {@link SCMRevision} for {@link BranchSCMHead}. 31 | */ 32 | public class BranchSCMRevision extends AbstractGitSCMSource.SCMRevisionImpl { 33 | /** 34 | * Constructor. 35 | * 36 | * @param head the head. 37 | * @param hash the hash. 38 | */ 39 | public BranchSCMRevision(BranchSCMHead head, String hash) { 40 | super(head, hash); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/ExcludeArchivedRepositoriesTrait.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2021, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import hudson.Extension; 27 | import javax.annotation.Nonnull; 28 | import jenkins.scm.api.trait.SCMNavigatorContext; 29 | import jenkins.scm.api.trait.SCMNavigatorTrait; 30 | import jenkins.scm.api.trait.SCMNavigatorTraitDescriptor; 31 | import jenkins.scm.impl.trait.Selection; 32 | import org.jenkinsci.Symbol; 33 | import org.kohsuke.stapler.DataBoundConstructor; 34 | 35 | /** 36 | * A {@link Selection} trait that will restrict the discovery of repositories that have been archived. 37 | */ 38 | public class ExcludeArchivedRepositoriesTrait extends SCMNavigatorTrait { 39 | 40 | /** 41 | * Constructor for stapler. 42 | */ 43 | @DataBoundConstructor 44 | public ExcludeArchivedRepositoriesTrait() { 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | protected void decorateContext(SCMNavigatorContext context) { 52 | super.decorateContext(context); 53 | GiteaSCMNavigatorContext ctx = (GiteaSCMNavigatorContext) context; 54 | ctx.setExcludeArchivedRepositories(true); 55 | } 56 | 57 | /** 58 | * Exclude archived repositories filter 59 | */ 60 | @Symbol("giteaExcludeArchivedRepositories") 61 | @Extension 62 | @Selection 63 | public static class DescriptorImpl extends SCMNavigatorTraitDescriptor { 64 | 65 | @Override 66 | public Class getContextClass() { 67 | return GiteaSCMNavigatorContext.class; 68 | } 69 | 70 | @Nonnull 71 | @Override 72 | public String getDisplayName() { 73 | return Messages.ExcludeArchivedRepositoriesTrait_displayName(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/GiteaAvatar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import java.util.Objects; 28 | import jenkins.scm.api.metadata.AvatarMetadataAction; 29 | import org.apache.commons.lang.StringUtils; 30 | 31 | /** 32 | * Metadata for the avatar of a Gitea Organization / user / repository. 33 | */ 34 | public class GiteaAvatar extends AvatarMetadataAction { 35 | 36 | /** 37 | * The avatar URL. 38 | */ 39 | private final String avatar; 40 | 41 | /** 42 | * Constructor. 43 | * 44 | * @param avatar the avatar URL. 45 | */ 46 | public GiteaAvatar(String avatar) { 47 | this.avatar = avatar; 48 | } 49 | 50 | @Override 51 | public String getAvatarImageOf(@NonNull String size) { 52 | return StringUtils.isBlank(avatar) 53 | ? avatarIconClassNameImageOf("icon-gitea-logo", size) 54 | : cachedResizedImageOf(avatar, size); 55 | } 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public boolean equals(Object o) { 62 | if (this == o) { 63 | return true; 64 | } 65 | if (o == null || getClass() != o.getClass()) { 66 | return false; 67 | } 68 | 69 | GiteaAvatar that = (GiteaAvatar) o; 70 | 71 | return Objects.equals(avatar, that.avatar); 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | */ 77 | @Override 78 | public int hashCode() { 79 | return avatar != null ? avatar.hashCode() : 0; 80 | } 81 | 82 | /** 83 | * {@inheritDoc} 84 | */ 85 | @Override 86 | public String toString() { 87 | return "GiteaAvatar{" + 88 | "avatar='" + avatar + '\'' + 89 | '}'; 90 | } 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/GiteaReleaseSCMEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017-2022, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import hudson.Extension; 27 | import java.io.IOException; 28 | import java.util.Collections; 29 | import java.util.Map; 30 | import java.util.logging.Logger; 31 | import jenkins.scm.api.SCMHead; 32 | import jenkins.scm.api.SCMHeadEvent; 33 | import jenkins.scm.api.SCMRevision; 34 | import org.jenkinsci.plugin.gitea.client.api.GiteaConnection; 35 | import org.jenkinsci.plugin.gitea.client.api.GiteaReleaseEvent; 36 | import org.jenkinsci.plugin.gitea.client.api.GiteaTag; 37 | 38 | public class GiteaReleaseSCMEvent extends AbstractGiteaSCMHeadEvent { 39 | 40 | public static final Logger LOGGER = Logger.getLogger(GiteaReleaseSCMEvent.class.getName()); 41 | 42 | public GiteaReleaseSCMEvent(GiteaReleaseEvent payload, String origin) { 43 | super(Type.CREATED, payload, origin); 44 | } 45 | 46 | @Override 47 | protected Map headsFor(GiteaSCMSource source) { 48 | if (getPayload().getRelease().isDraft()) { 49 | // skip draft releases 50 | return Collections.emptyMap(); 51 | } 52 | 53 | String ref = getPayload().getRelease().getTagName(); 54 | String sha = null; 55 | 56 | try (GiteaConnection c = source.gitea().open()) { 57 | GiteaTag releaseTag = c.fetchTag(source.getRepoOwner(), source.getRepository(), ref); 58 | sha = releaseTag.getCommit().getSha(); 59 | } catch (IOException | InterruptedException e) { 60 | throw new RuntimeException(e); 61 | } 62 | 63 | ReleaseSCMHead h = new ReleaseSCMHead(ref, getPayload().getRelease().getId()); 64 | return Collections.singletonMap(h, new ReleaseSCMRevision(h, sha)); 65 | } 66 | 67 | @Extension 68 | public static class HandlerImpl extends GiteaWebhookHandler { 69 | 70 | @Override 71 | protected GiteaReleaseSCMEvent createEvent(GiteaReleaseEvent payload, String origin) { 72 | return new GiteaReleaseSCMEvent(payload, origin); 73 | } 74 | 75 | @Override 76 | protected void process(GiteaReleaseSCMEvent event) { 77 | SCMHeadEvent.fireNow(event); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/GiteaSCMNavigatorContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import jenkins.scm.api.SCMNavigator; 28 | import jenkins.scm.api.SCMSourceObserver; 29 | import jenkins.scm.api.trait.SCMNavigatorContext; 30 | 31 | public class GiteaSCMNavigatorContext extends SCMNavigatorContext { 32 | 33 | /** 34 | * If true, archived repositories will be ignored. 35 | */ 36 | private boolean excludeArchivedRepositories; 37 | 38 | /** 39 | * @return True if archived repositories should be ignored, false if they should be included. 40 | */ 41 | public boolean isExcludeArchivedRepositories() { 42 | return excludeArchivedRepositories; 43 | } 44 | 45 | /** 46 | * @param excludeArchivedRepositories Set true to exclude archived repositories 47 | */ 48 | public void setExcludeArchivedRepositories(boolean excludeArchivedRepositories) { 49 | this.excludeArchivedRepositories = excludeArchivedRepositories; 50 | } 51 | 52 | @NonNull 53 | @Override 54 | public GiteaSCMNavigatorRequest newRequest(@NonNull SCMNavigator navigator, @NonNull SCMSourceObserver observer) { 55 | return new GiteaSCMNavigatorRequest(navigator, this, observer); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/GiteaSCMNavigatorRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import jenkins.scm.api.SCMNavigator; 28 | import jenkins.scm.api.SCMSourceObserver; 29 | import jenkins.scm.api.trait.SCMNavigatorRequest; 30 | 31 | public class GiteaSCMNavigatorRequest extends SCMNavigatorRequest { 32 | protected GiteaSCMNavigatorRequest(@NonNull SCMNavigator source, 33 | @NonNull GiteaSCMNavigatorContext context, 34 | @NonNull SCMSourceObserver observer) { 35 | super(source, context, observer); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/GiteaSCMSourceBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.CheckForNull; 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import jenkins.scm.api.trait.SCMSourceBuilder; 29 | 30 | public class GiteaSCMSourceBuilder extends SCMSourceBuilder { 31 | @CheckForNull 32 | private final String id; 33 | @CheckForNull 34 | private final String serverUrl; 35 | @CheckForNull 36 | private final String credentialsId; 37 | @NonNull 38 | private final String repoOwner; 39 | 40 | public GiteaSCMSourceBuilder(@CheckForNull String id, @CheckForNull String serverUrl, 41 | @CheckForNull String credentialsId, @NonNull String repoOwner, 42 | @NonNull String repoName) { 43 | super(GiteaSCMSource.class, repoName); 44 | this.id = id; 45 | this.serverUrl = serverUrl; 46 | this.repoOwner = repoOwner; 47 | this.credentialsId = credentialsId; 48 | } 49 | 50 | public final String id() { 51 | return id; 52 | } 53 | 54 | @CheckForNull 55 | public final String serverUrl() { 56 | return serverUrl; 57 | } 58 | 59 | @CheckForNull 60 | public final String credentialsId() { 61 | return credentialsId; 62 | } 63 | 64 | @NonNull 65 | public final String repoOwner() { 66 | return repoOwner; 67 | } 68 | 69 | @NonNull 70 | @Override 71 | public GiteaSCMSource build() { 72 | GiteaSCMSource result = new GiteaSCMSource(serverUrl, repoOwner, projectName()); 73 | result.setId(id()); 74 | result.setCredentialsId(credentialsId()); 75 | result.setTraits(traits()); 76 | return result; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/MergeWithGitSCMExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.CheckForNull; 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 29 | import java.io.ObjectStreamException; 30 | import org.kohsuke.accmod.Restricted; 31 | import org.kohsuke.accmod.restrictions.DoNotUse; 32 | 33 | /** 34 | * Retained for data migration. 35 | * @deprecated use {@link jenkins.plugins.git.MergeWithGitSCMExtension} 36 | */ 37 | @Deprecated 38 | @Restricted(DoNotUse.class) 39 | @SuppressFBWarnings("NM_SAME_SIMPLE_NAME_AS_SUPERCLASS") 40 | public class MergeWithGitSCMExtension extends jenkins.plugins.git.MergeWithGitSCMExtension { 41 | 42 | MergeWithGitSCMExtension(@NonNull String baseName, @CheckForNull String baseHash) { 43 | super(baseName, baseHash); 44 | } 45 | 46 | private Object readResolve() throws ObjectStreamException { 47 | return new jenkins.plugins.git.MergeWithGitSCMExtension(super.getBaseName(), super.getBaseHash()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/PullRequestSCMHead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import jenkins.scm.api.SCMHead; 28 | import jenkins.scm.api.SCMHeadOrigin; 29 | import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy; 30 | import jenkins.scm.api.mixin.ChangeRequestSCMHead2; 31 | 32 | public class PullRequestSCMHead extends SCMHead implements ChangeRequestSCMHead2 { 33 | private final long id; 34 | private final BranchSCMHead target; 35 | private final ChangeRequestCheckoutStrategy strategy; 36 | private final String originName; 37 | private final String originOwner; 38 | private final String originRepository; 39 | private final SCMHeadOrigin origin; 40 | 41 | /** 42 | * Constructor. 43 | * 44 | * @param id the pull request id. 45 | * @param name the name of the head. 46 | * @param target the target of this pull request. 47 | * @param strategy the checkout strategy 48 | * @param origin the origin of the pull request 49 | * @param originOwner the name of the owner of the origin repository 50 | * @param originRepository the name of the origin repository 51 | * @param originName the name of the branch in the origin repository 52 | */ 53 | public PullRequestSCMHead(@NonNull String name, long id, BranchSCMHead target, 54 | ChangeRequestCheckoutStrategy strategy, SCMHeadOrigin origin, String originOwner, 55 | String originRepository, String originName) { 56 | super(name); 57 | this.id = id; 58 | this.target = target; 59 | this.strategy = strategy; 60 | this.origin = origin; 61 | this.originOwner = originOwner; 62 | this.originRepository = originRepository; 63 | this.originName = originName; 64 | } 65 | 66 | @NonNull 67 | @Override 68 | public ChangeRequestCheckoutStrategy getCheckoutStrategy() { 69 | return strategy; 70 | } 71 | 72 | @NonNull 73 | @Override 74 | public String getOriginName() { 75 | return originName; 76 | } 77 | 78 | @NonNull 79 | @Override 80 | public String getId() { 81 | return Long.toString(id); 82 | } 83 | 84 | @NonNull 85 | @Override 86 | public BranchSCMHead getTarget() { 87 | return target; 88 | } 89 | 90 | @NonNull 91 | @Override 92 | public SCMHeadOrigin getOrigin() { 93 | return origin; 94 | } 95 | 96 | public String getOriginOwner() { 97 | return originOwner; 98 | } 99 | 100 | public String getOriginRepository() { 101 | return originRepository; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/PullRequestSCMRevision.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import jenkins.scm.api.SCMRevision; 28 | import jenkins.scm.api.mixin.ChangeRequestSCMRevision; 29 | import org.kohsuke.stapler.export.Exported; 30 | 31 | public class PullRequestSCMRevision extends ChangeRequestSCMRevision { 32 | 33 | private final BranchSCMRevision origin; 34 | 35 | /** 36 | * Constructor. 37 | * 38 | * @param head the {@link PullRequestSCMHead} that the {@link SCMRevision} belongs to. 39 | * @param target the {@link BranchSCMRevision} of the {@link PullRequestSCMHead#getTarget()}. 40 | * @param origin the {@link BranchSCMRevision} of the {@link PullRequestSCMHead#getOrigin()} head. 41 | */ 42 | protected PullRequestSCMRevision( 43 | @NonNull PullRequestSCMHead head, 44 | @NonNull BranchSCMRevision target, 45 | @NonNull BranchSCMRevision origin) { 46 | super(head, target); 47 | this.origin = origin; 48 | } 49 | 50 | @Exported 51 | @NonNull 52 | public final BranchSCMRevision getOrigin() { 53 | return origin; 54 | } 55 | 56 | 57 | @Override 58 | public boolean equivalent(ChangeRequestSCMRevision revision) { 59 | return (revision instanceof PullRequestSCMRevision) 60 | && origin.equals(((PullRequestSCMRevision) revision).getOrigin()); 61 | } 62 | 63 | @Override 64 | protected int _hashCode() { 65 | return origin.hashCode(); 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return (isMerge() ? ((BranchSCMRevision) getTarget()).getHash() + "+" : "") + origin.getHash(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/ReleaseSCMHead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017-2022, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import jenkins.scm.api.SCMHead; 28 | 29 | public class ReleaseSCMHead extends SCMHead { 30 | 31 | private final long id; 32 | 33 | public ReleaseSCMHead(@NonNull String name, long id) { 34 | super(name); 35 | this.id = id; 36 | } 37 | 38 | public long getId() { 39 | return id; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/ReleaseSCMHeadCategory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017-2022, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 28 | import jenkins.scm.api.SCMHead; 29 | import jenkins.scm.api.SCMHeadCategory; 30 | import jenkins.scm.api.SCMSource; 31 | import org.jvnet.localizer.Localizable; 32 | 33 | /** 34 | * Category for {@link SCMHead} instances that implement {@link ReleaseSCMHead}. 35 | */ 36 | public class ReleaseSCMHeadCategory extends SCMHeadCategory { 37 | 38 | /** 39 | * Constructs a {@link ReleaseSCMHeadCategory} with customized naming. Use this constructor when the generic 40 | * naming is not appropriate terminology for the specific {@link SCMSource}'s naming of change requests. 41 | * 42 | * @param displayName the display name for change requests. 43 | */ 44 | @SuppressFBWarnings("NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION") 45 | public ReleaseSCMHeadCategory(@NonNull Localizable displayName) { 46 | super("gitea-releases", displayName); 47 | } 48 | 49 | /** 50 | * {@inheritDoc} 51 | */ 52 | @Override 53 | public boolean isMatch(@NonNull SCMHead instance) { 54 | return instance instanceof ReleaseSCMHead; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/ReleaseSCMRevision.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017-2022, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import jenkins.plugins.git.AbstractGitSCMSource; 28 | 29 | public class ReleaseSCMRevision extends AbstractGitSCMSource.SCMRevisionImpl { 30 | 31 | public ReleaseSCMRevision(@NonNull ReleaseSCMHead head, @NonNull String hash) { 32 | super(head, hash); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/TagSCMHead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017-2020, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import jenkins.plugins.git.GitTagSCMHead; 28 | import jenkins.scm.api.SCMHead; 29 | 30 | /** 31 | * Our {@link SCMHead} for Gitea tags. 32 | */ 33 | public class TagSCMHead extends GitTagSCMHead { 34 | public TagSCMHead(@NonNull String name, long timestamp) { 35 | super(name, timestamp); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/TagSCMRevision.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 20197-2020, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | import jenkins.plugins.git.GitTagSCMRevision; 27 | import jenkins.scm.api.SCMRevision; 28 | 29 | /** 30 | * Our {@link SCMRevision} for {@link BranchSCMHead}. 31 | */ 32 | public class TagSCMRevision extends GitTagSCMRevision { 33 | /** 34 | * Constructor. 35 | * 36 | * @param head the head. 37 | * @param hash the hash. 38 | */ 39 | public TagSCMRevision(TagSCMHead head, String hash) { 40 | super(head, hash); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/WebhookRegistration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea; 25 | 26 | 27 | import org.jenkinsci.plugin.gitea.servers.GiteaServers; 28 | 29 | /** 30 | * Enumeration of the different webhook registration modes. 31 | */ 32 | public enum WebhookRegistration { 33 | /** 34 | * Disable webhook registration. 35 | */ 36 | DISABLE, 37 | /** 38 | * Use the global system configuration for webhook registration. (If the {@link GiteaServers} 39 | * does not have webhook registration configured then this will be the same as {@link #DISABLE}) 40 | */ 41 | SYSTEM, 42 | /** 43 | * Use the item scoped credentials to register the webhook. 44 | */ 45 | ITEM 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/authentication/GiteaAuthTokenSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.authentication; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import hudson.Extension; 28 | import jenkins.authentication.tokens.api.AuthenticationTokenException; 29 | import jenkins.authentication.tokens.api.AuthenticationTokenSource; 30 | import org.jenkinsci.plugin.gitea.client.api.GiteaAuthToken; 31 | import org.jenkinsci.plugin.gitea.credentials.PersonalAccessToken; 32 | 33 | /** 34 | * Converts {@link PersonalAccessToken} to {@link GiteaAuthToken} authentication. 35 | */ 36 | @Extension 37 | public class GiteaAuthTokenSource extends AuthenticationTokenSource { 38 | /** 39 | * Constructor. 40 | */ 41 | public GiteaAuthTokenSource() { 42 | super(GiteaAuthToken.class, PersonalAccessToken.class); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @NonNull 49 | @Override 50 | public GiteaAuthToken convert(@NonNull PersonalAccessToken credential) throws AuthenticationTokenException { 51 | return new GiteaAuthToken(credential.getToken().getPlainText()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/authentication/GiteaAuthUserSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.authentication; 25 | 26 | import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import hudson.Extension; 29 | import jenkins.authentication.tokens.api.AuthenticationTokenException; 30 | import jenkins.authentication.tokens.api.AuthenticationTokenSource; 31 | import org.jenkinsci.plugin.gitea.client.api.GiteaAuthUser; 32 | 33 | /** 34 | * Converts {@link UsernamePasswordCredentials} to {@link GiteaAuthUser} authentication. 35 | */ 36 | @Extension 37 | public class GiteaAuthUserSource extends AuthenticationTokenSource { 38 | /** 39 | * Constructor. 40 | */ 41 | public GiteaAuthUserSource() { 42 | super(GiteaAuthUser.class, UsernamePasswordCredentials.class); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @NonNull 49 | @Override 50 | public GiteaAuthUser convert(@NonNull UsernamePasswordCredentials credential) throws AuthenticationTokenException { 51 | return new GiteaAuthUser(credential.getUsername(), credential.getPassword().getPlainText()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/authentication/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | * The {@link jenkins.authentication.tokens.api.AuthenticationTokenSource} implementations to map between 26 | * {@link com.cloudbees.plugins.credentials.Credentials} API and the {@link org.jenkinsci.plugin.gitea.client.api} 27 | * authentication support. 28 | */ 29 | package org.jenkinsci.plugin.gitea.authentication; 30 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaAuth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | /** 27 | * Base class for client authentication information. 28 | */ 29 | public interface GiteaAuth { 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaAuthNone.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | /** 27 | * Represents anonymous authentication to the Gitea API. 28 | */ 29 | public class GiteaAuthNone implements GiteaAuth { 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaAuthToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | /** 27 | * Represents token based authentication to the Gitea API. 28 | */ 29 | public class GiteaAuthToken implements GiteaAuth { 30 | /** 31 | * The token. 32 | */ 33 | private final String token; 34 | 35 | /** 36 | * Constructor. 37 | * 38 | * @param token the token. 39 | */ 40 | public GiteaAuthToken(String token) { 41 | this.token = token; 42 | } 43 | 44 | /** 45 | * Gets the token. 46 | * 47 | * @return the token. 48 | */ 49 | public String getToken() { 50 | return token; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaAuthUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | /** 27 | * Represents username/password authentication to the Gitea API 28 | */ 29 | public class GiteaAuthUser implements GiteaAuth { 30 | /** 31 | * The username. 32 | */ 33 | private final String username; 34 | /** 35 | * The password. 36 | */ 37 | private final String password; 38 | 39 | /** 40 | * Constructor. 41 | * 42 | * @param username the username. 43 | * @param password the password. 44 | */ 45 | public GiteaAuthUser(String username, String password) { 46 | this.username = username; 47 | this.password = password; 48 | } 49 | 50 | /** 51 | * Gets the username. 52 | * 53 | * @return the username. 54 | */ 55 | public String getUsername() { 56 | return username; 57 | } 58 | 59 | /** 60 | * Gets the password. 61 | * 62 | * @return the password. 63 | */ 64 | public String getPassword() { 65 | return password; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaBranch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | 28 | /** 29 | * Represents a Gitea Branch. 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 32 | public final class GiteaBranch extends GiteaObject { 33 | private String name; 34 | private GiteaCommit commit; 35 | 36 | public GiteaBranch() { 37 | } 38 | 39 | public GiteaBranch(String name, GiteaCommit commit) { 40 | this.name = name; 41 | this.commit = commit; 42 | } 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public void setName(String name) { 49 | this.name = name; 50 | } 51 | 52 | public GiteaCommit getCommit() { 53 | return commit == null ? null : commit.clone(); 54 | } 55 | 56 | public void setCommit(GiteaCommit commit) { 57 | this.commit = commit == null ? null : commit.clone(); 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public String toString() { 65 | return "GiteaBranch{" + 66 | "name='" + name + '\'' + 67 | ", commit=" + commit + 68 | '}'; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaCommitHash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2020, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package org.jenkinsci.plugin.gitea.client.api; 26 | 27 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 28 | 29 | /** 30 | * A Commit hash with Url. 31 | */ 32 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 33 | public class GiteaCommitHash extends GiteaObject implements Cloneable { 34 | private String url; 35 | private String sha; 36 | 37 | public GiteaCommitHash() { 38 | } 39 | 40 | public String getUrl() { 41 | return url; 42 | } 43 | 44 | public void setUrl(String url) { 45 | this.url = url; 46 | } 47 | 48 | public String getSha() { 49 | return sha; 50 | } 51 | 52 | public void setSha(String sha) { 53 | this.sha = sha; 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Override 60 | public String toString() { 61 | return "Commit{" 62 | + "url='" + url + '\'' 63 | + ", sha='" + sha + '\'' 64 | + '}'; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaCommitState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonCreator; 27 | import com.fasterxml.jackson.annotation.JsonValue; 28 | 29 | /** 30 | * Represents the status of a commit. 31 | */ 32 | public enum GiteaCommitState { 33 | PENDING("pending"), 34 | SUCCESS("success"), 35 | ERROR("error"), 36 | FAILURE("failure"), 37 | WARNING("warning"); 38 | 39 | private final String key; 40 | 41 | GiteaCommitState(String key) { 42 | this.key = key; 43 | } 44 | 45 | @JsonCreator 46 | public static GiteaCommitState fromString(String key) { 47 | for (GiteaCommitState s : values()) { 48 | if (key.equals(s.key)) { 49 | return s; 50 | } 51 | } 52 | return null; 53 | } 54 | 55 | @JsonValue 56 | public String getKey() { 57 | return key; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaCreateEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | import com.fasterxml.jackson.annotation.JsonProperty; 28 | 29 | /** 30 | * Gitea {@link GiteaEventType#CREATE} event. 31 | */ 32 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 33 | public class GiteaCreateEvent extends GiteaEvent { 34 | private String ref; 35 | private String refType; 36 | private String sha; 37 | 38 | @Override 39 | public GiteaCreateEvent clone() { 40 | return (GiteaCreateEvent) super.clone(); 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "GiteaCreateEvent{" + 46 | super.toString() + 47 | ", ref='" + ref + '\'' + 48 | ", refType='" + refType + '\'' + 49 | ", sha='" + sha + '\'' + 50 | '}'; 51 | } 52 | 53 | public String getRef() { 54 | return ref; 55 | } 56 | 57 | public void setRef(String ref) { 58 | this.ref = ref; 59 | } 60 | 61 | public String getRefType() { 62 | return refType; 63 | } 64 | 65 | @JsonProperty("ref_type") 66 | public void setRefType(String refType) { 67 | this.refType = refType; 68 | } 69 | 70 | public String getSha() { 71 | return sha; 72 | } 73 | 74 | public void setSha(String sha) { 75 | this.sha = sha; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaDeleteEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2021, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | import com.fasterxml.jackson.annotation.JsonProperty; 28 | 29 | /** 30 | * Gitea {@link GiteaEventType#DELETE} event. 31 | */ 32 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 33 | public class GiteaDeleteEvent extends GiteaEvent { 34 | private String ref; 35 | private String refType; 36 | 37 | @Override 38 | public GiteaDeleteEvent clone() { 39 | return (GiteaDeleteEvent) super.clone(); 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "GiteaDeleteEvent{" + 45 | super.toString() + 46 | ", ref='" + ref + '\'' + 47 | ", refType='" + refType + '\'' + 48 | '}'; 49 | } 50 | 51 | public String getRef() { 52 | return ref; 53 | } 54 | 55 | public void setRef(String ref) { 56 | this.ref = ref; 57 | } 58 | 59 | public String getRefType() { 60 | return refType; 61 | } 62 | 63 | @JsonProperty("ref_type") 64 | public void setRefType(String refType) { 65 | this.refType = refType; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | 28 | /** 29 | * Generic Gitea event. 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 32 | public class GiteaEvent extends GiteaObject { 33 | private String secret; 34 | private GiteaRepository repository; 35 | private GiteaOwner sender; 36 | 37 | public GiteaEvent() { 38 | } 39 | 40 | public GiteaEvent(String secret, GiteaRepository repository, GiteaOwner sender) { 41 | this.secret = secret; 42 | this.repository = repository; 43 | this.sender = sender; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "GiteaEvent{" + 49 | "secret='" + secret + '\'' + 50 | ", repository=" + repository + 51 | ", sender=" + sender + 52 | '}'; 53 | } 54 | 55 | public String getSecret() { 56 | return secret; 57 | } 58 | 59 | public void setSecret(String secret) { 60 | this.secret = secret; 61 | } 62 | 63 | public GiteaRepository getRepository() { 64 | return repository == null ? null : repository.clone(); 65 | } 66 | 67 | public void setRepository(GiteaRepository repository) { 68 | this.repository = repository == null ? null : repository.clone(); 69 | } 70 | 71 | public GiteaOwner getSender() { 72 | return sender == null ? null : sender.clone(); 73 | } 74 | 75 | public void setSender(GiteaOwner sender) { 76 | this.sender = sender == null ? null : sender.clone(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonCreator; 27 | import com.fasterxml.jackson.annotation.JsonValue; 28 | 29 | /** 30 | * Gitea event types. 31 | */ 32 | public enum GiteaEventType { 33 | CREATE("create"), 34 | PUSH("push"), 35 | PULL_REQUEST("pull_request"), 36 | REPOSITORY("repository"), 37 | DELETE("delete"), 38 | RELEASE("release"); 39 | 40 | private final String key; 41 | 42 | GiteaEventType(String key) { 43 | this.key = key; 44 | } 45 | 46 | @JsonCreator 47 | public static GiteaEventType fromString(String key) { 48 | for (GiteaEventType s : values()) { 49 | if (key.equals(s.key)) { 50 | return s; 51 | } 52 | } 53 | return null; 54 | } 55 | 56 | @JsonValue 57 | public String getKey() { 58 | return key; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaHookType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonCreator; 27 | import com.fasterxml.jackson.annotation.JsonValue; 28 | 29 | /** 30 | * The type of {@link GiteaHook}. 31 | */ 32 | public enum GiteaHookType { 33 | GITEA("gitea"), 34 | GOGS("gogs"), 35 | SLACK("slack"); 36 | 37 | private final String key; 38 | 39 | GiteaHookType(String key) { 40 | this.key = key; 41 | } 42 | 43 | @JsonCreator 44 | public static GiteaHookType fromString(String key) { 45 | for (GiteaHookType s : values()) { 46 | if (key.equals(s.key)) { 47 | return s; 48 | } 49 | } 50 | return null; 51 | } 52 | 53 | @JsonValue 54 | public String getKey() { 55 | return key; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaHttpStatusException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2018, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import java.io.IOException; 27 | import org.apache.commons.lang.StringUtils; 28 | 29 | /** 30 | * A richer {@link IOException} that reflects the status code of a response. 31 | * 32 | * @since 1.0.5 33 | */ 34 | public class GiteaHttpStatusException extends IOException { 35 | 36 | private final int statusCode; 37 | private final String statusMessage; 38 | 39 | public GiteaHttpStatusException(int statusCode, String statusMessage) { 40 | this(statusCode, statusMessage, null, null); 41 | } 42 | 43 | public GiteaHttpStatusException(int statusCode, String statusMessage, Throwable cause) { 44 | this(statusCode, statusMessage, null, cause); 45 | } 46 | 47 | public GiteaHttpStatusException(int statusCode, String statusMessage, String requestBody) { 48 | this(statusCode, statusMessage, requestBody, null); 49 | } 50 | 51 | public GiteaHttpStatusException(int statusCode, String statusMessage, String responseBody, Throwable cause) { 52 | super("HTTP " + statusCode + "/" + statusMessage + (StringUtils.isNotBlank(responseBody) 53 | ? "\n" + responseBody 54 | : ""), cause); 55 | this.statusCode = statusCode; 56 | this.statusMessage = statusMessage; 57 | } 58 | 59 | public int getStatusCode() { 60 | return statusCode; 61 | } 62 | 63 | public String getStatusMessage() { 64 | return statusMessage; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaIssueState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonCreator; 27 | import com.fasterxml.jackson.annotation.JsonValue; 28 | 29 | public enum GiteaIssueState { 30 | OPEN("open"), 31 | CLOSED("closed"); 32 | 33 | private final String key; 34 | 35 | GiteaIssueState(String key) { 36 | this.key = key; 37 | } 38 | 39 | @JsonCreator 40 | public static GiteaIssueState fromString(String key) { 41 | for (GiteaIssueState s : values()) { 42 | if (key.equals(s.key)) { 43 | return s; 44 | } 45 | } 46 | return null; 47 | } 48 | 49 | @JsonValue 50 | public String getKey() { 51 | return key; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | 28 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 29 | public final class GiteaLabel extends GiteaObject { 30 | private long id; 31 | private String name; 32 | private String color; 33 | private String url; 34 | 35 | public GiteaLabel() { 36 | } 37 | 38 | public long getId() { 39 | return id; 40 | } 41 | 42 | public void setId(long id) { 43 | this.id = id; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | 54 | public String getColor() { 55 | return color; 56 | } 57 | 58 | public void setColor(String color) { 59 | this.color = color; 60 | } 61 | 62 | public String getUrl() { 63 | return url; 64 | } 65 | 66 | public void setUrl(String url) { 67 | this.url = url; 68 | } 69 | 70 | /** 71 | * {@inheritDoc} 72 | */ 73 | @Override 74 | public String toString() { 75 | return "GiteaLabel{" + 76 | "id=" + id + 77 | ", name='" + name + '\'' + 78 | ", color='" + color + '\'' + 79 | ", url='" + url + '\'' + 80 | '}'; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | 28 | /** 29 | * Base class for all types in the Gitea object model. 30 | * 31 | * @param the implementation type. 32 | */ 33 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 34 | public abstract class GiteaObject> implements Cloneable { 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @SuppressWarnings("unchecked") 40 | @Override 41 | public T clone() { 42 | try { 43 | return (T) super.clone(); 44 | } catch (CloneNotSupportedException e) { 45 | throw new IllegalStateException(e); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaOrganization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | 28 | /** 29 | * A Gitea organization. 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 32 | public class GiteaOrganization extends GiteaOwner { 33 | private String description; 34 | private String website; 35 | private String location; 36 | 37 | public GiteaOrganization() { 38 | } 39 | 40 | public GiteaOrganization(String login, String fullName, String avatarUrl, String description, 41 | String website, String location) { 42 | super(login, fullName, "", avatarUrl); 43 | this.description = description; 44 | this.website = website; 45 | this.location = location; 46 | } 47 | 48 | @Override 49 | public GiteaOrganization clone() { 50 | return (GiteaOrganization) super.clone(); 51 | } 52 | 53 | @Override 54 | public String getLogin() { 55 | return getUsername(); 56 | } 57 | 58 | @Override 59 | public void setLogin(String login) { 60 | setUsername(login); 61 | } 62 | 63 | public String getDescription() { 64 | return description; 65 | } 66 | 67 | public void setDescription(String description) { 68 | this.description = description; 69 | } 70 | 71 | public String getWebsite() { 72 | return website; 73 | } 74 | 75 | public void setWebsite(String website) { 76 | this.website = website; 77 | } 78 | 79 | public String getLocation() { 80 | return location; 81 | } 82 | 83 | public void setLocation(String location) { 84 | this.location = location; 85 | } 86 | 87 | /** 88 | * {@inheritDoc} 89 | */ 90 | @Override 91 | public String toString() { 92 | return "GiteaOrganization{" + 93 | "id=" + getId() + 94 | ", fullName='" + getFullName() + '\'' + 95 | ", description='" + description + '\'' + 96 | ", website='" + website + '\'' + 97 | ", username='" + getUsername() + '\'' + 98 | ", avatarUrl='" + getAvatarUrl() + '\'' + 99 | ", location='" + location + '\'' + 100 | '}'; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaOwner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | import com.fasterxml.jackson.annotation.JsonProperty; 28 | 29 | /** 30 | * Owner of a repository. Currently two concrete implementations: {@link GiteaOrganization} and {@link GiteaUser}. 31 | */ 32 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 33 | public class GiteaOwner extends GiteaObject { 34 | private long id; 35 | private String login; 36 | private String fullName; 37 | private String email; 38 | private String avatarUrl; 39 | private String username; 40 | 41 | public GiteaOwner() { 42 | } 43 | 44 | public GiteaOwner(String login, String fullName, String email, String avatarUrl) { 45 | this.login = login; 46 | this.fullName = fullName; 47 | this.email = email; 48 | this.avatarUrl = avatarUrl; 49 | this.username = login; 50 | } 51 | 52 | public long getId() { 53 | return id; 54 | } 55 | 56 | public void setId(long id) { 57 | this.id = id; 58 | } 59 | 60 | public String getLogin() { 61 | return login; 62 | } 63 | 64 | public void setLogin(String login) { 65 | this.login = login; 66 | } 67 | 68 | public String getFullName() { 69 | return fullName; 70 | } 71 | 72 | @JsonProperty("full_name") 73 | public void setFullName(String fullName) { 74 | this.fullName = fullName; 75 | } 76 | 77 | public String getEmail() { 78 | return email; 79 | } 80 | 81 | public void setEmail(String email) { 82 | this.email = email; 83 | } 84 | 85 | public String getAvatarUrl() { 86 | return avatarUrl; 87 | } 88 | 89 | @JsonProperty("avatar_url") 90 | public void setAvatarUrl(String avatarUrl) { 91 | this.avatarUrl = avatarUrl; 92 | } 93 | 94 | public String getUsername() { 95 | return username; 96 | } 97 | 98 | public void setUsername(String username) { 99 | this.username = username; 100 | } 101 | 102 | /** 103 | * {@inheritDoc} 104 | */ 105 | @Override 106 | public String toString() { 107 | return "GiteaOwner{" + 108 | "id=" + id + 109 | ", login='" + login + '\'' + 110 | ", fullName='" + fullName + '\'' + 111 | ", email='" + email + '\'' + 112 | ", avatarUrl='" + avatarUrl + '\'' + 113 | ", username='" + username + '\'' + 114 | '}'; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaPayloadType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonCreator; 27 | import com.fasterxml.jackson.annotation.JsonValue; 28 | 29 | /** 30 | * The {@link GiteaHook} event payload. 31 | */ 32 | public enum GiteaPayloadType { 33 | JSON("json"), 34 | FORM("form"); 35 | 36 | private final String key; 37 | 38 | GiteaPayloadType(String key) { 39 | this.key = key; 40 | } 41 | 42 | @JsonCreator 43 | public static GiteaPayloadType fromString(String key) { 44 | for (GiteaPayloadType s : values()) { 45 | if (key.equals(s.key)) { 46 | return s; 47 | } 48 | } 49 | return null; 50 | } 51 | 52 | @JsonValue 53 | public String getKey() { 54 | return key; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaPullRequestEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | import com.fasterxml.jackson.annotation.JsonProperty; 28 | 29 | /** 30 | * Gitea {@link GiteaEventType#PULL_REQUEST} event. 31 | */ 32 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 33 | public class GiteaPullRequestEvent extends GiteaEvent { 34 | private GiteaPullRequestEventType action; 35 | private long number; 36 | private GiteaPullRequest pullRequest; 37 | 38 | @Override 39 | public GiteaPullRequestEvent clone() { 40 | return (GiteaPullRequestEvent) super.clone(); 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "GiteaPullRequestEvent{" + 46 | super.toString() + 47 | ", action=" + action + 48 | ", number=" + number + 49 | ", pullRequest=" + pullRequest + 50 | '}'; 51 | } 52 | 53 | public GiteaPullRequestEventType getAction() { 54 | return action; 55 | } 56 | 57 | public void setAction(GiteaPullRequestEventType action) { 58 | this.action = action; 59 | } 60 | 61 | public long getNumber() { 62 | return number; 63 | } 64 | 65 | public void setNumber(long number) { 66 | this.number = number; 67 | } 68 | 69 | public GiteaPullRequest getPullRequest() { 70 | return pullRequest == null ? null : pullRequest.clone(); 71 | } 72 | 73 | @JsonProperty("pull_request") 74 | public void setPullRequest(GiteaPullRequest pullRequest) { 75 | this.pullRequest = pullRequest == null ? null : pullRequest.clone(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaPullRequestEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonCreator; 27 | import com.fasterxml.jackson.annotation.JsonValue; 28 | 29 | public enum GiteaPullRequestEventType { 30 | OPENED("opened"), 31 | CLOSED("closed"), 32 | REOPENED("reopened"), 33 | SYNCHRONIZED("synchronized"); 34 | 35 | private final String key; 36 | 37 | GiteaPullRequestEventType(String key) { 38 | this.key = key; 39 | } 40 | 41 | @JsonCreator 42 | public static GiteaPullRequestEventType fromString(String key) { 43 | for (GiteaPullRequestEventType s : values()) { 44 | if (key.equals(s.key)) { 45 | return s; 46 | } 47 | } 48 | return null; 49 | } 50 | 51 | @JsonValue 52 | public String getKey() { 53 | return key; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaReleaseEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017-2022, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | 28 | /** 29 | * Gitea {@link GiteaEventType#RELEASE} event. 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 32 | public class GiteaReleaseEvent extends GiteaEvent { 33 | private GiteaReleaseEventType action; 34 | private GiteaRelease release; 35 | private GiteaRepository repository; 36 | private GiteaOwner sender; 37 | 38 | @Override 39 | public GiteaReleaseEvent clone() { 40 | return (GiteaReleaseEvent) super.clone(); 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "GiteaReleaseEvent{" + 46 | super.toString() + 47 | ", action=" + action + 48 | ", release=" + release + 49 | ", repository=" + repository + 50 | ", sender=" + sender + 51 | '}'; 52 | } 53 | 54 | public GiteaReleaseEventType getAction() { 55 | return action; 56 | } 57 | 58 | public void setAction(GiteaReleaseEventType action) { 59 | this.action = action; 60 | } 61 | 62 | public GiteaRelease getRelease() { 63 | return release == null ? null : release.clone(); 64 | } 65 | 66 | public void setRelease(GiteaRelease release) { 67 | this.release = release == null ? null : release.clone(); 68 | } 69 | 70 | public GiteaRepository getRepository() { 71 | return repository == null ? null : repository.clone(); 72 | } 73 | 74 | public void setRepository(GiteaRepository repository) { 75 | this.repository = repository == null ? null : repository.clone(); 76 | } 77 | 78 | public GiteaOwner getSender() { 79 | return sender == null ? null : sender.clone(); 80 | } 81 | 82 | public void setSender(GiteaOwner sender) { 83 | this.sender = sender == null ? null : sender.clone(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaReleaseEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017-2022, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonCreator; 27 | import com.fasterxml.jackson.annotation.JsonValue; 28 | 29 | public enum GiteaReleaseEventType { 30 | PUBLISHED("published"), 31 | UPDATED("updated"), 32 | DELETED("deleted"); 33 | 34 | private final String key; 35 | 36 | GiteaReleaseEventType(String key) { 37 | this.key = key; 38 | } 39 | 40 | @JsonCreator 41 | public static GiteaReleaseEventType fromString(String key) { 42 | for (GiteaReleaseEventType s : values()) { 43 | if (key.equals(s.key)) { 44 | return s; 45 | } 46 | } 47 | return null; 48 | } 49 | 50 | @JsonValue 51 | public String getKey() { 52 | return key; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaRepositoryEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | 28 | /** 29 | * Gitea {@link GiteaEventType#REPOSITORY} event. 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 32 | public class GiteaRepositoryEvent extends GiteaEvent { 33 | private String action; 34 | 35 | @Override 36 | public GiteaRepositoryEvent clone() { 37 | return (GiteaRepositoryEvent) super.clone(); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "GiteaRepositoryEvent{" + 43 | super.toString() + 44 | ", action='" + action + '\'' + 45 | '}'; 46 | } 47 | 48 | public String getAction() { 49 | return action; 50 | } 51 | 52 | public void setAction(String action) { 53 | this.action = action; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaTag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2020, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | 28 | /** 29 | * Represents a Gitea Tag. 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 32 | public final class GiteaTag extends GiteaObject { 33 | private String name; 34 | private String id; 35 | private GiteaCommitHash commit; 36 | 37 | public GiteaTag() { 38 | } 39 | 40 | public GiteaTag(String name, String id, GiteaCommitHash commit) { 41 | this.name = name; 42 | this.commit = commit; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | public String getId() { 54 | return id; 55 | } 56 | 57 | public void setId(String id) { 58 | this.id = id; 59 | } 60 | 61 | public GiteaCommitHash getCommit() { 62 | return commit == null ? null : commit.clone(); 63 | } 64 | 65 | public void setCommit(GiteaCommitHash commit) { 66 | this.commit = commit == null ? null : commit.clone(); 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | @Override 73 | public String toString() { 74 | return "GiteaTag{" 75 | + "name='" + name + '\'' 76 | + ", id='" + getId() + '\'' 77 | + ", commit=" + commit 78 | + '}'; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | 28 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 29 | public class GiteaUser extends GiteaOwner implements Cloneable { 30 | 31 | public GiteaUser() { 32 | } 33 | 34 | public GiteaUser(String login, String fullName, String email, String avatarUrl) { 35 | super(login, fullName, email, avatarUrl); 36 | } 37 | 38 | @Override 39 | public GiteaUser clone() { 40 | return (GiteaUser) super.clone(); 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "GiteaUser{" + 46 | "id=" + getId() + 47 | ", login='" + getLogin() + '\'' + 48 | ", fullName='" + getFullName() + '\'' + 49 | ", email='" + getEmail() + '\'' + 50 | ", username='" + getUsername() + '\'' + 51 | ", avatarUrl='" + getAvatarUrl() + '\'' + 52 | '}'; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/GiteaVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.api; 25 | 26 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 27 | import com.fasterxml.jackson.annotation.JsonProperty; 28 | import hudson.util.VersionNumber; 29 | import org.kohsuke.accmod.Restricted; 30 | import org.kohsuke.accmod.restrictions.DoNotUse; 31 | 32 | @JsonIgnoreProperties(ignoreUnknown = Gitea.IGNORE_UNKNOWN_PROPERTIES) 33 | public final class GiteaVersion extends GiteaObject { 34 | private String version; 35 | 36 | public GiteaVersion() { 37 | } 38 | 39 | public GiteaVersion(String version) { 40 | this.version = version; 41 | } 42 | 43 | public String getVersion() { 44 | return version; 45 | } 46 | 47 | @JsonProperty("version") 48 | public void setVersion(String version) { 49 | this.version = version; 50 | } 51 | 52 | @Deprecated 53 | @Restricted(DoNotUse.class) // TODO switch to @JsonAlias once Jackson 2.9.0+ 54 | @JsonProperty("Version") 55 | public void set_Version(String version) { 56 | setVersion(version); 57 | } 58 | 59 | public VersionNumber getVersionNumber() { 60 | int index = version.indexOf('+'); 61 | return new VersionNumber(index == -1 ? version : version.substring(0, index)); 62 | } 63 | 64 | /** 65 | * {@inheritDoc} 66 | */ 67 | @Override 68 | public String toString() { 69 | return "GiteaVersion{" + 70 | "version='" + version + '\'' + 71 | '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/api/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | * Client API for Gitea. 26 | * Ideally this would be a separate non-Jenkins plugin dependency. This client is designed to not require any 27 | * Jenkins classes. (Note there is one Jenkins specific detail around classloaders in 28 | * {@link org.jenkinsci.plugin.gitea.client.api.Gitea#jenkinsPluginClassLoader()}). 29 | * 30 | *

Usage

31 | * The entry point to this API is the {@link org.jenkinsci.plugin.gitea.client.api.Gitea} class. Use this class to 32 | * establish a {@link org.jenkinsci.plugin.gitea.client.api.GiteaConnection} to the server, e.g. 33 | *
34 |  * try (GiteaConnection c = Gitea.server(...).as(...).open()) {
35 |  *     // do stuff with the connection
36 |  * }
37 |  * 
38 | */ 39 | package org.jenkinsci.plugin.gitea.client.api; 40 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/impl/DefaultGiteaConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.impl; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import java.io.IOException; 28 | import org.jenkinsci.plugin.gitea.client.api.Gitea; 29 | import org.jenkinsci.plugin.gitea.client.api.GiteaConnection; 30 | import org.jenkinsci.plugin.gitea.client.spi.GiteaConnectionFactory; 31 | 32 | /** 33 | * The SPI implementation of {@link GiteaConnectionFactory}. 34 | */ 35 | public class DefaultGiteaConnectionFactory extends GiteaConnectionFactory { 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public boolean canOpen(@NonNull Gitea gitea) { 41 | return gitea.serverUrl().startsWith("http://") || gitea.serverUrl().startsWith("https://"); 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @NonNull 48 | @Override 49 | public GiteaConnection open(@NonNull Gitea gitea) throws IOException { 50 | return new DefaultGiteaConnection(gitea.serverUrl(), gitea.as()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | * Default implementations of {@link org.jenkinsci.plugin.gitea.client.api.GiteaConnection} and 26 | * {@link org.jenkinsci.plugin.gitea.client.spi.GiteaConnectionFactory} 27 | */ 28 | package org.jenkinsci.plugin.gitea.client.impl; 29 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/spi/GiteaConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.client.spi; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import java.io.IOException; 28 | import java.util.ServiceLoader; 29 | import org.jenkinsci.plugin.gitea.client.api.Gitea; 30 | import org.jenkinsci.plugin.gitea.client.api.GiteaConnection; 31 | 32 | /** 33 | * The SPI for instantiating {@link GiteaConnection} implementations from {@link Gitea}. 34 | * All the {@link ServiceLoader} registered implementations will be filtered to only those that 35 | * {@link #canOpen(Gitea)}. In the event of multiple implementations, the one with the highest 36 | * {@link #priority(Gitea)} will be selected and then {@link #open(Gitea)} will be 37 | * called. 38 | */ 39 | public abstract class GiteaConnectionFactory { 40 | /** 41 | * SPI: confirm that this factory can open connections to the supplied builder. 42 | * 43 | * @param gitea the builder. 44 | * @return {@code true} if connections can be opened. 45 | */ 46 | public abstract boolean canOpen(@NonNull Gitea gitea); 47 | 48 | /** 49 | * SPI: return the priority with which this factory claims ownership of the supplied URL and authentication. 50 | * This method's return value is only valid after {@link #canOpen(Gitea)} has returned {@code true}. 51 | * 52 | * @param gitea the builder. 53 | * @return the priority. 54 | */ 55 | public long priority(@NonNull Gitea gitea) { 56 | return 0L; 57 | } 58 | 59 | /** 60 | * SPI: open the connection to the supplied URL with the supplied authentication. 61 | * 62 | * @param gitea the builder. 63 | * @return the connection. 64 | * @throws IOException if the connection could not be opened. 65 | * @throws InterruptedException if interrupted while opening the connection. 66 | */ 67 | @NonNull 68 | public abstract GiteaConnection open(@NonNull Gitea gitea) throws IOException, InterruptedException; 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/client/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | * Client SPI for Gitea. 26 | * We use the API / SPI split to enable alternative implementations to be provided, for example so that tests can use 27 | * mock implementations. 28 | */ 29 | package org.jenkinsci.plugin.gitea.client.spi; 30 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/credentials/PersonalAccessToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.credentials; 25 | 26 | import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials; 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import hudson.util.Secret; 29 | 30 | /** 31 | * A Gitea personal access token. 32 | */ 33 | public interface PersonalAccessToken extends StandardUsernamePasswordCredentials { 34 | /** 35 | * Gets the token. 36 | * @return the token. 37 | */ 38 | @NonNull 39 | Secret getToken(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/credentials/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | * Gitea specific {@link com.cloudbees.plugins.credentials.Credentials} interface and default implementation. 26 | * Note we use an interface so that {@link com.cloudbees.plugins.credentials.CredentialsProvider} implementations 27 | * that store credentials external from {@link jenkins.model.Jenkins} can use {@link java.lang.reflect.Proxy} 28 | * to lazily instantiate {@link hudson.util.Secret} properties on access. 29 | */ 30 | package org.jenkinsci.plugin.gitea.credentials; 31 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | *

Jenkins SCM API implementation for Gitea

. 27 | * 28 | * The primary entry points for the implementation are: 29 | * 30 | *
    31 | *
  • {@link org.jenkinsci.plugin.gitea.GiteaSCMSource} - the {@link jenkins.scm.api.SCMSource} implementation
  • 32 | *
  • {@link org.jenkinsci.plugin.gitea.GiteaSCMNavigator} - the {@link jenkins.scm.api.SCMNavigator} 33 | * implementation
  • 34 | *
35 | * 36 | * These implementations are {@link jenkins.scm.api.trait.SCMTrait} based and accept the traits for 37 | * {@link jenkins.plugins.git.AbstractGitSCMSource} as well as the Gitea specific traits: 38 | *
    39 | *
  • {@link org.jenkinsci.plugin.gitea.BranchDiscoveryTrait}
  • 40 | *
  • {@link org.jenkinsci.plugin.gitea.ForkPullRequestDiscoveryTrait}
  • 41 | *
  • {@link org.jenkinsci.plugin.gitea.OriginPullRequestDiscoveryTrait}
  • 42 | *
  • {@link org.jenkinsci.plugin.gitea.SSHCheckoutTrait}
  • 43 | *
  • {@link org.jenkinsci.plugin.gitea.WebhookRegistrationTrait}
  • 44 | *
45 | * 46 | * Extension plugins wanting to add Gitea-specific traits should target at least one of: 47 | *
    48 | *
  • {@link org.jenkinsci.plugin.gitea.GiteaSCMNavigatorContext} for 49 | * {@linkplain jenkins.scm.api.trait.SCMNavigatorTrait}s
  • 50 | *
  • {@link org.jenkinsci.plugin.gitea.GiteaSCMNavigatorRequest} for 51 | * {@linkplain jenkins.scm.api.trait.SCMNavigatorTrait}s
  • 52 | *
  • {@link org.jenkinsci.plugin.gitea.GiteaSCMSourceBuilder} for 53 | * {@linkplain jenkins.scm.api.trait.SCMNavigatorTrait}s
  • 54 | *
  • {@link org.jenkinsci.plugin.gitea.GiteaSCMSourceContext} for 55 | * {@linkplain jenkins.scm.api.trait.SCMSourceTrait}s
  • 56 | *
  • {@link org.jenkinsci.plugin.gitea.GiteaSCMSourceRequest} for 57 | * {@linkplain jenkins.scm.api.trait.SCMSourceTrait}s
  • 58 | *
  • {@link org.jenkinsci.plugin.gitea.GiteaSCMBuilder} for 59 | * {@linkplain jenkins.scm.api.trait.SCMSourceTrait}s
  • 60 | *
61 | * 62 | * Events from a Gitea server are propagated through the standard {@link jenkins.scm.api.SCMEvent} subsystem. 63 | * Plugins wanting to listen for Gitea events and take custom actions based on the Gitea payloads should 64 | * listen for the relevant {@link org.jenkinsci.plugin.gitea.AbstractGiteaSCMHeadEvent} subclass. 65 | * Adding support for new event types requires 66 | *
    67 | *
  1. implementing the required payload type (extending from 68 | * {@link org.jenkinsci.plugin.gitea.client.api.GiteaEvent})
  2. 69 | *
  3. implementing the required {@link jenkins.scm.api.SCMEvent} subclass
  4. 70 | *
  5. providing a {@link org.jenkinsci.plugin.gitea.GiteaWebhookHandler} extension to wire it all together
  6. 71 | *
72 | */ 73 | package org.jenkinsci.plugin.gitea; 74 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugin/gitea/servers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | * Jenkins UI for managing the list of Gitea servers. 26 | */ 27 | package org.jenkinsci.plugin.gitea.servers; 28 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/org.jenkinsci.plugin.gitea.client.spi.GiteaConnectionFactory: -------------------------------------------------------------------------------- 1 | org.jenkinsci.plugin.gitea.client.impl.DefaultGiteaConnectionFactory 2 | -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 | SCM API implementation for Gitea 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/BranchDiscoveryTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/BranchDiscoveryTrait/help-strategyId.html: -------------------------------------------------------------------------------- 1 |
2 | Determines which branches are discovered. 3 |
4 |
Exclude branches that are also filed as PRs
5 |
6 | If you are discovering origin pull requests, it may not make sense to discover the same changes both as a 7 | pull request and as a branch. 8 |
9 |
Only branches that are also filed as PRs
10 |
11 | This option exists to preserve legacy behaviour when upgrading from older versions of the plugin. 12 | NOTE: If you have an actual use case for this option please file a pull request against this text. 13 |
14 |
Only branches that are also filed as PRs or main
15 |
16 | Discover branches that are also files as PRs (have open PRs) or that are the master / main branch. 17 |
18 |
All branches
19 |
20 | Ignores whether the branch is also filed as a pull request and instead discovers all branches on the 21 | origin repository. 22 |
23 |
24 |
25 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/BranchDiscoveryTrait/help.html: -------------------------------------------------------------------------------- 1 |
2 | Discovers branches on the repository. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/ExcludeArchivedTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/ForkPullRequestDiscoveryTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/ForkPullRequestDiscoveryTrait/help-strategyId.html: -------------------------------------------------------------------------------- 1 |
2 | Determines how pull requests are discovered: 3 |
4 |
Merging the pull request with the current target branch revision
5 |
Discover each pull request once with the discovered revision corresponding to the result of merging with the 6 | current revision of the target branch 7 |
8 |
The current pull request revision
9 |
Discover each pull request once with the discovered revision corresponding to the pull request head revision 10 | without merging 11 |
12 |
Both the current pull request revision and the pull request merged with the current target branch revision
13 |
Discover each pull request twice. The first discovered revision corresponds to the result of merging with 14 | the current revision of the target branch in each scan. The second parallel discovered revision corresponds 15 | to the pull request head revision without merging 16 |
17 |
18 |
19 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/ForkPullRequestDiscoveryTrait/help-trust.html: -------------------------------------------------------------------------------- 1 |
2 |

3 | One of the great powers of pull requests is that anyone with read access to a repository can fork it, commit 4 | some changes to their fork and then create a pull request against the original repository with their changes. 5 | There are some files stored in source control that are important. For example, a Jenkinsfile 6 | may contain configuration details to sandbox pull requests in order to mitigate against malicious pull requests. 7 | In order to protect against a malicious pull request itself modifying the Jenkinsfile to remove 8 | the protections, you can define the trust policy for pull requests from forks. 9 |

10 |

11 | Other plugins can extend the available trust policies. The default policies are: 12 |

13 |
14 |
Nobody
15 |
16 | Pull requests from forks will all be treated as untrusted. This means that where Jenkins requires a 17 | trusted file (e.g. Jenkinsfile) the contents of that file will be retrieved from the 18 | target branch on the origin repository and not from the pull request branch on the fork repository. 19 |
20 |
Contributors
21 |
22 | Pull requests from collaborators to the origin repository will be treated as trusted, all other pull 23 | requests from fork repositories will be treated as untrusted. 24 | Note that if credentials used by Jenkins for scanning the repository does not have permission to 25 | query the list of contributors to the origin repository then only the origin account will be treated 26 | as trusted - i.e. this will fall back to Nobody. 27 |
28 |
Everyone
29 |
30 | All pull requests from forks will be treated as trusted. NOTE: this option can be dangerous 31 | if used on a public repository hosted on a Gitea instance that allows signup. 32 |
33 |
34 |
35 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/ForkPullRequestDiscoveryTrait/help.html: -------------------------------------------------------------------------------- 1 |
2 | Discovers pull requests where the origin repository is a fork of the target repository. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/GiteaBrowser/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/GiteaBrowser/help-repoUrl.html: -------------------------------------------------------------------------------- 1 |
2 | Specify the HTTP URL for this repository's Gitea page. The URL needs to include the owner and repository so, for 3 | example, if the Gitea server is https://gitea.example.com then the URL for bob's skunkworks project 4 | repository might be https://gitea.example.com/bob/skunkworks 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/GiteaSCMNavigator/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/GiteaSCMNavigator/help.html: -------------------------------------------------------------------------------- 1 |
2 | Exclude Gitea repositories that have been archived. If set, no jobs will be created for archived repositories. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/GiteaSCMSource/config-detail.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/Messages.properties: -------------------------------------------------------------------------------- 1 | BranchDiscoveryTrait.allBranches=All branches 2 | BranchDiscoveryTrait.authorityDisplayName=Trust origin branches 3 | BranchDiscoveryTrait.displayName=Discover branches 4 | BranchDiscoveryTrait.excludePRs=Only branches that are not also filed as PRs 5 | BranchDiscoveryTrait.onlyPRs=Only branches that are also filed as PRs 6 | BranchDiscoveryTrait.onlyPRsOrMain=Only branches that are also filed as PRs or master / main branch 7 | ForkPullRequestDiscoveryTrait.contributorsDisplayName=Contributors 8 | ForkPullRequestDiscoveryTrait.displayName=Discover pull requests from forks 9 | ForkPullRequestDiscoveryTrait.everyoneDisplayName=Everyone 10 | ForkPullRequestDiscoveryTrait.headAndMerge=Both the current pull request revision and the pull request merged with \ 11 | the current target branch revision 12 | ForkPullRequestDiscoveryTrait.headOnly=The current pull request revision 13 | ForkPullRequestDiscoveryTrait.mergeOnly=Merging the pull request with the current target branch revision 14 | ForkPullRequestDiscoveryTrait.nobodyDisplayName=Nobody 15 | GiteaBrowser.displayName=Gitea 16 | GiteaLink.displayName=Gitea 17 | GiteaSCMNavigator.description=Scans a Gitea Organization (or user account) for all repositories matching some defined \ 18 | markers. 19 | GiteaSCMNavigator.displayName=Gitea Organization 20 | GiteaSCMNavigator.pronoun=Gitea Organization 21 | GiteaSCMNavigator.selectedCredentialsMissing=Cannot find currently selected credentials 22 | GiteaSCMNavigator.traitSection_additional=Additional 23 | GiteaSCMNavigator.traitSection_repositories=Repositories 24 | GiteaSCMNavigator.traitSection_withinRepo=Within repository 25 | GiteaSCMSource.ChangeRequestCategory=Pull Requests 26 | GiteaSCMSource.DisplayName=Gitea 27 | GiteaSCMSource.Pronoun=Repository 28 | GiteaSCMSource.selectedCredentialsMissing=Cannot find currently selected credentials 29 | GiteaSCMSource.traitSection_additional=Additional 30 | GiteaSCMSource.traitSection_withinRepo=Within repository 31 | GiteaSCMSource.TagCategory=Tags 32 | GiteaSCMSource.UncategorizedCategory=Branches 33 | OriginPullRequestDiscoveryTrait.authorityDisplayName=Trust origin pull requests 34 | PullRequestSCMHead.Pronoun=Pull Request 35 | SSHCheckoutTrait.displayName=Checkout over SSH 36 | SSHCheckoutTrait.incompatibleCredentials=The currently configured credentials are incompatible with this behaviour 37 | SSHCheckoutTrait.missingCredentials=The currently configured credentials cannot be found 38 | SSHCheckoutTrait.useAgentKey=- use build agent''s key - 39 | ExcludeArchivedRepositoriesTrait.displayName=Exclude archived repositories 40 | WebhookRegistrationTrait.disableHook=Disable hook management 41 | WebhookRegistrationTrait.displayName=Override hook management 42 | WebhookRegistrationTrait.useItemHook=Use item credentials for hook management 43 | TagDiscoveryTrait.displayName=Discover tags 44 | TagDiscoveryTrait.authorityDisplayName=Trust tags 45 | ReleaseDiscoveryTrait.displayName=Discover Gitea releases 46 | GiteaSCMSource.ReleaseCategory=Releases 47 | 48 | GiteaAssetPublisher.StartPublishing=Publishing Gitea release assets 49 | GiteaAssetPublisher.DisplayName=Publishes an asset to the gitea release, if the build was triggered by an release 50 | GiteaAssetPublisher.SkipBecauseOnlyIfSuccessful=Skipped archiving because build is not successful 51 | GiteaAssetPublisher.NoIncludes=\ 52 | No assets are configured for publishing.\n\ 53 | You probably forgot to set the file pattern, so please go back to the configuration and specify it.\n\ 54 | If you really did mean to publish all the files in the workspace, please specify "**" 55 | GiteaAssetPublisher.NoMatchFound=No assets found that match the file pattern "{0}". Configuration error? -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/OriginPullRequestDiscoveryTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/OriginPullRequestDiscoveryTrait/help-strategyId.html: -------------------------------------------------------------------------------- 1 |
2 | Determines how pull requests are discovered: 3 |
4 |
Merging the pull request with the current target branch revision
5 |
Discover each pull request once with the discovered revision corresponding to the result of merging with the 6 | current revision of the target branch 7 |
8 |
The current pull request revision
9 |
Discover each pull request once with the discovered revision corresponding to the pull request head revision 10 | without merging 11 |
12 |
Both the current pull request revision and the pull request merged with the current target branch revision
13 |
Discover each pull request twice. The first discovered revision corresponds to the result of merging with 14 | the current revision of the target branch in each scan. The second parallel discovered revision corresponds 15 | to the pull request head revision without merging 16 |
17 |
18 |
19 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/OriginPullRequestDiscoveryTrait/help.html: -------------------------------------------------------------------------------- 1 |
2 | Discovers pull requests where the origin repository is the same as the target repository. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/ReleaseDiscoveryTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/ReleaseDiscoveryTrait/help-artifactToAssetMappingEnabled.html: -------------------------------------------------------------------------------- 1 |
2 | If enabled, artifacts that where archived (i.e. via archiveArtifacts) will be added 3 | as assets in the release, but only if the build was successfull. 4 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/ReleaseDiscoveryTrait/help-includePreReleases.html: -------------------------------------------------------------------------------- 1 |
2 | If enabled, releases that are marked as pre-release are also discovered 3 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/ReleaseDiscoveryTrait/help.html: -------------------------------------------------------------------------------- 1 |
2 | Discovers releases on the repository. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/SSHCheckoutTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/SSHCheckoutTrait/help-credentialsId.html: -------------------------------------------------------------------------------- 1 |
2 | Credentials used to check out sources. Must be a SSH key based credential. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/SSHCheckoutTrait/help.html: -------------------------------------------------------------------------------- 1 |
2 | By default the discovered branches / pull requests will all use the same username / password credentials 3 | that were used for discovery when checking out sources. This means that the checkout will be using the 4 | https:// protocol for the Git repository. 5 |

6 | This behaviour allows you to select the SSH private key to be used for checking out sources, which will 7 | consequently force the checkout to use the ssh:// protocol. 8 |

9 |
10 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/TagDiscoverTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/TagDiscoverTrait/help.html: -------------------------------------------------------------------------------- 1 |
2 | Discovers tags on the repository. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/WebhookRegistrationTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/WebhookRegistrationTrait/help-mode.html: -------------------------------------------------------------------------------- 1 |
2 | There are two available modes: 3 |
4 |
Disable hook management
5 |
Disables hook management irrespective of the global defaults.
6 |
Use item credentials for hook management
7 |
Enabled hook management but uses the selected credentials to manage the hooks rather than those defined in 8 | Manage Jenkins » Configure System › Gitea Server 9 |
10 |
11 |
12 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/WebhookRegistrationTrait/help.html: -------------------------------------------------------------------------------- 1 |
2 |

3 | Overrides the defaults for webhook management. 4 |

5 |

6 | Webhooks are used to inform Jenkins about changes to repositories. There are two ways webhooks can be 7 | configured: 8 |

9 |
    10 |
  • Manual webhook configuration requires the user to configure Gitea with the Jenkins URL in order 11 | to ensure that Gitea will send the events to Jenkins after every change. 12 |
  • 13 |
  • Automatic webhook configuration requires that Jenkins has credentials with sufficient permission to 14 | configure webhooks and also that Jenkins knows the URL that Gitea can connect to. 15 |
  • 16 |
17 |

18 | The Manage Jenkins » Configure System › Gitea Server allows defining the list of 19 | servers. Each server can be associated with credentials. If credentials are defined then the default behaviour 20 | is to use those credentials to automatically manage the webhooks of all repositories that Jenkins is interested 21 | in. If no credentials are defined then the default behaviour is to require the user to manually configure 22 | webhooks. 23 |

24 |
25 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/credentials/Messages.properties: -------------------------------------------------------------------------------- 1 | PersonalAccessTokenImpl.displayName=Gitea Personal Access Token 2 | PersonalAccessTokenImpl.tokenRequired=Token required 3 | PersonalAccessTokenImpl.tokenWrongLength=Token is not the expected length 4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/credentials/PersonalAccessTokenImpl/credentials.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/servers/GiteaServer/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/servers/GiteaServer/help-aliasUrl.html: -------------------------------------------------------------------------------- 1 |
2 | Leave this blank unless you are having issues with webhook events failing to trigger.
3 | In some rare cases, the URL that Gitea uses in webhook events may not be the same as the URL that Jenkins uses 4 | to access Gitea. For example, if Jenkins needs to access the Gitea web interface through a reverse proxy but 5 | regular users access Gitea directly. 6 |
7 | If this is the case, then provide the Server URL that Gitea publishes in the webhook events. To determine this URL 8 | you can inspect an event in the Gitea Web UI. The event will look something like: 9 |
10 | {
11 |   ...
12 |   "repository":{
13 |     ...
14 |     "full_name": "example/reponame",
15 |     ...
16 |     "html_url": "http://git.example.org:3000/example/reponame",
17 |     ...
18 |   },
19 |   ...
20 | }
21 |     
22 | You are looking for the repository/html_url value and you should remove the 23 | repository/full_name part at the end to determine the Alias URL to specify, i.e. using the example 24 | payload above, the alias URL would be http://git.example.org:3000/ 25 |
26 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/servers/GiteaServer/help-credentialsId.html: -------------------------------------------------------------------------------- 1 |
2 | Select the credentials to use for managing hooks. Both GLOBAL and SYSTEM scoped credentials are eligible as the 3 | management of hooks is run in the context of Jenkins itself and not in the context of the individual items. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/servers/GiteaServer/help-displayName.html: -------------------------------------------------------------------------------- 1 |
2 | The human friendly name for this Gitea server. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/servers/GiteaServer/help-manageHooks.html: -------------------------------------------------------------------------------- 1 |
2 | Selecting this option will enable the automatic management of web hooks for all items that use this 3 | endpoint, with the exception of those items that have explicitly opted out of hook management. 4 | When this option is not selected, individual items can still opt in to hook management provided the credentials 5 | those items have been configured with have permission to manage the required hooks. 6 |
7 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/servers/GiteaServer/help-serverUrl.html: -------------------------------------------------------------------------------- 1 |
2 | The URL of this Gitea Server, examples include: http://internal.example.com:7990/gitea 3 | and https://gitea.example.com. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/servers/GiteaServers/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 |
9 | 10 |
11 |
12 |
13 |
14 |
15 |
16 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/servers/Messages.properties: -------------------------------------------------------------------------------- 1 | GiteaServer.displayName=Gitea Server 2 | GiteaServer.hookManagementAs=Hook management will be performed as {0} 3 | GiteaServer.validateInterrupted=Interrupted while trying to validate credentials 4 | GiteaServer.versionInterrupted=Interrupted while trying to determine server version 5 | GiteaServer.invalidUrl=Invalid URL: {0} 6 | GiteaServer.serverVersion=Gitea Version: {0} 7 | GiteaServer.cannotConnect=Could not communicate with server: {0} 8 | GiteaServer.credentialsNotResolved=Cannot resolve suitable credentials with id: {0} 9 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugin/gitea/tasks/GiteaAssetPublisher/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/webapp/images/16x16/gitea-branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/16x16/gitea-branch.png -------------------------------------------------------------------------------- /src/main/webapp/images/16x16/gitea-org.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/16x16/gitea-org.png -------------------------------------------------------------------------------- /src/main/webapp/images/16x16/gitea-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/16x16/gitea-repo.png -------------------------------------------------------------------------------- /src/main/webapp/images/16x16/gitea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/16x16/gitea.png -------------------------------------------------------------------------------- /src/main/webapp/images/24x24/gitea-branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/24x24/gitea-branch.png -------------------------------------------------------------------------------- /src/main/webapp/images/24x24/gitea-org.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/24x24/gitea-org.png -------------------------------------------------------------------------------- /src/main/webapp/images/24x24/gitea-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/24x24/gitea-repo.png -------------------------------------------------------------------------------- /src/main/webapp/images/24x24/gitea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/24x24/gitea.png -------------------------------------------------------------------------------- /src/main/webapp/images/32x32/gitea-branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/32x32/gitea-branch.png -------------------------------------------------------------------------------- /src/main/webapp/images/32x32/gitea-org.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/32x32/gitea-org.png -------------------------------------------------------------------------------- /src/main/webapp/images/32x32/gitea-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/32x32/gitea-repo.png -------------------------------------------------------------------------------- /src/main/webapp/images/32x32/gitea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/32x32/gitea.png -------------------------------------------------------------------------------- /src/main/webapp/images/48x48/gitea-branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/48x48/gitea-branch.png -------------------------------------------------------------------------------- /src/main/webapp/images/48x48/gitea-org.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/48x48/gitea-org.png -------------------------------------------------------------------------------- /src/main/webapp/images/48x48/gitea-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/48x48/gitea-repo.png -------------------------------------------------------------------------------- /src/main/webapp/images/48x48/gitea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/gitea-plugin/7bb0aed4c1f7921b7a6bbb419e89c55d94a5717c/src/main/webapp/images/48x48/gitea.png -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugin/gitea/GiteaDeleteSCMEventTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugin.gitea; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Map; 5 | import jenkins.scm.api.SCMHead; 6 | import jenkins.scm.api.SCMRevision; 7 | import jenkins.scm.impl.mock.MockSCMNavigator; 8 | import jenkins.scm.impl.mock.MockSCMSource; 9 | import org.jenkinsci.plugin.gitea.client.api.GiteaDeleteEvent; 10 | import org.jenkinsci.plugin.gitea.client.api.GiteaOwner; 11 | import org.jenkinsci.plugin.gitea.client.api.GiteaRepository; 12 | import org.junit.jupiter.api.Test; 13 | 14 | import static org.hamcrest.MatcherAssert.assertThat; 15 | import static org.hamcrest.Matchers.is; 16 | import static org.hamcrest.Matchers.nullValue; 17 | 18 | class GiteaDeleteSCMEventTest { 19 | 20 | final GiteaSCMSource giteaSCMSource = new GiteaSCMSource("", "", ""); 21 | final MockSCMSource scmSource = new MockSCMSource("controllerId", "giteaRepo", new ArrayList<>()); 22 | final MockSCMNavigator scmNavigator = new MockSCMNavigator("controllerId", new ArrayList<>()); 23 | final GiteaDeleteSCMEvent branchDeleteEvent = new GiteaDeleteSCMEvent(withGiteaDeleteEvent("feature/branch", "branch"), "?"); 24 | final GiteaDeleteSCMEvent tagDeleteEvent = new GiteaDeleteSCMEvent(withGiteaDeleteEvent("mytag", "tag"), "?"); 25 | 26 | @Test 27 | void descriptionForSCMNavigator_withBranchDeleteEvent() { 28 | assertThat(branchDeleteEvent.descriptionFor(scmNavigator), is("Delete event for branch feature/branch in repository giteaRepo")); 29 | } 30 | 31 | @Test 32 | void descriptionForSCMNavigator_withTagDeleteEvent() { 33 | assertThat(tagDeleteEvent.descriptionFor(scmNavigator), is("Delete event for tag mytag in repository giteaRepo")); 34 | } 35 | 36 | @Test 37 | void descriptionForSCMSource_withBranchDeleteEvent() { 38 | assertThat(branchDeleteEvent.descriptionFor(scmSource), is("Delete event for branch feature/branch")); 39 | } 40 | 41 | @Test 42 | void descriptionForSCMSource_withTagDeleteEvent() { 43 | assertThat(tagDeleteEvent.descriptionFor(scmSource), is("Delete event for tag mytag")); 44 | } 45 | 46 | @Test 47 | void description_withBranchDeleteEvent() { 48 | assertThat(branchDeleteEvent.description(), is("Delete event for branch feature/branch in repository ownerUser/giteaRepo")); 49 | } 50 | 51 | @Test 52 | void description_withTagDeleteEvent() { 53 | assertThat(tagDeleteEvent.description(), is("Delete event for tag mytag in repository ownerUser/giteaRepo")); 54 | } 55 | 56 | @Test 57 | void headsFor_withBranchDeleteEvent() { 58 | Map headsFor = branchDeleteEvent.headsFor(giteaSCMSource); 59 | 60 | assertThat(headsFor.size(), is(1)); 61 | SCMHead scmHead = headsFor.keySet().iterator().next(); 62 | assertThat(scmHead.getName(), is("feature/branch")); 63 | SCMRevision scmRevision = headsFor.values().iterator().next(); 64 | assertThat(scmRevision, nullValue()); 65 | 66 | } 67 | 68 | @Test 69 | void headsFor_withTagDeleteEvent() { 70 | Map headsFor = tagDeleteEvent.headsFor(giteaSCMSource); 71 | 72 | assertThat(headsFor.size(), is(1)); 73 | SCMHead scmHead = headsFor.keySet().iterator().next(); 74 | assertThat(scmHead.getName(), is("mytag")); 75 | SCMRevision scmRevision = headsFor.values().iterator().next(); 76 | assertThat(scmRevision, nullValue()); 77 | } 78 | 79 | GiteaDeleteEvent withGiteaDeleteEvent(String ref, String refType) { 80 | GiteaDeleteEvent event = new GiteaDeleteEvent(); 81 | event.setRef(ref); 82 | event.setRefType(refType); 83 | GiteaRepository repository = new GiteaRepository(); 84 | repository.setName("giteaRepo"); 85 | GiteaOwner owner = new GiteaOwner(); 86 | owner.setUsername("ownerUser"); 87 | repository.setOwner(owner); 88 | event.setRepository(repository); 89 | return event; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugin/gitea/authentication/GiteaAuthSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.authentication; 25 | 26 | import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; 27 | import hudson.util.Secret; 28 | import jenkins.authentication.tokens.api.AuthenticationTokens; 29 | import org.jenkinsci.plugin.gitea.client.api.GiteaAuth; 30 | import org.jenkinsci.plugin.gitea.client.api.GiteaAuthToken; 31 | import org.jenkinsci.plugin.gitea.client.api.GiteaAuthUser; 32 | import org.jenkinsci.plugin.gitea.credentials.PersonalAccessToken; 33 | import org.junit.jupiter.api.Test; 34 | import org.jvnet.hudson.test.JenkinsRule; 35 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins; 36 | import org.mockito.Mockito; 37 | 38 | import static org.hamcrest.MatcherAssert.assertThat; 39 | import static org.hamcrest.Matchers.instanceOf; 40 | import static org.hamcrest.Matchers.is; 41 | 42 | @WithJenkins 43 | class GiteaAuthSourceTest { 44 | 45 | @Test 46 | void given__tokenCredential__when__convert__then__tokenAuth(JenkinsRule j) { 47 | // we use a mock to ensure that java.lang.reflect.Proxy implementations of the credential interface work 48 | PersonalAccessToken credential = Mockito.mock(PersonalAccessToken.class); 49 | Mockito.when(credential.getToken()).thenReturn(Secret.fromString("b5bc10f13665362bd61de931c731e3c74187acc4")); 50 | GiteaAuth auth = AuthenticationTokens.convert(GiteaAuth.class, credential); 51 | assertThat(auth, instanceOf(GiteaAuthToken.class)); 52 | assertThat(((GiteaAuthToken)auth).getToken(), is("b5bc10f13665362bd61de931c731e3c74187acc4")); 53 | } 54 | 55 | @Test 56 | void given__userPassCredential__when__convert__then__tokenAuth(JenkinsRule j) { 57 | // we use a mock to ensure that java.lang.reflect.Proxy implementations of the credential interface work 58 | UsernamePasswordCredentials credential = Mockito.mock(UsernamePasswordCredentials.class); 59 | Mockito.when(credential.getUsername()).thenReturn("bob"); 60 | Mockito.when(credential.getPassword()).thenReturn(Secret.fromString("secret")); 61 | GiteaAuth auth = AuthenticationTokens.convert(GiteaAuth.class, credential); 62 | assertThat(auth, instanceOf(GiteaAuthUser.class)); 63 | assertThat(((GiteaAuthUser)auth).getUsername(), is("bob")); 64 | assertThat(((GiteaAuthUser)auth).getPassword(), is("secret")); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugin/gitea/client/api/GiteaConnectionBuilderJenkinsTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugin.gitea.client.api; 2 | 3 | import org.jenkinsci.plugin.gitea.client.mock.MockGiteaConnection; 4 | import org.jenkinsci.plugin.gitea.client.mock.MockGiteaConnectionFactory; 5 | import org.junit.jupiter.api.Test; 6 | import org.jvnet.hudson.test.JenkinsRule; 7 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins; 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.instanceOf; 11 | import static org.hamcrest.Matchers.not; 12 | 13 | @WithJenkins 14 | class GiteaConnectionBuilderJenkinsTest { 15 | 16 | @Test 17 | void given__registered_mock__when__open__then__mock_returned(JenkinsRule j) throws Exception { 18 | MockGiteaConnectionFactory.reset(); 19 | MockGiteaConnectionFactory.register(new MockGiteaConnection("bob"), "http://gitea.test/open"); 20 | assertThat(Gitea.server("http://gitea.test/open").open(), instanceOf(MockGiteaConnection.class)); 21 | } 22 | 23 | @Test 24 | void given__no_registered_mock__when__open__then__real_returned(JenkinsRule j) throws Exception { 25 | MockGiteaConnectionFactory.reset(); 26 | assertThat(Gitea.server("http://gitea.test/open").open(), not(instanceOf(MockGiteaConnection.class))); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugin/gitea/client/api/GiteaConnectionBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugin.gitea.client.api; 2 | 3 | import org.jenkinsci.plugin.gitea.client.mock.MockGiteaConnection; 4 | import org.jenkinsci.plugin.gitea.client.mock.MockGiteaConnectionFactory; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.instanceOf; 9 | import static org.hamcrest.Matchers.not; 10 | 11 | class GiteaConnectionBuilderTest { 12 | 13 | @Test 14 | void given__registered_mock__when__open__then__mock_returned() throws Exception { 15 | MockGiteaConnectionFactory.reset(); 16 | MockGiteaConnectionFactory.register(new MockGiteaConnection("bob"), "http://gitea.test/open"); 17 | assertThat(Gitea.server("http://gitea.test/open").open(), instanceOf(MockGiteaConnection.class)); 18 | } 19 | 20 | @Test 21 | void given__no_registered_mock__when__open__then__real_returned() throws Exception { 22 | MockGiteaConnectionFactory.reset(); 23 | assertThat(Gitea.server("http://gitea.test/open").open(), not(instanceOf(MockGiteaConnection.class))); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugin/gitea/client/impl/GiteaConnection_DisabledPR_Issues.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugin.gitea.client.impl; 2 | 3 | import edu.umd.cs.findbugs.annotations.NonNull; 4 | import java.io.IOException; 5 | import java.net.HttpURLConnection; 6 | import org.jenkinsci.plugin.gitea.client.api.GiteaAuth; 7 | import org.jenkinsci.plugin.gitea.client.api.GiteaHttpStatusException; 8 | 9 | public class GiteaConnection_DisabledPR_Issues extends DefaultGiteaConnection { 10 | 11 | GiteaConnection_DisabledPR_Issues(@NonNull String serverUrl, @NonNull GiteaAuth authentication) { 12 | super(serverUrl, authentication); 13 | } 14 | 15 | @Override 16 | protected HttpURLConnection openConnection(String spec) throws IOException { 17 | throw new GiteaHttpStatusException(404, "TEST Case"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugin/gitea/client/impl/GiteaConnection_PagedRequests.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugin.gitea.client.impl; 2 | 3 | import edu.umd.cs.findbugs.annotations.NonNull; 4 | import java.net.HttpURLConnection; 5 | import java.util.Map; 6 | import org.jenkinsci.plugin.gitea.client.api.GiteaAuth; 7 | 8 | public class GiteaConnection_PagedRequests extends DefaultGiteaConnection { 9 | private final Map requestMocks; 10 | 11 | GiteaConnection_PagedRequests(@NonNull String serverUrl, @NonNull GiteaAuth authentication, Map requestMocks) { 12 | super(serverUrl, authentication); 13 | this.requestMocks = requestMocks; 14 | } 15 | 16 | @Override 17 | protected HttpURLConnection openConnection(String spec) { 18 | return requestMocks.get(spec); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugin/gitea/client/mock/MockGiteaConnectionFactory.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugin.gitea.client.mock; 2 | 3 | import edu.umd.cs.findbugs.annotations.NonNull; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import org.jenkinsci.plugin.gitea.client.api.Gitea; 7 | import org.jenkinsci.plugin.gitea.client.api.GiteaConnection; 8 | import org.jenkinsci.plugin.gitea.client.spi.GiteaConnectionFactory; 9 | 10 | public class MockGiteaConnectionFactory extends GiteaConnectionFactory { 11 | private static final Map mocks = new HashMap<>(); 12 | 13 | public static void reset() { 14 | synchronized (mocks) { 15 | mocks.clear(); 16 | } 17 | } 18 | 19 | public static T register(@NonNull T mock, @NonNull String serverUrl) { 20 | mock.getClass(); // NPE if null 21 | synchronized (mocks) { 22 | mocks.put(serverUrl, mock); 23 | } 24 | return mock; 25 | } 26 | 27 | @Override 28 | public long priority(@NonNull Gitea gitea) { 29 | return 1000L; 30 | } 31 | 32 | @Override 33 | public boolean canOpen(@NonNull Gitea gitea) { 34 | synchronized (mocks) { 35 | return mocks.containsKey(gitea.serverUrl()); 36 | 37 | } 38 | } 39 | 40 | @NonNull 41 | @Override 42 | public GiteaConnection open(@NonNull Gitea gitea) { 43 | synchronized (mocks) { 44 | return mocks.get(gitea.serverUrl()); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugin/gitea/credentials/PersonalAccessTokenImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2017, CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugin.gitea.credentials; 25 | 26 | import com.cloudbees.plugins.credentials.Credentials; 27 | import com.cloudbees.plugins.credentials.CredentialsScope; 28 | import edu.umd.cs.findbugs.annotations.NonNull; 29 | import hudson.model.AbstractProject; 30 | import hudson.tasks.BuildStepDescriptor; 31 | import hudson.tasks.Builder; 32 | import org.junit.jupiter.api.Test; 33 | import org.jvnet.hudson.test.JenkinsRule; 34 | import org.jvnet.hudson.test.TestExtension; 35 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins; 36 | import org.kohsuke.stapler.DataBoundConstructor; 37 | 38 | @WithJenkins 39 | class PersonalAccessTokenImplTest { 40 | 41 | @Test 42 | void configRoundtrip(JenkinsRule j) throws Exception { 43 | PersonalAccessTokenImpl expected = new PersonalAccessTokenImpl( 44 | CredentialsScope.GLOBAL, 45 | "magic-id", 46 | "configRoundtrip", 47 | "b5bc10f13665362bd61de931c731e3c74187acc4"); 48 | CredentialsBuilder builder = new CredentialsBuilder(expected); 49 | j.configRoundtrip(builder); 50 | j.assertEqualDataBoundBeans(expected, builder.credentials); 51 | } 52 | 53 | /** 54 | * Helper for {@link #configRoundtrip(JenkinsRule j)}. 55 | */ 56 | public static class CredentialsBuilder extends Builder { 57 | 58 | public final Credentials credentials; 59 | 60 | @DataBoundConstructor 61 | public CredentialsBuilder(Credentials credentials) { 62 | this.credentials = credentials; 63 | } 64 | 65 | @TestExtension 66 | public static class DescriptorImpl extends BuildStepDescriptor { 67 | 68 | @NonNull 69 | @Override 70 | public String getDisplayName() { 71 | return "CredentialsBuilder"; 72 | } 73 | 74 | @Override 75 | public boolean isApplicable(Class jobType) { 76 | return true; 77 | } 78 | 79 | } 80 | 81 | } 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/services/org.jenkinsci.plugin.gitea.client.spi.GiteaConnectionFactory: -------------------------------------------------------------------------------- 1 | org.jenkinsci.plugin.gitea.client.mock.MockGiteaConnectionFactory 2 | -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/client/impl/branchesResponse.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "commit": { 4 | "added": [ 5 | "string" 6 | ], 7 | "author": { 8 | "email": "user@example.com", 9 | "name": "string", 10 | "username": "string" 11 | }, 12 | "committer": { 13 | "email": "user@example.com", 14 | "name": "string", 15 | "username": "string" 16 | }, 17 | "id": "string", 18 | "message": "string", 19 | "modified": [ 20 | "string" 21 | ], 22 | "removed": [ 23 | "string" 24 | ], 25 | "timestamp": "2021-09-17T08:25:50.169Z", 26 | "url": "string", 27 | "verification": { 28 | "payload": "string", 29 | "reason": "string", 30 | "signature": "string", 31 | "signer": { 32 | "email": "user@example.com", 33 | "name": "string", 34 | "username": "string" 35 | }, 36 | "verified": true 37 | } 38 | }, 39 | "effective_branch_protection_name": "string", 40 | "enable_status_check": true, 41 | "name": "string", 42 | "protected": true, 43 | "required_approvals": 0, 44 | "status_check_contexts": [ 45 | "string" 46 | ], 47 | "user_can_merge": true, 48 | "user_can_push": true 49 | } 50 | ] -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/client/impl/commitStatusResponse.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "context": "string", 4 | "created_at": "2021-09-17T07:51:33.446Z", 5 | "creator": { 6 | "active": true, 7 | "avatar_url": "string", 8 | "created": "2021-09-17T07:51:33.446Z", 9 | "description": "string", 10 | "email": "user@example.com", 11 | "followers_count": 0, 12 | "following_count": 0, 13 | "full_name": "string", 14 | "id": 0, 15 | "is_admin": true, 16 | "language": "string", 17 | "last_login": "2021-09-17T07:51:33.446Z", 18 | "location": "string", 19 | "login": "string", 20 | "prohibit_login": true, 21 | "restricted": true, 22 | "starred_repos_count": 0, 23 | "visibility": "string", 24 | "website": "string" 25 | }, 26 | "description": "string", 27 | "id": 0, 28 | "status": "string", 29 | "target_url": "string", 30 | "updated_at": "2021-09-17T07:51:33.446Z", 31 | "url": "string" 32 | } 33 | ] -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/client/impl/hooksResponse.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "active": true, 4 | "config": { 5 | 6 | }, 7 | "created_at": "2021-09-17T07:43:00.781Z", 8 | "events": [ 9 | "string" 10 | ], 11 | "id": 0, 12 | "type": "string", 13 | "updated_at": "2021-09-17T07:43:00.781Z" 14 | } 15 | ] -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/client/impl/issuesResponse.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "assignee": { 4 | "active": true, 5 | "avatar_url": "string", 6 | "created": "2021-09-17T08:16:39.554Z", 7 | "description": "string", 8 | "email": "user@example.com", 9 | "followers_count": 0, 10 | "following_count": 0, 11 | "full_name": "string", 12 | "id": 0, 13 | "is_admin": true, 14 | "language": "string", 15 | "last_login": "2021-09-17T08:16:39.554Z", 16 | "location": "string", 17 | "login": "string", 18 | "prohibit_login": true, 19 | "restricted": true, 20 | "starred_repos_count": 0, 21 | "visibility": "string", 22 | "website": "string" 23 | }, 24 | "assignees": [ 25 | { 26 | "active": true, 27 | "avatar_url": "string", 28 | "created": "2021-09-17T08:16:39.554Z", 29 | "description": "string", 30 | "email": "user@example.com", 31 | "followers_count": 0, 32 | "following_count": 0, 33 | "full_name": "string", 34 | "id": 0, 35 | "is_admin": true, 36 | "language": "string", 37 | "last_login": "2021-09-17T08:16:39.554Z", 38 | "location": "string", 39 | "login": "string", 40 | "prohibit_login": true, 41 | "restricted": true, 42 | "starred_repos_count": 0, 43 | "visibility": "string", 44 | "website": "string" 45 | } 46 | ], 47 | "body": "string", 48 | "closed_at": "2021-09-17T08:16:39.554Z", 49 | "comments": 0, 50 | "created_at": "2021-09-17T08:16:39.554Z", 51 | "due_date": "2021-09-17T08:16:39.554Z", 52 | "html_url": "string", 53 | "id": 0, 54 | "is_locked": true, 55 | "labels": [ 56 | { 57 | "color": "00aabb", 58 | "description": "string", 59 | "id": 0, 60 | "name": "string", 61 | "url": "string" 62 | } 63 | ], 64 | "milestone": { 65 | "closed_at": "2021-09-17T08:16:39.554Z", 66 | "closed_issues": 0, 67 | "created_at": "2021-09-17T08:16:39.554Z", 68 | "description": "string", 69 | "due_on": "2021-09-17T08:16:39.554Z", 70 | "id": 0, 71 | "open_issues": 0, 72 | "state": "string", 73 | "title": "string", 74 | "updated_at": "2021-09-17T08:16:39.554Z" 75 | }, 76 | "number": 0, 77 | "original_author": "string", 78 | "original_author_id": 0, 79 | "pull_request": { 80 | "merged": true, 81 | "merged_at": "2021-09-17T08:16:39.554Z" 82 | }, 83 | "ref": "string", 84 | "repository": { 85 | "full_name": "string", 86 | "id": 0, 87 | "name": "string", 88 | "owner": "string" 89 | }, 90 | "state": "string", 91 | "title": "string", 92 | "updated_at": "2021-09-17T08:16:39.554Z", 93 | "url": "string", 94 | "user": { 95 | "active": true, 96 | "avatar_url": "string", 97 | "created": "2021-09-17T08:16:39.554Z", 98 | "description": "string", 99 | "email": "user@example.com", 100 | "followers_count": 0, 101 | "following_count": 0, 102 | "full_name": "string", 103 | "id": 0, 104 | "is_admin": true, 105 | "language": "string", 106 | "last_login": "2021-09-17T08:16:39.555Z", 107 | "location": "string", 108 | "login": "string", 109 | "prohibit_login": true, 110 | "restricted": true, 111 | "starred_repos_count": 0, 112 | "visibility": "string", 113 | "website": "string" 114 | } 115 | } 116 | ] -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/client/impl/pullRequestsResponse.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "context": "string", 4 | "created_at": "2021-09-17T07:54:36.713Z", 5 | "creator": { 6 | "active": true, 7 | "avatar_url": "string", 8 | "created": "2021-09-17T07:54:36.713Z", 9 | "description": "string", 10 | "email": "user@example.com", 11 | "followers_count": 0, 12 | "following_count": 0, 13 | "full_name": "string", 14 | "id": 0, 15 | "is_admin": true, 16 | "language": "string", 17 | "last_login": "2021-09-17T07:54:36.713Z", 18 | "location": "string", 19 | "login": "string", 20 | "prohibit_login": true, 21 | "restricted": true, 22 | "starred_repos_count": 0, 23 | "visibility": "string", 24 | "website": "string" 25 | }, 26 | "description": "string", 27 | "id": 0, 28 | "status": "string", 29 | "target_url": "string", 30 | "updated_at": "2021-09-17T07:54:36.713Z", 31 | "url": "string" 32 | } 33 | ] -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/client/impl/repoResponse.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "allow_merge_commits": true, 4 | "allow_rebase": true, 5 | "allow_rebase_explicit": true, 6 | "allow_squash_merge": true, 7 | "archived": true, 8 | "avatar_url": "string", 9 | "clone_url": "string", 10 | "created_at": "2021-09-17T08:56:05.122Z", 11 | "default_branch": "string", 12 | "default_merge_style": "string", 13 | "description": "string", 14 | "empty": true, 15 | "external_tracker": { 16 | "external_tracker_format": "string", 17 | "external_tracker_style": "string", 18 | "external_tracker_url": "string" 19 | }, 20 | "external_wiki": { 21 | "external_wiki_url": "string" 22 | }, 23 | "fork": true, 24 | "forks_count": 0, 25 | "full_name": "string", 26 | "has_issues": true, 27 | "has_projects": true, 28 | "has_pull_requests": true, 29 | "has_wiki": true, 30 | "html_url": "string", 31 | "id": 0, 32 | "ignore_whitespace_conflicts": true, 33 | "internal": true, 34 | "internal_tracker": { 35 | "allow_only_contributors_to_track_time": true, 36 | "enable_issue_dependencies": true, 37 | "enable_time_tracker": true 38 | }, 39 | "mirror": true, 40 | "mirror_interval": "string", 41 | "name": "string", 42 | "open_issues_count": 0, 43 | "open_pr_counter": 0, 44 | "original_url": "string", 45 | "owner": { 46 | "active": true, 47 | "avatar_url": "string", 48 | "created": "2021-09-17T08:56:05.122Z", 49 | "description": "string", 50 | "email": "user@example.com", 51 | "followers_count": 0, 52 | "following_count": 0, 53 | "full_name": "string", 54 | "id": 0, 55 | "is_admin": true, 56 | "language": "string", 57 | "last_login": "2021-09-17T08:56:05.122Z", 58 | "location": "string", 59 | "login": "string", 60 | "prohibit_login": true, 61 | "restricted": true, 62 | "starred_repos_count": 0, 63 | "visibility": "string", 64 | "website": "string" 65 | }, 66 | "parent": null, 67 | "permissions": { 68 | "admin": true, 69 | "pull": true, 70 | "push": true 71 | }, 72 | "private": true, 73 | "release_counter": 0, 74 | "size": 0, 75 | "ssh_url": "string", 76 | "stars_count": 0, 77 | "template": true, 78 | "updated_at": "2021-09-17T08:56:05.122Z", 79 | "watchers_count": 0, 80 | "website": "string" 81 | } 82 | ] -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/client/impl/tagsResponse.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "commit": { 4 | "created": "2021-09-17T08:24:25.249Z", 5 | "sha": "string", 6 | "url": "string" 7 | }, 8 | "id": "string", 9 | "message": "string", 10 | "name": "string", 11 | "tarball_url": "string", 12 | "zipball_url": "string" 13 | } 14 | ] -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/client/impl/usersResponse.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "active": true, 4 | "avatar_url": "string", 5 | "created": "2021-09-17T08:44:48.204Z", 6 | "description": "string", 7 | "email": "user@example.com", 8 | "followers_count": 0, 9 | "following_count": 0, 10 | "full_name": "string", 11 | "id": 0, 12 | "is_admin": true, 13 | "language": "string", 14 | "last_login": "2021-09-17T08:44:48.204Z", 15 | "location": "string", 16 | "login": "string", 17 | "prohibit_login": true, 18 | "restricted": true, 19 | "starred_repos_count": 0, 20 | "visibility": "string", 21 | "website": "string" 22 | } 23 | ] -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/credentials/PersonalAccessTokenImplTest/CredentialsBuilder/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/rawchangelog: -------------------------------------------------------------------------------- 1 | commit 396fc230a3db05c427737aa5c2eb7856ba72b05d 2 | tree 196333547f8b9a5fcc8b1fffe4accb01da42c5a6 3 | parent f28f125f4cc3e5f6a32daee6a26f36f7b788b8ff 4 | author Mirko Friedenhagen 1277411790 +0200 5 | committer Mirko Friedenhagen 1277411790 +0200 6 | 7 | Github seems to have no URL for deleted files, so just return a difflink instead. 8 | 9 | :100644 100644 3f28ad75f5ecd5e0ea9659362e2eef18951bd451 2e0756cd853dccac638486d6aab0e74bc2ef4041 M src/main/java/hudson/plugins/git/browser/GithubWeb.java 10 | :100644 100644 019d377767702b6c572fa4ae97c982e02dcd76ff 7c89764ba7a51c23e809b24376d90d7d06337434 M src/test/java/hudson/plugins/git/browser/GithubWebTest.java 11 | :000000 100644 0000000000000000000000000000000000000000 885ce99421b3ae3a413a5c7fb0cdf9ec477d3f64 A src/test/resources/hudson/plugins/git/browser/rawchangelog-with-deleted-file 12 | -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugin/gitea/rawchangelog-with-deleted-file: -------------------------------------------------------------------------------- 1 | commit fc029da233f161c65eb06d0f1ed4f36ae81d1f4f 2 | tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 3 | parent b547aa10c3f06710c6fdfcdb2a9149c81662923b 4 | author Mirko Friedenhagen 1277410107 +0200 5 | committer Mirko Friedenhagen 1277410107 +0200 6 | 7 | Delete file 8 | 9 | :100644 000000 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 0000000000000000000000000000000000000000 D bar 10 | --------------------------------------------------------------------------------