diff --git a/lib/Gitlab/Events/issue.js b/lib/Gitlab/Events/issue.js new file mode 100644 index 0000000..7a29520 --- /dev/null +++ b/lib/Gitlab/Events/issue.js @@ -0,0 +1,48 @@ +const EventResponse = require('../EventResponse'); + +class Issue extends EventResponse { + constructor(...args) { + super(...args, { + description: 'This event gets fired when a test issue event is executed', + }); + } + + embed(data) { + const issue = data.object_attributes; + + return { + color: 0xFFFc00, + title: `Issue #${issue.iid}: ${issue.title}`, + description: 'A test issue event was fired from the GitLab integrations page', + fields: [{ + name: 'Description', + value: `${issue.description.split('\n').slice(0, 4).join('\n').slice(0, 2000)}\n\u200B`, + }, { + name: 'State', + value: issue.state[0].toUpperCase() + issue.state.slice(1), + inline: true, + }, { + name: 'Created At', + value: new Date(issue.created_at).toGMTString(), + inline: true, + }, { + name: 'Labels', + value: data.labels && data.labels.length ? data.labels.map(l => `\`${l.title}\``).join(', ') : 'None', + }], + }; + } + + text(data) { + const { + user: actor, + object_attributes: issue, + } = data; + + return [ + `🤦‍♂️ **${actor.name}** tested an issue event, and issue **#${issue.iid}** was sent.`, + `<${issue.url}>`, + ].join('\n'); + } +} + +module.exports = Issue; diff --git a/lib/Web.js b/lib/Web.js index 0507dae..054b80a 100644 --- a/lib/Web.js +++ b/lib/Web.js @@ -47,7 +47,7 @@ app.post('/', (req, res) => { const repo = data.project.path_with_namespace; const channels = ChannelConfig.findByRepo(repo); - const action = data.object_attributes && (data.object_attributes.action || data.object_attributes.state); + const action = data.object_attributes && data.object_attributes.action; const actionText = action ? `/${action}` : ''; Log.verbose(`GitLab | ${repo} - ${eventName}${actionText} (${channels.size} channels)`); res.send(`${data.project.path_with_namespace} : Received ${eventName}${actionText}, emitting to ${channels.size} channels...`); @@ -57,7 +57,7 @@ app.post('/', (req, res) => { if (!eventResponse.embed && !eventResponse.text) return Log.warn(`GitLab | ${repo} - ${eventName}${actionText} ignored`); const handleError = (resp, channel) => { - const err = resp && resp.body; + const err = resp && resp.body || resp; const errors = ['Forbidden', 'Missing Access']; if (!res || !err) return; if (errors.includes(err.message) || (err.error && errors.includes(err.error.message))) {