Showing
5 changed files
with
83 additions
and
55 deletions
.vscode/launch.json
0 → 100644
| 1 | +{ | ||
| 2 | + // Use IntelliSense to learn about possible attributes. | ||
| 3 | + // Hover to view descriptions of existing attributes. | ||
| 4 | + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| 5 | + "version": "0.2.0", | ||
| 6 | + "configurations": [ | ||
| 7 | + { | ||
| 8 | + "type": "pwa-node", | ||
| 9 | + "request": "launch", | ||
| 10 | + "name": "Launch Program", | ||
| 11 | + "skipFiles": [ | ||
| 12 | + "<node_internals>/**" | ||
| 13 | + ], | ||
| 14 | + "program": "${workspaceFolder}\\src\\client\\js\\getUserRepo.js" | ||
| 15 | + } | ||
| 16 | + ] | ||
| 17 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | const userContributionsBox = document.querySelector(".user-status__contributions"); | 1 | const userContributionsBox = document.querySelector(".user-status__contributions"); |
| 2 | const totalContributionIndicator = document.getElementById("jsTotalContributions"); | 2 | const totalContributionIndicator = document.getElementById("jsTotalContributions"); |
| 3 | +const URL = "https://api.github.com/graphql" | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 6 | +// const handleImage = () =>{ | ||
| 7 | +// const total = totalContributionIndicator.innerText; | ||
| 8 | +// console.log(total); | ||
| 9 | +// }; | ||
| 5 | 10 | ||
| 6 | -const handleImage = () =>{ | 11 | +const handleContributons = (total) =>{ |
| 7 | - const total = totalContributionIndicator.innerText; | 12 | + totalContributionIndicator.appendChild(total); |
| 8 | - console.log(total); | ||
| 9 | }; | 13 | }; |
| 10 | 14 | ||
| 11 | - | ||
| 12 | const getGithubRepo = () =>{ | 15 | const getGithubRepo = () =>{ |
| 13 | - console.log("Get Api here"); | 16 | + const token = process.env.GH_SECRET_SH; |
| 17 | + const username = user.username | ||
| 18 | + const headers = { | ||
| 19 | + 'Authorization': `bearer ${token}`, | ||
| 20 | + }; | ||
| 21 | + const body = { | ||
| 22 | + "query": `query {user(login: "${username}") {contributionsCollection {contributionCalendar {totalContributions}}}}` | ||
| 23 | + }; | ||
| 24 | + const response = fetch(URL, { method: "POST", body: JSON.stringify(body), headers: headers }).then(function(response){ | ||
| 25 | + return response.json(); | ||
| 26 | + }).then(function(res){ | ||
| 27 | + const total = res.data.user.contributionsCollection.contributionCalendar.totalContributions; | ||
| 28 | + handleContributons(total); | ||
| 29 | + }); | ||
| 14 | }; | 30 | }; |
| 15 | 31 | ||
| 16 | const init=()=>{ | 32 | const init=()=>{ | ... | ... |
src/client/js/getUserRepo.js
0 → 100644
| 1 | +const RepoBox = document.getElementById("jsgetRepo"); | ||
| 2 | +const userRepoBox = document.getElementById("jsuserRepo"); | ||
| 3 | +const indicator = document.getElementById("jsIndicator"); | ||
| 4 | +const URL = "https://api.github.com/users/lsj8706/repos?sort=updated&per_page=2"; | ||
| 5 | + | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +const handleRepo = (list) =>{ | ||
| 9 | + list.forEach(element => { | ||
| 10 | + console.log(element.name); | ||
| 11 | + console.log(element.url); | ||
| 12 | + const anchor = document.createElement("a"); | ||
| 13 | + anchor.href = element.url; | ||
| 14 | + anchor.target = "_blank" | ||
| 15 | + anchor.innerHTML = `<span class="repoName">${element.name}</span> : <span class="repoUrl">${element.url}</span>` | ||
| 16 | + userRepoBox.appendChild(anchor); | ||
| 17 | + }); | ||
| 18 | + indicator.style.display = "none"; | ||
| 19 | +}; | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +const getRepos = () =>{ | ||
| 23 | + const response = fetch(URL).then(function(response){ | ||
| 24 | + return response.json(); | ||
| 25 | + }).then(function(data){ | ||
| 26 | + const userRepoList = data; | ||
| 27 | + handleRepo(userRepoList); | ||
| 28 | + }); | ||
| 29 | +}; | ||
| 30 | + | ||
| 31 | +const init=()=>{ | ||
| 32 | + getRepos(); | ||
| 33 | +}; | ||
| 34 | + | ||
| 35 | +if(RepoBox){ | ||
| 36 | + init(); | ||
| 37 | +}; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -28,18 +28,11 @@ export const getUserDetail = async (req, res) => { | ... | @@ -28,18 +28,11 @@ export const getUserDetail = async (req, res) => { |
| 28 | const id = req.params.id; | 28 | const id = req.params.id; |
| 29 | const quote = await getQuote(); | 29 | const quote = await getQuote(); |
| 30 | const user = await User.findById(id); | 30 | const user = await User.findById(id); |
| 31 | - const repo = await getRepos(); | ||
| 32 | - const totalCon = await getContributions(user.githubName); | ||
| 33 | res.render("userDetail", { | 31 | res.render("userDetail", { |
| 34 | pagetTitle: "User Detail", | 32 | pagetTitle: "User Detail", |
| 35 | quote: quote.quote, | 33 | quote: quote.quote, |
| 36 | author: quote.author, | 34 | author: quote.author, |
| 37 | user, | 35 | user, |
| 38 | - fitstRepoName: repo.fitstRepoName, | ||
| 39 | - firstRepoUrl: repo.firstRepoUrl, | ||
| 40 | - secondRepoName: repo.secondRepoName, | ||
| 41 | - secondRepoUrl: repo.secondRepoUrl, | ||
| 42 | - totalContributions: totalCon, | ||
| 43 | }); | 36 | }); |
| 44 | } catch(error){ | 37 | } catch(error){ |
| 45 | console.log(error); | 38 | console.log(error); |
| ... | @@ -155,35 +148,3 @@ export const logout = (req, res) => { | ... | @@ -155,35 +148,3 @@ export const logout = (req, res) => { |
| 155 | req.logout(); | 148 | req.logout(); |
| 156 | res.redirect("/"); | 149 | res.redirect("/"); |
| 157 | }; | 150 | }; |
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 158 | - | ||
| 159 | -const getRepos = async() =>{ | ||
| 160 | - const url = "https://api.github.com/users/lsj8706/repos?sort=updated&per_page=2"; | ||
| 161 | - const latelyRepos = await axios.get(url).then(function(response){ | ||
| 162 | - return response.data; | ||
| 163 | - }); | ||
| 164 | - const fitstRepoName = latelyRepos[0].name; | ||
| 165 | - const secondRepoName = latelyRepos[1].name; | ||
| 166 | - const firstRepoUrl = latelyRepos[0].html_url; | ||
| 167 | - const secondRepoUrl = latelyRepos[1].html_url; | ||
| 168 | - | ||
| 169 | - return { | ||
| 170 | - fitstRepoName, | ||
| 171 | - firstRepoUrl, | ||
| 172 | - secondRepoName, | ||
| 173 | - secondRepoUrl, | ||
| 174 | - }; | ||
| 175 | -}; | ||
| 176 | - | ||
| 177 | -const getContributions = async(username) =>{ | ||
| 178 | - const token = process.env.GH_SECRET_SH; | ||
| 179 | - const headers = { | ||
| 180 | - 'Authorization': `bearer ${token}`, | ||
| 181 | - }; | ||
| 182 | - const body = { | ||
| 183 | - "query": `query {user(login: "${username}") {contributionsCollection {contributionCalendar {totalContributions}}}}` | ||
| 184 | - }; | ||
| 185 | - const response = await fetch('https://api.github.com/graphql', { method: "POST", body: JSON.stringify(body), headers: headers }); | ||
| 186 | - const totalContributions = await response.json(); | ||
| 187 | - const total = totalContributions.data.user.contributionsCollection.contributionCalendar.totalContributions; | ||
| 188 | - return total; | ||
| 189 | -}; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -37,19 +37,16 @@ block content | ... | @@ -37,19 +37,16 @@ block content |
| 37 | hr | 37 | hr |
| 38 | .user-status | 38 | .user-status |
| 39 | .user-status__contributions | 39 | .user-status__contributions |
| 40 | - span#jsTotalContributions=totalContributions | 40 | + span#jsTotalContributions |
| 41 | img(src=`http://ghchart.rshah.org/${user.githubName}` alt="Name Your Github chart") | 41 | img(src=`http://ghchart.rshah.org/${user.githubName}` alt="Name Your Github chart") |
| 42 | .user-status__character | 42 | .user-status__character |
| 43 | h3 Your step | 43 | h3 Your step |
| 44 | img(src="https://preview.free3d.com/img/2019/12/2269306250288170045/1oe8ymrc-900.jpg" alt="character" style="height:200px; width:250px;") | 44 | img(src="https://preview.free3d.com/img/2019/12/2269306250288170045/1oe8ymrc-900.jpg" alt="character" style="height:200px; width:250px;") |
| 45 | - .user-repositories | 45 | + .user-repositories#jsgetRepo |
| 46 | - .user-repo | 46 | + h3 REPOSITORIES |
| 47 | - a(href=firstRepoUrl) | 47 | + .about-userRepo#jsuserRepo |
| 48 | - h3 REPO 1 | 48 | + span#jsIndicator Waiting... |
| 49 | - p=fitstRepoName | 49 | + |
| 50 | - br | ||
| 51 | - a(href=secondRepoUrl) | ||
| 52 | - h3 REPO 2 | ||
| 53 | - p=secondRepoName | ||
| 54 | block scripts | 50 | block scripts |
| 55 | - script(src="/static/js/githubInfo.js") | 51 | + script(src="/static/js/getUserRepo.js") |
| 52 | + script(src="/static/js/getContribution.js") | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment