Compare commits

...

18 commits
0.1.0 ... main

Author SHA1 Message Date
David Lord
4901f86f5e
Merge pull request #8 from davidism/release-0.2.0
release version 0.2.0
2025-01-14 14:40:03 -08:00
David Lord
b675431f94
release version 0.2.0 2025-01-14 14:35:23 -08:00
David Lord
37fc6104ce
Merge pull request #7 from davidism/document-behaviors
document untracked, direct, and update behaviors
2025-01-14 14:34:29 -08:00
David Lord
3a7c0d8874
document untracked, direct, and update behaviors 2025-01-14 14:33:12 -08:00
David Lord
4ecdea1a73
Merge pull request #6 from davidism/commit-shortcut
add `repo.commit` shortcut
2025-01-14 14:19:17 -08:00
David Lord
0c6e5ed62b
add repo.commit shortcut 2025-01-14 14:17:58 -08:00
David Lord
3e778fb77e
Merge pull request #5 from davidism/update-pr
update existing branch and pr
2025-01-14 14:09:34 -08:00
David Lord
4dba24283e
update existing branch and pr 2025-01-14 14:05:14 -08:00
David Lord
d7dbd26e42
start version 0.2.0 2025-01-14 14:03:15 -08:00
David Lord
7ab21ffd32
Merge pull request #4 from davidism/release-0.1.1
release version 0.1.1
2025-01-14 14:01:21 -08:00
David Lord
d80175d9a2
release version 0.1.1 2025-01-14 13:56:23 -08:00
David Lord
1c7b8fff96
don't need tests on tag 2025-01-14 13:54:17 -08:00
David Lord
409fe0ef5c
don't update uv lock in ci 2025-01-14 13:53:35 -08:00
David Lord
353ba6a098
error if same target and branch (#3)
error if same target and branch
2025-01-14 13:16:16 -08:00
David Lord
b0b6e11dcc
Merge pull request #2 from davidism/disable-submit
submit is disabled by default
2025-01-14 12:32:02 -08:00
David Lord
d968a7e815
submit is disabled by default 2025-01-14 12:30:39 -08:00
David Lord
78bbd954d9
start version 0.1.1 2025-01-14 12:26:50 -08:00
David Lord
dff0232764
Merge pull request #1 from davidism/release-0.1.0
release version 0.1.0
2025-01-14 11:15:36 -08:00
10 changed files with 102 additions and 18 deletions

View file

@ -20,6 +20,6 @@ jobs:
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ hashFiles('pyproject.toml', '.pre-commit-config.yaml') }}
- run: uv run --group pre-commit pre-commit run --show-diff-on-failure --color=always --all-files
- run: uv run --locked --group pre-commit pre-commit run --show-diff-on-failure --color=always --all-files
- uses: pre-commit-ci/lite-action@5d6cc0eb514c891a40562a58a8e71576c5c7fb43 # v1.1.0
if: ${{ !cancelled() }}

View file

@ -5,7 +5,6 @@ on:
push:
branches: [main, stable]
paths: ['src/**', 'pyproject.toml']
tags: ['*']
jobs:
typing:
runs-on: ubuntu-latest
@ -23,4 +22,4 @@ jobs:
with:
path: ./.mypy_cache
key: mypy|${{ hashFiles('pyproject.toml') }}
- run: uv run tox run -e typing
- run: uv run --locked tox run -e typing

View file

@ -1,3 +1,18 @@
## Version 0.2.0
Released 2025-01-14
- If a PR already exists from a previous failed run, force push to update the
existing branch and PR.
- Add shortcut `repo.commit(message)` method.
## Version 0.1.1
Released 2025-01-14
- Submit is disabled by default.
- Error if target and work branch are the same.
## Version 0.1.0
Released 2025-01-14

View file

@ -44,3 +44,47 @@ develop and preview your changes first.
[uv]: https://docs.astral.sh/uv/
[gh]: https://cli.github.com/
## Automatic Commit
After calling `modify`, the script will automatically add any tracked files
and create a commit if it detects there are uncommitted changes.
If you add a completely new file, it will not be tracked by Git yet, and this
won't be detected or committed. Therefore, you should call
{meth}`.Repo.add_files` to track any new files. Other modifications, such as
changing an existing file or using {meth}`.Repo.rm_files`, will already be
tracked by Git.
You can set {attr}`.GitRepo.add_untracked` to also detect and add completely
new untracked files. This is disabled by default as it might end up adding files
that were generated as a side effect of other changes.
```python
class MyScript(GitHubScript):
def modify(self, repo: GitHubRepo) -> None:
repo.add_untracked = True
...
```
## Merge vs PR
By default, the GitHub provider creates PRs. You can instruct a repo to merge
and push directly to the target instead. This is disabled by default because it
provides one less opportunity to ensure your script worked correctly.
Set {attr}`GitHubRepo.direct_submit` to `True` to enable this merge and push
behavior.
```python
class MyScript(GitHubScript):
def modify(self, repo: GitHubRepo) -> None:
repo.direct_submit = True
...
```
## Updating
You may have run your script with submit enabled, then noticed that more is
needed. If a branch and open PR already exist from a previous run of the script
that, a force push will be used to update.

View file

@ -1,6 +1,6 @@
[project]
name = "modify-repos"
version = "0.1.0"
version = "0.2.0"
description = "Apply changes across multiple repos at once."
readme = "README.md"
authors = [{ name = "David Lord" }]

View file

@ -5,6 +5,7 @@ from shutil import which
from subprocess import CompletedProcess
from ..utils import run_cmd
from ..utils import wrap_text
from .base import Repo
@ -64,6 +65,20 @@ class GitRepo(Repo):
self.git_cmd("merge", "--ff-only", self.script.branch)
self.git_cmd("push")
def commit(self, message: str, add: bool = False) -> None:
"""Create a commit with the given message.
:param message: The commit message.
:param add: Update tracked files while committing. Disabled by default.
Alternatively, call {meth}`add_files` first.
"""
args = ["commit", "--message", wrap_text(message, width=72)]
if add:
args.insert(1, "-a")
self.git_cmd(*args)
def add_files(
self, *items: str | Path, update: bool = False, all: bool = False
) -> None:

View file

@ -66,14 +66,21 @@ class GitHubRepo(GitRepo):
super().submit()
return
self.git_cmd("push", "--set-upstream", "origin", self.script.branch)
self.gh_cmd(
"pr",
"create",
"--base",
self.script.target,
"--title",
self.script.title,
"--body",
self.script.body,
)
result = self.gh_cmd("pr", "view", "--json", "closed", "--jq", ".closed")
has_pr = not result.returncode and result.stdout.strip() == "false"
if not has_pr:
self.git_cmd("push", "--set-upstream", "origin", self.script.branch)
self.gh_cmd(
"pr",
"create",
"--base",
self.script.target,
"--title",
self.script.title,
"--body",
self.script.body,
)
else:
# If open PR already exists from previous run, force push.
self.git_cmd("push", "--force", "origin", self.script.branch)

View file

@ -41,7 +41,11 @@ class Script[RepoType: Repo]:
"""
def __init__(self, *, submit: bool = False) -> None:
""" """
if self.target == self.branch:
raise ValueError(
"Work branch name must be different than target branch name."
)
source_file = inspect.getsourcefile(self.__class__)
if source_file is None:

View file

@ -17,7 +17,7 @@ class GitHubScript(Script[GitHubRepo]):
orgs: list[str]
"""The list of GitHub users/orgs to clone repositories from."""
def __init__(self, *, submit: bool = True, orgs: list[str] | None = None) -> None:
def __init__(self, *, submit: bool = False, orgs: list[str] | None = None) -> None:
super().__init__(submit=submit)
if orgs is not None:

2
uv.lock generated
View file

@ -335,7 +335,7 @@ wheels = [
[[package]]
name = "modify-repos"
version = "0.1.0"
version = "0.2.0"
source = { editable = "." }
dependencies = [
{ name = "click" },