Ejemplo n.º 1
0
def test_list_target(pr_tool_type, cd_to_pr_tool_repo):
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things',
                                  'master')
    mock_tool.create_pull_request('Another 2', 'Stable only!', 'stable')
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)

    result = CliRunner().invoke(pr, ['list', '--target', 'master'],
                                mix_stderr=True)
    assert result.exit_code == 0
    assert result.output == '''- [#1] My test
  test/pr/1

  This tests important things

'''
    result = CliRunner().invoke(pr, ['list', '--target', 'stable'],
                                mix_stderr=True)
    assert result.exit_code == 0
    assert result.output == '''- [#2] Another 2
  test/pr/2

  Stable only!

'''
    result = CliRunner().invoke(pr, ['list', '--target', 'does-not-exist'],
                                mix_stderr=True)
    assert result.exit_code == 0
    assert result.output == ''
Ejemplo n.º 2
0
def test_cli_tool_test_jenkins_swift_plans(
        cd_to_pr_tool_repo_clone_adjust_jenkins_ci):
    write_config('jenkins-test.foo-bar',
                 '{"username": "******", "token": "123"}')
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things',
                                  'master')
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool,
                                                    PRToolType.GitHub)

    def request_callback(request, uri, response_headers):
        return [201, response_headers, '']

    url1 = f'{JENKINS_TEST_API_URL}/view/monorepo/job/pr-build-test/buildWithParameters?token=GIT_APPLE_LLVM'
    url1 += '&cause=started%20by%20user%20using%20git%20apple-llvm&pullRequestID=1'
    url1 += '&test_targets=check-llvm'
    httpretty.register_uri(httpretty.POST, url1, body=request_callback)
    result = CliRunner().invoke(pr, ['test', '#1', '--test', 'pr'],
                                mix_stderr=True)
    assert result.exit_code == 0
    assert 'Triggering pull request testing for pr #1 by <author>:' in result.output
    assert 'My test' in result.output
    assert '✅ requested pr [a-RA] ci job for PR #1' in result.output
Ejemplo n.º 3
0
def test_cli_tool_create_pr_invalid_base(cd_to_pr_tool_repo_clone,
                                         pr_tool_type):
    git('checkout', 'master')
    git('branch', '-D', 'pr_branch2', ignore_error=True)
    git('checkout', '-b', 'pr_branch2')
    git('push', 'origin', '-u', '-f', 'pr_branch2')

    mock_tool = MockPRTool()
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)
    # PR creation fails when the branch is not pushed.
    result = CliRunner().invoke(
        pr, ['create', '-m', 'test pr', '-b', 'mastar', '-h', 'pr_branch2'],
        mix_stderr=True)
    assert result.exit_code == 1
    assert 'base branch "mastar" is not a valid remote tracking branch' in result.output
Ejemplo n.º 4
0
def test_cli_tool_create_pr(cd_to_pr_tool_repo_clone, pr_tool_type):
    git('checkout', 'master')
    git('branch', '-D', 'pr_branch', ignore_error=True)
    git('checkout', '-b', 'pr_branch')
    with open('pr-file', 'w') as f:
        f.write('test pr file')
    git('add', 'pr-file')
    git('commit', '-m', 'pr file')

    mock_tool = MockPRTool()
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)

    # PR creation fails when the branch is not pushed.
    result = CliRunner().invoke(
        pr, ['create', '-m', 'test pr', '-b', 'master', '-h', 'pr_branch'])
    if result.exit_code != 1:
        raise AssertionError
    if 'head branch "pr_branch" is not a valid remote tracking branch' not in result.output:
        raise AssertionError

    # PR should be create when the branch is there.
    git('push', 'origin', '-u', '-f', 'pr_branch')
    result = CliRunner().invoke(
        pr,
        ['create', '-m', 'test pr', '--base', 'master', '--head', 'pr_branch'])
    if result.exit_code != 0:
        raise AssertionError
    if 'Creating pull request:' not in result.output:
        raise AssertionError
    if '  pr_branch -> master on' not in result.output:
        raise AssertionError
    assert 'Created a pull request #1 (test/pr/1)'

    created_pr = git_apple_llvm.pr.main.pr_tool.get_pr_from_number(1)
    if created_pr.info.author_username != 'pr_branch':
        raise AssertionError
Ejemplo n.º 5
0
 def create_pull(self, title: str, base: str, head: str):
     mock = MockPRTool()
     mock.create_pr(title=title, base_branch=base, head_repo_url=None, head_branch=head)
     self.prs.append(_GitHubPullRequest(mock.pull_requests[0]))
     return self.prs[-1]