appview: Update New PR Page #490

The compare forks option dropdown now shows repos in which you are a collaborator on instead of just repos you own.

Changed files
+14 -10
appview
db
pages
templates
repo
pulls
pulls
+8 -5
appview/db/repos.go
···
var repos []Repo
rows, err := e.Query(
-
`select did, name, knot, rkey, description, created, at_uri, source
-
from repos
-
where did = ? and source is not null and source != ''
-
order by created desc`,
-
did,
+
`select distinct r.did, r.name, r.knot, r.rkey, r.description, r.created, r.at_uri, r.source
+
from repos r
+
left join collaborators c on r.at_uri = c.repo_at
+
where (r.did = ? or c.subject_did = ?)
+
and r.source is not null
+
and r.source != ''
+
order by r.created desc`,
+
did, did,
)
if err != nil {
return nil, err
+2 -2
appview/pages/templates/repo/pulls/fragments/pullCompareForks.html
···
>
<option disabled selected>select a fork</option>
{{ range .Forks }}
-
<option value="{{ .Name }}" {{ if eq .Name $.Selected }}selected{{ end }} class="py-1">
-
{{ .Name }}
+
<option value="{{ .Did }}/{{ .Name }}" {{ if eq .Name $.Selected }}selected{{ end }} class="py-1">
+
{{ .Did | resolve }}/{{ .Name }}
</option>
{{ end }}
</select>
+4 -3
appview/pulls/pulls.go
···
}
func (s *Pulls) handleForkBasedPull(w http.ResponseWriter, r *http.Request, f *reporesolver.ResolvedRepo, user *oauth.User, forkRepo string, title, body, targetBranch, sourceBranch string, isStacked bool) {
-
fork, err := db.GetForkByDid(s.db, user.Did, forkRepo)
+
splits := strings.SplitN(forkRepo, "/", 2)
+
fork, err := db.GetForkByDid(s.db, splits[0], splits[1])
if errors.Is(err, sql.ErrNoRows) {
s.pages.Notice(w, "pull", "No such fork.")
return
···
forkVal := r.URL.Query().Get("fork")
-
+
split := strings.SplitN(forkVal, "/", 2)
// fork repo
-
repo, err := db.GetRepo(s.db, user.Did, forkVal)
+
repo, err := db.GetRepo(s.db, split[0], split[1])
if err != nil {
log.Println("failed to get repo", user.Did, forkVal)
return