Beispiel #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)
Beispiel #2
0
def test_create_pr_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)

    issue = create_autospec(Issue.Issue, instance=True)

    # thing.run_checks = MagicMock(return_value=True)
    assert thing.create_pr("repo_name", "branch_name_origin",
                           "branch_name_destination", issue) == True
    repo.create_pull.assert_called_once_with(issue=issue,
                                             base="branch_name_destination",
                                             head="branch_name_origin")
Beispiel #3
0
def test_create_pr_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)

    issue = create_autospec(Issue.Issue, instance=True)

    repo.create_pull = MagicMock(
        side_effect=Exception("Problem creating pull request."))
    # thing.run_checks = MagicMock(return_value=True)
    with pytest.raises(Exception) as ex:
        assert thing.create_pr("repo_name", "branch_name_origin",
                               "branch_name_destination", issue) == False
        repo.create_pull.assert_called_once_with(
            issue=issue,
            base="branch_name_destination",
            head="branch_name_origin")