From 0f6a9a5dfd119f55f231af14f5a745964bb4c7ca Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Tue, 14 Apr 2026 00:20:37 +0900 Subject: [PATCH] appview: use `Pull.AsRecord()` everywhere Signed-off-by: Seongmin Lee --- appview/models/pull.go | 44 ++++++++++++++++++--------- appview/pulls/pulls.go | 69 ++++++++++++------------------------------ 2 files changed, 49 insertions(+), 64 deletions(-) diff --git a/appview/models/pull.go b/appview/models/pull.go index c514941e..4d127069 100644 --- a/appview/models/pull.go +++ b/appview/models/pull.go @@ -88,15 +88,6 @@ type Pull struct { // NOTE: This method does not include patch blob in returned atproto record func (p Pull) AsRecord() tangled.RepoPull { - var source *tangled.RepoPull_Source - if p.PullSource != nil { - source = &tangled.RepoPull_Source{} - source.Branch = p.PullSource.Branch - if p.PullSource.RepoAt != nil { - s := p.PullSource.RepoAt.String() - source.Repo = &s - } - } mentions := make([]string, len(p.Mentions)) for i, did := range p.Mentions { mentions[i] = string(did) @@ -123,7 +114,7 @@ func (p Pull) AsRecord() tangled.RepoPull { dependentOn = &x } - record := tangled.RepoPull{ + return tangled.RepoPull{ Title: p.Title, Body: &p.Body, Mentions: mentions, @@ -135,10 +126,9 @@ func (p Pull) AsRecord() tangled.RepoPull { Branch: p.TargetBranch, }, Rounds: rounds, - Source: source, + Source: p.PullSource.AsRecord(), DependentOn: dependentOn, } - return record } func PullFromRecord(did, rkey string, record tangled.RepoPull, blobs []*io.ReadCloser) Pull { @@ -181,6 +171,11 @@ func PullFromRecord(did, rkey string, record tangled.RepoPull, blobs []*io.ReadC pullSource.RepoAt = &uri } } + if record.Source.RepoDid != nil { + if did, err := syntax.ParseDID(*record.Source.RepoDid); err != nil { + pullSource.RepoDid = &did + } + } } var dependentOn *syntax.ATURI @@ -255,13 +250,34 @@ func PullSubmissionFromRecord(did, rkey string, roundNumber int, round *tangled. } type PullSource struct { - Branch string - RepoAt *syntax.ATURI + Branch string + RepoAt *syntax.ATURI + RepoDid *syntax.DID // optionally populate this for reverse mappings Repo *Repo } +func (s *PullSource) AsRecord() *tangled.RepoPull_Source { + if s == nil { + return nil + } + var repoAt, repoDid *string + if s.RepoAt != nil { + repoAt = new(string) + *repoAt = s.RepoAt.String() + } + if s.RepoDid != nil { + repoDid = new(string) + *repoDid = s.RepoDid.String() + } + return &tangled.RepoPull_Source{ + Branch: s.Branch, + Repo: repoAt, + RepoDid: repoDid, + } +} + type PullSubmission struct { // ids ID int diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index 99bf4921..caf74554 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -1131,11 +1131,8 @@ func (s *Pulls) handleBranchBasedPull( pullSource := &models.PullSource{ Branch: sourceBranch, } - recordPullSource := &tangled.RepoPull_Source{ - Branch: sourceBranch, - } - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) + s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, isStacked) } func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, user *oauth.MultiAccountUser, title, body, targetBranch, patch string, isStacked bool) { @@ -1145,7 +1142,7 @@ func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, rep return } - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, "", "", nil, nil, isStacked) + s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, "", "", nil, isStacked) } func (s *Pulls) handleForkBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, user *oauth.MultiAccountUser, forkRepo string, title, body, targetBranch, sourceBranch string, isStacked bool) { @@ -1240,21 +1237,19 @@ func (s *Pulls) handleForkBasedPull(w http.ResponseWriter, r *http.Request, repo } forkAtUri := fork.RepoAt() - forkAtUriStr := forkAtUri.String() + var forkDid *syntax.DID + if fork.RepoDid != "" { + forkDid = new(syntax.DID) + *forkDid = syntax.DID(fork.RepoDid) + } pullSource := &models.PullSource{ - Branch: sourceBranch, - RepoAt: &forkAtUri, - } - recordPullSource := &tangled.RepoPull_Source{ - Branch: sourceBranch, - Repo: &forkAtUriStr, - } - if fork.RepoDid != "" { - recordPullSource.RepoDid = &fork.RepoDid + Branch: sourceBranch, + RepoAt: &forkAtUri, + RepoDid: forkDid, } - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) + s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, isStacked) } func (s *Pulls) createPullRequest( @@ -1267,7 +1262,6 @@ func (s *Pulls) createPullRequest( combined string, sourceRev string, pullSource *models.PullSource, - recordPullSource *tangled.RepoPull_Source, isStacked bool, ) { l := s.logger.With("handler", "createPullRequest", "user", user.Active.Did, "target_branch", targetBranch, "is_stacked", isStacked) @@ -1336,13 +1330,6 @@ func (s *Pulls) createPullRequest( now := time.Now() - initialSubmission := models.PullSubmission{ - Patch: patch, - Combined: combined, - SourceRev: sourceRev, - Blob: *blob.Blob, - Created: time.Now(), - } pull := &models.Pull{ Title: title, Body: body, @@ -1353,26 +1340,20 @@ func (s *Pulls) createPullRequest( Mentions: mentions, References: references, Submissions: []*models.PullSubmission{ - &initialSubmission, + { + Patch: patch, + Combined: combined, + SourceRev: sourceRev, + Blob: *blob.Blob, + Created: now, + }, }, PullSource: pullSource, State: models.PullOpen, Created: now, } - record := tangled.RepoPull{ - Title: title, - Body: &body, - Target: repoPullTarget(repo, targetBranch), - Source: recordPullSource, - CreatedAt: time.Now().Format(time.RFC3339), - Rounds: []*tangled.RepoPull_Round{ - initialSubmission.AsRecord(), - }, - Mentions: nil, - References: nil, - } - + record := pull.AsRecord() _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoPullNSID, Repo: user.Active.Did, @@ -2663,15 +2644,3 @@ func gz(s string) io.Reader { } func ptrPullState(s models.PullState) *models.PullState { return &s } - -func repoPullTarget(repo *models.Repo, branch string) *tangled.RepoPull_Target { - s := string(repo.RepoAt()) - t := &tangled.RepoPull_Target{ - Branch: branch, - Repo: &s, - } - if repo.RepoDid != "" { - t.RepoDid = &repo.RepoDid - } - return t -} -- 2.51.2