Skip to content

Commit

Permalink
feat(gitlab: events): add issue (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed May 28, 2018
1 parent d1ef292 commit 8bfc74f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions lib/Gitlab/Events/issue.js
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions lib/Web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...`);
Expand All @@ -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))) {
Expand Down

0 comments on commit 8bfc74f

Please sign in to comment.