MCPcopy Create free account
hub / github.com/cli/cli / Prompt

Method Prompt

pkg/cmd/auth/shared/git_credential.go:26–69  ·  view source on GitHub ↗
(hostname string)

Source from the content-addressed store, hash-verified

24}
25
26func (flow *GitCredentialFlow) Prompt(hostname string) error {
27 // First we'll fetch the credential helper that would be used for this host
28 var configuredHelperErr error
29 flow.helper, configuredHelperErr = flow.HelperConfig.ConfiguredHelper(hostname)
30 // If the helper is gh itself, then we don't need to ask the user if they want to update their git credentials
31 // because it will happen automatically by virtue of the fact that gh will return the active token.
32 //
33 // Since gh is the helper, this token may be used for git operations, so we'll additionally request the workflow
34 // scope to ensure that git push operations that include workflow changes succeed.
35 if flow.helper.IsOurs() {
36 flow.scopes = append(flow.scopes, "workflow")
37 return nil
38 }
39
40 // Prompt the user for whether they want to configure git with the newly obtained token
41 result, err := flow.Prompter.Confirm("Authenticate Git with your GitHub credentials?", true)
42 if err != nil {
43 return err
44 }
45 flow.shouldSetup = result
46
47 if flow.shouldSetup {
48 // If the user does want to configure git, we'll check the error returned from fetching the configured helper
49 // above. If the error indicates that git isn't installed, we'll return an error now to ensure that the auth
50 // flow is aborted before the user goes any further.
51 //
52 // Note that this is _slightly_ naive because there may be other reasons that fetching the configured helper
53 // fails that might cause later failures but this code has existed for a long time and I don't want to change
54 // it as part of a refactoring.
55 //
56 // Refs:
57 // * https://git-scm.com/docs/git-config#_description
58 // * https://github.com/cli/cli/pull/4109
59 if _, ok := errors.AsType[*git.NotInstalled](configuredHelperErr); ok {
60 return configuredHelperErr
61 }
62
63 // On the other hand, if the user has requested setup we'll additionally request the workflow
64 // scope to ensure that git push operations that include workflow changes succeed.
65 flow.scopes = append(flow.scopes, "workflow")
66 }
67
68 return nil
69}
70
71func (flow *GitCredentialFlow) Scopes() []string {
72 return flow.scopes

Callers 1

refreshRunFunction · 0.95

Calls 3

IsOursMethod · 0.80
ConfiguredHelperMethod · 0.65
ConfirmMethod · 0.65

Tested by

no test coverage detected