MCPcopy Index your code
hub / github.com/sourcegraph/checkup / Maintain

Method Maintain

storage/github/github.go:280–330  ·  view source on GitHub ↗

Maintain deletes check files that are older than gh.CheckExpiry.

()

Source from the content-addressed store, hash-verified

278
279// Maintain deletes check files that are older than gh.CheckExpiry.
280func (gh *Storage) Maintain() error {
281 if gh.CheckExpiry == 0 {
282 return nil
283 }
284
285 if err := gh.ensureClient(); err != nil {
286 return err
287 }
288
289 index, indexSHA, err := gh.readIndex()
290 if err != nil {
291 return err
292 }
293
294 ref, _, err := gh.client.Git.GetRef(context.Background(), gh.RepositoryOwner, gh.RepositoryName, "heads/"+gh.Branch)
295 if err != nil {
296 return err
297 }
298 tree, _, err := gh.client.Git.GetTree(context.Background(), gh.RepositoryOwner, gh.RepositoryName, *ref.Object.SHA, true)
299 if err != nil {
300 return err
301 }
302
303 for _, treeEntry := range tree.Entries {
304 fileName := treeEntry.GetPath()
305
306 if fileName == filepath.Join(gh.Dir, fs.IndexName) {
307 continue
308 }
309 if gh.Dir != "" && !strings.HasPrefix(fileName, gh.Dir) {
310 log.Printf("github: maintain: skipping %s because it isn't in the configured subdirectory", fileName)
311 continue
312 }
313
314 nsec, ok := index[filepath.Base(fileName)]
315 if !ok {
316 log.Printf("github: maintain: skipping %s because it's not in the index", fileName)
317 continue
318 }
319
320 if time.Since(time.Unix(0, nsec)) > gh.CheckExpiry {
321 log.Printf("github: maintain: deleting %s", fileName)
322 if err = gh.deleteFile(fileName, treeEntry.GetSHA()); err != nil {
323 return err
324 }
325 delete(index, fileName)
326 }
327 }
328
329 return gh.writeIndex(index, indexSHA)
330}

Callers 2

TestGitHubWithoutSubdirFunction · 0.95
TestGitHubWithSubdirFunction · 0.95

Implementers 5

fakecheckup_test.go
Storagestorage/sql/sql.go
Storagestorage/s3/s3.go
Storagestorage/github/github.go
Storagestorage/fs/fs.go

Calls 4

ensureClientMethod · 0.95
readIndexMethod · 0.95
deleteFileMethod · 0.95
writeIndexMethod · 0.95

Tested by 2

TestGitHubWithoutSubdirFunction · 0.76
TestGitHubWithSubdirFunction · 0.76