Skip to content

Commit

Permalink
Fetch avatar by contributor name ()
Browse files Browse the repository at this point in the history
Fetch avatar by contributor name
  • Loading branch information
NBprojekt authored Sep 12, 2022
2 parents 8643090 + 739a34d commit 5d0b2e1
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 52 deletions.
115 changes: 71 additions & 44 deletions .github/workflows/gource-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,93 @@ on:
- 'dev/**'

jobs:
local-images:
runs-on: ubuntu-latest
# local-images:
# runs-on: ubuntu-latest

steps:
- name: 'Checkout'
uses: actions/checkout@v2
with:
fetch-depth: 0
# steps:
# - name: 'Checkout'
# uses: actions/checkout@v2
# with:
# fetch-depth: 0

- name: 'Current folder'
run: ls -al
# - name: 'Current folder'
# run: ls -al

- name: 'Gource Action'
uses: ./
with:
git_url: ./
avatars_url: ./avatars/
gource_title: 'Gource Action Development'
logo_url: ./logo.png
avatars_auto_fetch: true
# - name: 'Gource Action'
# uses: ./
# with:
# git_url: ./
# avatars_url: ./avatars/
# gource_title: 'Gource Action Development'
# logo_url: ./logo.png
# avatars_auto_fetch: true

- name: 'Check output'
run: |
ls -al ./
ls -al ./gource
# - name: 'Check output'
# run: |
# ls -al ./
# ls -al ./gource

- uses: actions/upload-artifact@v2
with:
name: gource-local
path: ./gource
retention-days: 1
# - uses: actions/upload-artifact@v2
# with:
# name: gource-local
# path: ./gource
# retention-days: 1

test-new-url-regex:
runs-on: ubuntu-latest
# test-new-url-regex:
# runs-on: ubuntu-latest

# steps:
# - name: 'Checkout'
# uses: actions/checkout@v2
# with:
# fetch-depth: 0

# - name: 'Current folder'
# run: ls -al

# - name: 'Gource Action'
# uses: ./
# with:
# git_url: ./
# avatars_url: ./avatars/
# gource_title: 'Gource Action Development'
# logo_url: https://raw.githubusercontent.com/glotaran/pyglotaran/main/docs/source/images/glotaran.png?raw=true
# avatars_auto_fetch: true

# - name: 'Check output'
# run: |
# ls -al ./
# ls -al ./gource

# - uses: actions/upload-artifact@v2
# with:
# name: gource-local
# path: ./gource
# retention-days: 1

avatar-issues:
runs-on: ubuntu-latest

steps:
- name: 'Checkout'
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: 'Current folder'
run: ls -al

- name: 'Gource Action'
uses: ./
with:
git_url: ./
avatars_url: ./avatars/
gource_title: 'Gource Action Development'
logo_url: https://raw.githubusercontent.com/glotaran/pyglotaran/main/docs/source/images/glotaran.png?raw=true
avatars_auto_fetch: true
git_url: 'https://github.com/Ismoh/NoitaMP'
gource_title: 'NoitaMP Gource master'
gource_resolution: '1080p'
gource_fps: 60
gource_font_size: 40
gource_auto_skip_seconds: 0.1
gource_seconds_per_day: 0.1

- name: 'Check output'
run: |
ls -al ./
ls -al ./gource
- uses: actions/upload-artifact@v2
- name: 'Upload gource video'
uses: actions/upload-artifact@v2
with:
name: gource-local
path: ./gource
retention-days: 1
name: Gource
path: ./gource/gource.mp4
33 changes: 25 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,43 @@ else
fi

# Auto fetch contributor avatars
printf "\n>\n> Auto fetch contributor avatars"
printf "\n>\n> Auto fetch contributor avatars: ${INPUT_AVATARS_AUTO_FETCH}"
if [ "${INPUT_AVATARS_AUTO_FETCH}" == "true" ]; then
printf "\n> \tFetching all contributors\n"
contributorCount=0
avatarsCount=0

while IFS='|' read -ra author; do
((contributorCount=contributorCount+1))
name=${author[0]}
name="${name#"${name%%[![:space:]]*}"}"
name="${name#"${name%%[![:space:]]*}"}" # This hack removes leating and trailing spaces
name="${name%"${name##*[![:space:]]}"}"
email=${author[1]}
# This hack removes leating and trailing spaces
email="${email#"${email%%[![:space:]]*}"}"
email="${email%"${email##*[![:space:]]}"}"

# Use github api to get avatar url using the author email
avatar=$(wget -O - -o /dev/null https://api.github.com/search/users?q=$email | jq -r '.items[0].avatar_url')
if [ "$avatar" != "null" ]; then
printf "\n> \t\tDownloading avatar for $name from: $avatar"
wget -O "/gource/avatars/$name.png" $avatar >/dev/null 2>&1

# Use github api to get avatar url using the author name or email
avatar_by_name=$(wget -O - -o /dev/null https://api.github.com/users/$name | jq -r '.avatar_url')

if ([ "$avatar_by_name" != "null" ] && [ ! -z "$avatar_by_name" ]); then
printf "\n> \t\tDownloading avatar for $name from: $avatar_by_name"
wget -O "/gource/avatars/$name.png" $avatar_by_name >/dev/null 2>&1
((avatarsCount=avatarsCount+1))
continue
fi

avatar_by_email=$(wget -O - -o /dev/null https://api.github.com/search/users?q=$email | jq -r '.items[0].avatar_url')
if ([ "$avatar_by_email" != "null" ] && [ ! -z "$avatar_by_name" ]); then
printf "\n> \t\tDownloading avatar for $email from: $avatar_by_email"
wget -O "/gource/avatars/$name.png" $avatar_by_email >/dev/null 2>&1
((avatarsCount=avatarsCount+1))
continue
fi
done <<< "$(git --git-dir /gource/git_repo/.git log --pretty="%aN | %aE" | sort | uniq)";

printf "\n>\n> \tFound $contributorCount contibutors"
printf "\n> \tSuccessfully fetched $avatarsCount avatars"
else
printf "\n> \tAuto fetch is disabled, fall back to avatars directory\n"

Expand Down

0 comments on commit 5d0b2e1

Please sign in to comment.