コード例 #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
ファイル: flow.py プロジェクト: rmatulat/nacl
    def write_patch_for_issue(self, issue_id=None):
        """
        Start a patch

        This is intended to be the first step in a process of providing
        a patch.
        Every patch should be written in its own branch. Therefore we
        provide a simple cmd to create a meaningfull named branch related to
        its issue. Thats why the issue id must be provided.
        There some consistency checks around starting a new branch.
        """

        __ret = []

        # first we have to do a few consistency checks
        if not check_string_to_int(issue_id):
            __ret.append(('WARNING', "ID must be an integer", 1))
            return __ret

        issue_id = int(issue_id)

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

        if not git.branch_is_clean():
            __ret.append((
                'WARNING',
                "Your branch is not clean. Please commit your changes first."))
            return __ret

        # Transform iid to id
        try:
            issue_uid = self.api.issue_iid_to_uid(issue_id)

            issue = self.api.getprojectissue(self.p_id, issue_uid)
            if not issue:
                __ret.append(('WARNING', "Issue ID not found", 1))
                return __ret

            if issue['project_id'] != self.p_id:
                __ret.append((
                    'WARNING',
                    "The issue ID does not correspond to the current " +
                    "git repository/project", 1))
                return __ret
        except TypeError as e:
            __ret.append(('FAIL', 'Something went wrong: {0}'. format(e.message)))
            return __ret

        # the workflow itself:
        # 1. create a branch
        # 2. switch to that branch.
        git.change_or_create_branch("issue_" + str(issue_id))
        return __ret
コード例 #3
0
ファイル: test_nacl_git.py プロジェクト: rmatulat/nacl
 def test_is_git_repo_raises(self, os_mock, mock_git):
     self.assertFalse(is_git_repo())
コード例 #4
0
ファイル: test_nacl_git.py プロジェクト: rmatulat/nacl
 def test_is_git_repo_with_dir_name(self, os_mock, mock_git):
     self.assertTrue(is_git_repo('foo'))
コード例 #5
0
ファイル: test_nacl_git.py プロジェクト: rmatulat/nacl
 def test_is_git_repo(self, os_mock, mock_git):
     self.assertTrue(is_git_repo())
コード例 #6
0
ファイル: test_nacl_git.py プロジェクト: rmatulat/nacl
 def test_is_git_repo_with_dir_name_raises(self, os_mock, mock_git):
     self.assertFalse(is_git_repo('foo'))