@@ -25,45 +25,48 @@ jobs:
2525          echo "{}" > contributors.json 
2626          commit_count=0 
2727          # Switch to dev branch 
28-           git checkout dev 
28+           git checkout dev || { echo "Failed to checkout dev branch"; exit 1; }  
2929          # Get all commits in dev branch 
30-           commits=$(git log --pretty=format:%H) 
31-           echo "Total commits to process: $(echo "$commits" | wc -l)" 
30+           commits=$(git log --pretty=format:%H || { echo "Failed to run git log"; exit 1; }) 
31+           total_commits=$(echo "$commits" | wc -l | tr -d ' ') 
32+           echo "Total commits to process: $total_commits" 
3233          for commit in $commits; do 
3334            ((commit_count++)) 
34-             echo "Processing commit $commit ($commit_count)" 
35-             author_name=$(git show -s --format=%an $commit) 
35+             echo "Processing commit $commit ($commit_count/$total_commits )" 
36+             author_name=$(git show -s --format=%an " $commit" 2>/dev/null || echo "" ) 
3637            if [ -z "$author_name" ]; then 
3738              echo "Skipping commit $commit with no author name" 
3839              continue 
3940            fi 
40-             # Map author name to GitHub username using author_to_github.json 
41-             login=$(jq -r --arg name "$author_name" '.[$name] // $name' author_to_github.json) 
42-             if [ "$login" = "$author_name" ]; then 
43-               echo "Warning: No GitHub username mapping for author '$author_name' in commit $commit" 
44-             else 
45-               echo "Mapped author '$author_name' to GitHub username '$login'" 
41+             # Use author name as GitHub username, sanitize for URL 
42+             login=$(echo "$author_name" | tr -s ' ' '-' | tr -dc '[:alnum:]-') 
43+             if echo "$author_name" | grep -q ' '; then 
44+               echo "Warning: Author '$author_name' may not be a valid GitHub username (contains spaces, sanitized to '$login')" 
4645            fi 
47-             stats=$(git show --shortstat --format= $commit | grep -E '[0-9]+ file(s)? changed' | awk '{add=$4; del=$6} END {print (add ? add : 0) - (del ? del : 0)}') 
46+             echo "Processing commit $commit by $login" 
47+             # Get commit stats 
48+             stats=$(git show --shortstat --format= "$commit" 2>/dev/null | grep -E '[0-9]+ file(s)? changed' | awk '{add=$4; del=$6} END {print (add ? add : 0) - (del ? del : 0)}' || echo "0") 
4849            net_lines=${stats:-0} 
4950            echo "Commit $commit by $login: $net_lines net lines" 
5051            # Update JSON with contributor stats 
5152            jq --arg login "$login" --arg net_lines "$net_lines" \ 
5253               '.[$login] |= (. // {netLines: 0, commits: 0, login: $login} | .netLines += ($net_lines | tonumber) | .commits += 1)' \ 
53-                contributors.json > tmp.json && mv tmp.json contributors.json 
54+                contributors.json > tmp.json 2>/dev/null || { echo "Error: jq failed to update stats for $login in commit $commit"; exit 1; } 
55+             mv tmp.json contributors.json || { echo "Error: Failed to move tmp.json"; exit 1; } 
5456          done 
5557          echo "Total commits processed: $commit_count" 
5658          # Format table 
57-           table=$(jq -r 'to_entries | sort_by(.value.netLines) | reverse | .[] | select(.value.netLines > 0 or .value.commits > 0) | "| [\(.key)](https://github.com/\(.key)) | \(.value.netLines) | \(.value.commits) |"' contributors.json) 
59+           table=$(jq -r 'to_entries | sort_by(.value.netLines) | reverse | .[] | select(.value.netLines > 0 or .value.commits > 0) | "| [\(.key)](https://github.com/\(.key)) | \(.value.netLines) | \(.value.commits) |"' contributors.json 2>/dev/null || { echo "Error: jq failed to format table"; exit 1; } ) 
5860          if [ -z "$table" ]; then 
5961            table="No contributors with commits or net lines added." 
62+             echo "Warning: No valid contributors found" 
6063          else 
6164            table="| Contributor | Net Lines Added | Commits |\n|-------------|-----------------|---------|\n$table" 
6265          fi 
63-           echo "Total contributors: $(jq 'length' contributors.json)" 
66+           echo "Total contributors: $(jq 'length' contributors.json 2>/dev/null || echo "Error: jq failed to count contributors" )" 
6467          echo "Generated table:" 
6568          echo "$table" 
66-           echo "$table" > contributors.txt 
69+           echo "$table" > contributors.txt || { echo "Error: Failed to write contributors.txt"; exit 1; }  
6770shell : bash 
6871
6972      - name : Update README 
0 commit comments