Hello Everybody,

I am using reviewboard server 1.7.26. I am trying to develop a system which 
will create a review-request when a use commit any from the client side. I 
decided go with pre-commit hook. For this i already configure the server 
and in my svn repository hook i added a script which will call a script to 
generate review-request. But i can't generate a single review-request with 
this process.I am not even sure where i am missing any thing here. So it 
will be great if any body help me to overcome this issue. below i am 
attaching  scripts that i have used and error logs i am getting in the 
server. Please 

Error logs: 
Sending        hello.txt
Transmitting file data .svn: Commit failed (details follow):
svn: Commit blocked by pre-commit hook (exit code 1) with output:
Executing pre-commit check
svnlook: Can't open file '73-48/format': No such file or directory
Log message is empty, no review request created

pre-commit script:

echo "Executing pre-commit check" >&2
"$TXN" "$REPOS" || exit 1

Get the Review Board Power Pack at http://www.reviewboard.org/powerpack/
Sign up for Review Board hosting at RBCommons: https://rbcommons.com/
Happy user? Let us know at http://www.reviewboard.org/users/
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to reviewboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/env python
# reviewboard-post-commit-hook
# This script should be invoked from the subversion post-commit hook like this:
# REPOS="$1"
# REV="$2"
# /usr/bin/python /some/path/reviewboard-post-commit-hook.py "$REPOS" "$REV" || exit 1
# Searches the commit message for text in the form of:
#   publish review - publishes a review request draft review - creates a 
#   draft review request
# The space before 'review' may be ommitted.
# The log message is interpreted for review request parameters:
#    summary = first 150 chars 
#    description = entire log message
#    existing review updated if log message includes 'review:[0-9]+'
#    bugs added to review if log message includes commands as defined in
#      supported_ticket_cmds
# The review request is created out of a diff between the current revision (M)
# and either the previous version (M-1) or any other revision if the log
# message includes 'prevrev:[0-9]+'.  The latter option is useful for creating
# a review that spans multiple commits.
# An example commit message is:
#    Changed blah and foo to do this or that.  Publish review ticket:1 review:2 prevrev:3.
# This would update the existing review 2 with a diff between this commit and
# revision 3.  It would place the entire log message in the review summary and
# description, and put bug id 1 in the bugs field.

# User configurable variables

# path to post-review script, which must be renamed/copied to
# postreview.py so that it can be loaded as a module.
POSTREVIEW_PATH = '/usr/local/bin/'
SVNLOOK_PATH = '/usr/bin/svnlook'
REVIEWBOARD_SERVER = 'http://localhost'
ADMIN_PASSWORD = 'sbrc123'

# end user configurable variables

import sys
import re
import subprocess

# import the Review Board 'postreview' script as a module
import postreview

# list of trac commands from trac-post-commit-hook.py.
# numbers following these commands will be added to the bugs
# field of the review request.
supported_ticket_cmds = {'close':      '_cmdClose',
                         'closed':     '_cmdClose',
                         'closes':     '_cmdClose',
                         'fix':        '_cmdClose',
                         'fixed':      '_cmdClose',
                         'fixes':      '_cmdClose',
                         'addresses':  '_cmdRefs',
                         're':         '_cmdRefs',
                         'references': '_cmdRefs',
                         'refs':       '_cmdRefs',
                         'see':        '_cmdRefs'}

ticket_prefix = '(?:#|(?:ticket|issue|bug)[: ]?)'
ticket_reference = ticket_prefix + '[0-9]+'
ticket_command = (r'(?P<action>[A-Za-z]*).?'
                  '(?P<ticket>%s(?:(?:[, &]*|[ ]?and[ ]?)%s)*)' %
                  (ticket_reference, ticket_reference))

def main():
    if len(sys.argv) != 3:
        print >> sys.stderr, 'Usage: %s <repos> <txn>' % sys.argv[0]

    repos = sys.argv[1]
    txn = sys.argv[2]

    # get the log message
    svnlook = [SVNLOOK_PATH, 'log', '-t', txn, repos]
    log = subprocess.Popen(svnlook, stdout=subprocess.PIPE).communicate()[0]

    # error if log message is blank
    if len(log.strip()) < 1:
        sys.stderr.write("Log message is empty, no review request created")

    # get the author
    svnlook = [SVNLOOK_PATH, 'author', '-t', txn, repos]
    author = subprocess.Popen(svnlook, stdout=subprocess.PIPE).communicate()[0]
    author = author.split('\n')[0]
    author = author.split('@')[0].replace('.','')

    # error if author is blank
    if len(author.strip()) < 1:
        sys.stderr.write("Author is blank, no review request created")

    # get the diff
    svnlook = [SVNLOOK_PATH, 'diff', '-t', txn, repos]
    diff = subprocess.Popen(svnlook, stdout=subprocess.PIPE).communicate()[0]
    filename = '/tmp/reviewboard-diff-%s' % (txn)
        fd = file(filename, 'wb')
        sys.stderr.write("Unable to write temporary diff, abort.")

    # check whether to create a review, based on presence of word 
    # 'review' with prefix
    review=r'(?:publish|draft)(?: )?review'
    if None == re.search(review, log, re.M | re.I):
        print 'No review requested'

    # check for update to existing review
    m = re.search(r'review:([0-9]+)', log, re.M | re.I)
    if m:
        reviewid='--review-request-id=' + m.group(1)

    # check whether to publish or leave review as draft
    if re.search(r'draft(?: )?review', log, re.M | re.I):

    # get bug numbers referenced in this log message
    ticket_command_re = re.compile(ticket_command)
    ticket_re = re.compile(ticket_prefix + '([0-9]+)')

    ticket_ids = []
    ticket_cmd_groups = ticket_command_re.findall(log)
    for cmd, tkts in ticket_cmd_groups:
        funcname = supported_ticket_cmds.get(cmd.lower(), '')
        if funcname:
            for tkt_id in ticket_re.findall(tkts):

    if ticket_ids:
        bugs='--bugs-closed=' + ','.join(ticket_ids)

    # other parameters for postreview
    #summary='--summary=' + log[:150].splitlines().pop(0)
    description='--description=' + log
    submitas='--submit-as=' + author
    difffile='--diff=' + filename
    args = ['post-review', '-d', publish, description,submitas, difffile,
            reviewid, bugs, repo, rbserver, username, password]

    # Run Review Board post-review script
    print '==> Post review for %s, transaction %s' % (author, txn)
    ret = postreview.main(args)
    return ret

if __name__ == '__main__':

# The pre-commit hook is invoked before a Subversion txn is
# committed.  Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#   [1] REPOS-PATH   (the path to this repository)
#   [2] TXN-NAME     (the name of the txn about to be committed)
#   [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.
#   If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a
#   single newline), the lines following it are the lock tokens for
#   this commit.  The end of the list is marked by a line containing
#   only a newline character.
#   Each lock token line consists of a URI-escaped path, followed
#   by the separator character '|', followed by the lock token string,
#   followed by a newline.
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
# If the hook program exits with success, the txn is committed; but
# if it exits with failure (non-zero), the txn is aborted, no commit
# takes place, and STDERR is returned to the client.   The hook
# program can use the 'svnlook' utility to help it examine the txn.
# On a Unix system, the normal procedure is to have 'pre-commit'
# invoke other programs to do the real work, though it may do the
# work itself too.
#   ***  FOR REVISION PROPERTIES (like svn:log or svn:author).   ***
#   This is why we recommend using the read-only 'svnlook' utility.
#   In the future, Subversion may enforce the rule that pre-commit
#   hooks should not modify the versioned data in txns, or else come
#   up with a mechanism to make it safe to do so (by informing the
#   committing client of the changes).  However, right now neither
#   mechanism is implemented, so hook writers just have to be careful.
# Note that 'pre-commit' must be executable by the user(s) who will
# invoke it (typically the user httpd runs as), and that user must
# have filesystem-level permission to access the repository.
# On a Windows system, you should name the hook program
# 'pre-commit.bat' or 'pre-commit.exe',
# but the basic idea is the same.
# The hook program typically does not inherit the environment of
# its parent process.  For example, a common problem is for the
# PATH environment variable to not be set to its usual value, so
# that subprograms fail to launch unless invoked via absolute path.
# If you're having unexpected problems with a hook program, the
# culprit may be unusual (or missing) environment variables.
# Here is an example hook script, for a Unix /bin/sh interpreter.
# For more examples and pre-written hooks, see those in
# /usr/share/subversion/hook-scripts, and in the repository at
# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/

#SVNLOOK= /usr/bin/svnlook
echo "Executing pre-commit check" >&2
/var/sourcecontrol/svn/newRepository/hooks/pre-commit-hook-reviewboard "$TXN" "$REPOS" || exit 1

Reply via email to