import fetch from 'node-fetch' ; import queryString from 'query-string' ; import PromiseHandler from '../../ph-manager/promise-handler' ; export class Webhooks { token : string ; promiseHandler : PromiseHandler ; constructor ( token , promiseHandler = new PromiseHandler ( ) ) { this . token = token ; this . promiseHandler = promiseHandler ; } async all ( param ) { const result = await this . promiseHandler . add ( async ( ) => await fetch ( `https://gitee.com/api/v5/repos/${ param . owner }/${ param . repo }/hooks` , { headers : { Authorization : `bearer ${ this . token }` } } ) ) ; return await result . json ( ) ; } async addWebhook ( param ) { const result = await this . promiseHandler . add ( async ( ) => await fetch ( `https://gitee.com/api/v5/repos/${ param . owner }/${ param . repo }/hooks` , { method : 'POST' , headers : { Authorization : `bearer ${ this . token }` , 'Content-Type' : 'application/x-www-form-urlencoded' , } , body : queryString . stringify ( { ... param , push_events : true , tag_push_events : true , issues_events : true , note_events : true , merge_requests_events : true , } ) , } ) ) ; return await result . json ( ) ; } }