diff --git a/action.yml b/action.yml index e0c7911..00d933e 100644 --- a/action.yml +++ b/action.yml @@ -37,24 +37,36 @@ inputs: description: "URL to apprise-api endpoint (optional)" default: "" + repository: + description: "Repository name (optional, required for act testing)" + default: "" + outputs: approved: + description: Approval result value: ${{ steps.wait.outputs.approved }} runs: using: "composite" steps: - # Detect platform + + # Detect platform & repository - id: detect shell: bash 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 - echo "platform=gitea" >> $GITHUB_OUTPUT + echo "platform=gitea" >> $GITHUB_OUTPUT else - echo "platform=github" >> $GITHUB_OUTPUT + echo "platform=github" >> $GITHUB_OUTPUT fi echo "api_url=${URL}/api/v1" >> $GITHUB_OUTPUT + echo "repository=${REPO}" >> $GITHUB_OUTPUT # Create approval issue - id: create-issue @@ -73,7 +85,7 @@ runs: 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(",")') json=$(jq -n \ @@ -86,33 +98,19 @@ runs: -H "Authorization: token $TOKEN" \ -H "Content-Type: application/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 - # 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 - id: wait shell: bash @@ -126,20 +124,34 @@ runs: DENIAL_KEYWORDS: ${{ inputs.denial_keywords }} REMINDER_INTERVAL: ${{ inputs.reminder_interval }} POLL_INTERVAL: ${{ inputs.poll_interval }} + APPRISE_URLS: ${{ inputs.apprise_urls }} + APPRISE_API: ${{ inputs.apprise_api }} run: | - # Split comma-separated inputs into Bash arrays + # Split inputs IFS=',' read -r -a approver_list <<< "$APPROVERS" 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" + ISSUE_URL="${API_URL}/repos/${{ steps.detect.outputs.repository }}/issues/$ISSUE" - # Function to send notifications + # Notification function (integrated Apprise) notify_func() { msg="$1" 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" @@ -215,4 +227,4 @@ runs: -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ -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