Esempio n. 1
0
    def test_no_good_commits(self):
        """
        Tests that when there are no commits that passed checks, we abort
        """
        commits_mock = Mock()
        commits_mock.return_value = [{'sha': 'a'}, {'sha': 'b'}]

        commit_statuses_mock = Mock()
        commit_statuses_mock.side_effect = [
            {'state': 'failure'},
            {'state': 'pending'},
        ]

        api = Mock(GithubApi)
        api.commits = commits_mock
        api.commit_statuses = commit_statuses_mock

        with self.assertRaises(utils.NoValidCommitsError):
            utils.most_recent_good_commit(api)
Esempio n. 2
0
    def test_no_parseable_commit_data(self):
        """
        Tests that if the JSON data we get back from Github is not parseable,
        then we abort
        """
        commits_mock = Mock()
        commits_mock.return_value = [{'sha': 'a'}, {'sha': 'b'}]

        commit_statuses_mock = Mock()
        commit_statuses_mock.side_effect = [
            {},
            {'foo': 'bar'},
        ]

        api = Mock(GithubApi)
        api.commits = commits_mock
        api.commit_statuses = commit_statuses_mock

        with self.assertRaises(utils.NoValidCommitsError):
            utils.most_recent_good_commit(api)
Esempio n. 3
0
def create_candidate_main(raw_args):
    parser = _build_parser()
    args = parser.parse_args(raw_args)

    logger.info("Getting GitHub token...")
    token = get_token()
    github_api = GithubApi(args.org, args.repo, token)

    logger.info("Fetching commits...")
    try:
        commit = utils.most_recent_good_commit(github_api)
        commit_hash = commit['sha']
        commit_message = commit['commit']['message']
        message = utils.extract_message_summary(commit_message)
        if args.find_commit:
            logger.info(
                "\n\thash: {commit_hash}\n\tcommit message: {message}".format(
                    commit_hash=commit_hash,
                    message=message
                    )
                )
            return
    except utils.NoValidCommitsError:
        logger.error(
            "Couldn't find a recent commit without test failures. Aborting"
        )

    branch_name = utils.rc_branch_name_for_date(args.release_date.date())

    logger.info(
        "Branching {rc} off {sha}. ({msg})".format(
            rc=branch_name, sha=commit_hash, msg=message
        )
    )
    try:
        github_api.create_branch(branch_name, commit_hash)
    except RequestFailed:
        logger.error("Unable to create branch. Aborting")
        raise

    logger.info(
        "Creating Pull Request for {rc} into release".format(rc=branch_name)
    )
    try:
        request_title = "Release Candidate {rc}".format(rc=branch_name)
        github_api.create_pull_request(branch_name, title=request_title)
    except RequestFailed:
        logger.error("Unable to create branch. Aborting")
        raise
Esempio n. 4
0
def create_candidate_main(raw_args):
    parser = _build_parser()
    args = parser.parse_args(raw_args)

    logger.info("Getting GitHub token...")
    token = get_token()
    github_api = GithubApi(args.org, args.repo, token)

    logger.info("Fetching commits...")
    try:
        commit = utils.most_recent_good_commit(github_api)
        commit_hash = commit['sha']
        commit_message = commit['commit']['message']
        message = utils.extract_message_summary(commit_message)
        if args.find_commit:
            logger.info(
                "\n\thash: {commit_hash}\n\tcommit message: {message}".format(
                    commit_hash=commit_hash, message=message))
            return
    except utils.NoValidCommitsError:
        logger.error(
            "Couldn't find a recent commit without test failures. Aborting")

    branch_name = utils.rc_branch_name_for_date(args.release_date.date())

    logger.info("Branching {rc} off {sha}. ({msg})".format(rc=branch_name,
                                                           sha=commit_hash,
                                                           msg=message))
    try:
        github_api.create_branch(branch_name, commit_hash)
    except RequestFailed:
        logger.error("Unable to create branch. Aborting")
        raise

    logger.info(
        "Creating Pull Request for {rc} into release".format(rc=branch_name))
    try:
        request_title = "Release Candidate {rc}".format(rc=branch_name)
        github_api.create_pull_request(branch_name, title=request_title)
    except RequestFailed:
        logger.error("Unable to create branch. Aborting")
        raise
Esempio n. 5
0
    def test_good_commits(self):
        """
        Tests that we properly return the last valid commit
        """
        commits_mock = Mock()
        commits_mock.return_value = [{'sha': 'a'}, {'sha': 'b'}, {'sha': 'c'}]

        commit_statuses_mock = Mock()
        commit_statuses_mock.side_effect = [
            {'state': 'failure'},
            {},
            {'state': 'success'},
        ]

        api = Mock(GithubApi)
        api.commits = commits_mock
        api.commit_statuses = commit_statuses_mock

        commit = utils.most_recent_good_commit(api)
        self.assertEquals(commit['sha'], 'c')
Esempio n. 6
0
def create_candidate_main(raw_args):
    """
    Create a release candidate for an edx release.

    Args:
        raw_args:

    Returns:
        None

    """
    parser = _build_parser()
    args = parser.parse_args(raw_args)

    logger.info("Getting GitHub token...")
    token = get_token()
    github_api = GithubApi(args.org, args.repo, token)

    if args.force_commit:
        commit_hash = args.force_commit
        message = "User overide SHA"
    else:
        logger.info("Fetching commits...")
        try:
            commit = utils.most_recent_good_commit(github_api)
            commit_hash = commit['sha']
            commit_message = commit['commit']['message']
            message = utils.extract_message_summary(commit_message)

        except utils.NoValidCommitsError:
            logger.error(
                "Couldn't find a recent commit without test failures. Aborting"
            )

    # Return early if we are only returning the commit hash to stdout
    if args.find_commit:
        logger.info(
            "\n\thash: {commit_hash}\n\tcommit message: {message}".format(
                commit_hash=commit_hash, message=message))
        return

    branch_name = RELEASE_CANDIDATE_BRANCH

    logger.info("Branching {rc} off {sha}. ({msg})".format(rc=branch_name,
                                                           sha=commit_hash,
                                                           msg=message))
    try:
        github_api.delete_branch(branch_name)
    except RequestFailed:
        logger.error("Unable to delete branch {branch_name}. " +
                     "Will attempt to recreate".format(
                         branch_name=branch_name))
    try:
        github_api.create_branch(branch_name, commit_hash)
    except RequestFailed:
        logger.error(
            "Unable to recreate branch {branch_name}. Aborting".format(
                branch_name=branch_name))
        raise

    logger.info(
        "Creating Pull Request for {rc} into release".format(rc=branch_name))
    try:
        request_title = "Release Candidate {rc}"\
            .format(rc=utils.rc_branch_name_for_date(args.release_date.date()))
        github_api.create_pull_request(branch_name, title=request_title)
    except RequestFailed:
        logger.error("Unable to create branch. Aborting")
        raise