Пример #1
0
 def test_get_origin_non_pr(self):
     mock = MagicMock()
     mock_repo = MagicMock()
     mock_org = MagicMock()
     mock_commit = MagicMock()
     mock_commit.commit.message = 'I am not pull request!'
     mock_org.get_repo.return_value = mock_repo
     mock.get_organization.return_value = mock_org
     client = SourceControlClient(mock, mock, mock)
     origin_pr = client.get_origin_pr('blah', 'bleh', 'shashasha')
     self.assertEqual(origin_pr, False)
Пример #2
0
 def test_get_origin_pr_fail(self):
     mock = MagicMock()
     mock_repo = MagicMock()
     mock_org = MagicMock()
     mock_commit = MagicMock()
     mock_commit.commit.message = 'I am not pull request!'
     mock_repo.get_pull.side_effect = GithubException(404, "Not Found")
     mock_org.get_repo.return_value = mock_repo
     mock.get_organization.return_value = mock_org
     client = SourceControlClient(mock, mock, mock)
     origin_pr = client.get_origin_pr('blah', 'bleh', 'shashasha')
     self.assertEqual(origin_pr, False)
Пример #3
0
 def test_get_origin_pr_old_format(self):
     mock = MagicMock()
     mock_repo = MagicMock()
     mock_org = MagicMock()
     mock_commit = MagicMock()
     mock_commit.commit.message = 'Merge pull request #197 from test/master'
     mock_repo.get_pull.return_value = 'a pr object'
     mock_repo.get_commit.return_value = mock_commit
     mock_org.get_repo.return_value = mock_repo
     mock.get_organization.return_value = mock_org
     client = SourceControlClient(mock, mock, mock)
     origin_pr = client.get_origin_pr('blah', 'bleh', 'shashasha')
     self.assertEqual(origin_pr, 'a pr object')
Пример #4
0
 def test_get_origin_pr_new_format(self):
     mock = MagicMock()
     mock_repo = MagicMock()
     mock_org = MagicMock()
     mock_commit = MagicMock()
     mock_commit.commit.message = 'New PR format on github very cool (#198)'
     mock_repo.get_pull.return_value = 'a pr object'
     mock_repo.get_commit.return_value = mock_commit
     mock_org.get_repo.return_value = mock_repo
     mock.get_organization.return_value = mock_org
     client = SourceControlClient(mock, mock, mock)
     origin_pr = client.get_origin_pr('blah', 'bleh', 'shashasha')
     self.assertEqual(origin_pr, 'a pr object')
Пример #5
0
def populate_pull_info(_):
    """ Add pull request details to environment """
    org = Constants.GITHUB_ORG
    repo = Constants.GITHUB_REPO
    branch = os.environ.get('BRANCH_NAME', None)
    commit = os.environ.get('GIT_COMMIT', None)
    source_control_token = os.environ.get('SOURCE_CLIENT_TOKEN', None)
    if branch is not None and branch == Constants.PROD_BRANCH_NAME and source_control_token is not None:
        source_client = SourceControlClient(source_control_token)
        pull = source_client.get_origin_pr(org, repo, commit)
        if not pull:
            return
        title = str(pull.title).replace(' ', '\\ ')
        name = str(pull.user.name).replace(' ', '\\ ')
        url = str(pull.html_url)
        email = str(pull.user.email)
        merged_name = str(pull.merged_by.name).replace(' ', '\\ ')
        merged_email = str(pull.merged_by.email).replace(' ', '\\ ')
        export = 'export CHANGE_TITLE="{0}" CHANGE_AUTHOR_DISPLAY_NAME="{1}" CHANGE_URL="{2}" ' \
                 'CHANGE_AUTHOR_EMAIL="{3}" CHANGE_MERGED_BY="{4}" CHANGE_MERGED_BY_EMAIL="{5}"'.format(
                     title, name, url, email, merged_name, merged_email)
        print(export)
        return