author Ehsan Akhgari <>
Wed, 07 May 2014 14:56:45 -0400
changeset 191 6f53da7dc8d3904653342d7a578fe4c28b991ca0
parent 188 94e6623eb57646b4e7fd4c13b1eb520ffbe2c956
child 193 476532bb505e7592f3d0d930d6213340aae7c239
permissions -rwxr-xr-x
Bug 1007235 - Search for all occurrences of the reviewers regex in prevent_webidl_hooks, not just the first one; r=ted

# Copyright (C) 2012 Mozilla Foundation
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
This hook is to prevent changes to .webidl files in pushes without proper DOM peer review.

import re
from mercurial.node import short

# Stolen from
backoutMessage = [re.compile(x) for x in [

def isBackout(message):
    for r in backoutMessage:
            return True
    return False

def hook(ui, repo, hooktype, node, **kwargs):
    DOM_peers = [
        'jst',              # Johnny Stenback
        'peterv',           # Peter Van der Beken
        'bz', 'bzbarsky',   # Boris Zbarsky
        'sicking', 'jonas', # Jonas Sicking
        'smaug',            # Olli Pettay
        'bent',             # Ben Turner
        'mounir',           # Mounir Lamouri
        'khuey',            # Kyle Huey
        'jlebar',           # Justin Lebar
        'hsivonen',         # Henri Sivonen
        'mrbkap',           # Blake Kaplan
        'bholley',          # Bobby Holley
    error = ""
    webidlReviewed = False
    # Loop through each changeset being added to the repository
    changesets = list(repo.changelog.revs(repo[node].rev()))
    for i in reversed(changesets):
        c = repo.changectx(i)

        if len(c.parents()) > 1:
            # Skip merge changesets

        # Loop through each file for the current changeset
        for file in c.files():
            # Only Check WebIDL Files
            if file.endswith('.webidl'):
                message = c.description().lower()
                def search():
                  matches = re.findall('\Wr\s*=\s*(\w+(?:,\w+)*)', message)
                  for match in matches:
                      for reviewer in match.split(','):
                          if reviewer in DOM_peers:
                              return True
                  return False
                webidlReviewed = search()
                if not webidlReviewed and not isBackout(message):
                        error += "WebIDL file %s altered in changeset %s without DOM peer review\n" % (file, short(c.node()))
    # Check if an error occured in any of the files that were changed
    if error != "":
        print "\n\n************************** ERROR ****************************"
        ui.warn("\n" + error + "\n")
        print "\n\rChanges to WebIDL files in this repo require review from a DOM peer in the form of r=...\n\rThis is to ensure that we behave responsibly with exposing new Web APIs. We appreciate your understanding..\n\r"
        print "*************************************************************\n\n"
        # Reject the changesets
        return 1
        if webidlReviewed:
            print "You've received proper review from a DOM peer on your WebIDL change(s) in your push, thanks for paying enough attention."
    # Accept the changesets
    return 0