Example #1
0
    def _which_plone_versions(self):
        response = requests.get(self.event.pull_request['url'])
        if response.status_code != 200:
            self.log('Could not get information regarding pull request', level='warn')
            return []

        data = response.json()
        target_branch = data['base']['ref']
        repo_full_name = data['base']['repo']['full_name']

        plone_versions = plone_versions_targeted(
            repo_full_name, target_branch, self.event.request
        )

        tracked_versions = self.event.request.registry.settings['plone_versions']
        if (
            repo_full_name == 'plone/buildout.coredev'
            and target_branch in tracked_versions
        ):
            plone_versions = (target_branch,)

        elif not plone_versions:
            self.log('Does not target any Plone version')

        return plone_versions
Example #2
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 #3
0
    def run(self):
        plone_versions = plone_versions_targeted(self.repo_full_name,
                                                 self.target_branch,
                                                 self.event.request)
        if not plone_versions:
            return

        user = self.pull_request['user']['login']
        msg = (
            f'@{user} thanks for creating this Pull Request and help improve Plone!\n\n'
            'To ensure that these changes do not break other parts of Plone, '
            'the Plone test suite matrix needs to pass.\n\n'
            'Whenever you feel that the pull request is ready to be tested, '
            'either start all jenkins jobs pull requests by yourself, '
            'or simply add a comment in this pull request stating:\n\n'
            '```\n'
            '@jenkins-plone-org please run jobs\n'
            '```\n\n'
            'With this simple comment all the jobs will be started automatically.\n\n'
            'Happy hacking!')
        self.g_issue.create_comment(body=msg)
Example #4
0
    def _plone_versions_targeted(self):
        if self.repo_name in IGNORE_NO_TEST_NEEDED:
            self.log('skip adding test warnings, repo whitelisted')
            return []

        target_branch = self.pull_request['base']['ref']

        plone_versions = plone_versions_targeted(self.repo_full_name,
                                                 target_branch,
                                                 self.event.request)

        tracked_versions = self.event.request.registry.settings[
            'plone_versions']
        if (self.repo_full_name == 'plone/buildout.coredev'
                and target_branch in tracked_versions):
            plone_versions = (target_branch, )

        elif not plone_versions:
            self.log('does not target any Plone version')
            return []

        return plone_versions
Example #5
0
    def run(self):
        plone_versions = plone_versions_targeted(
            self.repo_full_name, self.target_branch, self.event.request
        )
        if not plone_versions:
            return

        user = self.pull_request['user']['login']
        msg = (
            f'@{user} thanks for creating this Pull Request and help improve Plone!\n\n'
            'To ensure that these changes do not break other parts of Plone, '
            'the Plone test suite matrix needs to pass.\n\n'
            'Whenever you feel that the pull request is ready to be tested, '
            'either start all jenkins jobs pull requests by yourself, '
            'or simply add a comment in this pull request stating:\n\n'
            '```\n'
            '@jenkins-plone-org please run jobs\n'
            '```\n\n'
            'With this simple comment all the jobs will be started automatically.\n\n'
            'Happy hacking!'
        )
        self.g_issue.create_comment(body=msg)
Example #6
0
    def run(self):
        """Create waiting status for all pull request jobs that should be run
        before a pull request can be safely merged
        """
        if self.repo_name in IGNORE_NO_TEST_NEEDED:
            self.log('skip adding test warnings, repo whitelisted')
            return

        target_branch = self.pull_request['base']['ref']

        plone_versions = plone_versions_targeted(
            self.repo_full_name,
            target_branch,
            self.event.request
        )

        tracked_versions = \
            self.event.request.registry.settings['plone_versions']
        if self.repo_full_name == 'plone/buildout.coredev' and \
                target_branch in tracked_versions:
            plone_versions = (target_branch, )

        elif not plone_versions:
            self.log('does not target any Plone version')
            return

        # get the pull request and last commit
        last_commit = self.get_pull_request_last_commit()

        for version in plone_versions:

            last_commit.create_status(
                u'pending',
                target_url=self.jenkins_pr_job_url.format(version),
                description='Please run the job, click here ----------->',
                context=self.status_context.format(version),
            )
            self.log('created pending status for plone {0}'.format(version))
Example #7
0
    def _plone_versions_targeted(self):
        if self.repo_name in IGNORE_NO_TEST_NEEDED:
            self.log('skip adding test warnings, repo whitelisted')
            return []

        target_branch = self.pull_request['base']['ref']

        plone_versions = plone_versions_targeted(
            self.repo_full_name, target_branch, self.event.request
        )

        tracked_versions = self.event.request.registry.settings['plone_versions']
        if (
            self.repo_full_name == 'plone/buildout.coredev'
            and target_branch in tracked_versions
        ):
            plone_versions = (target_branch,)

        elif not plone_versions:
            self.log('does not target any Plone version')
            return []

        return plone_versions
Example #8
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 #9
0
    def _which_plone_versions(self):
        response = requests.get(self.event.pull_request['url'])
        if response.status_code != 200:
            self.log('Could not get information regarding pull request',
                     level='warn')
            return []

        data = response.json()
        target_branch = data['base']['ref']
        repo_full_name = data['base']['repo']['full_name']

        plone_versions = plone_versions_targeted(repo_full_name, target_branch,
                                                 self.event.request)

        tracked_versions = self.event.request.registry.settings[
            'plone_versions']
        if (repo_full_name == 'plone/buildout.coredev'
                and target_branch in tracked_versions):
            plone_versions = (target_branch, )

        elif not plone_versions:
            self.log('Does not target any Plone version')

        return plone_versions
Example #10
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 #11
0
 def is_core_package(self):
     base_branch = self.pull_request['base']['ref']
     return plone_versions_targeted(self.repo_full_name, base_branch,
                                    self.event.request)
Example #12
0
 def is_core_package(self):
     base_branch = self.pull_request['base']['ref']
     return plone_versions_targeted(
         self.repo_full_name, base_branch, self.event.request
     )
Example #13
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 #14
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'}
    )