summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorTheBlob42 <hessenmobbel@web.de>2022-04-10 15:26:31 +0200
committerJesse Duffield <jessedduffield@gmail.com>2022-04-11 17:17:40 +1000
commitbcc04664982f78fe919654f06a348e1ac25e364a (patch)
tree1be1ae4e6b5ee99c778e19ce04cb45b1fa36aa0c /pkg/commands
parent58ed23a47adbc4e0cef119c0f32adceaef28ff48 (diff)
feat: pull request support for bitbucket server
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/hosting_service/definitions.go13
-rw-r--r--pkg/commands/hosting_service/hosting_service_test.go56
2 files changed, 68 insertions, 1 deletions
diff --git a/pkg/commands/hosting_service/definitions.go b/pkg/commands/hosting_service/definitions.go
index 3e7f144da..04d496aa8 100644
--- a/pkg/commands/hosting_service/definitions.go
+++ b/pkg/commands/hosting_service/definitions.go
@@ -49,11 +49,24 @@ var azdoServiceDef = ServiceDefinition{
repoURLTemplate: "https://{{.webDomain}}/{{.org}}/{{.project}}/_git/{{.repo}}",
}
+var bitbucketServerServiceDef = ServiceDefinition{
+ provider: "bitbucketServer",
+ pullRequestURLIntoDefaultBranch: "/pull-requests?create&sourceBranch={{.From}}",
+ pullRequestURLIntoTargetBranch: "/pull-requests?create&targetBranch={{.To}}&sourceBranch={{.From}}",
+ commitURL: "/commits/{{.CommitSha}}",
+ regexStrings: []string{
+ `^ssh://git@.*/(?P<project>.*)/(?P<repo>.*?)(?:\.git)?$`,
+ `^https://.*/scm/(?P<project>.*)/(?P<repo>.*?)(?:\.git)?$`,
+ },
+ repoURLTemplate: "https://{{.webDomain}}/projects/{{.project}}/repos/{{.repo}}",
+}
+
var serviceDefinitions = []ServiceDefinition{
githubServiceDef,
bitbucketServiceDef,
gitLabServiceDef,
azdoServiceDef,
+ bitbucketServerServiceDef,
}
var defaultServiceDomains = []ServiceDomain{
diff --git a/pkg/commands/hosting_service/hosting_service_test.go b/pkg/commands/hosting_service/hosting_service_test.go
index df326c4ba..0c926117d 100644
--- a/pkg/commands/hosting_service/hosting_service_test.go
+++ b/pkg/commands/hosting_service/hosting_service_test.go
@@ -154,6 +154,60 @@ func TestGetPullRequestURL(t *testing.T) {
},
},
{
+ testName: "Opens a link to new pull request on Bitbucket Server (SSH)",
+ from: "feature/new",
+ remoteUrl: "ssh://git@mycompany.bitbucket.com/myproject/myrepo.git",
+ configServiceDomains: map[string]string{
+ // valid configuration for a bitbucket server URL
+ "mycompany.bitbucket.com": "bitbucketServer:mycompany.bitbucket.com",
+ },
+ test: func(url string, err error) {
+ assert.NoError(t, err)
+ assert.Equal(t, "https://mycompany.bitbucket.com/projects/myproject/repos/myrepo/pull-requests?create&sourceBranch=feature%2Fnew", url)
+ },
+ },
+ {
+ testName: "Opens a link to new pull request on Bitbucket Server (SSH) with specific target",
+ from: "feature/new",
+ to: "dev",
+ remoteUrl: "ssh://git@mycompany.bitbucket.com/myproject/myrepo.git",
+ configServiceDomains: map[string]string{
+ // valid configuration for a bitbucket server URL
+ "mycompany.bitbucket.com": "bitbucketServer:mycompany.bitbucket.com",
+ },
+ test: func(url string, err error) {
+ assert.NoError(t, err)
+ assert.Equal(t, "https://mycompany.bitbucket.com/projects/myproject/repos/myrepo/pull-requests?create&targetBranch=dev&sourceBranch=feature%2Fnew", url)
+ },
+ },
+ {
+ testName: "Opens a link to new pull request on Bitbucket Server (HTTP)",
+ from: "feature/new",
+ remoteUrl: "https://mycompany.bitbucket.com/scm/myproject/myrepo.git",
+ configServiceDomains: map[string]string{
+ // valid configuration for a bitbucket server URL
+ "mycompany.bitbucket.com": "bitbucketServer:mycompany.bitbucket.com",
+ },
+ test: func(url string, err error) {
+ assert.NoError(t, err)
+ assert.Equal(t, "https://mycompany.bitbucket.com/projects/myproject/repos/myrepo/pull-requests?create&sourceBranch=feature%2Fnew", url)
+ },
+ },
+ {
+ testName: "Opens a link to new pull request on Bitbucket Server (HTTP) with specific target",
+ from: "feature/new",
+ to: "dev",
+ remoteUrl: "https://mycompany.bitbucket.com/scm/myproject/myrepo.git",
+ configServiceDomains: map[string]string{
+ // valid configuration for a bitbucket server URL
+ "mycompany.bitbucket.com": "bitbucketServer:mycompany.bitbucket.com",
+ },
+ test: func(url string, err error) {
+ assert.NoError(t, err)
+ assert.Equal(t, "https://mycompany.bitbucket.com/projects/myproject/repos/myrepo/pull-requests?create&targetBranch=dev&sourceBranch=feature%2Fnew", url)
+ },
+ },
+ {
testName: "Throws an error if git service is unsupported",
from: "feature/divide-operation",
remoteUrl: "git@something.com:peter/calculator.git",
@@ -199,7 +253,7 @@ func TestGetPullRequestURL(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature%2Fprofile-page&t=1", url)
},
- expectedLoggedErrors: []string{"Unknown git service type: 'noservice'. Expected one of github, bitbucket, gitlab, azuredevops"},
+ expectedLoggedErrors: []string{"Unknown git service type: 'noservice'. Expected one of github, bitbucket, gitlab, azuredevops, bitbucketServer"},
},
{
testName: "Escapes reserved URL characters in from branch name",