{{ define "repo/pulls/fragments/diff" }}
{{ $split := .Split }}
{{ range .Files }}
{{ $ins := 0 }}
{{ $del := 0 }}
{{ range .Hunks }}
{{ if $split }}
{{ range .Rows }}
{{ if eq .Left.Kind "del" }}{{ $del = add $del 1 }}{{ end }}
{{ if eq .Right.Kind "add" }}{{ $ins = add $ins 1 }}{{ end }}
{{ end }}
{{ else }}
{{ range .Lines }}
{{ if eq .Op "-" }}{{ $del = add $del 1 }}{{ end }}
{{ if eq .Op "+" }}{{ $ins = add $ins 1 }}{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ i "chevron-right" "w-4 h-4" }}
{{ i "chevron-down" "w-4 h-4" }}
{{ template "repo/fragments/diffStatPill" (dict "Insertions" $ins "Deletions" $del) }}
{{ .Path }}
{{ if .Note }}
{{ .Note }}
{{ else if $split }}
{{ template "pullDiffSplitTable" . }}
{{ else }}
{{ template "pullDiffUnifiedTable" . }}
{{ end }}
{{ end }}
{{ end }}
{{/* pullDiffUnifiedTable renders a DiffFile's hunks as a 3-column unified table. */}}
{{ define "pullDiffUnifiedTable" }}
{{- range .Hunks -}}
| ··· |
{{- range .Lines -}}
{{- $cls := "" -}}
{{- if eq .Op "+" -}}{{- $cls = "added" -}}{{- else if eq .Op "-" -}}{{- $cls = "deleted" -}}{{- end -}}
| {{ if ge .Old 0 }}{{ .Old }}{{ end }} |
{{ if ge .New 0 }}{{ .New }}{{ end }} |
{{ .Content }} |
{{- end -}}
{{- end -}}
{{ end }}
{{/* pullDiffSplitTable renders a DiffFile's hunks as a 4-column side-by-side table. */}}
{{ define "pullDiffSplitTable" }}
{{- range .Hunks -}}
| ··· |
{{- range .Rows -}}
{{- template "pullDiffSplitCell" .Left -}}
{{- template "pullDiffSplitCell" .Right -}}
{{- end -}}
{{- end -}}
{{ end }}
{{/* pullDiffSplitCell renders the num + content s for one side of a split row.
Dot is a DiffCell (Kind ctx|del|add|empty, Num, Content). */}}
{{ define "pullDiffSplitCell" }}
{{- $cls := "" -}}
{{- $mark := "" -}}
{{- if eq .Kind "del" -}}{{- $cls = "deleted" -}}{{- $mark = "-" -}}
{{- else if eq .Kind "add" -}}{{- $cls = "added" -}}{{- $mark = "+" -}}
{{- else if eq .Kind "empty" -}}{{- $cls = "empty" -}}{{- end -}}
| {{ if ge .Num 0 }}{{ .Num }}{{ end }} |
{{ .Content }} |
{{ end }}