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

Add basic contributor's page based on git commit history #124

Closed
wants to merge 1 commit into from
Closed
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
81 changes: 81 additions & 0 deletions ci/contributors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python3
import os
import sys
import subprocess
from pathlib import Path
from functools import partial
from collections import namedtuple, defaultdict

Committer = namedtuple('Committer', ['name', 'email'])

BLACKLIST = ['GitHub', 'bors[bot]']
OVERWRITES = {
'James Munns': {'name': 'James Munns', 'email': '[email protected]'},
}


def committer_log():
"""
Generator, returning the commiter for each commit in the git repository.
"""
command = ['git', 'log', '--pretty=%cn;%ce']
result = subprocess.run(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
if result.returncode != 0:
raise Exception(f"Error while running git command, details {result.stdout}")
for line in result.stdout.decode('utf-8').split('\n'):
if ';' in line:
name, email = line.split(';')
yield Committer(name, email)


def unique_committers():
"""
Generator, returning all unique tuples of (name, email) for all commiters of the repository.
"""
committers = set(committer_log())
for c in committers:
yield c


def create_view_model(committers):
view_model = defaultdict(dict)
for c in committers:
view_model[c.name]['name'] = c.name
view_model[c.name]['email'] = c.email
return view_model


def update_view_model(model, preferences):
for user, data in preferences.items():
model[user]['name'] = data['name']
model[user]['email'] = data['email']
return model


def render(view_model):
output = [
"# Contributors",
"",
"Here is a list of the contributors who have helped creating this book:",
"",
]
for name, data in view_model.items():
output.append(f"* [{data['name']}](mailto:{data['email']})")
return '\n'.join(output)


def main():
current_dir = Path(os.path.dirname(__file__))
book_src_dir = current_dir.joinpath('..', 'src')
contributers_md = book_src_dir.joinpath('contributors.md')
committers = [c for c in unique_committers() if c.name not in BLACKLIST]
view_model = create_view_model(committers)
view_model = update_view_model(view_model, OVERWRITES)
output = render(view_model)
with open(contributers_md, 'w') as f: f.write(output)
sys.exit(0)


if __name__ == '__main__':
main()

1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ more information and coordination
- [A little Rust with your C](./interoperability/rust-with-c.md)
- [Unsorted topics](./unsorted/index.md)
- [Optimizations: The speed size tradeoff](./unsorted/speed-vs-size.md)
- [Contributors](contributors.md)
27 changes: 27 additions & 0 deletions src/contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Contributors

Here is a list of the contributors who have helped creating this book:

* [James Munns](mailto:[email protected])
* [rmsthebest](mailto:[email protected])
* [tomoyuki-nakabayashi](mailto:[email protected])
* [Steffan Karger](mailto:[email protected])
* [Adam Greig](mailto:[email protected])
* [Zhuowei Zhang](mailto:[email protected])
* [Katharina](mailto:[email protected])
* [Robert Warmka](mailto:[email protected])
* [Adam Green](mailto:[email protected])
* [Christopher J. McClellan](mailto:[email protected])
* [Henrik Enggaard Hansen](mailto:[email protected])
* [Roberto Vidal](mailto:[email protected])
* [Daniel Egger](mailto:[email protected])
* [Jonathan Pallant](mailto:[email protected])
* [Jorge Aparicio](mailto:[email protected])
* [Nathan](mailto:[email protected])
* [Jonathan 'theJPster' Pallant](mailto:[email protected])
* [Sam Stelfox](mailto:[email protected])
* [shellwirt](mailto:[email protected])
* [Nicola Coretti](mailto:[email protected])
* [Vincent Bernat](mailto:[email protected])
* [Eddy Petrișor](mailto:[email protected])
* [Katharina Fey](mailto:[email protected])