contrib: fix moving all/multiple apis from preview to stable

I hadn't tested apiage well enough to see that the existing code didn't
correctly handle the case when all or many apis were becoming stable all
together. Things worked fine for a single function call, but not with
many. This fix tries to only update the JSON when needed while correctly
handling the case of multiple changes in one pkg at once.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2022-10-17 12:45:22 -04:00 committed by mergify[bot]
parent 1b33c5fd2e
commit 4f5281df0f
1 changed files with 17 additions and 4 deletions

View File

@ -177,11 +177,20 @@ def api_promote(tracked, src, values):
for pkg, pkg_api in src.items():
src_stable = pkg_api.get("stable_api", [])
src_preview = pkg_api.get("preview_api", [])
tracked_stable = tracked.get(pkg, {}).get("stable_api", [])
tracked_preview = tracked.get(pkg, {}).get("preview_api", [])
indexed_stable = {a.get("name", ""): a for a in tracked_stable}
indexed_preview = {a.get("name", ""): a for a in tracked_preview}
new_tracked_stable = new_tracked_preview = False
try:
tracked_stable = tracked.get(pkg, {})["stable_api"]
except KeyError:
tracked_stable = []
new_tracked_stable = True
try:
tracked_preview = tracked.get(pkg, {})["preview_api"]
except KeyError:
tracked_preview = []
new_tracked_preview = True
for api in src_stable:
indexed_stable = {a.get("name", ""): a for a in tracked_stable}
indexed_preview = {a.get("name", ""): a for a in tracked_preview}
name = api.get("name", "")
if name in indexed_preview and name not in indexed_stable:
# need to promote this api
@ -201,6 +210,10 @@ def api_promote(tracked, src, values):
print("api not found in preview: {}:{}".format(pkg, name))
problems += 1
# else api is already stable. do nothing.
if new_tracked_stable and tracked_stable:
tracked[pkg]["stable_api"] = tracked_stable
if new_tracked_preview and tracked_preview:
tracked[pkg]["preview_api"] = tracked_preview
return changes, problems