feat(github): append orchestration ID to user-agent in getOctokitOptions
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
This commit is contained in:
@@ -42,3 +42,15 @@ export function getProxyFetch(destinationUrl): typeof fetch {
|
||||
export function getApiBaseUrl(): string {
|
||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
||||
}
|
||||
|
||||
export function getUserAgentWithOrchestrationId(
|
||||
baseUserAgent?: string
|
||||
): string | undefined {
|
||||
const orchId = process.env['ACTIONS_ORCHESTRATION_ID']?.trim()
|
||||
if (orchId) {
|
||||
const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_')
|
||||
const ua = baseUserAgent ? `${baseUserAgent} ` : ''
|
||||
return `${ua}actions_orchestration_id/${sanitizedId}`
|
||||
}
|
||||
return baseUserAgent
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ export const GitHub = Octokit.plugin(
|
||||
paginateRest
|
||||
).defaults(defaults)
|
||||
|
||||
export {getUserAgentWithOrchestrationId} from './internal/utils.js'
|
||||
|
||||
/**
|
||||
* Convience function to correctly format Octokit Options to pass into the constructor.
|
||||
*
|
||||
@@ -41,5 +43,13 @@ export function getOctokitOptions(
|
||||
opts.auth = auth
|
||||
}
|
||||
|
||||
// Orchestration ID
|
||||
const userAgent = Utils.getUserAgentWithOrchestrationId(
|
||||
opts.userAgent as string | undefined
|
||||
)
|
||||
if (userAgent) {
|
||||
opts.userAgent = userAgent
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user