{"action":"created","comment":{"url":"https://api.github.com/repos/quintilesims/slackbot/pulls/comments/175213315","pull_request_review_id":104710693,"id":175213315,"diff_hunk":"@@ -0,0 +1,149 @@\n+package bot\n+\n+import (\n+\t\"fmt\"\n+\t\"io\"\n+\t\"strings\"\n+\n+\t\"github.com/quintilesims/slackbot/db\"\n+\t\"github.com/quintilesims/slackbot/models\"\n+\tglob \"github.com/ryanuber/go-glob\"\n+\t\"github.com/urfave/cli\"\n+)\n+\n+// NewGlossaryCommand returns a cli.Command that manages !glossary\n+func NewGlossaryCommand(store db.Store, w io.Writer) cli.Command {\n+\treturn cli.Command{\n+\t\tName:  \"!glossary\",\n+\t\tUsage: \"manage the glossary\",\n+\t\tSubcommands: []cli.Command{\n+\t\t\t{\n+\t\t\t\tName:      \"define\",\n+\t\t\t\tUsage:     \"add or set an entry in the glossary\",\n+\t\t\t\tArgsUsage: \"KEY DEFINITION\",\n+\t\t\t\tAction:    newGlossaryDefineAction(store, w),\n+\t\t\t},\n+\t\t\t{\n+\t\t\t\tName:      \"rm\",\n+\t\t\t\tUsage:     \"remove an entry from the glossary\",\n+\t\t\t\tArgsUsage: \"KEY\",\n+\t\t\t\tAction:    newGlossaryRemoveAction(store, w),\n+\t\t\t},\n+\t\t\t{\n+\t\t\t\tName:      \"search\",\n+\t\t\t\tUsage:     \"search for entries in the glossary\",\n+\t\t\t\tArgsUsage: \"GLOB\",\n+\t\t\t\tAction:    newGlossarySearchAction(store, w),\n+\t\t\t},\n+\t\t},\n+\t}\n+}\n+\n+func newGlossaryDefineAction(store db.Store, w io.Writer) func(c *cli.Context) error {\n+\treturn func(c *cli.Context) error {\n+\t\targs := c.Args()\n+\t\tkey := args.First()\n+\t\tdefinition := strings.Join(args.Tail(), \" \")\n+\n+\t\tif key == \"\" {\n+\t\t\treturn fmt.Errorf(\"Arg KEY is required\")\n+\t\t}\n+\n+\t\tif definition == \"\" {\n+\t\t\treturn fmt.Errorf(\"Arg DEFINITION is required\")\n+\t\t}\n+\n+\t\tglossary := models.Glossary{}\n+\t\tif err := store.Read(db.GlossaryKey, &glossary); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tvar text string\n+\t\tif previousDefinition, ok := glossary[key]; previousDefinition != \"\" && ok {\n+\t\t\ttext = fmt.Sprintf(\"Replacing previous definition of *%s*: *%s* with *%s*\", key, previousDefinition, definition)\n+\t\t} else {\n+\t\t\ttext = fmt.Sprintf(\"Ok, *%s* %s\", key, definition)\n+\t\t}\n+\n+\t\tglossary[key] = definition\n+\n+\t\tif err := store.Write(db.GlossaryKey, glossary); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tif _, err := w.Write([]byte(text)); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\treturn nil\n+\t}\n+}\n+\n+func newGlossaryRemoveAction(store db.Store, w io.Writer) func(c *cli.Context) error {\n+\treturn func(c *cli.Context) error {\n+\t\tkey := c.Args().Get(0)\n+\n+\t\tif key == \"\" {\n+\t\t\treturn fmt.Errorf(\"Arg KEY is required\")\n+\t\t}\n+\n+\t\tglossary := models.Glossary{}\n+\t\tif err := store.Read(db.GlossaryKey, &glossary); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tif _, ok := glossary[key]; ok {\n+\t\t\tdelete(glossary, key)\n+\t\t} else {\n+\t\t\treturn fmt.Errorf(\"Key: *%s* not in glossary\", key)\n+\t\t}\n+\n+\t\tif err := store.Write(db.GlossaryKey, glossary); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\ttext := fmt.Sprintf(\"Ok, deleted *%s*\", key)\n+\t\tif _, err := w.Write([]byte(text)); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\treturn nil\n+\t}\n+}\n+\n+func newGlossarySearchAction(store db.Store, w io.Writer) func(c *cli.Context) error {\n+\treturn func(c *cli.Context) error {\n+\t\tg := c.Args().Get(0)\n+\n+\t\tif g == \"\" {\n+\t\t\treturn fmt.Errorf(\"Arg GLOB is required\")\n+\t\t}\n+\n+\t\tglossary := models.Glossary{}\n+\t\tif err := store.Read(db.GlossaryKey, &glossary); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tresults := models.Glossary{}\n+\t\tfor k, v := range glossary {\n+\t\t\tif glob.Glob(g, k) {\n+\t\t\t\tresults[k] = v\n+\t\t\t}\n+\t\t}\n+\n+\t\tif len(results) == 0 {\n+\t\t\treturn fmt.Errorf(\"Could not find any glossary entries matching the specified pattern *%s*\", g)\n+\t\t}\n+\n+\t\tvar text string\n+\t\tfor key, definition := range results {\n+\t\t\ttext += fmt.Sprintf(\"*%s* %s\\n\", key, definition)","path":"bot/glossary_command.go","position":140,"original_position":140,"commit_id":"af32302658cf9994efeba74acafc498ffc815827","original_commit_id":"af32302658cf9994efeba74acafc498ffc815827","user":{"login":"zpatrick","id":2894436,"avatar_url":"https://avatars2.githubusercontent.com/u/2894436?v=4","gravatar_id":"","url":"https://api.github.com/users/zpatrick","html_url":"https://github.com/zpatrick","followers_url":"https://api.github.com/users/zpatrick/followers","following_url":"https://api.github.com/users/zpatrick/following{/other_user}","gists_url":"https://api.github.com/users/zpatrick/gists{/gist_id}","starred_url":"https://api.github.com/users/zpatrick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zpatrick/subscriptions","organizations_url":"https://api.github.com/users/zpatrick/orgs","repos_url":"https://api.github.com/users/zpatrick/repos","events_url":"https://api.github.com/users/zpatrick/events{/privacy}","received_events_url":"https://api.github.com/users/zpatrick/received_events","type":"User","site_admin":false},"body":"[super nit] add a colon? `*%s*: %s` ","created_at":"2018-03-16T21:00:33Z","updated_at":"2018-03-16T21:03:12Z","html_url":"https://github.com/quintilesims/slackbot/pull/20#discussion_r175213315","pull_request_url":"https://api.github.com/repos/quintilesims/slackbot/pulls/20","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/quintilesims/slackbot/pulls/comments/175213315"},"html":{"href":"https://github.com/quintilesims/slackbot/pull/20#discussion_r175213315"},"pull_request":{"href":"https://api.github.com/repos/quintilesims/slackbot/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/quintilesims/slackbot/pulls/20","id":175638685,"html_url":"https://github.com/quintilesims/slackbot/pull/20","diff_url":"https://github.com/quintilesims/slackbot/pull/20.diff","patch_url":"https://github.com/quintilesims/slackbot/pull/20.patch","issue_url":"https://api.github.com/repos/quintilesims/slackbot/issues/20","number":20,"state":"open","locked":false,"title":"Add glossary command to bot","user":{"login":"nehayward","id":6733030,"avatar_url":"https://avatars1.githubusercontent.com/u/6733030?v=4","gravatar_id":"","url":"https://api.github.com/users/nehayward","html_url":"https://github.com/nehayward","followers_url":"https://api.github.com/users/nehayward/followers","following_url":"https://api.github.com/users/nehayward/following{/other_user}","gists_url":"https://api.github.com/users/nehayward/gists{/gist_id}","starred_url":"https://api.github.com/users/nehayward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nehayward/subscriptions","organizations_url":"https://api.github.com/users/nehayward/orgs","repos_url":"https://api.github.com/users/nehayward/repos","events_url":"https://api.github.com/users/nehayward/events{/privacy}","received_events_url":"https://api.github.com/users/nehayward/received_events","type":"User","site_admin":false},"body":"Maybe add template?\r\n\r\nCommand: \r\nGlossary Command\r\n","created_at":"2018-03-16T20:30:52Z","updated_at":"2018-03-16T21:03:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"073f756507ed62d52f4be0eed0358213fbed0fee","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/quintilesims/slackbot/pulls/20/commits","review_comments_url":"https://api.github.com/repos/quintilesims/slackbot/pulls/20/comments","review_comment_url":"https://api.github.com/repos/quintilesims/slackbot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/quintilesims/slackbot/issues/20/comments","statuses_url":"https://api.github.com/repos/quintilesims/slackbot/statuses/af32302658cf9994efeba74acafc498ffc815827","head":{"label":"quintilesims:glossary","ref":"glossary","sha":"af32302658cf9994efeba74acafc498ffc815827","user":{"login":"quintilesims","id":23506699,"avatar_url":"https://avatars2.githubusercontent.com/u/23506699?v=4","gravatar_id":"","url":"https://api.github.com/users/quintilesims","html_url":"https://github.com/quintilesims","followers_url":"https://api.github.com/users/quintilesims/followers","following_url":"https://api.github.com/users/quintilesims/following{/other_user}","gists_url":"https://api.github.com/users/quintilesims/gists{/gist_id}","starred_url":"https://api.github.com/users/quintilesims/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quintilesims/subscriptions","organizations_url":"https://api.github.com/users/quintilesims/orgs","repos_url":"https://api.github.com/users/quintilesims/repos","events_url":"https://api.github.com/users/quintilesims/events{/privacy}","received_events_url":"https://api.github.com/users/quintilesims/received_events","type":"Organization","site_admin":false},"repo":{"id":123020819,"name":"slackbot","full_name":"quintilesims/slackbot","owner":{"login":"quintilesims","id":23506699,"avatar_url":"https://avatars2.githubusercontent.com/u/23506699?v=4","gravatar_id":"","url":"https://api.github.com/users/quintilesims","html_url":"https://github.com/quintilesims","followers_url":"https://api.github.com/users/quintilesims/followers","following_url":"https://api.github.com/users/quintilesims/following{/other_user}","gists_url":"https://api.github.com/users/quintilesims/gists{/gist_id}","starred_url":"https://api.github.com/users/quintilesims/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quintilesims/subscriptions","organizations_url":"https://api.github.com/users/quintilesims/orgs","repos_url":"https://api.github.com/users/quintilesims/repos","events_url":"https://api.github.com/users/quintilesims/events{/privacy}","received_events_url":"https://api.github.com/users/quintilesims/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/quintilesims/slackbot","description":"Slack bot for IQVIA","fork":false,"url":"https://api.github.com/repos/quintilesims/slackbot","forks_url":"https://api.github.com/repos/quintilesims/slackbot/forks","keys_url":"https://api.github.com/repos/quintilesims/slackbot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quintilesims/slackbot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quintilesims/slackbot/teams","hooks_url":"https://api.github.com/repos/quintilesims/slackbot/hooks","issue_events_url":"https://api.github.com/repos/quintilesims/slackbot/issues/events{/number}","events_url":"https://api.github.com/repos/quintilesims/slackbot/events","assignees_url":"https://api.github.com/repos/quintilesims/slackbot/assignees{/user}","branches_url":"https://api.github.com/repos/quintilesims/slackbot/branches{/branch}","tags_url":"https://api.github.com/repos/quintilesims/slackbot/tags","blobs_url":"https://api.github.com/repos/quintilesims/slackbot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quintilesims/slackbot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quintilesims/slackbot/git/refs{/sha}","trees_url":"https://api.github.com/repos/quintilesims/slackbot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quintilesims/slackbot/statuses/{sha}","languages_url":"https://api.github.com/repos/quintilesims/slackbot/languages","stargazers_url":"https://api.github.com/repos/quintilesims/slackbot/stargazers","contributors_url":"https://api.github.com/repos/quintilesims/slackbot/contributors","subscribers_url":"https://api.github.com/repos/quintilesims/slackbot/subscribers","subscription_url":"https://api.github.com/repos/quintilesims/slackbot/subscription","commits_url":"https://api.github.com/repos/quintilesims/slackbot/commits{/sha}","git_commits_url":"https://api.github.com/repos/quintilesims/slackbot/git/commits{/sha}","comments_url":"https://api.github.com/repos/quintilesims/slackbot/comments{/number}","issue_comment_url":"https://api.github.com/repos/quintilesims/slackbot/issues/comments{/number}","contents_url":"https://api.github.com/repos/quintilesims/slackbot/contents/{+path}","compare_url":"https://api.github.com/repos/quintilesims/slackbot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quintilesims/slackbot/merges","archive_url":"https://api.github.com/repos/quintilesims/slackbot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quintilesims/slackbot/downloads","issues_url":"https://api.github.com/repos/quintilesims/slackbot/issues{/number}","pulls_url":"https://api.github.com/repos/quintilesims/slackbot/pulls{/number}","milestones_url":"https://api.github.com/repos/quintilesims/slackbot/milestones{/number}","notifications_url":"https://api.github.com/repos/quintilesims/slackbot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quintilesims/slackbot/labels{/name}","releases_url":"https://api.github.com/repos/quintilesims/slackbot/releases{/id}","deployments_url":"https://api.github.com/repos/quintilesims/slackbot/deployments","created_at":"2018-02-26T19:39:36Z","updated_at":"2018-03-16T00:15:15Z","pushed_at":"2018-03-16T20:30:52Z","git_url":"git://github.com/quintilesims/slackbot.git","ssh_url":"git@github.com:quintilesims/slackbot.git","clone_url":"https://github.com/quintilesims/slackbot.git","svn_url":"https://github.com/quintilesims/slackbot","homepage":"","size":9784,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"quintilesims:master","ref":"master","sha":"e96aa015c816d3cb60ddde274c76a03465764271","user":{"login":"quintilesims","id":23506699,"avatar_url":"https://avatars2.githubusercontent.com/u/23506699?v=4","gravatar_id":"","url":"https://api.github.com/users/quintilesims","html_url":"https://github.com/quintilesims","followers_url":"https://api.github.com/users/quintilesims/followers","following_url":"https://api.github.com/users/quintilesims/following{/other_user}","gists_url":"https://api.github.com/users/quintilesims/gists{/gist_id}","starred_url":"https://api.github.com/users/quintilesims/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quintilesims/subscriptions","organizations_url":"https://api.github.com/users/quintilesims/orgs","repos_url":"https://api.github.com/users/quintilesims/repos","events_url":"https://api.github.com/users/quintilesims/events{/privacy}","received_events_url":"https://api.github.com/users/quintilesims/received_events","type":"Organization","site_admin":false},"repo":{"id":123020819,"name":"slackbot","full_name":"quintilesims/slackbot","owner":{"login":"quintilesims","id":23506699,"avatar_url":"https://avatars2.githubusercontent.com/u/23506699?v=4","gravatar_id":"","url":"https://api.github.com/users/quintilesims","html_url":"https://github.com/quintilesims","followers_url":"https://api.github.com/users/quintilesims/followers","following_url":"https://api.github.com/users/quintilesims/following{/other_user}","gists_url":"https://api.github.com/users/quintilesims/gists{/gist_id}","starred_url":"https://api.github.com/users/quintilesims/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quintilesims/subscriptions","organizations_url":"https://api.github.com/users/quintilesims/orgs","repos_url":"https://api.github.com/users/quintilesims/repos","events_url":"https://api.github.com/users/quintilesims/events{/privacy}","received_events_url":"https://api.github.com/users/quintilesims/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/quintilesims/slackbot","description":"Slack bot for IQVIA","fork":false,"url":"https://api.github.com/repos/quintilesims/slackbot","forks_url":"https://api.github.com/repos/quintilesims/slackbot/forks","keys_url":"https://api.github.com/repos/quintilesims/slackbot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quintilesims/slackbot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quintilesims/slackbot/teams","hooks_url":"https://api.github.com/repos/quintilesims/slackbot/hooks","issue_events_url":"https://api.github.com/repos/quintilesims/slackbot/issues/events{/number}","events_url":"https://api.github.com/repos/quintilesims/slackbot/events","assignees_url":"https://api.github.com/repos/quintilesims/slackbot/assignees{/user}","branches_url":"https://api.github.com/repos/quintilesims/slackbot/branches{/branch}","tags_url":"https://api.github.com/repos/quintilesims/slackbot/tags","blobs_url":"https://api.github.com/repos/quintilesims/slackbot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quintilesims/slackbot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quintilesims/slackbot/git/refs{/sha}","trees_url":"https://api.github.com/repos/quintilesims/slackbot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quintilesims/slackbot/statuses/{sha}","languages_url":"https://api.github.com/repos/quintilesims/slackbot/languages","stargazers_url":"https://api.github.com/repos/quintilesims/slackbot/stargazers","contributors_url":"https://api.github.com/repos/quintilesims/slackbot/contributors","subscribers_url":"https://api.github.com/repos/quintilesims/slackbot/subscribers","subscription_url":"https://api.github.com/repos/quintilesims/slackbot/subscription","commits_url":"https://api.github.com/repos/quintilesims/slackbot/commits{/sha}","git_commits_url":"https://api.github.com/repos/quintilesims/slackbot/git/commits{/sha}","comments_url":"https://api.github.com/repos/quintilesims/slackbot/comments{/number}","issue_comment_url":"https://api.github.com/repos/quintilesims/slackbot/issues/comments{/number}","contents_url":"https://api.github.com/repos/quintilesims/slackbot/contents/{+path}","compare_url":"https://api.github.com/repos/quintilesims/slackbot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quintilesims/slackbot/merges","archive_url":"https://api.github.com/repos/quintilesims/slackbot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quintilesims/slackbot/downloads","issues_url":"https://api.github.com/repos/quintilesims/slackbot/issues{/number}","pulls_url":"https://api.github.com/repos/quintilesims/slackbot/pulls{/number}","milestones_url":"https://api.github.com/repos/quintilesims/slackbot/milestones{/number}","notifications_url":"https://api.github.com/repos/quintilesims/slackbot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quintilesims/slackbot/labels{/name}","releases_url":"https://api.github.com/repos/quintilesims/slackbot/releases{/id}","deployments_url":"https://api.github.com/repos/quintilesims/slackbot/deployments","created_at":"2018-02-26T19:39:36Z","updated_at":"2018-03-16T00:15:15Z","pushed_at":"2018-03-16T20:30:52Z","git_url":"git://github.com/quintilesims/slackbot.git","ssh_url":"git@github.com:quintilesims/slackbot.git","clone_url":"https://github.com/quintilesims/slackbot.git","svn_url":"https://github.com/quintilesims/slackbot","homepage":"","size":9784,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/quintilesims/slackbot/pulls/20"},"html":{"href":"https://github.com/quintilesims/slackbot/pull/20"},"issue":{"href":"https://api.github.com/repos/quintilesims/slackbot/issues/20"},"comments":{"href":"https://api.github.com/repos/quintilesims/slackbot/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/quintilesims/slackbot/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/quintilesims/slackbot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/quintilesims/slackbot/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/quintilesims/slackbot/statuses/af32302658cf9994efeba74acafc498ffc815827"}},"author_association":"NONE"}}
{"actor":{"display_login":"zpatrick"}}