forked from tangled.org/core
this repo has no description

appview: pulls: 0 indexed rounds and view raw patch

anirudh.fi fbf19ef0 d5f7bdf7

verified
Changed files
+44 -8
appview
pages
templates
repo
state
+6 -4
appview/pages/templates/repo/pulls/patch.html
··· 1 1 {{ define "title" }} 2 - {{ $oneIndexedRound := add .Round 1 }} 3 - patch of {{ .Pull.Title }} &middot; round #{{ $oneIndexedRound }} &middot; pull #{{ .Pull.PullId }} &middot; {{ .RepoInfo.FullName }} 2 + patch of {{ .Pull.Title }} &middot; round #{{ .Round }} &middot; pull #{{ .Pull.PullId }} &middot; {{ .RepoInfo.FullName }} 4 3 {{ end }} 5 4 6 5 {{ define "content" }} 7 - {{ $oneIndexedRound := add .Round 1 }} 8 6 {{ $stat := .Diff.Stat }} 9 7 <div class="rounded drop-shadow-sm bg-white py-4 px-6"> 10 8 <header class="pb-2"> ··· 14 12 back 15 13 </a> 16 14 <span class="select-none before:content-['\00B7']"></span> 17 - round #{{ $oneIndexedRound }} 15 + round #{{ .Round }} 16 + <span class="select-none before:content-['\00B7']"></span> 17 + <a href="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/round/{{ .Round }}.patch"> 18 + view raw 19 + </a> 18 20 </div> 19 21 <div class="border-t border-gray-200 my-2"></div> 20 22 <h1 class="text-2xl mt-3">
+3 -4
appview/pages/templates/repo/pulls/pull.html
··· 74 74 {{ range $idx, $item := .Pull.Submissions }} 75 75 {{ $diff := $item.AsNiceDiff $targetBranch }} 76 76 {{ with $item }} 77 - {{ $oneIndexedRound := add .RoundNumber 1 }} 78 77 <details {{ if eq $idx $lastIdx }}open{{ end }}> 79 - <summary id="round-#{{ $oneIndexedRound }}" class="list-none cursor-pointer"> 78 + <summary id="round-#{{ .RoundNumber }}" class="list-none cursor-pointer"> 80 79 <div class="flex flex-wrap gap-2 items-center"> 81 80 <!-- round number --> 82 81 <div class="rounded bg-white drop-shadow-sm px-3 py-2"> 83 - #{{ $oneIndexedRound }} 82 + #{{ .RoundNumber }} 84 83 </div> 85 84 <!-- round summary --> 86 85 <div class="rounded drop-shadow-sm bg-white p-2 text-gray-500"> ··· 93 92 <span class="hidden md:inline">{{$re}}submitted</span> 94 93 by <a href="/{{ $owner }}">{{ $owner }}</a> 95 94 <span class="select-none before:content-['\00B7']"></span> 96 - <a class="text-gray-500 hover:text-gray-500" href="#round-#{{ $oneIndexedRound }}"><time>{{ .Created | shortTimeFmt }}</time></a> 95 + <a class="text-gray-500 hover:text-gray-500" href="#round-#{{ .RoundNumber }}"><time>{{ .Created | shortTimeFmt }}</time></a> 97 96 <span class="select-none before:content-['·']"></span> 98 97 {{ $s := "s" }} 99 98 {{ if eq (len .Comments) 1 }}
+31
appview/state/pull.go
··· 221 221 222 222 } 223 223 224 + func (s *State) RepoPullPatchRaw(w http.ResponseWriter, r *http.Request) { 225 + pull, ok := r.Context().Value("pull").(*db.Pull) 226 + if !ok { 227 + log.Println("failed to get pull") 228 + s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") 229 + return 230 + } 231 + 232 + roundId := chi.URLParam(r, "round") 233 + roundIdInt, err := strconv.Atoi(roundId) 234 + if err != nil || roundIdInt >= len(pull.Submissions) { 235 + http.Error(w, "bad round id", http.StatusBadRequest) 236 + log.Println("failed to parse round id", err) 237 + return 238 + } 239 + 240 + identsToResolve := []string{pull.OwnerDid} 241 + resolvedIds := s.resolver.ResolveIdents(r.Context(), identsToResolve) 242 + didHandleMap := make(map[string]string) 243 + for _, identity := range resolvedIds { 244 + if !identity.Handle.IsInvalidHandle() { 245 + didHandleMap[identity.DID.String()] = fmt.Sprintf("@%s", identity.Handle.String()) 246 + } else { 247 + didHandleMap[identity.DID.String()] = identity.DID.String() 248 + } 249 + } 250 + 251 + w.Header().Set("Content-Type", "text/plain") 252 + w.Write([]byte(pull.Submissions[roundIdInt].Patch)) 253 + } 254 + 224 255 func (s *State) RepoPulls(w http.ResponseWriter, r *http.Request) { 225 256 user := s.auth.GetUser(r) 226 257 params := r.URL.Query()
+4
appview/state/router.go
··· 98 98 }) 99 99 }) 100 100 101 + r.Route("/round/{round}.patch", func(r chi.Router) { 102 + r.Get("/", s.RepoPullPatchRaw) 103 + }) 104 + 101 105 // authorized requests below this point 102 106 r.Group(func(r chi.Router) { 103 107 r.Use(AuthMiddleware(s))