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. diff --git a/action.yml b/action.yml index 939ab7b6..943ce0c4 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: 'Control PR comments: false - disable PR comments, true - comment on PRs' + required: false + default: 'true' log_level: description: 'Action logging level' required: false diff --git a/publish_unit_test_results.py b/publish_unit_test_results.py index 4ed3166b..90d27411 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 @@ -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 @@ -755,15 +755,20 @@ 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) + 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('hide_comments disabled, not hiding any comments') + else: + logger.info('there is no pull request for commit {}'.format(commit_sha)) else: - logger.info('there is no pull request for commit {}'.format(commit_sha)) + logger.info('comment_on_pr disabled, not commenting on any pull requests') def write_stats_file(stats, filename) -> None: @@ -774,7 +779,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 +795,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 +839,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 +849,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)