Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get newest RT ticket #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ocflib/infra/rt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this would work since I can't seem to find relevant stuff in the docs (https://rt-wiki.bestpractical.com/wiki/REST#Ticket_Search), but I think it might return a bunch of tickets instead of one?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid query: 'Wrong query, expecting a VALUE in 'Queue=>help<--here' at /opt/rt5/sbin/../lib/RT/Tickets.pm line 3036, <DATA> line 1662.

Stack:
  [/opt/rt5/sbin/../lib/RT/Tickets.pm:3036]
  [/opt/rt5/sbin/../lib/RT/Tickets.pm:3248]
  [/opt/rt5/share/html/REST/1.0/search/dhandler:120]
  [/opt/rt5/share/html/REST/1.0/autohandler:54]
  [/opt/rt5/sbin/../lib/RT/Interface/Web.pm:710]
  [/opt/rt5/sbin/../lib/RT/Interface/Web.pm:389]
  [/opt/rt5/share/html/autohandler:53]
'.

assert resp.status_code == 200, resp.status_code
assert '200 Ok' in resp.text

lines = resp.text.splitlines()

def find(header):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk this is legacy, it's elegant but comparatively inefficient i guess (need to do 4 passes instead of 1)

for line in lines:
if line.startswith(header + ': '):
return line.split(': ', 1)[1]

return cls(
number=num,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to do something to find id: ticket/<ticket-id>;

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"""
Expand Down