-
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?
Conversation
It didn't work until I called, Language selection is not working. After a point application exits due to undefined |
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.
It didn't work until I called, /api/repos/v1/updateRecord manually. We need to find a method to overcome this.
Language selection is not working.
After a point application exits due to undefined response body
Ya some of the language doesn't work becz dB doesn't have any repo for that language. |
It's not working for Javascript. It was working previously. |
I think its something to do with scroll, if you scroll down it starts doing API calls. Not sure why this is happening.... |
It's working now. I don't know why it was happening. |
Username array isn't stored in DB. Is it? |
No its just a file for now, but DB got all github info regarding those usernames..... |
If the user wants to add new username, it's not possible now. |
Regarding adding username on end user request is not yet possible but I was Thinking if user wants to add username we will let him add that but only for him like temp data. |
server/routes/api/repos.js
Outdated
} | ||
console.log('isAuthenticated: No'); | ||
res.redirect('/user/login'); | ||
return 0; |
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.
Any reason to return 0 here?
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.
This function will never reach return
statement. either it will be redirected if not authenticated or next()
will be called
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.
Gotcha, so I think there's no reason to call a return in here then (dead code)
server/routes/api/repos.js
Outdated
query.stargazersLogin = { $all: [req.query.stargazer] }; | ||
} | ||
// Filter language depending on what selected. | ||
if (req.query.language && req.query.language !== 'Any') { |
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.
Any
&& NoLanguage
can live in their own file, something like constants/index.js
server/routes/api/repos.js
Outdated
} | ||
} | ||
Repository.paginate(query, | ||
{ page: parseInt(req.query.page, 10) || 1, |
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.
Do you mind changing this into:
{
page: ...,
limit: ....
}
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 am sorry I didn't understand what you mean here...
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.
Beautify the code 😆
server/gitUtility/initialSeed.js
Outdated
{ new: true, upsert: true }, | ||
(error, doc) => { | ||
if (error) throw error; | ||
//logger.debug(`Updated: ${stargazer}`); |
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.
Can you remove this commented code please? Unless it's really necessary for the future.
config/winston.js
Outdated
|
||
logger.level = 'info'; | ||
|
||
// logger.debug('Test Log Message', { anything: 'This is metadata' }); |
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.
Commented out code.
public/js/languageSelection.js
Outdated
@@ -42,7 +42,7 @@ const selectLanguage = function selectLanguage(event) { | |||
languageSelected = event.target.value; | |||
content.innerHTML = ''; | |||
reqNo = Math.floor(Math.random() * 3) + 1; | |||
projectsPerPage = (languageSelected == ANY_LANGUAGE) ? 2 : 100; | |||
projectsPerPage = (languageSelected == ANY_LANGUAGE) ? 2 : 10; |
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.
You can mode 10 into const MAX_PROJECTS = 10
or something similar.
public/js/main.js
Outdated
innerContent += (entry.language != null) ? ` ${entry.language}` : ''; | ||
innerContent += ` (from ${userFormatter(username)})`; | ||
// innerContent += ` (from ${userFormatter(username)})`; |
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.
Remove this commented out code here.
public/js/main.js
Outdated
@@ -63,8 +68,12 @@ const getData = function getData() { | |||
usersCurrentCall = 0; | |||
callInProgress = true; | |||
reqNo += 1; | |||
if (reqNo > 10) { |
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.
maybe use something more descriptive as const REQ_NUMBER
???
public/js/main.js
Outdated
USERNAMES.forEach((username) => { | ||
const url = `https://api.github.com/users/${username}/starred?per_page=${projectsPerPage}&access_token=${accessToken}&page=${reqNo}`; | ||
// const url = `https://api.github.com/users/${username}/starred?per_page=${projectsPerPage}&access_token=${accessToken}&page=${reqNo}`; |
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.
This is commented code that I think it's not necessary, can you remove it?
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
💯
server/db/repositories.js
Outdated
if (repository.stargazersLogin.indexOf(stargazer) === -1) { | ||
repository.stargazersLogin.push(stargazer); | ||
} | ||
Object.assign(repository, repo); |
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.
You should better do Object.assign({}, repository, repo)
to avoid any undesired mutation.
server/db/stargazers.js
Outdated
public_repos: Number, | ||
public_gists: Number, | ||
followers: Number, | ||
}, { timestamps: { updatedAt: 'recordUpdated_at', createdAt: 'recordCreated_at' } }); |
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 you can write this object in multiple lines. A one liner is harder to read + the diff in the future might not be clear.
|
||
getUserDetails(login, token) { | ||
if (token) { | ||
headers = { |
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 don't see where headers
is defined? Am I missing something here?
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 header definition now...
server/gitUtility/gitService.js
Outdated
return new Promise((resolve, reject) => { | ||
logger.info('Calling api.github.com/users/user', { login }); | ||
request(options, (error, response, body) => { | ||
if (!error && response.statusCode == 200) { |
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.
Always use ===
instead of ==
, using ==
can led to bugs most of times.
server/gitUtility/gitService.js
Outdated
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) { |
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.
Same comment for ===
.eslintrc.json
Outdated
@@ -16,6 +16,7 @@ | |||
"no-console": "off", | |||
"func-names": "off", | |||
"no-alert": "off", | |||
"prefer-const": "off" | |||
"prefer-const": ["error", {"destructuring": "all"}], |
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....
/*eslint prefer-const: ["error", {"destructuring": "all"}]*/
/*eslint-env es6*/
// 'b' is never reassigned, but all of `a` and `b` should not be const, so those are ignored.
let {a, b} = obj;
a = a + 1;
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.
@alejandronanez @asiyani Status? |
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.
Enforce const { foo } = bar
. Mutate our data is not good.
.eslintrc.json
Outdated
@@ -16,6 +16,7 @@ | |||
"no-console": "off", | |||
"func-names": "off", | |||
"no-alert": "off", | |||
"prefer-const": "off" | |||
"prefer-const": ["error", {"destructuring": "all"}], |
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.
Sorry guys have been busy for last few days. I have made all changes now. |
Hi guys did you had time to review this? |
After merging this pull request Frontend will get data from backend DB.
Created Search API for front-end - (This one is not GraphQL) but some this for now just to use same front end without much modification.
Folders added.
gitUtility
inserver
foldergitService
file will make external git API calls. 2 function we can usegetUserDetails(login, token)
&getStarredRepository(login, token, page = 1)
.initialSeed.js
for initail seeding data or udpating records in future.created static method
updateRepoWithStargazer
in repositorySchema which we can use to update records in DB. this method will link Stargazer to Repos being updated./api/repos/v1/search
to search db with query parameterstargazer
,language
,page
,per_page
. this is to replicate current API we are doing to Github./api/repos/v1/updateRecord
this is to start DB seeding.Note:
We need to seed our DB for
/api/repos/v1/search
to work. To do that i have created simple call we can make from the browser (after login in).Just go to
http://localhost:3000/api/repos/v1/updateRecord
. this will start seeding process and you will get logs on the terminal.I am doing seeding for ALL starred records. some username got about 1K+ starred repos.I got about 11K repos documents in Repository collections. This process might take some time.
After seeding data front end will work as it is working now- just data will come from our db.
Since we are getting data from our server we can do following.
In the front-end, we need to change they way we do API calls when language is selected. Since now we can pass
language
as search parameter No need to filter that on the front-end.Please let me know if any issue or what you guys think about this process of getting data.