Skip to content

Commit d319f8f

Browse files
committed
Avoid setting baseUrl to undefined when input is not provided
1 parent e69ef54 commit d319f8f

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

.github/workflows/integration.yml

+75
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,78 @@ jobs:
248248
done <<< "$tests"
249249
250250
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
251+
252+
test-base-url:
253+
name: 'Integration test: base-url option'
254+
runs-on: ubuntu-latest
255+
steps:
256+
- uses: actions/checkout@v3
257+
- uses: ./.github/actions/install-dependencies
258+
259+
- id: base-url-default
260+
name: API URL with base-url not set
261+
uses: ./
262+
with:
263+
script: |
264+
const endpoint = github.request.endpoint
265+
return endpoint({}).url
266+
result-encoding: string
267+
268+
- id: base-url-default-graphql
269+
name: GraphQL URL with base-url not set
270+
uses: ./
271+
with:
272+
script: |
273+
const endpoint = github.request.endpoint
274+
return endpoint({url: "/graphql"}).url
275+
result-encoding: string
276+
277+
- id: base-url-set
278+
name: API URL with base-url set
279+
uses: ./
280+
with:
281+
base-url: https://my.github-enterprise-server.com/api/v3
282+
script: |
283+
const endpoint = github.request.endpoint
284+
return endpoint({}).url
285+
result-encoding: string
286+
287+
- id: base-url-set-graphql
288+
name: GraphQL URL with base-url set
289+
uses: ./
290+
with:
291+
base-url: https://my.github-enterprise-server.com/api/v3
292+
script: |
293+
const endpoint = github.request.endpoint
294+
return endpoint({url: "/graphql"}).url
295+
result-encoding: string
296+
297+
- run: |
298+
echo "- Validating API URL default"
299+
expected="https://api.github.com/"
300+
actual="${{steps.base-url-default.outputs.result}}"
301+
if [[ "$expected" != "$actual" ]]; then
302+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
303+
exit 1
304+
fi
305+
echo "- Validating GraphQL URL default"
306+
expected="https://api.github.com/graphql"
307+
actual="${{steps.base-url-default-graphql.outputs.result}}"
308+
if [[ "$expected" != "$actual" ]]; then
309+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
310+
exit 1
311+
fi
312+
echo "- Validating base-url set to a value"
313+
expected="https://my.github-enterprise-server.com/api/v3/"
314+
actual="${{steps.base-url-set.outputs.result}}"
315+
if [[ "$expected" != "$actual" ]]; then
316+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
317+
exit 1
318+
fi
319+
echo "- Validating GraphQL URL with base-url set to a value"
320+
expected="https://my.github-enterprise-server.com/api/v3/graphql"
321+
actual="${{steps.base-url-set-graphql.outputs.result}}"
322+
if [[ "$expected" != "$actual" ]]; then
323+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
324+
exit 1
325+
fi

dist/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -35509,9 +35509,13 @@ async function main() {
3550935509
userAgent: userAgent || undefined,
3551035510
previews: previews ? previews.split(',') : undefined,
3551135511
retry: retryOpts,
35512-
request: requestOpts,
35513-
baseUrl: baseUrl || undefined
35512+
request: requestOpts
3551435513
};
35514+
// Setting `baseUrl` to undefined will prevent the default value from being used
35515+
// https://github.com/actions/github-script/issues/436
35516+
if (baseUrl) {
35517+
opts.baseUrl = baseUrl;
35518+
}
3551535519
const github = (0,lib_github.getOctokit)(token, opts, plugin_retry_dist_node.retry, dist_node.requestLog);
3551635520
const script = core.getInput('script', { required: true });
3551735521
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.

src/main.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ async function main(): Promise<void> {
4444
userAgent: userAgent || undefined,
4545
previews: previews ? previews.split(',') : undefined,
4646
retry: retryOpts,
47-
request: requestOpts,
48-
baseUrl: baseUrl || undefined
47+
request: requestOpts
48+
}
49+
50+
// Setting `baseUrl` to undefined will prevent the default value from being used
51+
// https://github.com/actions/github-script/issues/436
52+
if (baseUrl) {
53+
opts.baseUrl = baseUrl
4954
}
5055

5156
const github = getOctokit(token, opts, retry, requestLog)

0 commit comments

Comments
 (0)