Monorepo for Tangled tangled.org

knotmirror/xrpc: return cursor and default branch in listBranches #1091

  • Added DefaultBranch field to ListBranches_Output struct
  • Computes next cursor when len(branches) == limit
  • Calls gr.FindMainBranch() to populate the default branch
  • Removed the two TODO comments
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:i2fgba5nignuw4nccml33wjp/sh.tangled.repo.pull/3mfruz3dk6o22
+16 -6
Diff #0
+16 -6
knotmirror/xrpc/repo_listBranches.go
··· 14 14 ) 15 15 16 16 type ListBranches_Output struct { 17 - Cursor *string `json:"cursor,omitempty"` 18 - Branches []types.Branch `json:"branches"` 17 + Cursor *string `json:"cursor,omitempty"` 18 + DefaultBranch string `json:"defaultBranch,omitempty"` 19 + Branches []types.Branch `json:"branches"` 19 20 } 20 21 21 22 func (x *Xrpc) ListBranches(w http.ResponseWriter, r *http.Request) { ··· 73 74 return nil, fmt.Errorf("failed to get git branches: %w", err) 74 75 } 75 76 76 - return &ListBranches_Output{ 77 + out := &ListBranches_Output{ 77 78 Branches: branches, 78 - // TODO: include default branch 79 - // TODO: return cursor 80 - }, nil 79 + } 80 + 81 + if len(branches) == limit { 82 + nextCursor := strconv.FormatInt(cursor+int64(len(branches)), 10) 83 + out.Cursor = &nextCursor 84 + } 85 + 86 + if defaultBranch, err := gr.FindMainBranch(); err == nil { 87 + out.DefaultBranch = defaultBranch 88 + } 89 + 90 + return out, nil 81 91 } 82 92 83 93 func (x *Xrpc) makeRepoPath(ctx context.Context, repo syntax.ATURI) (string, error) {

History

1 round 0 comments
sign up or login to add to the discussion
1 commit
expand
knotmirror/xrpc: return cursor and default branch in listBranches
expand 0 comments
closed without merging