mirror of
https://github.com/actions/github-script.git
synced 2026-05-14 11:57:01 +00:00
Compare commits
1 Commits
salmanmkc/
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d3beb123a |
48
.github/workflows/integration.yml
vendored
48
.github/workflows/integration.yml
vendored
@@ -155,51 +155,21 @@ jobs:
|
|||||||
result-encoding: string
|
result-encoding: string
|
||||||
- run: |
|
- run: |
|
||||||
echo "- Validating user-agent default"
|
echo "- Validating user-agent default"
|
||||||
ua="${{steps.user-agent-default.outputs.result}}"
|
expected="actions/github-script octokit-core.js/"
|
||||||
if [[ "$ua" != "actions/github-script octokit-core.js/"* ]] && [[ "$ua" != "actions/github-script actions_orchestration_id/"* ]]; then
|
if [[ "${{steps.user-agent-default.outputs.result}}" != "$expected"* ]]; then
|
||||||
echo $'::error::\u274C' "Expected user-agent to start with 'actions/github-script', got $ua"
|
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-default.outputs.result}}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "- Validating user-agent set to a value"
|
echo "- Validating user-agent set to a value"
|
||||||
ua="${{steps.user-agent-set.outputs.result}}"
|
expected="foobar octokit-core.js/"
|
||||||
if [[ "$ua" != "foobar octokit-core.js/"* ]] && [[ "$ua" != "foobar actions_orchestration_id/"* ]]; then
|
if [[ "${{steps.user-agent-set.outputs.result}}" != "$expected"* ]]; then
|
||||||
echo $'::error::\u274C' "Expected user-agent to start with 'foobar', got $ua"
|
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-set.outputs.result}}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "- Validating user-agent set to an empty string"
|
echo "- Validating user-agent set to an empty string"
|
||||||
ua="${{steps.user-agent-empty.outputs.result}}"
|
expected="octokit-core.js/"
|
||||||
if [[ "$ua" != "actions/github-script octokit-core.js/"* ]] && [[ "$ua" != "actions/github-script actions_orchestration_id/"* ]]; then
|
if [[ "${{steps.user-agent-empty.outputs.result}}" != "$expected"* ]]; then
|
||||||
echo $'::error::\u274C' "Expected user-agent to start with 'actions/github-script', got $ua"
|
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-empty.outputs.result}}"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
|
|
||||||
|
|
||||||
test-get-octokit:
|
|
||||||
name: 'Integration test: getOctokit'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Create secondary client with getOctokit
|
|
||||||
uses: ./
|
|
||||||
id: secondary-client
|
|
||||||
env:
|
|
||||||
APP_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
script: |
|
|
||||||
const appOctokit = getOctokit(process.env.APP_TOKEN)
|
|
||||||
const {data} = await appOctokit.rest.repos.get({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo
|
|
||||||
})
|
|
||||||
|
|
||||||
return `${appOctokit !== github}:${data.full_name}`
|
|
||||||
result-encoding: string
|
|
||||||
- run: |
|
|
||||||
echo "- Validating secondary client output"
|
|
||||||
expected="true:${{ github.repository }}"
|
|
||||||
if [[ "${{steps.secondary-client.outputs.result}}" != "$expected" ]]; then
|
|
||||||
echo $'::error::\u274C' "Expected '$expected', got ${{steps.secondary-client.outputs.result}}"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
|
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
|
||||||
|
|||||||
44
README.md
44
README.md
@@ -53,14 +53,6 @@ documentation.
|
|||||||
|
|
||||||
## Breaking Changes
|
## Breaking Changes
|
||||||
|
|
||||||
### V8
|
|
||||||
|
|
||||||
Version 8 of this action updated the runtime to Node 24 - https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions
|
|
||||||
|
|
||||||
All scripts are now run with Node 24 instead of Node 20 and are affected by any breaking changes between Node 20 and 24.
|
|
||||||
|
|
||||||
**This requires a minimum Actions Runner version of [v2.327.1](https://github.com/actions/runner/releases/tag/v2.327.1)**
|
|
||||||
|
|
||||||
### V7
|
### V7
|
||||||
|
|
||||||
Version 7 of this action updated the runtime to Node 20 - https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions
|
Version 7 of this action updated the runtime to Node 20 - https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions
|
||||||
@@ -99,7 +91,7 @@ and potential `SyntaxError`s when the expression is not valid JavaScript code (p
|
|||||||
To pass inputs, set `env` vars on the action step and reference them in your script with `process.env`:
|
To pass inputs, set `env` vars on the action step and reference them in your script with `process.env`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
env:
|
env:
|
||||||
TITLE: ${{ github.event.pull_request.title }}
|
TITLE: ${{ github.event.pull_request.title }}
|
||||||
with:
|
with:
|
||||||
@@ -118,7 +110,7 @@ The return value of the script will be in the step's outputs under the
|
|||||||
"result" key.
|
"result" key.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
id: set-result
|
id: set-result
|
||||||
with:
|
with:
|
||||||
script: return "Hello!"
|
script: return "Hello!"
|
||||||
@@ -137,7 +129,7 @@ output of a github-script step. For some workflows, string encoding is preferred
|
|||||||
`result-encoding` input:
|
`result-encoding` input:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
id: my-script
|
id: my-script
|
||||||
with:
|
with:
|
||||||
result-encoding: string
|
result-encoding: string
|
||||||
@@ -149,7 +141,7 @@ output of a github-script step. For some workflows, string encoding is preferred
|
|||||||
By default, requests made with the `github` instance will not be retried. You can configure this with the `retries` option:
|
By default, requests made with the `github` instance will not be retried. You can configure this with the `retries` option:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
id: my-script
|
id: my-script
|
||||||
with:
|
with:
|
||||||
result-encoding: string
|
result-encoding: string
|
||||||
@@ -167,7 +159,7 @@ In this example, request failures from `github.rest.issues.get()` will be retrie
|
|||||||
You can also configure which status codes should be exempt from retries via the `retry-exempt-status-codes` option:
|
You can also configure which status codes should be exempt from retries via the `retry-exempt-status-codes` option:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
id: my-script
|
id: my-script
|
||||||
with:
|
with:
|
||||||
result-encoding: string
|
result-encoding: string
|
||||||
@@ -196,7 +188,7 @@ By default, github-script will use the token provided to your workflow.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: View context attributes
|
- name: View context attributes
|
||||||
uses: actions/github-script@v8
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: console.log(context)
|
script: console.log(context)
|
||||||
```
|
```
|
||||||
@@ -212,7 +204,7 @@ jobs:
|
|||||||
comment:
|
comment:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
github.rest.issues.createComment({
|
github.rest.issues.createComment({
|
||||||
@@ -234,7 +226,7 @@ jobs:
|
|||||||
apply-label:
|
apply-label:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
github.rest.issues.addLabels({
|
github.rest.issues.addLabels({
|
||||||
@@ -256,7 +248,7 @@ jobs:
|
|||||||
welcome:
|
welcome:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
// Get a list of all issues created by the PR opener
|
// Get a list of all issues created by the PR opener
|
||||||
@@ -301,7 +293,7 @@ jobs:
|
|||||||
diff:
|
diff:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const diff_url = context.payload.pull_request.diff_url
|
const diff_url = context.payload.pull_request.diff_url
|
||||||
@@ -325,7 +317,7 @@ jobs:
|
|||||||
list-issues:
|
list-issues:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const query = `query($owner:String!, $name:String!, $label:String!) {
|
const query = `query($owner:String!, $name:String!, $label:String!) {
|
||||||
@@ -359,7 +351,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const script = require('./path/to/script.js')
|
const script = require('./path/to/script.js')
|
||||||
@@ -397,7 +389,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
env:
|
env:
|
||||||
SHA: '${{env.parentSHA}}'
|
SHA: '${{env.parentSHA}}'
|
||||||
with:
|
with:
|
||||||
@@ -441,7 +433,7 @@ jobs:
|
|||||||
- run: npm ci
|
- run: npm ci
|
||||||
# or one-off:
|
# or one-off:
|
||||||
- run: npm install execa
|
- run: npm install execa
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const execa = require('execa')
|
const execa = require('execa')
|
||||||
@@ -471,7 +463,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const { default: printStuff } = await import('${{ github.workspace }}/src/print-stuff.js')
|
const { default: printStuff } = await import('${{ github.workspace }}/src/print-stuff.js')
|
||||||
@@ -515,7 +507,7 @@ jobs:
|
|||||||
apply-label:
|
apply-label:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.MY_PAT }}
|
github-token: ${{ secrets.MY_PAT }}
|
||||||
script: |
|
script: |
|
||||||
@@ -539,7 +531,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const exitCode = await exec.exec('echo', ['hello'])
|
const exitCode = await exec.exec('echo', ['hello'])
|
||||||
@@ -557,7 +549,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/github-script@v8
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -8,94 +8,6 @@ describe('callAsyncFunction', () => {
|
|||||||
expect(result).toEqual('bar')
|
expect(result).toEqual('bar')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('passes getOctokit through the script context', async () => {
|
|
||||||
const getOctokit = jest.fn().mockReturnValue('secondary-client')
|
|
||||||
|
|
||||||
const result = await callAsyncFunction(
|
|
||||||
{getOctokit} as any,
|
|
||||||
"return getOctokit('token')"
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(getOctokit).toHaveBeenCalledWith('token')
|
|
||||||
expect(result).toEqual('secondary-client')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('getOctokit creates client independent from github', async () => {
|
|
||||||
const github = {rest: {issues: 'primary'}}
|
|
||||||
const getOctokit = jest.fn().mockReturnValue({rest: {issues: 'secondary'}})
|
|
||||||
|
|
||||||
const result = await callAsyncFunction(
|
|
||||||
{github, getOctokit} as any,
|
|
||||||
`
|
|
||||||
const secondary = getOctokit('other-token')
|
|
||||||
return {
|
|
||||||
primary: github.rest.issues,
|
|
||||||
secondary: secondary.rest.issues,
|
|
||||||
different: github !== secondary
|
|
||||||
}
|
|
||||||
`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
primary: 'primary',
|
|
||||||
secondary: 'secondary',
|
|
||||||
different: true
|
|
||||||
})
|
|
||||||
expect(getOctokit).toHaveBeenCalledWith('other-token')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('getOctokit passes options through', async () => {
|
|
||||||
const getOctokit = jest.fn().mockReturnValue('client-with-opts')
|
|
||||||
|
|
||||||
const result = await callAsyncFunction(
|
|
||||||
{getOctokit} as any,
|
|
||||||
`return getOctokit('my-token', { baseUrl: 'https://ghes.example.com/api/v3' })`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(getOctokit).toHaveBeenCalledWith('my-token', {
|
|
||||||
baseUrl: 'https://ghes.example.com/api/v3'
|
|
||||||
})
|
|
||||||
expect(result).toEqual('client-with-opts')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('getOctokit supports plugins', async () => {
|
|
||||||
const getOctokit = jest.fn().mockReturnValue('client-with-plugins')
|
|
||||||
|
|
||||||
const result = await callAsyncFunction(
|
|
||||||
{getOctokit} as any,
|
|
||||||
`return getOctokit('my-token', { previews: ['v3'] }, 'pluginA', 'pluginB')`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(getOctokit).toHaveBeenCalledWith(
|
|
||||||
'my-token',
|
|
||||||
{previews: ['v3']},
|
|
||||||
'pluginA',
|
|
||||||
'pluginB'
|
|
||||||
)
|
|
||||||
expect(result).toEqual('client-with-plugins')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('multiple getOctokit calls produce independent clients', async () => {
|
|
||||||
const getOctokit = jest
|
|
||||||
.fn()
|
|
||||||
.mockReturnValueOnce({id: 'client-a'})
|
|
||||||
.mockReturnValueOnce({id: 'client-b'})
|
|
||||||
|
|
||||||
const result = await callAsyncFunction(
|
|
||||||
{getOctokit} as any,
|
|
||||||
`
|
|
||||||
const a = getOctokit('token-a')
|
|
||||||
const b = getOctokit('token-b')
|
|
||||||
return { a: a.id, b: b.id, different: a !== b }
|
|
||||||
`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(getOctokit).toHaveBeenCalledTimes(2)
|
|
||||||
expect(getOctokit).toHaveBeenNthCalledWith(1, 'token-a')
|
|
||||||
expect(getOctokit).toHaveBeenNthCalledWith(2, 'token-b')
|
|
||||||
expect(result).toEqual({a: 'client-a', b: 'client-b', different: true})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('throws on ReferenceError', async () => {
|
test('throws on ReferenceError', async () => {
|
||||||
expect.assertions(1)
|
expect.assertions(1)
|
||||||
|
|
||||||
|
|||||||
@@ -1,268 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
|
|
||||||
import {createConfiguredGetOctokit} from '../src/create-configured-getoctokit'
|
|
||||||
|
|
||||||
describe('createConfiguredGetOctokit', () => {
|
|
||||||
const mockRetryPlugin = jest.fn()
|
|
||||||
const mockRequestLogPlugin = jest.fn()
|
|
||||||
|
|
||||||
function makeMockGetOctokit() {
|
|
||||||
return jest.fn().mockReturnValue('mock-client')
|
|
||||||
}
|
|
||||||
|
|
||||||
test('passes token and merged defaults to underlying getOctokit', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {
|
|
||||||
userAgent: 'actions/github-script actions_orchestration_id/abc',
|
|
||||||
retry: {enabled: true},
|
|
||||||
request: {retries: 3}
|
|
||||||
}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(
|
|
||||||
raw as any,
|
|
||||||
defaults,
|
|
||||||
mockRetryPlugin,
|
|
||||||
mockRequestLogPlugin
|
|
||||||
)
|
|
||||||
wrapped('my-token' as any)
|
|
||||||
|
|
||||||
expect(raw).toHaveBeenCalledWith(
|
|
||||||
'my-token',
|
|
||||||
expect.objectContaining({
|
|
||||||
userAgent: 'actions/github-script actions_orchestration_id/abc',
|
|
||||||
retry: {enabled: true},
|
|
||||||
request: {retries: 3}
|
|
||||||
}),
|
|
||||||
mockRetryPlugin,
|
|
||||||
mockRequestLogPlugin
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('user options override top-level defaults', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {
|
|
||||||
userAgent: 'default-agent',
|
|
||||||
previews: ['v3']
|
|
||||||
}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, defaults)
|
|
||||||
wrapped('tok' as any, {userAgent: 'custom-agent'} as any)
|
|
||||||
|
|
||||||
expect(raw).toHaveBeenCalledWith(
|
|
||||||
'tok',
|
|
||||||
expect.objectContaining({userAgent: 'custom-agent', previews: ['v3']})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('deep-merges request so partial overrides preserve retries', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {
|
|
||||||
request: {retries: 3, agent: 'proxy-agent', fetch: 'proxy-fetch'}
|
|
||||||
}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, defaults)
|
|
||||||
wrapped('tok' as any, {request: {timeout: 5000}} as any)
|
|
||||||
|
|
||||||
expect(raw).toHaveBeenCalledWith(
|
|
||||||
'tok',
|
|
||||||
expect.objectContaining({
|
|
||||||
request: {
|
|
||||||
retries: 3,
|
|
||||||
agent: 'proxy-agent',
|
|
||||||
fetch: 'proxy-fetch',
|
|
||||||
timeout: 5000
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('deep-merges retry so partial overrides preserve existing settings', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {
|
|
||||||
retry: {enabled: true, retries: 3}
|
|
||||||
}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, defaults)
|
|
||||||
wrapped('tok' as any, {retry: {retries: 5}} as any)
|
|
||||||
|
|
||||||
expect(raw).toHaveBeenCalledWith(
|
|
||||||
'tok',
|
|
||||||
expect.objectContaining({
|
|
||||||
retry: {enabled: true, retries: 5}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('user can override request.retries explicitly', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {request: {retries: 3}}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, defaults)
|
|
||||||
wrapped('tok' as any, {request: {retries: 0}} as any)
|
|
||||||
|
|
||||||
expect(raw).toHaveBeenCalledWith(
|
|
||||||
'tok',
|
|
||||||
expect.objectContaining({request: {retries: 0}})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('user plugins are appended after default plugins', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const customPlugin = jest.fn()
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(
|
|
||||||
raw as any,
|
|
||||||
{},
|
|
||||||
mockRetryPlugin,
|
|
||||||
mockRequestLogPlugin
|
|
||||||
)
|
|
||||||
wrapped('tok' as any, {} as any, customPlugin as any)
|
|
||||||
|
|
||||||
expect(raw).toHaveBeenCalledWith(
|
|
||||||
'tok',
|
|
||||||
expect.any(Object),
|
|
||||||
mockRetryPlugin,
|
|
||||||
mockRequestLogPlugin,
|
|
||||||
customPlugin
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('duplicate plugins are deduplicated', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(
|
|
||||||
raw as any,
|
|
||||||
{},
|
|
||||||
mockRetryPlugin,
|
|
||||||
mockRequestLogPlugin
|
|
||||||
)
|
|
||||||
// User passes retry again — should not duplicate
|
|
||||||
wrapped('tok' as any, {} as any, mockRetryPlugin as any)
|
|
||||||
|
|
||||||
expect(raw).toHaveBeenCalledWith(
|
|
||||||
'tok',
|
|
||||||
expect.any(Object),
|
|
||||||
mockRetryPlugin,
|
|
||||||
mockRequestLogPlugin
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('applies defaults when no user options provided', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {
|
|
||||||
userAgent: 'actions/github-script',
|
|
||||||
retry: {enabled: true},
|
|
||||||
request: {retries: 3}
|
|
||||||
}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(
|
|
||||||
raw as any,
|
|
||||||
defaults,
|
|
||||||
mockRetryPlugin
|
|
||||||
)
|
|
||||||
wrapped('tok' as any)
|
|
||||||
|
|
||||||
expect(raw).toHaveBeenCalledWith(
|
|
||||||
'tok',
|
|
||||||
{
|
|
||||||
userAgent: 'actions/github-script',
|
|
||||||
retry: {enabled: true},
|
|
||||||
request: {retries: 3}
|
|
||||||
},
|
|
||||||
mockRetryPlugin
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('baseUrl: undefined from user does not clobber default', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {baseUrl: 'https://ghes.example.com/api/v3'}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, defaults)
|
|
||||||
wrapped('tok' as any, {baseUrl: undefined} as any)
|
|
||||||
|
|
||||||
const calledOpts = raw.mock.calls[0][1]
|
|
||||||
expect(calledOpts.baseUrl).toBe('https://ghes.example.com/api/v3')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('undefined values in nested request are stripped', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {request: {retries: 3, agent: 'proxy'}}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, defaults)
|
|
||||||
wrapped('tok' as any, {request: {retries: undefined, timeout: 5000}} as any)
|
|
||||||
|
|
||||||
const calledOpts = raw.mock.calls[0][1]
|
|
||||||
expect(calledOpts.request).toEqual({
|
|
||||||
retries: 3,
|
|
||||||
agent: 'proxy',
|
|
||||||
timeout: 5000
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('undefined values in nested retry are stripped', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {retry: {enabled: true, retries: 3}}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, defaults)
|
|
||||||
wrapped('tok' as any, {retry: {enabled: undefined, retries: 5}} as any)
|
|
||||||
|
|
||||||
const calledOpts = raw.mock.calls[0][1]
|
|
||||||
expect(calledOpts.retry).toEqual({enabled: true, retries: 5})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('each call creates an independent client', () => {
|
|
||||||
const raw = jest
|
|
||||||
.fn()
|
|
||||||
.mockReturnValueOnce('client-a')
|
|
||||||
.mockReturnValueOnce('client-b')
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, {})
|
|
||||||
const a = wrapped('token-a' as any)
|
|
||||||
const b = wrapped('token-b' as any)
|
|
||||||
|
|
||||||
expect(a).toBe('client-a')
|
|
||||||
expect(b).toBe('client-b')
|
|
||||||
expect(raw).toHaveBeenCalledTimes(2)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('does not mutate defaultOptions between calls', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {
|
|
||||||
request: {retries: 3},
|
|
||||||
retry: {enabled: true}
|
|
||||||
}
|
|
||||||
const originalDefaults = JSON.parse(JSON.stringify(defaults))
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, defaults)
|
|
||||||
wrapped(
|
|
||||||
'tok' as any,
|
|
||||||
{request: {timeout: 5000}, retry: {retries: 10}} as any
|
|
||||||
)
|
|
||||||
wrapped('tok' as any, {request: {timeout: 9000}} as any)
|
|
||||||
|
|
||||||
expect(defaults).toEqual(originalDefaults)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('falsy-but-valid values are preserved, only undefined is stripped', () => {
|
|
||||||
const raw = makeMockGetOctokit()
|
|
||||||
const defaults = {baseUrl: 'https://ghes.example.com/api/v3'}
|
|
||||||
|
|
||||||
const wrapped = createConfiguredGetOctokit(raw as any, defaults)
|
|
||||||
wrapped(
|
|
||||||
'tok' as any,
|
|
||||||
{
|
|
||||||
log: null,
|
|
||||||
retries: 0,
|
|
||||||
debug: false,
|
|
||||||
userAgent: ''
|
|
||||||
} as any
|
|
||||||
)
|
|
||||||
|
|
||||||
const calledOpts = raw.mock.calls[0][1]
|
|
||||||
expect(calledOpts.log).toBeNull()
|
|
||||||
expect(calledOpts.retries).toBe(0)
|
|
||||||
expect(calledOpts.debug).toBe(false)
|
|
||||||
expect(calledOpts.userAgent).toBe('')
|
|
||||||
expect(calledOpts.baseUrl).toBe('https://ghes.example.com/api/v3')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
|
|
||||||
import {callAsyncFunction} from '../src/async-function'
|
|
||||||
|
|
||||||
// Create a mock getOctokit that returns Octokit-like objects.
|
|
||||||
// Real @actions/github integration is tested in the CI workflow
|
|
||||||
// (integration.yml test-get-octokit job). Here we verify the
|
|
||||||
// script context wiring — getOctokit is passed through and
|
|
||||||
// callable from user scripts.
|
|
||||||
function mockGetOctokit(token: string, options?: any) {
|
|
||||||
return {
|
|
||||||
_token: token,
|
|
||||||
_options: options,
|
|
||||||
rest: {
|
|
||||||
issues: {get: async () => ({data: {id: 1}})},
|
|
||||||
pulls: {get: async () => ({data: {id: 2}})}
|
|
||||||
},
|
|
||||||
graphql: async () => ({}),
|
|
||||||
request: async () => ({})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('getOctokit integration via callAsyncFunction', () => {
|
|
||||||
test('getOctokit creates a functional client in script scope', async () => {
|
|
||||||
const result = await callAsyncFunction(
|
|
||||||
{getOctokit: mockGetOctokit} as any,
|
|
||||||
`
|
|
||||||
const client = getOctokit('fake-token-for-test')
|
|
||||||
return {
|
|
||||||
hasRest: typeof client.rest === 'object',
|
|
||||||
hasGraphql: typeof client.graphql === 'function',
|
|
||||||
hasRequest: typeof client.request === 'function',
|
|
||||||
hasIssues: typeof client.rest.issues === 'object',
|
|
||||||
hasPulls: typeof client.rest.pulls === 'object'
|
|
||||||
}
|
|
||||||
`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
hasRest: true,
|
|
||||||
hasGraphql: true,
|
|
||||||
hasRequest: true,
|
|
||||||
hasIssues: true,
|
|
||||||
hasPulls: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('secondary client is independent from primary github client', async () => {
|
|
||||||
const primary = mockGetOctokit('primary-token')
|
|
||||||
|
|
||||||
const result = await callAsyncFunction(
|
|
||||||
{github: primary, getOctokit: mockGetOctokit} as any,
|
|
||||||
`
|
|
||||||
const secondary = getOctokit('secondary-token')
|
|
||||||
return {
|
|
||||||
bothHaveRest: typeof github.rest === 'object' && typeof secondary.rest === 'object',
|
|
||||||
areDistinct: github !== secondary
|
|
||||||
}
|
|
||||||
`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
bothHaveRest: true,
|
|
||||||
areDistinct: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('getOctokit accepts options for GHES base URL', async () => {
|
|
||||||
const result = await callAsyncFunction(
|
|
||||||
{getOctokit: mockGetOctokit} as any,
|
|
||||||
`
|
|
||||||
const client = getOctokit('fake-token', {
|
|
||||||
baseUrl: 'https://ghes.example.com/api/v3'
|
|
||||||
})
|
|
||||||
return typeof client.rest === 'object'
|
|
||||||
`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(result).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('multiple getOctokit calls produce independent clients with different tokens', async () => {
|
|
||||||
const result = await callAsyncFunction(
|
|
||||||
{getOctokit: mockGetOctokit} as any,
|
|
||||||
`
|
|
||||||
const clientA = getOctokit('token-a')
|
|
||||||
const clientB = getOctokit('token-b')
|
|
||||||
return {
|
|
||||||
aHasRest: typeof clientA.rest === 'object',
|
|
||||||
bHasRest: typeof clientB.rest === 'object',
|
|
||||||
areDistinct: clientA !== clientB
|
|
||||||
}
|
|
||||||
`
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
aHasRest: true,
|
|
||||||
bHasRest: true,
|
|
||||||
areDistinct: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
57
dist/index.js
vendored
57
dist/index.js
vendored
@@ -36188,42 +36188,6 @@ function callAsyncFunction(args, source) {
|
|||||||
return fn(...Object.values(args));
|
return fn(...Object.values(args));
|
||||||
}
|
}
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./src/create-configured-getoctokit.ts
|
|
||||||
function stripUndefined(obj) {
|
|
||||||
const result = {};
|
|
||||||
for (const [key, value] of Object.entries(obj)) {
|
|
||||||
if (value !== undefined) {
|
|
||||||
;
|
|
||||||
result[key] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
function createConfiguredGetOctokit(rawGetOctokit, defaultOptions, ...defaultPlugins) {
|
|
||||||
return (token, options, ...additionalPlugins) => {
|
|
||||||
const userOpts = stripUndefined(options || {});
|
|
||||||
const defaultRequest = defaultOptions.request;
|
|
||||||
const userRequestRaw = userOpts.request;
|
|
||||||
const userRequest = userRequestRaw ? stripUndefined(userRequestRaw) : {};
|
|
||||||
const defaultRetry = defaultOptions.retry;
|
|
||||||
const userRetryRaw = userOpts.retry;
|
|
||||||
const userRetry = userRetryRaw ? stripUndefined(userRetryRaw) : {};
|
|
||||||
const merged = {
|
|
||||||
...defaultOptions,
|
|
||||||
...userOpts,
|
|
||||||
request: { ...(defaultRequest || {}), ...userRequest },
|
|
||||||
retry: { ...(defaultRetry || {}), ...userRetry }
|
|
||||||
};
|
|
||||||
const allPlugins = [...defaultPlugins];
|
|
||||||
for (const plugin of additionalPlugins) {
|
|
||||||
if (!allPlugins.includes(plugin)) {
|
|
||||||
allPlugins.push(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rawGetOctokit(token, merged, ...allPlugins);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./src/retry-options.ts
|
;// CONCATENATED MODULE: ./src/retry-options.ts
|
||||||
|
|
||||||
function getRetryOptions(retries, exemptStatusCodes, defaultOptions) {
|
function getRetryOptions(retries, exemptStatusCodes, defaultOptions) {
|
||||||
@@ -36292,7 +36256,6 @@ const wrapRequire = new Proxy(require, {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
process.on('unhandledRejection', handleError);
|
process.on('unhandledRejection', handleError);
|
||||||
main().catch(handleError);
|
main().catch(handleError);
|
||||||
async function main() {
|
async function main() {
|
||||||
@@ -36304,11 +36267,9 @@ 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 || 'actions/github-script';
|
|
||||||
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent);
|
|
||||||
const opts = {
|
const opts = {
|
||||||
log: debug ? console : undefined,
|
log: debug ? console : undefined,
|
||||||
userAgent: finalUserAgent,
|
userAgent: userAgent || undefined,
|
||||||
previews: previews ? previews.split(',') : undefined,
|
previews: previews ? previews.split(',') : undefined,
|
||||||
retry: retryOpts,
|
retry: retryOpts,
|
||||||
request: requestOpts
|
request: requestOpts
|
||||||
@@ -36320,14 +36281,12 @@ async function main() {
|
|||||||
}
|
}
|
||||||
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 });
|
||||||
const configuredGetOctokit = createConfiguredGetOctokit(lib_github.getOctokit, opts, plugin_retry_dist_node.retry, dist_node.requestLog);
|
|
||||||
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
||||||
const result = await callAsyncFunction({
|
const result = await callAsyncFunction({
|
||||||
require: wrapRequire,
|
require: wrapRequire,
|
||||||
__original_require__: require,
|
__original_require__: require,
|
||||||
github,
|
github,
|
||||||
octokit: github,
|
octokit: github,
|
||||||
getOctokit: configuredGetOctokit,
|
|
||||||
context: lib_github.context,
|
context: lib_github.context,
|
||||||
core: core,
|
core: core,
|
||||||
exec: exec,
|
exec: exec,
|
||||||
@@ -36354,20 +36313,6 @@ function handleError(err) {
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
core.setFailed(`Unhandled 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) {
|
|
||||||
const orchestrationId = process.env['ACTIONS_ORCHESTRATION_ID'];
|
|
||||||
if (!orchestrationId) {
|
|
||||||
return userAgent;
|
|
||||||
}
|
|
||||||
// Sanitize orchestration ID - replace invalid characters with underscore
|
|
||||||
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
||||||
return `${userAgent} actions_orchestration_id/${sanitized}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
12
package-lock.json
generated
12
package-lock.json
generated
@@ -2273,9 +2273,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/brace-expansion": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
"integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"balanced-match": "^1.0.0",
|
"balanced-match": "^1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
@@ -9067,9 +9067,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
"integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "^1.0.0",
|
"balanced-match": "^1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import * as core from '@actions/core'
|
|||||||
import * as exec from '@actions/exec'
|
import * as exec from '@actions/exec'
|
||||||
import {Context} from '@actions/github/lib/context'
|
import {Context} from '@actions/github/lib/context'
|
||||||
import {GitHub} from '@actions/github/lib/utils'
|
import {GitHub} from '@actions/github/lib/utils'
|
||||||
import {getOctokit} from '@actions/github'
|
|
||||||
import * as glob from '@actions/glob'
|
import * as glob from '@actions/glob'
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
|
|
||||||
@@ -13,7 +12,6 @@ export declare type AsyncFunctionArguments = {
|
|||||||
core: typeof core
|
core: typeof core
|
||||||
github: InstanceType<typeof GitHub>
|
github: InstanceType<typeof GitHub>
|
||||||
octokit: InstanceType<typeof GitHub>
|
octokit: InstanceType<typeof GitHub>
|
||||||
getOctokit: typeof getOctokit
|
|
||||||
exec: typeof exec
|
exec: typeof exec
|
||||||
glob: typeof glob
|
glob: typeof glob
|
||||||
io: typeof io
|
io: typeof io
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
import {getOctokit} from '@actions/github'
|
|
||||||
import {GitHub} from '@actions/github/lib/utils'
|
|
||||||
import {OctokitOptions, OctokitPlugin} from '@octokit/core/dist-types/types'
|
|
||||||
|
|
||||||
type GetOctokit = typeof getOctokit
|
|
||||||
|
|
||||||
function stripUndefined<T extends Record<string, unknown>>(obj: T): Partial<T> {
|
|
||||||
const result: Partial<T> = {}
|
|
||||||
for (const [key, value] of Object.entries(obj)) {
|
|
||||||
if (value !== undefined) {
|
|
||||||
;(result as Record<string, unknown>)[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createConfiguredGetOctokit(
|
|
||||||
rawGetOctokit: GetOctokit,
|
|
||||||
defaultOptions: OctokitOptions,
|
|
||||||
...defaultPlugins: OctokitPlugin[]
|
|
||||||
): GetOctokit {
|
|
||||||
return (
|
|
||||||
token: string,
|
|
||||||
options?: OctokitOptions,
|
|
||||||
...additionalPlugins: OctokitPlugin[]
|
|
||||||
): InstanceType<typeof GitHub> => {
|
|
||||||
const userOpts = stripUndefined(options || {})
|
|
||||||
const defaultRequest = defaultOptions.request
|
|
||||||
const userRequestRaw = userOpts.request as
|
|
||||||
| Record<string, unknown>
|
|
||||||
| undefined
|
|
||||||
const userRequest = userRequestRaw ? stripUndefined(userRequestRaw) : {}
|
|
||||||
const defaultRetry = defaultOptions.retry
|
|
||||||
const userRetryRaw = userOpts.retry as Record<string, unknown> | undefined
|
|
||||||
const userRetry = userRetryRaw ? stripUndefined(userRetryRaw) : {}
|
|
||||||
|
|
||||||
const merged: OctokitOptions = {
|
|
||||||
...defaultOptions,
|
|
||||||
...userOpts,
|
|
||||||
request: {...(defaultRequest || {}), ...userRequest},
|
|
||||||
retry: {...(defaultRetry || {}), ...userRetry}
|
|
||||||
}
|
|
||||||
|
|
||||||
const allPlugins = [...defaultPlugins]
|
|
||||||
for (const plugin of additionalPlugins) {
|
|
||||||
if (!allPlugins.includes(plugin)) {
|
|
||||||
allPlugins.push(plugin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rawGetOctokit(token, merged, ...allPlugins)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
31
src/main.ts
31
src/main.ts
@@ -8,7 +8,6 @@ import {requestLog} from '@octokit/plugin-request-log'
|
|||||||
import {retry} from '@octokit/plugin-retry'
|
import {retry} from '@octokit/plugin-retry'
|
||||||
import {RequestRequestOptions} from '@octokit/types'
|
import {RequestRequestOptions} from '@octokit/types'
|
||||||
import {callAsyncFunction} from './async-function'
|
import {callAsyncFunction} from './async-function'
|
||||||
import {createConfiguredGetOctokit} from './create-configured-getoctokit'
|
|
||||||
import {RetryOptions, getRetryOptions, parseNumberArray} from './retry-options'
|
import {RetryOptions, getRetryOptions, parseNumberArray} from './retry-options'
|
||||||
import {wrapRequire} from './wrap-require'
|
import {wrapRequire} from './wrap-require'
|
||||||
|
|
||||||
@@ -40,12 +39,9 @@ async function main(): Promise<void> {
|
|||||||
defaultGitHubOptions
|
defaultGitHubOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
const baseUserAgent = userAgent || 'actions/github-script'
|
|
||||||
const finalUserAgent = getUserAgentWithOrchestrationId(baseUserAgent)
|
|
||||||
|
|
||||||
const opts: Options = {
|
const opts: Options = {
|
||||||
log: debug ? console : undefined,
|
log: debug ? console : undefined,
|
||||||
userAgent: finalUserAgent,
|
userAgent: userAgent || undefined,
|
||||||
previews: previews ? previews.split(',') : undefined,
|
previews: previews ? previews.split(',') : undefined,
|
||||||
retry: retryOpts,
|
retry: retryOpts,
|
||||||
request: requestOpts
|
request: requestOpts
|
||||||
@@ -60,13 +56,6 @@ async function main(): Promise<void> {
|
|||||||
const github = getOctokit(token, opts, retry, requestLog)
|
const github = getOctokit(token, opts, retry, requestLog)
|
||||||
const script = core.getInput('script', {required: true})
|
const script = core.getInput('script', {required: true})
|
||||||
|
|
||||||
const configuredGetOctokit = createConfiguredGetOctokit(
|
|
||||||
getOctokit,
|
|
||||||
opts,
|
|
||||||
retry,
|
|
||||||
requestLog
|
|
||||||
)
|
|
||||||
|
|
||||||
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
||||||
const result = await callAsyncFunction(
|
const result = await callAsyncFunction(
|
||||||
{
|
{
|
||||||
@@ -74,7 +63,6 @@ async function main(): Promise<void> {
|
|||||||
__original_require__: __non_webpack_require__,
|
__original_require__: __non_webpack_require__,
|
||||||
github,
|
github,
|
||||||
octokit: github,
|
octokit: github,
|
||||||
getOctokit: configuredGetOctokit,
|
|
||||||
context,
|
context,
|
||||||
core,
|
core,
|
||||||
exec,
|
exec,
|
||||||
@@ -108,20 +96,3 @@ function handleError(err: any): void {
|
|||||||
console.error(err)
|
console.error(err)
|
||||||
core.setFailed(`Unhandled 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 - replace invalid characters with underscore
|
|
||||||
const sanitized = orchestrationId.replace(/[^a-zA-Z0-9._-]/g, '_')
|
|
||||||
|
|
||||||
return `${userAgent} actions_orchestration_id/${sanitized}`
|
|
||||||
}
|
|
||||||
|
|||||||
2
types/async-function.d.ts
vendored
2
types/async-function.d.ts
vendored
@@ -3,7 +3,6 @@ import * as core from '@actions/core';
|
|||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import { Context } from '@actions/github/lib/context';
|
import { Context } from '@actions/github/lib/context';
|
||||||
import { GitHub } from '@actions/github/lib/utils';
|
import { GitHub } from '@actions/github/lib/utils';
|
||||||
import { getOctokit } from '@actions/github';
|
|
||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
export declare type AsyncFunctionArguments = {
|
export declare type AsyncFunctionArguments = {
|
||||||
@@ -11,7 +10,6 @@ export declare type AsyncFunctionArguments = {
|
|||||||
core: typeof core;
|
core: typeof core;
|
||||||
github: InstanceType<typeof GitHub>;
|
github: InstanceType<typeof GitHub>;
|
||||||
octokit: InstanceType<typeof GitHub>;
|
octokit: InstanceType<typeof GitHub>;
|
||||||
getOctokit: typeof getOctokit;
|
|
||||||
exec: typeof exec;
|
exec: typeof exec;
|
||||||
glob: typeof glob;
|
glob: typeof glob;
|
||||||
io: typeof io;
|
io: typeof io;
|
||||||
|
|||||||
Reference in New Issue
Block a user