mirror of
https://github.com/ipfs/awesome-ipfs.git
synced 2024-12-12 17:24:20 -05:00
dd28c19ba7
* fix: broken-links workflow * fix: trim bash var * fix: string comparison * fix: github action if condition syntax * debugging * debugging: gh action showing 1 changed file.. what is it? * fix: only count changed data files for scheduled broken link PRs
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
/**
|
|
* This file assumes that awesome_bot has already been ran.
|
|
*/
|
|
const markdownTable = require('../ab-results-README.md-markdown-table.json')
|
|
const fs = require('fs').promises
|
|
const { join } = require('path')
|
|
|
|
const dir = join(__dirname, '../data')
|
|
|
|
if (markdownTable.error) {
|
|
const brokenLinks = require('../ab-results-README.md-filtered.json').map((resultsData) => resultsData.link);
|
|
(async () => {
|
|
const files = (await fs.readdir(dir)).map(file => join(dir, file))
|
|
|
|
for await (const filePath of files) {
|
|
let fileContents = await fs.readFile(filePath, 'utf8')
|
|
brokenLinks.forEach((brokenLink) => {
|
|
console.log('Searching for "' + brokenLink + '" in ' + filePath)
|
|
const regex = new RegExp(brokenLink, 'g')
|
|
if (fileContents.match(regex)) {
|
|
fileContents = fileContents.replace(regex, '')
|
|
console.log('Removed "' + brokenLink + '" from ' + filePath)
|
|
}
|
|
})
|
|
await fs.writeFile(filePath, fileContents, 'utf8')
|
|
}
|
|
})()
|
|
} else {
|
|
console.log('No errors reported by awesome_bot.')
|
|
}
|