{"action":"created","comment":{"url":"https://api.github.com/repos/zendesk/samson/pulls/comments/71084998","id":71084998,"diff_hunk":"@@ -0,0 +1,100 @@\n+require_relative '../test_helper'\n+\n+SingleCov.covered!\n+\n+def post_as(id, params)\n+  opts = params.merge(\n+    token: nil,\n+    user_id: id.identifier,\n+    response_url: 'http://example.com/blah'\n+  )\n+  post :command, opts\n+end\n+\n+describe SlackAppController do\n+  let(:user1) { users(:deployer) }\n+  let(:user2) { users(:deployer_buddy) }\n+  let(:user1_identifier) { slack_identifiers(:user1) }\n+  let(:user2_identifier) { slack_identifiers(:user2) }\n+  before do\n+    user1_identifier.update_column(:user_id, user1.id)\n+    user2_identifier.update_column(:user_id, user2.id)\n+  end\n+\n+  as_a_viewer do\n+    describe '#oauth' do\n+      with_env SLACK_CLIENT_ID: 'client-id', SLACK_CLIENT_SECRET: 'client-secret' do\n+        it 'sends the user to Slack to connect the app' do\n+          get :oauth\n+          assert_match 'https://slack.com/oauth/authorize?client_id=', @response.body","path":"plugins/slack_app/test/controllers/slack_app_controller_test.rb","position":29,"original_position":29,"commit_id":"d008e855296f051e83d429a560e4e921b94fd917","original_commit_id":"d008e855296f051e83d429a560e4e921b94fd917","user":{"login":"grosser","id":11367,"avatar_url":"https://avatars.githubusercontent.com/u/11367?v=3","gravatar_id":"","url":"https://api.github.com/users/grosser","html_url":"https://github.com/grosser","followers_url":"https://api.github.com/users/grosser/followers","following_url":"https://api.github.com/users/grosser/following{/other_user}","gists_url":"https://api.github.com/users/grosser/gists{/gist_id}","starred_url":"https://api.github.com/users/grosser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grosser/subscriptions","organizations_url":"https://api.github.com/users/grosser/orgs","repos_url":"https://api.github.com/users/grosser/repos","events_url":"https://api.github.com/users/grosser/events{/privacy}","received_events_url":"https://api.github.com/users/grosser/received_events","type":"User","site_admin":false},"body":"`@response.body.must_include`","created_at":"2016-07-17T16:20:11Z","updated_at":"2016-07-17T16:20:11Z","html_url":"https://github.com/zendesk/samson/pull/1130#discussion_r71084998","pull_request_url":"https://api.github.com/repos/zendesk/samson/pulls/1130","_links":{"self":{"href":"https://api.github.com/repos/zendesk/samson/pulls/comments/71084998"},"html":{"href":"https://github.com/zendesk/samson/pull/1130#discussion_r71084998"},"pull_request":{"href":"https://api.github.com/repos/zendesk/samson/pulls/1130"}}},"pull_request":{"url":"https://api.github.com/repos/zendesk/samson/pulls/1130","id":76792034,"html_url":"https://github.com/zendesk/samson/pull/1130","diff_url":"https://github.com/zendesk/samson/pull/1130.diff","patch_url":"https://github.com/zendesk/samson/pull/1130.patch","issue_url":"https://api.github.com/repos/zendesk/samson/issues/1130","number":1130,"state":"open","locked":false,"title":"Slack slash-command","user":{"login":"ben","id":39902,"avatar_url":"https://avatars.githubusercontent.com/u/39902?v=3","gravatar_id":"","url":"https://api.github.com/users/ben","html_url":"https://github.com/ben","followers_url":"https://api.github.com/users/ben/followers","following_url":"https://api.github.com/users/ben/following{/other_user}","gists_url":"https://api.github.com/users/ben/gists{/gist_id}","starred_url":"https://api.github.com/users/ben/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ben/subscriptions","organizations_url":"https://api.github.com/users/ben/orgs","repos_url":"https://api.github.com/users/ben/repos","events_url":"https://api.github.com/users/ben/events{/privacy}","received_events_url":"https://api.github.com/users/ben/received_events","type":"User","site_admin":false},"body":"This is a better approach than #1088 for allowing deployments to be triggered from Slack.\r\n\r\nHere's the setup flow:\r\n\r\n1. A Samson admin would create a [new Slack app](https://api.slack.com/apps/new) for their team and configure it to connect to their Samson instance. This would involve mostly setting three URLs (one for OAuth, one for receiving slash-commands, and one for message interaction post-backs).\r\n1. The first time any user invokes the `/deploy` command from Slack, the app would prompt them to authenticate the app on their user account. (The `/trello` command is a good example of this flow.)\r\n  1. The app replies with an \"only you can see this\" message with a link.\r\n  1. The user clicks the link, which takes them to a confirmation page on their Samson instance.\r\n  1. The user confirms that they want to connect their Samson account with their Slack account, which stores their Slack user ID in their user record.\r\n\r\nOnce the setup flow is complete, the user can then do `/deploy project[/ref] to stage` to create a deployment. If a buddy is required, something like this will pop up in the chat room:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/39902/16696650/be138202-44fa-11e6-9972-b3e90fbe889e.png)\r\n\r\nOnce someone clicks the :+1: (or triggers a non-buddy deployment), the message content is changed to look like this:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/39902/16696726/09df4158-44fb-11e6-8f7f-eb0437815b70.png)\r\n\r\nAnd when the deployment completes, a new message is posted to the channel:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/39902/16696955/2ac29ee6-44fc-11e6-8710-11f4a3c8e78d.png)\r\n\r\nAnd if the deployment fails, it would look like this:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/39902/16696998/5c275eea-44fc-11e6-9130-1facf228d6f0.png)\r\n\r\n(Maybe. It's possible editing an existing message won't cause notifications to be sent out. In that case, that mention will be sent as a new message.)\r\n\r\nIt should be noted that all authorization paths would be respected regarding who can click the button, who can create deployments, etc, since Samson would map Slack users back to Samson users in order to perform actions. Read permissions get a bit muddied, since anyone in that channel can see that a deployment has happened and which PRs are going into it, but full details are still on Samson behind auth.\r\n\r\n/cc @zendesk/samson\r\n\r\n### Tasks\r\n - [x] Migration/model for storing Slack->Samson user mapping\r\n - [x] Implement OAuth flow\r\n - [x] Implement slash-command handler\r\n - [x] Implement interactive-button handler\r\n - [x] Documentation\r\n - [x] Tests\r\n - [ ] :+1: from team\r\n\r\n### Risks\r\n- Level: Low. All sensitive information passes through SSL and regular authenticated paths.\r\n\r\n","created_at":"2016-07-08T18:12:40Z","updated_at":"2016-07-17T16:20:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f7c7911c2ba75e72faba23a290637c3319897c8a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/zendesk/samson/pulls/1130/commits","review_comments_url":"https://api.github.com/repos/zendesk/samson/pulls/1130/comments","review_comment_url":"https://api.github.com/repos/zendesk/samson/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zendesk/samson/issues/1130/comments","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/d008e855296f051e83d429a560e4e921b94fd917","head":{"label":"zendesk:ben/slash-command","ref":"ben/slash-command","sha":"d008e855296f051e83d429a560e4e921b94fd917","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":20208662,"name":"samson","full_name":"zendesk/samson","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/samson","description":"Web interface for deployments","fork":false,"url":"https://api.github.com/repos/zendesk/samson","forks_url":"https://api.github.com/repos/zendesk/samson/forks","keys_url":"https://api.github.com/repos/zendesk/samson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/samson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/samson/teams","hooks_url":"https://api.github.com/repos/zendesk/samson/hooks","issue_events_url":"https://api.github.com/repos/zendesk/samson/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/samson/events","assignees_url":"https://api.github.com/repos/zendesk/samson/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/samson/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/samson/tags","blobs_url":"https://api.github.com/repos/zendesk/samson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/samson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/samson/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/samson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/samson/languages","stargazers_url":"https://api.github.com/repos/zendesk/samson/stargazers","contributors_url":"https://api.github.com/repos/zendesk/samson/contributors","subscribers_url":"https://api.github.com/repos/zendesk/samson/subscribers","subscription_url":"https://api.github.com/repos/zendesk/samson/subscription","commits_url":"https://api.github.com/repos/zendesk/samson/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/samson/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/samson/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/samson/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/samson/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/samson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/samson/merges","archive_url":"https://api.github.com/repos/zendesk/samson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/samson/downloads","issues_url":"https://api.github.com/repos/zendesk/samson/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/samson/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/samson/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/samson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/samson/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/samson/releases{/id}","deployments_url":"https://api.github.com/repos/zendesk/samson/deployments","created_at":"2014-05-27T05:55:57Z","updated_at":"2016-07-13T16:26:10Z","pushed_at":"2016-07-17T14:54:04Z","git_url":"git://github.com/zendesk/samson.git","ssh_url":"git@github.com:zendesk/samson.git","clone_url":"https://github.com/zendesk/samson.git","svn_url":"https://github.com/zendesk/samson","homepage":null,"size":197461,"stargazers_count":704,"watchers_count":704,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":130,"mirror_url":null,"open_issues_count":56,"forks":130,"open_issues":56,"watchers":704,"default_branch":"master"}},"base":{"label":"zendesk:master","ref":"master","sha":"0304be959c35364718ccf56f63ee317456397eaf","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":20208662,"name":"samson","full_name":"zendesk/samson","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/samson","description":"Web interface for deployments","fork":false,"url":"https://api.github.com/repos/zendesk/samson","forks_url":"https://api.github.com/repos/zendesk/samson/forks","keys_url":"https://api.github.com/repos/zendesk/samson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/samson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/samson/teams","hooks_url":"https://api.github.com/repos/zendesk/samson/hooks","issue_events_url":"https://api.github.com/repos/zendesk/samson/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/samson/events","assignees_url":"https://api.github.com/repos/zendesk/samson/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/samson/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/samson/tags","blobs_url":"https://api.github.com/repos/zendesk/samson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/samson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/samson/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/samson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/samson/languages","stargazers_url":"https://api.github.com/repos/zendesk/samson/stargazers","contributors_url":"https://api.github.com/repos/zendesk/samson/contributors","subscribers_url":"https://api.github.com/repos/zendesk/samson/subscribers","subscription_url":"https://api.github.com/repos/zendesk/samson/subscription","commits_url":"https://api.github.com/repos/zendesk/samson/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/samson/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/samson/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/samson/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/samson/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/samson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/samson/merges","archive_url":"https://api.github.com/repos/zendesk/samson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/samson/downloads","issues_url":"https://api.github.com/repos/zendesk/samson/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/samson/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/samson/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/samson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/samson/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/samson/releases{/id}","deployments_url":"https://api.github.com/repos/zendesk/samson/deployments","created_at":"2014-05-27T05:55:57Z","updated_at":"2016-07-13T16:26:10Z","pushed_at":"2016-07-17T14:54:04Z","git_url":"git://github.com/zendesk/samson.git","ssh_url":"git@github.com:zendesk/samson.git","clone_url":"https://github.com/zendesk/samson.git","svn_url":"https://github.com/zendesk/samson","homepage":null,"size":197461,"stargazers_count":704,"watchers_count":704,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":130,"mirror_url":null,"open_issues_count":56,"forks":130,"open_issues":56,"watchers":704,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zendesk/samson/pulls/1130"},"html":{"href":"https://github.com/zendesk/samson/pull/1130"},"issue":{"href":"https://api.github.com/repos/zendesk/samson/issues/1130"},"comments":{"href":"https://api.github.com/repos/zendesk/samson/issues/1130/comments"},"review_comments":{"href":"https://api.github.com/repos/zendesk/samson/pulls/1130/comments"},"review_comment":{"href":"https://api.github.com/repos/zendesk/samson/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zendesk/samson/pulls/1130/commits"},"statuses":{"href":"https://api.github.com/repos/zendesk/samson/statuses/d008e855296f051e83d429a560e4e921b94fd917"}}}}
{"actor":{"display_login":"grosser"}}