From 870cb69fde4d1bc401a464fe28c50847f4665e32 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Sat, 21 Jul 2018 22:28:37 +0200
Subject: [PATCH] Added script to remove unused artifacts from repository

---
 scripts/clean-unused-artifacts.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 scripts/clean-unused-artifacts.py

diff --git a/scripts/clean-unused-artifacts.py b/scripts/clean-unused-artifacts.py
new file mode 100644
index 0000000000..d38373b307
--- /dev/null
+++ b/scripts/clean-unused-artifacts.py
@@ -0,0 +1,30 @@
+import gitlab
+
+TOKEN = "CHANGEME"
+CLEAN_BEFORE = "2018-07"
+gl = gitlab.Gitlab("https://code.eliotberriot.com", private_token=TOKEN, per_page=100)
+project = gl.projects.get("funkwhale/funkwhale")
+
+jobs = project.jobs.list(as_list=False)
+total = jobs.total
+
+for job in jobs:
+    if job.attributes["ref"] != "develop":
+        continue
+    if job.attributes["status"] != "success":
+        continue
+    if job.attributes["tag"] is True:
+        continue
+    if job.attributes["name"] not in ["build_api", "build_front", "pages"]:
+        continue
+    if job.attributes["created_at"].startswith(CLEAN_BEFORE):
+        continue
+    relevant = {
+        "ref": job.attributes["ref"],
+        "status": job.attributes["status"],
+        "tag": job.attributes["tag"],
+        "name": job.attributes["name"],
+        "created_at": job.attributes["created_at"],
+    }
+    print("Deleting job {}!".format(job.id), relevant)
+    job.erase()
-- 
GitLab