-
Notifications
You must be signed in to change notification settings - Fork 1
/
repo.go
56 lines (48 loc) · 1.02 KB
/
repo.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
package main
import (
"net/url"
"regexp"
"strings"
)
var (
reParserWebURL = regexp.MustCompile(
`://([^/]+)/((users|projects)/([^/]+))/repos/([^/]+)`,
)
)
type Remote struct {
scheme string
host string
path string
project string
projectType string
repo string
user string
pass string
}
func GetRemote(opts Options) (*Remote, error) {
uri, err := url.Parse(opts.BitbucketURI)
if err != nil {
return nil, err
}
var user string
var pass string
if uri.User != nil {
user = uri.User.Username()
pass, _ = uri.User.Password()
}
remote := &Remote{
scheme: uri.Scheme,
host: uri.Host,
project: opts.Project,
projectType: "projects",
repo: opts.Repository,
user: user,
pass: pass,
path: strings.TrimSuffix(uri.Path, "/"),
}
return remote, nil
}
func getRepoWebURL(host, path, project, projectType, repo string) string {
return "http://" + host + path + "/" +
projectType + "/" + project + "/repos/" + repo
}