(repo *cache.RepoCache, params core.BridgeParams, interactive bool)
| 32 | } |
| 33 | |
| 34 | func (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 | } |
nothing calls this directly
no test coverage detected