mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
* 🐛 Submit the import audit events from the import job Since 2.20 the dashboard imports .penpot files through the :import-binfile job, which submitted no audit event. The outcome of an import and the files it created were lost, so analytics could no longer tell completed imports from failed ones. The job now submits the import-binfile event with the name and props of the legacy RPC event (status, file-ids, file-count, project, version, generated-by, referer), plus the job id, the team id, the package size and the elapsed time. A cancelled job reports the cancelled status. A completed import also submits a create-file event per imported file, as the legacy RPC does. As in the RPC, an import refused by the permission check submits no event. Closes #13148 AI-assisted-by: claude-opus-5-5 * 🐛 Audit import jobs at their terminal transition Run optional terminal hooks in the winning job transaction and use one for import audit events. Preserve the separate import transaction and cover cancellation, rollback, RPC paths, and dispatcher aborts. AI-assisted-by: gpt-6.1-terra * ♻️ Simplify the terminal job hook contract Pass a semantic terminal job to the hook with its final status and decoded parameters, result or error. Adapt the import audit and tests. AI-assisted-by: gpt-6.1-terra * 🐛 Keep import jobs bound to their original team Freeze the destination team when creating an import job and serialize imports with project moves. Use the frozen team for audit and webhook events, and keep compatibility with existing jobs. Select import audit props explicitly to prevent new job parameters from being included in events by default. AI-assisted-by: gpt-6.1-terra * 📚 Document the import team fallback removal Mark the legacy job audit fallback for removal in version 2.21.0. AI-assisted-by: gpt-6.1-terra * 🔧 Validate canonical AI model IDs in commit trailers Require bare lowercase model IDs in AI-assisted-by trailers and cover the validation with tests. Align the commit and PR workflows with the same attribution rules. AI-assisted-by: gpt-6.1-terra --------- Co-authored-by: Andrey Antukh <niwi@niwi.nz>
319 lines
12 KiB
Python
Executable File
319 lines
12 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Check commit messages against Penpot's commit guidelines.
|
|
|
|
Validates commit messages using the rules defined in:
|
|
- .github/workflows/commit-checker.yml (regex pattern)
|
|
- CONTRIBUTING.md (formatting rules, subject length)
|
|
- .serena/memories/workflow/creating-commits.md (body wrapped at 80 chars)
|
|
|
|
By default, checks HEAD. Use --commit to specify a different commit.
|
|
|
|
Usage:
|
|
./scripts/check-commit
|
|
./scripts/check-commit --commit HEAD~1
|
|
./scripts/check-commit -c abc1234
|
|
"""
|
|
|
|
import argparse
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
# ── Emoji list ───────────────────────────────────────────────────────────────
|
|
# Combined from commit-checker.yml AND CONTRIBUTING.md
|
|
VALID_EMOJIS = (
|
|
"lipstick|globe_with_meridians|wrench|books|"
|
|
"arrow_up|arrow_down|zap|ambulance|construction|"
|
|
"boom|fire|whale|bug|sparkles|paperclip|tada|"
|
|
"recycle|rewind|construction_worker|rocket"
|
|
)
|
|
|
|
# ── Regex from .github/workflows/commit-checker.yml ──────────────────────────
|
|
# Matches:
|
|
# 1) ":emoji: <Capitalized subject without trailing dot>"
|
|
# 2) "Merge|Revert|Reapply ... without trailing dot"
|
|
COMMIT_PATTERN = re.compile(
|
|
r"^((:(" + VALID_EMOJIS + r"):\s[A-Z].*[^.]))$"
|
|
)
|
|
|
|
MERGE_PATTERN = re.compile(r"^(Merge|Revert|Reapply).+[^.]$")
|
|
|
|
# ── Subject line length ──────────────────────────────────────────────────────
|
|
# Subject lines must fit in 80 characters. Merge/Revert/Reapply commits are
|
|
# exempt: git prepends "Merge ..."/"Revert ..." to an existing subject, so
|
|
# enforcing the limit would fail on text the author did not write.
|
|
MAX_SUBJECT_LINE = 80
|
|
|
|
# ── Body line wrapping ───────────────────────────────────────────────────────
|
|
# Commit bodies must wrap at 80 characters (see
|
|
# .serena/memories/workflow/creating-commits.md). Trailers and
|
|
# URLs are exempt: they cannot be wrapped without losing meaning.
|
|
MAX_BODY_LINE = 80
|
|
|
|
TRAILER_PATTERN = re.compile(
|
|
r"^(Signed-off-by|Co-authored-by|Co-developed-by|Reviewed-by|"
|
|
r"Acked-by|Tested-by|Reported-by|Suggested-by|AI-assisted-by):"
|
|
)
|
|
|
|
# ── Co-authored-by trailer ───────────────────────────────────────────────────
|
|
# A human co-author may be credited with Co-authored-by. The trailer is
|
|
# forbidden when its value names an AI provider, an AI agent, or a bot: for AI
|
|
# participation the message uses "AI-assisted-by: <model>" instead.
|
|
# Extend this list when a new tool starts adding trailers.
|
|
NON_HUMAN_COAUTHOR_PATTERN = re.compile(
|
|
r"^\s*co-authored-by\s*:.*("
|
|
r"\b(?:chatgpt|openai|anthropic|claude|copilot|codex|gemini|bard|"
|
|
r"deepseek|mistral|qwen|kimi|llama|grok|cursor|"
|
|
r"windsurf|cline|aider|codeium|tabnine|amazon\s+q|sourcegraph\s+cody|"
|
|
r"roo\s+code|kilo\s+code|opencode)\b"
|
|
r"|\bdevin-ai|@devin\.ai"
|
|
r"|\[bot\]|\bbot@"
|
|
r")",
|
|
re.IGNORECASE,
|
|
)
|
|
|
|
AI_TRAILER_PATTERN = re.compile(r"^\s*ai-assisted-by\s*:(.*)$", re.IGNORECASE)
|
|
MODEL_ID_PATTERN = re.compile(r"[a-z0-9]+(?:[.-][a-z0-9]+)*")
|
|
|
|
URL_PATTERN = re.compile(r"https?://\S+")
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
# Helpers
|
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
|
|
def run_git(args):
|
|
"""Run a git command and return (returncode, stdout, stderr)."""
|
|
try:
|
|
result = subprocess.run(
|
|
["git"] + args,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
return result.returncode, result.stdout, result.stderr
|
|
except FileNotFoundError:
|
|
print("ERROR: git not found. Is it installed?", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
def get_commit_message(commit_ref):
|
|
"""Return the full commit message for *commit_ref*."""
|
|
rc, out, err = run_git(["log", "--format=%B", "-n", "1", commit_ref])
|
|
if rc != 0:
|
|
print(f"ERROR: could not read commit {commit_ref}: {err.strip()}", file=sys.stderr)
|
|
sys.exit(1)
|
|
if not out.strip():
|
|
print(f"ERROR: commit {commit_ref} has no message", file=sys.stderr)
|
|
sys.exit(1)
|
|
return out.rstrip("\n")
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
# Validators
|
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
|
|
def check_regex(message):
|
|
"""Check the commit message against the CI regex pattern."""
|
|
# Normalise: strip trailing newlines for single-line matching
|
|
first_line = message.split("\n")[0]
|
|
|
|
if MERGE_PATTERN.match(first_line):
|
|
return True, None
|
|
|
|
if COMMIT_PATTERN.match(first_line):
|
|
return True, None
|
|
|
|
return False, (
|
|
"Commit subject must match one of:\n"
|
|
" :emoji: <Capitalized subject without trailing dot>\n"
|
|
" Merge|Revert|Reapply <rest without trailing dot>\n"
|
|
f"Got: {first_line!r}"
|
|
)
|
|
|
|
|
|
def check_subject_length(message):
|
|
"""Subject line must be ≤ 80 characters (Merge/Revert/Reapply exempt)."""
|
|
first_line = message.split("\n")[0]
|
|
if MERGE_PATTERN.match(first_line):
|
|
return True, None
|
|
if len(first_line) > MAX_SUBJECT_LINE:
|
|
return False, (
|
|
f"Subject line exceeds {MAX_SUBJECT_LINE} characters ({len(first_line)} chars):\n"
|
|
f" {first_line}"
|
|
)
|
|
return True, None
|
|
|
|
|
|
def check_subject_no_trailing_dot(message):
|
|
"""Subject line must not end with a period ('.')."""
|
|
first_line = message.split("\n")[0]
|
|
if first_line.endswith("."):
|
|
return False, (
|
|
"Subject line must not end with a period:\n"
|
|
f" {first_line}"
|
|
)
|
|
return True, None
|
|
|
|
|
|
def check_subject_capitalized(message):
|
|
"""Subject must be capitalized, but only if it's a regular commit (not Merge/Revert/Reapply)."""
|
|
first_line = message.split("\n")[0]
|
|
|
|
# Skip check for Merge/Revert/Reapply commits
|
|
if MERGE_PATTERN.match(first_line):
|
|
return True, None
|
|
|
|
# Strip emoji prefix before checking capitalization
|
|
emoji_match = re.match(r"^:([a-z_]+):\s+(.*)", first_line)
|
|
if emoji_match:
|
|
rest = emoji_match.group(2)
|
|
else:
|
|
rest = first_line
|
|
|
|
if rest and not rest[0].isupper():
|
|
return False, (
|
|
"Subject line must start with a capital letter "
|
|
"(after the emoji prefix):\n"
|
|
f" {first_line}"
|
|
)
|
|
return True, None
|
|
|
|
|
|
def check_body_blank_line(message):
|
|
"""If a body exists, there must be a blank line between subject and body."""
|
|
lines = message.split("\n")
|
|
if len(lines) >= 3 and lines[1] != "":
|
|
return False, (
|
|
"A blank line must separate the subject from the body."
|
|
)
|
|
return True, None
|
|
|
|
|
|
def check_body_line_length(message):
|
|
"""Body lines must wrap at 80 characters or fewer.
|
|
|
|
The subject (first line) has its own length rule. Trailers (e.g.
|
|
Signed-off-by) and lines carrying a URL are exempt, since wrapping them
|
|
would break tooling or lose information.
|
|
"""
|
|
lines = message.split("\n")
|
|
offenders = []
|
|
|
|
for line_number, line in enumerate(lines[1:], start=2):
|
|
if len(line) <= MAX_BODY_LINE:
|
|
continue
|
|
if TRAILER_PATTERN.match(line):
|
|
continue
|
|
if URL_PATTERN.search(line):
|
|
continue
|
|
# A long token with no whitespace before the limit cannot be wrapped.
|
|
if " " not in line[:MAX_BODY_LINE]:
|
|
continue
|
|
offenders.append((line_number, line))
|
|
|
|
if not offenders:
|
|
return True, None
|
|
|
|
details = "\n".join(
|
|
f" line {line_number} ({len(line)} chars): {line!r}"
|
|
for line_number, line in offenders
|
|
)
|
|
return False, (
|
|
f"Body lines must wrap at {MAX_BODY_LINE} characters or fewer. "
|
|
"Unwrapped line(s):\n" + details
|
|
)
|
|
|
|
|
|
def check_co_authored_by(message):
|
|
"""Co-authored-by is allowed for humans, not for AI providers or bots."""
|
|
offenders = [
|
|
(line_number, line)
|
|
for line_number, line in enumerate(message.split("\n"), start=1)
|
|
if NON_HUMAN_COAUTHOR_PATTERN.match(line)
|
|
]
|
|
if not offenders:
|
|
return True, None
|
|
details = "\n".join(
|
|
f" line {line_number}: {line!r}"
|
|
for line_number, line in offenders
|
|
)
|
|
return False, (
|
|
"The 'Co-authored-by:' trailer is only for human co-authors. This one "
|
|
"names an AI provider, an AI agent, or a bot. Offending line(s):\n"
|
|
+ details
|
|
+ "\n For AI participation use: AI-assisted-by: <model-name>"
|
|
)
|
|
|
|
|
|
def check_ai_assisted_by(message):
|
|
"""Validate every AI-assisted-by value as a bare lowercase model ID."""
|
|
offenders = []
|
|
for line_number, line in enumerate(message.split("\n"), start=1):
|
|
match = AI_TRAILER_PATTERN.match(line)
|
|
if match and not MODEL_ID_PATTERN.fullmatch(match.group(1).strip()):
|
|
offenders.append((line_number, line))
|
|
if not offenders:
|
|
return True, None
|
|
details = "\n".join(
|
|
f" line {line_number}: {line!r}"
|
|
for line_number, line in offenders
|
|
)
|
|
return False, (
|
|
"AI-assisted-by must use a bare lowercase canonical model ID slug "
|
|
"(for example, gpt-6.1-terra), without a provider prefix. "
|
|
"Offending line(s):\n" + details
|
|
)
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Check a commit message against Penpot commit guidelines."
|
|
)
|
|
parser.add_argument(
|
|
"-c", "--commit",
|
|
default="HEAD",
|
|
help="Commit to check (default: HEAD)",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
commit_ref = args.commit
|
|
message = get_commit_message(commit_ref)
|
|
|
|
print(f"Checking commit {commit_ref} ...\n")
|
|
|
|
validators = [
|
|
("Regex pattern", check_regex),
|
|
("Subject ≤ 80 chars", check_subject_length),
|
|
("No trailing period in subject", check_subject_no_trailing_dot),
|
|
("Subject capitalized", check_subject_capitalized),
|
|
("Blank line after subject", check_body_blank_line),
|
|
("Body wrapped at 80 chars", check_body_line_length),
|
|
("Co-authored-by is human only", check_co_authored_by),
|
|
("AI-assisted-by uses a model ID slug", check_ai_assisted_by),
|
|
]
|
|
|
|
all_ok = True
|
|
|
|
for name, validator in validators:
|
|
ok, error_msg = validator(message)
|
|
status = "✓" if ok else "✗"
|
|
print(f" [{status}] {name}")
|
|
if not ok:
|
|
all_ok = False
|
|
print(f" {error_msg}", file=sys.stderr)
|
|
|
|
print()
|
|
if all_ok:
|
|
print("All checks passed.")
|
|
sys.exit(0)
|
|
else:
|
|
print("Some checks FAILED. See messages above.", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|