-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-data.js
70 lines (59 loc) · 1.93 KB
/
parse-data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
export function getGithubCommits({separatedEvent, event}) {
const PushEvent = separatedEvent[event]
if (!PushEvent) {
console.log('\nCommits:')
console.log('No se han hecho commits')
process.exit(0)
}
let separtedByDate = {}
for (let i = 0; i < PushEvent.length; i++) {
const currentDate = new Date(PushEvent[i].created_at).toLocaleDateString()
if (separtedByDate[currentDate]) {
separtedByDate[currentDate] = [...separtedByDate[currentDate], PushEvent[i]]
} else {
separtedByDate[currentDate] = [PushEvent[i]]
}
}
const keys = Object.keys(separtedByDate)
console.log('\nCommits:')
for (let i = 0; i < keys.length; i++) {
let count = 0
let repos = []
separtedByDate[keys[i]].forEach(item => {
count += item.payload.commits.length
if (!repos.includes(item.repo.name)) {
repos.push(item.repo.name)
}
})
console.log(`${keys[i]} Pushed ${String(count).padEnd(5)} commits to ${repos.join(',')}`)
}
}
export function getGithubRepos({separatedEvent, event}) {
const PushEvent = separatedEvent[event]
if (!PushEvent) {
console.log('\nRepos:')
console.log('No se han credo repositorios')
process.exit(0)
}
let separtedByDate = {}
for (let i = 0; i < PushEvent.length; i++) {
const currentDate = new Date(PushEvent[i].created_at).toLocaleDateString();
if (!separtedByDate[currentDate]) {
separtedByDate[currentDate] = [];
}
const repoName = PushEvent[i].repo.name;
const isRepoAlreadyAdded = separtedByDate[currentDate].some(event => event.repo.name === repoName);
if (isRepoAlreadyAdded) {
continue;
} else {
separtedByDate[currentDate].push(PushEvent[i]);
}
}
const keys = Object.keys(separtedByDate)
console.log('\nRepos:')
for (let i = 0; i < keys.length; i++) {
separtedByDate[keys[i]].forEach(item => {
console.log(`${keys[i]} create ${item.repo.name}`)
})
}
}