forked from tiziano88/github-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
169 lines (168 loc) · 6.32 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
function map_append(map, key, value) {
const current = map.get(key);
if (current == undefined) {
map.set(key, [value]);
}
else {
current.push(value);
}
}
function format_user(user) {
if (user) {
return `[${user.login}](${user.html_url})`;
}
else {
return "n/a";
}
}
function main() {
return __awaiter(this, void 0, void 0, function* () {
const url_params = new URLSearchParams(window.location.search);
const username_input = document.getElementById("username");
console.log(username_input);
const start_date_input = document.getElementById("start_date");
const end_date_input = document.getElementById("end_date");
const username = url_params.get("username") || "";
if (username == "") {
return;
}
username_input.value = username;
const start_date = url_params.get("start_date") || "";
if (start_date == "") {
return;
}
start_date_input.value = start_date;
const end_date = url_params.get("end_date") || "";
if (end_date == "") {
return;
}
end_date_input.value = end_date;
const all_events = new Array();
const res = [1, 2, 3].map((page) => fetch(`https://api.github.com/users/${username}/events?per_page=1000&page=${page}`));
for (let r of res) {
const r1 = yield r;
all_events.push(...(yield r1.json()));
}
console.log(all_events);
const events = all_events.filter((e) => {
return e.created_at >= start_date && e.created_at < end_date;
});
console.log(events);
events.sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at));
/*
const issues = new Map<string, Promise<Issue>>();
const pull_requests = new Map<string, Promise<PullRequest>>();
for (let e of events) {
{
let issue_url = e.payload?.issue?.url;
if (issue_url) {
if (!issues.has(issue_url)) {
issues.set(
issue_url,
fetch(issue_url).then((r) => r.json())
);
}
}
}
{
let pr_url = e.payload?.pull_request?.url;
if (pr_url) {
if (!pull_requests.has(pr_url)) {
pull_requests.set(
pr_url,
fetch(pr_url).then((r) => r.json())
);
}
}
}
}
*/
let output = "";
output += "Opened issues:\n\n";
output += events
.filter((v) => v.type == "IssuesEvent")
.filter((v) => v.payload.action == "opened")
.map((v) => {
const issue = v.payload.issue;
return `- [${issue.title}](${issue.html_url}) (assignee: ${format_user(issue.assignee)})`;
})
.join("\n");
output += "\n\n";
output += "Reopened issues:\n\n";
output += events
.filter((v) => v.type == "IssuesEvent")
.filter((v) => v.payload.action == "reopened")
.map((v) => {
const issue = v.payload.issue;
return `- [${issue.title}](${issue.html_url}) (assignee: ${format_user(issue.assignee)})`;
})
.join("\n");
output += "\n\n";
output += "Commented on issues:\n\n";
output += Array.from(events
.filter((v) => v.type == "IssueCommentEvent")
.filter((v) => v.payload.action == "created")
.reduce((map, e) => {
map_append(map, e.payload.issue.html_url, e);
return map;
}, new Map())
.entries() || [])
.map(([k, v]) => {
const latest = v[v.length - 1];
const issue = latest.payload.issue;
return `- [${issue.title}](${k}) (author: ${format_user(issue.user)}, comments: ${v.length})`;
})
.join("\n");
output += "\n\n";
output += "Opened pull requests:\n\n";
output += events
.filter((v) => v.type == "PullRequestEvent")
.filter((v) => v.payload.action == "opened")
.map((v) => {
const pull_request = v.payload.pull_request;
return `- [${pull_request.title}](${pull_request.html_url}) (status: ${pull_request.state})`;
})
.join("\n");
output += "\n\n";
output += "Closed pull requests:\n\n";
output += events
.filter((v) => v.type == "PullRequestEvent")
.filter((v) => v.payload.action == "closed")
.map((v) => {
const pull_request = v.payload.pull_request;
return `- [${pull_request.title}](${pull_request.html_url})`;
})
.join("\n");
output += "\n\n";
output += "Commented on pull requests:\n\n";
output += Array.from(events
.filter((v) => v.type == "PullRequestReviewCommentEvent")
.reduce((map, e) => {
map_append(map, e.payload.pull_request.html_url, e);
return map;
}, new Map())
.entries() || [])
.map(([k, v]) => {
const latest = v[v.length - 1];
const pull_request = latest.payload.pull_request;
return `- [${pull_request.title}](${k}) (author: ${format_user(pull_request.user)}, comments: ${v.length})`;
})
.join("\n");
output += "\n\n";
const snippets = document.getElementById("snippets");
if (snippets) {
snippets.innerText = output;
}
});
}
main();