Skip to content

Update internal-contributor-of-the-month.yaml #31

Update internal-contributor-of-the-month.yaml

Update internal-contributor-of-the-month.yaml #31

name: Internal Contributor of the Month
on:
push:
branches:
- 'contributor-workflow'
jobs:
determine-internal-contributor:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Determine contributor
id: determine
run: |
# Set the start and end dates for June 2023
START_DATE="2023-07-01"
END_DATE="2023-07-31"
MONTH_NAME="June"
# Exclude certain users
EXCLUDED_USERS=("VadymSachenko" "lenadoc" "andriitserkovnyi" "AlexSlawinski") # Add the usernames to be excluded here
# Count PRs for each user
declare -A PR_COUNTS=()
PAGE=1
while : ; do
# Fetch merged pull requests within the specified date range
PRS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/spryker/spryker-docs/pulls?state=closed&base=master&sort=created&direction=desc&merge_state=merged&page=$PAGE&per_page=100" \
| jq -r --arg START "$START_DATE" --arg END "$END_DATE" 'map(select(.merged_at >= $START and .merged_at <= $END)) | .[].user.login')
if [ -z "$PRS" ]; then
break
fi
for USER in $PRS; do
if [[ ! " ${EXCLUDED_USERS[@]} " =~ " ${USER} " ]]; then
PR_COUNTS[$USER]=$((PR_COUNTS[$USER]+1))
fi
done
((PAGE++))
done
# Determine the top contributor
MAX_COUNT=0
TOP_CONTRIBUTORS=()
for USER in "${!PR_COUNTS[@]}"; do
COUNT=${PR_COUNTS[$USER]}
if (( COUNT > MAX_COUNT )); then
MAX_COUNT=$COUNT
TOP_CONTRIBUTORS=($USER)
elif (( COUNT == MAX_COUNT )); then
TOP_CONTRIBUTORS+=($USER)
fi
done
TOP_CONTRIBUTORS_LIST=$(IFS=,; echo "${TOP_CONTRIBUTORS[*]}")
TOP_CONTRIBUTORS_TEXT="The top contributor(s) of $MONTH_NAME: $TOP_CONTRIBUTORS_LIST (PRs: $MAX_COUNT)"
echo "TOP_CONTRIBUTORS_TEXT=$TOP_CONTRIBUTORS_TEXT" >> $GITHUB_ENV
# Prepare contributors list sorted by PR count in descending order
CONTRIBUTORS=""
for USER in $(for k in "${!PR_COUNTS[@]}"; do echo $k ${PR_COUNTS[$k]}; done | sort -rn -k2 | cut -d' ' -f1); do
COUNT="${PR_COUNTS[$USER]}"
CONTRIBUTORS+="- $USER (PRs: $COUNT)\n"
done
echo "CONTRIBUTORS=${CONTRIBUTORS}" >> $GITHUB_ENV
echo "MONTH_NAME=${MONTH_NAME}" >> $GITHUB_ENV
- name: Log contributors
run: |
CONTRIBUTORS="${{ env.CONTRIBUTORS }}"
MONTH_NAME="${{ env.MONTH_NAME }}"
TOP_CONTRIBUTORS_TEXT="${{ env.TOP_CONTRIBUTORS_TEXT }}"
# Print all contributors of the month and the number of PRs they created
echo "Contributors of $MONTH_NAME:"
echo -e "$CONTRIBUTORS"
# Print the top contributor(s) of the month
echo "$TOP_CONTRIBUTORS_TEXT"