Skip to content

Commit

Permalink
fix: various things
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Oct 18, 2023
1 parent 3924308 commit d8005cf
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 8 deletions.
14 changes: 14 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ const SHARED_OPTIONS = {
}
}

/**
*
* @param {*} create
* @param {*} argv
* @returns
*/
function createBoard (create, argv) {
if (argv.env) {
dotenv.config(argv.env || '.env')
Expand Down Expand Up @@ -134,6 +140,7 @@ module.exports = (create, builder, argv) => {
})

.command('clean', 'Cleans up database', SHARED_OPTIONS, async (argv) => {
console.log('If you want to CLEAR the database entirely, use `statusboard delete-db` instead.')
// Create the statusboard instance
const board = await createBoard(create, argv)

Expand All @@ -151,6 +158,13 @@ module.exports = (create, builder, argv) => {
}
}
})
.command('delete-db', 'Cleans up database', SHARED_OPTIONS, async (argv) => {
// Create the statusboard instance
const board = await createBoard(create, argv)

// delete everything in the db
await board.db.clear()
})
.help()

// Extend or override with builder
Expand Down
9 changes: 7 additions & 2 deletions lib/db/build-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module.exports = async function buildIndex (config, db) {
case 'ERROR':
console.log(evt)
continue
default:
// README, REPO, PACKAGE_JSON,PACKUMENT, PACKAGE_MANIFEST unsupported types here.
// I THINK they are used in the <root>/template/indicies.js file, and are therefore not saved in the DB?
}

await db.put(key, evt)
Expand Down Expand Up @@ -70,8 +73,10 @@ async function * loadProject (octokit, graphQL, project, config, _repo) {

let pkg
try {
const pathToPackageJson = project.repoDirectory !== '/' ? path.join(project.repoDirectory, 'package.json') : 'package.json'
pkg = JSON.parse(await github.getFile(graphQL, project.repoOwner, project.repoName, project.repoBranch, pathToPackageJson))
if (!project.skipNpm) {
const pathToPackageJson = project.repoDirectory !== '/' ? path.join(project.repoDirectory, 'package.json') : 'package.json'
pkg = JSON.parse(await github.getFile(graphQL, project.repoOwner, project.repoName, project.repoBranch, pathToPackageJson))
}
} catch (e) {
yield projectDetail('ERROR', project, e)
}
Expand Down
1 change: 1 addition & 0 deletions lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Repo {
this.watchers = repo.watchers.totalCount
this.forks = repo.forks.totalCount
this.openIssues = repo.issues.totalCount
this.pullRequests = repo.pullRequests.totalCount
this.license = repo.licenseInfo && (repo.licenseInfo.spdx_id || repo.licenseInfo.name)
this.language = repo.primaryLanguage ? repo.primaryLanguage.name : repo.primaryLanguage
this.homepage = repo.homepageUrl
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
"prepublushOnly": "npm t",
"postpublish": "git push origin && git push origin --tags",
"clean": "./bin/statusboard clean -C ./config -d ./gh-pages/data.db",
"delete-db": "./bin/statusboard delete-db -C ./config -d ./gh-pages/data.db",
"build": "./bin/statusboard build -o ./gh-pages -C ./config -d ./gh-pages/data.db",
"index": "./bin/statusboard index -o ./gh-pages -C ./config -d ./gh-pages/data.db",
"site": "./bin/statusboard site -o ./gh-pages -C ./config -d ./gh-pages/data.db",
"serve": "./bin/statusboard serve -o ./gh-pages -C ./config -d ./gh-pages/data.db"
},
"devDependencies": {
"@types/level": "^6.0.1",
"mocha": "^6.1.4",
"serve": "^11.1.0",
"standard": "^12.0.1"
Expand Down
17 changes: 13 additions & 4 deletions template/indicies.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
'use strict'

module.exports = {
projects: async (data, config, key, { type, project, detail }) => {
projects: (data, config, key, { type, project, detail }) => {
if (!['REPO', 'PACKAGE_JSON', 'PACKUMENT', 'TRAVIS'].includes(type)) {
return data
}

data = data || []
const existing = data.find((p) => p.repo === project.repo && p.repoBranch === project.repoBranch && p.repoDirectory === project.repoDirectory && p.packageName === project.packageName)
const existing = data.find((p) => {
const orgMatches = p.repoOwner === project.repoOwner
const repoNameMatches = p.repoName === project.repoName
const repoMatches = p.repo === project.repo
const packageNameMatches = p.packageName === project.packageName
return orgMatches && repoNameMatches && repoMatches && packageNameMatches
})

const proj = existing || { ...project }
switch (type) {
case 'TRAVIS':
Expand All @@ -22,6 +29,8 @@ module.exports = {
case 'PACKUMENT':
proj.packument = detail
break
default:
// console.log(`projects: Unknown type '${type}'`)
}
// When adding for the first time, unshift it (maintains order),
// otherwise we are just modifying it in place
Expand All @@ -32,7 +41,7 @@ module.exports = {
return data
},

userActivity: async (data, config, key, { type, project, detail }) => {
userActivity: (data, config, key, { type, project, detail }) => {
if (!['ACTIVITY', 'COMMIT'].includes(type)) {
return data
}
Expand Down Expand Up @@ -79,7 +88,7 @@ module.exports = {
return data
},

labeledIssues: async (data, config, key, { type, project, detail }) => {
labeledIssues: (data, config, key, { type, project, detail }) => {
if (type !== 'ISSUE' || detail.state !== 'OPEN') {
return data
}
Expand Down
45 changes: 43 additions & 2 deletions template/js/project-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ class ProjectList extends LitElement {
</a>`}
</td>
<td>
${project.packageJson && (html`
${project.skipNpm ? '' : project.packageJson && (html`
<a href="https://npmjs.org/package/${project.packageName}">
<img src="https://badgen.net/npm/v/${project.packageName}" />
</a>
`)}
</td>
<td>
${project.packageJson && (html`
${project.skipNpm ? '' : project.packageJson && (html`
<a href="https://npmjs.org/package/${project.packageName}">
<img src="https://badgen.net/npm/dm/${project.packageName}" />
</a>
Expand All @@ -112,12 +112,53 @@ class ProjectList extends LitElement {
`
}

/**
*
*/
renderTotals() {
const setOfProjectGithubUrls = new Set()
const totals = this.projects.reduce((acc, project) => {
const projectGithubUrl = this.getProjectRootGithubUrl(project)
const alreadyAddedForRepo = setOfProjectGithubUrls.has(projectGithubUrl)
setOfProjectGithubUrls.add(projectGithubUrl)
if (project.repoDetails != null) {
if (!alreadyAddedForRepo) {
acc.stars += project.repoDetails.stars
acc.watchers += project.repoDetails.watchers
acc.forks += project.repoDetails.forks
acc.openIssues += project.repoDetails.openIssues
acc.pullRequests += (project.repoDetails.pullRequests || 0)
console.log(`${project.repoDetails.url}: project.repoDetails.pullRequests: `, project.repoDetails.pullRequests);
console.log(`${project.repoDetails.url}: project.repoDetails: `, project.repoDetails);
}
} else {
console.log(`no repo details for ${project.repo} at ${project.repoDetails.url}`)
}
return acc
}, {stars: 0, watchers: 0, forks: 0, openIssues: 0, pullRequests: 0})
return html`
<tr>
<td><b>Totals</b></td>
<td>${totals.stars}</td>
<td>${totals.watchers}</td>
<td>${totals.openIssues}</td>
<td>${totals.pullRequests}</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
`
}

render () {
return html`
<link rel="stylesheet" href="${this.config.files.css.projectList}" />
<h2>Projects</h2>
<table class="project-list">
${this.projects.map(this.getRow)}
${this.renderTotals()}
</table>
`
}
Expand Down
36 changes: 36 additions & 0 deletions testDb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
const level = require('level')
const readline = require('readline/promises')

async function main () {
try {
const db = level('./gh-pages/data.db', {
valueEncoding: 'json'
})

for await (let { key, value } of db.createReadStream()) {
// log the key and value
console.log(key, value)

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})

// prompt user to continue or quit
const answer = await rl.question('Continue? (n to quit)');

rl.close()
if (answer.toLowerCase() === 'n') {
break
}
}
} catch (err) {
console.error(err)
}
}

main()
.catch((e) => {
console.error(e)
})

0 comments on commit d8005cf

Please sign in to comment.