From 91019bda9c7ad32cbb47fe5d44111b32cb3fe852 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber Date: Mon, 2 Nov 2020 00:03:16 +0100 Subject: [PATCH 1/6] Add option to disable PR comments --- publish_unit_test_results.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/publish_unit_test_results.py b/publish_unit_test_results.py index 4ed3166b..b0edb77c 100644 --- a/publish_unit_test_results.py +++ b/publish_unit_test_results.py @@ -513,7 +513,7 @@ def get_annotations(case_results: Dict[str, Dict[str, List[Dict[Any, Any]]]], re def publish(token: str, event: dict, repo_name: str, commit_sha: str, stats: Dict[Any, Any], cases: Dict[str, Dict[str, List[Dict[Any, Any]]]], check_name: str, comment_title: str, hide_comment_mode: str, - report_individual_runs: bool): + comment_on_pr: bool, report_individual_runs: bool): from github import Github, PullRequest, Requester, MainClass from githubext import Repository, Commit, IssueComment @@ -755,15 +755,16 @@ def hide_all_but_latest_comments(pull: PullRequest) -> None: logger.info('publishing results for commit {}'.format(commit_sha)) publish_check(stats, cases) - pull = get_pull(commit_sha) - if pull is not None: - publish_comment(comment_title, stats, pull) - if hide_comment_mode == hide_comments_mode_orphaned: - hide_orphaned_commit_comments(pull) - elif hide_comment_mode == hide_comments_mode_all_but_latest: - hide_all_but_latest_comments(pull) - else: - logger.info('there is no pull request for commit {}'.format(commit_sha)) + if comment_on_pr: + pull = get_pull(commit_sha) + if pull is not None: + publish_comment(comment_title, stats, pull) + if hide_comment_mode == hide_comments_mode_orphaned: + hide_orphaned_commit_comments(pull) + elif hide_comment_mode == hide_comments_mode_all_but_latest: + hide_all_but_latest_comments(pull) + else: + logger.info('there is no pull request for commit {}'.format(commit_sha)) def write_stats_file(stats, filename) -> None: @@ -774,7 +775,8 @@ def write_stats_file(stats, filename) -> None: def main(token: str, event: dict, repo: str, commit: str, files_glob: str, check_name: str, comment_title: str, hide_comment_mode: str, - report_individual_runs: bool, dedup_classes_by_file_name: bool) -> None: + comment_on_pr: bool, report_individual_runs: bool, + dedup_classes_by_file_name: bool) -> None: files = [str(file) for file in pathlib.Path().glob(files_glob)] logger.info('reading {}: {}'.format(files_glob, list(files))) @@ -789,7 +791,8 @@ def main(token: str, event: dict, repo: str, commit: str, files_glob: str, stats = get_stats(results) # publish the delta stats - publish(token, event, repo, commit, stats, results['case_results'], check_name, comment_title, hide_comment_mode, report_individual_runs) + publish(token, event, repo, commit, stats, results['case_results'], check_name, comment_title, hide_comment_mode, + comment_on_pr, report_individual_runs) def get_commit_sha(event: dict, event_name: str): @@ -832,6 +835,7 @@ def check_var(var: str, name: str, label: str, allowed_values: Optional[List[str report_individual_runs = get_var('REPORT_INDIVIDUAL_RUNS') == 'true' dedup_classes_by_file_name = get_var('DEDUPLICATE_CLASSES_BY_FILE_NAME') == 'true' hide_comment_mode = get_var('HIDE_COMMENTS') or 'all but latest' + comment_on_pr = get_var('COMMENT_ON_PR') == 'false' commit = get_var('COMMIT') or get_commit_sha(event, event_name) files = get_var('FILES') @@ -841,4 +845,5 @@ def check_var(var: str, name: str, label: str, allowed_values: Optional[List[str check_var(commit, 'COMMIT or event file', 'Commit SHA') check_var(files, 'FILES', 'Files pattern') - main(token, event, repo, commit, files, check_name, comment_title, hide_comment_mode, report_individual_runs, dedup_classes_by_file_name) + main(token, event, repo, commit, files, check_name, comment_title, hide_comment_mode, comment_on_pr, + report_individual_runs, dedup_classes_by_file_name) From def4afadc79790e2b13f2bf96f4e54b166ab4151 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber Date: Mon, 2 Nov 2020 00:11:38 +0100 Subject: [PATCH 2/6] Add option comment_on_pr to readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 96cd4740..a0829035 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ and configure it as follows: check_name: Unit Test Results comment_title: Unit Test Statistics hide_comments: all but latest + comment_on_pr: true files: test-results/**/*.xml report_individual_runs: true deduplicate_classes_by_file_name: false @@ -77,6 +78,9 @@ Setting the option to `orphaned commits` will hide comments for orphaned commits These are commits that do no longer belong to the pull request (due to commit history rewrite). Hiding comments can be disabled all together with value `off`. +To disable comments on pull requests completely, set the option `comment_on_pr` to `false`. +Pull request comments are enabled by default. + Files can be selected via the `files` variable, which is optional and defaults to the current working directory. It supports wildcards like `*`, `**`, `?` and `[]`. The `**` wildcard matches [directories recursively](https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob): `./`, `./*/`, `./*/*/`, etc. From 45a6329c48f69da76be2f0346c7f0ae7501eae11 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber Date: Mon, 2 Nov 2020 00:46:22 +0100 Subject: [PATCH 3/6] Make option comment_on_pr true by default --- publish_unit_test_results.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/publish_unit_test_results.py b/publish_unit_test_results.py index b0edb77c..95cfb03f 100644 --- a/publish_unit_test_results.py +++ b/publish_unit_test_results.py @@ -835,7 +835,8 @@ def check_var(var: str, name: str, label: str, allowed_values: Optional[List[str report_individual_runs = get_var('REPORT_INDIVIDUAL_RUNS') == 'true' dedup_classes_by_file_name = get_var('DEDUPLICATE_CLASSES_BY_FILE_NAME') == 'true' hide_comment_mode = get_var('HIDE_COMMENTS') or 'all but latest' - comment_on_pr = get_var('COMMENT_ON_PR') == 'false' + # Comment on PRs if COMMENT_ON_PR is not set to 'false' + comment_on_pr = get_var('COMMENT_ON_PR') != 'false' commit = get_var('COMMIT') or get_commit_sha(event, event_name) files = get_var('FILES') From 61347e2091ea1e4ee445849801a3efbb1e68cbac Mon Sep 17 00:00:00 2001 From: Erik Faulhaber Date: Mon, 2 Nov 2020 01:06:50 +0100 Subject: [PATCH 4/6] Add logging info if comment_on_pr is disabled --- publish_unit_test_results.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/publish_unit_test_results.py b/publish_unit_test_results.py index 95cfb03f..97276ff6 100644 --- a/publish_unit_test_results.py +++ b/publish_unit_test_results.py @@ -744,7 +744,7 @@ def hide_all_but_latest_comments(pull: PullRequest) -> None: if os.environ.get('GITHUB_ACTIONS') is None: logger.warning('action not running on GitHub, skipping hiding comment') for node_id in comment_ids: - logger.info('commend {} should be hidden'.format(node_id)) + logger.info('comment {} should be hidden'.format(node_id)) return # hide all those comments @@ -763,8 +763,12 @@ def hide_all_but_latest_comments(pull: PullRequest) -> None: hide_orphaned_commit_comments(pull) elif hide_comment_mode == hide_comments_mode_all_but_latest: hide_all_but_latest_comments(pull) + else: + logger.info('hide_comments disabled, not hiding any comments') else: logger.info('there is no pull request for commit {}'.format(commit_sha)) + else: + logger.info('comment_on_pr disabled, not commenting on any pull requests') def write_stats_file(stats, filename) -> None: From bbf42674e69c4efb1fe9bc1af1af13c142c46c01 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber Date: Mon, 2 Nov 2020 01:19:14 +0100 Subject: [PATCH 5/6] Add option comment_on_pr to action.yml --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index 939ab7b6..d5a7989c 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,10 @@ inputs: description: 'Configures which earlier comments of the action to hide: off - no comments, orphaned commits - comments for commits that are removed from the branch, all but latest - all comments but the latest' required: false default: 'all but latest' + comment_on_pr: + description: 'Toggle PR comments: false - disable PR comments, true - comment on PRs' + required: false + default: 'true' log_level: description: 'Action logging level' required: false From 170e05d1a01c40be18f57768211005e7f899ace1 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber Date: Mon, 2 Nov 2020 10:22:43 +0100 Subject: [PATCH 6/6] Implement suggestions --- action.yml | 2 +- publish_unit_test_results.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index d5a7989c..943ce0c4 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,7 @@ inputs: required: false default: 'all but latest' comment_on_pr: - description: 'Toggle PR comments: false - disable PR comments, true - comment on PRs' + description: 'Control PR comments: false - disable PR comments, true - comment on PRs' required: false default: 'true' log_level: diff --git a/publish_unit_test_results.py b/publish_unit_test_results.py index 97276ff6..90d27411 100644 --- a/publish_unit_test_results.py +++ b/publish_unit_test_results.py @@ -839,7 +839,6 @@ def check_var(var: str, name: str, label: str, allowed_values: Optional[List[str report_individual_runs = get_var('REPORT_INDIVIDUAL_RUNS') == 'true' dedup_classes_by_file_name = get_var('DEDUPLICATE_CLASSES_BY_FILE_NAME') == 'true' hide_comment_mode = get_var('HIDE_COMMENTS') or 'all but latest' - # Comment on PRs if COMMENT_ON_PR is not set to 'false' comment_on_pr = get_var('COMMENT_ON_PR') != 'false' commit = get_var('COMMIT') or get_commit_sha(event, event_name) files = get_var('FILES')