Skip to content

feat: forward PR and release metadata to CI run endpoint#5

Merged
KYN4 merged 1 commit into
mainfrom
feat/ci-metadata
Apr 20, 2026
Merged

feat: forward PR and release metadata to CI run endpoint#5
KYN4 merged 1 commit into
mainfrom
feat/ci-metadata

Conversation

@KYN4
Copy link
Copy Markdown
Contributor

@KYN4 KYN4 commented Apr 20, 2026

Summary

The testing-service /api/v1/ci/run contract gained three optional fields: prNumber, prTitle, releaseName. This PR auto-detects them from the GitHub event payload and forwards them.

Changes

  • src/ci-metadata.ts (new): getCiMetadata() reads GITHUB_EVENT_PATH and extracts:
    • prNumber + prTitle from pull_request / pull_request_target events
    • releaseName from release events (falls back to tag_name when name is empty)
    • Best-effort — returns {} for events that don't carry this metadata (push, workflow_dispatch, etc.), never throws
  • src/api.ts: extended TriggerRunRequest with the three new optional fields (camelCase, matches the Pydantic alias generator on the server)
  • src/main.ts: wires getCiMetadata() into the triggerRun call

Design notes

No new action inputs — metadata is fully auto-detected, keeping the action zero-config. Consistent with how commit-title defaults to event payload detection. If explicit override inputs are wanted later, they're an additive change.

Summary by CodeRabbit

  • New Features
    • The action now captures pull request metadata (PR number and PR title) from CI and includes it when triggering runs, improving traceability and making it easier to link runs back to originating PRs.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

📝 Walkthrough

Walkthrough

Adds CI metadata extraction and propagates PR number and PR title into the trigger run request payload sent to the CI API.

Changes

Cohort / File(s) Summary
API Interface
src/api.ts
Extended TriggerRunRequest to include optional prNumber?: number and prTitle?: string. Payload serialization unchanged.
CI Metadata Extraction
src/ci-metadata.ts
Added new module exporting CiMetadata and getCiMetadata() which reads GITHUB_EVENT_PATH, safely parses the event JSON, and best-effort extracts prNumber and prTitle for pull_request events; never throws.
Main Integration
src/main.ts
run() now calls getCiMetadata() and includes ciMetadata.prNumber and ciMetadata.prTitle in the triggerRun(...) request payload.

Sequence Diagram

sequenceDiagram
    participant Main as main.ts
    participant CiMeta as getCiMetadata()
    participant GHEnv as GitHub Actions (env)
    participant API as triggerRun API

    Main->>CiMeta: getCiMetadata()
    CiMeta->>GHEnv: read GITHUB_EVENT_PATH
    GHEnv-->>CiMeta: event JSON
    CiMeta->>CiMeta: parse & extract prNumber, prTitle
    CiMeta-->>Main: return CiMetadata
    Main->>API: triggerRun(request + prNumber, prTitle)
    API-->>Main: response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 I nibble event JSON late at night,
I pull the PR number into light,
A tiny title tucked in my paw,
Sent with the run — precise and raw,
Hop, hop, the CI hums with delight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the main change: forwarding PR and release metadata to the CI run endpoint, which aligns with the core objective of adding metadata detection and forwarding.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ci-metadata

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/ci-metadata.ts (1)

24-28: Include parse/read error details in the warning.

Current warning loses the root cause, making troubleshooting harder in CI logs.

Proposed patch
-  } catch {
-    core.warning('Failed to read GitHub event payload for CI metadata')
+  } catch (error) {
+    core.warning(
+      `Failed to read GitHub event payload for CI metadata: ${
+        error instanceof Error ? error.message : String(error)
+      }`,
+    )
     return {}
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ci-metadata.ts` around lines 24 - 28, The warning in the try/catch around
JSON.parse(fs.readFileSync(eventPath, 'utf-8')) discards the thrown error;
update the catch to capture the exception (e.g., catch (err)) and include its
message/stack in the core.warning call so the log shows the read/parse failure
details for eventPath and the variable/event name (event). Keep the behavior of
returning {} but ensure core.warning contains both a descriptive message and the
error details to aid debugging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/ci-metadata.ts`:
- Around line 24-28: The warning in the try/catch around
JSON.parse(fs.readFileSync(eventPath, 'utf-8')) discards the thrown error;
update the catch to capture the exception (e.g., catch (err)) and include its
message/stack in the core.warning call so the log shows the read/parse failure
details for eventPath and the variable/event name (event). Keep the behavior of
returning {} but ensure core.warning contains both a descriptive message and the
error details to aid debugging.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2945056d-1bd2-489e-ac1b-b53e82993e1b

📥 Commits

Reviewing files that changed from the base of the PR and between f390cd3 and a6fd43a.

📒 Files selected for processing (3)
  • src/api.ts
  • src/ci-metadata.ts
  • src/main.ts

Auto-detect prNumber and prTitle from pull_request / pull_request_target
events via GITHUB_EVENT_PATH and forward them to the updated
/api/v1/ci/run contract. Best-effort — no-op on events that don't carry
PR metadata, no new action inputs required.
@KYN4 KYN4 force-pushed the feat/ci-metadata branch from f2ad835 to d05af3e Compare April 20, 2026 13:30
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/ci-metadata.ts (1)

22-26: Include the parse/read error detail in the warning for debuggability.

Current warning is generic; adding the caught error message makes failed event parsing much easier to triage in Actions logs.

💡 Proposed patch
-  } catch {
-    core.warning('Failed to read GitHub event payload for CI metadata')
+  } catch (error) {
+    core.warning(
+      `Failed to read GitHub event payload for CI metadata: ${
+        error instanceof Error ? error.message : String(error)
+      }`,
+    )
     return {}
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ci-metadata.ts` around lines 22 - 26, The catch block in
src/ci-metadata.ts swallows the JSON read/parse error making debugging hard;
update the try/catch around JSON.parse(fs.readFileSync(eventPath, 'utf-8')) to
capture the thrown error (e.g., catch (err)) and include the error message (and
optionally eventPath) in the core.warning call so the log reads something like
"Failed to read GitHub event payload for CI metadata: <error>". Reference the
event/eventPath usage and the core.warning call when applying the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/ci-metadata.ts`:
- Around line 4-7: Update the CiMetadata type and the getCiMetadata() extractor
to include an optional releaseName string and ensure release-triggered runs
populate it: add releaseName?: string to the CiMetadata interface and in
getCiMetadata() detect release payloads (or the release object) and set
releaseName = release.name || release.tag_name (falling back to tag_name when
name is empty); keep existing prNumber/prTitle handling for PR runs and ensure
callers expecting releaseName will receive undefined for non-release runs.

---

Nitpick comments:
In `@src/ci-metadata.ts`:
- Around line 22-26: The catch block in src/ci-metadata.ts swallows the JSON
read/parse error making debugging hard; update the try/catch around
JSON.parse(fs.readFileSync(eventPath, 'utf-8')) to capture the thrown error
(e.g., catch (err)) and include the error message (and optionally eventPath) in
the core.warning call so the log reads something like "Failed to read GitHub
event payload for CI metadata: <error>". Reference the event/eventPath usage and
the core.warning call when applying the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ef71d417-f294-43d2-9019-1b78c24d45b7

📥 Commits

Reviewing files that changed from the base of the PR and between a6fd43a and d05af3e.

📒 Files selected for processing (3)
  • src/api.ts
  • src/ci-metadata.ts
  • src/main.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main.ts
  • src/api.ts

Comment thread src/ci-metadata.ts
Comment on lines +4 to +7
export interface CiMetadata {
prNumber?: number
prTitle?: string
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Missing releaseName extraction required by the new CI contract.

CiMetadata and getCiMetadata() currently only support PR fields. The PR objective includes releaseName (with fallback to tag_name when name is empty), so release-triggered runs will silently drop required metadata.

💡 Proposed patch
 export interface CiMetadata {
   prNumber?: number
   prTitle?: string
+  releaseName?: string
 }
@@
- * - `pull_request` / `pull_request_target` events → `prNumber`, `prTitle`
+ * - `pull_request` / `pull_request_target` events → `prNumber`, `prTitle`
+ * - `release` events → `releaseName` (fallback to `tag_name` when `name` is empty)
@@
   const pr = event?.pull_request as
     | { number?: number; title?: string }
     | undefined
@@
   }
+
+  const release = event?.release as
+    | { name?: string; tag_name?: string }
+    | undefined
+  if (release) {
+    const name =
+      typeof release.name === 'string' ? release.name.trim() : ''
+    const tagName =
+      typeof release.tag_name === 'string' ? release.tag_name.trim() : ''
+    if (name) metadata.releaseName = name
+    else if (tagName) metadata.releaseName = tagName
+  }

Also applies to: 9-16, 29-51

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ci-metadata.ts` around lines 4 - 7, Update the CiMetadata type and the
getCiMetadata() extractor to include an optional releaseName string and ensure
release-triggered runs populate it: add releaseName?: string to the CiMetadata
interface and in getCiMetadata() detect release payloads (or the release object)
and set releaseName = release.name || release.tag_name (falling back to tag_name
when name is empty); keep existing prNumber/prTitle handling for PR runs and
ensure callers expecting releaseName will receive undefined for non-release
runs.

@KYN4 KYN4 self-assigned this Apr 20, 2026
@KYN4 KYN4 merged commit ffe5849 into main Apr 20, 2026
2 checks passed
@KYN4 KYN4 deleted the feat/ci-metadata branch April 20, 2026 13:37
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.

1 participant