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

Method promptExpiring

pkg/cmd/auth/shared/git_credential.go:98–131  ·  view source on GitHub ↗

promptExpiring runs the credential-helper decision for an expiring login. gh must be the git credential helper to refresh an expiring token, so the consequence of declining is printed as a warning and the user is offered three choices: configure gh, continue without it, or stop the sign-in. Cancelli

(hostname string, configuredHelperErr error)

Source from the content-addressed store, hash-verified

96// [ErrExpiringSetupCredHelperCancelled]. configuredHelperErr carries any error from detecting the existing helper so
97// that a missing git binary aborts before the auth flow runs.
98func (flow *GitCredentialFlow) promptExpiring(hostname string, configuredHelperErr error) error {
99 cs := flow.IO.ColorScheme()
100 fmt.Fprintf(flow.IO.ErrOut,
101 "%s You asked for an expiring token, which gh refreshes automatically. For that to work, gh must be your "+
102 "Git credential helper for %s. Otherwise Git will not learn about refreshed tokens and your HTTPS Git "+
103 "operations will start to fail once the current token expires, within hours.\n",
104 cs.WarningIcon(), hostname)
105
106 options := []string{
107 "Set up gh as your Git credential helper (recommended)",
108 "Continue without it (you manage Git credentials yourself)",
109 "Cancel",
110 }
111
112 choice, err := flow.Prompter.Select("How would you like to proceed?", options[0], options)
113 if err != nil {
114 return err
115 }
116
117 switch choice {
118 case 0: // Set up gh as the Git credential helper.
119 // Abort before the auth flow if git isn't installed, matching the non-expiring prompt above.
120 if _, ok := errors.AsType[*git.NotInstalled](configuredHelperErr); ok {
121 return configuredHelperErr
122 }
123 flow.shouldSetup = true
124 flow.scopes = append(flow.scopes, "workflow")
125 case 2: // Cancel the sign-in.
126 return ErrExpiringSetupCredHelperCancelled
127 }
128 // case 1 (continue without gh): shouldSetup stays false, the user accepted that git will not be configured.
129
130 return nil
131}
132
133func (flow *GitCredentialFlow) Scopes() []string {
134 return flow.scopes

Callers 1

PromptMethod · 0.95

Calls 3

ColorSchemeMethod · 0.80
WarningIconMethod · 0.80
SelectMethod · 0.65

Tested by

no test coverage detected