diff --git a/lib/config.js b/lib/config.js index 7bc97d6..3b094e5 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,60 +1,10 @@ 'use strict' -const { Organization } = require('./organization') -const { Project } = require('./project') -const { Label } = require('./label') -const { Person } = require('./person') -const builder = require('./template/builder') -const indicies = require('../template/indicies') + +const { Config, defaults } = require('./models/config') module.exports = function (opts) { return new Config(opts) } -const DEFAULTS = { - db: 'data.db', - outputDirectory: 'build', - baseUrl: '', - port: 5005, - template: builder, - indicies, - title: 'StatusBoard', - description: 'Project StatusBoard', - issueLabels: ['top priority', 'good first issue', 'help wanted', 'discussion', 'meeting'] -} -module.exports.defaults = DEFAULTS - -class Config { - constructor (opts = {}) { - // StatusBoard build/index configuration - this.db = opts.db || DEFAULTS.db - this.outputDirectory = opts.outputDirectory || DEFAULTS.outputDirectory - this.baseUrl = opts.baseUrl || DEFAULTS.baseUrl - this.port = opts.port || DEFAULTS.port - this.indicies = opts.indicies || DEFAULTS.indicies - this.template = opts.template || DEFAULTS.template - - // Service auth/options - this.github = opts.github || false - - // All the dynamic stuff for a project - this.title = opts.title || DEFAULTS.title - this.description = opts.description || DEFAULTS.description - - // Orgs - this.orgs = (opts.orgs || []) - .map((org) => new Organization(org)) - - // Projects - this.projects = (opts.projects || []) - .map((proj) => new Project(proj)) - - // Issue/PR Labels - this.issueLabels = (opts.issueLabels || DEFAULTS.issueLabels) - .map((label) => new Label(label)) - - // People - this.people = (opts.people || []) - .map((person) => new Person(person)) - } -} module.exports.Config = Config +module.exports.defaults = defaults diff --git a/lib/db/build-index.js b/lib/db/build-index.js index fc5072a..7b13abc 100644 --- a/lib/db/build-index.js +++ b/lib/db/build-index.js @@ -2,7 +2,7 @@ const github = require('../github') const files = require('../files') const npm = require('../npm') -const { Project } = require('../project') +const { Project } = require('../models/project') module.exports = async function buildIndex (config, db) { // Loop projects diff --git a/lib/github.js b/lib/github.js index 73f0ba0..8f77630 100644 --- a/lib/github.js +++ b/lib/github.js @@ -8,6 +8,11 @@ const OctokitRest = Octokit .plugin(retry, throttling) const { graphql } = require('@octokit/graphql') +const { Repo, Issue, Activity, Commit } = require('./models/github') + +module.exports = { + Repo, Issue, Activity, Commit +} const repoQuerySnip = `{ name @@ -118,27 +123,6 @@ async function getOctokit (opts = {}) { return [octokit, graphqlWithAuth] } - -const Repo = module.exports.Repo = -class Repo { - constructor (owner, repo = {}) { - this.owner = owner - this.name = repo.name - this.url = repo.url - this.description = repo.description - this.created = repo.createdAt - this.updated = repo.updatedAt - this.pushed = repo.pushedAt - this.stars = repo.stargazers.totalCount - this.watchers = repo.watchers.totalCount - this.forks = repo.forks.totalCount - this.openIssues = repo.issues.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 - } -} - module.exports.getRepo = async function getRepo (graphQL, owner, repo) { try { @@ -158,40 +142,6 @@ module.exports.getRepo = } } -const Issue = module.exports.Issue = -class Issue { - constructor (owner, repo, issue = {}) { - this.owner = owner - this.repo = repo - this.number = issue.number - this.isPullRequest = !!(issue.__typename === 'PullRequest') - this.url = issue.url - this.state = issue.state - this.title = issue.title - this.description = issue.bodyText - this.createdAt = issue.createdAt - this.updatedAt = issue.updatedAt - this.closedAt = issue.closedAt - this.mergedAt = issue.mergedAt - this.labels = issue.labels.nodes.map((l) => { - return { - name: l.name, - color: l.color - } - }) - let assignee = issue.assignees.nodes[0] - if (!assignee) { - assignee = null - } - this.assignee = assignee - this.author = issue.author && { - login: issue.author.login, - avatarUrl: issue.author.avatarUrl, - url: issue.author.url - } - } -} - async function getRemainingPullRequests (graphQL, owner, repo, cursor) { try { const resp = await graphQL({ @@ -302,23 +252,6 @@ module.exports.getRepoIssues = } } -const Activity = module.exports.Activity = -class Activity { - constructor (owner, repo, activity = {}) { - this.owner = owner - this.repo = repo - this.id = activity.id - this.type = activity.type - this.createdAt = activity.created_at - this.actor = activity.actor && { - login: activity.actor.login, - avatarUrl: activity.actor.avatar_url, - url: activity.actor.url - } - this.payload = activity.payload - } -} - module.exports.getRepoActivity = async function * getRepoActivity (octokit, owner, repo) { const eventsOpts = octokit.activity.listRepoEvents.endpoint.merge({ @@ -444,27 +377,6 @@ module.exports.getOrgRepos = } } -const Commit = module.exports.Commit = -class Commit { - constructor (owner, repo, commit = {}) { - this.owner = owner - this.repo = repo - this.nodeId = commit.id - this.sha = commit.oid - this.message = commit.message - this.url = commit.url - this.date = new Date(commit.authoredDate) - - let author = commit.author.user || commit.committer - if (!author) { - author = { - login: commit.author.email - } - } - this.author = author - } -} - async function getRemainingCommits (graphQL, owner, repo, cursor) { try { const resp = await graphQL({ diff --git a/lib/models/config.js b/lib/models/config.js new file mode 100644 index 0000000..dfa22f8 --- /dev/null +++ b/lib/models/config.js @@ -0,0 +1,55 @@ +const { Label } = require('./label') +const { Organization } = require('./organization') +const { Person } = require('./person') +const { Project } = require('./project') +const builder = require('../template/builder') +const indicies = require('../../template/indicies') + +const DEFAULTS = { + db: 'data.db', + outputDirectory: 'build', + baseUrl: '', + port: 5005, + template: builder, + indicies, + title: 'StatusBoard', + description: 'Project StatusBoard', + issueLabels: ['top priority', 'good first issue', 'help wanted', 'discussion', 'meeting'] +} + +module.exports.defaults = DEFAULTS + +module.exports.Config = class Config { + constructor (opts = {}) { + // StatusBoard build/index configuration + this.db = opts.db || DEFAULTS.db + this.outputDirectory = opts.outputDirectory || DEFAULTS.outputDirectory + this.baseUrl = opts.baseUrl || DEFAULTS.baseUrl + this.port = opts.port || DEFAULTS.port + this.indicies = opts.indicies || DEFAULTS.indicies + this.template = opts.template || DEFAULTS.template + + // Service auth/options + this.github = opts.github || false + + // All the dynamic stuff for a project + this.title = opts.title || DEFAULTS.title + this.description = opts.description || DEFAULTS.description + + // Orgs + this.orgs = (opts.orgs || []) + .map((org) => new Organization(org)) + + // Projects + this.projects = (opts.projects || []) + .map((proj) => new Project(proj)) + + // Issue/PR Labels + this.issueLabels = (opts.issueLabels || DEFAULTS.issueLabels) + .map((label) => new Label(label)) + + // People + this.people = (opts.people || []) + .map((person) => new Person(person)) + } +} diff --git a/lib/models/github.js b/lib/models/github.js new file mode 100644 index 0000000..3b03e72 --- /dev/null +++ b/lib/models/github.js @@ -0,0 +1,87 @@ +module.exports.Repo = class Repo { + constructor (owner, repo = {}) { + this.owner = owner + this.name = repo.name + this.url = repo.url + this.description = repo.description + this.created = repo.createdAt + this.updated = repo.updatedAt + this.pushed = repo.pushedAt + this.stars = repo.stargazers.totalCount + this.watchers = repo.watchers.totalCount + this.forks = repo.forks.totalCount + this.openIssues = repo.issues.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 + } +} + +module.exports.Issue = class Issue { + constructor (owner, repo, issue = {}) { + this.owner = owner + this.repo = repo + this.number = issue.number + this.isPullRequest = !!(issue.__typename === 'PullRequest') + this.url = issue.url + this.state = issue.state + this.title = issue.title + this.description = issue.bodyText + this.createdAt = issue.createdAt + this.updatedAt = issue.updatedAt + this.closedAt = issue.closedAt + this.mergedAt = issue.mergedAt + this.labels = issue.labels.nodes.map((l) => { + return { + name: l.name, + color: l.color + } + }) + let assignee = issue.assignees.nodes[0] + if (!assignee) { + assignee = null + } + this.assignee = assignee + this.author = issue.author && { + login: issue.author.login, + avatarUrl: issue.author.avatarUrl, + url: issue.author.url + } + } +} + +module.exports.Activity = class Activity { + constructor (owner, repo, activity = {}) { + this.owner = owner + this.repo = repo + this.id = activity.id + this.type = activity.type + this.createdAt = activity.created_at + this.actor = activity.actor && { + login: activity.actor.login, + avatarUrl: activity.actor.avatar_url, + url: activity.actor.url + } + this.payload = activity.payload + } +} + +module.exports.Commit = class Commit { + constructor (owner, repo, commit = {}) { + this.owner = owner + this.repo = repo + this.nodeId = commit.id + this.sha = commit.oid + this.message = commit.message + this.url = commit.url + this.date = new Date(commit.authoredDate) + + let author = commit.author.user || commit.committer + if (!author) { + author = { + login: commit.author.email + } + } + this.author = author + } +} diff --git a/lib/label.js b/lib/models/label.js similarity index 100% rename from lib/label.js rename to lib/models/label.js diff --git a/lib/models/npm.js b/lib/models/npm.js new file mode 100644 index 0000000..b9d9722 --- /dev/null +++ b/lib/models/npm.js @@ -0,0 +1,21 @@ +module.exports.Manifest = class Manifest { + constructor (manifest) { + this.name = manifest.name + this.version = manifest.version + this.dependencies = manifest.dependencies + this.optionalDependencies = manifest.optionalDependencies + this.devDependencies = manifest.devDependencies + this.peerDependencies = manifest.peerDependencies + this.bundleDependencies = manifest.bundleDependencies + this.bin = manifest.bin + } +} + +module.exports.Packument = class Packument { + constructor (packument) { + this.name = packument.name + this.distTags = packument.distTags || packument['dist-tags'] + this.modified = packument.modified + this.versions = packument.versions + } +} diff --git a/lib/organization.js b/lib/models/organization.js similarity index 100% rename from lib/organization.js rename to lib/models/organization.js diff --git a/lib/person.js b/lib/models/person.js similarity index 100% rename from lib/person.js rename to lib/models/person.js diff --git a/lib/project.js b/lib/models/project.js similarity index 100% rename from lib/project.js rename to lib/models/project.js diff --git a/lib/npm.js b/lib/npm.js index 624042a..b997953 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -1,34 +1,12 @@ 'use strict' const pacote = require('pacote') - -const Packument = module.exports.Packument = -class Packument { - constructor (packument) { - this.name = packument.name - this.distTags = packument.distTags || packument['dist-tags'] - this.modified = packument.modified - this.versions = packument.versions - } -} +const { Manifest, Packument } = require('./models/npm') module.exports.getPackument = async function getNpmPackument (packageName) { const resp = await pacote.packument(packageName) return new Packument(resp) } -const Manifest = module.exports.Manifest = -class Manifest { - constructor (manifest) { - this.name = manifest.name - this.version = manifest.version - this.dependencies = manifest.dependencies - this.optionalDependencies = manifest.optionalDependencies - this.devDependencies = manifest.devDependencies - this.peerDependencies = manifest.peerDependencies - this.bundleDependencies = manifest.bundleDependencies - this.bin = manifest.bin - } -} module.exports.getManifest = async function getNpmManifest (packageName) { const resp = await pacote.manifest(packageName) return new Manifest(resp)