Code documentation: fix 🎫 reference to query github
Previously it queried long obsolete Trac at wiki.qubes-os.org.
This commit is contained in:
parent
d7d926edaa
commit
72bc0506b9
@ -29,7 +29,7 @@ particularly our custom Sphinx extension.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import csv
|
import json
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
import re
|
import re
|
||||||
@ -52,21 +52,27 @@ SUBCOMMANDS_TITLE = 'COMMANDS'
|
|||||||
OPTIONS_TITLE = 'OPTIONS'
|
OPTIONS_TITLE = 'OPTIONS'
|
||||||
|
|
||||||
|
|
||||||
def fetch_ticket_info(uri):
|
class GithubTicket(object):
|
||||||
|
def __init__(self, data):
|
||||||
|
self.number = data['number']
|
||||||
|
self.summary = data['title']
|
||||||
|
self.uri = data['html_url']
|
||||||
|
|
||||||
|
def fetch_ticket_info(app, number):
|
||||||
'''Fetch info about particular trac ticket given
|
'''Fetch info about particular trac ticket given
|
||||||
|
|
||||||
:param str uri: URI at which ticket resides
|
:param app: Sphinx app object
|
||||||
|
:param str number: number of the ticket, without #
|
||||||
:rtype: mapping
|
:rtype: mapping
|
||||||
:raises: urllib2.HTTPError
|
:raises: urllib2.HTTPError
|
||||||
'''
|
'''
|
||||||
|
|
||||||
data = urllib2.urlopen(uri + '?format=csv').read()
|
response = urllib2.urlopen(urllib2.Request(
|
||||||
reader = csv.reader((line + '\n' for line in data.split('\r\n')),
|
app.config.ticket_base_uri.format(number=number),
|
||||||
quoting=csv.QUOTE_MINIMAL, quotechar='"')
|
headers={
|
||||||
|
'Accept': 'application/vnd.github.v3+json',
|
||||||
return dict(zip(*((cell.decode('utf-8') for cell in row)
|
'User-agent': __name__}))
|
||||||
for row in list(reader)[:2])))
|
return GithubTicket(json.load(response))
|
||||||
|
|
||||||
|
|
||||||
def ticket(name, rawtext, text, lineno, inliner, options=None, content=None):
|
def ticket(name, rawtext, text, lineno, inliner, options=None, content=None):
|
||||||
'''Link to qubes ticket
|
'''Link to qubes ticket
|
||||||
@ -91,10 +97,8 @@ def ticket(name, rawtext, text, lineno, inliner, options=None, content=None):
|
|||||||
prb = inliner.problematic(rawtext, rawtext, msg)
|
prb = inliner.problematic(rawtext, rawtext, msg)
|
||||||
return [prb], [msg]
|
return [prb], [msg]
|
||||||
|
|
||||||
app = inliner.document.settings.env.app
|
|
||||||
uri = posixpath.join(app.config.ticket_base_uri, ticketno)
|
|
||||||
try:
|
try:
|
||||||
info = fetch_ticket_info(uri)
|
info = fetch_ticket_info(inliner.document.settings.env.app, ticketno)
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
msg = inliner.reporter.error(
|
msg = inliner.reporter.error(
|
||||||
'Error while fetching ticket info: {!s}'.format(e), line=lineno)
|
'Error while fetching ticket info: {!s}'.format(e), line=lineno)
|
||||||
@ -105,8 +109,8 @@ def ticket(name, rawtext, text, lineno, inliner, options=None, content=None):
|
|||||||
|
|
||||||
node = docutils.nodes.reference(
|
node = docutils.nodes.reference(
|
||||||
rawtext,
|
rawtext,
|
||||||
'#{} ({})'.format(ticketno, info['summary']),
|
'#{} ({})'.format(info.number, info.summary),
|
||||||
refuri=uri,
|
refuri=info.uri,
|
||||||
**options)
|
**options)
|
||||||
|
|
||||||
return [node], []
|
return [node], []
|
||||||
@ -423,8 +427,10 @@ def break_to_pdb(app, *dummy):
|
|||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_role('ticket', ticket)
|
app.add_role('ticket', ticket)
|
||||||
app.add_config_value('ticket_base_uri',
|
app.add_config_value(
|
||||||
'https://wiki.qubes-os.org/ticket/', 'env')
|
'ticket_base_uri',
|
||||||
|
'https://api.github.com/repos/QubesOS/qubes-issues/issues/{number}',
|
||||||
|
'env')
|
||||||
app.add_config_value('break_to_pdb', False, 'env')
|
app.add_config_value('break_to_pdb', False, 'env')
|
||||||
app.add_node(versioncheck,
|
app.add_node(versioncheck,
|
||||||
html=(visit, depart),
|
html=(visit, depart),
|
||||||
|
Loading…
Reference in New Issue
Block a user