Skip to content

Commit 51a6553

Browse files
committed
refactor: reorganize model imports and create new model files
1 parent f299c3e commit 51a6553

File tree

11 files changed

+158
-159
lines changed

11 files changed

+158
-159
lines changed

lib/config.js

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict'
2-
const { Organization } = require('./organization')
3-
const { Project } = require('./project')
4-
const { Label } = require('./label')
5-
const { Person } = require('./person')
62
const builder = require('./template/builder')
73
const indicies = require('../template/indicies')
4+
const { Config } = require('./models/config')
85

96
module.exports = function (opts) {
107
return new Config(opts)
118
}
9+
module.exports.Config = Config
10+
module.exports.defaults = DEFAULTS
1211

1312
const DEFAULTS = {
1413
db: 'data.db',
@@ -21,40 +20,3 @@ const DEFAULTS = {
2120
description: 'Project StatusBoard',
2221
issueLabels: ['top priority', 'good first issue', 'help wanted', 'discussion', 'meeting']
2322
}
24-
module.exports.defaults = DEFAULTS
25-
26-
class Config {
27-
constructor (opts = {}) {
28-
// StatusBoard build/index configuration
29-
this.db = opts.db || DEFAULTS.db
30-
this.outputDirectory = opts.outputDirectory || DEFAULTS.outputDirectory
31-
this.baseUrl = opts.baseUrl || DEFAULTS.baseUrl
32-
this.port = opts.port || DEFAULTS.port
33-
this.indicies = opts.indicies || DEFAULTS.indicies
34-
this.template = opts.template || DEFAULTS.template
35-
36-
// Service auth/options
37-
this.github = opts.github || false
38-
39-
// All the dynamic stuff for a project
40-
this.title = opts.title || DEFAULTS.title
41-
this.description = opts.description || DEFAULTS.description
42-
43-
// Orgs
44-
this.orgs = (opts.orgs || [])
45-
.map((org) => new Organization(org))
46-
47-
// Projects
48-
this.projects = (opts.projects || [])
49-
.map((proj) => new Project(proj))
50-
51-
// Issue/PR Labels
52-
this.issueLabels = (opts.issueLabels || DEFAULTS.issueLabels)
53-
.map((label) => new Label(label))
54-
55-
// People
56-
this.people = (opts.people || [])
57-
.map((person) => new Person(person))
58-
}
59-
}
60-
module.exports.Config = Config

lib/db/build-index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const github = require('../github')
33
const files = require('../files')
44
const npm = require('../npm')
5-
const { Project } = require('../project')
5+
const { Project } = require('../models/project')
66

77
module.exports = async function buildIndex (config, db) {
88
// Loop projects

lib/github.js

Lines changed: 5 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const OctokitRest = Octokit
88
.plugin(retry, throttling)
99

1010
const { graphql } = require('@octokit/graphql')
11+
const { Repo, Issue, Activity, Commit } = require('./models/github')
12+
13+
module.exports = {
14+
Repo, Issue, Activity, Commit
15+
}
1116

1217
const repoQuerySnip = `{
1318
name
@@ -118,27 +123,6 @@ async function getOctokit (opts = {}) {
118123

119124
return [octokit, graphqlWithAuth]
120125
}
121-
122-
const Repo = module.exports.Repo =
123-
class Repo {
124-
constructor (owner, repo = {}) {
125-
this.owner = owner
126-
this.name = repo.name
127-
this.url = repo.url
128-
this.description = repo.description
129-
this.created = repo.createdAt
130-
this.updated = repo.updatedAt
131-
this.pushed = repo.pushedAt
132-
this.stars = repo.stargazers.totalCount
133-
this.watchers = repo.watchers.totalCount
134-
this.forks = repo.forks.totalCount
135-
this.openIssues = repo.issues.totalCount
136-
this.license = repo.licenseInfo && (repo.licenseInfo.spdx_id || repo.licenseInfo.name)
137-
this.language = repo.primaryLanguage ? repo.primaryLanguage.name : repo.primaryLanguage
138-
this.homepage = repo.homepageUrl
139-
}
140-
}
141-
142126
module.exports.getRepo =
143127
async function getRepo (graphQL, owner, repo) {
144128
try {
@@ -158,40 +142,6 @@ module.exports.getRepo =
158142
}
159143
}
160144

161-
const Issue = module.exports.Issue =
162-
class Issue {
163-
constructor (owner, repo, issue = {}) {
164-
this.owner = owner
165-
this.repo = repo
166-
this.number = issue.number
167-
this.isPullRequest = !!(issue.__typename === 'PullRequest')
168-
this.url = issue.url
169-
this.state = issue.state
170-
this.title = issue.title
171-
this.description = issue.bodyText
172-
this.createdAt = issue.createdAt
173-
this.updatedAt = issue.updatedAt
174-
this.closedAt = issue.closedAt
175-
this.mergedAt = issue.mergedAt
176-
this.labels = issue.labels.nodes.map((l) => {
177-
return {
178-
name: l.name,
179-
color: l.color
180-
}
181-
})
182-
let assignee = issue.assignees.nodes[0]
183-
if (!assignee) {
184-
assignee = null
185-
}
186-
this.assignee = assignee
187-
this.author = issue.author && {
188-
login: issue.author.login,
189-
avatarUrl: issue.author.avatarUrl,
190-
url: issue.author.url
191-
}
192-
}
193-
}
194-
195145
async function getRemainingPullRequests (graphQL, owner, repo, cursor) {
196146
try {
197147
const resp = await graphQL({
@@ -302,23 +252,6 @@ module.exports.getRepoIssues =
302252
}
303253
}
304254

305-
const Activity = module.exports.Activity =
306-
class Activity {
307-
constructor (owner, repo, activity = {}) {
308-
this.owner = owner
309-
this.repo = repo
310-
this.id = activity.id
311-
this.type = activity.type
312-
this.createdAt = activity.created_at
313-
this.actor = activity.actor && {
314-
login: activity.actor.login,
315-
avatarUrl: activity.actor.avatar_url,
316-
url: activity.actor.url
317-
}
318-
this.payload = activity.payload
319-
}
320-
}
321-
322255
module.exports.getRepoActivity =
323256
async function * getRepoActivity (octokit, owner, repo) {
324257
const eventsOpts = octokit.activity.listRepoEvents.endpoint.merge({
@@ -444,27 +377,6 @@ module.exports.getOrgRepos =
444377
}
445378
}
446379

447-
const Commit = module.exports.Commit =
448-
class Commit {
449-
constructor (owner, repo, commit = {}) {
450-
this.owner = owner
451-
this.repo = repo
452-
this.nodeId = commit.id
453-
this.sha = commit.oid
454-
this.message = commit.message
455-
this.url = commit.url
456-
this.date = new Date(commit.authoredDate)
457-
458-
let author = commit.author.user || commit.committer
459-
if (!author) {
460-
author = {
461-
login: commit.author.email
462-
}
463-
}
464-
this.author = author
465-
}
466-
}
467-
468380
async function getRemainingCommits (graphQL, owner, repo, cursor) {
469381
try {
470382
const resp = await graphQL({

lib/models/config.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const { Label } = require("./label")
2+
const { Organization } = require("./organization")
3+
const { Person } = require("./person")
4+
const { Project } = require("./project")
5+
6+
module.exports.Config = class Config {
7+
constructor(opts = {}) {
8+
// StatusBoard build/index configuration
9+
this.db = opts.db || DEFAULTS.db
10+
this.outputDirectory = opts.outputDirectory || DEFAULTS.outputDirectory
11+
this.baseUrl = opts.baseUrl || DEFAULTS.baseUrl
12+
this.port = opts.port || DEFAULTS.port
13+
this.indicies = opts.indicies || DEFAULTS.indicies
14+
this.template = opts.template || DEFAULTS.template
15+
16+
// Service auth/options
17+
this.github = opts.github || false
18+
19+
// All the dynamic stuff for a project
20+
this.title = opts.title || DEFAULTS.title
21+
this.description = opts.description || DEFAULTS.description
22+
23+
// Orgs
24+
this.orgs = (opts.orgs || [])
25+
.map((org) => new Organization(org))
26+
27+
// Projects
28+
this.projects = (opts.projects || [])
29+
.map((proj) => new Project(proj))
30+
31+
// Issue/PR Labels
32+
this.issueLabels = (opts.issueLabels || DEFAULTS.issueLabels)
33+
.map((label) => new Label(label))
34+
35+
// People
36+
this.people = (opts.people || [])
37+
.map((person) => new Person(person))
38+
}
39+
}

lib/models/github.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
module.exports.Repo = class Repo {
2+
constructor (owner, repo = {}) {
3+
this.owner = owner
4+
this.name = repo.name
5+
this.url = repo.url
6+
this.description = repo.description
7+
this.created = repo.createdAt
8+
this.updated = repo.updatedAt
9+
this.pushed = repo.pushedAt
10+
this.stars = repo.stargazers.totalCount
11+
this.watchers = repo.watchers.totalCount
12+
this.forks = repo.forks.totalCount
13+
this.openIssues = repo.issues.totalCount
14+
this.license = repo.licenseInfo && (repo.licenseInfo.spdx_id || repo.licenseInfo.name)
15+
this.language = repo.primaryLanguage ? repo.primaryLanguage.name : repo.primaryLanguage
16+
this.homepage = repo.homepageUrl
17+
}
18+
}
19+
20+
module.exports.Issue = class Issue {
21+
constructor (owner, repo, issue = {}) {
22+
this.owner = owner
23+
this.repo = repo
24+
this.number = issue.number
25+
this.isPullRequest = !!(issue.__typename === 'PullRequest')
26+
this.url = issue.url
27+
this.state = issue.state
28+
this.title = issue.title
29+
this.description = issue.bodyText
30+
this.createdAt = issue.createdAt
31+
this.updatedAt = issue.updatedAt
32+
this.closedAt = issue.closedAt
33+
this.mergedAt = issue.mergedAt
34+
this.labels = issue.labels.nodes.map((l) => {
35+
return {
36+
name: l.name,
37+
color: l.color
38+
}
39+
})
40+
let assignee = issue.assignees.nodes[0]
41+
if (!assignee) {
42+
assignee = null
43+
}
44+
this.assignee = assignee
45+
this.author = issue.author && {
46+
login: issue.author.login,
47+
avatarUrl: issue.author.avatarUrl,
48+
url: issue.author.url
49+
}
50+
}
51+
}
52+
53+
module.exports.Activity = class Activity {
54+
constructor (owner, repo, activity = {}) {
55+
this.owner = owner
56+
this.repo = repo
57+
this.id = activity.id
58+
this.type = activity.type
59+
this.createdAt = activity.created_at
60+
this.actor = activity.actor && {
61+
login: activity.actor.login,
62+
avatarUrl: activity.actor.avatar_url,
63+
url: activity.actor.url
64+
}
65+
this.payload = activity.payload
66+
}
67+
}
68+
69+
module.exports.Commit = class Commit {
70+
constructor (owner, repo, commit = {}) {
71+
this.owner = owner
72+
this.repo = repo
73+
this.nodeId = commit.id
74+
this.sha = commit.oid
75+
this.message = commit.message
76+
this.url = commit.url
77+
this.date = new Date(commit.authoredDate)
78+
79+
let author = commit.author.user || commit.committer
80+
if (!author) {
81+
author = {
82+
login: commit.author.email
83+
}
84+
}
85+
this.author = author
86+
}
87+
}

lib/label.js renamed to lib/models/label.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
module.exports.Label = class Label {
4-
constructor (label = {}) {
4+
constructor(label = {}) {
55
this.name = typeof label === 'string' ? label : label.name
66
this.description = label.description
77
this.color = label.color

lib/models/npm.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports.Manifest = class Manifest {
2+
constructor(manifest) {
3+
this.name = manifest.name
4+
this.version = manifest.version
5+
this.dependencies = manifest.dependencies
6+
this.optionalDependencies = manifest.optionalDependencies
7+
this.devDependencies = manifest.devDependencies
8+
this.peerDependencies = manifest.peerDependencies
9+
this.bundleDependencies = manifest.bundleDependencies
10+
this.bin = manifest.bin
11+
}
12+
}
13+
14+
module.exports.Packument = class Packument {
15+
constructor(packument) {
16+
this.name = packument.name
17+
this.distTags = packument.distTags || packument['dist-tags']
18+
this.modified = packument.modified
19+
this.versions = packument.versions
20+
}
21+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)