-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathmaintain-contribution-issues.yml
More file actions
151 lines (125 loc) · 5.15 KB
/
maintain-contribution-issues.yml
File metadata and controls
151 lines (125 loc) · 5.15 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Maintain Contribution Issues
on:
issues:
types: [closed]
schedule:
# Run daily at 00:00 UTC to ensure we always have 3 open issues
- cron: "0 0 * * *"
workflow_dispatch:
permissions:
issues: write
jobs:
maintain-issues:
# Only run in the main repository, not in forks
if: github.repository == 'SashankBhamidi/git-gang'
runs-on: ubuntu-latest
steps:
- name: Check contribution issue count
id: check
run: |
set -euo pipefail
# Count open issues with "contribution" label (with retry)
MAX_RETRIES=3
RETRY_COUNT=0
OPEN_COUNT=""
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if OPEN_COUNT=$(gh issue list --repo ${{ github.repository }} --label contribution --state open --json number --jq 'length' 2>/dev/null); then
break
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
echo "Retry $RETRY_COUNT/$MAX_RETRIES: Waiting 2s..."
sleep 2
fi
done
if [ -z "$OPEN_COUNT" ]; then
echo "Error: Could not fetch issue count after $MAX_RETRIES attempts"
echo "need_to_create=0" >> $GITHUB_OUTPUT
exit 1
fi
echo "Found $OPEN_COUNT open contribution issues"
# Calculate how many we need to create
TARGET=7
NEEDED=$((TARGET - OPEN_COUNT))
if [ $NEEDED -gt 0 ]; then
echo "need_to_create=$NEEDED" >> $GITHUB_OUTPUT
echo "Need to create $NEEDED more issue(s) to maintain $TARGET open issues"
else
echo "need_to_create=0" >> $GITHUB_OUTPUT
echo "Already have $TARGET or more open issues"
fi
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
- name: Create contribution issues
if: steps.check.outputs.need_to_create > 0
run: |
set -euo pipefail
NEEDED=${{ steps.check.outputs.need_to_create }}
CURRENT_MONTH=$(date +%m)
# Determine labels based on month
if [ "$CURRENT_MONTH" = "10" ]; then
echo "October detected - adding Hacktoberfest label"
LABELS="good first issue,help wanted,contribution,hacktoberfest"
else
LABELS="good first issue,help wanted,contribution"
fi
# Split labels for gh api
IFS=',' read -ra LABEL_ARRAY <<< "$LABELS"
# Create issue body file
cat > /tmp/issue-body.txt << 'EOFBODY'
Add your name to the contributors list.
**Note:** No need to ask for assignment - the automation system will auto-assign you an issue within the PR. Just follow the steps below!
## How to contribute
1. **Star this repository** (helps us reach more contributors!)
2. Open [ADD_YOUR_NAME.md](https://github.com/SashankBhamidi/git-gang/blob/master/ADD_YOUR_NAME.md)
3. Click the edit icon
4. Fill out:
- Name: Your Name
- Username: your-github-username
- Message: Optional message
5. Open a pull request
6. Automation validates and merges automatically
See [README](https://github.com/SashankBhamidi/git-gang/blob/master/README.md) for details.
EOFBODY
# Create the needed number of issues
CREATED_COUNT=0
FAILED_COUNT=0
for i in $(seq 1 $NEEDED); do
echo "Creating contribution issue $i of $NEEDED..."
# Create issue with retry logic
MAX_RETRIES=3
RETRY_COUNT=0
ISSUE_CREATED=false
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if gh api repos/${{ github.repository }}/issues -X POST \
-f title="Add your name to Git Gang" \
-F body=@/tmp/issue-body.txt \
-f "labels[]=${LABEL_ARRAY[0]}" \
-f "labels[]=${LABEL_ARRAY[1]}" \
-f "labels[]=${LABEL_ARRAY[2]}" \
$([ "${LABEL_ARRAY[3]}" ] && echo "-f labels[]=${LABEL_ARRAY[3]}" || echo "") 2>/dev/null; then
echo "✓ Created issue $i"
ISSUE_CREATED=true
CREATED_COUNT=$((CREATED_COUNT + 1))
break
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
echo "Retry $RETRY_COUNT/$MAX_RETRIES: Waiting 2s..."
sleep 2
else
echo "⚠ Failed to create issue $i after $MAX_RETRIES attempts"
FAILED_COUNT=$((FAILED_COUNT + 1))
fi
done
# Add 1-second delay between creations to prevent hitting GitHub API rate limits
if [ $i -lt $NEEDED ]; then
sleep 1
fi
done
echo "✅ Created $CREATED_COUNT/$NEEDED issues"
if [ $FAILED_COUNT -gt 0 ]; then
echo "⚠ Warning: $FAILED_COUNT issue(s) failed to create"
fi
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}