func (ghc *client) GetBranch(ctx context.Context, details repository.BuildDetail, name string) (repository.Branch, error) {
	repo := repository.NewRepositoryMetadata(details.RepositoryURL)
	if nil == repo {
		return repository.Branch{}, errCreatingRepositoryMetadata
	}
	branchResult, err := newBranchResult(ctx, ghc.ghClient, repo.String(), name)
	if err != nil {
		return repository.Branch{}, fmt.Errorf("GetBranch query could not be completed. Error: %s", err)
	}
	return branchResult, nil
}
GetBranch retrieves the necessary GitHub branch information used in Voucher's checks given the name of the branch
package github
import (
	"context"
	"errors"
	"fmt"
	"net/http"
	"strconv"
	"github.com/bradleyfalzon/ghinstallation"
	"github.com/shurcooL/githubv4"
	"golang.org/x/oauth2"
	"github.com/grafeas/voucher/v2/repository"
)
var errCreatingRepositoryMetadata = errors.New("failed to create repository metadata")
type ghGraphQLClient interface {
	Query(ctx context.Context, q interface{}, variables map[string]interface{}) error
}
type client struct {
	ghClient ghGraphQLClient
}
func NewClient(ctx context.Context, auth *repository.Auth) (repository.Client, error) {
	if auth == nil {
		return nil, fmt.Errorf("must provide authentication")
	}
	var httpClient *http.Client
	if auth.Type() == repository.TokenAuthType {
		sts := oauth2.StaticTokenSource(
			&oauth2.Token{AccessToken: auth.Token},
		)
		httpClient = oauth2.NewClient(ctx, sts)
		rtw := newRoundTripperWrapper(httpClient.Transport)
		httpClient.Transport = rtw
	} else if auth.Type() == repository.GithubInstallType {
		appID, err := strconv.Atoi(auth.AppID)
		if err != nil {
			return nil, fmt.Errorf("invalid application ID: %v", err)
		}
		installID, err := strconv.Atoi(auth.InstallationID)
		if err != nil {
			return nil, fmt.Errorf("invalid installation ID: %v", err)
		}
		appsTransport, err := ghinstallation.New(http.DefaultTransport, int64(appID), int64(installID), []byte(auth.PrivateKey))
		if err != nil {
			return nil, fmt.Errorf("error configuring Github App transport: %v", err)
		}
		httpClient = &http.Client{}
		httpClient.Transport = newRoundTripperWrapper(appsTransport)
	} else {
		return nil, fmt.Errorf("unsupported auth type: %s", auth.Type())
	}
	return &client{
		ghClient: githubv4.NewClient(httpClient),
	}, nil
}
func (ghc *client) GetOrganization(ctx context.Context, details repository.BuildDetail) (repository.Organization, error) {
	repo := repository.NewRepositoryMetadata(details.RepositoryURL)
	if nil == repo {
		return repository.Organization{}, fmt.Errorf("error parsing repository url %s", details.RepositoryURL)
	}
	organization, err := newRepositoryOrgInfoResult(ctx, ghc.ghClient, repo.String())
	if err != nil {
		return repository.Organization{}, err
	}
	return organization, nil
}
func (ghc *client) GetCommit(ctx context.Context, details repository.BuildDetail) (repository.Commit, error) {
	commitURI, err := GetCommitURL(&details)
	if err != nil {
		return repository.Commit{}, fmt.Errorf("error creating a commit url. Error: %s", err)
	}
	commit, err := newCommitInfoResult(ctx, ghc.ghClient, commitURI)
	if err != nil {
		return repository.Commit{}, fmt.Errorf("GetCommitInfo query could not be completed. Error: %s", err)
	}
	return commit, nil
}
func (ghc *client) GetDefaultBranch(ctx context.Context, details repository.BuildDetail) (repository.Branch, error) {
	repo := repository.NewRepositoryMetadata(details.RepositoryURL)
	if nil == repo {
		return repository.Branch{}, errCreatingRepositoryMetadata
	}
	defaultBranchResult, err := newDefaultBranchResult(ctx, ghc.ghClient, repo.String())
	if err != nil {
		return repository.Branch{}, fmt.Errorf("GetDefaultBranch query could not be completed. Error: %s", err)
	}
	return defaultBranchResult, nil
}