-
Notifications
You must be signed in to change notification settings - Fork 12
168 lines (151 loc) · 6.11 KB
/
Copy pathhacktoberfest.yml
File metadata and controls
168 lines (151 loc) · 6.11 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Hacktoberfest Setup
on:
workflow_dispatch:
jobs:
sync-labels:
name: Sync repository labels
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Sync labels
uses: EndBug/label-sync@v2
with:
config-file: .github/labels.yml
token: ${{ secrets.GITHUB_TOKEN }}
create-issues:
name: Create Hacktoberfest issues
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Ensure dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y jq
- name: Create issues from combined file
env:
REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
FILE_PATH=".github/hacktoberfest-issues/ALL.md"
if [ ! -f "$FILE_PATH" ]; then
echo "No Hacktoberfest issues file found. Skipping."
exit 0
fi
# Split the ALL.md file into multiple temporary files using a flexible delimiter
i=1
f=$(printf "issue_%03d.md" "$i")
while IFS= read -r line; do
if [[ "$line" == "---" ]]; then
i=$((i+1))
f=$(printf "issue_%03d.md" "$i")
continue
fi
echo "$line" >> "$f"
done < "$FILE_PATH"
# Iterate over split files and create issues
for f in issue_*.md; do
if [ ! -s "$f" ]; then
echo "Skipping empty file $f"
continue
fi
# Skip leading blank lines and extract title from first non-empty line starting with #
title=$(grep -m 1 '^#' "$f" | sed 's/^# \{0,1\}//')
# Get body after the title line, including tasks section for PR description
body=$(sed -n '/^#/,$ p' "$f" | tail -n +2)
# Extract category/type from body or title - priority order matters!
category=""
# Check for specific keywords in title and body to determine category
if grep -qi "test\|testing" "$f"; then
category="testing"
elif grep -qi "performance\|optimization\|optimize" "$f"; then
category="performance"
elif grep -qi "accessibility\|a11y" "$f"; then
category="accessibility"
elif grep -qi "security\|auth" "$f"; then
category="security"
elif grep -qi "documentation\|docs\|tutorial\|guide" "$f"; then
category="documentation"
elif grep -qi "api\|sdk" "$f"; then
category="api"
elif grep -qi "mobile\|ios\|android" "$f"; then
category="mobile"
elif grep -qi "database\|storage\|migration" "$f"; then
category="database"
elif grep -qi "plugin\|marketplace" "$f"; then
category="enhancement"
elif grep -qi "collaboration\|real-time" "$f"; then
category="enhancement"
elif grep -qi "analytics\|dashboard" "$f"; then
category="enhancement"
elif grep -qi "pwa\|offline" "$f"; then
category="enhancement"
elif grep -qi "import\|export\|backup" "$f"; then
category="enhancement"
elif grep -qi "notification" "$f"; then
category="enhancement"
elif grep -qi "social\|community" "$f"; then
category="enhancement"
elif grep -qi "ci/cd\|devops\|deployment" "$f"; then
category="devops"
elif grep -qi "ai\|machine learning" "$f"; then
category="ai"
elif grep -qi "admin\|moderation" "$f"; then
category="enhancement"
elif grep -q "## Bug" "$f"; then
category="bug"
else
# Default to enhancement for feature requests
category="enhancement"
fi
# Determine labels based on content
labels='["hacktoberfest"]'
if grep -q "good first issue" "$f"; then
labels=$(echo "$labels" | jq '. + ["good first issue"]')
fi
if grep -q "help wanted" "$f"; then
labels=$(echo "$labels" | jq '. + ["help wanted"]')
fi
if [ -n "$category" ]; then
labels=$(echo "$labels" | jq --arg cat "$category" '. + [$cat]')
fi
if [ -z "$title" ]; then
echo "File $f missing title. Skipping."
continue
fi
# Check if an issue with this title already exists (open or closed)
echo "Checking for existing issue: $title"
existing_issue=$(curl -sS -H "Authorization: token $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO/issues?state=all&per_page=100" | \
jq --arg title "$title" '.[] | select(.title == $title) | .number' | head -n 1)
if [ -n "$existing_issue" ]; then
echo "⊘ Issue already exists: #$existing_issue - $title (skipping)"
continue
fi
payload=$(jq -n --arg title "$title" --arg body "$body" \
--argjson labels "$labels" \
'{title: $title, body: $body, labels: $labels}')
echo "Creating issue: $title"
response=$(curl -sS -X POST \
-H "Authorization: token $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/$REPO/issues \
-d "$payload")
if echo "$response" | jq -e '.number' > /dev/null 2>&1; then
issue_num=$(echo "$response" | jq -r '.number')
echo "✓ Created issue #$issue_num: $title"
else
echo "✗ Failed to create issue: $title"
echo "Response: $response"
fi
done
echo "Issue creation step completed."