mirror of
https://github.com/actions/github-script.git
synced 2026-10-15 20:06:55 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4aed96e0ba | ||
|
|
e7d3d7ecb7 | ||
|
|
44b873bc97 | ||
|
|
b92989f423 | ||
|
|
5e49adabf5 | ||
|
|
4db7989ab1 | ||
|
|
a4a34d1dea | ||
|
|
3f9262325d | ||
|
|
07ecbc5ac0 | ||
|
|
a656f437f9 | ||
|
|
83107c8695 | ||
|
|
603dfa3ce2 | ||
|
|
62c8044fd6 | ||
|
|
c19d6ba8b3 | ||
|
|
1ba1e95cf2 | ||
|
|
b507739f17 | ||
|
|
95130f1202 | ||
|
|
82b33c82ef | ||
|
|
53cd48b63b | ||
|
|
6e5ee1dc1c | ||
|
|
fa718ed671 | ||
|
|
4789b35ac3 | ||
|
|
89e3c40f24 | ||
|
|
1b10125da5 | ||
|
|
9b7fae11e2 | ||
|
|
c7971c2fc0 | ||
|
|
7ec2818723 | ||
|
|
287e10e610 | ||
|
|
b2c461f3a2 | ||
|
|
048309c447 | ||
|
|
a8704b62a3 | ||
|
|
e16145c72e | ||
|
|
dd16c14e71 | ||
|
|
5d33ffc89d | ||
|
|
adb3d5168d | ||
|
|
181dcc219c | ||
|
|
6f0504cb03 | ||
|
|
d89db5b6f4 | ||
|
|
52110c52e9 | ||
|
|
f498913621 | ||
|
|
58f0ff84d6 | ||
|
|
3037861304 | ||
|
|
b945d091bf | ||
|
|
ca14121875 | ||
|
|
ca6d0aaa59 | ||
|
|
5d879b69aa | ||
|
|
1bc9cbef6c | ||
|
|
9a58186a54 | ||
|
|
8934ce0ffe | ||
|
|
05997a2463 | ||
|
|
1bc2687309 | ||
|
|
97fd3f1973 | ||
|
|
f8e6050e29 | ||
|
|
648bc46b8a | ||
|
|
1268370776 | ||
|
|
5d03ada4b0 | ||
|
|
293ee0ca2d | ||
|
|
67d29bab15 | ||
|
|
0baa1791ca | ||
|
|
b4fd05ccdf | ||
|
|
2ccd1edaf4 | ||
|
|
a59996ab35 | ||
|
|
7ca8635cd0 | ||
|
|
8117de6119 | ||
|
|
3f4f5a83e8 | ||
|
|
0e2c0d5c7c | ||
|
|
0d15461bee | ||
|
|
e4cc5a8d47 | ||
|
|
dc16f26602 | ||
|
|
8982156783 | ||
|
|
80a5e943b4 | ||
|
|
0cb5c91bd3 | ||
|
|
493b839630 | ||
|
|
904b439f45 | ||
|
|
1e169ae445 | ||
|
|
62fdca610c | ||
|
|
26ee3d2d09 | ||
|
|
be5d094bf9 | ||
|
|
3758c2b05b | ||
|
|
317a0746d1 | ||
|
|
ec171b8961 | ||
|
|
d73e75dea8 | ||
|
|
7afad1e364 | ||
|
|
ebe3cb13e0 | ||
|
|
38e3ffe4c6 | ||
|
|
6eefe48bc9 | ||
|
|
5363c89495 | ||
|
|
b20057aecf | ||
|
|
ebc5283d9c | ||
|
|
f3c2f2ea28 | ||
|
|
8e6ec0efea | ||
|
|
c98effd497 | ||
|
|
e26865c60b | ||
|
|
1d4576cfc1 | ||
|
|
70e1324591 | ||
|
|
45a1478a3c | ||
|
|
b57a417097 | ||
|
|
966982d0f8 | ||
|
|
5bc9a17b5e | ||
|
|
aa2b350b20 | ||
|
|
49479481d1 | ||
|
|
173930380c | ||
|
|
2df917a7ec | ||
|
|
e27277ca72 | ||
|
|
ad75d095ea | ||
|
|
f2f148bee6 | ||
|
|
1daa763e63 | ||
|
|
2adb4f3620 | ||
|
|
38e28a96bd | ||
|
|
83e4cfe60a | ||
|
|
29c97cb536 | ||
|
|
de1677be2d | ||
|
|
99889c25e0 | ||
|
|
9abe67e516 | ||
|
|
622ce3121a | ||
|
|
1a49f59545 | ||
|
|
70dbd8d3ba | ||
|
|
5abce7d243 | ||
|
|
93e067c319 | ||
|
|
ae247f778e | ||
|
|
d9c834f45d | ||
|
|
11098d4ae3 | ||
|
|
87914af509 | ||
|
|
f59de04a66 |
No files matched your search
@@ -0,0 +1,13 @@
|
|||||||
|
root: true
|
||||||
|
parser: '@typescript-eslint/parser'
|
||||||
|
plugins: ['@typescript-eslint']
|
||||||
|
extends:
|
||||||
|
- eslint:recommended
|
||||||
|
- plugin:@typescript-eslint/eslint-recommended
|
||||||
|
- plugin:@typescript-eslint/recommended
|
||||||
|
- prettier/@typescript-eslint
|
||||||
|
rules:
|
||||||
|
# '@typescript-eslint/explicit-function-return-type': 0
|
||||||
|
'@typescript-eslint/no-use-before-define':
|
||||||
|
- 2
|
||||||
|
- functions: false
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
.licenses/** -diff linguist-generated=true
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
on:
|
||||||
|
push: {branches: main}
|
||||||
|
pull_request: {branches: main}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ci:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with: {node-version: 13.x}
|
||||||
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
|
||||||
|
restore-keys: ${{runner.os}}-npm-
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run style:check
|
||||||
|
- run: npm test
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
on:
|
||||||
|
push: {branches: main}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
integration:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- id: output-set
|
||||||
|
uses: actions/github-script@main
|
||||||
|
with:
|
||||||
|
script: return core.getInput('input-value')
|
||||||
|
result-encoding: string
|
||||||
|
input-value: output
|
||||||
|
- run: |
|
||||||
|
if [[ "${{steps.output-set.outputs.result}}" != "output" ]]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
name: Licensed
|
||||||
|
|
||||||
|
on:
|
||||||
|
push: {branches: main}
|
||||||
|
pull_request: {branches: main}
|
||||||
|
repository_dispatch:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Check licenses
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
|
||||||
|
restore-keys: ${{runner.os}}-npm-
|
||||||
|
- run: npm ci
|
||||||
|
- name: Install licensed
|
||||||
|
run: |-
|
||||||
|
cd $RUNNER_TEMP
|
||||||
|
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.9.2/licensed-2.9.2-linux-x64.tar.gz
|
||||||
|
sudo tar -xzf licensed.tar.gz
|
||||||
|
sudo mv licensed /usr/local/bin/licensed
|
||||||
|
- run: licensed status
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: main
|
||||||
|
types: [opened, synchronize]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pull-request-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
// Get the existing comments.
|
||||||
|
const {data: comments} = await github.issues.listComments({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: context.payload.number,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Find any comment already made by the bot.
|
||||||
|
const botComment = comments.find(comment => comment.user.id === 41898282)
|
||||||
|
const commentBody = "Hello from actions/github-script! (${{ github.sha }})"
|
||||||
|
|
||||||
|
if (botComment) {
|
||||||
|
await github.issues.updateComment({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
comment_id: botComment.id,
|
||||||
|
body: commentBody
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await github.issues.createComment({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: context.payload.number,
|
||||||
|
body: commentBody
|
||||||
|
})
|
||||||
|
}
|
||||||
+2
-1
@@ -1 +1,2 @@
|
|||||||
!node_modules
|
/node_modules/
|
||||||
|
!/.vscode/
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
sources:
|
||||||
|
npm: true
|
||||||
|
|
||||||
|
allowed:
|
||||||
|
- apache-2.0
|
||||||
|
- bsd-2-clause
|
||||||
|
- bsd-3-clause
|
||||||
|
- isc
|
||||||
|
- mit
|
||||||
|
- cc0-1.0
|
||||||
|
- unlicense
|
||||||
|
|
||||||
|
reviewed:
|
||||||
|
npm:
|
||||||
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
@@ -0,0 +1,5 @@
|
|||||||
|
arrowParens: avoid
|
||||||
|
bracketSpacing: false
|
||||||
|
semi: false
|
||||||
|
singleQuote: true
|
||||||
|
trailingComma: none
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.organizeImports": true
|
||||||
|
},
|
||||||
|
"files.exclude": {
|
||||||
|
"**/dist": true,
|
||||||
|
"**/node_modules": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
# github-script
|
# github-script  
|
||||||
|
|
||||||
This action makes it easy to quickly write a script in your workflow that
|
This action makes it easy to quickly write a script in your workflow that
|
||||||
uses the GitHub API and the workflow run context.
|
uses the GitHub API and the workflow run context.
|
||||||
|
|
||||||
In order to use this action, a `script` input is provided. The value of that
|
In order to use this action, a `script` input is provided. The value of that
|
||||||
input should be the body of an asynchronous function call. Two arguments will
|
input should be the body of an asynchronous function call. The following
|
||||||
be provided:
|
arguments will be provided:
|
||||||
|
|
||||||
- `github` A pre-authenticated
|
- `github` A pre-authenticated
|
||||||
[octokit/rest.js](https://github.com/octokit/rest.js) client
|
[octokit/rest.js](https://github.com/octokit/rest.js) client
|
||||||
- `context` An object containing the [context of the workflow
|
- `context` An object containing the [context of the workflow
|
||||||
run](https://github.com/actions/toolkit/tree/master/packages/github)
|
run](https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts)
|
||||||
|
- `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package
|
||||||
|
- `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package
|
||||||
|
|
||||||
Since the `script` is just a function body, these values will already be
|
Since the `script` is just a function body, these values will already be
|
||||||
defined, so you don't have to (see examples below).
|
defined, so you don't have to (see examples below).
|
||||||
@@ -19,42 +21,96 @@ See [octokit/rest.js](https://octokit.github.io/rest.js/) for the API client
|
|||||||
documentation.
|
documentation.
|
||||||
|
|
||||||
**Note** This action is still a bit of an experiment—the API may change in
|
**Note** This action is still a bit of an experiment—the API may change in
|
||||||
*future versions. 🙂
|
future versions. 🙂
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
See [development.md](/docs/development.md).
|
||||||
|
|
||||||
|
## Reading step results
|
||||||
|
|
||||||
|
The return value of the script will be in the step's outputs under the
|
||||||
|
"result" key.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/github-script@v2
|
||||||
|
id: set-result
|
||||||
|
with:
|
||||||
|
script: return "Hello!"
|
||||||
|
result-encoding: string
|
||||||
|
- name: Get result
|
||||||
|
run: echo "${{steps.set-result.outputs.result}}"
|
||||||
|
```
|
||||||
|
|
||||||
|
See ["Result encoding"](#result-encoding) for details on how the encoding of
|
||||||
|
these outputs can be changed.
|
||||||
|
|
||||||
|
## Result encoding
|
||||||
|
|
||||||
|
By default, the JSON-encoded return value of the function is set as the "result" in the
|
||||||
|
output of a github-script step. For some workflows, string encoding is preferred. This option can be set using the
|
||||||
|
`result-encoding` input:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/github-script@v2
|
||||||
|
id: my-script
|
||||||
|
with:
|
||||||
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
result-encoding: string
|
||||||
|
script: return "I will be string (not JSON) encoded!"
|
||||||
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
Note that `github-token` is optional in this action, and the input is there
|
||||||
|
in case you need to use a non-default token.
|
||||||
|
|
||||||
|
By default, github-script will use the token provided to your workflow.
|
||||||
|
|
||||||
### Comment on an issue
|
### Comment on an issue
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
issues: {types: opened}
|
issues:
|
||||||
|
types: [opened]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
comment:
|
comment:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@0.3.0
|
- uses: actions/github-script@v2
|
||||||
with:
|
with:
|
||||||
github-token: ${{github.token}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
script: |
|
script: |
|
||||||
github.issues.createComment({...context.issue, body: '👋 Thanks for reporting!'})
|
github.issues.createComment({
|
||||||
|
issue_number: context.issue.number,
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
body: '👋 Thanks for reporting!'
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Apply a label to an issue
|
### Apply a label to an issue
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
issues: {types: opened}
|
issues:
|
||||||
|
types: [opened]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
apply-label:
|
apply-label:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@0.2.0
|
- uses: actions/github-script@v2
|
||||||
with:
|
with:
|
||||||
github-token: ${{github.token}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
script: |
|
script: |
|
||||||
github.issues.addLabels({...context.issue, labels: ['Triage']})
|
github.issues.addLabels({
|
||||||
|
issue_number: context.issue.number,
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
labels: ['Triage']
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Welcome a first-time contributor
|
### Welcome a first-time contributor
|
||||||
@@ -66,9 +122,9 @@ jobs:
|
|||||||
welcome:
|
welcome:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@0.2.0
|
- uses: actions/github-script@v2
|
||||||
with:
|
with:
|
||||||
github-token: ${{github.token}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
script: |
|
script: |
|
||||||
// Get a list of all issues created by the PR opener
|
// Get a list of all issues created by the PR opener
|
||||||
// See: https://octokit.github.io/rest.js/#pagination
|
// See: https://octokit.github.io/rest.js/#pagination
|
||||||
@@ -90,7 +146,12 @@ jobs:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await github.issues.createComment({...context.issue, body: 'Welcome, new contributor!'})
|
await github.issues.createComment({
|
||||||
|
issue_number: context.issue.number,
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
body: 'Welcome, new contributor!'
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Download data from a URL
|
### Download data from a URL
|
||||||
@@ -99,21 +160,65 @@ You can use the `github` object to access the Octokit API. For
|
|||||||
instance, `github.request`
|
instance, `github.request`
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on: pull_request
|
||||||
pull_request
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
diff:
|
diff:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@0.2.0
|
- uses: actions/github-script@v2
|
||||||
with:
|
with:
|
||||||
github-token: ${{github.token}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
script: |
|
script: |
|
||||||
const diff_url = context.payload.pull_request.diff_url
|
const diff_url = context.payload.pull_request.diff_url
|
||||||
const result = await github.request(diff_url)
|
const result = await github.request(diff_url)
|
||||||
console.log(result)
|
console.log(result)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
_(Note that this particular example only works for a public URL, where the
|
||||||
|
diff URL is publicly accessible. Getting the diff for a private URL requires
|
||||||
|
using the API.)_
|
||||||
|
|
||||||
This will print the full diff object in the screen; `result.data` will
|
This will print the full diff object in the screen; `result.data` will
|
||||||
contain the actual diff text.
|
contain the actual diff text.
|
||||||
|
|
||||||
|
### Run a separate file
|
||||||
|
|
||||||
|
If you don't want to inline your entire script that you want to run, you can
|
||||||
|
use a separate JavaScript module in your repository like so:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
echo-input:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/github-script@v2
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`)
|
||||||
|
console.log(script({github, context}))
|
||||||
|
```
|
||||||
|
|
||||||
|
*Note that the script path given to `require()` must be an **absolute path** in this case, hence using [`GITHUB_WORKSPACE`](https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables).*
|
||||||
|
|
||||||
|
And then export a function from your module:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
module.exports = (github, context) => {
|
||||||
|
return context.payload.client_payload.value
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use async functions in this manner, as long as you `await` it in
|
||||||
|
the inline script.
|
||||||
|
|
||||||
|
Note that because you can't `require` things like the GitHub context or
|
||||||
|
Actions Toolkit libraries, you'll want to pass them as arguments to your
|
||||||
|
external function.
|
||||||
|
|
||||||
|
Additionally, you'll want to use the [checkout
|
||||||
|
action](https://github.com/actions/checkout) to make sure your script file is
|
||||||
|
available.
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
|
import {callAsyncFunction} from '../src/async-function'
|
||||||
|
|
||||||
|
describe('callAsyncFunction', () => {
|
||||||
|
test('calls the function with its arguments', async () => {
|
||||||
|
const result = await callAsyncFunction({foo: 'bar'} as any, 'return foo')
|
||||||
|
expect(result).toEqual('bar')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('throws on ReferenceError', async () => {
|
||||||
|
expect.assertions(1)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await callAsyncFunction({} as any, 'proces')
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).toBeInstanceOf(ReferenceError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can access process', async () => {
|
||||||
|
await callAsyncFunction({} as any, 'process')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can access console', async () => {
|
||||||
|
await callAsyncFunction({} as any, 'console')
|
||||||
|
})
|
||||||
|
})
|
||||||
+6
-2
@@ -10,7 +10,8 @@ inputs:
|
|||||||
required: true
|
required: true
|
||||||
github-token:
|
github-token:
|
||||||
description: The GitHub token used to create an authenticated client
|
description: The GitHub token used to create an authenticated client
|
||||||
required: true
|
default: ${{ github.token }}
|
||||||
|
required: false
|
||||||
debug:
|
debug:
|
||||||
description: Whether to tell the GitHub client to log details of its requests
|
description: Whether to tell the GitHub client to log details of its requests
|
||||||
default: false
|
default: false
|
||||||
@@ -19,9 +20,12 @@ inputs:
|
|||||||
default: actions/github-script
|
default: actions/github-script
|
||||||
previews:
|
previews:
|
||||||
description: A comma-separated list of API previews to accept
|
description: A comma-separated list of API previews to accept
|
||||||
|
result-encoding:
|
||||||
|
description: Either "string" or "json" (default "json")—how the result will be encoded
|
||||||
|
default: json
|
||||||
outputs:
|
outputs:
|
||||||
result:
|
result:
|
||||||
description: The return value of the script, stringified with `JSON.stringify`
|
description: The return value of the script, stringified with `JSON.stringify`
|
||||||
runs:
|
runs:
|
||||||
using: node12
|
using: node12
|
||||||
main: main.js
|
main: dist/index.js
|
||||||
Vendored
+12729
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,28 @@
|
|||||||
|
# Development
|
||||||
|
|
||||||
|
## How this action works
|
||||||
|
|
||||||
|
This action works by evaluating the user input as the body of an asynchronous
|
||||||
|
JavaScript function. See [main.ts](/src/main.ts) for details.
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
Before the action can be used, it needs to be compiled to JavaScript:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
bash> npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
It also has a pre-commit hook configured via
|
||||||
|
[husky](https://www.npmjs.com/package/husky) that should run the build script
|
||||||
|
before each commit. Additionally, this hook formats code and lints it, as
|
||||||
|
well.
|
||||||
|
|
||||||
|
## Releasing
|
||||||
|
|
||||||
|
Releases are done manually, for now:
|
||||||
|
|
||||||
|
1. Ensure that the build is up to date with `npm run build`.
|
||||||
|
1. Bump the [package.json](/package.json#L3) and [package-lock.json](/package-lock.json#L3) version numbers and commit them.
|
||||||
|
1. Update documentation (including updated version numbers).
|
||||||
|
1. Tag main with the new version number and create a GitHub release.
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
const core = require('@actions/core')
|
|
||||||
const {GitHub, context} = require('@actions/github')
|
|
||||||
|
|
||||||
process.on('unhandledRejection', handleError)
|
|
||||||
main().catch(handleError)
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor
|
|
||||||
const token = core.getInput('github-token', {required: true})
|
|
||||||
const debug = core.getInput('debug')
|
|
||||||
const userAgent = core.getInput('user-agent')
|
|
||||||
const previews = core.getInput('previews')
|
|
||||||
const opts = {}
|
|
||||||
if (debug === 'true') opts.log = console
|
|
||||||
if (userAgent != null) opts.userAgent = userAgent
|
|
||||||
if (previews != null) opts.previews = previews.split(',')
|
|
||||||
const client = new GitHub(token, opts)
|
|
||||||
const script = core.getInput('script', {required: true})
|
|
||||||
const fn = new AsyncFunction('require', 'github', 'context', script)
|
|
||||||
const result = await fn(require, client, context)
|
|
||||||
core.setOutput('result', JSON.stringify(result))
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleError(err) {
|
|
||||||
console.error(err)
|
|
||||||
core.setFailed(err.message)
|
|
||||||
}
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
../semver/bin/semver
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
../which/bin/which
|
|
||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
{
|
|
||||||
"systemParams": "darwin-x64-72",
|
|
||||||
"modulesFolders": [
|
|
||||||
"node_modules"
|
|
||||||
],
|
|
||||||
"flags": [],
|
|
||||||
"linkedModules": [],
|
|
||||||
"topLevelPatterns": [
|
|
||||||
"@actions/core@^1.1.0",
|
|
||||||
"@actions/github@^1.1.0"
|
|
||||||
],
|
|
||||||
"lockfileEntries": {
|
|
||||||
"@actions/core@^1.1.0": "https://registry.yarnpkg.com/@actions/core/-/core-1.1.0.tgz#25c3aff43a20f9c5a04e2a3439898a49ba8d3625",
|
|
||||||
"@actions/github@^1.1.0": "https://registry.yarnpkg.com/@actions/github/-/github-1.1.0.tgz#06f34e6b0cf07eb2b3641de3e680dbfae6bcd400",
|
|
||||||
"@octokit/endpoint@^5.1.0": "https://registry.yarnpkg.com/@octokit/endpoint/-/endpoint-5.3.2.tgz#2deda2d869cac9ba7f370287d55667be2a808d4b",
|
|
||||||
"@octokit/graphql@^2.0.1": "https://registry.yarnpkg.com/@octokit/graphql/-/graphql-2.1.3.tgz#60c058a0ed5fa242eca6f938908d95fd1a2f4b92",
|
|
||||||
"@octokit/request-error@^1.0.1": "https://registry.yarnpkg.com/@octokit/request-error/-/request-error-1.0.4.tgz#15e1dc22123ba4a9a4391914d80ec1e5303a23be",
|
|
||||||
"@octokit/request-error@^1.0.2": "https://registry.yarnpkg.com/@octokit/request-error/-/request-error-1.0.4.tgz#15e1dc22123ba4a9a4391914d80ec1e5303a23be",
|
|
||||||
"@octokit/request@^5.0.0": "https://registry.yarnpkg.com/@octokit/request/-/request-5.0.2.tgz#59a920451f24811c016ddc507adcc41aafb2dca5",
|
|
||||||
"@octokit/rest@^16.15.0": "https://registry.yarnpkg.com/@octokit/rest/-/rest-16.28.7.tgz#a2c2db5b318da84144beba82d19c1a9dbdb1a1fa",
|
|
||||||
"atob-lite@^2.0.0": "https://registry.yarnpkg.com/atob-lite/-/atob-lite-2.0.0.tgz#0fef5ad46f1bd7a8502c65727f0367d5ee43d696",
|
|
||||||
"before-after-hook@^2.0.0": "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.1.0.tgz#b6c03487f44e24200dd30ca5e6a1979c5d2fb635",
|
|
||||||
"btoa-lite@^1.0.0": "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337",
|
|
||||||
"cross-spawn@^6.0.0": "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4",
|
|
||||||
"deepmerge@4.0.0": "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.0.0.tgz#3e3110ca29205f120d7cb064960a39c3d2087c09",
|
|
||||||
"deprecation@^2.0.0": "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919",
|
|
||||||
"end-of-stream@^1.1.0": "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.1.tgz#ed29634d19baba463b6ce6b80a37213eab71ec43",
|
|
||||||
"execa@^1.0.0": "https://registry.yarnpkg.com/execa/-/execa-1.0.0.tgz#c6236a5bb4df6d6f15e88e7f017798216749ddd8",
|
|
||||||
"get-stream@^4.0.0": "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5",
|
|
||||||
"is-plain-object@^3.0.0": "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-3.0.0.tgz#47bfc5da1b5d50d64110806c199359482e75a928",
|
|
||||||
"is-stream@^1.1.0": "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44",
|
|
||||||
"isexe@^2.0.0": "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10",
|
|
||||||
"isobject@^4.0.0": "https://registry.yarnpkg.com/isobject/-/isobject-4.0.0.tgz#3f1c9155e73b192022a80819bacd0343711697b0",
|
|
||||||
"lodash.get@^4.4.2": "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99",
|
|
||||||
"lodash.set@^4.3.2": "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23",
|
|
||||||
"lodash.uniq@^4.5.0": "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773",
|
|
||||||
"macos-release@^2.2.0": "https://registry.yarnpkg.com/macos-release/-/macos-release-2.3.0.tgz#eb1930b036c0800adebccd5f17bc4c12de8bb71f",
|
|
||||||
"nice-try@^1.0.4": "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366",
|
|
||||||
"node-fetch@^2.3.0": "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd",
|
|
||||||
"npm-run-path@^2.0.0": "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f",
|
|
||||||
"octokit-pagination-methods@^1.1.0": "https://registry.yarnpkg.com/octokit-pagination-methods/-/octokit-pagination-methods-1.1.0.tgz#cf472edc9d551055f9ef73f6e42b4dbb4c80bea4",
|
|
||||||
"once@^1.3.1": "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1",
|
|
||||||
"once@^1.4.0": "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1",
|
|
||||||
"os-name@^3.0.0": "https://registry.yarnpkg.com/os-name/-/os-name-3.1.0.tgz#dec19d966296e1cd62d701a5a66ee1ddeae70801",
|
|
||||||
"p-finally@^1.0.0": "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae",
|
|
||||||
"path-key@^2.0.0": "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40",
|
|
||||||
"path-key@^2.0.1": "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40",
|
|
||||||
"pump@^3.0.0": "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64",
|
|
||||||
"semver@^5.5.0": "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7",
|
|
||||||
"shebang-command@^1.2.0": "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea",
|
|
||||||
"shebang-regex@^1.0.0": "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3",
|
|
||||||
"signal-exit@^3.0.0": "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d",
|
|
||||||
"strip-eof@^1.0.0": "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf",
|
|
||||||
"universal-user-agent@^2.0.3": "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-2.1.0.tgz#5abfbcc036a1ba490cb941f8fd68c46d3669e8e4",
|
|
||||||
"universal-user-agent@^3.0.0": "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-3.0.0.tgz#4cc88d68097bffd7ac42e3b7c903e7481424b4b9",
|
|
||||||
"url-template@^2.0.8": "https://registry.yarnpkg.com/url-template/-/url-template-2.0.8.tgz#fc565a3cccbff7730c775f5641f9555791439f21",
|
|
||||||
"which@^1.2.9": "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a",
|
|
||||||
"windows-release@^3.1.0": "https://registry.yarnpkg.com/windows-release/-/windows-release-3.2.0.tgz#8122dad5afc303d833422380680a79cdfa91785f",
|
|
||||||
"wrappy@1": "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
|
|
||||||
},
|
|
||||||
"files": [],
|
|
||||||
"artifacts": {}
|
|
||||||
}
|
|
||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
Copyright 2019 GitHub
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
-97
@@ -1,97 +0,0 @@
|
|||||||
# `@actions/core`
|
|
||||||
|
|
||||||
> Core functions for setting results, logging, registering secrets and exporting variables across actions
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
#### Inputs/Outputs
|
|
||||||
|
|
||||||
You can use this library to get inputs or set outputs:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
const myInput = core.getInput('inputName', { required: true });
|
|
||||||
|
|
||||||
// Do stuff
|
|
||||||
|
|
||||||
core.setOutput('outputKey', 'outputVal');
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Exporting variables
|
|
||||||
|
|
||||||
You can also export variables for future steps. Variables get set in the environment.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
// Do stuff
|
|
||||||
|
|
||||||
core.exportVariable('envVar', 'Val');
|
|
||||||
```
|
|
||||||
|
|
||||||
#### PATH Manipulation
|
|
||||||
|
|
||||||
You can explicitly add items to the path for all remaining steps in a workflow:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
core.addPath('pathToTool');
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Exit codes
|
|
||||||
|
|
||||||
You should use this library to set the failing exit code for your action:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Do stuff
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
// setFailed logs the message and sets a failing exit code
|
|
||||||
core.setFailed(`Action failed with error ${err}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Logging
|
|
||||||
|
|
||||||
Finally, this library provides some utilities for logging. Note that debug logging is hidden from the logs by default. This behavior can be toggled by enabling the [Step Debug Logs](../../docs/action-debugging.md#step-debug-logs).
|
|
||||||
|
|
||||||
```js
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
const myInput = core.getInput('input');
|
|
||||||
try {
|
|
||||||
core.debug('Inside try block');
|
|
||||||
|
|
||||||
if (!myInput) {
|
|
||||||
core.warning('myInput was not set');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do stuff
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
core.error(`Error ${err}, action may still succeed though`);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This library can also wrap chunks of output in foldable groups.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const core = require('@actions/core')
|
|
||||||
|
|
||||||
// Manually wrap output
|
|
||||||
core.startGroup('Do some function')
|
|
||||||
doSomeFunction()
|
|
||||||
core.endGroup()
|
|
||||||
|
|
||||||
// Wrap an asynchronous function call
|
|
||||||
const result = await core.group('Do something async', async () => {
|
|
||||||
const response = await doSomeHTTPRequest()
|
|
||||||
return response
|
|
||||||
})
|
|
||||||
```
|
|
||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
interface CommandProperties {
|
|
||||||
[key: string]: string;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Commands
|
|
||||||
*
|
|
||||||
* Command Format:
|
|
||||||
* ##[name key=value;key=value]message
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
* ##[warning]This is the user warning message
|
|
||||||
* ##[set-secret name=mypassword]definitelyNotAPassword!
|
|
||||||
*/
|
|
||||||
export declare function issueCommand(command: string, properties: CommandProperties, message: string): void;
|
|
||||||
export declare function issue(name: string, message?: string): void;
|
|
||||||
export {};
|
|
||||||
-66
@@ -1,66 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const os = require("os");
|
|
||||||
/**
|
|
||||||
* Commands
|
|
||||||
*
|
|
||||||
* Command Format:
|
|
||||||
* ##[name key=value;key=value]message
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
* ##[warning]This is the user warning message
|
|
||||||
* ##[set-secret name=mypassword]definitelyNotAPassword!
|
|
||||||
*/
|
|
||||||
function issueCommand(command, properties, message) {
|
|
||||||
const cmd = new Command(command, properties, message);
|
|
||||||
process.stdout.write(cmd.toString() + os.EOL);
|
|
||||||
}
|
|
||||||
exports.issueCommand = issueCommand;
|
|
||||||
function issue(name, message = '') {
|
|
||||||
issueCommand(name, {}, message);
|
|
||||||
}
|
|
||||||
exports.issue = issue;
|
|
||||||
const CMD_PREFIX = '##[';
|
|
||||||
class Command {
|
|
||||||
constructor(command, properties, message) {
|
|
||||||
if (!command) {
|
|
||||||
command = 'missing.command';
|
|
||||||
}
|
|
||||||
this.command = command;
|
|
||||||
this.properties = properties;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
toString() {
|
|
||||||
let cmdStr = CMD_PREFIX + this.command;
|
|
||||||
if (this.properties && Object.keys(this.properties).length > 0) {
|
|
||||||
cmdStr += ' ';
|
|
||||||
for (const key in this.properties) {
|
|
||||||
if (this.properties.hasOwnProperty(key)) {
|
|
||||||
const val = this.properties[key];
|
|
||||||
if (val) {
|
|
||||||
// safely append the val - avoid blowing up when attempting to
|
|
||||||
// call .replace() if message is not a string for some reason
|
|
||||||
cmdStr += `${key}=${escape(`${val || ''}`)};`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cmdStr += ']';
|
|
||||||
// safely append the message - avoid blowing up when attempting to
|
|
||||||
// call .replace() if message is not a string for some reason
|
|
||||||
const message = `${this.message || ''}`;
|
|
||||||
cmdStr += escapeData(message);
|
|
||||||
return cmdStr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function escapeData(s) {
|
|
||||||
return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A');
|
|
||||||
}
|
|
||||||
function escape(s) {
|
|
||||||
return s
|
|
||||||
.replace(/\r/g, '%0D')
|
|
||||||
.replace(/\n/g, '%0A')
|
|
||||||
.replace(/]/g, '%5D')
|
|
||||||
.replace(/;/g, '%3B');
|
|
||||||
}
|
|
||||||
//# sourceMappingURL=command.js.map
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";;AAAA,yBAAwB;AAQxB;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,OAAe,EACf,UAA6B,EAC7B,OAAe;IAEf,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;IACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;AAC/C,CAAC;AAPD,oCAOC;AAED,SAAgB,KAAK,CAAC,IAAY,EAAE,UAAkB,EAAE;IACtD,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;AACjC,CAAC;AAFD,sBAEC;AAED,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,MAAM,OAAO;IAKX,YAAY,OAAe,EAAE,UAA6B,EAAE,OAAe;QACzE,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,iBAAiB,CAAA;SAC5B;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,QAAQ;QACN,IAAI,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC,OAAO,CAAA;QAEtC,IAAI,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9D,MAAM,IAAI,GAAG,CAAA;YACb,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE;gBACjC,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;oBACvC,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;oBAChC,IAAI,GAAG,EAAE;wBACP,8DAA8D;wBAC9D,6DAA6D;wBAC7D,MAAM,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAA;qBAC9C;iBACF;aACF;SACF;QAED,MAAM,IAAI,GAAG,CAAA;QAEb,kEAAkE;QAClE,6DAA6D;QAC7D,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,EAAE,CAAA;QACvC,MAAM,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;QAE7B,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AACtD,CAAC;AAED,SAAS,MAAM,CAAC,CAAS;IACvB,OAAO,CAAC;SACL,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AACzB,CAAC"}
|
|
||||||
-94
@@ -1,94 +0,0 @@
|
|||||||
/**
|
|
||||||
* Interface for getInput options
|
|
||||||
*/
|
|
||||||
export interface InputOptions {
|
|
||||||
/** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */
|
|
||||||
required?: boolean;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* The code to exit an action
|
|
||||||
*/
|
|
||||||
export declare enum ExitCode {
|
|
||||||
/**
|
|
||||||
* A code indicating that the action was successful
|
|
||||||
*/
|
|
||||||
Success = 0,
|
|
||||||
/**
|
|
||||||
* A code indicating that the action was a failure
|
|
||||||
*/
|
|
||||||
Failure = 1
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* sets env variable for this action and future actions in the job
|
|
||||||
* @param name the name of the variable to set
|
|
||||||
* @param val the value of the variable
|
|
||||||
*/
|
|
||||||
export declare function exportVariable(name: string, val: string): void;
|
|
||||||
/**
|
|
||||||
* exports the variable and registers a secret which will get masked from logs
|
|
||||||
* @param name the name of the variable to set
|
|
||||||
* @param val value of the secret
|
|
||||||
*/
|
|
||||||
export declare function exportSecret(name: string, val: string): void;
|
|
||||||
/**
|
|
||||||
* Prepends inputPath to the PATH (for this action and future actions)
|
|
||||||
* @param inputPath
|
|
||||||
*/
|
|
||||||
export declare function addPath(inputPath: string): void;
|
|
||||||
/**
|
|
||||||
* Gets the value of an input. The value is also trimmed.
|
|
||||||
*
|
|
||||||
* @param name name of the input to get
|
|
||||||
* @param options optional. See InputOptions.
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
export declare function getInput(name: string, options?: InputOptions): string;
|
|
||||||
/**
|
|
||||||
* Sets the value of an output.
|
|
||||||
*
|
|
||||||
* @param name name of the output to set
|
|
||||||
* @param value value to store
|
|
||||||
*/
|
|
||||||
export declare function setOutput(name: string, value: string): void;
|
|
||||||
/**
|
|
||||||
* Sets the action status to failed.
|
|
||||||
* When the action exits it will be with an exit code of 1
|
|
||||||
* @param message add error issue message
|
|
||||||
*/
|
|
||||||
export declare function setFailed(message: string): void;
|
|
||||||
/**
|
|
||||||
* Writes debug message to user log
|
|
||||||
* @param message debug message
|
|
||||||
*/
|
|
||||||
export declare function debug(message: string): void;
|
|
||||||
/**
|
|
||||||
* Adds an error issue
|
|
||||||
* @param message error issue message
|
|
||||||
*/
|
|
||||||
export declare function error(message: string): void;
|
|
||||||
/**
|
|
||||||
* Adds an warning issue
|
|
||||||
* @param message warning issue message
|
|
||||||
*/
|
|
||||||
export declare function warning(message: string): void;
|
|
||||||
/**
|
|
||||||
* Begin an output group.
|
|
||||||
*
|
|
||||||
* Output until the next `groupEnd` will be foldable in this group
|
|
||||||
*
|
|
||||||
* @param name The name of the output group
|
|
||||||
*/
|
|
||||||
export declare function startGroup(name: string): void;
|
|
||||||
/**
|
|
||||||
* End an output group.
|
|
||||||
*/
|
|
||||||
export declare function endGroup(): void;
|
|
||||||
/**
|
|
||||||
* Wrap an asynchronous function call in a group.
|
|
||||||
*
|
|
||||||
* Returns the same type as the function itself.
|
|
||||||
*
|
|
||||||
* @param name The name of the group
|
|
||||||
* @param fn The function to wrap in the group
|
|
||||||
*/
|
|
||||||
export declare function group<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
||||||
-168
@@ -1,168 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const command_1 = require("./command");
|
|
||||||
const path = require("path");
|
|
||||||
/**
|
|
||||||
* The code to exit an action
|
|
||||||
*/
|
|
||||||
var ExitCode;
|
|
||||||
(function (ExitCode) {
|
|
||||||
/**
|
|
||||||
* A code indicating that the action was successful
|
|
||||||
*/
|
|
||||||
ExitCode[ExitCode["Success"] = 0] = "Success";
|
|
||||||
/**
|
|
||||||
* A code indicating that the action was a failure
|
|
||||||
*/
|
|
||||||
ExitCode[ExitCode["Failure"] = 1] = "Failure";
|
|
||||||
})(ExitCode = exports.ExitCode || (exports.ExitCode = {}));
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// Variables
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* sets env variable for this action and future actions in the job
|
|
||||||
* @param name the name of the variable to set
|
|
||||||
* @param val the value of the variable
|
|
||||||
*/
|
|
||||||
function exportVariable(name, val) {
|
|
||||||
process.env[name] = val;
|
|
||||||
command_1.issueCommand('set-env', { name }, val);
|
|
||||||
}
|
|
||||||
exports.exportVariable = exportVariable;
|
|
||||||
/**
|
|
||||||
* exports the variable and registers a secret which will get masked from logs
|
|
||||||
* @param name the name of the variable to set
|
|
||||||
* @param val value of the secret
|
|
||||||
*/
|
|
||||||
function exportSecret(name, val) {
|
|
||||||
exportVariable(name, val);
|
|
||||||
// the runner will error with not implemented
|
|
||||||
// leaving the function but raising the error earlier
|
|
||||||
command_1.issueCommand('set-secret', {}, val);
|
|
||||||
throw new Error('Not implemented.');
|
|
||||||
}
|
|
||||||
exports.exportSecret = exportSecret;
|
|
||||||
/**
|
|
||||||
* Prepends inputPath to the PATH (for this action and future actions)
|
|
||||||
* @param inputPath
|
|
||||||
*/
|
|
||||||
function addPath(inputPath) {
|
|
||||||
command_1.issueCommand('add-path', {}, inputPath);
|
|
||||||
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
|
|
||||||
}
|
|
||||||
exports.addPath = addPath;
|
|
||||||
/**
|
|
||||||
* Gets the value of an input. The value is also trimmed.
|
|
||||||
*
|
|
||||||
* @param name name of the input to get
|
|
||||||
* @param options optional. See InputOptions.
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
function getInput(name, options) {
|
|
||||||
const val = process.env[`INPUT_${name.replace(' ', '_').toUpperCase()}`] || '';
|
|
||||||
if (options && options.required && !val) {
|
|
||||||
throw new Error(`Input required and not supplied: ${name}`);
|
|
||||||
}
|
|
||||||
return val.trim();
|
|
||||||
}
|
|
||||||
exports.getInput = getInput;
|
|
||||||
/**
|
|
||||||
* Sets the value of an output.
|
|
||||||
*
|
|
||||||
* @param name name of the output to set
|
|
||||||
* @param value value to store
|
|
||||||
*/
|
|
||||||
function setOutput(name, value) {
|
|
||||||
command_1.issueCommand('set-output', { name }, value);
|
|
||||||
}
|
|
||||||
exports.setOutput = setOutput;
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// Results
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* Sets the action status to failed.
|
|
||||||
* When the action exits it will be with an exit code of 1
|
|
||||||
* @param message add error issue message
|
|
||||||
*/
|
|
||||||
function setFailed(message) {
|
|
||||||
process.exitCode = ExitCode.Failure;
|
|
||||||
error(message);
|
|
||||||
}
|
|
||||||
exports.setFailed = setFailed;
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// Logging Commands
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* Writes debug message to user log
|
|
||||||
* @param message debug message
|
|
||||||
*/
|
|
||||||
function debug(message) {
|
|
||||||
command_1.issueCommand('debug', {}, message);
|
|
||||||
}
|
|
||||||
exports.debug = debug;
|
|
||||||
/**
|
|
||||||
* Adds an error issue
|
|
||||||
* @param message error issue message
|
|
||||||
*/
|
|
||||||
function error(message) {
|
|
||||||
command_1.issue('error', message);
|
|
||||||
}
|
|
||||||
exports.error = error;
|
|
||||||
/**
|
|
||||||
* Adds an warning issue
|
|
||||||
* @param message warning issue message
|
|
||||||
*/
|
|
||||||
function warning(message) {
|
|
||||||
command_1.issue('warning', message);
|
|
||||||
}
|
|
||||||
exports.warning = warning;
|
|
||||||
/**
|
|
||||||
* Begin an output group.
|
|
||||||
*
|
|
||||||
* Output until the next `groupEnd` will be foldable in this group
|
|
||||||
*
|
|
||||||
* @param name The name of the output group
|
|
||||||
*/
|
|
||||||
function startGroup(name) {
|
|
||||||
command_1.issue('group', name);
|
|
||||||
}
|
|
||||||
exports.startGroup = startGroup;
|
|
||||||
/**
|
|
||||||
* End an output group.
|
|
||||||
*/
|
|
||||||
function endGroup() {
|
|
||||||
command_1.issue('endgroup');
|
|
||||||
}
|
|
||||||
exports.endGroup = endGroup;
|
|
||||||
/**
|
|
||||||
* Wrap an asynchronous function call in a group.
|
|
||||||
*
|
|
||||||
* Returns the same type as the function itself.
|
|
||||||
*
|
|
||||||
* @param name The name of the group
|
|
||||||
* @param fn The function to wrap in the group
|
|
||||||
*/
|
|
||||||
function group(name, fn) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
startGroup(name);
|
|
||||||
let result;
|
|
||||||
try {
|
|
||||||
result = yield fn();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
endGroup();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.group = group;
|
|
||||||
//# sourceMappingURL=core.js.map
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uCAA6C;AAE7C,6BAA4B;AAU5B;;GAEG;AACH,IAAY,QAUX;AAVD,WAAY,QAAQ;IAClB;;OAEG;IACH,6CAAW,CAAA;IAEX;;OAEG;IACH,6CAAW,CAAA;AACb,CAAC,EAVW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAUnB;AAED,yEAAyE;AACzE,YAAY;AACZ,yEAAyE;AAEzE;;;;GAIG;AACH,SAAgB,cAAc,CAAC,IAAY,EAAE,GAAW;IACtD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;IACvB,sBAAY,CAAC,SAAS,EAAE,EAAC,IAAI,EAAC,EAAE,GAAG,CAAC,CAAA;AACtC,CAAC;AAHD,wCAGC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAY,EAAE,GAAW;IACpD,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAEzB,6CAA6C;IAC7C,qDAAqD;IACrD,sBAAY,CAAC,YAAY,EAAE,EAAE,EAAE,GAAG,CAAC,CAAA;IACnC,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;AACrC,CAAC;AAPD,oCAOC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,SAAiB;IACvC,sBAAY,CAAC,UAAU,EAAE,EAAE,EAAE,SAAS,CAAC,CAAA;IACvC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,SAAS,GAAG,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;AAC7E,CAAC;AAHD,0BAGC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,IAAY,EAAE,OAAsB;IAC3D,MAAM,GAAG,GACP,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,EAAE,CAAA;IACpE,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAA;KAC5D;IAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AACnB,CAAC;AARD,4BAQC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,IAAY,EAAE,KAAa;IACnD,sBAAY,CAAC,YAAY,EAAE,EAAC,IAAI,EAAC,EAAE,KAAK,CAAC,CAAA;AAC3C,CAAC;AAFD,8BAEC;AAED,yEAAyE;AACzE,UAAU;AACV,yEAAyE;AAEzE;;;;GAIG;AACH,SAAgB,SAAS,CAAC,OAAe;IACvC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAA;IACnC,KAAK,CAAC,OAAO,CAAC,CAAA;AAChB,CAAC;AAHD,8BAGC;AAED,yEAAyE;AACzE,mBAAmB;AACnB,yEAAyE;AAEzE;;;GAGG;AACH,SAAgB,KAAK,CAAC,OAAe;IACnC,sBAAY,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;AACpC,CAAC;AAFD,sBAEC;AAED;;;GAGG;AACH,SAAgB,KAAK,CAAC,OAAe;IACnC,eAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACzB,CAAC;AAFD,sBAEC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,OAAe;IACrC,eAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;AAC3B,CAAC;AAFD,0BAEC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,eAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AACtB,CAAC;AAFD,gCAEC;AAED;;GAEG;AACH,SAAgB,QAAQ;IACtB,eAAK,CAAC,UAAU,CAAC,CAAA;AACnB,CAAC;AAFD,4BAEC;AAED;;;;;;;GAOG;AACH,SAAsB,KAAK,CAAI,IAAY,EAAE,EAAoB;;QAC/D,UAAU,CAAC,IAAI,CAAC,CAAA;QAEhB,IAAI,MAAS,CAAA;QAEb,IAAI;YACF,MAAM,GAAG,MAAM,EAAE,EAAE,CAAA;SACpB;gBAAS;YACR,QAAQ,EAAE,CAAA;SACX;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CAAA;AAZD,sBAYC"}
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@actions/core",
|
|
||||||
"version": "1.1.0",
|
|
||||||
"description": "Actions core lib",
|
|
||||||
"keywords": [
|
|
||||||
"github",
|
|
||||||
"actions",
|
|
||||||
"core"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "lib/core.js",
|
|
||||||
"directories": {
|
|
||||||
"lib": "lib",
|
|
||||||
"test": "__tests__"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"lib"
|
|
||||||
],
|
|
||||||
"publishConfig": {
|
|
||||||
"access": "public"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/actions/toolkit.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
|
||||||
"tsc": "tsc"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "^12.0.2"
|
|
||||||
},
|
|
||||||
"gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52"
|
|
||||||
}
|
|
||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
Copyright 2019 GitHub
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
-50
@@ -1,50 +0,0 @@
|
|||||||
# `@actions/github`
|
|
||||||
|
|
||||||
> A hydrated Octokit client.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Returns an Octokit client. See https://octokit.github.io/rest.js for the API.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const github = require('@actions/github');
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
// This should be a token with access to your repository scoped in as a secret.
|
|
||||||
const myToken = core.getInput('myToken');
|
|
||||||
|
|
||||||
const octokit = new github.GitHub(myToken);
|
|
||||||
|
|
||||||
const { data: pullRequest } = await octokit.pulls.get({
|
|
||||||
owner: 'octokit',
|
|
||||||
repo: 'rest.js',
|
|
||||||
pull_number: 123,
|
|
||||||
mediaType: {
|
|
||||||
format: 'diff'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(pullRequest);
|
|
||||||
```
|
|
||||||
|
|
||||||
You can pass client options (except `auth`, which is handled by the token argument), as specified by [Octokit](https://octokit.github.io/rest.js/), as a second argument to the `GitHub` constructor.
|
|
||||||
|
|
||||||
You can also make GraphQL requests. See https://github.com/octokit/graphql.js for the API.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const result = await octokit.graphql(query, variables);
|
|
||||||
```
|
|
||||||
|
|
||||||
Finally, you can get the context of the current action:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const github = require('@actions/github');
|
|
||||||
|
|
||||||
const context = github.context;
|
|
||||||
|
|
||||||
const newIssue = await octokit.issues.create({
|
|
||||||
...context.repo,
|
|
||||||
title: 'New issue!',
|
|
||||||
body: 'Hello Universe!'
|
|
||||||
});
|
|
||||||
```
|
|
||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
import { WebhookPayload } from './interfaces';
|
|
||||||
export declare class Context {
|
|
||||||
/**
|
|
||||||
* Webhook payload object that triggered the workflow
|
|
||||||
*/
|
|
||||||
payload: WebhookPayload;
|
|
||||||
eventName: string;
|
|
||||||
sha: string;
|
|
||||||
ref: string;
|
|
||||||
workflow: string;
|
|
||||||
action: string;
|
|
||||||
actor: string;
|
|
||||||
/**
|
|
||||||
* Hydrate the context from the environment
|
|
||||||
*/
|
|
||||||
constructor();
|
|
||||||
readonly issue: {
|
|
||||||
owner: string;
|
|
||||||
repo: string;
|
|
||||||
number: number;
|
|
||||||
};
|
|
||||||
readonly repo: {
|
|
||||||
owner: string;
|
|
||||||
repo: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
-45
@@ -1,45 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const fs_1 = require("fs");
|
|
||||||
const os_1 = require("os");
|
|
||||||
class Context {
|
|
||||||
/**
|
|
||||||
* Hydrate the context from the environment
|
|
||||||
*/
|
|
||||||
constructor() {
|
|
||||||
this.payload = {};
|
|
||||||
if (process.env.GITHUB_EVENT_PATH) {
|
|
||||||
if (fs_1.existsSync(process.env.GITHUB_EVENT_PATH)) {
|
|
||||||
this.payload = JSON.parse(fs_1.readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' }));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
process.stdout.write(`GITHUB_EVENT_PATH ${process.env.GITHUB_EVENT_PATH} does not exist${os_1.EOL}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.eventName = process.env.GITHUB_EVENT_NAME;
|
|
||||||
this.sha = process.env.GITHUB_SHA;
|
|
||||||
this.ref = process.env.GITHUB_REF;
|
|
||||||
this.workflow = process.env.GITHUB_WORKFLOW;
|
|
||||||
this.action = process.env.GITHUB_ACTION;
|
|
||||||
this.actor = process.env.GITHUB_ACTOR;
|
|
||||||
}
|
|
||||||
get issue() {
|
|
||||||
const payload = this.payload;
|
|
||||||
return Object.assign(Object.assign({}, this.repo), { number: (payload.issue || payload.pullRequest || payload).number });
|
|
||||||
}
|
|
||||||
get repo() {
|
|
||||||
if (process.env.GITHUB_REPOSITORY) {
|
|
||||||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
|
|
||||||
return { owner, repo };
|
|
||||||
}
|
|
||||||
if (this.payload.repository) {
|
|
||||||
return {
|
|
||||||
owner: this.payload.repository.owner.login,
|
|
||||||
repo: this.payload.repository.name
|
|
||||||
};
|
|
||||||
}
|
|
||||||
throw new Error("context.repo requires a GITHUB_REPOSITORY environment variable like 'owner/repo'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Context = Context;
|
|
||||||
//# sourceMappingURL=context.js.map
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;AAEA,2BAA2C;AAC3C,2BAAsB;AAEtB,MAAa,OAAO;IAalB;;OAEG;IACH;QACE,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;YACjC,IAAI,eAAU,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE;gBAC7C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CACvB,iBAAY,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAChE,CAAA;aACF;iBAAM;gBACL,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,qBACE,OAAO,CAAC,GAAG,CAAC,iBACd,kBAAkB,QAAG,EAAE,CACxB,CAAA;aACF;SACF;QACD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,iBAA2B,CAAA;QACxD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,UAAoB,CAAA;QAC3C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,UAAoB,CAAA;QAC3C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,eAAyB,CAAA;QACrD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,aAAuB,CAAA;QACjD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAsB,CAAA;IACjD,CAAC;IAED,IAAI,KAAK;QACP,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAE5B,uCACK,IAAI,CAAC,IAAI,KACZ,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC,MAAM,IACjE;IACH,CAAC;IAED,IAAI,IAAI;QACN,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;YACjC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC9D,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,CAAA;SACrB;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC3B,OAAO;gBACL,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK;gBAC1C,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI;aACnC,CAAA;SACF;QAED,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAA;IACH,CAAC;CACF;AAjED,0BAiEC"}
|
|
||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
import { GraphQlQueryResponse, Variables } from '@octokit/graphql';
|
|
||||||
import Octokit from '@octokit/rest';
|
|
||||||
import * as Context from './context';
|
|
||||||
export declare const context: Context.Context;
|
|
||||||
export declare class GitHub extends Octokit {
|
|
||||||
graphql: (query: string, variables?: Variables) => Promise<GraphQlQueryResponse>;
|
|
||||||
constructor(token: string, opts?: Omit<Octokit.Options, 'auth'>);
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
||||||
};
|
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
|
||||||
if (mod && mod.__esModule) return mod;
|
|
||||||
var result = {};
|
|
||||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
||||||
result["default"] = mod;
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/master/src/github.ts
|
|
||||||
const graphql_1 = require("@octokit/graphql");
|
|
||||||
const rest_1 = __importDefault(require("@octokit/rest"));
|
|
||||||
const Context = __importStar(require("./context"));
|
|
||||||
// We need this in order to extend Octokit
|
|
||||||
rest_1.default.prototype = new rest_1.default();
|
|
||||||
exports.context = new Context.Context();
|
|
||||||
class GitHub extends rest_1.default {
|
|
||||||
constructor(token, opts = {}) {
|
|
||||||
super(Object.assign(Object.assign({}, opts), { auth: `token ${token}` }));
|
|
||||||
this.graphql = graphql_1.defaults({
|
|
||||||
headers: { authorization: `token ${token}` }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.GitHub = GitHub;
|
|
||||||
//# sourceMappingURL=github.js.map
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"github.js","sourceRoot":"","sources":["../src/github.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gGAAgG;AAChG,8CAA0E;AAC1E,yDAAmC;AACnC,mDAAoC;AAEpC,0CAA0C;AAC1C,cAAO,CAAC,SAAS,GAAG,IAAI,cAAO,EAAE,CAAA;AAEpB,QAAA,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,CAAA;AAE5C,MAAa,MAAO,SAAQ,cAAO;IAMjC,YAAY,KAAa,EAAE,OAAsC,EAAE;QACjE,KAAK,iCAAK,IAAI,KAAE,IAAI,EAAE,SAAS,KAAK,EAAE,IAAE,CAAA;QACxC,IAAI,CAAC,OAAO,GAAG,kBAAQ,CAAC;YACtB,OAAO,EAAE,EAAC,aAAa,EAAE,SAAS,KAAK,EAAE,EAAC;SAC3C,CAAC,CAAA;IACJ,CAAC;CACF;AAZD,wBAYC"}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
export interface PayloadRepository {
|
|
||||||
[key: string]: any;
|
|
||||||
full_name?: string;
|
|
||||||
name: string;
|
|
||||||
owner: {
|
|
||||||
[key: string]: any;
|
|
||||||
login: string;
|
|
||||||
name?: string;
|
|
||||||
};
|
|
||||||
html_url?: string;
|
|
||||||
}
|
|
||||||
export interface WebhookPayload {
|
|
||||||
[key: string]: any;
|
|
||||||
repository?: PayloadRepository;
|
|
||||||
issue?: {
|
|
||||||
[key: string]: any;
|
|
||||||
number: number;
|
|
||||||
html_url?: string;
|
|
||||||
body?: string;
|
|
||||||
};
|
|
||||||
pull_request?: {
|
|
||||||
[key: string]: any;
|
|
||||||
number: number;
|
|
||||||
html_url?: string;
|
|
||||||
body?: string;
|
|
||||||
};
|
|
||||||
sender?: {
|
|
||||||
[key: string]: any;
|
|
||||||
type: string;
|
|
||||||
};
|
|
||||||
action?: string;
|
|
||||||
installation?: {
|
|
||||||
id: number;
|
|
||||||
[key: string]: any;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
//# sourceMappingURL=interfaces.js.map
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA,uDAAuD"}
|
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@actions/github",
|
|
||||||
"version": "1.1.0",
|
|
||||||
"description": "Actions github lib",
|
|
||||||
"keywords": [
|
|
||||||
"github",
|
|
||||||
"actions"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/github",
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "lib/github.js",
|
|
||||||
"directories": {
|
|
||||||
"lib": "lib",
|
|
||||||
"test": "__tests__"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"lib"
|
|
||||||
],
|
|
||||||
"publishConfig": {
|
|
||||||
"access": "public"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/actions/toolkit.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "jest",
|
|
||||||
"build": "tsc",
|
|
||||||
"tsc": "tsc"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@octokit/graphql": "^2.0.1",
|
|
||||||
"@octokit/rest": "^16.15.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"jest": "^24.7.1"
|
|
||||||
},
|
|
||||||
"gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52"
|
|
||||||
}
|
|
||||||
-21
@@ -1,21 +0,0 @@
|
|||||||
The MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2018 Octokit contributors
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
-421
@@ -1,421 +0,0 @@
|
|||||||
# endpoint.js
|
|
||||||
|
|
||||||
> Turns GitHub REST API endpoints into generic request options
|
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/@octokit/endpoint)
|
|
||||||
[](https://travis-ci.org/octokit/endpoint.js)
|
|
||||||
[](https://greenkeeper.io/)
|
|
||||||
|
|
||||||
`@octokit/endpoint` combines [GitHub REST API routes](https://developer.github.com/v3/) with your parameters and turns them into generic request options that can be used in any request library.
|
|
||||||
|
|
||||||
<!-- update table of contents by running `npx markdown-toc README.md -i` -->
|
|
||||||
<!-- toc -->
|
|
||||||
|
|
||||||
- [Usage](#usage)
|
|
||||||
- [API](#api)
|
|
||||||
- [endpoint()](#endpoint)
|
|
||||||
- [endpoint.defaults()](#endpointdefaults)
|
|
||||||
- [endpoint.DEFAULTS](#endpointdefaults)
|
|
||||||
- [endpoint.merge()](#endpointmerge)
|
|
||||||
- [endpoint.parse()](#endpointparse)
|
|
||||||
- [Special cases](#special-cases)
|
|
||||||
- [The `data` parameter – set request body directly](#the-data-parameter-%E2%80%93-set-request-body-directly)
|
|
||||||
- [Set parameters for both the URL/query and the request body](#set-parameters-for-both-the-urlquery-and-the-request-body)
|
|
||||||
- [LICENSE](#license)
|
|
||||||
|
|
||||||
<!-- tocstop -->
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<tbody valign=top align=left>
|
|
||||||
<tr><th>
|
|
||||||
Browsers
|
|
||||||
</th><td width=100%>
|
|
||||||
Load <code>@octokit/endpoint</code> directly from <a href="https://cdn.pika.dev">cdn.pika.dev</a>
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script type="module">
|
|
||||||
import { endpoint } from "https://cdn.pika.dev/@octokit/endpoint";
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
</td></tr>
|
|
||||||
<tr><th>
|
|
||||||
Node
|
|
||||||
</th><td>
|
|
||||||
|
|
||||||
Install with <code>npm install @octokit/endpoint</code>
|
|
||||||
|
|
||||||
```js
|
|
||||||
const { endpoint } = require("@octokit/endpoint");
|
|
||||||
// or: import { endpoint } from "@octokit/endpoint";
|
|
||||||
```
|
|
||||||
|
|
||||||
</td></tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
Example for [List organization repositories](https://developer.github.com/v3/repos/#list-organization-repositories)
|
|
||||||
|
|
||||||
```js
|
|
||||||
const requestOptions = endpoint("GET /orgs/:org/repos", {
|
|
||||||
headers: {
|
|
||||||
authorization: "token 0000000000000000000000000000000000000001"
|
|
||||||
},
|
|
||||||
org: "octokit",
|
|
||||||
type: "private"
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
The resulting `requestOptions` looks as follows
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"method": "GET",
|
|
||||||
"url": "https://api.github.com/orgs/octokit/repos?type=private",
|
|
||||||
"headers": {
|
|
||||||
"accept": "application/vnd.github.v3+json",
|
|
||||||
"authorization": "token 0000000000000000000000000000000000000001",
|
|
||||||
"user-agent": "octokit/endpoint.js v1.2.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can pass `requestOptions` to commen request libraries
|
|
||||||
|
|
||||||
```js
|
|
||||||
const { url, ...options } = requestOptions;
|
|
||||||
// using with fetch (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
|
|
||||||
fetch(url, options);
|
|
||||||
// using with request (https://github.com/request/request)
|
|
||||||
request(requestOptions);
|
|
||||||
// using with got (https://github.com/sindresorhus/got)
|
|
||||||
got[options.method](url, options);
|
|
||||||
// using with axios
|
|
||||||
axios(requestOptions);
|
|
||||||
```
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### `endpoint(route, options)` or `endpoint(options)`
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead align=left>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
name
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
type
|
|
||||||
</th>
|
|
||||||
<th width=100%>
|
|
||||||
description
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody align=left valign=top>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<code>route</code>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
String
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
If set, it has to be a string consisting of URL and the request method, e.g., <code>GET /orgs/:org</code>. If it’s set to a URL, only the method defaults to <code>GET</code>.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<code>options.method</code>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
String
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<strong>Required unless <code>route</code> is set.</strong> Any supported <a href="https://developer.github.com/v3/#http-verbs">http verb</a>. <em>Defaults to <code>GET</code></em>.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<code>options.url</code>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
String
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<strong>Required unless <code>route</code> is set.</strong> A path or full URL which may contain <code>:variable</code> or <code>{variable}</code> placeholders,
|
|
||||||
e.g., <code>/orgs/:org/repos</code>. The <code>url</code> is parsed using <a href="https://github.com/bramstein/url-template">url-template</a>.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<code>options.baseUrl</code>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
String
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<em>Defaults to <code>https://api.github.com</code></em>.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<code>options.headers</code>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
Object
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
Custom headers. Passed headers are merged with defaults:<br>
|
|
||||||
<em><code>headers['user-agent']</code> defaults to <code>octokit-endpoint.js/1.2.3</code> (where <code>1.2.3</code> is the released version)</em>.<br>
|
|
||||||
<em><code>headers['accept']</code> defaults to <code>application/vnd.github.v3+json</code></em>.<br>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<code>options.mediaType.format</code>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
String
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
Media type param, such as <code>raw</code>, <code>diff</code>, or <code>text+json</code>. See <a href="https://developer.github.com/v3/media/">Media Types</a>. Setting <code>options.mediaType.format</code> will amend the <code>headers.accept</code> value.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<code>options.mediaType.previews</code>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
Array of Strings
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
Name of previews, such as <code>mercy</code>, <code>symmetra</code>, or <code>scarlet-witch</code>. See <a href="https://developer.github.com/v3/previews/">API Previews</a>. If <code>options.mediaType.previews</code> was set as default, the new previews will be merged into the default ones. Setting <code>options.mediaType.previews</code> will amend the <code>headers.accept</code> value. <code>options.mediaType.previews</code> will be merged with an existing array set using <code>.defaults()</code>.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<code>options.data</code>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
Any
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
Set request body directly instead of setting it to JSON based on additional parameters. See <a href="#data-parameter">"The <code>data</code> parameter"</a> below.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<code>options.request</code>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
Object
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
Pass custom meta information for the request. The <code>request</code> object will be returned as is.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
All other options will be passed depending on the `method` and `url` options.
|
|
||||||
|
|
||||||
1. If the option key has a placeholder in the `url`, it will be used as the replacement. For example, if the passed options are `{url: '/orgs/:org/repos', org: 'foo'}` the returned `options.url` is `https://api.github.com/orgs/foo/repos`.
|
|
||||||
2. If the `method` is `GET` or `HEAD`, the option is passed as a query parameter.
|
|
||||||
3. Otherwise, the parameter is passed in the request body as a JSON key.
|
|
||||||
|
|
||||||
**Result**
|
|
||||||
|
|
||||||
`endpoint()` is a synchronous method and returns an object with the following keys:
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead align=left>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
key
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
type
|
|
||||||
</th>
|
|
||||||
<th width=100%>
|
|
||||||
description
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody align=left valign=top>
|
|
||||||
<tr>
|
|
||||||
<th><code>method</code></th>
|
|
||||||
<td>String</td>
|
|
||||||
<td>The http method. Always lowercase.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><code>url</code></th>
|
|
||||||
<td>String</td>
|
|
||||||
<td>The url with placeholders replaced with passed parameters.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><code>headers</code></th>
|
|
||||||
<td>Object</td>
|
|
||||||
<td>All header names are lowercased.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><code>body</code></th>
|
|
||||||
<td>Any</td>
|
|
||||||
<td>The request body if one is present. Only for <code>PATCH</code>, <code>POST</code>, <code>PUT</code>, <code>DELETE</code> requests.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><code>request</code></th>
|
|
||||||
<td>Object</td>
|
|
||||||
<td>Request meta option, it will be returned as it was passed into <code>endpoint()</code></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
### `endpoint.defaults()`
|
|
||||||
|
|
||||||
Override or set default options. Example:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const request = require("request");
|
|
||||||
const myEndpoint = require("@octokit/endpoint").defaults({
|
|
||||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3",
|
|
||||||
headers: {
|
|
||||||
"user-agent": "myApp/1.2.3",
|
|
||||||
authorization: `token 0000000000000000000000000000000000000001`
|
|
||||||
},
|
|
||||||
org: "my-project",
|
|
||||||
per_page: 100
|
|
||||||
});
|
|
||||||
|
|
||||||
request(myEndpoint(`GET /orgs/:org/repos`));
|
|
||||||
```
|
|
||||||
|
|
||||||
You can call `.defaults()` again on the returned method, the defaults will cascade.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const myProjectEndpoint = endpoint.defaults({
|
|
||||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3",
|
|
||||||
headers: {
|
|
||||||
"user-agent": "myApp/1.2.3"
|
|
||||||
},
|
|
||||||
org: "my-project"
|
|
||||||
});
|
|
||||||
const myProjectEndpointWithAuth = myProjectEndpoint.defaults({
|
|
||||||
headers: {
|
|
||||||
authorization: `token 0000000000000000000000000000000000000001`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
`myProjectEndpointWithAuth` now defaults the `baseUrl`, `headers['user-agent']`,
|
|
||||||
`org` and `headers['authorization']` on top of `headers['accept']` that is set
|
|
||||||
by the global default.
|
|
||||||
|
|
||||||
### `endpoint.DEFAULTS`
|
|
||||||
|
|
||||||
The current default options.
|
|
||||||
|
|
||||||
```js
|
|
||||||
endpoint.DEFAULTS.baseUrl; // https://api.github.com
|
|
||||||
const myEndpoint = endpoint.defaults({
|
|
||||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3"
|
|
||||||
});
|
|
||||||
myEndpoint.DEFAULTS.baseUrl; // https://github-enterprise.acme-inc.com/api/v3
|
|
||||||
```
|
|
||||||
|
|
||||||
### `endpoint.merge(route, options)` or `endpoint.merge(options)`
|
|
||||||
|
|
||||||
Get the defaulted endpoint options, but without parsing them into request options:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const myProjectEndpoint = endpoint.defaults({
|
|
||||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3",
|
|
||||||
headers: {
|
|
||||||
"user-agent": "myApp/1.2.3"
|
|
||||||
},
|
|
||||||
org: "my-project"
|
|
||||||
});
|
|
||||||
myProjectEndpoint.merge("GET /orgs/:org/repos", {
|
|
||||||
headers: {
|
|
||||||
authorization: `token 0000000000000000000000000000000000000001`
|
|
||||||
},
|
|
||||||
org: "my-secret-project",
|
|
||||||
type: "private"
|
|
||||||
});
|
|
||||||
|
|
||||||
// {
|
|
||||||
// baseUrl: 'https://github-enterprise.acme-inc.com/api/v3',
|
|
||||||
// method: 'GET',
|
|
||||||
// url: '/orgs/:org/repos',
|
|
||||||
// headers: {
|
|
||||||
// accept: 'application/vnd.github.v3+json',
|
|
||||||
// authorization: `token 0000000000000000000000000000000000000001`,
|
|
||||||
// 'user-agent': 'myApp/1.2.3'
|
|
||||||
// },
|
|
||||||
// org: 'my-secret-project',
|
|
||||||
// type: 'private'
|
|
||||||
// }
|
|
||||||
```
|
|
||||||
|
|
||||||
### `endpoint.parse()`
|
|
||||||
|
|
||||||
Stateless method to turn endpoint options into request options. Calling
|
|
||||||
`endpoint(options)` is the same as calling `endpoint.parse(endpoint.merge(options))`.
|
|
||||||
|
|
||||||
## Special cases
|
|
||||||
|
|
||||||
<a name="data-parameter"></a>
|
|
||||||
|
|
||||||
### The `data` parameter – set request body directly
|
|
||||||
|
|
||||||
Some endpoints such as [Render a Markdown document in raw mode](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode) don’t have parameters that are sent as request body keys, instead, the request body needs to be set directly. In these cases, set the `data` parameter.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const options = endpoint("POST /markdown/raw", {
|
|
||||||
data: "Hello world github/linguist#1 **cool**, and #1!",
|
|
||||||
headers: {
|
|
||||||
accept: "text/html;charset=utf-8",
|
|
||||||
"content-type": "text/plain"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// options is
|
|
||||||
// {
|
|
||||||
// method: 'post',
|
|
||||||
// url: 'https://api.github.com/markdown/raw',
|
|
||||||
// headers: {
|
|
||||||
// accept: 'text/html;charset=utf-8',
|
|
||||||
// 'content-type': 'text/plain',
|
|
||||||
// 'user-agent': userAgent
|
|
||||||
// },
|
|
||||||
// body: 'Hello world github/linguist#1 **cool**, and #1!'
|
|
||||||
// }
|
|
||||||
```
|
|
||||||
|
|
||||||
### Set parameters for both the URL/query and the request body
|
|
||||||
|
|
||||||
There are API endpoints that accept both query parameters as well as a body. In that case, you need to add the query parameters as templates to `options.url`, as defined in the [RFC 6570 URI Template specification](https://tools.ietf.org/html/rfc6570).
|
|
||||||
|
|
||||||
Example
|
|
||||||
|
|
||||||
```js
|
|
||||||
endpoint(
|
|
||||||
"POST https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",
|
|
||||||
{
|
|
||||||
name: "example.zip",
|
|
||||||
label: "short description",
|
|
||||||
headers: {
|
|
||||||
"content-type": "text/plain",
|
|
||||||
"content-length": 14,
|
|
||||||
authorization: `token 0000000000000000000000000000000000000001`
|
|
||||||
},
|
|
||||||
data: "Hello, world!"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
```
|
|
||||||
|
|
||||||
## LICENSE
|
|
||||||
|
|
||||||
[MIT](LICENSE)
|
|
||||||
-197
@@ -1,197 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
Object.defineProperty(exports, '__esModule', { value: true });
|
|
||||||
|
|
||||||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
||||||
|
|
||||||
var deepmerge = _interopDefault(require('deepmerge'));
|
|
||||||
var isPlainObject = _interopDefault(require('is-plain-object'));
|
|
||||||
var urlTemplate = _interopDefault(require('url-template'));
|
|
||||||
var getUserAgent = _interopDefault(require('universal-user-agent'));
|
|
||||||
|
|
||||||
function lowercaseKeys(object) {
|
|
||||||
if (!object) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object.keys(object).reduce((newObj, key) => {
|
|
||||||
newObj[key.toLowerCase()] = object[key];
|
|
||||||
return newObj;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
function merge(defaults, route, options) {
|
|
||||||
if (typeof route === "string") {
|
|
||||||
let [method, url] = route.split(" ");
|
|
||||||
options = Object.assign(url ? {
|
|
||||||
method,
|
|
||||||
url
|
|
||||||
} : {
|
|
||||||
url: method
|
|
||||||
}, options);
|
|
||||||
} else {
|
|
||||||
options = route || {};
|
|
||||||
} // lowercase header names before merging with defaults to avoid duplicates
|
|
||||||
|
|
||||||
|
|
||||||
options.headers = lowercaseKeys(options.headers);
|
|
||||||
const mergedOptions = deepmerge.all([defaults, options].filter(Boolean), {
|
|
||||||
isMergeableObject: isPlainObject
|
|
||||||
}); // mediaType.previews arrays are merged, instead of overwritten
|
|
||||||
|
|
||||||
if (defaults && defaults.mediaType.previews.length) {
|
|
||||||
mergedOptions.mediaType.previews = defaults.mediaType.previews.filter(preview => !mergedOptions.mediaType.previews.includes(preview)).concat(mergedOptions.mediaType.previews);
|
|
||||||
}
|
|
||||||
|
|
||||||
mergedOptions.mediaType.previews = mergedOptions.mediaType.previews.map(preview => preview.replace(/-preview/, ""));
|
|
||||||
return mergedOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addQueryParameters(url, parameters) {
|
|
||||||
const separator = /\?/.test(url) ? "&" : "?";
|
|
||||||
const names = Object.keys(parameters);
|
|
||||||
|
|
||||||
if (names.length === 0) {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
return url + separator + names.map(name => {
|
|
||||||
if (name === "q") {
|
|
||||||
return "q=" + parameters.q.split("+").map(encodeURIComponent).join("+");
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${name}=${encodeURIComponent(parameters[name])}`;
|
|
||||||
}).join("&");
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlVariableRegex = /\{[^}]+\}/g;
|
|
||||||
|
|
||||||
function removeNonChars(variableName) {
|
|
||||||
return variableName.replace(/^\W+|\W+$/g, "").split(/,/);
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractUrlVariableNames(url) {
|
|
||||||
const matches = url.match(urlVariableRegex);
|
|
||||||
|
|
||||||
if (!matches) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return matches.map(removeNonChars).reduce((a, b) => a.concat(b), []);
|
|
||||||
}
|
|
||||||
|
|
||||||
function omit(object, keysToOmit) {
|
|
||||||
return Object.keys(object).filter(option => !keysToOmit.includes(option)).reduce((obj, key) => {
|
|
||||||
obj[key] = object[key];
|
|
||||||
return obj;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
function parse(options) {
|
|
||||||
// https://fetch.spec.whatwg.org/#methods
|
|
||||||
let method = options.method.toUpperCase(); // replace :varname with {varname} to make it RFC 6570 compatible
|
|
||||||
|
|
||||||
let url = options.url.replace(/:([a-z]\w+)/g, "{+$1}");
|
|
||||||
let headers = Object.assign({}, options.headers);
|
|
||||||
let body;
|
|
||||||
let parameters = omit(options, ["method", "baseUrl", "url", "headers", "request", "mediaType"]); // extract variable names from URL to calculate remaining variables later
|
|
||||||
|
|
||||||
const urlVariableNames = extractUrlVariableNames(url);
|
|
||||||
url = urlTemplate.parse(url).expand(parameters);
|
|
||||||
|
|
||||||
if (!/^http/.test(url)) {
|
|
||||||
url = options.baseUrl + url;
|
|
||||||
}
|
|
||||||
|
|
||||||
const omittedParameters = Object.keys(options).filter(option => urlVariableNames.includes(option)).concat("baseUrl");
|
|
||||||
const remainingParameters = omit(parameters, omittedParameters);
|
|
||||||
const isBinaryRequset = /application\/octet-stream/i.test(headers.accept);
|
|
||||||
|
|
||||||
if (!isBinaryRequset) {
|
|
||||||
if (options.mediaType.format) {
|
|
||||||
// e.g. application/vnd.github.v3+json => application/vnd.github.v3.raw
|
|
||||||
headers.accept = headers.accept.split(/,/).map(preview => preview.replace(/application\/vnd(\.\w+)(\.v3)?(\.\w+)?(\+json)?$/, `application/vnd$1$2.${options.mediaType.format}`)).join(",");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.mediaType.previews.length) {
|
|
||||||
const previewsFromAcceptHeader = headers.accept.match(/[\w-]+(?=-preview)/g) || [];
|
|
||||||
headers.accept = previewsFromAcceptHeader.concat(options.mediaType.previews).map(preview => {
|
|
||||||
const format = options.mediaType.format ? `.${options.mediaType.format}` : "+json";
|
|
||||||
return `application/vnd.github.${preview}-preview${format}`;
|
|
||||||
}).join(",");
|
|
||||||
}
|
|
||||||
} // for GET/HEAD requests, set URL query parameters from remaining parameters
|
|
||||||
// for PATCH/POST/PUT/DELETE requests, set request body from remaining parameters
|
|
||||||
|
|
||||||
|
|
||||||
if (["GET", "HEAD"].includes(method)) {
|
|
||||||
url = addQueryParameters(url, remainingParameters);
|
|
||||||
} else {
|
|
||||||
if ("data" in remainingParameters) {
|
|
||||||
body = remainingParameters.data;
|
|
||||||
} else {
|
|
||||||
if (Object.keys(remainingParameters).length) {
|
|
||||||
body = remainingParameters;
|
|
||||||
} else {
|
|
||||||
headers["content-length"] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // default content-type for JSON if body is set
|
|
||||||
|
|
||||||
|
|
||||||
if (!headers["content-type"] && typeof body !== "undefined") {
|
|
||||||
headers["content-type"] = "application/json; charset=utf-8";
|
|
||||||
} // GitHub expects 'content-length: 0' header for PUT/PATCH requests without body.
|
|
||||||
// fetch does not allow to set `content-length` header, but we can set body to an empty string
|
|
||||||
|
|
||||||
|
|
||||||
if (["PATCH", "PUT"].includes(method) && typeof body === "undefined") {
|
|
||||||
body = "";
|
|
||||||
} // Only return body/request keys if present
|
|
||||||
|
|
||||||
|
|
||||||
return Object.assign({
|
|
||||||
method,
|
|
||||||
url,
|
|
||||||
headers
|
|
||||||
}, typeof body !== "undefined" ? {
|
|
||||||
body
|
|
||||||
} : null, options.request ? {
|
|
||||||
request: options.request
|
|
||||||
} : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
function endpointWithDefaults(defaults, route, options) {
|
|
||||||
return parse(merge(defaults, route, options));
|
|
||||||
}
|
|
||||||
|
|
||||||
function withDefaults(oldDefaults, newDefaults) {
|
|
||||||
const DEFAULTS = merge(oldDefaults, newDefaults);
|
|
||||||
const endpoint = endpointWithDefaults.bind(null, DEFAULTS);
|
|
||||||
return Object.assign(endpoint, {
|
|
||||||
DEFAULTS,
|
|
||||||
defaults: withDefaults.bind(null, DEFAULTS),
|
|
||||||
merge: merge.bind(null, DEFAULTS),
|
|
||||||
parse
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const VERSION = "0.0.0-development";
|
|
||||||
|
|
||||||
const userAgent = `octokit-endpoint.js/${VERSION} ${getUserAgent()}`;
|
|
||||||
const DEFAULTS = {
|
|
||||||
method: "GET",
|
|
||||||
baseUrl: "https://api.github.com",
|
|
||||||
headers: {
|
|
||||||
accept: "application/vnd.github.v3+json",
|
|
||||||
"user-agent": userAgent
|
|
||||||
},
|
|
||||||
mediaType: {
|
|
||||||
format: "",
|
|
||||||
previews: []
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const endpoint = withDefaults(null, DEFAULTS);
|
|
||||||
|
|
||||||
exports.endpoint = endpoint;
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
import getUserAgent from "universal-user-agent";
|
|
||||||
import { VERSION } from "./version";
|
|
||||||
const userAgent = `octokit-endpoint.js/${VERSION} ${getUserAgent()}`;
|
|
||||||
export const DEFAULTS = {
|
|
||||||
method: "GET",
|
|
||||||
baseUrl: "https://api.github.com",
|
|
||||||
headers: {
|
|
||||||
accept: "application/vnd.github.v3+json",
|
|
||||||
"user-agent": userAgent
|
|
||||||
},
|
|
||||||
mediaType: {
|
|
||||||
format: "",
|
|
||||||
previews: []
|
|
||||||
}
|
|
||||||
};
|
|
||||||
-5
@@ -1,5 +0,0 @@
|
|||||||
import { merge } from "./merge";
|
|
||||||
import { parse } from "./parse";
|
|
||||||
export function endpointWithDefaults(defaults, route, options) {
|
|
||||||
return parse(merge(defaults, route, options));
|
|
||||||
}
|
|
||||||
Whitespace-only changes.
-3
@@ -1,3 +0,0 @@
|
|||||||
import { withDefaults } from "./with-defaults";
|
|
||||||
import { DEFAULTS } from "./defaults";
|
|
||||||
export const endpoint = withDefaults(null, DEFAULTS);
|
|
||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
import deepmerge from "deepmerge";
|
|
||||||
import isPlainObject from "is-plain-object";
|
|
||||||
import { lowercaseKeys } from "./util/lowercase-keys";
|
|
||||||
export function merge(defaults, route, options) {
|
|
||||||
if (typeof route === "string") {
|
|
||||||
let [method, url] = route.split(" ");
|
|
||||||
options = Object.assign(url ? { method, url } : { url: method }, options);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
options = route || {};
|
|
||||||
}
|
|
||||||
// lowercase header names before merging with defaults to avoid duplicates
|
|
||||||
options.headers = lowercaseKeys(options.headers);
|
|
||||||
const mergedOptions = deepmerge.all([defaults, options].filter(Boolean), {
|
|
||||||
isMergeableObject: isPlainObject
|
|
||||||
});
|
|
||||||
// mediaType.previews arrays are merged, instead of overwritten
|
|
||||||
if (defaults && defaults.mediaType.previews.length) {
|
|
||||||
mergedOptions.mediaType.previews = defaults.mediaType.previews
|
|
||||||
.filter(preview => !mergedOptions.mediaType.previews.includes(preview))
|
|
||||||
.concat(mergedOptions.mediaType.previews);
|
|
||||||
}
|
|
||||||
mergedOptions.mediaType.previews = mergedOptions.mediaType.previews.map((preview) => preview.replace(/-preview/, ""));
|
|
||||||
return mergedOptions;
|
|
||||||
}
|
|
||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
import urlTemplate from "url-template";
|
|
||||||
import { addQueryParameters } from "./util/add-query-parameters";
|
|
||||||
import { extractUrlVariableNames } from "./util/extract-url-variable-names";
|
|
||||||
import { omit } from "./util/omit";
|
|
||||||
export function parse(options) {
|
|
||||||
// https://fetch.spec.whatwg.org/#methods
|
|
||||||
let method = options.method.toUpperCase();
|
|
||||||
// replace :varname with {varname} to make it RFC 6570 compatible
|
|
||||||
let url = options.url.replace(/:([a-z]\w+)/g, "{+$1}");
|
|
||||||
let headers = Object.assign({}, options.headers);
|
|
||||||
let body;
|
|
||||||
let parameters = omit(options, [
|
|
||||||
"method",
|
|
||||||
"baseUrl",
|
|
||||||
"url",
|
|
||||||
"headers",
|
|
||||||
"request",
|
|
||||||
"mediaType"
|
|
||||||
]);
|
|
||||||
// extract variable names from URL to calculate remaining variables later
|
|
||||||
const urlVariableNames = extractUrlVariableNames(url);
|
|
||||||
url = urlTemplate.parse(url).expand(parameters);
|
|
||||||
if (!/^http/.test(url)) {
|
|
||||||
url = options.baseUrl + url;
|
|
||||||
}
|
|
||||||
const omittedParameters = Object.keys(options)
|
|
||||||
.filter(option => urlVariableNames.includes(option))
|
|
||||||
.concat("baseUrl");
|
|
||||||
const remainingParameters = omit(parameters, omittedParameters);
|
|
||||||
const isBinaryRequset = /application\/octet-stream/i.test(headers.accept);
|
|
||||||
if (!isBinaryRequset) {
|
|
||||||
if (options.mediaType.format) {
|
|
||||||
// e.g. application/vnd.github.v3+json => application/vnd.github.v3.raw
|
|
||||||
headers.accept = headers.accept
|
|
||||||
.split(/,/)
|
|
||||||
.map(preview => preview.replace(/application\/vnd(\.\w+)(\.v3)?(\.\w+)?(\+json)?$/, `application/vnd$1$2.${options.mediaType.format}`))
|
|
||||||
.join(",");
|
|
||||||
}
|
|
||||||
if (options.mediaType.previews.length) {
|
|
||||||
const previewsFromAcceptHeader = headers.accept.match(/[\w-]+(?=-preview)/g) || [];
|
|
||||||
headers.accept = previewsFromAcceptHeader
|
|
||||||
.concat(options.mediaType.previews)
|
|
||||||
.map(preview => {
|
|
||||||
const format = options.mediaType.format
|
|
||||||
? `.${options.mediaType.format}`
|
|
||||||
: "+json";
|
|
||||||
return `application/vnd.github.${preview}-preview${format}`;
|
|
||||||
})
|
|
||||||
.join(",");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// for GET/HEAD requests, set URL query parameters from remaining parameters
|
|
||||||
// for PATCH/POST/PUT/DELETE requests, set request body from remaining parameters
|
|
||||||
if (["GET", "HEAD"].includes(method)) {
|
|
||||||
url = addQueryParameters(url, remainingParameters);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ("data" in remainingParameters) {
|
|
||||||
body = remainingParameters.data;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (Object.keys(remainingParameters).length) {
|
|
||||||
body = remainingParameters;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
headers["content-length"] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// default content-type for JSON if body is set
|
|
||||||
if (!headers["content-type"] && typeof body !== "undefined") {
|
|
||||||
headers["content-type"] = "application/json; charset=utf-8";
|
|
||||||
}
|
|
||||||
// GitHub expects 'content-length: 0' header for PUT/PATCH requests without body.
|
|
||||||
// fetch does not allow to set `content-length` header, but we can set body to an empty string
|
|
||||||
if (["PATCH", "PUT"].includes(method) && typeof body === "undefined") {
|
|
||||||
body = "";
|
|
||||||
}
|
|
||||||
// Only return body/request keys if present
|
|
||||||
return Object.assign({ method, url, headers }, typeof body !== "undefined" ? { body } : null, options.request ? { request: options.request } : null);
|
|
||||||
}
|
|
||||||
Whitespace-only changes.
-21
@@ -1,21 +0,0 @@
|
|||||||
export function addQueryParameters(url, parameters) {
|
|
||||||
const separator = /\?/.test(url) ? "&" : "?";
|
|
||||||
const names = Object.keys(parameters);
|
|
||||||
if (names.length === 0) {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
return (url +
|
|
||||||
separator +
|
|
||||||
names
|
|
||||||
.map(name => {
|
|
||||||
if (name === "q") {
|
|
||||||
return ("q=" +
|
|
||||||
parameters
|
|
||||||
.q.split("+")
|
|
||||||
.map(encodeURIComponent)
|
|
||||||
.join("+"));
|
|
||||||
}
|
|
||||||
return `${name}=${encodeURIComponent(parameters[name])}`;
|
|
||||||
})
|
|
||||||
.join("&"));
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
const urlVariableRegex = /\{[^}]+\}/g;
|
|
||||||
function removeNonChars(variableName) {
|
|
||||||
return variableName.replace(/^\W+|\W+$/g, "").split(/,/);
|
|
||||||
}
|
|
||||||
export function extractUrlVariableNames(url) {
|
|
||||||
const matches = url.match(urlVariableRegex);
|
|
||||||
if (!matches) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return matches.map(removeNonChars).reduce((a, b) => a.concat(b), []);
|
|
||||||
}
|
|
||||||
-9
@@ -1,9 +0,0 @@
|
|||||||
export function lowercaseKeys(object) {
|
|
||||||
if (!object) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
return Object.keys(object).reduce((newObj, key) => {
|
|
||||||
newObj[key.toLowerCase()] = object[key];
|
|
||||||
return newObj;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
export function omit(object, keysToOmit) {
|
|
||||||
return Object.keys(object)
|
|
||||||
.filter(option => !keysToOmit.includes(option))
|
|
||||||
.reduce((obj, key) => {
|
|
||||||
obj[key] = object[key];
|
|
||||||
return obj;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
export const VERSION = "0.0.0-development";
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
import { endpointWithDefaults } from "./endpoint-with-defaults";
|
|
||||||
import { merge } from "./merge";
|
|
||||||
import { parse } from "./parse";
|
|
||||||
export function withDefaults(oldDefaults, newDefaults) {
|
|
||||||
const DEFAULTS = merge(oldDefaults, newDefaults);
|
|
||||||
const endpoint = endpointWithDefaults.bind(null, DEFAULTS);
|
|
||||||
return Object.assign(endpoint, {
|
|
||||||
DEFAULTS,
|
|
||||||
defaults: withDefaults.bind(null, DEFAULTS),
|
|
||||||
merge: merge.bind(null, DEFAULTS),
|
|
||||||
parse
|
|
||||||
});
|
|
||||||
}
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
import { Defaults } from "./types";
|
|
||||||
export declare const DEFAULTS: Defaults;
|
|
||||||
Loaded 100 of 422 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user