+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-autoRegisterHook.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-autoRegisterHook.jelly
deleted file mode 100644
index 21e3fde71..000000000
--- a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-autoRegisterHook.jelly
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
- Activate this option to auto-register a hook on the specified Bitbucket repository. This hook will notify Jenkins
- about new commits on branches and pull requests, so new builds will be triggered automatically on related jobs.
-
-
- Otherwise the hook can be created manually using the following information:
-
- - URL: [JENKINS_ROOT_URL]/bitbucket-scmsource-hook/notify
- - Check "Push", "Pull Request Created" and "Pull Request Updated" in the triggers section.
-
- NOTE: [JENKINS_ROOT_URL] must be exactly the same that is configured in Jenkins main configuration.
-
-
-
-
\ No newline at end of file
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-bitbucketServerUrl.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-bitbucketServerUrl.html
deleted file mode 100644
index 5cc96ca08..000000000
--- a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-bitbucketServerUrl.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
- Left blank to use Bitbucket Cloud.
- Set your Bitbucket Server base URL to use your own server instance. The URL must contain the full URL including
- a base path (if exists).
-
-
\ No newline at end of file
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-checkoutCredentialsId.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-checkoutCredentialsId.jelly
deleted file mode 100644
index 6e4a8e298..000000000
--- a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-checkoutCredentialsId.jelly
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
- Credentials used to clone the repository. They can be Username and Password credentials or SSH credentials
-
-
-
\ No newline at end of file
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-credentialsId.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-credentialsId.html
new file mode 100644
index 000000000..81762e037
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-credentialsId.html
@@ -0,0 +1,3 @@
+
+ Credentials used to scan branches (also the default credentials to use when checking out sources)
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-credentialsId.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-credentialsId.jelly
deleted file mode 100644
index 3e4687723..000000000
--- a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-credentialsId.jelly
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
- Credentials used to access Bitbucket REST API to retrieve branches and pull requests information.
- They must be Username and Password credentials.
-
-
-
\ No newline at end of file
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-repoOwner.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-repoOwner.html
new file mode 100644
index 000000000..61a823e16
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-repoOwner.html
@@ -0,0 +1,11 @@
+
+
Specify the name of the Bitbucket Team or Bitbucket User Account.
+
+ It could be a Bitbucket Project also, if using Bitbucket Server.
+ In this case (Bitbucket Server):
+
+ - Use the project key, not the project name.
+ - If using a user account instead of a project, add a "~" character before the username, i.e. "~joe".
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-repoOwner.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-repoOwner.jelly
deleted file mode 100644
index 06b46f056..000000000
--- a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-repoOwner.jelly
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
- Repository owner. It will be used to build the repository URL: http://bitbucket.org/[owner]/repository
-
-
-
\ No newline at end of file
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-repository.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-repository.html
new file mode 100644
index 000000000..cf4748277
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-repository.html
@@ -0,0 +1,3 @@
+
+ The repository to scan.
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-serverUrl.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-serverUrl.html
new file mode 100644
index 000000000..473b322d6
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-serverUrl.html
@@ -0,0 +1,5 @@
+
+ The server to connect to. The list of servers is configured in the Manage Jenkins » Configure
+ Jenkins › Bitbucket Endpoints screen. The list of servers can include both Bitbucket Cloud as well as
+ Bitbucket Server instances.
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-traits.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-traits.html
new file mode 100644
index 000000000..7372680fa
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help-traits.html
@@ -0,0 +1,23 @@
+
+ The behaviours control what is discovered from the Bitbucket repository. The behaviours are grouped into a number
+ of categories:
+
+ - Within repository
+ - These behaviours determine what gets discovered. If you do not configure at least one discovery
+ behaviour then nothing will be found!
+ - General
+ - These behaviours affect the configuration of each discovered branch / pull request. These behaviours
+ are relevant to both Git and Mercurial based repositories
+
+ - Git
+ - These behaviours affect the configuration of each discovered branch / pull request
+ if and only if the repository is a Git repository. If the repository is a Mercurial
+ repository, these behaviours will be silently ignored.
+
+ - Mercurial
+ - These behaviours affect the configuration of each discovered branch / pull request
+ if and only if the repository is a Mercurial repository. If the repository is a Git
+ repository, these behaviours will be silently ignored.
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help.html
index 95469e763..1769838a1 100644
--- a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help.html
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource/help.html
@@ -1,10 +1,4 @@
- SCM Source implementation which provides a connector to import branches and pull requests
- from Bitbucket.
-
- It will retrieve all branches and pull requests available at indexing time. Username and password
- credentials are needed to access Bitbucket API (Scan Credentials field), and both SSH and username/password
- can be used for git checkout (see advanced options by clicking in the Advanced button below).
-
- If only "Scan Credentials" are provided they will be used for the scan process and git checkout.
+ Discovers branches and/or pull requests from a specific repository in either Bitbucket Cloud or a Bitbucket Server
+ instance.
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait/config.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait/config.jelly
new file mode 100644
index 000000000..3076844a2
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait/config.jelly
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait/help-strategyId.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait/help-strategyId.html
new file mode 100644
index 000000000..1caa2990c
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait/help-strategyId.html
@@ -0,0 +1,20 @@
+
+ Determines which branches are discovered.
+
+ - Exclude branches that are also filed as PRs
+ -
+ If you are discovering origin pull requests, it may not make sense to discover the same changes both as a
+ pull request and as a branch.
+
+ - Only branches that are also filed as PRs
+ -
+ This option exists to preserve legacy behaviour when upgrading from older versions of the plugin.
+ NOTE: If you have an actual use case for this option please file a pull request against this text.
+
+ - All branches
+ -
+ Ignores whether the branch is also filed as a pull request and instead discovers all branches on the
+ origin repository.
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait/help.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait/help.html
new file mode 100644
index 000000000..d3ab0bfdb
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait/help.html
@@ -0,0 +1,3 @@
+
+ Discovers branches on the repository.
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/config.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/config.jelly
new file mode 100644
index 000000000..47bc583ae
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/config.jelly
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/help-strategyId.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/help-strategyId.html
new file mode 100644
index 000000000..8310b7d80
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/help-strategyId.html
@@ -0,0 +1,15 @@
+
+ Determines how pull requests are discovered:
+
+ - Discover each pull request once with the discovered revision corresponding to the result of merging with the
+ current revision of the target branch
+
+ - Discover each pull request once with the discovered revision corresponding to the pull request head revision
+ without merging
+
+ - Discover each pull request twice. The first discovered revision corresponds to the result of merging with
+ the current revision of the target branch in each scan. The second parallel discovered revision corresponds
+ to the pull request head revision without merging
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/help-trust.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/help-trust.html
new file mode 100644
index 000000000..e9b2090cb
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/help-trust.html
@@ -0,0 +1,33 @@
+
+
+ One of the great powers of pull requests is that anyone with read access to a repository can fork it, commit
+ some changes to their fork and then create a pull request against the original repository with their changes.
+ There are some files stored in source control that are important. For example, a Jenkinsfile
+ may contain configuration details to sandbox pull requests in order to mitigate against malicious pull requests.
+ In order to protect against a malicious pull request itself modifying the Jenkinsfile
to remove
+ the protections, you can define the trust policy for pull requests from forks.
+
+
+ Other plugins can extend the available trust policies. The default policies are:
+
+
+ - Nobody
+ -
+ Pull requests from forks will all be treated as untrusted. This means that where Jenkins requires a
+ trusted file (e.g.
Jenkinsfile
) the contents of that file will be retrieved from the
+ target branch on the origin repository and not from the pull request branch on the fork repository.
+
+ - Forks in the same account
+ -
+ Bitbucket allows for a repository to be forked into a "sibling" repository in the same account but using
+ a different name. This strategy will trust any pull requests from forks that are in the same account as
+ the target repository on the basis that users have to have been granted write permission to account in
+ order create such a fork.
+
+ - Everyone
+ -
+ All pull requests from forks will be treated as trusted. NOTE: this option can be dangerous
+ if used on a public repository hosted on Bitbucket Cloud.
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/help.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/help.html
new file mode 100644
index 000000000..b124cab6f
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait/help.html
@@ -0,0 +1,3 @@
+
+ Discovers pull requests where the origin repository is a fork of the target repository.
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/Messages.properties b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/Messages.properties
index 9e34b7aae..3abda79c1 100644
--- a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/Messages.properties
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/Messages.properties
@@ -2,12 +2,32 @@ BitbucketLink.DisplayName=Bitbucket
BitbucketSCMNavigator.UncategorizedSCMSourceCategory.DisplayName=Repositories
BitbucketSCMSource.UncategorizedSCMHeadCategory.DisplayName=Branches
BitbucketSCMSource.ChangeRequestSCMHeadCategory.DisplayName=Pull requests
+BitbucketSCMSource.NoMatchingOwner=Could not find: {0}
+BitbucketSCMSource.UnauthorizedAnonymous=Determination as to whether {0} may or may not exist is not permitted \
+ without suitable credentials.
+BitbucketSCMSource.UnauthorizedOwner=The selected credentials do not have permission to determine whether {0} does or\
+ does not exist.
BitbucketSCMNavigator.DisplayName=Bitbucket Team/Project
BitbucketSCMNavigator.Description=Scans a Bitbucket Cloud Team (or Bitbucket Server Project) for all repositories matching some defined markers.
BitbucketRepoMetadataAction.IconDescription=Bitbucket Repository
BitbucketRepoMetadataAction.IconDescription.Git=Bitbucket Git Repository
BitbucketRepoMetadataAction.IconDescription.Hg=Bitbucket Mercurial Repository
BitbucketTeamMetadataAction.IconDescription=Bitbucket Team/Project
-ListViewColumn.Repository=Repository
-ListViewColumn.Branch=Branch
-ListViewColumn.PullRequest=Pull Request
+BranchDiscoveryTrait.allBranches=All branches
+BranchDiscoveryTrait.excludePRs=Exclude branches that are also filed as PRs
+BranchDiscoveryTrait.onlyPRs=Only branches that are also filed as PRs
+ForkPullRequestDiscoveryTrait.displayName=Discover pull requests from forks
+ForkPullRequestDiscoveryTrait.everyoneDisplayName=Everyone
+ForkPullRequestDiscoveryTrait.headAndMerge=Both the current pull request revision and the pull request merged with \
+ the current target branch revision
+ForkPullRequestDiscoveryTrait.headOnly=The current pull request revision
+ForkPullRequestDiscoveryTrait.mergeOnly=Merging the pull request with the current target branch revision
+ForkPullRequestDiscoveryTrait.nobodyDisplayName=Nobody
+ForkPullRequestDiscoveryTrait.teamDisplayName=Forks in the same account
+OriginPullRequestDiscoveryTrait.authorityDisplayName=Trust origin pull requests
+PublicRepoPullRequestFilterTrait.displayName=Exclude pull requests from public repositories
+SSHCheckoutTrait.displayName=Checkout over SSH
+SSHCheckoutTrait.useAgentKey=- use build agent''s key -
+WebhookRegistrationTrait.disableHook=Disable hook management
+WebhookRegistrationTrait.displayName=Override hook management
+WebhookRegistrationTrait.useItemHook=Use item credentials for hook management
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/OriginPullRequestDiscoveryTrait/config.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/OriginPullRequestDiscoveryTrait/config.jelly
new file mode 100644
index 000000000..3076844a2
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/OriginPullRequestDiscoveryTrait/config.jelly
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/OriginPullRequestDiscoveryTrait/help-strategyId.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/OriginPullRequestDiscoveryTrait/help-strategyId.html
new file mode 100644
index 000000000..8310b7d80
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/OriginPullRequestDiscoveryTrait/help-strategyId.html
@@ -0,0 +1,15 @@
+
+ Determines how pull requests are discovered:
+
+ - Discover each pull request once with the discovered revision corresponding to the result of merging with the
+ current revision of the target branch
+
+ - Discover each pull request once with the discovered revision corresponding to the pull request head revision
+ without merging
+
+ - Discover each pull request twice. The first discovered revision corresponds to the result of merging with
+ the current revision of the target branch in each scan. The second parallel discovered revision corresponds
+ to the pull request head revision without merging
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/OriginPullRequestDiscoveryTrait/help.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/OriginPullRequestDiscoveryTrait/help.html
new file mode 100644
index 000000000..bb405c5e2
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/OriginPullRequestDiscoveryTrait/help.html
@@ -0,0 +1,3 @@
+
+ Discovers pull requests where the origin repository is the same as the target repository.
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/PublicRepoPullRequestFilterTrait/help.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/PublicRepoPullRequestFilterTrait/help.html
new file mode 100644
index 000000000..178c06f6a
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/PublicRepoPullRequestFilterTrait/help.html
@@ -0,0 +1,5 @@
+
+ If the repository being scanned is a public repository, this behaviour will exclude all pull requests.
+ (Note: This behaviour is not especially useful if scanning a single repository as you could just not include the
+ pull request discovery behaviours in the first place)
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/SSHCheckoutTrait/config.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/SSHCheckoutTrait/config.jelly
new file mode 100644
index 000000000..10b015195
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/SSHCheckoutTrait/config.jelly
@@ -0,0 +1,7 @@
+
+
+
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/SSHCheckoutTrait/help-credentialsId.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/SSHCheckoutTrait/help-credentialsId.html
new file mode 100644
index 000000000..f5d1cf4cf
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/SSHCheckoutTrait/help-credentialsId.html
@@ -0,0 +1,3 @@
+
+ Credentials used to check out sources. Must be a SSH key based credential.
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/SSHCheckoutTrait/help.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/SSHCheckoutTrait/help.html
new file mode 100644
index 000000000..c36738c4c
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/SSHCheckoutTrait/help.html
@@ -0,0 +1,9 @@
+
+ By default the discovered branches / pull requests will all use the same username / password credentials
+ that were used for discovery when checking out sources. This means that the checkout will be using the
+
https://
protocol for the Git / Mercurial repository.
+
+ This behaviour allows you to select the SSH private key to be used for checking out sources, which will
+ consequently force the checkout to use the ssh://
protocol.
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/WebhookRegistrationTrait/config.jelly b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/WebhookRegistrationTrait/config.jelly
new file mode 100644
index 000000000..194536ed0
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/WebhookRegistrationTrait/config.jelly
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/WebhookRegistrationTrait/help-mode.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/WebhookRegistrationTrait/help-mode.html
new file mode 100644
index 000000000..2829c4f0c
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/WebhookRegistrationTrait/help-mode.html
@@ -0,0 +1,11 @@
+
+ There are two available modes:
+
+ - Disable hook management
+ - Disables hook management irrespective of the global defaults.
+ - Use item credentials for hook management
+ - Enabled hook management but uses the selected credentials to manage the hooks rather than those defined in
+ Manage Jenkins » Configure Jenkins › Bitbucket Endpoints
+
+
+
diff --git a/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/WebhookRegistrationTrait/help.html b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/WebhookRegistrationTrait/help.html
new file mode 100644
index 000000000..3124da05d
--- /dev/null
+++ b/src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/WebhookRegistrationTrait/help.html
@@ -0,0 +1,24 @@
+
+
+ Overrides the defaults for webhook management.
+
+
+ Webhooks are used to inform Jenkins about changes to repositories. There are two ways webhooks can be
+ configured:
+
+
+ - Manual webhook configuration requires the user to configure Bitbucket with the Jenkins URL in order
+ to ensure that Bitbucket will send the events to Jenkins after every change.
+
+ - Automatic webhook configuration requires that Jenkins has credentials with sufficient permission to
+ configure webhooks and also that Jenkins knows the URL that Bitbucket can connect to.
+
+
+
+ The Manage Jenkins » Configure Jenkins › Bitbucket Endpoints allows defining the list of
+ servers. Each server
+ can be associated with credentials. If credentials are defined then the default behaviour is to use those
+ credentials to automatically manage the webhooks of all repositories that Jenkins is interested in. If no
+ credentials are defined then the default behaviour is to require the user to manually configure webhooks.
+
+
diff --git a/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketClientMockUtils.java b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketClientMockUtils.java
index 061cb6c48..cdcb58abd 100644
--- a/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketClientMockUtils.java
+++ b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketClientMockUtils.java
@@ -23,37 +23,34 @@
*/
package com.cloudbees.jenkins.plugins.bitbucket;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
+import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApi;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketHref;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryProtocol;
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryType;
-import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValueDestination;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-
-import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApi;
import com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudApiClient;
import com.cloudbees.jenkins.plugins.bitbucket.client.branch.BitbucketCloudBranch;
import com.cloudbees.jenkins.plugins.bitbucket.client.branch.BitbucketCloudCommit;
import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValue;
-import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValue.Author;
+import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValueDestination;
import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValueRepository;
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketCloudRepository;
-import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketRepositoryHook;
import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketCloudTeam;
+import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketRepositoryHook;
import com.cloudbees.jenkins.plugins.bitbucket.hooks.BitbucketSCMSourcePushHookReceiver;
-
import hudson.model.TaskListener;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
import jenkins.model.Jenkins;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class BitbucketClientMockUtils {
public static BitbucketCloudApiClient getAPIClientMock(BitbucketRepositoryType type, boolean includePullRequests,
@@ -74,14 +71,15 @@ public static BitbucketCloudApiClient getAPIClientMock(BitbucketRepositoryType t
if (includePullRequests) {
when(bitbucket.getPullRequests()).thenReturn(Arrays.asList(getPullRequest()));
- when(bitbucket.checkPathExists("my-feature-branch", "markerfile.txt")).thenReturn(true);
+ when(bitbucket.checkPathExists("e851558f77c098d21af6bb8cc54a423f7cf12147", "markerfile.txt"))
+ .thenReturn(true);
when(bitbucket.resolveSourceFullHash(any(BitbucketPullRequestValue.class)))
.thenReturn("e851558f77c098d21af6bb8cc54a423f7cf12147");
}
// mock file exists
- when(bitbucket.checkPathExists("branch1", "markerfile.txt")).thenReturn(true);
- when(bitbucket.checkPathExists("branch2", "markerfile.txt")).thenReturn(false);
+ when(bitbucket.checkPathExists("52fc8e220d77ec400f7fc96a91d2fd0bb1bc553a", "markerfile.txt")).thenReturn(true);
+ when(bitbucket.checkPathExists("707c59ce8292c927dddb6807fcf9c3c5e7c9b00f", "markerfile.txt")).thenReturn(false);
// Team discovering mocks
when(bitbucket.getTeam()).thenReturn(getTeam());
diff --git a/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketGitSCMBuilderTest.java b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketGitSCMBuilderTest.java
new file mode 100644
index 000000000..42e691de5
--- /dev/null
+++ b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketGitSCMBuilderTest.java
@@ -0,0 +1,2210 @@
+package com.cloudbees.jenkins.plugins.bitbucket;
+
+import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketHref;
+import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryType;
+import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey;
+import com.cloudbees.plugins.credentials.Credentials;
+import com.cloudbees.plugins.credentials.CredentialsScope;
+import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
+import com.cloudbees.plugins.credentials.domains.Domain;
+import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
+import hudson.plugins.git.GitSCM;
+import hudson.plugins.git.Revision;
+import hudson.plugins.git.UserRemoteConfig;
+import hudson.plugins.git.browser.BitbucketWeb;
+import hudson.plugins.git.extensions.GitSCMExtension;
+import hudson.plugins.git.extensions.impl.BuildChooserSetting;
+import hudson.util.LogTaskListener;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import jenkins.branch.BranchSource;
+import jenkins.plugins.git.AbstractGitSCMSource;
+import jenkins.scm.api.SCMHead;
+import jenkins.scm.api.SCMHeadOrigin;
+import jenkins.scm.api.SCMRevision;
+import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
+import org.eclipse.jgit.transport.RemoteConfig;
+import org.jenkinsci.plugins.gitclient.GitClient;
+import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
+import org.mockito.Mockito;
+
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class BitbucketGitSCMBuilderTest {
+ @ClassRule
+ public static JenkinsRule j = new JenkinsRule();
+ private BitbucketSCMSource source;
+ private WorkflowMultiBranchProject owner;
+
+ @Before
+ public void setUp() throws IOException {
+ owner = j.createProject(WorkflowMultiBranchProject.class);
+ source = new BitbucketSCMSource("test", "tester", "test-repo");
+ owner.setSourcesList(Collections.singletonList(new BranchSource(source)));
+ source.setOwner(owner);
+ SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(),
+ Arrays.asList(
+ new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "user-pass", null, "git-user",
+ "git-secret"), new BasicSSHUserPrivateKey(CredentialsScope.GLOBAL, "user-key", "git",
+ new BasicSSHUserPrivateKey.UsersPrivateKeySource(), null, null))));
+ }
+
+ @After
+ public void tearDown() throws IOException, InterruptedException {
+ SystemCredentialsProvider.getInstance()
+ .setDomainCredentialsMap(Collections.>emptyMap());
+ owner.delete();
+ }
+
+ @Test
+ public void given__cloud_branch_rev_anon__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ AbstractGitSCMSource.SCMRevisionImpl revision =
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__cloud_branch_rev_userpass__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ AbstractGitSCMSource.SCMRevisionImpl revision =
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__cloud_branch_rev_userkey__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ AbstractGitSCMSource.SCMRevisionImpl revision =
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("git@bitbucket.org:tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("git@bitbucket.org:tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("git@bitbucket.org:tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__cloud_branch_norev_anon__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__cloud_branch_norev_userpass__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__cloud_branch_norev_userkey__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("git@bitbucket.org:tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("git@bitbucket.org:tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("git@bitbucket.org:tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__server_branch_rev_anon__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ AbstractGitSCMSource.SCMRevisionImpl revision =
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+
+ @Test
+ public void given__server_branch_rev_userpass__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ AbstractGitSCMSource.SCMRevisionImpl revision =
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__server_branch_rev_userkey__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ AbstractGitSCMSource.SCMRevisionImpl revision =
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__server_branch_norev_anon__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__server_branch_norev_userpass__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__server_branch_norev_userkey__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/origin/test-branch"));
+ assertThat(config.getUrl(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+
+ @Test
+ public void given__cloud_pullHead_rev_anon__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__cloud_pullHead_rev_userpass__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__cloud_pullHead_rev_userkey__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("git@bitbucket.org:qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("git@bitbucket.org:qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("git@bitbucket.org:qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__cloud_pullHead_norev_anon__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__cloud_pullHead_norev_userpass__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__cloud_pullHead_norev_userkey__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("git@bitbucket.org:qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("git@bitbucket.org:qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("git@bitbucket.org:qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__server_pullHead_rev_anon__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+
+ @Test
+ public void given__server_pullHead_rev_userpass__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__server_pullHead_rev_userkey__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(BuildChooserSetting.class));
+ BuildChooserSetting chooser = (BuildChooserSetting) extension;
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__server_pullHead_norev_anon__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__server_pullHead_norev_userpass__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+ @Test
+ public void given__server_pullHead_norev_userkey__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(1));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(0));
+ }
+
+
+ @Test
+ public void given__cloud_pullMerge_rev_anon__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(2));
+ BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
+ assertThat(chooser, notNullValue());
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
+ assertThat(merge, notNullValue());
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
+ }
+
+ @Test
+ public void given__cloud_pullMerge_rev_userpass__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(2));
+ BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
+ assertThat(chooser, notNullValue());
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
+ assertThat(merge, notNullValue());
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
+ }
+
+ @Test
+ public void given__cloud_pullMerge_rev_userkey__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("git@bitbucket.org:qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("git@bitbucket.org:qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("git@bitbucket.org:tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("git@bitbucket.org:qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("git@bitbucket.org:tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(2));
+ BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
+ assertThat(chooser, notNullValue());
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
+ assertThat(merge, notNullValue());
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
+ }
+
+ @Test
+ public void given__cloud_pullMerge_norev_anon__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(MergeWithGitSCMExtension.class));
+ MergeWithGitSCMExtension merge = (MergeWithGitSCMExtension) extension;
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is(nullValue()));
+ }
+
+ @Test
+ public void given__cloud_pullMerge_norev_userpass__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.org/qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.org/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(MergeWithGitSCMExtension.class));
+ MergeWithGitSCMExtension merge = (MergeWithGitSCMExtension) extension;
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is(nullValue()));
+ }
+
+ @Test
+ public void given__cloud_pullMerge_norev_userkey__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/heads/qa-branch:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.org/tester/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("git@bitbucket.org:qa/qa-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/heads/qa-branch:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("git@bitbucket.org:qa/qa-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("git@bitbucket.org:tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("git@bitbucket.org:qa/qa-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/qa-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("git@bitbucket.org:tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ GitSCMExtension extension = actual.getExtensions().get(0);
+ assertThat(extension, instanceOf(MergeWithGitSCMExtension.class));
+ MergeWithGitSCMExtension merge = (MergeWithGitSCMExtension) extension;
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is(nullValue()));
+ }
+
+ @Test
+ public void given__server_pullMerge_rev_anon__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(2));
+ BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
+ assertThat(chooser, notNullValue());
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
+ assertThat(merge, notNullValue());
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
+ }
+
+
+ @Test
+ public void given__server_pullMerge_rev_userpass__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(2));
+ BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
+ assertThat(chooser, notNullValue());
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
+ assertThat(merge, notNullValue());
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
+ }
+
+ @Test
+ public void given__server_pullMerge_rev_userkey__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new AbstractGitSCMSource.SCMRevisionImpl(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, revision, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(2));
+ BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
+ assertThat(chooser, notNullValue());
+ assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
+ AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
+ (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
+ Collection revisions = revChooser
+ .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
+ Logger.getAnonymousLogger(), Level.FINEST), null, null);
+ assertThat(revisions, hasSize(1));
+ assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
+ assertThat(merge, notNullValue());
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
+ }
+
+ @Test
+ public void given__server_pullMerge_norev_anon__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is(nullValue()));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
+ assertThat(merge, notNullValue());
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is(nullValue()));
+ }
+
+ @Test
+ public void given__server_pullMerge_norev_userpass__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-pass"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("https://bitbucket.test/scm/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
+ assertThat(merge, notNullValue());
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is(nullValue()));
+ }
+
+ @Test
+ public void given__server_pullMerge_norev_userkey__when__build__then__scmBuilt() throws Exception {
+ source.setServerUrl("https://bitbucket.test");
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.GIT), new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.MERGE);
+ BitbucketGitSCMBuilder instance = new BitbucketGitSCMBuilder(source,
+ head, null, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.refSpecs(), contains("+refs/pull-requests/1/from:refs/remotes/@{remote}/PR-1"));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketRemote called",
+ instance.remote(), is("https://bitbucket.test"));
+ assertThat(instance.browser(), instanceOf(BitbucketWeb.class));
+ assertThat(instance.browser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://tester@bitbucket.test/scm/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.test:7999/tester/test-repo.git")
+ ));
+ assertThat(instance.remote(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+
+ GitSCM actual = instance.build();
+ assertThat(actual.getBrowser(), instanceOf(BitbucketWeb.class));
+ assertThat(actual.getBrowser().getRepoUrl(), is("https://bitbucket.test/projects/tester/repos/test-repo"));
+ assertThat(actual.getGitTool(), nullValue());
+ assertThat(actual.getUserRemoteConfigs(), hasSize(2));
+ UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
+ assertThat(config.getName(), is("origin"));
+ assertThat(config.getRefspec(), is("+refs/pull-requests/1/from:refs/remotes/origin/PR-1"));
+ assertThat(config.getUrl(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ config = actual.getUserRemoteConfigs().get(1);
+ assertThat(config.getName(), is("upstream"));
+ assertThat(config.getRefspec(), is("+refs/heads/test-branch:refs/remotes/upstream/test-branch"));
+ assertThat(config.getUrl(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(config.getCredentialsId(), is("user-key"));
+ RemoteConfig origin = actual.getRepositoryByName("origin");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull-requests/1/from"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ origin = actual.getRepositoryByName("upstream");
+ assertThat(origin, notNullValue());
+ assertThat(origin.getURIs(), hasSize(1));
+ assertThat(origin.getURIs().get(0).toString(), is("ssh://git@bitbucket.test:7999/tester/test-repo.git"));
+ assertThat(origin.getFetchRefSpecs(), hasSize(1));
+ assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/upstream/test-branch"));
+ assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
+ assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
+ assertThat(actual.getExtensions(), hasSize(1));
+ MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
+ assertThat(merge, notNullValue());
+ assertThat(merge.getBaseName(), is("remotes/upstream/test-branch"));
+ assertThat(merge.getBaseHash(), is(nullValue()));
+ }
+
+ private static T getExtension(GitSCM scm, Class type) {
+ for (GitSCMExtension e : scm.getExtensions()) {
+ if (type.isInstance(e)) {
+ return type.cast(e);
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketHgSCMBuilderTest.java b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketHgSCMBuilderTest.java
new file mode 100644
index 000000000..bb3ee40b4
--- /dev/null
+++ b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketHgSCMBuilderTest.java
@@ -0,0 +1,456 @@
+package com.cloudbees.jenkins.plugins.bitbucket;
+
+import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketHref;
+import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryType;
+import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey;
+import com.cloudbees.plugins.credentials.Credentials;
+import com.cloudbees.plugins.credentials.CredentialsScope;
+import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
+import com.cloudbees.plugins.credentials.domains.Domain;
+import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
+import hudson.plugins.mercurial.MercurialSCM;
+import hudson.plugins.mercurial.browser.BitBucket;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import jenkins.branch.BranchSource;
+import jenkins.scm.api.SCMHead;
+import jenkins.scm.api.SCMHeadOrigin;
+import jenkins.scm.api.SCMRevision;
+import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
+import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
+
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class BitbucketHgSCMBuilderTest {
+ @ClassRule
+ public static JenkinsRule j = new JenkinsRule();
+ private BitbucketSCMSource source;
+ private WorkflowMultiBranchProject owner;
+
+ @Before
+ public void setUp() throws IOException {
+ owner = j.createProject(WorkflowMultiBranchProject.class);
+ source = new BitbucketSCMSource("test", "tester", "test-repo");
+ owner.setSourcesList(Collections.singletonList(new BranchSource(source)));
+ source.setOwner(owner);
+ SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(),
+ Arrays.asList(
+ new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "user-pass", null, "git-user",
+ "git-secret"), new BasicSSHUserPrivateKey(CredentialsScope.GLOBAL, "user-key", "git",
+ new BasicSSHUserPrivateKey.UsersPrivateKeySource(), null, null))));
+ }
+
+ @After
+ public void tearDown() throws IOException, InterruptedException {
+ SystemCredentialsProvider.getInstance()
+ .setDomainCredentialsMap(Collections.>emptyMap());
+ owner.delete();
+ }
+
+ @Test
+ public void given__branch_rev_anon__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL);
+ BitbucketSCMSource.MercurialRevision revision =
+ new BitbucketSCMSource.MercurialRevision(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, revision, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("https://bitbucket.org/tester/test-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is(nullValue()));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+ assertThat(actual.getSource(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.CHANGESET));
+ assertThat(actual.getRevision(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__pullHead_rev_anon__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL),
+ new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new BitbucketSCMSource.MercurialRevision(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new BitbucketSCMSource.MercurialRevision(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, revision, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("https://bitbucket.org/qa/qa-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is(nullValue()));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/qa/qa-repo/"));
+ assertThat(actual.getSource(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.CHANGESET));
+ assertThat(actual.getRevision(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__branch_rev_userpass__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL);
+ BitbucketSCMSource.MercurialRevision revision =
+ new BitbucketSCMSource.MercurialRevision(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, revision, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("https://bitbucket.org/tester/test-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is("user-pass"));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+ assertThat(actual.getSource(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.CHANGESET));
+ assertThat(actual.getRevision(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__pullHead_rev_userpass__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL),
+ new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new BitbucketSCMSource.MercurialRevision(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new BitbucketSCMSource.MercurialRevision(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, revision, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("https://bitbucket.org/qa/qa-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is("user-pass"));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/qa/qa-repo/"));
+ assertThat(actual.getSource(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.CHANGESET));
+ assertThat(actual.getRevision(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__branch_rev_userkey__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL);
+ BitbucketSCMSource.MercurialRevision revision =
+ new BitbucketSCMSource.MercurialRevision(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, revision, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("ssh://hg@bitbucket.org/tester/test-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is("user-key"));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+ assertThat(actual.getSource(), is("ssh://hg@bitbucket.org/tester/test-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.CHANGESET));
+ assertThat(actual.getRevision(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__pullHead_rev_userkey__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL),
+ new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ PullRequestSCMRevision revision =
+ new PullRequestSCMRevision<>(head, new BitbucketSCMSource.MercurialRevision(head.getTarget(),
+ "deadbeefcafebabedeadbeefcafebabedeadbeef"),
+ new BitbucketSCMSource.MercurialRevision(head, "cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, revision, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((SCMRevision) revision));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("ssh://hg@bitbucket.org/qa/qa-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is("user-key"));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/qa/qa-repo/"));
+ assertThat(actual.getSource(), is("ssh://hg@bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.CHANGESET));
+ assertThat(actual.getRevision(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
+ }
+
+ @Test
+ public void given__branch_norev_anon__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL);
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, null, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("https://bitbucket.org/tester/test-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is(nullValue()));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+ assertThat(actual.getSource(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.BRANCH));
+ assertThat(actual.getRevision(), is("test-branch"));
+ }
+
+ @Test
+ public void given__pullHead_norev_anon__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL),
+ new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, null, null);
+ assertThat(instance.credentialsId(), is(nullValue()));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("https://bitbucket.org/qa/qa-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is(nullValue()));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/qa/qa-repo/"));
+ assertThat(actual.getSource(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.BRANCH));
+ assertThat(actual.getRevision(), is("qa-branch"));
+ }
+
+ @Test
+ public void given__branch_norev_userpass__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL);
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, null, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is((nullValue())));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("https://bitbucket.org/tester/test-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is("user-pass"));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+ assertThat(actual.getSource(), is("https://bitbucket.org/tester/test-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.BRANCH));
+ assertThat(actual.getRevision(), is("test-branch"));
+ }
+
+ @Test
+ public void given__pullHead_norev_userpass__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL),
+ new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, null, "user-pass");
+ assertThat(instance.credentialsId(), is("user-pass"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("https://bitbucket.org/qa/qa-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is("user-pass"));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/qa/qa-repo/"));
+ assertThat(actual.getSource(), is("https://bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.BRANCH));
+ assertThat(actual.getRevision(), is("qa-branch"));
+ }
+
+ @Test
+ public void given__branch_norev_userkey__when__build__then__scmBuilt() throws Exception {
+ BranchSCMHead head = new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL);
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, null, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("ssh://hg@bitbucket.org/tester/test-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is("user-key"));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+ assertThat(actual.getSource(), is("ssh://hg@bitbucket.org/tester/test-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.BRANCH));
+ assertThat(actual.getRevision(), is("test-branch"));
+ }
+
+ @Test
+ public void given__pullHead_norev_userkey__when__build__then__scmBuilt() throws Exception {
+ PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", "1",
+ new BranchSCMHead("test-branch", BitbucketRepositoryType.MERCURIAL),
+ new SCMHeadOrigin.Fork("qa/qa-repo"),
+ ChangeRequestCheckoutStrategy.HEAD);
+ BitbucketHgSCMBuilder instance = new BitbucketHgSCMBuilder(source,
+ head, null, "user-key");
+ assertThat(instance.credentialsId(), is("user-key"));
+ assertThat(instance.head(), is((SCMHead) head));
+ assertThat(instance.revision(), is(nullValue()));
+ assertThat(instance.scmSource(), is(source));
+ assertThat(instance.cloneLinks(), is(Collections.emptyList()));
+ assertThat("expecting dummy value until clone links provided or withBitbucketSource called",
+ instance.source(), is("https://bitbucket.org"));
+ assertThat(instance.browser(), instanceOf(BitBucket.class));
+ assertThat(instance.browser().getUrl().toString(), is("https://bitbucket.org/tester/test-repo/"));
+
+ instance.withCloneLinks(Arrays.asList(
+ new BitbucketHref("https", "https://bitbucket.org/tester/test-repo.git"),
+ new BitbucketHref("ssh", "ssh://git@bitbucket.org/tester/test-repo.git")
+ ));
+ assertThat(instance.source(), is("ssh://hg@bitbucket.org/qa/qa-repo"));
+
+ MercurialSCM actual = instance.build();
+ assertThat(actual.getCredentialsId(), is("user-key"));
+ assertThat(actual.getBrowser(), instanceOf(BitBucket.class));
+ assertThat(actual.getBrowser().getUrl().toString(), is("https://bitbucket.org/qa/qa-repo/"));
+ assertThat(actual.getSource(), is("ssh://hg@bitbucket.org/qa/qa-repo"));
+ assertThat(actual.getRevisionType(), is(MercurialSCM.RevisionType.BRANCH));
+ assertThat(actual.getRevision(), is("qa-branch"));
+ }
+
+}
diff --git a/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMNavigatorTest.java b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMNavigatorTest.java
new file mode 100644
index 000000000..10b55e211
--- /dev/null
+++ b/src/test/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMNavigatorTest.java
@@ -0,0 +1,963 @@
+package com.cloudbees.jenkins.plugins.bitbucket;
+
+import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
+import java.util.Arrays;
+import java.util.Collections;
+import jenkins.model.Jenkins;
+import jenkins.scm.api.trait.SCMTrait;
+import jenkins.scm.impl.trait.RegexSCMSourceFilterTrait;
+import jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait;
+import org.hamcrest.Matchers;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.jvnet.hudson.test.JenkinsRule;
+
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class BitbucketSCMNavigatorTest {
+ @ClassRule
+ public static JenkinsRule j = new JenkinsRule();
+ @Rule
+ public TestName currentTestName = new TestName();
+
+ private BitbucketSCMNavigator load() {
+ return load(currentTestName.getMethodName());
+ }
+
+ private BitbucketSCMNavigator load(String dataSet) {
+ return (BitbucketSCMNavigator) Jenkins.XSTREAM2.fromXML(
+ getClass().getResource(getClass().getSimpleName() + "/" + dataSet + ".xml"));
+ }
+
+ @Test
+ public void modern() throws Exception {
+ BitbucketSCMNavigator instance = load();
+ assertThat(instance.id(), is("https://bitbucket.org::cloudbeers"));
+ assertThat(instance.getRepoOwner(), is("cloudbeers"));
+ assertThat(instance.getServerUrl(), is(BitbucketCloudEndpoint.SERVER_URL));
+ assertThat(instance.getCredentialsId(), is("bcaef157-f105-407f-b150-df7722eab6c1"));
+ assertThat(instance.getTraits(), is(Collections.>emptyList()));
+ }
+
+ @Test
+ public void basic_cloud() throws Exception {
+ BitbucketSCMNavigator instance = load();
+ assertThat(instance.id(), is("https://bitbucket.org::cloudbeers"));
+ assertThat(instance.getRepoOwner(), is("cloudbeers"));
+ assertThat(instance.getServerUrl(), is(BitbucketCloudEndpoint.SERVER_URL));
+ assertThat(instance.getCredentialsId(), is("bcaef157-f105-407f-b150-df7722eab6c1"));
+ assertThat("SAME checkout credentials should mean no checkout trait",
+ instance.getTraits(),
+ not(hasItem(Matchers.>instanceOf(SSHCheckoutTrait.class))));
+ assertThat(".* as a pattern should mean no RegexSCMSourceFilterTrait",
+ instance.getTraits(),
+ not(hasItem(Matchers.>instanceOf(RegexSCMSourceFilterTrait.class))));
+ assertThat(instance.getTraits(),
+ containsInAnyOrder(
+ Matchers.>allOf(
+ instanceOf(BranchDiscoveryTrait.class),
+ hasProperty("buildBranch", is(true)),
+ hasProperty("buildBranchesWithPR", is(true))
+ ),
+ Matchers.>allOf(
+ instanceOf(OriginPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2))
+ ),
+ Matchers.>allOf(
+ instanceOf(ForkPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2)),
+ hasProperty("trust", instanceOf(ForkPullRequestDiscoveryTrait.TrustEveryone.class))
+ ),
+ Matchers.>instanceOf(PublicRepoPullRequestFilterTrait.class),
+ Matchers.>allOf(
+ instanceOf(WebhookRegistrationTrait.class),
+ hasProperty("mode", is(WebhookRegistration.DISABLE))
+ )
+ )
+ );
+ // legacy API
+ assertThat(instance.getBitbucketServerUrl(), is(nullValue()));
+ assertThat(instance.getCheckoutCredentialsId(), is("SAME"));
+ assertThat(instance.getPattern(), is(".*"));
+ assertThat(instance.isAutoRegisterHooks(), is(false));
+ assertThat(instance.getIncludes(), is("*"));
+ assertThat(instance.getExcludes(), is(""));
+ }
+
+ @Test
+ public void basic_server() throws Exception {
+ BitbucketSCMNavigator instance = load();
+ assertThat(instance.id(), is("https://bitbucket.test::DUB"));
+ assertThat(instance.getRepoOwner(), is("DUB"));
+ assertThat(instance.getServerUrl(), is("https://bitbucket.test"));
+ assertThat(instance.getCredentialsId(), is("bitbucket"));
+ assertThat("checkout credentials should mean checkout trait",
+ instance.getTraits(),
+ hasItem(
+ Matchers.>allOf(
+ Matchers.instanceOf(SSHCheckoutTrait.class),
+ hasProperty("credentialsId", is("8b2e4f77-39c5-41a9-b63b-8d367350bfdf"))
+ )
+ )
+ );
+ assertThat(".* as a pattern should mean no RegexSCMSourceFilterTrait",
+ instance.getTraits(),
+ not(hasItem(Matchers.>instanceOf(RegexSCMSourceFilterTrait.class))));
+ assertThat(instance.getTraits(),
+ containsInAnyOrder(
+ Matchers.>allOf(
+ instanceOf(BranchDiscoveryTrait.class),
+ hasProperty("buildBranch", is(true)),
+ hasProperty("buildBranchesWithPR", is(true))
+ ),
+ Matchers.>allOf(
+ instanceOf(OriginPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2))
+ ),
+ Matchers.>allOf(
+ instanceOf(ForkPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2)),
+ hasProperty("trust", instanceOf(ForkPullRequestDiscoveryTrait.TrustEveryone.class))
+ ),
+ Matchers.>instanceOf(PublicRepoPullRequestFilterTrait.class),
+ Matchers.>allOf(
+ instanceOf(WebhookRegistrationTrait.class),
+ hasProperty("mode", is(WebhookRegistration.DISABLE))
+ ),
+ Matchers.>allOf(
+ Matchers.instanceOf(SSHCheckoutTrait.class),
+ hasProperty("credentialsId", is("8b2e4f77-39c5-41a9-b63b-8d367350bfdf"))
+ )
+ )
+ );
+ // legacy API
+ assertThat(instance.getBitbucketServerUrl(), is("https://bitbucket.test"));
+ assertThat(instance.getCheckoutCredentialsId(), is("8b2e4f77-39c5-41a9-b63b-8d367350bfdf"));
+ assertThat(instance.getPattern(), is(".*"));
+ assertThat(instance.isAutoRegisterHooks(), is(false));
+ assertThat(instance.getIncludes(), is("*"));
+ assertThat(instance.getExcludes(), is(""));
+ }
+
+ @Test
+ public void use_agent_checkout() throws Exception {
+ BitbucketSCMNavigator instance = load();
+ assertThat(instance.id(), is("https://bitbucket.test::DUB"));
+ assertThat(instance.getRepoOwner(), is("DUB"));
+ assertThat(instance.getServerUrl(), is("https://bitbucket.test"));
+ assertThat(instance.getCredentialsId(), is("bitbucket"));
+ assertThat("checkout credentials should mean checkout trait",
+ instance.getTraits(),
+ hasItem(
+ Matchers.>allOf(
+ Matchers.instanceOf(SSHCheckoutTrait.class),
+ hasProperty("credentialsId", is(nullValue()))
+ )
+ )
+ );
+ assertThat(".* as a pattern should mean no RegexSCMSourceFilterTrait",
+ instance.getTraits(),
+ not(hasItem(Matchers.>instanceOf(RegexSCMSourceFilterTrait.class))));
+ assertThat(instance.getTraits(),
+ containsInAnyOrder(
+ Matchers.>allOf(
+ instanceOf(BranchDiscoveryTrait.class),
+ hasProperty("buildBranch", is(true)),
+ hasProperty("buildBranchesWithPR", is(true))
+ ),
+ Matchers.>allOf(
+ instanceOf(OriginPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2))
+ ),
+ Matchers.>allOf(
+ instanceOf(ForkPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2)),
+ hasProperty("trust", instanceOf(ForkPullRequestDiscoveryTrait.TrustEveryone.class))
+ ),
+ Matchers.>instanceOf(PublicRepoPullRequestFilterTrait.class),
+ Matchers.>allOf(
+ instanceOf(WebhookRegistrationTrait.class),
+ hasProperty("mode", is(WebhookRegistration.DISABLE))
+ ),
+ Matchers.>allOf(
+ Matchers.instanceOf(SSHCheckoutTrait.class),
+ hasProperty("credentialsId", is(nullValue()))
+ )
+ )
+ );
+ // legacy API
+ assertThat(instance.getBitbucketServerUrl(), is("https://bitbucket.test"));
+ assertThat(instance.getCheckoutCredentialsId(), is(BitbucketSCMSource.DescriptorImpl.ANONYMOUS));
+ assertThat(instance.getPattern(), is(".*"));
+ assertThat(instance.isAutoRegisterHooks(), is(false));
+ assertThat(instance.getIncludes(), is("*"));
+ assertThat(instance.getExcludes(), is(""));
+ }
+
+ @Test
+ public void limit_repositories() throws Exception {
+ BitbucketSCMNavigator instance = load();
+ assertThat(instance.id(), is("https://bitbucket.test::DUB"));
+ assertThat(instance.getRepoOwner(), is("DUB"));
+ assertThat(instance.getServerUrl(), is("https://bitbucket.test"));
+ assertThat(instance.getCredentialsId(), is("bitbucket"));
+ assertThat("checkout credentials should mean checkout trait",
+ instance.getTraits(),
+ hasItem(
+ Matchers.>allOf(
+ Matchers.instanceOf(SSHCheckoutTrait.class),
+ hasProperty("credentialsId", is("8b2e4f77-39c5-41a9-b63b-8d367350bfdf"))
+ )
+ )
+ );
+ assertThat(instance.getTraits(),
+ containsInAnyOrder(
+ Matchers.>allOf(
+ instanceOf(BranchDiscoveryTrait.class),
+ hasProperty("buildBranch", is(true)),
+ hasProperty("buildBranchesWithPR", is(true))
+ ),
+ Matchers.>allOf(
+ instanceOf(OriginPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2))
+ ),
+ Matchers.>allOf(
+ instanceOf(ForkPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2)),
+ hasProperty("trust", instanceOf(ForkPullRequestDiscoveryTrait.TrustEveryone.class))
+ ),
+ Matchers.>instanceOf(PublicRepoPullRequestFilterTrait.class),
+ Matchers.>allOf(
+ instanceOf(WebhookRegistrationTrait.class),
+ hasProperty("mode", is(WebhookRegistration.DISABLE))
+ ),
+ Matchers.>allOf(
+ Matchers.instanceOf(SSHCheckoutTrait.class),
+ hasProperty("credentialsId", is("8b2e4f77-39c5-41a9-b63b-8d367350bfdf"))
+ ),
+ Matchers.>allOf(
+ instanceOf(RegexSCMSourceFilterTrait.class),
+ hasProperty("regex", is("limited.*"))
+ )
+ )
+ );
+ // legacy API
+ assertThat(instance.getBitbucketServerUrl(), is("https://bitbucket.test"));
+ assertThat(instance.getCheckoutCredentialsId(), is("8b2e4f77-39c5-41a9-b63b-8d367350bfdf"));
+ assertThat(instance.getPattern(), is("limited.*"));
+ assertThat(instance.isAutoRegisterHooks(), is(false));
+ assertThat(instance.getIncludes(), is("*"));
+ assertThat(instance.getExcludes(), is(""));
+ }
+
+
+ @Test
+ public void exclude_branches() throws Exception {
+ BitbucketSCMNavigator instance = load();
+ assertThat(instance.id(), is("https://bitbucket.org::cloudbeers"));
+ assertThat(instance.getRepoOwner(), is("cloudbeers"));
+ assertThat(instance.getServerUrl(), is(BitbucketCloudEndpoint.SERVER_URL));
+ assertThat(instance.getCredentialsId(), is("bcaef157-f105-407f-b150-df7722eab6c1"));
+ assertThat(instance.getTraits(),
+ containsInAnyOrder(
+ Matchers.>allOf(
+ instanceOf(BranchDiscoveryTrait.class),
+ hasProperty("buildBranch", is(true)),
+ hasProperty("buildBranchesWithPR", is(true))
+ ),
+ Matchers.>allOf(
+ instanceOf(OriginPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2))
+ ),
+ Matchers.>allOf(
+ instanceOf(ForkPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2)),
+ hasProperty("trust", instanceOf(ForkPullRequestDiscoveryTrait.TrustEveryone.class))
+ ),
+ Matchers.>instanceOf(PublicRepoPullRequestFilterTrait.class),
+ Matchers.>allOf(
+ instanceOf(WildcardSCMHeadFilterTrait.class),
+ hasProperty("includes", is("*")),
+ hasProperty("excludes", is("master"))
+ ),
+ Matchers.>allOf(
+ instanceOf(WebhookRegistrationTrait.class),
+ hasProperty("mode", is(WebhookRegistration.DISABLE))
+ )
+ )
+ );
+ // legacy API
+ assertThat(instance.getBitbucketServerUrl(), is(nullValue()));
+ assertThat(instance.getCheckoutCredentialsId(), is("SAME"));
+ assertThat(instance.getPattern(), is(".*"));
+ assertThat(instance.isAutoRegisterHooks(), is(false));
+ assertThat(instance.getIncludes(), is("*"));
+ assertThat(instance.getExcludes(), is("master"));
+ }
+
+ @Test
+ public void limit_branches() throws Exception {
+ BitbucketSCMNavigator instance = load();
+ assertThat(instance.id(), is("https://bitbucket.org::cloudbeers"));
+ assertThat(instance.getRepoOwner(), is("cloudbeers"));
+ assertThat(instance.getServerUrl(), is(BitbucketCloudEndpoint.SERVER_URL));
+ assertThat(instance.getCredentialsId(), is("bcaef157-f105-407f-b150-df7722eab6c1"));
+ assertThat(instance.getTraits(),
+ containsInAnyOrder(
+ Matchers.>allOf(
+ instanceOf(BranchDiscoveryTrait.class),
+ hasProperty("buildBranch", is(true)),
+ hasProperty("buildBranchesWithPR", is(true))
+ ),
+ Matchers.>allOf(
+ instanceOf(OriginPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2))
+ ),
+ Matchers.>allOf(
+ instanceOf(ForkPullRequestDiscoveryTrait.class),
+ hasProperty("strategyId", is(2)),
+ hasProperty("trust", instanceOf(ForkPullRequestDiscoveryTrait.TrustEveryone.class))
+ ),
+ Matchers.