diff --git a/.github/scripts/contributors_generator.py b/.github/scripts/contributors_generator.py new file mode 100644 index 000000000..9437fdc5a --- /dev/null +++ b/.github/scripts/contributors_generator.py @@ -0,0 +1,73 @@ +"""Simple Contributors Html table generator""" +import os +import json +import requests + +GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN") +AUTH_HEADER = {'Authorization': f'Bearer {GITHUB_TOKEN}'} + +def get_github_user_name(api_url: str, default_name: str): + """ + Using api url to get and retrun user name + """ + + response = requests.get(api_url, headers=AUTH_HEADER, timeout=6) + + if response.status_code == 200: + json_data = json.loads(response.content) + return json_data["name"] if json_data["name"] is not None else default_name + else: + print("ERROR, not successful to get user data") + +def get_contributors_list(): + """ + Using GitHub contributors api to get list, and return needs info list + """ + response = requests.get("https://api.github.com/repos/xMikux/ModsTranslationPack/contributors?per_page=100", headers=AUTH_HEADER, timeout=6) + contributor_list = [] + + if response.status_code == 200: + json_data = json.loads(response.content) + + for data in json_data: + if "[bot]" not in data["login"]: + user_name = get_github_user_name(data["url"], data["login"]) + html_url = data["html_url"] + avatar_url = data["avatar_url"] + + user_info = { + "user_name": user_name, + "html_url": html_url, + "avatar_url": avatar_url + } + + contributor_list.append(user_info) + + return contributor_list + +def generate_html_list(user_list: dict): + """ + Generate contributor html table list + """ + + html_table = "\n \n" + + for i, user in enumerate(user_list, 1): + html_table += ' \n' + + if i % 7 == 0 and i != len(user_list): + html_table += " \n \n" + + html_table += " \n
\n' + html_table += f' \n' + html_table += f' {user[\n' + html_table += f'
{user["user_name"]}\n' + html_table += '
\n' + html_table += '
" + + return html_table + +if __name__ == "__main__": + api_list = get_contributors_list() + html_list = generate_html_list(api_list) + print(html_list) diff --git a/.github/workflows/CI-Contributors.yml b/.github/workflows/CI-Contributors.yml index 9082d0f2f..9da6c75a5 100644 --- a/.github/workflows/CI-Contributors.yml +++ b/.github/workflows/CI-Contributors.yml @@ -20,12 +20,26 @@ jobs: - name: Checking Repository uses: actions/checkout@v4 - - name: Generate Contributors Images - uses: jaywcjlove/github-action-contributors@main - id: contributors - with: - filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\]) - avatarSize: 100 + - name: Generate Contributors Html Table + id: html_list + run: | + list_html=$(cat <<-EOF + python .github/scripts/contributors_generator.py + EOF + ) + { + echo 'html_table<> "$GITHUB_OUTPUT" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Print Html Table + run: | + cat << EOF + ${{ steps.html_list.outputs.html_table }} + EOF - name: Update Readme run: | @@ -35,7 +49,7 @@ jobs: MULTILINE_MODE: true START_TAG: "" END_TAG: "" - CONTENT: "${{steps.contributors.outputs.htmlTable}}" + CONTENT: "${{ steps.html_list.outputs.html_table }}" - name: Create Pull Request uses: peter-evans/create-pull-request@v5