github-rest-api 0.47.1__py3-none-any.whl → 0.47.2__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.
@@ -2,6 +2,7 @@
2
2
 
3
3
  import argparse
4
4
  import getpass
5
+ import logging
5
6
  import os
6
7
  import shutil
7
8
  import sys
@@ -12,6 +13,8 @@ from dulwich import porcelain
12
13
 
13
14
  from github_rest_api import Organization, User
14
15
 
16
+ logger = logging.getLogger(__name__)
17
+
15
18
 
16
19
  def _validate_repo(repo: str) -> None:
17
20
  parts = repo.split("/")
@@ -28,8 +31,9 @@ def _create_remote_repo(
28
31
  if is_owner_user
29
32
  else Organization(token=token, org=owner)
30
33
  )
34
+ logger.info("Creating remote GitHub repository '%s'...", repo)
31
35
  entity.create_repository(name=r, private=private)
32
- print(f"\nCreated the GitHub repo https://github.com/{repo}.\n")
36
+ logger.info("Created the GitHub repo https://github.com/%s.", repo)
33
37
 
34
38
 
35
39
  def _remote_url(repo: str, protocol: str) -> str:
@@ -41,6 +45,7 @@ def _remote_url(repo: str, protocol: str) -> str:
41
45
  def _ensure_remote(path: Path, repo: str, protocol: str) -> None:
42
46
  try:
43
47
  porcelain.remote_add(path, "origin", _remote_url(repo, protocol))
48
+ logger.info("Added remote 'origin' for %s", repo)
44
49
  except porcelain.RemoteExists:
45
50
  pass
46
51
 
@@ -70,24 +75,32 @@ def _init_local_repo(
70
75
  readme = path / "README.md"
71
76
  if not readme.exists():
72
77
  readme.write_text(f"# {repo_name}\n")
78
+ logger.info("Created %s", readme)
73
79
  if not (path / ".git").exists():
74
80
  porcelain.init(path=path)
81
+ logger.info("Initialized empty Git repository in %s", path)
75
82
  if not porcelain.branch_list(path):
76
83
  initial_branch = _active_branch(path)
77
84
  porcelain.add(repo=path, paths=["README.md"])
85
+ logger.info("Added README.md to staging")
78
86
  porcelain.commit(repo=path, message="first commit")
87
+ logger.info("Created first commit")
79
88
  for branch in branches:
80
89
  if branch != initial_branch:
81
90
  porcelain.branch_create(repo=path, name=branch)
91
+ logger.info("Created branch '%s'", branch)
82
92
  porcelain.checkout(repo=path, target=branches[0])
93
+ logger.info("Checked out branch '%s'", branches[0])
83
94
  if initial_branch not in branches:
84
95
  porcelain.branch_delete(repo=path, name=initial_branch)
96
+ logger.info("Deleted initial branch '%s'", initial_branch)
85
97
  _ensure_remote(path, repo, protocol)
86
98
  local_branches = {b.decode() for b in porcelain.branch_list(path)}
87
99
  branches_to_push = [branch for branch in branches if branch in local_branches]
88
100
  if not branches_to_push:
89
101
  branches_to_push = [_active_branch(path)]
90
102
  for branch in branches_to_push:
103
+ logger.info("Pushing branch '%s' to remote '%s'...", branch, repo)
91
104
  porcelain.push(
92
105
  repo=path,
93
106
  remote_location=_remote_url(repo, "https"),
@@ -95,6 +108,7 @@ def _init_local_repo(
95
108
  username="x-access-token",
96
109
  password=token,
97
110
  )
111
+ logger.info("Successfully pushed branch '%s'.", branch)
98
112
  _add_workflow(path, language)
99
113
 
100
114
 
@@ -138,6 +152,7 @@ def _add_workflow(path: Path, language: str, workflow_dir: Path | None = None) -
138
152
  for yaml in workflow_dir.glob("*.yaml"):
139
153
  if not (dir_dest / yaml.name).exists():
140
154
  shutil.copy2(yaml, dir_dest)
155
+ logger.info("Copied workflow %s to %s", yaml.name, dir_dest)
141
156
  if not language:
142
157
  return
143
158
  lang_dir = workflow_dir / language
@@ -146,6 +161,9 @@ def _add_workflow(path: Path, language: str, workflow_dir: Path | None = None) -
146
161
  for yaml in lang_dir.glob("*.yaml"):
147
162
  if not (dir_dest / yaml.name).exists():
148
163
  shutil.copy2(yaml, dir_dest)
164
+ logger.info(
165
+ "Copied %s specific workflow %s to %s", language, yaml.name, dir_dest
166
+ )
149
167
 
150
168
 
151
169
  def parse_args(args=None, namespace=None):
@@ -215,11 +233,19 @@ def parse_args(args=None, namespace=None):
215
233
  default="git",
216
234
  help="Use the HTTPS protocol for the remote URL.",
217
235
  )
236
+ parser.add_argument(
237
+ "-v",
238
+ "--verbose",
239
+ dest="verbose",
240
+ action="store_true",
241
+ help="Enable verbose output, including tracebacks on errors.",
242
+ )
218
243
  return parser.parse_args(args=args, namespace=namespace)
219
244
 
220
245
 
221
246
  def main() -> int:
222
247
  args = parse_args()
248
+ logging.basicConfig(level=logging.INFO, format="%(message)s")
223
249
  try:
224
250
  create_github_repo(
225
251
  repo=args.repo,
@@ -232,7 +258,7 @@ def main() -> int:
232
258
  protocol=args.protocol,
233
259
  )
234
260
  except Exception as e:
235
- print(str(e), file=sys.stderr)
261
+ logger.error("Failed to create GitHub repo: %s", e, exc_info=args.verbose)
236
262
  return 1
237
263
  return 0
238
264
 
@@ -0,0 +1,30 @@
1
+ name: Auto Merge PR
2
+ on:
3
+ pull_request_review:
4
+ types:
5
+ - submitted
6
+ issue_comment:
7
+ types:
8
+ - created
9
+ check_suite:
10
+ types:
11
+ - completed
12
+ schedule:
13
+ - cron: '0 * * * *'
14
+ timezone: 'America/Los_Angeles'
15
+ permissions:
16
+ contents: write
17
+ pull-requests: write
18
+ jobs:
19
+ auto_merge_pull_request:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - name: Install uv
23
+ run: |
24
+ curl -LsSf https://astral.sh/uv/install.sh | sudo env UV_INSTALL_DIR="/usr/local/bin" sh
25
+ - name: Auto Merge PR
26
+ run: |
27
+ uvx --from github-rest-api@latest auto_merge_pull_request \
28
+ --authors dclong \
29
+ --approvers dclong 'claude[bot]' 'gemini-code-assist[bot]' \
30
+ --token ${{ secrets.ACTIONS_TOKEN }}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: github-rest-api
3
- Version: 0.47.1
3
+ Version: 0.47.2
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,17 +14,18 @@ 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=gI4qt6ncOk2pB9dfZkXW_YSffbdQhWmqWmMYjXwsD44,7104
17
+ github_rest_api/scripts/github/create_github_repo.py,sha256=jH1uKOXKOxooO-PHMGlQ5YnIluWNqzRhkfgKdkH5UGU,8316
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
21
+ github_rest_api/scripts/github/workflows/auto_merge_pull_request.yaml,sha256=LOCYzTnubAqBbeGunSdnEt453ZLwJ2870YxRlcPJ7GE,768
21
22
  github_rest_api/scripts/github/workflows/create_pr_dev_to_main.yaml,sha256=fuYNQJ_BthRWmFv2J0JZgB_LrBsmEVAc8rZ-Cs_AqrQ,517
22
23
  github_rest_api/scripts/github/workflows/create_pr_to_dev.yaml,sha256=wFekTLVWffPQOguJCMfu8NnxLQ3OFvN5aBmYih8Ag14,548
23
24
  github_rest_api/scripts/github/workflows/create_pr_to_main.yaml,sha256=mgHPlewkCZfRyMH6PYtPlo-fuE7DaD8v_jj2dSc3nPA,531
24
25
  github_rest_api/scripts/github/workflows/remove_branch.yaml,sha256=KDpB76ovrhuRdP0HN5j6Th9gjIQWSDdh8b4b4yAgtoI,544
25
26
  github_rest_api/scripts/github/workflows/python/lint.yaml,sha256=toP2oUdVIKyu_n20Dr14k5cJYxN8rPksfbX4sfflXxc,699
26
27
  github_rest_api/scripts/github/workflows/python/test.yaml,sha256=86MljYEWX1E9kJYmhMCLwu46WNEWvoyO9PwqeRew540,887
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,,
28
+ github_rest_api-0.47.2.dist-info/METADATA,sha256=7Z7N5_Ed4-TbTs2G9T17mSdtM74ZO2FU_8dyvfKFoOE,915
29
+ github_rest_api-0.47.2.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
30
+ github_rest_api-0.47.2.dist-info/entry_points.txt,sha256=OfbP9GuQC7SyGbymfCYrXEG-TCcKuu31v0EPNvHc1Q4,659
31
+ github_rest_api-0.47.2.dist-info/RECORD,,