- commit
- f046171e27cf90024b6634849f42c1ebdea1345f
- parent
- 71a13de1a4f1b72cb08589bbd95040e5777229b7
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2022-07-31 08:22
add SLOC
Diffstat
| M | index.html | 11 | +++++++++++ |
| M | script.js | 38 | +++++++++++++++++++++++++++++--------- |
| M | style.css | 11 | +++++++++++ |
3 files changed, 51 insertions, 9 deletions
diff --git a/index.html b/index.html
@@ -26,6 +26,17 @@ 26 26 <input name="issues" readonly /> 27 27 </label> 28 28 -1 29 <table> -1 30 <tr> -1 31 <th>Language</th> -1 32 <th>Files</th> -1 33 <th>Lines</th> -1 34 <th>Blanks</th> -1 35 <th>Comments</th> -1 36 <th><abbr>SLOC</abbr></th> -1 37 </tr> -1 38 </table> -1 39 29 40 <script src="script.js"></script> 30 41 </body> 31 42 </html>
diff --git a/script.js b/script.js
@@ -1,3 +1,5 @@
-1 1 var table = document.querySelector('table');
-1 2
1 3 var setValue = function(name, value) {
2 4 document.getElementsByName(name)[0].value = value;
3 5 };
@@ -17,20 +19,38 @@ var getAverage = function(data) {
17 19 return duration / data.length;
18 20 };
19 21
-1 22 var addRow = function(row) {
-1 23 var tr = document.createElement('tr');
-1 24 table.append(tr);
-1 25
-1 26 var th = document.createElement('th');
-1 27 th.textContent = row.language;
-1 28 tr.append(th);
-1 29
-1 30 ['files', 'lines', 'blanks', 'comments', 'linesOfCode'].forEach(key => {
-1 31 var td = document.createElement('td');
-1 32 td.textContent = row[key];
-1 33 tr.append(td);
-1 34 });
-1 35 };
-1 36
20 37 var search = new URLSearchParams(location.search);
21 38 var repo = search.get('repo');
22 39 if (repo) {
23 40 setValue('repo', repo);
24 41 setBusy(true);
25 -1 fetch(`https://api.github.com/repos/${repo}/issues?per_page=100&state=closed`)
26 -1 .then(r => r.json())
27 -1 .then(data => {
28 -1 setBusy(false);
-1 42 Promise.all([
-1 43 fetch(`https://api.github.com/repos/${repo}/issues?per_page=100&state=closed`).then(r => r.json()),
-1 44 fetch(`https://api.codetabs.com/v1/loc/?github=${repo}`).then(r => r.json()),
-1 45 ]).then(data => {
-1 46 setBusy(false);
-1 47
-1 48 var pulls = data[0].filter(x => x.pull_request);
-1 49 setValue('pulls', getAverage(pulls))
29 50
30 -1 var pulls = data.filter(x => x.pull_request);
31 -1 setValue('pulls', getAverage(pulls))
-1 51 var issues = data[0].filter(x => !x.pull_request);
-1 52 setValue('issues', getAverage(issues))
32 53
33 -1 var issues = data.filter(x => !x.pull_request);
34 -1 setValue('issues', getAverage(issues))
35 -1 });
-1 54 data[1].forEach(addRow);
-1 55 });
36 56 }
diff --git a/style.css b/style.css
@@ -71,3 +71,14 @@ button:disabled {
71 71 opacity: 0.5;
72 72 cursor: progress;
73 73 }
-1 74
-1 75 table {
-1 76 width: 100%;
-1 77 margin-top: 2em;
-1 78 }
-1 79 td, th {
-1 80 text-align: end;
-1 81 }
-1 82 th:first-child {
-1 83 text-align: start;
-1 84 }