Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions ticketconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ def _setup_providers(self):
p.append( h.GitlabTitleProvider( 'gitlab.torproject.org',
'https://gitlab.torproject.org/',
prefix='tor:',
default_re=r'(?<!\w)(?:tor:|gitlabtpo:|https://gitlab.torproject.org/)(?P<path>[\w-]+/[\w/-]*\w)(?:#|/-/issues/)(?P<number>[0-9]+)(?:(?=\W)|$)',
postfix=' - https://bugs.torproject.org/%s/%s',
status_finder = h.GitLabStatusExtractor,
default_re=r'(?<!\w)(?:tor:|gitlabtpo:|https://gitlab.torproject.org/)(?P<path>[\w/-]*\w)(?:#|/-/issues/)(?P<number>[0-9]+)(?:(?=\W)|$)',
))
p.append( h.TicketHtmlTitleProvider( 'gitlab.torproject.org-legacy',
'https://gitlab.torproject.org/legacy/trac/-/issues/',
prefix='tor',
fixup=h.ReGroupFixup('(.*?) \(#[0-9]+\) . Issues . .*? . GitLab$'),
default_re=r'(?<!\w)(?:[tT]or#|https://trac.torproject.org/projects/tor/ticket/)([0-9]{4,})(?:(?=\W)|$)',
default_re=r'(?<!\w)(?:#|https://trac.torproject.org/projects/tor/ticket/)([0-9]{4,})(?:(?=\W)|$)',
postfix=' - https://bugs.torproject.org/%s',
status_finder = h.GitLabStatusExtractor,
))
Expand Down Expand Up @@ -122,7 +120,7 @@ def _setup_providers(self):
def _setup_channels(self):
for tor in ('#ooni', '#nottor', '#tor*', '#tpo-admin'):
self.providers['gitlab.torproject.org-legacy'].addChannel(tor, default=True)
self.providers['gitlab.torproject.org' ].addChannel(tor, regex=r'(?<!\w)(?P<path>[\w-]+/[\w/-]*\w)#(?P<number>[0-9]+)(?:(?=\W)|$)')
self.providers['gitlab.torproject.org' ].addChannel(tor, regex=r'(?<!\w)(?P<path>[\w/-]*\w)#(?P<number>[0-9]+)(?:(?=\W)|$)')
self.providers['proposal.torproject.org' ].addChannel(tor, regex='(?<!\w)[Pp]rop#([0-9]+)(?:(?=\W)|$)')

self.providers['gitproxy.zycloud.tk-tor-ooni-probe-pull'].addChannel('#ooni', regex='(?<!\w)(?:PR#|https://github.com/TheTorProject/ooni-probe/pull/)([0-9]+)(?:(?=\W)|$)')
Expand Down
35 changes: 27 additions & 8 deletions tickethelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
###

from bs4 import BeautifulSoup
from gitlab import Gitlab
import os
import re
import subprocess
Expand Down Expand Up @@ -265,7 +266,7 @@ def _gettitle(self, ticketnumber, url=None):
return res


class GitlabTitleProvider(TicketHtmlTitleProvider):
class GitlabTitleProvider(BaseProvider):
"""A ticket information provider that extracts the title
tag from GitLab issues at $url/$path/-/issues/$ticketnumber."""

Expand All @@ -277,7 +278,9 @@ def __init__(self, name, url, *args, **kwargs):
if 'fixup' not in kwargs:
kwargs['fixup'] = GitlabTitleProvider.gitlab_fixup

TicketHtmlTitleProvider.__init__(self, name, url, *args, **kwargs)

BaseProvider.__init__(self, name, *args, **kwargs)
self.gl = Gitlab(url)

@staticmethod
def gitlab_fixup(ticketnumber, title, extra):
Expand All @@ -286,16 +289,32 @@ def gitlab_fixup(ticketnumber, title, extra):
m = re.match('(.*?)\s*(?:\(#[0-9]+\)) \S{1,2} Issues \S{1,2} .+(?: / .+) \S{1,2} GitLab$', title)
if m and len(m.groups()) > 0: title = m.group(1)

# the url and ticketnumber can be added via a postfix, we do not need it here
#res = '%s#%s: %s - %s%s'%(extra['path'], extra['ticketnumber'], title, extra['url'], extra['ticketnumber'])
res = '%s#%s: %s'%(extra['path'], extra['ticketnumber'], title)
res = '%s#%s: %s - %s'%(extra['path'], extra['ticketnumber'], title, extra['url'])
return res

def _gettitle(self, ticketnumber):
path, ticketnumber = ticketnumber
url = '%s%s/-/issues/' % (self.url, path)
res = super()._gettitle(ticketnumber, url=url)
res['url'] = url
group = self.gl.groups.get('tpo')
issues = group.issues.list(iids=ticketnumber)

res = {}
for issue in issues:
issue_path = issue.references['relative'].split("#")[0]
if issue_path.endswith("/"+path) or issue_path == path:
if 'title' in res:
# if more than one project matches this issue, fail
log.warning("More than one project, raising error")
raise IndexError('More than one project with that name')
res['title'] = issue.title
res['url'] = issue.web_url
res['status'] = issue.state

if not 'title' in res:
# couldn't find any issues in provided project
log.warning("ticket %s#%s not found, raising error" % (ticketnumber, path))
raise IndexError('No ticket found')

res['title'] = "%s - [%s]" % (res['title'], res['status'])
res['path'] = path
res['ticketnumber'] = ticketnumber
return res
Expand Down