diff --git a/packages/github/__tests__/orchestration.test.ts b/packages/github/__tests__/orchestration.test.ts index 3b851ddb..0bda82f0 100644 --- a/packages/github/__tests__/orchestration.test.ts +++ b/packages/github/__tests__/orchestration.test.ts @@ -59,6 +59,14 @@ describe('orchestration ID support', () => { process.env['ACTIONS_ORCHESTRATION_ID'] = ' ' expect(getUserAgentWithOrchestrationId('my-app')).toBe('my-app') }) + + it('does not duplicate orchestration ID if already present in base', () => { + process.env['ACTIONS_ORCHESTRATION_ID'] = 'abc-123' + const alreadyTagged = 'my-app actions_orchestration_id/abc-123' + expect(getUserAgentWithOrchestrationId(alreadyTagged)).toBe( + alreadyTagged + ) + }) }) describe('public re-export', () => { @@ -110,5 +118,15 @@ describe('orchestration ID support', () => { const opts = getOctokitOptions('fake-token') expect(opts.userAgent).toBe('actions_orchestration_id/bad_chars_here_') }) + + it('does not duplicate orchestration ID when caller already applied it', () => { + process.env['ACTIONS_ORCHESTRATION_ID'] = 'test-orch-id' + const opts = getOctokitOptions('fake-token', { + userAgent: 'my-app actions_orchestration_id/test-orch-id' + }) + expect(opts.userAgent).toBe( + 'my-app actions_orchestration_id/test-orch-id' + ) + }) }) }) diff --git a/packages/github/src/internal/utils.ts b/packages/github/src/internal/utils.ts index 5ff4db52..03c5822a 100644 --- a/packages/github/src/internal/utils.ts +++ b/packages/github/src/internal/utils.ts @@ -49,8 +49,10 @@ export function getUserAgentWithOrchestrationId( const orchId = process.env['ACTIONS_ORCHESTRATION_ID']?.trim() if (orchId) { const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_') + const tag = `actions_orchestration_id/${sanitizedId}` + if (baseUserAgent?.includes(tag)) return baseUserAgent const ua = baseUserAgent ? `${baseUserAgent} ` : '' - return `${ua}actions_orchestration_id/${sanitizedId}` + return `${ua}${tag}` } return baseUserAgent }