{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/test-infra/pulls/comments/106227981","pull_request_review_id":27140251,"id":106227981,"diff_hunk":"@@ -0,0 +1,133 @@\n+/*\n+Copyright 2016 The Kubernetes Authors.\n+\n+Licensed under the Apache License, Version 2.0 (the \"License\");\n+you may not use this file except in compliance with the License.\n+You may obtain a copy of the License at\n+\n+    http://www.apache.org/licenses/LICENSE-2.0\n+\n+Unless required by applicable law or agreed to in writing, software\n+distributed under the License is distributed on an \"AS IS\" BASIS,\n+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+See the License for the specific language governing permissions and\n+limitations under the License.\n+*/\n+\n+package label\n+\n+import (\n+\t\"fmt\"\n+\t\"regexp\"\n+\t\"strings\"\n+\n+\t\"github.com/Sirupsen/logrus\"\n+\n+\t\"k8s.io/kubernetes/pkg/util/sets\"\n+\t\"k8s.io/test-infra/prow/github\"\n+\t\"k8s.io/test-infra/prow/plugins\"\n+)\n+\n+const pluginName = \"label\"\n+\n+var (\n+\tlabelRegex       = regexp.MustCompile(`(?m)^/(area|priority|kind)\\s*(.*)$`)\n+\tsigMatcher       = regexp.MustCompile(`(?m)@sig-([\\w-]*)-(?:misc|test-failures|bugs|feature-requests|proposals|pr-reviews|api-reviews)`)\n+\tnonExistentLabel = \"These labels do not exist in this repository: `%v`\"\n+\tlabelFailed      = \"The following labels: %v could not be added to this issue\"\n+)\n+\n+func init() {\n+\tplugins.RegisterIssueCommentHandler(pluginName, handleIssueComment)\n+}\n+\n+type githubClient interface {\n+\tCreateComment(owner, repo string, number int, comment string) error\n+\tIsMember(org, user string) (bool, error)\n+\tAddLabel(owner, repo string, number int, label string) error\n+\tGetLabels(owner, repo string) ([]string, error)\n+\tBotName() string\n+}\n+\n+func handleIssueComment(pc plugins.PluginClient, ic github.IssueCommentEvent) error {\n+\treturn handle(pc.GitHubClient, pc.Logger, ic)\n+}\n+\n+func handle(gc githubClient, log *logrus.Entry, ic github.IssueCommentEvent) error {\n+\tcommenter := ic.Comment.User.Login\n+\towner := ic.Repo.Owner.Name\n+\trepo := ic.Repo.Name\n+\tnumber := ic.Issue.Number\n+\n+\t// only parse newly created comments and if non bot author\n+\tif commenter == gc.BotName() || ic.Action != \"created\" {\n+\t\treturn nil\n+\t}\n+\n+\tlabelMatches := labelRegex.FindAllStringSubmatch(ic.Comment.Body, -1)\n+\tsigMatches := sigMatcher.FindAllStringSubmatch(ic.Comment.Body, -1)\n+\tif len(labelMatches) == 0 && len(sigMatches) == 0 {\n+\t\treturn nil\n+\t}\n+\n+\tmember, err := gc.IsMember(owner, commenter)\n+\tif err != nil {\n+\t\treturn fmt.Errorf(\"IsMember failed: %v\", err)\n+\t}\n+\tif !member {\n+\t\treturn gc.CreateComment(owner, repo, number, plugins.FormatResponse(ic.Comment, \"Only kubernetes org members can add labels.\"))\n+\t}\n+\n+\tlabels, err := gc.GetLabels(owner, repo)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\texistingLabels := sets.NewString(labels...)","path":"prow/plugins/label/label.go","position":85,"original_position":85,"commit_id":"d6352b9414c238c901b2a144321a8d64d7042980","original_commit_id":"d6352b9414c238c901b2a144321a8d64d7042980","user":{"login":"spxtr","id":7368979,"avatar_url":"https://avatars1.githubusercontent.com/u/7368979?v=3","gravatar_id":"","url":"https://api.github.com/users/spxtr","html_url":"https://github.com/spxtr","followers_url":"https://api.github.com/users/spxtr/followers","following_url":"https://api.github.com/users/spxtr/following{/other_user}","gists_url":"https://api.github.com/users/spxtr/gists{/gist_id}","starred_url":"https://api.github.com/users/spxtr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spxtr/subscriptions","organizations_url":"https://api.github.com/users/spxtr/orgs","repos_url":"https://api.github.com/users/spxtr/repos","events_url":"https://api.github.com/users/spxtr/events{/privacy}","received_events_url":"https://api.github.com/users/spxtr/received_events","type":"User","site_admin":false},"body":"```go\r\nexistingLabels := map[string]bool{}\r\nfor _, l := range labels {\r\n    existingLabels[l] = true\r\n}\r\n```\r\nAnd then instead of\r\n```go\r\nif !existingLabels.Has(newLabel) {\r\n```\r\nuse\r\n```go\r\nif !existingLabels[newLabel] {\r\n```","created_at":"2017-03-15T17:17:48Z","updated_at":"2017-03-15T17:37:43Z","html_url":"https://github.com/kubernetes/test-infra/pull/2023#discussion_r106227981","pull_request_url":"https://api.github.com/repos/kubernetes/test-infra/pulls/2023","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/test-infra/pulls/comments/106227981"},"html":{"href":"https://github.com/kubernetes/test-infra/pull/2023#discussion_r106227981"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/test-infra/pulls/2023"}}},"pull_request":{"url":"https://api.github.com/repos/kubernetes/test-infra/pulls/2023","id":107917700,"html_url":"https://github.com/kubernetes/test-infra/pull/2023","diff_url":"https://github.com/kubernetes/test-infra/pull/2023.diff","patch_url":"https://github.com/kubernetes/test-infra/pull/2023.patch","issue_url":"https://api.github.com/repos/kubernetes/test-infra/issues/2023","number":2023,"state":"open","locked":false,"title":"Allow people to add routing labels with commands","user":{"login":"grodrigues3","id":4854198,"avatar_url":"https://avatars2.githubusercontent.com/u/4854198?v=3","gravatar_id":"","url":"https://api.github.com/users/grodrigues3","html_url":"https://github.com/grodrigues3","followers_url":"https://api.github.com/users/grodrigues3/followers","following_url":"https://api.github.com/users/grodrigues3/following{/other_user}","gists_url":"https://api.github.com/users/grodrigues3/gists{/gist_id}","starred_url":"https://api.github.com/users/grodrigues3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grodrigues3/subscriptions","organizations_url":"https://api.github.com/users/grodrigues3/orgs","repos_url":"https://api.github.com/users/grodrigues3/repos","events_url":"https://api.github.com/users/grodrigues3/events{/privacy}","received_events_url":"https://api.github.com/users/grodrigues3/received_events","type":"User","site_admin":false},"body":"I'm open to changing the command name but does the functionality and design sound okay.\r\n\r\nAs currently implemented you could type\r\n\r\n/label sig-testing sig-network area/kubelet \r\n\r\nAnd all of those labels would be added.","created_at":"2017-02-24T22:04:25Z","updated_at":"2017-03-15T17:37:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"72a6bd18f6a8b51bbfe19a700a3b858e652c5536","assignee":{"login":"apelisse","id":1929644,"avatar_url":"https://avatars3.githubusercontent.com/u/1929644?v=3","gravatar_id":"","url":"https://api.github.com/users/apelisse","html_url":"https://github.com/apelisse","followers_url":"https://api.github.com/users/apelisse/followers","following_url":"https://api.github.com/users/apelisse/following{/other_user}","gists_url":"https://api.github.com/users/apelisse/gists{/gist_id}","starred_url":"https://api.github.com/users/apelisse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apelisse/subscriptions","organizations_url":"https://api.github.com/users/apelisse/orgs","repos_url":"https://api.github.com/users/apelisse/repos","events_url":"https://api.github.com/users/apelisse/events{/privacy}","received_events_url":"https://api.github.com/users/apelisse/received_events","type":"User","site_admin":false},"assignees":[{"login":"apelisse","id":1929644,"avatar_url":"https://avatars3.githubusercontent.com/u/1929644?v=3","gravatar_id":"","url":"https://api.github.com/users/apelisse","html_url":"https://github.com/apelisse","followers_url":"https://api.github.com/users/apelisse/followers","following_url":"https://api.github.com/users/apelisse/following{/other_user}","gists_url":"https://api.github.com/users/apelisse/gists{/gist_id}","starred_url":"https://api.github.com/users/apelisse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apelisse/subscriptions","organizations_url":"https://api.github.com/users/apelisse/orgs","repos_url":"https://api.github.com/users/apelisse/repos","events_url":"https://api.github.com/users/apelisse/events{/privacy}","received_events_url":"https://api.github.com/users/apelisse/received_events","type":"User","site_admin":false},{"login":"spxtr","id":7368979,"avatar_url":"https://avatars1.githubusercontent.com/u/7368979?v=3","gravatar_id":"","url":"https://api.github.com/users/spxtr","html_url":"https://github.com/spxtr","followers_url":"https://api.github.com/users/spxtr/followers","following_url":"https://api.github.com/users/spxtr/following{/other_user}","gists_url":"https://api.github.com/users/spxtr/gists{/gist_id}","starred_url":"https://api.github.com/users/spxtr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spxtr/subscriptions","organizations_url":"https://api.github.com/users/spxtr/orgs","repos_url":"https://api.github.com/users/spxtr/repos","events_url":"https://api.github.com/users/spxtr/events{/privacy}","received_events_url":"https://api.github.com/users/spxtr/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/test-infra/pulls/2023/commits","review_comments_url":"https://api.github.com/repos/kubernetes/test-infra/pulls/2023/comments","review_comment_url":"https://api.github.com/repos/kubernetes/test-infra/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/test-infra/issues/2023/comments","statuses_url":"https://api.github.com/repos/kubernetes/test-infra/statuses/d6352b9414c238c901b2a144321a8d64d7042980","head":{"label":"grodrigues3:add-label-adding-command-prow","ref":"add-label-adding-command-prow","sha":"d6352b9414c238c901b2a144321a8d64d7042980","user":{"login":"grodrigues3","id":4854198,"avatar_url":"https://avatars2.githubusercontent.com/u/4854198?v=3","gravatar_id":"","url":"https://api.github.com/users/grodrigues3","html_url":"https://github.com/grodrigues3","followers_url":"https://api.github.com/users/grodrigues3/followers","following_url":"https://api.github.com/users/grodrigues3/following{/other_user}","gists_url":"https://api.github.com/users/grodrigues3/gists{/gist_id}","starred_url":"https://api.github.com/users/grodrigues3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grodrigues3/subscriptions","organizations_url":"https://api.github.com/users/grodrigues3/orgs","repos_url":"https://api.github.com/users/grodrigues3/repos","events_url":"https://api.github.com/users/grodrigues3/events{/privacy}","received_events_url":"https://api.github.com/users/grodrigues3/received_events","type":"User","site_admin":false},"repo":{"id":67077512,"name":"test-infra","full_name":"grodrigues3/test-infra","owner":{"login":"grodrigues3","id":4854198,"avatar_url":"https://avatars2.githubusercontent.com/u/4854198?v=3","gravatar_id":"","url":"https://api.github.com/users/grodrigues3","html_url":"https://github.com/grodrigues3","followers_url":"https://api.github.com/users/grodrigues3/followers","following_url":"https://api.github.com/users/grodrigues3/following{/other_user}","gists_url":"https://api.github.com/users/grodrigues3/gists{/gist_id}","starred_url":"https://api.github.com/users/grodrigues3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grodrigues3/subscriptions","organizations_url":"https://api.github.com/users/grodrigues3/orgs","repos_url":"https://api.github.com/users/grodrigues3/repos","events_url":"https://api.github.com/users/grodrigues3/events{/privacy}","received_events_url":"https://api.github.com/users/grodrigues3/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/grodrigues3/test-infra","description":"Test infrastructure for the Kubernetes project.","fork":true,"url":"https://api.github.com/repos/grodrigues3/test-infra","forks_url":"https://api.github.com/repos/grodrigues3/test-infra/forks","keys_url":"https://api.github.com/repos/grodrigues3/test-infra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grodrigues3/test-infra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grodrigues3/test-infra/teams","hooks_url":"https://api.github.com/repos/grodrigues3/test-infra/hooks","issue_events_url":"https://api.github.com/repos/grodrigues3/test-infra/issues/events{/number}","events_url":"https://api.github.com/repos/grodrigues3/test-infra/events","assignees_url":"https://api.github.com/repos/grodrigues3/test-infra/assignees{/user}","branches_url":"https://api.github.com/repos/grodrigues3/test-infra/branches{/branch}","tags_url":"https://api.github.com/repos/grodrigues3/test-infra/tags","blobs_url":"https://api.github.com/repos/grodrigues3/test-infra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grodrigues3/test-infra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grodrigues3/test-infra/git/refs{/sha}","trees_url":"https://api.github.com/repos/grodrigues3/test-infra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grodrigues3/test-infra/statuses/{sha}","languages_url":"https://api.github.com/repos/grodrigues3/test-infra/languages","stargazers_url":"https://api.github.com/repos/grodrigues3/test-infra/stargazers","contributors_url":"https://api.github.com/repos/grodrigues3/test-infra/contributors","subscribers_url":"https://api.github.com/repos/grodrigues3/test-infra/subscribers","subscription_url":"https://api.github.com/repos/grodrigues3/test-infra/subscription","commits_url":"https://api.github.com/repos/grodrigues3/test-infra/commits{/sha}","git_commits_url":"https://api.github.com/repos/grodrigues3/test-infra/git/commits{/sha}","comments_url":"https://api.github.com/repos/grodrigues3/test-infra/comments{/number}","issue_comment_url":"https://api.github.com/repos/grodrigues3/test-infra/issues/comments{/number}","contents_url":"https://api.github.com/repos/grodrigues3/test-infra/contents/{+path}","compare_url":"https://api.github.com/repos/grodrigues3/test-infra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grodrigues3/test-infra/merges","archive_url":"https://api.github.com/repos/grodrigues3/test-infra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grodrigues3/test-infra/downloads","issues_url":"https://api.github.com/repos/grodrigues3/test-infra/issues{/number}","pulls_url":"https://api.github.com/repos/grodrigues3/test-infra/pulls{/number}","milestones_url":"https://api.github.com/repos/grodrigues3/test-infra/milestones{/number}","notifications_url":"https://api.github.com/repos/grodrigues3/test-infra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grodrigues3/test-infra/labels{/name}","releases_url":"https://api.github.com/repos/grodrigues3/test-infra/releases{/id}","deployments_url":"https://api.github.com/repos/grodrigues3/test-infra/deployments","created_at":"2016-08-31T22:18:27Z","updated_at":"2017-01-23T21:59:09Z","pushed_at":"2017-03-15T16:20:53Z","git_url":"git://github.com/grodrigues3/test-infra.git","ssh_url":"git@github.com:grodrigues3/test-infra.git","clone_url":"https://github.com/grodrigues3/test-infra.git","svn_url":"https://github.com/grodrigues3/test-infra","homepage":null,"size":15605,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kubernetes:master","ref":"master","sha":"9cc4768b776acfc064d18df3358910fe8f188039","user":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars1.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"repo":{"id":57333709,"name":"test-infra","full_name":"kubernetes/test-infra","owner":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars1.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kubernetes/test-infra","description":"Test infrastructure for the Kubernetes project.","fork":false,"url":"https://api.github.com/repos/kubernetes/test-infra","forks_url":"https://api.github.com/repos/kubernetes/test-infra/forks","keys_url":"https://api.github.com/repos/kubernetes/test-infra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kubernetes/test-infra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kubernetes/test-infra/teams","hooks_url":"https://api.github.com/repos/kubernetes/test-infra/hooks","issue_events_url":"https://api.github.com/repos/kubernetes/test-infra/issues/events{/number}","events_url":"https://api.github.com/repos/kubernetes/test-infra/events","assignees_url":"https://api.github.com/repos/kubernetes/test-infra/assignees{/user}","branches_url":"https://api.github.com/repos/kubernetes/test-infra/branches{/branch}","tags_url":"https://api.github.com/repos/kubernetes/test-infra/tags","blobs_url":"https://api.github.com/repos/kubernetes/test-infra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kubernetes/test-infra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kubernetes/test-infra/git/refs{/sha}","trees_url":"https://api.github.com/repos/kubernetes/test-infra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kubernetes/test-infra/statuses/{sha}","languages_url":"https://api.github.com/repos/kubernetes/test-infra/languages","stargazers_url":"https://api.github.com/repos/kubernetes/test-infra/stargazers","contributors_url":"https://api.github.com/repos/kubernetes/test-infra/contributors","subscribers_url":"https://api.github.com/repos/kubernetes/test-infra/subscribers","subscription_url":"https://api.github.com/repos/kubernetes/test-infra/subscription","commits_url":"https://api.github.com/repos/kubernetes/test-infra/commits{/sha}","git_commits_url":"https://api.github.com/repos/kubernetes/test-infra/git/commits{/sha}","comments_url":"https://api.github.com/repos/kubernetes/test-infra/comments{/number}","issue_comment_url":"https://api.github.com/repos/kubernetes/test-infra/issues/comments{/number}","contents_url":"https://api.github.com/repos/kubernetes/test-infra/contents/{+path}","compare_url":"https://api.github.com/repos/kubernetes/test-infra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kubernetes/test-infra/merges","archive_url":"https://api.github.com/repos/kubernetes/test-infra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kubernetes/test-infra/downloads","issues_url":"https://api.github.com/repos/kubernetes/test-infra/issues{/number}","pulls_url":"https://api.github.com/repos/kubernetes/test-infra/pulls{/number}","milestones_url":"https://api.github.com/repos/kubernetes/test-infra/milestones{/number}","notifications_url":"https://api.github.com/repos/kubernetes/test-infra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kubernetes/test-infra/labels{/name}","releases_url":"https://api.github.com/repos/kubernetes/test-infra/releases{/id}","deployments_url":"https://api.github.com/repos/kubernetes/test-infra/deployments","created_at":"2016-04-28T21:05:35Z","updated_at":"2017-03-10T03:03:49Z","pushed_at":"2017-03-15T16:35:08Z","git_url":"git://github.com/kubernetes/test-infra.git","ssh_url":"git@github.com:kubernetes/test-infra.git","clone_url":"https://github.com/kubernetes/test-infra.git","svn_url":"https://github.com/kubernetes/test-infra","homepage":null,"size":16393,"stargazers_count":62,"watchers_count":62,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":113,"mirror_url":null,"open_issues_count":172,"forks":113,"open_issues":172,"watchers":62,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/test-infra/pulls/2023"},"html":{"href":"https://github.com/kubernetes/test-infra/pull/2023"},"issue":{"href":"https://api.github.com/repos/kubernetes/test-infra/issues/2023"},"comments":{"href":"https://api.github.com/repos/kubernetes/test-infra/issues/2023/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/test-infra/pulls/2023/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/test-infra/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/test-infra/pulls/2023/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/test-infra/statuses/d6352b9414c238c901b2a144321a8d64d7042980"}}}}
{"actor":{"display_login":"spxtr"}}