Fix date for ciniz post #82
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Push Notification | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| notify: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get commit info | |
| id: commit-info | |
| shell: bash | |
| run: | | |
| # Handle multiline commit messages with proper escaping | |
| MSG=$(git log --format=%B -n 1 ${{ github.sha }}) | |
| # Replace newlines with \n for proper output formatting | |
| MSG_ESCAPED="${MSG//$'\n'/\\n}" | |
| echo "message<<EOF" >> $GITHUB_OUTPUT | |
| echo "$MSG_ESCAPED" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| # Get author name | |
| AUTHOR=$(git log --format=%an -n 1 ${{ github.sha }}) | |
| echo "author_name=$AUTHOR" >> $GITHUB_OUTPUT | |
| # Get files changed | |
| FILES_CHANGED=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | tr '\n' ', ') | |
| echo "files_changed=$FILES_CHANGED" >> $GITHUB_OUTPUT | |
| # Extract issue numbers from commit message with error handling | |
| ISSUE_PATTERN='(fix|close|resolve|fixes|closes|resolves|fixed|closed|resolved)[[:space:]]*#([0-9]+)' | |
| ISSUE_NUMBERS=$(echo "$MSG" | grep -oE "$ISSUE_PATTERN" | grep -oE '#[0-9]+' | tr -d '#' || echo "") | |
| # If no issues found, check for PR references (e.g. Merge pull request #23) | |
| if [ -z "$ISSUE_NUMBERS" ]; then | |
| PR_PATTERN='pull request #([0-9]+)' | |
| PR_NUMBER=$(echo "$MSG" | grep -oE "$PR_PATTERN" | grep -oE '#[0-9]+' | tr -d '#' || echo "") | |
| if [ ! -z "$PR_NUMBER" ]; then | |
| echo "Found PR #$PR_NUMBER, but no direct issue references" | |
| # You could look up issues referenced by the PR here if needed | |
| fi | |
| fi | |
| echo "issue_numbers=$ISSUE_NUMBERS" >> $GITHUB_OUTPUT | |
| # Successfully completed the step even if no issues were found | |
| echo "✅ Commit info processing complete" | |
| - name: Send GitHub app notification | |
| run: | | |
| echo "🔔 New Push to Repository" | |
| echo "Branch: ${{ github.ref_name }}" | |
| echo "Commit: ${{ github.sha }}" | |
| echo "Author: ${{ steps.commit-info.outputs.author_name }}" | |
| # Create a repository dispatch event for external notification systems | |
| # This allows other systems to react to all pushes | |
| TOKEN="${{ secrets.GITHUB_TOKEN }}" | |
| REPO="${{ github.repository }}" | |
| curl -X POST \ | |
| -H "Authorization: token $TOKEN" \ | |
| -H "Accept: application/vnd.github.everest-preview+json" \ | |
| "https://api.github.com/repos/$REPO/dispatches" \ | |
| -d "{\"event_type\":\"push_event\",\"client_payload\":{\"ref\":\"${{ github.ref }}\",\"sha\":\"${{ github.sha }}\",\"author\":\"${{ steps.commit-info.outputs.author_name }}\"}}" | |
| - name: Comment on related issues | |
| if: ${{ steps.commit-info.outputs.issue_numbers != '' }} | |
| uses: peter-evans/create-or-update-comment@v2 | |
| with: | |
| issue-number: ${{ steps.commit-info.outputs.issue_numbers }} | |
| body: | | |
| ## 🔔 This issue was referenced in a commit | |
| **Branch:** ${{ github.ref_name }} | |
| **Commit:** [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) | |
| **Author:** ${{ steps.commit-info.outputs.author_name }} | |
| ### Commit Message | |
| ``` | |
| ${{ steps.commit-info.outputs.message }} | |
| ``` | |
| ### Files Changed | |
| ``` | |
| ${{ steps.commit-info.outputs.files_changed }} | |
| ``` | |
| [View Changes](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |