From 9ab1a23ff49005ab907f406eb92e18a743867eae Mon Sep 17 00:00:00 2001 From: matt Date: Sun, 23 Feb 2025 19:06:07 -0800 Subject: [PATCH] 2025-02-23 daily publish --- pyproject.toml | 1 + src/daily/cli.py | 5 ++++- src/daily/git.py | 42 ++++++++++++++++++++++++++++++++++++++++++ uv.lock | 11 +++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/daily/git.py diff --git a/pyproject.toml b/pyproject.toml index c312a8c..eb1119e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ authors = [{ name = "GitMatt", email = "git@publicmatt.com" }] requires-python = ">=3.12" dependencies = [ "click>=8.1.8", + "invoke>=2.2.0", "option>=2.1.0", "pydanclick>=0.4.0", "pydantic>=2.10.6", diff --git a/src/daily/cli.py b/src/daily/cli.py index 36e3c85..e6e215f 100644 --- a/src/daily/cli.py +++ b/src/daily/cli.py @@ -1,7 +1,7 @@ import click from pydanclick import from_pydantic -from . import weather, hacker_news +from . import weather, hacker_news, git @click.group() @@ -26,3 +26,6 @@ def top(): stories = hacker_news.recent_top_stories() for item in stories: print(f"[{item.score:>4}|{item.diff_for_humans():>12}]: {item.title}") + + +cli.add_command(git.cli) diff --git a/src/daily/git.py b/src/daily/git.py new file mode 100644 index 0000000..92d29f3 --- /dev/null +++ b/src/daily/git.py @@ -0,0 +1,42 @@ +import os +import subprocess +import os +import click +from pathlib import Path +from datetime import datetime +import logging + + +@click.command("commit-push") +@click.option( + "--repo-path", "-p", "repo_path", help="path to commit", default=Path().cwd() +) +def cli(repo_path): + """ + Commits and pushes changes in the specified Git repository. + """ + commit_message = f"{datetime.now().strftime('%Y-%m-%d')} daily publish" + os.chdir(repo_path) + + try: + # Run git add (add all changes) + subprocess.run(["git", "add", "."], check=True) + + # Run git commit + subprocess.run(["git", "commit", "-m", commit_message], check=True) + + # Run git push + subprocess.run(["git", "push"], check=True) + + click.echo( + f"changes have been committed and pushed to {repo_path} with message: {commit_message}" + ) + logging.info("git pushed") + + except subprocess.CalledProcessError as e: + logging.warning(f"error occurred while running git command: {e}") + click.echo(f"error occurred while running git command: {e}") + + +if __name__ == "__main__": + cli() diff --git a/uv.lock b/uv.lock index c07b35e..d388185 100644 --- a/uv.lock +++ b/uv.lock @@ -81,6 +81,7 @@ version = "0.1.0" source = { editable = "." } dependencies = [ { name = "click" }, + { name = "invoke" }, { name = "option" }, { name = "pydanclick" }, { name = "pydantic" }, @@ -91,6 +92,7 @@ dependencies = [ [package.metadata] requires-dist = [ { name = "click", specifier = ">=8.1.8" }, + { name = "invoke", specifier = ">=2.2.0" }, { name = "option", specifier = ">=2.1.0" }, { name = "pydanclick", specifier = ">=0.4.0" }, { name = "pydantic", specifier = ">=2.10.6" }, @@ -107,6 +109,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3", size = 70442 }, ] +[[package]] +name = "invoke" +version = "2.2.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f9/42/127e6d792884ab860defc3f4d80a8f9812e48ace584ffc5a346de58cdc6c/invoke-2.2.0.tar.gz", hash = "sha256:ee6cbb101af1a859c7fe84f2a264c059020b0cb7fe3535f9424300ab568f6bd5", size = 299835 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0a/66/7f8c48009c72d73bc6bbe6eb87ac838d6a526146f7dab14af671121eb379/invoke-2.2.0-py3-none-any.whl", hash = "sha256:6ea924cc53d4f78e3d98bc436b08069a03077e6f85ad1ddaa8a116d7dad15820", size = 160274 }, +] + [[package]] name = "option" version = "2.1.0"