Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:
exit 1
fi
echo "- Validating user-agent set to an empty string"
expected="octokit-core.js/"
expected="actions/github-script octokit-core.js/"
if [[ "${{steps.user-agent-empty.outputs.result}}" != "$expected"* ]]; then
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-empty.outputs.result}}"
exit 1
Expand Down
18 changes: 17 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36267,9 +36267,11 @@ async function main() {
const retries = parseInt(core.getInput('retries'));
const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes'));
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults);
const baseUserAgent = userAgent || 'actions/github-script';
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent);
const opts = {
log: debug ? console : undefined,
userAgent: userAgent || undefined,
userAgent: finalUserAgent,
previews: previews ? previews.split(',') : undefined,
retry: retryOpts,
request: requestOpts
Expand Down Expand Up @@ -36313,6 +36315,20 @@ function handleError(err) {
console.error(err);
core.setFailed(`Unhandled error: ${err}`);
}
/**
* 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) {
const orchestrationId = process.env['ACTIONS_ORCHESTRATION_ID'];
if (!orchestrationId) {
return userAgent;
}
// Sanitize orchestration ID - replace invalid characters with underscore
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_');
return `${userAgent} actions_orchestration_id/${sanitized}`;
}

})();

Expand Down
22 changes: 21 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,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
Expand Down Expand Up @@ -96,3 +99,20 @@ function handleError(err: any): void {
console.error(err)
core.setFailed(`Unhandled error: ${err}`)
}

/**
* 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 - replace invalid characters with underscore
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_')

return `${userAgent} actions_orchestration_id/${sanitized}`
}
Loading