From 2c5e83f5d0c86478f6e354238eb11c08fbb91654 Mon Sep 17 00:00:00 2001 From: yashin Date: Wed, 25 Jul 2018 16:06:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E8=87=AA=E5=8A=A8=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E7=9A=84PR=E4=B8=8D=E8=A7=A6=E5=8F=91=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=EF=BC=8C=E4=B8=94=E5=8F=91=E9=80=81=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=88=B0PR=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 320 ------------------ README.md | 12 +- pom.xml | 2 +- .../com/gitee/jenkins/cause/CauseData.java | 142 ++++---- .../connection/GiteeConnectionProperty.java | 9 + .../gitee/jenkins/gitee/api/GiteeClient.java | 4 +- .../jenkins/gitee/api/impl/GiteeApiProxy.java | 4 +- .../gitee/api/impl/GiteeV5ApiProxy.java | 4 +- .../gitee/api/impl/GiteeV5ClientBuilder.java | 8 +- .../gitee/api/impl/ResteasyGiteeClient.java | 15 +- .../api/impl/ResteasyGiteeClientBuilder.java | 10 +- .../gitee/jenkins/gitee/api/model/Label.java | 16 +- .../{MergeRequest.java => PullRequest.java} | 45 ++- .../jenkins/gitee/hook/model/NoteHook.java | 16 +- ...eRequestHook.java => PullRequestHook.java} | 16 +- ...equestLabel.java => PullRequestLabel.java} | 4 +- ....java => PullRequestObjectAttributes.java} | 12 +- ...a => GiteeAcceptPullRequestPublisher.java} | 18 +- .../publisher/GiteeMessagePublisher.java | 35 +- ...Notifier.java => PullRequestNotifier.java} | 16 +- .../jenkins/trigger/GiteePushTrigger.java | 200 ++++++----- .../MergeRequestLabelFilterFactory.java | 17 - ...er.java => NopPullRequestLabelFilter.java} | 4 +- ...ilter.java => PullRequestLabelFilter.java} | 4 +- ...java => PullRequestLabelFilterConfig.java} | 8 +- .../filter/PullRequestLabelFilterFactory.java | 17 + ...l.java => PullRequestLabelFilterImpl.java} | 6 +- .../AbstractWebHookTriggerHandler.java | 4 +- .../handler/WebHookTriggerHandler.java | 4 +- .../merge/MergeRequestHookTriggerHandler.java | 9 - ...MergeRequestHookTriggerHandlerFactory.java | 115 ------- .../NopMergeRequestHookTriggerHandler.java | 16 - .../NopPullRequestHookTriggerHandler.java | 16 + .../merge/PullRequestHookTriggerHandler.java | 9 + .../PullRequestHookTriggerHandlerFactory.java | 113 +++++++ ...=> PullRequestHookTriggerHandlerImpl.java} | 93 ++--- .../note/NopNoteHookTriggerHandler.java | 4 +- .../note/NoteHookTriggerHandlerImpl.java | 80 +++-- .../NopPipelineHookTriggerHandler.java | 4 +- .../PipelineHookTriggerHandlerImpl.java | 6 +- .../push/NopPushHookTriggerHandler.java | 4 +- .../push/PushHookTriggerHandlerFactory.java | 6 +- .../push/PushHookTriggerHandlerImpl.java | 20 +- .../push/PushHookTriggerHandlerList.java | 6 +- .../gitee/jenkins/webhook/ActionResolver.java | 4 +- ...ction.java => PullRequestBuildAction.java} | 28 +- ...p.java => AcceptGiteePullRequestStep.java} | 26 +- ...va => AddGiteePullRequestCommentStep.java} | 26 +- .../gitee/jenkins/cause/Messages.properties | 4 +- .../jenkins/cause/Messages_zh_CN.properties | 4 +- .../jenkins/publisher/Messages.properties | 2 +- .../publisher/Messages_zh_CN.properties | 2 +- .../trigger/GiteePushTrigger/config.jelly | 12 +- .../GiteePushTrigger/config.properties | 2 +- src/main/resources/index.jelly | 2 +- src/main/webapp/help/help-noteRegex.html | 4 +- .../help/help-send-result-to-gitee.html | 2 +- .../help/help-send-result-to-gitee_zh_CN.html | 2 +- 58 files changed, 666 insertions(+), 927 deletions(-) delete mode 100644 CHANGELOG.md rename src/main/java/com/gitee/jenkins/gitee/api/model/{MergeRequest.java => PullRequest.java} (83%) rename src/main/java/com/gitee/jenkins/gitee/hook/model/{MergeRequestHook.java => PullRequestHook.java} (86%) rename src/main/java/com/gitee/jenkins/gitee/hook/model/{MergeRequestLabel.java => PullRequestLabel.java} (97%) rename src/main/java/com/gitee/jenkins/gitee/hook/model/{MergeRequestObjectAttributes.java => PullRequestObjectAttributes.java} (92%) rename src/main/java/com/gitee/jenkins/publisher/{GiteeAcceptMergeRequestPublisher.java => GiteeAcceptPullRequestPublisher.java} (66%) rename src/main/java/com/gitee/jenkins/publisher/{MergeRequestNotifier.java => PullRequestNotifier.java} (77%) delete mode 100644 src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterFactory.java rename src/main/java/com/gitee/jenkins/trigger/filter/{NopMergeRequestLabelFilter.java => NopPullRequestLabelFilter.java} (51%) rename src/main/java/com/gitee/jenkins/trigger/filter/{MergeRequestLabelFilter.java => PullRequestLabelFilter.java} (50%) rename src/main/java/com/gitee/jenkins/trigger/filter/{MergeRequestLabelFilterConfig.java => PullRequestLabelFilterConfig.java} (71%) create mode 100644 src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterFactory.java rename src/main/java/com/gitee/jenkins/trigger/filter/{MergeRequestLabelFilterImpl.java => PullRequestLabelFilterImpl.java} (85%) delete mode 100644 src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandler.java delete mode 100644 src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerFactory.java delete mode 100644 src/main/java/com/gitee/jenkins/trigger/handler/merge/NopMergeRequestHookTriggerHandler.java create mode 100644 src/main/java/com/gitee/jenkins/trigger/handler/merge/NopPullRequestHookTriggerHandler.java create mode 100644 src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandler.java create mode 100644 src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandlerFactory.java rename src/main/java/com/gitee/jenkins/trigger/handler/merge/{MergeRequestHookTriggerHandlerImpl.java => PullRequestHookTriggerHandlerImpl.java} (62%) rename src/main/java/com/gitee/jenkins/webhook/build/{MergeRequestBuildAction.java => PullRequestBuildAction.java} (62%) rename src/main/java/com/gitee/jenkins/workflow/{AcceptGiteeMergeRequestStep.java => AcceptGiteePullRequestStep.java} (78%) rename src/main/java/com/gitee/jenkins/workflow/{AddGiteeMergeRequestCommentStep.java => AddGiteePullRequestCommentStep.java} (80%) diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 033850e..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,320 +0,0 @@ -ChangeLog - -1.0 for Gitee plugin -===================== -* change Gitlab to Gitee -* support Gitee api v5 - - -1.5.6 -===================== -* #691: Fix project ID regex to not require '.git' in URLs -* #693: Allow sending 'pending' status when Pipeline jobs are in queue -* #693: Allow canceling of running MR builds when new commits are pushed to the MR -* #759: Fix NPE when saving job config in some cases -* #767: Fix NPE when GitLab pipeline event is received - -1.5.5 -===================== -* #698: Make plugin respect no-proxy-hosts when a proxy is used -* #731: "Build on successful pipeline events" setting does not stay set -* #732: Filtering by label never matches anything - -1.5.4 -===================== -* #714: Fix broken 'Trigger on approved merge requests' setting -* #726: Do not build approved merge requests unless configured to do so - -1.5.3 -===================== -* #622: GitlabCommitStatus throws error after force kill -* #678: Fixes NPE if GitLab connection fails - -1.5.2 -===================== -* #524: If Blue Ocean is installed, build URL in GitLab will point to Blue Ocean -* #564: Build status can now be sent to GitLab from builds downstream of the one that GitLab triggered -* #589: Make it easier to distinguish a commit push from a tag push -* #616: Make it easier to configure gitlab-plugin from Job DSL plugin. -* #639: Don't NPE if one of the filter specs is not specified in a Jenkinsfile -* #658: Send current state of build to GitLab when making commit API calls so it can be seen in the GitLab UI -* #659: Trigger builds when MR is approved in GitLab - -1.5.1 -===================== -* #648: Fix NPE when an MR build is triggered -* #650: Improve GitLab API version autodetection -* #653: Fix unsupported date format in MR trigger -* #656: Fix 404 error when making v4 API calls for MRs - -1.5.0 -===================== -* #614: Add optional support for GitLab API v4 - -1.4.8 -===================== -* #483: If 'Add message for failed builds' feature is used, send the message for both failed and 'unstable' builds -* #514: Fix branch name comparison to avoid spurious builds, fixes issue #512 -* #540: Allow jobs to be triggered by GitLab 'Pipeline' event -* #552: Use GitLab's host url to calculate project's ID - allows Jenkins to work with GitLab projects that are in subgroups (issue #538) -* #567: Plugin should have secure defaults - first-time installs will now have plugin endpoint require auth by default -* #604: Recursively retrieve all BuildData - prevents Jenkins from rebuilding when MR assignee changes (issue #603) - -1.4.7 -===================== -* #584: Fixes commit status exception found in issue #583 - -1.4.6 -===================== -* #508 and #542: Trigger build when merge request has been merged or closed -* #510: Add gitlabMergeRequestTargetProjectId to available variables in builds -* #516: Fix: Trigger for pushes to the destination branch of open merge requests does not work in pipeline scripts -* #532: Allow publishing a comment to the GitLab MR if the build result is 'unstable' -* #543: Matrix/multi-configuration project support -* #544: Add a button to clear the security token in build configuration -* #559: Add a function to (re)set the Gitlab connections for bootstrapping new Jenkins installs -* #562: Fix issue #523 - Build result sent to Pipeline library repo instead of project repo - -1.4.5 -===================== -* #488: Support Declarative Pipeline job syntax -* #503: Don't create spurious 'pending' states in GitLab when updating build status - -1.4.4 -===================== -* #429: Number format is added at merge requests > 1000 -* #447: Token creation throws exception -* #448: When user is not permitted to trigger build there is no information logged -* #455: "HTTP 414 Request-URI Too Long" when posting a large note -* #470: NPE on merge request web hook - -1.4.3 -===================== -* #407: Added Remove-Accept Encoding Filter, to resolve occasional issues with data sent from GitLab - -1.4.2 -===================== -* #408: Multiple branches pushed, Only one job triggered - -1.4.1 -===================== -* #410: `NoStaplerConstructorException` for `addGitLabMRComment` -* Use plugin ClassLoader for the resteasy client instead of the uberClassLoader -* #406: Add include/exclude of merge requests based on gitlab merge request labels -* Add possibility to configure secret tokens per job to allow only web hooks with the correct token to trigger builds -* #415: Add actual trigger phrase as environment variable - -1.4.0 -===================== -* Breaking changes for some Pipeline jobs (see [migration guide](https://github.com/jenkinsci/gitlab-plugin/wiki/Migration-Guides) for more information) -* Cleanup UI for GitLabPushTrigger -* #201: customize notes for merge requsts -* #168: MR Voting Broken after Gitlab 8.2 -* #190: Add option to mark unstable builds as success in GitLab -* #345: Configurable "Add note with build status on merge requests" -* Add Notifier and workflow step for accepting a MR on success -* Add workflow step for adding comments to a MR - -1.3.2 -===================== -* JENKINS-36863: Credentials drop-down doesn't show API token credential! (finally fixed it) -* #402: Web hooks not triggering build in v1.3.1, Jenkins 2.20 -* #404: NullPointerException with gitlab ce 8.11 - -1.3.1 -===================== -* JENKINS-36863: Credentials drop-down doesn't show API token credential! -* #299: Upgrading the plugin sometimes causes loss of configuration -* #382: Outgoing HTTP Proxy support in gitlab-plugin -* #383: Pipeline - "Pending" Jobs for all stages -* #69: Link to gitlab merge request url in getShortDescription posted to jenkins -* #396: Jenkins job stuck publishing build status -* #400: Fix gitlabBuilds step to actually use 'pending' -* JENKINS-35258: ci-skip and author should use the latest commit, not the first one from the push event - -1.3.0 -===================== -* Drop official support for GitLab 7.14 -> no guarantee that new features will work for this version -* #298: Pipeline Multibranch builds are not supported -* #374/JENKINS-36347: Status publisher not updating status when "Merge before build" (git) fails - -1.2.5 -===================== -* #361: Avoid rebuild merge request if assignee changes -* #366: Jenkins can't install plugin - -1.2.4 -===================== -* #332: Find better fitting labels for the supported kind of GitLab credentials in global configuration -* #261: Support [WIP] tag to prevent builds from triggering -* #317: Retried builds are not marked immediately with Gitlab 8.1 -* #306: GitLab [ci-skip] is ignored -* #362: Allow to change build name submitted to GitLab -* Catch client exceptions while retrieving the projectId from GitLab -* #358: Null pointer exception when using 'rebuild open MRs' and GitLab 7.14 -* #364: gitlabCommitStatus: Gitlab in non-root location -* #213: Trigger build by phrase in merge request note -* #282: Authentication not required for /project end-point -* #359: Git repositories in dockerized GitLab cannot be reached from Jenkins when using plugin-provided url parameters -* JENKINS-35538: Update credentials-plugin to version 2.1.0 -* #357: gitlabCommitStatus usage not clear -* #349: Fix NPE when updating commit status -* #342: Timeout when "Add note with build status on merge requests" runs -* Catch also ProcessingExceptions while using the GitLab client -* Change order of steps add note and accept MR -* #335: More tests and refactoring of ActionResolver.onPost - -1.2.3 -===================== -* #294 Fix: Do not trigger a build for remove branch push event -* #246, #290 Add gitlabMergeRequestIid, gitlabSourceNamespace and gitlabTargetNamespace to CauseData and show the correct MR id within the build description -* #281 Fix: Builds not be triggered on tag push events -* #304 Utilizing SpringUtils to safely perform string comparison -* #308 Use the character encoding of the request or UTF-8 if no character encoding is available for decoding the request body of a web hook -* #311 Fix finding related commit of the build -* #312 Fix setting MR IID -* #319: Wrong username in Jenkins build description on push event -* #322 Git push hook namespace compatibility for Gitlab pre ~v8.5 -* #327 Fix to support NameSpace or ProjectName with dot in it -* Update tests for new commit status publisher behavior -* Use HTTP Get instead of HEAD to check for the existence of a commit as workaround for RESTEASY-1347 -* Fix: HTTP 404 error for the rebuild open MRs on push to target branch for forked repositories -* Update list of variables available in builds -* Add notes to README about known Pipeline bugs -* Use ResteasyClientBuilder to configure ignoreCertificateErrors -* Configure connection pooling and timeouts for the client -* Docker: Update Jenkins version to 2.3 -* Readme: Fix contents links -* Readme: Update branch name filtering section -* Readme: Add note on gitlab hook values injection -* Readme: Add known bugs section -* Readme: Note Jenkins parameter security update that can cause problems -* Readme: Explain how to add the GitLab API key as a credential. - -1.2.2 -===================== -* #283 Send thumbs-down icon when build fails -* #284 NullPointerException when using the GitLabCommitStatusPublisher -* Use jenkins credentials-plugin for storing the GitLab API Token -* Clear clients cache if connection config has changed -* Add workflow step that updates the GitLab commit status depending on the build status - -1.2.1 -===================== -* #271 Version 1.2.0 breaks support for Workflow/Pipeline jobs - * **This version of the plugin is incompatible with earlier versions if you are using Pipeline jobs!** You will need to manually change your job configurations. Please see the README section on using the plugin with Pipeline for more information about this. -* #275 Handle GitLab API deprecations >= 8.5.0 - -1.2.0 -===================== -* #217 Inconsistent code formatting -* #212 branch names with non-URL safe characters -* #211 Provide useful values of the Push and MR events as build variables -* #210 Listen for update MR events instead of push events to rebuild open MRs -* #203 Use JAX-RS and resteasy for implementing the GitLab API -* #179 NPE if description of MR event is null -* #175 Retrieve author name from MR event 'last_commit' -* #162 Build status for first push to new branch does not get reported to GitLab -* #159 Utilize "not_found" state for GitLab CI Merge Status page -* #136 gitlabSourceRepoURL from hook request -* #121 Configure GitLab host url and API token at job level -* #77 "Ignore SSL Certificate Errors" has no effect -* #231 Cleanup GitLabWebHook -* #230 Add functionality to configure multiple gitlab connections -* #229 Add publisher to update the commit/merge request status in GitLab -* #228 Cleanup GitLabPushTrigger - -1.1.32 -===================== -* #218 license within pom.xml and LICENSE is different -* #226 Add description to parameters actions -* #216 Fix NPE when author email is not available -* #235 mention required permissions for commit status API -* #225 Enhance README section Contribution -* #236 Fix the usage of CommitStatus -* #215 Fix error "failed to communicate with gitlab server ..." when try to rebuild open MRs - -1.1.30 + 1.1.31 -===================== -* issues with the release plugin - -1.1.29 -===================== -* #127 Added support for the GitLab 8.1 commit API -* #128 Add two variables gitlabUserName and gitlabUserEmail -* #129 Assorted minor fixes for merge requests -* #139 Fix for issue #125: use reponame for branch caching -* #140 Added missing documentation 8.1 CI features -* #141 Refactoring data objects to own package -* #146 Fixed Documentation after #128 -* #149 New feature: Add support for regex based filtering and more -* #151 Update readme to reflect support for the commit status API -* #154 8.1 is now a supported version -* #163 Bugfix for issue #160: allow merge requests to different branches from one commit -* #164 Not reporting build status 8.1+ -* #180 Parameter gitlabMergeRequestTitle is always blank -* #182 Status to canceled instead of failed if Jenkins build is aborted -* #195 Fix NPE if there is no assignee of the MR -* #197 Reorganize README to be more clear about config for different versions of GitLab -* #205 closes #183 Plugin not working with multiple SCM configuration -* #206 Fix Jenkins Workflow support in build trigger code -* #209 Don't ignore push builds when responding to status query - -1.1.28 -===================== -* (#119 - @mfriedenhagen) Add buildUrl in the description of the merge (shown in GitLab) -* (#124 - @jsyrjala) Fix acceptMergeRequestOnSuccess configuration so it stays set, and is disabled by default -* (#127 and #134 - @thommy101) Added support for the GitLab 8.1 commit API -* (#133 - @EmteZogaf) Send commit status on push-triggered merge request build - -1.1.27 -===================== -* (#118 - @christ66) IntelliJ Excludes -* (#117 - @christ66) Ball Color Changed to Result -* (#110 - @kasper-f) Accept Merge Request On Build Succes -* (#106 - @xathien) Null Pointer Error Fix -* (#105 - @jr4) Merge Request Not Built On First Raise - -1.1.26 -===================== -* (#101 - @TomAndrews) Generalise ci-skip -* (#102 - @TomAndrews) Configurable Rebuild Options - -1.1.4 -===================== -* Updated git-plugin dependency to latest version; minimum supported version of Jenkins is now 1.568 -* Rebuild open merge requests after a push to the source branch (configurable parameter) (kasper-f) -* Build page link on Merge Request page redirects to the correct build (zenovich) -* Stop building closed merge requests -* Bug fixes and documentation updates - -1.1.2 -===================== -* Filter source branches (for push requests only) -* Show build status images when Jenkins authentication is on - -1.1.1 -===================== -* Support for Merge Requests from forked repositories -* Selective triggering (Push events and/or Merge Request events) - -1.0.8 -===================== -* Fix images not showing up. (Jotschi) -* Supprting nested groups with CloudBees Plugin (FrantaM) - -1.0.7 -===================== -* Initial Release - -1.0.2 - 1.0.6 -===================== -* Trying to figure out releases - -1.0.1 -===================== -* Changed Parameter names that were used by default by jenkins. - -1.0 -===================== -* Initial Release diff --git a/README.md b/README.md index 710fc5a..0b8586b 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,12 @@ - [Freestyle jobs](#freestyle-jobs-1) - [Advanced features](#advanced-features) - [Branch filtering](#branch-filtering) - - [Add a note to merge requests](#add-a-note-to-merge-requests) + - [Add a note to pull requests](#add-a-note-to-merge-requests) - [Release Workflow](#release-workflow) # Introduction -This plugin allows Gitee to trigger builds in Jenkins when code is committed or merge requests are opened/updated. It can also send build status back to Gitee. +This plugin allows Gitee to trigger builds in Jenkins when code is committed or pull requests are opened/updated. It can also send build status back to Gitee. ### Seeking maintainers @@ -109,7 +109,7 @@ When you configure the plugin to trigger your Jenkins job, by following the inst * Select *Build when a change is pushed to Gitee* * Copy the *Gitee webhook URL* shown in the UI (see [here](#webhook-url) for guidance) * Use the check boxes to trigger builds on *Push Events* and/or *Created Pull Request Events* and/or *Accepted Pull Request Events* and/or *Closed Pull Request Events* - * Optionally use *Rebuild open Pull Requests* to enable re-building open merge requests after a push to the source branch + * Optionally use *Rebuild open Pull Requests* to enable re-building open pull requests after a push to the source branch * If you selected *Rebuild open Pull Requests* other than *None*, check *Comments*, and specify the *Comment for triggering a build*. A new build will be triggered when this phrase appears in a commit comment. In addition to a literal phrase, you can also specify a Java regular expression 2. Configure any other pre build, build or post build actions as necessary 3. Click *Save* to preserve your changes in Jenkins @@ -117,7 +117,7 @@ When you configure the plugin to trigger your Jenkins job, by following the inst ## Build status configuration -You can optionally have your Jenkins jobs send their build status back to Gitee, where it will be displayed in the commit or merge request UI as appropriate. +You can optionally have your Jenkins jobs send their build status back to Gitee, where it will be displayed in the commit or pull request UI as appropriate. ### Freestyle jobs Freestyle jobs can only send build status after the build steps are complete. To do this, choose 'Publish build status to Gitee' from the available 'Post-build actions' in your Jenkins job config. Also make sure you have chosen the appropriate Gitee instance from the 'Gitee connection' dropdown menu, if you have more than one. @@ -130,8 +130,8 @@ Triggers may be filtered based on the branch name, i.e. the build will only be a **Note:** This functionality requires access to Gitee and a git repository url already saved in the project configuration. In other words, when creating a new project, the configuration needs to be saved *once* before being able to add branch filters. For Pipeline jobs, the configuration must be saved *and* the job must be run once before the list is populated. -## Add a note to merge requests -To add a note to Gitee merge requests after the build completes, select 'Add note with build status on Gitee merge requests' from the optional Post-build actions. Optionally, click the 'Advanced' button to customize the content of the note depending on the build result. +## Add a note to pull requests +To add a note to Gitee pull requests after the build completes, select 'Add note with build status on Gitee pull requests' from the optional Post-build actions. Optionally, click the 'Advanced' button to customize the content of the note depending on the build result. # Release Workflow diff --git a/pom.xml b/pom.xml index f7605d2..a3b1b9d 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ gitee 1.0.12-SNAPSHOT Gitee Plugin - This plugin integrates Gitee to Jenkins by faking a Gitee CI Server. This plugin allows Gitee to trigger builds in Jenkins when code is committed or merge requests are opened/updated. It can also send build status back to Gitee. + This plugin integrates Gitee to Jenkins by faking a Gitee CI Server. This plugin allows Gitee to trigger builds in Jenkins when code is committed or pull requests are opened/updated. It can also send build status back to Gitee. https://wiki.jenkins.io/display/JENKINS/Gitee+Plugin hpi diff --git a/src/main/java/com/gitee/jenkins/cause/CauseData.java b/src/main/java/com/gitee/jenkins/cause/CauseData.java index 3f5d06c..1301cda 100644 --- a/src/main/java/com/gitee/jenkins/cause/CauseData.java +++ b/src/main/java/com/gitee/jenkins/cause/CauseData.java @@ -1,6 +1,6 @@ package com.gitee.jenkins.cause; -import com.gitee.jenkins.gitee.api.model.MergeRequest; +import com.gitee.jenkins.gitee.api.model.PullRequest; import hudson.markup.EscapedMarkupFormatter; import jenkins.model.Jenkins; import net.karneim.pojobuilder.GeneratePojoBuilder; @@ -31,14 +31,14 @@ public final class CauseData { private final String sourceRepoUrl; private final String sourceRepoSshUrl; private final String sourceRepoHttpUrl; - private final String mergeRequestTitle; - private final String mergeRequestDescription; - private final Integer mergeRequestId; - private final Integer mergeRequestIid; - private final String mergeRequestState; + private final String pullRequestTitle; + private final String pullRequestDescription; + private final Integer pullRequestId; + private final Integer pullRequestIid; + private final String pullRequestState; private final String mergedByUser; - private final String mergeRequestAssignee; - private final Integer mergeRequestTargetProjectId; + private final String pullRequestAssignee; + private final Integer pullRequestTargetProjectId; private final String targetBranch; private final String targetRepoName; private final String targetNamespace; @@ -63,10 +63,10 @@ public final class CauseData { @GeneratePojoBuilder(withFactoryMethod = "*") CauseData(ActionType actionType, Integer sourceProjectId, Integer targetProjectId, String branch, String sourceBranch, String userName, String userEmail, String sourceRepoHomepage, String sourceRepoName, String sourceNamespace, String sourceRepoUrl, - String sourceRepoSshUrl, String sourceRepoHttpUrl, String mergeRequestTitle, String mergeRequestDescription, Integer mergeRequestId, - Integer mergeRequestIid, Integer mergeRequestTargetProjectId, String targetBranch, String targetRepoName, String targetNamespace, String targetRepoSshUrl, + String sourceRepoSshUrl, String sourceRepoHttpUrl, String pullRequestTitle, String pullRequestDescription, Integer pullRequestId, + Integer pullRequestIid, Integer pullRequestTargetProjectId, String targetBranch, String targetRepoName, String targetNamespace, String targetRepoSshUrl, String targetRepoHttpUrl, String triggeredByUser, String before, String after, String lastCommit, String targetProjectUrl, - String triggerPhrase, String mergeRequestState, String mergedByUser, String mergeRequestAssignee, String ref, String isTag, + String triggerPhrase, String pullRequestState, String mergedByUser, String pullRequestAssignee, String ref, String isTag, String sha, String beforeSha, String status, String stages, String createdAt, String finishedAt, String buildDuration, String pathWithNamespace) { this.actionType = checkNotNull(actionType, "actionType must not be null."); this.sourceProjectId = checkNotNull(sourceProjectId, "sourceProjectId must not be null."); @@ -81,14 +81,14 @@ public final class CauseData { this.sourceRepoUrl = sourceRepoUrl == null ? sourceRepoSshUrl : sourceRepoUrl; this.sourceRepoSshUrl = checkNotNull(sourceRepoSshUrl, "sourceRepoSshUrl must not be null."); this.sourceRepoHttpUrl = checkNotNull(sourceRepoHttpUrl, "sourceRepoHttpUrl must not be null."); - this.mergeRequestTitle = checkNotNull(mergeRequestTitle, "mergeRequestTitle must not be null."); - this.mergeRequestDescription = mergeRequestDescription == null ? "" : mergeRequestDescription; - this.mergeRequestId = mergeRequestId; - this.mergeRequestIid = mergeRequestIid; - this.mergeRequestState = mergeRequestState == null ? "" : mergeRequestState; + this.pullRequestTitle = checkNotNull(pullRequestTitle, "pullRequestTitle must not be null."); + this.pullRequestDescription = pullRequestDescription == null ? "" : pullRequestDescription; + this.pullRequestId = pullRequestId; + this.pullRequestIid = pullRequestIid; + this.pullRequestState = pullRequestState == null ? "" : pullRequestState; this.mergedByUser = mergedByUser == null ? "" : mergedByUser; - this.mergeRequestAssignee = mergeRequestAssignee == null ? "" : mergeRequestAssignee; - this.mergeRequestTargetProjectId = mergeRequestTargetProjectId; + this.pullRequestAssignee = pullRequestAssignee == null ? "" : pullRequestAssignee; + this.pullRequestTargetProjectId = pullRequestTargetProjectId; this.targetBranch = checkNotNull(targetBranch, "targetBranch must not be null."); this.targetRepoName = checkNotNull(targetRepoName, "targetRepoName must not be null."); this.targetNamespace = checkNotNull(targetNamespace, "targetNamespace must not be null."); @@ -97,7 +97,9 @@ public final class CauseData { this.triggeredByUser = checkNotNull(triggeredByUser, "triggeredByUser must not be null."); this.before = before == null ? "" : before; this.after = after == null ? "" : after; - this.lastCommit = checkNotNull(lastCommit, "lastCommit must not be null"); +// this.lastCommit = checkNotNull(lastCommit, "lastCommit must not be null"); + // 直接checkout到分支,而非commit sha,暂时不需要确保lastCommit 非空 + this.lastCommit = lastCommit; this.targetProjectUrl = targetProjectUrl; this.triggerPhrase = triggerPhrase; this.ref = ref; @@ -125,15 +127,15 @@ public final class CauseData { variables.put("giteeSourceRepoURL", sourceRepoUrl); variables.put("giteeSourceRepoSshUrl", sourceRepoSshUrl); variables.put("giteeSourceRepoHttpUrl", sourceRepoHttpUrl); - variables.put("giteeMergeRequestTitle", mergeRequestTitle); - variables.put("giteeMergeRequestDescription", mergeRequestDescription); - variables.put("giteeMergeRequestId", mergeRequestId == null ? "" : mergeRequestId.toString()); - variables.put("giteeMergeRequestIid", mergeRequestIid == null ? "" : mergeRequestIid.toString()); - variables.put("giteeMergeRequestTargetProjectId", mergeRequestTargetProjectId == null ? "" : mergeRequestTargetProjectId.toString()); - variables.put("giteeMergeRequestLastCommit", lastCommit); - variables.putIfNotNull("giteeMergeRequestState", mergeRequestState); + variables.put("giteePullRequestTitle", pullRequestTitle); + variables.put("giteePullRequestDescription", pullRequestDescription); + variables.put("giteePullRequestId", pullRequestId == null ? "" : pullRequestId.toString()); + variables.put("giteePullRequestIid", pullRequestIid == null ? "" : pullRequestIid.toString()); + variables.put("giteePullRequestTargetProjectId", pullRequestTargetProjectId == null ? "" : pullRequestTargetProjectId.toString()); + variables.put("giteePullRequestLastCommit", lastCommit); + variables.putIfNotNull("giteePullRequestState", pullRequestState); variables.putIfNotNull("giteeMergedByUser", mergedByUser); - variables.putIfNotNull("giteeMergeRequestAssignee", mergeRequestAssignee); + variables.putIfNotNull("giteePullRequestAssignee", pullRequestAssignee); variables.put("giteeTargetBranch", targetBranch); variables.put("giteeTargetRepoName", targetRepoName); variables.put("giteeTargetNamespace", targetNamespace); @@ -206,26 +208,26 @@ public final class CauseData { return sourceRepoHttpUrl; } - public String getMergeRequestTitle() { - return mergeRequestTitle; + public String getPullRequestTitle() { + return pullRequestTitle; } - public String getMergeRequestDescription() { - return mergeRequestDescription; + public String getPullRequestDescription() { + return pullRequestDescription; } public String getPathWithNamespace() { return pathWithNamespace; } - public Integer getMergeRequestId() { - return mergeRequestId; + public Integer getPullRequestId() { + return pullRequestId; } - public Integer getMergeRequestIid() { - return mergeRequestIid; + public Integer getPullRequestIid() { + return pullRequestIid; } - public Integer getMergeRequestTargetProjectId() { - return mergeRequestTargetProjectId; + public Integer getPullRequestTargetProjectId() { + return pullRequestTargetProjectId; } public String getTargetBranch() { @@ -291,25 +293,25 @@ public final class CauseData { return actionType.getShortDescription(this); } - public String getMergeRequestState() { - return mergeRequestState; + public String getPullRequestState() { + return pullRequestState; } public String getMergedByUser() { return mergedByUser; } - public String getMergeRequestAssignee() { - return mergeRequestAssignee; + public String getPullRequestAssignee() { + return pullRequestAssignee; } - public MergeRequest getMergeRequest() { - if (mergeRequestId == null) { + public PullRequest getPullRequest() { + if (pullRequestId == null) { return null; } - return new MergeRequest(mergeRequestId, mergeRequestIid, sourceBranch, targetBranch, mergeRequestTitle, - sourceProjectId, targetProjectId, mergeRequestDescription, mergeRequestState, pathWithNamespace); + return new PullRequest(pullRequestId, pullRequestIid, sourceBranch, targetBranch, pullRequestTitle, + sourceProjectId, targetProjectId, pullRequestDescription, pullRequestState, pathWithNamespace); } @Override @@ -335,14 +337,14 @@ public final class CauseData { .append(sourceRepoUrl, causeData.sourceRepoUrl) .append(sourceRepoSshUrl, causeData.sourceRepoSshUrl) .append(sourceRepoHttpUrl, causeData.sourceRepoHttpUrl) - .append(mergeRequestTitle, causeData.mergeRequestTitle) - .append(mergeRequestDescription, causeData.mergeRequestDescription) - .append(mergeRequestId, causeData.mergeRequestId) - .append(mergeRequestIid, causeData.mergeRequestIid) - .append(mergeRequestState, causeData.mergeRequestState) + .append(pullRequestTitle, causeData.pullRequestTitle) + .append(pullRequestDescription, causeData.pullRequestDescription) + .append(pullRequestId, causeData.pullRequestId) + .append(pullRequestIid, causeData.pullRequestIid) + .append(pullRequestState, causeData.pullRequestState) .append(mergedByUser, causeData.mergedByUser) - .append(mergeRequestAssignee, causeData.mergeRequestAssignee) - .append(mergeRequestTargetProjectId, causeData.mergeRequestTargetProjectId) + .append(pullRequestAssignee, causeData.pullRequestAssignee) + .append(pullRequestTargetProjectId, causeData.pullRequestTargetProjectId) .append(targetBranch, causeData.targetBranch) .append(targetRepoName, causeData.targetRepoName) .append(targetNamespace, causeData.targetNamespace) @@ -382,14 +384,14 @@ public final class CauseData { .append(sourceRepoUrl) .append(sourceRepoSshUrl) .append(sourceRepoHttpUrl) - .append(mergeRequestTitle) - .append(mergeRequestDescription) - .append(mergeRequestId) - .append(mergeRequestIid) - .append(mergeRequestState) + .append(pullRequestTitle) + .append(pullRequestDescription) + .append(pullRequestId) + .append(pullRequestIid) + .append(pullRequestState) .append(mergedByUser) - .append(mergeRequestAssignee) - .append(mergeRequestTargetProjectId) + .append(pullRequestAssignee) + .append(pullRequestTargetProjectId) .append(targetBranch) .append(targetRepoName) .append(targetNamespace) @@ -429,14 +431,14 @@ public final class CauseData { .append("sourceRepoUrl", sourceRepoUrl) .append("sourceRepoSshUrl", sourceRepoSshUrl) .append("sourceRepoHttpUrl", sourceRepoHttpUrl) - .append("mergeRequestTitle", mergeRequestTitle) - .append("mergeRequestDescription", mergeRequestDescription) - .append("mergeRequestId", mergeRequestId) - .append("mergeRequestIid", mergeRequestIid) - .append("mergeRequestState", mergeRequestState) + .append("pullRequestTitle", pullRequestTitle) + .append("pullRequestDescription", pullRequestDescription) + .append("pullRequestId", pullRequestId) + .append("pullRequestIid", pullRequestIid) + .append("pullRequestState", pullRequestState) .append("mergedByUser", mergedByUser) - .append("mergeRequestAssignee", mergeRequestAssignee) - .append("mergeRequestTargetProjectId", mergeRequestTargetProjectId) + .append("pullRequestAssignee", pullRequestAssignee) + .append("pullRequestTargetProjectId", pullRequestTargetProjectId) .append("targetBranch", targetBranch) .append("targetRepoName", targetRepoName) .append("targetNamespace", targetNamespace) @@ -476,11 +478,11 @@ public final class CauseData { String getShortDescription(CauseData data) { String forkNamespace = StringUtils.equals(data.getSourceNamespace(), data.getTargetBranch()) ? "" : data.getSourceNamespace() + "/"; if (Jenkins.getActiveInstance().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) { - return Messages.GiteeWebHookCause_ShortDescription_MergeRequestHook_plain(String.valueOf(data.getMergeRequestIid()), + return Messages.GiteeWebHookCause_ShortDescription_PullRequestHook_plain(String.valueOf(data.getPullRequestIid()), forkNamespace + data.getSourceBranch(), data.getTargetBranch()); } else { - return Messages.GiteeWebHookCause_ShortDescription_MergeRequestHook_html(String.valueOf(data.getMergeRequestIid()), + return Messages.GiteeWebHookCause_ShortDescription_PullRequestHook_html(String.valueOf(data.getPullRequestIid()), forkNamespace + data.getSourceBranch(), data.getTargetBranch(), data.getTargetProjectUrl()); @@ -493,12 +495,12 @@ public final class CauseData { String forkNamespace = StringUtils.equals(data.getSourceNamespace(), data.getTargetBranch()) ? "" : data.getSourceNamespace() + "/"; if (Jenkins.getActiveInstance().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) { return Messages.GiteeWebHookCause_ShortDescription_NoteHook_plain(triggeredBy, - String.valueOf(data.getMergeRequestIid()), + String.valueOf(data.getPullRequestIid()), forkNamespace + data.getSourceBranch(), data.getTargetBranch()); } else { return Messages.GiteeWebHookCause_ShortDescription_NoteHook_html(triggeredBy, - String.valueOf(data.getMergeRequestIid()), + String.valueOf(data.getPullRequestIid()), forkNamespace + data.getSourceBranch(), data.getTargetBranch(), data.getTargetProjectUrl()); diff --git a/src/main/java/com/gitee/jenkins/connection/GiteeConnectionProperty.java b/src/main/java/com/gitee/jenkins/connection/GiteeConnectionProperty.java index d53acca..ce985b2 100644 --- a/src/main/java/com/gitee/jenkins/connection/GiteeConnectionProperty.java +++ b/src/main/java/com/gitee/jenkins/connection/GiteeConnectionProperty.java @@ -47,6 +47,15 @@ public class GiteeConnectionProperty extends JobProperty> { return null; } + public static GiteeClient getClient(Job job) { + final GiteeConnectionProperty connectionProperty = job.getProperty(GiteeConnectionProperty.class); + if (connectionProperty != null) { + return connectionProperty.getClient(); + } + return null; + } + + @Extension @Symbol("giteeConnection") public static class DescriptorImpl extends JobPropertyDescriptor { diff --git a/src/main/java/com/gitee/jenkins/gitee/api/GiteeClient.java b/src/main/java/com/gitee/jenkins/gitee/api/GiteeClient.java index 6cea2aa..ef71b2e 100644 --- a/src/main/java/com/gitee/jenkins/gitee/api/GiteeClient.java +++ b/src/main/java/com/gitee/jenkins/gitee/api/GiteeClient.java @@ -5,9 +5,9 @@ import com.gitee.jenkins.gitee.api.model.*; public interface GiteeClient { String getHostUrl(); - void acceptMergeRequest(MergeRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch); + void acceptPullRequest(PullRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch); - void createMergeRequestNote(MergeRequest mr, String body); + void createPullRequestNote(PullRequest mr, String body); User getCurrentUser(); diff --git a/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeApiProxy.java b/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeApiProxy.java index f958e26..b8e015d 100644 --- a/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeApiProxy.java +++ b/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeApiProxy.java @@ -6,8 +6,8 @@ import com.gitee.jenkins.gitee.api.model.*; interface GiteeApiProxy { - void createMergeRequestNote(String owner, String repo, Integer mergeRequestId, String body); + void createPullRequestNote(String owner, String repo, Integer pullRequestId, String body); void headCurrentUser(); - void acceptMergeRequest(String owner, String repo, Integer mergeRequestId); + void acceptPullRequest(String owner, String repo, Integer pullRequestId); User getCurrentUser(); } diff --git a/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeV5ApiProxy.java b/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeV5ApiProxy.java index 0ab6698..c8d49b4 100644 --- a/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeV5ApiProxy.java +++ b/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeV5ApiProxy.java @@ -17,7 +17,7 @@ interface GiteeV5ApiProxy extends GiteeApiProxy { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/repos/{ownerPath}/{repoPath}/pulls/{prNumber}/merge") - void acceptMergeRequest(@PathParam("ownerPath") String ownerPath, + void acceptPullRequest(@PathParam("ownerPath") String ownerPath, @PathParam("repoPath") String repoPath, @PathParam("prNumber") Integer prNumber); @@ -25,7 +25,7 @@ interface GiteeV5ApiProxy extends GiteeApiProxy { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/repos/{ownerPath}/{repoPath}/pulls/{prNumber}/comments") - void createMergeRequestNote(@PathParam("ownerPath") String ownerPath, + void createPullRequestNote(@PathParam("ownerPath") String ownerPath, @PathParam("repoPath") String repoPath, @PathParam("prNumber") Integer prNumber, @FormParam("body") String body); diff --git a/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeV5ClientBuilder.java b/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeV5ClientBuilder.java index 8bd1408..74f62e5 100644 --- a/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeV5ClientBuilder.java +++ b/src/main/java/com/gitee/jenkins/gitee/api/impl/GiteeV5ClientBuilder.java @@ -1,7 +1,7 @@ package com.gitee.jenkins.gitee.api.impl; -import com.gitee.jenkins.gitee.api.model.MergeRequest; +import com.gitee.jenkins.gitee.api.model.PullRequest; import com.google.common.base.Function; import hudson.Extension; import org.kohsuke.accmod.Restricted; @@ -12,10 +12,10 @@ import org.kohsuke.accmod.restrictions.NoExternalUse; @Restricted(NoExternalUse.class) public final class GiteeV5ClientBuilder extends ResteasyGiteeClientBuilder { private static final int ORDINAL = 3; - private static final Function MERGE_REQUEST_ID_PROVIDER = new Function() { + private static final Function MERGE_REQUEST_ID_PROVIDER = new Function() { @Override - public Integer apply(MergeRequest mergeRequest) { - return mergeRequest.getIid(); + public Integer apply(PullRequest pullRequest) { + return pullRequest.getIid(); } }; diff --git a/src/main/java/com/gitee/jenkins/gitee/api/impl/ResteasyGiteeClient.java b/src/main/java/com/gitee/jenkins/gitee/api/impl/ResteasyGiteeClient.java index c2d7d96..a15dab2 100644 --- a/src/main/java/com/gitee/jenkins/gitee/api/impl/ResteasyGiteeClient.java +++ b/src/main/java/com/gitee/jenkins/gitee/api/impl/ResteasyGiteeClient.java @@ -9,12 +9,13 @@ import com.google.common.base.Function; final class ResteasyGiteeClient implements GiteeClient { private final String hostUrl; private final GiteeApiProxy api; - private final Function mergeRequestIdProvider; + private final Function pullRequestIdProvider; - ResteasyGiteeClient(String hostUrl, GiteeApiProxy api, Function mergeRequestIdProvider) { + + ResteasyGiteeClient(String hostUrl, GiteeApiProxy api, Function pullRequestIdProvider) { this.hostUrl = hostUrl; this.api = api; - this.mergeRequestIdProvider = mergeRequestIdProvider; + this.pullRequestIdProvider = pullRequestIdProvider; } @Override @@ -24,13 +25,13 @@ final class ResteasyGiteeClient implements GiteeClient { // Gitee v5 don't support commit message and remove source branch @Override - public void acceptMergeRequest(MergeRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch) { - api.acceptMergeRequest(mr.getRepoOwner(), mr.getRepoPath(), mergeRequestIdProvider.apply(mr)); + public void acceptPullRequest(PullRequest mr, String mergeCommitMessage, boolean shouldRemoveSourceBranch) { + api.acceptPullRequest(mr.getRepoOwner(), mr.getRepoPath(), mr.getIid()); } @Override - public void createMergeRequestNote(MergeRequest mr, String body) { - api.createMergeRequestNote(mr.getRepoOwner(), mr.getRepoPath(), mergeRequestIdProvider.apply(mr), body); + public void createPullRequestNote(PullRequest mr, String body) { + api.createPullRequestNote(mr.getRepoOwner(), mr.getRepoPath(), mr.getIid(), body); } @Override diff --git a/src/main/java/com/gitee/jenkins/gitee/api/impl/ResteasyGiteeClientBuilder.java b/src/main/java/com/gitee/jenkins/gitee/api/impl/ResteasyGiteeClientBuilder.java index 24e9134..e2a432b 100644 --- a/src/main/java/com/gitee/jenkins/gitee/api/impl/ResteasyGiteeClientBuilder.java +++ b/src/main/java/com/gitee/jenkins/gitee/api/impl/ResteasyGiteeClientBuilder.java @@ -4,7 +4,7 @@ package com.gitee.jenkins.gitee.api.impl; import com.gitee.jenkins.gitee.JacksonConfig; import com.gitee.jenkins.gitee.api.GiteeClient; import com.gitee.jenkins.gitee.api.GiteeClientBuilder; -import com.gitee.jenkins.gitee.api.model.MergeRequest; +import com.gitee.jenkins.gitee.api.model.PullRequest; import com.gitee.jenkins.util.JsonUtil; import com.gitee.jenkins.util.LoggerUtil; import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; @@ -67,12 +67,12 @@ public class ResteasyGiteeClientBuilder extends GiteeClientBuilder { } private final Class apiProxyClass; - private final Function mergeRequestIdProvider; + private final Function pullRequestIdProvider; - ResteasyGiteeClientBuilder(String id, int ordinal, Class apiProxyClass, Function mergeRequestIdProvider) { + ResteasyGiteeClientBuilder(String id, int ordinal, Class apiProxyClass, Function pullRequestIdProvider) { super(id, ordinal); this.apiProxyClass = apiProxyClass; - this.mergeRequestIdProvider = mergeRequestIdProvider; + this.pullRequestIdProvider = pullRequestIdProvider; } @Nonnull @@ -124,7 +124,7 @@ public class ResteasyGiteeClientBuilder extends GiteeClientBuilder { .classloader(apiProxyClass.getClassLoader()) .build(); - return new ResteasyGiteeClient(url, apiProxy, mergeRequestIdProvider); + return new ResteasyGiteeClient(url, apiProxy, pullRequestIdProvider); } private String getHost(String url) { diff --git a/src/main/java/com/gitee/jenkins/gitee/api/model/Label.java b/src/main/java/com/gitee/jenkins/gitee/api/model/Label.java index 06a788c..69f577d 100644 --- a/src/main/java/com/gitee/jenkins/gitee/api/model/Label.java +++ b/src/main/java/com/gitee/jenkins/gitee/api/model/Label.java @@ -23,7 +23,7 @@ public class Label { private String description; private long openIssuesCount; private long closedIssuesCount; - private long openMergeRequestsCount; + private long openPullRequestsCount; public String getName() { return name; @@ -65,12 +65,12 @@ public class Label { this.closedIssuesCount = closedIssuesCount; } - public long getOpenMergeRequestsCount() { - return openMergeRequestsCount; + public long getOpenPullRequestsCount() { + return openPullRequestsCount; } - public void setOpenMergeRequestsCount(long openMergeRequestsCount) { - this.openMergeRequestsCount = openMergeRequestsCount; + public void setOpenPullRequestsCount(long openPullRequestsCount) { + this.openPullRequestsCount = openPullRequestsCount; } @Override @@ -85,7 +85,7 @@ public class Label { return new EqualsBuilder() .append(openIssuesCount, label.openIssuesCount) .append(closedIssuesCount, label.closedIssuesCount) - .append(openMergeRequestsCount, label.openMergeRequestsCount) + .append(openPullRequestsCount, label.openPullRequestsCount) .append(name, label.name) .append(color, label.color) .append(description, label.description) @@ -100,7 +100,7 @@ public class Label { .append(description) .append(openIssuesCount) .append(closedIssuesCount) - .append(openMergeRequestsCount) + .append(openPullRequestsCount) .toHashCode(); } @@ -112,7 +112,7 @@ public class Label { .append("description", description) .append("openIssuesCount", openIssuesCount) .append("closedIssuesCount", closedIssuesCount) - .append("openMergeRequestsCount", openMergeRequestsCount) + .append("openPullRequestsCount", openPullRequestsCount) .toString(); } } diff --git a/src/main/java/com/gitee/jenkins/gitee/api/model/MergeRequest.java b/src/main/java/com/gitee/jenkins/gitee/api/model/PullRequest.java similarity index 83% rename from src/main/java/com/gitee/jenkins/gitee/api/model/MergeRequest.java rename to src/main/java/com/gitee/jenkins/gitee/api/model/PullRequest.java index fc1c681..35f675f 100644 --- a/src/main/java/com/gitee/jenkins/gitee/api/model/MergeRequest.java +++ b/src/main/java/com/gitee/jenkins/gitee/api/model/PullRequest.java @@ -1,5 +1,6 @@ package com.gitee.jenkins.gitee.api.model; +import com.gitee.jenkins.gitee.hook.model.PullRequestObjectAttributes; import com.gitee.jenkins.gitee.hook.model.State; import net.karneim.pojobuilder.GeneratePojoBuilder; import org.apache.commons.lang.builder.EqualsBuilder; @@ -12,7 +13,7 @@ import java.util.List; * @author Robin Müller */ @GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*") -public class MergeRequest { +public class PullRequest { private Integer id; private Integer iid; private String sourceBranch; @@ -34,11 +35,11 @@ public class MergeRequest { private String repoOwner; private String repoPath; - public MergeRequest() { /* default-constructor for Resteasy-based-api-proxies */ } + public PullRequest() { /* default-constructor for Resteasy-based-api-proxies */ } - public MergeRequest(int id, int iid, String sourceBranch, String targetBranch, String title, - int sourceProjectId, int targetProjectId, - String description, String mergeStatus) { + public PullRequest(int id, int iid, String sourceBranch, String targetBranch, String title, + int sourceProjectId, int targetProjectId, + String description, String mergeStatus) { this.id = id; this.iid= iid; this.sourceBranch = sourceBranch; @@ -50,9 +51,29 @@ public class MergeRequest { this.mergeStatus = mergeStatus; } - public MergeRequest(int id, int iid, String sourceBranch, String targetBranch, String title, - int sourceProjectId, int targetProjectId, - String description, String mergeStatus, String pathWithNamespace) { + public PullRequest(PullRequestObjectAttributes objectAttributes) { + this.id = objectAttributes.getId(); + this.iid= objectAttributes.getNumber(); + this.sourceBranch = objectAttributes.getSourceBranch(); + this.targetBranch = objectAttributes.getTargetBranch(); + this.title = objectAttributes.getTitle(); + this.sourceProjectId = objectAttributes.getSourceProjectId(); + this.projectId = objectAttributes.getTargetProjectId(); + this.description = objectAttributes.getBody(); + this.mergeStatus = objectAttributes.getMergeStatus(); + +// try { + String[] path = objectAttributes.getTarget().getPathWithNamespace().split("/"); + this.repoOwner = path[0]; + this.repoPath = path[1]; +// } catch (Exception e) { +// // do nothing +// } + } + + public PullRequest(int id, int iid, String sourceBranch, String targetBranch, String title, + int sourceProjectId, int targetProjectId, + String description, String mergeStatus, String pathWithNamespace) { this.id = id; this.iid= iid; this.sourceBranch = sourceBranch; @@ -64,10 +85,8 @@ public class MergeRequest { this.mergeStatus = mergeStatus; try { String[] path = pathWithNamespace.split("/"); - String repoOwner = path[0]; - String repoPath = path[1]; - this.repoOwner = repoOwner; - this.repoPath = repoPath; + this.repoOwner = path[0]; + this.repoPath = path[1]; } catch (Exception e) { // do nothing } @@ -241,7 +260,7 @@ public class MergeRequest { if (o == null || getClass() != o.getClass()) { return false; } - MergeRequest that = (MergeRequest) o; + PullRequest that = (PullRequest) o; return new EqualsBuilder() .append(id, that.id) .append(iid, that.iid) diff --git a/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteHook.java b/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteHook.java index da7c9b2..ca3502e 100644 --- a/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteHook.java +++ b/src/main/java/com/gitee/jenkins/gitee/hook/model/NoteHook.java @@ -14,7 +14,7 @@ public class NoteHook extends WebHook { private User user; private Project project; - private MergeRequestObjectAttributes mergeRequest; + private PullRequestObjectAttributes pullRequest; private NoteObjectAttributes objectAttributes; public User getUser() { @@ -41,12 +41,12 @@ public class NoteHook extends WebHook { this.objectAttributes = objectAttributes; } - public MergeRequestObjectAttributes getMergeRequest() { - return mergeRequest; + public PullRequestObjectAttributes getPullRequest() { + return pullRequest; } - public void setMergeRequest(MergeRequestObjectAttributes mergeRequest) { - this.mergeRequest = mergeRequest; + public void setPullRequest(PullRequestObjectAttributes pullRequest) { + this.pullRequest = pullRequest; } @Override @@ -62,7 +62,7 @@ public class NoteHook extends WebHook { .append(user, that.user) .append(project, that.project) .append(objectAttributes, that.objectAttributes) - .append(mergeRequest, that.mergeRequest) + .append(pullRequest, that.pullRequest) .isEquals(); } @@ -72,7 +72,7 @@ public class NoteHook extends WebHook { .append(user) .append(project) .append(objectAttributes) - .append(mergeRequest) + .append(pullRequest) .toHashCode(); } @@ -82,7 +82,7 @@ public class NoteHook extends WebHook { .append("user", user) .append("project", project) .append("objectAttributes", objectAttributes) - .append("mergeRequest", mergeRequest) + .append("pullRequest", pullRequest) .toString(); } } diff --git a/src/main/java/com/gitee/jenkins/gitee/hook/model/MergeRequestHook.java b/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestHook.java similarity index 86% rename from src/main/java/com/gitee/jenkins/gitee/hook/model/MergeRequestHook.java rename to src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestHook.java index 6d4a81a..8d89808 100644 --- a/src/main/java/com/gitee/jenkins/gitee/hook/model/MergeRequestHook.java +++ b/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestHook.java @@ -13,15 +13,15 @@ import java.util.List; * @author Yashin Luo */ @GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*") -public class MergeRequestHook extends WebHook { +public class PullRequestHook extends WebHook { private User user; private User assignee; private Project repo; private Action action; private State state; - private MergeRequestObjectAttributes pullRequest; - private List labels; + private PullRequestObjectAttributes pullRequest; + private List labels; public Action getAction() { return action; @@ -63,19 +63,19 @@ public class MergeRequestHook extends WebHook { this.repo = repo; } - public MergeRequestObjectAttributes getPullRequest() { + public PullRequestObjectAttributes getPullRequest() { return pullRequest; } - public void setPullRequest(MergeRequestObjectAttributes pullRequest) { + public void setPullRequest(PullRequestObjectAttributes pullRequest) { this.pullRequest = pullRequest; } - public List getLabels() { + public List getLabels() { return labels; } - public void setLabels(List labels) { + public void setLabels(List labels) { this.labels = labels; } @@ -91,7 +91,7 @@ public class MergeRequestHook extends WebHook { if (o == null || getClass() != o.getClass()) { return false; } - MergeRequestHook that = (MergeRequestHook) o; + PullRequestHook that = (PullRequestHook) o; return new EqualsBuilder() .append(user, that.user) .append(assignee, that.assignee) diff --git a/src/main/java/com/gitee/jenkins/gitee/hook/model/MergeRequestLabel.java b/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestLabel.java similarity index 97% rename from src/main/java/com/gitee/jenkins/gitee/hook/model/MergeRequestLabel.java rename to src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestLabel.java index a5bba7c..07f628a 100644 --- a/src/main/java/com/gitee/jenkins/gitee/hook/model/MergeRequestLabel.java +++ b/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestLabel.java @@ -11,7 +11,7 @@ import java.util.Date; * @author Benjamin ROBIN */ @GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*") -public class MergeRequestLabel { +public class PullRequestLabel { /* "id": 206, @@ -124,7 +124,7 @@ public class MergeRequestLabel { if (o == null || getClass() != o.getClass()) { return false; } - MergeRequestLabel that = (MergeRequestLabel) o; + PullRequestLabel that = (PullRequestLabel) o; return new EqualsBuilder() .append(id, that.id) .append(title, that.title) diff --git a/src/main/java/com/gitee/jenkins/gitee/hook/model/MergeRequestObjectAttributes.java b/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestObjectAttributes.java similarity index 92% rename from src/main/java/com/gitee/jenkins/gitee/hook/model/MergeRequestObjectAttributes.java rename to src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestObjectAttributes.java index 33183de..5312d70 100644 --- a/src/main/java/com/gitee/jenkins/gitee/hook/model/MergeRequestObjectAttributes.java +++ b/src/main/java/com/gitee/jenkins/gitee/hook/model/PullRequestObjectAttributes.java @@ -1,6 +1,7 @@ package com.gitee.jenkins.gitee.hook.model; import net.karneim.pojobuilder.GeneratePojoBuilder; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; @@ -12,8 +13,11 @@ import java.util.Date; * @author Yashin */ @GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*") -public class MergeRequestObjectAttributes { +public class PullRequestObjectAttributes { + private final static String UNCHECKED = "unchecked"; + private final static String CAN_BE_MERGED = "can_be_merged"; + private final static String CANNOT_BE_MERGED = "cannot_be_merged"; private Integer id; private Integer number; private Integer authorId; @@ -175,6 +179,10 @@ public class MergeRequestObjectAttributes { this.workInProgress = workInProgress; } + public boolean can_be_merged() { + return StringUtils.isNotBlank(mergeCommitSha) && !StringUtils.equals(CANNOT_BE_MERGED, mergeStatus); + } + @Override public boolean equals(Object o) { if (this == o) { @@ -183,7 +191,7 @@ public class MergeRequestObjectAttributes { if (o == null || getClass() != o.getClass()) { return false; } - MergeRequestObjectAttributes that = (MergeRequestObjectAttributes) o; + PullRequestObjectAttributes that = (PullRequestObjectAttributes) o; return new EqualsBuilder() .append(id, that.id) .append(number, that.number) diff --git a/src/main/java/com/gitee/jenkins/publisher/GiteeAcceptMergeRequestPublisher.java b/src/main/java/com/gitee/jenkins/publisher/GiteeAcceptPullRequestPublisher.java similarity index 66% rename from src/main/java/com/gitee/jenkins/publisher/GiteeAcceptMergeRequestPublisher.java rename to src/main/java/com/gitee/jenkins/publisher/GiteeAcceptPullRequestPublisher.java index 0e37a1f..350725c 100644 --- a/src/main/java/com/gitee/jenkins/publisher/GiteeAcceptMergeRequestPublisher.java +++ b/src/main/java/com/gitee/jenkins/publisher/GiteeAcceptPullRequestPublisher.java @@ -2,7 +2,7 @@ package com.gitee.jenkins.publisher; import com.gitee.jenkins.gitee.api.GiteeClient; -import com.gitee.jenkins.gitee.api.model.MergeRequest; +import com.gitee.jenkins.gitee.api.model.PullRequest; import hudson.Extension; import hudson.model.AbstractProject; import hudson.model.Result; @@ -21,11 +21,11 @@ import java.util.logging.Logger; /** * @author Robin Müller */ -public class GiteeAcceptMergeRequestPublisher extends MergeRequestNotifier { - private static final Logger LOGGER = Logger.getLogger(GiteeAcceptMergeRequestPublisher.class.getName()); +public class GiteeAcceptPullRequestPublisher extends PullRequestNotifier { + private static final Logger LOGGER = Logger.getLogger(GiteeAcceptPullRequestPublisher.class.getName()); @DataBoundConstructor - public GiteeAcceptMergeRequestPublisher() { } + public GiteeAcceptPullRequestPublisher() { } public BuildStepMonitor getRequiredMonitorService() { return BuildStepMonitor.NONE; @@ -41,19 +41,19 @@ public class GiteeAcceptMergeRequestPublisher extends MergeRequestNotifier { @Override public String getDisplayName() { - return Messages.GiteeAcceptMergeRequestPublisher_DisplayName(); + return Messages.GiteeAcceptPullRequestPublisher_DisplayName(); } } @Override - protected void perform(Run build, TaskListener listener, GiteeClient client, MergeRequest mergeRequest) { + protected void perform(Run build, TaskListener listener, GiteeClient client, PullRequest pullRequest) { try { if (build.getResult() == Result.SUCCESS) { - client.acceptMergeRequest(mergeRequest, "Merge Request accepted by jenkins build success", false); + client.acceptPullRequest(pullRequest, "Merge Request accepted by jenkins build success", false); } } catch (WebApplicationException | ProcessingException e) { - listener.getLogger().printf("Failed to accept merge request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage()); - LOGGER.log(Level.SEVERE, String.format("Failed to accept merge request for project '%s'", mergeRequest.getProjectId()), e); + listener.getLogger().printf("Failed to accept pull request for project '%s': %s%n", pullRequest.getProjectId(), e.getMessage()); + LOGGER.log(Level.SEVERE, String.format("Failed to accept pull request for project '%s'", pullRequest.getProjectId()), e); } } } diff --git a/src/main/java/com/gitee/jenkins/publisher/GiteeMessagePublisher.java b/src/main/java/com/gitee/jenkins/publisher/GiteeMessagePublisher.java index 1b60c29..c44dde5 100644 --- a/src/main/java/com/gitee/jenkins/publisher/GiteeMessagePublisher.java +++ b/src/main/java/com/gitee/jenkins/publisher/GiteeMessagePublisher.java @@ -2,16 +2,17 @@ package com.gitee.jenkins.publisher; import com.gitee.jenkins.gitee.api.GiteeClient; -import com.gitee.jenkins.gitee.api.model.MergeRequest; +import com.gitee.jenkins.gitee.api.model.PullRequest; +import com.gitee.jenkins.trigger.GiteePushTrigger; import hudson.Extension; import hudson.Util; -import hudson.model.AbstractProject; -import hudson.model.Result; -import hudson.model.Run; -import hudson.model.TaskListener; +import hudson.model.*; import hudson.tasks.BuildStepDescriptor; +import hudson.tasks.Notifier; import hudson.tasks.Publisher; +import hudson.triggers.Trigger; import jenkins.model.Jenkins; +import jenkins.model.ParameterizedJobMixIn; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -26,7 +27,7 @@ import java.util.logging.Logger; /** * @author Nikolay Ustinov */ -public class GiteeMessagePublisher extends MergeRequestNotifier { +public class GiteeMessagePublisher extends PullRequestNotifier { private static final Logger LOGGER = Logger.getLogger(GiteeMessagePublisher.class.getName()); private boolean onlyForFailure = false; private boolean replaceSuccessNote = false; @@ -58,6 +59,20 @@ public class GiteeMessagePublisher extends MergeRequestNotifier { @DataBoundConstructor public GiteeMessagePublisher() { } + public static GiteeMessagePublisher getFromJob(Job job) { + GiteeMessagePublisher publisher = null; + if (job instanceof ParameterizedJobMixIn.ParameterizedJob) { + AbstractProject p = (AbstractProject) job; + Map, Publisher> map = p.getPublishersList().toMap(); + for (Publisher n : map.values()) { + if (n instanceof GiteeMessagePublisher) { + publisher = (GiteeMessagePublisher) n; + } + } + } + return publisher; + } + public boolean isOnlyForFailure() { return onlyForFailure; } @@ -159,14 +174,14 @@ public class GiteeMessagePublisher extends MergeRequestNotifier { } @Override - protected void perform(Run build, TaskListener listener, GiteeClient client, MergeRequest mergeRequest) { + protected void perform(Run build, TaskListener listener, GiteeClient client, PullRequest pullRequest) { try { if (!onlyForFailure || build.getResult() == Result.FAILURE || build.getResult() == Result.UNSTABLE) { - client.createMergeRequestNote(mergeRequest, getNote(build, listener)); + client.createPullRequestNote(pullRequest, getNote(build, listener)); } } catch (WebApplicationException | ProcessingException e) { - listener.getLogger().printf("Failed to add comment on Merge Request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage()); - LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", mergeRequest.getProjectId()), e); + listener.getLogger().printf("Failed to add comment on Merge Request for project '%s': %s%n", pullRequest.getProjectId(), e.getMessage()); + LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", pullRequest.getProjectId()), e); } } diff --git a/src/main/java/com/gitee/jenkins/publisher/MergeRequestNotifier.java b/src/main/java/com/gitee/jenkins/publisher/PullRequestNotifier.java similarity index 77% rename from src/main/java/com/gitee/jenkins/publisher/MergeRequestNotifier.java rename to src/main/java/com/gitee/jenkins/publisher/PullRequestNotifier.java index 3e90c00..b36180a 100644 --- a/src/main/java/com/gitee/jenkins/publisher/MergeRequestNotifier.java +++ b/src/main/java/com/gitee/jenkins/publisher/PullRequestNotifier.java @@ -2,7 +2,7 @@ package com.gitee.jenkins.publisher; import com.gitee.jenkins.cause.GiteeWebHookCause; import com.gitee.jenkins.gitee.api.GiteeClient; -import com.gitee.jenkins.gitee.api.model.MergeRequest; +import com.gitee.jenkins.gitee.api.model.PullRequest; import hudson.Launcher; import hudson.matrix.MatrixAggregatable; import hudson.matrix.MatrixAggregator; @@ -21,7 +21,7 @@ import static com.gitee.jenkins.connection.GiteeConnectionProperty.getClient; /** * @author Robin Müller */ -public abstract class MergeRequestNotifier extends Notifier implements MatrixAggregatable { +public abstract class PullRequestNotifier extends Notifier implements MatrixAggregatable { public BuildStepMonitor getRequiredMonitorService() { return BuildStepMonitor.NONE; } @@ -34,9 +34,9 @@ public abstract class MergeRequestNotifier extends Notifier implements MatrixAgg return true; } - MergeRequest mergeRequest = getMergeRequest(build); - if (mergeRequest != null) { - perform(build, listener, client, mergeRequest); + PullRequest pullRequest = getPullRequest(build); + if (pullRequest != null) { + perform(build, listener, client, pullRequest); } return true; } @@ -51,11 +51,11 @@ public abstract class MergeRequestNotifier extends Notifier implements MatrixAgg }; } - protected abstract void perform(Run build, TaskListener listener, GiteeClient client, MergeRequest mergeRequest); + protected abstract void perform(Run build, TaskListener listener, GiteeClient client, PullRequest pullRequest); - MergeRequest getMergeRequest(Run run) { + PullRequest getPullRequest(Run run) { GiteeWebHookCause cause = run.getCause(GiteeWebHookCause.class); - return cause == null ? null : cause.getData().getMergeRequest(); + return cause == null ? null : cause.getData().getPullRequest(); } } diff --git a/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java b/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java index e6cac6a..00b947c 100644 --- a/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java +++ b/src/main/java/com/gitee/jenkins/trigger/GiteePushTrigger.java @@ -4,19 +4,15 @@ package com.gitee.jenkins.trigger; import com.gitee.jenkins.connection.GiteeConnection; import com.gitee.jenkins.connection.GiteeConnectionConfig; import com.gitee.jenkins.connection.GiteeConnectionProperty; -import com.gitee.jenkins.gitee.hook.model.MergeRequestHook; +import com.gitee.jenkins.gitee.hook.model.PullRequestHook; import com.gitee.jenkins.gitee.hook.model.NoteHook; import com.gitee.jenkins.gitee.hook.model.PipelineHook; import com.gitee.jenkins.gitee.hook.model.PushHook; -import com.gitee.jenkins.publisher.GiteeAcceptMergeRequestPublisher; +import com.gitee.jenkins.publisher.GiteeAcceptPullRequestPublisher; import com.gitee.jenkins.publisher.GiteeMessagePublisher; -import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.BranchFilterFactory; -import com.gitee.jenkins.trigger.filter.BranchFilterType; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilterConfig; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilterFactory; -import com.gitee.jenkins.trigger.handler.merge.MergeRequestHookTriggerHandler; +import com.gitee.jenkins.trigger.filter.*; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilterConfig; +import com.gitee.jenkins.trigger.handler.merge.PullRequestHookTriggerHandler; import com.gitee.jenkins.trigger.handler.note.NoteHookTriggerHandler; import com.gitee.jenkins.trigger.handler.pipeline.PipelineHookTriggerHandler; import com.gitee.jenkins.trigger.handler.push.PushHookTriggerHandler; @@ -51,7 +47,7 @@ import java.io.ObjectStreamException; import java.security.SecureRandom; import static com.gitee.jenkins.trigger.filter.BranchFilterConfig.BranchFilterConfigBuilder.branchFilterConfig; -import static com.gitee.jenkins.trigger.handler.merge.MergeRequestHookTriggerHandlerFactory.newMergeRequestHookTriggerHandler; +import static com.gitee.jenkins.trigger.handler.merge.PullRequestHookTriggerHandlerFactory.newPullRequestHookTriggerHandler; import static com.gitee.jenkins.trigger.handler.note.NoteHookTriggerHandlerFactory.newNoteHookTriggerHandler; import static com.gitee.jenkins.trigger.handler.pipeline.PipelineHookTriggerHandlerFactory.newPipelineHookTriggerHandler; import static com.gitee.jenkins.trigger.handler.push.PushHookTriggerHandlerFactory.newPushHookTriggerHandler; @@ -69,82 +65,82 @@ public class GiteePushTrigger extends Trigger> { private static final SecureRandom RANDOM = new SecureRandom(); private boolean triggerOnPush = true; - private boolean triggerOnOpenMergeRequest = true; + private boolean triggerOnOpenPullRequest = true; private boolean triggerOnPipelineEvent = false; - private boolean triggerOnAcceptedMergeRequest = false; - private boolean triggerOnUpdateMergeRequest = false; - private boolean triggerOnClosedMergeRequest = false; - private boolean triggerOnApprovedMergeRequest = false; - private boolean triggerOnTestedMergeRequest = false; + private boolean triggerOnAcceptedPullRequest = false; + private boolean triggerOnUpdatePullRequest = false; + private boolean triggerOnClosedPullRequest = false; + private boolean triggerOnApprovedPullRequest = false; + private boolean triggerOnTestedPullRequest = false; private boolean triggerOnNoteRequest = true; private String noteRegex = ""; private boolean ciSkip = true; - private boolean skipWorkInProgressMergeRequest; + private boolean skipWorkInProgressPullRequest; private boolean skipLastCommitHasBeenBuild; private boolean setBuildDescription = true; - private transient boolean addNoteOnMergeRequest; + private transient boolean addNoteOnPullRequest; private transient boolean addCiMessage; - private transient boolean addVoteOnMergeRequest; + private transient boolean addVoteOnPullRequest; private transient boolean allowAllBranches = false; private transient String branchFilterName; private BranchFilterType branchFilterType; private String includeBranchesSpec; private String excludeBranchesSpec; private String targetBranchRegex; - private MergeRequestLabelFilterConfig mergeRequestLabelFilterConfig; + private PullRequestLabelFilterConfig pullRequestLabelFilterConfig; private volatile Secret secretToken; private String pendingBuildName; private boolean cancelPendingBuildsOnUpdate; private transient BranchFilter branchFilter; private transient PushHookTriggerHandler pushHookTriggerHandler; - private transient MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler; + private transient PullRequestHookTriggerHandler pullRequestHookTriggerHandler; private transient NoteHookTriggerHandler noteHookTriggerHandler; private transient PipelineHookTriggerHandler pipelineTriggerHandler; - private transient boolean acceptMergeRequestOnSuccess; - private transient MergeRequestLabelFilter mergeRequestLabelFilter; + private transient boolean acceptPullRequestOnSuccess; + private transient PullRequestLabelFilter pullRequestLabelFilter; /** * @deprecated use {@link #GiteePushTrigger()} with setters to configure an instance of this class. */ @Deprecated @GeneratePojoBuilder(intoPackage = "*.builder.generated", withFactoryMethod = "*") - public GiteePushTrigger(boolean triggerOnPush, boolean triggerOnOpenMergeRequest, boolean triggerOnUpdateMergeRequest, boolean triggerOnAcceptedMergeRequest, boolean triggerOnClosedMergeRequest, + public GiteePushTrigger(boolean triggerOnPush, boolean triggerOnOpenPullRequest, boolean triggerOnUpdatePullRequest, boolean triggerOnAcceptedPullRequest, boolean triggerOnClosedPullRequest, boolean triggerOnNoteRequest, String noteRegex, - boolean skipWorkInProgressMergeRequest, boolean ciSkip, - boolean setBuildDescription, boolean addNoteOnMergeRequest, boolean addCiMessage, boolean addVoteOnMergeRequest, - boolean acceptMergeRequestOnSuccess, BranchFilterType branchFilterType, + boolean skipWorkInProgressPullRequest, boolean ciSkip, + boolean setBuildDescription, boolean addNoteOnPullRequest, boolean addCiMessage, boolean addVoteOnPullRequest, + boolean acceptPullRequestOnSuccess, BranchFilterType branchFilterType, String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex, - MergeRequestLabelFilterConfig mergeRequestLabelFilterConfig, String secretToken, boolean triggerOnPipelineEvent, - boolean triggerOnApprovedMergeRequest, String pendingBuildName, boolean cancelPendingBuildsOnUpdate) { + PullRequestLabelFilterConfig pullRequestLabelFilterConfig, String secretToken, boolean triggerOnPipelineEvent, + boolean triggerOnApprovedPullRequest, String pendingBuildName, boolean cancelPendingBuildsOnUpdate) { this.triggerOnPush = triggerOnPush; - this.triggerOnOpenMergeRequest = triggerOnOpenMergeRequest; - this.triggerOnUpdateMergeRequest = triggerOnUpdateMergeRequest; - this.triggerOnAcceptedMergeRequest = triggerOnAcceptedMergeRequest; - this.triggerOnClosedMergeRequest = triggerOnClosedMergeRequest; + this.triggerOnOpenPullRequest = triggerOnOpenPullRequest; + this.triggerOnUpdatePullRequest = triggerOnUpdatePullRequest; + this.triggerOnAcceptedPullRequest = triggerOnAcceptedPullRequest; + this.triggerOnClosedPullRequest = triggerOnClosedPullRequest; this.triggerOnNoteRequest = triggerOnNoteRequest; this.noteRegex = noteRegex; this.triggerOnPipelineEvent = triggerOnPipelineEvent; this.ciSkip = ciSkip; - this.skipWorkInProgressMergeRequest = skipWorkInProgressMergeRequest; + this.skipWorkInProgressPullRequest = skipWorkInProgressPullRequest; this.setBuildDescription = setBuildDescription; - this.addNoteOnMergeRequest = addNoteOnMergeRequest; + this.addNoteOnPullRequest = addNoteOnPullRequest; this.addCiMessage = addCiMessage; - this.addVoteOnMergeRequest = addVoteOnMergeRequest; + this.addVoteOnPullRequest = addVoteOnPullRequest; this.branchFilterType = branchFilterType; this.includeBranchesSpec = includeBranchesSpec; this.excludeBranchesSpec = excludeBranchesSpec; this.targetBranchRegex = targetBranchRegex; - this.acceptMergeRequestOnSuccess = acceptMergeRequestOnSuccess; - this.mergeRequestLabelFilterConfig = mergeRequestLabelFilterConfig; + this.acceptPullRequestOnSuccess = acceptPullRequestOnSuccess; + this.pullRequestLabelFilterConfig = pullRequestLabelFilterConfig; this.secretToken = Secret.fromString(secretToken); - this.triggerOnApprovedMergeRequest = triggerOnApprovedMergeRequest; + this.triggerOnApprovedPullRequest = triggerOnApprovedPullRequest; this.pendingBuildName = pendingBuildName; this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate; initializeTriggerHandler(); initializeBranchFilter(); - initializeMergeRequestLabelFilter(); + initializePullRequestLabelFilter(); } @DataBoundConstructor @@ -180,11 +176,11 @@ public class GiteePushTrigger extends Trigger> { for (AbstractProject project : Jenkins.getInstance().getAllItems(AbstractProject.class)) { GiteePushTrigger trigger = project.getTrigger(GiteePushTrigger.class); if (trigger != null) { - if (trigger.addNoteOnMergeRequest) { + if (trigger.addNoteOnPullRequest) { project.getPublishersList().add(new GiteeMessagePublisher()); } - if (trigger.acceptMergeRequestOnSuccess) { - project.getPublishersList().add(new GiteeAcceptMergeRequestPublisher()); + if (trigger.acceptPullRequestOnSuccess) { + project.getPublishersList().add(new GiteeAcceptPullRequestPublisher()); } project.save(); } @@ -194,32 +190,34 @@ public class GiteePushTrigger extends Trigger> { } } + public boolean getAddNoteOnPullRequest() { return addNoteOnPullRequest; } + public boolean getTriggerOnPush() { return triggerOnPush; } - public boolean getTriggerOnOpenMergeRequest() { - return triggerOnOpenMergeRequest; + public boolean getTriggerOnOpenPullRequest() { + return triggerOnOpenPullRequest; } - public boolean getTriggerOnTestedMergeRequest() { - return triggerOnTestedMergeRequest; + public boolean getTriggerOnTestedPullRequest() { + return triggerOnTestedPullRequest; } - public boolean getTriggerOnUpdateMergeRequest() { - return triggerOnUpdateMergeRequest; + public boolean getTriggerOnUpdatePullRequest() { + return triggerOnUpdatePullRequest; } - public boolean isTriggerOnAcceptedMergeRequest() { - return triggerOnAcceptedMergeRequest; + public boolean isTriggerOnAcceptedPullRequest() { + return triggerOnAcceptedPullRequest; } - public boolean isTriggerOnApprovedMergeRequest() { - return triggerOnApprovedMergeRequest; + public boolean isTriggerOnApprovedPullRequest() { + return triggerOnApprovedPullRequest; } - public boolean isTriggerOnClosedMergeRequest() { - return triggerOnClosedMergeRequest; + public boolean isTriggerOnClosedPullRequest() { + return triggerOnClosedPullRequest; } public boolean getTriggerOnNoteRequest() { @@ -244,8 +242,8 @@ public class GiteePushTrigger extends Trigger> { return skipLastCommitHasBeenBuild; } - public boolean isSkipWorkInProgressMergeRequest() { - return skipWorkInProgressMergeRequest; + public boolean isSkipWorkInProgressPullRequest() { + return skipWorkInProgressPullRequest; } public boolean isSkipLastCommitHasBuild() { @@ -268,8 +266,8 @@ public class GiteePushTrigger extends Trigger> { return targetBranchRegex; } - public MergeRequestLabelFilterConfig getMergeRequestLabelFilterConfig() { - return mergeRequestLabelFilterConfig; + public PullRequestLabelFilterConfig getPullRequestLabelFilterConfig() { + return pullRequestLabelFilterConfig; } public String getSecretToken() { @@ -290,28 +288,28 @@ public class GiteePushTrigger extends Trigger> { } @DataBoundSetter - public void setTriggerOnApprovedMergeRequest(boolean triggerOnApprovedMergeRequest) { - this.triggerOnApprovedMergeRequest = triggerOnApprovedMergeRequest; + public void setTriggerOnApprovedPullRequest(boolean triggerOnApprovedPullRequest) { + this.triggerOnApprovedPullRequest = triggerOnApprovedPullRequest; } @DataBoundSetter - public void setTriggerOnTestedMergeRequest(boolean triggerOnTestedMergeRequest) { - this.triggerOnTestedMergeRequest = triggerOnTestedMergeRequest; + public void setTriggerOnTestedPullRequest(boolean triggerOnTestedPullRequest) { + this.triggerOnTestedPullRequest = triggerOnTestedPullRequest; } @DataBoundSetter - public void setTriggerOnOpenMergeRequest(boolean triggerOnOpenMergeRequest) { - this.triggerOnOpenMergeRequest = triggerOnOpenMergeRequest; + public void setTriggerOnOpenPullRequest(boolean triggerOnOpenPullRequest) { + this.triggerOnOpenPullRequest = triggerOnOpenPullRequest; } @DataBoundSetter - public void setTriggerOnAcceptedMergeRequest(boolean triggerOnAcceptedMergeRequest) { - this.triggerOnAcceptedMergeRequest = triggerOnAcceptedMergeRequest; + public void setTriggerOnAcceptedPullRequest(boolean triggerOnAcceptedPullRequest) { + this.triggerOnAcceptedPullRequest = triggerOnAcceptedPullRequest; } @DataBoundSetter - public void setTriggerOnClosedMergeRequest(boolean triggerOnClosedMergeRequest) { - this.triggerOnClosedMergeRequest = triggerOnClosedMergeRequest; + public void setTriggerOnClosedPullRequest(boolean triggerOnClosedPullRequest) { + this.triggerOnClosedPullRequest = triggerOnClosedPullRequest; } @DataBoundSetter @@ -330,8 +328,8 @@ public class GiteePushTrigger extends Trigger> { } @DataBoundSetter - public void setSkipWorkInProgressMergeRequest(boolean skipWorkInProgressMergeRequest) { - this.skipWorkInProgressMergeRequest = skipWorkInProgressMergeRequest; + public void setSkipWorkInProgressPullRequest(boolean skipWorkInProgressPullRequest) { + this.skipWorkInProgressPullRequest = skipWorkInProgressPullRequest; } @DataBoundSetter @@ -347,8 +345,8 @@ public class GiteePushTrigger extends Trigger> { } @DataBoundSetter - public void setAddNoteOnMergeRequest(boolean addNoteOnMergeRequest) { - this.addNoteOnMergeRequest = addNoteOnMergeRequest; + public void setAddNoteOnPullRequest(boolean addNoteOnPullRequest) { + this.addNoteOnPullRequest = addNoteOnPullRequest; } @DataBoundSetter @@ -357,8 +355,8 @@ public class GiteePushTrigger extends Trigger> { } @DataBoundSetter - public void setAddVoteOnMergeRequest(boolean addVoteOnMergeRequest) { - this.addVoteOnMergeRequest = addVoteOnMergeRequest; + public void setAddVoteOnPullRequest(boolean addVoteOnPullRequest) { + this.addVoteOnPullRequest = addVoteOnPullRequest; } @DataBoundSetter @@ -387,8 +385,8 @@ public class GiteePushTrigger extends Trigger> { } @DataBoundSetter - public void setMergeRequestLabelFilterConfig(MergeRequestLabelFilterConfig mergeRequestLabelFilterConfig) { - this.mergeRequestLabelFilterConfig = mergeRequestLabelFilterConfig; + public void setPullRequestLabelFilterConfig(PullRequestLabelFilterConfig pullRequestLabelFilterConfig) { + this.pullRequestLabelFilterConfig = pullRequestLabelFilterConfig; } @DataBoundSetter @@ -397,13 +395,13 @@ public class GiteePushTrigger extends Trigger> { } @DataBoundSetter - public void setAcceptMergeRequestOnSuccess(boolean acceptMergeRequestOnSuccess) { - this.acceptMergeRequestOnSuccess = acceptMergeRequestOnSuccess; + public void setAcceptPullRequestOnSuccess(boolean acceptPullRequestOnSuccess) { + this.acceptPullRequestOnSuccess = acceptPullRequestOnSuccess; } @DataBoundSetter - public void setTriggerOnUpdateMergeRequest(boolean triggerOnUpdateMergeRequest) { - this.triggerOnUpdateMergeRequest = triggerOnUpdateMergeRequest; + public void setTriggerOnUpdatePullRequest(boolean triggerOnUpdatePullRequest) { + this.triggerOnUpdatePullRequest = triggerOnUpdatePullRequest; } @DataBoundSetter public void setTriggerOnPipelineEvent(boolean triggerOnPipelineEvent) { @@ -425,27 +423,27 @@ public class GiteePushTrigger extends Trigger> { if (branchFilter == null) { initializeBranchFilter(); } - if (mergeRequestLabelFilter == null) { - initializeMergeRequestLabelFilter(); + if (pullRequestLabelFilter == null) { + initializePullRequestLabelFilter(); } if (pushHookTriggerHandler == null) { initializeTriggerHandler(); } - pushHookTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, mergeRequestLabelFilter); + pushHookTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter); } - // executes when the Trigger receives a merge request - public void onPost(final MergeRequestHook hook) { + // executes when the Trigger receives a pull request + public void onPost(final PullRequestHook hook) { if (branchFilter == null) { initializeBranchFilter(); } - if (mergeRequestLabelFilter == null) { - initializeMergeRequestLabelFilter(); + if (pullRequestLabelFilter == null) { + initializePullRequestLabelFilter(); } - if (mergeRequestHookTriggerHandler == null) { + if (pullRequestHookTriggerHandler == null) { initializeTriggerHandler(); } - mergeRequestHookTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, mergeRequestLabelFilter); + pullRequestHookTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter); } // executes when the Trigger receives a note request @@ -453,13 +451,13 @@ public class GiteePushTrigger extends Trigger> { if (branchFilter == null) { initializeBranchFilter(); } - if (mergeRequestLabelFilter == null) { - initializeMergeRequestLabelFilter(); + if (pullRequestLabelFilter == null) { + initializePullRequestLabelFilter(); } if (noteHookTriggerHandler == null) { initializeTriggerHandler(); } - noteHookTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, mergeRequestLabelFilter); + noteHookTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter); } // executes when the Trigger receives a pipeline event @@ -467,15 +465,15 @@ public class GiteePushTrigger extends Trigger> { if (pipelineTriggerHandler == null) { initializeTriggerHandler(); } - pipelineTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, mergeRequestLabelFilter); + pipelineTriggerHandler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter); } private void initializeTriggerHandler() { - mergeRequestHookTriggerHandler = newMergeRequestHookTriggerHandler(triggerOnOpenMergeRequest, - triggerOnUpdateMergeRequest, triggerOnAcceptedMergeRequest, triggerOnClosedMergeRequest, - skipWorkInProgressMergeRequest, triggerOnApprovedMergeRequest, triggerOnTestedMergeRequest, cancelPendingBuildsOnUpdate); + pullRequestHookTriggerHandler = newPullRequestHookTriggerHandler(triggerOnOpenPullRequest, + triggerOnUpdatePullRequest, triggerOnAcceptedPullRequest, triggerOnClosedPullRequest, + skipWorkInProgressPullRequest, triggerOnApprovedPullRequest, triggerOnTestedPullRequest, cancelPendingBuildsOnUpdate); noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnNoteRequest, noteRegex); - pushHookTriggerHandler = newPushHookTriggerHandler(triggerOnPush, skipWorkInProgressMergeRequest); + pushHookTriggerHandler = newPushHookTriggerHandler(triggerOnPush, skipWorkInProgressPullRequest); pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent); } @@ -491,15 +489,15 @@ public class GiteePushTrigger extends Trigger> { .build(branchFilterType)); } - private void initializeMergeRequestLabelFilter() { - mergeRequestLabelFilter = MergeRequestLabelFilterFactory.newMergeRequestLabelFilter(mergeRequestLabelFilterConfig); + private void initializePullRequestLabelFilter() { + pullRequestLabelFilter = PullRequestLabelFilterFactory.newPullRequestLabelFilter(pullRequestLabelFilterConfig); } @Override protected Object readResolve() throws ObjectStreamException { initializeTriggerHandler(); initializeBranchFilter(); - initializeMergeRequestLabelFilter(); + initializePullRequestLabelFilter(); return super.readResolve(); } diff --git a/src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterFactory.java b/src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterFactory.java deleted file mode 100644 index 0d02ad8..0000000 --- a/src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gitee.jenkins.trigger.filter; - -/** - * @author Robin Müller - */ -public class MergeRequestLabelFilterFactory { - - private MergeRequestLabelFilterFactory() { } - - public static MergeRequestLabelFilter newMergeRequestLabelFilter(MergeRequestLabelFilterConfig config) { - if (config == null) { - return new NopMergeRequestLabelFilter(); - } else { - return new MergeRequestLabelFilterImpl(config.getInclude(), config.getExclude()); - } - } -} diff --git a/src/main/java/com/gitee/jenkins/trigger/filter/NopMergeRequestLabelFilter.java b/src/main/java/com/gitee/jenkins/trigger/filter/NopPullRequestLabelFilter.java similarity index 51% rename from src/main/java/com/gitee/jenkins/trigger/filter/NopMergeRequestLabelFilter.java rename to src/main/java/com/gitee/jenkins/trigger/filter/NopPullRequestLabelFilter.java index ce39214..6f15e33 100644 --- a/src/main/java/com/gitee/jenkins/trigger/filter/NopMergeRequestLabelFilter.java +++ b/src/main/java/com/gitee/jenkins/trigger/filter/NopPullRequestLabelFilter.java @@ -5,9 +5,9 @@ import java.util.Collection; /** * @author Robin Müller */ -class NopMergeRequestLabelFilter implements MergeRequestLabelFilter { +class NopPullRequestLabelFilter implements PullRequestLabelFilter { @Override - public boolean isMergeRequestAllowed(Collection labels) { + public boolean isPullRequestAllowed(Collection labels) { return true; } } diff --git a/src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilter.java b/src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilter.java similarity index 50% rename from src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilter.java rename to src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilter.java index 01079df..bbff02b 100644 --- a/src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilter.java +++ b/src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilter.java @@ -5,6 +5,6 @@ import java.util.Collection; /** * @author Robin Müller */ -public interface MergeRequestLabelFilter { - boolean isMergeRequestAllowed(Collection labels); +public interface PullRequestLabelFilter { + boolean isPullRequestAllowed(Collection labels); } diff --git a/src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterConfig.java b/src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterConfig.java similarity index 71% rename from src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterConfig.java rename to src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterConfig.java index 36ddcc5..c67e171 100644 --- a/src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterConfig.java +++ b/src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterConfig.java @@ -6,22 +6,22 @@ import org.kohsuke.stapler.DataBoundSetter; /** * @author Robin Müller */ -public class MergeRequestLabelFilterConfig { +public class PullRequestLabelFilterConfig { private String include; private String exclude; /** - * @deprecated use {@link #MergeRequestLabelFilterConfig()} with setters to configure an instance of this class. + * @deprecated use {@link #PullRequestLabelFilterConfig()} with setters to configure an instance of this class. */ @Deprecated - public MergeRequestLabelFilterConfig(String include, String exclude) { + public PullRequestLabelFilterConfig(String include, String exclude) { this.include = include; this.exclude = exclude; } @DataBoundConstructor - public MergeRequestLabelFilterConfig() { } + public PullRequestLabelFilterConfig() { } public String getInclude() { return include; diff --git a/src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterFactory.java b/src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterFactory.java new file mode 100644 index 0000000..161c3e1 --- /dev/null +++ b/src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterFactory.java @@ -0,0 +1,17 @@ +package com.gitee.jenkins.trigger.filter; + +/** + * @author Robin Müller + */ +public class PullRequestLabelFilterFactory { + + private PullRequestLabelFilterFactory() { } + + public static PullRequestLabelFilter newPullRequestLabelFilter(PullRequestLabelFilterConfig config) { + if (config == null) { + return new NopPullRequestLabelFilter(); + } else { + return new PullRequestLabelFilterImpl(config.getInclude(), config.getExclude()); + } + } +} diff --git a/src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterImpl.java b/src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterImpl.java similarity index 85% rename from src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterImpl.java rename to src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterImpl.java index 3c33540..0adbb5f 100644 --- a/src/main/java/com/gitee/jenkins/trigger/filter/MergeRequestLabelFilterImpl.java +++ b/src/main/java/com/gitee/jenkins/trigger/filter/PullRequestLabelFilterImpl.java @@ -9,18 +9,18 @@ import java.util.Set; /** * @author Robin Müller */ -class MergeRequestLabelFilterImpl implements MergeRequestLabelFilter { +class PullRequestLabelFilterImpl implements PullRequestLabelFilter { private final Set includeLabels; private final Set excludeLabels; - public MergeRequestLabelFilterImpl(String includeLabels, String excludeLabels) { + public PullRequestLabelFilterImpl(String includeLabels, String excludeLabels) { this.includeLabels = convert(includeLabels); this.excludeLabels = convert(excludeLabels); } @Override - public boolean isMergeRequestAllowed(Collection labels) { + public boolean isPullRequestAllowed(Collection labels) { return containsNoExcludeLabel(labels) && containsIncludeLabel(labels); } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/AbstractWebHookTriggerHandler.java b/src/main/java/com/gitee/jenkins/trigger/handler/AbstractWebHookTriggerHandler.java index de0ab22..ea937b5 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/AbstractWebHookTriggerHandler.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/AbstractWebHookTriggerHandler.java @@ -5,7 +5,7 @@ import com.gitee.jenkins.cause.GiteeWebHookCause; import com.gitee.jenkins.gitee.hook.model.WebHook; import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException; import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; import com.gitee.jenkins.util.LoggerUtil; import hudson.model.Action; import hudson.model.CauseAction; @@ -34,7 +34,7 @@ public abstract class AbstractWebHookTriggerHandler implement protected PendingBuildsHandler pendingBuildsHandler = new PendingBuildsHandler(); @Override - public void handle(Job job, H hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { + public void handle(Job job, H hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { if (ciSkip && isCiSkip(hook)) { LOGGER.log(Level.INFO, "Skipping due to ci-skip."); return; diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/WebHookTriggerHandler.java b/src/main/java/com/gitee/jenkins/trigger/handler/WebHookTriggerHandler.java index 8960753..97a7aed 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/WebHookTriggerHandler.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/WebHookTriggerHandler.java @@ -2,7 +2,7 @@ package com.gitee.jenkins.trigger.handler; import com.gitee.jenkins.gitee.hook.model.WebHook; import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; import hudson.model.Job; /** @@ -10,5 +10,5 @@ import hudson.model.Job; */ public interface WebHookTriggerHandler { - void handle(Job job, H hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter); + void handle(Job job, H hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter); } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandler.java b/src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandler.java deleted file mode 100644 index 0367bc0..0000000 --- a/src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandler.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.gitee.jenkins.trigger.handler.merge; - -import com.gitee.jenkins.gitee.hook.model.MergeRequestHook; -import com.gitee.jenkins.trigger.handler.WebHookTriggerHandler; - -/** - * @author Robin Müller - */ -public interface MergeRequestHookTriggerHandler extends WebHookTriggerHandler { } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerFactory.java b/src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerFactory.java deleted file mode 100644 index 9396145..0000000 --- a/src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerFactory.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.gitee.jenkins.trigger.handler.merge; - -import com.gitee.jenkins.gitee.hook.model.Action; -import com.gitee.jenkins.gitee.hook.model.State; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; - -/** - * @author Robin Müller - */ -public final class MergeRequestHookTriggerHandlerFactory { - - private MergeRequestHookTriggerHandlerFactory() {} - - public static MergeRequestHookTriggerHandler newMergeRequestHookTriggerHandler(boolean triggerOnOpenMergeRequest, - boolean triggerOnUpdateMergeRequest, - boolean triggerOnAcceptedMergeRequest, - boolean triggerOnClosedMergeRequest, - boolean skipWorkInProgressMergeRequest, - boolean triggerOnApprovedMergeRequest, - boolean triggerOnTestedMergeRequest, - boolean cancelPendingBuildsOnUpdate) { - if (triggerOnOpenMergeRequest - || triggerOnUpdateMergeRequest - || triggerOnAcceptedMergeRequest - || triggerOnClosedMergeRequest - || triggerOnApprovedMergeRequest - || triggerOnTestedMergeRequest) { - - return new MergeRequestHookTriggerHandlerImpl( - retrieveAllowedStates(triggerOnOpenMergeRequest, - triggerOnUpdateMergeRequest, - triggerOnAcceptedMergeRequest, - triggerOnClosedMergeRequest, - triggerOnApprovedMergeRequest, - triggerOnTestedMergeRequest), - retrieveAllowedActions(triggerOnOpenMergeRequest, - triggerOnUpdateMergeRequest, - triggerOnAcceptedMergeRequest, - triggerOnClosedMergeRequest, - triggerOnApprovedMergeRequest, - triggerOnTestedMergeRequest), - skipWorkInProgressMergeRequest, - cancelPendingBuildsOnUpdate); - } else { - return new NopMergeRequestHookTriggerHandler(); - } - } - - private static List retrieveAllowedActions(boolean triggerOnOpenMergeRequest, - boolean triggerOnUpdateMergeRequest, - boolean triggerOnAcceptedMergeRequest, - boolean triggerOnClosedMergeRequest, - boolean triggerOnApprovedMergeRequest, - boolean triggerOnTestedMergeRequest) { - List allowedActions =new ArrayList<>(); - - if (triggerOnOpenMergeRequest) { - allowedActions.add(Action.open); - } - - if (triggerOnUpdateMergeRequest) { - allowedActions.add(Action.update); - } - - if (triggerOnAcceptedMergeRequest) { - allowedActions.add(Action.merge); - } - - if (triggerOnClosedMergeRequest) { - allowedActions.add(Action.close); - } - - if (triggerOnApprovedMergeRequest) { - allowedActions.add(Action.approved); - } - - if (triggerOnTestedMergeRequest) { - allowedActions.add(Action.tested); - } - - return allowedActions; - } - - private static List retrieveAllowedStates(boolean triggerOnOpenMergeRequest, - boolean triggerOnUpdateMergeRequest, - boolean triggerOnAcceptedMergeRequest, - boolean triggerOnClosedMergeRequest, - boolean triggerOnApprovedMergeRequest, - boolean triggerOnTestedMergeRequest) { - List result = new ArrayList<>(); - if (triggerOnOpenMergeRequest - || triggerOnUpdateMergeRequest - || triggerOnApprovedMergeRequest - || triggerOnTestedMergeRequest) { - - result.add(State.opened); - result.add(State.open); - result.add(State.reopened); - result.add(State.updated); - } - - if (triggerOnAcceptedMergeRequest) { - result.add(State.merged); - } - if (triggerOnClosedMergeRequest) { - result.add(State.closed); - } - - return result; - } -} diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/merge/NopMergeRequestHookTriggerHandler.java b/src/main/java/com/gitee/jenkins/trigger/handler/merge/NopMergeRequestHookTriggerHandler.java deleted file mode 100644 index e8cdd78..0000000 --- a/src/main/java/com/gitee/jenkins/trigger/handler/merge/NopMergeRequestHookTriggerHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.gitee.jenkins.trigger.handler.merge; - -import com.gitee.jenkins.gitee.hook.model.MergeRequestHook; -import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; -import hudson.model.Job; - -/** - * @author Robin Müller - */ -class NopMergeRequestHookTriggerHandler implements MergeRequestHookTriggerHandler { - @Override - public void handle(Job job, MergeRequestHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { - // nothing to do - } -} diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/merge/NopPullRequestHookTriggerHandler.java b/src/main/java/com/gitee/jenkins/trigger/handler/merge/NopPullRequestHookTriggerHandler.java new file mode 100644 index 0000000..438b3c2 --- /dev/null +++ b/src/main/java/com/gitee/jenkins/trigger/handler/merge/NopPullRequestHookTriggerHandler.java @@ -0,0 +1,16 @@ +package com.gitee.jenkins.trigger.handler.merge; + +import com.gitee.jenkins.gitee.hook.model.PullRequestHook; +import com.gitee.jenkins.trigger.filter.BranchFilter; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; +import hudson.model.Job; + +/** + * @author Robin Müller + */ +class NopPullRequestHookTriggerHandler implements PullRequestHookTriggerHandler { + @Override + public void handle(Job job, PullRequestHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { + // nothing to do + } +} diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandler.java b/src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandler.java new file mode 100644 index 0000000..71cde48 --- /dev/null +++ b/src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandler.java @@ -0,0 +1,9 @@ +package com.gitee.jenkins.trigger.handler.merge; + +import com.gitee.jenkins.gitee.hook.model.PullRequestHook; +import com.gitee.jenkins.trigger.handler.WebHookTriggerHandler; + +/** + * @author Robin Müller + */ +public interface PullRequestHookTriggerHandler extends WebHookTriggerHandler { } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandlerFactory.java b/src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandlerFactory.java new file mode 100644 index 0000000..4792d6d --- /dev/null +++ b/src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandlerFactory.java @@ -0,0 +1,113 @@ +package com.gitee.jenkins.trigger.handler.merge; + +import com.gitee.jenkins.gitee.hook.model.Action; +import com.gitee.jenkins.gitee.hook.model.State; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Robin Müller + */ +public final class PullRequestHookTriggerHandlerFactory { + + private PullRequestHookTriggerHandlerFactory() {} + + public static PullRequestHookTriggerHandler newPullRequestHookTriggerHandler(boolean triggerOnOpenPullRequest, + boolean triggerOnUpdatePullRequest, + boolean triggerOnAcceptedPullRequest, + boolean triggerOnClosedPullRequest, + boolean skipWorkInProgressPullRequest, + boolean triggerOnApprovedPullRequest, + boolean triggerOnTestedPullRequest, + boolean cancelPendingBuildsOnUpdate) { + if (triggerOnOpenPullRequest + || triggerOnUpdatePullRequest + || triggerOnAcceptedPullRequest + || triggerOnClosedPullRequest + || triggerOnApprovedPullRequest + || triggerOnTestedPullRequest) { + + return new PullRequestHookTriggerHandlerImpl( + retrieveAllowedStates(triggerOnOpenPullRequest, + triggerOnUpdatePullRequest, + triggerOnAcceptedPullRequest, + triggerOnClosedPullRequest, + triggerOnApprovedPullRequest, + triggerOnTestedPullRequest), + retrieveAllowedActions(triggerOnOpenPullRequest, + triggerOnUpdatePullRequest, + triggerOnAcceptedPullRequest, + triggerOnClosedPullRequest, + triggerOnApprovedPullRequest, + triggerOnTestedPullRequest), + skipWorkInProgressPullRequest, + cancelPendingBuildsOnUpdate); + } else { + return new NopPullRequestHookTriggerHandler(); + } + } + + private static List retrieveAllowedActions(boolean triggerOnOpenPullRequest, + boolean triggerOnUpdatePullRequest, + boolean triggerOnAcceptedPullRequest, + boolean triggerOnClosedPullRequest, + boolean triggerOnApprovedPullRequest, + boolean triggerOnTestedPullRequest) { + List allowedActions =new ArrayList<>(); + + if (triggerOnOpenPullRequest) { + allowedActions.add(Action.open); + } + + if (triggerOnUpdatePullRequest) { + allowedActions.add(Action.update); + } + + if (triggerOnAcceptedPullRequest) { + allowedActions.add(Action.merge); + } + + if (triggerOnClosedPullRequest) { + allowedActions.add(Action.close); + } + + if (triggerOnApprovedPullRequest) { + allowedActions.add(Action.approved); + } + + if (triggerOnTestedPullRequest) { + allowedActions.add(Action.tested); + } + + return allowedActions; + } + + private static List retrieveAllowedStates(boolean triggerOnOpenPullRequest, + boolean triggerOnUpdatePullRequest, + boolean triggerOnAcceptedPullRequest, + boolean triggerOnClosedPullRequest, + boolean triggerOnApprovedPullRequest, + boolean triggerOnTestedPullRequest) { + List result = new ArrayList<>(); + if (triggerOnOpenPullRequest + || triggerOnUpdatePullRequest + || triggerOnApprovedPullRequest + || triggerOnTestedPullRequest) { + + result.add(State.opened); + result.add(State.open); + result.add(State.reopened); + result.add(State.updated); + } + + if (triggerOnAcceptedPullRequest) { + result.add(State.merged); + } + if (triggerOnClosedPullRequest) { + result.add(State.closed); + } + + return result; + } +} diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerImpl.java b/src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandlerImpl.java similarity index 62% rename from src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerImpl.java rename to src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandlerImpl.java index 3ef943d..1abb595 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerImpl.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/merge/PullRequestHookTriggerHandlerImpl.java @@ -2,14 +2,15 @@ package com.gitee.jenkins.trigger.handler.merge; import com.gitee.jenkins.cause.CauseData; import com.gitee.jenkins.cause.GiteeWebHookCause; -import com.gitee.jenkins.gitee.hook.model.Action; -import com.gitee.jenkins.gitee.hook.model.MergeRequestHook; -import com.gitee.jenkins.gitee.hook.model.MergeRequestObjectAttributes; -import com.gitee.jenkins.gitee.hook.model.MergeRequestLabel; -import com.gitee.jenkins.gitee.hook.model.State; +import com.gitee.jenkins.gitee.api.GiteeClient; +import com.gitee.jenkins.gitee.api.model.PullRequest; +import com.gitee.jenkins.gitee.hook.model.*; +import com.gitee.jenkins.gitee.hook.model.PullRequestHook; +import com.gitee.jenkins.publisher.GiteeMessagePublisher; +import com.gitee.jenkins.trigger.GiteePushTrigger; import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException; import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; import com.gitee.jenkins.trigger.handler.AbstractWebHookTriggerHandler; import com.gitee.jenkins.util.BuildUtil; import hudson.model.Job; @@ -27,48 +28,60 @@ import java.util.logging.Logger; import static com.gitee.jenkins.cause.CauseDataBuilder.causeData; import static com.gitee.jenkins.trigger.handler.builder.generated.BuildStatusUpdateBuilder.buildStatusUpdate; +import static com.gitee.jenkins.connection.GiteeConnectionProperty.getClient; /** * @author Robin Müller * @author Yashin Luo */ -class MergeRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler implements MergeRequestHookTriggerHandler { +class PullRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler implements PullRequestHookTriggerHandler { - private static final Logger LOGGER = Logger.getLogger(MergeRequestHookTriggerHandlerImpl.class.getName()); + private static final Logger LOGGER = Logger.getLogger(PullRequestHookTriggerHandlerImpl.class.getName()); private final Collection allowedStates; - private final boolean skipWorkInProgressMergeRequest; + private final boolean skipWorkInProgressPullRequest; private final Collection allowedActions; private final boolean cancelPendingBuildsOnUpdate; - MergeRequestHookTriggerHandlerImpl(Collection allowedStates, boolean skipWorkInProgressMergeRequest, boolean cancelPendingBuildsOnUpdate) { - this(allowedStates, EnumSet.allOf(Action.class), skipWorkInProgressMergeRequest, cancelPendingBuildsOnUpdate); + PullRequestHookTriggerHandlerImpl(Collection allowedStates, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate) { + this(allowedStates, EnumSet.allOf(Action.class), skipWorkInProgressPullRequest, cancelPendingBuildsOnUpdate); } - MergeRequestHookTriggerHandlerImpl(Collection allowedStates, Collection allowedActions, boolean skipWorkInProgressMergeRequest, boolean cancelPendingBuildsOnUpdate) { + PullRequestHookTriggerHandlerImpl(Collection allowedStates, Collection allowedActions, boolean skipWorkInProgressPullRequest, boolean cancelPendingBuildsOnUpdate) { this.allowedStates = allowedStates; this.allowedActions = allowedActions; - this.skipWorkInProgressMergeRequest = skipWorkInProgressMergeRequest; + this.skipWorkInProgressPullRequest = skipWorkInProgressPullRequest; this.cancelPendingBuildsOnUpdate = cancelPendingBuildsOnUpdate; } @Override - public void handle(Job job, MergeRequestHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { - MergeRequestObjectAttributes objectAttributes = hook.getPullRequest(); + public void handle(Job job, PullRequestHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { + PullRequestObjectAttributes objectAttributes = hook.getPullRequest(); try { LOGGER.log(Level.INFO, "request hook state=" + hook.getState() + ", action = " + hook.getAction() + " pr iid = " + objectAttributes.getNumber() + " hook name = " + hook.getHookName()); if (isAllowedByConfig(hook) - && isNotSkipWorkInProgressMergeRequest(objectAttributes)) { + && isNotSkipWorkInProgressPullRequest(objectAttributes)) { List labelsNames = new ArrayList<>(); if (hook.getLabels() != null) { - for (MergeRequestLabel label : hook.getLabels()) { + for (PullRequestLabel label : hook.getLabels()) { labelsNames.add(label.getTitle()); } } - if (mergeRequestLabelFilter.isMergeRequestAllowed(labelsNames)) { - super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, mergeRequestLabelFilter); + // 若pr不可自动合并则评论至pr + if (!objectAttributes.can_be_merged()) { + LOGGER.log(Level.INFO, "This pull request can not be merge"); + GiteeMessagePublisher publisher = GiteeMessagePublisher.getFromJob(job); + if (publisher != null) { + GiteeClient client = getClient(job); + PullRequest pullRequest = new PullRequest(objectAttributes); + LOGGER.log(Level.INFO, "sending message to gitee....."); + client.createPullRequestNote(pullRequest, ":bangbang: This pull request can not be merge! Please manual merge conflict."); + } + return; + } else if (pullRequestLabelFilter.isPullRequestAllowed(labelsNames)) { + super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter); } } else { @@ -82,15 +95,15 @@ class MergeRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler project, MergeRequestHook hook) { - MergeRequestObjectAttributes objectAttributes = hook.getPullRequest(); + protected boolean isCommitSkip(Job project, PullRequestHook hook) { + PullRequestObjectAttributes objectAttributes = hook.getPullRequest(); if (objectAttributes != null && objectAttributes.getMergeCommitSha() != null) { Run mergeBuild = BuildUtil.getBuildBySHA1IncludingMergeBuilds(project, objectAttributes.getMergeCommitSha()); @@ -103,7 +116,7 @@ class MergeRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler job, MergeRequestHook hook) { + protected void cancelPendingBuildsIfNecessary(Job job, PullRequestHook hook) { if (!this.cancelPendingBuildsOnUpdate) { return; } @@ -114,17 +127,17 @@ class MergeRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler job, NoteHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { + public void handle(Job job, NoteHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { // nothing to do } } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerImpl.java b/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerImpl.java index d5151e4..b8344e2 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerImpl.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/note/NoteHookTriggerHandlerImpl.java @@ -2,19 +2,15 @@ package com.gitee.jenkins.trigger.handler.note; import com.gitee.jenkins.cause.CauseData; import com.gitee.jenkins.gitee.hook.model.NoteHook; -import com.gitee.jenkins.gitee.hook.model.PushHook; import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException; import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; import com.gitee.jenkins.trigger.handler.AbstractWebHookTriggerHandler; -import com.gitee.jenkins.util.BuildUtil; import hudson.model.Job; -import hudson.model.Run; import hudson.plugins.git.GitSCM; import hudson.plugins.git.RevisionParameterAction; import org.apache.commons.lang.StringUtils; -import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -36,17 +32,17 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler } @Override - public void handle(Job job, NoteHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { + public void handle(Job job, NoteHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { if (isValidTriggerPhrase(hook.getObjectAttributes().getNote())) { - super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, mergeRequestLabelFilter); + super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter); } } @Override protected boolean isCiSkip(NoteHook hook) { - return hook.getMergeRequest() != null - && hook.getMergeRequest().getBody() != null - && hook.getMergeRequest().getBody().contains("[ci-skip]"); + return hook.getPullRequest() != null + && hook.getPullRequest().getBody() != null + && hook.getPullRequest().getBody().contains("[ci-skip]"); } @Override @@ -55,7 +51,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler } @Override protected String getTargetBranch(NoteHook hook) { - return hook.getMergeRequest() == null ? null : hook.getMergeRequest().getTargetBranch(); + return hook.getPullRequest() == null ? null : hook.getPullRequest().getTargetBranch(); } @Override @@ -67,31 +63,31 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler protected CauseData retrieveCauseData(NoteHook hook) { return causeData() .withActionType(CauseData.ActionType.NOTE) - .withSourceProjectId(hook.getMergeRequest().getSourceProjectId()) - .withTargetProjectId(hook.getMergeRequest().getTargetProjectId()) - .withBranch(hook.getMergeRequest().getSourceBranch()) - .withSourceBranch(hook.getMergeRequest().getSourceBranch()) - .withUserName(hook.getMergeRequest().getHead().getUser().getName()) - .withUserEmail(hook.getMergeRequest().getHead().getUser().getEmail()) - .withSourceRepoHomepage(hook.getMergeRequest().getSource().getHomepage()) - .withSourceRepoName(hook.getMergeRequest().getSource().getName()) - .withSourceNamespace(hook.getMergeRequest().getSource().getNamespace()) - .withSourceRepoUrl(hook.getMergeRequest().getSource().getUrl()) - .withSourceRepoSshUrl(hook.getMergeRequest().getSource().getSshUrl()) - .withSourceRepoHttpUrl(hook.getMergeRequest().getSource().getGitHttpUrl()) - .withMergeRequestTitle(hook.getMergeRequest().getTitle()) - .withMergeRequestDescription(hook.getMergeRequest().getBody()) - .withMergeRequestId(hook.getMergeRequest().getId()) - .withMergeRequestIid(hook.getMergeRequest().getNumber()) - .withMergeRequestTargetProjectId(hook.getMergeRequest().getTargetProjectId()) - .withTargetBranch(hook.getMergeRequest().getTargetBranch()) - .withTargetRepoName(hook.getMergeRequest().getTarget().getName()) - .withTargetNamespace(hook.getMergeRequest().getTarget().getNamespace()) - .withTargetRepoSshUrl(hook.getMergeRequest().getTarget().getSshUrl()) - .withTargetRepoHttpUrl(hook.getMergeRequest().getTarget().getGitHttpUrl()) - .withTriggeredByUser(hook.getMergeRequest().getHead().getUser().getName()) - .withLastCommit(hook.getMergeRequest().getMergeCommitSha()) - .withTargetProjectUrl(hook.getMergeRequest().getTarget().getUrl()) + .withSourceProjectId(hook.getPullRequest().getSourceProjectId()) + .withTargetProjectId(hook.getPullRequest().getTargetProjectId()) + .withBranch(hook.getPullRequest().getSourceBranch()) + .withSourceBranch(hook.getPullRequest().getSourceBranch()) + .withUserName(hook.getPullRequest().getHead().getUser().getName()) + .withUserEmail(hook.getPullRequest().getHead().getUser().getEmail()) + .withSourceRepoHomepage(hook.getPullRequest().getSource().getHomepage()) + .withSourceRepoName(hook.getPullRequest().getSource().getName()) + .withSourceNamespace(hook.getPullRequest().getSource().getNamespace()) + .withSourceRepoUrl(hook.getPullRequest().getSource().getUrl()) + .withSourceRepoSshUrl(hook.getPullRequest().getSource().getSshUrl()) + .withSourceRepoHttpUrl(hook.getPullRequest().getSource().getGitHttpUrl()) + .withPullRequestTitle(hook.getPullRequest().getTitle()) + .withPullRequestDescription(hook.getPullRequest().getBody()) + .withPullRequestId(hook.getPullRequest().getId()) + .withPullRequestIid(hook.getPullRequest().getNumber()) + .withPullRequestTargetProjectId(hook.getPullRequest().getTargetProjectId()) + .withTargetBranch(hook.getPullRequest().getTargetBranch()) + .withTargetRepoName(hook.getPullRequest().getTarget().getName()) + .withTargetNamespace(hook.getPullRequest().getTarget().getNamespace()) + .withTargetRepoSshUrl(hook.getPullRequest().getTarget().getSshUrl()) + .withTargetRepoHttpUrl(hook.getPullRequest().getTarget().getGitHttpUrl()) + .withTriggeredByUser(hook.getPullRequest().getHead().getUser().getName()) + .withLastCommit(hook.getPullRequest().getMergeCommitSha()) + .withTargetProjectUrl(hook.getPullRequest().getTarget().getUrl()) .withTriggerPhrase(hook.getObjectAttributes().getNote()) .build(); } @@ -104,17 +100,17 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler @Override protected BuildStatusUpdate retrieveBuildStatusUpdate(NoteHook hook) { return buildStatusUpdate() - .withProjectId(hook.getMergeRequest().getSourceProjectId()) - .withSha(hook.getMergeRequest().getMergeCommitSha()) - .withRef(hook.getMergeRequest().getSourceBranch()) + .withProjectId(hook.getPullRequest().getSourceProjectId()) + .withSha(hook.getPullRequest().getMergeCommitSha()) + .withRef(hook.getPullRequest().getSourceBranch()) .build(); } private String retrieveRevisionToBuild(NoteHook hook) throws NoRevisionToBuildException { - if (hook.getMergeRequest() != null - && hook.getMergeRequest().getMergeCommitSha() != null) { + if (hook.getPullRequest() != null + && hook.getPullRequest().getMergeCommitSha() != null) { - return hook.getMergeRequest().getMergeCommitSha(); + return hook.getPullRequest().getMergeCommitSha(); } else { throw new NoRevisionToBuildException(); } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/pipeline/NopPipelineHookTriggerHandler.java b/src/main/java/com/gitee/jenkins/trigger/handler/pipeline/NopPipelineHookTriggerHandler.java index 0159102..4ba290c 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/pipeline/NopPipelineHookTriggerHandler.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/pipeline/NopPipelineHookTriggerHandler.java @@ -2,7 +2,7 @@ package com.gitee.jenkins.trigger.handler.pipeline; import com.gitee.jenkins.gitee.hook.model.PipelineHook; import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; import hudson.model.Job; /** @@ -11,7 +11,7 @@ import hudson.model.Job; class NopPipelineHookTriggerHandler implements PipelineHookTriggerHandler { @Override - public void handle(Job job, PipelineHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { + public void handle(Job job, PipelineHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { } } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/pipeline/PipelineHookTriggerHandlerImpl.java b/src/main/java/com/gitee/jenkins/trigger/handler/pipeline/PipelineHookTriggerHandlerImpl.java index a647586..69bb084 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/pipeline/PipelineHookTriggerHandlerImpl.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/pipeline/PipelineHookTriggerHandlerImpl.java @@ -8,7 +8,7 @@ import com.gitee.jenkins.gitee.hook.model.PipelineEventObjectAttributes; import com.gitee.jenkins.gitee.hook.model.PipelineHook; import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException; import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; import com.gitee.jenkins.trigger.handler.AbstractWebHookTriggerHandler; import com.gitee.jenkins.util.BuildUtil; import com.gitee.jenkins.util.LoggerUtil; @@ -44,7 +44,7 @@ class PipelineHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler job, PipelineHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { + public void handle(Job job, PipelineHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { PipelineEventObjectAttributes objectAttributes = hook.getObjectAttributes(); try { if (job instanceof AbstractProject) { @@ -109,7 +109,7 @@ class PipelineHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler job, PushHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { + public void handle(Job job, PushHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { // nothing to do } } diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerFactory.java b/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerFactory.java index 36dd30a..92f4111 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerFactory.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerFactory.java @@ -10,15 +10,15 @@ public final class PushHookTriggerHandlerFactory { private PushHookTriggerHandlerFactory() {} - public static PushHookTriggerHandler newPushHookTriggerHandler(boolean triggerOnPush, boolean skipWorkInProgressMergeRequest) { + public static PushHookTriggerHandler newPushHookTriggerHandler(boolean triggerOnPush, boolean skipWorkInProgressPullRequest) { if (triggerOnPush) { - return new PushHookTriggerHandlerList(retrieveHandlers(triggerOnPush, skipWorkInProgressMergeRequest)); + return new PushHookTriggerHandlerList(retrieveHandlers(triggerOnPush, skipWorkInProgressPullRequest)); } else { return new NopPushHookTriggerHandler(); } } - private static List retrieveHandlers(boolean triggerOnPush, boolean skipWorkInProgressMergeRequest) { + private static List retrieveHandlers(boolean triggerOnPush, boolean skipWorkInProgressPullRequest) { List result = new ArrayList<>(); if (triggerOnPush) { result.add(new PushHookTriggerHandlerImpl()); diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerImpl.java b/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerImpl.java index b228c4a..fb0aab1 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerImpl.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerImpl.java @@ -6,7 +6,7 @@ import com.gitee.jenkins.gitee.hook.model.Commit; import com.gitee.jenkins.gitee.hook.model.PushHook; import com.gitee.jenkins.trigger.exception.NoRevisionToBuildException; import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; import com.gitee.jenkins.trigger.handler.AbstractWebHookTriggerHandler; import hudson.model.Job; import hudson.model.Run; @@ -31,9 +31,9 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler private static final String NO_COMMIT = "0000000000000000000000000000000000000000"; @Override - public void handle(Job job, PushHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { + public void handle(Job job, PushHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { if (isNoRemoveBranchPush(hook)) { - super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, mergeRequestLabelFilter); + super.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter); } } @@ -78,14 +78,14 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler .withSourceRepoUrl(hook.getProject().getUrl()) .withSourceRepoSshUrl(hook.getProject().getSshUrl()) .withSourceRepoHttpUrl(hook.getProject().getGitHttpUrl()) - .withMergeRequestTitle("") - .withMergeRequestDescription("") - .withMergeRequestId(null) - .withMergeRequestIid(null) - .withMergeRequestState(null) + .withPullRequestTitle("") + .withPullRequestDescription("") + .withPullRequestId(null) + .withPullRequestIid(null) + .withPullRequestState(null) .withMergedByUser("") - .withMergeRequestAssignee("") - .withMergeRequestTargetProjectId(null) + .withPullRequestAssignee("") + .withPullRequestTargetProjectId(null) .withTargetBranch(getTargetBranch(hook)) .withTargetRepoName("") .withTargetNamespace("") diff --git a/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerList.java b/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerList.java index bfe8822..f9e13aa 100644 --- a/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerList.java +++ b/src/main/java/com/gitee/jenkins/trigger/handler/push/PushHookTriggerHandlerList.java @@ -2,7 +2,7 @@ package com.gitee.jenkins.trigger.handler.push; import com.gitee.jenkins.gitee.hook.model.PushHook; import com.gitee.jenkins.trigger.filter.BranchFilter; -import com.gitee.jenkins.trigger.filter.MergeRequestLabelFilter; +import com.gitee.jenkins.trigger.filter.PullRequestLabelFilter; import hudson.model.Job; import java.util.List; @@ -19,9 +19,9 @@ class PushHookTriggerHandlerList implements PushHookTriggerHandler { } @Override - public void handle(Job job, PushHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) { + public void handle(Job job, PushHook hook, boolean ciSkip, boolean skipLastCommitHasBeenBuild, BranchFilter branchFilter, PullRequestLabelFilter pullRequestLabelFilter) { for (PushHookTriggerHandler handler : handlers) { - handler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, mergeRequestLabelFilter); + handler.handle(job, hook, ciSkip, skipLastCommitHasBeenBuild, branchFilter, pullRequestLabelFilter); } } } diff --git a/src/main/java/com/gitee/jenkins/webhook/ActionResolver.java b/src/main/java/com/gitee/jenkins/webhook/ActionResolver.java index aef8107..fee9856 100644 --- a/src/main/java/com/gitee/jenkins/webhook/ActionResolver.java +++ b/src/main/java/com/gitee/jenkins/webhook/ActionResolver.java @@ -1,7 +1,7 @@ package com.gitee.jenkins.webhook; import com.gitee.jenkins.util.ACLUtil; -import com.gitee.jenkins.webhook.build.MergeRequestBuildAction; +import com.gitee.jenkins.webhook.build.PullRequestBuildAction; import com.gitee.jenkins.webhook.build.NoteBuildAction; import com.gitee.jenkins.webhook.build.PipelineBuildAction; import com.gitee.jenkins.webhook.build.PushBuildAction; @@ -107,7 +107,7 @@ public class ActionResolver { String tokenHeader = request.getHeader("X-Gitee-Token"); switch (eventHeader) { case "Merge Request Hook": - return new MergeRequestBuildAction(project, getRequestBody(request), tokenHeader); + return new PullRequestBuildAction(project, getRequestBody(request), tokenHeader); case "Push Hook": case "Tag Push Hook": return new PushBuildAction(project, getRequestBody(request), tokenHeader); diff --git a/src/main/java/com/gitee/jenkins/webhook/build/MergeRequestBuildAction.java b/src/main/java/com/gitee/jenkins/webhook/build/PullRequestBuildAction.java similarity index 62% rename from src/main/java/com/gitee/jenkins/webhook/build/MergeRequestBuildAction.java rename to src/main/java/com/gitee/jenkins/webhook/build/PullRequestBuildAction.java index db36bb8..7ee232b 100644 --- a/src/main/java/com/gitee/jenkins/webhook/build/MergeRequestBuildAction.java +++ b/src/main/java/com/gitee/jenkins/webhook/build/PullRequestBuildAction.java @@ -1,8 +1,8 @@ package com.gitee.jenkins.webhook.build; +import com.gitee.jenkins.gitee.hook.model.PullRequestHook; import com.gitee.jenkins.trigger.GiteePushTrigger; -import com.gitee.jenkins.gitee.hook.model.MergeRequestHook; -import com.gitee.jenkins.gitee.hook.model.MergeRequestObjectAttributes; +import com.gitee.jenkins.gitee.hook.model.PullRequestObjectAttributes; import com.gitee.jenkins.gitee.hook.model.Project; import com.gitee.jenkins.util.JsonUtil; import hudson.model.Item; @@ -19,23 +19,23 @@ import static com.gitee.jenkins.util.JsonUtil.toPrettyPrint; /** * @author Robin Müller */ -public class MergeRequestBuildAction extends BuildWebHookAction { +public class PullRequestBuildAction extends BuildWebHookAction { - private final static Logger LOGGER = Logger.getLogger(MergeRequestBuildAction.class.getName()); + private final static Logger LOGGER = Logger.getLogger(PullRequestBuildAction.class.getName()); private Item project; - private MergeRequestHook mergeRequestHook; + private PullRequestHook pullRequestHook; private final String secretToken; - public MergeRequestBuildAction(Item project, String json, String secretToken) { - LOGGER.log(Level.FINE, "MergeRequest: {0}", toPrettyPrint(json)); + public PullRequestBuildAction(Item project, String json, String secretToken) { + LOGGER.log(Level.FINE, "PullRequest: {0}", toPrettyPrint(json)); this.project = project; - this.mergeRequestHook = JsonUtil.read(json, MergeRequestHook.class); + this.pullRequestHook = JsonUtil.read(json, PullRequestHook.class); this.secretToken = secretToken; } void processForCompatibility() { // url and homepage are introduced in 8.x versions of Gitee - final MergeRequestObjectAttributes attributes = this.mergeRequestHook.getPullRequest(); + final PullRequestObjectAttributes attributes = this.pullRequestHook.getPullRequest(); if (attributes != null) { final Project source = attributes.getSource(); if (source != null && source.getGitHttpUrl() != null) { @@ -47,9 +47,9 @@ public class MergeRequestBuildAction extends BuildWebHookAction { } } - // The MergeRequestHookTriggerHandlerImpl is looking for Project - if (mergeRequestHook.getRepo() == null && attributes.getTarget() != null) { - mergeRequestHook.setRepo(attributes.getTarget()); + // The PullRequestHookTriggerHandlerImpl is looking for Project + if (pullRequestHook.getRepo() == null && attributes.getTarget() != null) { + pullRequestHook.setRepo(attributes.getTarget()); } } } @@ -61,9 +61,9 @@ public class MergeRequestBuildAction extends BuildWebHookAction { ACL.impersonate(ACL.SYSTEM, new TriggerNotifier(project, secretToken, Jenkins.getAuthentication()) { @Override protected void performOnPost(GiteePushTrigger trigger) { - trigger.onPost(mergeRequestHook); + trigger.onPost(pullRequestHook); } }); - throw responseWithHook(mergeRequestHook); + throw responseWithHook(pullRequestHook); } } diff --git a/src/main/java/com/gitee/jenkins/workflow/AcceptGiteeMergeRequestStep.java b/src/main/java/com/gitee/jenkins/workflow/AcceptGiteePullRequestStep.java similarity index 78% rename from src/main/java/com/gitee/jenkins/workflow/AcceptGiteeMergeRequestStep.java rename to src/main/java/com/gitee/jenkins/workflow/AcceptGiteePullRequestStep.java index ebb3ef9..fce0fac 100644 --- a/src/main/java/com/gitee/jenkins/workflow/AcceptGiteeMergeRequestStep.java +++ b/src/main/java/com/gitee/jenkins/workflow/AcceptGiteePullRequestStep.java @@ -18,7 +18,7 @@ import org.kohsuke.stapler.export.ExportedBean; import com.gitee.jenkins.cause.GiteeWebHookCause; import com.gitee.jenkins.gitee.api.GiteeClient; -import com.gitee.jenkins.gitee.api.model.MergeRequest; +import com.gitee.jenkins.gitee.api.model.PullRequest; import com.google.common.collect.ImmutableSet; import hudson.Extension; @@ -29,20 +29,20 @@ import hudson.model.TaskListener; * @author Robin Müller */ @ExportedBean -public class AcceptGiteeMergeRequestStep extends Step { +public class AcceptGiteePullRequestStep extends Step { - private static final Logger LOGGER = Logger.getLogger(AcceptGiteeMergeRequestStep.class.getName()); + private static final Logger LOGGER = Logger.getLogger(AcceptGiteePullRequestStep.class.getName()); private String mergeCommitMessage; @DataBoundConstructor - public AcceptGiteeMergeRequestStep(String mergeCommitMessage) { + public AcceptGiteePullRequestStep(String mergeCommitMessage) { this.mergeCommitMessage = StringUtils.isEmpty(mergeCommitMessage) ? null : mergeCommitMessage; } @Override public StepExecution start(StepContext context) throws Exception { - return new AcceptGiteeMergeRequestStepExecution(context, this); + return new AcceptGiteePullRequestStepExecution(context, this); } public String getMergeCommitMessage() { @@ -54,14 +54,14 @@ public class AcceptGiteeMergeRequestStep extends Step { this.mergeCommitMessage = StringUtils.isEmpty(mergeCommitMessage) ? null : mergeCommitMessage; } - public static class AcceptGiteeMergeRequestStepExecution extends AbstractSynchronousStepExecution { + public static class AcceptGiteePullRequestStepExecution extends AbstractSynchronousStepExecution { private static final long serialVersionUID = 1; private final transient Run run; - private final transient AcceptGiteeMergeRequestStep step; + private final transient AcceptGiteePullRequestStep step; - AcceptGiteeMergeRequestStepExecution(StepContext context, AcceptGiteeMergeRequestStep step) throws Exception { + AcceptGiteePullRequestStepExecution(StepContext context, AcceptGiteePullRequestStep step) throws Exception { super(context); this.step = step; run = context.get(Run.class); @@ -71,17 +71,17 @@ public class AcceptGiteeMergeRequestStep extends Step { protected Void run() throws Exception { GiteeWebHookCause cause = run.getCause(GiteeWebHookCause.class); if (cause != null) { - MergeRequest mergeRequest = cause.getData().getMergeRequest(); - if (mergeRequest != null) { + PullRequest pullRequest = cause.getData().getPullRequest(); + if (pullRequest != null) { GiteeClient client = getClient(run); if (client == null) { println("No Gitee connection configured"); } else { try { - client.acceptMergeRequest(mergeRequest, step.mergeCommitMessage, false); + client.acceptPullRequest(pullRequest, step.mergeCommitMessage, false); } catch (WebApplicationException | ProcessingException e) { - printf("Failed to accept merge request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage()); - LOGGER.log(Level.SEVERE, String.format("Failed to accept merge request for project '%s'", mergeRequest.getProjectId()), e); + printf("Failed to accept pull request for project '%s': %s%n", pullRequest.getProjectId(), e.getMessage()); + LOGGER.log(Level.SEVERE, String.format("Failed to accept pull request for project '%s'", pullRequest.getProjectId()), e); } } } diff --git a/src/main/java/com/gitee/jenkins/workflow/AddGiteeMergeRequestCommentStep.java b/src/main/java/com/gitee/jenkins/workflow/AddGiteePullRequestCommentStep.java similarity index 80% rename from src/main/java/com/gitee/jenkins/workflow/AddGiteeMergeRequestCommentStep.java rename to src/main/java/com/gitee/jenkins/workflow/AddGiteePullRequestCommentStep.java index a10c4b4..fe50b63 100644 --- a/src/main/java/com/gitee/jenkins/workflow/AddGiteeMergeRequestCommentStep.java +++ b/src/main/java/com/gitee/jenkins/workflow/AddGiteePullRequestCommentStep.java @@ -9,6 +9,7 @@ import java.util.logging.Logger; import javax.ws.rs.ProcessingException; import javax.ws.rs.WebApplicationException; +import com.gitee.jenkins.gitee.api.model.PullRequest; import org.apache.commons.lang.StringUtils; import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution; import org.jenkinsci.plugins.workflow.steps.Step; @@ -21,7 +22,6 @@ import org.kohsuke.stapler.export.ExportedBean; import com.gitee.jenkins.cause.GiteeWebHookCause; import com.gitee.jenkins.gitee.api.GiteeClient; -import com.gitee.jenkins.gitee.api.model.MergeRequest; import com.google.common.collect.ImmutableSet; import hudson.Extension; @@ -32,20 +32,20 @@ import hudson.model.TaskListener; * @author Robin Müller */ @ExportedBean -public class AddGiteeMergeRequestCommentStep extends Step { +public class AddGiteePullRequestCommentStep extends Step { - private static final Logger LOGGER = Logger.getLogger(AddGiteeMergeRequestCommentStep.class.getName()); + private static final Logger LOGGER = Logger.getLogger(AddGiteePullRequestCommentStep.class.getName()); private String comment; @DataBoundConstructor - public AddGiteeMergeRequestCommentStep(String comment) { + public AddGiteePullRequestCommentStep(String comment) { this.comment = StringUtils.isEmpty(comment) ? null : comment; } @Override public StepExecution start(StepContext context) throws Exception { - return new AddGiteeMergeRequestCommentStepExecution(context, this); + return new AddGiteePullRequestCommentStepExecution(context, this); } public String getComment() { @@ -57,14 +57,14 @@ public class AddGiteeMergeRequestCommentStep extends Step { this.comment = StringUtils.isEmpty(comment) ? null : comment; } - public static class AddGiteeMergeRequestCommentStepExecution extends AbstractSynchronousStepExecution { + public static class AddGiteePullRequestCommentStepExecution extends AbstractSynchronousStepExecution { private static final long serialVersionUID = 1; private final transient Run run; - private final transient AddGiteeMergeRequestCommentStep step; + private final transient AddGiteePullRequestCommentStep step; - AddGiteeMergeRequestCommentStepExecution(StepContext context, AddGiteeMergeRequestCommentStep step) throws Exception { + AddGiteePullRequestCommentStepExecution(StepContext context, AddGiteePullRequestCommentStep step) throws Exception { super(context); this.step = step; run = context.get(Run.class); @@ -74,17 +74,17 @@ public class AddGiteeMergeRequestCommentStep extends Step { protected Void run() throws Exception { GiteeWebHookCause cause = run.getCause(GiteeWebHookCause.class); if (cause != null) { - MergeRequest mergeRequest = cause.getData().getMergeRequest(); - if (mergeRequest != null) { + PullRequest pullRequest = cause.getData().getPullRequest(); + if (pullRequest != null) { GiteeClient client = getClient(run); if (client == null) { println("No Gitee connection configured"); } else { try { - client.createMergeRequestNote(mergeRequest, step.getComment()); + client.createPullRequestNote(pullRequest, step.getComment()); } catch (WebApplicationException | ProcessingException e) { - printf("Failed to add comment on Merge Request for project '%s': %s%n", mergeRequest.getProjectId(), e.getMessage()); - LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", mergeRequest.getProjectId()), e); + printf("Failed to add comment on Merge Request for project '%s': %s%n", pullRequest.getProjectId(), e.getMessage()); + LOGGER.log(Level.SEVERE, String.format("Failed to add comment on Merge Request for project '%s'", pullRequest.getProjectId()), e); } } } diff --git a/src/main/resources/com/gitee/jenkins/cause/Messages.properties b/src/main/resources/com/gitee/jenkins/cause/Messages.properties index 76e325a..1cc3c3f 100644 --- a/src/main/resources/com/gitee/jenkins/cause/Messages.properties +++ b/src/main/resources/com/gitee/jenkins/cause/Messages.properties @@ -1,7 +1,7 @@ GiteeWebHookCause.ShortDescription.PushHook_noUser=Started by Gitee push GiteeWebHookCause.ShortDescription.PushHook=Started by Gitee push by {0} -GiteeWebHookCause.ShortDescription.MergeRequestHook_html=Triggered by Gitee Pull Request #{0}: {1} => {2} -GiteeWebHookCause.ShortDescription.MergeRequestHook_plain=Triggered by Gitee Pull Request #{0}: {1} => {2} +GiteeWebHookCause.ShortDescription.PullRequestHook_html=Triggered by Gitee Pull Request #{0}: {1} => {2} +GiteeWebHookCause.ShortDescription.PullRequestHook_plain=Triggered by Gitee Pull Request #{0}: {1} => {2} GiteeWebHookCause.ShortDescription.NoteHook_html=Triggered by {0} Gitee Pull Request #{1}: {2} => {3} GiteeWebHookCause.ShortDescription.NoteHook_plain=Triggered by {0} Gitee Pull Request #{1}: {2} => {3} GiteeWebHookCause.ShortDescription.PipelineHook_noStatus=Started by Gitee Pipeline event diff --git a/src/main/resources/com/gitee/jenkins/cause/Messages_zh_CN.properties b/src/main/resources/com/gitee/jenkins/cause/Messages_zh_CN.properties index e96e99e..435b1f5 100644 --- a/src/main/resources/com/gitee/jenkins/cause/Messages_zh_CN.properties +++ b/src/main/resources/com/gitee/jenkins/cause/Messages_zh_CN.properties @@ -1,7 +1,7 @@ GiteeWebHookCause.ShortDescription.PushHook_noUser=Gitee \u63A8\u9001\u89E6\u53D1\u6784\u5EFA GiteeWebHookCause.ShortDescription.PushHook=Gitee \u7528\u6237 {0} \u63A8\u9001\u89E6\u53D1\u6784\u5EFA -GiteeWebHookCause.ShortDescription.MergeRequestHook_html=\u7531 Gitee Pull Request #{0}: {1} => {2} \u89E6\u53D1 -GiteeWebHookCause.ShortDescription.MergeRequestHook_plain=\u7531 Gitee Pull Request #{0}: {1} => {2} \u89E6\u53D1 +GiteeWebHookCause.ShortDescription.PullRequestHook_html=\u7531 Gitee Pull Request #{0}: {1} => {2} \u89E6\u53D1 +GiteeWebHookCause.ShortDescription.PullRequestHook_plain=\u7531 Gitee Pull Request #{0}: {1} => {2} \u89E6\u53D1 GiteeWebHookCause.ShortDescription.NoteHook_html=\u7531 {0} Gitee Pull Request #{1}: {2} => {3} \u89E6\u53D1 GiteeWebHookCause.ShortDescription.NoteHook_plain=\u7531 {0} Gitee Pull Request #{1}: {2} => {3} \u89E6\u53D1 GiteeWebHookCause.ShortDescription.PipelineHook_noStatus=\u7531 Gitee Pipeline \u89E6\u53D1 diff --git a/src/main/resources/com/gitee/jenkins/publisher/Messages.properties b/src/main/resources/com/gitee/jenkins/publisher/Messages.properties index 0ec8574..a31e300 100644 --- a/src/main/resources/com/gitee/jenkins/publisher/Messages.properties +++ b/src/main/resources/com/gitee/jenkins/publisher/Messages.properties @@ -1,4 +1,4 @@ GiteeCommitStatusPublisher.DisplayName=Publish build status to Gitee name.required=Build name required. GiteeMessagePublisher.DisplayName=Add note with build status on Gitee pull requests -GiteeAcceptMergeRequestPublisher.DisplayName=Accept Gitee pull request on success +GiteeAcceptPullRequestPublisher.DisplayName=Accept Gitee pull request on success diff --git a/src/main/resources/com/gitee/jenkins/publisher/Messages_zh_CN.properties b/src/main/resources/com/gitee/jenkins/publisher/Messages_zh_CN.properties index 5d03cfb..9c79e1a 100644 --- a/src/main/resources/com/gitee/jenkins/publisher/Messages_zh_CN.properties +++ b/src/main/resources/com/gitee/jenkins/publisher/Messages_zh_CN.properties @@ -1,4 +1,4 @@ GiteeCommitStatusPublisher.DisplayName=\u53D1\u5E03\u6784\u5EFA\u72B6\u6001\u5230 Gitee name.required=\u8BF7\u8F93\u5165\u6784\u5EFA\u540D\u79F0\u3002 GiteeMessagePublisher.DisplayName=\u5C06\u6784\u5EFA\u72B6\u6001\u8BC4\u8BBA\u5230 Gitee Pull Request \u4E2D -GiteeAcceptMergeRequestPublisher.DisplayName=\u5F53\u6784\u5EFA\u6210\u529F\u81EA\u52A8\u5408\u5E76 Gitee \u7684 Pull Request +GiteeAcceptPullRequestPublisher.DisplayName=\u5F53\u6784\u5EFA\u6210\u529F\u81EA\u52A8\u5408\u5E76 Gitee \u7684 Pull Request diff --git a/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.jelly b/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.jelly index 9dfee0b..d8920b8 100644 --- a/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.jelly +++ b/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.jelly @@ -6,22 +6,22 @@ - + - + - + - + - + - + diff --git a/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties b/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties index 26038ff..a6eb5e7 100644 --- a/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties +++ b/src/main/resources/com/gitee/jenkins/trigger/GiteePushTrigger/config.properties @@ -28,7 +28,7 @@ Allow.all.branches=Allow all branches to trigger this job Filter.branches.by.name=Filter branches by name Filter.branches.by.regex=Filter branches by regex Target.Branch.Regex=Target Branch Regex -Filter.merge.request.by.label=Filter merge request by label +Filter.merge.request.by.label=Filter pull request by label Exclude=Exclude Include=Include Ignore.Last.Commit.Has.Build=Ignore last commit has been build diff --git a/src/main/resources/index.jelly b/src/main/resources/index.jelly index 6e917ff..947a284 100644 --- a/src/main/resources/index.jelly +++ b/src/main/resources/index.jelly @@ -3,6 +3,6 @@ This plugin integrates Gitee to Jenkins by faking a Gitee CI Server. - This plugin allows Gitee to trigger builds in Jenkins when code is committed or merge requests are opened/updated. + This plugin allows Gitee to trigger builds in Jenkins when code is committed or pull requests are opened/updated. It can also send build status back to Gitee. diff --git a/src/main/webapp/help/help-noteRegex.html b/src/main/webapp/help/help-noteRegex.html index 23a6169..f6960fe 100644 --- a/src/main/webapp/help/help-noteRegex.html +++ b/src/main/webapp/help/help-noteRegex.html @@ -1,5 +1,5 @@
-

When filled, a comment in the merge request matching this regular expression will trigger a build.

+

When filled, a comment in the pull request matching this regular expression will trigger a build.

-
\ No newline at end of file + diff --git a/src/main/webapp/help/help-send-result-to-gitee.html b/src/main/webapp/help/help-send-result-to-gitee.html index 87d62f2..ca108cf 100644 --- a/src/main/webapp/help/help-send-result-to-gitee.html +++ b/src/main/webapp/help/help-send-result-to-gitee.html @@ -1,3 +1,3 @@
- Send build result to Gitee. It will be visible in the commit and/or merge request UI as appropriate. You must have at least one Gitee connection/server configured in the Jenkins global configuration. If you have more than one, select the appropriate one from the 'Gitee connection' dropdown menu in the job configuration. + Send build result to Gitee. It will be visible in the commit and/or pull request UI as appropriate. You must have at least one Gitee connection/server configured in the Jenkins global configuration. If you have more than one, select the appropriate one from the 'Gitee connection' dropdown menu in the job configuration.
diff --git a/src/main/webapp/help/help-send-result-to-gitee_zh_CN.html b/src/main/webapp/help/help-send-result-to-gitee_zh_CN.html index 81fc212..6f2644f 100644 --- a/src/main/webapp/help/help-send-result-to-gitee_zh_CN.html +++ b/src/main/webapp/help/help-send-result-to-gitee_zh_CN.html @@ -1,6 +1,6 @@
Send build result to Gitee. - It will be visible in the commit and/or merge request UI as appropriate. + It will be visible in the commit and/or pull request UI as appropriate. You must have at least one Gitee connection/server configured in the Jenkins global configuration. If you have more than one, select the appropriate one from the 'Gitee connection' dropdown menu in the job configuration.