{"action":"created","comment":{"url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/comments/218898605","pull_request_review_id":156932513,"id":218898605,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxODg5ODYwNQ==","diff_hunk":"@@ -0,0 +1,200 @@\n+;;; -*- lexical-binding: t; -*-\n+;;\n+;;; bazel-build.el --- Emacs utilities for using Bazel\n+;;\n+;; Copyright (C) 2018 Google LLC\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+;;; Commentary:\n+;;\n+;; This package provides commands to build and run code using Bazel.\n+;; It defines interactive commands `bazel-build' and `bazel-run' which\n+;; perform completion of available Bazel targets.\n+;;\n+;;; Code:\n+\n+(require 'cl-lib)\n+\n+(defun bazel-build ()\n+  \"Find and build a Bazel target.\"\n+  (interactive)\n+  (bazel-build--run-bazel-command \"build\"))\n+\n+(defun bazel-run ()\n+  \"Find and run a Bazel target.\"\n+  (interactive)\n+  (bazel-build--run-bazel-command \"run\"))\n+\n+(defun bazel-test ()\n+  \"Find and run a Bazel test target.\"\n+  (interactive)\n+  (bazel-build--run-bazel-command \"test\"))\n+\n+(defun bazel-build--run-bazel-command (command)\n+  \"Run Bazel tool with given COMMAND, e.g. build or run.\"\n+  (let* ((file-name (buffer-file-name))\n+         (workspace-root (bazel-build--find-workspace-root file-name))\n+         (initial-input (bazel-build--suggest-initial-input file-name workspace-root))\n+         (target (completing-read\n+\t\t\t\t  (format \"bazel %s \" command) ; prompt\n+                  #'bazel-build--completions   ; collection\n+                  nil                          ; predicate\n+                  nil                          ; require-match\n+                  initial-input)))             ; initial-input\n+\t(compile\n+\t (mapconcat #'shell-quote-argument (list \"bazel\" command target) \" \"))))\n+\n+(defun bazel-build--find-workspace-root (file-name)\n+  \"Find the root of the Bazel workspace containing FILE-NAME.\"\n+  (let ((workspace-root (locate-dominating-file file-name \"WORKSPACE\")))\n+    (if workspace-root (expand-file-name workspace-root)\n+      (error \"Not in a Bazel workspace\"))))\n+\n+(defun bazel-build--suggest-initial-input (file-name workspace-root)\n+  \"Suggest initial input to the interactive completion.\n+FILE-NAME is the file-name of the current buffer.  WORKSPACE-ROOT is\n+the root of the Bazel workspace.\"\n+  (concat \"//\" (directory-file-name (bazel-build--extract-package-name file-name workspace-root))))\n+\n+(defconst bazel-build--recognized-build-file-names\n+  '(\"BUILD.bazel\" \"BUILD\")\n+  \"Names files Bazel will look in to find build rules.\")\n+\n+(defun bazel-build--extract-package-name (file-name workspace-root)\n+  \"Extract the nearest Bazel package for FILE-NAME under WORKSPACE-ROOT.\"\n+  (file-relative-name\n+   (expand-file-name\n+\t(or\n+\t (cl-some\n+\t  (lambda (build-name) (locate-dominating-file file-name build-name)) bazel-build--recognized-build-file-names)\n+\t workspace-root))\n+   workspace-root))\n+\n+(defun bazel-build--completions (string pred mode)\n+  \"Programmed completion for arguments to 'bazel-build', 'bazel-run', etc.\n+STRING is the string to be completed by this rule.  PRED is a\n+predicate which may be used to filter possible completions.  MODE\n+specifies the completion mode.\"\n+  (let* ((string-split (bazel-build--extract-special-prefix string))","path":"bazel-build.el","position":88,"original_position":88,"commit_id":"e8ed8eeebf89924da3045105a20f945a2cbfb425","original_commit_id":"e8ed8eeebf89924da3045105a20f945a2cbfb425","user":{"login":"phst","id":398701,"node_id":"MDQ6VXNlcjM5ODcwMQ==","avatar_url":"https://avatars0.githubusercontent.com/u/398701?v=4","gravatar_id":"","url":"https://api.github.com/users/phst","html_url":"https://github.com/phst","followers_url":"https://api.github.com/users/phst/followers","following_url":"https://api.github.com/users/phst/following{/other_user}","gists_url":"https://api.github.com/users/phst/gists{/gist_id}","starred_url":"https://api.github.com/users/phst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phst/subscriptions","organizations_url":"https://api.github.com/users/phst/orgs","repos_url":"https://api.github.com/users/phst/repos","events_url":"https://api.github.com/users/phst/events{/privacy}","received_events_url":"https://api.github.com/users/phst/received_events","type":"User","site_admin":false},"body":"It might be helpful to inline a few of the helper functions and restructure the code to make it easier to read. IIUC, what you want is something like \"if the user entered something starting with //, then complete package names, else complete targets starting from the current package\". I guess this is what the code implements, but it's hard to tell.","created_at":"2018-09-19T17:41:13Z","updated_at":"2018-09-19T17:41:21Z","html_url":"https://github.com/bazelbuild/emacs-bazel-mode/pull/4#discussion_r218898605","pull_request_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/4","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/comments/218898605"},"html":{"href":"https://github.com/bazelbuild/emacs-bazel-mode/pull/4#discussion_r218898605"},"pull_request":{"href":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/4","id":208474549,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA4NDc0NTQ5","html_url":"https://github.com/bazelbuild/emacs-bazel-mode/pull/4","diff_url":"https://github.com/bazelbuild/emacs-bazel-mode/pull/4.diff","patch_url":"https://github.com/bazelbuild/emacs-bazel-mode/pull/4.patch","issue_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/issues/4","number":4,"state":"open","locked":false,"title":"Adding bazel-build.el","user":{"login":"tautomaton","id":22972019,"node_id":"MDQ6VXNlcjIyOTcyMDE5","avatar_url":"https://avatars0.githubusercontent.com/u/22972019?v=4","gravatar_id":"","url":"https://api.github.com/users/tautomaton","html_url":"https://github.com/tautomaton","followers_url":"https://api.github.com/users/tautomaton/followers","following_url":"https://api.github.com/users/tautomaton/following{/other_user}","gists_url":"https://api.github.com/users/tautomaton/gists{/gist_id}","starred_url":"https://api.github.com/users/tautomaton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tautomaton/subscriptions","organizations_url":"https://api.github.com/users/tautomaton/orgs","repos_url":"https://api.github.com/users/tautomaton/repos","events_url":"https://api.github.com/users/tautomaton/events{/privacy}","received_events_url":"https://api.github.com/users/tautomaton/received_events","type":"User","site_admin":false},"body":"bazel-build adds functionality around building Bazel rules and autocompleting rule names. One uses it via M-x bazel-build from a buffer editing a file within a Bazel workspace.","created_at":"2018-08-15T05:13:35Z","updated_at":"2018-09-19T17:41:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"04f1b89ba7f9ef6d25c717f435885d148f02c524","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/4/commits","review_comments_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/4/comments","review_comment_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/issues/4/comments","statuses_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/statuses/e8ed8eeebf89924da3045105a20f945a2cbfb425","head":{"label":"tautomaton:bazel-build","ref":"bazel-build","sha":"e8ed8eeebf89924da3045105a20f945a2cbfb425","user":{"login":"tautomaton","id":22972019,"node_id":"MDQ6VXNlcjIyOTcyMDE5","avatar_url":"https://avatars0.githubusercontent.com/u/22972019?v=4","gravatar_id":"","url":"https://api.github.com/users/tautomaton","html_url":"https://github.com/tautomaton","followers_url":"https://api.github.com/users/tautomaton/followers","following_url":"https://api.github.com/users/tautomaton/following{/other_user}","gists_url":"https://api.github.com/users/tautomaton/gists{/gist_id}","starred_url":"https://api.github.com/users/tautomaton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tautomaton/subscriptions","organizations_url":"https://api.github.com/users/tautomaton/orgs","repos_url":"https://api.github.com/users/tautomaton/repos","events_url":"https://api.github.com/users/tautomaton/events{/privacy}","received_events_url":"https://api.github.com/users/tautomaton/received_events","type":"User","site_admin":false},"repo":{"id":143958277,"node_id":"MDEwOlJlcG9zaXRvcnkxNDM5NTgyNzc=","name":"emacs-bazel-mode","full_name":"tautomaton/emacs-bazel-mode","private":false,"owner":{"login":"tautomaton","id":22972019,"node_id":"MDQ6VXNlcjIyOTcyMDE5","avatar_url":"https://avatars0.githubusercontent.com/u/22972019?v=4","gravatar_id":"","url":"https://api.github.com/users/tautomaton","html_url":"https://github.com/tautomaton","followers_url":"https://api.github.com/users/tautomaton/followers","following_url":"https://api.github.com/users/tautomaton/following{/other_user}","gists_url":"https://api.github.com/users/tautomaton/gists{/gist_id}","starred_url":"https://api.github.com/users/tautomaton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tautomaton/subscriptions","organizations_url":"https://api.github.com/users/tautomaton/orgs","repos_url":"https://api.github.com/users/tautomaton/repos","events_url":"https://api.github.com/users/tautomaton/events{/privacy}","received_events_url":"https://api.github.com/users/tautomaton/received_events","type":"User","site_admin":false},"html_url":"https://github.com/tautomaton/emacs-bazel-mode","description":null,"fork":true,"url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode","forks_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/forks","keys_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/teams","hooks_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/hooks","issue_events_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/issues/events{/number}","events_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/events","assignees_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/assignees{/user}","branches_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/branches{/branch}","tags_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/tags","blobs_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/git/refs{/sha}","trees_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/statuses/{sha}","languages_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/languages","stargazers_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/stargazers","contributors_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/contributors","subscribers_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/subscribers","subscription_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/subscription","commits_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/commits{/sha}","git_commits_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/git/commits{/sha}","comments_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/comments{/number}","issue_comment_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/issues/comments{/number}","contents_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/contents/{+path}","compare_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/merges","archive_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/downloads","issues_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/issues{/number}","pulls_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/pulls{/number}","milestones_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/milestones{/number}","notifications_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/labels{/name}","releases_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/releases{/id}","deployments_url":"https://api.github.com/repos/tautomaton/emacs-bazel-mode/deployments","created_at":"2018-08-08T03:51:41Z","updated_at":"2018-09-16T14:49:48Z","pushed_at":"2018-09-16T15:54:41Z","git_url":"git://github.com/tautomaton/emacs-bazel-mode.git","ssh_url":"git@github.com:tautomaton/emacs-bazel-mode.git","clone_url":"https://github.com/tautomaton/emacs-bazel-mode.git","svn_url":"https://github.com/tautomaton/emacs-bazel-mode","homepage":null,"size":25,"stargazers_count":0,"watchers_count":0,"language":"Emacs Lisp","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bazelbuild:master","ref":"master","sha":"190a35d750a43f36904c42b1a7629755f2642a8c","user":{"login":"bazelbuild","id":11684617,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNjg0NjE3","avatar_url":"https://avatars1.githubusercontent.com/u/11684617?v=4","gravatar_id":"","url":"https://api.github.com/users/bazelbuild","html_url":"https://github.com/bazelbuild","followers_url":"https://api.github.com/users/bazelbuild/followers","following_url":"https://api.github.com/users/bazelbuild/following{/other_user}","gists_url":"https://api.github.com/users/bazelbuild/gists{/gist_id}","starred_url":"https://api.github.com/users/bazelbuild/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bazelbuild/subscriptions","organizations_url":"https://api.github.com/users/bazelbuild/orgs","repos_url":"https://api.github.com/users/bazelbuild/repos","events_url":"https://api.github.com/users/bazelbuild/events{/privacy}","received_events_url":"https://api.github.com/users/bazelbuild/received_events","type":"Organization","site_admin":false},"repo":{"id":141580441,"node_id":"MDEwOlJlcG9zaXRvcnkxNDE1ODA0NDE=","name":"emacs-bazel-mode","full_name":"bazelbuild/emacs-bazel-mode","private":false,"owner":{"login":"bazelbuild","id":11684617,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNjg0NjE3","avatar_url":"https://avatars1.githubusercontent.com/u/11684617?v=4","gravatar_id":"","url":"https://api.github.com/users/bazelbuild","html_url":"https://github.com/bazelbuild","followers_url":"https://api.github.com/users/bazelbuild/followers","following_url":"https://api.github.com/users/bazelbuild/following{/other_user}","gists_url":"https://api.github.com/users/bazelbuild/gists{/gist_id}","starred_url":"https://api.github.com/users/bazelbuild/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bazelbuild/subscriptions","organizations_url":"https://api.github.com/users/bazelbuild/orgs","repos_url":"https://api.github.com/users/bazelbuild/repos","events_url":"https://api.github.com/users/bazelbuild/events{/privacy}","received_events_url":"https://api.github.com/users/bazelbuild/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/bazelbuild/emacs-bazel-mode","description":null,"fork":false,"url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode","forks_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/forks","keys_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/teams","hooks_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/hooks","issue_events_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/issues/events{/number}","events_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/events","assignees_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/assignees{/user}","branches_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/branches{/branch}","tags_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/tags","blobs_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/git/refs{/sha}","trees_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/statuses/{sha}","languages_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/languages","stargazers_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/stargazers","contributors_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/contributors","subscribers_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/subscribers","subscription_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/subscription","commits_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/commits{/sha}","git_commits_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/git/commits{/sha}","comments_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/comments{/number}","issue_comment_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/issues/comments{/number}","contents_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/contents/{+path}","compare_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/merges","archive_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/downloads","issues_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/issues{/number}","pulls_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls{/number}","milestones_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/milestones{/number}","notifications_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/labels{/name}","releases_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/releases{/id}","deployments_url":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/deployments","created_at":"2018-07-19T13:03:03Z","updated_at":"2018-09-17T03:06:03Z","pushed_at":"2018-09-16T15:54:42Z","git_url":"git://github.com/bazelbuild/emacs-bazel-mode.git","ssh_url":"git@github.com:bazelbuild/emacs-bazel-mode.git","clone_url":"https://github.com/bazelbuild/emacs-bazel-mode.git","svn_url":"https://github.com/bazelbuild/emacs-bazel-mode","homepage":null,"size":6,"stargazers_count":9,"watchers_count":9,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":3,"open_issues":3,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/4"},"html":{"href":"https://github.com/bazelbuild/emacs-bazel-mode/pull/4"},"issue":{"href":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/issues/4"},"comments":{"href":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/bazelbuild/emacs-bazel-mode/statuses/e8ed8eeebf89924da3045105a20f945a2cbfb425"}},"author_association":"NONE"}}
{"actor":{"display_login":"phst"}}