forked from tangled.org/core
Monorepo for Tangled

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

Co-Authored-By: oppiliappan <me@oppi.li>
Signed-off-by: Samuel Shuert <me@thecoded.prof>

authored by thecoded.prof oppiliappan and committed by anirudh.fi bb04c7a8 7f658363

Changed files
+13 -8
appview
pages
templates
repo
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>
+1 -1
appview/pages/templates/repo/pulls/fragments/pullHeader.html
··· 17 17 {{ $icon = "git-merge" }} 18 18 {{ end }} 19 19 20 - {{ $owner := resolve .Pull.OwnerDid }} 20 + {{ $owner := resolve .Pull.PullSource.Repo.Did }} 21 21 <section class="mt-2"> 22 22 <div class="flex items-center gap-2"> 23 23 <div
+10 -5
appview/pulls/pulls.go
··· 850 850 } 851 851 852 852 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) { 853 - fork, err := db.GetForkByDid(s.db, user.Did, forkRepo) 853 + repoString := strings.SplitN(forkRepo, "/", 2) 854 + forkOwnerDid := repoString[0] 855 + repoName := repoString[1] 856 + fork, err := db.GetForkByDid(s.db, forkOwnerDid, repoName) 854 857 if errors.Is(err, sql.ErrNoRows) { 855 858 s.pages.Notice(w, "pull", "No such fork.") 856 859 return ··· 908 911 // hiddenRef: hidden/feature-1/main (on repo-fork) 909 912 // targetBranch: main (on repo-1) 910 913 // sourceBranch: feature-1 (on repo-fork) 911 - comparison, err := us.Compare(user.Did, fork.Name, hiddenRef, sourceBranch) 914 + comparison, err := us.Compare(fork.Did, fork.Name, hiddenRef, sourceBranch) 912 915 if err != nil { 913 916 log.Println("failed to compare across branches", err) 914 917 s.pages.Notice(w, "pull", err.Error()) ··· 1271 1274 } 1272 1275 1273 1276 forkVal := r.URL.Query().Get("fork") 1274 - 1277 + repoString := strings.SplitN(forkVal, "/", 2) 1278 + forkOwnerDid := repoString[0] 1279 + forkName := repoString[1] 1275 1280 // fork repo 1276 - repo, err := db.GetRepo(s.db, user.Did, forkVal) 1281 + repo, err := db.GetRepo(s.db, forkOwnerDid, forkName) 1277 1282 if err != nil { 1278 1283 log.Println("failed to get repo", user.Did, forkVal) 1279 1284 return ··· 1286 1291 return 1287 1292 } 1288 1293 1289 - sourceResult, err := sourceBranchesClient.Branches(user.Did, repo.Name) 1294 + sourceResult, err := sourceBranchesClient.Branches(forkOwnerDid, repo.Name) 1290 1295 if err != nil { 1291 1296 log.Println("failed to reach knotserver for source branches", err) 1292 1297 return