示例#1
0
def evergreen_yaml(conf):
    # initialize Jira to get the jira user name for Evergreen.
    if config.EVG_CONFIG_FILE.exists():
        get_logger().info(
            'Found existing ~/.evergreen.yml, skipping adding Evergreen configuration'
        )
        get_logger().info(
            'Please ensure your ~/.evergreen.yml was generated by this tool. If not, '
            'make sure you know what\'s in there')
    else:
        settings_url = 'https://evergreen.mongodb.com/login/key'
        while True:
            res = requests.post(settings_url,
                                json={
                                    'username': conf.username,
                                    'password': conf.jira_pwd
                                })
            if res.status_code != 200:
                get_logger().error(
                    'Failed to fetch API key from evergreen. Error: %s',
                    str(res))
                req_input('Press any key to retry...')
                conf.reset_jira_credentials()
                continue
            res_json = res.json()

            evg_config = evergreen_yaml_template.format(
                res_json['user'], res_json['api_key'])

            with open(config.EVG_CONFIG_FILE, 'w') as fh:
                fh.write(evg_config)
            break

    return True
示例#2
0
def ssh_keys(ctx):
    ssh_dir = config.HOME / '.ssh'
    ssh_dir.mkdir(exist_ok=True)

    if config.SSH_KEY_FILE.is_file():
        get_logger().info(
            'Found existing key ~/.ssh/id_rsa, skipping setting up ssh keys')
        get_logger().info(
            'Please ensure your keys are added to your GitHub account')
        return
    else:
        get_logger().info('Did not find existing ssh key in ~/.ssh/id_rsa')

    with open(ssh_dir / 'config', 'w') as fh:
        get_logger().info('Disabling host key checking for github.com in %s',
                          str(ssh_dir / 'config'))
        fh.write('Host github.com\n\tStrictHostKeyChecking no\n')

    res = req_input(
        'Opening browser for instructions to setting up ssh keys in GitHub, '
        'press any key to continue, enter "skip" to skip: ')

    if res != 'skip':
        webbrowser.open(config.GITHUB_SSH_HELP_URL)
        get_logger().info(
            actionable(
                'Once you\'ve generated SSH keys and added them to GitHub, '
                'please rerun `workflow setup.macos`'))
        sys.exit(0)

    else:
        get_logger().info('Skipping adding SSH Keys to GitHub')
示例#3
0
def review(ctx):
    """
    Step 4: Open a new code review (CR) or put up a new patch to an existing code review
    """
    helpers.check_mongo_repo_root()

    ticket_conf = helpers.get_ticket_conf(ctx)

    if not ticket_conf.commits:
        get_logger().warning('Did not find any commits on this branch. Please make sure you run `commit` '
                             'before `review`')

    with ctx.prefix(helpers.virtualenv):
        def upload(existing_cr, repo_name):
            has_changes = ctx.run(f'git diff {ticket_conf.base_branch}').stdout.strip()
            if has_changes:
                get_logger().info(f'Submitting code review for the {repo_name} repo')
            else:
                get_logger().info(f'There are no changes in the {repo_name} repository, skipping code review')
                return

            cmd = f'python {str(config.UPLOAD_PY)} --rev {ticket_conf.base_branch}...'  # Yes three dots.
            cmd += ' --nojira -y --git_similarity 90 --check-clang-format --check-eslint'

            if existing_cr is not None:
                # Continue an existing CR.
                cmd += f' -i {existing_cr}'
            else:
                # Start a new CR.
                commit_msg = ctx.run('git log -1 --pretty=%B').stdout.strip()
                cr_title = input(f'Please enter the title for this code review (without the ticket number). '
                                 f'Default: {commit_msg}')
                if not cr_title:
                    cr_title = commit_msg
                else:
                    # Add the ticket number to the description.
                    cr_title = f'{git.cur_branch_name(ctx).upper()} {commit_msg}'

                cmd += f' -t "{cr_title}"'

            get_logger().info('Opening browser to authenticate with OAuth2... ')
            # Simulate some newline inputs to get the browser to open.
            sim_stdin = io.StringIO(initial_value='\n\n')
            res = ctx.run(cmd, in_stream=sim_stdin)

            if existing_cr is None:
                cr_url = re.search('Issue created. URL: (.*)', res.stdout.strip()).group(1)
                cr_issue_number = cr_url.split('/')[-1]
                get_logger().info(f'Code review created: {cr_url}')

                ticket_number = git.cur_branch_name(ctx).upper()
                jira.transition_ticket(ticket_number, 'In Progress', 'Start Code Review')

                jira.add_comment(
                    ticket_number,
                    f'Code Review: {cr_url}',
                    visibility={'type': 'role', 'value': 'Developers'}
                )

                return cr_issue_number
            else:
                get_logger().info(f'Code review updated')
                return existing_cr

        ticket_conf.cr_info.community = upload(ticket_conf.cr_info.community, 'community')
        with ctx.cd(git.ent_repo_rel_path):
            ticket_conf.cr_info.enterprise = upload(ticket_conf.cr_info.enterprise, 'enterprise')

        note = actionable('Note:')
        get_logger().info('')
        get_logger().info(f'{note} Step 3 (patch build) and Step 4 (code review) may need to be repeated to address')
        get_logger().info('      CR feedback or to validate new changes. Please consult with your mentor on the exact')
        get_logger().info('      workflow for your team.')
        get_logger().info('')
        req_input('Press any key to open the code review app...')
        webbrowser.open('https://mongodbcr.appspot.com')