Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wildan3105 committed Aug 19, 2023
1 parent 263f225 commit ea68909
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@
"no-use-before-define": "error",
"no-whitespace-before-property":"error",
"no-cond-assign": [2, "except-parens"],
"no-unused-vars": [1, {"vars": "local", "args": "none"}],
"no-unused-vars": [
"error",
{ "vars": "local", "args": "none" }
],
"no-loop-func":"error",
"object-shorthand":"error",
"object-curly-spacing": [2, "always"],
Expand Down
14 changes: 5 additions & 9 deletions src/api/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ const client_secret = process.env.CLIENT_SECRET || false;
if (!(client_id && client_secret)) {
throw CLIENT_ID_AND_CLIENT_SECRET_MISSING_ERROR_MESSAGE;
}
const clientParams = `client_id=${client_id}&client_secret=${client_secret}`;

// load service
const GithubService = require('./service');
const githubService = new GithubService();
const githubService = new GithubService(GITHUB_API_URL, client_id, client_secret);

const reqRepos = (username, numberOfPages) => {
const headers = { 'User-Agent': `${username}` };
const url = (page) =>
`${GITHUB_API_URL}/users/${username}/repos?${clientParams}&per_page=${REPOS_PER_PAGE}&page=${page}`;
const reqRepos = async (username, numberOfPages) => {
const requests = [];
for (let i = 1; i <= numberOfPages; i++) {
requests.push(axios.get(url(i), { headers }));
requests.push(await githubService.getReposForUser(username, i));
}
return requests;
};
Expand Down Expand Up @@ -68,7 +64,7 @@ exports.index = async (req, res) => {
}

await githubService.getUser(username)
.then((user) => {
.then(async (user) => {
const userData = user.data;
const numberOfRepos = userData.public_repos;
const fetchedRenderValue = {
Expand All @@ -94,7 +90,7 @@ exports.index = async (req, res) => {

const numberOfPages = (parseInt(numberOfRepos) / REPOS_PER_PAGE) + 1;

axios.all(reqRepos(username, numberOfPages))
axios.all(await reqRepos(username, numberOfPages))
.then((pages) => {
const reposData = _.flatMap(pages, (page) => page.data);

Expand Down
9 changes: 5 additions & 4 deletions src/api/service.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';

const axios = require('axios');
const { GITHUB_API_URL, REPOS_PER_PAGE } = require('../config');
const { REPOS_PER_PAGE } = require('../config');

class GithubService {
constructor() {
this.url = GITHUB_API_URL,
constructor(url, clientId, clientSecret) {
this.url = url,
this.clientParams = `client_id=${clientId}&client_secret=${clientSecret}`;

this.timeout = 10000;
this.clientParams = `client_id=${process.env.CLIENT_ID}&client_secret=${process.env.CLIENT_SECRET}`;
this.reposPerPage = REPOS_PER_PAGE;
}

Expand Down

0 comments on commit ea68909

Please sign in to comment.