Example #1
0
def branches(context, request):
    plone_versions = request.registry.settings['plone_versions']
    sources = get_pickled_data(request.registry.settings['sources_file'])
    checkouts = get_pickled_data(request.registry.settings['checkouts_file'])

    def plone_versions_dict():
        """Provide a dict prefilled with all plone versions"""
        _dict = {
            v: {'branch': None, 'active': None, }
            for v in plone_versions
        }
        _dict['id'] = None
        return _dict

    data = defaultdict(plone_versions_dict)

    for dist_with_branch, target_versions in sources.items():
        dist, branch = dist_with_branch
        dist = dist.split('/')[1]
        data[dist]['id'] = dist
        for version in target_versions:
            data[dist][version]['branch'] = branch

    for target_version, dists in checkouts.items():
        for dist in dists:
            data[dist][target_version]['active'] = 'red'

    sorted_data = [data[x] for x in sorted(data.keys())]

    return {
        'versions': sorted(plone_versions),
        'data': sorted_data,
    }
Example #2
0
def branches(context, request):
    plone_versions = request.registry.settings['plone_versions']
    sources = get_pickled_data(request.registry.settings['sources_file'])
    checkouts = get_pickled_data(request.registry.settings['checkouts_file'])

    def plone_versions_dict():
        """Provide a dict prefilled with all plone versions"""
        _dict = {v: {'branch': None, 'active': None} for v in plone_versions}
        _dict['id'] = None
        return _dict

    data = defaultdict(plone_versions_dict)

    for dist_with_branch, target_versions in sources.items():
        dist, branch = dist_with_branch
        dist = dist.split('/')[1]
        data[dist]['id'] = dist
        for version in target_versions:
            data[dist][version]['branch'] = branch

    for target_version, dists in checkouts.items():
        for dist in dists:
            data[dist][target_version]['active'] = 'red'

    sorted_data = [data[x] for x in sorted(data.keys())]

    return {'versions': sorted(plone_versions), 'data': sorted_data}
Example #3
0
    def run(self):
        """Add package that got a pull request merged into checkouts.cfg

        - only for packages that are part of Plone coredev.
        - on all Plone coredev versions that track the branch that was
        targeted by the pull request
        """
        # pull requests on buildout.coredev itself do not need any extra work
        if self.repo_full_name == 'plone/buildout.coredev':
            return

        plone_versions = plone_versions_targeted(self.repo_full_name,
                                                 self.target_branch,
                                                 self.event.request)
        if not plone_versions:
            self.log(
                f'no plone coredev version tracks branch {self.target_branch} '
                f'of {self.repo_name}, checkouts.cfg not updated')
            return

        checkouts = get_pickled_data(
            self.event.request.registry.settings['checkouts_file'])
        not_in_checkouts = [
            version for version in plone_versions
            if self.repo_name not in checkouts[version]
        ]
        if not not_in_checkouts:
            self.log(f'is already on checkouts.cfg of all plone '
                     f'versions that it targets {plone_versions}')
            return

        self.add_pacakge_to_checkouts(not_in_checkouts)
Example #4
0
    def run(self):
        """Add package that got a pull request merged into checkouts.cfg

        - only for packages that are part of Plone coredev.
        - on all Plone coredev versions that track the branch that was
        targeted by the pull request
        """
        # pull requests on buildout.coredev itself do not need any extra work
        if self.repo_full_name == 'plone/buildout.coredev':
            return

        plone_versions = plone_versions_targeted(
            self.repo_full_name,
            self.target_branch,
            self.event.request,
        )
        if not plone_versions:
            msg = 'no plone coredev version tracks branch {0} ' \
                  'of {1}, checkouts.cfg not updated'
            self.log(msg.format(self.target_branch, self.repo_name))
            return

        checkouts = get_pickled_data(
            self.event.request.registry.settings['checkouts_file']
        )
        not_in_checkouts = [
            version
            for version in plone_versions
            if self.repo_name not in checkouts[version]
        ]
        if not not_in_checkouts:
            msg = 'is already on checkouts.cfg of all plone ' \
                  'versions that it targets {1}'
            self.log(msg.format(self.short_url, plone_versions))
            return

        self.add_pacakge_to_checkouts(not_in_checkouts)
Example #5
0
def run_function_core_tests(request):
    """When we are called by GH we want to run the jenkins builds

    It's called for each push on the plone repo, so we look which tests needs
    to run for the given repository and branch:
    """
    # bail out early if it's just a github check
    payload = json.loads(request.POST['payload'])
    if 'ref' not in payload:
        return json.dumps({'message': 'pong'})

    # lots of variables
    repo_name = payload['repository']['name']
    repo = payload['repository']['full_name']
    branch = payload['ref'].split('/')[-1]

    # who pushed the commits?
    who = get_user(payload['pusher'])

    data = get_info(payload, repo, branch)
    timestamp, changeset, changeset_long, fake, skip, source_or_checkout = data

    if not fake and not skip:
        request.registry.notify(NewCoreDevPush(payload, request))

    # If it is a push to buildout.coredev,
    # update sources and checkouts and quit
    if repo == 'plone/buildout.coredev':
        logger.info('Commit: on coredev - do nothing')
        if source_or_checkout:
            get_sources_and_checkouts(request)

        return json.dumps(
            {'message': 'Thanks! Commit to coredev, nothing to do'})

    ##
    # It's not a commit to coredev repo
    ##

    # if it's a skip commit, log and done
    if skip:
        logger.info(f'Commit: skip CI - {repo} - {branch} do nothing')
        return json.dumps({'message': 'Thanks! Skipping CI'})

    # if the repo+branch are not in any plone version sources.cfg,
    # log and done
    plone_versions = plone_versions_targeted(repo, branch, request)
    if not plone_versions:
        # Error repo not in sources
        logger.info(f'Commit: not in sources - {repo} - {branch} do nothing')
        return json.dumps(
            {'message': 'Thanks! Commits done on a branch, nothing to do'})

    ##
    # a commit on a branch that's part of a plone version
    ##
    checkouts = get_pickled_data(request.registry.settings['checkouts_file'])
    for plone_version in plone_versions:
        # if the repository is not on checkouts.cfg things could be broken
        # at a later point when it's added, warn about it!!
        if repo_name not in checkouts[plone_version]:
            warn_repo_not_in_checkouts(plone_version, request, who, repo,
                                       branch, payload)

        commit_on_plone_version(plone_version, request, payload, changeset,
                                changeset_long, timestamp)

    return json.dumps({'message': 'Thanks! Plone Jenkins CI will run tests'})
Example #6
0
def run_function_core_tests(request):
    """When we are called by GH we want to run the jenkins builds

    It's called for each push on the plone repo, so we look which tests needs
    to run for the given repository and branch:
    """
    # bail out early if it's just a github check
    payload = json.loads(request.POST['payload'])
    if 'ref' not in payload:
        return json.dumps({'message': 'pong'})

    # lots of variables
    repo_name = payload['repository']['name']
    repo = payload['repository']['full_name']
    branch = payload['ref'].split('/')[-1]

    # who pushed the commits?
    who = get_user(payload['pusher'])

    data = get_info(payload, repo, branch)
    timestamp, changeset, changeset_long, fake, skip, source_or_checkout = data

    if not fake and not skip:
        request.registry.notify(NewCoreDevPush(payload, request))

    # If it is a push to buildout.coredev,
    # update sources and checkouts and quit
    if repo == 'plone/buildout.coredev':
        logger.info('Commit: on coredev - do nothing')
        if source_or_checkout:
            get_sources_and_checkouts(request)

        return json.dumps({'message': 'Thanks! Commit to coredev, nothing to do'})

    ##
    # It's not a commit to coredev repo
    ##

    # if it's a skip commit, log and done
    if skip:
        logger.info(f'Commit: skip CI - {repo} - {branch} do nothing')
        return json.dumps({'message': 'Thanks! Skipping CI'})

    # if the repo+branch are not in any plone version sources.cfg,
    # log and done
    plone_versions = plone_versions_targeted(repo, branch, request)
    if not plone_versions:
        # Error repo not in sources
        logger.info(f'Commit: not in sources - {repo} - {branch} do nothing')
        return json.dumps(
            {'message': 'Thanks! Commits done on a branch, nothing to do'}
        )

    ##
    # a commit on a branch that's part of a plone version
    ##
    checkouts = get_pickled_data(request.registry.settings['checkouts_file'])
    for plone_version in plone_versions:
        # if the repository is not on checkouts.cfg things could be broken
        # at a later point when it's added, warn about it!!
        if repo_name not in checkouts[plone_version]:
            warn_repo_not_in_checkouts(
                plone_version, request, who, repo, branch, payload
            )

        commit_on_plone_version(
            plone_version, request, payload, changeset, changeset_long, timestamp
        )

    return json.dumps({'message': 'Thanks! Plone Jenkins CI will run tests'})
Example #7
0
def run_function_core_tests(request):
    """When we are called by GH we want to run the jenkins builds

    It's called for each push on the plone repo, so we look which tests needs
    to run for the given repository and branch:
    """
    # bail out early if it's just a github check
    payload = json.loads(request.POST['payload'])
    if 'ref' not in payload:
        return json.dumps({'message': 'pong'})

    # lots of variables
    repo_name = payload['repository']['name']
    repo = payload['repository']['full_name']
    branch = payload['ref'].split('/')[-1]

    # who pushed the commits?
    who = get_user(payload['pusher'])

    data = get_info(payload, repo, branch)
    timestamp = data[0]
    changeset = data[1]
    changeset_long = data[2]
    fake = data[3]
    skip = data[4]
    source_or_checkout = data[5]

    if not fake and not skip:
        request.registry.notify(NewCoreDevPush(payload, request))

    # If it is a push to buildout.coredev,
    # update sources and checkouts and quit
    if repo == 'plone/buildout.coredev':
        logger.info('Commit: on coredev - do nothing')
        if source_or_checkout:
            get_sources_and_checkouts(request)

        return json.dumps(
            {'message': 'Thanks! Commit to coredev, nothing to do'}
        )

    ##
    # It's not a commit to coredev repo
    ##

    # if it's a skip commit, log and done
    if skip:
        msg = 'Commit: skip CI - {0} - {1} do nothing'
        logger.info(msg.format(repo, branch))
        return json.dumps({'message': 'Thanks! Skipping CI'})

    # if the repo+branch are not in any plone version sources.cfg,
    # log and done
    plone_versions = plone_versions_targeted(repo, branch, request)
    if not plone_versions:
        # Error repo not in sources
        msg = 'Commit: not in sources - {0} - {1} do nothing'
        logger.info(msg.format(repo, branch))
        return json.dumps(
            {'message': 'Thanks! Commits done on a branch, nothing to do'}
        )

    ##
    # a commit on a branch that's part of a plone version
    ##
    checkouts = get_pickled_data(request.registry.settings['checkouts_file'])
    for plone_version in plone_versions:
        # if the repository is not on checkouts.cfg things could be broken
        # at a later point when it's added, warn about it!!
        if repo_name not in checkouts[plone_version]:
            request.registry.notify(
                CommitAndMissingCheckout(
                    who,
                    request,
                    repo,
                    branch,
                    plone_version,
                    payload['pusher']['email']  # duplicated, already on 'who'
                )
            )
        # commit to the plone version branch. This way jenkins will trigger a
        # build and will get the latest changes from the repository that
        # triggered this view
        commit_to_coredev(
            request,
            payload,
            plone_version,
            changeset,
            changeset_long,
            timestamp,
        )

    return json.dumps(
        {'message': 'Thanks! Plone Jenkins CI will run tests'}
    )