Skip to content

Commit fb7e66d

Browse files
authored
Add ability to ignore certain users comments (#1039)
* Add ability to ignore certain users comments Some build/CI systems can become too noisy, you still want to pull real people's comments and ignore bot accounts when adding annotations. Signed-off-by: Jorge Gallegos <[email protected]> * Modify test case for ignoring user comments * Modifying gerrit test case for ignoring user comments * Update GH docs to include new config option * Update gerrit docs * Remove useless comment --------- Signed-off-by: Jorge Gallegos <[email protected]>
1 parent dfe4443 commit fb7e66d

File tree

6 files changed

+47
-9
lines changed

6 files changed

+47
-9
lines changed

bugwarrior/docs/services/gerrit.rst

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ For example:
4545

4646
gerrit.query = is:open+((reviewer:self+-owner:self+-is:ignored)+OR+assignee:self)
4747

48+
49+
Synchronizing Issue Content
50+
+++++++++++++++++++++++++++
51+
52+
This service synchronizes fields to UDAs, as described below.
53+
Comments are synchronized as annotations.
54+
55+
To limit the amount of content synchronized into TaskWarrior (which can help to avoid issues with synchronization), use
56+
57+
* ``annotation_comments=False`` (a global configuration) to disable synchronizing comments to annotations; and
58+
* ``ignore_user_comments=<comma separated list>`` in the ``[gerrit]`` section to filter out (e.g. automated) comments turning into annotations if ``annotation_comments`` is on
59+
60+
4861
Provided UDA Fields
4962
-------------------
5063

bugwarrior/docs/services/github.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ Comments are synchronized as annotations.
199199
To limit the amount of content synchronized into TaskWarrior (which can help to avoid issues with synchronization), use
200200

201201
* ``annotation_comments=False`` (a global configuration) to disable synchronizing comments to annotations; and
202-
* either ``body_length``` to limit the size of the Github Body UDA or include ``githubbody`` in ``static_fields`` in the ``[general]`` section to eliminate the UDA entirely.
202+
* either ``body_length`` to limit the size of the Github Body UDA or include ``githubbody`` in ``static_fields`` in the ``[general]`` section to eliminate the UDA entirely.
203+
* ``ignore_user_comments=<comma separated list>`` in the ``[github]`` section to filter out (e.g. automated) comments turning into annotations if ``annotation_comments`` is on
203204

204205
Including Project Owner in Project Name
205206
+++++++++++++++++++++++++++++++++++++++

bugwarrior/services/gerrit.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from bugwarrior import config
77
from bugwarrior.services import Service, Issue, Client
88

9+
import logging
10+
log = logging.getLogger(__name__)
11+
912

1013
class GerritConfig(config.ServiceConfig):
1114
service: typing.Literal['gerrit']
@@ -15,6 +18,7 @@ class GerritConfig(config.ServiceConfig):
1518

1619
ssl_ca_path: typing.Optional[config.ExpandedPath] = None
1720
query: str = 'is:open+is:reviewer'
21+
ignore_user_comments: config.ConfigList = config.ConfigList([])
1822

1923

2024
class GerritIssue(Issue):
@@ -144,7 +148,9 @@ def annotations(self, change):
144148
break
145149
else:
146150
username = item['author']['_account_id']
147-
# Gerrit messages are really messy
151+
if username in self.config.ignore_user_comments:
152+
log.debug(" ignoring comment from %s", username)
153+
continue
148154
message = item['message']\
149155
.lstrip('Patch Set ')\
150156
.lstrip("%s:" % item['_revision_number'])\

bugwarrior/services/github.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class GithubConfig(config.ServiceConfig):
4040
body_length: int = sys.maxsize
4141
project_owner_prefix: bool = False
4242
issue_urls: config.ConfigList = config.ConfigList([])
43+
ignore_user_comments: config.ConfigList = config.ConfigList([])
4344

4445
@pydantic.v1.root_validator
4546
def deprecate_password(cls, values):
@@ -389,11 +390,20 @@ def annotations(self, tag, issue):
389390
if self.main_config.annotation_comments:
390391
comments = self._comments(tag, issue['number'])
391392
log.debug(" got comments for %s", issue['html_url'])
392-
annotations = ((
393-
c['user']['login'],
394-
c['body'],
395-
) for c in comments)
396-
return self.build_annotations(annotations, url)
393+
annotations = []
394+
for c in comments:
395+
login = c['user']['login']
396+
if login in self.config.ignore_user_comments:
397+
log.debug(" ignoring comment from %s", login)
398+
continue
399+
annotations.append((
400+
login,
401+
c['body'],
402+
))
403+
return self.build_annotations(
404+
annotations,
405+
url
406+
)
397407

398408
def body(self, issue):
399409
body = issue['body']

tests/test_gerrit.py

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TestGerritIssue(AbstractServiceTest, ServiceTest):
1414
'base_uri': 'https://one.com',
1515
'username': 'two',
1616
'password': 'three',
17+
'ignore_user_comments': ['CI Bot'],
1718
}
1819

1920
record = {
@@ -26,6 +27,9 @@ class TestGerritIssue(AbstractServiceTest, ServiceTest):
2627
'subject': 'this is a title',
2728
'messages': [{'author': {'username': 'Iam Author'},
2829
'message': 'this is a message',
30+
'_revision_number': 1},
31+
{'author': {'username': 'CI Bot'},
32+
'message': 'ignore me please',
2933
'_revision_number': 1}],
3034
}
3135

tests/test_github.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
'body': 'Something',
4343
'namespace': 'arbitrary_username',
4444
}
45+
IGNORABLE = {
46+
'user': {'login': 'cibot'},
47+
'body': 'Ignore this comment.'
48+
}
4549

4650

4751
class TestGithubIssue(AbstractServiceTest, ServiceTest):
@@ -51,6 +55,7 @@ class TestGithubIssue(AbstractServiceTest, ServiceTest):
5155
'login': 'arbitrary_login',
5256
'token': 'arbitrary_token',
5357
'username': 'arbitrary_username',
58+
'ignore_user_comments': [IGNORABLE['user']['login']],
5459
}
5560

5661
def test_draft(self):
@@ -151,7 +156,7 @@ def test_issues(self):
151156
json=[{
152157
'user': {'login': 'arbitrary_login'},
153158
'body': 'Arbitrary comment.'
154-
}])
159+
}, IGNORABLE]) # second comment should be ignored and still pass
155160

156161
service = self.get_mock_service(GithubService)
157162
issue = next(service.issues())
@@ -248,7 +253,6 @@ class TestGithubService(ServiceTest):
248253
'login': 'tintin',
249254
'username': 'milou',
250255
'token': 't0ps3cr3t',
251-
252256
}
253257

254258
def test_token_authorization_header(self):

0 commit comments

Comments
 (0)