Skip to content

feat(github): add orchestration ID to user-agent in getOctokitOptions#2364

Merged
salmanmkc merged 4 commits intoactions:mainfrom
salmanmkc:salmanmkc/orchestration-id-support
Apr 8, 2026
Merged

feat(github): add orchestration ID to user-agent in getOctokitOptions#2364
salmanmkc merged 4 commits intoactions:mainfrom
salmanmkc:salmanmkc/orchestration-id-support

Conversation

@salmanmkc
Copy link
Copy Markdown
Contributor

Summary

Appends actions_orchestration_id/{sanitizedId} to the user-agent string when the ACTIONS_ORCHESTRATION_ID environment variable is set. This follows the same pattern already used in @actions/http-client and @actions/attest.

Changes

packages/github/src/internal/utils.ts

  • Added getUserAgentWithOrchestrationId(baseUserAgent?) — reads env var, sanitizes with /[^a-z0-9_.-]/gi, appends to user-agent. Trims whitespace-only values.

packages/github/src/utils.ts

  • getOctokitOptions() now calls the helper to include orchestration ID automatically
  • Re-exports getUserAgentWithOrchestrationId for downstream consumers (e.g. actions/github-script) via @actions/github/lib/utils

packages/github/__tests__/orchestration.test.ts

  • 14 deterministic unit tests covering:
    • Helper function (env var present/absent, sanitization, whitespace, allowed chars)
    • getOctokitOptions integration (auto-append, preserve caller UA, no mutation)
    • Public re-export wiring verification

packages/github/RELEASES.md

  • Added 9.1.0 release notes

Why

Actions orchestration needs to track which orchestration triggered API calls. The http-client and attest packages already do this — @actions/github was the missing piece. This unblocks actions/github-script#708 from needing a local workaround.

Testing

All 14 tests pass. No existing tests affected.

When ACTIONS_ORCHESTRATION_ID is set, appends
actions_orchestration_id/{sanitizedId} to the user-agent string.

- Add getUserAgentWithOrchestrationId() to internal/utils.ts
- Wire into getOctokitOptions() so all getOctokit() calls include it
- Re-export helper from @actions/github/lib/utils for downstream consumers
- 14 deterministic unit tests covering helper, integration, edge cases
Copilot AI review requested due to automatic review settings April 7, 2026 16:16
@salmanmkc salmanmkc requested a review from a team as a code owner April 7, 2026 16:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for propagating the ACTIONS_ORCHESTRATION_ID into the Octokit user-agent via getOctokitOptions, aligning @actions/github with existing orchestration tracking behavior in other toolkit packages.

Changes:

  • Added getUserAgentWithOrchestrationId(baseUserAgent?) helper to read/sanitize ACTIONS_ORCHESTRATION_ID and append it to a user-agent string.
  • Updated getOctokitOptions() to automatically apply the orchestration ID user-agent suffix when present.
  • Added unit tests covering helper behavior, getOctokitOptions integration, and the public re-export; updated release notes.
Show a summary per file
File Description
packages/github/src/utils.ts Re-exports the helper and appends orchestration ID to opts.userAgent in getOctokitOptions.
packages/github/src/internal/utils.ts Introduces getUserAgentWithOrchestrationId (env read + sanitization + formatting).
packages/github/tests/orchestration.test.ts Adds coverage for helper, re-export wiring, and getOctokitOptions behavior.
packages/github/RELEASES.md Documents the new 9.1.0 behavior and export.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

export {getUserAgentWithOrchestrationId} from './internal/utils.js'

/**
* Convience function to correctly format Octokit Options to pass into the constructor.
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

Spelling: "Convience" should be "Convenience" in the JSDoc comment to avoid propagating the typo into generated docs/search results.

Suggested change
* Convience function to correctly format Octokit Options to pass into the constructor.
* Convenience function to correctly format Octokit Options to pass into the constructor.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

was already there, not related to change, good thing to fix tho

if (orchId) {
const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_')
const ua = baseUserAgent ? `${baseUserAgent} ` : ''
return `${ua}actions_orchestration_id/${sanitizedId}`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

will concat the string together cause invalid user-agent format?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The concatenation should be fine — the User-Agent spec (RFC 9110 §10.1.5) is just space-separated product/version tokens, and actions_orchestration_id/<sanitizedId> fits that since the ID is sanitized to [a-z0-9_.-].

Octokit already concatenates the same way internally (${options.userAgent} ${userAgentTrail}), so the final header ends up looking like:

actions_orchestration_id/abc123 octokit-core.js/6.1.3 Node.js/20

Also worth noting this is the same approach used by @actions/http-client and @actions/attest already in the toolkit.

baseUserAgent?: string
): string | undefined {
const orchId = process.env['ACTIONS_ORCHESTRATION_ID']?.trim()
if (orchId) {
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.

should we check if base user agent already contains the orchestration ID? Or is that unlikely?

ericsciple
ericsciple previously approved these changes Apr 8, 2026
Copy link
Copy Markdown
Contributor Author

@salmanmkc salmanmkc left a comment

Choose a reason for hiding this comment

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

Good catch — since getUserAgentWithOrchestrationId is exported as public API, downstream consumers (e.g., github-script) could call it directly while also using getOctokitOptions() which already appends the ID. A simple .includes() guard prevents double-appending.

Add idempotency check to getUserAgentWithOrchestrationId — if the
tag is already present in baseUserAgent, return it unchanged. This
prevents doubling when both the exported helper and getOctokitOptions
run for the same client.
@salmanmkc salmanmkc merged commit 14a0900 into actions:main Apr 8, 2026
25 of 27 checks passed
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