GeezerVison is showing github.com — Merge branch 'main' into joshmgross/node-20 · actions/github-script@5349cf9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: README.md +18Lines changed: 18 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -424,6 +424,24 @@ jobs: | 424 | 424 | await printStuff() | 425 | 425 | ``` | 426 | 426 |
| | 427 | +### Use scripts with jsDoc support | | 428 | + | | 429 | +If you want type support for your scripts, you could use the command below to install the | | 430 | +`github-script` type declaration. | | 431 | +```sh | | 432 | +$ npm i -D @types/github-script@github:actions/github-script | | 433 | +``` | | 434 | + | | 435 | +And then add the `jsDoc` declaration to your script like this: | | 436 | +```js | | 437 | +// @ts-check | | 438 | +/** @param {import('@types/github-script').AsyncFunctionArguments} AsyncFunctionArguments */ | | 439 | +export default async ({ core, context }) => { | | 440 | + core.debug("Running something at the moment"); | | 441 | + return context.actor; | | 442 | +}; | | 443 | +``` | | 444 | + | 427 | 445 | ### Use env as input | 428 | 446 |
| 429 | 447 | You can set env vars to use them in your script: | |
Collapse file Copy file name to clipboardExpand all lines: action.yml +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,9 @@ inputs: | 29 | 29 | retry-exempt-status-codes: | 30 | 30 | description: A comma separated list of status codes that will NOT be retried e.g. "400,500". No effect unless `retries` is set | 31 | 31 | default: 400,401,403,404,422 # from https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14 | | 32 | + base-url: | | 33 | + description: An optional GitHub REST API URL to connect to a different GitHub instance. For example, https://my.github-enterprise-server.com/api/v3 | | 34 | + required: false | 32 | 35 | outputs: | 33 | 36 | result: | 34 | 37 | description: The return value of the script, stringified with `JSON.stringify` | |
Collapse file Copy file name to clipboardExpand all lines: dist/index.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -35500,6 +35500,7 @@ async function main() { | 35500 | 35500 | const debug = core.getBooleanInput('debug'); | 35501 | 35501 | const userAgent = core.getInput('user-agent'); | 35502 | 35502 | const previews = core.getInput('previews'); | | 35503 | + const baseUrl = core.getInput('base-url'); | 35503 | 35504 | const retries = parseInt(core.getInput('retries')); | 35504 | 35505 | const exemptStatusCodes = parseNumberArray(core.getInput('retry-exempt-status-codes')); | 35505 | 35506 | const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults); | @@ -35508,7 +35509,8 @@ async function main() { | 35508 | 35509 | userAgent: userAgent || undefined, | 35509 | 35510 | previews: previews ? previews.split(',') : undefined, | 35510 | 35511 | retry: retryOpts, | 35511 | | - request: requestOpts | | 35512 | + request: requestOpts, | | 35513 | + baseUrl: baseUrl || undefined | 35512 | 35514 | }; | 35513 | 35515 | const github = (0,lib_github.getOctokit)(token, opts, plugin_retry_dist_node.retry, dist_node.requestLog); | 35514 | 35516 | const script = core.getInput('script', { required: true }); | |
Collapse file Copy file name to clipboardExpand all lines: package.json +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | "author": "GitHub", | 6 | 6 | "license": "MIT", | 7 | 7 | "main": "dist/index.js", | | 8 | + "types": "types/async-function.d.ts", | 8 | 9 | "private": true, | 9 | 10 | "engines": { | 10 | 11 | "node": ">=20.0.0 <21.0.0" | 11 | 12 | }, | 12 | 13 | "scripts": { | 13 | | - "build": "ncc build src/main.ts", | | 14 | + "build": "npm run build:types && ncc build src/main.ts", | | 15 | + "build:types": "tsc src/async-function.ts -t es5 --declaration --allowJs --emitDeclarationOnly --outDir types", | 14 | 16 | "format:check": "prettier --check src __test__", | 15 | 17 | "format:write": "prettier --write src __test__", | 16 | 18 | "lint": "eslint src __test__", | |
Collapse file Copy file name to clipboardExpand all lines: src/async-function.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ import * as io from '@actions/io' | 7 | 7 |
| 8 | 8 | const AsyncFunction = Object.getPrototypeOf(async () => null).constructor | 9 | 9 |
| 10 | | -type AsyncFunctionArguments = { | | 10 | +export declare type AsyncFunctionArguments = { | 11 | 11 | context: Context | 12 | 12 | core: typeof core | 13 | 13 | github: InstanceType<typeof GitHub> | |
Collapse file Copy file name to clipboardExpand all lines: src/main.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,6 +17,7 @@ main().catch(handleError) | 17 | 17 | type Options = { | 18 | 18 | log?: Console | 19 | 19 | userAgent?: string | | 20 | + baseUrl?: string | 20 | 21 | previews?: string[] | 21 | 22 | retry?: RetryOptions | 22 | 23 | request?: RequestRequestOptions | @@ -27,6 +28,7 @@ async function main(): Promise<void> { | 27 | 28 | const debug = core.getBooleanInput('debug') | 28 | 29 | const userAgent = core.getInput('user-agent') | 29 | 30 | const previews = core.getInput('previews') | | 31 | + const baseUrl = core.getInput('base-url') | 30 | 32 | const retries = parseInt(core.getInput('retries')) | 31 | 33 | const exemptStatusCodes = parseNumberArray( | 32 | 34 | core.getInput('retry-exempt-status-codes') | @@ -42,7 +44,8 @@ async function main(): Promise<void> { | 42 | 44 | userAgent: userAgent || undefined, | 43 | 45 | previews: previews ? previews.split(',') : undefined, | 44 | 46 | retry: retryOpts, | 45 | | - request: requestOpts | | 47 | + request: requestOpts, | | 48 | + baseUrl: baseUrl || undefined | 46 | 49 | } | 47 | 50 |
| 48 | 51 | const github = getOctokit(token, opts, retry, requestLog) | |
Collapse file Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/// <reference types="node" /> | | 2 | +import * as core from '@actions/core'; | | 3 | +import * as exec from '@actions/exec'; | | 4 | +import { Context } from '@actions/github/lib/context'; | | 5 | +import { GitHub } from '@actions/github/lib/utils'; | | 6 | +import * as glob from '@actions/glob'; | | 7 | +import * as io from '@actions/io'; | | 8 | +import fetch from 'node-fetch'; | | 9 | +export declare type AsyncFunctionArguments = { | | 10 | + context: Context; | | 11 | + core: typeof core; | | 12 | + github: InstanceType<typeof GitHub>; | | 13 | + exec: typeof exec; | | 14 | + glob: typeof glob; | | 15 | + io: typeof io; | | 16 | + fetch: typeof fetch; | | 17 | + require: NodeRequire; | | 18 | + __original_require__: NodeRequire; | | 19 | +}; | | 20 | +export declare function callAsyncFunction<T>(args: AsyncFunctionArguments, source: string): Promise<T>; |
|