Skip to content

Commit 9a202b7

Browse files
authored
Merge d09af74 into e69ef54
2 parents e69ef54 + d09af74 commit 9a202b7

File tree

3 files changed

+125
-4
lines changed

3 files changed

+125
-4
lines changed

.github/workflows/integration.yml

+116
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,119 @@ 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+
- id: base-url-env
298+
name: base-url does not override API URL when not set
299+
uses: ./
300+
env:
301+
GITHUB_API_URL: https://my.github-enterprise-server.com/api/v3
302+
with:
303+
script: |
304+
const endpoint = github.request.endpoint
305+
return endpoint({}).url
306+
result-encoding: string
307+
308+
- id: base-url-env-graphql
309+
name: base-url does not override GraphQL URL when not set
310+
uses: ./
311+
env:
312+
GITHUB_API_URL: https://my.github-enterprise-server.com/api/v3
313+
with:
314+
script: |
315+
const endpoint = github.request.endpoint
316+
return endpoint({url: "/graphql"}).url
317+
result-encoding: string
318+
319+
- run: |
320+
echo "- Validating API URL default"
321+
expected="https://api.github.com/"
322+
actual="${{steps.base-url-default.outputs.result}}"
323+
if [[ "$expected" != "$actual" ]]; then
324+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
325+
exit 1
326+
fi
327+
328+
echo "- Validating GraphQL URL default"
329+
expected="https://api.github.com/graphql"
330+
actual="${{steps.base-url-default-graphql.outputs.result}}"
331+
if [[ "$expected" != "$actual" ]]; then
332+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
333+
exit 1
334+
fi
335+
336+
echo "- Validating base-url set to a value"
337+
expected="https://my.github-enterprise-server.com/api/v3/"
338+
actual="${{steps.base-url-set.outputs.result}}"
339+
if [[ "$expected" != "$actual" ]]; then
340+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
341+
exit 1
342+
fi
343+
344+
echo "- Validating GraphQL URL with base-url set to a value"
345+
expected="https://my.github-enterprise-server.com/api/v3/graphql"
346+
actual="${{steps.base-url-set-graphql.outputs.result}}"
347+
if [[ "$expected" != "$actual" ]]; then
348+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
349+
exit 1
350+
fi
351+
352+
echo "- Validating API URL with base-url not set respects GITHUB_API_URL"
353+
expected="https://my.github-enterprise-server.com/api/v3/"
354+
actual="${{steps.base-url-env.outputs.result}}"
355+
if [[ "$expected" != "$actual" ]]; then
356+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
357+
exit 1
358+
fi
359+
360+
echo "- Validating GraphQL URL with base-url not set respects GITHUB_API_URL"
361+
expected="https://my.github-enterprise-server.com/api/v3/graphql"
362+
actual="${{steps.base-url-env-graphql.outputs.result}}"
363+
if [[ "$expected" != "$actual" ]]; then
364+
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
365+
exit 1
366+
fi

dist/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -35509,9 +35509,11 @@ 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+
if (baseUrl) {
35515+
opts.baseUrl = baseUrl;
35516+
}
3551535517
const github = (0,lib_github.getOctokit)(token, opts, plugin_retry_dist_node.retry, dist_node.requestLog);
3551635518
const script = core.getInput('script', { required: true });
3551735519
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.

src/main.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ 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+
if (baseUrl) {
51+
opts.baseUrl = baseUrl
4952
}
5053

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

0 commit comments

Comments
 (0)