From a9e9578d5b4310bea83775a707c537f9418d75c3 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 Feb 2023 17:51:21 -0800 Subject: [PATCH 1/3] Expose CheckSuitesService and ChuckRunsService classes Require Dart 2.18 Also a bunch of other cleanup, enabled latest lints removed duplicate lints sorted lints etc --- .github/workflows/tests.yml | 2 +- CHANGELOG.md | 5 + analysis_options.yaml | 342 +------------------- example/release_notes.dart | 13 +- example/stars.dart | 2 +- lib/src/common/activity_service.dart | 64 ++-- lib/src/common/authorizations_service.dart | 6 +- lib/src/common/checks_service.dart | 37 +-- lib/src/common/gists_service.dart | 24 +- lib/src/common/git_service.dart | 28 +- lib/src/common/github.dart | 7 +- lib/src/common/issues_service.dart | 55 ++-- lib/src/common/misc_service.dart | 5 +- lib/src/common/model/users.dart | 2 +- lib/src/common/orgs_service.dart | 34 +- lib/src/common/pulls_service.dart | 27 +- lib/src/common/repos_service.dart | 108 ++++--- lib/src/common/search_service.dart | 29 +- lib/src/common/users_service.dart | 37 +-- lib/src/common/util/oauth2.dart | 6 +- pubspec.yaml | 10 +- test/assets/responses/nocked_responses.dart | 22 +- test/common/github_test.dart | 2 +- test/experiment/error_handling.dart | 4 - test/git_test.dart | 1 - test/scenarios_test.dart | 2 + test/unit/issues_test.dart | 4 +- tool/release_unreleased_prs.dart | 2 +- 28 files changed, 258 insertions(+), 622 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 225f514f..b5a0c40d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - sdk: [2.17.7, stable] # Test with at least the declared minimum Dart version + sdk: [2.18.7, stable] # Test with at least the declared minimum Dart version steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1.3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fd43ae6..e49cfa75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 9.9.1-dev + +* Require Dart 2.17 +* Expose `CheckSuitesService` and `ChuckRunsService` classes. + ## 9.9.0 * Add "author_association" field to the IssueComment object by @ricardoamador in https://github.com/SpinlockLabs/github.dart/pull/348 diff --git a/analysis_options.yaml b/analysis_options.yaml index 1b107aa5..f7a9ff49 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,397 +1,61 @@ include: package:lints/recommended.yaml analyzer: - strong-mode: - implicit-casts: true - implicit-dynamic: true + language: + #strict-casts: true linter: rules: - - # Separate the control structure expression from its statement. - # http://dart-lang.github.io/linter/lints/always_put_control_body_on_new_line.html - always_put_control_body_on_new_line - - # Put @required named parameters first. - # http://dart-lang.github.io/linter/lints/always_put_required_named_parameters_first.html - always_put_required_named_parameters_first - - # Avoid bool literals in conditional expressions. - # http://dart-lang.github.io/linter/lints/avoid_bool_literals_in_conditional_expressions.html - # - avoid_bool_literals_in_conditional_expressions - - # Don't explicitly catch Error or types that implement it. - # http://dart-lang.github.io/linter/lints/avoid_catching_errors.html - avoid_catching_errors - - # Avoid defining a class that contains only static members. - # http://dart-lang.github.io/linter/lints/avoid_classes_with_only_static_members.html - avoid_classes_with_only_static_members - - # Avoid double and int checks. - # http://dart-lang.github.io/linter/lints/avoid_double_and_int_checks.html - avoid_double_and_int_checks - - # Avoid field initializers in const classes. - # http://dart-lang.github.io/linter/lints/avoid_field_initializers_in_const_classes.html - avoid_field_initializers_in_const_classes - - # Avoid using `forEach` with a function literal. - # http://dart-lang.github.io/linter/lints/avoid_function_literals_in_foreach_calls.html - # reason: Use for (x in y) or forEach(someFunc) instead - # - avoid_function_literals_in_foreach_calls - - # Don't implement classes that override `==`. - # http://dart-lang.github.io/linter/lints/avoid_implementing_value_types.html - avoid_implementing_value_types - - # Avoid JavaScript rounded ints. - # http://dart-lang.github.io/linter/lints/avoid_js_rounded_ints.html - avoid_js_rounded_ints - - # Avoid positional boolean parameters. - # http://dart-lang.github.io/linter/lints/avoid_positional_boolean_parameters.html - # - avoid_positional_boolean_parameters - - # Avoid `print` calls in production code. - # http://dart-lang.github.io/linter/lints/avoid_print.html - # - avoid_print - - # Avoid private typedef functions. - # http://dart-lang.github.io/linter/lints/avoid_private_typedef_functions.html - avoid_private_typedef_functions - - # Don't rename parameters of overridden methods. - # http://dart-lang.github.io/linter/lints/avoid_renaming_method_parameters.html - # - avoid_renaming_method_parameters - - # Avoid returning null from members whose return type is bool, double, int, or num. - # http://dart-lang.github.io/linter/lints/avoid_returning_null.html - avoid_returning_null - - # Avoid returning null for Future. - # http://dart-lang.github.io/linter/lints/avoid_returning_null_for_future.html - avoid_returning_null_for_future - - # Avoid returning null for void. - # http://dart-lang.github.io/linter/lints/avoid_returning_null_for_void.html - - avoid_returning_null_for_void - - # Avoid returning this from methods just to enable a fluent interface. - # http://dart-lang.github.io/linter/lints/avoid_returning_this.html - avoid_returning_this - - # Avoid setters without getters. - # http://dart-lang.github.io/linter/lints/avoid_setters_without_getters.html - avoid_setters_without_getters - - # Avoid single cascade in expression statements. - # http://dart-lang.github.io/linter/lints/avoid_single_cascade_in_expression_statements.html - - avoid_single_cascade_in_expression_statements - - # Avoid slow async `dart:io` methods. - # http://dart-lang.github.io/linter/lints/avoid_slow_async_io.html - avoid_slow_async_io - - # Avoid defining unused parameters in constructors. - # http://dart-lang.github.io/linter/lints/avoid_unused_constructor_parameters.html - avoid_unused_constructor_parameters - - # Avoid async functions that return void. - # http://dart-lang.github.io/linter/lints/avoid_void_async.html - avoid_void_async - - # Await only futures. - # http://dart-lang.github.io/linter/lints/await_only_futures.html - - await_only_futures - - # Name types using UpperCamelCase. - # http://dart-lang.github.io/linter/lints/camel_case_types.html - - camel_case_types - - # Cancel instances of dart.async.StreamSubscription. - # http://dart-lang.github.io/linter/lints/cancel_subscriptions.html - cancel_subscriptions - - # Cascade consecutive method invocations on the same reference. - # http://dart-lang.github.io/linter/lints/cascade_invocations.html - # - cascade_invocations - - # Close instances of `dart.core.Sink`. - # http://dart-lang.github.io/linter/lints/close_sinks.html - close_sinks - - # Only reference in scope identifiers in doc comments. - # http://dart-lang.github.io/linter/lints/comment_references.html - comment_references - - # Avoid control flow in finally blocks. - # http://dart-lang.github.io/linter/lints/control_flow_in_finally.html - - control_flow_in_finally - - # DO reference all public properties in debug methods. - # http://dart-lang.github.io/linter/lints/diagnostic_describe_all_properties.html - diagnostic_describe_all_properties - - # Adhere to Effective Dart Guide directives sorting conventions. - # http://dart-lang.github.io/linter/lints/directives_ordering.html - directives_ordering - - # Avoid empty statements. - # http://dart-lang.github.io/linter/lints/empty_statements.html - - empty_statements - - # Name source files using `lowercase_with_underscores`. - # http://dart-lang.github.io/linter/lints/file_names.html - - file_names - - # Use Flutter TODO format: // TODO(username): message, https://URL-to-issue. - # http://dart-lang.github.io/linter/lints/flutter_style_todos.html - # - flutter_style_todos - - # Always override `hashCode` if overriding `==`. - # http://dart-lang.github.io/linter/lints/hash_and_equals.html - - hash_and_equals - - # Don't import implementation files from another package. - # http://dart-lang.github.io/linter/lints/implementation_imports.html - - implementation_imports - - # Conditions should not unconditionally evaluate to `true` or to `false`. - # http://dart-lang.github.io/linter/lints/invariant_booleans.html - # reason: There are several outstanding bugs with this lint that cause a good deal of noise - - invariant_booleans - - # Invocation of Iterable.contains with references of unrelated types. - # http://dart-lang.github.io/linter/lints/iterable_contains_unrelated_type.html - - iterable_contains_unrelated_type - - # Join return statement with assignment when possible. - # http://dart-lang.github.io/linter/lints/join_return_with_assignment.html - join_return_with_assignment - - - # AVOID lines longer than 80 characters. - # http://dart-lang.github.io/linter/lints/lines_longer_than_80_chars.html - # - lines_longer_than_80_chars - - # Invocation of `remove` with references of unrelated types. - # http://dart-lang.github.io/linter/lints/list_remove_unrelated_type.html - - list_remove_unrelated_type - - # Boolean expression composed only with literals. - # http://dart-lang.github.io/linter/lints/literal_only_boolean_expressions.html - literal_only_boolean_expressions - - # Don't use adjacent strings in list. - # http://dart-lang.github.io/linter/lints/no_adjacent_strings_in_list.html - no_adjacent_strings_in_list - - - # Name non-constant identifiers using lowerCamelCase. - # http://dart-lang.github.io/linter/lints/non_constant_identifier_names.html - - non_constant_identifier_names - - # Avoid defining a one-member abstract class when a simple function will do. - # http://dart-lang.github.io/linter/lints/one_member_abstracts.html + - omit_local_variable_types - one_member_abstracts - - # Only throw instances of classes extending either Exception or Error. - # http://dart-lang.github.io/linter/lints/only_throw_errors.html - only_throw_errors - - # Don't override fields. - # http://dart-lang.github.io/linter/lints/overridden_fields.html - - overridden_fields - - # Provide doc comments for all public APIs. - # http://dart-lang.github.io/linter/lints/package_api_docs.html - package_api_docs - - # Use `lowercase_with_underscores` for package names. - # http://dart-lang.github.io/linter/lints/package_names.html - - package_names - - # Prefix library names with the package name and a dot-separated path. - # http://dart-lang.github.io/linter/lints/package_prefixed_library_names.html - - package_prefixed_library_names - - # Don't reassign references to parameters of functions or methods. - # http://dart-lang.github.io/linter/lints/parameter_assignments.html - # - parameter_assignments - - # Prefer putting asserts in initializer list. - # http://dart-lang.github.io/linter/lints/prefer_asserts_in_initializer_lists.html - prefer_asserts_in_initializer_lists - - # Prefer asserts with message. - # http://dart-lang.github.io/linter/lints/prefer_asserts_with_message.html - # - prefer_asserts_with_message - - # Prefer using a boolean as the assert condition. - # http://dart-lang.github.io/linter/lints/prefer_bool_in_asserts.html - # reason: This lint rule has been deprecated - # - prefer_bool_in_asserts - - # Prefer using `??=` over testing for null. - # http://dart-lang.github.io/linter/lints/prefer_conditional_assignment.html - # - prefer_conditional_assignment - - # Prefer const with constant constructors. - # http://dart-lang.github.io/linter/lints/prefer_const_constructors.html - prefer_const_constructors - - # Prefer declare const constructors on `@immutable` classes. - # http://dart-lang.github.io/linter/lints/prefer_const_constructors_in_immutables.html - prefer_const_constructors_in_immutables - - # Prefer const over final for declarations. - # http://dart-lang.github.io/linter/lints/prefer_const_declarations.html - prefer_const_declarations - - # Prefer const literals as parameters of constructors on @immutable classes. - # http://dart-lang.github.io/linter/lints/prefer_const_literals_to_create_immutables.html - prefer_const_literals_to_create_immutables - - # Prefer defining constructors instead of static methods to create instances. - # http://dart-lang.github.io/linter/lints/prefer_constructors_over_static_methods.html - prefer_constructors_over_static_methods - - # Prefer final in for-each loop variable if reference is not reassigned. - # http://dart-lang.github.io/linter/lints/prefer_final_in_for_each.html - prefer_final_in_for_each - - # Use `forEach` to only apply a function to all the elements. - # http://dart-lang.github.io/linter/lints/prefer_foreach.html - prefer_foreach - - # Use a function declaration to bind a function to a name. - # http://dart-lang.github.io/linter/lints/prefer_function_declarations_over_variables.html - - prefer_function_declarations_over_variables - - # Prefer if elements to conditional expressions where possible. - # http://dart-lang.github.io/linter/lints/prefer_if_elements_to_conditional_expressions.html - prefer_if_elements_to_conditional_expressions - - # Use initializing formals when possible. - # http://dart-lang.github.io/linter/lints/prefer_initializing_formals.html - - prefer_initializing_formals - - # Inline list item declarations where possible. - # http://dart-lang.github.io/linter/lints/prefer_inlined_adds.html - - prefer_inlined_adds - - # Prefer int literals over double literals. - # http://dart-lang.github.io/linter/lints/prefer_int_literals.html - prefer_int_literals - - # Prefer using mixins. - # http://dart-lang.github.io/linter/lints/prefer_mixin.html - prefer_mixin - - # Prefer typing uninitialized variables and fields. - # http://dart-lang.github.io/linter/lints/prefer_typing_uninitialized_variables.html - - prefer_typing_uninitialized_variables - - # Don't use the Null type, unless you are positive that you don't want void. - # http://dart-lang.github.io/linter/lints/prefer_void_to_null.html - - prefer_void_to_null - - # Provide a deprecation message, via @Deprecated("message"). - # http://dart-lang.github.io/linter/lints/provide_deprecation_message.html - - provide_deprecation_message - - # Document all public members. - # http://dart-lang.github.io/linter/lints/public_member_api_docs.html - # reason: Can get annoying for React component lifecycle methods, constructors. - # - public_member_api_docs - - # Sort child properties last in widget instance creations. - # http://dart-lang.github.io/linter/lints/sort_child_properties_last.html - sort_child_properties_last - - # Sort constructor declarations before other members. - # http://dart-lang.github.io/linter/lints/sort_constructors_first.html - # - sort_constructors_first - - # Sort pub dependencies. - # http://dart-lang.github.io/linter/lints/sort_pub_dependencies.html - sort_pub_dependencies - - # Sort unnamed constructor declarations first. - # http://dart-lang.github.io/linter/lints/sort_unnamed_constructors_first.html - sort_unnamed_constructors_first - - # Test type arguments in operator ==(Object other). - # http://dart-lang.github.io/linter/lints/test_types_in_equals.html - test_types_in_equals - - # Avoid `throw` in finally block. - # http://dart-lang.github.io/linter/lints/throw_in_finally.html - throw_in_finally - - # Type annotate public APIs. - # http://dart-lang.github.io/linter/lints/type_annotate_public_apis.html - # reason: React component render() method can return either ReactElement or false. Use overrides. - type_annotate_public_apis - - # Unnecessary await keyword in return. - # http://dart-lang.github.io/linter/lints/unnecessary_await_in_return.html - unnecessary_await_in_return - - # Avoid using braces in interpolation when not needed. - # http://dart-lang.github.io/linter/lints/unnecessary_brace_in_string_interps.html - - unnecessary_brace_in_string_interps - - # Avoid wrapping fields in getters and setters just to be "safe". - # http://dart-lang.github.io/linter/lints/unnecessary_getters_setters.html - - unnecessary_getters_setters - - # Don't create a lambda when a tear-off will do. - # http://dart-lang.github.io/linter/lints/unnecessary_lambdas.html - unnecessary_lambdas - - # Avoid null in null-aware assignment. - # http://dart-lang.github.io/linter/lints/unnecessary_null_aware_assignments.html - - unnecessary_null_aware_assignments - - # Don't override a method to do a super method invocation with the same parameters. - # http://dart-lang.github.io/linter/lints/unnecessary_overrides.html - - unnecessary_overrides - - # Unnecessary parenthesis can be removed. - # http://dart-lang.github.io/linter/lints/unnecessary_parenthesis.html - unnecessary_parenthesis - - # Avoid using unnecessary statements. - # http://dart-lang.github.io/linter/lints/unnecessary_statements.html - unnecessary_statements - - # Avoid unsafe HTML APIs. - # http://dart-lang.github.io/linter/lints/unsafe_html.html - # - unsafe_html - - # Prefer an 8-digit hexadecimal integer(0xFFFFFFFF) to instantiate Color. - # http://dart-lang.github.io/linter/lints/use_full_hex_values_for_flutter_colors.html - use_full_hex_values_for_flutter_colors - - # Use a setter for operations that conceptually change a property. - # http://dart-lang.github.io/linter/lints/use_setters_to_change_properties.html - use_setters_to_change_properties - - # Use string buffers to compose strings. - # http://dart-lang.github.io/linter/lints/use_string_buffers.html - use_string_buffers - - # Start the name of the method with to/_to or as/_as if applicable. - # http://dart-lang.github.io/linter/lints/use_to_and_as_if_applicable.html - use_to_and_as_if_applicable - - # Don't assign to void. - # http://dart-lang.github.io/linter/lints/void_checks.html - # reason: Trying to assigning a value to void is an error. - - void_checks - - - omit_local_variable_types - - prefer_final_fields - - use_function_type_syntax_for_parameters diff --git a/example/release_notes.dart b/example/release_notes.dart index 867474ee..be929744 100644 --- a/example/release_notes.dart +++ b/example/release_notes.dart @@ -1,8 +1,9 @@ import 'dart:html'; -import 'common.dart'; import 'package:pub_semver/pub_semver.dart'; +import 'common.dart'; + late DivElement releasesDiv; Future main() async { @@ -28,12 +29,12 @@ Future loadReleaseNotes() async { print('No unreleased PRs'); return ''; } - var semvers = Set(); - for (var pr in unreleasedPRs) { + var semvers = {}; + for (final pr in unreleasedPRs) { var prlabels = pr.labels .where((element) => element.name.startsWith('semver:')) .toList(); - for (var l in prlabels) { + for (final l in prlabels) { semvers.add(l.name); } } @@ -50,7 +51,9 @@ Future loadReleaseNotes() async { newVersion = latestVersion.nextPatch.toString(); } print(newVersion); - if (newVersion.isEmpty) return ''; + if (newVersion.isEmpty) { + return ''; + } var notes = await github.repositories.generateReleaseNotes(CreateReleaseNotes( slug.owner, slug.name, newVersion, diff --git a/example/stars.dart b/example/stars.dart index a7c96bc4..52a95e54 100644 --- a/example/stars.dart +++ b/example/stars.dart @@ -30,6 +30,6 @@ void loadStars() { $stars!.append(h); }).onDone(() { querySelector('#total')! - .appendText(querySelectorAll('.user').length.toString() + ' stars'); + .appendText('${querySelectorAll('.user').length} stars'); }); } diff --git a/lib/src/common/activity_service.dart b/lib/src/common/activity_service.dart index 16b7b84a..0001fcdc 100644 --- a/lib/src/common/activity_service.dart +++ b/lib/src/common/activity_service.dart @@ -15,9 +15,8 @@ class ActivityService extends Service { /// /// API docs: https://developer.github.com/v3/activity/events/#list-public-events Stream listPublicEvents({int pages = 2}) { - return PaginationHelper(github).objects( - 'GET', '/events', (dynamic i) => Event.fromJson(i), - pages: pages); + return PaginationHelper(github) + .objects('GET', '/events', Event.fromJson, pages: pages); } /// Lists public events for a network of repositories. @@ -25,8 +24,8 @@ class ActivityService extends Service { /// API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories Stream listRepositoryNetworkEvents(RepositorySlug slug, {int pages = 2}) { - return PaginationHelper(github).objects('GET', - '/networks/${slug.fullName}/events', (dynamic i) => Event.fromJson(i), + return PaginationHelper(github).objects( + 'GET', '/networks/${slug.fullName}/events', Event.fromJson, pages: pages); } @@ -47,9 +46,7 @@ class ActivityService extends Service { /// API docs: https://developer.github.com/v3/activity/events/#list-repository-events Stream listRepositoryIssueEvents(RepositorySlug slug, {int? pages}) { return PaginationHelper(github).objects( - 'GET', - '/repos/${slug.fullName}/issues/events', - (dynamic i) => Event.fromJson(i), + 'GET', '/repos/${slug.fullName}/issues/events', Event.fromJson, pages: pages); } @@ -62,8 +59,8 @@ class ActivityService extends Service { /// /// API docs: https://developer.github.com/v3/activity/events/#list-repository-events Stream listRepositoryEvents(RepositorySlug slug, {int? pages}) { - return PaginationHelper(github).objects('GET', - '/repos/${slug.fullName}/events', (dynamic i) => Event.fromJson(i), + return PaginationHelper(github).objects( + 'GET', '/repos/${slug.fullName}/events', Event.fromJson, pages: pages); } @@ -77,9 +74,8 @@ class ActivityService extends Service { /// /// API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-an-organization Stream listEventsForOrganization(String name, {int? pages}) { - return PaginationHelper(github).objects( - 'GET', '/orgs/$name/events', (dynamic i) => Event.fromJson(i), - pages: pages); + return PaginationHelper(github) + .objects('GET', '/orgs/$name/events', Event.fromJson, pages: pages); } /// Returns an [EventPoller] for public events for an organization. @@ -105,7 +101,7 @@ class ActivityService extends Service { /// API docs: https://developer.github.com/v3/activity/events/#list-events-performed-by-a-user Stream listEventsPerformedByUser(String username, {int? pages}) { return PaginationHelper(github).objects( - 'GET', '/users/$username/events', (dynamic i) => Event.fromJson(i), + 'GET', '/users/$username/events', Event.fromJson, pages: pages); } @@ -113,8 +109,8 @@ class ActivityService extends Service { /// /// API docs: https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user Stream listPublicEventsPerformedByUser(String username, {int? pages}) { - return PaginationHelper(github).objects('GET', - '/users/$username/events/public', (dynamic i) => Event.fromJson(i), + return PaginationHelper(github).objects( + 'GET', '/users/$username/events/public', Event.fromJson, pages: pages); } @@ -132,7 +128,7 @@ class ActivityService extends Service { Stream listNotifications( {bool all = false, bool participating = false}) { return PaginationHelper(github).objects( - 'GET', '/notifications', (dynamic i) => Notification.fromJson(i), + 'GET', '/notifications', Notification.fromJson, params: {'all': all, 'participating': participating}); } @@ -141,10 +137,8 @@ class ActivityService extends Service { /// API docs: https://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository Stream listRepositoryNotifications(RepositorySlug repository, {bool all = false, bool participating = false}) { - return PaginationHelper(github).objects( - 'GET', - '/repos/${repository.fullName}/notifications', - (dynamic i) => Notification.fromJson(i), + return PaginationHelper(github).objects('GET', + '/repos/${repository.fullName}/notifications', Notification.fromJson, params: {'all': all, 'participating': participating}); } @@ -192,8 +186,7 @@ class ActivityService extends Service { /// API docs: https://developer.github.com/v3/activity/notifications/#view-a-single-thread Future getThread(String threadId) => github.getJSON('/notification/threads/$threadId', - statusCode: StatusCodes.OK, - convert: (dynamic i) => Notification.fromJson(i)); + statusCode: StatusCodes.OK, convert: Notification.fromJson); /// Mark the specified notification thread as read. /// @@ -214,8 +207,8 @@ class ActivityService extends Service { /// /// API docs: https://developer.github.com/v3/activity/starring/#list-stargazers Stream listStargazers(RepositorySlug slug, {int perPage = 30}) { - return PaginationHelper(github).objects('GET', - '/repos/${slug.fullName}/stargazers', (dynamic i) => User.fromJson(i), + return PaginationHelper(github).objects( + 'GET', '/repos/${slug.fullName}/stargazers', User.fromJson, params: {'per_page': perPage}); } @@ -224,7 +217,7 @@ class ActivityService extends Service { /// API docs: https://developer.github.com/v3/activity/starring/#list-repositories-being-starred Stream listStarredByUser(String user, {int perPage = 30}) { return PaginationHelper(github).objects( - 'GET', '/users/$user/starred', (dynamic i) => Repository.fromJson(i), + 'GET', '/users/$user/starred', Repository.fromJson, params: {'per_page': perPage}); } @@ -233,7 +226,7 @@ class ActivityService extends Service { /// API docs: https://developer.github.com/v3/activity/starring/#list-repositories-being-starred Stream listStarred({int perPage = 30}) { return PaginationHelper(github).objects( - 'GET', '/user/starred', (dynamic i) => Repository.fromJson(i), + 'GET', '/user/starred', Repository.fromJson, params: {'per_page': perPage}); } @@ -272,24 +265,24 @@ class ActivityService extends Service { /// /// API docs: https://developer.github.com/v3/activity/watching/#list-watchers Stream listWatchers(RepositorySlug slug) { - return PaginationHelper(github).objects('GET', - '/repos/${slug.fullName}/subscribers', (dynamic i) => User.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/repos/${slug.fullName}/subscribers', User.fromJson); } /// Lists the repositories the specified user is watching. /// /// API docs: https://developer.github.com/v3/activity/watching/#list-repositories-being-watched Stream listWatchedByUser(String user) { - return PaginationHelper(github).objects('GET', '/users/$user/subscriptions', - (dynamic i) => Repository.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/users/$user/subscriptions', Repository.fromJson); } /// Lists the repositories the current user is watching. /// /// API docs: https://developer.github.com/v3/activity/watching/#list-repositories-being-watched Stream listWatched() { - return PaginationHelper(github).objects( - 'GET', '/user/subscriptions', (dynamic i) => Repository.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/user/subscriptions', Repository.fromJson); } /// Fetches repository subscription information. @@ -298,8 +291,7 @@ class ActivityService extends Service { Future getRepositorySubscription( RepositorySlug slug) => github.getJSON('/repos/${slug.fullName}/subscription', - statusCode: StatusCodes.OK, - convert: (dynamic i) => RepositorySubscription.fromJson(i)); + statusCode: StatusCodes.OK, convert: RepositorySubscription.fromJson); /// Sets the Repository Subscription Status /// @@ -315,7 +307,7 @@ class ActivityService extends Service { return github.putJSON( '/repos/${slug.fullName}/subscription', statusCode: StatusCodes.OK, - convert: (dynamic i) => RepositorySubscription.fromJson(i), + convert: RepositorySubscription.fromJson, body: GitHubJson.encode(map), ); } diff --git a/lib/src/common/authorizations_service.dart b/lib/src/common/authorizations_service.dart index 7e714afb..3cbe6ef0 100644 --- a/lib/src/common/authorizations_service.dart +++ b/lib/src/common/authorizations_service.dart @@ -16,8 +16,8 @@ class AuthorizationsService extends Service { /// /// API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations Stream listAuthorizations() { - return PaginationHelper(github).objects( - 'GET', '/authorizations', (dynamic i) => Authorization.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/authorizations', Authorization.fromJson); } /// Fetches an authorization specified by [id]. @@ -25,7 +25,7 @@ class AuthorizationsService extends Service { /// API docs: https://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization Future getAuthorization(int id) => github.getJSON('/authorizations/$id', - statusCode: 200, convert: (dynamic i) => Authorization.fromJson(i)); + statusCode: 200, convert: Authorization.fromJson); // TODO: Implement remaining API methods of authorizations: // See https://developer.github.com/v3/oauth_authorizations/ diff --git a/lib/src/common/checks_service.dart b/lib/src/common/checks_service.dart index d3b63f77..0e87f4d2 100644 --- a/lib/src/common/checks_service.dart +++ b/lib/src/common/checks_service.dart @@ -11,21 +11,21 @@ class ChecksService extends Service { /// Methods to interact with Check Runs. /// /// API docs: https://developer.github.com/v3/checks/runs/ - final _CheckRunsService checkRuns; + final CheckRunsService checkRuns; /// Methods to interact with Check Suites. /// /// API docs: https://developer.github.com/v3/checks/suites/ - final _CheckSuitesService checkSuites; + final CheckSuitesService checkSuites; ChecksService(GitHub github) - : checkRuns = _CheckRunsService._(github), - checkSuites = _CheckSuitesService._(github), + : checkRuns = CheckRunsService._(github), + checkSuites = CheckSuitesService._(github), super(github); } -class _CheckRunsService extends Service { - _CheckRunsService._(GitHub github) : super(github); +class CheckRunsService extends Service { + CheckRunsService._(GitHub github) : super(github); /// Creates a new check run for a specific commit in a repository. /// Your GitHub App must have the `checks:write` permission to create check runs. @@ -78,7 +78,7 @@ class _CheckRunsService extends Service { 'output': output, 'actions': actions, })), - convert: (i) => CheckRun.fromJson(i), + convert: CheckRun.fromJson, ); } @@ -129,7 +129,7 @@ class _CheckRunsService extends Service { 'output': output, 'actions': actions, })), - convert: (i) => CheckRun.fromJson(i), + convert: CheckRun.fromJson, ); } @@ -153,7 +153,7 @@ class _CheckRunsService extends Service { return PaginationHelper(github).objects, CheckRun>( 'GET', 'repos/$slug/commits/$ref/check-runs', - (input) => CheckRun.fromJson(input), + CheckRun.fromJson, statusCode: StatusCodes.OK, preview: _previewHeader, params: createNonNullMap({ @@ -184,7 +184,7 @@ class _CheckRunsService extends Service { return PaginationHelper(github).objects, CheckRun>( 'GET', 'repos/$slug/check-suites/$checkSuiteId/check-runs', - (input) => CheckRun.fromJson(input), + CheckRun.fromJson, statusCode: StatusCodes.OK, preview: _previewHeader, params: createNonNullMap({ @@ -210,7 +210,7 @@ class _CheckRunsService extends Service { 'repos/${slug.fullName}/check-runs/$checkRunId', preview: _previewHeader, statusCode: StatusCodes.OK, - convert: (i) => CheckRun.fromJson(i), + convert: CheckRun.fromJson, ); } @@ -227,15 +227,15 @@ class _CheckRunsService extends Service { .objects, CheckRunAnnotation>( 'GET', '/repos/${slug.fullName}/check-runs/${checkRun.id}/annotations', - (i) => CheckRunAnnotation.fromJSON(i), + CheckRunAnnotation.fromJSON, statusCode: StatusCodes.OK, preview: _previewHeader, ); } } -class _CheckSuitesService extends Service { - _CheckSuitesService._(GitHub github) : super(github); +class CheckSuitesService extends Service { + CheckSuitesService._(GitHub github) : super(github); /// Gets a single check suite using its `id`. /// GitHub Apps must have the `checks:read` permission on a private repository or pull access to a public repository to get check suites. @@ -250,7 +250,7 @@ class _CheckSuitesService extends Service { return github.requestJson( 'GET', 'repos/$slug/check-suites/$checkSuiteId', - convert: (dynamic input) => CheckSuite.fromJson(input), + convert: CheckSuite.fromJson, preview: _previewHeader, statusCode: StatusCodes.OK, ); @@ -274,7 +274,7 @@ class _CheckSuitesService extends Service { return PaginationHelper(github).objects, CheckSuite>( 'GET', 'repos/$slug/commits/$ref/check-suites', - (input) => CheckSuite.fromJson(input), + CheckSuite.fromJson, preview: _previewHeader, params: createNonNullMap({ 'app_id': appId, @@ -304,7 +304,8 @@ class _CheckSuitesService extends Service { preview: _previewHeader, body: {'auto_trigger_checks': autoTriggerChecks}, convert: (input) => (input['preferences']['auto_trigger_checks'] as List) - .map((e) => AutoTriggerChecks.fromJson(e)) + .cast>() + .map(AutoTriggerChecks.fromJson) .toList(), ); } @@ -326,7 +327,7 @@ class _CheckSuitesService extends Service { statusCode: StatusCodes.CREATED, preview: _previewHeader, params: {'head_sha': headSha}, - convert: (input) => CheckSuite.fromJson(input), + convert: CheckSuite.fromJson, ); } diff --git a/lib/src/common/gists_service.dart b/lib/src/common/gists_service.dart index 9f64717e..9078e03d 100644 --- a/lib/src/common/gists_service.dart +++ b/lib/src/common/gists_service.dart @@ -14,8 +14,8 @@ class GistsService extends Service { /// /// API docs: https://developer.github.com/v3/gists/#list-gists Stream listUserGists(String username) { - return PaginationHelper(github).objects( - 'GET', '/users/$username/gists', (dynamic i) => Gist.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/users/$username/gists', Gist.fromJson); } /// Fetches the gists for the currently authenticated user. @@ -23,8 +23,7 @@ class GistsService extends Service { /// /// API docs: https://developer.github.com/v3/gists/#list-gists Stream listCurrentUserGists() { - return PaginationHelper(github) - .objects('GET', '/gists', (dynamic i) => Gist.fromJson(i)); + return PaginationHelper(github).objects('GET', '/gists', Gist.fromJson); } /// Fetches the currently authenticated user's public gists. @@ -32,7 +31,7 @@ class GistsService extends Service { /// API docs: https://developer.github.com/v3/gists/#list-gists Stream listCurrentUserPublicGists() { return PaginationHelper(github) - .objects('GET', '/gists/public', (dynamic i) => Gist.fromJson(i)); + .objects('GET', '/gists/public', Gist.fromJson); } /// Fetches the currently authenticated user's starred gists. @@ -40,14 +39,14 @@ class GistsService extends Service { /// API docs: https://developer.github.com/v3/gists/#list-gists Stream listCurrentUserStarredGists() { return PaginationHelper(github) - .objects('GET', '/gists/starred', (dynamic i) => Gist.fromJson(i)); + .objects('GET', '/gists/starred', Gist.fromJson); } /// Fetches a Gist by the specified [id]. /// /// API docs: https://developer.github.com/v3/gists/#get-a-single-gist Future getGist(String id) => github.getJSON('/gists/$id', - statusCode: StatusCodes.OK, convert: (dynamic i) => Gist.fromJson(i)); + statusCode: StatusCodes.OK, convert: Gist.fromJson); /// Creates a Gist /// @@ -77,7 +76,7 @@ class GistsService extends Service { '/gists', statusCode: 201, body: GitHubJson.encode(map), - convert: (dynamic i) => Gist.fromJson(i), + convert: Gist.fromJson, ); } @@ -116,7 +115,7 @@ class GistsService extends Service { '/gists/$id', statusCode: 200, body: GitHubJson.encode(map), - convert: (dynamic i) => Gist.fromJson(i), + convert: Gist.fromJson, ); } @@ -166,8 +165,8 @@ class GistsService extends Service { /// /// API docs: https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist Stream listComments(String gistId) { - return PaginationHelper(github).objects('GET', '/gists/$gistId/comments', - (dynamic i) => GistComment.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/gists/$gistId/comments', GistComment.fromJson); } // TODO: Implement getComment: https://developer.github.com/v3/gists/comments/#get-a-single-comment @@ -177,8 +176,7 @@ class GistsService extends Service { /// API docs: https://developer.github.com/v3/gists/comments/#create-a-comment Future createComment(String gistId, CreateGistComment request) { return github.postJSON('/gists/$gistId/comments', - body: GitHubJson.encode(request), - convert: (dynamic i) => GistComment.fromJson(i)); + body: GitHubJson.encode(request), convert: GistComment.fromJson); } // TODO: Implement editComment: https://developer.github.com/v3/gists/comments/#edit-a-comment diff --git a/lib/src/common/git_service.dart b/lib/src/common/git_service.dart index 1165eeb0..7052e4f6 100644 --- a/lib/src/common/git_service.dart +++ b/lib/src/common/git_service.dart @@ -15,15 +15,14 @@ class GitService extends Service { /// API docs: https://developer.github.com/v3/git/blobs/#get-a-blob Future getBlob(RepositorySlug slug, String? sha) => github.getJSON('/repos/${slug.fullName}/git/blobs/$sha', - convert: (dynamic i) => GitBlob.fromJson(i), - statusCode: StatusCodes.OK); + convert: GitBlob.fromJson, statusCode: StatusCodes.OK); /// Creates a blob with specified [blob] content. /// /// API docs: https://developer.github.com/v3/git/blobs/#create-a-blob Future createBlob(RepositorySlug slug, CreateGitBlob blob) { return github.postJSON('/repos/${slug.fullName}/git/blobs', - convert: (dynamic i) => GitBlob.fromJson(i), + convert: GitBlob.fromJson, statusCode: StatusCodes.CREATED, body: GitHubJson.encode(blob)); } @@ -33,15 +32,14 @@ class GitService extends Service { /// API docs: https://developer.github.com/v3/git/commits/#get-a-commit Future getCommit(RepositorySlug slug, String? sha) => github.getJSON('/repos/${slug.fullName}/git/commits/$sha', - convert: (dynamic i) => GitCommit.fromJson(i), - statusCode: StatusCodes.OK); + convert: GitCommit.fromJson, statusCode: StatusCodes.OK); /// Creates a new commit in a repository. /// /// API docs: https://developer.github.com/v3/git/commits/#create-a-commit Future createCommit(RepositorySlug slug, CreateGitCommit commit) { return github.postJSON('/repos/${slug.fullName}/git/commits', - convert: (dynamic i) => GitCommit.fromJson(i), + convert: GitCommit.fromJson, statusCode: StatusCodes.CREATED, body: GitHubJson.encode(commit)); } @@ -53,8 +51,7 @@ class GitService extends Service { /// API docs: https://developer.github.com/v3/git/refs/#get-a-reference Future getReference(RepositorySlug slug, String ref) => github.getJSON('/repos/${slug.fullName}/git/refs/$ref', - convert: (dynamic i) => GitReference.fromJson(i), - statusCode: StatusCodes.OK); + convert: GitReference.fromJson, statusCode: StatusCodes.OK); /// Lists the references in a repository. /// @@ -69,8 +66,7 @@ class GitService extends Service { path += '/$type'; } - return PaginationHelper(github) - .objects('GET', path, (dynamic i) => GitReference.fromJson(i)); + return PaginationHelper(github).objects('GET', path, GitReference.fromJson); } /// Creates a new reference in a repository. @@ -82,7 +78,7 @@ class GitService extends Service { Future createReference( RepositorySlug slug, String ref, String? sha) { return github.postJSON('/repos/${slug.fullName}/git/refs', - convert: (dynamic i) => GitReference.fromJson(i), + convert: GitReference.fromJson, statusCode: StatusCodes.CREATED, body: GitHubJson.encode({'ref': ref, 'sha': sha})); } @@ -123,15 +119,14 @@ class GitService extends Service { /// API docs: https://developer.github.com/v3/git/tags/#get-a-tag Future getTag(RepositorySlug slug, String? sha) => github.getJSON('/repos/${slug.fullName}/git/tags/$sha', - convert: (dynamic i) => GitTag.fromJson(i), - statusCode: StatusCodes.OK); + convert: GitTag.fromJson, statusCode: StatusCodes.OK); /// Creates a new tag in a repository. /// /// API docs: https://developer.github.com/v3/git/tags/#create-a-tag-object Future createTag(RepositorySlug slug, CreateGitTag tag) => github.postJSON('/repos/${slug.fullName}/git/tags', - convert: (dynamic i) => GitTag.fromJson(i), + convert: GitTag.fromJson, statusCode: StatusCodes.CREATED, body: GitHubJson.encode(tag)); @@ -149,8 +144,7 @@ class GitService extends Service { } return github.getJSON(path, - convert: (dynamic j) => GitTree.fromJson(j), - statusCode: StatusCodes.OK); + convert: GitTree.fromJson, statusCode: StatusCodes.OK); } /// Creates a new tree in a repository. @@ -158,7 +152,7 @@ class GitService extends Service { /// API docs: https://developer.github.com/v3/git/trees/#create-a-tree Future createTree(RepositorySlug slug, CreateGitTree tree) { return github.postJSON('/repos/${slug.fullName}/git/trees', - convert: (dynamic j) => GitTree.fromJson(j), + convert: GitTree.fromJson, statusCode: StatusCodes.CREATED, body: GitHubJson.encode(tree)); } diff --git a/lib/src/common/github.dart b/lib/src/common/github.dart index 77864725..fdfbdc1c 100644 --- a/lib/src/common/github.dart +++ b/lib/src/common/github.dart @@ -333,7 +333,7 @@ class GitHub { final json = jsonDecode(response.body); - final T returnValue = convert(json)!; + final returnValue = convert(json) as T; _applyExpandos(returnValue, response); return returnValue; } @@ -424,15 +424,12 @@ class GitHub { } else { return response; } - - throw UnknownError(this); } /// /// Internal method to handle status codes /// - @alwaysThrows - void handleStatusCode(http.Response response) { + Never handleStatusCode(http.Response response) { print(response.body); String? message = ''; List>? errors; diff --git a/lib/src/common/issues_service.dart b/lib/src/common/issues_service.dart index b20d809a..490396fb 100644 --- a/lib/src/common/issues_service.dart +++ b/lib/src/common/issues_service.dart @@ -123,7 +123,7 @@ class IssuesService extends Service { return PaginationHelper(github).objects( 'GET', pathSegment, - (dynamic i) => Issue.fromJson(i), + Issue.fromJson, params: params, ); } @@ -144,7 +144,7 @@ class IssuesService extends Service { return PaginationHelper(github).objects( 'GET', '/repos/${slug.owner}/${slug.name}/issues/$issueNumber/reactions$query', - (dynamic i) => Reaction.fromJson(i), + Reaction.fromJson, headers: { 'Accept': 'application/vnd.github.squirrel-girl-preview+json', }, @@ -169,7 +169,7 @@ class IssuesService extends Service { /// API docs: https://developer.github.com/v3/issues/#get-a-single-issue Future get(RepositorySlug slug, int issueNumber) => github.getJSON('/repos/${slug.fullName}/issues/$issueNumber', - convert: (dynamic i) => Issue.fromJson(i)); + convert: Issue.fromJson); /// Create an issue. /// @@ -194,8 +194,8 @@ class IssuesService extends Service { /// /// API docs: https://developer.github.com/v3/issues/assignees/#list-assignees Stream listAssignees(RepositorySlug slug) { - return PaginationHelper(github).objects('GET', - '/repos/${slug.fullName}/assignees', (dynamic i) => User.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/repos/${slug.fullName}/assignees', User.fromJson); } /// Checks if a user is an assignee for the specified repository. @@ -215,17 +215,15 @@ class IssuesService extends Service { return PaginationHelper(github).objects( 'GET', '/repos/${slug.fullName}/issues/$issueNumber/comments', - (dynamic i) => IssueComment.fromJson(i)); + IssueComment.fromJson); } /// Lists all comments in a repository. /// /// API docs: https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue Stream listCommentsByRepo(RepositorySlug slug) { - return PaginationHelper(github).objects( - 'GET', - '/repos/${slug.fullName}/issues/comments', - (dynamic i) => IssueComment.fromJson(i)); + return PaginationHelper(github).objects('GET', + '/repos/${slug.fullName}/issues/comments', IssueComment.fromJson); } /// Fetches the specified issue comment. @@ -233,7 +231,7 @@ class IssuesService extends Service { /// API docs: https://developer.github.com/v3/issues/comments/#get-a-single-comment Future getComment(RepositorySlug slug, int id) => github.getJSON('/repos/${slug.fullName}/issues/comments/$id', - convert: (dynamic i) => IssueComment.fromJson(i)); + convert: IssueComment.fromJson); /// Creates a new comment on the specified issue /// @@ -244,7 +242,7 @@ class IssuesService extends Service { return github.postJSON( '/repos/${slug.fullName}/issues/$issueNumber/comments', body: it, - convert: (dynamic i) => IssueComment.fromJson(i), + convert: IssueComment.fromJson, statusCode: StatusCodes.CREATED, ); } @@ -257,7 +255,7 @@ class IssuesService extends Service { return github.postJSON( '/repos/${slug.fullName}/issues/comments/$id', body: it, - convert: (dynamic i) => IssueComment.fromJson(i), + convert: IssueComment.fromJson, statusCode: StatusCodes.OK, ); } @@ -277,10 +275,8 @@ class IssuesService extends Service { /// /// API docs: https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository Stream listLabels(RepositorySlug slug) { - return PaginationHelper(github).objects( - 'GET', - '/repos/${slug.fullName}/labels', - (dynamic i) => IssueLabel.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/repos/${slug.fullName}/labels', IssueLabel.fromJson); } /// Fetches a single label. @@ -288,8 +284,7 @@ class IssuesService extends Service { /// API docs: https://developer.github.com/v3/issues/labels/#get-a-single-label Future getLabel(RepositorySlug slug, String name) => github.getJSON('/repos/${slug.fullName}/labels/$name', - convert: (dynamic i) => IssueLabel.fromJson(i), - statusCode: StatusCodes.OK); + convert: IssueLabel.fromJson, statusCode: StatusCodes.OK); /// Creates a new label on the specified repository. /// @@ -298,7 +293,7 @@ class IssuesService extends Service { RepositorySlug slug, String name, String color) { return github.postJSON('/repos/${slug.fullName}/labels', body: GitHubJson.encode({'name': name, 'color': color}), - convert: (dynamic i) => IssueLabel.fromJson(i)); + convert: IssueLabel.fromJson); } /// Edits a label. @@ -307,7 +302,7 @@ class IssuesService extends Service { Future editLabel(RepositorySlug slug, String name, String color) { return github.postJSON('/repos/${slug.fullName}/labels/$name', body: GitHubJson.encode({'name': name, 'color': color}), - convert: (dynamic i) => IssueLabel.fromJson(i)); + convert: IssueLabel.fromJson); } /// Deletes a label. @@ -327,7 +322,7 @@ class IssuesService extends Service { return PaginationHelper(github).objects( 'GET', '/repos/${slug.fullName}/issues/$issueNumber/labels', - (dynamic i) => IssueLabel.fromJson(i)); + IssueLabel.fromJson); } /// Adds labels to an issue. @@ -338,10 +333,8 @@ class IssuesService extends Service { return github.postJSON, List>( '/repos/${slug.fullName}/issues/$issueNumber/labels', body: GitHubJson.encode(labels), - convert: (input) => input - .cast>() - .map((i) => IssueLabel.fromJson(i)) - .toList(), + convert: (input) => + input.cast>().map(IssueLabel.fromJson).toList(), ); } @@ -354,8 +347,7 @@ class IssuesService extends Service { .request('PUT', '/repos/${slug.fullName}/issues/$issueNumber/labels', body: GitHubJson.encode(labels)) .then((response) { - return jsonDecode(response.body) - .map((Map it) => IssueLabel.fromJson(it)); + return jsonDecode(response.body).map(IssueLabel.fromJson); }); } @@ -386,9 +378,7 @@ class IssuesService extends Service { /// API docs: https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository Stream listMilestones(RepositorySlug slug) { return PaginationHelper(github).objects( - 'GET', - '/repos/${slug.fullName}/milestones', - (dynamic i) => Milestone.fromJson(i)); + 'GET', '/repos/${slug.fullName}/milestones', Milestone.fromJson); } // TODO: Implement getMilestone: https://developer.github.com/v3/issues/milestones/#get-a-single-milestone @@ -399,8 +389,7 @@ class IssuesService extends Service { Future createMilestone( RepositorySlug slug, CreateMilestone request) { return github.postJSON('/repos/${slug.fullName}/milestones', - body: GitHubJson.encode(request), - convert: (dynamic i) => Milestone.fromJson(i)); + body: GitHubJson.encode(request), convert: Milestone.fromJson); } // TODO: Implement editMilestone: https://developer.github.com/v3/issues/milestones/#update-a-milestone diff --git a/lib/src/common/misc_service.dart b/lib/src/common/misc_service.dart index f34a7964..4951848f 100644 --- a/lib/src/common/misc_service.dart +++ b/lib/src/common/misc_service.dart @@ -35,7 +35,7 @@ class MiscService extends Service { /// API docs: https://developer.github.com/v3/gitignore/#get-a-single-template Future getGitignoreTemplate(String name) => github.getJSON('/gitignore/templates/$name', - convert: (dynamic i) => GitignoreTemplate.fromJson(i)); + convert: GitignoreTemplate.fromJson); /// Renders Markdown from the [input]. /// @@ -70,8 +70,7 @@ class MiscService extends Service { /// Gets the GitHub API Status. Future getApiStatus() => github.getJSON('https://status.github.com/api/status.json', - statusCode: StatusCodes.OK, - convert: (dynamic i) => APIStatus.fromJson(i)); + statusCode: StatusCodes.OK, convert: APIStatus.fromJson); /// Returns an ASCII Octocat with the specified [text]. Future getOctocat([String? text]) { diff --git a/lib/src/common/model/users.dart b/lib/src/common/model/users.dart index 766f6185..8044983a 100644 --- a/lib/src/common/model/users.dart +++ b/lib/src/common/model/users.dart @@ -26,7 +26,7 @@ class User { this.updatedAt, }); - @JsonKey(ignore: true) + @JsonKey(includeToJson: false, includeFromJson: false) Map? json; // TODO remove /// User's Username diff --git a/lib/src/common/orgs_service.dart b/lib/src/common/orgs_service.dart index f72f93b1..c0774bda 100644 --- a/lib/src/common/orgs_service.dart +++ b/lib/src/common/orgs_service.dart @@ -22,16 +22,15 @@ class OrganizationsService extends Service { requestPath = '/user/orgs'; } return PaginationHelper(github) - .objects('GET', requestPath, (dynamic i) => Organization.fromJson(i)); + .objects('GET', requestPath, Organization.fromJson); } /// Fetches the organization specified by [name]. /// /// API docs: https://developer.github.com/v3/orgs/#get-an-organization Future get(String? name) => github.getJSON('/orgs/$name', - convert: (dynamic i) => Organization.fromJson(i), - statusCode: StatusCodes.OK, - fail: (http.Response response) { + convert: Organization.fromJson, + statusCode: StatusCodes.OK, fail: (http.Response response) { if (response.statusCode == 404) { throw OrganizationNotFound(github, name); } @@ -66,7 +65,7 @@ class OrganizationsService extends Service { return github.postJSON('/orgs/$org', statusCode: 200, - convert: (dynamic i) => Organization.fromJson(i), + convert: Organization.fromJson, body: GitHubJson.encode(map)); } @@ -74,8 +73,8 @@ class OrganizationsService extends Service { /// /// API docs: https://developer.github.com/v3/orgs/teams/#list-teams Stream listTeams(String orgName) { - return PaginationHelper(github).objects( - 'GET', '/orgs/$orgName/teams', (dynamic i) => Team.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/orgs/$orgName/teams', Team.fromJson); } /// Gets the team specified by the [teamId]. @@ -83,8 +82,7 @@ class OrganizationsService extends Service { /// API docs: https://developer.github.com/v3/orgs/teams/#get-team Future getTeam(int teamId) { return github.getJSON('/teams/$teamId', - convert: (dynamic i) => Organization.fromJson(i), - statusCode: 200) as Future; + convert: Organization.fromJson, statusCode: 200) as Future; } /// Creates a Team. @@ -100,9 +98,7 @@ class OrganizationsService extends Service { }); return github.postJSON('/orgs/$org/teams', - statusCode: 201, - convert: (dynamic i) => Team.fromJson(i), - body: GitHubJson.encode(map)); + statusCode: 201, convert: Team.fromJson, body: GitHubJson.encode(map)); } /// Edits a Team. @@ -119,7 +115,7 @@ class OrganizationsService extends Service { return github.postJSON( '/teams/$teamId', statusCode: 200, - convert: (dynamic i) => Team.fromJson(i), + convert: Team.fromJson, body: GitHubJson.encode(map), ); } @@ -137,8 +133,8 @@ class OrganizationsService extends Service { /// /// API docs: https://developer.github.com/v3/orgs/teams/#list-team-members Stream listTeamMembers(int teamId) { - return PaginationHelper(github).objects( - 'GET', '/teams/$teamId/members', (dynamic i) => TeamMember.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/teams/$teamId/members', TeamMember.fromJson); } Future getTeamMemberStatus(int teamId, String user) { @@ -192,8 +188,8 @@ class OrganizationsService extends Service { /// /// API docs: https://developer.github.com/v3/orgs/teams/#list-team-repos Stream listTeamRepositories(int teamId) { - return PaginationHelper(github).objects( - 'GET', '/teams/$teamId/repos', (dynamic i) => Repository.fromJson(i)); + return PaginationHelper(github) + .objects('GET', '/teams/$teamId/repos', Repository.fromJson); } /// Checks if a team manages the specified repository. @@ -234,7 +230,7 @@ class OrganizationsService extends Service { /// API docs: https://developer.github.com/v3/orgs/teams/#list-user-teams Stream listUserTeams() { return PaginationHelper(github) - .objects('GET', '/user/teams', (dynamic i) => Team.fromJson(i)); + .objects('GET', '/user/teams', Team.fromJson); } /// Lists all of the users in an organization @@ -242,7 +238,7 @@ class OrganizationsService extends Service { /// API docs: https://developer.github.com/v3/orgs/teams/#list-user-teams Stream listUsers(String org) { return PaginationHelper(github) - .objects('GET', '/orgs/$org/members', (dynamic i) => User.fromJson(i)); + .objects('GET', '/orgs/$org/members', User.fromJson); } /// Lists the hooks for the specified organization. diff --git a/lib/src/common/pulls_service.dart b/lib/src/common/pulls_service.dart index f0ec3dcc..5242f0e3 100644 --- a/lib/src/common/pulls_service.dart +++ b/lib/src/common/pulls_service.dart @@ -29,8 +29,8 @@ class PullRequestsService extends Service { putValue('sort', sort, params); putValue('state', state, params); - return PaginationHelper(github).objects('GET', - '/repos/${slug.fullName}/pulls', (dynamic i) => PullRequest.fromJson(i), + return PaginationHelper(github).objects( + 'GET', '/repos/${slug.fullName}/pulls', PullRequest.fromJson, pages: pages, params: params); } @@ -39,8 +39,7 @@ class PullRequestsService extends Service { /// API docs: https://developer.github.com/v3/pulls/#get-a-single-pull-request Future get(RepositorySlug slug, int number) => github.getJSON('/repos/${slug.fullName}/pulls/$number', - convert: (dynamic i) => PullRequest.fromJson(i), - statusCode: StatusCodes.OK); + convert: PullRequest.fromJson, statusCode: StatusCodes.OK); /// Creates a Pull Request based on the given [request]. /// @@ -48,7 +47,7 @@ class PullRequestsService extends Service { Future create(RepositorySlug slug, CreatePullRequest request) { return github.postJSON( '/repos/${slug.fullName}/pulls', - convert: (dynamic i) => PullRequest.fromJson(i), + convert: PullRequest.fromJson, body: GitHubJson.encode(request), preview: request.draft! ? 'application/vnd.github.shadow-cat-preview+json' @@ -83,7 +82,7 @@ class PullRequestsService extends Service { return PaginationHelper(github).objects( 'GET', '/repos/${slug.fullName}/pulls/$number/commits', - (dynamic i) => RepositoryCommit.fromJson(i)); + RepositoryCommit.fromJson); } /// Lists the files in a pull request. @@ -93,7 +92,7 @@ class PullRequestsService extends Service { return PaginationHelper(github).objects( 'GET', '/repos/${slug.fullName}/pulls/$number/files', - (dynamic i) => PullRequestFile.fromJson(i)); + PullRequestFile.fromJson); } /// Lists the reviews for a pull request. @@ -103,7 +102,7 @@ class PullRequestsService extends Service { return PaginationHelper(github).objects( 'GET', '/repos/${slug.fullName}/pulls/$number/reviews', - (dynamic i) => PullRequestReview.fromJson(i)); + PullRequestReview.fromJson); } Future isMerged(RepositorySlug slug, int number) { @@ -156,17 +155,15 @@ class PullRequestsService extends Service { return PaginationHelper(github).objects( 'GET', '/repos/${slug.fullName}/pulls/$number/comments', - (dynamic i) => PullRequestComment.fromJson(i)); + PullRequestComment.fromJson); } /// Lists all comments on all pull requests for the repository. /// /// API docs: https://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository Stream listComments(RepositorySlug slug) { - return PaginationHelper(github).objects( - 'GET', - '/repos/${slug.fullName}/pulls/comments', - (dynamic i) => PullRequestComment.fromJson(i)); + return PaginationHelper(github).objects('GET', + '/repos/${slug.fullName}/pulls/comments', PullRequestComment.fromJson); } /// Creates a new pull request comment. @@ -176,7 +173,7 @@ class PullRequestsService extends Service { RepositorySlug slug, int number, CreatePullRequestComment comment) { return github.postJSON('/repos/${slug.fullName}/pulls/$number/comments', body: GitHubJson.encode(comment.toJson()), - convert: (dynamic i) => PullRequestComment.fromJson(i), + convert: PullRequestComment.fromJson, statusCode: 201); } @@ -191,7 +188,7 @@ class PullRequestsService extends Service { return github.postJSON( '/repos/${slug.fullName}/pulls/${review.pullNumber}/reviews', body: GitHubJson.encode(review), - convert: (dynamic i) => PullRequestReview.fromJson(i), + convert: PullRequestReview.fromJson, ); } } diff --git a/lib/src/common/repos_service.dart b/lib/src/common/repos_service.dart index a3a73531..535e1060 100644 --- a/lib/src/common/repos_service.dart +++ b/lib/src/common/repos_service.dart @@ -27,7 +27,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, Repository>( 'GET', '/user/repos', - (i) => Repository.fromJson(i), + Repository.fromJson, params: params, ); } @@ -49,7 +49,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, Repository>( 'GET', '/users/$user/repos', - (i) => Repository.fromJson(i), + Repository.fromJson, params: params, ); } @@ -65,7 +65,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, Repository>( 'GET', '/orgs/$org/repos', - (i) => Repository.fromJson(i), + Repository.fromJson, params: params, ); } @@ -91,7 +91,7 @@ class RepositoriesService extends Service { .expand((http.Response response) { final list = jsonDecode(response.body) as List>; - return list.map((Map it) => Repository.fromJson(it)); + return list.map(Repository.fromJson); }); } @@ -107,13 +107,13 @@ class RepositoriesService extends Service { return github.postJSON, Repository>( '/orgs/$org/repos', body: GitHubJson.encode(repository), - convert: (i) => Repository.fromJson(i), + convert: Repository.fromJson, ); } else { return github.postJSON, Repository>( '/user/repos', body: GitHubJson.encode(repository), - convert: (i) => Repository.fromJson(i), + convert: Repository.fromJson, ); } } @@ -122,7 +122,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(slug); return github.getJSON, LicenseDetails>( '/repos/${slug.owner}/${slug.name}/license', - convert: (json) => LicenseDetails.fromJson(json), + convert: LicenseDetails.fromJson, ); } @@ -133,7 +133,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(slug); return github.getJSON, Repository>( '/repos/${slug.owner}/${slug.name}', - convert: (i) => Repository.fromJson(i), + convert: Repository.fromJson, statusCode: StatusCodes.OK, fail: (http.Response response) { if (response.statusCode == 404) { @@ -206,7 +206,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, Contributor>( 'GET', '/repos/${slug.fullName}/contributors', - (i) => Contributor.fromJson(i), + Contributor.fromJson, params: {'anon': anon.toString()}, ); } @@ -219,7 +219,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, Team>( 'GET', '/repos/${slug.fullName}/teams', - (i) => Team.fromJson(i), + Team.fromJson, ); } @@ -242,7 +242,7 @@ class RepositoriesService extends Service { {int page = 1, int? pages, int perPage = 30}) { ArgumentError.checkNotNull(slug); return PaginationHelper(github).objects, Tag>( - 'GET', '/repos/${slug.fullName}/tags', (i) => Tag.fromJson(i), + 'GET', '/repos/${slug.fullName}/tags', Tag.fromJson, pages: pages, params: {'page': page, 'per_page': perPage}); } @@ -254,7 +254,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, Branch>( 'GET', '/repos/${slug.fullName}/branches', - (i) => Branch.fromJson(i), + Branch.fromJson, ); } @@ -266,7 +266,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(branch); return github.getJSON, Branch>( '/repos/${slug.fullName}/branches/$branch', - convert: (i) => Branch.fromJson(i), + convert: Branch.fromJson, ); } @@ -278,7 +278,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, Collaborator>( 'GET', '/repos/${slug.fullName}/collaborators', - (json) => Collaborator.fromJson(json), + Collaborator.fromJson, ); } @@ -346,7 +346,7 @@ class RepositoriesService extends Service { .objects, CommitComment>( 'GET', '/repos/${slug.fullName}/commits/${commit.sha}/comments', - (i) => CommitComment.fromJson(i), + CommitComment.fromJson, statusCode: StatusCodes.OK, ); } @@ -360,7 +360,7 @@ class RepositoriesService extends Service { .objects, CommitComment>( 'GET', 'repos/${slug.fullName}/comments', - (i) => CommitComment.fromJson(i), + CommitComment.fromJson, statusCode: StatusCodes.OK, ); } @@ -392,7 +392,7 @@ class RepositoriesService extends Service { '/repos/${slug.fullName}/commits/${commit.sha}/comments', body: GitHubJson.encode(data), statusCode: StatusCodes.CREATED, - convert: (i) => CommitComment.fromJson(i), + convert: CommitComment.fromJson, ); } @@ -406,7 +406,7 @@ class RepositoriesService extends Service { return github.getJSON, CommitComment>( '/repos/${slug.fullName}/comments/$id', statusCode: StatusCodes.OK, - convert: (i) => CommitComment.fromJson(i), + convert: CommitComment.fromJson, ); } @@ -426,7 +426,7 @@ class RepositoriesService extends Service { '/repos/${slug.fullName}/comments/$id', body: GitHubJson.encode(createNonNullMap({'body': body})), statusCode: StatusCodes.OK, - convert: (i) => CommitComment.fromJson(i), + convert: CommitComment.fromJson, ); } @@ -455,7 +455,7 @@ class RepositoriesService extends Service { .objects, RepositoryCommit>( 'GET', '/repos/${slug.fullName}/commits', - (i) => RepositoryCommit.fromJson(i), + RepositoryCommit.fromJson, ); } @@ -467,7 +467,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(sha); return github.getJSON, RepositoryCommit>( '/repos/${slug.fullName}/commits/$sha', - convert: (i) => RepositoryCommit.fromJson(i), + convert: RepositoryCommit.fromJson, statusCode: StatusCodes.OK, ); } @@ -501,7 +501,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(refHead); return github.getJSON, GitHubComparison>( '/repos/${slug.fullName}/compare/$refBase...$refHead', - convert: (j) => GitHubComparison.fromJson(j), + convert: GitHubComparison.fromJson, ); } @@ -572,8 +572,10 @@ class RepositoriesService extends Service { } contents.file = GitHubFile.fromJson(input as Map); } else { - contents.tree = - (input as List).map((it) => GitHubFile.fromJson(it)).toList(); + contents.tree = (input as List) + .cast>() + .map(GitHubFile.fromJson) + .toList(); } return contents; }, @@ -662,7 +664,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, Repository>( 'GET', '/repos/${slug.fullName}/forks', - (i) => Repository.fromJson(i), + Repository.fromJson, ); } @@ -675,7 +677,7 @@ class RepositoriesService extends Service { return github.postJSON, Repository>( '/repos/${slug.fullName}/forks', body: GitHubJson.encode(fork), - convert: (i) => Repository.fromJson(i), + convert: Repository.fromJson, ); } @@ -820,7 +822,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, PublicKey>( 'GET', '/repos/${slug.fullName}/keys', - (i) => PublicKey.fromJson(i), + PublicKey.fromJson, ); } @@ -834,7 +836,7 @@ class RepositoriesService extends Service { return github.getJSON, PublicKey>( '/repos/${slug.fullName}/keys/$id', statusCode: StatusCodes.OK, - convert: (i) => PublicKey.fromJson(i), + convert: PublicKey.fromJson, ); } @@ -849,7 +851,7 @@ class RepositoriesService extends Service { '/repos/${slug.fullName}/keys', body: GitHubJson.encode(key), statusCode: StatusCodes.CREATED, - convert: (i) => PublicKey.fromJson(i), + convert: PublicKey.fromJson, ); } @@ -878,7 +880,7 @@ class RepositoriesService extends Service { return github.postJSON, RepositoryCommit>( '/repos/${slug.fullName}/merges', body: GitHubJson.encode(merge), - convert: (i) => RepositoryCommit.fromJson(i), + convert: RepositoryCommit.fromJson, statusCode: StatusCodes.CREATED, ); } @@ -891,7 +893,7 @@ class RepositoriesService extends Service { return github.getJSON, RepositoryPages>( '/repos/${slug.fullName}/pages', statusCode: StatusCodes.OK, - convert: (i) => RepositoryPages.fromJson(i), + convert: RepositoryPages.fromJson, ); } @@ -903,7 +905,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, PageBuild>( 'GET', '/repos/${slug.fullName}/pages/builds', - (i) => PageBuild.fromJson(i), + PageBuild.fromJson, statusCode: StatusCodes.OK, ); } @@ -915,7 +917,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(slug); return github.getJSON( '/repos/${slug.fullName}/pages/builds/latest', - convert: (dynamic i) => PageBuild.fromJson(i), + convert: PageBuild.fromJson, statusCode: StatusCodes.OK, ); } @@ -930,7 +932,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, Release>( 'GET', '/repos/${slug.fullName}/releases', - (i) => Release.fromJson(i), + Release.fromJson, ); } @@ -941,7 +943,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(slug); return github.getJSON, Release>( '/repos/${slug.fullName}/releases/latest', - convert: (i) => Release.fromJson(i), + convert: Release.fromJson, statusCode: StatusCodes.OK, ); } @@ -954,7 +956,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(id); return github.getJSON, Release>( '/repos/${slug.fullName}/releases/$id', - convert: (i) => Release.fromJson(i), + convert: Release.fromJson, ); } @@ -968,7 +970,7 @@ class RepositoriesService extends Service { RepositorySlug slug, String? tagName) async { return github.getJSON( '/repos/${slug.fullName}/releases/tags/$tagName', - convert: (dynamic i) => Release.fromJson(i), + convert: Release.fromJson, statusCode: StatusCodes.OK, fail: (http.Response response) { if (response.statusCode == 404) { @@ -992,7 +994,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(createRelease); final release = await github.postJSON, Release>( '/repos/${slug.fullName}/releases', - convert: (i) => Release.fromJson(i), + convert: Release.fromJson, body: GitHubJson.encode(createRelease.toJson()), statusCode: StatusCodes.CREATED); if (release.hasErrors) { @@ -1052,7 +1054,7 @@ class RepositoriesService extends Service { 'prerelease': preRelease ?? releaseToEdit.isPrerelease, })), statusCode: StatusCodes.OK, - convert: (i) => Release.fromJson(i), + convert: Release.fromJson, ); } @@ -1080,7 +1082,7 @@ class RepositoriesService extends Service { return PaginationHelper(github).objects, ReleaseAsset>( 'GET', '/repos/${slug.fullName}/releases/${release.id}/assets', - (i) => ReleaseAsset.fromJson(i), + ReleaseAsset.fromJson, statusCode: StatusCodes.OK, ); } @@ -1096,7 +1098,7 @@ class RepositoriesService extends Service { return github.postJSON, ReleaseAsset>( '/repos/${slug.fullName}/releases/assets/$assetId', statusCode: StatusCodes.OK, - convert: (i) => ReleaseAsset.fromJson(i), + convert: ReleaseAsset.fromJson, ); } @@ -1114,7 +1116,7 @@ class RepositoriesService extends Service { return github.postJSON, ReleaseAsset>( '/repos/${slug.fullName}/releases/assets/${assetToEdit.id}', statusCode: StatusCodes.OK, - convert: (i) => ReleaseAsset.fromJson(i), + convert: ReleaseAsset.fromJson, body: GitHubJson.encode(createNonNullMap({ 'name': name ?? assetToEdit.name, 'label': label ?? assetToEdit.label, @@ -1152,7 +1154,7 @@ class RepositoriesService extends Service { ), headers: headers, body: createReleaseAsset.assetData, - convert: (dynamic i) => ReleaseAsset.fromJson(i)); + convert: ReleaseAsset.fromJson); releaseAssets.add(releaseAsset); } return releaseAssets; @@ -1174,13 +1176,13 @@ class RepositoriesService extends Service { if (response.statusCode == StatusCodes.OK) { return (jsonDecode(response.body) as List) - .map((e) => ContributorStatistics.fromJson(e)) + .cast>() + .map(ContributorStatistics.fromJson) .toList(); } else if (response.statusCode == StatusCodes.ACCEPTED) { throw NotReady(github, path); } github.handleStatusCode(response); - throw UnknownError(github); } /// Fetches commit counts for the past year. @@ -1192,7 +1194,7 @@ class RepositoriesService extends Service { .objects, YearCommitCountWeek>( 'GET', '/repos/${slug.fullName}/stats/commit_activity', - (i) => YearCommitCountWeek.fromJson(i), + YearCommitCountWeek.fromJson, ); } @@ -1205,7 +1207,7 @@ class RepositoriesService extends Service { .objects, WeeklyChangesCount>( 'GET', '/repos/${slug.fullName}/stats/code_frequency', - (i) => WeeklyChangesCount.fromJson(i), + WeeklyChangesCount.fromJson, ); } @@ -1217,7 +1219,7 @@ class RepositoriesService extends Service { return github.getJSON( '/repos/${slug.fullName}/stats/participation', statusCode: StatusCodes.OK, - convert: (dynamic i) => ContributorParticipation.fromJson(i), + convert: ContributorParticipation.fromJson, ); } @@ -1230,7 +1232,7 @@ class RepositoriesService extends Service { .objects, PunchcardEntry>( 'GET', '/repos/${slug.fullName}/stats/punchcard', - (i) => PunchcardEntry.fromJson(i), + PunchcardEntry.fromJson, ); } @@ -1245,7 +1247,7 @@ class RepositoriesService extends Service { .objects, RepositoryStatus>( 'GET', '/repos/${slug.fullName}/commits/$ref/statuses', - (i) => RepositoryStatus.fromJson(i), + RepositoryStatus.fromJson, ); } @@ -1261,7 +1263,7 @@ class RepositoriesService extends Service { return github.postJSON, RepositoryStatus>( '/repos/${slug.fullName}/statuses/$ref', body: GitHubJson.encode(request), - convert: (i) => RepositoryStatus.fromJson(i), + convert: RepositoryStatus.fromJson, ); } @@ -1274,7 +1276,7 @@ class RepositoriesService extends Service { ArgumentError.checkNotNull(ref); return github.getJSON, CombinedRepositoryStatus>( '/repos/${slug.fullName}/commits/$ref/status', - convert: (i) => CombinedRepositoryStatus.fromJson(i), + convert: CombinedRepositoryStatus.fromJson, statusCode: StatusCodes.OK, ); } @@ -1291,7 +1293,7 @@ class RepositoriesService extends Service { '/repos/${crn.owner}/${crn.repo}/releases/generate-notes', body: GitHubJson.encode(crn), statusCode: StatusCodes.OK, - convert: (i) => ReleaseNotes.fromJson(i), + convert: ReleaseNotes.fromJson, ); } } diff --git a/lib/src/common/search_service.dart b/lib/src/common/search_service.dart index e98344a6..bf2b41ec 100644 --- a/lib/src/common/search_service.dart +++ b/lib/src/common/search_service.dart @@ -44,7 +44,10 @@ class SearchService extends Service { final items = input['items'] as List; - items.map((item) => Repository.fromJson(item)).forEach(controller.add); + items + .cast>() + .map(Repository.fromJson) + .forEach(controller.add); }).onDone(controller.close); return controller.stream; @@ -94,19 +97,19 @@ class SearchService extends Service { query += _searchQualifier('size', size); // build up the in: qualifier based on the 2 booleans - var _in = ''; + var inValue = ''; if (inFile) { - _in = 'file'; + inValue = 'file'; } if (inPath) { - if (_in.isEmpty) { - _in = 'path'; + if (inValue.isEmpty) { + inValue = 'path'; } else { - _in = 'file,path'; + inValue = 'file,path'; } } - if (_in.isNotEmpty) { - query += ' in:$_in'; + if (inValue.isNotEmpty) { + query += ' in:$inValue'; } final params = {}; @@ -159,7 +162,10 @@ class SearchService extends Service { final items = input['items'] as List; - items.map((item) => Issue.fromJson(item)).forEach(controller.add); + items + .cast>() + .map(Issue.fromJson) + .forEach(controller.add); }).onDone(controller.close); return controller.stream; @@ -206,7 +212,10 @@ class SearchService extends Service { final items = input['items'] as List; - items.map((item) => User.fromJson(item)).forEach(controller.add); + items + .cast>() + .map(User.fromJson) + .forEach(controller.add); }).onDone(controller.close); return controller.stream; diff --git a/lib/src/common/users_service.dart b/lib/src/common/users_service.dart index 3a469401..bb27ff6d 100644 --- a/lib/src/common/users_service.dart +++ b/lib/src/common/users_service.dart @@ -14,7 +14,7 @@ class UsersService extends Service { /// /// API docs: https://developer.github.com/v3/users/#get-a-single-user Future getUser(String? name) => - github.getJSON('/users/$name', convert: (dynamic i) => User.fromJson(i)); + github.getJSON('/users/$name', convert: User.fromJson); /// Updates the Current User. /// @@ -41,7 +41,7 @@ class UsersService extends Service { '/user', body: GitHubJson.encode(map), statusCode: 200, - convert: (dynamic i) => CurrentUser.fromJson(i), + convert: CurrentUser.fromJson, ); } @@ -58,14 +58,13 @@ class UsersService extends Service { /// Throws [AccessForbidden] if we are not authenticated. /// /// API docs: https://developer.github.com/v3/users/#get-the-authenticated-user - Future getCurrentUser() => github.getJSON('/user', - statusCode: StatusCodes.OK, - fail: (http.Response response) { + Future getCurrentUser() => + github.getJSON('/user', statusCode: StatusCodes.OK, + fail: (http.Response response) { if (response.statusCode == StatusCodes.FORBIDDEN) { throw AccessForbidden(github); } - }, - convert: (dynamic i) => CurrentUser.fromJson(i)); + }, convert: CurrentUser.fromJson); /// Checks if a user exists. Future isUser(String name) => github @@ -77,21 +76,21 @@ class UsersService extends Service { /// Lists all users. /// /// API docs: https://developer.github.com/v3/users/#get-all-users - Stream listUsers({int? pages, int? since}) => PaginationHelper(github) - .objects('GET', '/users', (dynamic i) => User.fromJson(i), + Stream listUsers({int? pages, int? since}) => + PaginationHelper(github).objects('GET', '/users', User.fromJson, pages: pages, params: {'since': since}); /// Lists all email addresses for the currently authenticated user. /// /// API docs: https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user Stream listEmails() => PaginationHelper(github) - .objects('GET', '/user/emails', (dynamic i) => UserEmail.fromJson(i)); + .objects('GET', '/user/emails', UserEmail.fromJson); /// Add Emails /// /// API docs: https://developer.github.com/v3/users/emails/#add-email-addresses Stream addEmails(List emails) => PaginationHelper(github) - .objects('POST', '/user/emails', (dynamic i) => UserEmail.fromJson(i), + .objects('POST', '/user/emails', UserEmail.fromJson, statusCode: 201, body: GitHubJson.encode(emails)); /// Delete Emails @@ -106,8 +105,7 @@ class UsersService extends Service { /// /// API docs: https://developer.github.com/v3/users/followers/#list-followers-of-a-user Stream listUserFollowers(String user) => PaginationHelper(github) - .objects('GET', '/users/$user/followers', (dynamic i) => User.fromJson(i), - statusCode: 200); + .objects('GET', '/users/$user/followers', User.fromJson, statusCode: 200); /// Check if the current user is following the specified user. Future isFollowingUser(String user) => @@ -144,16 +142,14 @@ class UsersService extends Service { /// List current user followers. /// /// API docs: https://developer.github.com/v3/users/followers/#list-followers-of-a-user - Stream listCurrentUserFollowers() => PaginationHelper(github).objects( - 'GET', '/user/followers', (dynamic i) => User.fromJson(i), - statusCode: 200); + Stream listCurrentUserFollowers() => PaginationHelper(github) + .objects('GET', '/user/followers', User.fromJson, statusCode: 200); /// List current user following /// /// API docs: https://developer.github.com/v3/users/followers/#list-users-followed-by-the-authenticated-user - Stream listCurrentUserFollowing() => PaginationHelper(github).objects( - 'GET', '/user/following', (dynamic i) => User.fromJson(i), - statusCode: 200); + Stream listCurrentUserFollowing() => PaginationHelper(github) + .objects('GET', '/user/following', User.fromJson, statusCode: 200); /// Lists the verified public keys for a [userLogin]. If no [userLogin] is specified, /// the public keys for the authenticated user are fetched. @@ -162,8 +158,7 @@ class UsersService extends Service { /// and https://developer.github.com/v3/users/keys/#list-your-public-keys Stream listPublicKeys([String? userLogin]) { final path = userLogin == null ? '/user/keys' : '/users/$userLogin/keys'; - return PaginationHelper(github) - .objects('GET', path, (dynamic i) => PublicKey.fromJson(i)); + return PaginationHelper(github).objects('GET', path, PublicKey.fromJson); } // TODO: Implement getPublicKey: https://developer.github.com/v3/users/keys/#get-a-single-public-key diff --git a/lib/src/common/util/oauth2.dart b/lib/src/common/util/oauth2.dart index 5d3c9e59..9333d606 100644 --- a/lib/src/common/util/oauth2.dart +++ b/lib/src/common/util/oauth2.dart @@ -54,14 +54,12 @@ class OAuth2Flow { /// /// This should be displayed to the user. String createAuthorizeUrl() { - return baseUrl + - '/authorize' + - buildQueryString({ + return '$baseUrl/authorize${buildQueryString({ 'client_id': clientId, 'scope': scopes.join(','), 'redirect_uri': redirectUri, 'state': state - }); + })}'; } /// Exchanges the given [code] for a token. diff --git a/pubspec.yaml b/pubspec.yaml index bdc75ce3..9e9a6ace 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,15 +1,15 @@ name: github -version: 9.9.0 +version: 9.9.1-dev description: A high-level GitHub API Client Library that uses Github's v3 API homepage: https://github.com/SpinlockLabs/github.dart environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.18.0 <3.0.0' dependencies: http: ^0.13.0 http_parser: ^4.0.0 - json_annotation: ^4.4.0 + json_annotation: ^4.8.0 meta: ^1.3.0 dev_dependencies: @@ -18,8 +18,8 @@ dev_dependencies: build_web_compilers: any collection: ^1.15.0 dependency_validator: - json_serializable: ^6.0.0 - lints: ^1.0.0 + json_serializable: ^6.6.1 + lints: ^2.0.0 mockito: ^5.0.0 nock: ^1.0.0 pub_semver: ^2.0.0 diff --git a/test/assets/responses/nocked_responses.dart b/test/assets/responses/nocked_responses.dart index 3a1b9b5b..bf0e50f4 100644 --- a/test/assets/responses/nocked_responses.dart +++ b/test/assets/responses/nocked_responses.dart @@ -1,4 +1,4 @@ -var getBlob = ''' +String getBlob = ''' { "content": "Q29udGVudCBvZiB0aGUgYmxvYg==", "encoding": "base64", @@ -8,7 +8,7 @@ var getBlob = ''' "node_id": "Q29udGVudCBvZiB0aGUgYmxvYg==" }'''; -var createBlob = ''' +String createBlob = ''' { "url": "https://api.github.com/repos/octocat/example/git/blobs/3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15", "sha": "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15", @@ -16,7 +16,7 @@ var createBlob = ''' "encoding": "utf-8" }'''; -var getCommit = ''' +String getCommit = ''' { "sha": "7638417db6d59f3c431d3e1f261cc637155684cd", "node_id": "MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ==", @@ -52,7 +52,7 @@ var getCommit = ''' } }'''; -var createCommit = ''' +String createCommit = ''' { "sha": "7638417db6d59f3c431d3e1f261cc637155684cd", "node_id": "MDY6Q29tbWl0NzYzODQxN2RiNmQ1OWYzYzQzMWQzZTFmMjYxY2M2MzcxNTU2ODRjZA==", @@ -88,7 +88,7 @@ var createCommit = ''' "html_url": "https://github.com/octocat/Hello-World/commit/7638417db6d59f3c431d3e1f261cc637155684cd" }'''; -var getReference = '''{ +String getReference = '''{ "ref": "refs/heads/b", "node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlQQ==", "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/featureA", @@ -99,7 +99,7 @@ var getReference = '''{ } }'''; -var createReference = '''{ +String createReference = '''{ "ref": "refs/heads/b", "node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlQQ==", "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/featureA", @@ -110,7 +110,7 @@ var createReference = '''{ } }'''; -var getTag = '''{ +String getTag = '''{ "node_id": "MDM6VGFnOTQwYmQzMzYyNDhlZmFlMGY5ZWU1YmM3YjJkNWM5ODU4ODdiMTZhYw==", "tag": "v0.0.1", "sha": "940bd336248efae0f9ee5bc7b2d5c985887b16ac", @@ -134,7 +134,7 @@ var getTag = '''{ } }'''; -var createTag = '''{ +String createTag = '''{ "node_id": "MDM6VGFnOTQwYmQzMzYyNDhlZmFlMGY5ZWU1YmM3YjJkNWM5ODU4ODdiMTZhYw==", "tag": "v0.0.1", "sha": "940bd336248efae0f9ee5bc7b2d5c985887b16ac", @@ -158,7 +158,7 @@ var createTag = '''{ } }'''; -var createTree = '''{ +String createTree = '''{ "sha": "44b4fc6d56897b048c772eb4087f854f46256132", "url": "https://api.github.com/repos/octocat/Hello-World/trees/44b4fc6d56897b048c772eb4087f854f46256132", "tree": [ @@ -174,7 +174,7 @@ var createTree = '''{ "truncated": true }'''; -var searchResults = '''{ +String searchResults = '''{ "total_count": 17, "incomplete_results": false, "items": [ @@ -1473,7 +1473,7 @@ var searchResults = '''{ ] }'''; -var mergedPR1 = '''{ +String mergedPR1 = '''{ "sha": "someSHA", "merged": true, "message": "Pull Request successfully merged" diff --git a/test/common/github_test.dart b/test/common/github_test.dart index 45c3b68f..7b50ef54 100644 --- a/test/common/github_test.dart +++ b/test/common/github_test.dart @@ -6,7 +6,7 @@ import 'package:http/testing.dart'; import 'package:test/test.dart'; void main() { - group(GitHub, () { + group(GitHub, () { test('passes calendar version header', () async { Request? request; final client = MockClient((r) async { diff --git a/test/experiment/error_handling.dart b/test/experiment/error_handling.dart index 5456b237..e76b7e9d 100644 --- a/test/experiment/error_handling.dart +++ b/test/experiment/error_handling.dart @@ -27,8 +27,4 @@ void main() { print(e); exit(0); } - - print('Invalid Entity Error Handling Failed'); - - exit(1); } diff --git a/test/git_test.dart b/test/git_test.dart index f769571b..34487b95 100644 --- a/test/git_test.dart +++ b/test/git_test.dart @@ -1,4 +1,3 @@ -import 'dart:io'; import 'package:github/github.dart'; import 'package:nock/nock.dart'; import 'package:test/test.dart'; diff --git a/test/scenarios_test.dart b/test/scenarios_test.dart index 6486553d..c39ceb53 100644 --- a/test/scenarios_test.dart +++ b/test/scenarios_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: unused_local_variable + @Tags(['scenarios']) @TestOn('vm') diff --git a/test/unit/issues_test.dart b/test/unit/issues_test.dart index 88b06086..512d83a3 100644 --- a/test/unit/issues_test.dart +++ b/test/unit/issues_test.dart @@ -3,7 +3,6 @@ import 'package:github/src/common/model/issues.dart'; import 'package:test/test.dart'; - const String testIssueCommentJson = ''' { "url": "https://api.github.com/repos/flutter/cocoon/issues/comments/1352355796", @@ -54,7 +53,8 @@ const String testIssueCommentJson = ''' void main() { group('Issue Comments', () { test('IssueComment from Json', () { - final issueComment = IssueComment.fromJson(jsonDecode(testIssueCommentJson)); + final issueComment = + IssueComment.fromJson(jsonDecode(testIssueCommentJson)); expect(1352355796, issueComment.id); expect('MEMBER', issueComment.authorAssociation); expect('CaseyHillers', issueComment.user!.login); diff --git a/tool/release_unreleased_prs.dart b/tool/release_unreleased_prs.dart index 2eb1d273..b8cf8b17 100644 --- a/tool/release_unreleased_prs.dart +++ b/tool/release_unreleased_prs.dart @@ -103,7 +103,7 @@ Future> getUnreleasedPRs() async { } String getNextVersion(Version currentVersion, List unreleased) { - var semvers = Set(); + var semvers = {}; for (final pr in unreleased) { var prlabels = pr.labels .where((element) => element.name.startsWith('semver:')) From 54f8e17c0e70d75ddebc93dec7c13ab0ad4fac01 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 Feb 2023 17:57:13 -0800 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e49cfa75..77d1b5c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 9.9.1-dev -* Require Dart 2.17 +* Require Dart 2.18 * Expose `CheckSuitesService` and `ChuckRunsService` classes. ## 9.9.0 From 10013bfd8517ddbecd0938e977690f2157a5cc2c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 2 Feb 2023 17:59:14 -0800 Subject: [PATCH 3/3] oops --- CHANGELOG.md | 2 +- pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d1b5c8..eae3873b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 9.9.1-dev +## 9.10.0-dev * Require Dart 2.18 * Expose `CheckSuitesService` and `ChuckRunsService` classes. diff --git a/pubspec.yaml b/pubspec.yaml index 9e9a6ace..188c93ec 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: github -version: 9.9.1-dev +version: 9.10.0-dev description: A high-level GitHub API Client Library that uses Github's v3 API homepage: https://github.com/SpinlockLabs/github.dart