mozreview: unify irc nick parsing and disallow periods (
bug 1238353) r?smacleod
MozReview and mozautomation's commitparser disagree when it comes to deciding
if a period is valid in an IRC nick. According to IRC a period is not valid,
which is mozautomation's behavour. Updating mozreview and rbbz extensions to
use the RE defined in mozautomation instead of duplicating the code.
MozReview-Commit-ID: GlcmzbTUkIg
--- a/pylib/mozautomation/mozautomation/commitparser.py
+++ b/pylib/mozautomation/mozautomation/commitparser.py
@@ -28,27 +28,30 @@ SPECIFIER = r'(?:r|a|sr|rs|ui-r)[=?]'
R_SPECIFIER = r'\br[=?]'
R_SPECIFIER_RE = re.compile(R_SPECIFIER)
REQUAL_SPECIFIER_RE = re.compile(r'r=')
RQUESTION_SPECIFIER_RE = re.compile(r'r\?')
LIST = r'[;,\/\\]\s*'
LIST_RE = re.compile(LIST)
-REVIEWER = r'[a-zA-Z0-9\-\_]+' # this needs to match irc nicks
+# Note that we only allows a subset of legal IRC-nick characters.
+# Specifically we not allow [ \ ] ^ ` { | }
+IRC_NICK = r'[a-zA-Z0-9\-\_]+' # this needs to match irc nicks
+BMO_IRC_NICK_RE = re.compile(':(' + IRC_NICK + ')')
REVIEWERS_RE = re.compile(
r'([\s\(\.\[;,])' + # before 'r' delimiter
r'(' + SPECIFIER + r')' + # flag
r'(' + # capture all reviewers
- REVIEWER + # reviewer
+ IRC_NICK + # reviewer
r'(?:' + # additional reviewers
LIST + # delimiter
r'(?![a-z0-9\.\-]+[=?])' + # don't extend match into next flag
- REVIEWER + # reviewer
+ IRC_NICK + # reviewer
r')*' +
r')') # noqa
BACKED_OUT_RE = re.compile('^backed out changeset (?P<node>[0-9a-f]{12}) ',
re.I)
BACKOUT_RE = re.compile('^back\s?out (?P<node>[0-9a-f]{12}) ', re.I)
--- a/pylib/mozautomation/setup.py
+++ b/pylib/mozautomation/setup.py
@@ -1,8 +1,10 @@
from setuptools import setup
-setup(name='mozautomation',
- version='0.1',
- description='Support packages for interacting with parts of Mozilla\'s automation infrastructure',
- author='Mozilla Developer Services',
- packages = ['mozautomation'],
+setup(
+ name='mozautomation',
+ version='0.2',
+ description="Support packages for interacting with parts of Mozilla's "
+ "automation infrastructure",
+ author='Mozilla Developer Services',
+ packages=['mozautomation'],
)
--- a/pylib/mozreview/mozreview/bugzilla/models.py
+++ b/pylib/mozreview/mozreview/bugzilla/models.py
@@ -1,31 +1,23 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import datetime
import logging
-import re
from django.contrib.auth.models import User
from django.db import models, transaction
+from mozautomation.commitparser import BMO_IRC_NICK_RE
from reviewboard.accounts.models import Profile
from reviewboard.reviews.models import ReviewRequest
-
logger = logging.getLogger(__name__)
-# Note that Review Board only allows a subset of legal IRC-nick characters.
-# Specifically, Review Board does not allow [ \ ] ^ ` { | }
-# Anyone with those in their :ircnicks will have them truncated at the last
-# legal character. Not great, but we can later implement a UI for letting
-# people change their usernames in Review Board.
-BZ_IRCNICK_RE = re.compile(':([A-Za-z0-9_\-\.]+)')
-
class BugzillaUserMap(models.Model):
"""Holds Bugzilla-related data about Review Board users.
This model is deprecated in favour of MozReviewUserProfile; please put
any future user data there.
"""
user = models.OneToOneField(User)
@@ -61,17 +53,17 @@ def get_or_create_bugzilla_users(user_da
users = []
for user in user_data['users']:
bz_user_id = user['id']
email = user['email']
real_name = user['real_name']
can_login = user['can_login']
- ircnick_match = BZ_IRCNICK_RE.search(real_name)
+ ircnick_match = BMO_IRC_NICK_RE.search(real_name)
if ircnick_match:
username = ircnick_match.group(1)
else:
username = placeholder_username(email, bz_user_id)
try:
bugzilla_user_map = BugzillaUserMap.objects.get(
--- a/pylib/mozreview/setup.py
+++ b/pylib/mozreview/setup.py
@@ -7,17 +7,18 @@ from mozreview import get_package_versio
setup(
name='mozreview',
version=get_package_version(),
license='MIT',
description='MozReview extension to Review Board',
packages=find_packages(),
install_requires=[
- 'MozillaPulse'
+ 'MozillaPulse',
+ 'mozautomation>=0.2'
],
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
],
entry_points={
'reviewboard.extensions':
'%s = mozreview.extension:MozReviewExtension' % 'mozreview',
--- a/pylib/rbbz/rbbz/auth.py
+++ b/pylib/rbbz/rbbz/auth.py
@@ -4,24 +4,24 @@
import logging
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.utils.translation import ugettext as _
+from mozautomation.commitparser import BMO_IRC_NICK_RE
from reviewboard.accounts.backends import AuthBackend
from reviewboard.accounts.errors import UserQueryError
from mozreview.bugzilla.client import Bugzilla
from mozreview.bugzilla.errors import BugzillaError, BugzillaUrlError
from mozreview.bugzilla.models import (
BugzillaUserMap,
- BZ_IRCNICK_RE,
get_bugzilla_api_key,
get_or_create_bugzilla_users,
)
from mozreview.errors import (
BugzillaAPIKeyNeededError,
WebLoginNeededError,
)
from rbbz.forms import BugzillaAuthSettingsForm
@@ -231,17 +231,17 @@ class BugzillaBackend(AuthBackend):
try:
# We don't want to auto populate just any user because Bugzilla has
# over 300,000 users and most of them aren't relevant to MozReview.
#
# So, we only auto import users if they have IRC nick syntax or
# if the search matches them exactly.
def user_relevant(u):
- if BZ_IRCNICK_RE.search(u['real_name']):
+ if BMO_IRC_NICK_RE.search(u['real_name']):
return True
if u['email'] == query:
return True
# This might allow too many users through. Let's not get too
# attached to this.
if u['real_name'] == query:
return True
--- a/pylib/rbbz/setup.py
+++ b/pylib/rbbz/setup.py
@@ -1,18 +1,20 @@
from reviewboard.extensions.packaging import setup
PACKAGE = 'rbbz'
VERSION = '0.2.9'
-setup(name=PACKAGE,
- version=VERSION,
- description='Review Board extension for Bugzilla support',
- url='https://github.com/mozilla/rbbz',
- author='Mark Cote',
- author_email='mcote@mozilla.com',
- license='MPL 2.0',
- packages=['rbbz'],
- entry_points={
- 'reviewboard.extensions':
- '%s = rbbz.extension:BugzillaExtension' % PACKAGE,
- }
+setup(
+ name=PACKAGE,
+ version=VERSION,
+ description='Review Board extension for Bugzilla support',
+ url='https://github.com/mozilla/rbbz',
+ author='Mark Cote',
+ author_email='mcote@mozilla.com',
+ license='MPL 2.0',
+ packages=['rbbz'],
+ install_requires=['mozautomation>=0.2'],
+ entry_points={
+ 'reviewboard.extensions':
+ '%s = rbbz.extension:BugzillaExtension' % PACKAGE,
+ }
)