Skip to content

Commit

Permalink
add rollup grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanKingston committed Apr 17, 2023
1 parent 8378698 commit da9cad0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
42 changes: 35 additions & 7 deletions .github/scripts/diff-directories.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,31 @@ function mungeFileContents (fileContent, filePath) {
}

function displayDiffs (dir1Files, dir2Files, isOpen) {
const out = []
const out = {}
function add(fileName, string, summary = undefined) {
if (summary === undefined) {
summary = string
}
if (!(shortString in out)) {
out[shortString] = { files: [] }
}
out[shortString].files.push(fileName)
out[shortString].string = string
}
for (const [filePath, fileContent] of Object.entries(dir1Files)) {
let diffOut = ''
let compareOut = undefined
if (filePath in dir2Files) {
const fileOut = mungeFileContents(fileContent, filePath)
const file2Out = mungeFileContents(dir2Files[filePath], filePath)
if (fileOut === file2Out) {
diffOut = `⚠️ File ${filePath} is identical`
diffOut = `⚠️ File is identical`
compareOut = 'identical'
} else {
// Slice of file header from diff output
const fileDiff = diff.createPatch(filePath, fileOut, file2Out).split('\n').slice(2).join('\n')
// Ignore out lines
compareOut = fileDiff.split('\n').slice(3).filter(line => line.startsWith('-') || line.startsWith('+')).join('\n')
if (fileDiff) {
fileDiffOut =
diffOut = `
Expand All @@ -71,15 +85,29 @@ ${fileDiff}

delete dir2Files[filePath]
} else {
diffOut = `❌ File ${filePath} only exists in old changeset`
diffOut = '❌ File only exists in old changeset'
compareOut = 'old 1'
}
out.push(renderDetails(filePath, diffOut, isOpen))
add(filePath, diffOut, compareOut)
}

for (const filePath of Object.keys(dir2Files)) {
out.push(`❌ File ${filePath} only exists in new changeset`)
add(filePath, '❌ File only exists in new changeset', 'new 2')
}
return out
const outString = Object.keys(out).map(key => {
const rollup = out[key]
let outString = ''
// If there's more than one file in the rollup, list them
if (rollup.files.length > 1) {
outString += '\n'
for (const file of rollup.files) {
outString += `- ${file}\n`
}
}
outString += '\n\n' + rollup.string
return renderDetails(rollup.files.join(', '), outString, isOpen)
}).join('\n')
return outString
}

function renderDetails (section, text, isOpen) {
Expand Down Expand Up @@ -118,6 +146,6 @@ sortFiles(readFilesRecursively(dir2), 'dir2')

for (const [section, files] of Object.entries(sections)) {
const isOpen = section === 'latest'
const fileOut = displayDiffs(files.dir1, files.dir2, isOpen).join('\n')
const fileOut = displayDiffs(files.dir1, files.dir2, isOpen)
console.log(renderDetails(section, fileOut, isOpen))
}
2 changes: 1 addition & 1 deletion overrides/browsers/chrome-override.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
"domain": "dr3fr5q4g2ul9.cloudfront.net"
},
{
"disabled_domain": "cnn.io",
"disabled_domain": "cnin.io",
"reason": "https://github.com/duckduckgo/privacy-configuration/issues/837"
},
{
Expand Down

0 comments on commit da9cad0

Please sign in to comment.