A Python script to count Codefresh Kubernetes releases per cluster over the last week.
https://github.com/davidbmar/codefresh · private · shipped
A lightweight CLI utility that queries the Codefresh API to retrieve Kubernetes release events for specified selectors (clusters) and calculates the number of deployments occurring within the previous seven days. It outputs raw status codes and aggregate counts to stdout.
pip install requests python codefresh.py
flowchart TD
A[User] -->|Executes| B(codefresh.py)
B -->|Reads Config| C[Access Token & Selectors]
B -->|HTTP GET| D[Codefresh API]
D -->|JSON Response| B
B -->|Parses Timestamps| E[DateTime Logic]
E -->|Filters Last 7 Days| F[Count Aggregator]
F -->|Prints| G[Stdout]
Built with Python 3 using the `requests` library for HTTP communication and `datetime` for time-window calculations. It iterates through a hardcoded list of cluster selectors, authenticates via Bearer token, fetches release metadata, parses Unix timestamps, and filters results based on the current date minus seven days.
sequenceDiagram
participant User
participant Script as codefresh.py
participant API as Codefresh API
User->>Script: Execute script
loop For each cluster in selectors
Script->>API: GET /api/kubernetes/releases?selector={cluster}
API-->>Script: JSON Response (Releases)
Script->>Script: Parse JSON & Extract createdAt
Script->>Script: Filter by last 7 days
Script->>User: Print Status Code & Count
end
Use this script for quick operational audits or dashboarding inputs to track deployment frequency across different environments (e.g., production, internal, external). It requires manual configuration of the API access token and selector list within the source code before execution.
✓ all on main — nothing unmerged.