Skip to content

Commit b45104c

Browse files
committedOct 13, 2019
10: W3/D6 --addition the prototype of 06-git-commits:
--add prototype of this exercise --css is not done, all the borders are used for layout development --miss some information showing on the page --js is not reviewed, could be improved
1 parent 1d4d2d3 commit b45104c

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>Document</title>
8+
<link rel="stylesheet" href="style.css" />
9+
</head>
10+
<body>
11+
<div>
12+
<h1>Commit messages of someone</h1>
13+
<ul class="commits">
14+
</ul>
15+
<button>Get the next repo</button>
16+
</div>
17+
18+
<script src="index.js"></script>
19+
</body>
20+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const org = 'green-fox-academy'
2+
const get_REPOS_URL = org => `https://api.github.com/orgs/${org}/repos`
3+
const get_COMMITS_URL = repo =>
4+
`https://api.github.com/repos/green-fox-academy/${repo}/commits`
5+
6+
const d = document
7+
const header = d.querySelector('h1')
8+
const button = d.querySelector('button')
9+
const ul = d.querySelector('ul')
10+
11+
const fetchRepos = org => {
12+
return fetch(get_REPOS_URL(org)).then(response => response.json())
13+
}
14+
15+
const fetchCommits = repo => {
16+
return fetch(get_COMMITS_URL(repo)).then(response => response.json())
17+
}
18+
19+
const showName = name => {
20+
header.textContent = `Commit messages of ${name}`
21+
return Promise.resolve(name)
22+
}
23+
24+
const showCommits = commits => {
25+
ul.innerHTML = ''
26+
commits.forEach(commit => {
27+
let li = d.createElement('li')
28+
li.className = 'commit'
29+
li.textContent = commit.commit.message
30+
ul.appendChild(li)
31+
})
32+
return Promise.resolve('Show all commits')
33+
}
34+
35+
function* nextRepo(repos) {
36+
repos.length ? yield repos.shift() : yield 'no more repo...'
37+
}
38+
39+
const addButtonEvent = repos => {
40+
button.addEventListener('click', async () => {
41+
let repo = nextRepo(repos).next().value.name
42+
let commits = await fetchCommits(repo)
43+
await showName(repo)
44+
await showCommits(commits)
45+
})
46+
return Promise.resolve('Adding the event listener to the button.')
47+
}
48+
49+
const entryFunction = async org => {
50+
let repos = await fetchRepos(org)
51+
await addButtonEvent(repos)
52+
}
53+
54+
entryFunction(org)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
font-size: 16px;
5+
border: thin solid black;
6+
}
7+
8+
div {
9+
width: 60%;
10+
height: 80vh;
11+
margin: 2em auto;
12+
display: flex;
13+
flex-direction: column;
14+
justify-content: flex-start;
15+
}
16+
17+
h1 {
18+
font-size: 2.5em;
19+
margin-top: 1em;
20+
}
21+
22+
ul[class='commits'] {
23+
list-style: none;
24+
width: 100%;
25+
height: 100%;
26+
overflow: auto;
27+
padding: 1em;
28+
box-sizing: border-box;
29+
}
30+
31+
li[class='commit'] {
32+
width: 100%;
33+
height: 3em;
34+
display: flex;
35+
border-bottom: thin solid #5953F3;
36+
justify-content: space-between;
37+
text-align: center;
38+
}
39+
40+
li:nth-of-type(2n) {
41+
background-color: #c4d6f7;
42+
}
43+
44+
button {
45+
width: 10em;
46+
height: 5em;
47+
color: white;
48+
margin: 1em auto;
49+
border-radius: 0.5em;
50+
background-color: #0029fa;
51+
}

0 commit comments

Comments
 (0)
Please sign in to comment.