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)
| 96 | // [ErrExpiringSetupCredHelperCancelled]. configuredHelperErr carries any error from detecting the existing helper so |
| 97 | // that a missing git binary aborts before the auth flow runs. |
| 98 | func (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 | |
| 133 | func (flow *GitCredentialFlow) Scopes() []string { |
| 134 | return flow.scopes |
no test coverage detected