Skip to content

Commit

Permalink
Add slug check
Browse files Browse the repository at this point in the history
  • Loading branch information
froggleston authored Jun 27, 2024
1 parent 34da415 commit eea9980
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ create a workshop website.
3. Select the owner for your new repository.
(This will probably be you, but may instead be an organization you belong to.)

4. Choose a name for your workshop website repository.
This name should have the form `YYYY-MM-DD-site`,
4. Create a slug for your workshop website repository.
The slug should have the form `YYYY-MM-DD-site`,
e.g., `2016-12-01-oomza`,
where `YYYY-MM-DD` is the start date of the workshop.
where `YYYY-MM-DD` is the start date of the workshop and 'oomza' is an example site name.
If your workshop is held online, then the respository name should have `-online` in the end.
e.g., `2016-12-01-oomza-online`

Expand Down
24 changes: 24 additions & 0 deletions bin/workshop_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
HUMANTIME_PATTERN = r'((0?[1-9]|1[0-2]):[0-5]\d(am|pm)(-|to)(0?[1-9]|1[0-2]):[0-5]\d(am|pm))|((0?\d|1\d|2[0-3]):[0-5]\d(-|to)(0?\d|1\d|2[0-3]):[0-5]\d)'
EVENTBRITE_PATTERN = r'\d{9,10}'
URL_PATTERN = r'https?://.+'
SLUG_PATTERN = r'\d{4}-\d{2}-\d{2}-[A-z0-9\-\_]+'

# Defaults.
CARPENTRIES = ("dc", "swc", "lc", "cp")
Expand Down Expand Up @@ -400,6 +401,28 @@ def check_config(reporter, filename):
carpentry)


def check_slug(reporter, repo_dir):
config = load_yaml(filename)

repo_name = os.path.basename(repo_dir)

carpentry = config.get('carpentry', None)
kind = config.get('kind', None)

if carpentry == "cp":
slugfmt = "YYYY-MM-DD-ttt-format"
else:
slugfmt = "YYYY-MM-DD-site-format"

fail_msg = f'Workshop website slug does not match the required `{slugfmt}`'

if carpentry in ('swc', 'dc', 'lc', 'cp'):
reporter.check(
bool(re.match(SLUG_PATTERN, repo_name)),
fail_msg
)


def main():
'''Run as the main program.'''

Expand All @@ -413,6 +436,7 @@ def main():

reporter = Reporter()
check_config(reporter, config_file)
check_slug(reporter, root_dir)
check_unwanted_files(root_dir, reporter)
with open(index_file, encoding='utf-8') as reader:
data = reader.read()
Expand Down

0 comments on commit eea9980

Please sign in to comment.