Skip to content

Commit

Permalink
Add support for authorlist
Browse files Browse the repository at this point in the history
This makes it possible to enforce both the committer name and the author name,
while not enforcing them to actually be the same. Meaning one committer
can commit a patch authored by another one.

As asked for by Peter E.
  • Loading branch information
mhagander committed Jan 5, 2013
1 parent 6da709c commit df4138f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.rst
Expand Up @@ -120,6 +120,12 @@ committerlist
config file. This ensures that committers don't accidentally use a
badly configured client. All the commiters should be listed in the
[committers] section, in the format User Name=email.
authorlist
Enforce that the username and email of the author is listed in the
config file. It uses the same list of users as the committerlist,
thus it should be listed in [committers]. This allows one committer
to push things made by another committer, while still making sure
all authors are registered.
nolightweighttags
Enforce that there are no lightweight tags - only tags carrying
a description are allowed.
Expand Down
30 changes: 17 additions & 13 deletions policyenforce.py
Expand Up @@ -8,7 +8,7 @@
# Note: the script (not surprisingly) uses the git commands in pipes, so git
# needs to be available in the path.
#
# Copyright (C) 2010-2011 PostgreSQL Global Development Group
# Copyright (C) 2010-2013 PostgreSQL Global Development Group
# Author: Magnus Hagander <magnus@hagander.net>
#
# Released under the PostgreSQL license
Expand Down Expand Up @@ -149,19 +149,23 @@ def check_policies(self):

if self._enforce("committerlist"):
# Enforce specific committer listed in config file.
# We do this by splitting the name again, and doing a lookup
# match on that.
m = re.search('^([a-zA-Z0-9. ]+) <([^>]+)>', self.committer)
if not m:
raise Exception("Committer '%s' for commit %s does not follow format rules." % (self.committer, self.commitid))
if not c.has_option('committers', m.group(1)):
self._policyfail("Committer %s not listed in committers section" % m.group(1))
if not c.get('committers', m.group(1)) == m.group(2):
self._policyfail("Committer %s has wrong email (%s, should be %s)" % (
m.group(1), m.group(2), c.get('committers', m.group(1))))
# Currently no policy for "authorlist" - expect committerequalsauthor+committerlist to be
# used in those cases.
self.enforce_user(self.committer, 'Committer')

if self._enforce("authorlist"):
# Enforce specific author is listed in config file (as committer).
self.enforce_user(self.author, 'Author')

def enforce_user(self, user, usertype):
# We do this by splitting the name again, and doing a lookup
# match on that.
m = re.search('^([a-zA-Z0-9. ]+) <([^>]+)>', user)
if not m:
raise Exception("%s '%s' for commit %s does not follow format rules." % (usertype, user, self.commitid))
if not c.has_option('committers', m.group(1)):
self._policyfail("%s %s not listed in committers section" % (usertype, m.group(1)))
if not c.get('committers', m.group(1)) == m.group(2):
self._policyfail("%s %s has wrong email (%s, should be %s)" % (
usertype, m.group(1), m.group(2), c.get('committers', m.group(1))))

class Tag(PolicyObject):
def __init__(self, ref, name):
Expand Down

0 comments on commit df4138f

Please sign in to comment.