{"action":"created","comment":{"url":"https://api.github.com/repos/heroku/retrodot/pulls/comments/83320440","pull_request_review_id":4173120,"id":83320440,"diff_hunk":"@@ -1,42 +1,78 @@\n module ChatOps\n+  class CommandSetup\n+    attr_reader :config\n+\n+    def initialize\n+      @config = {}\n+    end\n+\n+    def match(m)\n+      @config[:regex] = m\n+    end\n+\n+    def help(h)\n+      @config[:help] = h\n+    end\n+\n+    def incident_optional(value=true)\n+      @config[:incident_optional] = value\n+    end\n+  end\n+\n   class Command\n     class << self\n-      attr_reader :regex, :name, :help, :should_parse_incident\n+      attr_reader :regex\n \n       # Ruby calls this function when a class is declared that inherits from this\n       # class.  We then register it with the ChatOps module.\n       def inherited(klass)\n         ChatOps.register(klass)\n       end\n \n-      private\n-      def match(r)\n-        @regex = r\n+      def process(user, message)\n+        new(user, message).process\n       end\n \n-      def help_message(text)\n-        @help = [Config.chatops_prefix, text].compact.join(' ')\n+      # Outsiders should call process() instead.\n+      private :new\n+\n+      def incident_optional?\n+        @incident_optional\n       end\n \n-      # If this is set to true, then this command can take an optional incident\n-      # ID.  Its regex should have a (?<incident_id>\\d+)? group.  process() will\n-      # retrieve the specified incident from the DB and pass it in as an\n-      # argument to run().  If the user does not specify an incident, then\n-      # ChatOps.current_incident is used.\n-      def parse_incident(should_parse_incident)\n-        @should_parse_incident = should_parse_incident\n+      def help\n+        [Config.chatops_prefix, @help].compact.join(' ')\n       end\n+\n+      private\n+      def setup(&block)\n+        s = CommandSetup.new\n+        s.instance_eval &block\n+        s.config.each do |name, value|\n+          instance_variable_set \"@#{name}\", value","path":"lib/chat_ops/command.rb","position":65,"original_position":65,"commit_id":"59a773384bbfcf0a093a4acd57cb7411539e2c74","original_commit_id":"59a773384bbfcf0a093a4acd57cb7411539e2c74","user":{"login":"reidmix","id":12073,"avatar_url":"https://avatars.githubusercontent.com/u/12073?v=3","gravatar_id":"","url":"https://api.github.com/users/reidmix","html_url":"https://github.com/reidmix","followers_url":"https://api.github.com/users/reidmix/followers","following_url":"https://api.github.com/users/reidmix/following{/other_user}","gists_url":"https://api.github.com/users/reidmix/gists{/gist_id}","starred_url":"https://api.github.com/users/reidmix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reidmix/subscriptions","organizations_url":"https://api.github.com/users/reidmix/orgs","repos_url":"https://api.github.com/users/reidmix/repos","events_url":"https://api.github.com/users/reidmix/events{/privacy}","received_events_url":"https://api.github.com/users/reidmix/received_events","type":"User","site_admin":false},"body":"Nice","created_at":"2016-10-13T21:52:48Z","updated_at":"2016-10-13T21:52:48Z","html_url":"https://github.com/heroku/retrodot/pull/67#discussion_r83320440","pull_request_url":"https://api.github.com/repos/heroku/retrodot/pulls/67","_links":{"self":{"href":"https://api.github.com/repos/heroku/retrodot/pulls/comments/83320440"},"html":{"href":"https://github.com/heroku/retrodot/pull/67#discussion_r83320440"},"pull_request":{"href":"https://api.github.com/repos/heroku/retrodot/pulls/67"}}},"pull_request":{"url":"https://api.github.com/repos/heroku/retrodot/pulls/67","id":87565675,"html_url":"https://github.com/heroku/retrodot/pull/67","diff_url":"https://github.com/heroku/retrodot/pull/67.diff","patch_url":"https://github.com/heroku/retrodot/pull/67.patch","issue_url":"https://api.github.com/repos/heroku/retrodot/issues/67","number":67,"state":"open","locked":false,"title":"Chatops methods to command","user":{"login":"lexelby","id":4446653,"avatar_url":"https://avatars.githubusercontent.com/u/4446653?v=3","gravatar_id":"","url":"https://api.github.com/users/lexelby","html_url":"https://github.com/lexelby","followers_url":"https://api.github.com/users/lexelby/followers","following_url":"https://api.github.com/users/lexelby/following{/other_user}","gists_url":"https://api.github.com/users/lexelby/gists{/gist_id}","starred_url":"https://api.github.com/users/lexelby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lexelby/subscriptions","organizations_url":"https://api.github.com/users/lexelby/orgs","repos_url":"https://api.github.com/users/lexelby/repos","events_url":"https://api.github.com/users/lexelby/events{/privacy}","received_events_url":"https://api.github.com/users/lexelby/received_events","type":"User","site_admin":false},"body":"Note that this depends on #66.\r\n\r\nLots of changes in here, but it boils down to this:\r\n\r\n1. Move helper methods from `ChatOps` to `ChatOps::Command`.  (Actually, grouped related methods into modules and included them in `ChatOps::Command`.)\r\n2. Instead of passing `user` and `match` to `Command.process` and then passing them in turn to `run()`, store them as instance variables.\r\n3. Use the new instance variable semantics to change from `parse_incident` to always parsing, with `incident_optional` for exceptional commands like `start incident`.\r\n\r\nAll of this makes the code much better organized and easier to work with.\r\n\r\nThe rest of this PR is just a bunch of little changes to make the tests pass.\r\n\r\n@joshuatobin @reidmix","created_at":"2016-09-30T21:01:29Z","updated_at":"2016-10-13T21:52:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8a390dd74123a908510d670e60dc0799b74bc8d0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/heroku/retrodot/pulls/67/commits","review_comments_url":"https://api.github.com/repos/heroku/retrodot/pulls/67/comments","review_comment_url":"https://api.github.com/repos/heroku/retrodot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/heroku/retrodot/issues/67/comments","statuses_url":"https://api.github.com/repos/heroku/retrodot/statuses/59a773384bbfcf0a093a4acd57cb7411539e2c74","head":{"label":"heroku:chatops-methods-to-command","ref":"chatops-methods-to-command","sha":"59a773384bbfcf0a093a4acd57cb7411539e2c74","user":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"repo":{"id":64845715,"name":"retrodot","full_name":"heroku/retrodot","owner":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/heroku/retrodot","description":"A self-service tool to automate the facilitation, collection and system of record for the retrospective process","fork":false,"url":"https://api.github.com/repos/heroku/retrodot","forks_url":"https://api.github.com/repos/heroku/retrodot/forks","keys_url":"https://api.github.com/repos/heroku/retrodot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heroku/retrodot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heroku/retrodot/teams","hooks_url":"https://api.github.com/repos/heroku/retrodot/hooks","issue_events_url":"https://api.github.com/repos/heroku/retrodot/issues/events{/number}","events_url":"https://api.github.com/repos/heroku/retrodot/events","assignees_url":"https://api.github.com/repos/heroku/retrodot/assignees{/user}","branches_url":"https://api.github.com/repos/heroku/retrodot/branches{/branch}","tags_url":"https://api.github.com/repos/heroku/retrodot/tags","blobs_url":"https://api.github.com/repos/heroku/retrodot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heroku/retrodot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heroku/retrodot/git/refs{/sha}","trees_url":"https://api.github.com/repos/heroku/retrodot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heroku/retrodot/statuses/{sha}","languages_url":"https://api.github.com/repos/heroku/retrodot/languages","stargazers_url":"https://api.github.com/repos/heroku/retrodot/stargazers","contributors_url":"https://api.github.com/repos/heroku/retrodot/contributors","subscribers_url":"https://api.github.com/repos/heroku/retrodot/subscribers","subscription_url":"https://api.github.com/repos/heroku/retrodot/subscription","commits_url":"https://api.github.com/repos/heroku/retrodot/commits{/sha}","git_commits_url":"https://api.github.com/repos/heroku/retrodot/git/commits{/sha}","comments_url":"https://api.github.com/repos/heroku/retrodot/comments{/number}","issue_comment_url":"https://api.github.com/repos/heroku/retrodot/issues/comments{/number}","contents_url":"https://api.github.com/repos/heroku/retrodot/contents/{+path}","compare_url":"https://api.github.com/repos/heroku/retrodot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heroku/retrodot/merges","archive_url":"https://api.github.com/repos/heroku/retrodot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heroku/retrodot/downloads","issues_url":"https://api.github.com/repos/heroku/retrodot/issues{/number}","pulls_url":"https://api.github.com/repos/heroku/retrodot/pulls{/number}","milestones_url":"https://api.github.com/repos/heroku/retrodot/milestones{/number}","notifications_url":"https://api.github.com/repos/heroku/retrodot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heroku/retrodot/labels{/name}","releases_url":"https://api.github.com/repos/heroku/retrodot/releases{/id}","deployments_url":"https://api.github.com/repos/heroku/retrodot/deployments","created_at":"2016-08-03T12:51:55Z","updated_at":"2016-09-01T14:23:25Z","pushed_at":"2016-10-13T19:52:40Z","git_url":"git://github.com/heroku/retrodot.git","ssh_url":"git@github.com:heroku/retrodot.git","clone_url":"https://github.com/heroku/retrodot.git","svn_url":"https://github.com/heroku/retrodot","homepage":null,"size":423,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"heroku:master","ref":"master","sha":"c74c0302dba28252aceb6b14fe05005d72cd09ba","user":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"repo":{"id":64845715,"name":"retrodot","full_name":"heroku/retrodot","owner":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/heroku/retrodot","description":"A self-service tool to automate the facilitation, collection and system of record for the retrospective process","fork":false,"url":"https://api.github.com/repos/heroku/retrodot","forks_url":"https://api.github.com/repos/heroku/retrodot/forks","keys_url":"https://api.github.com/repos/heroku/retrodot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heroku/retrodot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heroku/retrodot/teams","hooks_url":"https://api.github.com/repos/heroku/retrodot/hooks","issue_events_url":"https://api.github.com/repos/heroku/retrodot/issues/events{/number}","events_url":"https://api.github.com/repos/heroku/retrodot/events","assignees_url":"https://api.github.com/repos/heroku/retrodot/assignees{/user}","branches_url":"https://api.github.com/repos/heroku/retrodot/branches{/branch}","tags_url":"https://api.github.com/repos/heroku/retrodot/tags","blobs_url":"https://api.github.com/repos/heroku/retrodot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heroku/retrodot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heroku/retrodot/git/refs{/sha}","trees_url":"https://api.github.com/repos/heroku/retrodot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heroku/retrodot/statuses/{sha}","languages_url":"https://api.github.com/repos/heroku/retrodot/languages","stargazers_url":"https://api.github.com/repos/heroku/retrodot/stargazers","contributors_url":"https://api.github.com/repos/heroku/retrodot/contributors","subscribers_url":"https://api.github.com/repos/heroku/retrodot/subscribers","subscription_url":"https://api.github.com/repos/heroku/retrodot/subscription","commits_url":"https://api.github.com/repos/heroku/retrodot/commits{/sha}","git_commits_url":"https://api.github.com/repos/heroku/retrodot/git/commits{/sha}","comments_url":"https://api.github.com/repos/heroku/retrodot/comments{/number}","issue_comment_url":"https://api.github.com/repos/heroku/retrodot/issues/comments{/number}","contents_url":"https://api.github.com/repos/heroku/retrodot/contents/{+path}","compare_url":"https://api.github.com/repos/heroku/retrodot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heroku/retrodot/merges","archive_url":"https://api.github.com/repos/heroku/retrodot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heroku/retrodot/downloads","issues_url":"https://api.github.com/repos/heroku/retrodot/issues{/number}","pulls_url":"https://api.github.com/repos/heroku/retrodot/pulls{/number}","milestones_url":"https://api.github.com/repos/heroku/retrodot/milestones{/number}","notifications_url":"https://api.github.com/repos/heroku/retrodot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heroku/retrodot/labels{/name}","releases_url":"https://api.github.com/repos/heroku/retrodot/releases{/id}","deployments_url":"https://api.github.com/repos/heroku/retrodot/deployments","created_at":"2016-08-03T12:51:55Z","updated_at":"2016-09-01T14:23:25Z","pushed_at":"2016-10-13T19:52:40Z","git_url":"git://github.com/heroku/retrodot.git","ssh_url":"git@github.com:heroku/retrodot.git","clone_url":"https://github.com/heroku/retrodot.git","svn_url":"https://github.com/heroku/retrodot","homepage":null,"size":423,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/heroku/retrodot/pulls/67"},"html":{"href":"https://github.com/heroku/retrodot/pull/67"},"issue":{"href":"https://api.github.com/repos/heroku/retrodot/issues/67"},"comments":{"href":"https://api.github.com/repos/heroku/retrodot/issues/67/comments"},"review_comments":{"href":"https://api.github.com/repos/heroku/retrodot/pulls/67/comments"},"review_comment":{"href":"https://api.github.com/repos/heroku/retrodot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/heroku/retrodot/pulls/67/commits"},"statuses":{"href":"https://api.github.com/repos/heroku/retrodot/statuses/59a773384bbfcf0a093a4acd57cb7411539e2c74"}}}}
{"actor":{"display_login":"reidmix"}}