/
bitbucket.go
63 lines (49 loc) · 1.92 KB
/
bitbucket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package drivers
import (
"errors"
"fmt"
"net/url"
"strings"
"github.com/Originate/git-town/src/git"
)
type bitbucketCodeHostingDriver struct {
originURL string
hostname string
repository string
}
func (d *bitbucketCodeHostingDriver) CanBeUsed(driverType string) bool {
return driverType == "bitbucket" || d.hostname == "bitbucket.org"
}
func (d *bitbucketCodeHostingDriver) CanMergePullRequest(branch, parentBranch string) (bool, string, error) {
return false, "", nil
}
func (d *bitbucketCodeHostingDriver) GetNewPullRequestURL(branch, parentBranch string) string {
query := url.Values{}
query.Add("source", strings.Join([]string{d.repository, git.GetBranchSha(branch)[0:12], branch}, ":"))
query.Add("dest", strings.Join([]string{d.repository, "", parentBranch}, ":"))
return fmt.Sprintf("%s/pull-request/new?%s", d.GetRepositoryURL(), query.Encode())
}
func (d *bitbucketCodeHostingDriver) GetRepositoryURL() string {
return fmt.Sprintf("https://%s/%s", d.hostname, d.repository)
}
func (d *bitbucketCodeHostingDriver) MergePullRequest(options MergePullRequestOptions) (string, error) {
return "", errors.New("shipping pull requests via the Bitbucket API is currently not supported. If you need this functionality, please vote for it by opening a ticket at https://github.com/originate/git-town/issues")
}
func (d *bitbucketCodeHostingDriver) HostingServiceName() string {
return "Bitbucket"
}
func (d *bitbucketCodeHostingDriver) SetOriginURL(originURL string) {
d.originURL = originURL
d.hostname = git.Config().GetURLHostname(originURL)
d.repository = git.Config().GetURLRepositoryName(originURL)
}
func (d *bitbucketCodeHostingDriver) SetOriginHostname(originHostname string) {
d.hostname = originHostname
}
func (d *bitbucketCodeHostingDriver) GetAPIToken() string {
return ""
}
func (d *bitbucketCodeHostingDriver) SetAPIToken(apiToken string) {}
func init() {
registry.RegisterDriver(&bitbucketCodeHostingDriver{})
}