(hostname string)
| 24 | } |
| 25 | |
| 26 | func (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 | var errNotInstalled *git.NotInstalled |
| 60 | if errors.As(configuredHelperErr, &errNotInstalled) { |
| 61 | return configuredHelperErr |
| 62 | } |
| 63 | |
| 64 | // On the other hand, if the user has requested setup we'll additionally request the workflow |
| 65 | // scope to ensure that git push operations that include workflow changes succeed. |
| 66 | flow.scopes = append(flow.scopes, "workflow") |
| 67 | } |
| 68 | |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | func (flow *GitCredentialFlow) Scopes() []string { |
| 73 | return flow.scopes |
no test coverage detected