-
Notifications
You must be signed in to change notification settings - Fork 0
/
php_tests.js
63 lines (50 loc) · 1.79 KB
/
php_tests.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
'use strict';
let github = require('octonode');
let fetch = require('node-fetch');
let base64 = require('base-64');
module.exports.handler = (event, context, callback) => {
let body = JSON.parse(event.body);
if (!body || !body.hasOwnProperty('pull_request')) {
const response = {
statusCode: 400
};
callback(null, response);
return;
}
if (!body.pull_request.head.ref.includes('feature')) {
const response = {
statusCode: 204
};
callback(null, response);
return;
}
let headers = new fetch.Headers();
headers.append('Accept', 'application/vnd.github.diff');
headers.append('Authorization', 'Basic ' + base64.encode(":" + process.env['GITHUB_TOKEN']));
let promise = fetch('https://api.github.com/repos/' + body.repository.full_name + '/commits/' + body.pull_request.merge_commit_sha, {
method: 'GET',
headers: headers,
});
console.log(event.body);
promise
.then(response => response.text())
.then(patch => {
console.log(patch);
let payload = {
state: 'success',
description: 'yay tests!',
context: 'qa/php-tests'
};
if (!patch.includes('assert')) {
payload.state = 'failure';
payload.description = 'no test assertions found';
}
let client = github.client(process.env['GITHUB_TOKEN']);
client.post('/repos/' + body.repository.full_name + '/statuses/' + body.pull_request.head.sha, payload, function (err, status, body, headers) {
const response = {
statusCode: 200,
};
callback(null, response);
});
});
};