-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-test-event.js
72 lines (67 loc) · 1.78 KB
/
create-test-event.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
64
65
66
67
68
69
70
71
72
'use strict';
const crypto = require('crypto');
const AWS = require('aws-sdk');
AWS.config.apiVersions = {
ssm: '2014-11-06'
};
AWS.config.region = process.env.REGION || 'eu-west-1';
function getSecret() {
return new Promise((resolve, reject) => {
const ssm = new AWS.SSM();
const params = {
Names: ['GitHubWebhookSecret'],
WithDecryption: true
};
ssm.getParameters(params, (err, data) => {
if (err) return reject(err);
if (!data.Parameters.length) {
return reject(new Error('"GitHubWebhookSecret" not found'));
}
return resolve(data.Parameters[0].Value);
});
});
}
const testData = {
'action': 'published',
'release': {
'tag_name': '2.1.7',
'target_commitish': 'master',
'name': 'test',
'draft': false,
'author': {
'login': 'CompareTheMarket',
},
'prerelease': false,
'assets': [
{
'name': 'cloudkat-linux',
'browser_download_url': 'https://github.com/CompareTheMarket/cloudkat/releases/download/2.1.7/cloudkat-linux'
}
],
'tarball_url': 'https://api.github.com/repos/CompareTheMarket/cloudkat/tarball/2.1.7',
'zipball_url': 'https://api.github.com/repos/CompareTheMarket/cloudkat/zipball/2.1.7',
},
'repository': {
'id': 83574183,
'name': 'cloudkat',
'full_name': 'CompareTheMarket/cloudkat',
'private': true,
'default_branch': 'master'
}
};
getSecret()
.then(secret => {
const hmac = crypto.createHmac('sha1', secret);
const body = JSON.stringify(testData);
hmac.update(body);
const event = {
headers: {
'X-Hub-Signature': `sha1=${hmac.digest('hex')}`
},
body: JSON.stringify(testData)
};
console.log(JSON.stringify(event, null, 2));
})
.catch(err => {
console.log(err);
});