-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (51 loc) · 1.72 KB
/
Copy pathapp.js
File metadata and controls
56 lines (51 loc) · 1.72 KB
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
console.log('Enter Your GitHub Username: ');
async function fetchGitHubActivity(url) {
const res = await fetch(url);
if (!res.ok) {
console.error(`User Not Found.`);
process.exit();
}
console.log(`Fetch Activity from ${url}`);
return res.json();
}
function displayActivity(data) {
if (data.length === 0) {
console.log("No recent activity found.");
return;
}
data.forEach((event) => {
let action;
switch (event.type) {
case "PushEvent":
const commitCount = event.payload.commits.length;
action = `Pushed ${commitCount} commit(s) to ${event.repo.name}`;
break;
case "IssuesEvent":
action = `${event.payload.action.charAt(0).toUpperCase() + event.payload.action.slice(1)} an issue in ${event.repo.name}`;
break;
case "WatchEvent":
action = `Starred ${event.repo.name}`;
break;
case "ForkEvent":
action = `Forked ${event.repo.name}`;
break;
case "CreateEvent":
action = `Created ${event.payload.ref_type} in ${event.repo.name}`;
break;
default:
action = `${event.type.replace("Event", "")} in ${event.repo.name}`;
break;
}
console.log(`- ${action}`);
});
}
process.stdin.on('data', username => {
username = username.toString().trim();
let url = `https://api.github.com/users/${username}/events`;
fetchGitHubActivity(url)
.then((data) => {
displayActivity(data);
process.exit();
})
.catch(err => console.error(err));
});