···
256
-
err = db.EditPatch(s.db, f.RepoAt, prIdInt, patch)
256
+
// Get pull information before updating to get the atproto record URI
257
+
pull, _, err := db.GetPullWithComments(s.db, f.RepoAt, prIdInt)
259
+
log.Println("failed to get pull information", err)
260
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
264
+
// Start a transaction for database operations
265
+
tx, err := s.db.BeginTx(r.Context(), nil)
267
+
log.Println("failed to start transaction", err)
268
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
272
+
// Set up deferred rollback that will be overridden by commit if successful
273
+
defer tx.Rollback()
275
+
// Update patch in the database within transaction
276
+
err = db.EditPatch(tx, f.RepoAt, prIdInt, patch)
log.Println("failed to update patch", err)
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
263
-
// Get target branch after patch update
264
-
pull, _, err := db.GetPullWithComments(s.db, f.RepoAt, prIdInt)
283
+
// Update the atproto record
284
+
client, _ := s.auth.AuthorizedClient(r)
285
+
pullAt := pull.PullAt
287
+
// Get the existing record first
288
+
ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoPullNSID, user.Did, pullAt.RecordKey().String())
290
+
log.Println("failed to get existing pull record", err)
291
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
295
+
// Update the record
296
+
_, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{
297
+
Collection: tangled.RepoPullNSID,
299
+
Rkey: pullAt.RecordKey().String(),
300
+
SwapRecord: ex.Cid,
301
+
Record: &lexutil.LexiconTypeDecoder{
302
+
Val: &tangled.RepoPull{
304
+
PullId: int64(pull.PullId),
305
+
TargetRepo: string(f.RepoAt),
306
+
TargetBranch: pull.TargetBranch,
266
-
log.Println("failed to get pull information", err)
267
-
s.pages.Notice(w, "pull-success", "Patch updated successfully.")
313
+
log.Println("failed to update pull record in atproto", err)
314
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
318
+
// Commit the transaction now that both operations have succeeded
321
+
log.Println("failed to commit transaction", err)
322
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")