prow/flagutil/github.go
func (o *GitHubOptions) GitClient(secretAgent *secret.Agent, dryRun bool) (client *git.Client, err error) {
	client, err = git.NewClient()
	if err != nil {
		return nil, err
	}

	// We must capture the value of client here to prevent issues related
	// to the use of named return values when an error is encountered.
	// Without this, we risk a nil pointer dereference.
	defer func(client *git.Client) {
		if err != nil {
			client.Clean()
		}
	}(client)

	// Get the bot's name in order to set credentials for the Git client.
	githubClient, err := o.GitHubClient(secretAgent, dryRun)
	if err != nil {
		return nil, fmt.Errorf("error getting GitHub client: %v", err)
	}
	botName, err := githubClient.BotName()
	if err != nil {
		return nil, fmt.Errorf("error getting bot name: %v", err)
	}
	client.SetCredentials(botName, secretAgent.GetTokenGenerator(o.TokenPath))

	return client, nil
}
func (o *GitHubOptions) GitClient(secretAgent *secret.Agent, dryRun bool) (client *git.Client, err error) {
	client, err = git.NewClient()
	if err != nil {
		return nil, err
	}

	// We must capture the value of client here to prevent issues related
	// to the use of named return values when an error is encountered.
	// Without this, we risk a nil pointer dereference.
	defer func(client *git.Client) {
		if err != nil {
			client.Clean()
		}
	}(client)

	// Get the bot's name in order to set credentials for the Git client.
	githubClient, err := o.GitHubClient(secretAgent, dryRun)
	if err != nil {
		return nil, fmt.Errorf("error getting GitHub client: %v", err)
	}
	botName, err := githubClient.BotName()
	if err != nil {
		return nil, fmt.Errorf("error getting bot name: %v", err)
	}
	client.SetCredentials(botName, secretAgent.GetTokenGenerator(o.TokenPath))

	return client, nil
}
func ( o * GitHubOptions ) GitClient ( secretAgent * secret . Agent , dryRun bool ) ( client * git . Client , err error ) { client , err = git . NewClient ( ) if err != nil { return nil , err } // We must capture the value of client here to prevent issues related // to the use of named return values when an error is encountered. // Without this, we risk a nil pointer dereference. defer func ( client * git . Client ) { if err != nil { client . Clean ( ) } } ( client ) // Get the bot's name in order to set credentials for the Git client. githubClient , err := o . GitHubClient ( secretAgent , dryRun ) if err != nil { return nil , fmt . Errorf ( " " , err ) } botName , err := githubClient . BotName ( ) if err != nil { return nil , fmt . Errorf ( " " , err ) } client . SetCredentials ( botName , secretAgent . GetTokenGenerator ( o . TokenPath ) ) return client , nil }
// GitClient returns a Git client.
GitClient returns a Git client .