Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions builder/git/gitserver/gitaly/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,28 @@ func (c *Client) CreateBranch(ctx context.Context, req gitserver.CreateBranchReq
}
return nil
}

func (c *Client) SetDefaultBranch(ctx context.Context, req gitserver.SetDefaultBranchReq) error {
repoType := fmt.Sprintf("%ss", string(req.RepoType))
relativePath, err := c.BuildRelativePath(ctx, req.RepoType, req.Namespace, req.Name)
if err != nil {
return err
}
_, err = c.repoClient.WriteRef(ctx, &gitalypb.WriteRefRequest{
Repository: &gitalypb.Repository{
StorageName: c.config.GitalyServer.Storage,
RelativePath: relativePath,
GlRepository: filepath.Join(repoType, req.Namespace, req.Name),
},
Ref: []byte("HEAD"),
Revision: []byte("refs/heads/" + req.BranchName),
})
if err != nil {
return errorx.SetDefaultBranchFailed(err, errorx.Ctx().
Set("repo_type", req.RepoType).
Set("path", relativePath).
Set("branch", req.BranchName),
)
}
return nil
}
4 changes: 4 additions & 0 deletions builder/git/gitserver/gitea/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ func (c *Client) DeleteRepoBranch(ctx context.Context, req gitserver.DeleteBranc
func (c *Client) CreateBranch(ctx context.Context, req gitserver.CreateBranchReq) error {
return nil
}

func (c *Client) SetDefaultBranch(ctx context.Context, req gitserver.SetDefaultBranchReq) error {
return nil
}
1 change: 1 addition & 0 deletions builder/git/gitserver/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type GitServer interface {
GetRepoBranches(ctx context.Context, req GetBranchesReq) ([]types.Branch, error)
GetRepoBranchByName(ctx context.Context, req GetBranchReq) (*types.Branch, error)
DeleteRepoBranch(ctx context.Context, req DeleteBranchReq) error
SetDefaultBranch(ctx context.Context, req SetDefaultBranchReq) error
GetRepoCommits(ctx context.Context, req GetRepoCommitsReq) ([]types.Commit, *types.RepoPageOpts, error)
GetRepoLastCommit(ctx context.Context, req GetRepoLastCommitReq) (*types.Commit, error)
GetSingleCommit(ctx context.Context, req GetRepoLastCommitReq) (*types.CommitResponse, error)
Expand Down
7 changes: 7 additions & 0 deletions builder/git/gitserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ type CreateBranchReq struct {
RepoType types.RepositoryType `json:"repo_type"`
}

type SetDefaultBranchReq struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
BranchName string `json:"branch_name"`
RepoType types.RepositoryType `json:"repo_type"`
}

type GetBranchReq struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
Expand Down
10 changes: 10 additions & 0 deletions common/errorx/error_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
gitBranchNotFound
gitDeleteBranchFailed
gitCreateBranchFailed
gitSetDefaultBranchFailed
gitFileNotFound
gitUploadFailed
gitDownloadFailed
Expand Down Expand Up @@ -565,6 +566,15 @@ func CreateBranchFailed(err error, ctx context) error {
}
}

func SetDefaultBranchFailed(err error, ctx context) error {
return CustomError{
prefix: errGitPrefix,
code: gitSetDefaultBranchFailed,
err: err,
context: ctx,
}
}

func GitFileNotFound(err error, ctx context) error {
return CustomError{
prefix: errGitPrefix,
Expand Down
Loading