Skip to content

Instantly share code, notes, and snippets.

@yaf
Created February 13, 2024 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaf/1426907c1a38fd1fa96b249211b68c28 to your computer and use it in GitHub Desktop.
Save yaf/1426907c1a38fd1fa96b249211b68c28 to your computer and use it in GitHub Desktop.
let result = 'content, file\n';
const fs = require('node:fs');
// Fichier `support-url-usage-in-pix.json` généré à partir de la command suivant
// `gh search code "support.pix" --repo 1024pix/pix --json "repository,path,textMatches,url" --jq 'map(.textMatches = (.textMatches | map(.fragment)))'`
const fileContent = fs.readFileSync('support-url-usage-in-pix.json', 'utf-8');
const supportUrlUsage = JSON.parse(fileContent);
supportUrlUsage.forEach(function(usageInFile) {
const path = usageInFile.path;
const matches = usageInFile.textMatches;
matches.forEach(function(matchingUrl) {
filteredContent(matchingUrl).forEach(function(url) {
console.log(url)
result += `"${url}",${path}\n`;
});
});
});
function filteredContent(matchingUrl) {
const splitted = matchingUrl.split('\n');
const r = splitted.filter((part) => part.includes('support.pix')).join(' ');
let s = r.split(' ').filter((part) => part.includes('support.pix')).join(' ');
s = s.split('"').filter((part) => part.includes('support.pix')).join(' ');
s = s.split(',').filter((part) => part.includes('support.pix')).join(' ');
s = s.split('\'').filter((part) => part.includes('support.pix')).join(' ');
return s.split(' ');
}
fs.writeFile('result.csv', result, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment