From be5bb7841c2d8f0faac87daf678d1fea6b3a0135 Mon Sep 17 00:00:00 2001 From: Robin Schneider Date: Fri, 29 Jul 2016 23:47:06 +0200 Subject: [PATCH] Implement `changelog_url` key for /roles?/ Related to: #4 --- .gitignore | 4 +++ Makefile | 5 +-- bin/debops-api | 36 ++++++++++++++----- docs/api-reference-v0.rst | 18 ++++++---- .../v0/role/debops.unattended_upgrades.json | 2 +- tests/api_data/v0/roles/debops.json | 2 +- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index d56c89d..56eb1fa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ docs/_build/ docs/conf.py docs/defaults.rst docs/includes/global.rst +docs/_templates/page.html +docs/_templates/.gitkeep +docs/_static/custom.css +docs/_static/.gitkeep diff --git a/Makefile b/Makefile index f64460a..925f80e 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,7 @@ check: tests/api_data git diff --quiet --exit-code HEAD -- $^ tests/api_data: bin/debops-api tests/example_roles FORCE_MAKE - "$<" --test-mode --role-path tests/example_roles/ \ - --docs-url-pattern 'http://docs.debops.org/en/latest/ansible/roles/ansible-{role_name}/docs/index.html' \ - --role-owner debops \ - --api-dir "$@" + "$<" --test-mode --role-path tests/example_roles/ --api-dir "$@" pre-commit-hook: hooks/pre-commit ln -srf "$<" "$(shell git rev-parse --git-dir)/hooks" diff --git a/bin/debops-api b/bin/debops-api index 4061eb8..9c9242c 100755 --- a/bin/debops-api +++ b/bin/debops-api @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (C) 2016 Robin Schneider +# Copyright (C) 2016 DebOps Project http://debops.org/ # # debops-api is part of DebOps. # @@ -60,11 +61,13 @@ class DebOpsAPI: def __init__( self, docs_url_pattern=None, + changelog_url_pattern=None, role_owner=None, test_mode=False, ): self._docs_url_pattern = docs_url_pattern + self._changelog_url_pattern = changelog_url_pattern self._role_owner = role_owner self._test_mode = test_mode @@ -136,7 +139,7 @@ class DebOpsAPI: def _interpret_role_dir_name(self, role_dir_name): """ - Read metadata from each role available in role_path. + Extract and return information from the role directory name. """ version_by_pattern_map = { @@ -356,14 +359,22 @@ class DebOpsAPI: 'pr_url': metadata['vcs_url'] + '/pulls', }) - if self._docs_url_pattern and StrictVersion('0.2.0') <= \ + if StrictVersion('0.2.0') <= \ StrictVersion(metadata['role_format_version']): - additonal_metadata['docs_url'] = self._docs_url_pattern.format( - role_owner=role_owner, - role_name=role_name, - normalized_role_name=self._get_normalized_role_name(role_name), - ) + if self._docs_url_pattern: + additonal_metadata['docs_url'] = self._docs_url_pattern.format( + role_owner=role_owner, + role_name=role_name, + normalized_role_name=self._get_normalized_role_name(role_name), + ) + + if self._changelog_url_pattern: + additonal_metadata['changelog_url'] = self._changelog_url_pattern.format( + role_owner=role_owner, + role_name=role_name, + normalized_role_name=self._get_normalized_role_name(role_name), + ) self._metadata[role_full_name].update(additonal_metadata) @@ -411,7 +422,7 @@ class DebOpsAPI: role_name = role_dir_info['role_name'] role_owner = role_dir_info['role_owner'] if role_dir_info['role_owner'] else self._role_owner if not role_owner: - raise Exception('Default role owner not given but required.') + raise Exception("Default role owner not given but required.") role_vcs_url = self._get_repo_url( role_owner, @@ -564,6 +575,7 @@ if __name__ == '__main__': args_parser.add_argument( '-o', '--role-owner', help="Default role owner if not available from Ansible role metadata.", + default='debops', ) args_parser.add_argument( '-a', '--api-dir', @@ -574,7 +586,12 @@ if __name__ == '__main__': args_parser.add_argument( '-D', '--docs-url-pattern', help="Documentation URL for each role.", - default=None, + default='https://docs.debops.org/en/latest/ansible/roles/ansible-{role_name}/docs/index.html', + ) + args_parser.add_argument( + '-C', '--changelog-url-pattern', + help="Changelog URL for each role.", + default='https://docs.debops.org/en/latest/ansible/roles/ansible-{role_name}/docs/changelog.html', ) args_parser.add_argument( '-t', '--test-mode', @@ -596,6 +613,7 @@ if __name__ == '__main__': debops_metadata = DebOpsAPI( docs_url_pattern=args.docs_url_pattern, + changelog_url_pattern=args.changelog_url_pattern, role_owner=args.role_owner, test_mode=args.test_mode, ) diff --git a/docs/api-reference-v0.rst b/docs/api-reference-v0.rst index 217f671..59c71da 100644 --- a/docs/api-reference-v0.rst +++ b/docs/api-reference-v0.rst @@ -1,5 +1,5 @@ -API reference v0 -================ +DebOps API reference v0 +======================= .. contents:: :local: @@ -63,12 +63,13 @@ Role metadata JSON format :regexp:`^/role/.*\.json$` API calls return a JSON object containing the keys described below. -:regexp:`^/roles/.*\.json$` API calls return a JSON object. The outer dict is a -full role name to meta data (described below) mapping. +:regexp:`^/roles/.*\.json$` API calls return a JSON object. The outer dict maps +from the full role name to the meta data (described below). .. note:: ``role_format_version`` below ``0.2.0`` are not fully supported by - this API. Keys might be missing for roles with this version. - Do a version compare for ``0.2.0`` or higher of fixup the DebOps API. + this API. Keys might be missing for roles below ``v0.2.0``. + Do a version compare for ``0.2.0`` or higher or update the roles (or fixup + the DebOps API). ``role_owner`` Ansible Galaxy role owner. @@ -101,7 +102,10 @@ full role name to meta data (described below) mapping. TODO: The versions are currently not documented elsewhere. ``docs_url`` - HTML URL of the rendered documentation of the repository + HTML URL of the rendered documentation of the repository. + +``changelog_url`` + HTML URL of the rendered changelog. ``galaxy_url`` HTML URL of the role on Ansible Galaxy. diff --git a/tests/api_data/v0/role/debops.unattended_upgrades.json b/tests/api_data/v0/role/debops.unattended_upgrades.json index 642307b..f43199a 100644 --- a/tests/api_data/v0/role/debops.unattended_upgrades.json +++ b/tests/api_data/v0/role/debops.unattended_upgrades.json @@ -1 +1 @@ -{"authors": [{"name": "Maciej Delmanowski", "nick": "drybjed"}, {"name": "Robin Schneider", "nick": "ypid"}], "ci_badge_url": "https://api.travis-ci.org/debops/ansible-unattended_upgrades.png", "ci_url": "https://travis-ci.org/debops/ansible-unattended_upgrades", "clone_url": "https://github.com/debops/ansible-unattended_upgrades.git", "description": "Configure unattended upgrades on Debian-based hosts", "docs_url": "http://docs.debops.org/en/latest/ansible/roles/ansible-unattended_upgrades/docs/index.html", "galaxy_url": "https://galaxy.ansible.com/debops/unattended_upgrades", "issue_url": "https://github.com/debops/ansible-unattended_upgrades/issues", "license": "GPL-3.0", "min_ansible_version": "2.0.0", "normalized_role_name": "unattended_upgrades", "platforms": [{"name": "Ubuntu", "versions": ["precise", "quantal", "raring", "saucy", "trusty"]}, {"name": "Debian", "versions": ["wheezy", "jessie"]}], "pr_url": "https://github.com/debops/ansible-unattended_upgrades/pulls", "role_format_version": "0.2.0", "role_name": "unattended_upgrades", "role_owner": "debops", "tags": ["apt", "system", "security"], "test_suite_url": "https://github.com/debops/test-suite/tree/master/ansible-unattended_upgrades", "vcs_last_committer_date": "1970-01-01 00:00:00 +0000", "vcs_url": "https://github.com/debops/ansible-unattended_upgrades", "version": "0.0.0"} +{"authors": [{"name": "Maciej Delmanowski", "nick": "drybjed"}, {"name": "Robin Schneider", "nick": "ypid"}], "changelog_url": "https://docs.debops.org/en/latest/ansible/roles/ansible-unattended_upgrades/docs/changelog.html", "ci_badge_url": "https://api.travis-ci.org/debops/ansible-unattended_upgrades.png", "ci_url": "https://travis-ci.org/debops/ansible-unattended_upgrades", "clone_url": "https://github.com/debops/ansible-unattended_upgrades.git", "description": "Configure unattended upgrades on Debian-based hosts", "docs_url": "https://docs.debops.org/en/latest/ansible/roles/ansible-unattended_upgrades/docs/index.html", "galaxy_url": "https://galaxy.ansible.com/debops/unattended_upgrades", "issue_url": "https://github.com/debops/ansible-unattended_upgrades/issues", "license": "GPL-3.0", "min_ansible_version": "2.0.0", "normalized_role_name": "unattended_upgrades", "platforms": [{"name": "Ubuntu", "versions": ["precise", "quantal", "raring", "saucy", "trusty"]}, {"name": "Debian", "versions": ["wheezy", "jessie"]}], "pr_url": "https://github.com/debops/ansible-unattended_upgrades/pulls", "role_format_version": "0.2.0", "role_name": "unattended_upgrades", "role_owner": "debops", "tags": ["apt", "system", "security"], "test_suite_url": "https://github.com/debops/test-suite/tree/master/ansible-unattended_upgrades", "vcs_last_committer_date": "1970-01-01 00:00:00 +0000", "vcs_url": "https://github.com/debops/ansible-unattended_upgrades", "version": "0.0.0"} diff --git a/tests/api_data/v0/roles/debops.json b/tests/api_data/v0/roles/debops.json index a2e12d0..24e7766 100644 --- a/tests/api_data/v0/roles/debops.json +++ b/tests/api_data/v0/roles/debops.json @@ -1 +1 @@ -{"debops.ansible": {"ci_badge_url": "https://api.travis-ci.org/debops/ansible-role-ansible.png", "ci_url": "https://travis-ci.org/debops/ansible-role-ansible", "clone_url": "https://github.com/debops/ansible-role-ansible.git", "galaxy_url": "https://galaxy.ansible.com/debops/ansible", "issue_url": "https://github.com/debops/ansible-role-ansible/issues", "normalized_role_name": "role-ansible", "pr_url": "https://github.com/debops/ansible-role-ansible/pulls", "role_format_version": "0.1.0", "role_name": "ansible", "role_owner": "debops", "test_suite_url": "https://github.com/debops/test-suite/tree/master/ansible-role-ansible", "vcs_url": "https://github.com/debops/ansible-role-ansible"}, "debops.unattended_upgrades": {"authors": [{"name": "Maciej Delmanowski", "nick": "drybjed"}, {"name": "Robin Schneider", "nick": "ypid"}], "ci_badge_url": "https://api.travis-ci.org/debops/ansible-unattended_upgrades.png", "ci_url": "https://travis-ci.org/debops/ansible-unattended_upgrades", "clone_url": "https://github.com/debops/ansible-unattended_upgrades.git", "description": "Configure unattended upgrades on Debian-based hosts", "docs_url": "http://docs.debops.org/en/latest/ansible/roles/ansible-unattended_upgrades/docs/index.html", "galaxy_url": "https://galaxy.ansible.com/debops/unattended_upgrades", "issue_url": "https://github.com/debops/ansible-unattended_upgrades/issues", "license": "GPL-3.0", "min_ansible_version": "2.0.0", "normalized_role_name": "unattended_upgrades", "platforms": [{"name": "Ubuntu", "versions": ["precise", "quantal", "raring", "saucy", "trusty"]}, {"name": "Debian", "versions": ["wheezy", "jessie"]}], "pr_url": "https://github.com/debops/ansible-unattended_upgrades/pulls", "role_format_version": "0.2.0", "role_name": "unattended_upgrades", "role_owner": "debops", "tags": ["apt", "system", "security"], "test_suite_url": "https://github.com/debops/test-suite/tree/master/ansible-unattended_upgrades", "vcs_last_committer_date": "1970-01-01 00:00:00 +0000", "vcs_url": "https://github.com/debops/ansible-unattended_upgrades", "version": "0.0.0"}, "debops.users": {"ci_badge_url": "https://api.travis-ci.org/debops/ansible-users.png", "ci_url": "https://travis-ci.org/debops/ansible-users", "clone_url": "https://github.com/debops/ansible-users.git", "galaxy_url": "https://galaxy.ansible.com/debops/users", "issue_url": "https://github.com/debops/ansible-users/issues", "normalized_role_name": "users", "pr_url": "https://github.com/debops/ansible-users/pulls", "role_format_version": "0.1.0", "role_name": "users", "role_owner": "debops", "test_suite_url": "https://github.com/debops/test-suite/tree/master/ansible-users", "vcs_url": "https://github.com/debops/ansible-users"}} +{"debops.ansible": {"ci_badge_url": "https://api.travis-ci.org/debops/ansible-role-ansible.png", "ci_url": "https://travis-ci.org/debops/ansible-role-ansible", "clone_url": "https://github.com/debops/ansible-role-ansible.git", "galaxy_url": "https://galaxy.ansible.com/debops/ansible", "issue_url": "https://github.com/debops/ansible-role-ansible/issues", "normalized_role_name": "role-ansible", "pr_url": "https://github.com/debops/ansible-role-ansible/pulls", "role_format_version": "0.1.0", "role_name": "ansible", "role_owner": "debops", "test_suite_url": "https://github.com/debops/test-suite/tree/master/ansible-role-ansible", "vcs_url": "https://github.com/debops/ansible-role-ansible"}, "debops.unattended_upgrades": {"authors": [{"name": "Maciej Delmanowski", "nick": "drybjed"}, {"name": "Robin Schneider", "nick": "ypid"}], "changelog_url": "https://docs.debops.org/en/latest/ansible/roles/ansible-unattended_upgrades/docs/changelog.html", "ci_badge_url": "https://api.travis-ci.org/debops/ansible-unattended_upgrades.png", "ci_url": "https://travis-ci.org/debops/ansible-unattended_upgrades", "clone_url": "https://github.com/debops/ansible-unattended_upgrades.git", "description": "Configure unattended upgrades on Debian-based hosts", "docs_url": "https://docs.debops.org/en/latest/ansible/roles/ansible-unattended_upgrades/docs/index.html", "galaxy_url": "https://galaxy.ansible.com/debops/unattended_upgrades", "issue_url": "https://github.com/debops/ansible-unattended_upgrades/issues", "license": "GPL-3.0", "min_ansible_version": "2.0.0", "normalized_role_name": "unattended_upgrades", "platforms": [{"name": "Ubuntu", "versions": ["precise", "quantal", "raring", "saucy", "trusty"]}, {"name": "Debian", "versions": ["wheezy", "jessie"]}], "pr_url": "https://github.com/debops/ansible-unattended_upgrades/pulls", "role_format_version": "0.2.0", "role_name": "unattended_upgrades", "role_owner": "debops", "tags": ["apt", "system", "security"], "test_suite_url": "https://github.com/debops/test-suite/tree/master/ansible-unattended_upgrades", "vcs_last_committer_date": "1970-01-01 00:00:00 +0000", "vcs_url": "https://github.com/debops/ansible-unattended_upgrades", "version": "0.0.0"}, "debops.users": {"ci_badge_url": "https://api.travis-ci.org/debops/ansible-users.png", "ci_url": "https://travis-ci.org/debops/ansible-users", "clone_url": "https://github.com/debops/ansible-users.git", "galaxy_url": "https://galaxy.ansible.com/debops/users", "issue_url": "https://github.com/debops/ansible-users/issues", "normalized_role_name": "users", "pr_url": "https://github.com/debops/ansible-users/pulls", "role_format_version": "0.1.0", "role_name": "users", "role_owner": "debops", "test_suite_url": "https://github.com/debops/test-suite/tree/master/ansible-users", "vcs_url": "https://github.com/debops/ansible-users"}}