Changeset View
Changeset View
Standalone View
Standalone View
Phabricator/plugin.py
Show First 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | def diff_status_theme(self, status): | ||||
return status | return status | ||||
def phabricator_object_from_regexp(self, irc, msg, match): | def phabricator_object_from_regexp(self, irc, msg, match): | ||||
r""" | r""" | ||||
(?: | (?: | ||||
^ # start of line | ^ # start of line | ||||
|(?<![:])\b # word boundary, not preceded by ":" | |(?<![:])\b # word boundary, not preceded by ":" | ||||
) | ) | ||||
[A-Z]\d+ | ([A-Z])(\d+)(#\d+[-A-Za-z0-9]*)* # optional comment | ||||
(?: | (?: | ||||
vlorentz: Replace the last `*` by a `?`, there's at most one fragment. | |||||
Done Inline ActionsRight! ardumont: Right! | |||||
$ # end of line | $ # end of line | ||||
|\b # word boundary | |\b # word boundary | ||||
) | ) | ||||
""" | """ | ||||
for recipient in msg.args[0].split(','): | for recipient in msg.args[0].split(','): | ||||
object_tag = match.group(0) | object_type = match.group(1) | ||||
Done Inline Actions@vlorentz asked for this, so the bot can hint even lowered-case object ardumont: @vlorentz asked for this, so the bot can hint even lowered-case object | |||||
object_type = object_tag[0] | |||||
object_id = int(object_tag[1:]) | |||||
lookup = { | lookup = { | ||||
'B': self.conduit(recipient).harbormaster.build.search, | 'B': self.conduit(recipient).harbormaster.build.search, | ||||
'D': self.conduit(recipient).differential.revision.search, | 'D': self.conduit(recipient).differential.revision.search, | ||||
'P': self.conduit(recipient).paste.search, | 'P': self.conduit(recipient).paste.search, | ||||
'T': self.conduit(recipient).maniphest.search, | 'T': self.conduit(recipient).maniphest.search, | ||||
} | } | ||||
if object_type not in lookup: | if object_type not in lookup: | ||||
return | return | ||||
object_id = int(match.group(2)) | |||||
object_fragment = match.group(3) # Or None as this is optional | |||||
lookup_args = { | lookup_args = { | ||||
'constraints': { | 'constraints': { | ||||
'ids': [object_id], | 'ids': [object_id], | ||||
}, | }, | ||||
} | } | ||||
query = lookup[object_type](**lookup_args) | query = lookup[object_type](**lookup_args) | ||||
r = query.response | r = query.response | ||||
if not r['data']: | if not r['data']: | ||||
return | return | ||||
object = r['data'][0] | object = r['data'][0] | ||||
formatter = { | formatter = { | ||||
'B': self.build_formatter, | 'B': self.build_formatter, | ||||
'D': self.diff_formatter, | 'D': self.diff_formatter, | ||||
'P': self.paste_formatter, | 'P': self.paste_formatter, | ||||
'T': self.task_formatter, | 'T': self.task_formatter, | ||||
} | } | ||||
self.wrapped_message( | self.wrapped_message( | ||||
irc.reply, | irc.reply, | ||||
formatter[object_type](recipient, object), | formatter[object_type](recipient, object, object_fragment), | ||||
notice=True, | notice=True, | ||||
prefixNick=False, | prefixNick=False, | ||||
to=recipient, | to=recipient, | ||||
) | ) | ||||
def build_formatter(self, recipient, build): | def build_formatter(self, recipient, build, object_fragment=None): | ||||
full_build = self.get_object_by_phid(recipient, build['phid'], True) | full_build = self.get_object_by_phid(recipient, build['phid'], True) | ||||
buildable = self.get_buildable(recipient, | buildable = self.get_buildable(recipient, | ||||
build['fields']['buildablePHID']) | build['fields']['buildablePHID']) | ||||
details = [] | details = [] | ||||
status = build['fields']['buildStatus']['name'] | status = build['fields']['buildStatus']['name'] | ||||
details.append('status: %s' % self.build_status_theme(status)) | details.append('status: %s' % self.build_status_theme(status)) | ||||
return "{id} for {buildable} ({details}): {title} <{url}>".format( | return "{id} for {buildable} ({details}): {title} <{url}>".format( | ||||
id=ircutils.bold('B%s' % build['id']), | id=ircutils.bold('B%s' % build['id']), | ||||
buildable=buildable['buildable']['fullName'], | buildable=buildable['buildable']['fullName'], | ||||
title=build['fields']['name'], | title=build['fields']['name'], | ||||
details=', '.join(details), | details=', '.join(details), | ||||
url=full_build['uri'], | url=full_build['uri'], | ||||
) | ) | ||||
def diff_formatter(self, recipient, diff): | def diff_formatter(self, recipient, diff, object_fragment=None): | ||||
full_diff = self.get_object_by_phid(recipient, diff['phid'], True) | full_diff = self.get_object_by_phid(recipient, diff['phid'], True) | ||||
repo = self.get_repo(recipient, diff['fields']['repositoryPHID']) | repo = self.get_repo(recipient, diff['fields']['repositoryPHID']) | ||||
details = [] | details = [] | ||||
details.append( | details.append( | ||||
'author: %s' % self.get_user_by_phid( | 'author: %s' % self.get_user_by_phid( | ||||
recipient, diff['fields']['authorPHID'] | recipient, diff['fields']['authorPHID'] | ||||
) | ) | ||||
) | ) | ||||
status = diff['fields']['status']['name'] | status = diff['fields']['status']['name'] | ||||
details.append(self.diff_status_theme(status)) | details.append(self.diff_status_theme(status)) | ||||
url = full_diff['uri'] | |||||
if object_fragment is not None: | |||||
url = '%s%s' % (url, object_fragment) | |||||
return "{id} ({details}) on {repo}: {title} <{url}>".format( | return "{id} ({details}) on {repo}: {title} <{url}>".format( | ||||
id=ircutils.bold('D%s' % diff['id']), | id=ircutils.bold('D%s' % diff['id']), | ||||
repo=ircutils.bold(self.get_repo_name(repo)), | repo=ircutils.bold(self.get_repo_name(repo)), | ||||
title=diff['fields']['title'], | title=diff['fields']['title'], | ||||
details=', '.join(details), | details=', '.join(details), | ||||
url=full_diff['uri'], | url=url, | ||||
) | ) | ||||
def paste_formatter(self, recipient, paste): | def paste_formatter(self, recipient, paste, object_fragment=None): | ||||
full_paste = self.get_object_by_phid(recipient, paste['phid'], True) | full_paste = self.get_object_by_phid(recipient, paste['phid'], True) | ||||
details = [] | details = [] | ||||
details.append( | details.append( | ||||
'author: %s' % self.get_user_by_phid( | 'author: %s' % self.get_user_by_phid( | ||||
recipient, paste['fields']['authorPHID'] | recipient, paste['fields']['authorPHID'] | ||||
) | ) | ||||
) | ) | ||||
url = full_paste['uri'] | |||||
if object_fragment is not None: | |||||
url = '%s%s' % (url, object_fragment) | |||||
return "{id} ({details}): {title} <{url}>".format( | return "{id} ({details}): {title} <{url}>".format( | ||||
id=ircutils.bold('P%s' % paste['id']), | id=ircutils.bold('P%s' % paste['id']), | ||||
title=paste['fields']['title'], | title=paste['fields']['title'], | ||||
details=', '.join(details), | details=', '.join(details), | ||||
url=full_paste['uri'], | url=url, | ||||
) | ) | ||||
def task_formatter(self, recipient, task): | def task_formatter(self, recipient, task, object_fragment=None): | ||||
full_task = self.get_object_by_phid(recipient, task['phid'], True) | full_task = self.get_object_by_phid(recipient, task['phid'], True) | ||||
details = [] | details = [] | ||||
details.append( | details.append( | ||||
'submitter: %s' % self.get_user_by_phid( | 'submitter: %s' % self.get_user_by_phid( | ||||
recipient, task['fields']['authorPHID'] | recipient, task['fields']['authorPHID'] | ||||
) | ) | ||||
) | ) | ||||
if task['fields']['ownerPHID']: | if task['fields']['ownerPHID']: | ||||
details.append( | details.append( | ||||
'owner: %s' % self.get_user_by_phid( | 'owner: %s' % self.get_user_by_phid( | ||||
recipient, task['fields']['ownerPHID'] | recipient, task['fields']['ownerPHID'] | ||||
) | ) | ||||
) | ) | ||||
priority = task['fields']['priority']['name'] | priority = task['fields']['priority']['name'] | ||||
if priority != 'Normal': | if priority != 'Normal': | ||||
details.append('priority %s' % self.task_priority_theme(priority)) | details.append('priority %s' % self.task_priority_theme(priority)) | ||||
status = task['fields']['status']['name'] | status = task['fields']['status']['name'] | ||||
details.append('status: %s' % self.task_status_theme(status)) | details.append('status: %s' % self.task_status_theme(status)) | ||||
url = full_task['uri'] | |||||
if object_fragment is not None: | |||||
url = '%s%s' % (url, object_fragment) | |||||
return "{id} ({details}): {title} <{url}>".format( | return "{id} ({details}): {title} <{url}>".format( | ||||
id=ircutils.bold('T%s' % task['id']), | id=ircutils.bold('T%s' % task['id']), | ||||
title=task['fields']['name'], | title=task['fields']['name'], | ||||
details=', '.join(details), | details=', '.join(details), | ||||
url=full_task['uri'], | url=url, | ||||
) | ) | ||||
def commit_formatter(self, recipient, commit, skip_details=None): | def commit_formatter(self, recipient, commit, skip_details=None): | ||||
if not skip_details: | if not skip_details: | ||||
skip_details = [] | skip_details = [] | ||||
details = [] | details = [] | ||||
if 'author' not in skip_details: | if 'author' not in skip_details: | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |
Replace the last * by a ?, there's at most one fragment.