Skip to content
This repository was archived by the owner on May 2, 2021. It is now read-only.

Commit f1ee4d1

Browse files
committed
updated log
1 parent 612b2e1 commit f1ee4d1

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

netlify_functions/deploy-succeeded/deploy-succeeded.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ const axios = require('axios');
22

33
const { ONE_SIGNAL_API_KEY, ONE_SIGNAL_APP_ID } = process.env;
44

5-
exports.handler = async function ({ body = '{}' }) {
6-
const { payload = {} } = JSON.parse(body);
7-
8-
const ret = {
5+
function response(body = '') {
6+
return {
97
statusCode: 200,
8+
body,
109
};
10+
}
11+
12+
exports.handler = async function ({ body = '{}' }) {
13+
const { payload = {} } = JSON.parse(body);
1114

1215
if (payload.branch !== 'master') {
13-
return ret;
16+
return response('Nothing to do. Branch' + payload.branch);
1417
}
1518

1619
const { data } = await axios.get(
@@ -21,7 +24,7 @@ exports.handler = async function ({ body = '{}' }) {
2124
data.commit.message.match(/fevrcoding\/cms\/event\/(.+?)\n/) || [];
2225

2326
if (!eventPath) {
24-
return ret;
27+
return response(data.commit.message);
2528
}
2629

2730
const eventFile = data.files.find(
@@ -30,7 +33,7 @@ exports.handler = async function ({ body = '{}' }) {
3033
);
3134

3235
if (!eventFile) {
33-
return ret;
36+
return response(data.files.map(({ filename }) => filename));
3437
}
3538

3639
const { data: eventTxt } = await axios.get(eventFile.raw_url, {
@@ -40,7 +43,7 @@ exports.handler = async function ({ body = '{}' }) {
4043
const [, eventTitle] = eventTxt.match(/title:(.+?)\n/) || [];
4144

4245
if (!eventTitle) {
43-
return ret;
46+
return response(eventTxt);
4447
}
4548

4649
axios.post(
@@ -60,5 +63,5 @@ exports.handler = async function ({ body = '{}' }) {
6063
headers: { Authorization: `Basic ${ONE_SIGNAL_API_KEY}` },
6164
},
6265
);
63-
return ret;
66+
return response();
6467
};

0 commit comments

Comments
 (0)