-
Notifications
You must be signed in to change notification settings - Fork 1
/
git_provider.go
78 lines (66 loc) · 1.97 KB
/
git_provider.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
package issues
import (
"fmt"
"strconv"
"time"
"github.com/jenkins-x/jx/pkg/gits"
"github.com/jenkins-x/jx/pkg/util"
)
type GitIssueProvider struct {
GitProvider gits.GitProvider
Owner string
Repository string
}
func CreateGitIssueProvider(gitProvider gits.GitProvider, owner string, repository string) (IssueProvider, error) {
if owner == "" {
return nil, fmt.Errorf("No owner specified")
}
if repository == "" {
return nil, fmt.Errorf("No owner specified")
}
return &GitIssueProvider{
GitProvider: gitProvider,
Owner: owner,
Repository: repository,
}, nil
}
func (i *GitIssueProvider) GetIssue(key string) (*gits.GitIssue, error) {
n, err := issueKeyToNumber(key)
if err != nil {
return nil, err
}
return i.GitProvider.GetIssue(i.Owner, i.Repository, n)
}
func (i *GitIssueProvider) SearchIssues(query string) ([]*gits.GitIssue, error) {
return i.GitProvider.SearchIssues(i.Owner, i.Repository, query)
}
func (i *GitIssueProvider) SearchIssuesClosedSince(t time.Time) ([]*gits.GitIssue, error) {
return i.GitProvider.SearchIssuesClosedSince(i.Owner, i.Repository, t)
}
func (i *GitIssueProvider) IssueURL(key string) string {
n, err := issueKeyToNumber(key)
if err != nil {
return ""
}
return i.GitProvider.IssueURL(i.Owner, i.Repository, n, false)
}
func issueKeyToNumber(key string) (int, error) {
n, err := strconv.Atoi(key)
if err != nil {
return n, fmt.Errorf("Failed to convert issue key '%s' to number: %s", key, err)
}
return n, nil
}
func (i *GitIssueProvider) CreateIssue(issue *gits.GitIssue) (*gits.GitIssue, error) {
return i.GitProvider.CreateIssue(i.Owner, i.Repository, issue)
}
func (i *GitIssueProvider) CreateIssueComment(key string, comment string) error {
n, err := issueKeyToNumber(key)
if err != nil {
return err
}
return i.GitProvider.CreateIssueComment(i.Owner, i.Repository, n, comment)
}
func (i *GitIssueProvider) HomeURL() string {
return util.UrlJoin(i.GitProvider.ServerURL(), i.Owner, i.Repository)
}