8000 Initial pass on script Action · pierluigi/github-script@8080ea7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8080ea7

Browse files
committed
Initial pass on script Action
0 parents  commit 8080ea7

File tree

363 files changed

+77611
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

363 files changed

+77611
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!node_modules

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# script
2+
3+
This action makes it easy to quickly write a script in your workflow that uses the GitHub API and the workflow execution context.
4+
5+
See [octokit/rest.js](https://octokit.github.io/rest.js/) for the API client documentation.
6+
7+
## Examples
8+
9+
### Comment on an issue
10+
11+
```yaml
12+
on:
13+
issue: {type: opened}
14+
15+
jobs:
16+
comment:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/script@1.0.0
20+
with:
21+
github-token: ${{github.token}}
22+
script: |
23+
await github.issues.createComment({...context.issue, body: '👋 Thanks for reporting!'})
24+
```
25+
26+
### Apply a label to an issue
27+
28+
```yaml
29+
on:
30+
issue: {type: opened}
31+
32+
jobs:
33+
apply-label:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/script@1.0.0
37+
with:
38+
github-token: ${{github.token}}
39+
script: |
40+
await github.issues.addLabels({...context.issue, labels: ['Triage']})
41+
```
42+
43+
### Welcome a first-time contributor
44+
45+
```yaml
46+
on: pull_request
47+
48+
jobs:
49+
welcome:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/script@1.0.0
53+
with:
54+
github-token: ${{github.token}}
55+
script: |
56+
// Get a list of all issues created by the PR opener
57+
// See: https://octokit.github.io/rest.js/#pagination
58+
const creator = context.payload.sender.login
59+
const opts = github.issues.listForRepo.endpoint.merge({
60+
...context.issue,
61+
creator,
62+
state: 'all'
63+
})
64+
const issues = await github.paginate(opts)
65+
66+
for (const issue of issues) {
67+
if (issue.number === context.issue.number) {
68+
continue
69+
}
70+
71+
if (issue.pull_request) {
72+
return // Creator is already a contributor.
73+
}
74+
}
75+
76+
await github.issues.createComment({...context.issue, body: 'Welcome, new contributor!'})
77+
```

action.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Script
2+
description: An action for running simple scripts with a GitHub client
3+
inputs:
4+
script:
5+
description: The script to run
6+
required: true
7+
github-token:
8+
description: The GitHub token used to create an authenticated client
9+
required: true
10+
outputs:
11+
result:
12+
description: The return value of the script, stringified with `JSON.stringify`
13+
runs:
14+
using: node12
15+
main: main.js

main.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const core = require('@actions/core')
2+
const {GitHub, context} = require('@actions/github')
3+
4+
process.on('unhandledRejection', handleError)
5+
main().catch(handleError)
6+
7+
async function main() {
8+
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor
9+
const script = core.getInput('script', {required: true})
10+
const token = core.getInput('github-token', {required: true})
11+
const fn = new AsyncFunction('github', 'context', script)
12+
const client = new GitHub(token)
13+
const result = await fn(client, context)
14+
core.setOutput('result', JSON.stringify(result))
15+
}
16+
17+
function handleError(err) {
18+
console.error(err)
19+
core.setFailed(err.message)
20+
}

node_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/which

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.yarn-integrity

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/LICENSE.md

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/README.md

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.d.ts

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0