Skip to content

Commit

Permalink
Create main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
donggook-me authored Nov 17, 2023
1 parent ebf3c50 commit 56509d1
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Fetch Commit History

on:
push:
branches:
- master
workflow_dispatch:

jobs:
fetch-commit-history:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Get members of "gdsc" organization
id: get-members
run: |
#dummy data testing
echo "GDSC_MEMBERS=donggook-me handsomem1n ChangHoon-Sung" >> $GITHUB_ENV
- name: Fetch commit history for each member
id: fetch-commit-history
run: |
set -x
# Access the environment variable and split it into an array
members=($GDSC_MEMBERS)
all_commits=()
for member in "${members[@]}"; do
echo "Fetching commit history for $member..."
member_commits=$(curl -sSL -H "Authorization: Bearer ${{ secrets.GDSC_GH_TOKEN }}" "https://api.github.com/users/${member}/events")
if [[ $(echo "$member_commits" | jq length) -gt 0 ]]; then
# Extracting commit-related data (commit ID, name, time, message, link)
commits_data=$(echo "$member_commits" | jq -r 'map(select(.type == "PushEvent")) | .[].payload.commits[] | {commitId: .sha, userName: .author.name, commitTime: .timestamp, commitMessage: .message, commitLink: .url }')

# Append the commit data to the member's entry in all_commits
all_commits+=("$member: $commits_data")
else
echo "No new commit data for $member."
fi
done

if [[ ${#all_commits[@]} -gt 0 ]]; then
# Save the commits data to data.json
mkdir -p data
echo "{ ${all_commits[@]} }" > data/data.json
else
echo "No new commit data for any member." > data/empty_commit_data.txt
fi

- name: Commit and push fetched data to repository
run: |
cd $GITHUB_WORKSPACE
git config user.email "[email protected]"
git config user.name "GitHub Actions"
if [[ -n $(git status --porcelain) ]]; then
git add data
git commit -m "Update commit data"
git push origin main
fi

0 comments on commit 56509d1

Please sign in to comment.