Skip to content

Commit 0cc821d

Browse files
committed
Add filename date requirement (yyyymmdd_) for request files
1 parent cb5e0b1 commit 0cc821d

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

.github/scripts/validate_community_kv.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import re
1515
import sys
1616
from dataclasses import dataclass, field
17+
from datetime import datetime, timedelta, timezone
1718
from pathlib import Path
1819
from typing import Any
1920

@@ -52,6 +53,7 @@
5253
}
5354

5455
CANONICAL_NAME_PATTERN = re.compile(r"^[a-zA-Z][a-zA-Z0-9_]*$")
56+
FILENAME_DATE_PATTERN = re.compile(r"^(\d{8})_.*\.json$")
5557
VALID_TYPES = {"class", "property", "datatype", "constant"}
5658
MIN_CODEPOINT = 100000
5759

@@ -346,6 +348,48 @@ def validate_name_uniqueness_within_request(
346348
seen_names[name] = i
347349

348350

351+
def validate_filename_date(file_path: Path, result: ValidationResult) -> bool:
352+
"""V-006: Filename must start with date in yyyymmdd_ format (±1 day tolerance)."""
353+
filename = file_path.name
354+
355+
# Skip the example template
356+
if filename.startswith("_"):
357+
return True
358+
359+
match = FILENAME_DATE_PATTERN.match(filename)
360+
if not match:
361+
result.add_error(
362+
"V-006",
363+
str(file_path),
364+
f"Filename must start with date in yyyymmdd_ format (e.g., 20260107_myrequest.json), got: {filename}",
365+
)
366+
return False
367+
368+
date_str = match.group(1)
369+
try:
370+
file_date = datetime.strptime(date_str, "%Y%m%d").date()
371+
except ValueError:
372+
result.add_error(
373+
"V-006",
374+
str(file_path),
375+
f"Invalid date in filename: {date_str}",
376+
)
377+
return False
378+
379+
# Allow ±1 day tolerance for timezone differences
380+
today = datetime.now(timezone.utc).date()
381+
delta = abs((file_date - today).days)
382+
if delta > 1:
383+
result.add_error(
384+
"V-006",
385+
str(file_path),
386+
f"Filename date {date_str} is more than 1 day from today ({today.strftime('%Y%m%d')})",
387+
)
388+
return False
389+
390+
return True
391+
392+
349393
def validate_request_file(
350394
file_path: Path,
351395
assigned_codepoints: set[int],
@@ -354,6 +398,9 @@ def validate_request_file(
354398
result: ValidationResult,
355399
):
356400
"""Validate a single request file against all rules."""
401+
# V-006: Filename date format
402+
validate_filename_date(file_path, result)
403+
357404
# V-001: Parse JSON
358405
data = validate_json_syntax(file_path, result)
359406
if data is None:

community-known-values/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This directory manages community-submitted Known Value assignments. Known Values
44

55
## How to Submit a Request
66

7-
1. **Create a JSON file** in the `requests/` directory following the naming convention: `<submitter>_<description>.json`
7+
1. **Create a JSON file** in the `requests/` directory following the naming convention: `yyyymmdd_<description>.json` (e.g., `20260107_myproject.json`)
88
2. **Choose your code points** — each entry must specify a `codepoint` value ≥ 100,000 that is not already assigned
99
3. **Submit a Pull Request** with your request file(s)
1010

community-known-values/Spec.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ community-known-values/requests/
3838

3939
### 2.2 File Naming Convention
4040

41-
Request files should follow the pattern:
41+
Request files must follow the pattern:
4242

4343
```
44-
<submitter>_<short_description>.json
44+
yyyymmdd_<short_description>.json
4545
```
4646

47+
Where `yyyymmdd` is the submission date (e.g., `20260107` for January 7, 2026). This ensures request files are sorted chronologically.
48+
4749
Examples:
48-
- `alice_credential_types.json`
49-
- `myorg_payment_terms.json`
50+
- `20260107_credential_types.json`
51+
- `20260115_payment_terms.json`
52+
53+
**Note:** The date is validated with ±1 day tolerance to account for timezone differences.
5054

5155
### 2.3 JSON Schema
5256

@@ -170,6 +174,7 @@ The workflow must validate each request against the following rules. A PR is rej
170174
| V-003 | `canonical_name` must match `^[a-zA-Z][a-zA-Z0-9_]*$` |
171175
| V-004 | `type` must be one of: `class`, `property`, `datatype`, `constant` |
172176
| V-005 | `description` must be at least 10 characters |
177+
| V-006 | Filename must start with date in `yyyymmdd_` format (±1 day) |
173178

174179
### 3.2 Code Point Rules
175180

0 commit comments

Comments
 (0)