-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathprofile.js
779 lines (687 loc) · 29.2 KB
/
profile.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
let user_data;
let issues_data;
let commits_data = {
total_count: 0,
items: []
};
let prs_data = {
items: []
};
let prs_data_merged = {
items: []
};
let projects_data = {
items: []
};
let projects_list;
let projects_list_filtered = {
list: []
};
let contri_data = [];
let url_params;
// Change according to duration of GSSoC
let gssoc_start_date = "2021-03-08"; // 2021-03-08
let gssoc_end_date = "2021-06-01"; // 2021-06-01
// Get GitHub username from URL query string
let search = location.search.substring(1);
if(search != "") {
url_params = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g,'":"') + '"}', (key, value) => key===""?value:decodeURIComponent(value));
}
// Fetch data from GitHub API
async function getUser(github_username) {
const url = `https://api.github.com/users/${github_username}`;
const response = await fetch(url);
user_data = await response.json();
// let errorText = document.querySelector('#errorText');
if(user_data.hasOwnProperty('message')) {
$('#profileContainer').css("display", "none");
$('#searchContainer').css("display", "flex");
} else {
$('#searchContainer').css("display", "none");
$('#profileContainer').css("display", "grid");
}
// console.log("User:\n", user_data);
let gs_profile_pic_container = document.querySelector('.gs-profile-pic-container');
let fullname = document.querySelector('.gs-fullname');
let username = document.querySelector('.gs-username');
let bio = document.querySelector('.gs-bio');
let github = document.querySelector('.gs-profile-social .github');
let followers = document.querySelector('.gs-user-stats .followers');
let following = document.querySelector('.gs-user-stats .following');
// Do something
gs_profile_pic_container.innerHTML = `<img class="gs-profile-pic" src="${user_data.avatar_url}" alt="Profile Pic" />`;
fullname.innerHTML = user_data.name;
username.innerHTML = user_data.login;
bio.innerHTML = user_data.bio;
github.setAttribute('href', user_data.html_url);
followers.innerHTML = `
<div class="gs-user-stats-title">Followers</div>
<div class="gs-user-stats-data">${user_data.followers}</div>
`;
following.innerHTML = `
<div class="gs-user-stats-title">Following</div>
<div class="gs-user-stats-data">${user_data.following}</div>
`;
}
async function getCommits(github_username, start_date, end_date) {
const headers = {
"Accept" : "application/vnd.github.cloak-preview"
}
const params = {
"method" : "GET",
"headers" : headers
}
let temp_data;
let page = 1;
do {
const url_commits = `https://api.github.com/search/commits?q=author:${github_username} author-date:${start_date}..${end_date} sort:committer-date&page=${page}&per_page=100`;
const response = await fetch(url_commits, params);
temp_data = await response.json();
commits_data.total_count = temp_data.total_count;
if(temp_data.items.length == 0) {
break;
}
commits_data.items = [...commits_data.items, ...temp_data.items].unique();
page++;
} while (page <= 1);
// store only commits that are in the project list
commits_data.items = commits_data.items.filter((commit, index, arr) => {
for(let i = 0; i < projects_list.list.length; i++) {
if(commit.repository.full_name === projects_list.list[i]) {
// create list of projects that user has committed to
projects_list_filtered.list.includes(commit.repository.full_name) ? null : projects_list_filtered.list.push(commit.repository.full_name);
return true;
}
}
return false;
});
let total_commits = document.querySelector('.gs-profile-container-stats .total-commits');
total_commits.innerHTML = commits_data.items.length;
let commitsContainer = document.querySelector('#commitsContainer');
commitsContainer.innerHTML = '';
commits_data.items.forEach(element => {
const sha = element.sha.substring(0, 7);
const repo = element.repository.full_name;
const repo_url = element.repository.html_url;
const commit_url = element.html_url;
const message = element.commit.message.length <= 165 ? element.commit.message.substring(0, 165) : element.commit.message.substring(0, 165) + '...';
const date_str = element.commit.author.date;
const date = new Date(date_str);
commitsContainer.innerHTML = commitsContainer.innerHTML + `
<div class="gs-commit">
<div class="gs-commit-infobox">
<div class="gs-commit-date">${date.toDateString() + " " + date.toLocaleTimeString()}</div>
<div class="gs-commit-text">Committed <a class="gs-commit-url" href="${commit_url}" target="_blank"><b>${sha}</b></a> to <a href="${repo_url}" target="_blank">${repo}</a></div>
<div class="gs-commit-message">${message}</div>
</div>
</div>
`;
});
}
async function getIssues(github_username, start_date, end_date) {
const url = `https://api.github.com/search/issues?q=author:${github_username} type:issue created:${start_date}..${end_date} sort:created&per_page=100`;
const response = await fetch(url);
issues_data = await response.json();
// store only issues that are in the project list
issues_data.items = issues_data.items.filter((issue, index, arr) => {
const repo = issue.repository_url.substring(29);
for(let i = 0; i < projects_list.list.length; i++) {
if(repo === projects_list.list[i]) {
return true;
}
}
return false;
});
let total_issues = document.querySelector('.gs-profile-container-stats .total-issues');
total_issues.innerHTML = issues_data.items.length;
let issuesContainer = document.querySelector('#issuesContainer');
issuesContainer.innerHTML = '';
issues_data.items.forEach(element => {
const id = element.id;
const url = element.html_url;
const title = element.title;
const state = element.state;
const stateCapital = element.state.charAt(0).toUpperCase() + element.state.substring(1);
const labels = element.labels;
// const body = element.body;
// const number = element.number;
const repo_url = element.repository_url.replace('api.', '').replace('repos/', '');
const repo = repo_url.substring(19);
const date_start = element.created_at;
const date_end = element.closed_at ? element.closed_at : "";
const date_s = new Date(date_start);
const date_e = (date_end != "") ? new Date(date_end) : "";
issuesContainer.innerHTML = issuesContainer.innerHTML + `
<div class="gs-issue gs-issue-${id} gs-issue-${state}">
<span class="iconify" data-icon="octicon:issue-${state=='open'?'opened':'closed'}" data-inline="false"></span>
<div>
<div class="gs-labels-container"></div>
<div class="gs-issue-infobox">
<div class="gs-issue-text">${stateCapital}: <a class="gs-issue-url" href="${url}" target="_blank"><b>${title}</b></a> in <a href="${repo_url}" target="_blank">${repo}</a></div>
<div class="gs-issue-date">Opened:${date_s.toLocaleDateString() + (date_e != "" ? " | Closed: " + date_e.toLocaleDateString() : "")}</div>
</div>
</div>
</div>
`;
let gs_labels_container = document.querySelector(`.gs-issue-${id} .gs-labels-container`);
gs_labels_container.innerHTML = '';
labels.forEach(label => {
gs_labels_container.innerHTML = gs_labels_container.innerHTML + `<div class="gs-label" style="color:${isLight(label.color)?'#000':'#fff'};background-color:#${label.color}">${label.name}</div>`;
});
});
}
async function getPRs(github_username, start_date, end_date) {
// if(projects_list_filtered.list.length != 0) {
// const url = `https://api.github.com/search/issues?q=author:${github_username} type:pr created:${start_date}..${end_date} sort:created&per_page=100`;
// const url_merged = `https://api.github.com/search/issues?q=author:${github_username} type:pr is:merged created:${start_date}..${end_date} sort:created&per_page=100`;
// const response = await fetch(url);
// prs_data = await response.json();
// const response_merged = await fetch(url_merged);
// prs_data_merged = await response_merged.json();
// } else {
// prs_data = {
// total_count: 0,
// items: []
// };
// prs_data_merged = {
// total_count: 0,
// items: []
// };
// }
// const url = `https://api.github.com/search/issues?q=author:${github_username} type:pr updated:${start_date}..${end_date} sort:created&page=1&per_page=100`;
// const url_merged = `https://api.github.com/search/issues?q=author:${github_username} type:pr is:merged updated:${start_date}..${end_date} sort:updated&page=1&per_page=100`;
// const response = await fetch(url);
// prs_data = await response.json();
// const response_merged = await fetch(url_merged);
// prs_data_merged = await response_merged.json();
let temp_data;
let page;
page = 1;
do {
const url = `https://api.github.com/search/issues?q=author:${github_username} type:pr updated:${start_date}..${end_date} sort:created&page=${page}&per_page=100`;
const response = await fetch(url);
temp_data = await response.json();
prs_data.total_count = temp_data.total_count;
if(temp_data.items.length == 0) {
break;
}
prs_data.items = [...prs_data.items, ...temp_data.items].unique();
page++;
} while (page <= 3);
page = 1;
do {
const url_merged = `https://api.github.com/search/issues?q=author:${github_username} type:pr is:merged updated:${start_date}..${end_date} sort:updated&page=${page}&per_page=100`;
const response_merged = await fetch(url_merged);
temp_data = await response_merged.json();
prs_data_merged.total_count = temp_data.total_count;
if(temp_data.items.length == 0) {
break;
}
prs_data_merged.items = [...prs_data_merged.items, ...temp_data.items].unique();
page++;
} while (page <= 3);
// console.log("PRs:\n", prs_data);
// console.log("Merged PRs:\n", prs_data_merged);
// store only PRs that are in the project list
prs_data.items = prs_data.items.filter((pr, index, arr) => {
const repo = pr.repository_url.substring(29);
for(let i = 0; i < projects_list.list.length; i++) {
if(repo === projects_list.list[i]) {
return true;
}
}
return false;
});
prs_data_merged.items = prs_data_merged.items.filter((pr, index, arr) => {
const repo = pr.repository_url.substring(29);
for(let i = 0; i < projects_list.list.length; i++) {
if(repo === projects_list.list[i]) {
return true;
}
}
return false;
});
// change PR state to 'merged' for those that are merged
prs_data.items = prs_data.items.map(element => {
prs_data_merged.items.forEach((ele) => {
if(JSON.stringify(ele) === JSON.stringify(element)) {
element.state = "merged";
}
});
return element;
});
// console.log("PRs:\n", prs_data);
// console.log("Merged PRs:\n", prs_data_merged);
// filter merged PRs so that only the ones with the label 'gssoc' are left
prs_data_merged.items = prs_data_merged.items.filter(element => {
if(element.labels.map(label => label.name.toLowerCase()).includes('gssoc21') || element.labels.map(label => label.name.toLowerCase()).includes('gssoc-21') || element.labels.map(label => label.name.toLowerCase()).includes(`gssoc'21`) ) {
return true;
} else {
return false;
}
});
// SCORE CALCULATION
let possible_scores = {"level0": 5, "level1": 10, "level2": 25, "level3": 45};
// combine all labels from all merged PRs into an array
let merged_labels = [];
prs_data_merged.items.forEach(element => {
const labels = element.labels;
merged_labels = merged_labels.concat(labels);
});
console.log(merged_labels);
// keep only the scoring labels from possible_labels in the array
const merged_labels_scoring = merged_labels.filter(label => {
if(Object.keys(possible_scores).includes(label.name.replace(/\s/g,'').toLowerCase())) {
return true;
} else {
return false;
}
});
// console.log("MERGED LABELS SCORING\n", merged_labels_scoring);
// convert scoring labels into respective numbers
const scores_array = merged_labels_scoring.map(label => {
return possible_scores[label.name.replace(/\s/g,'').toLowerCase()];
});
// console.log("SCORES ARRAY\n", scores_array);
// add all scores
const total_score = scores_array.reduce((prev, curr) => {
return prev + curr;
}, 0);
// console.log("TOTAL SCORE\n", total_score);
// Do something
let userScoreContainer = document.querySelector('#userScoreContainer');
userScoreContainer.innerHTML = `<div id="userScore"><span id="userScoreTitle">Score</span><span id="userScoreOutput">${total_score}</span></div>`;
let total_prs = document.querySelector('.gs-profile-container-stats .total-prs');
total_prs.innerHTML = prs_data.items.length;
let prsContainer = document.querySelector('#prsContainer');
prsContainer.innerHTML = '';
prs_data.items.forEach(element => {
const id = element.id;
const url = element.html_url;
const title = element.title;
const state = element.state;
const stateCapital = element.state.charAt(0).toUpperCase() + element.state.substring(1);
// const labels = element.labels;
const repo_url = element.repository_url.replace('api.', '').replace('repos/', '');
const repo = repo_url.substring(19);
const date_start = element.created_at;
const date_end = element.closed_at ? element.closed_at : "";
const date_s = new Date(date_start);
const date_e = (date_end != "") ? new Date(date_end) : "";
prsContainer.innerHTML = prsContainer.innerHTML + `
<div class="gs-pr gs-pr-${id} gs-pr-${state}">
<span class="iconify" data-icon="octicon:git-${state=='merged'?'merge':'pull-request'}" data-inline="false"></span>
<div class="gs-pr-infobox">
<div class="gs-pr-text">${stateCapital}: <a class="gs-pr-url" href="${url}" target="_blank"><b>${title}</b></a> in <a href="${repo_url}" target="_blank">${repo}</a></div>
<div class="gs-pr-date"><b>Opened:</b> ${date_s.toDateString() + " " + date_s.toLocaleTimeString()}</div>
<div class="gs-pr-date">${(date_e != "" ? "<b>Closed:</b> " + date_e.toDateString() + " " + date_e.toLocaleTimeString() : "")}</div>
</div>
</div>
`;
});
}
async function loadProjectList() {
projects_list = Object.assign({}, project_list);
projects_list.list = projects_list.list.map(item => item.repo_fullname);
let org_arr = projects_list.list.filter(item => !item.includes('/'));
const fetchOrgPromises = org_arr.map(async org => {
const url = `https://api.github.com/orgs/${org}/repos`;
const response = await fetch(url);
let data = await response.json();
return data;
});
org_arr = await Promise.all(fetchOrgPromises);
org_arr = [].concat(...org_arr);
org_arr = org_arr.map(item => item.full_name);
projects_list.list = projects_list.list.filter(item => item.includes('/'));
projects_list.list = projects_list.list.concat(org_arr);
// console.log("Projects List:\n", projects_list);
}
async function getProjects(github_username) {
// loop through each project in the project list
const fetchProjectPromises = projects_list_filtered.list.map(async project => {
const url = `https://api.github.com/repos/${project}`;
const response = await fetch(url);
let p_data = await response.json();
// fetch contributors of project
// const url_contributors = `https://api.github.com/repos/${project}/contributors?q=per_page=100`;
// const response_contributors = await fetch(url_contributors);
// let c_data = await response_contributors.json();
// p_data.contributors = c_data.slice();
return p_data;
});
projects_data.items = await Promise.all(fetchProjectPromises);
// store only projects that are in the project list
// projects_data.items = projects_data.items.filter((project, index, arr) => {
// for(let i = 0; i < project.contributors.length; i++) {
// if(arr[index].contributors[i].login === github_username) {
// return true;
// }
// }
// return false;
// });
// console.log("Projects:\n", projects_data.items);
// Do something
let total_projects = document.querySelector('.gs-profile-container-stats .total-projects');
total_projects.innerHTML = projects_data.items.length;
let projectsContainer = document.querySelector('#projectsContainer');
projectsContainer.innerHTML = '';
projects_data.items.forEach(element => {
const id = element.id;
const url = element.html_url;
const full_name = element.full_name;
const description = element.description;
const homepage = element.homepage ? element.homepage : '';
const stars_count = element.stargazers_count;
const forks_count = element.forks_count;
const open_issues_count = element.open_issues_count;
const language = element.language;
// const date_start = element.created_at;
// const date_s = new Date(date_start);
projectsContainer.innerHTML = projectsContainer.innerHTML + `
<div class="gs-project gs-project-${id}">
<span class="iconify iconify-main" data-icon="octicon:repo" data-inline="false"></span>
<div class="gs-project-infobox">
<div class="gs-project-text"><a class="gs-project-url" href="${url}" target="_blank"><b>${full_name}</b></a></div>
<div class="gs-project-description">${description ? (description.length <= 165 ? description.substring(0, 165) : description.substring(0, 165) + '...') : ''}</div>
<div class="gs-project-extra">
<div class="gs-project-extra-item gs-project-lang">${language} </div>
<div class="gs-project-extra-item">
${stars_count != "0" ? '<div class="gs-project-extra-stat"><span class="iconify" data-icon="octicon:star" data-inline="false"></span>' + stars_count + '</div>' : ""}
${forks_count != "0" ? '<div class="gs-project-extra-stat"><span class="iconify" data-icon="octicon:repo-forked" data-inline="false"></span>' + forks_count + '</div>' : ""}
</div>
</div>
${homepage != '' ? '<a href="' + homepage + '" target="_blank"><div class="gs-project-link"><span class="iconify" data-icon="octicon:link" data-inline="false"></span></div></a>' : ''}
</div>
</div>
`;
});
}
async function getContributions(github_username, start_date, end_date) {
// get GitHub data
// const url = `https://github-contributions-api.now.sh/v1/${github_username}`;
// const response = await fetch(url);
// contri_data_api = await response.json();
// console.log(contri_data_api);
// // filter by date
// contri_data.contributions = contri_data.contributions.filter(ele => {
// if(ele.date >= start_date && ele.date <= end_date) {
// return true;
// } else {
// return false;
// }
// });
// create initial array of contributions with dates and initial values that will later be filled with data
let start_date_iso = new Date(start_date);
let end_date_iso = new Date(end_date);
let today_date = new Date();
today_date = `${today_date.getFullYear()}-${(today_date.getMonth().toString().length == 1 ? '0' : '') + (today_date.getMonth() + 1)}-${(today_date.getDate().toString().length == 1 ? '0' : '') + today_date.getDate()}`;
for(let d = start_date_iso; d <= end_date_iso; d.setDate(d.getDate() + 1)) {
const new_date = d.toISOString().substring(0, 10);
contri_data.push({
contributions: 0,
intensity: 0,
date: new_date
});
}
// add Commit contributions
commits_data.items.forEach(ele => {
const commit_date = ele.commit.author.date.substring(0, 10);
contri_data = contri_data.map(square => {
if(square.date == commit_date) {
square.contributions++;
return square;
}
return square;
});
});
// add PRs contributions
prs_data.items.forEach(ele => {
const commit_date = ele.created_at.substring(0, 10);
contri_data = contri_data.map(square => {
if(square.date == commit_date) {
square.contributions++;
return square;
}
return square;
});
});
// add Issues contributions
issues_data.items.forEach(ele => {
const commit_date = ele.created_at.substring(0, 10);
contri_data = contri_data.map(square => {
if(square.date == commit_date) {
square.contributions++;
return square;
}
return square;
});
});
// calculate intensity [0-4]
// const max = contri_data.map(ele => ele.contributions).reduce((prev, curr, i, arr) => {
// return (curr > prev) ? curr : prev;
// }, 0);
const total_contri_days = contri_data.map(ele => ele.contributions).reduce((prev, curr, i, arr) => {
return curr < 1 ? prev : prev + 1;
}, 0);
const total_contri = contri_data.map(ele => ele.contributions).reduce((prev, curr, i, arr) => {
return prev + curr;
}, 0);
const avg = total_contri / total_contri_days;
const avg_sq = avg ** 2;
const l0 = 1;
const l1 = (avg_sq / 100) * 30;
const l2 = (avg_sq / 100) * 55;
const l3 = (avg_sq / 100) * 80;
// console.table(max, total_contri_days, total_contri, avg, avg_sq);
// console.table(l0,l1,l2,l3);
contri_data = contri_data.map(square => {
if(square.contributions > l3) {
square.intensity = 4;
}
else if(square.contributions > l2) {
square.intensity = 3;
}
else if(square.contributions > l1) {
square.intensity = 2;
}
else if(square.contributions > l0) {
square.intensity = 1;
}
else {
square.intensity = 0;
}
return square;
});
// console.table(contri_data);
// get intensity and make squares
const squares = document.querySelector('.squares');
contri_data.forEach(ele => {
if(ele.date > today_date) {
return;
}
squares.insertAdjacentHTML('beforeend', `
<li class="square" data-level="${ele.intensity}">
<div class="gs-tooltip-container">
<div class="gs-tooltip">
<span class="gs-tooltip-white-text">${ele.contributions == 0 ? 'No' : ele.contributions} contributions</span><span> on ${(new Date(ele.date)).toDateString().substring(4)}</span>
</div>
</div>
</li>`);
});
// make random squares for display purpose
// for (var i = 0; i < 91; i++) {
// const level = Math.floor(Math.random() * 5);
// squares.insertAdjacentHTML('beforeend', `<li data-level="${level}"></li>`);
// }
}
// initiate data fetching
if(url_params != undefined) {
getUser(url_params.id).catch(() => {
$('#errorFetchUser').html('Error fetching user.');
$('#errorFetchUser').effect("shake");
});
let loadProjectListPromise = new Promise(async (resolve, reject) => {
await loadProjectList().then(() => {
resolve();
}).catch(() => {
reject();
});
});
loadProjectListPromise.then(() => {
let loadFilteredProjectListPromise = new Promise(async (resolve, reject) => {
await getCommits(url_params.id, gssoc_start_date, gssoc_end_date)
.then(() => resolve())
.catch(() => {
$('#commitsContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('.total-commits').html('<span class="fetch_error">Unable to fetch.</span>');
});
reject();
});
loadFilteredProjectListPromise.then(async () => {
await getIssues(url_params.id, gssoc_start_date, gssoc_end_date)
.catch(() => {
$('#issuesContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('.total-issues').html('<span class="fetch_error">Unable to fetch.</span>');
});
// performScoreCalc(url_params.id, gssoc_start_date, gssoc_end_date);
await getPRs(url_params.id, gssoc_start_date, gssoc_end_date)
.catch(() => {
$('#prsContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('.total-prs').html('<span class="fetch_error">Unable to fetch.</span>');
});
getProjects(url_params.id);
// Add GitHub contribution squares
await getContributions(url_params.id, gssoc_start_date, gssoc_end_date);
});
loadFilteredProjectListPromise.catch(() => {
$('#issuesContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('#prsContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('#projectsContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('.total-prs').html('<span class="fetch_error">Unable to fetch.</span>');
$('.total-issues').html('<span class="fetch_error">Unable to fetch.</span>');
$('.total-projects').html('<span class="fetch_error">Unable to fetch.</span>');
});
});
loadProjectListPromise.catch(() => {
$('#issuesContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('#prsContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('#projectsContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('#commitsContainer').html('<span class="fetch_error">Unable to fetch. Wait 1 minute, then try again.</span>');
$('.total-prs').html('<span class="fetch_error">Unable to fetch.</span>');
$('.total-issues').html('<span class="fetch_error">Unable to fetch.</span>');
$('.total-projects').html('<span class="fetch_error">Unable to fetch.</span>');
$('.total-commits').html('<span class="fetch_error">Unable to fetch.</span>');
});
}
// Check if color is Light or Not, used for text color of labels
function isLight(color) {
// Variables for red, green, blue values
var r, g, b, hsp;
// Check the format of the color, HEX or RGB?
if (color.match(/^rgb/)) {
// If HEX --> store the red, green, blue values in separate variables
color = color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);
r = color[1];
g = color[2];
b = color[3];
}
else {
// If RGB --> Convert it to HEX: http://gist.github.com/983661
color = +("0x" + color.slice(1).replace(
color.length < 5 && /./g, '$&$&'));
r = color >> 16;
g = color >> 8 & 255;
b = color & 255;
}
// HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html
hsp = Math.sqrt(
0.299 * (r * r) +
0.587 * (g * g) +
0.114 * (b * b)
);
// Using the HSP value, determine whether the color is light or dark
return (hsp>127.5) ? true : false;
}
// add array method to remove duplicate items from array
Array.prototype.unique = function() {
var a = this.concat();
for(var i=0; i<a.length; ++i) {
for(var j=i+1; j<a.length; ++j) {
if(a[i] === a[j])
a.splice(j--, 1);
}
}
return a;
};
// Only Unique function
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
// update query string in url
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
}
$(document).ready(function(){
if(url_params == undefined) {
$('#profileContainer').css("display", "none");
$('#searchContainer').css("display", "flex");
} else {
$('#searchContainer').css("display", "none");
$('#profileContainer').css("display", "grid");
}
let usernameSearchInput = document.querySelector('#usernameSearchInput');
let usernameSearchButton = document.querySelector('#usernameSearchButton');
let errorText = document.querySelector('#errorText');
let backButton = document.querySelector('#backButton');
let fixedActionBtn = document.querySelector('.fixed-action-btn');
const checkUsername = () => {
let getUserPromise = new Promise(async (resolve, reject) => {
// console.log("Requesting User...");
await getUser(usernameSearchInput.value);
if(user_data.hasOwnProperty('message')) {
reject();
} else {
resolve();
}
})
getUserPromise.then(() => {
window.location = updateQueryStringParameter(window.location.href, "id", usernameSearchInput.value);
}).catch(() => {
errorText.innerHTML = "Username not found.";
});
}
usernameSearchButton.addEventListener('click', () => {
if(usernameSearchInput.value != "") {
checkUsername();
}
})
usernameSearchInput.addEventListener('keypress', (e) => {
if(usernameSearchInput.value != "" && e.key === 'Enter') {
checkUsername();
}
});
backButton.addEventListener('click', () => {
window.location = window.location.href.split("?")[0];
});
fixedActionBtn.addEventListener('click', () => {
window.location = window.location.href.split("?")[0];
});
// Change tabs
$('.gs-selector-items').click(function(){
$(`.selected`).removeClass('selected');
$(this).addClass('selected');
$(`.selected-container`).removeClass('selected').hide();
$(`#${this.id}Container`).addClass('selected-container').show();
$(`.gs-profile-container-activity .gs-container-subtitle`).html(`${$(this).html()}`);
});
// add floating button for mobile users
$('.fixed-action-btn').floatingActionButton();
});