-
Notifications
You must be signed in to change notification settings - Fork 71
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
Bundle install via registry #988
Conversation
%HTTPotion.Response{status_code: 200, body: body} -> | ||
{:ok, Poison.decode!(body)} | ||
%HTTPotion.Response{status_code: 404} -> | ||
{:error, "Bundle not found"} |
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.
We should probably have a catch-all case for other errors, too (e.g., registry is unavailable, registry crashes, etc.) just so we don't crash Cog.
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.
Good point.
@@ -19,14 +19,10 @@ defmodule Cog.Commands.Bundle do | |||
"info <bundle>" => "Detailed information on an installed bundle", | |||
"enable <bundle> [<version>]" => "Enable a specific version of an installed bundle", | |||
"disable <bundle>" => "Disable an installed bundle", | |||
"versions <bundle>" => "List all installed versions for a given bundle" | |||
"versions <bundle>" => "List all installed versions for a given bundle", | |||
"install <bundle>[:<version>]" => "Install latest or specified version of bundle from registry" |
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.
I thought we went with version being an optional standalone argument, instead of tacked on with a colon?
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.
Oops. Updated the usage but missed this. Thanks.
Installation and uninstallation of bundles cannot currently be done via | ||
chat; please use `cogctl` for this functionality. | ||
""" | ||
|
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.
Yay! 🎊
|
||
expected = """ | ||
Bundle "heroku" version "0.0.4" installed. | ||
""" |> String.strip |
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.
For short-and-sweet templates like this, a single line is fine, instead of the whole triple-quote-and-strip dance.
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.
Ah yeah just some rushed copy-pasta. Fixing.
@@ -61,4 +61,8 @@ defmodule Integration.Commands.BundleTest do | |||
assert_error_message_contains(response, "Unknown subcommand 'not-a-subcommand'") | |||
end | |||
|
|||
test "installing a bundle", %{user: user} do | |||
[payload] = send_message(user, "@bot: operable:bundle install heroku 0.0.4") | |||
assert %{name: "heroku", version: "0.0.4"} = payload |
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.
Musing out loud here... it may be better for composability to have bundle-related commands return the same shape of data.
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.
I think they do. This just uses Bundle
's implementation of Poison.encode
IIRC. Should I be rendering a view instead?
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.
I think we should try to use the views when we can... that way we have one central place to do the JSON conversion, and the Cog commands look just like the API requests. Documentation for one can double as documentation for the other.
And if /when we ever get around to calling embedded commands via the API, it'll be purely a backend change, without any user-visible effects.
Installation and uninstallation of bundles cannot currently be done via | ||
chat; please use `cogctl` for this functionality. | ||
""" | ||
|
||
permission "manage_commands" | ||
|
||
rule "when command is #{Cog.Util.Misc.embedded_bundle}:bundle must have #{Cog.Util.Misc.embedded_bundle}:manage_commands" |
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.
Somewhat tangential to this PR, but we should probably consider adding some allow
rules for the list
, info
, and versions
subcommands.
(Locking down installation of bundles, of course, is definitely the way to go, though 😄 )
@@ -0,0 +1 @@ | |||
Bundle "~$results[0].name~" version "~$results[0].version~" installed. |
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.
We should wrap this in an ~each var=$results~
tag to handle cases where people install a bunch of bundles at once:
for bundle in heroku pingdom twitter | bundle install $bundle
Otherwise, we'll just show the installation of the first bundle.
(Alternatively, you could do a table for the more-than-one bundle scenario; that might be overkill in this case, though.)
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.
Good point. Will do.
Two questions:
|
Answers:
|
0f54e20
to
d4bfce4
Compare
This adds support for installing a bundle via the registry.
Example:
I'll follow this up with a
bundle uninstall
subcommand as well.