import * as needle from 'needle' ; import * as config from './config' ; const options = { json : true , compressed : true , headers : { Authorization : 'token ' + config . GITHUB_TOKEN , } , } ; export async function postComment ( issueUrl , commentText ) { const url = `${ issueUrl }/comments` ; const payload = { body : commentText , } ; await needle ( 'post' , url , payload , options ) ; } export async function deleteExistingComments ( issueUrl ) { const listCommentsUrl = `${ issueUrl }/comments` ; const payload = null ; const commentsResponse = await needle ( 'get' , listCommentsUrl , payload , options ) ; const comments = commentsResponse . body ; const deleteRequests = [ ] ; for ( const comment of comments ) { if ( ( comment . body . indexOf ( config . ACKNOWLEDGEMENT . CHECKED ) === - 1 ) && ( comment . body . indexOf ( config . ACKNOWLEDGEMENT . UNCHECKED ) === - 1 ) ) { continue ; } const deleteUrl = comment . url ; console . log ( 'deleting comment' , deleteUrl ) ; const deleteRequest = needle ( 'delete' , deleteUrl , payload , options ) ; deleteRequests . push ( deleteRequest ) ; } await Promise . all ( deleteRequests ) ; }