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

Method modifyFiles

component/callback/git_callback.go:187–220  ·  view source on GitHub ↗

modifyFiles method handles modified files, skip if not modify README.md

(ctx context.Context, repoType, namespace, repoName, ref string, fileNames []string)

Source from the content-addressed store, hash-verified

185
186// modifyFiles method handles modified files, skip if not modify README.md
187func (c *GitCallbackComponent) modifyFiles(ctx context.Context, repoType, namespace, repoName, ref string, fileNames []string) error {
188 for _, fileName := range fileNames {
189 slog.Debug("modify file", slog.String("file", fileName))
190 // update model runtime
191 c.updateModelRuntimeFrameworks(ctx, repoType, namespace, repoName, ref, fileName, false)
192 // only care about readme file under root directory
193 if fileName != ReadmeFileName {
194 continue
195 }
196
197 content, err := c.getFileRaw(repoType, namespace, repoName, ref, fileName)
198 if err != nil {
199 return err
200 }
201 if c.setRepoVisibility {
202 go func(content string) {
203 ok, err := c.checkFileContent(ctx, repoType, namespace, repoName, content)
204 if err != nil {
205 slog.Error("callback check file failed", slog.String("repo", path.Join(namespace, repoName)), slog.String("file", fileName),
206 slog.String("error", err.Error()))
207 return
208 }
209 if !ok {
210 err := fmt.Errorf("sensitie context detected. Set %s %s/%s to private", repoType, namespace, repoName)
211 slog.Error(err.Error())
212 return
213 }
214 }(content)
215 }
216 // should be only one README.md
217 return c.updateMetaTags(ctx, repoType, namespace, repoName, ref, content)
218 }
219 return nil
220}
221
222func (c *GitCallbackComponent) removeFiles(ctx context.Context, repoType, namespace, repoName, ref string, fileNames []string) error {
223 // handle removed files

Callers 1

HandlePushMethod · 0.95

Calls 5

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

Tested by

no test coverage detected