Skip to content

Commit

Permalink
Number of commits more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
MSt-10 authored Jun 25, 2024
1 parent a957fd5 commit 99eee8a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ runs:
OWNER=$(echo $REPO_PATH | cut -d'/' -f1)
REPO_NAME=$(echo $REPO_PATH | cut -d'/' -f2 | sed 's/\.git$//')
API_URL="https://api.github.com/repos/$OWNER/$REPO_NAME"
# Get the number of commits using GitHub API and pagination info
NUM_COMMITS=$(curl -s -I "${API_URL}/commits?per_page=1" | grep -i 'link:' | sed -E 's/.*page=([0-9]+)>; rel="last".*/\1/')
NUM_STARS=$(curl -s $API_URL | jq '.stargazers_count // 0')
NUM_CONTRIBUTORS=$(curl -s -I "${API_URL}/contributors?per_page=1" | grep -i 'link:' | sed -E 's/.*page=([0-9]+)>; rel="last".*/\1/')
# Get number of commits, handle the case where pagination info might not be present (less than 30 commits)
COMMITS_LINK_HEADER=$(curl -s -I "${API_URL}/commits?per_page=1" | grep -i 'link:')
if [ -z "$COMMITS_LINK_HEADER" ]; then
NUM_COMMITS=$(curl -s "${API_URL}/commits" | jq 'length')
else
NUM_COMMITS=$(echo "$COMMITS_LINK_HEADER" | sed -E 's/.*page=([0-9]+)>; rel="last".*/\1/' || echo "1")
fi
# Get number of contributors, handle the case where pagination info might not be present (less than 30 contributors)
CONTRIBUTORS_LINK_HEADER=$(curl -s -I "${API_URL}/contributors?per_page=1" | grep -i 'link:')
if [ -z "$CONTRIBUTORS_LINK_HEADER" ]; then
Expand Down

0 comments on commit 99eee8a

Please sign in to comment.