Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Title level #24 #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions campbot/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def get_fixed_tests(lang):
RouteTypeTest(),
DistanceTest(),
QualityTest(),
TitleLevel(),
]


Expand Down Expand Up @@ -486,3 +487,28 @@ def __init__(self):

def test_contribution(self, old_doc, new_doc):
return old_doc.quality == new_doc.quality

class TitleLevel(object):
def __init__(self):
self.name = "Titre de niveau trop élevé"
self.fail_marker = emoji("<strong>H</strong>",
self.name)
self.success_marker = ""

def __call__(self, contrib, old_version, new_version):
if old_version is None or new_version is None:
return True, True

old_doc = old_version.document
new_doc = new_version.document

if "redirects_to" in old_doc or "redirects_to" in new_doc:
return True, True

def check(doc):
has_level2 = doc.search( r"(^|\n)##[^#]") is not None
has_level3_or_more = doc.search(r"(^|\n)###*" is not None

return not has_level2 and has_level3_or_more

return check(old_doc), check(new_doc)