This commit is contained in:
2025-11-24 10:14:23 -05:00
parent 51ee84e692
commit 1f656f31c0
+17 -27
View File
@@ -1,5 +1,5 @@
name: "manual-approval-cross"
description: "Manual approval for Github & Gitea with reminders + Apprise notifications"
description: "Manual approval for GitHub & Gitea with reminders + Apprise notifications"
branding:
icon: "check-circle"
color: "green"
@@ -14,11 +14,11 @@ inputs:
required: true
approval_keywords:
description: "Approval keywords"
description: "Approval keywords (comma-separated)"
default: "approve,approved,lgtm,yes"
denial_keywords:
description: "Denial keywords"
description: "Denial keywords (comma-separated)"
default: "deny,denied,no"
poll_interval:
@@ -39,7 +39,6 @@ inputs:
outputs:
approved:
description: Approval response
value: ${{ steps.wait.outputs.approved }}
runs:
@@ -72,9 +71,9 @@ runs:
**Approval keywords:** ${{ inputs.approval_keywords }}
**Denial keywords:** ${{ inputs.denial_keywords }}
Please reply with a keyword on this issue.
"
Please reply with a keyword on this issue."
# Proper JSON array for assignees
ASSIGNEES_JSON=$(jq -nc --arg csv "$APPROVERS" '$csv | split(",")')
json=$(jq -n \
@@ -90,10 +89,9 @@ runs:
"${{ steps.detect.outputs.api_url }}/repos/${{ github.repository }}/issues")
issue_number=$(echo "$resp" | jq -r '.number // .index')
echo "issue=$issue_number" >> $GITHUB_OUTPUT
# Notification helper function
# Notification helper
- id: notify
shell: bash
if: always()
@@ -102,8 +100,6 @@ runs:
APPRISE_API: ${{ inputs.apprise_api }}
run: |
msg="$1"
# Apprise CLI URLs
if [[ -n "$APPRISE_URLS" ]]; then
IFS=',' read -r -a urls <<< "$APPRISE_URLS"
for u in "${urls[@]}"; do
@@ -111,16 +107,13 @@ runs:
done
fi
# Apprise-API server
if [[ -n "$APPRISE_API" ]]; then
curl -s -X POST "$APPRISE_API" \
-H "Content-Type: application/json" \
-d "{\"title\": \"Manual Approval\", \"body\": \"$msg\"}" || true
-d "{\"title\":\"Manual Approval\",\"body\":\"$msg\"}" || true
fi
# note: the script expects $1, so we will call it with "run: echo 'message' | ./.github/actions/.../notify"
# Wait for approval with reminder support
# Wait for approval with reminders
- id: wait
shell: bash
env:
@@ -129,23 +122,20 @@ runs:
API_URL: ${{ steps.detect.outputs.api_url }}
ISSUE: ${{ steps.create-issue.outputs.issue }}
APPROVERS: ${{ inputs.approvers }}
APPROVAL_KEYWORDS: ${{ inputs.approval_keywords }}
DENIAL_KEYWORDS: ${{ inputs.denial_keywords }}
REMINDER_INTERVAL: ${{ inputs.reminder_interval }}
POLL_INTERVAL: ${{ inputs.poll_interval }}
run: |
# Split comma-separated inputs into Bash arrays
IFS=',' read -r -a approver_list <<< "$APPROVERS"
approved_kws=(${ { inputs.approval_keywords }//,/ })
denied_kws=(${ { inputs.denial_keywords }//,/ })
IFS=',' read -r -a approved_kws <<< "$APPROVAL_KEYWORDS"
IFS=',' read -r -a denied_kws <<< "$DENIAL_KEYWORDS"
last_reminder=$(date +%s)
ISSUE_URL="${API_URL}/repos/${{ github.repository }}/issues/$ISSUE"
# Send first notification
echo "::group::Initial notification"
echo "Issue #$ISSUE created for manual approval"
echo "::endgroup::"
# Run notifications in a reusable function
# Function to send notifications
notify_func() {
msg="$1"
echo "::notice::$msg"
@@ -156,8 +146,8 @@ runs:
while true; do
comments=$(curl -s \
-H "Authorization: token $TOKEN" \
"$ISSUE_URL/comments")
-H "Authorization: token $TOKEN" \
"$ISSUE_URL/comments")
declare -A state
for u in "${approver_list[@]}"; do state[$u]="pending"; done
@@ -196,7 +186,7 @@ runs:
break
fi
# Send reminder
# Send reminders
if (( REMINDER_INTERVAL > 0 )); then
now=$(date +%s)
since=$(( now - last_reminder ))