-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgitlab.js
15 lines (13 loc) · 933 Bytes
/
gitlab.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const { gitlab } = require('../config');
const { gitlabPushRequest, gitlabCommentOnCommit, gitlabMergeRequest, gitlabMergeRequestOnCloseAndMerge } = require('../services/gitlab');
const { log } = require('@spaship/common/lib/logging/pino');
module.exports.post = async (req, res) => {
const action = req.header('X-Gitlab-Event');
const payload = req.body;
log.info(action);
if (action === gitlab.PUSH_REQUEST && payload?.event_name === gitlab.STATE_PUSHED) await gitlabPushRequest(payload);
else if (action === gitlab.COMMENT_REQUEST) await gitlabCommentOnCommit(payload);
else if (action === gitlab.MERGE_REQUEST && payload?.object_attributes?.state === gitlab.STATE_OPENED) await gitlabMergeRequest(payload);
else if (payload?.object_attributes?.state === gitlab.STATE_MERGED || payload?.object_attributes?.state === gitlab.STATE_CLOSED) await gitlabMergeRequestOnCloseAndMerge(payload);
res.sendStatus(200);
};