···
-
err = db.EditPatch(s.db, f.RepoAt, prIdInt, patch)
log.Println("failed to update patch", err)
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
-
// Get target branch after patch update
-
pull, _, err := db.GetPullWithComments(s.db, f.RepoAt, prIdInt)
-
log.Println("failed to get pull information", err)
-
s.pages.Notice(w, "pull-success", "Patch updated successfully.")
···
+
// Get pull information before updating to get the atproto record URI
+
pull, _, err := db.GetPullWithComments(s.db, f.RepoAt, prIdInt)
+
log.Println("failed to get pull information", err)
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
+
// Start a transaction for database operations
+
tx, err := s.db.BeginTx(r.Context(), nil)
+
log.Println("failed to start transaction", err)
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
+
// Set up deferred rollback that will be overridden by commit if successful
+
// Update patch in the database within transaction
+
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.")
+
// Update the atproto record
+
client, _ := s.auth.AuthorizedClient(r)
+
// Get the existing record first
+
ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoPullNSID, user.Did, pullAt.RecordKey().String())
+
log.Println("failed to get existing pull record", err)
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
+
_, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{
+
Collection: tangled.RepoPullNSID,
+
Rkey: pullAt.RecordKey().String(),
+
Record: &lexutil.LexiconTypeDecoder{
+
Val: &tangled.RepoPull{
+
PullId: int64(pull.PullId),
+
TargetRepo: string(f.RepoAt),
+
TargetBranch: pull.TargetBranch,
+
log.Println("failed to update pull record in atproto", err)
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
+
// Commit the transaction now that both operations have succeeded
+
log.Println("failed to commit transaction", err)
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")