Monorepo for Tangled tangled.org

apview/repo/tags: Add a redirect to get latest tag #1081

merged opened by evan.jarrett.net targeting master from evan.jarrett.net/core: latest-tag

Adds the ability to point to the point to the latest tag. if first checks if latest is a real tag, if not, it gets the latest tag from the knot.

It assumes the knot will return tags in order by creation date. This appears to be the case in unit tests and calling the actual xrpc endpoint on knot1

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:pddp4xt5lgnv2qsegbzzs4xg/sh.tangled.repo.pull/3mf3xts7q7e22
+48 -1
Diff #0
+27 -1
appview/repo/tags.go
··· 4 4 "encoding/json" 5 5 "fmt" 6 6 "net/http" 7 + "net/url" 7 8 8 9 "tangled.org/core/api/tangled" 9 10 "tangled.org/core/appview/db" 10 11 "tangled.org/core/appview/models" 11 12 "tangled.org/core/appview/pages" 13 + "tangled.org/core/appview/reporesolver" 12 14 xrpcclient "tangled.org/core/appview/xrpcclient" 13 15 "tangled.org/core/orm" 14 16 "tangled.org/core/types" ··· 101 103 102 104 xrpcBytes, err := tangled.RepoTag(r.Context(), xrpcc, repo, tag) 103 105 if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil { 104 - l.Error("failed to call XRPC repo.tags", "err", xrpcerr) 106 + // if we don't match an existing tag, and the tag we're trying 107 + // to match is "latest", resolve to the most recent tag 108 + if tag == "latest" { 109 + tagsBytes, err := tangled.RepoTags(r.Context(), xrpcc, "", 1, repo) 110 + if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil { 111 + l.Error("failed to call XRPC repo.tags for latest", "err", xrpcerr) 112 + rp.pages.Error503(w) 113 + return 114 + } 115 + var tagsResult types.RepoTagsResponse 116 + if err := json.Unmarshal(tagsBytes, &tagsResult); err != nil { 117 + l.Error("failed to decode XRPC response", "err", err) 118 + rp.pages.Error503(w) 119 + return 120 + } 121 + if len(tagsResult.Tags) == 0 { 122 + rp.pages.Error503(w) 123 + return 124 + } 125 + latestTag := tagsResult.Tags[0].Name 126 + ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) 127 + http.Redirect(w, r, fmt.Sprintf("/%s/tags/%s", ownerSlashRepo, url.PathEscape(latestTag)), http.StatusTemporaryRedirect) 128 + return 129 + } 130 + l.Error("failed to call XRPC repo.tag", "err", xrpcerr) 105 131 rp.pages.Error503(w) 106 132 return 107 133 }
+21
knotserver/git/tag_test.go
··· 353 353 assert.Len(s.T(), tags, 5, "zero limit should return all tags") 354 354 } 355 355 356 + func (s *TagSuite) TestTags_OrderedNewestFirst() { 357 + s.setupRepoWithTags() 358 + 359 + tags, err := s.repo.Tags(nil) 360 + require.NoError(s.T(), err) 361 + require.Len(s.T(), tags, 5) 362 + 363 + // v3.0.0 has the latest tagger date (baseTime+3h), should be first 364 + assert.Equal(s.T(), "v3.0.0", tags[0].Name, "newest tag should be first") 365 + } 366 + 367 + func (s *TagSuite) TestTags_LatestWithLimit1() { 368 + s.setupRepoWithTags() 369 + 370 + tags, err := s.repo.Tags(&TagsOptions{Limit: 1}) 371 + require.NoError(s.T(), err) 372 + require.Len(s.T(), tags, 1) 373 + 374 + assert.Equal(s.T(), "v3.0.0", tags[0].Name, "limit=1 should return the newest tag") 375 + } 376 + 356 377 func (s *TagSuite) TestTags_Pattern() { 357 378 s.setupRepoWithTags() 358 379

History

1 round 1 comment
sign up or login to add to the discussion
evan.jarrett.net submitted #0
1 commit
expand
apview/repo/tags: Add a redirect to get latest tag
expand 1 comment

ncie addition!

pull request successfully merged