From 9aacf6aeaa83b91fbc48f02711b96d2c067fbd3b Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Mon, 22 Jul 2019 16:26:28 -0400 Subject: [PATCH] Propose github package spec (#31) * Create github-package.md * Add getters for issue/repo * Update github-package.md --- docs/github-package.md | 100 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 docs/github-package.md diff --git a/docs/github-package.md b/docs/github-package.md new file mode 100644 index 00000000..7b2f3341 --- /dev/null +++ b/docs/github-package.md @@ -0,0 +1,100 @@ +# Github Package + +In order to support using actions to interact with GitHub, I propose adding a `github` package to the toolkit. + +Its main purpose will be to provide a hydrated GitHub context/Octokit client with some convenience functions. It is largely pulled from the GitHub utilities provided in https://github.com/JasonEtco/actions-toolkit, though it has been condensed. + +### Spec + +##### interfaces.ts + +``` +/* + * Interfaces + */ + +export interface PayloadRepository { + [key: string]: any + full_name?: string + name: string + owner: { + [key: string]: any + login: string + name?: string + } + html_url?: string +} + +export interface WebhookPayloadWithRepository { + [key: string]: any + repository?: PayloadRepository + issue?: { + [key: string]: any + number: number + html_url?: string + body?: string + } + pull_request?: { + [key: string]: any + number: number + html_url?: string + body?: string + } + sender?: { + [key: string]: any + type: string + } + action?: string + installation?: { + id: number + [key: string]: any + } +} +``` + +##### context.ts + +Contains a GitHub context + +``` +export class Context { + /** + * Webhook payload object that triggered the workflow + */ + public payload: WebhookPayloadWithRepository + + /** + * Name of the event that triggered the workflow + */ + public event: string + public sha: string + public ref: string + public workflow: string + public action: string + public actor: string + + /** + * Hydrate the context from the environment + */ + constructor () + + public get issue () + + public get repo () +} + +``` + +##### github.ts + +Contains a hydrated Octokit client + +``` +export class GithubClient extends Octokit { + // For making GraphQL requests + public graphql: (query: string, variables?: Variables) => Promise + + // Calls super and initializes graphql + constructor (token: string) +} +```