github-rest-api 0.46.0__py3-none-any.whl → 0.47.1__py3-none-any.whl

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.
@@ -38,6 +38,24 @@ def _remote_url(repo: str, protocol: str) -> str:
38
38
  return f"https://github.com/{repo}.git"
39
39
 
40
40
 
41
+ def _ensure_remote(path: Path, repo: str, protocol: str) -> None:
42
+ try:
43
+ porcelain.remote_add(path, "origin", _remote_url(repo, protocol))
44
+ except porcelain.RemoteExists:
45
+ pass
46
+
47
+
48
+ def _active_branch(path: Path) -> str:
49
+ try:
50
+ return porcelain.active_branch(path).decode()
51
+ except (IndexError, ValueError) as e:
52
+ raise ValueError(
53
+ f"HEAD of the local repo at '{path}' is detached (not on any branch), "
54
+ "which is unsupported (this happens, e.g., with a colocated Jujutsu repo). "
55
+ "Check out a branch (e.g. `git switch -c main`) before running this command."
56
+ ) from e
57
+
58
+
41
59
  def _init_local_repo(
42
60
  repo: str,
43
61
  language: str,
@@ -54,29 +72,29 @@ def _init_local_repo(
54
72
  readme.write_text(f"# {repo_name}\n")
55
73
  if not (path / ".git").exists():
56
74
  porcelain.init(path=path)
57
- porcelain.remote_add(path, "origin", _remote_url(repo, protocol))
58
- initial_branch = (
59
- (path / ".git" / "HEAD").read_text().strip().partition("refs/heads/")[-1]
60
- )
61
- porcelain.add(repo=path)
75
+ if not porcelain.branch_list(path):
76
+ initial_branch = _active_branch(path)
77
+ porcelain.add(repo=path, paths=["README.md"])
62
78
  porcelain.commit(repo=path, message="first commit")
63
-
64
- def _create_push_branch(branch: str):
79
+ for branch in branches:
65
80
  if branch != initial_branch:
66
81
  porcelain.branch_create(repo=path, name=branch)
67
- porcelain.checkout(repo=path, target=branch)
68
- porcelain.push(
69
- repo=path,
70
- remote_location=_remote_url(repo, "https"),
71
- username="x-access-token",
72
- password=token,
73
- )
74
-
75
- for branch in branches:
76
- _create_push_branch(branch)
77
82
  porcelain.checkout(repo=path, target=branches[0])
78
83
  if initial_branch not in branches:
79
84
  porcelain.branch_delete(repo=path, name=initial_branch)
85
+ _ensure_remote(path, repo, protocol)
86
+ local_branches = {b.decode() for b in porcelain.branch_list(path)}
87
+ branches_to_push = [branch for branch in branches if branch in local_branches]
88
+ if not branches_to_push:
89
+ branches_to_push = [_active_branch(path)]
90
+ for branch in branches_to_push:
91
+ porcelain.push(
92
+ repo=path,
93
+ remote_location=_remote_url(repo, "https"),
94
+ refspecs=[branch.encode()],
95
+ username="x-access-token",
96
+ password=token,
97
+ )
80
98
  _add_workflow(path, language)
81
99
 
82
100
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: github-rest-api
3
- Version: 0.46.0
3
+ Version: 0.47.1
4
4
  Summary: Simple wrapper of GitHub REST APIs.
5
5
  Author-email: Ben Du <longendu@yahoo.com>
6
6
  Classifier: Programming Language :: Python :: 3 :: Only
@@ -14,7 +14,7 @@ github_rest_api/scripts/container/config_container.py,sha256=BtOqgZlQFM9cWZMoHKv
14
14
  github_rest_api/scripts/container/update_version_containerfile.py,sha256=1PkuJkAsJBCEMdacMSndbuZKcmgUyXy6nBArnxKoPZk,4535
15
15
  github_rest_api/scripts/github/__init__.py,sha256=tEU1SdCS51M4M13WoqXZt3rjGEAI_QgNljt5XAyQJ_w,38
16
16
  github_rest_api/scripts/github/auto_merge_pull_request.py,sha256=_5191Xt_b8DtxjIqHrdY-gKLxvkzWd8oWoSbF2uauc8,3527
17
- github_rest_api/scripts/github/create_github_repo.py,sha256=6JiNDKYmRuAwJhBsNJOkeIHGmuP2ukii4esmdC8HQw8,6362
17
+ github_rest_api/scripts/github/create_github_repo.py,sha256=gI4qt6ncOk2pB9dfZkXW_YSffbdQhWmqWmMYjXwsD44,7104
18
18
  github_rest_api/scripts/github/create_pull_request.py,sha256=gXtRRsxzegGxagHb6k3kxtRd3mt4QVwSPZQpsFnzz1Y,3968
19
19
  github_rest_api/scripts/github/release_on_github.py,sha256=9psaIv-GtrHdvE-tkw0yxCMDmW0bPts-db2vUxhoKXo,4368
20
20
  github_rest_api/scripts/github/remove_branch.py,sha256=iKZ4Y_lQlSOIfifC4plqP-B6pEMnFrknGMvV1oLnuLc,3538
@@ -24,7 +24,7 @@ github_rest_api/scripts/github/workflows/create_pr_to_main.yaml,sha256=mgHPlewkC
24
24
  github_rest_api/scripts/github/workflows/remove_branch.yaml,sha256=KDpB76ovrhuRdP0HN5j6Th9gjIQWSDdh8b4b4yAgtoI,544
25
25
  github_rest_api/scripts/github/workflows/python/lint.yaml,sha256=toP2oUdVIKyu_n20Dr14k5cJYxN8rPksfbX4sfflXxc,699
26
26
  github_rest_api/scripts/github/workflows/python/test.yaml,sha256=86MljYEWX1E9kJYmhMCLwu46WNEWvoyO9PwqeRew540,887
27
- github_rest_api-0.46.0.dist-info/METADATA,sha256=ONbUloesiPnF-4Dvv1tzFuOq4dDNwHtAEoPNr0cQCPU,915
28
- github_rest_api-0.46.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
29
- github_rest_api-0.46.0.dist-info/entry_points.txt,sha256=OfbP9GuQC7SyGbymfCYrXEG-TCcKuu31v0EPNvHc1Q4,659
30
- github_rest_api-0.46.0.dist-info/RECORD,,
27
+ github_rest_api-0.47.1.dist-info/METADATA,sha256=b9iysY6lBcuo-RKdZ2j-z7qXusI1uTbDzuBPuqh1rAU,915
28
+ github_rest_api-0.47.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
29
+ github_rest_api-0.47.1.dist-info/entry_points.txt,sha256=OfbP9GuQC7SyGbymfCYrXEG-TCcKuu31v0EPNvHc1Q4,659
30
+ github_rest_api-0.47.1.dist-info/RECORD,,