{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/beats/pulls/comments/92770307","pull_request_review_id":13290467,"id":92770307,"diff_hunk":"@@ -1,20 +1,41 @@\n #!/usr/bin/env python\n import os\n+import re\n import argparse\n \n-pattern = '''const defaultBeatVersion = \"'''\n+pattern = re.compile(r'(const\\s|)\\w*(v|V)ersion\\s=\\s\"(?P<version>.*)\"')\n+vendored_libbeat = os.path.normpath(\"vendor/github.com/elastic/beats\")\n+\n+\n+def get_filepath(filename):\n+    script_directory = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))\n+    index = script_directory.find(vendored_libbeat)\n+    if index > 0:\n+        # Community beat detected\n+        filename = os.path.join(script_directory[:index], filename)\n+        if os.path.exists(filename):\n+            return filename # Community beat version exists\n+    return  os.path.abspath(os.path.join(script_directory, os.pardir, \"libbeat\",\"beat\",\"version.go\"))\n \n \n def main():\n     parser = argparse.ArgumentParser(\n         description=\"Prints the current version at stdout.\")\n-    parser.parse_args()\n+    args = parser.parse_args()\n+\n+    goversion_filepath = get_filepath(\"version.go\")\n+\n+    try:\n+        with open(goversion_filepath, \"r\") as f:\n+            for line in f:\n+                match = pattern.match(line)\n+                if match:\n+                    print(match.group('version'))\n+                    return\n+            print (\"No version found in file {}\".format(goversion_filepath))\n+    except:\n+        print (\"Can't read file {}\".format(goversion_filepath))","path":"dev-tools/get_version","position":39,"original_position":39,"commit_id":"9d5899209bf5755657c11124584c1edd132da61c","original_commit_id":"502b352a5cef1a02fdd0480372fccc4d4a96eec2","user":{"login":"cyrilleverrier","id":16701739,"avatar_url":"https://avatars.githubusercontent.com/u/16701739?v=3","gravatar_id":"","url":"https://api.github.com/users/cyrilleverrier","html_url":"https://github.com/cyrilleverrier","followers_url":"https://api.github.com/users/cyrilleverrier/followers","following_url":"https://api.github.com/users/cyrilleverrier/following{/other_user}","gists_url":"https://api.github.com/users/cyrilleverrier/gists{/gist_id}","starred_url":"https://api.github.com/users/cyrilleverrier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyrilleverrier/subscriptions","organizations_url":"https://api.github.com/users/cyrilleverrier/orgs","repos_url":"https://api.github.com/users/cyrilleverrier/repos","events_url":"https://api.github.com/users/cyrilleverrier/events{/privacy}","received_events_url":"https://api.github.com/users/cyrilleverrier/received_events","type":"User","site_admin":false},"body":"I cleaned the code. See 9d58992\r\n","created_at":"2016-12-16T08:28:06Z","updated_at":"2016-12-16T08:28:06Z","html_url":"https://github.com/elastic/beats/pull/3203#discussion_r92770307","pull_request_url":"https://api.github.com/repos/elastic/beats/pulls/3203","_links":{"self":{"href":"https://api.github.com/repos/elastic/beats/pulls/comments/92770307"},"html":{"href":"https://github.com/elastic/beats/pull/3203#discussion_r92770307"},"pull_request":{"href":"https://api.github.com/repos/elastic/beats/pulls/3203"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/beats/pulls/3203","id":98173038,"html_url":"https://github.com/elastic/beats/pull/3203","diff_url":"https://github.com/elastic/beats/pull/3203.diff","patch_url":"https://github.com/elastic/beats/pull/3203.patch","issue_url":"https://api.github.com/repos/elastic/beats/issues/3203","number":3203,"state":"open","locked":false,"title":"Community beat can set/get their own version","user":{"login":"cyrilleverrier","id":16701739,"avatar_url":"https://avatars.githubusercontent.com/u/16701739?v=3","gravatar_id":"","url":"https://api.github.com/users/cyrilleverrier","html_url":"https://github.com/cyrilleverrier","followers_url":"https://api.github.com/users/cyrilleverrier/followers","following_url":"https://api.github.com/users/cyrilleverrier/following{/other_user}","gists_url":"https://api.github.com/users/cyrilleverrier/gists{/gist_id}","starred_url":"https://api.github.com/users/cyrilleverrier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyrilleverrier/subscriptions","organizations_url":"https://api.github.com/users/cyrilleverrier/orgs","repos_url":"https://api.github.com/users/cyrilleverrier/repos","events_url":"https://api.github.com/users/cyrilleverrier/events{/privacy}","received_events_url":"https://api.github.com/users/cyrilleverrier/received_events","type":"User","site_admin":false},"body":"By default, community beats have the same version as libbeat.\r\n\r\nUsage\r\n=====\r\n\r\nset version\r\n-----------\r\nthe version number can be set with the following command:\r\n     `make set_version VERSION=0.1.0-alpha1`\r\n\r\nthe script writes `version.go` and `version.yml` files at the root folder of the community beat project.\r\n\r\nget version\r\n -----------\r\n the version number can be retrieved with the following command:\r\n       `make get_version`\r\n\r\nTest community beat\r\n===\r\n```\r\n           examplebeat $ make make get_version\r\n           6.0.0-alpha1\r\n\r\n           examplebeat $ make set_version VERSION=1.0.0\r\n           ./vendor/github.com/elastic/beats/dev-tools/set_version 1.0.0\r\n           Set version 1.0.0 in file /home/cyrille/code/go/workspace/src/github.com/cyrille/examplebeat/version.go\r\n           Set version 1.0.0 in file /home/cyrille/code/go/workspace/src/github.com/cyrille/examplebeat/version.yml\r\n\r\n           examplebeat $ make get_version\r\n           1.0.0\r\n\r\n           examplebeat $ make package\r\n           ....\r\n\r\n           examplebeat $ ./build/examplebeat-linux-amd64 -version\r\n           examplebeat version 1.0.0 (amd64), 6.0.0-alpha1\r\n\r\n           examplebeat $ rpm -qip build/upload/examplebeat-1.0.0-SNAPSHOT-i686.rpm\r\n           Name        : examplebeat\r\n           Version     : 1.0.0_alpha1_SNAPSHOT\r\n```\r\n\r\nTest libbeat\r\n============\r\n\r\n```\r\n           beats $ ./dev-tools/get_version\r\n           6.0.0-alpha1\r\n\r\n           beats $ ./dev-tools/set_version 6.0.0-alpha2\r\n           Set version 6.0.0-alpha2 in file /home/cyrille/code/go/workspace/src/github.com/elastic/beats/libbeat/beat/version.go\r\n           Set version 6.0.0-alpha2 in file /home/cyrille/code/go/workspace/src/github.com/elastic/beats/dev-tools/packer/version.yml\r\n\r\n           beats $ cat cat libbeat/beat/version.go\r\n           package beat\r\n\r\n           const defaultBeatVersion = \"6.0.0-alpha2\"\r\n```","created_at":"2016-12-15T15:34:42Z","updated_at":"2016-12-16T08:28:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"678950fe7e6baf0cd5d17496963d18fc6073edb3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/beats/pulls/3203/commits","review_comments_url":"https://api.github.com/repos/elastic/beats/pulls/3203/comments","review_comment_url":"https://api.github.com/repos/elastic/beats/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/beats/issues/3203/comments","statuses_url":"https://api.github.com/repos/elastic/beats/statuses/9d5899209bf5755657c11124584c1edd132da61c","head":{"label":"cyrilleverrier:packer_versionning_simpler","ref":"packer_versionning_simpler","sha":"9d5899209bf5755657c11124584c1edd132da61c","user":{"login":"cyrilleverrier","id":16701739,"avatar_url":"https://avatars.githubusercontent.com/u/16701739?v=3","gravatar_id":"","url":"https://api.github.com/users/cyrilleverrier","html_url":"https://github.com/cyrilleverrier","followers_url":"https://api.github.com/users/cyrilleverrier/followers","following_url":"https://api.github.com/users/cyrilleverrier/following{/other_user}","gists_url":"https://api.github.com/users/cyrilleverrier/gists{/gist_id}","starred_url":"https://api.github.com/users/cyrilleverrier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyrilleverrier/subscriptions","organizations_url":"https://api.github.com/users/cyrilleverrier/orgs","repos_url":"https://api.github.com/users/cyrilleverrier/repos","events_url":"https://api.github.com/users/cyrilleverrier/events{/privacy}","received_events_url":"https://api.github.com/users/cyrilleverrier/received_events","type":"User","site_admin":false},"repo":{"id":49642039,"name":"beats","full_name":"cyrilleverrier/beats","owner":{"login":"cyrilleverrier","id":16701739,"avatar_url":"https://avatars.githubusercontent.com/u/16701739?v=3","gravatar_id":"","url":"https://api.github.com/users/cyrilleverrier","html_url":"https://github.com/cyrilleverrier","followers_url":"https://api.github.com/users/cyrilleverrier/followers","following_url":"https://api.github.com/users/cyrilleverrier/following{/other_user}","gists_url":"https://api.github.com/users/cyrilleverrier/gists{/gist_id}","starred_url":"https://api.github.com/users/cyrilleverrier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyrilleverrier/subscriptions","organizations_url":"https://api.github.com/users/cyrilleverrier/orgs","repos_url":"https://api.github.com/users/cyrilleverrier/repos","events_url":"https://api.github.com/users/cyrilleverrier/events{/privacy}","received_events_url":"https://api.github.com/users/cyrilleverrier/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cyrilleverrier/beats","description":"Beats - Lightweight shippers for Elasticsearch & Logstash ","fork":true,"url":"https://api.github.com/repos/cyrilleverrier/beats","forks_url":"https://api.github.com/repos/cyrilleverrier/beats/forks","keys_url":"https://api.github.com/repos/cyrilleverrier/beats/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cyrilleverrier/beats/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cyrilleverrier/beats/teams","hooks_url":"https://api.github.com/repos/cyrilleverrier/beats/hooks","issue_events_url":"https://api.github.com/repos/cyrilleverrier/beats/issues/events{/number}","events_url":"https://api.github.com/repos/cyrilleverrier/beats/events","assignees_url":"https://api.github.com/repos/cyrilleverrier/beats/assignees{/user}","branches_url":"https://api.github.com/repos/cyrilleverrier/beats/branches{/branch}","tags_url":"https://api.github.com/repos/cyrilleverrier/beats/tags","blobs_url":"https://api.github.com/repos/cyrilleverrier/beats/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cyrilleverrier/beats/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cyrilleverrier/beats/git/refs{/sha}","trees_url":"https://api.github.com/repos/cyrilleverrier/beats/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cyrilleverrier/beats/statuses/{sha}","languages_url":"https://api.github.com/repos/cyrilleverrier/beats/languages","stargazers_url":"https://api.github.com/repos/cyrilleverrier/beats/stargazers","contributors_url":"https://api.github.com/repos/cyrilleverrier/beats/contributors","subscribers_url":"https://api.github.com/repos/cyrilleverrier/beats/subscribers","subscription_url":"https://api.github.com/repos/cyrilleverrier/beats/subscription","commits_url":"https://api.github.com/repos/cyrilleverrier/beats/commits{/sha}","git_commits_url":"https://api.github.com/repos/cyrilleverrier/beats/git/commits{/sha}","comments_url":"https://api.github.com/repos/cyrilleverrier/beats/comments{/number}","issue_comment_url":"https://api.github.com/repos/cyrilleverrier/beats/issues/comments{/number}","contents_url":"https://api.github.com/repos/cyrilleverrier/beats/contents/{+path}","compare_url":"https://api.github.com/repos/cyrilleverrier/beats/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cyrilleverrier/beats/merges","archive_url":"https://api.github.com/repos/cyrilleverrier/beats/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cyrilleverrier/beats/downloads","issues_url":"https://api.github.com/repos/cyrilleverrier/beats/issues{/number}","pulls_url":"https://api.github.com/repos/cyrilleverrier/beats/pulls{/number}","milestones_url":"https://api.github.com/repos/cyrilleverrier/beats/milestones{/number}","notifications_url":"https://api.github.com/repos/cyrilleverrier/beats/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cyrilleverrier/beats/labels{/name}","releases_url":"https://api.github.com/repos/cyrilleverrier/beats/releases{/id}","deployments_url":"https://api.github.com/repos/cyrilleverrier/beats/deployments","created_at":"2016-01-14T11:02:01Z","updated_at":"2016-01-14T11:02:03Z","pushed_at":"2016-12-16T08:19:20Z","git_url":"git://github.com/cyrilleverrier/beats.git","ssh_url":"git@github.com:cyrilleverrier/beats.git","clone_url":"https://github.com/cyrilleverrier/beats.git","svn_url":"https://github.com/cyrilleverrier/beats","homepage":"https://www.elastic.co/products/beats","size":43499,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"elastic:master","ref":"master","sha":"241df11fc67d707edce99a02e55d3291680bc595","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":16554739,"name":"beats","full_name":"elastic/beats","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/beats","description":":tropical_fish: Beats - Lightweight shippers for Elasticsearch & Logstash ","fork":false,"url":"https://api.github.com/repos/elastic/beats","forks_url":"https://api.github.com/repos/elastic/beats/forks","keys_url":"https://api.github.com/repos/elastic/beats/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/beats/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/beats/teams","hooks_url":"https://api.github.com/repos/elastic/beats/hooks","issue_events_url":"https://api.github.com/repos/elastic/beats/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/beats/events","assignees_url":"https://api.github.com/repos/elastic/beats/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/beats/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/beats/tags","blobs_url":"https://api.github.com/repos/elastic/beats/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/beats/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/beats/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/beats/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/beats/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/beats/languages","stargazers_url":"https://api.github.com/repos/elastic/beats/stargazers","contributors_url":"https://api.github.com/repos/elastic/beats/contributors","subscribers_url":"https://api.github.com/repos/elastic/beats/subscribers","subscription_url":"https://api.github.com/repos/elastic/beats/subscription","commits_url":"https://api.github.com/repos/elastic/beats/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/beats/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/beats/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/beats/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/beats/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/beats/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/beats/merges","archive_url":"https://api.github.com/repos/elastic/beats/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/beats/downloads","issues_url":"https://api.github.com/repos/elastic/beats/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/beats/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/beats/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/beats/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/beats/labels{/name}","releases_url":"https://api.github.com/repos/elastic/beats/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/beats/deployments","created_at":"2014-02-05T19:01:02Z","updated_at":"2016-12-16T06:38:32Z","pushed_at":"2016-12-16T08:19:22Z","git_url":"git://github.com/elastic/beats.git","ssh_url":"git@github.com:elastic/beats.git","clone_url":"https://github.com/elastic/beats.git","svn_url":"https://github.com/elastic/beats","homepage":"https://www.elastic.co/products/beats","size":44424,"stargazers_count":3488,"watchers_count":3488,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":680,"mirror_url":null,"open_issues_count":322,"forks":680,"open_issues":322,"watchers":3488,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/beats/pulls/3203"},"html":{"href":"https://github.com/elastic/beats/pull/3203"},"issue":{"href":"https://api.github.com/repos/elastic/beats/issues/3203"},"comments":{"href":"https://api.github.com/repos/elastic/beats/issues/3203/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/beats/pulls/3203/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/beats/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/beats/pulls/3203/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/beats/statuses/9d5899209bf5755657c11124584c1edd132da61c"}}}}
{"actor":{"display_login":"cyrilleverrier"}}