query: rt_ticket() supports looking up custom fields.
This commit is contained in:
parent
5ac2e4a872
commit
39a9d0d67e
3 changed files with 16 additions and 1 deletions
|
@ -53,6 +53,7 @@ import functools
|
|||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
|
@ -254,6 +255,10 @@ class RTField(NamedTuple):
|
|||
class RTTicket(bc_query_compile.EvalFunction):
|
||||
"""Look up a field from RT ticket(s) mentioned in metadata documentation"""
|
||||
__intypes__ = [str, str, int]
|
||||
_CF_REGEXPS = [
|
||||
re.compile(r'^CF_([-\w]+)$', re.IGNORECASE),
|
||||
re.compile(r'^CF\.\{([-\w]+)\}$', re.IGNORECASE),
|
||||
]
|
||||
FIELDS = {key: RTField(key, None) for key in [
|
||||
'AdminCc',
|
||||
'Cc',
|
||||
|
@ -320,6 +325,13 @@ class RTTicket(bc_query_compile.EvalFunction):
|
|||
try:
|
||||
return self.FIELDS[key]
|
||||
except KeyError:
|
||||
for regexp in self._CF_REGEXPS:
|
||||
match = regexp.fullmatch(key)
|
||||
if match is not None:
|
||||
cfield = RTField(f'CF.{{{match.group(1)}}}', None)
|
||||
self.FIELDS[cfield.key] = cfield
|
||||
self.FIELDS[key] = cfield
|
||||
return cfield
|
||||
raise ValueError(f"unknown RT ticket field {key!r}") from None
|
||||
|
||||
def _meta_key(self, key: str) -> str:
|
||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ from setuptools import setup
|
|||
setup(
|
||||
name='conservancy_beancount',
|
||||
description="Plugin, library, and reports for reading Conservancy's books",
|
||||
version='1.19.2',
|
||||
version='1.19.3',
|
||||
author='Software Freedom Conservancy',
|
||||
author_email='info@sfconservancy.org',
|
||||
license='GNU AGPLv3+',
|
||||
|
|
|
@ -90,6 +90,7 @@ def test_rt_ticket_bad_metadata(ticket_query, meta_name):
|
|||
('Queue', 'approval', {'general'}),
|
||||
('Requestors', 'invoice', {'mx1@example.org', 'requestor2@example.org'}),
|
||||
('Due', 'tax-reporting', {datetime.datetime(2017, 1, 14, 12, 1, 0, tzinfo=UTC)}),
|
||||
('cf.{payment-to}', 'statement', {'Hon. Mx. 1'}),
|
||||
])
|
||||
def test_rt_ticket_from_txn(ticket_query, field_name, meta_name, expected):
|
||||
func = ticket_query(const_operands(field_name, meta_name))
|
||||
|
@ -104,6 +105,7 @@ def test_rt_ticket_from_txn(ticket_query, field_name, meta_name, expected):
|
|||
('Queue', 'approval', {'general'}),
|
||||
('Requestors', 'invoice', {'mx2@example.org', 'requestor2@example.org'}),
|
||||
('Due', 'tax-reporting', {datetime.datetime(2017, 1, 14, 12, 2, 0, tzinfo=UTC)}),
|
||||
('CF_payment-to', 'statement', {'Hon. Mx. 2'}),
|
||||
])
|
||||
def test_rt_ticket_from_post(ticket_query, field_name, meta_name, expected):
|
||||
func = ticket_query(const_operands(field_name, meta_name))
|
||||
|
@ -121,6 +123,7 @@ def test_rt_ticket_from_post(ticket_query, field_name, meta_name, expected):
|
|||
'mx2@example.org',
|
||||
'requestor2@example.org',
|
||||
}, False),
|
||||
('cf_payment-to', 'statement', {'Hon. Mx. 1', 'Hon. Mx. 2'}, True),
|
||||
])
|
||||
def test_rt_ticket_multi_results(ticket_query, field_name, meta_name, expected, on_txn):
|
||||
func = ticket_query(const_operands(field_name, meta_name))
|
||||
|
|
Loading…
Reference in a new issue