import { MrkdwnElement , KnownBlock } from '@slack/types/dist' ; import { IncomingWebhookSendArguments } from '@slack/webhook/dist/IncomingWebhook' ; function generateTitle ( repoName ) { return [ { type : 'section' , text : { type : 'mrkdwn' , text : '*Weekly Report of ' + repoName + '*' , } , } , { type : 'section' , text : { type : 'mrkdwn' , text : 'This is a weekly report of ' + repoName + '. It summarizes what have changed in the project during the passed week, including pr merged, new contributors, and more things in the future.' , } , } , { type : 'divider' , } , ] ; } function generateRepoOverview ( basicDataTable , issueAndPRsTable ) { const res = [ { type : 'section' , text : { type : 'mrkdwn' , text : '*1. Repo Overview*' , } , } , { type : 'section' , text : { type : 'mrkdwn' , text : '*Basic data*' , } , } , { type : 'section' , text : { type : 'mrkdwn' , text : 'Baisc data shows how the watch, star, fork and contributors count changed in the passed week.' , } , } , ] ; if ( basicDataTable && basicDataTable . size > 0 ) { const basicData = [ ] ; basicDataTable . forEach ( ( value , key ) => { basicData . push ( { type : 'mrkdwn' , text : key , } ) ; basicData . push ( { type : 'mrkdwn' , text : value , } ) ; } ) ; res . push ( { type : 'section' , fields : basicData , } ) ; } res . push ( { type : 'divider' , } , { type : 'section' , text : { type : 'mrkdwn' , text : '*Issues & PRs*' , } , } , { type : 'section' , text : { type : 'mrkdwn' , text : 'Issues & PRs show the new/closed issues/pull requests count in the passed week.' , } , } ) ; if ( issueAndPRsTable && issueAndPRsTable . size > 0 ) { const issueAndPRs = [ ] ; issueAndPRsTable . forEach ( ( value , key ) => { issueAndPRs . push ( { type : 'mrkdwn' , text : key , } ) ; issueAndPRs . push ( { type : 'mrkdwn' , text : value , } ) ; } ) ; res . push ( { type : 'section' , fields : issueAndPRs , } ) ; } res . push ( { type : 'divider' , } ) ; return res ; } function generatePRsOverview ( prsTable , prsTotal ) { const res = [ { type : 'section' , text : { type : 'mrkdwn' , text : '*2. PR Overview*' , } , } , { type : 'section' , text : { type : 'mrkdwn' , text : 'Thanks to contributions from community, ' + prsTotal + ' pull requests was merged in the repository last week. They are:' , } , } , ] ; if ( prsTable && prsTable . size > 0 ) { const prs = [ ] ; prsTable . forEach ( ( value , key ) => { prs . push ( { type : 'mrkdwn' , text : key , } ) ; prs . push ( { type : 'mrkdwn' , text : value , } ) ; } ) ; res . push ( { type : 'section' , fields : prs , } ) ; } res . push ( { type : 'divider' , } ) ; return res ; } function generateCodeReviewsOverview ( codeReviewsTable , repoName ) { const res = [ { type : 'section' , text : { type : 'mrkdwn' , text : '*3. Code Review Statistics*' , } , } , { type : 'section' , text : { type : 'mrkdwn' , text : repoName + ' encourages everyone to participant in code review, in order to improve software quality. This robot would automatically help to count pull request reviews of single github user as the following every week. So, try to help review code in this project.' , } , } , ] ; if ( codeReviewsTable && codeReviewsTable . size > 0 ) { const codeReviews = [ ] ; codeReviewsTable . forEach ( ( value , key ) => { codeReviews . push ( { type : 'mrkdwn' , text : key , } ) ; codeReviews . push ( { type : 'mrkdwn' , text : value , } ) ; } ) ; res . push ( { type : 'section' , fields : codeReviews , } ) ; } res . push ( { type : 'divider' , } ) ; return res ; } function generateContributorsOverview ( contributors , repoName , contributingLink ) { const res = [ { type : 'section' , text : { type : 'mrkdwn' , text : '*4. Contributors Overview*' , } , } , ] ; if ( contributors && contributors . length > 0 ) { res . push ( { type : 'section' , text : { type : 'mrkdwn' , text : 'It is ' + repoName + ' team\'s great honor to have new contributors from community. We really appreciate your contributions. Feel free to tell us if you have any opinion and please share this open source project with more people if you could. If you hope to be a contributor as well, please start from ' + contributingLink + ' .\n\n' , } , } ) ; let contributorStr = 'Here is the list of new contributors:\n\n' ; contributors . forEach ( v => { contributorStr += '\n' + v ; } ) ; res . push ( { type : 'section' , text : { type : 'mrkdwn' , text : contributorStr , } , } , { type : 'section' , text : { type : 'mrkdwn' , text : '\n\nThanks to you all.' , } , } ) ; } else { res . push ( { type : 'section' , text : { type : 'mrkdwn' , text : `We have no new contributors in this project this week.\n\n ${ repoName } team encourages everything about contribution from community.\n\n For more details, please refer to ${ contributingLink }.` , } , } ) ; } return res ; } export function generateSlackWeeklyReport ( repoName , basicDataTable , issuesAndPRsTable , prsTable , prsTotal , codeReviewsTable , contributors , contributingLink ) { return { blocks : [ ... generateTitle ( repoName ) , ... generateRepoOverview ( basicDataTable , issuesAndPRsTable ) , ... generatePRsOverview ( prsTable , prsTotal ) , ... generateCodeReviewsOverview ( codeReviewsTable , repoName ) , ... generateContributorsOverview ( contributors , repoName , contributingLink ) , ] , } ; }