aboutsummaryrefslogtreecommitdiff
path: root/applications/gitlab/pipelines.py
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2025-05-06 20:49:19 -0500
committerGitHub <noreply@github.com>2025-05-06 20:49:19 -0500
commitd62f25007470fe546e0f9d2e38a26e84146f72c5 (patch)
treed85405346693e0800d2fa6d18a2d6bb2357513f6 /applications/gitlab/pipelines.py
parent714cb4c213f1c39dba62be4e401a7229afc4589a (diff)
downloadaudit-tools-d62f25007470fe546e0f9d2e38a26e84146f72c5.tar.gz
audit-tools-d62f25007470fe546e0f9d2e38a26e84146f72c5.tar.bz2
audit-tools-d62f25007470fe546e0f9d2e38a26e84146f72c5.zip
add gitlab pipelines.py script (#5)
* add gitlab pipelines.py script * Commit from GitHub Actions (Ruff) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'applications/gitlab/pipelines.py')
-rw-r--r--applications/gitlab/pipelines.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/applications/gitlab/pipelines.py b/applications/gitlab/pipelines.py
new file mode 100644
index 0000000..cd333f6
--- /dev/null
+++ b/applications/gitlab/pipelines.py
@@ -0,0 +1,59 @@
+"""
+Review CI/CD pipelines and their configurations for a specific GitLab project.
+"""
+
+import requests
+
+BASE_URL = "https://gitlab.com/api/v4"
+PRIVATE_TOKEN = "your_access_token"
+PROJECT_ID = "project_id"
+TIMEOUT = 30
+
+HEADERS = {"PRIVATE-TOKEN": PRIVATE_TOKEN}
+
+if __name__ == "__main__":
+ page = 1
+ per_page = 100
+
+ while True:
+ response = requests.get(
+ f"{BASE_URL}/projects/{PROJECT_ID}/pipelines",
+ headers=HEADERS,
+ params={"page": page, "per_page": per_page},
+ timeout=TIMEOUT,
+ )
+ if response.status_code == 200:
+ pipelines = response.json()
+ if not pipelines:
+ break
+
+ for pipeline in pipelines:
+ pipeline_id = pipeline["id"]
+ status = pipeline["status"]
+ ref = pipeline["ref"]
+ created_at = pipeline["created_at"]
+ duration = pipeline.get("duration", "N/A")
+
+ print(f"Pipeline ID: {pipeline_id}")
+ print(f" Status: {status}")
+ print(f" Ref: {ref}")
+ print(f" Created At: {created_at}")
+ print(f" Duration: {duration} seconds")
+
+ detail_response = requests.get(
+ f"{BASE_URL}/projects/{PROJECT_ID}/pipelines/{pipeline_id}",
+ headers=HEADERS,
+ timeout=TIMEOUT,
+ )
+ if detail_response.status_code == 200:
+ pipeline_details = detail_response.json()
+ print(f" Configuration: {pipeline_details.get('config', 'N/A')}")
+ else:
+ print(
+ f" Failed to fetch pipeline details: {detail_response.status_code}, {detail_response.text}"
+ )
+
+ page += 1
+ else:
+ print(f"Failed to fetch pipelines: {response.status_code}, {response.text}")
+ break