Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ packages/*/__tests__/_temp/
.DS_Store
*.xar
packages/*/audit.json
.nx/
4 changes: 2 additions & 2 deletions packages/artifact/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/cache/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions packages/http-client/__tests__/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
11 changes: 10 additions & 1 deletion packages/http-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ 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)
Expand Down Expand Up @@ -816,6 +817,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<void> {
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber)
const ms: number = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber)
Expand Down