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