Skip to content

Commit

Permalink
fix: Processing default branch for bitbucket (#155)
Browse files Browse the repository at this point in the history
Fixed:
- Error 'API not supported' while processing default branch for Codebase.
  Now, this error is logged, and don't block Codebase.
- The operator creates new branches from Codebase.spec.defaultBranch.
  • Loading branch information
zmotso authored and MykolaMarusenko committed Nov 5, 2024
1 parent ef8981c commit beff993
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 66 deletions.
4 changes: 2 additions & 2 deletions controllers/codebase/service/chain/put_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ func (h *PutProject) setDefaultBranch(
codebase.Spec.GetProjectID(),
codebase.Spec.DefaultBranch,
); err != nil {
if errors.Is(gitprovider.ErrApiNotSupported, err) {
if errors.Is(err, gitprovider.ErrApiNotSupported) {
// We can skip this error, because it is not supported by Git provider.
// And this is not critical for the whole process.
log.Error(err, "Setting default branch is not supported by Git provider. Set it manually if needed")
log.Info("Setting default branch is not supported by Git provider. Set it manually if needed")

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ func (h PutBranchInGit) ServeRequest(ctx context.Context, branch *codebaseApi.Co
}
}

err := h.Git.CreateRemoteBranch(string(secret.Data[util.PrivateSShKeyName]), gitServer.Spec.GitUser, wd, branch.Spec.BranchName, branch.Spec.FromCommit, gitServer.Spec.SshPort)
currentBranchName, err := h.Git.GetCurrentBranchName(wd)
if err != nil {
return fmt.Errorf("failed to get current branch name: %w", err)
}

if currentBranchName != codebase.Spec.DefaultBranch {
if err = h.Git.CheckoutRemoteBranchBySSH(string(secret.Data[util.PrivateSShKeyName]), gitServer.Spec.GitUser, wd, codebase.Spec.DefaultBranch); err != nil {
return fmt.Errorf("failed to checkout to default branch %s: %w", codebase.Spec.DefaultBranch, err)
}
}

err = h.Git.CreateRemoteBranch(string(secret.Data[util.PrivateSShKeyName]), gitServer.Spec.GitUser, wd, branch.Spec.BranchName, branch.Spec.FromCommit, gitServer.Spec.SshPort)
if err != nil {
setFailedFields(branch, codebaseApi.PutGitBranch, err.Error())

Expand Down
Loading

0 comments on commit beff993

Please sign in to comment.