Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8080ea7

Browse filesBrowse files
committed
Initial pass on script Action
0 parents  commit 8080ea7
Copy full SHA for 8080ea7

File tree

Expand file treeCollapse file tree

363 files changed

+77611
-0
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

363 files changed

+77611
-0
lines changed

‎.gitignore

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

‎README.md

Copy file name to clipboard
+77Lines 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

Copy file name to clipboard
+15Lines 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

Copy file name to clipboard
+20Lines 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

Copy file name to clipboardExpand all lines: node_modules/.bin/semver
+1Lines 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

Copy file name to clipboardExpand all lines: node_modules/.bin/which
+1Lines 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

Copy file name to clipboardExpand all lines: node_modules/.yarn-integrity
+63Lines 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

Copy file name to clipboardExpand all lines: node_modules/@actions/core/LICENSE.md
+7Lines 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

Copy file name to clipboardExpand all lines: node_modules/@actions/core/README.md
+81Lines 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

Copy file name to clipboardExpand all lines: node_modules/@actions/core/lib/command.d.ts
+16Lines changed: 16 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.js

Copy file name to clipboardExpand all lines: node_modules/@actions/core/lib/command.js
+66Lines changed: 66 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.js.map

Copy file name to clipboardExpand all lines: node_modules/@actions/core/lib/command.js.map
+1Lines changed: 1 addition & 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.