import { PayloadRepository , WebhookEvent } from '@octokit/webhooks' ; export const isMainRepo = ( repo ) => { return repo . name === repo . owner . login ; } ; type HookContext = { log : ( ... args : any [ ] ) => void ; error : ( ... args : any [ ] ) => void ; } ; export const hook = < T > ( fn ) : ( ( event : WebhookEvent < T > ) => Promise < void > ) => { return async ( event ) => { const context = { error : ( ... args ) => console . error ( `hook(${ event . id }):` , ... args ) , log : ( ... args ) => console . log ( `hook(${ event . id }):` , ... args ) , } ; try { await fn ( event , context ) ; } catch ( err ) { context . error ( 'an error occurred while handling an event:' , event . name , '\n' , err ) ; } } ; } ; export const memoize = < A extends any [ ] , T > ( fn ) : ( ( ... args : A ) => Promise < T > ) & { invalidate : ( ) => void ; } => { let val = null ; const f = async ( ... args ) => { if ( ! val ) { val = await fn ( ... args ) ; } return val ; } ; ( f as any ) . invalidate = ( ) => { val = null ; } ; return f as any ; } ; export const IS_DRY_RUN = ! process . argv . includes ( '--do-it-for-real-this-time' ) ;