import Webhooks , { PayloadRepository } from "@octokit/webhooks" ; import Octokit from "@octokit/rest" ; import { Logger } from "./logger" ; interface WebhookPayloadWithRepository { [ key ] : any ; repository ? : PayloadRepository ; issue ? : { [ key ] : any ; number : number ; html_url ? : string ; body ? : string ; } ; pull_request ? : { [ key ] : any ; number : number ; html_url ? : string ; body ? : string ; } ; sender ? : { [ key ] : any ; type : string ; } ; action ? : string ; installation ? : { id : number ; [ key ] : any ; } ; } property property property export class Context < E extends WebhookPayloadWithRepository = any > implements Webhooks . WebhookEvent < E > { public name : string ; public id : string ; public payload : E ; public protocol ? : "http" | "https" ; public host ? : string ; public url ? : string ; public github : Octokit ; public log : Logger ; constructor ( event , github , log ) { this . name = event . name ; this . id = event . id ; this . payload = event . payload ; this . protocol = event . protocol ; this . host = event . host ; this . url = event . url ; this . github = github ; this . log = log ; } public get event ( ) : string { return this . name ; } param object public repo < T > ( object ? ) { const repo = this . payload . repository ; if ( ! repo ) { throw new Error ( "context.repo() is not supported for this webhook event." ) ; } return Object . assign ( { owner : repo . owner . login || repo . owner . name ! , repo : repo . name , } , object ) ; } param object public issue < T > ( object ? ) { const payload = this . payload ; return Object . assign ( { number : ( payload . issue || payload . pull_request || payload ) . number , } , this . repo ( object ) ) ; } type { boolean } get isBot ( ) { return this . payload . sender ! . type === "Bot" ; } }