Backport command can upload patches to tracker
authorFrederic Massart <fred@moodle.com>
Mon, 10 Mar 2014 12:38:08 +0000 (20:38 +0800)
committerFrederic Massart <fred@moodle.com>
Mon, 10 Mar 2014 12:38:08 +0000 (20:38 +0800)
lib/commands/backport.py
lib/commands/push.py
lib/moodle.py

index 648a0c7..136ee95 100644 (file)
@@ -23,7 +23,7 @@ http://github.com/FMCorz/mdk
 """
 
 import logging
-from lib import tools, css
+from lib import tools, css, jira
 from lib.command import Command
 from lib.tools import yesOrNo
 
@@ -73,6 +73,14 @@ class BackportCommand(Command):
                 }
             ),
             (
+                ['--patch'],
+                {
+                    'action': 'store_true',
+                    'dest': 'patch',
+                    'help': 'instead of pushing to a remote, this will upload a patch file to the tracker. Security issues use this by default if --push is set. This option discards most other flags.',
+                }
+            ),
+            (
                 ['-t', '--update-tracker'],
                 {
                     'const': True,
@@ -126,6 +134,14 @@ class BackportCommand(Command):
         suffix = parsedbranch['suffix']
         version = parsedbranch['version']
 
+        if args.push and not args.patch:
+            mdlIssue = 'MDL-%s' % (issue)
+            J = jira.Jira()
+            args.patch = J.isSecurityIssue(mdlIssue)
+            args.push = False
+            if args.patch:
+                logging.info('%s appears to be a security issue, switching to patch mode...' % (mdlIssue))
+
         # Original track
         originaltrack = tools.stableBranch(version)
 
@@ -244,6 +260,10 @@ class BackportCommand(Command):
                     ref = None if args.updatetracker == True else args.updatetracker
                     M2.updateTrackerGitInfo(branch=newbranch, ref=ref)
 
+            elif args.patch:
+                if not M2.pushPatch(newbranch):
+                    continue
+
             stashPop(stash)
 
             logging.info('Instance %s successfully patched!' % name)
index d114456..6728ab7 100644 (file)
@@ -152,7 +152,7 @@ class PushCommand(Command):
             mdlIssue = 'MDL-%s' % (parsedbranch['issue'])
             args.patch = J.isSecurityIssue(mdlIssue)
             if args.patch:
-                logging.info('%s appears to be a security issue, attempting to upload a patch...' % (mdlIssue))
+                logging.info('%s appears to be a security issue, switching to patch mode...' % (mdlIssue))
 
         if args.patch:
             if not M.pushPatch(branch):
index 6cf7fe3..4ba9948 100644 (file)
@@ -596,7 +596,7 @@ class Moodle(object):
         headcommit = self.headcommit(branch)
 
         # Creating a patch file.
-        fileName = branch + '-mdk' + '.patch'
+        fileName = branch + '.mdk.patch'
         tmpPatchFile = os.path.join(gettempdir(), fileName)
         if self.git().createPatch('%s...%s' % (headcommit, branch), saveTo=tmpPatchFile):