mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
fix: stop the authorship check from flagging people whose names contain an assistant's name
This commit is contained in:
1 parent
ac0909eaa3
commit
b7bf189166
3 files changed
+51
-11
No files matched your search
@@ -4,7 +4,7 @@ from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from check_authorship import BOT, COAUTHOR, check_revision
|
||||
from check_authorship import COAUTHOR, check_revision, is_bot
|
||||
|
||||
|
||||
def main():
|
||||
@@ -23,13 +23,13 @@ def main():
|
||||
return 1
|
||||
else:
|
||||
identity = subprocess.check_output(["git", "var", "GIT_AUTHOR_IDENT"], text=True)
|
||||
if BOT.search(identity):
|
||||
if is_bot(identity):
|
||||
print("Bot commit author is forbidden: " + identity.strip(), file=sys.stderr)
|
||||
return 1
|
||||
message = Path(args[0])
|
||||
original = message.read_text(encoding="utf-8")
|
||||
cleaned = "".join(line for line in original.splitlines(keepends=True)
|
||||
if not (COAUTHOR.match(line) and BOT.search(line)))
|
||||
if not (COAUTHOR.match(line) and is_bot(line)))
|
||||
if cleaned != original:
|
||||
message.write_text(cleaned, encoding="utf-8")
|
||||
print("Removed bot co-author trailers; human credits preserved.", file=sys.stderr)
|
||||
|
||||
@@ -6,15 +6,34 @@ import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
BOT = re.compile(
|
||||
r"Claude|Anthropic|OpenAI|ChatGPT|GPT|Copilot|Cursor|Gemini|Codex|Devin|"
|
||||
r"Windsurf|Codeium|Amazon Q|Tabnine|Cody|\[bot\]|github-actions|"
|
||||
r"dependabot|renovate(?:\[bot\])?",
|
||||
PRODUCT = re.compile(
|
||||
r"(?<![a-z0-9])(?:Anthropic|OpenAI|ChatGPT|GPT(?:-?\d[\w.]*)?|Copilot|Codex|Codeium|Windsurf|"
|
||||
r"Amazon Q|Tabnine|github-actions|dependabot|renovate)(?![a-z0-9])|\[bot\]",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
# These are also people's names, so they only count alone or followed by a product word.
|
||||
ASSISTANT = r"(?:Claude|Cursor|Devin|Cody|Gemini)"
|
||||
ASSISTANT_ALONE = re.compile(ASSISTANT, re.IGNORECASE)
|
||||
ASSISTANT_PRODUCT = re.compile(
|
||||
ASSISTANT + r"[\s_-]+(?:Code|Opus|Sonnet|Haiku|Fable|Instant|AI|Agent|Bot|Assistant|CLI|Pro|Flash|Ultra|\d)(?![a-z])",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
BOT_DOMAIN = re.compile(
|
||||
r"@(?:[\w-]+\.)*(?:anthropic\.com|openai\.com|cursor\.(?:com|sh)|cognition\.ai|sourcegraph\.com|"
|
||||
r"codeium\.com|tabnine\.com)$",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
COAUTHOR = re.compile(r"^\s*Co-authored-by\s*:", re.IGNORECASE)
|
||||
|
||||
|
||||
def is_bot(identity):
|
||||
name, _, rest = identity.partition("<")
|
||||
email = rest.partition(">")[0].strip()
|
||||
name = COAUTHOR.sub("", name).strip()
|
||||
return bool(PRODUCT.search(name) or PRODUCT.search(email) or BOT_DOMAIN.search(email)
|
||||
or ASSISTANT_ALONE.fullmatch(name) or ASSISTANT_PRODUCT.search(name))
|
||||
|
||||
|
||||
def commit_violations(commit, raw):
|
||||
header, separator, message = raw.partition(b"\n\n")
|
||||
if not separator:
|
||||
@@ -24,10 +43,10 @@ def commit_violations(commit, raw):
|
||||
return [f"{commit}: expected one author"]
|
||||
identity = authors[0].decode("utf-8", errors="replace")
|
||||
errors = []
|
||||
if BOT.search(identity):
|
||||
if is_bot(identity):
|
||||
errors.append(f"{commit}: bot author: {identity}")
|
||||
for line in message.decode("utf-8", errors="replace").splitlines():
|
||||
if COAUTHOR.match(line) and BOT.search(line):
|
||||
if COAUTHOR.match(line) and is_bot(line):
|
||||
errors.append(f"{commit}: bot co-author: {line.strip()}")
|
||||
return errors
|
||||
|
||||
@@ -36,11 +55,11 @@ def event_violations(event):
|
||||
pr = event.get("pull_request", {})
|
||||
user = pr.get("user", {})
|
||||
errors = []
|
||||
if user.get("type") == "Bot" or BOT.search(user.get("login", "")):
|
||||
if user.get("type") == "Bot" or is_bot(user.get("login", "")):
|
||||
errors.append("pull request: bot authorship is forbidden")
|
||||
for field in ("title", "body"):
|
||||
for line in (pr.get(field) or "").splitlines():
|
||||
if COAUTHOR.match(line) and BOT.search(line):
|
||||
if COAUTHOR.match(line) and is_bot(line):
|
||||
errors.append(f"pull request {field}: bot co-author trailer")
|
||||
return errors
|
||||
|
||||
|
||||
@@ -40,6 +40,27 @@ class AuthorshipTest(unittest.TestCase):
|
||||
def test_bot_pr_author_is_rejected(self):
|
||||
self.assertTrue(check.event_violations({"pull_request": {"user": {"login": "service", "type": "Bot"}}}))
|
||||
|
||||
def test_people_named_like_assistants_are_not_bots(self):
|
||||
for author in ("Claudemirovsky <63046606+Claudemirovsky@users.noreply.github.com>",
|
||||
"Claude Monet <claude@example.com>", "Devin Smith <devin@example.com>",
|
||||
"Cody Allen <cody@example.com>", "Gemini Patel <gp@example.com>"):
|
||||
with self.subTest(author=author):
|
||||
self.assertEqual([], check.commit_violations("abc", self.commit(author=author)))
|
||||
self.assertEqual([], check.event_violations({"pull_request": {"user": {"login": "Claudemirovsky", "type": "User"}}}))
|
||||
|
||||
def test_assistant_identities_are_still_bots(self):
|
||||
for author in ("Claude Opus 5.5 <noreply@anthropic.com>", "Claude Code <cc@example.com>",
|
||||
"Cursor Agent <cursoragent@cursor.com>",
|
||||
"Devin AI <devin-ai-integration[bot]@users.noreply.github.com>",
|
||||
"Gemini <gemini@example.com>", "GPT-5 <a@example.com>"):
|
||||
with self.subTest(author=author):
|
||||
self.assertTrue(check.commit_violations("abc", self.commit(author=author)))
|
||||
for login in ("chatgpt-codex-connector", "Copilot", "claude"):
|
||||
with self.subTest(login=login):
|
||||
self.assertTrue(check.event_violations({"pull_request": {"user": {"login": login, "type": "User"}}}))
|
||||
message = "Fix\n\nCo-authored-by: Claude Opus 5.5 <noreply@anthropic.com>\n"
|
||||
self.assertEqual(1, len(check.commit_violations("abc", self.commit(message=message))))
|
||||
|
||||
def test_missing_author_fails_closed(self):
|
||||
self.assertTrue(check.commit_violations("abc", b"tree 000\n\nmessage\n"))
|
||||
|
||||
|
||||
Reference in new issue
Block a user