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

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