mirror of
https://github.com/actions/github-script.git
synced 2026-02-07 19:47:26 +00:00
Simplify user-agent logic and update integration test
Co-authored-by: TingluoHuang <1750815+TingluoHuang@users.noreply.github.com>
This commit is contained in:
parent
c36bdc0a3a
commit
c0078b2072
3 changed files with 3 additions and 10 deletions
2
.github/workflows/integration.yml
vendored
2
.github/workflows/integration.yml
vendored
|
|
@ -167,7 +167,7 @@ jobs:
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "- Validating user-agent set to an empty string"
|
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
|
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}}"
|
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-empty.outputs.result}}"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
||||||
5
dist/index.js
vendored
5
dist/index.js
vendored
|
|
@ -36267,7 +36267,7 @@ async function main() {
|
||||||
const retries = parseInt(core.getInput('retries'));
|
const retries = parseInt(core.getInput('retries'));
|
||||||
const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes'));
|
const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes'));
|
||||||
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults);
|
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults);
|
||||||
const baseUserAgent = userAgent === '' ? '' : userAgent || 'actions/github-script';
|
const baseUserAgent = userAgent || 'actions/github-script';
|
||||||
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent);
|
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent);
|
||||||
const opts = {
|
const opts = {
|
||||||
log: debug ? console : undefined,
|
log: debug ? console : undefined,
|
||||||
|
|
@ -36327,9 +36327,6 @@ function getUserAgentWithOrchestrationId(userAgent) {
|
||||||
}
|
}
|
||||||
// Sanitize orchestration ID - replace invalid characters with underscore
|
// Sanitize orchestration ID - replace invalid characters with underscore
|
||||||
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_');
|
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_');
|
||||||
if (!sanitized) {
|
|
||||||
return userAgent;
|
|
||||||
}
|
|
||||||
return `${userAgent} orchestration-id/${sanitized}`;
|
return `${userAgent} orchestration-id/${sanitized}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,7 @@ async function main(): Promise<void> {
|
||||||
defaultGitHubOptions
|
defaultGitHubOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
const baseUserAgent =
|
const baseUserAgent = userAgent || 'actions/github-script'
|
||||||
userAgent === '' ? '' : userAgent || 'actions/github-script'
|
|
||||||
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent)
|
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent)
|
||||||
|
|
||||||
const opts: Options = {
|
const opts: Options = {
|
||||||
|
|
@ -114,9 +113,6 @@ function getUserAgentWithOrchestrationId(userAgent: string): string {
|
||||||
|
|
||||||
// Sanitize orchestration ID - replace invalid characters with underscore
|
// Sanitize orchestration ID - replace invalid characters with underscore
|
||||||
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_')
|
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_')
|
||||||
if (!sanitized) {
|
|
||||||
return userAgent
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${userAgent} orchestration-id/${sanitized}`
|
return `${userAgent} orchestration-id/${sanitized}`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue