forked from tangled.org/core
Monorepo for Tangled — https://tangled.org
at master 4.7 kB view raw
1{{ define "repo/pulls/fragments/pullActions" }} 2 {{ $lastIdx := sub (len .Pull.Submissions) 1 }} 3 {{ $roundNumber := .RoundNumber }} 4 {{ $stack := .Stack }} 5 6 {{ $totalPulls := sub 0 1 }} 7 {{ $below := sub 0 1 }} 8 {{ $stackCount := "" }} 9 {{ if .Pull.IsStacked }} 10 {{ $totalPulls = len $stack }} 11 {{ $below = $stack.Below .Pull }} 12 {{ $mergeable := len $below.Mergeable }} 13 {{ $stackCount = printf "%d/%d" $mergeable $totalPulls }} 14 {{ end }} 15 16 {{ $isPushAllowed := .RepoInfo.Roles.IsPushAllowed }} 17 {{ $isMerged := .Pull.State.IsMerged }} 18 {{ $isClosed := .Pull.State.IsClosed }} 19 {{ $isOpen := .Pull.State.IsOpen }} 20 {{ $isConflicted := and .MergeCheck (or .MergeCheck.Error .MergeCheck.IsConflicted) }} 21 {{ $isPullAuthor := and .LoggedInUser (eq .LoggedInUser.Did .Pull.OwnerDid) }} 22 {{ $isLastRound := eq $roundNumber $lastIdx }} 23 {{ $isSameRepoBranch := .Pull.IsBranchBased }} 24 {{ $isUpToDate := .ResubmitCheck.No }} 25 <div id="actions-{{$roundNumber}}" class="flex flex-wrap gap-2 relative"> 26 <button 27 hx-get="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/round/{{ $roundNumber }}/comment" 28 hx-target="#actions-{{$roundNumber}}" 29 hx-swap="outerHtml" 30 class="btn p-2 flex items-center gap-2 no-underline hover:no-underline group"> 31 {{ i "message-square-plus" "w-4 h-4" }} 32 <span>comment</span> 33 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 34 </button> 35 {{ if .BranchDeleteStatus }} 36 <button 37 hx-delete="/{{ .BranchDeleteStatus.Repo.Did }}/{{ .BranchDeleteStatus.Repo.Name }}/branches" 38 hx-vals='{"branch": "{{ .BranchDeleteStatus.Branch }}" }' 39 hx-swap="none" 40 class="btn 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"> 41 {{ i "git-branch" "w-4 h-4" }} 42 <span>delete branch</span> 43 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 44 </button> 45 {{ end }} 46 {{ if and $isPushAllowed $isOpen $isLastRound }} 47 {{ $disabled := "" }} 48 {{ if $isConflicted }} 49 {{ $disabled = "disabled" }} 50 {{ end }} 51 <button 52 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/merge" 53 hx-swap="none" 54 hx-confirm="Are you sure you want to merge pull #{{ .Pull.PullId }} into the `{{ .Pull.TargetBranch }}` branch?" 55 class="btn p-2 flex items-center gap-2 group" {{ $disabled }}> 56 {{ i "git-merge" "w-4 h-4" }} 57 <span>merge{{if $stackCount}} {{$stackCount}}{{end}}</span> 58 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 59 </button> 60 {{ end }} 61 62 {{ if and $isPullAuthor $isOpen $isLastRound }} 63 {{ $disabled := "" }} 64 {{ if $isUpToDate }} 65 {{ $disabled = "disabled" }} 66 {{ end }} 67 <button id="resubmitBtn" 68 {{ if not .Pull.IsPatchBased }} 69 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/resubmit" 70 {{ else }} 71 hx-get="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/resubmit" 72 hx-target="#actions-{{$roundNumber}}" 73 hx-swap="outerHtml" 74 {{ end }} 75 76 hx-disabled-elt="#resubmitBtn" 77 class="btn p-2 flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed group" {{ $disabled }} 78 79 {{ if $disabled }} 80 title="Update this branch to resubmit this pull request" 81 {{ else }} 82 title="Resubmit this pull request" 83 {{ end }} 84 > 85 {{ i "rotate-ccw" "w-4 h-4" }} 86 <span>resubmit</span> 87 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 88 </button> 89 {{ end }} 90 91 {{ if and (or $isPullAuthor $isPushAllowed) $isOpen $isLastRound }} 92 <button 93 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/close" 94 hx-swap="none" 95 class="btn p-2 flex items-center gap-2 group"> 96 {{ i "ban" "w-4 h-4" }} 97 <span>close</span> 98 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 99 </button> 100 {{ end }} 101 102 {{ if and (or $isPullAuthor $isPushAllowed) $isClosed $isLastRound }} 103 <button 104 hx-post="/{{ .RepoInfo.FullName }}/pulls/{{ .Pull.PullId }}/reopen" 105 hx-swap="none" 106 class="btn p-2 flex items-center gap-2 group"> 107 {{ i "refresh-ccw-dot" "w-4 h-4" }} 108 <span>reopen</span> 109 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 110 </button> 111 {{ end }} 112 </div> 113{{ end }} 114 115