Skip to content

Commit

Permalink
fix(gitlab): Fix erroring on log for jobs event
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaaz committed Feb 15, 2020
1 parent c810fc3 commit 5b14b13
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/routes/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { Parser } = require('../services/Parser');
const gitlab = async(req, res) => {
if (!req.headers['x-gitlab-event']
|| (config.auth && !req.headers['x-gitlab-token'])
|| req.headers['x-gitlab-token'] !== config.authorizationGitlab) {
|| (config.auth && req.headers['x-gitlab-token'] !== config.authorizationGitlab)) {
Logger.warn('Unauthorized connection: Refused!');
res.status(403).send('Unauthorized!');

Expand All @@ -26,15 +26,20 @@ const gitlab = async(req, res) => {
return;
}

Logger.notice(`Gitlab: ${req.body.project.path_with_namespace} - ${req.body.project.http_url}`); // TO CHANGE
Logger.notice(`Gitlab: ${req.body.project ? `${req.body.project.path_with_namespace} - ${req.body.project.http_url}` : ''} `); // TO CHANGE
res.send('Success!');
Logger.info('Forwarding gitlab request');

const embeds = Parser.parse(req.body);
// Close guard: doesn't send webhook if no embeds have been constructed
if (embeds.length === 0) {
return;
}
// Creating body formatted for discord
const body = {
username: 'GitLab',
avatar_url: `https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo.png`,
embeds: Parser.parse(req.body), // parsing a discord formatted array of embeds with req datas
embeds, // parsing a discord formatted array of embeds with req datas
};

const headers = { 'Content-Type': 'application/json' };
Expand Down

0 comments on commit 5b14b13

Please sign in to comment.