-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gitlab: events): add pipeline (#21)
Adds pipelines events, thanks to @Formic. Removes `pipeline` from default ignored events in the channel configuration. Ref #21
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters