Exemplo n.º 1
0
# Getting issue number
if M and not branch:
    branch = M.currentBranch()

# Parsing the branch
parsedbranch = tools.parseBranch(branch, C.get('wording.branchRegex'))
if not parsedbranch:
    debug('Could not extract issue number from %s' % branch)
    sys.exit(1)
issue = parsedbranch['issue']
suffix = parsedbranch['suffix']
version = parsedbranch['version']

# Original track
originaltrack = tools.stableBranch(version)

# Pushes the branch to the remote first
if M and not args.dontpush:
    debug('Pushing %s to %s' % (branch, remote))
    if not M.git().push(remote, branch):
        debug('Could not push %s to %s' % (branch, remote))
        sys.exit(1)

# Integration?
if M:
    integration = M.isIntegration()

# Begin backport
for v in versions:
Exemplo n.º 2
0
    def run(self, args):
        M = None
        branch = args.branch
        versions = args.versions
        integration = args.integration

        # If we don't have a branch, we need an instance
        M = self.Wp.resolve(args.name)
        if not M and not branch:
            raise Exception("This is not a Moodle instance")

        # Getting issue number
        if M and not branch:
            branch = M.currentBranch()

        # Parsing the branch
        parsedbranch = tools.parseBranch(branch, self.C.get("wording.branchRegex"))
        if not parsedbranch:
            raise Exception("Could not extract issue number from %s" % branch)
        issue = parsedbranch["issue"]
        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)

        # Integration?
        if M:
            integration = M.isIntegration()

        def stashPop(stash):
            """Small helper to pop the stash has we have to do it in some different places"""
            if not stash[1].startswith("No local changes"):
                pop = M2.git().stash(command="pop")
                if pop[0] != 0:
                    logging.error("An error ocured while unstashing your changes")
                else:
                    logging.info("Popped the stash")

        # Begin backport
        for v in versions:

            # Gets the instance to cherry-pick to
            name = self.Wp.generateInstanceName(v, integration=integration)
            if not self.Wp.isMoodle(name):
                logging.warning("Could not find instance %s for version %s" % (name, v))
                continue
            M2 = self.Wp.get(name)

            logging.info("Preparing cherry-pick of %s/%s in %s" % (M.get("identifier"), branch, name))

            # Get hash list
            cherry = "%s/%s..%s" % (self.C.get("upstreamRemote"), originaltrack, branch)
            hashes = M.git().hashes(cherry)
            hashes.reverse()

            # Stash
            stash = M2.git().stash(untracked=False)
            if stash[0] != 0:
                logging.error("Error while trying to stash your changes. Skipping %s." % M2.get("identifier"))
                logging.debug(stash[2])
                continue
            elif not stash[1].startswith("No local changes"):
                logging.info("Stashed your local changes")

            # Fetch the remote to get reference to the branch to backport
            logging.info("Fetching remote %s..." % (M.get("path")))
            M2.git().fetch(M.get("path"), branch)

            # Creates a new branch if necessary
            newbranch = M2.generateBranchName(issue, suffix=suffix)
            track = "%s/%s" % (self.C.get("upstreamRemote"), M2.get("stablebranch"))
            if not M2.git().hasBranch(newbranch):
                logging.info("Creating branch %s" % newbranch)
                if not M2.git().createBranch(newbranch, track=track):
                    logging.error("Could not create branch %s tracking %s in %s" % (newbranch, track, name))
                    stashPop(stash)
                    continue
                M2.git().checkout(newbranch)
            else:
                M2.git().checkout(newbranch)
                logging.info("Hard reset %s to %s" % (newbranch, track))
                M2.git().reset(to=track, hard=True)

            # Picking the diff upstream/MOODLE_23_STABLE..github/MDL-12345-master
            logging.info("Cherry-picking %s" % (cherry))
            result = M2.git().pick(hashes)
            if result[0] != 0:

                # Try to resolve the conflicts if any.
                resolveConflicts = True
                conflictsResolved = False
                while resolveConflicts:

                    # Check the list of possible conflicting files.
                    conflictingFiles = M2.git().conflictingFiles()
                    if (
                        conflictingFiles
                        and len(conflictingFiles) == 1
                        and "theme/bootstrapbase/style/moodle.css" in conflictingFiles
                    ):
                        logging.info("Conflicts found in bootstrapbase moodle CSS, trying to auto resolve...")
                        cssCompiler = css.Css(M2)
                        if cssCompiler.compile(theme="bootstrapbase", sheets=["moodle"]):
                            M2.git().add("theme/bootstrapbase/style/moodle.css")
                            # We need to commit manually to prevent the editor to open.
                            M2.git().commit(filepath=".git/MERGE_MSG")
                            result = M2.git().pick(continu=True)
                            if result[0] == 0:
                                resolveConflicts = False
                                conflictsResolved = True
                    else:
                        resolveConflicts = False

                # We still have a dirty repository.
                if not conflictsResolved:
                    logging.error("Error while cherry-picking %s in %s." % (cherry, name))
                    logging.debug(result[2])
                    if yesOrNo("The cherry-pick might still be in progress, would you like to abort it?"):
                        result = M2.git().pick(abort=True)
                        if result[0] > 0 and result[0] != 128:
                            logging.error("Could not abort the cherry-pick!")
                        else:
                            stashPop(stash)
                    logging.info("")
                    continue

            # Pushing branch
            if args.push:
                pushremote = args.pushremote
                if pushremote == None:
                    pushremote = self.C.get("myRemote")
                logging.info("Pushing %s to %s" % (newbranch, pushremote))
                result = M2.git().push(remote=pushremote, branch=newbranch, force=args.forcepush)
                if result[0] != 0:
                    logging.warning("Error while pushing to remote %s" % (pushremote))
                    logging.debug(result[2])
                    stashPop(stash)
                    continue

                # Update the tracker
                if args.updatetracker != None:
                    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)
            logging.info("")

        logging.info("Done.")
Exemplo n.º 3
0
    def run(self, args):
        M = None
        branch = args.branch
        versions = args.versions
        integration = args.integration

        # If we don't have a branch, we need an instance
        M = self.Wp.resolve(args.name)
        if not M and not branch:
            raise Exception('This is not a Moodle instance')

        # Getting issue number
        if M and not branch:
            branch = M.currentBranch()

        # Parsing the branch
        parsedbranch = tools.parseBranch(branch, self.C.get('wording.branchRegex'))
        if not parsedbranch:
            raise Exception('Could not extract issue number from %s' % branch)
        issue = parsedbranch['issue']
        suffix = parsedbranch['suffix']
        version = parsedbranch['version']

        # Original track
        originaltrack = tools.stableBranch(version)

        # Integration?
        if M:
            integration = M.isIntegration()

        def stashPop(stash):
            """Small helper to pop the stash has we have to do it in some different places"""
            if not stash[1].startswith('No local changes'):
                pop = M2.git().stash(command='pop')
                if pop[0] != 0:
                    logging.error('An error ocured while unstashing your changes')
                else:
                    logging.info('Popped the stash')

        # Begin backport
        for v in versions:

            # Gets the instance to cherry-pick to
            name = self.Wp.generateInstanceName(v, integration=integration)
            if not self.Wp.isMoodle(name):
                logging.warning('Could not find instance %s for version %s' % (name, v))
                continue
            M2 = self.Wp.get(name)

            logging.info("Preparing cherry-pick of %s/%s in %s" % (M.get('identifier'), branch, name))

            # Get hash list
            cherry = '%s/%s..%s' % (self.C.get('upstreamRemote'), originaltrack, branch)
            hashes = M.git().hashes(cherry)
            hashes.reverse()

            # Stash
            stash = M2.git().stash(untracked=False)
            if stash[0] != 0:
                logging.error('Error while trying to stash your changes. Skipping %s.' % M2.get('identifier'))
                logging.debug(stash[2])
                continue
            elif not stash[1].startswith('No local changes'):
                logging.info('Stashed your local changes')

            # Fetch the remote to get reference to the branch to backport
            logging.info("Fetching remote %s..." % (M.get('path')))
            M2.git().fetch(M.get('path'), branch)

            # Creates a new branch if necessary
            newbranch = M2.generateBranchName(issue, suffix=suffix)
            track = '%s/%s' % (self.C.get('upstreamRemote'), M2.get('stablebranch'))
            if not M2.git().hasBranch(newbranch):
                logging.info('Creating branch %s' % newbranch)
                if not M2.git().createBranch(newbranch, track=track):
                    logging.error('Could not create branch %s tracking %s in %s' % (newbranch, track, name))
                    stashPop(stash)
                    continue
                M2.git().checkout(newbranch)
            else:
                M2.git().checkout(newbranch)
                logging.info('Hard reset %s to %s' % (newbranch, track))
                M2.git().reset(to=track, hard=True)

            # Picking the diff upstream/MOODLE_23_STABLE..github/MDL-12345-master
            logging.info('Cherry-picking %s' % (cherry))
            result = M2.git().pick(hashes)
            if result[0] != 0:
                logging.error('Error while cherry-picking %s in %s.' % (cherry, name))
                logging.debug(result[2])
                if yesOrNo('The cherry-pick might still be in progress, would you like to abort it?'):
                    result = M2.git().pick(abort=True)
                    if result[0] > 0 and result[0] != 128:
                        logging.error('Could not abort the cherry-pick!')
                    else:
                        stashPop(stash)
                logging.info('')
                continue

            # Pushing branch
            if args.push:
                pushremote = args.pushremote
                if pushremote == None:
                    pushremote = self.C.get('myRemote')
                logging.info('Pushing %s to %s' % (newbranch, pushremote))
                result = M2.git().push(remote=pushremote, branch=newbranch, force=args.forcepush)
                if result[0] != 0:
                    logging.warning('Error while pushing to remote %s' % (pushremote))
                    logging.debug(result[2])
                    stashPop(stash)
                    continue

                # Update the tracker
                if args.updatetracker:
                    M2.updateTrackerGitInfo(branch=newbranch)

            stashPop(stash)

            logging.info('Instance %s successfully patched!' % name)
            logging.info('')

        logging.info('Done.')
Exemplo n.º 4
0
# Getting issue number
if M and not branch:
    branch = M.currentBranch()

# Parsing the branch
parsedbranch = tools.parseBranch(branch, C.get('wording.branchRegex'))
if not parsedbranch:
    debug('Could not extract issue number from %s' % branch)
    sys.exit(1)
issue = parsedbranch['issue']
suffix = parsedbranch['suffix']
version = parsedbranch['version']

# Original track
originaltrack = tools.stableBranch(version)

# Pushes the branch to the remote first
if M and not args.dontpush:
    debug('Pushing %s to %s' % (branch, remote))
    if not M.git().push(remote, branch):
        debug('Could not push %s to %s' % (branch, remote))
        sys.exit(1)

# Integration?
if M:
    integration = M.isIntegration()

# Begin backport
for v in versions: