Skip to content

Commit e257421

Browse files
committed
added profile and reposetories
1 parent ded93a5 commit e257421

4 files changed

Lines changed: 82 additions & 3 deletions

File tree

code/chart.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,24 @@
22
const ctx = document.getElementById('chart').getContext('2d')
33

44
//"Draw" the chart here 👇
5+
const drawChart = (amount) => {
6+
const config = {
7+
type: 'doughnut',
8+
data: {
9+
labels: [
10+
'Finished Projects',
11+
'Projects Left'
12+
],
13+
datasets: [{
14+
label: 'My First Dataset',
15+
data: [amount, 20-amount],
16+
backgroundColor: [
17+
"rgb(255, 99, 132)",
18+
"rgb(54, 162, 235)"
19+
],
20+
hoverOffset: 4
21+
}]
22+
},
23+
};
24+
const myChart = new Chart(ctx, config)
25+
}

code/index.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Project GitHub Tracker</title>
88
<link rel="stylesheet" href="./style.css" />
9+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
910
</head>
1011
<body>
1112
<h1>GitHub Tracker</h1>
13+
<h2>Profile:</h2>
14+
<div id="profile"></div>
15+
1216
<h2>Projects:</h2>
1317
<main id="projects"></main>
1418

19+
20+
1521
<!-- This will be used to draw the chart 👇 -->
22+
<div class="chart">
1623
<canvas id="chart"></canvas>
17-
24+
</div>
1825
<script src="./script.js"></script>
1926
<script src="./chart.js"></script>
2027
</body>

code/script.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// API's
2+
const USER = 'Mattsson717'
3+
const REPOS_URL = `https://api.github.com/users/${USER}/repos`
4+
const PROFILE_URL = `https://api.github.com/users/${USER}`
5+
const COMMITS_URL = `https://api.github.com/repos/Mattsson717/project-business-site/commits{/sha}`
6+
const projectsContainer = document.getElementById('projects')
7+
const profileContainer = document.getElementById('profile')
8+
9+
// Profile
10+
const getProfile = () => {
11+
fetch(PROFILE_URL)
12+
.then(response => response.json())
13+
.then(data => {
14+
console.log('Profile:',data)
15+
profileContainer.innerHTML += `
16+
<img src=${data.avatar_url}>
17+
<h2>${data.login}</h2>`
18+
})
19+
}
20+
getProfile()
21+
22+
// Repositories
23+
const getRepos = () => {
24+
fetch(REPOS_URL)
25+
.then(response => response.json())
26+
.then(json => {
27+
console.log('json:',json)
28+
const forkedRepos = json.filter(repo => repo.fork && repo.name.startsWith('project-'))
29+
forkedRepos.forEach(repo => projectsContainer.innerHTML +=
30+
`<h3>${repo.name}</h3>
31+
<h3>${repo.default_branch}</h3>
32+
<h4>Latest push: ${repo.pushed_at.slice(0, 10)} - ${repo.pushed_at.slice(11,16)}</h4>
33+
<a href="${repo.html_url}">Github adress</a>
34+
`)
35+
drawChart(forkedRepos.length)
36+
})
37+
}
38+
getRepos()
39+
40+
const getCommits = () => {
41+
fetch(COMMITS_URL)
42+
.then(response => response.json())
43+
.then(json => {
44+
console.log('Commits:',json)
45+
})
46+
}
47+
getCommits()

code/style.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
body {
2-
background: #FFECE9;
3-
}
2+
background: #ffece9;
3+
}
4+
5+
.chart {
6+
width: 200px;
7+
}

0 commit comments

Comments
 (0)