Exclude bot commit users from PR credit (#747)

This commit is contained in:
Glenn Jocher
2026-04-24 00:57:19 +02:00
committed by GitHub
parent f03397fa21
commit 0c76581dfa
2 changed files with 43 additions and 2 deletions
+9 -2
View File
@@ -37,7 +37,14 @@ query($owner: String!, $repo: String!, $pr_number: Int!) {
author { login, __typename }
reviews(first: 50) { nodes { author { login, __typename } } }
comments(first: 50) { nodes { author { login, __typename } } }
commits(first: 100) { nodes { commit { author { user { login } }, committer { user { login } } } } }
commits(first: 100) {
nodes {
commit {
author { user { login, __typename } }
committer { user { login, __typename } }
}
}
}
}
}
}
@@ -417,7 +424,7 @@ Thank you 🙏
commit_data = commit["commit"]
for user_type in ["author", "committer"]:
if user := commit_data[user_type].get("user"):
if login := user.get("login"):
if user["__typename"] != "Bot" and (login := user.get("login")):
contributors.add(login)
contributors.discard(author)
+34
View File
@@ -53,6 +53,40 @@ def test_action_request_methods():
mock_get.assert_called_once()
def test_get_pr_contributors_excludes_bots():
"""Test PR contributor credit excludes bot commit users."""
action = Action(
token="test-token",
event_data={"repository": {"full_name": "test/repo"}, "pull_request": {"number": 123}},
)
data = {
"author": {"login": "pr-author", "__typename": "User"},
"reviews": {"nodes": []},
"comments": {"nodes": []},
"commits": {
"nodes": [
{
"commit": {
"author": {"user": {"login": "github-actions[bot]", "__typename": "Bot"}},
"committer": {"user": {"login": "teammate", "__typename": "User"}},
}
},
]
},
}
pr_response = MagicMock(
status_code=200,
json=lambda: {"data": {"repository": {"pullRequest": data}}},
)
with patch.object(action, "post", return_value=pr_response), patch.object(
action, "get_username", return_value="actions-user"
):
pr_credit, _ = action.get_pr_contributors()
assert pr_credit == "@pr-author with contributions from @teammate"
def test_load_event_data():
"""Test loading event data from file."""
with patch("pathlib.Path.exists", return_value=True):