1{{ define "repo/pulls/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.IsBranchBased }}
13 {{ $isUpToDate := .ResubmitCheck.No }}
14 <div class="relative w-fit">
15 <div id="actions-{{$roundNumber}}" class="flex flex-wrap gap-2">
16 <button
17 hx-get="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/round/{{ $roundNumber }}/comment"
18 hx-target="#actions-{{$roundNumber}}"
19 hx-swap="outerHtml"
20 class="btn p-2 flex items-center gap-2 no-underline hover:no-underline">
21 {{ i "message-square-plus" "w-4 h-4" }}
22 <span>comment</span>
23 </button>
24 {{ if and $isPushAllowed $isOpen $isLastRound }}
25 {{ $disabled := "" }}
26 {{ if $isConflicted }}
27 {{ $disabled = "disabled" }}
28 {{ end }}
29 <button
30 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/merge"
31 hx-swap="none"
32 hx-confirm="Are you sure you want to merge pull #{{ .Pull.PullId }} into the `{{ .Pull.TargetBranch }}` branch?"
33 class="btn p-2 flex items-center gap-2" {{ $disabled }}>
34 {{ i "git-merge" "w-4 h-4" }}
35 <span>merge</span>
36 </button>
37 {{ end }}
38
39 {{ if and $isPullAuthor $isOpen $isLastRound }}
40 {{ $disabled := "" }}
41 {{ if $isUpToDate }}
42 {{ $disabled = "disabled" }}
43 {{ end }}
44 <button id="resubmitBtn"
45 {{ if not .Pull.IsPatchBased }}
46 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/resubmit"
47 {{ else }}
48 hx-get="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/resubmit"
49 hx-target="#actions-{{$roundNumber}}"
50 hx-swap="outerHtml"
51 {{ end }}
52
53 hx-disabled-elt="#resubmitBtn"
54 class="btn p-2 flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed" {{ $disabled }}
55
56 {{ if $disabled }}
57 title="Update this branch to resubmit this pull request"
58 {{ else }}
59 title="Resubmit this pull request"
60 {{ end }}
61 >
62 {{ i "rotate-ccw" "w-4 h-4" }}
63 <span>resubmit</span>
64 </button>
65 {{ end }}
66
67 {{ if and (or $isPullAuthor $isPushAllowed) $isOpen $isLastRound }}
68 <button
69 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/close"
70 hx-swap="none"
71 class="btn p-2 flex items-center gap-2">
72 {{ i "ban" "w-4 h-4" }}
73 <span>close</span>
74 </button>
75 {{ end }}
76
77 {{ if and (or $isPullAuthor $isPushAllowed) $isClosed $isLastRound }}
78 <button
79 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/reopen"
80 hx-swap="none"
81 class="btn p-2 flex items-center gap-2">
82 {{ i "refresh-ccw-dot" "w-4 h-4" }}
83 <span>reopen</span>
84 </button>
85 {{ end }}
86 </div>
87 </div>
88{{ end }}
89
90