@@ -84,30 +84,33 @@ function filterDuplicates(report, changes) {
8484 return duplicates
8585}
8686
87- function formatDuplicates ( duplicates ) {
87+ function formatDuplicates ( duplicates , commitHash , repoName ) {
88+ const baseUrl = `https://github.com/${ repoName } `
8889 return duplicates . map ( ( dupe ) => {
8990 return {
90- firstFile : dupe . firstFile . name ,
91- firstStart : dupe . firstFile . start ,
92- firstEnd : dupe . firstFile . end ,
93- secondFile : dupe . secondFile . name ,
94- secondStart : dupe . secondFile . start ,
95- secondEnd : dupe . secondFile . end ,
91+ first : formUrl ( dupe . firstFile , commitHash ) ,
92+ second : formUrl ( dupe . secondFile , commitHash ) ,
93+ numberOfLines : dupe . lines ,
9694 }
9795 } )
96+ function formUrl ( file , commitHash ) {
97+ return `${ baseUrl } blob/${ commitHash } /${ file . name } #L${ file . start } -L${ file . end } `
98+ }
9899}
99100
100101async function run ( ) {
101102 const rawDiffPath = process . argv [ 3 ]
102103 const jscpdReportPath = process . argv [ 4 ]
104+ const commitHash = process . argv [ 5 ]
105+ const repoName = process . argv [ 6 ]
103106 const changes = await parseDiff ( rawDiffPath )
104107 const jscpdReport = JSON . parse ( await fs . readFile ( jscpdReportPath , 'utf8' ) )
105108 const filteredDuplicates = filterDuplicates ( jscpdReport , changes )
106109
107110 console . log ( '%s files changes' , changes . size )
108111 console . log ( '%s duplicates found' , filteredDuplicates . length )
109112 if ( filteredDuplicates . length > 0 ) {
110- console . log ( formatDuplicates ( filteredDuplicates ) )
113+ console . log ( formatDuplicates ( filteredDuplicates , commitHash , repoName ) )
111114 process . exit ( 1 )
112115 }
113116}
0 commit comments