Showing
3 changed files
with
51 additions
and
3 deletions
... | @@ -24,6 +24,7 @@ | ... | @@ -24,6 +24,7 @@ |
24 | "mongoose": "^5.12.9", | 24 | "mongoose": "^5.12.9", |
25 | "morgan": "^1.10.0", | 25 | "morgan": "^1.10.0", |
26 | "multer": "^1.4.2", | 26 | "multer": "^1.4.2", |
27 | + "node-fetch": "^2.6.1", | ||
27 | "nodemon": "^2.0.7", | 28 | "nodemon": "^2.0.7", |
28 | "passport": "^0.4.1", | 29 | "passport": "^0.4.1", |
29 | "passport-github2": "^0.1.12", | 30 | "passport-github2": "^0.1.12", | ... | ... |
1 | import axios from "axios"; | 1 | import axios from "axios"; |
2 | import passport from "passport"; | 2 | import passport from "passport"; |
3 | import User from "../models/User"; | 3 | import User from "../models/User"; |
4 | +import fetch from "node-fetch"; | ||
4 | 5 | ||
5 | const getQuote = async (req, res) => { | 6 | const getQuote = async (req, res) => { |
6 | const url = "http://quotes.stormconsultancy.co.uk/random.json"; | 7 | const url = "http://quotes.stormconsultancy.co.uk/random.json"; |
... | @@ -74,11 +75,18 @@ export const getUserDetail = async (req, res) => { | ... | @@ -74,11 +75,18 @@ export const getUserDetail = async (req, res) => { |
74 | const id = req.params.id; | 75 | const id = req.params.id; |
75 | const quote = await getQuote(); | 76 | const quote = await getQuote(); |
76 | const user = await User.findById(id); | 77 | const user = await User.findById(id); |
78 | + const repo = await getRepos(); | ||
79 | + const totalCon = await getContributions(); | ||
77 | res.render("userDetail", { | 80 | res.render("userDetail", { |
78 | pagetTitle: "User Detail", | 81 | pagetTitle: "User Detail", |
79 | quote: quote.quote, | 82 | quote: quote.quote, |
80 | author: quote.author, | 83 | author: quote.author, |
81 | user, | 84 | user, |
85 | + fitstRepoName: repo.fitstRepoName, | ||
86 | + firstRepoUrl: repo.firstRepoUrl, | ||
87 | + secondRepoName: repo.secondRepoName, | ||
88 | + secondRepoUrl: repo.secondRepoUrl, | ||
89 | + totalContributions: totalCon, | ||
82 | }); | 90 | }); |
83 | } catch(error){ | 91 | } catch(error){ |
84 | console.log(error); | 92 | console.log(error); |
... | @@ -194,3 +202,36 @@ export const logout = (req, res) => { | ... | @@ -194,3 +202,36 @@ export const logout = (req, res) => { |
194 | req.logout(); | 202 | req.logout(); |
195 | res.redirect("/"); | 203 | res.redirect("/"); |
196 | }; | 204 | }; |
205 | + | ||
206 | +const getRepos = async(req,res) =>{ | ||
207 | + const url = "https://api.github.com/users/lsj8706/repos?sort=updated&per_page=2"; | ||
208 | + const latelyRepos = await axios.get(url).then(function(response){ | ||
209 | + return response.data; | ||
210 | + }); | ||
211 | + const fitstRepoName = latelyRepos[0].name; | ||
212 | + const secondRepoName = latelyRepos[1].name; | ||
213 | + const firstRepoUrl = latelyRepos[0].html_url; | ||
214 | + const secondRepoUrl = latelyRepos[1].html_url; | ||
215 | + | ||
216 | + return { | ||
217 | + fitstRepoName, | ||
218 | + firstRepoUrl, | ||
219 | + secondRepoName, | ||
220 | + secondRepoUrl, | ||
221 | + }; | ||
222 | +}; | ||
223 | + | ||
224 | +const getContributions = async(req, res) =>{ | ||
225 | + const token = process.env.GH_SECRET_SH; | ||
226 | + const username = 'lsj8706' | ||
227 | + const headers = { | ||
228 | + 'Authorization': `bearer ${token}`, | ||
229 | + }; | ||
230 | + const body = { | ||
231 | + "query": `query {user(login: "${username}") {contributionsCollection {contributionCalendar {totalContributions}}}}` | ||
232 | + }; | ||
233 | + const response = await fetch('https://api.github.com/graphql', { method: "POST", body: JSON.stringify(body), headers: headers }); | ||
234 | + const totalContributions = await response.json(); | ||
235 | + const total = totalContributions.data.user.contributionsCollection.contributionCalendar.totalContributions; | ||
236 | + return total; | ||
237 | +}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -37,6 +37,9 @@ block content | ... | @@ -37,6 +37,9 @@ block content |
37 | hr | 37 | hr |
38 | .user-status | 38 | .user-status |
39 | .user-status__contributions | 39 | .user-status__contributions |
40 | + img(src="http://ghchart.rshah.org/lsj8706" alt="Name Your Github chart") | ||
41 | + a(href=Url0, style={color:'grey'}) | ||
42 | + p=totalContributions | ||
40 | img(src=`http://ghchart.rshah.org/${user.githubName}` alt="Name Your Github chart") | 43 | img(src=`http://ghchart.rshah.org/${user.githubName}` alt="Name Your Github chart") |
41 | .user-status__character | 44 | .user-status__character |
42 | h3 Your step | commit numbers | 45 | h3 Your step | commit numbers |
... | @@ -44,6 +47,9 @@ block content | ... | @@ -44,6 +47,9 @@ block content |
44 | .user-repositories | 47 | .user-repositories |
45 | .user-repo | 48 | .user-repo |
46 | h3 REPO 1 | 49 | h3 REPO 1 |
47 | - | ||
48 | - | ||
49 | - | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
50 | + a(href=Url0, style={color:'grey'}) | ||
51 | + p=fitstRepoName+": "+firstRepoUrl | ||
52 | + br | ||
53 | + h3 REPO 2 | ||
54 | + a(href=Url0, style={color:'grey'}) | ||
55 | + p=secondRepoName+": "+secondRepoUrl | ... | ... |
-
Please register or login to post a comment