-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
|
||
from git import Commit, Repo | ||
from git.exc import InvalidGitRepositoryError | ||
|
||
|
||
def repo_from_path(path: Path) -> Repo | None: | ||
"""Return the repo for the given path.""" | ||
try: | ||
repo = Repo(path) | ||
except InvalidGitRepositoryError: | ||
repo = None | ||
return repo | ||
|
||
|
||
def check_path_is_repository(path: Path) -> bool: | ||
"""Check if given path is a Git Repository.""" | ||
return bool(repo_from_path(path)) | ||
|
||
|
||
def initialize_repository(path: Path) -> Repo: | ||
"""Initialize a git repository and add all files.""" | ||
if not check_path_is_repository(path): | ||
repo = Repo.init(path) | ||
repo.git.add(path) | ||
return repo | ||
|
||
|
||
def get_last_commit(path: Path) -> Commit | None: | ||
"""Return the last commit for a repo.""" | ||
repo = repo_from_path(path) | ||
return repo.head.commit if repo else None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
from cookiecutter import __version__ as __cookiecutter_version__ | ||
|
||
from cookieplone import __version__ | ||
from cookieplone.utils import git | ||
|
||
COOKIEPLONE_REPO = "https://github.com/plone/cookieplone" | ||
TEMPLATES_REPO = "https://github.com/plone/cookiecutter-plone" | ||
|
||
|
||
def version_info() -> str: | ||
"""Return the Cookieplone version, location and Python powering it.""" | ||
python_version = sys.version | ||
# Get the root of cookieplone | ||
location = Path(__file__).parent.parent | ||
return ( | ||
f"Cookieplone {__version__} from {location} " | ||
f"(Cookiecutter {__cookiecutter_version__}, " | ||
f"Python {python_version})" | ||
) | ||
|
||
|
||
def signature_md(path: Path) -> str: | ||
"""Return a signature, in markdown.""" | ||
date_info = f"{datetime.now()}" | ||
cookieplone = f"[Cookieplone ({__version__})]({COOKIEPLONE_REPO})" | ||
commit = git.get_last_commit(path) | ||
if not commit: | ||
template = f"[cookiecutter-plone]({TEMPLATES_REPO})" | ||
else: | ||
sha = commit.hexsha | ||
template = f"[cookiecutter-plone ({sha[:7]})]({TEMPLATES_REPO}/commit/{sha})" | ||
return f"""Generated using {cookieplone} and {template} on {date_info}""" |