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

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

Changed files
+14 -9
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
+11 -6
appview/pulls/pulls.go
··· 857 857 } 858 858 859 859 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) { 860 - fork, err := db.GetForkByDid(s.db, user.Did, forkRepo) 860 + repoString := strings.SplitN(forkRepo, "/", 2) 861 + forkOwnerDid := repoString[0] 862 + repoName := repoString[1] 863 + fork, err := db.GetForkByDid(s.db, forkOwnerDid, repoName) 861 864 if errors.Is(err, sql.ErrNoRows) { 862 865 s.pages.Notice(w, "pull", "No such fork.") 863 866 return ··· 888 891 return 889 892 } 890 893 891 - resp, err := sc.NewHiddenRef(user.Did, fork.Name, sourceBranch, targetBranch) 894 + resp, err := sc.NewHiddenRef(fork.Did, fork.Name, sourceBranch, targetBranch) 892 895 if err != nil { 893 896 log.Println("failed to create hidden ref:", err, resp.StatusCode) 894 897 s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") ··· 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()) ··· 1270 1273 } 1271 1274 1272 1275 forkVal := r.URL.Query().Get("fork") 1273 - 1276 + repoString := strings.SplitN(forkVal, "/", 2) 1277 + forkOwnerDid := repoString[0] 1278 + forkName := repoString[1] 1274 1279 // fork repo 1275 - repo, err := db.GetRepo(s.db, user.Did, forkVal) 1280 + repo, err := db.GetRepo(s.db, forkOwnerDid, forkName) 1276 1281 if err != nil { 1277 1282 log.Println("failed to get repo", user.Did, forkVal) 1278 1283 return ··· 1285 1290 return 1286 1291 } 1287 1292 1288 - sourceResult, err := sourceBranchesClient.Branches(user.Did, repo.Name) 1293 + sourceResult, err := sourceBranchesClient.Branches(forkOwnerDid, repo.Name) 1289 1294 if err != nil { 1290 1295 log.Println("failed to reach knotserver for source branches", err) 1291 1296 return