forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
60 lines (48 loc) · 1.59 KB
/
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
package issues
import (
"fmt"
"time"
"github.com/jenkins-x/jx/pkg/auth"
"github.com/jenkins-x/jx/pkg/gits"
)
type IssueProvider interface {
// GetIssue returns the issue of the given key
GetIssue(key string) (*gits.GitIssue, error)
// SearchIssues searches for issues (open by default)
SearchIssues(query string) ([]*gits.GitIssue, error)
// SearchIssuesClosedSince searches the issues closed since the given da
SearchIssuesClosedSince(t time.Time) ([]*gits.GitIssue, error)
// Creates a new issue in the current project
CreateIssue(issue *gits.GitIssue) (*gits.GitIssue, error)
// Creates a comment on the given issue
CreateIssueComment(key string, comment string) error
// IssueURL returns the URL of the given issue for this project
IssueURL(key string) string
// HomeURL returns the home URL of the issue tracker
HomeURL() string
}
func CreateIssueProvider(kind string, server *auth.AuthServer, userAuth *auth.UserAuth, project string, batchMode bool) (IssueProvider, error) {
switch kind {
case Jira:
return CreateJiraIssueProvider(server, userAuth, project, batchMode)
default:
return nil, fmt.Errorf("Unsupported issue provider kind: %s", kind)
}
}
func ProviderAccessTokenURL(kind string, url string) string {
switch kind {
case Jira:
// TODO handle on premise servers too by detecting the URL is at atlassian.com
return "https://id.atlassian.com/manage/api-tokens"
default:
return ""
}
}
// GetIssueProvider returns the kind of issue provider
func GetIssueProvider(tracker IssueProvider) string {
_, ok := tracker.(*JiraService)
if ok {
return Jira
}
return Git
}