-
Notifications
You must be signed in to change notification settings - Fork 785
/
common_issues.go
80 lines (74 loc) · 2.49 KB
/
common_issues.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
package cmd
import (
"fmt"
"github.com/jenkins-x/jx/pkg/auth"
"github.com/jenkins-x/jx/pkg/config"
"github.com/jenkins-x/jx/pkg/gits"
"github.com/jenkins-x/jx/pkg/issues"
"github.com/jenkins-x/jx/pkg/kube"
"github.com/jenkins-x/jx/pkg/log"
)
func (o *CommonOptions) createIssueTrackerAuthConfigService() (auth.ConfigService, error) {
secrets, err := o.LoadPipelineSecrets(kube.ValueKindIssue, "")
if err != nil {
log.Infof("The current user cannot query pipeline issue tracker secrets: %s", err)
}
return o.CreateIssueTrackerAuthConfigService(secrets)
}
func (o *CommonOptions) errorCreateIssueTrackerAuthConfigService(parentError error) (auth.ConfigService, error) {
answer, err := o.CreateIssueTrackerAuthConfigService(nil)
if err == nil {
return answer, parentError
}
return answer, err
}
func (o *CommonOptions) createIssueProvider(dir string) (issues.IssueProvider, error) {
gitDir, gitConfDir, err := o.Git().FindGitConfigDir(dir)
if err != nil {
return nil, fmt.Errorf("No issue tracker configured for this project and cannot find the .git directory: %s", err)
}
pc, _, err := config.LoadProjectConfig(dir)
if err != nil {
return nil, err
}
if pc != nil && pc.IssueTracker == nil {
pc, _, err = config.LoadProjectConfig(gitDir)
if err != nil {
return nil, err
}
}
if pc != nil {
it := pc.IssueTracker
if it != nil {
if it.URL != "" && it.Kind != "" {
authConfigSvc, err := o.createIssueTrackerAuthConfigService()
if err != nil {
return nil, err
}
config := authConfigSvc.Config()
server := config.GetOrCreateServer(it.URL)
userAuth, err := config.PickServerUserAuth(server, "user to access the issue tracker", o.BatchMode, "", o.In, o.Out, o.Err)
if err != nil {
return nil, err
}
return issues.CreateIssueProvider(it.Kind, server, userAuth, it.Project, o.BatchMode, o.Git())
}
}
}
if gitConfDir == "" {
return nil, fmt.Errorf("No issue tracker configured and no git directory could be found from dir %s\n", dir)
}
gitUrl, err := o.Git().DiscoverUpstreamGitURL(gitConfDir)
if err != nil {
return nil, fmt.Errorf("No issue tracker configured and could not find the upstream git URL for dir %s, due to: %s\n", dir, err)
}
gitInfo, err := gits.ParseGitURL(gitUrl)
if err != nil {
return nil, err
}
gitProvider, err := o.gitProviderForURL(gitUrl, "user name to use for authenticating with git issues")
if err != nil {
return nil, err
}
return issues.CreateGitIssueProvider(gitProvider, gitInfo.Organisation, gitInfo.Name)
}