scitex-git 0.4.1__tar.gz → 0.4.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {scitex_git-0.4.1/src/scitex_git.egg-info → scitex_git-0.4.3}/PKG-INFO +1 -1
  2. {scitex_git-0.4.1 → scitex_git-0.4.3}/pyproject.toml +1 -1
  3. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/mirror/__init__.py +45 -4
  4. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/mirror/_config.py +10 -0
  5. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/mirror/_scan.py +9 -3
  6. {scitex_git-0.4.1 → scitex_git-0.4.3/src/scitex_git.egg-info}/PKG-INFO +1 -1
  7. {scitex_git-0.4.1 → scitex_git-0.4.3}/LICENSE +0 -0
  8. {scitex_git-0.4.1 → scitex_git-0.4.3}/README.md +0 -0
  9. {scitex_git-0.4.1 → scitex_git-0.4.3}/setup.cfg +0 -0
  10. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/__init__.py +0 -0
  11. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/__main__.py +0 -0
  12. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_branch.py +0 -0
  13. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_cli.py +0 -0
  14. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_clone.py +0 -0
  15. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_commit.py +0 -0
  16. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_constants.py +0 -0
  17. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_gh_secrets.py +0 -0
  18. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_init.py +0 -0
  19. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_remote.py +0 -0
  20. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_result.py +0 -0
  21. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_retry.py +0 -0
  22. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_skills/scitex-git/01_installation.md +0 -0
  23. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_skills/scitex-git/02_quick-start.md +0 -0
  24. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_skills/scitex-git/03_python-api.md +0 -0
  25. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_skills/scitex-git/04_cli-reference.md +0 -0
  26. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_skills/scitex-git/05_public-mirror.md +0 -0
  27. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_skills/scitex-git/SKILL.md +0 -0
  28. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_types.py +0 -0
  29. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_utils.py +0 -0
  30. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_validation.py +0 -0
  31. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_vendor_sh.py +0 -0
  32. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/_workflow.py +0 -0
  33. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git/mirror/_tree.py +0 -0
  34. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git.egg-info/SOURCES.txt +0 -0
  35. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git.egg-info/dependency_links.txt +0 -0
  36. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git.egg-info/entry_points.txt +0 -0
  37. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git.egg-info/requires.txt +0 -0
  38. {scitex_git-0.4.1 → scitex_git-0.4.3}/src/scitex_git.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scitex-git
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Summary: Git + GitHub Actions utilities (clone, branch, commit, retry, remote helpers, gh secrets/variables with SHA256 sidecar) — standalone module from the SciTeX ecosystem
5
5
  Author-email: Yusuke Watanabe <ywatanabe@scitex.ai>
6
6
  License-Expression: AGPL-3.0-only
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "scitex-git"
7
- version = "0.4.1"
7
+ version = "0.4.3"
8
8
  description = "Git + GitHub Actions utilities (clone, branch, commit, retry, remote helpers, gh secrets/variables with SHA256 sidecar) — standalone module from the SciTeX ecosystem"
9
9
  readme = "README.md"
10
10
  license = "AGPL-3.0-only"
@@ -94,7 +94,9 @@ def _commit(
94
94
  f"Redacted (content differs from the private commit): {', '.join(result.redacted_files) or 'none'}\n"
95
95
  "One-way export by `scitex-git mirror export`."
96
96
  )
97
- git(clone, "add", "-A")
97
+ # --force: the export set is exactly what must be committed, including
98
+ # files the private side tracks despite an ignore rule (git add -f).
99
+ git(clone, "add", "-A", "--force")
98
100
  if not git(clone, "status", "--porcelain").strip():
99
101
  result.findings.append(
100
102
  "export is identical to the public HEAD; nothing to commit"
@@ -102,17 +104,56 @@ def _commit(
102
104
  return
103
105
  git(clone, "commit", "-q", "-m", message)
104
106
  result.public_sha = git(clone, "rev-parse", "HEAD").strip()
107
+ if push and cfg.push_via == "pr":
108
+ result.public_sha = _land_via_pr(clone, result, message)
105
109
  for tag in tags:
106
- git(clone, "tag", "-a", tag, "-m", message)
110
+ git(clone, "tag", "-a", tag, result.public_sha, "-m", message)
107
111
  result.public_tags.append(tag)
108
112
  if push:
109
- branch = git(clone, "rev-parse", "--abbrev-ref", "HEAD").strip()
110
- git(clone, "push", "-q", "origin", f"HEAD:refs/heads/{branch}")
113
+ if cfg.push_via == "direct":
114
+ branch = git(clone, "rev-parse", "--abbrev-ref", "HEAD").strip()
115
+ git(clone, "push", "-q", "origin", f"HEAD:refs/heads/{branch}")
111
116
  for tag in tags:
112
117
  git(clone, "push", "-q", "origin", f"refs/tags/{tag}")
113
118
  result.pushed = True
114
119
 
115
120
 
121
+ def _land_via_pr(clone: Path, result: ExportResult, message: str) -> str:
122
+ """Land the export commit through a pull request on the public repository.
123
+
124
+ For hosts or organisations that forbid pushing to the default branch: the
125
+ commit goes to ``export/<private-sha12>``, a PR is opened and merged by
126
+ GitHub with a rebase (history stays linear), the branch is deleted, and
127
+ the merged commit is checked to carry exactly the exported tree. Needs
128
+ the ``gh`` CLI, authenticated for the public repository.
129
+ """
130
+ import shutil
131
+ import subprocess
132
+
133
+ if shutil.which("gh") is None:
134
+ raise RuntimeError("push_via: pr needs the GitHub CLI (gh) on PATH")
135
+ base = git(clone, "rev-parse", "--abbrev-ref", "HEAD").strip()
136
+ branch = f"export/{result.private_sha[:12]}"
137
+ tree = git(clone, "rev-parse", "HEAD^{tree}").strip()
138
+ git(clone, "push", "-q", "origin", f"HEAD:refs/heads/{branch}")
139
+
140
+ def gh(*args: str) -> str:
141
+ proc = subprocess.run(["gh", *args], cwd=clone, capture_output=True, text=True)
142
+ if proc.returncode != 0:
143
+ raise RuntimeError(f"gh {' '.join(args[:2])} failed: {proc.stderr.strip()}")
144
+ return proc.stdout.strip()
145
+
146
+ title, _, body = message.partition("\n\n")
147
+ url = gh("pr", "create", "--base", base, "--head", branch, "--title", title, "--body", body)
148
+ gh("pr", "merge", url, "--rebase", "--delete-branch")
149
+ git(clone, "fetch", "-q", "origin", base)
150
+ merged = git(clone, "rev-parse", f"origin/{base}").strip()
151
+ if git(clone, "rev-parse", f"{merged}^{{tree}}").strip() != tree:
152
+ raise RuntimeError(f"merged commit {merged[:12]} does not carry the exported tree")
153
+ git(clone, "reset", "-q", "--hard", merged)
154
+ return merged
155
+
156
+
116
157
  def export(
117
158
  cfg: MirrorConfig,
118
159
  *,
@@ -6,6 +6,7 @@ some material private publishes a separate public repository exported one way
6
6
  from its private one. This file declares that export::
7
7
 
8
8
  public_repo: owner/name-public # target (informational; the clone is given)
9
+ push_via: direct # or pr: land each export through a merged PR
9
10
  ref: origin/develop # private commit exported by default
10
11
  tags: ["paper-v*", "abstract-*"] # private tags carried over to the public commit
11
12
  include: [] # path regexes; empty means every tracked file
@@ -63,6 +64,7 @@ class ScanConfig:
63
64
  class MirrorConfig:
64
65
  root: Path
65
66
  public_repo: str | None = None
67
+ push_via: str = "direct"
66
68
  ref: str = "HEAD"
67
69
  tags: tuple = ()
68
70
  include: tuple = ()
@@ -103,6 +105,12 @@ def _strs(data: dict, key: str) -> tuple:
103
105
  return tuple(value)
104
106
 
105
107
 
108
+ def _push_via(value) -> str:
109
+ if value not in ("direct", "pr"):
110
+ raise MirrorConfigError("push_via must be 'direct' or 'pr'")
111
+ return value
112
+
113
+
106
114
  def load_config(root: Path, path: Path | None = None) -> MirrorConfig:
107
115
  """Read and validate ``<root>/.scitex/git/publish.yaml`` (or ``path``)."""
108
116
  root = Path(root).resolve()
@@ -116,6 +124,7 @@ def load_config(root: Path, path: Path | None = None) -> MirrorConfig:
116
124
  raise MirrorConfigError("publish config must be a mapping")
117
125
  unknown = set(data) - {
118
126
  "public_repo",
127
+ "push_via",
119
128
  "ref",
120
129
  "tags",
121
130
  "include",
@@ -172,6 +181,7 @@ def load_config(root: Path, path: Path | None = None) -> MirrorConfig:
172
181
  return MirrorConfig(
173
182
  root=root,
174
183
  public_repo=data.get("public_repo"),
184
+ push_via=_push_via(data.get("push_via", "direct")),
175
185
  ref=data.get("ref", "HEAD"),
176
186
  tags=_strs(data, "tags"),
177
187
  include=tuple(_compile(p, "include") for p in _strs(data, "include")),
@@ -173,9 +173,15 @@ def scan_internal(cfg: MirrorConfig, out: Path) -> list:
173
173
  def scan_leak_check(cfg: MirrorConfig, out: Path) -> list:
174
174
  if not cfg.scan.leak_check:
175
175
  return []
176
- proc = subprocess.run(
177
- cfg.scan.leak_check, shell=True, cwd=out, capture_output=True, text=True
178
- )
176
+ # Run in a disposable copy: a leak check may write into its working tree
177
+ # (staged files, bytecode caches), and the export must stay exactly the
178
+ # scanned selection.
179
+ with tempfile.TemporaryDirectory() as tmp:
180
+ work = Path(tmp) / "export"
181
+ shutil.copytree(out, work, symlinks=True) # stx-allow: STX-IO018 (scratch copy)
182
+ proc = subprocess.run(
183
+ cfg.scan.leak_check, shell=True, cwd=work, capture_output=True, text=True
184
+ )
179
185
  if proc.returncode == 0:
180
186
  return []
181
187
  tail = (proc.stdout + proc.stderr).strip().splitlines()[-5:]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scitex-git
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Summary: Git + GitHub Actions utilities (clone, branch, commit, retry, remote helpers, gh secrets/variables with SHA256 sidecar) — standalone module from the SciTeX ecosystem
5
5
  Author-email: Yusuke Watanabe <ywatanabe@scitex.ai>
6
6
  License-Expression: AGPL-3.0-only
File without changes
File without changes
File without changes