diff --git a/appview/pages/templates/repo/pulls/patch.html b/appview/pages/templates/repo/pulls/patch.html index 2f05c22..eb10f32 100644 --- a/appview/pages/templates/repo/pulls/patch.html +++ b/appview/pages/templates/repo/pulls/patch.html @@ -1,10 +1,8 @@ {{ define "title" }} - {{ $oneIndexedRound := add .Round 1 }} - patch of {{ .Pull.Title }} · round #{{ $oneIndexedRound }} · pull #{{ .Pull.PullId }} · {{ .RepoInfo.FullName }} + patch of {{ .Pull.Title }} · round #{{ .Round }} · pull #{{ .Pull.PullId }} · {{ .RepoInfo.FullName }} {{ end }} {{ define "content" }} - {{ $oneIndexedRound := add .Round 1 }} {{ $stat := .Diff.Stat }}
@@ -14,7 +12,11 @@ back - round #{{ $oneIndexedRound }} + round #{{ .Round }} + + + view raw +

diff --git a/appview/pages/templates/repo/pulls/pull.html b/appview/pages/templates/repo/pulls/pull.html index 7252856..b8bd597 100644 --- a/appview/pages/templates/repo/pulls/pull.html +++ b/appview/pages/templates/repo/pulls/pull.html @@ -74,13 +74,12 @@ {{ range $idx, $item := .Pull.Submissions }} {{ $diff := $item.AsNiceDiff $targetBranch }} {{ with $item }} - {{ $oneIndexedRound := add .RoundNumber 1 }}
- +
- #{{ $oneIndexedRound }} + #{{ .RoundNumber }}
@@ -93,7 +92,7 @@ by {{ $owner }} - + {{ $s := "s" }} {{ if eq (len .Comments) 1 }} diff --git a/appview/state/pull.go b/appview/state/pull.go index 4bd8e6f..3d37ecd 100644 --- a/appview/state/pull.go +++ b/appview/state/pull.go @@ -221,6 +221,37 @@ func (s *State) RepoPullPatch(w http.ResponseWriter, r *http.Request) { } +func (s *State) RepoPullPatchRaw(w http.ResponseWriter, r *http.Request) { + pull, ok := r.Context().Value("pull").(*db.Pull) + if !ok { + log.Println("failed to get pull") + s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") + return + } + + roundId := chi.URLParam(r, "round") + roundIdInt, err := strconv.Atoi(roundId) + if err != nil || roundIdInt >= len(pull.Submissions) { + http.Error(w, "bad round id", http.StatusBadRequest) + log.Println("failed to parse round id", err) + return + } + + identsToResolve := []string{pull.OwnerDid} + resolvedIds := s.resolver.ResolveIdents(r.Context(), identsToResolve) + didHandleMap := make(map[string]string) + for _, identity := range resolvedIds { + if !identity.Handle.IsInvalidHandle() { + didHandleMap[identity.DID.String()] = fmt.Sprintf("@%s", identity.Handle.String()) + } else { + didHandleMap[identity.DID.String()] = identity.DID.String() + } + } + + w.Header().Set("Content-Type", "text/plain") + w.Write([]byte(pull.Submissions[roundIdInt].Patch)) +} + func (s *State) RepoPulls(w http.ResponseWriter, r *http.Request) { user := s.auth.GetUser(r) params := r.URL.Query() diff --git a/appview/state/router.go b/appview/state/router.go index 92bf574..a19b750 100644 --- a/appview/state/router.go +++ b/appview/state/router.go @@ -98,6 +98,10 @@ func (s *State) UserRouter() http.Handler { }) }) + r.Route("/round/{round}.patch", func(r chi.Router) { + r.Get("/", s.RepoPullPatchRaw) + }) + // authorized requests below this point r.Group(func(r chi.Router) { r.Use(AuthMiddleware(s))