MCPcopy Index your code
hub / github.com/git-bug/git-bug / Configure

Method Configure

bridge/gitlab/config.go:34–149  ·  view source on GitHub ↗
(repo *cache.RepoCache, params core.BridgeParams, interactive bool)

Source from the content-addressed store, hash-verified

32}
33
34func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams, interactive bool) (core.Configuration, error) {
35 var err error
36 var baseUrl string
37
38 switch {
39 case params.BaseURL != "":
40 baseUrl = params.BaseURL
41 default:
42 if !interactive {
43 return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the gitlab instance URL via the --base-url option.")
44 }
45 baseUrl, err = input.PromptDefault("Gitlab server URL", "URL", defaultBaseURL, input.Required, input.IsURL)
46 if err != nil {
47 return nil, errors.Wrap(err, "base url prompt")
48 }
49 }
50
51 var projectURL string
52
53 // get project url
54 switch {
55 case params.URL != "":
56 projectURL = params.URL
57 default:
58 // terminal prompt
59 if !interactive {
60 return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the gitlab project URL via the --url option.")
61 }
62 projectURL, err = promptProjectURL(repo, baseUrl)
63 if err != nil {
64 return nil, errors.Wrap(err, "url prompt")
65 }
66 }
67
68 if !strings.HasPrefix(projectURL, params.BaseURL) {
69 return nil, fmt.Errorf("base URL (%s) doesn't match the project URL (%s)", params.BaseURL, projectURL)
70 }
71
72 var login string
73 var cred auth.Credential
74
75 switch {
76 case params.CredPrefix != "":
77 cred, err = auth.LoadWithPrefix(repo, params.CredPrefix)
78 if err != nil {
79 return nil, err
80 }
81 l, ok := cred.GetMetadata(auth.MetaKeyLogin)
82 if !ok {
83 return nil, fmt.Errorf("credential doesn't have a login")
84 }
85 login = l
86 case params.TokenRaw != "":
87 token := auth.NewToken(target, params.TokenRaw)
88 login, err = getLoginFromToken(baseUrl, token)
89 if err != nil {
90 return nil, err
91 }

Callers

nothing calls this directly

Calls 15

GetMetadataMethod · 0.95
ValidateConfigMethod · 0.95
IDMethod · 0.95
PromptDefaultFunction · 0.92
LoadWithPrefixFunction · 0.92
NewTokenFunction · 0.92
PromptFunction · 0.92
IdExistFunction · 0.92
StoreFunction · 0.92
FinishConfigFunction · 0.92
promptProjectURLFunction · 0.85
validateProjectURLFunction · 0.85

Tested by

no test coverage detected