3 from docutils
.nodes
import reference
5 STEM_TICKET_URL
= 'https://github.com/torproject/stem/issues/{ticket}'
6 TOR_TICKET_URL
= 'https://gitlab.torproject.org/tpo/core/tor/-/issues/{ticket}'
7 ARCHIVE_TICKET_URL
= 'https://gitlab.torproject.org/legacy/trac/-/issues/{ticket}'
8 SPEC_URL
= 'https://gitweb.torproject.org/torspec.git/commit/?id={commit}'
11 def role_ticket(name
, rawtext
, argument
, lineno
, inliner
, options
= {}, content
= []):
13 Alias :ticket:`1234` or :ticket:`tor-1234` to a link for that ticket. Tickets
14 default to be for Stem if no project is indicated.
18 project
, ticket
= argument
.split('-', 1)
20 project
, ticket
= 'stem', argument
22 if not ticket
.isdigit() or int(ticket
) <= 0:
23 return error('Invalid ticket number: %s' % ticket
, rawtext
, lineno
, inliner
)
26 label
= 'ticket %s' % ticket
27 url
= STEM_TICKET_URL
.format(ticket
= ticket
)
28 elif project
== 'archive':
29 label
= 'ticket %s' % ticket
30 url
= ARCHIVE_TICKET_URL
.format(ticket
= ticket
)
31 elif project
== 'tor':
32 label
= 'tor ticket %s' % ticket
33 url
= TOR_TICKET_URL
.format(ticket
= ticket
)
35 return error('Project %s is unrecognized: %s' % (project
, argument
), rawtext
, lineno
, inliner
)
38 [reference(rawtext
, label
, refuri
= url
, **options
)],
43 def role_spec(name
, rawtext
, argument
, lineno
, inliner
, options
= {}, content
= []):
45 Aliases :spec:`25b0d43` to 'https://gitweb.torproject.org/torspec.git/commit/?id=25b0d43'.
48 if not re
.match('^[0-9a-f]{7}$', argument
):
49 return error('Spec tag expects a short commit id (seven hex characters): %s' % argument
, rawtext
, lineno
, inliner
)
52 [reference(rawtext
, 'spec', refuri
= SPEC_URL
.format(commit
= argument
), **options
)],
57 def error(message
, rawtext
, lineno
, inliner
):
58 msg
= inliner
.reporter
.error(message
, line
= lineno
)
59 prb
= inliner
.problematic(rawtext
, rawtext
, msg
)
68 :param app: sphinx application context
71 app
.add_role('ticket', role_ticket
)
72 app
.add_role('spec', role_spec
)