From d30472ed056651454ee91502a66ca8b2e554ad59 Mon Sep 17 00:00:00 2001 From: Lance Mathias Date: Sat, 2 Oct 2021 15:59:10 -0700 Subject: [PATCH] added get newest RT ticket --- ocflib/infra/rt.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ocflib/infra/rt.py b/ocflib/infra/rt.py index 778f0d20..f1d49d09 100644 --- a/ocflib/infra/rt.py +++ b/ocflib/infra/rt.py @@ -36,6 +36,28 @@ def find(header): status=find('Status'), ) + @classmethod + def get_newest(cls, connection, queue): + """Returns the newest created RT ticket in the given queue""" + resp = connection.get("https://rt.ocf.berkeley.edu/REST/1.0/search/ticket?query=Queue='{}'&orderby=-Created".format(queue)) + assert resp.status_code == 200, resp.status_code + assert '200 Ok' in resp.text + + lines = resp.text.splitlines() + + def find(header): + for line in lines: + if line.startswith(header + ': '): + return line.split(': ', 1)[1] + + return cls( + number=num, + owner=find('Owner'), + subject=find('Subject'), + queue=find('Queue'), + status=find('Status'), + ) + @classmethod def create(cls, connection, queue, requestor, subject, text, **kwargs): """Create an RT ticket and returns an instance of the result"""