Toggle navigation
Toggle navigation
This project
Loading...
Sign in
JungSeungHyun
/
dev-profile
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
JungSeungHyun
2021-06-04 11:38:28 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ef8f451b1fdb6fe1d2e6092e93cd666091fa4b13
ef8f451b
1 parent
aa98d150
Update getContribution and UserRepoitories in frontend
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
56 deletions
.vscode/launch.json
src/client/js/githubInfo.js → src/client/js/getContribution.js
src/client/js/getUserRepo.js
src/controllers/userController.js
src/views/userDetail.pug
.vscode/launch.json
0 → 100644
View file @
ef8f451
{
//
Use
IntelliSense
to
learn
about
possible
attributes.
//
Hover
to
view
descriptions
of
existing
attributes.
//
For
more
information
,
visit
:
https
:
//go.microsoft.com/fwlink/?linkid=
830387
"version"
:
"0.2.0"
,
"configurations"
:
[
{
"type"
:
"pwa-node"
,
"request"
:
"launch"
,
"name"
:
"Launch Program"
,
"skipFiles"
:
[
"<node_internals>/**"
],
"program"
:
"${workspaceFolder}
\\
src
\\
client
\\
js
\\
getUserRepo.js"
}
]
}
\ No newline at end of file
src/client/js/g
ithubInfo
.js
→
src/client/js/g
etContribution
.js
View file @
ef8f451
const
userContributionsBox
=
document
.
querySelector
(
".user-status__contributions"
);
const
totalContributionIndicator
=
document
.
getElementById
(
"jsTotalContributions"
);
const
URL
=
"https://api.github.com/graphql"
// const handleImage = () =>{
// const total = totalContributionIndicator.innerText;
// console.log(total);
// };
const
handleImage
=
()
=>
{
const
total
=
totalContributionIndicator
.
innerText
;
console
.
log
(
total
);
const
handleContributons
=
(
total
)
=>
{
totalContributionIndicator
.
appendChild
(
total
);
};
const
getGithubRepo
=
()
=>
{
console
.
log
(
"Get Api here"
);
const
token
=
process
.
env
.
GH_SECRET_SH
;
const
username
=
user
.
username
const
headers
=
{
'Authorization'
:
`bearer
${
token
}
`
,
};
const
body
=
{
"query"
:
`query {user(login: "
${
username
}
") {contributionsCollection {contributionCalendar {totalContributions}}}}`
};
const
response
=
fetch
(
URL
,
{
method
:
"POST"
,
body
:
JSON
.
stringify
(
body
),
headers
:
headers
}).
then
(
function
(
response
){
return
response
.
json
();
}).
then
(
function
(
res
){
const
total
=
res
.
data
.
user
.
contributionsCollection
.
contributionCalendar
.
totalContributions
;
handleContributons
(
total
);
});
};
const
init
=
()
=>
{
...
...
src/client/js/getUserRepo.js
0 → 100644
View file @
ef8f451
const
RepoBox
=
document
.
getElementById
(
"jsgetRepo"
);
const
userRepoBox
=
document
.
getElementById
(
"jsuserRepo"
);
const
indicator
=
document
.
getElementById
(
"jsIndicator"
);
const
URL
=
"https://api.github.com/users/lsj8706/repos?sort=updated&per_page=2"
;
const
handleRepo
=
(
list
)
=>
{
list
.
forEach
(
element
=>
{
console
.
log
(
element
.
name
);
console
.
log
(
element
.
url
);
const
anchor
=
document
.
createElement
(
"a"
);
anchor
.
href
=
element
.
url
;
anchor
.
target
=
"_blank"
anchor
.
innerHTML
=
`<span class="repoName">
${
element
.
name
}
</span> : <span class="repoUrl">
${
element
.
url
}
</span>`
userRepoBox
.
appendChild
(
anchor
);
});
indicator
.
style
.
display
=
"none"
;
};
const
getRepos
=
()
=>
{
const
response
=
fetch
(
URL
).
then
(
function
(
response
){
return
response
.
json
();
}).
then
(
function
(
data
){
const
userRepoList
=
data
;
handleRepo
(
userRepoList
);
});
};
const
init
=
()
=>
{
getRepos
();
};
if
(
RepoBox
){
init
();
};
\ No newline at end of file
src/controllers/userController.js
View file @
ef8f451
...
...
@@ -28,18 +28,11 @@ 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
(
user
.
githubName
);
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
);
...
...
@@ -154,36 +147,4 @@ export const postGithubLogin = (req, res) => {
export
const
logout
=
(
req
,
res
)
=>
{
req
.
logout
();
res
.
redirect
(
"/"
);
};
const
getRepos
=
async
()
=>
{
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
(
username
)
=>
{
const
token
=
process
.
env
.
GH_SECRET_SH
;
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 @
ef8f451
...
...
@@ -37,19 +37,16 @@ block content
hr
.user-status
.user-status__contributions
span#jsTotalContributions
=totalContributions
span#jsTotalContributions
img(src=`http://ghchart.rshah.org/${user.githubName}` alt="Name Your Github chart")
.user-status__character
h3 Your step
img(src="https://preview.free3d.com/img/2019/12/2269306250288170045/1oe8ymrc-900.jpg" alt="character" style="height:200px; width:250px;")
.user-repositories
.user-repo
a(href=firstRepoUrl)
h3 REPO 1
p=fitstRepoName
br
a(href=secondRepoUrl)
h3 REPO 2
p=secondRepoName
block scripts
script(src="/static/js/githubInfo.js")
.user-repositories#jsgetRepo
h3 REPOSITORIES
.about-userRepo#jsuserRepo
span#jsIndicator Waiting...
block scripts
script(src="/static/js/getUserRepo.js")
script(src="/static/js/getContribution.js")
\ No newline at end of file
...
...
Please
register
or
login
to post a comment