Skip to content

Commit 6c3e01d

Browse files
committedSep 8, 2018
Cleanup and simplify
1 parent 79629b0 commit 6c3e01d

14 files changed

+112
-103
lines changed
 

‎.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ insert_final_newline = true
99
trim_trailing_whitespace = true
1010

1111
[*.{json,yml,md}]
12-
indent_style = tab
12+
indent_style = space
1313
indent_size = 2

‎controllers/github.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,55 @@ const rest = require('@octokit/rest');
33
const github = new rest();
44
const Plugins = require('../models/plugins');
55
const util = require('util');
6+
const fetch = require('node-fetch');
7+
const marked = require('marked');
68

79
(async () => {
810
try {
911
github.authenticate({
1012
type: 'oauth',
1113
token: '1b01a00c5b950b472e444079b7e8363fe57429ab' // Put in config | Yeah just testing if it works, wasn't going to push it.
12-
})
14+
});
1315

1416
const result = await github.search.repos({ q: 'topic:nfive-plugin' });
1517

16-
1718
for (let i of result.data.items) {
1819
try {
1920
let releases = await github.repos.getReleases({ owner: i.owner.login, repo: i.name, per_page: '100', page: '1' });
20-
releases = releases.data.filter(r => !r.draft && !r.prerelease && !r);
21+
releases = releases.data.filter(r => !r.draft && !r.prerelease);
2122
releases = await Promise.all(releases.map(async r => {
23+
let readme = await github.repos.getReadme({ owner: i.owner.login, repo: i.name, ref: r.tag_name });
24+
readme = await fetch(readme.data.download_url);
25+
2226
return {
2327
tag: r.tag_name,
2428
created: r.published_at,
25-
notes: r.body,
29+
notes: marked(r.body),
2630
downloads: r.assets[0].download_count,
27-
readme: (await github.repos.getReadme({ owner: i.owner.login, repo: i.name, ref: r.tag_name })).data.download_url
31+
readme: marked(await readme.text())
2832
};
2933
}));
3034

3135
await Plugins.findOneAndUpdate({ gh_id: i.id }, {
3236
gh_id: i.id,
3337
org: i.owner.login,
3438
project: i.name,
35-
full_name: i.full_name,
36-
org_url: i.owner.html_url,
37-
project_url: i.html_url,
3839
avatar_url: i.owner.avatar_url,
3940
homepage_url: i.homepage,
4041
description: i.description,
4142
releases: releases,
42-
counts: { stars: i.stargazers_count, watchers: i.watchers, forks: i.forks_count, issues: i.open_issues_count },
43+
counts: {
44+
stars: i.stargazers_count,
45+
watchers: i.watchers_count,
46+
forks: i.forks_count,
47+
issues: i.open_issues_count
48+
},
4349
license: i.license.key,
44-
creationdate: i.created_at
50+
created: i.created_at
4551
}, {
46-
upsert: true,
47-
setDefaultsOnInsert: true
48-
});
49-
50-
51-
//console.log(await github.repos.getPages({owner: i.owner.login, repo: i.name}))
52+
upsert: true,
53+
setDefaultsOnInsert: true
54+
});
5255
}
5356
catch (err) {
5457
util.log('Error: %s', err);

‎controllers/projects.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const config = require('config');
22
const Plugins = require('../models/plugins');
33
const moment = require('moment');
4-
const fetch = require("node-fetch");
5-
const marked = require('marked');
64

75
module.exports = {
86
async view(ctx) {
@@ -11,28 +9,21 @@ module.exports = {
119
if (plugin == null) return ctx.throw(404, 'Project not found!');
1210

1311
const created = [
14-
moment(plugin.creationdate).fromNow(),
15-
moment(plugin.creationdate).format("YYYY-MM-DD")
16-
]
17-
12+
moment(plugin.created).fromNow(),
13+
moment(plugin.created).format('YYYY-MM-DD')
14+
];
1815

1916
let updated = [
2017
moment(plugin.releases[0].created).fromNow(),
21-
moment(plugin.releases[0].created).format("YYYY-MM-DD")
22-
]
23-
24-
const readme = await fetch(plugin.releases[0].readme)
25-
.then(res => res.text())
26-
//.then(body => body);
27-
28-
18+
moment(plugin.releases[0].created).format('YYYY-MM-DD')
19+
];
2920

3021
return await ctx.render('project', {
3122
pretty: config.prettyHtml,
3223
title: config.name,
3324
created: created,
3425
updated: updated,
35-
readme: readme,
26+
readme: plugin.releases[0].readme,
3627
plugin: plugin
3728
});
3829
}

‎db.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = () => {
1111
mongoose.set('useCreateIndex', true);
1212
mongoose.set('useFindAndModify', false);
1313
//mongoose.set('debug', true);
14+
1415
mongoose.connect(config.db, { useNewUrlParser: true });
1516

1617
return mongoose.connection;

‎docker-compose.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
version: '2'
1+
version: "3"
22

33
services:
44
nfivehub:
55
image: node:latest
66
command: "npm start"
77
working_dir: /app
8-
links:
9-
- db
108
volumes:
11-
- .:/app
9+
- .:/app
1210
ports:
13-
- "3000:80"
11+
- "3000:80"
1412
environment:
15-
- NODE_ENV=docker
13+
- NODE_ENV=docker
1614

1715
db:
1816
image: mongo:latest
1917
command: "--smallfiles"
2018
volumes:
21-
- ./db:/data/db
19+
- ./db:/data/db
2220
expose:
23-
- 27017
21+
- 27017
2422
ports:
25-
- "27017:27017"
23+
- "27017:27017"

‎models/plugins.js

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
const mongoose = require('mongoose');
22

3-
const Releases = new mongoose.Schema({ tag: String, created: String, notes: String, downloads: Number, readme: String });
4-
const Counts = new mongoose.Schema({ stars: Number, watchers: Number, forks: Number, issues: Number, })
3+
const Release = new mongoose.Schema({
4+
tag: String,
5+
created: Date,
6+
notes: String,
7+
downloads: Number,
8+
readme: String
9+
});
10+
511
const Repositories = new mongoose.Schema({
612
gh_id: { type: Number, unique: true },
7-
org: String, //owner.login
8-
project: String, //name
9-
full_name: String, //full_name
10-
org_url: String, //owner.html_url
11-
project_url: String, //html_url
12-
avatar_url: String, //owner.avatar_url
13-
homepage_url: String, //homepage
14-
description: String, //discription
15-
releases: [Releases],
16-
counts: [Counts],
17-
license: String, //license.key
18-
creationdate: Date, //created_at
19-
last_grab: { type: Date, default: Date.now() }
20-
},{ timestamps: false });
13+
org: String,
14+
project: String,
15+
avatar_url: String,
16+
homepage_url: String,
17+
description: String,
18+
releases: [Release],
19+
counts: {
20+
stars: Number,
21+
watchers: Number,
22+
forks: Number,
23+
issues: Number
24+
},
25+
license: String,
26+
created: Date,
27+
scraped: { type: Date, default: Date.now() }
28+
});
2129

2230
Repositories.index({
2331
org: 'text',
2432
project: 'text',
25-
full_name: 'text',
2633
description: 'text'
2734
});
2835

‎package-lock.json

+23-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/clippy.svg

-5
This file was deleted.

‎public/style.css

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ body {
22
font-family: 'Open Sans', sans-serif;
33
}
44

5-
header {
6-
height: 5rem;
7-
}
8-
95
header .container {
106
max-width: 1540px;
117
}

‎router.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const orgs = require('./controllers/orgs');
55
const projects = require('./controllers/projects');
66

77
router
8-
.get('/', async (ctx) => {
8+
.get('/', async ctx => {
99
await ctx.render('index', {
1010
pretty: config.prettyHtml,
1111
title: config.name

‎views/layout.pug

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ html(lang='en')
1515
header.mb-5.border-bottom
1616
.container
1717
.row
18-
.col-sm-2
18+
.col-xlg-2
1919
h1.float-left
2020
a(href="/") #{title}
2121

22-
.col-sm-10
22+
.col-lg-10
2323
form(action="/search").form-inline
2424
label(for="search").sr-only Search
2525
input(name="q" placeholder="Search plugins")#search.form-control.w-100

‎views/org.pug

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ block content
66
hr
77

88
each plugin in plugins
9-
a(href="/" + plugin.full_name) #{plugin.full_name}
9+
a(href="/" + plugin.org + "/" + plugin.project) #{plugin.org}/#{plugin.project}
1010
hr

0 commit comments

Comments
 (0)