diff --git a/appview/db/pulls.go b/appview/db/pulls.go index f2774b7e..69efee45 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -10,6 +10,7 @@ import ( "github.com/bluekeyes/go-gitdiff/gitdiff" "github.com/bluesky-social/indigo/atproto/syntax" + tangled "tangled.sh/tangled.sh/core/api/tangled" "tangled.sh/tangled.sh/core/patchutil" "tangled.sh/tangled.sh/core/types" ) @@ -54,7 +55,6 @@ type Pull struct { RepoAt syntax.ATURI OwnerDid string Rkey string - PullAt syntax.ATURI // content Title string @@ -120,6 +120,10 @@ func (p *Pull) LatestPatch() string { return latestSubmission.Patch } +func (p *Pull) PullAt() syntax.ATURI { + return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", p.OwnerDid, tangled.RepoPullNSID, p.Rkey)) +} + func (p *Pull) LastRoundNumber() int { return len(p.Submissions) - 1 } @@ -298,15 +302,12 @@ func NewPull(tx *sql.Tx, pull *Pull) error { return nil } -func SetPullAt(e Execer, repoAt syntax.ATURI, pullId int, pullAt string) error { - _, err := e.Exec(`update pulls set pull_at = ? where repo_at = ? and pull_id = ?`, pullAt, repoAt, pullId) - return err -} - -func GetPullAt(e Execer, repoAt syntax.ATURI, pullId int) (string, error) { - var pullAt string - err := e.QueryRow(`select pull_at from pulls where repo_at = ? and pull_id = ?`, repoAt, pullId).Scan(&pullAt) - return pullAt, err +func GetPullAt(e Execer, repoAt syntax.ATURI, pullId int) (syntax.ATURI, error) { + pull, err := GetPull(e, repoAt, pullId) + if err != nil { + return "", err + } + return pull.PullAt(), err } func NextPullId(e Execer, repoAt syntax.ATURI) (int, error) { @@ -326,7 +327,6 @@ func GetPulls(e Execer, repoAt syntax.ATURI, state PullState) ([]*Pull, error) { title, state, target_branch, - pull_at, body, rkey, source_branch, @@ -351,7 +351,6 @@ func GetPulls(e Execer, repoAt syntax.ATURI, state PullState) ([]*Pull, error) { &pull.Title, &pull.State, &pull.TargetBranch, - &pull.PullAt, &pull.Body, &pull.Rkey, &sourceBranch, @@ -487,7 +486,6 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { title, state, target_branch, - pull_at, repo_at, body, rkey, @@ -510,7 +508,6 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { &pull.Title, &pull.State, &pull.TargetBranch, - &pull.PullAt, &pull.RepoAt, &pull.Body, &pull.Rkey, diff --git a/appview/state/pull.go b/appview/state/pull.go index 931ac3ef..8996ac87 100644 --- a/appview/state/pull.go +++ b/appview/state/pull.go @@ -528,7 +528,7 @@ func (s *State) PullComment(w http.ResponseWriter, r *http.Request) { Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.RepoPullComment{ Repo: &atUri, - Pull: pullAt, + Pull: string(pullAt), Owner: &ownerDid, Body: &body, CreatedAt: &createdAt, @@ -879,7 +879,7 @@ func (s *State) createPullRequest( return } - atResp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ + _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoPullNSID, Repo: user.Did, Rkey: rkey, @@ -895,9 +895,8 @@ func (s *State) createPullRequest( }, }) - err = db.SetPullAt(s.db, f.RepoAt, pullId, atResp.Uri) if err != nil { - log.Println("failed to get pull id", err) + log.Println("failed to create pull request", err) s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") return }