diff --git a/ticketconfig.py b/ticketconfig.py index ff0cb4d..c0826e1 100644 --- a/ticketconfig.py +++ b/ticketconfig.py @@ -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-]+/[\w/-]*\w)(?:#|/-/issues/)(?P[0-9]+)(?:(?=\W)|$)', - postfix=' - https://bugs.torproject.org/%s/%s', - status_finder = h.GitLabStatusExtractor, + default_re=r'(?[\w/-]*\w)(?:#|/-/issues/)(?P[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-]+/[\w/-]*\w)#(?P[0-9]+)(?:(?=\W)|$)') + self.providers['gitlab.torproject.org' ].addChannel(tor, regex=r'(?[\w/-]*\w)#(?P[0-9]+)(?:(?=\W)|$)') self.providers['proposal.torproject.org' ].addChannel(tor, regex='(? 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