This commit is contained in:
2025-11-24 10:20:41 -05:00
parent 1f656f31c0
commit 91002081f7
+46 -34
View File
@@ -37,24 +37,36 @@ inputs:
description: "URL to apprise-api endpoint (optional)" description: "URL to apprise-api endpoint (optional)"
default: "" default: ""
repository:
description: "Repository name (optional, required for act testing)"
default: ""
outputs: outputs:
approved: approved:
description: Approval result
value: ${{ steps.wait.outputs.approved }} value: ${{ steps.wait.outputs.approved }}
runs: runs:
using: "composite" using: "composite"
steps: steps:
# Detect platform
# Detect platform & repository
- id: detect - id: detect
shell: bash shell: bash
run: | run: |
URL="${{ github.server_url }}" URL="${GITHUB_SERVER_URL:-${{ github.server_url }}}"
REPO="${{ inputs.repository }}:${{ github.repository }}"
if [[ -z "$REPO" ]]; then
echo "❌ Repository not set. Please provide inputs.repository or github.repository"
exit 1
fi
if [[ "$URL" =~ gitea ]]; then if [[ "$URL" =~ gitea ]]; then
echo "platform=gitea" >> $GITHUB_OUTPUT echo "platform=gitea" >> $GITHUB_OUTPUT
else else
echo "platform=github" >> $GITHUB_OUTPUT echo "platform=github" >> $GITHUB_OUTPUT
fi fi
echo "api_url=${URL}/api/v1" >> $GITHUB_OUTPUT echo "api_url=${URL}/api/v1" >> $GITHUB_OUTPUT
echo "repository=${REPO}" >> $GITHUB_OUTPUT
# Create approval issue # Create approval issue
- id: create-issue - id: create-issue
@@ -73,7 +85,7 @@ runs:
Please reply with a keyword on this issue." Please reply with a keyword on this issue."
# Proper JSON array for assignees # Build JSON array of assignees
ASSIGNEES_JSON=$(jq -nc --arg csv "$APPROVERS" '$csv | split(",")') ASSIGNEES_JSON=$(jq -nc --arg csv "$APPROVERS" '$csv | split(",")')
json=$(jq -n \ json=$(jq -n \
@@ -86,33 +98,19 @@ runs:
-H "Authorization: token $TOKEN" \ -H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$json" \ -d "$json" \
"${{ steps.detect.outputs.api_url }}/repos/${{ github.repository }}/issues") "${{ steps.detect.outputs.api_url }}/repos/${{ steps.detect.outputs.repository }}/issues")
echo "Response from API: $resp"
# Extract issue number (GitHub: number, Gitea: index or id)
issue_number=$(echo "$resp" | jq -r '.number // .index // .id')
if [[ -z "$issue_number" || "$issue_number" == "null" ]]; then
echo "❌ Failed to create issue, response: $resp"
exit 1
fi
issue_number=$(echo "$resp" | jq -r '.number // .index')
echo "issue=$issue_number" >> $GITHUB_OUTPUT echo "issue=$issue_number" >> $GITHUB_OUTPUT
# Notification helper
- id: notify
shell: bash
if: always()
env:
APPRISE_URLS: ${{ inputs.apprise_urls }}
APPRISE_API: ${{ inputs.apprise_api }}
run: |
msg="$1"
if [[ -n "$APPRISE_URLS" ]]; then
IFS=',' read -r -a urls <<< "$APPRISE_URLS"
for u in "${urls[@]}"; do
apprise -b "$msg" -t "Manual Approval" "$u" || true
done
fi
if [[ -n "$APPRISE_API" ]]; then
curl -s -X POST "$APPRISE_API" \
-H "Content-Type: application/json" \
-d "{\"title\":\"Manual Approval\",\"body\":\"$msg\"}" || true
fi
# Wait for approval with reminders # Wait for approval with reminders
- id: wait - id: wait
shell: bash shell: bash
@@ -126,20 +124,34 @@ runs:
DENIAL_KEYWORDS: ${{ inputs.denial_keywords }} DENIAL_KEYWORDS: ${{ inputs.denial_keywords }}
REMINDER_INTERVAL: ${{ inputs.reminder_interval }} REMINDER_INTERVAL: ${{ inputs.reminder_interval }}
POLL_INTERVAL: ${{ inputs.poll_interval }} POLL_INTERVAL: ${{ inputs.poll_interval }}
APPRISE_URLS: ${{ inputs.apprise_urls }}
APPRISE_API: ${{ inputs.apprise_api }}
run: | run: |
# Split comma-separated inputs into Bash arrays # Split inputs
IFS=',' read -r -a approver_list <<< "$APPROVERS" IFS=',' read -r -a approver_list <<< "$APPROVERS"
IFS=',' read -r -a approved_kws <<< "$APPROVAL_KEYWORDS" IFS=',' read -r -a approved_kws <<< "$APPROVAL_KEYWORDS"
IFS=',' read -r -a denied_kws <<< "$DENIAL_KEYWORDS" IFS=',' read -r -a denied_kws <<< "$DENIAL_KEYWORDS"
last_reminder=$(date +%s) last_reminder=$(date +%s)
ISSUE_URL="${API_URL}/repos/${{ github.repository }}/issues/$ISSUE" ISSUE_URL="${API_URL}/repos/${{ steps.detect.outputs.repository }}/issues/$ISSUE"
# Function to send notifications # Notification function (integrated Apprise)
notify_func() { notify_func() {
msg="$1" msg="$1"
echo "::notice::$msg" echo "::notice::$msg"
bash $GITHUB_ACTION_PATH/notify "$msg"
if [[ -n "$APPRISE_URLS" ]]; then
IFS=',' read -r -a urls <<< "$APPRISE_URLS"
for u in "${urls[@]}"; do
apprise -b "$msg" -t "Manual Approval" "$u" || true
done
fi
if [[ -n "$APPRISE_API" ]]; then
curl -s -X POST "$APPRISE_API" \
-H "Content-Type: application/json" \
-d "{\"title\":\"Manual Approval\",\"body\":\"$msg\"}" || true
fi
} }
notify_func "Approval required on issue #$ISSUE" notify_func "Approval required on issue #$ISSUE"
@@ -215,4 +227,4 @@ runs:
-H "Authorization: token $TOKEN" \ -H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"state":"closed"}' \ -d '{"state":"closed"}' \
"$API_URL/repos/${{ github.repository }}/issues/$ISSUE" >/dev/null || true "$API_URL/repos/${{ steps.detect.outputs.repository }}/issues/$ISSUE" >/dev/null || true