Skip to content

Commit

Permalink
Adds check for GitHub CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jevandezande committed Feb 13, 2024
1 parent 03fe70d commit 3730dda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The cookiecutter will automagically
- Install dependencies
- Setup pre-commit and pre-push hooks
- Make initial commit
- Setup remote on GitHub (optional)


## Recommendations
Expand Down
20 changes: 15 additions & 5 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
import shutil
import subprocess
import sys
from datetime import datetime
from pathlib import Path
from shutil import rmtree
from subprocess import check_call
from typing import Literal
from typing import Any, Literal

logger = logging.Logger("post_gen_project_logger")
logger.setLevel(logging.INFO)
Expand All @@ -14,14 +14,14 @@
PROTOCOL = Literal["git", "https"]


def call(*inputs: str) -> None:
def call(*inputs: str, **kwargs: Any) -> None:
"""
Call shell commands.
Warning: strings with spaces are not yet supported.
"""
for input in inputs:
logger.debug(f"Calling: {input}")
check_call(input.split())
subprocess.check_call(input.split(), **kwargs)


def set_python_version() -> None:
Expand Down Expand Up @@ -127,7 +127,10 @@ def install() -> None:


def git_hooks() -> None:
call("poetry run pre-commit install -t pre-commit", "poetry run pre-commit install -t pre-push")
call(
"poetry run pre-commit install -t pre-commit",
"poetry run pre-commit install -t pre-push",
)


def git_initial_commit() -> None:
Expand All @@ -150,6 +153,13 @@ def github_setup(privacy: str) -> None:
if privacy not in privacy_options:
raise ValueError(f"Privacy must be one of {privacy_options}, got: {privacy}")

try:
call("gh", stdout=subprocess.DEVNULL)
except FileNotFoundError:
raise OSError("The GitHub CLI is not installed; install from https://cli.github.com/")
except subprocess.CalledProcessError:
raise OSError("Issue with GitHub CLI encountered")

call(f"gh repo create {{cookiecutter.package_name}} --{privacy}")


Expand Down

0 comments on commit 3730dda

Please sign in to comment.