MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / Create

Method Create

component/code.go:33–133  ·  view source on GitHub ↗
(ctx context.Context, req *types.CreateCodeReq)

Source from the content-addressed store, hash-verified

31}
32
33func (c *CodeComponent) Create(ctx context.Context, req *types.CreateCodeReq) (*types.Code, error) {
34 var (
35 nickname string
36 tags []types.RepoTag
37 )
38
39 if req.Nickname != "" {
40 nickname = req.Nickname
41 } else {
42 nickname = req.Name
43 }
44
45 if req.DefaultBranch == "" {
46 req.DefaultBranch = "main"
47 }
48
49 req.RepoType = types.CodeRepo
50 req.Readme = generateReadmeData(req.License)
51 req.Nickname = nickname
52 _, dbRepo, err := c.CreateRepo(ctx, req.CreateRepoReq)
53 if err != nil {
54 return nil, err
55 }
56
57 dbCode := database.Code{
58 Repository: dbRepo,
59 RepositoryID: dbRepo.ID,
60 }
61
62 code, err := c.cs.Create(ctx, dbCode)
63 if err != nil {
64 return nil, fmt.Errorf("failed to create database code, cause: %w", err)
65 }
66
67 // Create README.md file
68 err = c.git.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{
69 Username: dbRepo.User.Username,
70 Email: dbRepo.User.Email,
71 Message: initCommitMessage,
72 Branch: req.DefaultBranch,
73 Content: req.Readme,
74 NewBranch: req.DefaultBranch,
75 Namespace: req.Namespace,
76 Name: req.Name,
77 FilePath: readmeFileName,
78 }, types.CodeRepo))
79 if err != nil {
80 return nil, fmt.Errorf("failed to create README.md file, cause: %w", err)
81 }
82
83 // Create .gitattributes file
84 err = c.git.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{
85 Username: dbRepo.User.Username,
86 Email: dbRepo.User.Email,
87 Message: initCommitMessage,
88 Branch: req.DefaultBranch,
89 Content: codeGitattributesContent,
90 NewBranch: req.DefaultBranch,

Callers 11

BuildObjectResponseMethod · 0.45
LfsUploadMethod · 0.45
LfsVerifyMethod · 0.45
CreateLockMethod · 0.45
CreateMirrorRepoMethod · 0.45
createUserMethod · 0.45
CreateMirrorMethod · 0.45
MirrorFromSaasMethod · 0.45
CreateRepoDiscussionMethod · 0.45
GenSyncVersionMethod · 0.45

Calls 5

BuildCloneInfoFunction · 0.92
generateReadmeDataFunction · 0.85
buildCreateFileReqFunction · 0.85
CreateRepoMethod · 0.65
CreateRepoFileMethod · 0.65

Tested by

no test coverage detected