Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix agent_changelog command #2808

Merged
merged 5 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions datadog_checks_dev/datadog_checks/dev/tooling/commands/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from ..github import from_contributor, get_changelog_types, get_pr, get_pr_from_hash, get_pr_labels, get_pr_milestone
from ..release import (
get_agent_requirement_line, get_release_tag_string, update_agent_requirements,
update_version_module
update_version_module, get_folder_name, get_package_name, DATADOG_PACKAGE_PREFIX
)
from ..trello import TrelloClient
from ..utils import (
Expand Down Expand Up @@ -926,23 +926,35 @@ def agent_changelog(since, to, output, force):
# store the changes in a mapping {agent_version --> {check_name --> current_version}}
changes_per_agent = OrderedDict()

# to keep indexing easy, we run the loop off-by-one
for i in range(1, len(agent_tags)):
req_file_name = os.path.basename(get_agent_release_requirements())
contents_from = git_show_file(req_file_name, agent_tags[i - 1])
catalog_from = parse_agent_req_file(contents_from)
current_tag = agent_tags[i - 1]
# Requirements for current tag
file_contents = git_show_file(req_file_name, current_tag)
catalog_now = parse_agent_req_file(file_contents)
# Requirements for previous tag
file_contents = git_show_file(req_file_name, agent_tags[i])
catalog_prev = parse_agent_req_file(file_contents)

changes_per_agent[current_tag] = OrderedDict()

for name, ver in iteritems(catalog_now):
# at some point in the git history, the requirements file erroneusly
# contained the folder name instead of the package name for each check,
# let's be resilient
old_ver = catalog_prev.get(name) \
or catalog_prev.get(get_folder_name(name)) \
or catalog_prev.get(get_package_name(name))

# normalize the package name to the check_name
if name.startswith(DATADOG_PACKAGE_PREFIX):
name = get_folder_name(name)

contents_to = git_show_file(req_file_name, agent_tags[i])
catalog_to = parse_agent_req_file(contents_to)

version_changes = OrderedDict()
changes_per_agent[agent_tags[i - 1]] = version_changes

for name, ver in iteritems(catalog_to):
old_ver = catalog_from.get(name, "")
if old_ver and old_ver != ver:
# determine whether major version changed
breaking = old_ver.split('.')[0] < ver.split('.')[0]
version_changes[name] = (ver, breaking)
changes_per_agent[current_tag][name] = (ver, breaking)

# store the changelog in memory
changelog_contents = StringIO()
Expand All @@ -968,7 +980,7 @@ def agent_changelog(since, to, output, force):
else:
display_name = name

breaking_notice = " **BREAKING CHANGE** " if ver[1] else ""
breaking_notice = " **BREAKING CHANGE**" if ver[1] else ""
changelog_url = check_changelog_url.format(name)
changelog_contents.write(
'* {} [{}]({}){}\n'.format(display_name, ver[0], changelog_url, breaking_notice)
Expand Down
25 changes: 20 additions & 5 deletions datadog_checks_dev/datadog_checks/dev/tooling/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
'linux': 'linux2',
}
ALL_PLATFORMS = sorted(PLATFORMS_TO_PY)

VERSION = re.compile(r'__version__ *= *(?:[\'"])(.+?)(?:[\'"])')
DATADOG_PACKAGE_PREFIX = 'datadog-'


def get_release_tag_string(check_name, version_string):
Expand All @@ -36,11 +36,26 @@ def update_version_module(check_name, old_ver, new_ver):
write_file(version_file, contents)


def get_package_name(check_name):
if check_name == 'datadog_checks_base':
return check_name.replace('_', '-')
def get_package_name(folder_name):
"""
Given a folder name for a check, return the name of the
corresponding Python package
"""
if folder_name == 'datadog_checks_base':
return 'datadog-checks-base'

return '{}{}'.format(DATADOG_PACKAGE_PREFIX, folder_name.replace('_', '-'))


def get_folder_name(package_name):
"""
Given a Python package name for a check, return the corresponding folder
name in the git repo
"""
if package_name == 'datadog-checks-base':
return 'datadog_checks_base'

return 'datadog-{}'.format(check_name.replace('_', '-'))
return package_name.replace('-', '_')[len(DATADOG_PACKAGE_PREFIX):]


def get_agent_requirement_line(check, version):
Expand Down
4 changes: 2 additions & 2 deletions datadog_checks_dev/datadog_checks/dev/tooling/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ def get_bump_function(changelog_types):

def parse_agent_req_file(contents):
"""
Returns a dictionary mapping {check_name --> pinned_version} from the
Returns a dictionary mapping {check-package-name --> pinned_version} from the
given file contents. We can assume lines are in the form:

active_directory==1.1.1; sys_platform == 'win32'
datadog-active-directory==1.1.1; sys_platform == 'win32'

"""
catalog = OrderedDict()
Expand Down
14 changes: 14 additions & 0 deletions datadog_checks_dev/tests/tooling/test_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from datadog_checks.dev.tooling.release import get_package_name, get_folder_name


def test_get_package_name():
assert get_package_name('datadog_checks_base') == 'datadog-checks-base'
assert get_package_name('my_check') == 'datadog-my-check'


def test_get_folder_name():
assert get_folder_name('datadog-checks-base') == 'datadog_checks_base'
assert get_folder_name('datadog-my-check') == 'my_check'