mirror of
https://github.com/penpot/penpot.git
synced 2026-11-18 16:12:24 +00:00
✨ Allow human co-authors in the commit checker
The checker rejected any Co-authored-by trailer, which also blocked a real person. The trailer is meant to credit a human co-author, and git and GitHub use it for that; only AI providers, agents and bots are unwanted. Match the trailer value against a blocklist of providers and agents plus bot identities, and point to the dedicated AI-assisted-by trailer for AI participation. Co-authored-by joins the trailer exemption of the 80-character body rule. Update the tests, CONTRIBUTING.md, the create-commit skill and the commit memory to the new rule. AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
parent
1d60ba65b5
commit
dce4d8fe56
@ -63,6 +63,8 @@ subject/body limits, and the `AI-assisted-by` trailer. Follow it exactly.
|
||||
- Do not pass `--author`. Author identity comes from the local git config.
|
||||
- Do not amend a commit you did not create in this session, unless explicitly asked.
|
||||
- Do not bypass pre-commit hooks (`--no-verify`) unless explicitly asked.
|
||||
- Never add a `Co-authored-by:` trailer. It is forbidden and fails `./scripts/check-commit`.
|
||||
- Add `Co-authored-by:` only for a human co-author. AI providers, agents and
|
||||
bots are rejected by `./scripts/check-commit`; for AI participation use the
|
||||
`AI-assisted-by:` trailer.
|
||||
- Do not add untracked files that were not created in this session.
|
||||
- Do not skip the `scripts/check-commit` verification step (Iron Rule 4).
|
||||
|
||||
@ -43,10 +43,9 @@ that breaks them is wrong, even if the code is right.
|
||||
- For another commit: `./scripts/check-commit -c <ref>`
|
||||
- **NEVER** hand-wave the body as "one long line". If a line exceeds 80,
|
||||
break it at a space.
|
||||
- **NEVER add a `Co-authored-by:` trailer.** It is forbidden; `scripts/check-commit` fails the commit when any line matches it (case-insensitive).
|
||||
- **`Co-authored-by:` is for human co-authors only** (`Co-authored-by: Name <email>`). AI providers, agents and bots must not be credited that way; use `AI-assisted-by:` instead. `scripts/check-commit` rejects a trailer value that names an AI provider or agent (`Claude`, `Copilot`, `Cursor`, `Codex`, `Gemini`, `Aider`, `Cline`, `Windsurf`, `DeepSeek`, `OpenCode`, `devin-ai`, `amazon q`, and similar) or carries a bot identity (`[bot]`, `bot@`). `NON_HUMAN_COAUTHOR_PATTERN` is the list; extend it when a new tool starts adding trailers. A person whose own name or email matches one of those tokens (a surname like `Cline`, an address at a provider) is rejected too; amend the trailer or credit them with `Reviewed-by:`.
|
||||
- CI runs `scripts/check-commit` on every new commit (`mem:workflow/creating-commits` is enforced by `.github/workflows/commit-checker.yml`), so a forbidden trailer fails the build.
|
||||
- Exceptions inside the body (do not wrap these): `Signed-off-by:`,
|
||||
`AI-assisted-by:` trailers, and lines carrying a URL.
|
||||
- Exceptions inside the body (do not wrap these): `Signed-off-by:`, `Co-authored-by:`, `AI-assisted-by:` trailers, and lines carrying a URL.
|
||||
|
||||
**AI-assisted-by trailer rules:**
|
||||
- Use only the model name, e.g. `mimo-v2.5`, `deepseek-v4-flash`
|
||||
|
||||
@ -225,8 +225,11 @@ Commit messages must follow this format:
|
||||
those prefixes to an existing subject)
|
||||
- **Wrap body lines at 80 characters or fewer** (trailers and URLs excepted)
|
||||
- Separate the subject from the body with a **blank line**
|
||||
- Never add a `Co-authored-by` trailer — it is forbidden and fails
|
||||
`./scripts/check-commit`
|
||||
- Use `Co-authored-by:` only for a human co-author
|
||||
(`Co-authored-by: Name <email>`). AI providers, agents and bots are not
|
||||
allowed there; for AI participation add an `AI-assisted-by: <model-name>`
|
||||
trailer instead. `./scripts/check-commit` rejects the trailer when its value
|
||||
names one of them.
|
||||
|
||||
You can check a commit against these rules with `./scripts/check-commit`.
|
||||
CI runs the same script on every new commit in
|
||||
|
||||
@ -52,11 +52,26 @@ MAX_SUBJECT_LINE = 80
|
||||
MAX_BODY_LINE = 80
|
||||
|
||||
TRAILER_PATTERN = re.compile(
|
||||
r"^(Signed-off-by|Co-developed-by|Reviewed-by|"
|
||||
r"^(Signed-off-by|Co-authored-by|Co-developed-by|Reviewed-by|"
|
||||
r"Acked-by|Tested-by|Reported-by|Suggested-by|AI-assisted-by):"
|
||||
)
|
||||
|
||||
FORBIDDEN_TRAILER_PATTERN = re.compile(r"^\s*Co-authored-by\s*:", re.IGNORECASE)
|
||||
# ── 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,
|
||||
)
|
||||
|
||||
URL_PATTERN = re.compile(r"https?://\S+")
|
||||
|
||||
@ -218,12 +233,12 @@ def check_signed_off_by(message):
|
||||
return True, None
|
||||
|
||||
|
||||
def check_no_co_authored_by(message):
|
||||
"""Check that the forbidden Co-authored-by trailer is absent."""
|
||||
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 FORBIDDEN_TRAILER_PATTERN.match(line)
|
||||
if NON_HUMAN_COAUTHOR_PATTERN.match(line)
|
||||
]
|
||||
if not offenders:
|
||||
return True, None
|
||||
@ -232,8 +247,10 @@ def check_no_co_authored_by(message):
|
||||
for line_number, line in offenders
|
||||
)
|
||||
return False, (
|
||||
"The 'Co-authored-by:' trailer is forbidden and must not appear "
|
||||
"in the commit message. Offending line(s):\n" + details
|
||||
"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>"
|
||||
)
|
||||
|
||||
|
||||
@ -262,7 +279,7 @@ def main():
|
||||
("Subject capitalized", check_subject_capitalized),
|
||||
("Blank line after subject", check_body_blank_line),
|
||||
("Body wrapped at 80 chars", check_body_line_length),
|
||||
("No Co-authored-by trailer", check_no_co_authored_by),
|
||||
("Co-authored-by is human only", check_co_authored_by),
|
||||
]
|
||||
|
||||
all_ok = True
|
||||
|
||||
@ -6,7 +6,9 @@ Run with:
|
||||
python3 scripts/test_check_commit.py
|
||||
|
||||
Covers the body line-wrapping validator added to enforce the commit body
|
||||
wrap rule documented in .serena/memories/workflow/creating-commits.md.
|
||||
wrap rule documented in .serena/memories/workflow/creating-commits.md, and
|
||||
the Co-authored-by validator, which allows human co-authors and rejects AI
|
||||
providers and bots.
|
||||
"""
|
||||
|
||||
import importlib.machinery
|
||||
@ -87,6 +89,14 @@ class BodyLineLengthTests(unittest.TestCase):
|
||||
line = "Signed-off-by: Someone With A Long Name <someone@example.com>"
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\n" + line + "\n")
|
||||
|
||||
def test_human_co_author_trailer_passes(self):
|
||||
line = (
|
||||
"Co-authored-by: Someone With A Very Long Name "
|
||||
"<someone.with.a.long.address@example.com>"
|
||||
)
|
||||
self.assertGreater(len(line), 80)
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\n" + line + "\n")
|
||||
|
||||
def test_unbreakable_token_passes(self):
|
||||
line = "a" * 100 # no whitespace to wrap at
|
||||
self.assert_ok(":bug: Fix crash\n\n" + line + "\n")
|
||||
@ -106,14 +116,16 @@ class BodyLineLengthTests(unittest.TestCase):
|
||||
self.assertIn("line 4", error)
|
||||
|
||||
|
||||
class ForbiddenTrailerTests(unittest.TestCase):
|
||||
class CoAuthorTrailerTests(unittest.TestCase):
|
||||
"""Co-authored-by is allowed for humans, forbidden for AI providers/bots."""
|
||||
|
||||
def assert_ok(self, message):
|
||||
ok, error = check_commit.check_no_co_authored_by(message)
|
||||
ok, error = check_commit.check_co_authored_by(message)
|
||||
self.assertTrue(ok, error)
|
||||
self.assertIsNone(error)
|
||||
|
||||
def assert_fail(self, message):
|
||||
ok, error = check_commit.check_no_co_authored_by(message)
|
||||
ok, error = check_commit.check_co_authored_by(message)
|
||||
self.assertFalse(ok)
|
||||
self.assertIsNotNone(error)
|
||||
return error
|
||||
@ -121,15 +133,57 @@ class ForbiddenTrailerTests(unittest.TestCase):
|
||||
def test_body_without_trailer_passes(self):
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\nSigned-off-by: Someone <someone@example.com>\n")
|
||||
|
||||
def test_co_authored_by_fails(self):
|
||||
error = self.assert_fail(":bug: Fix crash\n\nBody.\n\nCo-authored-by: Someone <someone@example.com>\n")
|
||||
self.assertIn("Co-authored-by", error)
|
||||
def test_human_co_author_passes(self):
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\nCo-authored-by: Jane Doe <jane@example.com>\n")
|
||||
|
||||
def test_co_authored_by_case_insensitive_fails(self):
|
||||
self.assert_fail(":bug: Fix crash\n\nBody.\n\nco-authored-by: Someone <someone@example.com>\n")
|
||||
def test_human_with_github_noreply_email_passes(self):
|
||||
self.assert_ok(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Jane Doe <1234+jane@users.noreply.github.com>\n"
|
||||
)
|
||||
|
||||
def test_human_whose_email_ends_with_bot_passes(self):
|
||||
# "abbot@" must not count as a "bot@" identity.
|
||||
self.assert_ok(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Jane Abbot <abbot@example.com>\n"
|
||||
)
|
||||
|
||||
def test_claude_fails(self):
|
||||
error = self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Claude <noreply@anthropic.com>\n"
|
||||
)
|
||||
self.assertIn("Co-authored-by", error)
|
||||
self.assertIn("AI-assisted-by", error)
|
||||
|
||||
def test_cursor_fails(self):
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Cursor Agent <cursoragent@cursor.com>\n"
|
||||
)
|
||||
|
||||
def test_copilot_fails(self):
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>\n"
|
||||
)
|
||||
|
||||
def test_case_insensitive_fails(self):
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\nco-authored-by: CHATGPT <x@example.com>\n"
|
||||
)
|
||||
|
||||
def test_bot_identity_fails(self):
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nBody.\n\n"
|
||||
"Co-authored-by: dependabot[bot] <support@github.com>\n"
|
||||
)
|
||||
|
||||
def test_co_authored_by_in_body_fails(self):
|
||||
self.assert_fail(":bug: Fix crash\n\nCo-authored-by: Someone <someone@example.com>\nBody.\n")
|
||||
self.assert_fail(
|
||||
":bug: Fix crash\n\nCo-authored-by: Gemini <gemini@example.com>\nBody.\n"
|
||||
)
|
||||
|
||||
def test_similar_trailer_passes(self):
|
||||
self.assert_ok(":bug: Fix crash\n\nBody.\n\nCo-developed-by: Someone <someone@example.com>\n")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user