import { Probot } from 'probot' ; import { logger } from 'gcf-utils' ; import * as fileIterator from './file-iterator' ; import { Validate , ValidationResult } from './validate' ; import { IssueOpener } from './issue-opener' ; /**
 * Main function, run on schedule and on PRs, checking validity of .repo-metadata.json.
 */ export function handler ( app ) { app . on ( 'schedule.repository' as any , async ( context ) => { const owner = context . payload . organization . login ; const repo = context . payload . repository . name ; const iterator = new fileIterator . FileIterator ( owner , repo , context . octokit ) ; const results = [ ] ; const validate = new Validate ( context . octokit ) ; for await ( const [ path , metadata ] of iterator . repoMetadata ( ) ) { const result = await validate . validate ( path , metadata ) ; if ( result . status === 'error' ) { results . push ( result ) ; } } if ( results . length === 0 ) { logger . info ( `no validation errors found for ${ owner }/${ repo }` ) ; } else { logger . info ( `${ results . length } validation errors found for ${ owner }/${ repo }` ) ; } const opener = new IssueOpener ( owner , repo , context . octokit ) ; await opener . open ( results ) ; } ) ; app . on ( [ 'pull_request.opened' , 'pull_request.synchronize' ] , async ( context ) => { const owner = context . payload . repository . owner . login ; logger . info ( 'pr opened endpoint' , owner ) ; } ) ; }