pygitpub 0.0.60__tar.gz → 0.0.61__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.61
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.61
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.61
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.61"
8
8
  requires-python = ">=3.14"
9
9
  authors = [
10
10
  { name = "Mark Veltzer", email = "mark.veltzer@gmail.com" }
@@ -194,15 +194,17 @@ def repos_list() -> None:
194
194
 
195
195
 
196
196
  @register_endpoint(
197
- description="Cleanup old failing or un-needed runs in all workflows in all repositories",
197
+ description="Cleanup old failing or un-needed runs, deployments, and releases in all repositories",
198
198
  configs=[
199
199
  ConfigGithub,
200
200
  ConfigOutput,
201
201
  ConfigAlgo,
202
202
  ],
203
203
  )
204
- def runs_cleanup() -> None:
204
+ def cleanup() -> None:
205
+ # pylint: disable=too-many-branches
205
206
  for repo in yield_repos():
207
+ # 1. Cleanup workflow runs
206
208
  for workflow in repo.get_workflows():
207
209
  existing = 0
208
210
  for run in workflow.get_runs():
@@ -216,7 +218,9 @@ def runs_cleanup() -> None:
216
218
  if run.head_branch != "master":
217
219
  delete_it = True
218
220
  # if its not a paged build and it failed then delete it
219
- if workflow.name != "pages-build-deployment" and run.conclusion == "failure":
221
+ if workflow.name != "pages-build-deployment" and run.conclusion in (
222
+ "failure", "cancelled", "timed_out", "startup_failure", "action_required"
223
+ ):
220
224
  delete_it = True
221
225
  if existing >= 4:
222
226
  delete_it = True
@@ -226,6 +230,46 @@ def runs_cleanup() -> None:
226
230
  else:
227
231
  existing += 1
228
232
 
233
+ # 2. Cleanup deployments
234
+ existing_deployments = 0
235
+ for deployment in repo.get_deployments():
236
+ state = None
237
+ for status in deployment.get_statuses():
238
+ state = status.state
239
+ break
240
+
241
+ delete_it = False
242
+ if state in ("failure", "error") or existing_deployments >= 4:
243
+ delete_it = True
244
+ else:
245
+ existing_deployments += 1
246
+
247
+ if delete_it:
248
+ print(f"deleting deployment {repo.name} {deployment.id}")
249
+ try:
250
+ deployment.create_status("inactive")
251
+ except github.GithubException as e:
252
+ print(f"Failed to deactivate deployment: {e}")
253
+ try:
254
+ # pylint: disable=protected-access
255
+ status, _, _ = deployment._requester.requestJson("DELETE", deployment.url)
256
+ if status != 204:
257
+ print(f"Failed to delete deployment: HTTP {status}")
258
+ except github.GithubException as e:
259
+ print(f"Failed to delete deployment: {e}")
260
+
261
+ # 3. Cleanup releases
262
+ existing_releases = 0
263
+ for release in repo.get_releases():
264
+ if existing_releases >= 4:
265
+ print(f"deleting release {repo.name} {release.title}")
266
+ try:
267
+ release.delete_release()
268
+ except github.GithubException as e:
269
+ print(f"Failed to delete release: {e}")
270
+ else:
271
+ existing_releases += 1
272
+
229
273
 
230
274
  @register_endpoint(
231
275
  description="Show all runs in all workflows in all repos",
@@ -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.61"
3
3
  DESCRIPTION = "Pygitpub will help you work with github"
4
4
  APP_NAME = "pygitpub"
5
5
  LOGGER_NAME = "pygitpub"
File without changes
File without changes