Merge pull request #27 from MikePfunk28/012-visual-builder-update #9
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: Setup GitHub Project Automations | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 0 * * 0" # Every Sunday at midnight UTC | |
| issues: | |
| types: [opened, reopened] | |
| pull_request: | |
| types: [opened, reopened] | |
| workflow_dispatch: | |
| jobs: | |
| setup-project: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Backfill existing open issues | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PROJECT_ID: "4" | |
| run: | | |
| REPO="${{ github.repository }}" | |
| # Fetch all open issues via paginated API | |
| failures=0 | |
| issues_json=$(gh api --paginate "repos/$REPO/issues?state=open&per_page=100" --jq '.[].number' 2>&1) | |
| rc=$? | |
| if [ $rc -ne 0 ]; then | |
| echo "Error listing issues for $REPO: $issues_json" >&2 | |
| exit $rc | |
| fi | |
| while read -r issue_num; do | |
| [ -z "$issue_num" ] && continue | |
| ISSUE_URL="https://github.com/$REPO/issues/$issue_num" | |
| err=$(gh project item-add "$PROJECT_ID" --owner MikePfunk28 --url "$ISSUE_URL" 2>&1) || { | |
| echo "Error adding issue $issue_num to project $PROJECT_ID: $err" >&2 | |
| failures=$((failures+1)) | |
| } | |
| done <<< "$issues_json" | |
| if [ "$failures" -gt 0 ]; then | |
| echo "Summary: $failures issue(s) failed to add to project $PROJECT_ID" >&2 | |
| fi | |
| - name: Add new issues/PRs to project | |
| if: github.event_name == 'issues' || github.event_name == 'pull_request' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PROJECT_ID: "4" | |
| run: | | |
| REPO="${{ github.repository }}" | |
| if [ "${{ github.event_name }}" = "issues" ]; then | |
| ISSUE_URL="https://github.com/${REPO}/issues/${{ github.event.issue.number }}" | |
| out=$(gh project item-add "$PROJECT_ID" --owner MikePfunk28 --url "$ISSUE_URL" 2>&1) || { echo "Error adding issue $ISSUE_URL to project: $out" >&2; exit 1; } | |
| elif [ "${{ github.event_name }}" = "pull_request" ]; then | |
| URL="https://github.com/${REPO}/pull/${{ github.event.pull_request.number }}" | |
| out=$(gh project item-add "$PROJECT_ID" --owner MikePfunk28 --url "$URL" 2>&1) || { echo "Error adding PR $URL to project: $out" >&2; exit 1; } | |
| else | |
| echo "Unsupported event: ${{ github.event_name }}" >&2 | |
| exit 1 | |
| fi |