From 19847a933d5930dde1ea256de30f5dddcc6e042e Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 21 Jan 2014 01:11:54 +0000 Subject: [PATCH] ICU-7589 add traccheck script to check ticket status.. X-SVN-Rev: 34940 --- .gitattributes | 1 + .gitignore | 1 + .../0.12/icucodetools/traccheck.py | 75 +++++++++++++++++++ tools/trac/IcuCodeTools/0.12/readme.txt | 30 ++++---- tools/trac/IcuCodeTools/0.12/setup.py | 5 +- 5 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 tools/trac/IcuCodeTools/0.12/icucodetools/traccheck.py diff --git a/.gitattributes b/.gitattributes index d65a91be7bf..99f9104bc5c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -692,6 +692,7 @@ tools/trac/IcuCodeTools/0.12/icucodetools/templates/nothing.html -text tools/trac/IcuCodeTools/0.12/icucodetools/templates/review.html -text tools/trac/IcuCodeTools/0.12/icucodetools/ticketmgr.py -text tools/trac/IcuCodeTools/0.12/icucodetools/tktlist.py -text +tools/trac/IcuCodeTools/0.12/icucodetools/traccheck.py -text tools/trac/IcuCodeTools/0.12/license.html -text tools/trac/IcuCodeTools/0.12/readme.txt -text tools/trac/IcuCodeTools/0.12/setup.cfg -text diff --git a/.gitignore b/.gitignore index 2a20a993272..7bc7c3ef74c 100644 --- a/.gitignore +++ b/.gitignore @@ -950,6 +950,7 @@ tools/trac/IcuCodeTools/0.11/build tools/trac/IcuCodeTools/0.11/icucodetools/*.pyc tools/trac/IcuCodeTools/0.12/*.egg-info tools/trac/IcuCodeTools/0.12/build +tools/trac/IcuCodeTools/0.12/dist tools/trac/IcuCodeTools/0.12/icucodetools/*.pyc tools/unicode/c/genprops/*.d tools/unicode/c/genprops/*.ncb diff --git a/tools/trac/IcuCodeTools/0.12/icucodetools/traccheck.py b/tools/trac/IcuCodeTools/0.12/icucodetools/traccheck.py new file mode 100644 index 00000000000..561100bd460 --- /dev/null +++ b/tools/trac/IcuCodeTools/0.12/icucodetools/traccheck.py @@ -0,0 +1,75 @@ +#!/usr/bin/python + +# Copyright (C) 2014 IBM Corporation and Others. All Rights Reserved. +# + +# This script should be invoked from the subversion pre-commit hook just like the trac plugin +# +# REPOS="$1" +# TXN="$2" +# TRAC_ENV="/somewhere/trac/project/" +# LOG=`/usr/bin/svnlook log -t "$TXN" "$REPOS"` +# /path/to/traccheck "$TRAC_ENV" "$LOG" >&2 || exit 1 + +import sys, re +from trac.core import TracError +from trac.env import open_environment +from trac.resource import ResourceNotFound +from trac.ticket.model import Ticket +from trac.util.text import exception_to_unicode + +okstatus = ['new','accepted','reviewing'] + +def run(args=None): + """trac check script""" + if args is None: + args = sys.argv[1:] + env = open_environment(args[0]) + + ticket_pattern = env.config.get('icucodetools', 'ticket_pattern', 'NoneFound') + ticket_match = None + + def lusage(): + print "Please make your message match /%s/\n and use an open ticket (One of these: %s)" % (ticket_pattern, str(okstatus)) + print "See %s/wiki/TracCheck for more details." % env.project_url + + try: + ticket_match = re.compile(ticket_pattern) + except Exception, e: + # not sorry? + raise TracError('*** INTERNAL ERROR: Could not compile icucodetools.ticket_pattern=/%s/: %s' % (ticket_pattern, exception_to_unicode(e, traceback=True))) + res = ticket_match.match(args[1].strip()) + if res: + tickname = res.group(1) + try: + int(res.group(1)) # should be int + except Exception, e: + print('*** Sorry, "%s" is not a valid number when parsing "%s": %s.' % + (tickname, args[1], e)) + lusage() + sys.exit(1) + else: + print('*** Sorry, could not parse a ticket number from your commit message "%s".' % + (args[1])) + lusage() + sys.exit(1) + id = int(res.group(1)) + try: + ticket = Ticket(env, id) + status = ticket.values['status'] + if status in okstatus: + print "Okay! You are committing against ticket #%d which is in state '%s': %s" % (id,status,ticket.values['summary']) + sys.exit(0) + else: + print "*** Sorry, ticket #%d is '%s' and is not open for commits: %s" % (id,status,ticket.values['summary']) + lusage() + sys.exit(1) + except (ResourceNotFound): + print "*** Sorry, ticket #%d does not exist." % (id) + lusage() + sys.exit(1) + sys.exit(0) + +# make this file runnable +if __name__ == '__main__': + sys.exit(run()) diff --git a/tools/trac/IcuCodeTools/0.12/readme.txt b/tools/trac/IcuCodeTools/0.12/readme.txt index d549d913db2..04cd1cd3cd7 100644 --- a/tools/trac/IcuCodeTools/0.12/readme.txt +++ b/tools/trac/IcuCodeTools/0.12/readme.txt @@ -1,6 +1,6 @@ ICU Code Tools plugin -Copyright (C) 2010 IBM Corporation and Others. All Rights Reserved. +Copyright (C) 2010-2014 IBM Corporation and Others. All Rights Reserved. See license.html for the license file. This file is part of the ICU project and is under the same license. @@ -13,27 +13,27 @@ Installing: a. There is no source release at this time: I recommend that you check out this code with svn - and in this directory, run: + and in this directory, run: "python setup.py develop" - + b. In trac.ini under '[components]' add: icucodetools.review.reviewmodule = enabled icucodetools.ticketmgr.ticketmanager = enabled - - NOTE: DCUT and TKTLIST parts are not working yet. + + NOTE: DCUT and TKTLIST parts are not working yet. Don't bother to enable them. - 2. in your trac.ini describe how your changesets describe a ticket. + 2. in your trac.ini describe how your changesets describe a ticket. Our changesets look like this: "ticket:1234: fixed the broken code" We use this regex: [icucodetools] ticket_pattern = ^ticket:(\d+) - 3. you may need to run trac-admin upgrade + 3. you may need to run trac-admin upgrade - 4. Grant permission of ICUREVIEW_VIEW to whomever you want to - be able to review tickets. + 4. Grant permission of ICUREVIEW_VIEW to whomever you want to + be able to review tickets. 5. Now, any ticket will have something in the top right corner which says: "No commits" - no commits against this ticket @@ -44,7 +44,7 @@ Installing: "Review n commits" - there are more than one commits against this ticket. - + Troubleshooting: Q: My commits aren't being found! @@ -56,7 +56,7 @@ A: Until we implement trac 0.12 changeset listeners, you can do this: 0. back up your path/to/env/db/trac.db 1. $ sqlite3 path/to/env/db/trac.db - + 2. sqlite> delete from rev2ticket; 3. sqlite> update system set value='-1' where name='icu_tktmgr_youngest'; @@ -65,10 +65,12 @@ A: Until we implement trac 0.12 changeset listeners, you can do this: Now the ticket manager will re-sync the first time you hit a ticket. +RESTRICT CHECKINS + See the comments at the top of icucodetools/traccheck.py. + note that /path/to/traccheck is the path to the installed "traccheck" script, + not the 'traccheck.py' source file. + FILING BUGS/FEATURE REQUESTS: - Use ICU's trac repository at http://bugs.icu-project.org/trac - Use the 'infrastructure' component and clearly identify the 'ICU Code Tools for Trac' when you file the bug. - - - diff --git a/tools/trac/IcuCodeTools/0.12/setup.py b/tools/trac/IcuCodeTools/0.12/setup.py index fdbdd03591f..87ba37f4e6f 100755 --- a/tools/trac/IcuCodeTools/0.12/setup.py +++ b/tools/trac/IcuCodeTools/0.12/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# Copyright (C) 2007-2012 IBM and Others. All Rights Reserved. +# Copyright (C) 2007-2014 IBM and Others. All Rights Reserved. # All rights reserved. # @@ -30,6 +30,9 @@ setup( 'icucodetools.review = icucodetools.review', 'icucodetools.tktlist = icucodetools.tktlist', 'icucodetools.dcut = icucodetools.dcut' + ], + 'console_scripts': [ + 'traccheck = icucodetools.traccheck:run' ] } ) -- 2.40.0