From 8b78620c2c39c996007212616a586a8644ae7e33 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Mon, 7 Apr 2025 22:52:59 -0500 Subject: Gitlab enhancements (#2) * add various in-progress scripts for gitlab * Commit from GitHub Actions (Ruff) * add gitlab results for free-tier tools * Commit from GitHub Actions (Ruff) * add gitlab results for ultimate-tier tools * Commit from GitHub Actions (Ruff) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- applications/gitlab/approvals.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 applications/gitlab/approvals.py (limited to 'applications/gitlab/approvals.py') diff --git a/applications/gitlab/approvals.py b/applications/gitlab/approvals.py new file mode 100644 index 0000000..b6ea3ef --- /dev/null +++ b/applications/gitlab/approvals.py @@ -0,0 +1,38 @@ +""" +Extract merge request approval rules and their statuses in GitLab. +""" + +import requests + +BASE_URL = "https://gitlab.com/api/v4" +PRIVATE_TOKEN = "your_access_token" +PROJECT_ID = "your_project_id" +TIMEOUT = 30 + +URL = f"{BASE_URL}/projects/{PROJECT_ID}/approval_rules" +HEADERS = {"PRIVATE-TOKEN": PRIVATE_TOKEN} + +if __name__ == "__main__": + # Get approval rules + response = requests.get(URL, headers=HEADERS, timeout=TIMEOUT) + if response.status_code == 200: + approval_rules = response.json() + for rule in approval_rules: + name = rule["name"] + approvals_required = rule["approvals_required"] + rule_type = rule["rule_type"] + protected_branches = rule["protected_branches"] + eligible_approvers = rule["eligible_approvers"] + print(f"Rule: {name}") + print(f" Approvals Required: {approvals_required}") + print(f" Rule type: {rule_type}") + for branch in protected_branches: + branch_name = branch["name"] + print(f" Protected Branch: {branch_name}") + for approver in eligible_approvers: + approver_username = approver["name"] + print(f" Eligible Approver: {approver_username}") + else: + print( + f"Failed to fetch approval rules: {response.status_code}, {response.text}" + ) -- cgit v1.2.3-70-g09d2