Skip to content

Commit cdd0754

Browse files
committed
Address comments
1 parent dd86b5d commit cdd0754

File tree

8 files changed

+89
-175
lines changed

8 files changed

+89
-175
lines changed

functions/data_image.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const bucket = gcs.bucket(firebaseFunctions.config().firebase.storageBucket);
99

1010
/**
1111
* Convert data to images. Image data posted to database will be saved as png files
12-
* and upload to screenshot/$prNumber/dataType/$filename
12+
* and uploaded to screenshot/$prNumber/dataType/$filename
1313
*/
1414
export function convertTestImageDataToFiles(event: any) {
1515
// Only edit data when it is first created. Exit when the data is deleted.
@@ -22,7 +22,7 @@ export function convertTestImageDataToFiles(event: any) {
2222
let data = event.data.val();
2323
let saveFilename = `${event.params.filename}.screenshot.png`;
2424

25-
if (dataType != 'diff' && dataType != 'test') {
25+
if (dataType !== 'diff' && dataType !== 'test') {
2626
return;
2727
}
2828

functions/github.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ export function updateGithubStatus(event: firebaseFunctions.Event<any>) {
2222
let prNumber = event.params.prNumber;
2323
return event.data.ref.parent.child('sha').once('value').then((sha: firebaseAdmin.database.DataSnapshot) => {
2424
return setGithubStatus(sha.val(),
25-
result,
26-
toolName,
27-
`${toolName} ${result ? 'passed' : 'failed'}`,
28-
`http://${authDomain}/${prNumber}`,
25+
{
26+
result: result,
27+
name: toolName,
28+
description: `${toolName} ${result ? 'passed' : 'failed'}`,
29+
url: `http://${authDomain}/${prNumber}`
30+
},
2931
repoSlug,
3032
token);
3133
});

functions/index.js

Lines changed: 57 additions & 141 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"firebase-admin": "^4.1.3",
77
"firebase-functions": "^0.5.2",
88
"jsonwebtoken": "^7.3.0",
9-
"request": "^2.81.0",
10-
"typescript": "^2.2.1"
9+
"request": "^2.81.0"
1110
}
1211
}

functions/test_goldens.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ const bucket = gcs.bucket(firebaseFunctions.config().firebase.storageBucket);
1515
export function copyTestImagesToGoldens(prNumber: string) {
1616
return firebaseAdmin.database().ref(`screenshot/reports/${prNumber}/results`).once('value')
1717
.then((snapshot: firebaseAdmin.database.DataSnapshot) => {
18-
let keys: string[] = [];
18+
let failedFilenames: string[] = [];
1919
let counter = 0;
2020
snapshot.forEach((childSnapshot: firebaseAdmin.database.DataSnapshot) => {
21-
if (childSnapshot.val() == false) {
22-
keys.push(childSnapshot.key);
21+
if (childSnapshot.val() === false) {
22+
failedFilenames.push(childSnapshot.key);
2323
}
24-
counter ++;
24+
counter++;
2525
if (counter == snapshot.numChildren()) return true;
2626
});
27-
return keys;
28-
}).then((keys: string[]) => {
27+
return failedFilenames;
28+
}).then((failedFilenames: string[]) => {
2929
return bucket.getFiles({prefix: `screenshots/${prNumber}/test`}).then(function (data: any) {
3030
return Promise.all(data[0]
31-
.filter((file: any) => keys.includes(path.basename(file.name, '.screenshot.png')))
31+
.filter((file: any) => failedFilenames.includes(path.basename(file.name, '.screenshot.png')))
3232
.map((file: any) => file.copy(`goldens/${path.basename(file.name)}`)));
3333
});
3434
})

functions/tsconfig.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
]
1919
},
2020
"files": [
21-
"data.ts",
22-
"data_image.ts",
23-
"github.ts",
24-
"image_data.ts",
25-
"index.ts",
26-
"jwt_util.ts",
27-
"test_goldens.ts",
28-
"util/github.ts",
29-
"util/jwt.ts"
21+
"index.ts"
3022
]
3123
}

functions/util/github.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
const request = require('request');
22

3+
/** Data that must be specified to set a Github PR status. */
4+
export type GithubStatusData = {
5+
result: boolean;
6+
name: string;
7+
description: string;
8+
url: string;
9+
};
10+
311
/** Function that sets a Github commit status */
412
export function setGithubStatus(commitSHA: string,
5-
result: boolean,
6-
name: string,
7-
description: string,
8-
url: string,
13+
statusData: GithubStatusData,
914
repoSlug: string,
1015
token: string) {
11-
let state = result ? 'success' : 'failure';
16+
let state = statusData.result ? 'success' : 'failure';
1217

1318
let data = JSON.stringify({
1419
state: state,
15-
target_url: url,
16-
context: name,
17-
description: description
20+
target_url: statusData.url,
21+
context: statusData.name,
22+
description: statusData.description
1823
});
1924

2025
let headers = {
2126
"Authorization": `token ${token}`,
22-
"User-Agent": `${name}/1.0`,
27+
"User-Agent": `${statusData.name}/1.0`,
2328
"Content-Type": "application/json"
2429
};
2530

tools/gulp/tasks/screenshots.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ task('screenshots', () => {
4646

4747
function updateFileResult(database: firebase.database.Database, prNumber: string,
4848
filenameKey: string, result: boolean) {
49-
return getPullRequestRef(database, prNumber).child('results').child(filenameKey).set(result) ;
49+
return getPullRequestRef(database, prNumber).child('results').child(filenameKey).set(result);
5050
}
5151

5252
function updateResult(database: firebase.database.Database, prNumber: string, result: boolean) {

0 commit comments

Comments
 (0)