-
Notifications
You must be signed in to change notification settings - Fork 66
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
Added git services, db caching and front end API changes #57
base: v2
Are you sure you want to change the base?
Changes from 10 commits
bc19f87
39227b2
d32db3c
44af092
b0cd898
2ad21ac
1e3ae42
6cb90d6
3a49382
e4d76c2
94eec53
16b21d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
.vscode | ||
config/.dev.env | ||
config/.dev.env | ||
filelog-debug.log |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const winston = require('winston'); | ||
|
||
const tsFormat = () => (new Date()).toLocaleTimeString(); | ||
|
||
const logger = new (winston.Logger)({ | ||
transports: [ | ||
// colorize the output to the console | ||
new (winston.transports.Console)({ | ||
timestamp: tsFormat, | ||
colorize: true, | ||
}), | ||
new (winston.transports.File)({ | ||
name: 'debug-file', | ||
filename: 'filelog-debug.log', | ||
level: 'debug', | ||
}), | ||
], | ||
}); | ||
|
||
logger.level = 'info'; | ||
|
||
module.exports.logger = logger; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
let mongoose = require('mongoose'); | ||
const mongoose = require('mongoose'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
|
||
mongoose.Promise = global.Promise; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Schema of stargazers in Github | ||
const mongoose = require('./mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const stargazersSchema = new Schema({ | ||
githubId: Number, | ||
login: String, | ||
name: String, | ||
html_url: String, | ||
location: String, | ||
bio: String, | ||
public_repos: Number, | ||
public_gists: Number, | ||
followers: Number, | ||
}, { | ||
timestamps: { | ||
updatedAt: 'recordUpdated_at', | ||
createdAt: 'recordCreated_at', | ||
} }); | ||
|
||
|
||
const Stargazers = mongoose.model('Stargazers', stargazersSchema); | ||
|
||
module.exports.Stargazers = Stargazers; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const request = require('request'); | ||
const { logger } = require('./../../config/winston'); | ||
|
||
const gitService = { | ||
|
||
getUserDetails(login, token) { | ||
if (token) { | ||
headers = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added header definition now... |
||
'User-Agent': 'request', | ||
Authorization: `token ${token}`, | ||
}; | ||
} else { | ||
headers = { | ||
'User-Agent': 'request', | ||
}; | ||
} | ||
const options = { | ||
url: `https://api.github.com/users/${login}`, | ||
headers, | ||
}; | ||
return new Promise((resolve, reject) => { | ||
logger.info('Calling api.github.com/users/user', { login }); | ||
request(options, (error, response, body) => { | ||
if (!error && response.statusCode === 200) { | ||
const user = JSON.parse(body); | ||
const stargazer = { | ||
githubId: user.id, | ||
login: user.login, | ||
name: user.name, | ||
html_url: user.html_url, | ||
location: user.location, | ||
bio: user.bio, | ||
public_repos: user.public_repos, | ||
public_gists: user.public_gists, | ||
followers: user.followers, | ||
}; | ||
resolve(stargazer); | ||
} else { | ||
logger.warn('Error api.github.com/users/user', { Error: response.body }); | ||
reject(response.body); | ||
} | ||
}); | ||
}); | ||
}, | ||
|
||
getStarredRepository(login, token, page = 1) { | ||
let headers; | ||
if (token) { | ||
headers = { | ||
'User-Agent': 'request', | ||
Authorization: `token ${token}`, | ||
}; | ||
} else { | ||
headers = { | ||
'User-Agent': 'request', | ||
}; | ||
} | ||
const options = { | ||
url: `https://api.github.com/users/${login}/starred?per_page=100&page=${page}`, | ||
headers, | ||
}; | ||
return new Promise((resolve, reject) => { | ||
logger.info('Calling api.github.com/users/login/starred', { login, page }); | ||
request(options, (error, response, body) => { | ||
if (!error && response.statusCode === 200) { | ||
const repos = JSON.parse(body); | ||
// Only select required info from data received. | ||
const filterRepos = repos.map(repo => ({ | ||
githubId: repo.id, | ||
name: repo.name, | ||
html_url: repo.html_url, | ||
description: repo.description, | ||
stargazers_count: repo.stargazers_count, | ||
forks_count: repo.forks_count, | ||
created_at: repo.created_at, | ||
updated_at: repo.updated_at, | ||
language: repo.language, | ||
})); | ||
logger.debug('Data Received:', { login, length: filterRepos.length, currentPage: page }); | ||
resolve(filterRepos); | ||
} else { | ||
logger.warn('Error api.github.com/users/login/starred', { err: response.body }); | ||
reject(response.body); | ||
} | ||
}); | ||
}); | ||
}, | ||
}; | ||
|
||
module.exports.gitService = gitService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure about this change, any specific reason for this update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added that to warn us if
let
is used and we never resigned that variable....{"destructuring": "all"}
because of the following....There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid this, if we mutate our data some weird bugs may arise.