Skip to content

Commit

Permalink
feat(gitlab: events): add pipeline (#21)
Browse files Browse the repository at this point in the history
Adds pipelines events, thanks to @Formic.
Removes `pipeline` from default ignored events in the channel configuration.

Ref #21
  • Loading branch information
Formic authored and David Sevilla Martín committed Dec 16, 2017
1 parent 96a9db8 commit 7e8a790
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
42 changes: 42 additions & 0 deletions lib/Gitlab/Events/pipeline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const EventResponse = require('../EventResponse');

class Pipeline extends EventResponse {
constructor(...args) {
super(...args, {
description: `This event is fired when a pipeline job finishes.`,
});
}
embed(data) {
if (data.object_attributes.status !== 'success' && data.object_attributes.status !== 'failed') return;

const branch = data.project.default_branch;
const id = data.object_attributes.id;
const result = data.object_attributes.status === 'success' ? 'passed' : 'failed';
const color = result === 'passed' ? 'success' : 'error';
const duration = data.object_attributes.duration;

const url = `${data.project.web_url}/pipelines/${id}`;
const description = `Pipeline [\`#${id}\`](${url}) of \`${branch}\` branch **${result}** in ${duration} seconds.`;

return {
color,
description,
};
}
text(data) {
if (data.object_attributes.status !== 'success' && data.object_attributes.status !== 'failed') return;

const actor = data.user.username;
const branch = data.project.default_branch;
const id = data.object_attributes.id;
const result = data.object_attributes.status === 'success' ? 'passed' : 'failed';
const icon = result === 'passed' ? ':white_check_mark:' : ':no_entry:';
const duration = data.object_attributes.duration;

const msg = `Pipeline \`#${id}\` of \`${branch}\` branch created by *${actor}* **${result}** in ${duration} seconds. ${icon}\n` +
`<${data.project.web_url}/pipelines/${id}>`;
return msg;
}
}

module.exports = Pipeline;
3 changes: 1 addition & 2 deletions lib/Models/ChannelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const channelConfigSchema = Schema({
disabledEvents: {
type: Array,
default: [
'merge_request/update',
'pipeline',
'merge_request/update'
],
},
ignoredUsers: Array,
Expand Down

0 comments on commit 7e8a790

Please sign in to comment.