示例#1
0
文件: flow.py 项目: rmatulat/nacl
    def test_merge_request(self, mergerequest_iid=None):
        """
        Test a mergerequest localy

        Fetch the content of a mergerequest and put it into a local
        branch so that one can test and inspect the changes before
        accepting the MR.
        """

        __ret = []

        if not git.is_git_repo():
            __ret.append(('WARNING', "Not a git repository", 1))
            return __ret

        # TODO:
        # Maybe we can create a workflow to git stash automatically.
        # But it feels bad because we just do things with code the owner
        # of this code is not expecting (like stashing)
        if not git.branch_is_clean():
            __ret.append((
                'FAIL',
                "Your current branch is not clean. "
                "Please git stash first your changes.", 1))

            return __ret

        mergerequest_id = self.api.mergerequest_iid_to_id(mergerequest_iid)

        if not self.api.is_mergerequest_open(mergerequest_id):
            __ret.append((
                'FAIL',
                "Mergerequest '{0}' already closed? "
                "Is there a mergerequest with this ID?"
                .format(mergerequest_id), 1))

            return __ret

        values = self.api.get_mergerequest_details(mergerequest_id)
        if not values:
            __ret.append(('FAIL', "Mergerequest not found", 1))
            return __ret

        mr_branch = values['changes']['source_branch']

        if git.branch_exist('test_' + mr_branch):
            __ret.append((
                'FAIL',
                "Branch test_{0} exists!".format(mr_branch), 1))

            return __ret

        __ret.append(('GREEN', "Fetch from origin"))
        git.git(['fetch'])
        __ret.append(('GREEN', "Checkout test_{0}".format(mr_branch)))
        git.git(['checkout', '-b', 'test_' + mr_branch, 'origin/' + mr_branch])
        __ret.append(('GREEN',
                      "Current branch: {0}".
                      format(git.get_current_branch())))
        return __ret
示例#2
0
 def test_branch_exists_2(self, mock):
     self.assertFalse(branch_exist("b4"))
示例#3
0
 def test_branch_exists_1(self, mock):
     self.assertTrue(branch_exist("b2"))