-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuilder.go
115 lines (93 loc) · 2.9 KB
/
builder.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"fmt"
"path"
)
func NewBacklogURLBuilder(domain, spaceKey string) *BacklogURLBuilder {
return &BacklogURLBuilder{
domain: domain,
spaceKey: spaceKey,
}
}
type BacklogURLBuilder struct {
domain string
spaceKey string
projectKey string
repoName string
}
func (b *BacklogURLBuilder) SetProjectKey(key string) *BacklogURLBuilder {
b.projectKey = key
return b
}
func (b *BacklogURLBuilder) SetRepoName(name string) *BacklogURLBuilder {
b.repoName = name
return b
}
func (b *BacklogURLBuilder) Host() string {
return fmt.Sprintf("%s.%s", b.spaceKey, b.domain)
}
func (b *BacklogURLBuilder) BaseURL() string {
return "https://" + b.Host()
}
func (b *BacklogURLBuilder) GitBaseURL() string {
return b.BaseURL() + path.Join("/", "git", b.projectKey)
}
func (b *BacklogURLBuilder) GitRepoBaseURL() string {
return b.GitBaseURL() + path.Join("/", b.repoName)
}
func (b *BacklogURLBuilder) ObjectURL(refOrHash string, relPath string, isDirectory bool, line string) string {
base := "blob"
if isDirectory {
base = "tree"
}
hash := ""
if line != "" {
hash = "#" + line
}
return b.GitRepoBaseURL() + path.Join("/", base, refOrHash, relPath) + hash
}
func (b *BacklogURLBuilder) TreeURL(refOrHash string) string {
return b.GitRepoBaseURL() + path.Join("/", "tree", refOrHash)
}
func (b *BacklogURLBuilder) HistoryURL(refOrHash string) string {
return b.GitRepoBaseURL() + path.Join("/", "history", refOrHash)
}
func (b *BacklogURLBuilder) NetworkURL(refOrHash string) string {
return b.GitRepoBaseURL() + path.Join("/", "network", refOrHash)
}
func (b *BacklogURLBuilder) BranchListURL() string {
return b.GitRepoBaseURL() + path.Join("/", "branches")
}
func (b *BacklogURLBuilder) TagListURL() string {
return b.GitRepoBaseURL() + path.Join("/", "tags")
}
func (b *BacklogURLBuilder) CommitURL(hash string) string {
return b.GitRepoBaseURL() + path.Join("/", "commit", hash)
}
func (b *BacklogURLBuilder) PullRequestListURL(statusID int) string {
var q string
if statusID > 0 {
q += fmt.Sprintf("?q.statusId=%d", statusID)
}
return b.GitRepoBaseURL() + path.Join("/", "pullRequests") + q
}
func (b *BacklogURLBuilder) PullRequestURL(id string) string {
return b.GitRepoBaseURL() + path.Join("/", "pullRequests", id)
}
func (b *BacklogURLBuilder) AddPullRequestURL(base, topic string) string {
s := fmt.Sprintf("%s...%s", base, topic)
return b.GitRepoBaseURL() + path.Join("/", "pullRequests", "add", s)
}
func (b *BacklogURLBuilder) IssueListURL(statusIDs []int) string {
q := "?condition.simpleSearch=true"
for _, v := range statusIDs {
q += fmt.Sprintf("&condition.statusId=%d", v)
}
return b.BaseURL() + path.Join("/", "find", b.projectKey) + q
}
func (b *BacklogURLBuilder) IssueURL(issueKey string) string {
return b.BaseURL() + path.Join("/", "view", issueKey)
}
func (b *BacklogURLBuilder) AddIssueURL() string {
return b.BaseURL() + path.Join("/", "add", b.projectKey)
}