Skip to content

Commit 05c81a5

Browse files
Enhance repo creation (#570)
1 parent 29bc560 commit 05c81a5

File tree

17 files changed

+71
-44
lines changed

17 files changed

+71
-44
lines changed

_mocks/opencsg.com/csghub-server/component/mock_RepoComponent.go

Lines changed: 18 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

component/code.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (c *codeComponentImpl) Create(ctx context.Context, req *types.CreateCodeReq
9393
Path: types.GitattributesFileName,
9494
},
9595
}
96-
_, dbRepo, err := c.repoComponent.CreateRepo(ctx, req.CreateRepoReq)
96+
_, dbRepo, commitFilesReq, err := c.repoComponent.CreateRepo(ctx, req.CreateRepoReq)
9797
if err != nil {
9898
return nil, err
9999
}
@@ -109,6 +109,8 @@ func (c *codeComponentImpl) Create(ctx context.Context, req *types.CreateCodeReq
109109
return nil, fmt.Errorf("failed to create database code, cause: %w", err)
110110
}
111111

112+
_ = c.gitServer.CommitFiles(ctx, *commitFilesReq)
113+
112114
for _, tag := range code.Repository.Tags {
113115
tags = append(tags, types.RepoTag{
114116
Name: tag.Name,

component/code_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/stretchr/testify/mock"
99

1010
"github.com/stretchr/testify/require"
11+
"opencsg.com/csghub-server/builder/git/gitserver"
1112
"opencsg.com/csghub-server/builder/git/membership"
1213
"opencsg.com/csghub-server/builder/store/database"
1314
"opencsg.com/csghub-server/common/types"
@@ -62,8 +63,9 @@ func TestCodeComponent_Create(t *testing.T) {
6263
return nil
6364
}).Once()
6465
cc.mocks.components.repo.EXPECT().CreateRepo(ctx, crq).Return(
65-
nil, dbrepo, nil,
66+
nil, dbrepo, &gitserver.CommitFilesReq{}, nil,
6667
)
68+
cc.mocks.gitServer.EXPECT().CommitFiles(ctx, gitserver.CommitFilesReq{}).Return(nil)
6769
cc.mocks.stores.CodeMock().EXPECT().CreateAndUpdateRepoPath(ctx, database.Code{
6870
Repository: dbrepo,
6971
RepositoryID: 1,

component/dataset.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (c *datasetComponentImpl) Create(ctx context.Context, req *types.CreateData
128128
Path: types.GitattributesFileName,
129129
},
130130
}
131-
_, dbRepo, err := c.repoComponent.CreateRepo(ctx, req.CreateRepoReq)
131+
_, dbRepo, commitFilesReq, err := c.repoComponent.CreateRepo(ctx, req.CreateRepoReq)
132132
if err != nil {
133133
return nil, err
134134
}
@@ -144,6 +144,8 @@ func (c *datasetComponentImpl) Create(ctx context.Context, req *types.CreateData
144144
return nil, fmt.Errorf("failed to create database dataset, cause: %w", err)
145145
}
146146

147+
_ = c.gitServer.CommitFiles(ctx, *commitFilesReq)
148+
147149
for _, tag := range dataset.Repository.Tags {
148150
tags = append(tags, types.RepoTag{
149151
Name: tag.Name,

component/dataset_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ func TestDatasetCompnent_Create(t *testing.T) {
5353
dc.mocks.components.repo.EXPECT().CreateRepo(ctx, rq).Return(&gitserver.CreateRepoResp{}, &database.Repository{
5454
Tags: []database.Tag{{Name: "t1"}},
5555
User: database.User{UUID: "user-uuid"},
56-
}, nil)
56+
}, &gitserver.CommitFilesReq{}, nil)
5757

58+
dc.mocks.gitServer.EXPECT().CommitFiles(ctx, gitserver.CommitFilesReq{}).Return(nil)
5859
dc.mocks.stores.DatasetMock().EXPECT().CreateAndUpdateRepoPath(ctx, mock.Anything, "ns/n").RunAndReturn(
5960
func(ctx context.Context, ds database.Dataset, _ string) (*database.Dataset, error) {
6061
require.NotNil(t, ds.Repository)

component/mcp_server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (m *mcpServerComponentImpl) Create(ctx context.Context, req *types.CreateMC
103103
Path: types.ReadmeFileName,
104104
},
105105
}
106-
_, dbRepo, err := m.repoComponent.CreateRepo(ctx, req.CreateRepoReq)
106+
_, dbRepo, commitFilesReq, err := m.repoComponent.CreateRepo(ctx, req.CreateRepoReq)
107107
if err != nil {
108108
return nil, fmt.Errorf("fail to create mcp repo cause: %w", err)
109109
}
@@ -120,6 +120,8 @@ func (m *mcpServerComponentImpl) Create(ctx context.Context, req *types.CreateMC
120120
return nil, fmt.Errorf("fail to create mcp server cause: %w", err)
121121
}
122122

123+
_ = m.gitServer.CommitFiles(ctx, *commitFilesReq)
124+
123125
for _, tag := range mcpServer.Repository.Tags {
124126
tags = append(tags, types.RepoTag{
125127
Name: tag.Name,

component/mcp_server_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ func TestMCPServerComponent_Create(t *testing.T) {
6161
Path: types.ReadmeFileName,
6262
},
6363
},
64-
}).Return(nil, dbrepo, nil)
64+
}).Return(nil, dbrepo, &gitserver.CommitFilesReq{}, nil)
65+
66+
mc.mocks.gitServer.EXPECT().CommitFiles(ctx, gitserver.CommitFilesReq{}).Return(nil)
6567

6668
mc.mocks.stores.MCPServerMock().EXPECT().CreateAndUpdateRepoPath(ctx, database.MCPServer{
6769
RepositoryID: dbrepo.ID,

component/mirror.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (c *mirrorComponentImpl) CreateMirrorRepo(ctx context.Context, req types.Cr
167167
username = dbNamespace.User.Username
168168

169169
// create repo, create mirror repo
170-
_, repo, err = c.repoComp.CreateRepo(ctx, types.CreateRepoReq{
170+
_, repo, _, err = c.repoComp.CreateRepo(ctx, types.CreateRepoReq{
171171
Username: username,
172172
Namespace: namespace,
173173
Name: name,

component/mirror_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestMirrorComponent_CreateMirrorRepo(t *testing.T) {
6363
}, nil)
6464

6565
repo1 := &database.Repository{ID: 11}
66-
mc.mocks.components.repo.EXPECT().CreateRepo(ctx, mock.AnythingOfType("types.CreateRepoReq")).Return(&gitserver.CreateRepoResp{}, repo1, nil)
66+
mc.mocks.components.repo.EXPECT().CreateRepo(ctx, mock.AnythingOfType("types.CreateRepoReq")).Return(&gitserver.CreateRepoResp{}, repo1, &gitserver.CommitFilesReq{}, nil)
6767
switch req.RepoType {
6868
case types.ModelRepo:
6969
mc.mocks.stores.ModelMock().EXPECT().CreateAndUpdateRepoPath(ctx, database.Model{

component/model.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (c *modelComponentImpl) Create(ctx context.Context, req *types.CreateModelR
267267
Path: types.GitattributesFileName,
268268
},
269269
}
270-
_, dbRepo, err := c.repoComponent.CreateRepo(ctx, req.CreateRepoReq)
270+
_, dbRepo, commitFilesReq, err := c.repoComponent.CreateRepo(ctx, req.CreateRepoReq)
271271
if err != nil {
272272
return nil, err
273273
}
@@ -287,6 +287,8 @@ func (c *modelComponentImpl) Create(ctx context.Context, req *types.CreateModelR
287287
return nil, fmt.Errorf("failed to create database model, cause: %w", err)
288288
}
289289

290+
_ = c.gitServer.CommitFiles(ctx, *commitFilesReq)
291+
290292
for _, tag := range model.Repository.Tags {
291293
tags = append(tags, types.RepoTag{
292294
Name: tag.Name,

0 commit comments

Comments
 (0)