MCPcopy
hub / github.com/harness/harness / verifyBranchExistence

Method verifyBranchExistence

app/api/controller/pullreq/controller.go:155–179  ·  view source on GitHub ↗
(ctx context.Context,
	repo *types.RepositoryCore, branch string,
)

Source from the content-addressed store, hash-verified

153}
154
155func (c *Controller) verifyBranchExistence(ctx context.Context,
156 repo *types.RepositoryCore, branch string,
157) (sha.SHA, error) {
158 if branch == "" {
159 return sha.SHA{}, usererror.BadRequest("branch name can't be empty")
160 }
161
162 ref, err := c.git.GetRef(ctx,
163 git.GetRefParams{
164 ReadParams: git.ReadParams{RepoUID: repo.GitUID},
165 Name: branch,
166 Type: gitenum.RefTypeBranch,
167 })
168 if errors.AsStatus(err) == errors.StatusNotFound {
169 return sha.SHA{}, usererror.BadRequest(
170 fmt.Sprintf("branch %q does not exist in the repository %q", branch, repo.Identifier))
171 }
172 if err != nil {
173 return sha.SHA{}, fmt.Errorf(
174 "failed to check existence of the branch %q in the repository %q: %w",
175 branch, repo.Identifier, err)
176 }
177
178 return ref.SHA, nil
179}
180
181func (c *Controller) getRepo(ctx context.Context, repoRef string) (*types.RepositoryCore, error) {
182 if repoRef == "" {

Callers 3

ChangeTargetBranchMethod · 0.95
CreateMethod · 0.95
StateMethod · 0.95

Calls 4

BadRequestFunction · 0.92
AsStatusFunction · 0.92
GetRefMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected