From c8fb958865c6e80d450c03da5292472387d22bc3 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 7 Oct 2020 00:14:15 +0800 Subject: [PATCH] ceph-pr-commits: add a doc_test checking title of commit message Signed-off-by: Kefu Chai --- ceph-pr-commits/build/build | 2 +- ceph-pr-commits/build/conftest.py | 3 +++ ceph-pr-commits/build/test_commits.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ceph-pr-commits/build/build b/ceph-pr-commits/build/build index 326791a6..504b7bca 100644 --- a/ceph-pr-commits/build/build +++ b/ceph-pr-commits/build/build @@ -14,7 +14,7 @@ if git rev-parse --verify ${GIT_COMMIT}^2; then pytest_mark="code_test" else echo "Only the doc/ dir changed. No need to check for signed commits." - pytest_mark="not code_test" + pytest_mark="doc_test" fi fi popd diff --git a/ceph-pr-commits/build/conftest.py b/ceph-pr-commits/build/conftest.py index 5ec09260..f5feed0c 100644 --- a/ceph-pr-commits/build/conftest.py +++ b/ceph-pr-commits/build/conftest.py @@ -5,6 +5,9 @@ def pytest_configure(config): config.addinivalue_line( "markers", "code_test: mark test to run against code related changes" ) + config.addinivalue_line( + "markers", "doc_test: mark test to run against doc only changes" + ) def pytest_addoption(parser): diff --git a/ceph-pr-commits/build/test_commits.py b/ceph-pr-commits/build/test_commits.py index b23988f2..315a8002 100644 --- a/ceph-pr-commits/build/test_commits.py +++ b/ceph-pr-commits/build/test_commits.py @@ -35,6 +35,23 @@ class TestCommits(object): 'git fetch origin +refs/heads/{target_branch}:refs/remotes/origin/{target_branch}'.format( target_branch=cls.target_branch)) + @pytest.mark.doc_test + def test_doc_title(self): + doc_regex = '\nDate:[^\n]+\n\n doc' + all_commits = 'git log -z --no-merges origin/%s..%s' % ( + self.target_branch, self.source_branch) + wrong_commits = list(filterfalse( + re.compile(doc_regex).search, + self.command(all_commits).split('\0'))) + if wrong_commits: + raise AssertionError("\n".join([ + "The title/s of following commit/s is/are not started with 'doc', but they only touch files under 'doc/'. Please make sure the commit titles", + "are started with 'doc'. See the 'Submitting Patches' guide:", + "https://github.com/ceph/ceph/blob/master/SubmittingPatches.rst#commit-title", + ""] + + wrong_commits + )) + @pytest.mark.code_test def test_signed_off_by(self): signed_off_regex = r'Signed-off-by: \S.* <[^@]+@[^@]+\.[^@]+>' -- 2.39.5