From 18181743a5a2600fa197b7c7f6cb7876b579e622 Mon Sep 17 00:00:00 2001 From: Dongge Liu Date: Wed, 13 Sep 2023 12:52:09 +1000 Subject: [PATCH 1/5] Fix #1897 --- service/gcbrun_experiment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/gcbrun_experiment.py b/service/gcbrun_experiment.py index e9b9c5371..4e663c3da 100644 --- a/service/gcbrun_experiment.py +++ b/service/gcbrun_experiment.py @@ -54,7 +54,7 @@ def get_latest_gcbrun_command(comments): if body.startswith(SKIP_COMMAND_STR): return None if not body.startswith(RUN_EXPERIMENT_COMMAND_STR): - continue + return None if len(body) == len(RUN_EXPERIMENT_COMMAND_STR): return None command = body[len(RUN_EXPERIMENT_COMMAND_STR):].strip().split(' ') From badeeb40896c805f8875d2719345904193c7586e Mon Sep 17 00:00:00 2001 From: Dongge Liu Date: Wed, 13 Sep 2023 12:52:26 +1000 Subject: [PATCH 2/5] Format --- service/gcbrun_experiment.py | 1 - 1 file changed, 1 deletion(-) diff --git a/service/gcbrun_experiment.py b/service/gcbrun_experiment.py index 4e663c3da..9ce1d2da5 100644 --- a/service/gcbrun_experiment.py +++ b/service/gcbrun_experiment.py @@ -23,7 +23,6 @@ # pytype: disable=import-error import github # pylint: disable=import-error - from experiment import run_experiment TRIGGER_COMMAND = '/gcbrun' From 13509dfd81adb7a1bce925341b0fb095ecf5fdd6 Mon Sep 17 00:00:00 2001 From: Dongge Liu Date: Wed, 13 Sep 2023 14:15:55 +1000 Subject: [PATCH 3/5] Simplify the logic --- service/gcbrun_experiment.py | 37 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/service/gcbrun_experiment.py b/service/gcbrun_experiment.py index 9ce1d2da5..a5b9f19f5 100644 --- a/service/gcbrun_experiment.py +++ b/service/gcbrun_experiment.py @@ -42,33 +42,32 @@ def get_comments(pull_request_number): # Github only returns comments if from the pull object when a pull request # is open. If it is a draft, it will only return comments from the issue # object. - return pull_comments + issue_comments + return pull_comments[-1], issue_comments[-1] -def get_latest_gcbrun_command(comments): +def get_latest_gcbrun_command(comment): """Gets the last /gcbrun comment from comments.""" - for comment in reversed(comments): - # This seems to get comments on code too. - body = comment.body - if body.startswith(SKIP_COMMAND_STR): - return None - if not body.startswith(RUN_EXPERIMENT_COMMAND_STR): - return None - if len(body) == len(RUN_EXPERIMENT_COMMAND_STR): - return None - command = body[len(RUN_EXPERIMENT_COMMAND_STR):].strip().split(' ') - # Items that only contain space are redundant and will confuse - # `run_experiment_main()` in `experiment/run_experiment.py` - return [word for word in command if word.strip()] - return None + # This seems to get comments on code too. + body = comment.body + if body.startswith(SKIP_COMMAND_STR): + return None + if not body.startswith(RUN_EXPERIMENT_COMMAND_STR): + return None + if len(body) == len(RUN_EXPERIMENT_COMMAND_STR): + return None + command = body[len(RUN_EXPERIMENT_COMMAND_STR):].strip().split(' ') + # Items that only contain space are redundant and will confuse + # `run_experiment_main()` in `experiment/run_experiment.py` + return [word for word in command if word.strip()] def exec_command_from_github(pull_request_number): """Executes the gcbrun command for run_experiment.py in the most recent command on |pull_request_number|.""" - comments = get_comments(pull_request_number) - print(comments) - command = get_latest_gcbrun_command(comments) + pull_cmt, issue_cmt = get_comments(pull_request_number) + print(f'Pull comment: {pull_cmt}\nIssue comment: {issue_cmt}') + command = (get_latest_gcbrun_command(pull_cmt) or + get_latest_gcbrun_command(issue_cmt)) if command is None: logging.info('Experiment not requested.') return None From b28e60280dbcea68820b2844248631e948155126 Mon Sep 17 00:00:00 2001 From: Dongge Liu Date: Wed, 13 Sep 2023 14:32:16 +1000 Subject: [PATCH 4/5] Fix non-exist comments --- service/gcbrun_experiment.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/service/gcbrun_experiment.py b/service/gcbrun_experiment.py index a5b9f19f5..b52281fff 100644 --- a/service/gcbrun_experiment.py +++ b/service/gcbrun_experiment.py @@ -37,12 +37,14 @@ def get_comments(pull_request_number): repo = github_obj.get_repo('google/fuzzbench') pull = repo.get_pull(pull_request_number) pull_comments = list(pull.get_comments()) + last_pull_comment = pull_comments[-1] if pull_comments else '' issue = repo.get_issue(pull_request_number) issue_comments = list(issue.get_comments()) + last_issue_comment = issue_comments[-1] if issue_comments else '' # Github only returns comments if from the pull object when a pull request # is open. If it is a draft, it will only return comments from the issue # object. - return pull_comments[-1], issue_comments[-1] + return last_pull_comment, last_issue_comment def get_latest_gcbrun_command(comment): From 663af20db7431184eae586e7fd557b15e4aea29a Mon Sep 17 00:00:00 2001 From: Dongge Liu Date: Wed, 13 Sep 2023 14:42:23 +1000 Subject: [PATCH 5/5] Fix type --- service/gcbrun_experiment.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/service/gcbrun_experiment.py b/service/gcbrun_experiment.py index b52281fff..bbebcf1b9 100644 --- a/service/gcbrun_experiment.py +++ b/service/gcbrun_experiment.py @@ -37,10 +37,10 @@ def get_comments(pull_request_number): repo = github_obj.get_repo('google/fuzzbench') pull = repo.get_pull(pull_request_number) pull_comments = list(pull.get_comments()) - last_pull_comment = pull_comments[-1] if pull_comments else '' + last_pull_comment = pull_comments[-1] if pull_comments else None issue = repo.get_issue(pull_request_number) issue_comments = list(issue.get_comments()) - last_issue_comment = issue_comments[-1] if issue_comments else '' + last_issue_comment = issue_comments[-1] if issue_comments else None # Github only returns comments if from the pull object when a pull request # is open. If it is a draft, it will only return comments from the issue # object. @@ -50,6 +50,8 @@ def get_comments(pull_request_number): def get_latest_gcbrun_command(comment): """Gets the last /gcbrun comment from comments.""" # This seems to get comments on code too. + if comment is None: + return None body = comment.body if body.startswith(SKIP_COMMAND_STR): return None