{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/63727","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/63727/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/63727/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/63727/events","html_url":"https://github.com/ansible/ansible/pull/63727","id":509644649,"node_id":"MDExOlB1bGxSZXF1ZXN0MzMwMTUyMzUy","number":63727,"title":"Add a lookup plugin to retrieve latest tagged release version from a Github repository","user":{"login":"artis3n","id":6969296,"node_id":"MDQ6VXNlcjY5NjkyOTY=","avatar_url":"https://avatars2.githubusercontent.com/u/6969296?v=4","gravatar_id":"","url":"https://api.github.com/users/artis3n","html_url":"https://github.com/artis3n","followers_url":"https://api.github.com/users/artis3n/followers","following_url":"https://api.github.com/users/artis3n/following{/other_user}","gists_url":"https://api.github.com/users/artis3n/gists{/gist_id}","starred_url":"https://api.github.com/users/artis3n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artis3n/subscriptions","organizations_url":"https://api.github.com/users/artis3n/orgs","repos_url":"https://api.github.com/users/artis3n/repos","events_url":"https://api.github.com/users/artis3n/events{/privacy}","received_events_url":"https://api.github.com/users/artis3n/received_events","type":"User","site_admin":false},"labels":[{"id":1528399399,"node_id":"MDU6TGFiZWwxNTI4Mzk5Mzk5","url":"https://api.github.com/repos/ansible/ansible/labels/affects_2.10","name":"affects_2.10","color":"5319e7","default":false},{"id":61436281,"node_id":"MDU6TGFiZWw2MTQzNjI4MQ==","url":"https://api.github.com/repos/ansible/ansible/labels/needs_revision","name":"needs_revision","color":"eb6450","default":false},{"id":503572087,"node_id":"MDU6TGFiZWw1MDM1NzIwODc=","url":"https://api.github.com/repos/ansible/ansible/labels/needs_triage","name":"needs_triage","color":"0e8a16","default":false},{"id":723150340,"node_id":"MDU6TGFiZWw3MjMxNTAzNDA=","url":"https://api.github.com/repos/ansible/ansible/labels/new_contributor","name":"new_contributor","color":"c2e0c6","default":false},{"id":153577825,"node_id":"MDU6TGFiZWwxNTM1Nzc4MjU=","url":"https://api.github.com/repos/ansible/ansible/labels/new_plugin","name":"new_plugin","color":"bfe5bf","default":false},{"id":383076471,"node_id":"MDU6TGFiZWwzODMwNzY0NzE=","url":"https://api.github.com/repos/ansible/ansible/labels/python3","name":"python3","color":"fbca04","default":false},{"id":636327968,"node_id":"MDU6TGFiZWw2MzYzMjc5Njg=","url":"https://api.github.com/repos/ansible/ansible/labels/support:community","name":"support:community","color":"ededed","default":false},{"id":636352796,"node_id":"MDU6TGFiZWw2MzYzNTI3OTY=","url":"https://api.github.com/repos/ansible/ansible/labels/support:core","name":"support:core","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2019-10-20T20:03:21Z","updated_at":"2019-10-21T04:58:30Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/ansible/ansible/pulls/63727","html_url":"https://github.com/ansible/ansible/pull/63727","diff_url":"https://github.com/ansible/ansible/pull/63727.diff","patch_url":"https://github.com/ansible/ansible/pull/63727.patch"},"body":"##### SUMMARY\r\nA convenience lookup plugin to get the latest tagged release version of a Github repo. If the reviewers agree on getting this into this repo I will add the ability to use a github token in an env var to look up private repo versions.\r\n\r\n##### ISSUE TYPE\r\n- New Module Pull Request\r\n\r\n##### COMPONENT NAME\r\ngithub_version\r\n\r\n##### ADDITIONAL INFORMATION\r\n\r\n###### Tests\r\nI was unable to get local unit tests running following the [unit test doc instructions](https://docs.ansible.com/ansible/devel/dev_guide/testing_units.html#running-tests). Due to this I did not write unit tests for this plugin, which I would like to do before this is accepted. I did manually tests all of the cases I have commented in the unit test file, and it's working great.\r\n\r\nFor example, running `ansible-test units --python 3.6 apt` returns an error that `pytest` is not available in my venv. I can add that easily enough, but that should probably be installed as part of some local dev setup step that I must be missing.\r\n\r\n###### Usage\r\nYou can accomplish this lookup plugin's behavior through 2 different methods in tasks:\r\n\r\n1-task option:\r\n\r\n```yaml\r\n- name: Get the latest version\r\n  shell: |\r\n    set -o pipefail\r\n    curl -H 'Accept: application/vnd.github.v3+json' https://api.github.com/repos/ansible/ansible/releases/latest | jq .tag_name\r\n  args:\r\n    executable: /bin/bash\r\n  changed_when: false\r\n  register: ansible_version\r\n```\r\n\r\n2-task option, not using `shell`:\r\n\r\n```yaml\r\n- name: Ansible | Get latest release\r\n  uri:\r\n    url: https://api.github.com/repos/ansible/ansible/releases/latest\r\n    headers:\r\n      Accept: application/vnd.github.v3+json\r\n    body_format: json\r\n    return_content: yes\r\n  register: terraform_release\r\n\r\n- name: Ansible | Set version\r\n  set_fact:\r\n    # This removes the 'v' from the tag: 'v1.1.0' -> '1.1.0'\r\n    ansible_version: \"{{ terraform_release.json.tag_name[1:] }}\"\r\n```\r\n\r\nNow you can simply use:\r\n\r\n```yaml\r\n\r\n- name: Ansible | Get latest release\r\n  set_fact:\r\n    ansible_version: \"{{ lookup('github_version', 'ansible/ansible')[1:] }}\"\r\n```"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/544349167","html_url":"https://github.com/ansible/ansible/pull/63727#issuecomment-544349167","issue_url":"https://api.github.com/repos/ansible/ansible/issues/63727","id":544349167,"node_id":"MDEyOklzc3VlQ29tbWVudDU0NDM0OTE2Nw==","user":{"login":"ansibot","id":6585283,"node_id":"MDQ6VXNlcjY1ODUyODM=","avatar_url":"https://avatars0.githubusercontent.com/u/6585283?v=4","gravatar_id":"","url":"https://api.github.com/users/ansibot","html_url":"https://github.com/ansibot","followers_url":"https://api.github.com/users/ansibot/followers","following_url":"https://api.github.com/users/ansibot/following{/other_user}","gists_url":"https://api.github.com/users/ansibot/gists{/gist_id}","starred_url":"https://api.github.com/users/ansibot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansibot/subscriptions","organizations_url":"https://api.github.com/users/ansibot/orgs","repos_url":"https://api.github.com/users/ansibot/repos","events_url":"https://api.github.com/users/ansibot/events{/privacy}","received_events_url":"https://api.github.com/users/ansibot/received_events","type":"User","site_admin":false},"created_at":"2019-10-21T04:58:30Z","updated_at":"2019-10-21T04:58:30Z","author_association":"CONTRIBUTOR","body":"The test `ansible-test sanity --test metaclass-boilerplate` [[explain](https://docs.ansible.com/ansible/devel/dev_guide/testing/sanity/metaclass-boilerplate.html)] failed with 1 error:\n```\ntest/units/plugins/lookup/github_version.py:0:0: missing: __metaclass__ = type\n```\n<!-- job_id: 5dad2df9e8eb750006440c3d -->\n<!-- job_id: 5dad2dfa2a89db00071103e0 -->\n<!-- job_id: /testresults/ansible-test-sanity-metaclass-boilerplate.json -->\n\n[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)\n<!--- boilerplate: shippable_test_result --->"}}
{"actor":{"display_login":"ansibot"}}