This repository has no description
1{{ define "repo/pulls/fragments/pullActions" }}
2 {{ $lastIdx := sub (len .Pull.Submissions) 1 }}
3 {{ $roundNumber := .RoundNumber }}
4 {{ $stack := .Stack }}
5 {{ $loading := .Loading }}
6
7 {{ $totalPulls := sub 0 1 }}
8 {{ $below := sub 0 1 }}
9 {{ $stackCount := "" }}
10 {{ if (gt (len .Stack) 1) }}
11 {{ $totalPulls = len $stack }}
12 {{ $below = $stack.Below .Pull }}
13 {{ $mergeable := len $below.Mergeable }}
14 {{ $stackCount = printf "%d/%d" $mergeable $totalPulls }}
15 {{ end }}
16
17 {{ $isPushAllowed := .RepoInfo.Roles.IsPushAllowed }}
18 {{ $isMerged := .Pull.State.IsMerged }}
19 {{ $isClosed := .Pull.State.IsClosed }}
20 {{ $isOpen := .Pull.State.IsOpen }}
21 {{ $isConflicted := and .MergeCheck (or .MergeCheck.Error .MergeCheck.IsConflicted) }}
22 {{ $isPullAuthor := and .LoggedInUser (eq .LoggedInUser.Did .Pull.OwnerDid) }}
23 {{ $isLastRound := eq $roundNumber $lastIdx }}
24 {{ $isSameRepoBranch := .Pull.IsBranchBased }}
25 {{ $isUpToDate := .ResubmitCheck.No }}
26 {{ $isForkBased := .Pull.IsForkBased }}
27 {{ $showRunCI := and (not $loading) $isPushAllowed $isOpen $isLastRound $isForkBased (not .HasPipeline) (ne .RepoInfo.Spindle "") }}
28
29 <div id="action-card-{{$roundNumber}}" class="{{ if .LoggedInUser }}relative p-2 flex flex-col gap-2{{ else }}hidden{{ end }}"
30 {{ if $loading }}
31 hx-get="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/round/{{ $roundNumber }}/actions"
32 hx-trigger="load"
33 hx-swap="outerHTML"
34 hx-target="this"
35 {{ end }}
36 >
37 {{ if and (not $loading) $isLastRound }}
38 {{ if and $isOpen $isForkBased (not .HasPipeline) (ne .RepoInfo.Spindle "") }}
39 {{ template "workflowWarning" . }}
40 {{ end }}
41 {{ template "mergeCheck" . }}
42 {{ template "resubmitStatus" . }}
43 {{ end }}
44 <div id="actions-{{$roundNumber}}" hx-target="this" class="flex flex-wrap gap-2 relative"
45 {{ if $loading }}
46 hx-swap="outerHTML"
47 {{ end }}
48 >
49 {{ if .LoggedInUser }}
50 <button
51 hx-get="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/round/{{ $roundNumber }}/comment"
52 class="btn-flat p-2 flex items-center gap-2 no-underline hover:no-underline group">
53 {{ i "message-square-plus" "w-4 h-4 inline group-[.htmx-request]:hidden" }}
54 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
55 Comment
56 </button>
57 {{ end }}
58 {{ if and (not $loading) .BranchDeleteStatus }}
59 <button
60 hx-delete="/{{ resolve .BranchDeleteStatus.Repo.Did }}/{{ .BranchDeleteStatus.Repo.Slug }}/branches"
61 hx-vals='{"branch": "{{ .BranchDeleteStatus.Branch }}" }'
62 hx-swap="none"
63 class="btn-flat p-2 flex items-center gap-2 no-underline hover:no-underline group text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300">
64 {{ i "git-branch" "w-4 h-4 inline group-[.htmx-request]:hidden" }}
65 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
66 Delete branch
67 </button>
68 {{ end }}
69 {{ if $showRunCI }}
70 {{ template "runCiModal" . }}
71 {{ end }}
72 {{ if and $isPushAllowed $isOpen $isLastRound }}
73 <button
74 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/merge"
75 hx-swap="none"
76 hx-confirm="Are you sure you want to merge pull #{{ .Pull.PullId }} into the `{{ .Pull.TargetBranch }}` branch?"
77 class="btn-flat p-2 flex items-center gap-2 group"
78 {{ if or $loading $isConflicted }}disabled{{ end }}
79 >
80 {{ if $loading }}
81 {{ i "loader-circle" "w-4 h-4 animate-spin" }}
82 {{ else }}
83 {{ i "git-merge" "w-4 h-4 inline group-[.htmx-request]:hidden" }}
84 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
85 {{ end }}
86 Merge{{if $stackCount}} {{$stackCount}}{{end}}
87 </button>
88 {{ end }}
89
90 {{ if and $isPullAuthor $isOpen $isLastRound }}
91 <button id="resubmitBtn"
92 {{ if not .Pull.IsPatchBased }}
93 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/resubmit"
94 hx-swap="none"
95 {{ else }}
96 hx-get="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/resubmit"
97 {{ end }}
98
99 hx-disabled-elt="#resubmitBtn"
100 class="btn-flat p-2 flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed group"
101
102 {{ if $loading }}
103 title="Checking for updates…"
104 disabled
105 {{ else if $isUpToDate }}
106 title="Update this branch to resubmit this pull request"
107 disabled
108 {{ else }}
109 title="Resubmit this pull request"
110 {{ end }}
111 >
112 {{ if $loading }}
113 {{ i "loader-circle" "w-4 h-4 animate-spin" }}
114 {{ else }}
115 {{ i "rotate-ccw" "w-4 h-4 inline group-[.htmx-request]:hidden" }}
116 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
117 {{ end }}
118 Resubmit
119 </button>
120 {{ end }}
121
122 {{ if and (or $isPullAuthor $isPushAllowed) $isOpen $isLastRound }}
123 <button
124 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/close"
125 hx-swap="none"
126 class="btn-flat p-2 flex items-center gap-2 group">
127 {{ i "ban" "w-4 h-4 inline group-[.htmx-request]:hidden" }}
128 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
129 Close
130 </button>
131 {{ end }}
132
133 {{ if and (or $isPullAuthor $isPushAllowed) $isClosed $isLastRound }}
134 <button
135 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/reopen"
136 hx-swap="none"
137 class="btn-flat p-2 flex items-center gap-2 group">
138 {{ i "refresh-ccw-dot" "w-4 h-4 inline group-[.htmx-request]:hidden" }}
139 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
140 Reopen
141 </button>
142 {{ end }}
143 </div>
144 </div>
145{{ end }}
146
147{{ define "workflowWarning" }}
148 {{ if .WorkflowsChanged }}
149 <details class="group/ci">
150 <summary class="flex items-center gap-2 cursor-pointer list-none">
151 {{ i "triangle-alert" "w-4 h-4 text-amber-600 dark:text-amber-500" }}
152 <span class="font-medium text-amber-600 dark:text-amber-500">Workflow files changed in this round</span>
153 <div class="text-sm text-gray-500 dark:text-gray-400">
154 <span class="group-open/ci:hidden inline">Expand</span>
155 <span class="hidden group-open/ci:inline">Collapse</span>
156 </div>
157 </summary>
158 <ul class="space-y-1 mt-2 overflow-x-auto">
159 {{ range .ChangedWorkflowFiles }}
160 <li class="flex items-center whitespace-nowrap">
161 {{ i "file-warning" "inline-flex w-4 h-4 mr-1.5 text-amber-600 dark:text-amber-500 flex-shrink-0" }}
162 <span class="font-mono">{{ . }}</span>
163 </li>
164 {{ end }}
165 </ul>
166 </details>
167 {{ else }}
168 <div class="flex items-center gap-2 text-amber-600 dark:text-amber-500">
169 {{ i "triangle-alert" "w-4 h-4" }}
170 <span class="font-medium">Workflow needs approval</span>
171 </div>
172 {{ end }}
173{{ end }}
174
175{{ define "runCiModal" }}
176 <button
177 class="btn-flat p-2 flex items-center gap-2 flex-shrink-0 group"
178 popovertarget="run-ci-{{ .Pull.PullId }}"
179 popovertargetaction="toggle"
180 >
181 {{ i "circle-play" "w-4 h-4 inline" }}
182 Run CI
183 </button>
184
185 <div
186 id="run-ci-{{ .Pull.PullId }}"
187 popover
188 class="bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 dark:text-white backdrop:bg-gray-400/50 dark:backdrop:bg-gray-800/50 w-full md:w-96 p-4 rounded drop-shadow overflow-visible"
189 >
190 <form
191 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/trigger-ci?confirm=1"
192 hx-swap="none"
193 hx-indicator="#run-ci-spinner-{{ .Pull.PullId }}"
194 class="flex flex-col gap-2"
195 >
196 <label class="text-lg font-medium p-0">Run CI</label>
197 {{ if .WorkflowsChanged }}
198 <div class="flex items-center gap-2 text-amber-600 dark:text-amber-500">
199 {{ i "triangle-alert" "size-4" }}
200 <span class="font-medium">Workflow files changed in this round</span>
201 </div>
202 <ul class="space-y-1 overflow-x-auto pl-6">
203 {{ range .ChangedWorkflowFiles }}
204 <li class="flex items-center whitespace-nowrap">
205 {{ i "file-warning" "size-4 mr-1.5 text-amber-600 dark:text-amber-500 flex-shrink-0" }}
206 <span class="font-mono text-sm">{{ . }}</span>
207 </li>
208 {{ end }}
209 </ul>
210 <p class="text-sm text-gray-500 dark:text-gray-400">Workflow files changed in this round. Are you sure you want to run CI?</p>
211 {{ else }}
212 <div class="flex items-center gap-2 text-amber-600 dark:text-amber-500">
213 {{ i "triangle-alert" "size-4" }}
214 <span class="font-medium">Workflow needs approval</span>
215 </div>
216 <p class="text-sm text-gray-500 dark:text-gray-400">This fork-based pull request needs approval to run CI. Are you sure?</p>
217 {{ end }}
218 <div class="flex gap-2 pt-2">
219 <button
220 type="button"
221 popovertarget="run-ci-{{ .Pull.PullId }}"
222 popovertargetaction="hide"
223 class="btn w-1/2 flex items-center gap-2 text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300"
224 >
225 {{ i "x" "size-4" }} Cancel
226 </button>
227 <button type="submit" class="btn w-1/2 flex items-center">
228 <span class="inline-flex gap-2 items-center">{{ i "shield-check" "size-4" }} Approve</span>
229 <span id="run-ci-spinner-{{ .Pull.PullId }}" class="group">
230 {{ i "loader-circle" "ml-2 w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
231 </span>
232 </button>
233 </div>
234 <div id="pull-error" class="text-red-500 dark:text-red-400"></div>
235 </form>
236 </div>
237{{ end }}
238
239{{ define "mergeCheck" }}
240 {{ $isOpen := .Pull.State.IsOpen }}
241 {{ if and $isOpen .MergeCheck .MergeCheck.Error }}
242 <div class="flex items-center gap-2 text-red-600 dark:text-red-500">
243 {{ i "triangle-alert" "w-4 h-4" }}
244 <span class="font-medium">{{ .MergeCheck.Error }}</span>
245 </div>
246 {{ else if and $isOpen .MergeCheck .MergeCheck.IsConflicted }}
247 <details class="group/conflict">
248 <summary class="flex items-center justify-between cursor-pointer list-none">
249 <div class="flex items-center gap-2 text-red-600 dark:text-red-500">
250 {{ i "triangle-alert" "w-4 h-4" }}
251 <span class="font-medium">Merge conflicts detected</span>
252 <div class="text-sm text-gray-500 dark:text-gray-400">
253 <span class="group-open/conflict:hidden inline">Expand</span>
254 <span class="hidden group-open/conflict:inline">Collapse</span>
255 </div>
256 </div>
257 </summary>
258 {{ if gt (len .MergeCheck.Conflicts) 0 }}
259 <ul class="space-y-1 mt-2 overflow-x-auto">
260 {{ range .MergeCheck.Conflicts }}
261 {{ if .Filename }}
262 <li class="flex items-center whitespace-nowrap">
263 {{ i "file-warning" "inline-flex w-4 h-4 mr-1.5 text-red-600 dark:text-red-500 flex-shrink-0" }}
264 <span class="font-mono">{{ .Filename }}</span>
265 </li>
266 {{ else if .Reason }}
267 <li class="flex items-center whitespace-nowrap">
268 {{ i "file-warning" "w-4 h-4 mr-1.5 text-red-600 dark:text-red-500 " }}
269 <span>{{.Reason}}</span>
270 </li>
271 {{ end }}
272 {{ end }}
273 </ul>
274 {{ end }}
275 </details>
276 {{ else if and $isOpen .MergeCheck }}
277 <div class="flex items-center gap-2 text-green-600 dark:text-green-500">
278 {{ i "check" "w-4 h-4" }}
279 <span class="font-medium">No conflicts, ready to merge</span>
280 </div>
281 {{ end }}
282{{ end }}
283
284{{ define "resubmitStatus" }}
285 {{ if .ResubmitCheck.Yes }}
286 <div class="bg-amber-50 dark:bg-amber-900 border border-amber-500 rounded shadow-sm px-6 py-2 relative">
287 <div class="flex items-center gap-2 text-amber-500 dark:text-amber-300">
288 {{ i "triangle-alert" "w-4 h-4" }}
289 <span class="font-medium">This branch has been updated, consider resubmitting</span>
290 </div>
291 </div>
292 {{ end }}
293{{ end }}