Skip to content
Merged
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.

46 changes: 46 additions & 0 deletions builder/git/gitserver/gitaly/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,49 @@ func (c *Client) DeleteRepoBranch(ctx context.Context, req gitserver.DeleteBranc

return nil
}

func (c *Client) CreateBranch(ctx context.Context, req gitserver.CreateBranchReq) error {
repoType := fmt.Sprintf("%ss", string(req.RepoType))
relativePath, err := c.BuildRelativePath(ctx, req.RepoType, req.Namespace, req.Name)
if err != nil {
return err
}
client, err := c.refClient.UpdateReferences(ctx)
if err != nil {
return err
}
createBranchReq := &gitalypb.UpdateReferencesRequest{
Repository: &gitalypb.Repository{
StorageName: c.config.GitalyServer.Storage,
RelativePath: relativePath,
GlRepository: filepath.Join(repoType, req.Namespace, req.Name),
},
Updates: []*gitalypb.UpdateReferencesRequest_Update{
{
Reference: []byte("refs/heads/" + req.BranchName),
NewObjectId: []byte(req.CommitID),
},
},
}

err = client.Send(createBranchReq)
if err != nil {
return errorx.CreateBranchFailed(err, errorx.Ctx().
Set("repo_type", req.RepoType).
Set("path", relativePath).
Set("branch", req.BranchName).
Set("commit_id", req.CommitID),
)
}

_, err = client.CloseAndRecv()
if err != nil {
return errorx.CreateBranchFailed(err, errorx.Ctx().
Set("repo_type", req.RepoType).
Set("path", relativePath).
Set("branch", req.BranchName).
Set("commit_id", req.CommitID),
)
}
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 @@ -62,3 +62,7 @@ func (c *Client) GetRepoBranchByName(ctx context.Context, req gitserver.GetBranc
func (c *Client) DeleteRepoBranch(ctx context.Context, req gitserver.DeleteBranchReq) error {
return nil
}

func (c *Client) CreateBranch(ctx context.Context, req gitserver.CreateBranchReq) 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 @@ -26,6 +26,7 @@ type GitServer interface {
CreateRepo(ctx context.Context, req CreateRepoReq) (*CreateRepoResp, error)
UpdateRepo(ctx context.Context, req UpdateRepoReq) (*CreateRepoResp, error)
DeleteRepo(ctx context.Context, relativePath string) error
CreateBranch(ctx context.Context, req CreateBranchReq) error
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
Expand Down
8 changes: 8 additions & 0 deletions builder/git/gitserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ type GetBranchesReq struct {
RepoType types.RepositoryType `json:"repo_type"`
}

type CreateBranchReq struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
BranchName string `json:"branch_name"`
CommitID string `json:"commit_id"`
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 @@ -19,6 +19,7 @@ const (
gitFindBranchFailed
gitBranchNotFound
gitDeleteBranchFailed
gitCreateBranchFailed
gitFileNotFound
gitUploadFailed
gitDownloadFailed
Expand Down Expand Up @@ -555,6 +556,15 @@ func DeleteBranchFailed(err error, ctx context) error {
}
}

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

func GitFileNotFound(err error, ctx context) error {
return CustomError{
prefix: errGitPrefix,
Expand Down
1 change: 1 addition & 0 deletions component/checker/wire_gen.go

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

Loading