Ejemplo n.º 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)
Ejemplo n.º 2
0
def test_create_issue_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.create_issue = MagicMock(
        side_effect=Exception("Problem creating issue."))
    # thing.run_checks = MagicMock(return_value=True)
    with pytest.raises(Exception) as ex:
        assert thing.create_issue("repo_name", "branch_name_origin",
                                  "branch_name_destination") == False
        repo.create_issue.assert_called_once_with(
            "Pull Request from branch branch_name_origin to branch branch_name_destination"
        )
Ejemplo n.º 3
0
def test_create_issue_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)
    repo.create_issue = MagicMock(return_value=issue)

    # thing.run_checks = MagicMock(return_value=True)
    assert thing.create_issue("repo_name", "branch_name_origin",
                              "branch_name_destination") == issue
    repo.create_issue.assert_called_once_with(
        "Pull Request from branch branch_name_origin to branch branch_name_destination"
    )