Merge branch 'atmsn/delete-repo' of _OKE5H2PQKOUfzFFDuD4FA/default/CODE/gitness (#11)

This commit is contained in:
Atefeh Mohseni-Ejiyeh 2023-03-31 22:26:16 +00:00 committed by Harness
commit 5f211bdea5
14 changed files with 415 additions and 124 deletions

View File

@ -4,6 +4,20 @@
Install the latest stable version of Node and Go version 1.19 or higher, and then install the below Go programs. Ensure the GOPATH [bin directory](https://go.dev/doc/gopath_code#GOPATH) is added to your PATH.
Install protobuf
- Check if you've already installed protobuf ```protoc --version```
- If your version is different than v3.21.11, run ```brew unlink protobuf```
- Get v3.21.11 ```curl -s https://raw.githubusercontent.com/Homebrew/homebrew-core/9de8de7a533609ebfded833480c1f7c05a3448cb/Formula/protobuf.rb > /tmp/protobuf.rb```
- Install it ```brew install /tmp/protobuf.rb```
- Check out your version ```protoc --version```
Install protoc-gen-go and protoc-gen-go-rpc:
- Install protoc-gen-go v1.28.1 ```go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1```
(Note that this will install a binary in $GOBIN so make sure $GOBIN is in your $PATH)
- Install protoc-gen-go-grpc v1.2.0 ```go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0```
```bash
$ make all
```

View File

@ -11,6 +11,7 @@ import (
type Interface interface {
CreateRepository(ctx context.Context, params *CreateRepositoryParams) (*CreateRepositoryOutput, error)
DeleteRepository(ctx context.Context, params *DeleteRepositoryParams) error
GetTreeNode(ctx context.Context, params *GetTreeNodeParams) (*GetTreeNodeOutput, error)
ListTreeNodes(ctx context.Context, params *ListTreeNodeParams) (*ListTreeNodeOutput, error)
GetSubmodule(ctx context.Context, params *GetSubmoduleParams) (*GetSubmoduleOutput, error)

View File

@ -57,19 +57,21 @@ type Storage interface {
type RepositoryService struct {
rpc.UnimplementedRepositoryServiceServer
adapter GitAdapter
store Storage
reposRoot string
gitHookPath string
adapter GitAdapter
store Storage
reposRoot string
gitHookPath string
reposGraveyard string
}
func NewRepositoryService(adapter GitAdapter, store Storage, reposRoot string,
gitHookPath string) (*RepositoryService, error) {
gitHookPath string, reposGraveyard string) (*RepositoryService, error) {
return &RepositoryService{
adapter: adapter,
store: store,
reposRoot: reposRoot,
gitHookPath: gitHookPath,
adapter: adapter,
store: store,
reposRoot: reposRoot,
gitHookPath: gitHookPath,
reposGraveyard: reposGraveyard,
}, nil
}
@ -104,11 +106,17 @@ func (s RepositoryService) CreateRepository(stream rpc.RepositoryService_CreateR
ctx, cancel := context.WithCancel(ctx)
defer cancel()
err = s.adapter.InitRepository(ctx, repoPath, true)
if err != nil {
// on error cleanup repo dir
if errCleanup := os.RemoveAll(repoPath); errCleanup != nil {
log.Err(errCleanup).Msg("failed to cleanup repository dir")
// delete repo dir on error
defer func() {
if err != nil {
cleanuperr := s.DeleteRepositoryBestEffort(ctx, base.GetRepoUid())
if cleanuperr != nil {
log.Warn().Err(cleanuperr).Msg("failed to cleanup repo dir")
}
}
}()
if err != nil {
return processGitErrorf(err, "failed to initialize the repository")
}
@ -199,3 +207,39 @@ func (s RepositoryService) CreateRepository(stream rpc.RepositoryService_CreateR
func isValidGitSHA(sha string) bool {
return gitSHARegex.MatchString(sha)
}
func (s RepositoryService) DeleteRepository(ctx context.Context, request *rpc.DeleteRepositoryRequest) (*rpc.DeleteRepositoryResponse, error) {
base := request.GetBase()
if base == nil {
return nil, types.ErrBaseCannotBeEmpty
}
repoPath := getFullPathForRepo(s.reposRoot, base.RepoUid)
// check if directory exists
// if dir does not exist already fail silently
if _, err := os.Stat(repoPath); err != nil && os.IsNotExist(err) {
return nil, status.Errorf(codes.NotFound, "repository does not exist %v", repoPath)
} else if err != nil {
return nil, fmt.Errorf("failed to check the status of the repository %v: %w", repoPath, err)
}
rmerr := s.DeleteRepositoryBestEffort(ctx, base.RepoUid)
return &rpc.DeleteRepositoryResponse{}, rmerr
}
func (s *RepositoryService) DeleteRepositoryBestEffort(ctx context.Context, repoUID string) error {
repoPath := getFullPathForRepo(s.reposRoot, repoUID)
tempPath := path.Join(s.reposGraveyard, repoUID)
// move current dir to a temp dir (prevent partial deletion)
if err := os.Rename(repoPath, tempPath); err != nil {
return fmt.Errorf("couldn't move dir %s to %s : %w", repoPath, tempPath, err)
}
if err := os.RemoveAll(tempPath); err != nil {
log.Ctx(ctx).Warn().Err(err).Msgf("failed to delete dir %s from graveyard", tempPath)
}
return nil
}

View File

@ -15,6 +15,7 @@ service RepositoryService {
rpc ListCommits(ListCommitsRequest) returns (stream ListCommitsResponse);
rpc GetCommit(GetCommitRequest) returns (GetCommitResponse);
rpc GetCommitDivergences(GetCommitDivergencesRequest) returns (GetCommitDivergencesResponse);
rpc DeleteRepository(DeleteRepositoryRequest) returns (DeleteRepositoryResponse);
}
message CreateRepositoryRequest {
@ -152,4 +153,11 @@ message GetCommitDivergencesResponse {
message CommitDivergence {
int32 ahead = 1;
int32 behind = 2;
}
message DeleteRepositoryRequest {
WriteRequest base = 1;
}
message DeleteRepositoryResponse {
}

View File

@ -41,6 +41,10 @@ type CreateRepositoryOutput struct {
UID string
}
type DeleteRepositoryParams struct {
WriteParams
}
func (c *Client) CreateRepository(ctx context.Context,
params *CreateRepositoryParams) (*CreateRepositoryOutput, error) {
if params == nil {
@ -113,3 +117,17 @@ func (c *Client) CreateRepository(ctx context.Context,
func newRepositoryUID() (string, error) {
return gonanoid.Generate(repoGitUIDAlphabet, repoGitUIDLength)
}
func (c *Client) DeleteRepository(ctx context.Context, params *DeleteRepositoryParams) error {
if params == nil {
return ErrNoParamsProvided
}
_, err := c.repoService.DeleteRepository(ctx, &rpc.DeleteRepositoryRequest{
Base: mapToRPCWriteRequest(params.WriteParams),
})
if err != nil {
return processRPCErrorf(err, "failed to delete repository on server")
}
return nil
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v3.21.12
// protoc v3.21.11
// source: blame.proto
package rpc

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.12
// - protoc v3.21.11
// source: blame.proto
package rpc

View File

@ -1439,6 +1439,91 @@ func (x *CommitDivergence) GetBehind() int32 {
return 0
}
type DeleteRepositoryRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Base *WriteRequest `protobuf:"bytes,1,opt,name=base,proto3" json:"base,omitempty"`
}
func (x *DeleteRepositoryRequest) Reset() {
*x = DeleteRepositoryRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_repo_proto_msgTypes[22]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeleteRepositoryRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteRepositoryRequest) ProtoMessage() {}
func (x *DeleteRepositoryRequest) ProtoReflect() protoreflect.Message {
mi := &file_repo_proto_msgTypes[22]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeleteRepositoryRequest.ProtoReflect.Descriptor instead.
func (*DeleteRepositoryRequest) Descriptor() ([]byte, []int) {
return file_repo_proto_rawDescGZIP(), []int{22}
}
func (x *DeleteRepositoryRequest) GetBase() *WriteRequest {
if x != nil {
return x.Base
}
return nil
}
type DeleteRepositoryResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *DeleteRepositoryResponse) Reset() {
*x = DeleteRepositoryResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_repo_proto_msgTypes[23]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeleteRepositoryResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteRepositoryResponse) ProtoMessage() {}
func (x *DeleteRepositoryResponse) ProtoReflect() protoreflect.Message {
mi := &file_repo_proto_msgTypes[23]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeleteRepositoryResponse.ProtoReflect.Descriptor instead.
func (*DeleteRepositoryResponse) Descriptor() ([]byte, []int) {
return file_repo_proto_rawDescGZIP(), []int{23}
}
var File_repo_proto protoreflect.FileDescriptor
var file_repo_proto_rawDesc = []byte{
@ -1582,61 +1667,72 @@ var file_repo_proto_rawDesc = []byte{
0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x12,
0x14, 0x0a, 0x05, 0x61, 0x68, 0x65, 0x61, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05,
0x61, 0x68, 0x65, 0x61, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x65, 0x68, 0x69, 0x6e, 0x64, 0x18,
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x65, 0x68, 0x69, 0x6e, 0x64, 0x2a, 0x52, 0x0a,
0x0c, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a,
0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x54, 0x72, 0x65,
0x65, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54,
0x79, 0x70, 0x65, 0x42, 0x6c, 0x6f, 0x62, 0x10, 0x01, 0x12, 0x16, 0x0a, 0x12, 0x54, 0x72, 0x65,
0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x10,
0x02, 0x2a, 0x81, 0x01, 0x0a, 0x0c, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f,
0x64, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f,
0x64, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x10, 0x00, 0x12, 0x17, 0x0a, 0x13, 0x54, 0x72, 0x65, 0x65,
0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x53, 0x79, 0x6d, 0x6c, 0x69, 0x6e, 0x6b, 0x10,
0x01, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64,
0x65, 0x45, 0x78, 0x65, 0x63, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e,
0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x54, 0x72, 0x65, 0x65, 0x10, 0x03, 0x12, 0x16, 0x0a,
0x12, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x43, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x10, 0x04, 0x32, 0xca, 0x04, 0x0a, 0x11, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69,
0x74, 0x6f, 0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x51, 0x0a, 0x10, 0x43,
0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x12,
0x1c, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f,
0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e,
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x65, 0x68, 0x69, 0x6e, 0x64, 0x22, 0x40, 0x0a,
0x17, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72,
0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x25, 0x0a, 0x04, 0x62, 0x61, 0x73, 0x65,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x57, 0x72, 0x69,
0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x62, 0x61, 0x73, 0x65, 0x22,
0x1a, 0x0a, 0x18, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74,
0x6f, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2a, 0x52, 0x0a, 0x0c, 0x54,
0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x10, 0x54,
0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x54, 0x72, 0x65, 0x65, 0x10,
0x00, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x54, 0x79, 0x70,
0x65, 0x42, 0x6c, 0x6f, 0x62, 0x10, 0x01, 0x12, 0x16, 0x0a, 0x12, 0x54, 0x72, 0x65, 0x65, 0x4e,
0x6f, 0x64, 0x65, 0x54, 0x79, 0x70, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x10, 0x02, 0x2a,
0x81, 0x01, 0x0a, 0x0c, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65,
0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65,
0x46, 0x69, 0x6c, 0x65, 0x10, 0x00, 0x12, 0x17, 0x0a, 0x13, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f,
0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x53, 0x79, 0x6d, 0x6c, 0x69, 0x6e, 0x6b, 0x10, 0x01, 0x12,
0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x45,
0x78, 0x65, 0x63, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64,
0x65, 0x4d, 0x6f, 0x64, 0x65, 0x54, 0x72, 0x65, 0x65, 0x10, 0x03, 0x12, 0x16, 0x0a, 0x12, 0x54,
0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x69,
0x74, 0x10, 0x04, 0x32, 0x9b, 0x05, 0x0a, 0x11, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f,
0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x51, 0x0a, 0x10, 0x43, 0x72, 0x65,
0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x1c, 0x2e,
0x72, 0x70, 0x63, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69,
0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x12, 0x40,
0x0a, 0x0b, 0x47, 0x65, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x17, 0x2e,
0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74,
0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x12, 0x48, 0x0a, 0x0d, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65,
0x73, 0x12, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72, 0x65, 0x65,
0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x72,
0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x73,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x43, 0x0a, 0x0c, 0x47, 0x65,
0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x18, 0x2e, 0x72, 0x70, 0x63,
0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75,
0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x34, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x12, 0x13, 0x2e, 0x72, 0x70, 0x63,
0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x14, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x73, 0x12, 0x17, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43,
0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e,
0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x3a, 0x0a, 0x09, 0x47, 0x65, 0x74,
0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x12, 0x15, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74,
0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e,
0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5b, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d,
0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x12, 0x20, 0x2e,
0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x72, 0x70,
0x63, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f,
0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x12, 0x40, 0x0a, 0x0b,
0x47, 0x65, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x17, 0x2e, 0x72, 0x70,
0x63, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72,
0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x48,
0x0a, 0x0d, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x12,
0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f,
0x64, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x72, 0x70, 0x63,
0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x72, 0x65, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x43, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x53,
0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x18, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47,
0x65, 0x74, 0x53, 0x75, 0x62, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x19, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6d,
0x6f, 0x64, 0x75, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x34, 0x0a,
0x07, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x12, 0x13, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47,
0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e,
0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x62, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69,
0x74, 0x73, 0x12, 0x17, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x72, 0x70,
0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x73, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x3a, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x43, 0x6f,
0x6d, 0x6d, 0x69, 0x74, 0x12, 0x15, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f,
0x6d, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x72, 0x70,
0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x5b, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
0x44, 0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x12, 0x20, 0x2e, 0x72, 0x70,
0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76, 0x65, 0x72,
0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e,
0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44, 0x69, 0x76,
0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x21, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x44,
0x69, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x68, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x73, 0x2f, 0x67, 0x69, 0x74, 0x6e, 0x65, 0x73, 0x73,
0x2f, 0x67, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x12, 0x4f, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69,
0x74, 0x6f, 0x72, 0x79, 0x12, 0x1c, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74,
0x65, 0x52, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52,
0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
0x68, 0x61, 0x72, 0x6e, 0x65, 0x73, 0x73, 0x2f, 0x67, 0x69, 0x74, 0x6e, 0x65, 0x73, 0x73, 0x2f,
0x67, 0x69, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
}
var (
@ -1652,7 +1748,7 @@ func file_repo_proto_rawDescGZIP() []byte {
}
var file_repo_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
var file_repo_proto_msgTypes = make([]protoimpl.MessageInfo, 22)
var file_repo_proto_msgTypes = make([]protoimpl.MessageInfo, 24)
var file_repo_proto_goTypes = []interface{}{
(TreeNodeType)(0), // 0: rpc.TreeNodeType
(TreeNodeMode)(0), // 1: rpc.TreeNodeMode
@ -1678,58 +1774,63 @@ var file_repo_proto_goTypes = []interface{}{
(*CommitDivergenceRequest)(nil), // 21: rpc.CommitDivergenceRequest
(*GetCommitDivergencesResponse)(nil), // 22: rpc.GetCommitDivergencesResponse
(*CommitDivergence)(nil), // 23: rpc.CommitDivergence
(*FileUpload)(nil), // 24: rpc.FileUpload
(*WriteRequest)(nil), // 25: rpc.WriteRequest
(*Identity)(nil), // 26: rpc.Identity
(*ReadRequest)(nil), // 27: rpc.ReadRequest
(*Commit)(nil), // 28: rpc.Commit
(*DeleteRepositoryRequest)(nil), // 24: rpc.DeleteRepositoryRequest
(*DeleteRepositoryResponse)(nil), // 25: rpc.DeleteRepositoryResponse
(*FileUpload)(nil), // 26: rpc.FileUpload
(*WriteRequest)(nil), // 27: rpc.WriteRequest
(*Identity)(nil), // 28: rpc.Identity
(*ReadRequest)(nil), // 29: rpc.ReadRequest
(*Commit)(nil), // 30: rpc.Commit
}
var file_repo_proto_depIdxs = []int32{
3, // 0: rpc.CreateRepositoryRequest.header:type_name -> rpc.CreateRepositoryRequestHeader
24, // 1: rpc.CreateRepositoryRequest.file:type_name -> rpc.FileUpload
25, // 2: rpc.CreateRepositoryRequestHeader.base:type_name -> rpc.WriteRequest
26, // 3: rpc.CreateRepositoryRequestHeader.author:type_name -> rpc.Identity
26, // 4: rpc.CreateRepositoryRequestHeader.committer:type_name -> rpc.Identity
27, // 5: rpc.GetTreeNodeRequest.base:type_name -> rpc.ReadRequest
26, // 1: rpc.CreateRepositoryRequest.file:type_name -> rpc.FileUpload
27, // 2: rpc.CreateRepositoryRequestHeader.base:type_name -> rpc.WriteRequest
28, // 3: rpc.CreateRepositoryRequestHeader.author:type_name -> rpc.Identity
28, // 4: rpc.CreateRepositoryRequestHeader.committer:type_name -> rpc.Identity
29, // 5: rpc.GetTreeNodeRequest.base:type_name -> rpc.ReadRequest
9, // 6: rpc.GetTreeNodeResponse.node:type_name -> rpc.TreeNode
28, // 7: rpc.GetTreeNodeResponse.commit:type_name -> rpc.Commit
27, // 8: rpc.ListTreeNodesRequest.base:type_name -> rpc.ReadRequest
30, // 7: rpc.GetTreeNodeResponse.commit:type_name -> rpc.Commit
29, // 8: rpc.ListTreeNodesRequest.base:type_name -> rpc.ReadRequest
9, // 9: rpc.ListTreeNodesResponse.node:type_name -> rpc.TreeNode
28, // 10: rpc.ListTreeNodesResponse.commit:type_name -> rpc.Commit
30, // 10: rpc.ListTreeNodesResponse.commit:type_name -> rpc.Commit
0, // 11: rpc.TreeNode.type:type_name -> rpc.TreeNodeType
1, // 12: rpc.TreeNode.mode:type_name -> rpc.TreeNodeMode
27, // 13: rpc.GetCommitRequest.base:type_name -> rpc.ReadRequest
28, // 14: rpc.GetCommitResponse.commit:type_name -> rpc.Commit
27, // 15: rpc.ListCommitsRequest.base:type_name -> rpc.ReadRequest
28, // 16: rpc.ListCommitsResponse.commit:type_name -> rpc.Commit
27, // 17: rpc.GetBlobRequest.base:type_name -> rpc.ReadRequest
29, // 13: rpc.GetCommitRequest.base:type_name -> rpc.ReadRequest
30, // 14: rpc.GetCommitResponse.commit:type_name -> rpc.Commit
29, // 15: rpc.ListCommitsRequest.base:type_name -> rpc.ReadRequest
30, // 16: rpc.ListCommitsResponse.commit:type_name -> rpc.Commit
29, // 17: rpc.GetBlobRequest.base:type_name -> rpc.ReadRequest
16, // 18: rpc.GetBlobResponse.blob:type_name -> rpc.Blob
27, // 19: rpc.GetSubmoduleRequest.base:type_name -> rpc.ReadRequest
29, // 19: rpc.GetSubmoduleRequest.base:type_name -> rpc.ReadRequest
19, // 20: rpc.GetSubmoduleResponse.submodule:type_name -> rpc.Submodule
27, // 21: rpc.GetCommitDivergencesRequest.base:type_name -> rpc.ReadRequest
29, // 21: rpc.GetCommitDivergencesRequest.base:type_name -> rpc.ReadRequest
21, // 22: rpc.GetCommitDivergencesRequest.requests:type_name -> rpc.CommitDivergenceRequest
23, // 23: rpc.GetCommitDivergencesResponse.divergences:type_name -> rpc.CommitDivergence
2, // 24: rpc.RepositoryService.CreateRepository:input_type -> rpc.CreateRepositoryRequest
5, // 25: rpc.RepositoryService.GetTreeNode:input_type -> rpc.GetTreeNodeRequest
7, // 26: rpc.RepositoryService.ListTreeNodes:input_type -> rpc.ListTreeNodesRequest
17, // 27: rpc.RepositoryService.GetSubmodule:input_type -> rpc.GetSubmoduleRequest
14, // 28: rpc.RepositoryService.GetBlob:input_type -> rpc.GetBlobRequest
12, // 29: rpc.RepositoryService.ListCommits:input_type -> rpc.ListCommitsRequest
10, // 30: rpc.RepositoryService.GetCommit:input_type -> rpc.GetCommitRequest
20, // 31: rpc.RepositoryService.GetCommitDivergences:input_type -> rpc.GetCommitDivergencesRequest
4, // 32: rpc.RepositoryService.CreateRepository:output_type -> rpc.CreateRepositoryResponse
6, // 33: rpc.RepositoryService.GetTreeNode:output_type -> rpc.GetTreeNodeResponse
8, // 34: rpc.RepositoryService.ListTreeNodes:output_type -> rpc.ListTreeNodesResponse
18, // 35: rpc.RepositoryService.GetSubmodule:output_type -> rpc.GetSubmoduleResponse
15, // 36: rpc.RepositoryService.GetBlob:output_type -> rpc.GetBlobResponse
13, // 37: rpc.RepositoryService.ListCommits:output_type -> rpc.ListCommitsResponse
11, // 38: rpc.RepositoryService.GetCommit:output_type -> rpc.GetCommitResponse
22, // 39: rpc.RepositoryService.GetCommitDivergences:output_type -> rpc.GetCommitDivergencesResponse
32, // [32:40] is the sub-list for method output_type
24, // [24:32] is the sub-list for method input_type
24, // [24:24] is the sub-list for extension type_name
24, // [24:24] is the sub-list for extension extendee
0, // [0:24] is the sub-list for field type_name
27, // 24: rpc.DeleteRepositoryRequest.base:type_name -> rpc.WriteRequest
2, // 25: rpc.RepositoryService.CreateRepository:input_type -> rpc.CreateRepositoryRequest
5, // 26: rpc.RepositoryService.GetTreeNode:input_type -> rpc.GetTreeNodeRequest
7, // 27: rpc.RepositoryService.ListTreeNodes:input_type -> rpc.ListTreeNodesRequest
17, // 28: rpc.RepositoryService.GetSubmodule:input_type -> rpc.GetSubmoduleRequest
14, // 29: rpc.RepositoryService.GetBlob:input_type -> rpc.GetBlobRequest
12, // 30: rpc.RepositoryService.ListCommits:input_type -> rpc.ListCommitsRequest
10, // 31: rpc.RepositoryService.GetCommit:input_type -> rpc.GetCommitRequest
20, // 32: rpc.RepositoryService.GetCommitDivergences:input_type -> rpc.GetCommitDivergencesRequest
24, // 33: rpc.RepositoryService.DeleteRepository:input_type -> rpc.DeleteRepositoryRequest
4, // 34: rpc.RepositoryService.CreateRepository:output_type -> rpc.CreateRepositoryResponse
6, // 35: rpc.RepositoryService.GetTreeNode:output_type -> rpc.GetTreeNodeResponse
8, // 36: rpc.RepositoryService.ListTreeNodes:output_type -> rpc.ListTreeNodesResponse
18, // 37: rpc.RepositoryService.GetSubmodule:output_type -> rpc.GetSubmoduleResponse
15, // 38: rpc.RepositoryService.GetBlob:output_type -> rpc.GetBlobResponse
13, // 39: rpc.RepositoryService.ListCommits:output_type -> rpc.ListCommitsResponse
11, // 40: rpc.RepositoryService.GetCommit:output_type -> rpc.GetCommitResponse
22, // 41: rpc.RepositoryService.GetCommitDivergences:output_type -> rpc.GetCommitDivergencesResponse
25, // 42: rpc.RepositoryService.DeleteRepository:output_type -> rpc.DeleteRepositoryResponse
34, // [34:43] is the sub-list for method output_type
25, // [25:34] is the sub-list for method input_type
25, // [25:25] is the sub-list for extension type_name
25, // [25:25] is the sub-list for extension extendee
0, // [0:25] is the sub-list for field type_name
}
func init() { file_repo_proto_init() }
@ -2003,6 +2104,30 @@ func file_repo_proto_init() {
return nil
}
}
file_repo_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeleteRepositoryRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_repo_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeleteRepositoryResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
file_repo_proto_msgTypes[0].OneofWrappers = []interface{}{
(*CreateRepositoryRequest_Header)(nil),
@ -2014,7 +2139,7 @@ func file_repo_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_repo_proto_rawDesc,
NumEnums: 2,
NumMessages: 22,
NumMessages: 24,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -30,6 +30,7 @@ type RepositoryServiceClient interface {
ListCommits(ctx context.Context, in *ListCommitsRequest, opts ...grpc.CallOption) (RepositoryService_ListCommitsClient, error)
GetCommit(ctx context.Context, in *GetCommitRequest, opts ...grpc.CallOption) (*GetCommitResponse, error)
GetCommitDivergences(ctx context.Context, in *GetCommitDivergencesRequest, opts ...grpc.CallOption) (*GetCommitDivergencesResponse, error)
DeleteRepository(ctx context.Context, in *DeleteRepositoryRequest, opts ...grpc.CallOption) (*DeleteRepositoryResponse, error)
}
type repositoryServiceClient struct {
@ -183,6 +184,15 @@ func (c *repositoryServiceClient) GetCommitDivergences(ctx context.Context, in *
return out, nil
}
func (c *repositoryServiceClient) DeleteRepository(ctx context.Context, in *DeleteRepositoryRequest, opts ...grpc.CallOption) (*DeleteRepositoryResponse, error) {
out := new(DeleteRepositoryResponse)
err := c.cc.Invoke(ctx, "/rpc.RepositoryService/DeleteRepository", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// RepositoryServiceServer is the server API for RepositoryService service.
// All implementations must embed UnimplementedRepositoryServiceServer
// for forward compatibility
@ -195,6 +205,7 @@ type RepositoryServiceServer interface {
ListCommits(*ListCommitsRequest, RepositoryService_ListCommitsServer) error
GetCommit(context.Context, *GetCommitRequest) (*GetCommitResponse, error)
GetCommitDivergences(context.Context, *GetCommitDivergencesRequest) (*GetCommitDivergencesResponse, error)
DeleteRepository(context.Context, *DeleteRepositoryRequest) (*DeleteRepositoryResponse, error)
mustEmbedUnimplementedRepositoryServiceServer()
}
@ -226,6 +237,9 @@ func (UnimplementedRepositoryServiceServer) GetCommit(context.Context, *GetCommi
func (UnimplementedRepositoryServiceServer) GetCommitDivergences(context.Context, *GetCommitDivergencesRequest) (*GetCommitDivergencesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetCommitDivergences not implemented")
}
func (UnimplementedRepositoryServiceServer) DeleteRepository(context.Context, *DeleteRepositoryRequest) (*DeleteRepositoryResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteRepository not implemented")
}
func (UnimplementedRepositoryServiceServer) mustEmbedUnimplementedRepositoryServiceServer() {}
// UnsafeRepositoryServiceServer may be embedded to opt out of forward compatibility for this service.
@ -397,6 +411,24 @@ func _RepositoryService_GetCommitDivergences_Handler(srv interface{}, ctx contex
return interceptor(ctx, in, info, handler)
}
func _RepositoryService_DeleteRepository_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeleteRepositoryRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RepositoryServiceServer).DeleteRepository(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/rpc.RepositoryService/DeleteRepository",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RepositoryServiceServer).DeleteRepository(ctx, req.(*DeleteRepositoryRequest))
}
return interceptor(ctx, in, info, handler)
}
// RepositoryService_ServiceDesc is the grpc.ServiceDesc for RepositoryService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -424,6 +456,10 @@ var RepositoryService_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetCommitDivergences",
Handler: _RepositoryService_GetCommitDivergences_Handler,
},
{
MethodName: "DeleteRepository",
Handler: _RepositoryService_DeleteRepository_Handler,
},
},
Streams: []grpc.StreamDesc{
{

View File

@ -24,7 +24,8 @@ import (
)
const (
repoSubdirName = "repos"
repoSubdirName = "repos"
reposGraveyardSubdirName = "cleanup"
)
type Server struct {
@ -68,9 +69,16 @@ func NewServer(config Config) (*Server, error) {
)),
)
store := storage.NewLocalStore()
// create a temp dir for deleted repositories
// this dir should get cleaned up peridocally if it's not empty
reposGraveyard := filepath.Join(config.GitRoot, reposGraveyardSubdirName)
if _, errdir := os.Stat(reposGraveyard); os.IsNotExist(errdir) {
if errdir = os.MkdirAll(reposGraveyard, 0o700); errdir != nil {
return nil, errdir
}
}
// initialize services
repoService, err := service.NewRepositoryService(adapter, store, reposRoot, config.GitHookPath)
repoService, err := service.NewRepositoryService(adapter, store, reposRoot, config.GitHookPath, reposGraveyard)
if err != nil {
return nil, err
}

2
go.mod
View File

@ -44,7 +44,7 @@ require (
golang.org/x/sync v0.1.0
golang.org/x/term v0.2.0
google.golang.org/grpc v1.43.0
google.golang.org/protobuf v1.28.0
google.golang.org/protobuf v1.28.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

2
go.sum
View File

@ -1832,6 +1832,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -22,6 +22,7 @@ import (
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/check"
"github.com/harness/gitness/types/enum"
"github.com/rs/zerolog/log"
)
var (
@ -81,10 +82,18 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea
ForkID: in.ForkID,
DefaultBranch: in.DefaultBranch,
}
err = c.repoStore.Create(ctx, repo)
if err != nil {
// TODO: cleanup git repo!
return fmt.Errorf("faild to create repository in storage: %w", err)
dberr := c.repoStore.Create(ctx, repo)
// cleanup git repo if we fail to create repo in db (best effort deletion)
defer func() {
if dberr != nil {
err := c.DeleteRepositoryRPC(ctx, session, repo)
if err != nil {
log.Ctx(ctx).Warn().Err(err).Msg("gitrpc failed to delete repo for cleanup")
}
}
}()
if dberr != nil {
return fmt.Errorf("faild to create repository in storage: %w", dberr)
}
path := &types.Path{
@ -97,11 +106,10 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea
Created: repo.Created,
Updated: repo.Updated,
}
err = c.pathStore.Create(ctx, path)
if err != nil {
return fmt.Errorf("failed to create path: %w", err)
dberr = c.pathStore.Create(ctx, path)
if dberr != nil {
return fmt.Errorf("failed to create path: %w", dberr)
}
return nil
})
if err != nil {

View File

@ -6,10 +6,15 @@ package repo
import (
"context"
"errors"
"fmt"
"github.com/harness/gitness/gitrpc"
apiauth "github.com/harness/gitness/internal/api/auth"
"github.com/harness/gitness/internal/auth"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
"github.com/rs/zerolog/log"
)
// Delete deletes a repo.
@ -23,10 +28,32 @@ func (c *Controller) Delete(ctx context.Context, session *auth.Session, repoRef
return err
}
if err = c.DeleteRepositoryRPC(ctx, session, repo); err != nil {
return err
}
err = c.repoStore.Delete(ctx, repo.ID)
if err != nil {
return err
}
return nil
}
func (c *Controller) DeleteRepositoryRPC(ctx context.Context, session *auth.Session, repo *types.Repository) error {
writeParams, err := CreateRPCWriteParams(ctx, c.urlProvider, session, repo)
if err != nil {
return fmt.Errorf("failed to create RPC write params: %w", err)
}
err = c.gitRPCClient.DeleteRepository(ctx, &gitrpc.DeleteRepositoryParams{
WriteParams: writeParams,
})
// deletion should not fail if dir does not exist in repos dir
if errors.Is(err, gitrpc.ErrNotFound) {
log.Ctx(ctx).Warn().Msgf("gitrpc repo %s does not exist", repo.GitUID)
} else if err != nil {
// deletion has failed before removing(rename) the repo dir
return fmt.Errorf("gitrpc failed to delete repo %s: %w", repo.GitUID, err)
}
return nil
}