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

ENT-10866: Fixed packages_mapping helper for versions #96

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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
50 changes: 29 additions & 21 deletions tom/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, github, slack, dispatcher, username):
dispatcher.register_command(
keyword="packages_mapping",
callback=lambda branches: self.run(branches),
parameter_name="branches",
parameter_name="branches or versions",
short_help="Add packages to packages_mapping.json",
long_help="Scan releases.json for last release of given branches and add all of their packages to packages_mapping file",
)
Expand Down Expand Up @@ -119,31 +119,39 @@ def run(self, inputs):
if value_type == "version":
version = value
branch = re.sub("^(\\d+\\.\\d+\\.).*", "\\1x", version)
release_url = "https://cfengine.com/release-data/%s/%s.json" % (
product,
version,
)
else:
branch = value
releases_url = (
"https://cfengine.com/release-data/%s/releases.json" % product

releases_url = (
"https://cfengine.com/release-data/%s/releases.json" % product
)
releases_request = requests.get(releases_url)
if not releases_request.ok:
raise URLDownloadFailureException(
"failed to download %s, return code %d"
% (releases_url, releases_request.status_code)
)
releases_request = requests.get(releases_url)
if not releases_request.ok:
raise URLDownloadFailureException(
"failed to download %s, return code %d"
% (releases_url, releases_request.status_code)
)
try:
releases_data = releases_request.json()
except json.decoder.JSONDecodeError as e:
raise JSONParsingError(
"file %s is not a valid JSON" % releases_url
) from e
if "releases" not in releases_data:
raise JSONStructureError('no "releases" in %s JSON' % releases_url)
if value_type == "version":
try:
releases_data = releases_request.json()
except json.decoder.JSONDecodeError as e:
raise JSONParsingError(
"file %s is not a valid JSON" % releases_url
) from e
if "releases" not in releases_data:
raise JSONStructureError(
'no "releases" in %s JSON' % releases_url
release_url = next(
(release["URL"])
for release in releases_data["releases"]
if release["version"] == version
)
except StopIteration as e:
raise JSONStructureError(
'no release with "version"=="%s" in %s JSON'
% (version, releases_url)
) from e
else:
try:
release_url, version = next(
(release["URL"], release["version"])
Expand Down
Loading