Skip to content

Conversation

@lancemathias
Copy link

New method to get latest RT ticket using REST API. Pushed to master to test since local tests aren't working.

@emmatyping emmatyping closed this Oct 3, 2021
@emmatyping emmatyping reopened this Oct 3, 2021
@emmatyping
Copy link
Member

(Closed and reopened, which seems to have fixed CI not getting triggered initially)

Copy link

@axmmisaka axmmisaka left a comment

Choose a reason for hiding this comment

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

thanks for the good work, i'm still figuring out how to access rt api with my acct

@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]
'.

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>;


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)

@axmmisaka
Copy link

https://metacpan.org/pod/RT::Extension::REST2#Cookie-Auth
There's some discussion in #rebuild regarding using REST 2.0 api. The issue is for REST 2.0 it appears that the docs suggest against using session-token to authenticate, so every time auth token/password is needed in the header if I understand it correctly?
Otherwise use resp = s.get('https://rt.ocf.berkeley.edu/REST/2.0/tickets?query=Queue="help"&orderby=Created&order=DESC', headers={"Authorization": "token dskljvelkajdhvluierwbvlijaebvleisuadghea"}) json parse resp.text, and pick the first in items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants