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 378a50f

Browse filesBrowse files
authored
Merge pull request actions#508 from iamstarkov/patch-2
make octokit instance available as octokit on top of github, to make it easier to seamlessly copy examples from GitHub rest api or octokit documentations
2 parents 91a83c0 + 6320504 commit 378a50f
Copy full SHA for 378a50f

File tree

Expand file treeCollapse file tree

5 files changed

+22
-18
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+22
-18
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+18-18Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ uses the GitHub API and the workflow run context.
1010
To use this action, provide an input named `script` that contains the body of an asynchronous JavaScript function call.
1111
The following arguments will be provided:
1212

13-
- `github` A pre-authenticated
14-
[octokit/rest.js](https://octokit.github.io/rest.js) client with pagination plugins
13+
- `octokit` (and `github`) A pre-authenticated
14+
[octokit/rest.js](https://octokit.github.io/rest.js) client _instance_ with pagination plugins
1515
- `context` An object containing the [context of the workflow
1616
run](https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts)
1717
- `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package
@@ -102,14 +102,14 @@ By default, requests made with the `github` instance will not be retried. You ca
102102
result-encoding: string
103103
retries: 3
104104
script: |
105-
github.rest.issues.get({
105+
octokit.rest.issues.get({
106106
issue_number: context.issue.number,
107107
owner: context.repo.owner,
108108
repo: context.repo.repo,
109109
})
110110
```
111111

112-
In this example, request failures from `github.rest.issues.get()` will be retried up to 3 times.
112+
In this example, request failures from `octokit.rest.issues.get()` will be retried up to 3 times.
113113

114114
You can also configure which status codes should be exempt from retries via the `retry-exempt-status-codes` option:
115115

@@ -121,7 +121,7 @@ You can also configure which status codes should be exempt from retries via the
121121
retries: 3
122122
retry-exempt-status-codes: 400,401
123123
script: |
124-
github.rest.issues.get({
124+
octokit.rest.issues.get({
125125
issue_number: context.issue.number,
126126
owner: context.repo.owner,
127127
repo: context.repo.repo,
@@ -162,7 +162,7 @@ jobs:
162162
- uses: actions/github-script@v7
163163
with:
164164
script: |
165-
github.rest.issues.createComment({
165+
octokit.rest.issues.createComment({
166166
issue_number: context.issue.number,
167167
owner: context.repo.owner,
168168
repo: context.repo.repo,
@@ -184,7 +184,7 @@ jobs:
184184
- uses: actions/github-script@v7
185185
with:
186186
script: |
187-
github.rest.issues.addLabels({
187+
octokit.rest.issues.addLabels({
188188
issue_number: context.issue.number,
189189
owner: context.repo.owner,
190190
repo: context.repo.repo,
@@ -209,12 +209,12 @@ jobs:
209209
// Get a list of all issues created by the PR opener
210210
// See: https://octokit.github.io/rest.js/#pagination
211211
const creator = context.payload.sender.login
212-
const opts = github.rest.issues.listForRepo.endpoint.merge({
212+
const opts = octokit.rest.issues.listForRepo.endpoint.merge({
213213
...context.issue,
214214
creator,
215215
state: 'all'
216216
})
217-
const issues = await github.paginate(opts)
217+
const issues = await octokit.paginate(opts)
218218
219219
for (const issue of issues) {
220220
if (issue.number === context.issue.number) {
@@ -226,7 +226,7 @@ jobs:
226226
}
227227
}
228228
229-
await github.rest.issues.createComment({
229+
await octokit.rest.issues.createComment({
230230
issue_number: context.issue.number,
231231
owner: context.repo.owner,
232232
repo: context.repo.repo,
@@ -252,7 +252,7 @@ jobs:
252252
with:
253253
script: |
254254
const diff_url = context.payload.pull_request.diff_url
255-
const result = await github.request(diff_url)
255+
const result = await octokit.request(diff_url)
256256
console.log(result)
257257
```
258258
@@ -289,7 +289,7 @@ jobs:
289289
name: context.repo.repo,
290290
label: 'wontfix'
291291
}
292-
const result = await github.graphql(query, variables)
292+
const result = await octokit.graphql(query, variables)
293293
console.log(result)
294294
```
295295

@@ -310,13 +310,13 @@ jobs:
310310
with:
311311
script: |
312312
const script = require('./path/to/script.js')
313-
console.log(script({github, context}))
313+
console.log(script({octokit, context}))
314314
```
315315
316316
And then export a function from your module:
317317
318318
```javascript
319-
module.exports = ({github, context}) => {
319+
module.exports = ({octokit, context}) => {
320320
return context.payload.client_payload.value
321321
}
322322
```
@@ -350,15 +350,15 @@ jobs:
350350
with:
351351
script: |
352352
const script = require('./path/to/script.js')
353-
await script({github, context, core})
353+
await script({octokit, context, core})
354354
```
355355
356356
And then export an async function from your module:
357357
358358
```javascript
359-
module.exports = async ({github, context, core}) => {
359+
module.exports = async ({octokit, context, core}) => {
360360
const {SHA} = process.env
361-
const commit = await github.rest.repos.getCommit({
361+
const commit = await octokit.rest.repos.getCommit({
362362
owner: context.repo.owner,
363363
repo: context.repo.repo,
364364
ref: `${SHA}`
@@ -487,7 +487,7 @@ jobs:
487487
with:
488488
github-token: ${{ secrets.MY_PAT }}
489489
script: |
490-
github.rest.issues.addLabels({
490+
octokit.rest.issues.addLabels({
491491
issue_number: context.issue.number,
492492
owner: context.repo.owner,
493493
repo: context.repo.repo,

‎dist/index.js

Copy file name to clipboardExpand all lines: dist/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36286,6 +36286,7 @@ async function main() {
3628636286
require: wrapRequire,
3628736287
__original_require__: require,
3628836288
github,
36289+
octokit: github,
3628936290
context: lib_github.context,
3629036291
core: core,
3629136292
exec: exec,

‎src/async-function.ts

Copy file name to clipboardExpand all lines: src/async-function.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export declare type AsyncFunctionArguments = {
1111
context: Context
1212
core: typeof core
1313
github: InstanceType<typeof GitHub>
14+
octokit: InstanceType<typeof GitHub>
1415
exec: typeof exec
1516
glob: typeof glob
1617
io: typeof io

‎src/main.ts

Copy file name to clipboardExpand all lines: src/main.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async function main(): Promise<void> {
6262
require: wrapRequire,
6363
__original_require__: __non_webpack_require__,
6464
github,
65+
octokit: github,
6566
context,
6667
core,
6768
exec,

‎types/async-function.d.ts

Copy file name to clipboardExpand all lines: types/async-function.d.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export declare type AsyncFunctionArguments = {
99
context: Context;
1010
core: typeof core;
1111
github: InstanceType<typeof GitHub>;
12+
octokit: InstanceType<typeof GitHub>;
1213
exec: typeof exec;
1314
glob: typeof glob;
1415
io: typeof io;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.