Example #1
0
    def request_pull(self, github_token, repo_name, branch_name):
        print("Entering method requestpull(**********, " + repo_name + "," +
              branch_name + ")")
        gitator = Gitator()
        gitator.create_github_connection(github_token)

        gitator.check_repo_existence(repo_name)

        if branch_name == 'merge_back':
            branch_list = gitator.list_branches(repo_name)
            gitator.delete_prs(repo_name)

            branch_name_origin = 'master'
            for branch in branch_list:
                branch_name_destination = branch.name
                i = gitator.create_issue(repo_name, branch_name_origin,
                                         branch_name_destination)
                gitator.create_pr(repo_name, branch_name_origin,
                                  branch_name_destination, i)
        else:
            branch_name_origin = branch_name
            branch_name_destination = 'master'
            if not gitator.check_branch_existence(repo_name,
                                                  branch_name_origin):
                raise Exception('Branch not found.')
            i = gitator.create_issue(repo_name, branch_name_origin,
                                     branch_name_destination)
            gitator.create_pr(repo_name, branch_name_origin,
                              branch_name_destination, i)
Example #2
0
def test_delete_prs_good():
    thing = Gitator()
    thing.create_github_connection = MagicMock()

    github_connection = create_autospec(Github)
    thing.g = github_connection

    repo = create_autospec(Repository.Repository, instance=True)
    github_connection.get_repo = MagicMock(return_value=repo)

    assert thing.delete_prs("repo_name") == True
    repo.get_pulls.assert_called_once_with(state='open')
Example #3
0
def test_delete_prs_bad():
    thing = Gitator()
    thing.create_github_connection = MagicMock()

    github_connection = create_autospec(Github)
    thing.g = github_connection

    repo = create_autospec(Repository.Repository, instance=True)
    github_connection.get_repo = MagicMock(return_value=repo)

    repo.get_pulls = MagicMock(side_effect=Exception("Can't get pulls"))
    # thing.run_checks = MagicMock(return_value=True)
    with pytest.raises(Exception) as ex:
        assert thing.delete_prs("repo_name") == False
        repo.get_pulls.assert_called_once_with(state='open')
        assert ex.value.__str__() == "Can't get pulls"