Blame SOURCES/0006-copr-migrate-all-calls-to-APIv3.patch

5a4a77
From 54b7c5f91b4ad1db1f716f25cc7973ec7542f0d4 Mon Sep 17 00:00:00 2001
5a4a77
From: Jakub Kadlcik <frostyx@email.cz>
5a4a77
Date: Tue, 12 Oct 2021 12:54:05 +0200
5a4a77
Subject: [PATCH] copr: migrate all calls to APIv3
5a4a77
5a4a77
In the latest Copr release we dropped all APIv1 code from frontend.
5a4a77
https://docs.pagure.org/copr.copr/release-notes/2021-10-01.html
5a4a77
5a4a77
Unfortunatelly we frogot to migrate DNF copr plugin to APIv3 and
5a4a77
therefore the following commands started failing with 404.
5a4a77
5a4a77
    dnf copr search tests
5a4a77
    dnf copr list --available-by-user frostyx
5a4a77
---
5a4a77
 plugins/copr.py | 40 +++++++++++++++++-----------------------
5a4a77
 1 file changed, 17 insertions(+), 23 deletions(-)
5a4a77
5a4a77
diff --git a/plugins/copr.py b/plugins/copr.py
5a4a77
index 8841f03..7fc6c6f 100644
5a4a77
--- a/plugins/copr.py
5a4a77
+++ b/plugins/copr.py
5a4a77
@@ -355,51 +355,45 @@ Bugzilla. In case of problems, contact the owner of this repository.
5a4a77
                     "Re-enable the project to fix this."))
5a4a77
 
5a4a77
     def _list_user_projects(self, user_name):
5a4a77
-        # http://copr.fedorainfracloud.org/api/coprs/ignatenkobrain/
5a4a77
-        api_path = "/api/coprs/{}/".format(user_name)
5a4a77
-        res = self.base.urlopen(self.copr_url + api_path, mode='w+')
5a4a77
+        # https://copr.fedorainfracloud.org/api_3/project/list?ownername=ignatenkobrain
5a4a77
+        api_path = "/api_3/project/list?ownername={0}".format(user_name)
5a4a77
+        url = self.copr_url + api_path
5a4a77
+        res = self.base.urlopen(url, mode='w+')
5a4a77
         try:
5a4a77
             json_parse = json.loads(res.read())
5a4a77
         except ValueError:
5a4a77
             raise dnf.exceptions.Error(
5a4a77
                 _("Can't parse repositories for username '{}'.")
5a4a77
                 .format(user_name))
5a4a77
         self._check_json_output(json_parse)
5a4a77
         section_text = _("List of {} coprs").format(user_name)
5a4a77
         self._print_match_section(section_text)
5a4a77
-        i = 0
5a4a77
-        while i < len(json_parse["repos"]):
5a4a77
-            msg = "{0}/{1} : ".format(user_name,
5a4a77
-                                      json_parse["repos"][i]["name"])
5a4a77
-            desc = json_parse["repos"][i]["description"]
5a4a77
-            if not desc:
5a4a77
-                desc = _("No description given")
5a4a77
+
5a4a77
+        for item in json_parse["items"]:
5a4a77
+            msg = "{0}/{1} : ".format(user_name, item["name"])
5a4a77
+            desc = item["description"] or _("No description given")
5a4a77
             msg = self.base.output.fmtKeyValFill(ucd(msg), desc)
5a4a77
             print(msg)
5a4a77
-            i += 1
5a4a77
 
5a4a77
     def _search(self, query):
5a4a77
-        # http://copr.fedorainfracloud.org/api/coprs/search/tests/
5a4a77
-        api_path = "/api/coprs/search/{}/".format(query)
5a4a77
-        res = self.base.urlopen(self.copr_url + api_path, mode='w+')
5a4a77
+        # https://copr.fedorainfracloud.org/api_3/project/search?query=tests
5a4a77
+        api_path = "/api_3/project/search?query={}".format(query)
5a4a77
+        url = self.copr_url + api_path
5a4a77
+        res = self.base.urlopen(url, mode='w+')
5a4a77
         try:
5a4a77
             json_parse = json.loads(res.read())
5a4a77
         except ValueError:
5a4a77
             raise dnf.exceptions.Error(_("Can't parse search for '{}'."
5a4a77
                                          ).format(query))
5a4a77
         self._check_json_output(json_parse)
5a4a77
         section_text = _("Matched: {}").format(query)
5a4a77
         self._print_match_section(section_text)
5a4a77
-        i = 0
5a4a77
-        while i < len(json_parse["repos"]):
5a4a77
-            msg = "{0}/{1} : ".format(json_parse["repos"][i]["username"],
5a4a77
-                                      json_parse["repos"][i]["coprname"])
5a4a77
-            desc = json_parse["repos"][i]["description"]
5a4a77
-            if not desc:
5a4a77
-                desc = _("No description given.")
5a4a77
+
5a4a77
+        for item in json_parse["items"]:
5a4a77
+            msg = "{0} : ".format(item["full_name"])
5a4a77
+            desc = item["description"] or _("No description given.")
5a4a77
             msg = self.base.output.fmtKeyValFill(ucd(msg), desc)
5a4a77
             print(msg)
5a4a77
-            i += 1
5a4a77
 
5a4a77
     def _print_match_section(self, text):
5a4a77
         formatted = self.base.output.fmtSection(text)
5a4a77
@@ -624,7 +618,7 @@ Bugzilla. In case of problems, contact the owner of this repository.
5a4a77
 
5a4a77
     @classmethod
5a4a77
     def _check_json_output(cls, json_obj):
5a4a77
-        if json_obj["output"] != "ok":
5a4a77
+        if "error" in json_obj:
5a4a77
             raise dnf.exceptions.Error("{}".format(json_obj["error"]))
5a4a77
 
5a4a77
     @classmethod
5a4a77
--
5a4a77
libgit2 1.0.1
5a4a77