diff --git a/action/main.py b/action/main.py index e5a6fd1..5fc7421 100644 --- a/action/main.py +++ b/action/main.py @@ -253,6 +253,7 @@ def process_release_body(release_body: str) -> str: """ # replace contributor mentions with GitHub profile processed_body = '' + contributors = {} re_username = re.compile(r'@([a-zA-Z\d\-]{0,38})') re_pr_url = re.compile(r'(https://github\.com/([a-zA-Z\d\-]{0,38})/([a-zA-Z\d-]+)/pull/(\d+))') for line in io.StringIO(release_body).readlines(): @@ -267,14 +268,24 @@ def process_release_body(release_body: str) -> str: username = username_search.group(1) update_pr_url = False - username_url = f'[@{username}](https://github.com/{username})' + username_url = f'https://github.com/{username}' + username_url_md = f'[@{username}]({username_url})' + + if username in contributors: + contributors[username]['contributions'] += 1 + else: + contributors[username] = { + 'contributions': 1, + 'url': username_url, + } + if ' by @' in line: # replace the mention with a GitHub profile URL - line = line.replace(f' by @{username}', f' by {username_url}') + line = line.replace(f' by @{username}', f' by {username_url_md}') update_pr_url = True if '* @' in line: # replace the mention with a GitHub profile URL - line = line.replace(f'* @{username}', f'* {username_url}') + line = line.replace(f'* @{username}', f'* {username_url_md}') update_pr_url = True if update_pr_url: pr_search = re_pr_url.search(line) @@ -290,6 +301,32 @@ def process_release_body(release_body: str) -> str: processed_body += line + # add contributors to the release notes + if contributors: + # sort contributors by contributions count + contributors = dict(sorted(contributors.items(), key=lambda item: (-item[1]['contributions'], item[0]))) + + processed_body += '\n---\n' + processed_body += '## Contributors\n' + for contributor, details in contributors.items(): + # add the contributor's avatar + # use tag to ensure the image is the correct size of 50x50 + # unchanged avatars cannot use the size query + processed_body += ( + f'' + f' 1 else "merge"}" ' + '>') + processed_body += '\n' + return processed_body diff --git a/tests/data/expected_release_notes_sample_0.md b/tests/data/expected_release_notes_sample_0.md index 0e3d9ac..2dc9d7f 100644 --- a/tests/data/expected_release_notes_sample_0.md +++ b/tests/data/expected_release_notes_sample_0.md @@ -148,3 +148,7 @@ * [@cfalas](https://github.com/cfalas) made their first contribution in [#2841](https://github.com/LizardByte/Sunshine/pull/2841) **Full Changelog**: https://github.com/LizardByte/Sunshine/compare/v0.23.1...2024.713.195308 + +--- +## Contributors +ReenigneArcherdependabotHazerLizardByte-botgschintgenTimmyOVOtez011BeeLeDevc3m3gyaneshcathyjfcfalascgarstcgutmanchewihgaiserns6089skryvelxanderfrangosABeltramomariotaku diff --git a/tests/data/expected_release_notes_sample_1.md b/tests/data/expected_release_notes_sample_1.md index 7103c3c..19490c3 100644 --- a/tests/data/expected_release_notes_sample_1.md +++ b/tests/data/expected_release_notes_sample_1.md @@ -4,3 +4,7 @@ ## New Contributors * [@LizardByte](https://github.com/LizardByte) made their first contribution + +--- +## Contributors +LizardBytedependabot