import yargs = require ( 'yargs' ) ; import { octokitFrom } from '../../utils/octokit-util' ; import { FileIterator } from '../../file-iterator' ; import { IssueOpener } from '../../issue-opener' ; import { Validate , ValidationResult } from '../../validate' ; interface Args { 'pem-path' : string ; 'app-id' : number ; installation : number ; owner : string ; repo : string ; } export const scanRepo = { command : 'scan-repo' , describe : 'scans a repository opening issues for corrupt .repo-metadata.json files' , builder ( yargs ) { return yargs . option ( 'pem-path' , { describe : 'provide path to private key for requesting JWT' , type : 'string' , demand : true , } ) . option ( 'app-id' , { describe : 'GitHub AppID' , type : 'number' , demand : true , } ) . option ( 'installation' , { describe : 'installation ID for GitHub app' , type : 'number' , demand : true , } ) . option ( 'owner' , { describe : 'organization to lint .repo-metadata.json for' , type : 'string' , demand : true , } ) . option ( 'repo' , { describe : 'repo to lint .repo-metadata.json for' , type : 'string' , demand : true , } ) ; } , async handler ( argv ) { const octokit = await octokitFrom ( argv ) ; const iterator = new FileIterator ( argv . owner , argv . repo , octokit ) ; const results = [ ] ; const validate = new Validate ( octokit ) ; for await ( const [ path , metadata ] of iterator . repoMetadata ( ) ) { const result = await validate . validate ( path , metadata ) ; if ( result . status === 'error' ) { results . push ( result ) ; } } const opener = new IssueOpener ( argv . owner , argv . repo , octokit ) ; await opener . open ( results ) ; } , } ;