Toggle navigation
Toggle navigation
This project
Loading...
Sign in
이세진
/
dev-profile
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
10
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
JungSeungHyun
2021-05-28 23:46:28 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e886d2f659133d28fb67c25895a90fcb529fc675
e886d2f6
1 parent
aa0b218f
getContribution
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
3 deletions
package.json
src/controllers/userController.js
src/views/userDetail.pug
package.json
View file @
e886d2f
...
...
@@ -24,6 +24,7 @@
"mongoose"
:
"^5.12.9"
,
"morgan"
:
"^1.10.0"
,
"multer"
:
"^1.4.2"
,
"node-fetch"
:
"^2.6.1"
,
"nodemon"
:
"^2.0.7"
,
"passport"
:
"^0.4.1"
,
"passport-github2"
:
"^0.1.12"
,
...
...
src/controllers/userController.js
View file @
e886d2f
import
axios
from
"axios"
;
import
passport
from
"passport"
;
import
User
from
"../models/User"
;
import
fetch
from
"node-fetch"
;
const
getQuote
=
async
(
req
,
res
)
=>
{
const
url
=
"http://quotes.stormconsultancy.co.uk/random.json"
;
...
...
@@ -74,11 +75,18 @@ export const getUserDetail = async (req, res) => {
const
id
=
req
.
params
.
id
;
const
quote
=
await
getQuote
();
const
user
=
await
User
.
findById
(
id
);
const
repo
=
await
getRepos
();
const
totalCon
=
await
getContributions
();
res
.
render
(
"userDetail"
,
{
pagetTitle
:
"User Detail"
,
quote
:
quote
.
quote
,
author
:
quote
.
author
,
user
,
fitstRepoName
:
repo
.
fitstRepoName
,
firstRepoUrl
:
repo
.
firstRepoUrl
,
secondRepoName
:
repo
.
secondRepoName
,
secondRepoUrl
:
repo
.
secondRepoUrl
,
totalContributions
:
totalCon
,
});
}
catch
(
error
){
console
.
log
(
error
);
...
...
@@ -194,3 +202,36 @@ export const logout = (req, res) => {
req
.
logout
();
res
.
redirect
(
"/"
);
};
const
getRepos
=
async
(
req
,
res
)
=>
{
const
url
=
"https://api.github.com/users/lsj8706/repos?sort=updated&per_page=2"
;
const
latelyRepos
=
await
axios
.
get
(
url
).
then
(
function
(
response
){
return
response
.
data
;
});
const
fitstRepoName
=
latelyRepos
[
0
].
name
;
const
secondRepoName
=
latelyRepos
[
1
].
name
;
const
firstRepoUrl
=
latelyRepos
[
0
].
html_url
;
const
secondRepoUrl
=
latelyRepos
[
1
].
html_url
;
return
{
fitstRepoName
,
firstRepoUrl
,
secondRepoName
,
secondRepoUrl
,
};
};
const
getContributions
=
async
(
req
,
res
)
=>
{
const
token
=
process
.
env
.
GH_SECRET_SH
;
const
username
=
'lsj8706'
const
headers
=
{
'Authorization'
:
`bearer
${
token
}
`
,
};
const
body
=
{
"query"
:
`query {user(login: "
${
username
}
") {contributionsCollection {contributionCalendar {totalContributions}}}}`
};
const
response
=
await
fetch
(
'https://api.github.com/graphql'
,
{
method
:
"POST"
,
body
:
JSON
.
stringify
(
body
),
headers
:
headers
});
const
totalContributions
=
await
response
.
json
();
const
total
=
totalContributions
.
data
.
user
.
contributionsCollection
.
contributionCalendar
.
totalContributions
;
return
total
;
};
\ No newline at end of file
...
...
src/views/userDetail.pug
View file @
e886d2f
...
...
@@ -37,6 +37,9 @@ block content
hr
.user-status
.user-status__contributions
img(src="http://ghchart.rshah.org/lsj8706" alt="Name Your Github chart")
a(href=Url0, style={color:'grey'})
p=totalContributions
img(src=`http://ghchart.rshah.org/${user.githubName}` alt="Name Your Github chart")
.user-status__character
h3 Your step | commit numbers
...
...
@@ -44,6 +47,9 @@ block content
.user-repositories
.user-repo
h3 REPO 1
\ No newline at end of file
a(href=Url0, style={color:'grey'})
p=fitstRepoName+": "+firstRepoUrl
br
h3 REPO 2
a(href=Url0, style={color:'grey'})
p=secondRepoName+": "+secondRepoUrl
...
...
Please
register
or
login
to post a comment