Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reorganize model imports and create new model files #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 3 additions & 53 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/db/build-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 5 additions & 93 deletions lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
55 changes: 55 additions & 0 deletions lib/models/config.js
Original file line number Diff line number Diff line change
@@ -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))
}
}
87 changes: 87 additions & 0 deletions lib/models/github.js
Original file line number Diff line number Diff line change
@@ -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
}
}
File renamed without changes.
21 changes: 21 additions & 0 deletions lib/models/npm.js
Original file line number Diff line number Diff line change
@@ -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
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading