From 6ac1a4c992e9c59fb03c606168ef324a9944675b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 13 2019 14:41:24 +0000 Subject: Add a new API endpoint returning the status of a package This endpoint will return True on active packages and False on retired packages (based on PDC data). Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure_distgit/plugin.py b/pagure_distgit/plugin.py index f026063..9665ec7 100644 --- a/pagure_distgit/plugin.py +++ b/pagure_distgit/plugin.py @@ -90,6 +90,27 @@ def anitya_patch_endpoint(namespace, repo): return anitya_get_endpoint(namespace, repo.name) +@DISTGIT_NS.route("/actived//", methods=["GET"]) +@api_method +def get_actived_status(namespace, repo): + """ Retrieves the active status of the specified package. + """ + _log.info("Received a request to unorphan: %s/%s", namespace, repo) + + repo = _get_repo(repo, namespace=namespace) + + if repo.user.user != "orphan": + raise pagure.exceptions.APIError( + 401, error_code=APIERROR.EMODIFYPROJECTNOTALLOWED + ) + + # Check if the project is retired in PDC + active = _is_active_in_pdc(repo.name, repo.namespace) + + output = {"active": active} + return flask.jsonify(output) + + def _is_active_in_pdc(name, namespace): """ Queries PDC and return whether the project is active on the master branch in PDC or not.