Skip to content

Commit

Permalink
Improve contribs 🛡️
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato authored Oct 3, 2022
1 parent d1ec35b commit e85cd0e
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 68 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2022-10-03
- Corrects bug in the `contributors` plugin, causing failures in certain CI/CD
solutions and improves its safety and performance (removes `shell=True`!)
- Adds option to apply a class to specific contributors, for simpler styling
- Minor improvements to styles

## [0.0.9] - 2022-10-02
- Improves the `contributors` plugin:
- - Adds the possibility to exclude contributor information (for example to not display
contributions from bots).
contributions from bots)
- - Adds the possibility to merge contributors' information
for cases in which the same person commits using two different email addresses.
- - Adds the possibility to display an element with the count of contributors.
- Resolves a small issue in pip package resolution.
for cases in which the same person commits using two different email addresses
- - Adds the possibility to display an element with the count of contributors
- Resolves a small issue in pip package resolution

## [0.0.8] - 2022-10-01
- Improves the Gantt extension:
Expand Down
1 change: 1 addition & 0 deletions neoteroi/contribs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def _get_contributors(self, page_file: File) -> List[Contributor]:
)
if contributor_info:
contributor.image = contributor_info.get("image")
contributor.key = contributor_info.get("key")

if contributor_info.get("ignore"):
# ignore the contributor's information (can be useful for bots)
Expand Down
1 change: 1 addition & 0 deletions neoteroi/contribs/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Contributor:
email: str
count: int = -1
image: Optional[str] = None
key: Optional[str] = None


class ContributionsReader(ABC):
Expand Down
34 changes: 28 additions & 6 deletions neoteroi/contribs/git.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import re
import subprocess
from datetime import datetime
from pathlib import Path
from typing import Iterable, List, Tuple

from dateutil.parser import parse as parse_date

from neoteroi.contribs.domain import ContributionsReader, Contributor
from neoteroi.markdown.commands import Command


class GitContributionsReader(ContributionsReader):

_name_email_rx = re.compile(r"(?P<name>[\w\s]+)\s<(?P<email>[^\>]+)>")

def _decode(self, value: bytes) -> str:
try:
return value.decode("utf8")
except UnicodeDecodeError:
return value.decode("ISO-8859-1")

def _parse_name_and_email(self, name_and_email) -> Tuple[str, str]:
match = self._name_email_rx.search(name_and_email)
if match:
Expand All @@ -33,14 +39,30 @@ def get_contributors(self, file_path: Path) -> List[Contributor]:
Obtains the list of contributors for a file with the given path,
using the Git CLI.
"""
command = Command(f'git shortlog --summary --numbered --email "{file_path}"')
in_process = subprocess.Popen(
["git", "log", "--pretty=short"], stdout=subprocess.PIPE
)
result = self._decode(
subprocess.check_output(
[
"git",
"shortlog",
"--summary",
"--numbered",
"--email",
str(file_path),
],
stdin=in_process.stdout,
)
)

result = command.execute()
return list(self.parse_committers(result))

def get_last_commit_date(self, file_path: Path) -> datetime:
"""Reads the last commit on a file."""
command = Command(f'git log -1 --pretty="format:%ci" "{file_path}"')

result = command.execute()
result = self._decode(
subprocess.check_output(
["git", "log", "-1", "--pretty=format:%ci", str(file_path)]
)
)
return parse_date(result)
5 changes: 3 additions & 2 deletions neoteroi/contribs/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def contribution_stats_to_element(
if options.show_last_modified_time:
last_modified_time = etree.SubElement(
element,
"em",
"p",
{"class": "nt-mod-time"},
)
if options.last_modified_label:
Expand All @@ -56,7 +56,8 @@ def contribution_stats_to_element(
sorted(contributors, key=lambda item: item.count, reverse=True)
):
props = {
"class": "nt-contributor",
"class": "nt-contributor"
+ (f" {contributor.key}" if contributor.key else ""),
"title": (
f"{contributor.name} <{contributor.email}> ({contributor.count})"
),
Expand Down
52 changes: 0 additions & 52 deletions neoteroi/markdown/commands.py

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ def readme():

setup(
name="neoteroi-mkdocs",
version="0.0.9",
version="0.1.0",
description="Plugins for MkDocs and Python Markdown",
long_description=readme(),
long_description_content_type="text/markdown",
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
4 changes: 2 additions & 2 deletions styles/contribs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ $dot-size: 40px;

.nt-initials {
text-transform: uppercase;
font-size: 24px;
font-size: 20px;
text-align: center;
width: $dot-size;
height: $dot-size;
display: inline-block;
vertical-align: middle;
position: relative;
top: 2px;
top: 4px;
color: inherit;
font-weight: bold;
}
Expand Down
2 changes: 2 additions & 0 deletions styles/timeline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@

.icon {
color: white;
position: relative;
top: 1px;
}
}

Expand Down

0 comments on commit e85cd0e

Please sign in to comment.