Skip to content

Commit 55e88ac

Browse files
authored
Pyproject (#10)
* add support for pyproject.toml parsing * cleanup * allow default branch * fix var name * add warning * qa * fix action * cleanup * update README * only add repo-list from pyproject * avoid duplicates * fix README * no default branch * rename
1 parent 16f4e99 commit 55e88ac

3 files changed

Lines changed: 44 additions & 14 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This action can be used in other repositories' workflows to clone multiple repos
1111
**Inputs:**
1212
- **`repo-list`** (required): Space-separated list of repositories in `org/repo` format to clone
1313
- **`git-pat`** (optional): Git Personal Access Token for authentication
14+
- **`default-repo-ref`** (optional): Default Git reference to check out
15+
- **`pyproject-path`** (optional): Path to the pyproject.toml file
1416

1517
**Example workflow:**
1618

@@ -22,7 +24,8 @@ This action can be used in other repositories' workflows to clone multiple repos
2224
with:
2325
repo-list: "org/repo1 org/repo2"
2426
git-pat: ${{ secrets.GIT_PAT }}
25-
default-repo-ref: "main"
27+
default-repo-ref: main
28+
pyproject-path: pyproject.toml
2629
~~~
2730

2831
### Features

git-clone/action.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ inputs:
1010
required: false
1111
default-repo-ref:
1212
description: 'Default Git reference to check out'
13-
default: 'main'
13+
default: ''
14+
required: false
15+
pyproject-path:
16+
description: 'Path to the pyproject.toml file'
17+
default: ''
1418
required: false
1519
runs:
1620
using: "composite"
@@ -22,5 +26,7 @@ runs:
2226
env:
2327
GIT_PAT: ${{ inputs.git-pat }}
2428
REPO_LIST: ${{ inputs.repo-list }}
29+
DEFAULT_REPO_REF: ${{ inputs.default-repo-ref }}
30+
PYPROJECT_PATH: ${{ inputs.pyproject-path }}
2531
run: |
26-
uv run ${{ github.action_path }}/../scripts/git-clone-ref.py ${REPO_LIST}
32+
uv run ${{ github.action_path }}/../scripts/git-clone-ref.py ${REPO_LIST} --default-repo-ref "${DEFAULT_REPO_REF}" --pyproject-path "${PYPROJECT_PATH}"

scripts/git-clone-ref.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
# ]
77
# ///
88

9-
import os
109
import logging
10+
import os
1111
import shutil
12+
from typing import Annotated
1213

1314
import git
15+
import tomllib
1416
import typer
1517

1618
logger = logging.getLogger(__name__)
@@ -24,7 +26,8 @@ def git_clone_repo(
2426
repo_ref: str,
2527
multi_options: tuple[str, ...] = ("--depth=1", "--recurse-submodules"),
2628
) -> str:
27-
multi_options += (f"--branch {repo_ref}",)
29+
if repo_ref:
30+
multi_options += (f"--branch {repo_ref}",)
2831

2932
if os.path.exists(repo_path):
3033
logger.info(f"removing {repo_path!r}")
@@ -44,7 +47,10 @@ def git_clone_repos(
4447
git_pat: str,
4548
default_repo_ref: str,
4649
) -> None:
47-
for repo_path in paths:
50+
if not paths:
51+
logger.warning("No repository to clone.")
52+
53+
for repo_path in set(paths):
4854
repo_name = os.path.basename(repo_path)
4955
repo_org = os.path.basename(os.path.dirname(repo_path))
5056
git_pat_org = os.getenv(f"GIT_PAT_{repo_org.upper()}", git_pat)
@@ -68,17 +74,32 @@ def git_clone_repos(
6874

6975
@app.command()
7076
def main(
71-
github_repos: list[str] = typer.Argument(..., help="GitHub repositories to clone"),
72-
git_pat: str = typer.Option(
73-
default="", envvar="GIT_PAT", help="GitHub Personal Access Token"
74-
),
75-
default_repo_ref: str = typer.Option(
76-
default="main", help="Default Git reference to check out"
77-
),
77+
repo_list: Annotated[
78+
list[str],
79+
typer.Argument(help="GitHub repositories to clone."),
80+
] = [],
81+
git_pat: Annotated[
82+
str,
83+
typer.Option(envvar="GIT_PAT", help="GitHub Personal Access Token."),
84+
] = "",
85+
default_repo_ref: Annotated[
86+
str,
87+
typer.Option(help="Default Git reference to check out."),
88+
] = "",
89+
pyproject_path: Annotated[
90+
str | None,
91+
typer.Option(help="Path to the pyproject.toml file."),
92+
] = None,
7893
):
94+
if pyproject_path:
95+
with open(pyproject_path, "rb") as fp:
96+
pyproject = tomllib.load(fp)
97+
config = pyproject.get("tool", {}).get("git-clone", {})
98+
repo_list.extend(config.get("repo-list", []))
99+
79100
logging.basicConfig(level=logging.INFO)
80101
git_clone_repos(
81-
github_repos,
102+
repo_list,
82103
"https://{credentials}github.com/{repo_org}/{repo_name}.git",
83104
git_pat,
84105
default_repo_ref,

0 commit comments

Comments
 (0)