import fetch from 'node-fetch' ; import queryString from 'query-string' ; import PromiseHandler from '../../ph-manager/promise-handler' ; export class Repos { token : string ; promiseHandler : PromiseHandler ; constructor ( token , promiseHandler = new PromiseHandler ( ) ) { this . token = token ; this . promiseHandler = promiseHandler ; } async getContents ( param ) { const result = await this . promiseHandler . add ( async ( ) => await fetch ( `https://gitee.com/api/v5/repos/${ param . owner }/${ param . repo }/contents/${ param . path }` , { method : 'GET' , headers : { Authorization : `bearer ${ this . token }` , } , } ) ) ; return result . json ( ) ; } async listUserRepos ( ) { const param = { visibility : 'all' , affiliation : 'admin' , per_page : 100 , } ; const result = await this . promiseHandler . add ( async ( ) => await fetch ( `https://gitee.com/api/v5/user/repos?${ queryString . stringify ( param ) }` , { method : 'GET' , headers : { Authorization : `bearer ${ this . token }` , } , } ) ) ; return result . json ( ) ; } async getRepoData ( param ) { const result = await this . promiseHandler . add ( async ( ) => await fetch ( `https://gitee.com/api/v5/repos/${ param . owner }/${ param . repo }` , { method : 'GET' , headers : { Authorization : `bearer ${ this . token }` , } , } ) ) ; return result . json ( ) ; } async getContributors ( param ) { const result = await this . promiseHandler . add ( async ( ) => await fetch ( `https://gitee.com/api/v5/repos/${ param . owner }/${ param . repo }/contributors` , { method : 'GET' , headers : { Authorization : `bearer ${ this . token }` , } , } ) ) ; return result . json ( ) ; } async getForks ( param ) { const result = await this . promiseHandler . add ( async ( ) => await fetch ( `https://gitee.com/api/v5/repos/${ param . owner }/${ param . repo }/forks` , { method : 'GET' , headers : { Authorization : `bearer ${ this . token }` , } , } ) ) ; return result . json ( ) ; } }