Skip to content

Commit f0fb1d1

Browse files
committed
Added extra check when searching for an existing comment in Disqus.
Tries to match the comment templates we have in order to separate the automatically generated comments from the comments made manually by the same user.
1 parent 04a9ffc commit f0fb1d1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

codebender_testing/disqus.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def handle_library_comment(self, library, domain, current_date, log, examples=Tr
127127
for thread in paginator:
128128

129129
# Check if library has already a comment.
130-
post_id, existing_message = self.get_posts(thread['id'])
130+
post_id, existing_message = self.get_posts(thread['id'], 'library')
131131

132132
# If library already has a comment, update it.
133133
if post_id and existing_message:
@@ -173,7 +173,7 @@ def handle_example_comment(self, url, results, current_date, log):
173173
new_message = self.messages['example_unsupported'].replace('TEST_DATE', current_date)
174174

175175
for page in paginator:
176-
post_id, existing_message = self.get_posts(page['id'])
176+
post_id, existing_message = self.get_posts(page['id'], 'example')
177177
if post_id and existing_message:
178178
log[url]['comment'] = self.update_post(post_id, new_message)
179179
comment_updated = True
@@ -187,9 +187,12 @@ def handle_example_comment(self, url, results, current_date, log):
187187

188188
return log
189189

190-
def get_posts(self, thread_id):
190+
def get_posts(self, thread_id, type):
191191
post_id = None
192192
raw_message = None
193+
type_regexp = re.compile(r'^This example was tested.+')
194+
if type == 'library':
195+
type_regexp = re.compile(r'^This library and its examples were tested.+')
193196
try:
194197
""" Returns a Paginator object that matches the desired criteria:
195198
`self.disqus.api.posts.list`: Returns a list of posts ordered by the date created.
@@ -203,7 +206,7 @@ def get_posts(self, thread_id):
203206
order='asc')
204207
if paginator:
205208
for post in paginator:
206-
if post['author']['name'] == self.user['username'] and post['author']['url'] == AUTHOR_URL:
209+
if post['author']['name'] == self.user['username'] and post['author']['url'] == AUTHOR_URL and type_regexp.match(post['raw_message']):
207210
post_id = post['id']
208211
raw_message = post['raw_message']
209212
break

0 commit comments

Comments
 (0)