import { Issue , Comment , PullRequest , Review , Repo , Push } from './DataTypes' ; import { PayloadRepository , WebhookPayloadIssuesIssue , WebhookPayloadIssueCommentComment , WebhookPayloadPullRequestPullRequest , WebhookPayloadPullRequestReviewReview , WebhookPayloadPullRequestReviewCommentComment , WebhookPayloadPush , } from '@octokit/webhooks' ; import { ParseDate } from './Utils' ; export interface DataWrapper { actionWrapper ( action ) : string | undefined ; repoWrapper ( repo ) : Repo | undefined ; issueWrapper ( issue ) : Issue | undefined ; commentWrapper ( comment ) : Comment | undefined ; pullRequestWrapper ( pullRequest ) : PullRequest | undefined ; reviewCommentWrapper ( reviewComment ) : Comment | undefined ; } export class GithubWrapper implements DataWrapper { public actionWrapper ( action ) { return action ; } public repoWrapper ( repo ) { try { return { id : repo . id , owner : repo . owner . login , ownerInfo : { login : repo . owner . login , __typename : repo . owner . type , name : ( ! repo . owner . name ) ? '' : repo . owner . name , bio : '' , description : '' , createdAt : null , company : '' , location : '' , websiteUrl : null , repositories : { totalCount : 0 , } , membersWithRole : { totalCount : 0 , } , } , name : repo . name , license : repo . license , codeOfConduct : null , createdAt : new Date ( repo . created_at ) , updatedAt : new Date ( repo . updated_at ) , pushedAt : ParseDate ( repo . pushed_at ) , isFork : repo . fork , description : repo . description , language : repo . language , starCount : repo . stargazers_count , stars : [ ] , watchCount : repo . watchers_count , forkCount : repo . forks_count , directForkCount : 0 , forks : [ ] , branchCount : 0 , defaultBranchName : repo . default_branch , defaultBranchCommitCount : 0 , releaseCount : 0 , issues : [ ] , pulls : [ ] , contributors : [ ] , } ; } catch ( error ) { return undefined ; } } public issueWrapper ( issue ) { try { return { id : issue . id , author : issue . user . login , number : issue . number , createdAt : new Date ( issue . created_at ) , updatedAt : new Date ( issue . updated_at ) , closedAt : ParseDate ( issue . closed_at ) , title : issue . title , body : issue . body , labels : issue . labels . map ( l => l . name ) , comments : [ ] , } ; } catch ( error ) { return undefined ; } } public commentWrapper ( comment ) { try { return { id : comment . id , login : comment . user . login , body : comment . body , url : comment . url , createdAt : new Date ( comment . created_at ) , } ; } catch ( error ) { return undefined ; } } public pullRequestWrapper ( pullRequest ) { try { return { id : pullRequest . id , author : pullRequest . user . login , number : pullRequest . number , createdAt : new Date ( pullRequest . created_at ) , updatedAt : new Date ( pullRequest . updated_at ) , closedAt : ParseDate ( pullRequest . closed_at ) , mergedAt : ParseDate ( pullRequest . merged_at ) , title : pullRequest . title , body : pullRequest . body , labels : pullRequest . labels . map ( label => label . name ) , comments : [ ] , reviewComments : [ ] , additions : pullRequest . additions , deletions : pullRequest . deletions , } ; } catch ( error ) { return undefined ; } } public reviewWrapper ( review ) { try { return { id : review . id , login : review . user . login , body : ( review . body ) as any , createdAt : new Date ( review . submitted_at ) , } ; } catch ( error ) { return undefined ; } } public reviewCommentWrapper ( reviewComment ) { try { return { id : reviewComment . id , login : reviewComment . user . login , body : reviewComment . body , url : reviewComment . url , createdAt : new Date ( reviewComment . created_at ) , } ; } catch ( error ) { return undefined ; } } public pushWrapper ( push ) { return { ref : push . ref , before : push . before , after : push . after , created : push . created , deleted : push . deleted , forced : push . forced , base_ref : push . base_ref , compare : push . compare , commits : push . commits , head_commit : push . head_commit , repository : this . repoWrapper ( push . repository ) , pusher : push . pusher , } ; } }