Skip to content

Commit 72c1846

Browse files
authored
[IMPROVEMENT] Delete and repost bot comment, remove GITHUB_BOT from config (#855)
* Delete old bot comments and repost Signed-off-by: Tarun Arora <tarun.arora.030402@gmail.com> * Remove role of GITHUB_BOT in config Signed-off-by: Tarun Arora <tarun.arora.030402@gmail.com> --------- Signed-off-by: Tarun Arora <tarun.arora.030402@gmail.com>
1 parent 694d34d commit 72c1846

File tree

5 files changed

+13
-28
lines changed

5 files changed

+13
-28
lines changed

config_sample.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
APPLICATION_ROOT = None
66
CSRF_ENABLED = True
77
DATABASE_URI = 'mysql+pymysql://root:@localhost:3306/test?charset=utf8'
8-
GITHUB_BOT = ''
98
GITHUB_TOKEN = ''
109
GITHUB_OWNER = 'CCExtractor'
1110
GITHUB_REPOSITORY = 'ccextractor'

mod_ci/controllers.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,18 +1612,13 @@ def comment_pr(test_id, state, pr_nr, platform) -> None:
16121612
# Pull requests are just issues with code, so GitHub considers PR comments in issues
16131613
pull_request = repository.get_pull(number=pr_nr)
16141614
comments = pull_request.get_issue_comments()
1615-
bot_name = g.github['bot_name']
1616-
comment_id = None
1615+
bot_name = gh.get_user().login
16171616
for comment in comments:
16181617
if comment.user.login == bot_name and platform in comment.body:
1619-
comment_id = comment.id
1620-
comment.edit(body=message)
1621-
break
1622-
log.debug(f"GitHub PR Comment ID Fetched for Test_id: {test_id}")
1623-
if comment_id is None:
1624-
comment = pull_request.create_issue_comment(body=message)
1625-
comment_id = comment.id
1626-
log.debug(f"GitHub PR Comment ID {comment_id} Uploaded for Test_id: {test_id}")
1618+
comment.delete()
1619+
log.debug(f"GitHub PR old comment deleted for test_id: {test_id}")
1620+
comment = pull_request.create_issue_comment(body=message)
1621+
log.debug(f"GitHub PR Comment ID {comment.id} Uploaded for Test_id: {test_id}")
16271622
except Exception as e:
16281623
log.error(f"GitHub PR Comment Failed for Test_id: {test_id} with Exception {e}")
16291624

run.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ def get_github_config(config: Dict[str, str]) -> Dict[str, str]:
249249
return {
250250
'ci_key': config.get('GITHUB_CI_KEY', ''),
251251
'bot_token': config.get('GITHUB_TOKEN', ''),
252-
'bot_name': config.get('GITHUB_BOT', ''),
253252
'repository_owner': config.get('GITHUB_OWNER', ''),
254253
'repository': config.get('GITHUB_REPOSITORY', '')
255254
}

tests/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def load_config(file):
106106
'SQLALCHEMY_POOL_SIZE': 1,
107107
'GITHUB_CI_KEY': "test_ci",
108108
'GITHUB_TOKEN': "",
109-
'GITHUB_BOT': "",
110109
'GITHUB_OWNER': "test_owner",
111110
'GITHUB_REPOSITORY': "test_repo",
112111
'HMAC_KEY': "test_key",

tests/test_ci/test_controllers.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,16 @@ def test_comments_successfully_in_passed_pr_test(self, mock_github):
337337
repository = mock_github(g.github['bot_token']).get_repo(
338338
f"{g.github['repository_owner']}/{g.github['repository']}")
339339
pull_request = repository.get_pull(number=1)
340+
mock_github(g.github['bot_token']).get_user().login = 'test-bot'
340341

341342
comment1 = MagicMock(IssueComment)
342343
comment1.user.login = 'invalid'
343344

344345
comment2 = MagicMock(IssueComment)
345-
comment2.user.login = ''
346+
comment2.user.login = 'test-bot'
346347
comment2.body = 'linux test passed'
347348

348-
# When previous comment is found, and is to be edited
349+
# Delete old bot comments and create a new comment
349350
pull_request.get_issue_comments.return_value = [comment1, comment2]
350351
comment_pr(1, Status.SUCCESS, 1, 'linux')
351352
mock_github.assert_called_with(g.github['bot_token'])
@@ -354,31 +355,23 @@ def test_comments_successfully_in_passed_pr_test(self, mock_github):
354355

355356
repository.get_pull.assert_called_with(number=1)
356357
pull_request.get_issue_comments.assert_called_once()
357-
args, kwargs = comment2.edit.call_args
358-
message = kwargs['body']
359-
if "passed" not in message:
360-
assert False, "Message not Correct"
358+
comment1.delete.assert_not_called()
359+
comment2.delete.assert_called_once()
361360

362-
# When commit is not found, and is to be created
363-
pull_request.reset_mock()
364-
pull_request.get_issue_comments.return_value = [comment1]
365-
comment_pr(1, Status.SUCCESS, 1, 'linux')
366-
repository.get_pull.assert_called_with(number=1)
367-
pull_request.get_issue_comments.assert_called_once()
368361
args, kwargs = pull_request.create_issue_comment.call_args
369362
message = kwargs['body']
370363
if "passed" not in message:
371364
assert False, "Message not Correct"
372365

373-
@mock.patch('github.Github.get_repo')
374-
def test_comments_successfuly_in_failed_pr_test(self, mock_repo):
366+
@mock.patch('github.Github')
367+
def test_comments_successfuly_in_failed_pr_test(self, mock_github):
375368
"""Check comments in failed PR test."""
376369
import mod_ci.controllers
377370
reload(mod_ci.controllers)
378371
from github.IssueComment import IssueComment
379372

380373
from mod_ci.controllers import Status, comment_pr
381-
pull_request = mock_repo.return_value.get_pull(number=1)
374+
pull_request = mock_github.return_value.get_repo.return_value.get_pull(number=1)
382375
message = ("<b>CCExtractor CI platform</b> finished running the "
383376
"test files on <b>linux</b>. Below is a summary of the test results")
384377
pull_request.get_issue_comments.return_value = [MagicMock(IssueComment)]

0 commit comments

Comments
 (0)