Skip to content

Commit

Permalink
Merge pull request #1290 from operable/peck/cog-info
Browse files Browse the repository at this point in the history
cog info command
  • Loading branch information
Kevin Smith authored Jan 8, 2017
2 parents 62ca9ef + 9d6fc69 commit 50aa078
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/cog/commands/info.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule Cog.Commands.Info do
use Cog.Command.GenCommand.Base,
bundle: Cog.Util.Misc.embedded_bundle

@description "Display information about the current running instance of Cog."

@output_example """
[
{
"embedded_bundle_version": "0.18.0",
"elixir_version": "1.3.4",
"cog_version": "0.18.0",
"bundle_config_version": 5
}
]
"""

rule "when command is #{Cog.Util.Misc.embedded_bundle}:info allow"

def handle_message(req, state) do
info = %{
cog_version: Keyword.get(Mix.Project.config(), :version),
elixir_version: System.build_info().version,
embedded_bundle_version: Application.fetch_env!(:cog, :embedded_bundle_version),
bundle_config_version: Spanner.Config.current_config_version()
}

{:reply, req.reply_to, "info", info, state}
end
end
9 changes: 9 additions & 0 deletions priv/templates/embedded/info.greenbar
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
~each var=$results as=info~
**Cog System Information**
~attachment color="blue"~
**Cog Version:** ~$info.cog_version~
**Embedded Bundle Version:** ~$info.embedded_bundle_version~
**Bundle Config Version:** ~$info.bundle_config_version~
**Elixir Version:** ~$info.elixir_version~
~end~
~end~
21 changes: 21 additions & 0 deletions test/cog/chat/hipchat/templates/embedded/info_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Cog.Chat.HipChat.Templates.Embedded.InfoTest do
use Cog.TemplateCase

test "info template" do
data = %{"results" => [%{"embedded_bundle_version" => "0.18.0",
"elixir_version" => "1.3.4",
"cog_version" => "0.18.0",
"bundle_config_version" => 5}]}

expected = """
<strong>Cog System Information</strong><br/>\
<br/>\
<strong>Cog Version:</strong> 0.18.0<br/>\
<strong>Embedded Bundle Version:</strong> 0.18.0<br/>\
<strong>Bundle Config Version:</strong> 5<br/>\
<strong>Elixir Version:</strong> 1.3.4
""" |> String.strip

assert_rendered_template(:hipchat, :embedded, "info", data, expected)
end
end
23 changes: 23 additions & 0 deletions test/cog/chat/slack/templates/embedded/info_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule Cog.Chat.Slack.Templates.Embedded.InfoTest do
use Cog.TemplateCase

test "info template" do
data = %{"results" => [%{"embedded_bundle_version" => "0.18.0",
"elixir_version" => "1.3.4",
"cog_version" => "0.18.0",
"bundle_config_version" => 5}]}

expected = """
*Cog System Information*
""" |> String.strip

attachment = ["""
*Cog Version:* 0.18.0
*Embedded Bundle Version:* 0.18.0
*Bundle Config Version:* 5
*Elixir Version:* 1.3.4
"""] |> Enum.map(&String.strip/1)

assert_rendered_template(:slack, :embedded, "info", data, {expected, attachment})
end
end

0 comments on commit 50aa078

Please sign in to comment.