Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hosting service definition for Azure DevOps Server #4079

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ services:
Where:

- `gitDomain` stands for the domain used by git itself (i.e. the one present on clone URLs), e.g. `git.work.com`
- `provider` is one of `github`, `bitbucket`, `bitbucketServer`, `azuredevops`, `gitlab` or `gitea`
- `provider` is one of `github`, `bitbucket`, `bitbucketServer`, `azuredevops`, `azuredevopsServer`, `gitlab` or `gitea`
- `webDomain` is the URL where your git service exposes a web interface and APIs, e.g. `gitservice.work.com`

## Predefined commit message prefix
Expand Down
13 changes: 13 additions & 0 deletions pkg/commands/hosting_service/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ var azdoServiceDef = ServiceDefinition{
repoURLTemplate: "https://{{.webDomain}}/{{.org}}/{{.project}}/_git/{{.repo}}",
}

var azdoServerServiceDef = ServiceDefinition{
provider: "azuredevopsServer",
pullRequestURLIntoDefaultBranch: "/pullrequestcreate?sourceRef={{.From}}",
pullRequestURLIntoTargetBranch: "/pullrequestcreate?sourceRef={{.From}}&targetRef={{.To}}",
commitURL: "/commit/{{.CommitHash}}",
regexStrings: []string{
`^(?:ssh://)?(?:git@)?[^:/]+(?::\d+)?[:/](?P<collection>[^/]+)/(?P<project>[^/]+)/(?P<repo>.+)$`,
`^https://[^/]+/(?P<collection>[^/]+)/(?P<project>[^/]+)/_git/(?P<repo>.+)$`,
},
repoURLTemplate: "https://{{.webDomain}}/{{.collection}}/{{.project}}/_git/{{.repo}}",
}

var bitbucketServerServiceDef = ServiceDefinition{
provider: "bitbucketServer",
pullRequestURLIntoDefaultBranch: "/pull-requests?create&sourceBranch={{.From}}",
Expand All @@ -78,6 +90,7 @@ var serviceDefinitions = []ServiceDefinition{
bitbucketServiceDef,
gitLabServiceDef,
azdoServiceDef,
azdoServerServiceDef,
bitbucketServerServiceDef,
giteaServiceDef,
}
Expand Down
64 changes: 63 additions & 1 deletion pkg/commands/hosting_service/hosting_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,68 @@ func TestGetPullRequestURL(t *testing.T) {
assert.Equal(t, "https://dev.azure.com/myorg/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew&targetRef=dev", url)
},
},
{
testName: "Opens a link to new pull request on Azure DevOps Server (SSH with scheme)",
from: "feature/new",
remoteUrl: "ssh://my.server:22/DefaultCollection/myproject/myrepo",
configServiceDomains: map[string]string{
"my.server": "azuredevopsServer:my.server",
},
test: func(url string, err error) {
assert.NoError(t, err)
assert.Equal(t, "https://my.server/DefaultCollection/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew", url)
},
},
{
testName: "Opens a link to new pull request on Azure DevOps Server (SSH without scheme)",
from: "feature/new",
remoteUrl: "git@my.server:DefaultCollection/myproject/myrepo",
configServiceDomains: map[string]string{
"my.server": "azuredevopsServer:my.server",
},
test: func(url string, err error) {
assert.NoError(t, err)
assert.Equal(t, "https://my.server/DefaultCollection/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew", url)
},
},
{
testName: "Opens a link to new pull request on Azure DevOps Server (SSH) with specific target",
from: "feature/new",
to: "dev",
remoteUrl: "git@my.server:DefaultCollection/myproject/myrepo",
configServiceDomains: map[string]string{
"my.server": "azuredevopsServer:my.server",
},
test: func(url string, err error) {
assert.NoError(t, err)
assert.Equal(t, "https://my.server/DefaultCollection/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew&targetRef=dev", url)
},
},
{
testName: "Opens a link to new pull request on Azure DevOps Server (HTTP)",
from: "feature/new",
remoteUrl: "https://my.server/DefaultCollection/myproject/_git/myrepo",
configServiceDomains: map[string]string{
"my.server": "azuredevopsServer:my.server",
},
test: func(url string, err error) {
assert.NoError(t, err)
assert.Equal(t, "https://my.server/DefaultCollection/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew", url)
},
},
{
testName: "Opens a link to new pull request on Azure DevOps Server (HTTP) with specific target",
from: "feature/new",
to: "dev",
remoteUrl: "https://my.server/DefaultCollection/myproject/_git/myrepo",
configServiceDomains: map[string]string{
"my.server": "azuredevopsServer:my.server",
},
test: func(url string, err error) {
assert.NoError(t, err)
assert.Equal(t, "https://my.server/DefaultCollection/myproject/_git/myrepo/pullrequestcreate?sourceRef=feature%2Fnew&targetRef=dev", url)
},
},
{
testName: "Opens a link to new pull request on Bitbucket Server (SSH)",
from: "feature/new",
Expand Down Expand Up @@ -388,7 +450,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, bitbucketServer, gitea"},
expectedLoggedErrors: []string{"Unknown git service type: 'noservice'. Expected one of github, bitbucket, gitlab, azuredevops, azuredevopsServer, bitbucketServer, gitea"},
},
{
testName: "Escapes reserved URL characters in from branch name",
Expand Down