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'
+ html_table += f' \n'
+ html_table += f' \n'
+ html_table += f' {user["user_name"]}\n' + html_table += ' \n' + html_table += ' | \n'
+
+ if i % 7 == 0 and i != len(user_list):
+ html_table += "