(ctx context.Context, repo *types.RepositoryCore, branch string, )
| 153 | } |
| 154 | |
| 155 | func (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 | |
| 181 | func (c *Controller) getRepo(ctx context.Context, repoRef string) (*types.RepositoryCore, error) { |
| 182 | if repoRef == "" { |
no test coverage detected