-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·40 lines (38 loc) · 1.16 KB
/
index.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
exports.handler = event => {
const request = require('request');
const githubEvent = JSON.parse(event.Records[0].Sns.Message);
const gitFork = githubEvent.repository.owner.name;
const refSplit = githubEvent.ref.split("/");
const refScope = refSplit[1];
const gitRef = refSplit[2];
const templateURL = process.env.TEMPLATE_URL;
const awxToken = process.env.AWX_TOKEN;
console.log('Received GitHub event for: '+githubEvent);
if (refScope === 'tags' || gitRef === 'develop') {
const postData = {
"extra_vars": {
target_user: gitFork,
target_ref: gitRef
}
};
const clientServerOptions = {
uri: templateURL,
auth: {
'bearer': awxToken
},
body: JSON.stringify(postData),
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};
request(clientServerOptions, (error, response) => {
console.log(error, response.body);
return;
});
}
else {
// Not a new tag push
return;
};
};