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

Function promptToken

bridge/gitlab/config.go:196–228  ·  view source on GitHub ↗
(baseUrl string)

Source from the content-addressed store, hash-verified

194}
195
196func 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
230func promptProjectURL(repo repository.RepoCommon, baseUrl string) (string, error) {
231 validRemotes, err := getValidGitlabRemoteURLs(repo, baseUrl)

Callers 1

promptTokenOptionsFunction · 0.70

Calls 6

NewTokenFunction · 0.92
PromptFunction · 0.92
getLoginFromTokenFunction · 0.70
PrintfMethod · 0.65
PrintlnMethod · 0.65
SetMetadataMethod · 0.65

Tested by

no test coverage detected