Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the plugins command to Jarvis #76

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@
guard :rspec, :cmd => "rspec" do
watch(%r{^(lib|spec)/.*\.rb$})
end

guard :process, :name => "lita", :command => ['bundle', 'exec', 'lita'] do
watch(%r{^lib/.*\.rb$})
end
21 changes: 21 additions & 0 deletions lib/jarvis/commands/plugins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "clamp"
require "jarvis/cla"
require "jarvis/patches/i18n"
require "jarvis/github/review_search"
require "jarvis/travis/watchdog"

module Jarvis module Command class Plugins < Clamp::Command
banner "Get travis status for the default plugins"

def execute
total_failures, total_plugins, failures = ::Jarvis::Travis::Watchdog.execute

if total_failures == 0
puts "Good job, all default plugins are green! :green_heart:"
else
messages = [ "Oops, We have currently have *#{total_failures}* plugins jobs failing :sadbazpanda: (#{total_plugins} plugins checked)" ]
messages.concat(::Jarvis::Travis::Watchdog.format_items(failures))
messages.each { |message| puts message }
end
end
end end end
76 changes: 76 additions & 0 deletions lib/jarvis/travis/watchdog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require "open-uri"
require "travis"
require "yaml"

module Jarvis module Travis
class Watchdog
DEFAULT_PLUGINS_URL = "https://raw.githubusercontent.com/elastic/logstash/master/rakelib/plugins-metadata.json"
PLUGINS_CONFIG_FILE = File.join(File.dirname(__FILE__), "../../../plugins_config.yml")
PLUGINS_CONFIG = YAML.load(File.read(PLUGINS_CONFIG_FILE))
DEFAULT_BRANCHES = ["master"]

def initialize
end

def default_plugins
@default_plugins ||= fetch(DEFAULT_PLUGINS_URL).select { |_, v| v["default-plugins"] }.keys
end

def get_status
status = {}

default_plugins.each do |plugin_name|
location = "logstash-plugins/#{plugin_name}"
repo = ::Travis::Repository.find(location)
branches = branch_to_monitor(plugin_name)
status[plugin_name] = branches.each_with_object({}) { |branch, hsh| hsh[branch] = repo.branches[branch].passed? }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you use passed? at the build level it will ignore jobs marked as allowed to fails (like for the feature/9000), But you can check status per job.

end

status
end

def extract_failures(plugins_status)
failures = {}

plugins_status.each do |plugin_name, status|
status.each do |branch, state|
if !state
failures[branch] ||= []
failures[branch] << plugin_name
end
end
end

total_failures = failures.values.collect(&:size).reduce(&:+)
[total_failures, plugins_status.size, failures]
end

def execute
plugins_status = get_status
extract_failures(plugins_status)
end

def branch_to_monitor(plugin_name)
DEFAULT_BRANCHES.dup.concat(Array(PLUGINS_CONFIG["plugin_name"])).uniq
end

def fetch(url)
MultiJson.load(open(url) { |f| f.read })
end

def self.execute
self.new.execute
end

def self.format_items(failures)
messages = []

failures.each do |branch, plugins|
messages << "Failures for branch: *#{branch}*"
messages << plugins.sort.join(", ")
end

messages
end
end
end end
33 changes: 28 additions & 5 deletions lib/lita/handlers/jarvis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
require "jarvis/commands/cla"
require "jarvis/commands/publish"
require "jarvis/commands/teamtime"
require "jarvis/commands/plugins"
require "jarvis/mixins/fancy_route"
require "jarvis/thread_logger"
require "jarvis/commands/review"
require 'jarvis/github/review_search'
require "jarvis/github/review_search"
require "travis"

module Lita
module Handlers
class Jarvis < Handler
extend ::Jarvis::Mixins::FancyRoute

config :cla_url
config :github_token
config :organization
Expand All @@ -24,25 +27,44 @@ class Jarvis < Handler
::Jarvis::Github.client(config.github_token)
::Jarvis::ThreadLogger.setup

# Use github token to get a travis token
Travis.github_auth(config.github_token)

every(60*60) { review_search(robot) }
every(6*60*60) { travis,watchdog(robot) }
end

def travis_watchdog(robot)
total_failures, total_pl_gins, failures = ::Jarvis::Travis::Watchdog.execute
return if total_failures == 0

messages = [ "Oops, We have currently have *#{total_failures}* plugins jobs failing :sadbazpanda: (#{total_plugins} plugins checked)" ]
messages.concat(::Jarvis::Travis::Watchdog.format_items(failures))

send_messages(room_target, messages)
end

def room_target
@target_room ||= Lita::Room.find_by_name("logstash")
@target ||= Lita::Source.new(room: @target_room)
end

def review_search(robot)
total, items = ::Jarvis::Github::ReviewSearch.execute
return if total == 0

@target_room ||= Lita::Room.find_by_name("logstash")
@target ||= Lita::Source.new(room: @target_room)

messages = []
messages << "There are #{total} items needing PR review. Consider reviewing one of these please :)"
messages.concat ::Jarvis::Github::ReviewSearch.format_items(items)
send_messages(room_target, messages)
end

def send_messages(target, messages)
messages.each do |message|
robot.send_messages(@target, message)
# Weirdly, slack displays messages out of order unless you do this. They must have a race
# this only happens sometimes
sleep 0.1
sleep 0.1
end
end

Expand All @@ -64,6 +86,7 @@ def review_search(robot)
# and 'review PR_URL' to submit a PR
fancy_route("reviews", ::Jarvis::Command::Review, :command => true)
fancy_route("review", ::Jarvis::Command::Review, :command => true)
fancy_route("plugins", ::Jarvis::Command::Plugins, :command => true)

Lita.register_handler(self)
end
Expand Down
2 changes: 2 additions & 0 deletions lita-jarvis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "rfc2047"
spec.add_runtime_dependency "gems"
spec.add_runtime_dependency "tzinfo"
spec.add_runtime_dependency "travis"

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "pry-byebug"
Expand All @@ -41,4 +42,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "guard"
spec.add_development_dependency "guard-rspec"
spec.add_development_dependency "guard-bundler"
spec.add_development_dependency "guard-process"
end
2 changes: 2 additions & 0 deletions plugins_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
logstash-output-elasticsearch:
- "6.x"