Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(release_notes): add conributors section #117

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)
Expand All @@ -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 <img> tag to ensure the image is the correct size of 50x50
# unchanged avatars cannot use the size query
processed_body += (
f'<a href="{details["url"]}" '
'target="_blank" '
'rel="external noopener noreferrer" '
f'aria-label="GitHub profile of contributor, {contributor}" '
'>'
f'<img src="{details["url"]}.png?size=50" '
'width="50" '
'height="50" '
f'alt="{contributor}" '
f'title="{contributor}: {details["contributions"]} '
f'{"merges" if details["contributions"] > 1 else "merge"}" '
'></a>')
processed_body += '\n'

return processed_body


Expand Down
4 changes: 4 additions & 0 deletions tests/data/expected_release_notes_sample_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<a href="https://github.com/ReenigneArcher" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, ReenigneArcher" ><img src="https://github.com/ReenigneArcher.png?size=50" width="50" height="50" alt="ReenigneArcher" title="ReenigneArcher: 59 merges" ></a><a href="https://github.com/dependabot" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, dependabot" ><img src="https://github.com/dependabot.png?size=50" width="50" height="50" alt="dependabot" title="dependabot: 41 merges" ></a><a href="https://github.com/Hazer" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, Hazer" ><img src="https://github.com/Hazer.png?size=50" width="50" height="50" alt="Hazer" title="Hazer: 6 merges" ></a><a href="https://github.com/LizardByte-bot" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, LizardByte-bot" ><img src="https://github.com/LizardByte-bot.png?size=50" width="50" height="50" alt="LizardByte-bot" title="LizardByte-bot: 5 merges" ></a><a href="https://github.com/gschintgen" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, gschintgen" ><img src="https://github.com/gschintgen.png?size=50" width="50" height="50" alt="gschintgen" title="gschintgen: 4 merges" ></a><a href="https://github.com/TimmyOVO" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, TimmyOVO" ><img src="https://github.com/TimmyOVO.png?size=50" width="50" height="50" alt="TimmyOVO" title="TimmyOVO: 3 merges" ></a><a href="https://github.com/tez011" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, tez011" ><img src="https://github.com/tez011.png?size=50" width="50" height="50" alt="tez011" title="tez011: 3 merges" ></a><a href="https://github.com/BeeLeDev" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, BeeLeDev" ><img src="https://github.com/BeeLeDev.png?size=50" width="50" height="50" alt="BeeLeDev" title="BeeLeDev: 2 merges" ></a><a href="https://github.com/c3m3gyanesh" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, c3m3gyanesh" ><img src="https://github.com/c3m3gyanesh.png?size=50" width="50" height="50" alt="c3m3gyanesh" title="c3m3gyanesh: 2 merges" ></a><a href="https://github.com/cathyjf" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, cathyjf" ><img src="https://github.com/cathyjf.png?size=50" width="50" height="50" alt="cathyjf" title="cathyjf: 2 merges" ></a><a href="https://github.com/cfalas" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, cfalas" ><img src="https://github.com/cfalas.png?size=50" width="50" height="50" alt="cfalas" title="cfalas: 2 merges" ></a><a href="https://github.com/cgarst" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, cgarst" ><img src="https://github.com/cgarst.png?size=50" width="50" height="50" alt="cgarst" title="cgarst: 2 merges" ></a><a href="https://github.com/cgutman" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, cgutman" ><img src="https://github.com/cgutman.png?size=50" width="50" height="50" alt="cgutman" title="cgutman: 2 merges" ></a><a href="https://github.com/chewi" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, chewi" ><img src="https://github.com/chewi.png?size=50" width="50" height="50" alt="chewi" title="chewi: 2 merges" ></a><a href="https://github.com/hgaiser" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, hgaiser" ><img src="https://github.com/hgaiser.png?size=50" width="50" height="50" alt="hgaiser" title="hgaiser: 2 merges" ></a><a href="https://github.com/ns6089" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, ns6089" ><img src="https://github.com/ns6089.png?size=50" width="50" height="50" alt="ns6089" title="ns6089: 2 merges" ></a><a href="https://github.com/skryvel" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, skryvel" ><img src="https://github.com/skryvel.png?size=50" width="50" height="50" alt="skryvel" title="skryvel: 2 merges" ></a><a href="https://github.com/xanderfrangos" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, xanderfrangos" ><img src="https://github.com/xanderfrangos.png?size=50" width="50" height="50" alt="xanderfrangos" title="xanderfrangos: 2 merges" ></a><a href="https://github.com/ABeltramo" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, ABeltramo" ><img src="https://github.com/ABeltramo.png?size=50" width="50" height="50" alt="ABeltramo" title="ABeltramo: 1 merge" ></a><a href="https://github.com/mariotaku" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, mariotaku" ><img src="https://github.com/mariotaku.png?size=50" width="50" height="50" alt="mariotaku" title="mariotaku: 1 merge" ></a>
4 changes: 4 additions & 0 deletions tests/data/expected_release_notes_sample_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@

## New Contributors
* [@LizardByte](https://github.com/LizardByte) made their first contribution

---
## Contributors
<a href="https://github.com/LizardByte" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, LizardByte" ><img src="https://github.com/LizardByte.png?size=50" width="50" height="50" alt="LizardByte" title="LizardByte: 2 merges" ></a><a href="https://github.com/dependabot" target="_blank" rel="external noopener noreferrer" aria-label="GitHub profile of contributor, dependabot" ><img src="https://github.com/dependabot.png?size=50" width="50" height="50" alt="dependabot" title="dependabot: 1 merge" ></a>