mirror of
https://github.com/actions/github-script.git
synced 2026-04-07 14:49:25 +00:00
Move helper method to end of file and revert package-lock.json changes
Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>
This commit is contained in:
parent
728b23b52d
commit
8a9be95424
3 changed files with 40 additions and 58 deletions
40
src/main.ts
40
src/main.ts
|
|
@ -23,26 +23,6 @@ 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, hyphens, and underscores
|
||||
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')
|
||||
|
|
@ -119,3 +99,23 @@ 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 - only keep alphanumeric, dots, hyphens, and underscores
|
||||
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '')
|
||||
if (!sanitized) {
|
||||
return userAgent
|
||||
}
|
||||
|
||||
return `${userAgent} orchestration-id/${sanitized}`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue