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

add detailed patch view

Changed files
+156 -6
appview
pages
templates
repo
state
+15
appview/pages/pages.go
···
return p.executeRepo("repo/pulls/pull", w, params)
}
+
type RepoPullPatchParams struct {
+
LoggedInUser *auth.User
+
DidHandleMap map[string]string
+
RepoInfo RepoInfo
+
Pull *db.Pull
+
Diff types.NiceDiff
+
Round int
+
Submission *db.PullSubmission
+
}
+
+
// this name is a mouthful
+
func (p *Pages) RepoPullPatchPage(w io.Writer, params RepoPullPatchParams) error {
+
return p.execute("repo/pulls/patch", w, params)
+
}
+
func (p *Pages) Static() http.Handler {
sub, err := fs.Sub(files, "static")
if err != nil {
+90
appview/pages/templates/repo/pulls/patch.html
···
+
{{ define "title" }}
+
viewing patch of {{ .Pull.Title }} · pull #{{ .Pull.PullId }} · {{ .RepoInfo.FullName }}
+
{{ end }}
+
+
{{ define "content" }}
+
{{ $oneIndexedRound := add .Round 1 }}
+
{{ $stat := .Diff.Stat }}
+
<div class="flex gap-2 items-center text-gray-500 mb-2 px-6">
+
<a href="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/" class="flex items-center gap-2">
+
<i data-lucide="arrow-left" class="w-4 h-4"></i>
+
back
+
</a>
+
<span class="select-none before:content-['·']"></span>
+
viewing round
+
<span class="text-black">#{{ $oneIndexedRound }}</span>
+
</div>
+
<div class="rounded drop-shadow-sm bg-white py-4 px-6">
+
<header class="pb-4">
+
<h1 class="text-2xl">
+
{{ .Pull.Title }}
+
<span class="text-gray-500">#{{ .Pull.PullId }}</span>
+
</h1>
+
</header>
+
+
{{ $bgColor := "bg-gray-800" }}
+
{{ $icon := "ban" }}
+
+
{{ if .Pull.State.IsOpen }}
+
{{ $bgColor = "bg-green-600" }}
+
{{ $icon = "git-pull-request" }}
+
{{ else if .Pull.State.IsMerged }}
+
{{ $bgColor = "bg-purple-600" }}
+
{{ $icon = "git-merge" }}
+
{{ end }}
+
+
<section>
+
<div class="flex items-center gap-2">
+
<div
+
id="state"
+
class="inline-flex items-center rounded px-3 py-1 {{ $bgColor }}"
+
>
+
<i
+
data-lucide="{{ $icon }}"
+
class="w-4 h-4 mr-1.5 text-white"
+
></i>
+
<span class="text-white">{{ .Pull.State.String }}</span>
+
</div>
+
<span class="text-gray-500 text-sm">
+
opened by
+
{{ $owner := index $.DidHandleMap .Pull.OwnerDid }}
+
<a href="/{{ $owner }}" class="no-underline hover:underline"
+
>{{ $owner }}</a
+
>
+
<span class="select-none before:content-['\00B7']"></span>
+
<time>{{ .Pull.Created | timeFmt }}</time>
+
<span class="select-none before:content-['\00B7']"></span>
+
<span>targeting branch
+
<span class="text-xs rounded bg-gray-100 text-black font-mono px-2 mx-1/2 inline-flex items-center">
+
{{ .Pull.TargetBranch }}
+
</span>
+
</span>
+
</span>
+
</div>
+
+
{{ if .Pull.Body }}
+
<article id="body" class="mt-2 prose">
+
{{ .Pull.Body | markdown }}
+
</article>
+
{{ end }}
+
</section>
+
+
<div id="diff-stat">
+
<br>
+
<strong class="text-sm uppercase mb-4">Changed files</strong>
+
{{ range .Diff.Diff }}
+
<ul>
+
{{ if .IsDelete }}
+
<li><a href="#file-{{ .Name.Old }}">{{ .Name.Old }}</a></li>
+
{{ else }}
+
<li><a href="#file-{{ .Name.New }}">{{ .Name.New }}</a></li>
+
{{ end }}
+
</ul>
+
{{ end }}
+
</div>
+
</div>
+
<section>
+
{{ template "fragments/diff" (list .RepoInfo.FullName .Diff) }}
+
</section>
+
{{ end }}
+
+3 -5
appview/pages/templates/repo/pulls/pull.html
···
</div>
{{ if .Pull.Body }}
-
<article id="body" class="mt-8 prose">
+
<article id="body" class="mt-2 prose">
{{ .Pull.Body | markdown }}
</article>
{{ end }}
···
{{ $s = "" }}
{{ end }}
{{ len .Comments }} comment{{$s}}
+
<span class="before:content-['·']"></span>
+
<a href="/{{ $.RepoInfo.FullName }}/pulls/{{ $.Pull.PullId }}/round/{{.RoundNumber}}">view patch</a>
</span>
</div>
</div>
</summary>
<div class="pl-12 flex flex-col gap-2 mt-2 relative">
-
<div>
-
{{ template "fragments/diff" (list $repoName $diff) }}
-
</div>
-
{{ range .Comments }}
<div id="comment-{{.ID}}" class="bg-white rounded drop-shadow-sm py-2 px-4 relative w-fit">
<div class="absolute left-8 -top-2 w-px h-2 bg-gray-300"></div>
+47
appview/state/pull.go
···
"strings"
"time"
+
"github.com/go-chi/chi/v5"
"github.com/sotangled/tangled/api/tangled"
"github.com/sotangled/tangled/appview/db"
"github.com/sotangled/tangled/appview/pages"
···
Pull: *pull,
MergeCheck: mergeCheckResponse,
})
+
}
+
+
func (s *State) RepoPullPatch(w http.ResponseWriter, r *http.Request) {
+
user := s.auth.GetUser(r)
+
f, err := fullyResolvedRepo(r)
+
if err != nil {
+
log.Println("failed to get repo and knot", err)
+
return
+
}
+
+
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()
+
}
+
}
+
+
s.pages.RepoPullPatchPage(w, pages.RepoPullPatchParams{
+
LoggedInUser: user,
+
DidHandleMap: didHandleMap,
+
RepoInfo: f.RepoInfo(s, user),
+
Pull: pull,
+
Round: roundIdInt,
+
Submission: pull.Submissions[roundIdInt],
+
Diff: pull.Submissions[roundIdInt].AsNiceDiff(pull.TargetBranch),
+
})
+
}
func (s *State) RepoPulls(w http.ResponseWriter, r *http.Request) {
+1 -1
appview/state/router.go
···
r.Route("/{pull}", func(r chi.Router) {
r.Use(ResolvePull(s))
r.Get("/", s.RepoSinglePull)
-
r.Get("/patch", s.RepoSinglePull)
+
r.Get("/round/{round}", s.RepoPullPatch)
// authorized requests below this point
r.Group(func(r chi.Router) {