mirror of
https://github.com/actions/github-script.git
synced 2025-12-08 16:16:21 +00:00
Merge pull request #439 from actions/joshmgross/avoid-setting-base-url
Avoid setting `baseUrl` to undefined when input is not provided
This commit is contained in:
75
.github/workflows/integration.yml
vendored
75
.github/workflows/integration.yml
vendored
@@ -248,3 +248,78 @@ jobs:
|
|||||||
done <<< "$tests"
|
done <<< "$tests"
|
||||||
|
|
||||||
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
|
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
test-base-url:
|
||||||
|
name: 'Integration test: base-url option'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: ./.github/actions/install-dependencies
|
||||||
|
|
||||||
|
- id: base-url-default
|
||||||
|
name: API URL with base-url not set
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const endpoint = github.request.endpoint
|
||||||
|
return endpoint({}).url
|
||||||
|
result-encoding: string
|
||||||
|
|
||||||
|
- id: base-url-default-graphql
|
||||||
|
name: GraphQL URL with base-url not set
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const endpoint = github.request.endpoint
|
||||||
|
return endpoint({url: "/graphql"}).url
|
||||||
|
result-encoding: string
|
||||||
|
|
||||||
|
- id: base-url-set
|
||||||
|
name: API URL with base-url set
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
base-url: https://my.github-enterprise-server.com/api/v3
|
||||||
|
script: |
|
||||||
|
const endpoint = github.request.endpoint
|
||||||
|
return endpoint({}).url
|
||||||
|
result-encoding: string
|
||||||
|
|
||||||
|
- id: base-url-set-graphql
|
||||||
|
name: GraphQL URL with base-url set
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
base-url: https://my.github-enterprise-server.com/api/v3
|
||||||
|
script: |
|
||||||
|
const endpoint = github.request.endpoint
|
||||||
|
return endpoint({url: "/graphql"}).url
|
||||||
|
result-encoding: string
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
echo "- Validating API URL default"
|
||||||
|
expected="https://api.github.com/"
|
||||||
|
actual="${{steps.base-url-default.outputs.result}}"
|
||||||
|
if [[ "$expected" != "$actual" ]]; then
|
||||||
|
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "- Validating GraphQL URL default"
|
||||||
|
expected="https://api.github.com/graphql"
|
||||||
|
actual="${{steps.base-url-default-graphql.outputs.result}}"
|
||||||
|
if [[ "$expected" != "$actual" ]]; then
|
||||||
|
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "- Validating base-url set to a value"
|
||||||
|
expected="https://my.github-enterprise-server.com/api/v3/"
|
||||||
|
actual="${{steps.base-url-set.outputs.result}}"
|
||||||
|
if [[ "$expected" != "$actual" ]]; then
|
||||||
|
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "- Validating GraphQL URL with base-url set to a value"
|
||||||
|
expected="https://my.github-enterprise-server.com/api/v3/graphql"
|
||||||
|
actual="${{steps.base-url-set-graphql.outputs.result}}"
|
||||||
|
if [[ "$expected" != "$actual" ]]; then
|
||||||
|
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|||||||
8
dist/index.js
vendored
8
dist/index.js
vendored
@@ -35509,9 +35509,13 @@ async function main() {
|
|||||||
userAgent: userAgent || undefined,
|
userAgent: userAgent || undefined,
|
||||||
previews: previews ? previews.split(',') : undefined,
|
previews: previews ? previews.split(',') : undefined,
|
||||||
retry: retryOpts,
|
retry: retryOpts,
|
||||||
request: requestOpts,
|
request: requestOpts
|
||||||
baseUrl: baseUrl || undefined
|
|
||||||
};
|
};
|
||||||
|
// Setting `baseUrl` to undefined will prevent the default value from being used
|
||||||
|
// https://github.com/actions/github-script/issues/436
|
||||||
|
if (baseUrl) {
|
||||||
|
opts.baseUrl = baseUrl;
|
||||||
|
}
|
||||||
const github = (0,lib_github.getOctokit)(token, opts, plugin_retry_dist_node.retry, dist_node.requestLog);
|
const github = (0,lib_github.getOctokit)(token, opts, plugin_retry_dist_node.retry, dist_node.requestLog);
|
||||||
const script = core.getInput('script', { required: true });
|
const script = core.getInput('script', { required: true });
|
||||||
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
||||||
|
|||||||
@@ -44,8 +44,13 @@ async function main(): Promise<void> {
|
|||||||
userAgent: userAgent || undefined,
|
userAgent: userAgent || undefined,
|
||||||
previews: previews ? previews.split(',') : undefined,
|
previews: previews ? previews.split(',') : undefined,
|
||||||
retry: retryOpts,
|
retry: retryOpts,
|
||||||
request: requestOpts,
|
request: requestOpts
|
||||||
baseUrl: baseUrl || undefined
|
}
|
||||||
|
|
||||||
|
// Setting `baseUrl` to undefined will prevent the default value from being used
|
||||||
|
// https://github.com/actions/github-script/issues/436
|
||||||
|
if (baseUrl) {
|
||||||
|
opts.baseUrl = baseUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
const github = getOctokit(token, opts, retry, requestLog)
|
const github = getOctokit(token, opts, retry, requestLog)
|
||||||
|
|||||||
Reference in New Issue
Block a user