Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ include: package:lints/recommended.yaml

analyzer:
language:
#strict-casts: true
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
Expand Down
6 changes: 3 additions & 3 deletions example/languages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ String generateMarkdown(int accuracy) {
|Name|Bytes|Percentage|
|-----|-----|-----|
''');
data.sort((a, b) => b[1].compareTo(a[1]));
data.sort((a, b) => (b[1] as num).compareTo(a[1] as num));

for (final info in data) {
final String? name = info[0];
final int bytes = info[1];
final name = info[0] as String?;
final bytes = info[1] as int;
final num percentage = (bytes / total) * 100;
md.writeln('|$name|$bytes|${percentage.toStringAsFixed(accuracy)}|');
}
Expand Down
2 changes: 1 addition & 1 deletion example/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void loadUser() {
append('Created', user.createdAt);
document.getElementById('load')!.hidden = true;
document.getElementById('token')!.hidden = true;
}).catchError((e) {
}).catchError((Object e) {
if (e is AccessForbidden) {
window.alert('Invalid Token');
}
Expand Down
63 changes: 32 additions & 31 deletions lib/src/common/model/checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class CheckRunAnnotationLevel extends EnumWithValue {
case 'failure':
return failure;
default:
throw Exception(
'This level of check run annotation is unimplemented: $value.');
return CheckRunAnnotationLevel._(value ?? 'notice');
}
}

Expand Down Expand Up @@ -70,8 +69,7 @@ class CheckRunConclusion extends EnumWithValue {
return level;
}
}
throw Exception(
'This level of check run conclusion is unimplemented: $value.');
return CheckRunConclusion._(value);
}
}

Expand Down Expand Up @@ -124,16 +122,19 @@ class CheckRun {
break;
}
}
final checkSuite = input['check_suite'] as Map<String, dynamic>?;
return CheckRun._(
name: input['name'],
id: input['id'],
externalId: input['external_id'],
name: input['name'] as String?,
id: input['id'] as int?,
externalId: input['external_id'] as String?,
status: status,
headSha: input['head_sha'],
checkSuiteId: input['check_suite']['id'],
detailsUrl: input['details_url'],
startedAt: DateTime.parse(input['started_at']),
conclusion: CheckRunConclusion._fromValue(input['conclusion']),
headSha: input['head_sha'] as String?,
checkSuiteId: checkSuite?['id'] as int?,
detailsUrl: input['details_url'] as String?,
startedAt: input['started_at'] != null
? (DateTime.tryParse(input['started_at'] as String) ?? DateTime.now())
: DateTime.now(),
conclusion: CheckRunConclusion._fromValue(input['conclusion'] as String?),
);
}

Expand All @@ -143,7 +144,7 @@ class CheckRun {
'id': id,
'external_id': externalId,
'status': status,
'head_sha': externalId,
'head_sha': headSha,
'check_suite': <String, dynamic>{
'id': checkSuiteId,
},
Expand Down Expand Up @@ -273,16 +274,16 @@ class CheckRunAnnotation {

factory CheckRunAnnotation.fromJSON(Map<String, dynamic> input) {
return CheckRunAnnotation(
path: input['path'],
startLine: input['start_line'],
endLine: input['end_line'],
startColumn: input['start_column'],
endColumn: input['end_column'],
annotationLevel:
CheckRunAnnotationLevel._fromValue(input['annotation_level']),
title: input['title'],
message: input['message'],
rawDetails: input['raw_details'],
path: input['path'] as String,
startLine: input['start_line'] as int,
endLine: input['end_line'] as int,
startColumn: input['start_column'] as int?,
endColumn: input['end_column'] as int?,
annotationLevel: CheckRunAnnotationLevel._fromValue(
input['annotation_level'] as String?),
title: (input['title'] as String?) ?? '',
message: (input['message'] as String?) ?? '',
rawDetails: (input['raw_details'] ?? input['rax_details']) as String?,
);
}

Expand All @@ -296,7 +297,7 @@ class CheckRunAnnotation {
'annotation_level': annotationLevel.toString(),
'message': message,
'title': title,
'rax_details': rawDetails,
'raw_details': rawDetails,
});
}
}
Expand Down Expand Up @@ -376,16 +377,16 @@ class CheckSuite {
});

factory CheckSuite.fromJson(Map<String, dynamic> input) {
var pullRequestsJson = input['pull_requests'] as List<dynamic>;
var pullRequestsJson = (input['pull_requests'] as List?) ?? const [];
var pullRequests = pullRequestsJson
.map((dynamic json) =>
PullRequest.fromJson(json as Map<String, dynamic>))
.toList();
return CheckSuite(
conclusion: CheckRunConclusion._fromValue(input['conclusion']),
headBranch: input['head_branch'],
headSha: input['head_sha'],
id: input['id'],
conclusion: CheckRunConclusion._fromValue(input['conclusion'] as String?),
headBranch: input['head_branch'] as String?,
headSha: input['head_sha'] as String?,
id: input['id'] as int?,
pullRequests: pullRequests,
);
}
Expand Down Expand Up @@ -414,8 +415,8 @@ class AutoTriggerChecks {

factory AutoTriggerChecks.fromJson(Map<String, dynamic> input) {
return AutoTriggerChecks(
appId: input['app_id'],
setting: input['setting'],
appId: input['app_id'] as int,
setting: input['setting'] as bool?,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/common/model/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RateLimit {
final remaining = rateJson?['remaining'] as int?;
final resets = rateJson?['reset'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(rateJson?['reset']);
: DateTime.fromMillisecondsSinceEpoch(rateJson!['reset'] as int);
return RateLimit(limit, remaining, resets);
}

Expand Down
7 changes: 6 additions & 1 deletion lib/src/common/model/reaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ class ReactionType {
':eyes:': eyes,
};

static ReactionType? fromString(String? content) => _types[content!];
static ReactionType? fromString(String? content) {
if (content == null) {
return null;
}
return _types[content] ?? ReactionType._(content, content);
}
}

@JsonSerializable()
Expand Down
7 changes: 5 additions & 2 deletions lib/src/common/model/repos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,12 @@ class LanguageBreakdown {

/// The Primary Language
String get primary {
final list = mapToList(_data);
if (_data.isEmpty) {
return '';
}
final list = _data.entries.toList();
list.sort((a, b) {
return a.value.compareTo(b.value);
return b.value.compareTo(a.value);
});
return list.first.key;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/common/model/repos_releases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Release {
/// Release Assets
List<ReleaseAsset>? assets;

List? errors;
List<dynamic>? errors;

factory Release.fromJson(Map<String, dynamic> input) =>
_$ReleaseFromJson(input);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/common/model/users.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class User {
});

@JsonKey(includeToJson: false, includeFromJson: false)
Map? json; // TODO remove
Map<dynamic, dynamic>? json; // TODO remove

/// User's Username
String? login;
Expand Down
7 changes: 5 additions & 2 deletions lib/src/common/util/oauth2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ class OAuth2Flow {
if (json['error'] != null) {
throw Exception(json['error']);
}
return ExchangeResponse(json['access_token'], json['token_type'],
(json['scope'] as String).split(','));
return ExchangeResponse(
json['access_token'] as String?,
json['token_type'] as String?,
((json['scope'] as String?) ?? '').split(','),
);
});
}
}
Expand Down
13 changes: 8 additions & 5 deletions lib/src/common/util/pagination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PaginationHelper {
if (serverErrors >= maxServerErrors) {
break;
}
await Future.delayed(serverErrorBackOff);
await Future<void>.delayed(serverErrorBackOff);
continue;
}

Expand Down Expand Up @@ -98,12 +98,15 @@ class PaginationHelper {
body: body,
statusCode: statusCode,
)) {
final decoded = jsonDecode(response.body);
final json = arrayKey == null
? jsonDecode(response.body) as List?
: (jsonDecode(response.body) as Map)[arrayKey];
? (decoded as List?)
: ((decoded as Map<String, dynamic>)[arrayKey] as List?);

for (final item in json) {
yield (item as T?)!;
if (json != null) {
for (final item in json) {
yield (item as T?)!;
}
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions lib/src/common/xplat_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ import 'package:github/src/common.dart';

/// Looks for GitHub Authentication information from the current environment.
///
/// If in a browser context, it will look through query string parameters first
/// and then sessionStorage.
/// If in a browser context, it will check sessionStorage (and optionally query strings
/// if [allowQueryAuth] is explicitly set to true, which is deprecated).
///
/// If in a server, command line or Flutter context it will use the system environment variables.
///
/// In both contexts it delegates to [findAuthenticationInMap] to find the
/// github token or username and password.
Authentication findAuthenticationFromEnvironment() =>
Authentication findAuthenticationFromEnvironment(
{bool allowQueryAuth = false}) =>
const Authentication.anonymous();

/// Checks the passed in map for keys in [COMMON_GITHUB_TOKEN_ENV_KEYS].
/// The first one that exists is used as the github token to call [Authentication.withToken] with.
/// If the above fails, the GITHUB_USERNAME and GITHUB_PASSWORD keys will be checked.
/// If those keys both exist, then [Authentication.basic] will be used.
Authentication? findAuthenticationInMap(Map map) {
Authentication? findAuthenticationInMap(Map<dynamic, dynamic> map) {
for (final key in COMMON_GITHUB_TOKEN_ENV_KEYS) {
if (map.containsKey(key)) {
return Authentication.withToken(map[key]);
return Authentication.withToken(map[key] as String?);
}
if (map['GITHUB_USERNAME'] is String && map['GITHUB_PASSWORD'] is String) {
return Authentication.basic(
map['GITHUB_USERNAME'], map['GITHUB_PASSWORD']);
map['GITHUB_USERNAME'] as String?, map['GITHUB_PASSWORD'] as String?);
}
}
return null;
Expand Down
9 changes: 6 additions & 3 deletions test/common/github_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ void main() {
});

final github = GitHub(client: client);
await github.getJSON(''); // Make HTTP request
await github.getJSON<Map<String, dynamic>, Map<String, dynamic>>(
''); // Make HTTP request

expect(request, isNotNull);
expect(request!.headers.containsKey(GitHub.versionHeader), isTrue);
Expand All @@ -31,7 +32,8 @@ void main() {
});

final github = GitHub(client: client);
await github.getJSON(''); // Make HTTP request
await github.getJSON<Map<String, dynamic>, Map<String, dynamic>>(
''); // Make HTTP request

expect(request, isNotNull);
expect(request!.headers.containsKey('User-Agent'), isTrue);
Expand All @@ -50,7 +52,8 @@ void main() {
client: client,
auth: const Authentication.anonymous(),
);
await github.getJSON(''); // Make HTTP request
await github.getJSON<Map<String, dynamic>, Map<String, dynamic>>(
''); // Make HTTP request

expect(request, isNotNull);
expect(request!.headers.containsKey('Authorization'), isFalse);
Expand Down
2 changes: 1 addition & 1 deletion test/data_object_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ void main() {
});
}

String _prettyEncode(obj) => GitHubJson.encode(obj, indent: ' ');
String _prettyEncode(Object obj) => GitHubJson.encode(obj, indent: ' ');
2 changes: 1 addition & 1 deletion test/experiment/org_hooks.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';
import '../helper.dart';

Future main() async {
Future<void> main() async {
const org = 'IOT-DSA';

final hooks = await github.organizations.listHooks(org).toList();
Expand Down
2 changes: 1 addition & 1 deletion test/experiment/orglist.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';
import 'package:github/github.dart';

Future main() async {
Future<void> main() async {
final github = GitHub();
final repos =
await github.repositories.listUserRepositories('dart-lang').toList();
Expand Down
8 changes: 4 additions & 4 deletions test/helper/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ class MockResponse extends http.Response {
final responseData =
jsonDecode(asset('responses/$name.json').readAsStringSync())
as Map<String, dynamic>;
final headers = responseData['headers'] as Map<String, String>;
final headers = (responseData['headers'] as Map).cast<String, String>();
final dynamic body = responseData['body'];
final int statusCode = responseData['statusCode'];
final statusCode = responseData['statusCode'] as int;
String? actualBody;
if (body is Map || body is List) {
actualBody = jsonDecode(body);
actualBody = jsonEncode(body);
} else {
actualBody = body.toString();
}

return MockResponse(actualBody!, headers, statusCode);
return MockResponse(actualBody, headers, statusCode);
}
}
7 changes: 4 additions & 3 deletions test/scenarios_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ Future<GitHub> createGithubWithScenario(String scenario,
throw Exception(
'Error loading scenario: $scenario\n${resp.statusCode}\n${resp.body}');
}
var j = json.decode(resp.body);
var j = json.decode(resp.body) as Map<String, dynamic>;
return GitHub(
endpoint: j['url'],
endpoint: j['url'] as String,
auth: const Authentication.withToken(
'0000000000000000000000000000000000000001'));
'0000000000000000000000000000000000000001'),
allowInsecureAuth: true);
}

/// Run scenario tests against ockokits fixtures-server
Expand Down
Loading
Loading