@@ -34,18 +34,100 @@ jobs:
3434 END { print notes; }
3535 ' CHANGELOG.md)
3636
37- # Get recent commits since last tag
37+ # Get recent commits since last tag with GitHub usernames
3838 PREVIOUS_TAG=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "")
39+
40+ # Function to get GitHub username from email
41+ get_github_username() {
42+ local email="$1"
43+ local commit_hash="$2"
44+
45+ # First try to extract username from GitHub noreply email
46+ if [[ "$email" =~ ([0-9]+\+)?([^@]+)@users\.noreply\.github\.com ]]; then
47+ echo "${BASH_REMATCH[2]}"
48+ return
49+ fi
50+
51+ # Try to get GitHub username via API using commit hash
52+ local github_user=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
53+ "https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$commit_hash" | \
54+ jq -r '.author.login // empty' 2>/dev/null)
55+
56+ if [ -n "$github_user" ] && [ "$github_user" != "null" ]; then
57+ echo "$github_user"
58+ return
59+ fi
60+
61+ # Fallback: try to get user by email via API
62+ local api_user=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
63+ "https://api.github.com/search/users?q=$email+in:email" | \
64+ jq -r '.items[0].login // empty' 2>/dev/null)
65+
66+ if [ -n "$api_user" ] && [ "$api_user" != "null" ]; then
67+ echo "$api_user"
68+ else
69+ # Final fallback: use the part before @ in email
70+ echo "${email%%@*}"
71+ fi
72+ }
73+
74+ # Get ALL conventional commits, excluding merge commits to avoid duplicates
3975 if [ -z "$PREVIOUS_TAG" ]; then
40- # If no previous tag exists, get all commits
41- COMMITS=$(git log --pretty=format:" - %s" | grep -E "^ - (feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)" || echo "")
76+ COMMIT_DATA=$(git log --pretty=format:"%H|%ae|%s" --no-merges --grep="^\(feat\|fix\|docs\|style\|refactor\|perf\|test\|build\|ci\|chore\|revert\)")
4277 else
43- # Get commits between previous tag and HEAD
44- COMMITS=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:" - %s" | grep -E "^ - (feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)" || echo "")
78+ COMMIT_DATA=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"%H|%ae|%s" --no-merges --grep="^\(feat\|fix\|docs\|style\|refactor\|perf\|test\|build\|ci\|chore\|revert\)")
79+ fi
80+
81+ # Initialize categorized commit arrays
82+ FEATURES=""
83+ BUGFIXES=""
84+ OTHER_COMMITS=""
85+
86+ # Process ALL matching commits and categorize them
87+ while IFS='|' read -r hash email subject; do
88+ [ -z "$hash" ] && continue
89+
90+ # Get full commit message for PR detection
91+ message=$(git show -s --format=%B $hash)
92+
93+ # Extract username
94+ username=$(get_github_username "$email" "$hash")
95+
96+ # Check for ANY PR reference (#number)
97+ if [[ "$message" =~ \#([0-9]+) ]]; then
98+ pr_num=" (#${BASH_REMATCH[1]})"
99+ else
100+ pr_num=""
101+ fi
102+
103+ # Categorize based on conventional commit type
104+ if [[ "$subject" =~ ^feat(\(.+\))?:* ]]; then
105+ FEATURES="${FEATURES} - ${subject}${pr_num} (@$username)\n"
106+ elif [[ "$subject" =~ ^fix(\(.+\))?:* ]]; then
107+ BUGFIXES="${BUGFIXES} - ${subject}${pr_num} (@$username)\n"
108+ else
109+ OTHER_COMMITS="${OTHER_COMMITS} - ${subject}${pr_num} (@$username)\n"
110+ fi
111+ done <<< "$COMMIT_DATA"
112+
113+ # Build categorized commits section
114+ COMMITS=""
115+ if [ -n "$FEATURES" ]; then
116+ COMMITS="${COMMITS}#### 🚀 Features\n${FEATURES}\n"
117+ fi
118+ if [ -n "$BUGFIXES" ]; then
119+ COMMITS="${COMMITS}#### 🐛 Bug Fixes\n${BUGFIXES}\n"
120+ fi
121+ if [ -n "$OTHER_COMMITS" ]; then
122+ COMMITS="${COMMITS}#### 📝 Other Commits\n${OTHER_COMMITS}\n"
45123 fi
46124
47- # Combine CHANGELOG notes with commit messages
48- FULL_NOTES="${NOTES}\n\n### Commits\n${COMMITS}"
125+ # Combine CHANGELOG notes with categorized commit messages
126+ if [ -n "$COMMITS" ]; then
127+ FULL_NOTES="${NOTES}\n\n### Commits\n${COMMITS}"
128+ else
129+ FULL_NOTES="${NOTES}"
130+ fi
49131
50132 # Save notes to output with correct GitHub multiline syntax
51133 EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
@@ -72,10 +154,6 @@ jobs:
72154 env :
73155 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
74156
75- - name : Create zip archive
76- if : steps.check_release.outputs.exists == 'false'
77- run : zip -r my-unicorn-${{ steps.changelog.outputs.version }}.zip ./ -x "*.git*" ".github/*"
78-
79157 - name : Create GitHub Release
80158 if : steps.check_release.outputs.exists == 'false'
81159 uses : softprops/action-gh-release@v1
85163 body : ${{ steps.changelog.outputs.notes }}
86164 draft : false
87165 prerelease : ${{ contains(steps.changelog.outputs.version, '-') }}
88- files : my-unicorn-${{ steps.changelog.outputs.version }}.zip
89166 env :
90167 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments