-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.js
More file actions
128 lines (111 loc) · 3.02 KB
/
demo.js
File metadata and controls
128 lines (111 loc) · 3.02 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
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
const express = require('express');
const http = require('http');
const {
pullRequests: { getData, normalise, summariseContributions },
org: { getOrgMembers },
} = require('./');
const membersLog = require('./__mocks__/membersLog');
const app = express();
const org = 'yldio';
// const contributionsPromise = async () => {
// const members = await getOrgMembers(membersLog);
// const contributions = await getContributionStats({
// org,
// token: process.env.GITHUB_TOKEN,
// members,
// });
// console.log('contributions: ', contributions);
// return contributions;
// }
// return contributionsPromise();
const summaryPromise = getOrgMembers(membersLog)
.then((members) => getData({ org, token: process.env.GITHUB_TOKEN, members }))
.then(normalise)
.then(summariseContributions)
.catch(console.log);
app.get('/', async (req, res) => {
res.status(200);
res.write(`
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Open Source Stats</title>
<style>
body {
font-family: -apple-system;
margin: 40px;
}
* {
box-sizing: border-box;
}
.big {
font-size: 35px;
margin-bottom: 30px;
max-width: 400px;
}
.repo-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.repo {
border: 1px solid black;
width: 250px;
height: 250px;
padding: 20px;
font-size: 20px;
margin: 5px;
overflow: hidden;
}
.repo > div {
margin-bottom: 10px;
}
.repo-name {
font-weight: 500;
}
.topics {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.topic {
padding: 5px;
border: 1px solid rgba(0,0,0,0.5);
margin-right: 5px;
margin-bottom: 5px;
}
</style>
</head>
<body>
`);
const summary = await summaryPromise;
res.write(
`<div class="big"><b>${org}</b> has made<br /><b>${summary.contributionsCount}</b> contributions<br /> to <b>${summary.repoCount}</b> open source projects.</div>`,
);
res.write(`<div class="big">Top projects:</div>`);
res.write(`
<div class="repo-container">
${summary.repos
.map(
(repo) => `<div class="repo">
<div class="repo-name">${repo.nameWithOwner}</div>
<div>${repo.starCount} stars</div>
<div>${repo.pullRequestCount} contributions</div>
<div class="topics">${repo.topics
.map((t) => `<div class="topic">${t}</div>`)
.slice(0, 5)
.join('')}</div>
</div>`,
)
.join('')}
</div>
`);
res.write(`</body></html>`);
res.end();
});
const server = http.createServer(app);
const port = process.env.PORT || 3000;
server.listen(port, function () {
console.log('Express server running on *:' + port);
});