import Command , { flags as flagTypes } from "@oclif/command" ; import { IConfig } from "@oclif/config" ; import { Octokit } from "@octokit/rest" ; import { DateTime } from "luxon" ; export default abstract class Base extends Command { constructor ( argv , config ) { super ( argv , config ) ; } github : Octokit = new Octokit ( ) ; static flags = { baseUrl : flagTypes . string ( { description : "GitHub base url" , default : "https://api.github.com" , } ) , token : flagTypes . string ( { description : "GitHub personal access token" , env : "GITHUB_TOKEN" , required : true , } ) , owner : flagTypes . string ( { dependsOn : [ "repo" ] , description : "GitHub repository owner" , } ) , repo : flagTypes . string ( { dependsOn : [ "owner" ] , description : "GitHub repository name" , } ) , format : flagTypes . enum ( { options : [ "JSONL" , "JSON" , "CSV" ] , default : "JSONL" , description : "export format" , } ) , } ; param { string } flagName param { string } date returns { string } parseDateFlag ( flagName , date ) { let searchDate = "*" ; if ( date ) { const datetime = DateTime . fromFormat ( date , "yyyy-MM-dd" ) ; if ( ! datetime . isValid ) { throw new Error ( `unable to parse flag "${ flagName }"\n${ datetime . invalidExplanation }` ) ; } searchDate = datetime . toISODate ( ) ; } return searchDate ; } async init ( ) { const { flags : { baseUrl , token } , } = this . parse ( this . constructor ) ; this . github = new Octokit ( { baseUrl , auth : token , } ) ; } }