Skip to content

Commit

Permalink
feat(release_notes): add conributors section (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Jul 17, 2024
1 parent ade2a48 commit 29965b0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
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>

0 comments on commit 29965b0

Please sign in to comment.