codefresh-release-stats

A Python script to count Codefresh Kubernetes releases per cluster over the last week.

https://github.com/davidbmar/codefresh  ·  private  ·  shipped

What it is

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.

Features

Quickstart

pip install requests
python codefresh.py

Architecture

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]

How it's built

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.

How it runs

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

How to apply & reuse

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.

At a glance

CapabilitiesAPI IntegrationData FilteringCLI Reporting
ComponentsHTTP ClientJSON ParserDate CalculatorLoop Controller
TechPythonRequestsJSONDatetime
Depends onrequestspython3
Integrates withCodefresh API
PatternsScriptingPollingFilter-Map-Reduce
Reuse tagsdevopsmonitoringcodefreshkubernetespython-script

Repo hygiene

✓ all on main — nothing unmerged.