]> granicus.if.org Git - icu/commitdiff
ICU-7589 add traccheck script to check ticket status..
authorSteven R. Loomis <srl@icu-project.org>
Tue, 21 Jan 2014 01:11:54 +0000 (01:11 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Tue, 21 Jan 2014 01:11:54 +0000 (01:11 +0000)
X-SVN-Rev: 34940

.gitattributes
.gitignore
tools/trac/IcuCodeTools/0.12/icucodetools/traccheck.py [new file with mode: 0644]
tools/trac/IcuCodeTools/0.12/readme.txt
tools/trac/IcuCodeTools/0.12/setup.py

index d65a91be7bfaff06eae036855653dad7a2d48289..99f9104bc5c38997702c74ff23589f53b0fac595 100644 (file)
@@ -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
index 2a20a993272915d910401b7a7e59e9897c75fe91..7bc7c3ef74c8e3793a2d030e257c84e18bd9af80 100644 (file)
@@ -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 (file)
index 0000000..561100b
--- /dev/null
@@ -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())
index d549d913db28d929df6b841c9919831ced8edc7b..04cd1cd3cd7ff3cb5ea74956e33ce1804584ff09 100644 (file)
@@ -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 <environment> upgrade 
+       3. you may need to run trac-admin <environment> 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.
-
-
-
index fdbdd03591f73e7586d7119e31886fe5d0d7c45a..87ba37f4e6fd92a504d6c6a7008da409e16bc75d 100755 (executable)
@@ -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'
         ]
     }
 )