-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-github-projects_Version3.yml
More file actions
68 lines (60 loc) · 2.43 KB
/
setup-github-projects_Version3.yml
File metadata and controls
68 lines (60 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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