forked from tangled.org/core
A fork of tangled.org/core to hack on

appview: pages: update pr compare fork page

Show fork titles in owner/repo format, otherwise if you have collaborator
access to multiple forks of the same repo (in which the forks have the
same title) it may be hard to differentiate

Also update the underlying logic to use the option value instead of
checking against the currently logged in users DID

Signed-off-by: Samuel Shuert <me@thecoded.prof>

Changed files
+12 -7
appview
pages
templates
repo
pulls
pulls
+2 -2
appview/pages/templates/repo/pulls/fragments/pullCompareForks.html
··· 19 19 > 20 20 <option disabled selected>select a fork</option> 21 21 {{ range .Forks }} 22 - <option value="{{ .Name }}" {{ if eq .Name $.Selected }}selected{{ end }} class="py-1"> 23 - {{ .Name }} 22 + <option value="{{ .Did }}/{{ .Name }}" {{ if eq .Name $.Selected }}selected{{ end }} class="py-1"> 23 + {{ .Did | resolve }}/{{ .Name }} 24 24 </option> 25 25 {{ end }} 26 26 </select>
+10 -5
appview/pulls/pulls.go
··· 852 852 } 853 853 854 854 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) { 855 - fork, err := db.GetForkByDid(s.db, user.Did, forkRepo) 855 + repoString := strings.SplitN(forkRepo, "/", 2) 856 + forkOwnerDid := repoString[0] 857 + repoName := repoString[1] 858 + fork, err := db.GetForkByDid(s.db, forkOwnerDid, repoName) 856 859 if errors.Is(err, sql.ErrNoRows) { 857 860 s.pages.Notice(w, "pull", "No such fork.") 858 861 return ··· 883 886 return 884 887 } 885 888 886 - resp, err := sc.NewHiddenRef(user.Did, fork.Name, sourceBranch, targetBranch) 889 + resp, err := sc.NewHiddenRef(fork.Did, fork.Name, sourceBranch, targetBranch) 887 890 if err != nil { 888 891 log.Println("failed to create hidden ref:", err, resp.StatusCode) 889 892 s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") ··· 903 906 // hiddenRef: hidden/feature-1/main (on repo-fork) 904 907 // targetBranch: main (on repo-1) 905 908 // sourceBranch: feature-1 (on repo-fork) 906 - comparison, err := us.Compare(user.Did, fork.Name, hiddenRef, sourceBranch) 909 + comparison, err := us.Compare(fork.Did, fork.Name, hiddenRef, sourceBranch) 907 910 if err != nil { 908 911 log.Println("failed to compare across branches", err) 909 912 s.pages.Notice(w, "pull", err.Error()) ··· 1269 1272 } 1270 1273 1271 1274 forkVal := r.URL.Query().Get("fork") 1272 - 1275 + repoString := strings.SplitN(forkVal, "/", 2) 1276 + forkOwnerDid := repoString[0] 1277 + forkName := repoString[1] 1273 1278 // fork repo 1274 - repo, err := db.GetRepo(s.db, user.Did, forkVal) 1279 + repo, err := db.GetRepo(s.db, forkOwnerDid, forkName) 1275 1280 if err != nil { 1276 1281 log.Println("failed to get repo", user.Did, forkVal) 1277 1282 return