Skip to content

feat: add commit activities endpoint under v1-alpha - #2238

Merged
epipav merged 3 commits into
mainfrom
feat/IN-1332-commit-activities
Sep 21, 2026
Merged

epipav merged 3 commits into
mainfrom
feat/IN-1332-commit-activities

Conversation

@epipav

@epipav epipav commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds GET /v1-alpha/projects/{slug}/development/commit-activities, a port of the Nuxt commit-activities widget handler (frontend/server/api/widget/development/commit-activities.get.ts) to the public API.

Query: repos[], startDate, endDate (shared DateRangeQuery, YYYY-MM-DD UTC days), granularity (required: daily, weekly, monthly, quarterly, yearly) and countType (new by default, or cumulative).

Response:

{
  "summary": {
    "current": 120,
    "previous": 100,
    "percentageChange": 20,
    "changeValue": 20,
    "periodFrom": "2025-01-01T00:00:00Z",
    "periodTo": "2025-03-31T00:00:00Z"
  },
  "data": [
    { "startDate": "2025-01-01T00:00:00Z", "endDate": "2025-01-31T00:00:00Z", "commits": 40 }
  ]
}

Behind it: one project_buckets lookup, then the same three concurrent Tinybird calls Nuxt makes (activities_count twice for the current and previous summaries, and activities_count or activities_cumulative_count for the series), with the same fixed parameters (activity_type=authored-commit, onlyContributions=true, includeCodeContributions=true, includeCollaborations=false) and Nuxt's YYYY-MM-DD 00:00:00 date format.

Changes vs. the Nuxt handler

  • type (ignored by the handler) and activityType (always authored-commit from the UI) are gone; project/collectionSlug are replaced by the path slug.
  • granularity is required. Without it the series pipe falls into summary mode and returns rows without bucket dates.
  • countType only selects the series pipe; it is no longer forwarded to Tinybird.
  • periodFrom/periodTo and the bucket startDate/endDate are ISO-8601 UTC (2025-01-01T00:00:00Z); Nuxt returned Luxon strings and raw pipe dates.
  • percentageChange is signed (Nuxt used Math.abs); a drop reads negative like changeValue.
  • An unknown slug is a 200 with a zero summary and data: [] (Nuxt returned 404); the epic's definition of done for metric endpoints.
  • Any Tinybird failure, bucket lookup included, is a 503 upstream_unavailable; Tinybird's own status never reaches the caller. An inverted date range is a 400 invalid_request.

Decisions

  • The bucket is resolved once with client.getBucketIdForProject(slug) and passed as bucketId on the three pipe calls. api/ has no bucket cache, so letting the client resolve it per call would mean three lookups per request.
  • Every pipe call gets the resolved range. getPreviousDates fills the default (2010-01-01 to today) and the previous window, and both are sent on every call, so periodFrom/periodTo match what was counted.
  • The summary block keeps the PeriodSummary keys and types but describes the counts as commits, so the OpenAPI reference states the unit of every field. Bucket keys stay startDate/endDate/commits, the keys the Nuxt data layer actually emits.
  • Helpers (tinybirdDay, toUtcDateTime, the described granularity/countType schemas, the summary schema) live in the route file on purpose; the five Development PRs run in parallel and a consolidation chore follows once they merge.

Tests

api/tests/development-commit-activities.test.ts: 27 integration tests against the real buildApp() and Tinybird client, with fetch stubbed per pipe path. They cover the response shape and key stripping, the exact Tinybird calls and their concurrency, countType, granularity, omitted and invalid dates, the unknown slug, every Tinybird failure class, Cache-Control, and the OpenAPI document (tag, parameters, a description on every field, /v1 exclusion).

pnpm test (189 tests, 14 files), pnpm tsc-check, pnpm lint and pnpm format:check pass in api/.

Includes the routing-test parser fix from the base branch (62b136b): version-routing.test.ts now reads nested route paths, which this is the first route to produce.

Based on main, which includes #2241 (IN-1348, directory-based route registration) as dd37a7a. Jira: IN-1332

Copilot AI balanced review requested due to automatic review settings September 21, 2026 11:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Malformed successful Tinybird responses can bypass error mapping and produce generic 500 responses.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds the /v1-alpha commit-activities metric endpoint backed by Tinybird.

Changes:

  • Adds schemas, date conversion, aggregation, and upstream error handling.
  • Registers the route and adds comprehensive integration/OpenAPI tests.
File Description
api/​src/​versions/​v1-alpha/​development/​commit-activities.ts Implements the endpoint.
api/​src/​versions/​v1-alpha/​index.ts Registers the route plugin.
api/​tests/​development-commit-activities.test.ts Tests behavior, failures, caching, and OpenAPI.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread api/src/versions/v1-alpha/development/commit-activities.ts Outdated
Copilot AI review requested due to automatic review settings September 21, 2026 11:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Malformed Tinybird row fields can still bypass upstream error mapping and cause invalid responses or generic 500 errors.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread api/src/versions/v1-alpha/development/commit-activities.ts
@epipav epipav self-assigned this Sep 21, 2026

@gaspergrom gaspergrom left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked that countType picks between activities_count and activities_cumulative_count without being forwarded to Tinybird, and the concurrency test proves the three pipe calls run in parallel rather than just counting calls. Error mapping and the unknown slug path are well covered too.

Base automatically changed from feat/IN-1345-project-endpoint to main September 21, 2026 12:26
@epipav
epipav force-pushed the feat/IN-1332-commit-activities branch from f5360d6 to f0976cc Compare September 21, 2026 12:30
Copilot AI review requested due to automatic review settings September 21, 2026 12:39
@epipav
epipav force-pushed the feat/IN-1332-commit-activities branch from f0976cc to e0adda1 Compare September 21, 2026 12:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation is complete, consistent with existing API patterns, and thoroughly tested.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@themarolt themarolt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - one question on the omitted-startDate path, rest reads clean against the Nuxt handler

Comment thread api/src/versions/v1-alpha/development/commit-activities.ts Outdated
Copilot AI review requested due to automatic review settings September 21, 2026 12:54
@epipav
epipav force-pushed the feat/IN-1332-commit-activities branch from e0adda1 to bc805c8 Compare September 21, 2026 12:54
@epipav
epipav changed the base branch from main to refactor/IN-1348-autoload-routes September 21, 2026 12:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The public API documentation incorrectly guarantees equal-length comparison periods.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

Comment thread api/src/versions/v1-alpha/development/commit-activities.ts
Base automatically changed from refactor/IN-1348-autoload-routes to main September 21, 2026 14:16
@epipav
epipav force-pushed the feat/IN-1332-commit-activities branch from bc805c8 to 51bdd99 Compare September 21, 2026 14:17
Copilot AI review requested due to automatic review settings September 21, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The public documentation incorrectly promises equal-length comparison periods despite calendar-based periods having different elapsed day counts.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation and coverage are coherent; only a non-blocking PR-description inconsistency remains.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (1)

Comment thread api/src/versions/v1-alpha/development/commit-activities.ts
@epipav
epipav merged commit 90ca137 into main Sep 21, 2026
12 checks passed
@epipav
epipav deleted the feat/IN-1332-commit-activities branch September 21, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants