From 75e122cd02766d489177e880ef38ae4ad21b4754 Mon Sep 17 00:00:00 2001 From: sbimochan Date: Mon, 13 Aug 2018 17:35:18 +0545 Subject: [PATCH 1/6] Code refactor --- js/githubresume.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/js/githubresume.js b/js/githubresume.js index fd4b48f..daf5965 100644 --- a/js/githubresume.js +++ b/js/githubresume.js @@ -1,5 +1,6 @@ var urlParams = {}; var username; +var userAPIUrl; var trackerId = 'UA-21222559-1'; (function () { @@ -18,6 +19,7 @@ $(document).ready(function() { try { if (urlParams[0] !== undefined) { username = urlParams[0]; + userAPIUrl = 'https://api.github.com/users/' + username; run(); } else { home(); @@ -53,13 +55,13 @@ var home = function() { }); }; -var github_user = function(username, callback) { - $.getJSON('https://api.github.com/users/' + username + '?callback=?', callback); +var github_user = function(callback) { + $.getJSON(userAPIUrl + '?callback=?', callback); } var github_user_repos = function(username, callback, page_number, prev_data) { var page = (page_number ? page_number : 1), - url = 'https://api.github.com/users/' + username + '/repos?per_page=100&callback=?', + url = userAPIUrl + '/repos?per_page=100&callback=?', data = (prev_data ? prev_data : []); if (page_number > 1) { @@ -94,8 +96,8 @@ var github_user_issues = function(username, callback, page_number, prev_data) { }); } -var github_user_orgs = function(username, callback) { - $.getJSON('https://api.github.com/users/' + username + '/orgs?callback=?', callback); +var github_user_orgs = function(callback) { + $.getJSON(userAPIUrl + '/orgs?callback=?', callback); } // Check to see if the user has starred the resume.github.com repo. @@ -105,7 +107,7 @@ var github_user_starred_resume = function(username, page) { var star = false; var repos = []; var page = (page ? page : 1); - var url = 'https://api.github.com/users/' + username + '/starred?per_page=100&page=' + page; + var url = userAPIUrl + '/starred?per_page=100&page=' + page; var errorMsg; $.ajax({ @@ -158,7 +160,6 @@ var run = function() { url: 'views/api_limit.html', dataType: 'html', success: function(data) { - var template = data; $('#resume').html(data); } }); @@ -167,7 +168,6 @@ var run = function() { url: 'views/not_found.html', dataType: 'html', success: function(data) { - var template = data; $('#resume').html(data); } }); @@ -176,7 +176,6 @@ var run = function() { url: 'views/opt_out.html', dataType: 'html', success: function(data) { - var template = data; $('#resume').html(data); } }); From b4fc5a9cac3cf17071572343e1f23ad94f1f1386 Mon Sep 17 00:00:00 2001 From: sbimochan Date: Mon, 13 Aug 2018 17:35:39 +0545 Subject: [PATCH 2/6] Add gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file From 87ce60382c7edf2bcdfa8bd9fbbcd98e5d4fe874 Mon Sep 17 00:00:00 2001 From: sbimochan Date: Mon, 13 Aug 2018 21:11:29 +0545 Subject: [PATCH 3/6] remove unnecessary parameters --- js/githubresume.js | 58 +++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/js/githubresume.js b/js/githubresume.js index daf5965..8003289 100644 --- a/js/githubresume.js +++ b/js/githubresume.js @@ -20,6 +20,7 @@ $(document).ready(function() { if (urlParams[0] !== undefined) { username = urlParams[0]; userAPIUrl = 'https://api.github.com/users/' + username; + console.log(userAPIUrl); run(); } else { home(); @@ -28,7 +29,7 @@ $(document).ready(function() { try { console.log(err); } catch (e) { - /*fail silently*/ + console.log(e); } } }); @@ -38,7 +39,6 @@ var error = function() { url: 'views/error.html', dataType: 'html', success: function(data) { - var template = data; $('#resume').html(data); } }); @@ -49,7 +49,6 @@ var home = function() { url: 'views/index.html', dataType: 'html', success: function(data) { - var template = data; $('#resume').html(data); } }); @@ -69,7 +68,7 @@ var github_user_repos = function(username, callback, page_number, prev_data) { } $.getJSON(url, function(repos) { data = data.concat(repos.data); - if (repos.data.length == 100) { + if (repos.data.length === 100) { github_user_repos(username, callback, page + 1, data); } else { callback(data); @@ -88,7 +87,7 @@ var github_user_issues = function(username, callback, page_number, prev_data) { $.getJSON(url, function(repos) { data = data.concat(repos.data.items); - if (repos.data.total_count == 100) { + if (repos.data.total_count === 100) { github_user_issues(username, callback, page + 1, data); } else { callback(data); @@ -100,9 +99,11 @@ var github_user_orgs = function(callback) { $.getJSON(userAPIUrl + '/orgs?callback=?', callback); } -// Check to see if the user has starred the resume.github.com repo. -// -// Returns true/false. +/** + * Check to see if the user has starred the resume.github.com repo. + * Returns true / false. + */ + var github_user_starred_resume = function(username, page) { var star = false; var repos = []; @@ -112,15 +113,18 @@ var github_user_starred_resume = function(username, page) { $.ajax({ url: url, + headers: { + Authorization: "Basic f3b39df3513c0d7bb3f0c1e7577d55b4dcb36d8b" + }, async: false, dataType: 'json', success: function(data) { repos = data; }, error: function(e) { - if (e.status == 403) { + if (e.status === 403) { errorMsg = 'api_limit' - } else if (e.status == 404) { + } else if (e.status === 404) { errorMsg = 'not_found' } } @@ -131,7 +135,7 @@ var github_user_starred_resume = function(username, page) { } $.each(repos, function(i, repo) { - if (repo.full_name == "resume/resume.github.com") { + if (repo.full_name === 'resume/resume.github.com') { star = true; return false; // stop iterating } @@ -141,7 +145,7 @@ var github_user_starred_resume = function(username, page) { return star; } - if (repos.length == 100) { + if (repos.length === 100) { star = github_user_starred_resume(username, page + 1); } @@ -183,7 +187,7 @@ var run = function() { return; } - var res = github_user(username, function(data) { + var result = github_user(function(data) { data = data.data; var sinceDate = new Date(data.created_at); var sinceMonth = sinceDate.getMonth(); @@ -213,7 +217,7 @@ var run = function() { } var avatar = ''; - if (data.type == 'Organization'){ + if (data.type === 'Organization'){ avatar = data.avatar_url.match(/https:\/\/secure.gravatar.com\/avatar\/[0-9a-z]+/)[0]; avatar += '?s=140&d=https://github.com/images/gravatars/gravatar-140.png'; } @@ -262,7 +266,7 @@ var run = function() { // Extra points // - Early adopter - if (view.earlyAdopter == 1) { + if (view.earlyAdopter === 1) { statusScore += EXTRA_POINT_GAIN; } // - Blog & Email & Location @@ -270,7 +274,7 @@ var run = function() { statusScore += EXTRA_POINT_GAIN; } - if (statusScore == FIRST_STEP) { + if (statusScore === FIRST_STEP) { return 'Inactive GitHub user'; } else if (statusScore > FIRST_STEP && statusScore <= SECOND_STEP) { @@ -294,7 +298,7 @@ var run = function() { view.website = addHttp + data.blog; } - var resume = (data.type == 'User' ? 'views/resume.html' : 'views/resumeOrgs.html'); + var resume = (data.type === 'User' ? 'views/resume.html' : 'views/resumeOrgs.html'); $.ajax({ url: resume, dataType: 'html', @@ -303,7 +307,7 @@ var run = function() { html = Mustache.to_html(template, view); $('#resume').html(html); document.title = name + "'s Résumé"; - $("#actions #print").click(function(){ + $('#actions #print').click(function(){ window.print(); return false; }); @@ -344,7 +348,7 @@ var run = function() { var sorted_languages = []; for (var lang in languages) { - if (typeof(lang) !== "string") { + if (typeof(lang) !== 'string') { continue; } sorted_languages.push({ @@ -382,7 +386,7 @@ var run = function() { percent = parseInt((lang.popularity / languageTotal) * 100); li = $('
  • ' + lang.toString() + ' ('+percent+'%)
  • '); - if (x % 3 == 0 || (languages.length < 3 && i == languages.length - 1)) { + if (x % 3 === 0 || (languages.length < 3 && i === languages.length - 1)) { li.attr('class', 'last'); ul.append(li); $('#content-languages').append(ul); @@ -410,7 +414,7 @@ var run = function() { since = since.getFullYear(); until = new Date(repo.info.pushed_at); until = until.getFullYear(); - if (since == until) { + if (since === until) { date = since; } else { date = since + ' – ' + until; @@ -429,11 +433,11 @@ var run = function() { username: username, watchers: repo.info.watchers, forks: repo.info.forks, - watchersLabel: repo.info.watchers == 0 || repo.info.watchers > 1 ? 'stars' : 'star', - forksLabel: repo.info.forks == 0 || repo.info.forks > 1 ? 'forks' : 'fork', + watchersLabel: repo.info.watchers === 0 || repo.info.watchers > 1 ? 'stars' : 'star', + forksLabel: repo.info.forks === 0 || repo.info.forks > 1 ? 'forks' : 'fork', }; - if (itemCount == sorted.length - 1 || itemCount == maxItems - 1) { + if (itemCount === sorted.length - 1 || itemCount === maxItems - 1) { view.last = 'last'; } @@ -507,7 +511,7 @@ var run = function() { }); }); - github_user_orgs(username, function(response) { + github_user_orgs(function(response) { var sorted = []; $.each(response.data, function(i, org) { @@ -538,7 +542,7 @@ var run = function() { now: now }; - if (itemCount == sorted.length - 1 || itemCount == maxItems) { + if (itemCount === sorted.length - 1 || itemCount === maxItems) { view.last = 'last'; } template = response; @@ -563,7 +567,7 @@ if (trackerId) { (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); } From 027ecd157c20e1ac7f88ef46f0cfc4e7cd0b62bb Mon Sep 17 00:00:00 2001 From: sbimochan Date: Mon, 13 Aug 2018 21:54:09 +0545 Subject: [PATCH 4/6] add profile image and company name --- js/githubresume.js | 32 +++++++++++++++----------------- views/resume.html | 14 +++++++++----- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/js/githubresume.js b/js/githubresume.js index 8003289..8696f61 100644 --- a/js/githubresume.js +++ b/js/githubresume.js @@ -20,7 +20,6 @@ $(document).ready(function() { if (urlParams[0] !== undefined) { username = urlParams[0]; userAPIUrl = 'https://api.github.com/users/' + username; - console.log(userAPIUrl); run(); } else { home(); @@ -112,22 +111,19 @@ var github_user_starred_resume = function(username, page) { var errorMsg; $.ajax({ - url: url, - headers: { - Authorization: "Basic f3b39df3513c0d7bb3f0c1e7577d55b4dcb36d8b" - }, - async: false, - dataType: 'json', - success: function(data) { - repos = data; - }, - error: function(e) { - if (e.status === 403) { - errorMsg = 'api_limit' - } else if (e.status === 404) { - errorMsg = 'not_found' - } + url: url, + async: false, + dataType: "json", + success: function(data) { + repos = data; + }, + error: function(e) { + if (e.status === 403) { + errorMsg = "api_limit"; + } else if (e.status === 404) { + errorMsg = "not_found"; } + } }); if (errorMsg === 'api_limit' || errorMsg === 'not_found') { @@ -220,11 +216,14 @@ var run = function() { if (data.type === 'Organization'){ avatar = data.avatar_url.match(/https:\/\/secure.gravatar.com\/avatar\/[0-9a-z]+/)[0]; avatar += '?s=140&d=https://github.com/images/gravatars/gravatar-140.png'; + }else if(data.type === 'User'){ + avatar = data.avatar_url; } var view = { name: name, type: data.type, + company: data.company, email: data.email, created_at: data.created_at, earlyAdopter: 0, @@ -240,7 +239,6 @@ var run = function() { since: since, resume_url: window.location }; - // We consider a limit of 4 months since the GitHub opening (Feb 2008) to be considered as an early adopter if ((since == '2008' && sinceMonth <= 5) || since <= '2007') { view.earlyAdopter = 1; diff --git a/views/resume.html b/views/resume.html index c018132..8821320 100644 --- a/views/resume.html +++ b/views/resume.html @@ -16,10 +16,8 @@

    {{userStatus}}

    - {{#gravatar_id}} - avatar - {{/gravatar_id}} - {{#email}}

    {{/email}} + avatar + {{email}}

    @@ -108,7 +106,13 @@

    About This Résumé

    From 4a1bcea827f014a1d6008d64597bf53e3f460432 Mon Sep 17 00:00:00 2001 From: sbimochan Date: Mon, 13 Aug 2018 22:40:51 +0545 Subject: [PATCH 5/6] error prevention and code refactor --- js/githubresume.js | 53 +++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/js/githubresume.js b/js/githubresume.js index 8696f61..ed2aa03 100644 --- a/js/githubresume.js +++ b/js/githubresume.js @@ -55,7 +55,7 @@ var home = function() { var github_user = function(callback) { $.getJSON(userAPIUrl + '?callback=?', callback); -} +}; var github_user_repos = function(username, callback, page_number, prev_data) { var page = (page_number ? page_number : 1), @@ -73,7 +73,7 @@ var github_user_repos = function(username, callback, page_number, prev_data) { callback(data); } }); -} +}; var github_user_issues = function(username, callback, page_number, prev_data) { var page = (page_number ? page_number : 1), @@ -82,7 +82,7 @@ var github_user_issues = function(username, callback, page_number, prev_data) { if (page_number > 1) { url += '&page=' + page_number; - } + }; $.getJSON(url, function(repos) { data = data.concat(repos.data.items); @@ -92,12 +92,11 @@ var github_user_issues = function(username, callback, page_number, prev_data) { callback(data); } }); -} +}; var github_user_orgs = function(callback) { $.getJSON(userAPIUrl + '/orgs?callback=?', callback); -} - +}; /** * Check to see if the user has starred the resume.github.com repo. * Returns true / false. @@ -128,7 +127,7 @@ var github_user_starred_resume = function(username, page) { if (errorMsg === 'api_limit' || errorMsg === 'not_found') { return errorMsg; - } + }; $.each(repos, function(i, repo) { if (repo.full_name === 'resume/resume.github.com') { @@ -146,7 +145,7 @@ var github_user_starred_resume = function(username, page) { } return star; -} +}; var run = function() { var itemCount = 0, @@ -181,7 +180,7 @@ var run = function() { }); } return; - } + }; var result = github_user(function(data) { data = data.data; @@ -197,12 +196,12 @@ var run = function() { case currentYear: since = 'this year'; break; - } + }; var addHttp = ''; if (data.blog && data.blog.indexOf('http') < 0) { addHttp = 'http://'; - } + }; // set view.name to the "friendly" name e.g. "John Doe". If not defined // (in which case data.name is empty), fall back to the login @@ -210,7 +209,7 @@ var run = function() { var name = username; if (data.name !== null && data.name !== undefined && data.name.length) { name = data.name; - } + }; var avatar = ''; if (data.type === 'Organization'){ @@ -218,7 +217,7 @@ var run = function() { avatar += '?s=140&d=https://github.com/images/gravatars/gravatar-140.png'; }else if(data.type === 'User'){ avatar = data.avatar_url; - } + }; var view = { name: name, @@ -242,7 +241,7 @@ var run = function() { // We consider a limit of 4 months since the GitHub opening (Feb 2008) to be considered as an early adopter if ((since == '2008' && sinceMonth <= 5) || since <= '2007') { view.earlyAdopter = 1; - } + }; view.userStatus = getUserStatus(); function getUserStatus() { @@ -266,11 +265,11 @@ var run = function() { // - Early adopter if (view.earlyAdopter === 1) { statusScore += EXTRA_POINT_GAIN; - } + }; // - Blog & Email & Location if (view.location && view.location != '' && view.email && view.email != '' && data.blog && data.blog != '') { statusScore += EXTRA_POINT_GAIN; - } + }; if (statusScore === FIRST_STEP) { return 'Inactive GitHub user'; @@ -294,9 +293,15 @@ var run = function() { if (data.blog !== undefined && data.blog !== null && data.blog !== '') { view.website = addHttp + data.blog; + }; + + if (typeof(data.type) !== 'undefined') { + var resume = (data.type === 'User' ? 'views/resume.html' : 'views/resumeOrgs.html'); } + else{ + return false; + }; - var resume = (data.type === 'User' ? 'views/resume.html' : 'views/resumeOrgs.html'); $.ajax({ url: resume, dataType: 'html', @@ -321,15 +326,15 @@ var run = function() { $.each(data, function(i, repo) { if (repo.fork !== false) { return; - } + }; if (repo.language) { if (repo.language in languages) { languages[repo.language]++; } else { languages[repo.language] = 1; - } - } + }; + }; popularity = repo.watchers + repo.forks; sorted.push({position: i, popularity: popularity, info: repo}); @@ -360,14 +365,14 @@ var run = function() { }); languageTotal += languages[lang]; - } + }; if (limit) { sorted_languages = sorted_languages.slice(0, limit); - } + }; return sorted_languages.sort(sortByPopularity); - } + }; $.ajax({ url: 'views/job.html', @@ -470,7 +475,7 @@ var run = function() { $.each(repos, function(repo, obj) { sorted.push({ repo: repo, popularity: obj.popularity}); - }) + }); function sortByPopularity(a, b) { return b.popularity - a.popularity; From bc5861460029f51c8036c95202adc43418ccaca9 Mon Sep 17 00:00:00 2001 From: Bimochan Shrestha Date: Tue, 20 Jul 2021 22:25:31 +0545 Subject: [PATCH 6/6] api-url: Remove .gitignore file --- .gitignore | 1 - .vscode/settings.json | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) delete mode 100644 .gitignore create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 600d2d3..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.vscode \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..97239e0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "eslint.enable": false, + "jshint.enable": false, + "editor.tabSize": 2 +} \ No newline at end of file