109 |
112 |
113 |
114 |
115 |
116 | Elapsed time since deploy:
117 |
118 |
119 |
122 |
123 |
124 |
125 | ${pathsWithStatusColour}
126 |
127 |
128 |
129 | `;
130 |
131 | const response = {
132 | statusCode: 200,
133 | headers: {
134 | 'Content-Type': 'text/html',
135 | },
136 | body: html,
137 | };
138 |
139 | resolve(response);
140 | });
141 | }
142 |
143 | function msToTime(s) {
144 | var ms = s % 1000;
145 | s = (s - ms) / 1000;
146 | var secs = s % 60;
147 | s = (s - secs) / 60;
148 | var mins = s % 60;
149 | var hrs = (s - mins) / 60;
150 |
151 | return hrs + ':' + mins + ':' + secs;
152 | }
153 |
154 | exports.handler = (event, context, callback) => {
155 | const sha = event.pathParameters.sha;
156 |
157 | getBoard(sha)
158 | .then(data => renderBoard(data))
159 | .then(boardAsHtml => callback(null, boardAsHtml));
160 | };
161 |
--------------------------------------------------------------------------------
/cloud/tip-get-head-board.js:
--------------------------------------------------------------------------------
1 | const AWS = require('aws-sdk');
2 | AWS.config.update({region: 'eu-west-1'});
3 | const ddb = new AWS.DynamoDB.DocumentClient();
4 |
5 | const getBoard = (repo) => {
6 | return ddb.scan(
7 | {
8 | TableName: 'TipCloud-PROD',
9 | FilterExpression : 'repo = :repo',
10 | ExpressionAttributeValues : {':repo' : `${repo}`}
11 | }
12 | ).promise();
13 | }
14 |
15 | const getLatestBoard = (boards) =>
16 | boards
17 | .Items
18 | .sort((a,b) => new Date(b.deployTime) - new Date(a.deployTime))[0];
19 |
20 | const buildLinkToCommit = (repo, sha) => {
21 | if (repo == sha)
22 | return `https://github.com/${repo}/commit/master`;
23 | else
24 | return `https://github.com/${repo}/commit/${sha}`;
25 | }
26 |
27 | const buildLinkToCommitHeader = (repo, sha) => {
28 | if (repo == sha)
29 | return `${repo}`;
30 | else
31 | return `${repo} ${sha}`;
32 | }
33 |
34 | const renderBoard = (item) => {
35 | return new Promise((resolve, reject) => {
36 | const pathsWithStatusColour =
37 | item.board
38 | .map(path => {
39 | let colour;
40 | if (path.verified)
41 | colour = `style="background-color:green"`;
42 | else
43 | colour = `style="background-color:grey"`;
44 |
45 | return `