From 06bfbce3a12ea8e3fd572df58144f75f8a62ef91 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 6 Jan 2026 15:32:55 +0000 Subject: [PATCH] Add ACTIONS_ORCHESTRATION_ID support to http-client user-agent Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com> --- __tests__/basics.test.ts | 31 +++++++++++++++++++++++++++++++ src/index.ts | 10 +++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/__tests__/basics.test.ts b/__tests__/basics.test.ts index 254a8ec..159cf7b 100644 --- a/__tests__/basics.test.ts +++ b/__tests__/basics.test.ts @@ -374,4 +374,35 @@ describe('basics', () => { httpm.MediaTypes.ApplicationJson ) }) + + it('appends orchestration ID to user-agent when ACTIONS_ORCHESTRATION_ID is set', async () => { + const orchId = 'test-orch-id-12345' + process.env['ACTIONS_ORCHESTRATION_ID'] = orchId + + const http: httpm.HttpClient = new httpm.HttpClient('http-client-tests') + const res: httpm.HttpClientResponse = await http.get( + 'https://postman-echo.com/get' + ) + expect(res.message.statusCode).toBe(200) + const body: string = await res.readBody() + const obj = JSON.parse(body) + expect(obj.headers['user-agent']).toBe( + `http-client-tests (gh_orch_id:${orchId})` + ) + + delete process.env['ACTIONS_ORCHESTRATION_ID'] + }) + + it('does not modify user-agent when ACTIONS_ORCHESTRATION_ID is not set', async () => { + delete process.env['ACTIONS_ORCHESTRATION_ID'] + + const http: httpm.HttpClient = new httpm.HttpClient('http-client-tests') + const res: httpm.HttpClientResponse = await http.get( + 'https://postman-echo.com/get' + ) + expect(res.message.statusCode).toBe(200) + const body: string = await res.readBody() + const obj = JSON.parse(body) + expect(obj.headers['user-agent']).toBe('http-client-tests') + }) }) diff --git a/src/index.ts b/src/index.ts index 5691e89..51a01ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -599,7 +599,7 @@ export class HttpClient { info.options.method = method info.options.headers = this._mergeHeaders(headers) if (this.userAgent != null) { - info.options.headers['user-agent'] = this.userAgent + info.options.headers['user-agent'] = this._getUserAgentWithOrchestrationId(this.userAgent) } info.options.agent = this._getAgent(info.parsedUrl) @@ -816,6 +816,14 @@ export class HttpClient { return proxyAgent } + private _getUserAgentWithOrchestrationId(userAgent: string): string { + const orchId = process.env['ACTIONS_ORCHESTRATION_ID'] + if (orchId) { + return `${userAgent} (gh_orch_id:${orchId})` + } + return userAgent + } + private async _performExponentialBackoff(retryNumber: number): Promise { retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber) const ms: number = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber)