This repository has been archived by the owner on Jan 29, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Rocketchat plugin #53
Merged
+117
−10
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8c7195b
Add rocket-chat-notifier runtime dependency
e53378c
Add Rocket.Chat support to ChatOps plugin
d6c44ac
Add Rocket.Chat documentation
b0066bc
Rubocop fixes
e95cff8
Only load chatops subclasses when needed
e2f28f6
Update formate within notify case statement
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require 'plugins/chatops/slack' | ||
|
||
class PuppetWebhook | ||
# Chatops object for sending webhook notifications to chatops tools | ||
class Chatops | ||
|
@@ -14,13 +12,27 @@ def initialize(service, url, channel, user, options = {}) | |
def notify(message) | ||
case @service | ||
when 'slack' | ||
require 'plugins/chatops/slack' | ||
LOGGER.info("Sending Slack webhook message to #{@url}") | ||
Chatops::Slack.new(@channel, | ||
@url, | ||
@user, | ||
message, | ||
http_options: @args[:http_options] || {}, | ||
icon_emoji: @args[:icon_emoji]).notify | ||
Chatops::Slack.new( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might consider moving the |
||
@channel, | ||
@url, | ||
@user, | ||
message, | ||
http_options: @args[:http_options] || {}, | ||
icon_emoji: @args[:icon_emoji] | ||
).notify | ||
when 'rocketchat' | ||
require 'plugins/chatops/rocketchat' | ||
LOGGER.info("Sending Rocket.Chat webhook message to #{@url}") | ||
Chatops::Rocketchat.new( | ||
@channel, | ||
@url, | ||
@user, | ||
message, | ||
http_options: @args[:http_options] || {}, | ||
icon_emoji: @args[:icon_emoji] | ||
).notify | ||
else | ||
LOGGER.error("Service #{@service} is not currently supported") | ||
end | ||
|
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,60 @@ | ||
require 'rocket-chat-notifier' | ||
|
||
class PuppetWebhook | ||
class Chatops | ||
# Sets up Rocketchat object that will send notifications to Slack via a webhook. | ||
class Rocketchat | ||
def initialize(channel, url, user, message, options = {}) | ||
@channel = channel | ||
@url = url | ||
@user = user | ||
@message = message | ||
@options = options | ||
end | ||
|
||
def notify | ||
notifier = RocketChat::Notifier.new @url, http_options: @options[:http_options] | ||
notifier.username = @user | ||
notifier.channel = @channel | ||
|
||
target = if @message[:branch] | ||
@message[:branch] | ||
elsif @message[:module] | ||
@message[:module] | ||
end | ||
|
||
msg = "r10k deployment of Puppet environment/module #{target} started..." | ||
|
||
attachment = format_attachment(target) | ||
|
||
notifier.ping(msg, icon_emoji: @options[:icon_emoji], attachments: [attachment]) | ||
end | ||
|
||
private | ||
|
||
def format_attachment(target) | ||
attachment = { | ||
author: 'r10k for Puppet', | ||
title: "r10k deployment of Puppet environment #{target}" | ||
} | ||
|
||
case @message[:status_code] | ||
when 200 | ||
attachment.merge!( | ||
color: 'good', | ||
text: "Successfully started deployment of #{target}", | ||
fallback: "Successfully started deployment of #{target}" | ||
) | ||
when 500 | ||
attachment.merge!( | ||
color: 'bad', | ||
text: "Failed to deploy #{target}", | ||
fallback: "Failed to deploy #{target}" | ||
) | ||
end | ||
|
||
attachment | ||
end | ||
end | ||
end | ||
end |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: Will the runtime dependency provide this during installation, or do we need to plan to provide that another way? And if the runtime dep does, should it for an optional component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a runtime dependency, the
rocket-chat-notifier
gem will be installed as a dependency. We could make the gem "optional", but the more you do that, the more work you put on your users to install those "optional" dependencies themselves.Think of
puppetlabs-beaker
dependencies, there are so many dependencies for each supported hypervisor that you either install a ton of deps during gem install or put the entire onus on the user to install what he needs (though he may not know what he needs).I think at this point, we should leave it as a runtime dependency and instead make it optional in the future by providing the ChatOps plugin as a separate gem for puppet_webhook unto itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rnelson0 I should probably add that, right now, the Chatops class doesn't test to see if a dependency exists before loading it, so it expects all dependencies to be there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to understand what the model looks like. Something to keep in mind later if we see dependencies explode.