-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpr_title.js
48 lines (38 loc) · 1.21 KB
/
pr_title.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
'use strict';
let github = require('octonode');
let client = github.client(process.env['GITHUB_TOKEN']);
module.exports.handler = (event, context, callback) => {
let body = JSON.parse(event.body);
console.log(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 payload = {
state: 'success',
description: 'PR title according to format',
context: 'qa/pr-title'
};
if (!/^[A-Z0-9]+\-[0-9]+\: .+/.test(body.pull_request.title)) {
payload.state = 'failure';
payload.description = 'PR title should start with a ticket number';
}
client.post('/repos/' + body.repository.full_name + '/statuses/' + body.pull_request.head.sha, payload, function (err, status, body, headers) {
console.log(err);
console.log(body);
const response = {
statusCode: 200,
};
callback(null, response);
});
};