aboutsummaryrefslogtreecommitdiff
path: root/applications/gitlab/pipelines.py
blob: cd333f6211112e0186cb3c6c0896f18bfe46b18d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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