diff --git a/appview/db/pulls.go b/appview/db/pulls.go index 56ff2258..2b2e80da 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -68,7 +68,10 @@ type Pull struct { type PullSource struct { Branch string - Repo *syntax.ATURI + RepoAt *syntax.ATURI + + // optionally populate this for reverse mappings + Repo *Repo } type PullSubmission struct { @@ -118,8 +121,8 @@ func (p *Pull) LastRoundNumber() int { func (p *Pull) IsSameRepoBranch() bool { if p.PullSource != nil { - if p.PullSource.Repo != nil { - return p.PullSource.Repo == &p.RepoAt + if p.PullSource.RepoAt != nil { + return p.PullSource.RepoAt == &p.RepoAt } else { // no repo specified return true @@ -201,8 +204,8 @@ func NewPull(tx *sql.Tx, pull *Pull) error { var sourceBranch, sourceRepoAt *string if pull.PullSource != nil { sourceBranch = &pull.PullSource.Branch - if pull.PullSource.Repo != nil { - x := pull.PullSource.Repo.String() + if pull.PullSource.RepoAt != nil { + x := pull.PullSource.RepoAt.String() sourceRepoAt = &x } } @@ -321,7 +324,7 @@ func GetPulls(e Execer, repoAt syntax.ATURI, state PullState) ([]Pull, error) { if err != nil { return nil, err } - pull.PullSource.Repo = &sourceRepoAtParsed + pull.PullSource.RepoAt = &sourceRepoAtParsed } } @@ -394,7 +397,7 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { if err != nil { return nil, err } - pull.PullSource.Repo = &sourceRepoAtParsed + pull.PullSource.RepoAt = &sourceRepoAtParsed } } diff --git a/appview/pages/templates/repo/pulls/pull.html b/appview/pages/templates/repo/pulls/pull.html index 7de9a8e8..dccbe72e 100644 --- a/appview/pages/templates/repo/pulls/pull.html +++ b/appview/pages/templates/repo/pulls/pull.html @@ -50,7 +50,7 @@ {{ if not .Pull.IsSameRepoBranch }} {{ $owner }}/{{ .PullSourceRepo.Name }} {{ end }} - + {{ $fullRepo := .RepoInfo.FullName }} {{ if not .Pull.IsSameRepoBranch }} {{ $fullRepo = printf "%s/%s" $owner .PullSourceRepo.Name }} diff --git a/appview/pages/templates/repo/pulls/pulls.html b/appview/pages/templates/repo/pulls/pulls.html index 9bbed391..979d34cf 100644 --- a/appview/pages/templates/repo/pulls/pulls.html +++ b/appview/pages/templates/repo/pulls/pulls.html @@ -42,6 +42,7 @@

+ {{ $owner := index $.DidHandleMap .OwnerDid }} {{ $bgColor := "bg-gray-800 dark:bg-gray-700" }} {{ $icon := "ban" }} @@ -62,7 +63,6 @@ - {{ $owner := index $.DidHandleMap .OwnerDid }} {{ $owner }} @@ -74,12 +74,16 @@ targeting - + {{ .TargetBranch }} - {{ if .IsSameRepoBranch }} + {{ if not .IsPatch }} from + {{ if not .IsSameRepoBranch }} + {{ $owner }}/{{ .PullSource.Repo.Name }} + {{ end }} + {{ .PullSource.Branch }} diff --git a/appview/state/pull.go b/appview/state/pull.go index 82c99702..eae4b477 100644 --- a/appview/state/pull.go +++ b/appview/state/pull.go @@ -122,8 +122,8 @@ func (s *State) RepoSinglePull(w http.ResponseWriter, r *http.Request) { var pullSourceRepo *db.Repo if pull.PullSource != nil { - if pull.PullSource.Repo != nil { - pullSourceRepo, err = db.GetRepoByAtUri(s.db, pull.PullSource.Repo.String()) + if pull.PullSource.RepoAt != nil { + pullSourceRepo, err = db.GetRepoByAtUri(s.db, pull.PullSource.RepoAt.String()) if err != nil { log.Printf("failed to get repo by at uri: %v", err) return @@ -209,9 +209,9 @@ func (s *State) resubmitCheck(f *FullyResolvedRepo, pull *db.Pull) pages.Resubmi var knot, ownerDid, repoName string - if pull.PullSource.Repo != nil { + if pull.PullSource.RepoAt != nil { // fork-based pulls - sourceRepo, err := db.GetRepoByAtUri(s.db, pull.PullSource.Repo.String()) + sourceRepo, err := db.GetRepoByAtUri(s.db, pull.PullSource.RepoAt.String()) if err != nil { log.Println("failed to get source repo", err) return pages.Unknown @@ -362,6 +362,21 @@ func (s *State) RepoPulls(w http.ResponseWriter, r *http.Request) { return } + for _, p := range pulls { + var pullSourceRepo *db.Repo + if p.PullSource != nil { + if p.PullSource.RepoAt != nil { + pullSourceRepo, err = db.GetRepoByAtUri(s.db, p.PullSource.RepoAt.String()) + if err != nil { + log.Printf("failed to get repo by at uri: %v", err) + return + } + } + } + + p.PullSource.Repo = pullSourceRepo + } + identsToResolve := make([]string, len(pulls)) for i, pull := range pulls { identsToResolve[i] = pull.OwnerDid @@ -731,7 +746,7 @@ func (s *State) handleForkBasedPull(w http.ResponseWriter, r *http.Request, f *F s.createPullRequest(w, r, f, user, title, body, targetBranch, patch, sourceRev, &db.PullSource{ Branch: sourceBranch, - Repo: &forkAtUri, + RepoAt: &forkAtUri, }, &tangled.RepoPull_Source{Branch: sourceBranch, Repo: &fork.AtUri}) } @@ -993,7 +1008,7 @@ func (s *State) ResubmitPull(w http.ResponseWriter, r *http.Request) { repoName = f.RepoName knotName = f.Knot } else if !isSameRepo { - sourceRepo, err := db.GetRepoByAtUri(s.db, pull.PullSource.Repo.String()) + sourceRepo, err := db.GetRepoByAtUri(s.db, pull.PullSource.RepoAt.String()) if err != nil { log.Println("failed to get source repo", err) s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") diff --git a/knotserver/routes.go b/knotserver/routes.go index 101f3760..4d1b7323 100644 --- a/knotserver/routes.go +++ b/knotserver/routes.go @@ -38,7 +38,7 @@ func (h *Handle) Capabilities(w http.ResponseWriter, r *http.Request) { "pull_requests": map[string]any{ "patch_submissions": true, "branch_submissions": true, - "fork_submissions": false, + "fork_submissions": true, }, }