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

Method ListLocks

component/git_http.go:483–542  ·  view source on GitHub ↗
(ctx context.Context, req types.ListLFSLockReq)

Source from the content-addressed store, hash-verified

481}
482
483func (c *GitHTTPComponent) ListLocks(ctx context.Context, req types.ListLFSLockReq) (*types.LFSLockList, error) {
484 repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name)
485 if err != nil {
486 return nil, fmt.Errorf("failed to find repo, error: %w", err)
487 }
488
489 _, err = c.user.FindByUsername(ctx, req.CurrentUser)
490 if err != nil {
491 return nil, ErrUnauthorized
492 }
493
494 allowed, err := c.AllowReadAccess(ctx, req.RepoType, req.Namespace, req.Name, req.CurrentUser)
495 if err != nil {
496 slog.Error("Unable to check user write access:", slog.Any("error", err))
497 return nil, err
498 }
499
500 if !allowed {
501 return nil, ErrUnauthorized
502 }
503
504 if req.ID != 0 {
505 l, err := c.lfsLockStore.FindByID(ctx, req.ID)
506 if err != nil {
507 if errors.Is(err, sql.ErrNoRows) {
508 return buildLFSLockList([]database.LfsLock{}), nil
509 }
510 return buildLFSLockList([]database.LfsLock{}), err
511 }
512 if l.RepositoryID != repo.ID {
513 return buildLFSLockList([]database.LfsLock{}), nil
514 }
515 return buildLFSLockList([]database.LfsLock{*l}), nil
516 }
517
518 if req.Path != "" {
519 l, err := c.lfsLockStore.FindByPath(ctx, repo.ID, req.Path)
520 if err != nil {
521 if errors.Is(err, sql.ErrNoRows) {
522 return buildLFSLockList([]database.LfsLock{}), nil
523 }
524 return buildLFSLockList([]database.LfsLock{}), err
525 }
526 return buildLFSLockList([]database.LfsLock{*l}), nil
527 }
528
529 locks, err := c.lfsLockStore.FindByRepoID(ctx, repo.ID, req.Cursor, req.Limit)
530 if err != nil {
531 return buildLFSLockList([]database.LfsLock{}), err
532 }
533
534 next := ""
535 if req.Limit > 0 && len(locks) == req.Limit {
536 next = strconv.Itoa(req.Cursor + 1)
537 }
538 res := buildLFSLockList(locks)
539 res.Next = next
540

Callers

nothing calls this directly

Calls 7

buildLFSLockListFunction · 0.85
FindByUsernameMethod · 0.80
AllowReadAccessMethod · 0.80
ErrorMethod · 0.80
FindByPathMethod · 0.45
FindByIDMethod · 0.45
FindByRepoIDMethod · 0.45

Tested by

no test coverage detected