-
Notifications
You must be signed in to change notification settings - Fork 1
/
auditing.js
executable file
·37 lines (31 loc) · 1.26 KB
/
auditing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fs = require('mz/fs')
const ghDescription = require('gh-description')
const mkdirp = require('mkdirp-promise')
const path = require('path')
const getDirName = path.dirname
module.exports = async function download (repoName, dest) {
if (!repoName) {
throw new Error('A GitHub repository directory must be provided! Format: probot/probot')
}
dest = dest || `${repoName.split('/')[1]}-audit.md`
await fs.readFile(path.join(__dirname, 'audit-template.md')).then(async res => {
console.log('Replacing repo name and description...')
let description = await ghDescription(repoName).then(async res => {
return res.description
}).catch((err) => {
console.log('Unable to get repository description', err)
})
var newContent = res.toString()
.replace(/\[INSERT REPONAME\]/g, repoName)
.replace(/\[INSERT GITHUB DESCRIPTION\]/g, description)
await mkdirp(getDirName(dest)).then(async () => {
fs.writeFile(dest, newContent, 'utf8')
.catch((err) => console.log('Error writing file:', err))
.then(() => console.log(`Done! Created file ${dest}.`))
}).catch(err => {
console.log('Unable to creat directory for path.', err)
})
}).catch(error => {
console.log('Error getting file:', error)
})
}