Skip to content

Credit the contributors #113

Credit the contributors

Credit the contributors #113

Workflow file for this run

name: Credit the contributors
on:
workflow_dispatch: {}
schedule:
- cron: "0 0 1 * *" # Run at midnight on the first of every month
env:
ORGANIZATION_NAME: "CodeWithAloha"
# This is a list of repositories that you want to gather contributors from
# To add a new repository, add a new line with the repository name in quotes
REPOSITORY_NAMES: |
(
"Hawaii-Zoning-Atlas"
"HIERR"
"website"
"uipa"
"froide"
"docs"
"ACLU"
)
jobs:
gather-the-contributors:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
# For every contributor to the 'CodeWithAloha' organization, add them to the contributors.json file
- name: Query for all contributors for all repositories
run: |
echo "{\"contributors\": {" > contributors.json
array=${{env.REPOSITORY_NAMES}}
for item in ${array[@]}
do
echo " \"$item\": " >> contributors.json
contributors=$(curl -s -H "Accept: application/vnd.github+json" https://api.github.com/repos/${{ env.ORGANIZATION_NAME }}/$item/contributors | jq -r '.[] | {username: .login, avatar_url: .avatar_url, url: .html_url }' | jq -s .)
collaborators=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CWA_BOT_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/${{ env.ORGANIZATION_NAME }}/$item/collaborators?per_page=100" | jq -r '.[].login')
echo $contributors > copy_contributors.json
# Filter for only the contributors that are also collaborators
jq -c '.[]' copy_contributors.json | while read i; do
username=$(echo $i | jq -r '.username')
if [[ " ${collaborators[@]} " =~ "${username}" ]]; then
echo $i | jq -c . >> filtered_contributors.json
fi
done
echo $(jq -s . filtered_contributors.json) >> contributors.json
sed -i '$ s/.$//' contributors.json
rm copy_contributors.json
rm filtered_contributors.json
echo " ]," >> contributors.json
done
sed -i '$ s/.$//' contributors.json
echo "}}" >> contributors.json
cat contributors.json
- name: Collect all the contributors from allcontributors files
run: |
repositories=${{env.REPOSITORY_NAMES}}
for repository in ${repositories[@]}
do
echo "Collecting contributors for $repository"
curl -s https://raw.githubusercontent.com/CodeWithAloha/$repository/main/.all-contributorsrc > $repository-contributors.json
cat $repository-contributors.json
if ! jq -e . >/dev/null 2>&1 <<< "$(cat $repository-contributors.json)"; then
echo "No contributors for $repository, or .all-contributorsrc is not valid JSON"
rm $repository-contributors.json
continue
fi
cat $repository-contributors.json | jq -r '.contributors[] | {username: .login, avatar_url: .avatar_url, url: .profile }' | jq -s . > $repository-output.json
echo "Contributors found for $repository"
cat $repository-output.json
jq --argjson newContributors "$(cat $repository-output.json)" \
--arg repo "$repository" \
'.contributors[$repo] |= (. + $newContributors) |
.contributors[$repo] |= unique_by(.username)' \
"contributors.json" > temp.json && mv temp.json "contributors.json"
rm $repository-contributors.json
rm $repository-output.json
done
cat contributors.json
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- run: npm ci
- run: npm run lint
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: "[bot] Update contributors.json"
title: "[bot] Update contributors.json"
branch: "update-contributors-json-bot"