Skip to content

Commit 7fcab87

Browse files
fix: Exclude dependabot from thanks message (#102)
1 parent 7d4d534 commit 7fcab87

2 files changed

Lines changed: 44 additions & 10 deletions

File tree

cz_version_bump/thanks.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import typing as t
88
from warnings import warn
99

10-
from github import Auth, Consts, Github
10+
from github import Auth, Consts, Github, NamedUser
1111

1212
if t.TYPE_CHECKING:
1313
from collections.abc import Iterable
@@ -53,12 +53,16 @@ def thanks_message(self, commit: git.GitCommit) -> str:
5353

5454
def third_party_contributors(self: Thanker, commit: git.GitCommit) -> Iterable[str]:
5555
for contributor in self.contributors(commit):
56-
if contributor not in self.org_members:
57-
yield contributor
56+
# Exclude org members and dependabot from the thanks message
57+
if contributor.login not in self.org_members and contributor.type != "Bot":
58+
yield contributor.login
5859

59-
def contributors(self: Thanker, commit: git.GitCommit) -> Iterable[str]:
60+
def contributors(
61+
self: Thanker,
62+
commit: git.GitCommit,
63+
) -> Iterable[NamedUser.NamedUser]:
6064
github_commit = self.repo.get_commit(commit.rev)
61-
yield github_commit.author.login
65+
yield github_commit.author
6266
# FIXME: Cannot thank co-authors automatically until `email_to_github_username`
6367
# is implemented.
6468
# yield from self.co_authors(github_commit.commit.message) # noqa: ERA001

tests/test_thanks.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import dataclasses
34
import typing as t
45

56
import pytest
@@ -16,7 +17,35 @@ def _env(monkeypatch: pytest.MonkeyPatch) -> None:
1617
monkeypatch.setenv("INPUT_GITHUB_TOKEN", "my_gh_token")
1718

1819

19-
def test_thanker(httpserver: HTTPServer) -> None:
20+
@dataclasses.dataclass
21+
class DummyAuthor:
22+
id: int
23+
login: str
24+
path: str
25+
type: str
26+
27+
28+
@pytest.mark.parametrize(
29+
"author,expected",
30+
[
31+
pytest.param(
32+
DummyAuthor(101, "jappleseed", "users/j.appleseed", "User"),
33+
" -- _**Thanks @jappleseed!**_",
34+
id="third_party_contributor",
35+
),
36+
pytest.param(
37+
DummyAuthor(1, "user1", "users/user1", "User"),
38+
"",
39+
id="org_member",
40+
),
41+
pytest.param(
42+
DummyAuthor(2, "dependabot[bot]", "users/dependabot[bot]", "Bot"),
43+
"",
44+
id="bot",
45+
),
46+
],
47+
)
48+
def test_thanker(httpserver: HTTPServer, author: DummyAuthor, expected: str) -> None:
2049
org = "my_gh_org"
2150
repo = "my_gh_repo"
2251
base_url = httpserver.url_for("/")
@@ -73,12 +102,13 @@ def test_thanker(httpserver: HTTPServer) -> None:
73102
},
74103
},
75104
"author": {
76-
"id": 101,
77-
"login": "jappleseed",
78-
"url": f"{base_url}users/j.appleseed",
105+
"id": author.id,
106+
"login": author.login,
107+
"url": f"{base_url}{author.path}",
108+
"type": author.type,
79109
},
80110
},
81111
)
82112

83113
thanker = Thanker(f"{org}/{repo}", base_url=base_url)
84-
assert thanker.thanks_message(commit) == " -- _**Thanks @jappleseed!**_"
114+
assert thanker.thanks_message(commit) == expected

0 commit comments

Comments
 (0)