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

HipChat Support #1012

Merged
merged 31 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
46ee211
Preliminary work for HipChat integration
Sep 20, 2016
a61bb9d
Skip CI if NO_CI file is present
Sep 22, 2016
936ae71
More HipChat progress
Sep 22, 2016
ffed5b2
More progress
Sep 23, 2016
728a0ad
Added persistent state for chat providers
Sep 26, 2016
a2436a3
Parameterize all 3 HipChat hosts
Sep 27, 2016
c59aac6
Table rendering;User/room lookup tweaks
Sep 27, 2016
860287d
Use secondary_id to send room notifications
Sep 27, 2016
bdb3b92
Redirect support
Sep 27, 2016
4f63a34
Render attachments
Sep 29, 2016
34aab15
Ported Slack template tests to HipChat
Sep 29, 2016
17446cd
Integration test prep
Sep 30, 2016
6208011
Test fixups after rebase
Sep 30, 2016
1aa0fba
Stop hardcoding api.hipchat.com
Oct 1, 2016
1337f32
De-tangling logic around provider-specific integ. tests
Oct 3, 2016
e1057f2
HipChat integration tests
Oct 5, 2016
0b8a3af
Find bot's XMPP name via roster
Oct 5, 2016
1aab1d4
Use non-throwing version of Repo.get_by/2
Oct 5, 2016
62c5773
Moved REST API calls to helper function
Oct 5, 2016
58019d3
DRY-ing up provider config
Oct 5, 2016
afcd6ef
Replaced ~r with ~i
Oct 5, 2016
cda66f4
Updated test excludes to reflect current state
Oct 5, 2016
5773f26
Put :chat config key back for now
Oct 5, 2016
b57a30b
Reduce likelihood of Slack throttling
Oct 6, 2016
ce297aa
Hoist "integration" tests into unit tests
Oct 6, 2016
8a78bcd
Streamline restarts;Prevent Slack API throttling
Oct 6, 2016
5be0cc2
Removed dead test
Oct 6, 2016
8584571
Refactored config to more test-friendly form
Oct 6, 2016
b1b693e
Bumped timeout to allow for slow HipChat responses
Oct 6, 2016
13497d1
Tagged w/integration test
Oct 6, 2016
c2dbc11
Separated integration and unit tests
Oct 6, 2016
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
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ endif

DOCKER_IMAGE ?= operable/cog:0.5-dev

ifeq ($(wildcard NO_CI),)
ci: export DATABASE_URL = $(TEST_DATABASE_URL)
ci: export MIX_ENV = test
ci: ci-setup test-all ci-cleanup

ci-reset:
@echo "Resetting build environment"
@rm -rf _build
# @rm -rf _build

ci-setup: ci-reset
# Nuke mnesia dirs so we don't get borked on emqttd upgrades
Expand All @@ -27,6 +28,11 @@ ci-setup: ci-reset

ci-cleanup:
mix ecto.drop
else
ci:
@echo "NO_CI file found. CI build targets skipped."
@exit 0
endif

setup:
mix deps.get
Expand All @@ -51,8 +57,13 @@ test: reset-db
mix test $(TEST)

test-all: export MIX_ENV = test
test-all: reset-db
mix test
test-all: unit-tests integration-tests

unit-tests: reset-db
mix test --exclude=integration

integration-tests: reset-db
mix test --only=integration

test-watch: export MIX_ENV = test
test-watch: reset-db
Expand All @@ -66,4 +77,4 @@ coverage:
docker:
docker build --build-arg MIX_ENV=prod -t $(DOCKER_IMAGE) .

.PHONY: ci ci-setup ci-cleanup test docker
.PHONY: ci ci-setup ci-cleanup test docker unit-tests integration-tests
10 changes: 3 additions & 7 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ config :cog, :embedded_bundle_version, "0.13.0"
# Chat Adapters
# ========================================================================

config :cog, Cog.Chat.Adapter,
providers: [http: Cog.Chat.Http.Provider],
cache_ttl: {60, :sec}

config :cog, Cog.Chat.Slack.Provider,
api_token: System.get_env("SLACK_API_TOKEN")

config :cog, Cog.Chat.Http.Provider,
foo: "blah"

Expand Down Expand Up @@ -193,4 +186,7 @@ config :cog, Cog.Mailer,
config :cog, :email_from, System.get_env("COG_EMAIL_FROM")
config :cog, :password_reset_base_url, System.get_env("COG_PASSWORD_RESET_BASE_URL")

import_config "slack.exs"
import_config "hipchat.exs"

import_config "#{Mix.env}.exs"
7 changes: 3 additions & 4 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ config :lager, :handlers,

config :cog, :enable_spoken_commands, ensure_boolean(System.get_env("ENABLE_SPOKEN_COMMANDS")) || false

config :cog,
:template_cache_ttl, {1, :sec}

config :cog, Cog.Chat.Adapter,
providers: [slack: Cog.Chat.Slack.Provider],
providers: [slack: Cog.Chat.Slack.Provider,
http: Cog.Chat.Http.Provider],
cache_ttl: {1, :sec},
chat: :slack

config :cog, Cog.Endpoint,
Expand Down
10 changes: 10 additions & 0 deletions config/hipchat.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use Mix.Config

config :cog, Cog.Chat.HipChat.Provider,
api_root: System.get_env("HIPCHAT_API_ROOT") || "https://api.hipchat.com/v2",
chat_host: System.get_env("HIPCHAT_CHAT_HOST") || "chat.hipchat.com",
conf_host: System.get_env("HIPCHAT_CONF_HOST") || "conf.hipchat.com",
api_token: System.get_env("HIPCHAT_API_TOKEN"),
nickname: System.get_env("HIPCHAT_NICKNAME"),
jabber_id: System.get_env("HIPCHAT_JABBER_ID"),
jabber_password: System.get_env("HIPCHAT_JABBER_PASSWORD")
3 changes: 2 additions & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ config :comeonin,

config :cog, Cog.Chat.Adapter,
providers: [slack: Cog.Chat.Slack.Provider],
chat: :slack
chat: :slack,
cache_ttl: {60, sec}
4 changes: 4 additions & 0 deletions config/slack.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use Mix.Config

config :cog, Cog.Chat.Slack.Provider,
api_token: System.get_env("SLACK_API_TOKEN")
4 changes: 3 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ config :lager, :handlers,
[{LagerLogger, [level: :error]}]

config :cog, Cog.Chat.Adapter,
providers: [test: Cog.Chat.Test.Provider],
providers: [test: Cog.Chat.Test.Provider,
http: Cog.Chat.Http.Provider],
cache_ttl: {1, :sec},
chat: :test

config :cog, Cog.Chat.Test.Provider,
Expand Down
8 changes: 8 additions & 0 deletions lib/cog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ defmodule Cog do

import Supervisor.Spec, warn: false

def restart() do
Logger.debug("Stopping Cog...")
:ok = Application.stop(:cog)
Logger.debug("Cog stopped. Restarting...")
{:ok, _} = Application.ensure_all_started(:cog)
Logger.debug("Cog restarted.")
end

def start(_type, _args) do
maybe_display_unenforcing_warning()
children = [worker(Cog.BusDriver, [], shutdown: 1000),
Expand Down
14 changes: 7 additions & 7 deletions lib/cog/chat/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ defmodule Cog.Chat.Adapter do
false ->
state
end
_error ->
Logger.error("Ignoring invalid chat message: #{inspect message, pretty: true}")
error ->
Logger.error("Error decoding chat message: #{inspect error} #{inspect message, pretty: true}")
state
end
{:noreply, state}
Expand Down Expand Up @@ -332,14 +332,14 @@ defmodule Cog.Chat.Adapter do

defp parse_mention(_text, nil), do: nil
defp parse_mention(text, bot_name) do
updated = Regex.replace(~r/^#{Regex.escape(bot_name)}/, text, "")
updated = Regex.replace(~r/^#{Regex.escape(bot_name)}/i, text, "")
if updated != text do
Regex.replace(~r/^:/, updated, "")
|> String.trim
else
nil
end
end
else
nil
end
end

defp prepare_target(target) do
case Cog.Chat.Room.from_map(target) do
Expand Down
Loading