Monorepo for Tangled tangled.org

draft: render backlinks #765

merged opened by boltless.me targeting master from feat/mentions
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3m4ya772l5c22
+48 -9
Interdiff #6 #7
+3 -3
appview/db/reference.go
··· 397 397 rows, err := e.Query( 398 398 fmt.Sprintf( 399 399 `select r.did, r.name, p.pull_id, p.title, p.state 400 + from pulls p 400 401 join repos r 401 - join pulls p 402 - on r.at_uri = i.repo_at 402 + on r.at_uri = p.repo_at 403 403 where (p.owner_did, p.rkey) in (%s)`, 404 404 strings.Join(vals, ","), 405 405 ), ··· 412 412 var refLinks []models.RichReferenceLink 413 413 for rows.Next() { 414 414 var l models.RichReferenceLink 415 - l.Kind = models.RefKindIssue 415 + l.Kind = models.RefKindPull 416 416 if err := rows.Scan(&l.Handle, &l.Repo, &l.SubjectId, &l.Title, &l.State); err != nil { 417 417 return nil, err 418 418 }
appview/issues/issues.go

This file has not been changed.

appview/models/reference.go

This file has not been changed.

appview/pages/pages.go

This file has not been changed.

appview/pages/templates/repo/fragments/backlinks.html

This file has not been changed.

appview/pages/templates/repo/issues/issue.html

This file has not been changed.

appview/pages/templates/repo/pulls/pull.html

This file has not been changed.

+12 -3
appview/pulls/pulls.go
··· 1 1 package pulls 2 2 3 3 import ( 4 + "context" 4 5 "database/sql" 5 6 "encoding/json" 6 7 "errors" ··· 1215 1216 } 1216 1217 } 1217 1218 1219 + mentions, references := s.refResolver.Resolve(r.Context(), body) 1220 + 1218 1221 rkey := tid.TID() 1219 1222 initialSubmission := models.PullSubmission{ 1220 1223 Patch: patch, ··· 1228 1231 OwnerDid: user.Did, 1229 1232 RepoAt: f.RepoAt(), 1230 1233 Rkey: rkey, 1234 + Mentions: mentions, 1235 + References: references, 1231 1236 Submissions: []*models.PullSubmission{ 1232 1237 &initialSubmission, 1233 1238 }, ··· 1315 1320 1316 1321 // build a stack out of this patch 1317 1322 stackId := uuid.New() 1318 - stack, err := newStack(f, user, targetBranch, patch, pullSource, stackId.String()) 1323 + stack, err := s.newStack(r.Context(), f, user, targetBranch, patch, pullSource, stackId.String()) 1319 1324 if err != nil { 1320 1325 log.Println("failed to create stack", err) 1321 1326 s.pages.Notice(w, "pull", fmt.Sprintf("Failed to create stack: %v", err)) ··· 1941 1946 targetBranch := pull.TargetBranch 1942 1947 1943 1948 origStack, _ := r.Context().Value("stack").(models.Stack) 1944 - newStack, err := newStack(f, user, targetBranch, patch, pull.PullSource, stackId) 1949 + newStack, err := s.newStack(r.Context(), f, user, targetBranch, patch, pull.PullSource, stackId) 1945 1950 if err != nil { 1946 1951 log.Println("failed to create resubmitted stack", err) 1947 1952 s.pages.Notice(w, "pull-merge-error", "Failed to merge pull request. Try again later.") ··· 2385 2390 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) 2386 2391 } 2387 2392 2388 - func newStack(f *reporesolver.ResolvedRepo, user *oauth.User, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) { 2393 + func (s *Pulls) newStack(ctx context.Context, f *reporesolver.ResolvedRepo, user *oauth.User, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) { 2389 2394 formatPatches, err := patchutil.ExtractPatches(patch) 2390 2395 if err != nil { 2391 2396 return nil, fmt.Errorf("Failed to extract patches: %v", err) ··· 2410 2415 body := fp.Body 2411 2416 rkey := tid.TID() 2412 2417 2418 + mentions, references := s.refResolver.Resolve(ctx, body) 2419 + 2413 2420 initialSubmission := models.PullSubmission{ 2414 2421 Patch: fp.Raw, 2415 2422 SourceRev: fp.SHA, ··· 2422 2429 OwnerDid: user.Did, 2423 2430 RepoAt: f.RepoAt(), 2424 2431 Rkey: rkey, 2432 + Mentions: mentions, 2433 + References: references, 2425 2434 Submissions: []*models.PullSubmission{ 2426 2435 &initialSubmission, 2427 2436 },
+19 -1
appview/db/pulls.go
··· 93 93 insert into pull_submissions (pull_at, round_number, patch, combined, source_rev) 94 94 values (?, ?, ?, ?, ?) 95 95 `, pull.AtUri(), 0, pull.Submissions[0].Patch, pull.Submissions[0].Combined, pull.Submissions[0].SourceRev) 96 - return err 96 + if err != nil { 97 + return err 98 + } 99 + 100 + if err := putReferences(tx, pull.AtUri(), pull.References); err != nil { 101 + return fmt.Errorf("put reference_links: %w", err) 102 + } 103 + 104 + return nil 97 105 } 98 106 99 107 func GetPullAt(e Execer, repoAt syntax.ATURI, pullId int) (syntax.ATURI, error) { ··· 266 274 } 267 275 } 268 276 277 + allReferences, err := GetReferencesAll(e, FilterIn("from_at", pullAts)) 278 + if err != nil { 279 + return nil, fmt.Errorf("failed to query reference_links: %w", err) 280 + } 281 + for pullAt, references := range allReferences { 282 + if pull, ok := pulls[pullAt]; ok { 283 + pull.References = references 284 + } 285 + } 286 + 269 287 orderedByPullId := []*models.Pull{} 270 288 for _, p := range pulls { 271 289 orderedByPullId = append(orderedByPullId, p)
+14 -2
appview/models/pull.go
··· 66 66 TargetBranch string 67 67 State PullState 68 68 Submissions []*PullSubmission 69 + Mentions []syntax.DID 70 + References []syntax.ATURI 69 71 70 72 // stacking 71 73 StackId string // nullable string ··· 92 94 source.Repo = &s 93 95 } 94 96 } 97 + mentions := make([]string, len(p.Mentions)) 98 + for i, did := range p.Mentions { 99 + mentions[i] = string(did) 100 + } 101 + references := make([]string, len(p.References)) 102 + for i, uri := range p.References { 103 + references[i] = string(uri) 104 + } 95 105 96 106 record := tangled.RepoPull{ 97 - Title: p.Title, 98 - Body: &p.Body, 107 + Title: p.Title, 108 + Body: &p.Body, 109 + Mentions: mentions, 110 + References: references, 99 111 CreatedAt: p.Created.Format(time.RFC3339), 100 112 Target: &tangled.RepoPull_Target{ 101 113 Repo: p.RepoAt.String(),

History

12 rounds 1 comment
sign up or login to add to the discussion
1 commit
expand
appview: backlinks
3/3 success
expand
expand 1 comment

tested this locally: and all edge cases i can think of are handled pretty well! the rendering of backlinks also looks good. thanks for the brilliant work on this!

pull request successfully merged
1 commit
expand
appview: backlinks
3/3 success
expand
expand 0 comments
1 commit
expand
appview: backlinks
3/3 success
expand
expand 0 comments
1 commit
expand
appview: backlinks
3/3 success
expand
expand 0 comments
1 commit
expand
appview: backlinks
1/3 failed, 2/3 timeout
expand
expand 0 comments
1 commit
expand
draft: render backlinks
3/3 success
expand
expand 0 comments
1 commit
expand
draft: render backlinks
3/3 success
expand
expand 0 comments
1 commit
expand
draft: render backlinks
3/3 success
expand
expand 0 comments
1 commit
expand
draft: render backlinks
3/3 success
expand
expand 0 comments
1 commit
expand
draft: render backlinks
2/3 failed, 1/3 running
expand
expand 0 comments
1 commit
expand
draft: render backlinks
1/3 failed, 2/3 timeout
expand
expand 0 comments
1 commit
expand
draft: render backlinks
1/3 failed, 2/3 timeout
expand
expand 0 comments