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

Method addFiles

component/callback/git_callback.go:267–320  ·  view source on GitHub ↗
(ctx context.Context, repoType, namespace, repoName, ref string, fileNames []string)

Source from the content-addressed store, hash-verified

265}
266
267func (c *GitCallbackComponent) addFiles(ctx context.Context, repoType, namespace, repoName, ref string, fileNames []string) error {
268 for _, fileName := range fileNames {
269 slog.Debug("add file", slog.String("file", fileName))
270 // update model runtime
271 c.updateModelRuntimeFrameworks(ctx, repoType, namespace, repoName, ref, fileName, false)
272 // only care about readme file under root directory
273 if fileName == ReadmeFileName {
274 content, err := c.getFileRaw(repoType, namespace, repoName, ref, fileName)
275 if err != nil {
276 return err
277 }
278 if c.setRepoVisibility {
279 go func(content string) {
280 ok, err := c.checkFileContent(ctx, repoType, namespace, repoName, content)
281 if err != nil {
282 slog.Error("callback check file failed", slog.String("file", fileName), slog.String("error", err.Error()))
283 return
284 }
285 if !ok {
286 err := fmt.Errorf("sensitie contest detected. Set %s %s/%s to private", repoType, namespace, repoName)
287 slog.Error(err.Error())
288 return
289 }
290 }(content)
291 }
292 err = c.updateMetaTags(ctx, repoType, namespace, repoName, ref, content)
293 if err != nil {
294 return err
295 }
296 } else {
297 var tagScope database.TagScope
298 switch repoType {
299 case DatasetRepoType:
300 tagScope = database.DatasetTagScope
301 case ModelRepoType:
302 tagScope = database.ModelTagScope
303 default:
304 return nil
305 // case CodeRepoType:
306 // tagScope = database.CodeTagScope
307 // case SpaceRepoType:
308 // tagScope = database.SpaceTagScope
309 }
310 err := c.tc.UpdateLibraryTags(ctx, tagScope, namespace, repoName, "", fileName)
311 if err != nil {
312 slog.Error("failed to add Library tag", slog.String("namespace", namespace),
313 slog.String("name", repoName), slog.String("ref", ref), slog.String("fileName", fileName),
314 slog.Any("error", err))
315 return fmt.Errorf("failed to add Library tag, cause: %w", err)
316 }
317 }
318 }
319 return nil
320}
321
322func (c *GitCallbackComponent) updateMetaTags(ctx context.Context, repoType, namespace, repoName, ref, content string) error {
323 var (

Callers 1

HandlePushMethod · 0.95

Calls 6

getFileRawMethod · 0.95
checkFileContentMethod · 0.95
updateMetaTagsMethod · 0.95
ErrorMethod · 0.80
UpdateLibraryTagsMethod · 0.80

Tested by

no test coverage detected