mirror of
https://github.com/actions/toolkit.git
synced 2025-06-11 10:18:16 +09:00
Add github package (#32)
* Add github package * Docs * Feedback * Accidentally added extra * Allow octokit to be extended * Respond to feedback * Feedback
This commit is contained in:
parent
4f5cf60872
commit
2a2b51f939
12 changed files with 5617 additions and 0 deletions
3
packages/github/__tests__/__snapshots__/lib.test.ts.snap
Normal file
3
packages/github/__tests__/__snapshots__/lib.test.ts.snap
Normal file
|
@ -0,0 +1,3 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`@actions/context return error for context.repo when repository doesn't exist 1`] = `"context.repo requires a GITHUB_REPOSITORY environment variable like 'owner/repo'"`;
|
80
packages/github/__tests__/lib.test.ts
Normal file
80
packages/github/__tests__/lib.test.ts
Normal file
|
@ -0,0 +1,80 @@
|
|||
import * as path from 'path'
|
||||
import {Context} from '../src/context'
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||
|
||||
describe('@actions/context', () => {
|
||||
let context: Context
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.GITHUB_EVENT_PATH = path.join(__dirname, 'payload.json')
|
||||
process.env.GITHUB_REPOSITORY = 'actions/toolkit'
|
||||
context = new Context()
|
||||
})
|
||||
|
||||
it('returns the payload object', () => {
|
||||
expect(context.payload).toEqual(require('./payload.json'))
|
||||
})
|
||||
|
||||
it('returns an empty payload if the GITHUB_EVENT_PATH environment variable is falsey', () => {
|
||||
delete process.env.GITHUB_EVENT_PATH
|
||||
|
||||
context = new Context()
|
||||
expect(context.payload).toEqual({})
|
||||
})
|
||||
|
||||
it('returns attributes from the GITHUB_REPOSITORY', () => {
|
||||
expect(context.repo).toEqual({owner: 'actions', repo: 'toolkit'})
|
||||
})
|
||||
|
||||
it('returns attributes from the repository payload', () => {
|
||||
delete process.env.GITHUB_REPOSITORY
|
||||
|
||||
context.payload.repository = {
|
||||
name: 'test',
|
||||
owner: {login: 'user'}
|
||||
}
|
||||
expect(context.repo).toEqual({owner: 'user', repo: 'test'})
|
||||
})
|
||||
|
||||
it("return error for context.repo when repository doesn't exist", () => {
|
||||
delete process.env.GITHUB_REPOSITORY
|
||||
|
||||
context.payload.repository = undefined
|
||||
expect(() => context.repo).toThrowErrorMatchingSnapshot()
|
||||
})
|
||||
|
||||
it('returns issue attributes from the repository', () => {
|
||||
expect(context.issue).toEqual({
|
||||
owner: 'actions',
|
||||
repo: 'toolkit',
|
||||
number: 1
|
||||
})
|
||||
})
|
||||
|
||||
it('works with pullRequest payloads', () => {
|
||||
delete process.env.GITHUB_REPOSITORY
|
||||
context.payload = {
|
||||
pullRequest: {number: 2},
|
||||
repository: {owner: {login: 'user'}, name: 'test'}
|
||||
}
|
||||
expect(context.issue).toEqual({
|
||||
number: 2,
|
||||
owner: 'user',
|
||||
repo: 'test'
|
||||
})
|
||||
})
|
||||
|
||||
it('works with payload.number payloads', () => {
|
||||
delete process.env.GITHUB_REPOSITORY
|
||||
context.payload = {
|
||||
number: 2,
|
||||
repository: {owner: {login: 'user'}, name: 'test'}
|
||||
}
|
||||
expect(context.issue).toEqual({
|
||||
number: 2,
|
||||
owner: 'user',
|
||||
repo: 'test'
|
||||
})
|
||||
})
|
||||
})
|
15
packages/github/__tests__/payload.json
Normal file
15
packages/github/__tests__/payload.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"action": "opened",
|
||||
"repository": {
|
||||
"owner": {
|
||||
"login": "user"
|
||||
},
|
||||
"name": "test"
|
||||
},
|
||||
"issue": {
|
||||
"number": 1
|
||||
},
|
||||
"sender": {
|
||||
"type": "User"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue