def get_settings(options: dict) -> Settings: event = get_var('GITHUB_EVENT_PATH', options) event_name = get_var('GITHUB_EVENT_NAME', options) check_var(event, 'GITHUB_EVENT_PATH', 'GitHub event file path') check_var(event_name, 'GITHUB_EVENT_NAME', 'GitHub event name') with open(event, 'r') as f: event = json.load(f) api_url = options.get( 'GITHUB_API_URL') or github.MainClass.DEFAULT_BASE_URL graphql_url = options.get( 'GITHUB_GRAPHQL_URL') or f'{github.MainClass.DEFAULT_BASE_URL}/graphql' test_changes_limit = get_var('TEST_CHANGES_LIMIT', options) test_changes_limit = int( test_changes_limit ) if test_changes_limit and test_changes_limit.isdigit() else 10 check_name = get_var('CHECK_NAME', options) or 'Unit Test Results' annotations = get_annotations_config(options, event) settings = Settings( token=get_var('GITHUB_TOKEN', options), api_url=api_url, graphql_url=graphql_url, event=event, event_name=event_name, repo=get_var('GITHUB_REPOSITORY', options), commit=get_var('COMMIT', options) or get_commit_sha(event, event_name, options), files_glob=get_var('FILES', options), check_name=check_name, comment_title=get_var('COMMENT_TITLE', options) or check_name, comment_on_pr=get_var('COMMENT_ON_PR', options) != 'false', pull_request_build=get_var('PULL_REQUEST_BUILD', options) or 'merge', test_changes_limit=test_changes_limit, hide_comment_mode=get_var('HIDE_COMMENTS', options) or 'all but latest', report_individual_runs=get_var('REPORT_INDIVIDUAL_RUNS', options) == 'true', dedup_classes_by_file_name=get_var('DEDUPLICATE_CLASSES_BY_FILE_NAME', options) == 'true', check_run_annotation=annotations) check_var(settings.token, 'GITHUB_TOKEN', 'GitHub token') check_var(settings.repo, 'GITHUB_REPOSITORY', 'GitHub repository') check_var(settings.commit, 'COMMIT, GITHUB_SHA or event file', 'Commit SHA') check_var(settings.pull_request_build, 'PULL_REQUEST_BUILD', 'Pull Request build', pull_request_build_modes) check_var(settings.files_glob, 'FILES', 'Files pattern') check_var(settings.hide_comment_mode, 'HIDE_COMMENTS', 'hide comments mode', hide_comments_modes) check_var(settings.check_run_annotation, 'CHECK_RUN_ANNOTATIONS', 'check run annotations', available_annotations) return settings
def create_settings(comment_on_pr=False, hide_comment_mode=hide_comments_mode_off, report_individual_runs=False, dedup_classes_by_file_name=False, before: Optional[str] = 'before'): return Settings(token=None, event=dict(before=before), repo='owner/repo', commit='commit', files_glob='*.xml', check_name='Check Name', comment_title='Comment Title', comment_on_pr=comment_on_pr, hide_comment_mode=hide_comment_mode, report_individual_runs=report_individual_runs, dedup_classes_by_file_name=dedup_classes_by_file_name)
def create_settings(comment_on_pr=False, hide_comment_mode=hide_comments_mode_off, report_individual_runs=False, dedup_classes_by_file_name=False, check_run_annotation=available_annotations, before: Optional[str] = 'before'): return Settings(token=None, api_url='https://the-github-api-url', event=dict(before=before), repo='owner/repo', commit='commit', files_glob='*.xml', check_name='Check Name', comment_title='Comment Title', comment_on_pr=comment_on_pr, hide_comment_mode=hide_comment_mode, report_individual_runs=report_individual_runs, dedup_classes_by_file_name=dedup_classes_by_file_name, check_run_annotation=check_run_annotation)
event = get_var('GITHUB_EVENT_PATH') event_name = get_var('GITHUB_EVENT_NAME') check_var(event, 'GITHUB_EVENT_PATH', 'GitHub event file path') check_var(event_name, 'GITHUB_EVENT_NAME', 'GitHub event name') with open(event, 'r') as f: event = json.load(f) check_name = get_var('CHECK_NAME') or 'Unit Test Results' settings = Settings( token=get_var('GITHUB_TOKEN'), event=event, repo=get_var('GITHUB_REPOSITORY'), commit=get_var('COMMIT') or get_commit_sha(event, event_name), files_glob=get_var('FILES'), check_name=check_name, comment_title=get_var('COMMENT_TITLE') or check_name, comment_on_pr=get_var('COMMENT_ON_PR') != 'false', hide_comment_mode=get_var('HIDE_COMMENTS') or 'all but latest', report_individual_runs=get_var('REPORT_INDIVIDUAL_RUNS') == 'true', dedup_classes_by_file_name=get_var('DEDUPLICATE_CLASSES_BY_FILE_NAME') == 'true', ) check_var(settings.token, 'GITHUB_TOKEN', 'GitHub token') check_var(settings.repo, 'GITHUB_REPOSITORY', 'GitHub repository') check_var(settings.commit, 'COMMIT or event file', 'Commit SHA') check_var(settings.files_glob, 'FILES', 'Files pattern') check_var(settings.hide_comment_mode, 'HIDE_COMMENTS', 'hide comments mode', hide_comments_modes) main(settings)
def get_settings(options: dict, gha: Optional[GithubAction] = None) -> Settings: event_file = get_var('EVENT_FILE', options) event = event_file or get_var('GITHUB_EVENT_PATH', options) event_name = get_var('EVENT_NAME', options) or get_var('GITHUB_EVENT_NAME', options) check_var(event, 'GITHUB_EVENT_PATH', 'GitHub event file path') check_var(event_name, 'GITHUB_EVENT_NAME', 'GitHub event name') with open(event, 'rt', encoding='utf-8') as f: event = json.load(f) api_url = options.get('GITHUB_API_URL') or github.MainClass.DEFAULT_BASE_URL graphql_url = options.get('GITHUB_GRAPHQL_URL') or f'{github.MainClass.DEFAULT_BASE_URL}/graphql' test_changes_limit = get_var('TEST_CHANGES_LIMIT', options) or '10' check_var_condition(test_changes_limit.isnumeric(), f'TEST_CHANGES_LIMIT must be a positive integer or 0: {test_changes_limit}') time_unit = get_var('TIME_UNIT', options) or 'seconds' time_factors = {'seconds': 1.0, 'milliseconds': 0.001} time_factor = time_factors.get(time_unit.lower()) check_var_condition(time_factor is not None, f'TIME_UNIT {time_unit} is not supported. ' f'It is optional, but when given must be one of these values: ' f'{", ".join(time_factors.keys())}') check_name = get_var('CHECK_NAME', options) or 'Unit Test Results' comment_on_pr = get_bool_var('COMMENT_ON_PR', options, default=True, gha=gha) annotations = get_annotations_config(options, event) fail_on = get_var('FAIL_ON', options) or 'test failures' check_var(fail_on, 'FAIL_ON', 'Check fail mode', fail_on_modes) # here we decide that we want to fail on errors when we fail on test failures, like log level escalation fail_on_failures = fail_on == fail_on_mode_failures fail_on_errors = fail_on == fail_on_mode_errors or fail_on_failures retries = get_var('GITHUB_RETRIES', options) or '10' seconds_between_github_reads = get_var('SECONDS_BETWEEN_GITHUB_READS', options) or '1' seconds_between_github_writes = get_var('SECONDS_BETWEEN_GITHUB_WRITES', options) or '2' check_var_condition(retries.isnumeric(), f'GITHUB_RETRIES must be a positive integer or 0: {retries}') check_var_condition(is_float(seconds_between_github_reads), f'SECONDS_BETWEEN_GITHUB_READS must be a positive number: {seconds_between_github_reads}') check_var_condition(is_float(seconds_between_github_writes), f'SECONDS_BETWEEN_GITHUB_WRITES must be a positive number: {seconds_between_github_writes}') settings = Settings( token=get_var('GITHUB_TOKEN', options), api_url=api_url, graphql_url=graphql_url, api_retries=int(retries), event=event, event_file=event_file, event_name=event_name, repo=get_var('GITHUB_REPOSITORY', options), commit=get_var('COMMIT', options) or get_commit_sha(event, event_name, options), json_file=get_var('JSON_FILE', options), fail_on_errors=fail_on_errors, fail_on_failures=fail_on_failures, files_glob=get_var('FILES', options) or '*.xml', time_factor=time_factor, check_name=check_name, comment_title=get_var('COMMENT_TITLE', options) or check_name, comment_mode=get_var('COMMENT_MODE', options) or (comment_mode_update if comment_on_pr else comment_mode_off), compare_earlier=get_bool_var('COMPARE_TO_EARLIER_COMMIT', options, default=True, gha=gha), pull_request_build=get_var('PULL_REQUEST_BUILD', options) or 'merge', test_changes_limit=int(test_changes_limit), hide_comment_mode=get_var('HIDE_COMMENTS', options) or 'all but latest', report_individual_runs=get_bool_var('REPORT_INDIVIDUAL_RUNS', options, default=False, gha=gha), dedup_classes_by_file_name=get_bool_var('DEDUPLICATE_CLASSES_BY_FILE_NAME', options, default=False, gha=gha), ignore_runs=get_bool_var('IGNORE_RUNS', options, default=False, gha=gha), check_run_annotation=annotations, seconds_between_github_reads=float(seconds_between_github_reads), seconds_between_github_writes=float(seconds_between_github_writes) ) check_var(settings.token, 'GITHUB_TOKEN', 'GitHub token') check_var(settings.repo, 'GITHUB_REPOSITORY', 'GitHub repository') check_var(settings.commit, 'COMMIT, GITHUB_SHA or event file', 'Commit SHA') check_var(settings.comment_mode, 'COMMENT_MODE', 'Commit mode', comment_modes) check_var(settings.pull_request_build, 'PULL_REQUEST_BUILD', 'Pull Request build', pull_request_build_modes) check_var(settings.hide_comment_mode, 'HIDE_COMMENTS', 'Hide comments mode', hide_comments_modes) check_var(settings.check_run_annotation, 'CHECK_RUN_ANNOTATIONS', 'Check run annotations', available_annotations) check_var_condition(settings.test_changes_limit >= 0, f'TEST_CHANGES_LIMIT must be a positive integer or 0: {settings.test_changes_limit}') check_var_condition(settings.api_retries >= 0, f'GITHUB_RETRIES must be a positive integer or 0: {settings.api_retries}') check_var_condition(settings.seconds_between_github_reads > 0, f'SECONDS_BETWEEN_GITHUB_READS must be a positive number: {seconds_between_github_reads}') check_var_condition(settings.seconds_between_github_writes > 0, f'SECONDS_BETWEEN_GITHUB_WRITES must be a positive number: {seconds_between_github_writes}') deprecate_var(get_var('COMMENT_ON_PR', options) or None, 'COMMENT_ON_PR', 'Instead, use option "comment_mode" with values "off", "create new", or "update last".', gha) return settings
def get_settings(options: dict, gha: Optional[GithubAction] = None) -> Settings: event = get_var('GITHUB_EVENT_PATH', options) event_name = get_var('GITHUB_EVENT_NAME', options) check_var(event, 'GITHUB_EVENT_PATH', 'GitHub event file path') check_var(event_name, 'GITHUB_EVENT_NAME', 'GitHub event name') with open(event, 'rt', encoding='utf-8') as f: event = json.load(f) api_url = options.get( 'GITHUB_API_URL') or github.MainClass.DEFAULT_BASE_URL graphql_url = options.get( 'GITHUB_GRAPHQL_URL') or f'{github.MainClass.DEFAULT_BASE_URL}/graphql' test_changes_limit = get_var('TEST_CHANGES_LIMIT', options) test_changes_limit = int( test_changes_limit ) if test_changes_limit and test_changes_limit.isdigit() else 10 check_name = get_var('CHECK_NAME', options) or 'Unit Test Results' annotations = get_annotations_config(options, event) fail_on = get_var('FAIL_ON', options) or 'test failures' check_var(fail_on, 'FAIL_ON', 'Check fail mode', fail_on_modes) # here we decide that we want to fail on errors when we fail on test failures, like log level escalation fail_on_failures = fail_on == fail_on_mode_failures fail_on_errors = fail_on == fail_on_mode_errors or fail_on_failures settings = Settings( token=get_var('GITHUB_TOKEN', options), api_url=api_url, graphql_url=graphql_url, event=event, event_name=event_name, repo=get_var('GITHUB_REPOSITORY', options), commit=get_var('COMMIT', options) or get_commit_sha(event, event_name, options), fail_on_errors=fail_on_errors, fail_on_failures=fail_on_failures, files_glob=get_var('FILES', options) or '*.xml', check_name=check_name, comment_title=get_var('COMMENT_TITLE', options) or check_name, comment_mode=get_var('COMMENT_MODE', options) or (comment_mode_update if get_var('COMMENT_ON_PR', options) != 'false' else comment_mode_off), compare_earlier=get_var('COMPARE_TO_EARLIER_COMMIT', options) != 'false', pull_request_build=get_var('PULL_REQUEST_BUILD', options) or 'merge', test_changes_limit=test_changes_limit, hide_comment_mode=get_var('HIDE_COMMENTS', options) or 'all but latest', report_individual_runs=get_var('REPORT_INDIVIDUAL_RUNS', options) == 'true', dedup_classes_by_file_name=get_var('DEDUPLICATE_CLASSES_BY_FILE_NAME', options) == 'true', check_run_annotation=annotations) check_var(settings.token, 'GITHUB_TOKEN', 'GitHub token') check_var(settings.repo, 'GITHUB_REPOSITORY', 'GitHub repository') check_var(settings.commit, 'COMMIT, GITHUB_SHA or event file', 'Commit SHA') check_var(settings.comment_mode, 'COMMENT_MODE', 'Commit mode', comment_modes) check_var(settings.pull_request_build, 'PULL_REQUEST_BUILD', 'Pull Request build', pull_request_build_modes) check_var(settings.hide_comment_mode, 'HIDE_COMMENTS', 'Hide comments mode', hide_comments_modes) check_var(settings.check_run_annotation, 'CHECK_RUN_ANNOTATIONS', 'Check run annotations', available_annotations) deprecate_var( get_var('COMMENT_ON_PR', options) or None, 'COMMENT_ON_PR', 'Instead, use option "comment_mode" with values "off", "create new", or "update last".', gha) return settings