Skip to content

Commit

Permalink
Update GraphQL support in base API
Browse files Browse the repository at this point in the history
  • Loading branch information
hross committed Nov 26, 2019
1 parent 5c89429 commit 986e32e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 87 deletions.
11 changes: 4 additions & 7 deletions packages/exec/__tests__/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ describe('@actions/exec', () => {
})

it('Handles child process holding streams open', async function() {
// this was timing out on some slower hosted macOS runs at default 5s
jest.setTimeout(10000)
const semaphorePath = path.join(
getTestTemp(),
'child-process-semaphore.txt'
Expand Down Expand Up @@ -332,11 +330,9 @@ describe('@actions/exec', () => {
).toBe(1)

fs.unlinkSync(semaphorePath)
})
}, 10000) // this was timing out on some slower hosted macOS runs at default 5s

it('Handles child process holding streams open and non-zero exit code', async function() {
// this was timing out on some slower hosted macOS runs at default 5s
jest.setTimeout(10000)
const semaphorePath = path.join(
getTestTemp(),
'child-process-semaphore.txt'
Expand Down Expand Up @@ -388,7 +384,7 @@ describe('@actions/exec', () => {
).toBe(1)

fs.unlinkSync(semaphorePath)
})
}, 10000) // this was timing out on some slower hosted macOS runs at default 5s

it('Handles child process holding streams open and stderr', async function() {
const semaphorePath = path.join(
Expand Down Expand Up @@ -645,6 +641,7 @@ describe('@actions/exec', () => {
// this test validates the quoting that tool runner adds around the tool path
// when using the windowsVerbatimArguments option. otherwise the target process
// interprets the args as starting after the first space in the tool path.

const exePath = compileArgsExe('print args exe with spaces.exe')
const args: string[] = ['myarg1 myarg2']
const outStream = new StringStream()
Expand All @@ -665,7 +662,7 @@ describe('@actions/exec', () => {
`[command]"${exePath}" myarg1 myarg2`
)
expect(output.trim()).toBe("args[0]: 'myarg1'\r\nargs[1]: 'myarg2'")
})
}, 10000) // slower windows runs timeout, so upping timeout to 10s (from default of 5s)

it('execs .cmd with a space and with verbatim args (Windows)', async () => {
// this test validates the quoting that tool runner adds around the script path.
Expand Down
84 changes: 52 additions & 32 deletions packages/github/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
"scripts": {
"test": "jest",
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"tsc": "tsc"
},
"bugs": {
"url": "https://github.com/actions/toolkit/issues"
},
"dependencies": {
"@octokit/graphql": "^2.0.1",
"@octokit/graphql": "^4.3.1",
"@octokit/rest": "^16.15.0"
},
"devDependencies": {
Expand Down
36 changes: 0 additions & 36 deletions packages/github/src/@types/@octokit/index.d.ts

This file was deleted.

7 changes: 2 additions & 5 deletions packages/github/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ export class Context {
readFileSync(process.env.GITHUB_EVENT_PATH, {encoding: 'utf8'})
)
} else {
process.stdout.write(
`GITHUB_EVENT_PATH ${
process.env.GITHUB_EVENT_PATH
} does not exist${EOL}`
)
const path = process.env.GITHUB_EVENT_PATH
process.stdout.write(`GITHUB_EVENT_PATH ${path} does not exist${EOL}`)
}
}
this.eventName = process.env.GITHUB_EVENT_NAME as string
Expand Down
16 changes: 10 additions & 6 deletions packages/github/src/github.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/master/src/github.ts
import {GraphQlQueryResponse, Variables, defaults} from '@octokit/graphql'
import {graphql} from '@octokit/graphql'

// we need this type to set up a property on the GitHub object
// that has token authorization
// (it is not exported from octokit by default)
import {graphql as GraphQL} from '@octokit/graphql/dist-types/types'

import Octokit from '@octokit/rest'
import * as Context from './context'

Expand All @@ -9,14 +15,12 @@ Octokit.prototype = new Octokit()
export const context = new Context.Context()

export class GitHub extends Octokit {
graphql: (
query: string,
variables?: Variables
) => Promise<GraphQlQueryResponse>
graphql: GraphQL

constructor(token: string, opts: Omit<Octokit.Options, 'auth'> = {}) {
super({...opts, auth: `token ${token}`})
this.graphql = defaults({

this.graphql = graphql.defaults({
headers: {authorization: `token ${token}`}
})
}
Expand Down

0 comments on commit 986e32e

Please sign in to comment.