[Patchew-devel] [PATCH] Make patchew-cli use PUT of results

Shubham Jain posted 1 patch 5 years, 7 months ago
Failed in applying to current master (apply log)
patchew-cli | 87 ++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 66 insertions(+), 21 deletions(-)
[Patchew-devel] [PATCH] Make patchew-cli use PUT of results
Posted by Shubham Jain 5 years, 7 months ago
Convert patchew-cli *-report to use result PUT
---
 patchew-cli | 87 ++++++++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 66 insertions(+), 21 deletions(-)

diff --git a/patchew-cli b/patchew-cli
index cdedbb6..cf6fdf2 100755
--- a/patchew-cli
+++ b/patchew-cli
@@ -23,6 +23,7 @@ import traceback
 import time
 import hashlib
 import fcntl
+import datetime
 
 COOKIE_FILENAME = os.path.expanduser("~/.patchew.cookie")
 
@@ -125,7 +126,7 @@ class SubCommand(object):
         else:
             r = None
         return r
-        
+
     def do(self, args, argv):
         """Do command"""
         print("Not implemented")
@@ -620,7 +621,10 @@ class TesterCommand(SubCommand):
         except:
             traceback.print_exc(file=logf)
         finally:
-            passed = rc == 0
+            if rc == 0:
+                passed = "success"
+            else:
+                passed = "failure"
             try:
                 try:
                     logf.seek(0)
@@ -629,15 +633,28 @@ class TesterCommand(SubCommand):
                     log = "N/A. Internal error while reading log file\n"
                 print("  Result:", "Passed" if passed else "Failed")
                 logging.debug(log)
-                self.api_do("testing-report", project=r["project"],
-                                              identity=r["identity"],
-                                              test=r["test"]["name"],
-                                              tester=name,
-                                              head=r["head"],
-                                              base=r["base"],
-                                              passed=passed,
-                                              log=log,
-                                              is_timeout=is_timeout)
+                project_url = self.base_url + "/api/v1/projects/?name=" + project
+                test_name = "testing." + r['test']['name']
+                pr = self.rest_api_do(url_cmd=project_url)
+                if identity["type"] == "project":
+                    url =  pr['results'][0]['results'] + test_name + "/"
+                else:
+                    url = pr['results'][0]['series'] + identity['message_id'] + "/results/" + test_name + "/"
+                json_data= {
+                        "name": test_name,
+                        "status": passed,
+                        "last_update": datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f'),
+                        "data": {
+                            "is_timeout": is_timeout,
+                            "head": r["head"],
+                            "tester": name
+                        },
+                        "log": log
+                    }
+                self.rest_api_do(url_cmd=url,
+                                 request_method='put',
+                                 content_type='application/json',
+                                 data=json.dumps(json_data))
                 logf.close()
             finally:
                 if not no_clean_up:
@@ -785,6 +802,11 @@ class ApplyCommand(SubCommand):
         push_repo = toapply.get("git.push_to")
         public_repo = toapply.get("git.public_repo")
         wd = tempfile.mkdtemp(dir="/var/tmp")
+        project = toapply['project']
+        message_id = toapply['message-id']
+        project_url = self.base_url + "/api/v1/projects/?name=" + project
+        pr = self.rest_api_do(url_cmd=project_url)
+        report_url =  pr['results'][0]['series'] + message_id + "/results/git/"
         try:
             if toapply.get("git.repo"):
                 remote, head = toapply["git.repo"], toapply["git.base"]
@@ -806,6 +828,7 @@ class ApplyCommand(SubCommand):
             if push_repo:
                 self._push(wd, push_repo, tag, logf)
             url = toapply.get("git.url_template", "").replace("%t", tag)
+            tag = "refs/tags/" + tag
         except Exception as e:
             if not isinstance(e, ApplyFailedException):
                 traceback.print_exc(file=logf)
@@ -814,11 +837,22 @@ class ApplyCommand(SubCommand):
             if push_repo:
                 log = log.replace(push_repo, public_repo)
             print(log)
-            self.api_do("applier-report",
-                        project=toapply["project"],
-                        message_id=toapply["message-id"],
-                        tag=None, url=None, base=None, repo=None,
-                        failed=True, log=log)
+            json_data = {
+                        "name": "git",
+                        "status": "failure",
+                        "last_update": datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f'),
+                        "data": {
+                                "repo": "",
+                                "url": "",
+                                "base": "",
+                                "tag": ""
+                                },
+                        "log": log
+                        }
+            self.rest_api_do(url_cmd=report_url,
+                             request_method='put',
+                             content_type='application/json',
+                             data=json.dumps(json_data))
             return 1
         finally:
             shutil.rmtree(wd)
@@ -826,11 +860,22 @@ class ApplyCommand(SubCommand):
         log = logf.read()
         if push_repo:
             log = log.replace(push_repo, public_repo)
-        self.api_do("applier-report",
-                    project=toapply["project"],
-                    message_id=toapply["message-id"],
-                    tag=tag, url=url, base=base, repo=public_repo,
-                    failed=False, log=log)
+        json_data = {
+                    "name": "git",
+                    "status": "success",
+                    "last_update": datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f'),
+                    "data": {
+                            "repo": public_repo,
+                            "url": url,
+                            "base": base,
+                            "tag": tag
+                            },
+                    "log": log
+                    }
+        self.rest_api_do(url_cmd=report_url,
+                         request_method='put',
+                         content_type='application/json',
+                         data=json.dumps(json_data))
         return 0
 
     def do(self, args, argv):
-- 
2.15.1 (Apple Git-101)

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel