1{{ define "fragments/pullActions" }}
2 {{ $lastIdx := sub (len .Pull.Submissions) 1 }}
3 {{ $roundNumber := .RoundNumber }}
4
5 {{ $isPushAllowed := .RepoInfo.Roles.IsPushAllowed }}
6 {{ $isMerged := .Pull.State.IsMerged }}
7 {{ $isClosed := .Pull.State.IsClosed }}
8 {{ $isOpen := .Pull.State.IsOpen }}
9 {{ $isConflicted := and .MergeCheck (or .MergeCheck.Error .MergeCheck.IsConflicted) }}
10 {{ $isPullAuthor := and .LoggedInUser (eq .LoggedInUser.Did .Pull.OwnerDid) }}
11 {{ $isLastRound := eq $roundNumber $lastIdx }}
12 {{ $isSameRepoBranch := .Pull.IsSameRepoBranch }}
13 {{ $isUpToDate := .ResubmitCheck.No }}
14 <div class="relative w-fit">
15 <div class="absolute left-8 -top-2 w-px h-2 bg-gray-300 dark:bg-gray-600"></div>
16 <div id="actions-{{$roundNumber}}" class="flex flex-wrap gap-2">
17 <button
18 hx-get="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/round/{{ $roundNumber }}/comment"
19 hx-target="#actions-{{$roundNumber}}"
20 hx-swap="outerHtml"
21 class="btn p-2 flex items-center gap-2 no-underline hover:no-underline">
22 {{ i "message-square-plus" "w-4 h-4" }}
23 <span>comment</span>
24 </button>
25 {{ if and $isPushAllowed $isOpen $isLastRound }}
26 {{ $disabled := "" }}
27 {{ if $isConflicted }}
28 {{ $disabled = "disabled" }}
29 {{ end }}
30 <button
31 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/merge"
32 hx-swap="none"
33 hx-confirm="Are you sure you want to merge pull #{{ .Pull.PullId }} into the `{{ .Pull.TargetBranch }}` branch?"
34 class="btn p-2 flex items-center gap-2" {{ $disabled }}>
35 {{ i "git-merge" "w-4 h-4" }}
36 <span>merge</span>
37 </button>
38 {{ end }}
39
40 {{ if and $isPullAuthor $isOpen $isLastRound }}
41 {{ $disabled := "" }}
42 {{ if $isUpToDate }}
43 {{ $disabled = "disabled" }}
44 {{ end }}
45 <button id="resubmitBtn"
46 {{ if not .Pull.IsPatch }}
47 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/resubmit"
48 {{ else }}
49 hx-get="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/resubmit"
50 hx-target="#actions-{{$roundNumber}}"
51 hx-swap="outerHtml"
52 {{ end }}
53
54 hx-disabled-elt="#resubmitBtn"
55 class="btn p-2 flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed" {{ $disabled }}
56
57 {{ if $disabled }}
58 title="Update this branch to resubmit this pull request"
59 {{ else }}
60 title="Resubmit this pull request"
61 {{ end }}
62 >
63 {{ i "rotate-ccw" "w-4 h-4" }}
64 <span>resubmit</span>
65 </button>
66 {{ end }}
67
68 {{ if and (or $isPullAuthor $isPushAllowed) $isOpen $isLastRound }}
69 <button
70 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/close"
71 hx-swap="none"
72 class="btn p-2 flex items-center gap-2">
73 {{ i "ban" "w-4 h-4" }}
74 <span>close</span>
75 </button>
76 {{ end }}
77
78 {{ if and (or $isPullAuthor $isPushAllowed) $isClosed $isLastRound }}
79 <button
80 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/reopen"
81 hx-swap="none"
82 class="btn p-2 flex items-center gap-2">
83 {{ i "circle-dot" "w-4 h-4" }}
84 <span>reopen</span>
85 </button>
86 {{ end }}
87 </div>
88 </div>
89{{ end }}
90
91