pygitpub 0.0.60__tar.gz → 0.0.62__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pygitpub
3
- Version: 0.0.60
3
+ Version: 0.0.62
4
4
  Summary: Pygitpub will help you work with github
5
5
  Project-URL: Homepage, https://github.com/veltzer/pygitpub
6
6
  Project-URL: Bug Tracker, https://github.com/veltzer/pygitpub/issues
@@ -41,7 +41,7 @@ project website: https://veltzer.github.io/pygitpub
41
41
 
42
42
  author: Mark Veltzer
43
43
 
44
- version: 0.0.60
44
+ version: 0.0.62
45
45
 
46
46
  ![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)
47
47
 
@@ -9,7 +9,7 @@ project website: https://veltzer.github.io/pygitpub
9
9
 
10
10
  author: Mark Veltzer
11
11
 
12
- version: 0.0.60
12
+ version: 0.0.62
13
13
 
14
14
  ![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)
15
15
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pygitpub"
7
- version = "0.0.60"
7
+ version = "0.0.62"
8
8
  requires-python = ">=3.14"
9
9
  authors = [
10
10
  { name = "Mark Veltzer", email = "mark.veltzer@gmail.com" }
@@ -17,7 +17,7 @@ from pytconf.registry import the_registry
17
17
  import pygitpub.static
18
18
  from pygitpub.configs import AFFILIATIONS, ConfigAlgo, ConfigGithub, ConfigOutput
19
19
  from pygitpub.utils.lua import config_path, load_lua_file
20
- from pygitpub.utils.misc import delete, get_all_git_repos
20
+ from pygitpub.utils.misc import get_all_git_repos
21
21
 
22
22
 
23
23
  def get_base_dir() -> str:
@@ -77,21 +77,15 @@ def yield_repos():
77
77
  ],
78
78
  )
79
79
  def fix_metadata() -> None:
80
- orig_folder = os.getcwd()
81
80
  for repo in yield_repos():
82
81
  folder = get_repo_folder(repo)
83
82
  if not os.path.isdir(folder):
84
- # print(f"folder [{folder}] does not exist, continuing...")
85
83
  continue
86
- os.chdir(folder)
87
- # print(f"doing [{folder}]...")
88
- file_path = config_path("project")
84
+ file_path = os.path.join(folder, config_path("project"))
89
85
  if not os.path.isfile(file_path):
90
- os.chdir(orig_folder)
91
86
  continue
92
87
  project = load_lua_file(file_path)
93
88
  if "DESCRIPTION_SHORT" not in project:
94
- os.chdir(orig_folder)
95
89
  continue
96
90
  description_short = project["DESCRIPTION_SHORT"]
97
91
  if description_short != repo.description:
@@ -101,7 +95,6 @@ def fix_metadata() -> None:
101
95
  repo.edit(description=description_short)
102
96
  if "KEYWORDS" not in project:
103
97
  print(f"{folder} no keywords")
104
- os.chdir(orig_folder)
105
98
  continue
106
99
  keywords = project["KEYWORDS"]
107
100
  if set(keywords) != set(repo.get_topics()):
@@ -109,7 +102,6 @@ def fix_metadata() -> None:
109
102
  print(f"keywords is [{keywords}]")
110
103
  print(f"repo.get_topics() is [{repo.get_topics()}]")
111
104
  repo.replace_topics(keywords)
112
- os.chdir(orig_folder)
113
105
 
114
106
 
115
107
  @register_endpoint(
@@ -148,8 +140,8 @@ def homepage_fix() -> None:
148
140
  )
149
141
  def repos_json() -> None:
150
142
  for repo in yield_repos():
151
- # pylint: disable=protected-access
152
- json.dump(repo._rawData, fp=sys.stdout, indent=4)
143
+ json.dump(repo.raw_data, fp=sys.stdout, indent=4)
144
+ print()
153
145
 
154
146
 
155
147
  @register_endpoint(
@@ -189,20 +181,23 @@ def repos_list() -> None:
189
181
  for repo in yield_repos():
190
182
  if ConfigOutput.verbose:
191
183
  json.dump(obj=repo.raw_data, fp=sys.stdout, indent=4, sort_keys=True)
184
+ print()
192
185
  else:
193
186
  print(f"{repo.name}")
194
187
 
195
188
 
196
189
  @register_endpoint(
197
- description="Cleanup old failing or un-needed runs in all workflows in all repositories",
190
+ description="Cleanup old failing or un-needed runs, deployments, and releases in all repositories",
198
191
  configs=[
199
192
  ConfigGithub,
200
193
  ConfigOutput,
201
194
  ConfigAlgo,
202
195
  ],
203
196
  )
204
- def runs_cleanup() -> None:
197
+ def cleanup() -> None:
198
+ # pylint: disable=too-many-branches,too-many-statements
205
199
  for repo in yield_repos():
200
+ # 1. Cleanup workflow runs
206
201
  for workflow in repo.get_workflows():
207
202
  existing = 0
208
203
  for run in workflow.get_runs():
@@ -216,16 +211,61 @@ def runs_cleanup() -> None:
216
211
  if run.head_branch != "master":
217
212
  delete_it = True
218
213
  # if its not a paged build and it failed then delete it
219
- if workflow.name != "pages-build-deployment" and run.conclusion == "failure":
214
+ if workflow.name != "pages-build-deployment" and run.conclusion in (
215
+ "failure", "cancelled", "timed_out", "startup_failure", "action_required"
216
+ ):
220
217
  delete_it = True
221
218
  if existing >= 4:
222
219
  delete_it = True
223
220
  if delete_it:
224
221
  print(f"deleting {repo.name} {workflow.name} {run.head_branch} {run.conclusion} {run.url}")
225
- delete(run)
222
+ try:
223
+ run.delete()
224
+ except github.GithubException as e:
225
+ print(f"Failed to delete run: {e}")
226
226
  else:
227
227
  existing += 1
228
228
 
229
+ # 2. Cleanup deployments
230
+ existing_deployments = 0
231
+ for deployment in repo.get_deployments():
232
+ state = None
233
+ for status in deployment.get_statuses():
234
+ state = status.state
235
+ break
236
+
237
+ delete_it = False
238
+ if state in ("failure", "error") or existing_deployments >= 4:
239
+ delete_it = True
240
+ else:
241
+ existing_deployments += 1
242
+
243
+ if delete_it:
244
+ print(f"deleting deployment {repo.name} {deployment.id}")
245
+ try:
246
+ deployment.create_status("inactive")
247
+ except github.GithubException as e:
248
+ print(f"Failed to deactivate deployment: {e}")
249
+ try:
250
+ # pylint: disable=protected-access
251
+ status, _, _ = deployment._requester.requestJson("DELETE", deployment.url)
252
+ if status != 204:
253
+ print(f"Failed to delete deployment: HTTP {status}")
254
+ except github.GithubException as e:
255
+ print(f"Failed to delete deployment: {e}")
256
+
257
+ # 3. Cleanup releases
258
+ existing_releases = 0
259
+ for release in repo.get_releases():
260
+ if existing_releases >= 4:
261
+ print(f"deleting release {repo.name} {release.title}")
262
+ try:
263
+ release.delete_release()
264
+ except github.GithubException as e:
265
+ print(f"Failed to delete release: {e}")
266
+ else:
267
+ existing_releases += 1
268
+
229
269
 
230
270
  @register_endpoint(
231
271
  description="Show all runs in all workflows in all repos",
@@ -266,12 +306,8 @@ def runs_show_running() -> None:
266
306
  def runs_show_failing() -> None:
267
307
  for repo in yield_repos():
268
308
  for workflow in repo.get_workflows():
269
- for run in workflow.get_runs():
270
- last_run = run
271
- break
272
- else:
273
- continue
274
- if last_run.conclusion == "failure":
309
+ last_run = next(iter(workflow.get_runs()), None)
310
+ if last_run is not None and last_run.conclusion == "failure":
275
311
  print(f"{repo.name}: {workflow.name} {last_run.conclusion}")
276
312
 
277
313
 
@@ -285,12 +321,8 @@ def runs_show_failing() -> None:
285
321
  def runs_show_not_success() -> None:
286
322
  for repo in yield_repos():
287
323
  for workflow in repo.get_workflows():
288
- for run in workflow.get_runs():
289
- last_run = run
290
- break
291
- else:
292
- continue
293
- if last_run.conclusion != "success":
324
+ last_run = next(iter(workflow.get_runs()), None)
325
+ if last_run is not None and last_run.conclusion != "success":
294
326
  print(f"{repo.name}: {workflow.name} {last_run.conclusion}")
295
327
 
296
328
 
@@ -302,7 +334,6 @@ def runs_show_not_success() -> None:
302
334
  ],
303
335
  )
304
336
  def pull_all() -> None:
305
- orig_folder = os.getcwd()
306
337
  base_dir = get_base_dir()
307
338
  for repo in yield_repos():
308
339
  project = repo.name
@@ -310,15 +341,14 @@ def pull_all() -> None:
310
341
  if os.path.isdir(folder):
311
342
  if not os.path.isfile(os.path.join(folder, ".skip")):
312
343
  print(f"project [{project}] exists, pulling it...")
313
- os.chdir(folder)
314
344
  subprocess.check_call(
315
345
  [
316
346
  "git",
317
347
  "pull",
318
348
  # "--tags",
319
- ]
349
+ ],
350
+ cwd=folder,
320
351
  )
321
- os.chdir(orig_folder)
322
352
  else:
323
353
  print(f"project [{project}] exists, skipping it because of .skip file...")
324
354
  else:
@@ -1,5 +1,5 @@
1
1
  """ version which can be consumed from within the module """
2
- VERSION_STR = "0.0.60"
2
+ VERSION_STR = "0.0.62"
3
3
  DESCRIPTION = "Pygitpub will help you work with github"
4
4
  APP_NAME = "pygitpub"
5
5
  LOGGER_NAME = "pygitpub"
@@ -19,13 +19,6 @@ def get_number_of_files(folder: str) -> int:
19
19
  return count
20
20
 
21
21
 
22
- def delete(workflow_run):
23
- # stolen from
24
- # https://github.com/PyGithub/PyGithub/blob/master/github/WorkflowRun.py
25
- # which is not yet in released
26
- # pylint: disable=protected-access
27
- status, _, _ = workflow_run._requester.requestJson("DELETE", workflow_run.url)
28
- return status == 204
29
22
 
30
23
 
31
24
  def get_all_git_repos(base_dir: str) -> set[str]:
File without changes
File without changes