Ejemplo n.º 1
0
 def test_invalid_branch_name(self):
     def mock_get_current_branch_name():
         return 'invalid'
     branch_name_swap = self.swap(
         common, 'get_current_branch_name', mock_get_current_branch_name)
     with branch_name_swap, self.assertRaisesRegexp(
         Exception, (
             'This script should only be run from the latest release '
             'branch.')):
         generate_release_info.main('test-token')
Ejemplo n.º 2
0
    def test_release_summary_content(self):
        def mock_check_blocking_bug_issue_count(unused_repo):
            pass

        def mock_check_prs_for_current_release_are_released(unused_repo):
            pass

        def mock_get_current_version_tag(unused_repo):
            return github.Tag.Tag(requester='',
                                  headers='',
                                  attributes={'commit': {
                                      'sha': 'sha'
                                  }},
                                  completed='')

        def mock_get_extra_commits_in_new_release(unused_base_commit,
                                                  unused_repo):
            return [
                github.Commit.Commit(requester='',
                                     headers='',
                                     attributes={'sha': 'sha1'},
                                     completed=''),
                github.Commit.Commit(requester='',
                                     headers='',
                                     attributes={'sha': 'sha2'},
                                     completed=''),
                github.Commit.Commit(requester='',
                                     headers='',
                                     attributes={'sha': 'sha3'},
                                     completed='')
            ]

        def mock_gather_logs(unused_start, stop='HEAD'):
            new_log1 = generate_release_info.Log('sha1', 'author1', 'email1',
                                                 'message1')
            new_log2 = generate_release_info.Log('sha2', 'author2', 'email2',
                                                 'message2')
            old_log = generate_release_info.Log('sha3', 'author3', 'email3',
                                                'message3')
            cherrypick_log = generate_release_info.Log('sha4', 'author4',
                                                       'email4', 'message4')
            if stop == 'HEAD':
                return [new_log1, new_log2, old_log, cherrypick_log]
            else:
                return [old_log]

        def mock_extract_issues(unused_logs):
            return {'issues'}

        def mock_check_versions(unused_current_release):
            return ['version_change']

        def mock_check_setup_scripts(unused_base_release_tag):
            return {'setup_changes': True}

        def mock_check_storage_models(unused_current_release):
            return ['storage_changes']

        def mock_extract_pr_numbers(unused_logs):
            return []

        def mock_get_prs_from_pr_numbers(unused_pr_numbers, unused_repo):
            return []

        def mock_get_changelog_categories(unused_pulls):
            return {'category': ['pr1', 'pr2']}

        blocking_bug_swap = self.swap(common, 'check_blocking_bug_issue_count',
                                      mock_check_blocking_bug_issue_count)
        check_prs_swap = self.swap(
            common, 'check_prs_for_current_release_are_released',
            mock_check_prs_for_current_release_are_released)
        version_tag_swap = self.swap(generate_release_info,
                                     'get_current_version_tag',
                                     mock_get_current_version_tag)
        extra_commits_swap = self.swap(generate_release_info,
                                       'get_extra_commits_in_new_release',
                                       mock_get_extra_commits_in_new_release)
        gather_logs_swap = self.swap(generate_release_info, 'gather_logs',
                                     mock_gather_logs)
        extract_issues_swap = self.swap(generate_release_info,
                                        'extract_issues', mock_extract_issues)
        check_versions_swap = self.swap(generate_release_info,
                                        'check_versions', mock_check_versions)
        setup_scripts_swap = self.swap(generate_release_info,
                                       'check_setup_scripts',
                                       mock_check_setup_scripts)
        storage_models_swap = self.swap(generate_release_info,
                                        'check_storage_models',
                                        mock_check_storage_models)
        extract_prs_swap = self.swap(generate_release_info,
                                     'extract_pr_numbers',
                                     mock_extract_pr_numbers)
        get_prs_swap = self.swap(generate_release_info,
                                 'get_prs_from_pr_numbers',
                                 mock_get_prs_from_pr_numbers)
        get_changelog_swap = self.swap(generate_release_info,
                                       'get_changelog_categories',
                                       mock_get_changelog_categories)

        tmp_file = tempfile.NamedTemporaryFile()
        release_summary_swap = self.swap(release_constants,
                                         'RELEASE_SUMMARY_FILEPATH',
                                         tmp_file.name)

        with self.branch_name_swap, self.open_browser_swap:
            with self.get_organization_swap, self.get_repo_swap:
                with self.getpass_swap, blocking_bug_swap, check_prs_swap:
                    with version_tag_swap, extra_commits_swap, get_prs_swap:
                        with gather_logs_swap, extract_issues_swap:
                            with check_versions_swap, setup_scripts_swap:
                                with storage_models_swap, release_summary_swap:
                                    with get_changelog_swap, extract_prs_swap:
                                        generate_release_info.main(
                                            'test-token')
        with python_utils.open_file(GENERATED_RELEASE_SUMMARY_FILEPATH,
                                    'r') as f:
            expected_lines = f.readlines()
        with python_utils.open_file(tmp_file.name, 'r') as f:
            actual_lines = f.readlines()
        update_changelog_and_credits.check_ordering_of_sections(actual_lines)
        self.assertEqual(actual_lines, expected_lines)
def main():
    """Collects necessary info and dumps it to disk."""
    branch_name = common.get_current_branch_name()
    if not common.is_current_branch_a_release_branch():
        raise Exception(
            'This script should only be run from the latest release branch.')

    parsed_args = _PARSER.parse_args()
    if parsed_args.github_username is None:
        raise Exception(
            'No GitHub username provided. Please re-run the '
            'script specifying a username using '
            '--github_username=<Your username>')
    github_username = parsed_args.github_username

    personal_access_token = common.get_personal_access_token()

    python_utils.PRINT('Generating release summary...')
    generate_release_info.main(personal_access_token)

    if not os.path.exists(release_constants.RELEASE_SUMMARY_FILEPATH):
        raise Exception(
            'Release summary file %s is missing. Please re-run '
            'this script.' % release_constants.RELEASE_SUMMARY_FILEPATH)

    g = github.Github(personal_access_token)
    repo_fork = g.get_repo('%s/oppia' % github_username)

    current_release_version_number = common.get_current_release_version_number(
        branch_name)
    target_branch = 'update-changelog-for-releasev%s' % (
        current_release_version_number)

    remove_updates_and_delete_branch(repo_fork, target_branch)

    # Opens Credit Form.
    python_utils.PRINT(
        'Note: Make following changes directly to %s and make sure to '
        'save the file after making these changes.' % (
            release_constants.RELEASE_SUMMARY_FILEPATH))

    common.ask_user_to_confirm(
        'Check emails and names for authors and contributors in the release '
        'summary file and verify that the emails are '
        'correct through welcome emails sent from [email protected] '
        '(confirm with Sean in case of doubt).')
    common.open_new_tab_in_browser_if_possible(
        release_constants.CREDITS_FORM_URL)
    common.ask_user_to_confirm(
        'Check the credits form and add any additional contributors '
        'to the contributor list in the release summary file.')
    common.ask_user_to_confirm(
        'Categorize the PR titles in the Uncategorized section of the '
        'changelog in the release summary file, and arrange the changelog '
        'to have user-facing categories on top.')
    common.ask_user_to_confirm(
        'Verify each item is in the correct section in the release summary '
        'file and remove trivial changes like "Fix lint errors" '
        'from the changelog.')
    common.ask_user_to_confirm(
        'Ensure that all items in changelog in the release summary file '
        'start with a verb in simple present tense.')
    common.ask_user_to_confirm(
        'Please save the release summary file with all the changes that '
        'you have made.')

    release_summary_lines = []
    with python_utils.open_file(
        release_constants.RELEASE_SUMMARY_FILEPATH, 'r'
        ) as release_summary_file:
        release_summary_lines = release_summary_file.readlines()

    check_ordering_of_sections(release_summary_lines)

    update_changelog(
        branch_name, release_summary_lines, current_release_version_number)
    update_authors(release_summary_lines)
    update_contributors(release_summary_lines)
    update_developer_names(release_summary_lines)

    message = (
        'Please check the changes and make updates if required in the '
        'following files:\n1. %s\n2. %s\n3. %s\n4. %s\n' % (
            CHANGELOG_FILEPATH, AUTHORS_FILEPATH, CONTRIBUTORS_FILEPATH,
            ABOUT_PAGE_FILEPATH))
    common.ask_user_to_confirm(message)

    create_branch(
        repo_fork, target_branch, github_username,
        current_release_version_number)