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
···
{{ 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 }}
<div class="rounded drop-shadow-sm bg-white py-4 px-6">
<header class="pb-2">
···
back
</a>
<span class="select-none before:content-['\00B7']"></span>
-
round #{{ $oneIndexedRound }}
+
round #{{ .Round }}
+
<span class="select-none before:content-['\00B7']"></span>
+
<a href="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/round/{{ .Round }}.patch">
+
view raw
+
</a>
</div>
<div class="border-t border-gray-200 my-2"></div>
<h1 class="text-2xl mt-3">
+3 -4
appview/pages/templates/repo/pulls/pull.html
···
{{ range $idx, $item := .Pull.Submissions }}
{{ $diff := $item.AsNiceDiff $targetBranch }}
{{ with $item }}
-
{{ $oneIndexedRound := add .RoundNumber 1 }}
<details {{ if eq $idx $lastIdx }}open{{ end }}>
-
<summary id="round-#{{ $oneIndexedRound }}" class="list-none cursor-pointer">
+
<summary id="round-#{{ .RoundNumber }}" class="list-none cursor-pointer">
<div class="flex flex-wrap gap-2 items-center">
<!-- round number -->
<div class="rounded bg-white drop-shadow-sm px-3 py-2">
-
#{{ $oneIndexedRound }}
+
#{{ .RoundNumber }}
</div>
<!-- round summary -->
<div class="rounded drop-shadow-sm bg-white p-2 text-gray-500">
···
<span class="hidden md:inline">{{$re}}submitted</span>
by <a href="/{{ $owner }}">{{ $owner }}</a>
<span class="select-none before:content-['\00B7']"></span>
-
<a class="text-gray-500 hover:text-gray-500" href="#round-#{{ $oneIndexedRound }}"><time>{{ .Created | shortTimeFmt }}</time></a>
+
<a class="text-gray-500 hover:text-gray-500" href="#round-#{{ .RoundNumber }}"><time>{{ .Created | shortTimeFmt }}</time></a>
<span class="select-none before:content-['·']"></span>
{{ $s := "s" }}
{{ if eq (len .Comments) 1 }}
+31
appview/state/pull.go
···
}
+
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()
+4
appview/state/router.go
···
})
})
+
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))