(baseUrl string)
| 194 | } |
| 195 | |
| 196 | func promptToken(baseUrl string) (*auth.Token, error) { |
| 197 | fmt.Printf("You can generate a new token by visiting %s.\n", strings.TrimSuffix(baseUrl, "/")+"/-/user_settings/personal_access_tokens") |
| 198 | fmt.Println("Choose 'Create personal access token' and set the necessary access scope for your repository.") |
| 199 | fmt.Println() |
| 200 | fmt.Println("'api' access scope: to be able to make api calls") |
| 201 | fmt.Println() |
| 202 | |
| 203 | re := regexp.MustCompile(`^(glpat-)?[a-zA-Z0-9\-\_]{20}$`) |
| 204 | |
| 205 | var login string |
| 206 | |
| 207 | validator := func(name string, value string) (complaint string, err error) { |
| 208 | if !re.MatchString(value) { |
| 209 | return "token has incorrect format", nil |
| 210 | } |
| 211 | login, err = getLoginFromToken(baseUrl, auth.NewToken(target, value)) |
| 212 | if err != nil { |
| 213 | return fmt.Sprintf("token is invalid: %v", err), nil |
| 214 | } |
| 215 | return "", nil |
| 216 | } |
| 217 | |
| 218 | rawToken, err := input.Prompt("Enter token", "token", input.Required, validator) |
| 219 | if err != nil { |
| 220 | return nil, err |
| 221 | } |
| 222 | |
| 223 | token := auth.NewToken(target, rawToken) |
| 224 | token.SetMetadata(auth.MetaKeyLogin, login) |
| 225 | token.SetMetadata(auth.MetaKeyBaseURL, baseUrl) |
| 226 | |
| 227 | return token, nil |
| 228 | } |
| 229 | |
| 230 | func promptProjectURL(repo repository.RepoCommon, baseUrl string) (string, error) { |
| 231 | validRemotes, err := getValidGitlabRemoteURLs(repo, baseUrl) |
no test coverage detected