Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: use `Pull.AsRecord()` everywhere

Signed-off-by: Seongmin Lee <git@boltless.me>

authored by

Seongmin Lee and committed by tangled.org 0f6a9a5d 7472ce0d

+49 -64
+30 -14
appview/models/pull.go
··· 88 88 89 89 // NOTE: This method does not include patch blob in returned atproto record 90 90 func (p Pull) AsRecord() tangled.RepoPull { 91 - var source *tangled.RepoPull_Source 92 - if p.PullSource != nil { 93 - source = &tangled.RepoPull_Source{} 94 - source.Branch = p.PullSource.Branch 95 - if p.PullSource.RepoAt != nil { 96 - s := p.PullSource.RepoAt.String() 97 - source.Repo = &s 98 - } 99 - } 100 91 mentions := make([]string, len(p.Mentions)) 101 92 for i, did := range p.Mentions { 102 93 mentions[i] = string(did) ··· 123 114 dependentOn = &x 124 115 } 125 116 126 - record := tangled.RepoPull{ 117 + return tangled.RepoPull{ 127 118 Title: p.Title, 128 119 Body: &p.Body, 129 120 Mentions: mentions, ··· 135 126 Branch: p.TargetBranch, 136 127 }, 137 128 Rounds: rounds, 138 - Source: source, 129 + Source: p.PullSource.AsRecord(), 139 130 DependentOn: dependentOn, 140 131 } 141 - return record 142 132 } 143 133 144 134 func PullFromRecord(did, rkey string, record tangled.RepoPull, blobs []*io.ReadCloser) Pull { ··· 179 169 if record.Source.Repo != nil { 180 170 if uri, err := syntax.ParseATURI(*record.Source.Repo); err == nil { 181 171 pullSource.RepoAt = &uri 172 + } 173 + } 174 + if record.Source.RepoDid != nil { 175 + if did, err := syntax.ParseDID(*record.Source.RepoDid); err != nil { 176 + pullSource.RepoDid = &did 182 177 } 183 178 } 184 179 } ··· 255 250 } 256 251 257 252 type PullSource struct { 258 - Branch string 259 - RepoAt *syntax.ATURI 253 + Branch string 254 + RepoAt *syntax.ATURI 255 + RepoDid *syntax.DID 260 256 261 257 // optionally populate this for reverse mappings 262 258 Repo *Repo 259 + } 260 + 261 + func (s *PullSource) AsRecord() *tangled.RepoPull_Source { 262 + if s == nil { 263 + return nil 264 + } 265 + var repoAt, repoDid *string 266 + if s.RepoAt != nil { 267 + repoAt = new(string) 268 + *repoAt = s.RepoAt.String() 269 + } 270 + if s.RepoDid != nil { 271 + repoDid = new(string) 272 + *repoDid = s.RepoDid.String() 273 + } 274 + return &tangled.RepoPull_Source{ 275 + Branch: s.Branch, 276 + Repo: repoAt, 277 + RepoDid: repoDid, 278 + } 263 279 } 264 280 265 281 type PullSubmission struct {
+19 -50
appview/pulls/pulls.go
··· 1131 1131 pullSource := &models.PullSource{ 1132 1132 Branch: sourceBranch, 1133 1133 } 1134 - recordPullSource := &tangled.RepoPull_Source{ 1135 - Branch: sourceBranch, 1136 - } 1137 1134 1138 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1135 + s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, isStacked) 1139 1136 } 1140 1137 1141 1138 func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, user *oauth.MultiAccountUser, title, body, targetBranch, patch string, isStacked bool) { ··· 1145 1142 return 1146 1143 } 1147 1144 1148 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, "", "", nil, nil, isStacked) 1145 + s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, "", "", nil, isStacked) 1149 1146 } 1150 1147 1151 1148 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 1237 } 1241 1238 1242 1239 forkAtUri := fork.RepoAt() 1243 - forkAtUriStr := forkAtUri.String() 1240 + var forkDid *syntax.DID 1241 + if fork.RepoDid != "" { 1242 + forkDid = new(syntax.DID) 1243 + *forkDid = syntax.DID(fork.RepoDid) 1244 + } 1244 1245 1245 1246 pullSource := &models.PullSource{ 1246 - Branch: sourceBranch, 1247 - RepoAt: &forkAtUri, 1248 - } 1249 - recordPullSource := &tangled.RepoPull_Source{ 1250 - Branch: sourceBranch, 1251 - Repo: &forkAtUriStr, 1252 - } 1253 - if fork.RepoDid != "" { 1254 - recordPullSource.RepoDid = &fork.RepoDid 1247 + Branch: sourceBranch, 1248 + RepoAt: &forkAtUri, 1249 + RepoDid: forkDid, 1255 1250 } 1256 1251 1257 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1252 + s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, isStacked) 1258 1253 } 1259 1254 1260 1255 func (s *Pulls) createPullRequest( ··· 1267 1262 combined string, 1268 1263 sourceRev string, 1269 1264 pullSource *models.PullSource, 1270 - recordPullSource *tangled.RepoPull_Source, 1271 1265 isStacked bool, 1272 1266 ) { 1273 1267 l := s.logger.With("handler", "createPullRequest", "user", user.Active.Did, "target_branch", targetBranch, "is_stacked", isStacked) ··· 1336 1330 1337 1331 now := time.Now() 1338 1332 1339 - initialSubmission := models.PullSubmission{ 1340 - Patch: patch, 1341 - Combined: combined, 1342 - SourceRev: sourceRev, 1343 - Blob: *blob.Blob, 1344 - Created: time.Now(), 1345 - } 1346 1333 pull := &models.Pull{ 1347 1334 Title: title, 1348 1335 Body: body, ··· 1353 1340 Mentions: mentions, 1354 1341 References: references, 1355 1342 Submissions: []*models.PullSubmission{ 1356 - &initialSubmission, 1343 + { 1344 + Patch: patch, 1345 + Combined: combined, 1346 + SourceRev: sourceRev, 1347 + Blob: *blob.Blob, 1348 + Created: now, 1349 + }, 1357 1350 }, 1358 1351 PullSource: pullSource, 1359 1352 State: models.PullOpen, 1360 1353 Created: now, 1361 1354 } 1362 1355 1363 - record := tangled.RepoPull{ 1364 - Title: title, 1365 - Body: &body, 1366 - Target: repoPullTarget(repo, targetBranch), 1367 - Source: recordPullSource, 1368 - CreatedAt: time.Now().Format(time.RFC3339), 1369 - Rounds: []*tangled.RepoPull_Round{ 1370 - initialSubmission.AsRecord(), 1371 - }, 1372 - Mentions: nil, 1373 - References: nil, 1374 - } 1375 - 1356 + record := pull.AsRecord() 1376 1357 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1377 1358 Collection: tangled.RepoPullNSID, 1378 1359 Repo: user.Active.Did, ··· 2663 2644 } 2664 2645 2665 2646 func ptrPullState(s models.PullState) *models.PullState { return &s } 2666 - 2667 - func repoPullTarget(repo *models.Repo, branch string) *tangled.RepoPull_Target { 2668 - s := string(repo.RepoAt()) 2669 - t := &tangled.RepoPull_Target{ 2670 - Branch: branch, 2671 - Repo: &s, 2672 - } 2673 - if repo.RepoDid != "" { 2674 - t.RepoDid = &repo.RepoDid 2675 - } 2676 - return t 2677 - }