Add ACTIONS_ORCHESTRATION_ID to user-agent string

Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-06 21:10:26 +00:00
parent 4389015762
commit d053ab3e3c
3 changed files with 117 additions and 2 deletions

View File

@@ -23,6 +23,26 @@ type Options = {
request?: RequestRequestOptions
}
/**
* Gets the user agent string with orchestration ID appended if available
* @param userAgent The base user agent string
* @returns The user agent string with orchestration ID appended if ACTIONS_ORCHESTRATION_ID is set
*/
function getUserAgentWithOrchestrationId(userAgent: string): string {
const orchestrationId = process.env['ACTIONS_ORCHESTRATION_ID']
if (!orchestrationId) {
return userAgent
}
// Sanitize orchestration ID - only keep alphanumeric, dots, and hyphens
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9.-]/g, '')
if (!sanitized) {
return userAgent
}
return `${userAgent} orchestration-id/${sanitized}`
}
async function main(): Promise<void> {
const token = core.getInput('github-token', {required: true})
const debug = core.getBooleanInput('debug')
@@ -39,9 +59,12 @@ async function main(): Promise<void> {
defaultGitHubOptions
)
const baseUserAgent = userAgent || 'actions/github-script'
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent)
const opts: Options = {
log: debug ? console : undefined,
userAgent: userAgent || undefined,
userAgent: finalUserAgent,
previews: previews ? previews.split(',') : undefined,
retry: retryOpts,
request: requestOpts