Skip to content

Commit

Permalink
Merge pull request #81 from plone/py-versions-per-plone-version
Browse files Browse the repository at this point in the history
Py versions per plone version
  • Loading branch information
gforcada committed May 3, 2021
2 parents a0e35c5 + 858c6ed commit 3fd95d0
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 261 deletions.
11 changes: 3 additions & 8 deletions src/mr.roboto/src/mr/roboto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ def main(global_config, **settings):
settings['plone_versions']
)

# plone versions that need py3 support
config.registry.settings['plone_py3_versions'] = ast.literal_eval(
settings['plone_py3_versions']
)

# python versions
config.registry.settings['py3_versions'] = ast.literal_eval(
settings['py3_versions']
# dictionary the list of python versions (value) per plone version (key)
config.registry.settings['py_versions'] = ast.literal_eval(
settings['py_versions']
)

# github users
Expand Down
6 changes: 3 additions & 3 deletions src/mr.roboto/src/mr/roboto/buildout.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def path(self):
match = PATH_RE.match(self.url)
if match:
return match.groupdict()['path']
return None
return None # pragma: no cover


class SourcesFile(UserDict):
Expand Down Expand Up @@ -85,7 +85,7 @@ def __init__(self, file_location):
@property
def data(self):
if self._data:
return self._data
return self._data # pragma: no cover
config = ConfigParser(interpolation=ExtendedInterpolation())
with open(self.file_location) as f:
config.read_file(f)
Expand Down Expand Up @@ -148,7 +148,7 @@ def get_sources_and_checkouts(request):
else:
sources_dict[key].append(plone_version)
else:
logger.warning(f'Package {source} does not have a valid URL')
logger.warning(f'Package {source} does not have a valid URL') # pragma: no cover

checkouts_dict[plone_version] = []
for checkout in buildout.checkouts.data:
Expand Down
69 changes: 15 additions & 54 deletions src/mr.roboto/src/mr/roboto/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ def target_branch(self):
return self._target_branch

def run(self):
raise NotImplementedError
raise NotImplementedError # pragma: no cover

def log(self, msg, level='info'):
if level == 'warn':
if level == 'warn': # pragma: no cover
logger.warning(f'PR {self.short_url}: {msg}')
return
logger.info(f'PR {self.short_url}: {msg}')
Expand Down Expand Up @@ -351,7 +351,7 @@ def run(self):
for diff_file in patch_data:
if VALID_CHANGELOG_FILES.search(diff_file.path):
break
if diff_file.path.startswith('news/'):
if 'news/' in diff_file.path:
# towncrier news snippet
break
else:
Expand Down Expand Up @@ -385,20 +385,16 @@ def run(self):
"""Create waiting status for all pull request jobs that should be run
before a pull request can be safely merged
"""
# This may return ["5.2", "6.0"].
plone_versions = self._plone_versions_targeted()
# This WarnTestsNeedToRun check is for Python 2 only.
# The plone_versions setting in production.ini should contain only 2.7
plone_py2_versions = self.event.request.registry.settings['plone_versions']
python_versions = self.event.request.registry.settings['py_versions']

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

for version in plone_versions:
if version not in plone_py2_versions:
continue
self._create_commit_status(last_commit, version)
self.log(f'created pending status for plone {version}')
for plone_version in plone_versions:
for py_version in python_versions[plone_version]:
self._create_commit_status(last_commit, plone_version, py_version)
self.log(f'created pending status for plone {plone_version} on python {py_version}')

def _plone_versions_targeted(self):
if self.repo_name in IGNORE_NO_TEST_NEEDED:
Expand All @@ -424,38 +420,6 @@ def _plone_versions_targeted(self):

return plone_versions

def _create_commit_status(self, commit, version):
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),
)


@subscriber(NewPullRequest, UpdatedPullRequest)
class WarnPy3TestsNeedToRun(WarnTestsNeedToRun):
def run(self):
"""Create waiting status for pull requests that target a plone version
that targets python 3.
"""
plone_py3_versions = self.event.request.registry.settings['plone_py3_versions']
plone_versions = self._plone_versions_targeted()

if not set(plone_py3_versions).intersection(plone_versions):
self.log('does not target a Plone version that targets Python 3, no py3 pull request job needed')
return

py3_tracked_versions = self.event.request.registry.settings['py3_versions']

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

for plone_version in plone_py3_versions:
for py_version in py3_tracked_versions:
self._create_commit_status(last_commit, plone_version, py_version)
self.log(f'created pending status for plone {plone_version} on python {py_version}')

def _create_commit_status(self, commit, plone_version, python_version):
combination = f'{plone_version}-{python_version}'
commit.create_status(
Expand Down Expand Up @@ -522,7 +486,7 @@ def add_pacakge_to_checkouts(self, versions):
while attempts < 5:
try:
self.make_commit(repo, version, user)
except GithubException:
except GithubException: # pragma: no cover
attempts += 1
if attempts == 5:
self.log(
Expand All @@ -544,7 +508,7 @@ def make_commit(self, repo, version, user):
latest_commit = repo.get_git_commit(head_ref.object.sha)
base_tree = latest_commit.tree
mode = [t.mode for t in base_tree.tree if t.path == filename]
if mode:
if mode: # pragma: no cover
mode = mode[0]
else:
mode = '100644'
Expand Down Expand Up @@ -626,14 +590,11 @@ def _which_plone_versions(self):

def _trigger_jobs(self, plone_versions):
settings = self.event.request.registry.settings
py3_versions = settings['py3_versions']
plone_py3_versions = settings['plone_py3_versions']

for version in plone_versions:
self._create_job(version)
if version in plone_py3_versions:
for python in py3_versions:
self._create_job(f'{version}-{python}')
python_versions = settings['py_versions']

for plone in plone_versions:
for python in python_versions[plone]:
self._create_job(f'{plone}-{python}')

def _create_job(self, version):
settings = self.event.request.registry.settings
Expand Down
53 changes: 53 additions & 0 deletions src/mr.roboto/src/mr/roboto/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-


def default_settings(github=None, parsed=True, override_settings=None):
plone = ['5.2', '6.0']
python = {'5.2': ['2.7', '3.6', ], '6.0': ['3.8', '3.9']}
github_users = ['mister-roboto', 'jenkins-plone-org', ]
if not parsed:
plone = str(plone)
python = str(python)
github_users = str(github_users)
data = {
'plone_versions': plone,
'py_versions': python,
'roboto_url': 'http://jenkins.plone.org/roboto',
'api_key': '1234567890',
'sources_file': 'sources.pickle',
'checkouts_file': 'checkouts.pickle',
'github_token': 'secret',
'jenkins_user_id': 'jenkins-plone-org',
'jenkins_user_token': 'some-random-token',
'jenkins_url': 'https://jenkins.plone.org',
'collective_repos': '',
'github': github,
'github_users': github_users,
'debug': 'True',
}
if override_settings:
data.update(override_settings)
return data


def minimal_main(override_settings=None, scan_path=''):
from github import Github
from pyramid.config import Configurator

settings = default_settings(override_settings=override_settings)

config = Configurator(settings=settings)
config.include('cornice')

for key, value in settings.items():
config.registry.settings[key] = value

config.registry.settings['github_users'] = (
settings['jenkins_user_id'],
'mister-roboto',
)
config.registry.settings['github'] = Github(settings['github_token'])

config.scan(scan_path)
config.end()
return config.make_wsgi_app()
37 changes: 11 additions & 26 deletions src/mr.roboto/src/mr/roboto/tests/test_buildout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from git import Repo
from mr.roboto import main
from mr.roboto.buildout import PloneCoreBuildout
from mr.roboto.tests import default_settings
from tempfile import mkdtemp
from tempfile import NamedTemporaryFile
from webtest import TestApp as BaseApp

import os
Expand Down Expand Up @@ -40,28 +40,13 @@ def setUp(self):

self._commit(SOURCES, filename='sources.cfg')
self._commit(CHECKOUTS, filename='checkouts.cfg')
self.coredev_repo.create_head('4.3')
self.coredev_repo.create_head('5.1')

with NamedTemporaryFile(delete=False) as tmp_file:
sources_pickle = tmp_file.name

with NamedTemporaryFile(delete=False) as tmp_file:
checkouts_pickle = tmp_file.name

self.settings = {
'plone_versions': '["5.1", "4.3", ]',
'py3_versions': '["2.7", "3.6", ]',
'plone_py3_versions': '["5.2", ]',
'github_users': '["mister-roboto", "jenkins-plone-org", ]',
'roboto_url': 'http://jenkins.plone.org/roboto',
'api_key': 'xyz1234mnop',
'sources_file': sources_pickle,
'checkouts_file': checkouts_pickle,
'github_token': 'x',
}
app = main({}, **self.settings)

app = main({}, **default_settings(parsed=False))
self.roboto = BaseApp(app)
self.settings = app.registry.settings

for plone in self.settings['plone_versions']:
self.coredev_repo.create_head(plone)

def tearDown(self):
shutil.rmtree(self.coredev_repo.working_tree_dir)
Expand All @@ -83,11 +68,11 @@ def test_get_sources_and_checkouts(self):
with open(self.settings['sources_file'], 'br') as sources:
data = pickle.load(sources)

self.assertEqual(data[('plone/Products.CMFPlone', 'master')], ['5.1', '4.3'])
self.assertEqual(data[('plone/Products.CMFCore', '2.2.x')], ['5.1', '4.3'])
self.assertEqual(data[('plone/Products.CMFPlone', 'master')], ['5.2', '6.0'])
self.assertEqual(data[('plone/Products.CMFCore', '2.2.x')], ['5.2', '6.0'])

with open(self.settings['checkouts_file'], 'br') as checkouts:
data = pickle.load(checkouts)

self.assertEqual(data['5.1'], ['plone.app.contenttypes', 'Products.CMFPlone'])
self.assertEqual(data['4.3'], ['plone.app.contenttypes', 'Products.CMFPlone'])
self.assertEqual(data['5.2'], ['plone.app.contenttypes', 'Products.CMFPlone'])
self.assertEqual(data['6.0'], ['plone.app.contenttypes', 'Products.CMFPlone'])
25 changes: 25 additions & 0 deletions src/mr.roboto/src/mr/roboto/tests/test_changelog_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@
setup(
"""

DIFF_WITH_NEWS_ENTRY = """
diff --git a/src/mr.roboto/CHANGES.rst b/src/mr.roboto/news/1.bugfix
index 2a20bdc..57ce05f 100644
--- a/src/mr.roboto/news/1.bugfix
+++ b/src/mr.roboto/news/1.bugfix
@@ -16,6 +16,7 @@
'pyramid_debugtoolbar',
'pytest',
'WebTest',
+ 'testfixtures',
]
setup(
"""

DIFF_WITH_CHANGELOG_ON_HISTORY_txt = """diff --git a/src/mr.roboto/HISTORY.rst b/src/mr.roboto/HISTORY.rst
index 2a20bdc..57ce05f 100644
--- a/src/mr.roboto/HISTORY.rst
Expand Down Expand Up @@ -126,6 +140,17 @@ def test_with_change_log_file(self, m1):

self.assertIn('changelog entry: success', captured_data.records[-1].msg)

@mock.patch('requests.get')
def test_with_news_entry(self, m1):
m1.return_value = MockDiff(DIFF_WITH_NEWS_ENTRY)

event = NewPullRequest(pull_request=PAYLOAD, request=MockRequest())

with LogCapture() as captured_data:
WarnNoChangelogEntry(event)

self.assertIn('changelog entry: success', captured_data.records[-1].msg)

@mock.patch('requests.get')
def test_with_change_log_file_history(self, m1):
m1.return_value = MockDiff(DIFF_WITH_CHANGELOG_ON_HISTORY_txt)
Expand Down
Loading

0 comments on commit 3fd95d0

Please sign in to comment.