Skip to content

Commit

Permalink
(draft) Migrate remaining samples to null safety (dart-lang#91)
Browse files Browse the repository at this point in the history
* run migration tool in command_line

* update command_line to null safety

* upgrade extension_methods to null safety

* add extension on Null

* upgrade native_app to null safety

* upgrade null_safety/calculate_lix to 2.12.0

* upgrade ffi/test_utils to null safety

* upgrade ffi/hello_world to null safety

* use sdk 2.12.0 in system-command pubspec

* use 2.12.0 in primitives pubspec

* run mono_repo generate with 3.4.7

* use HTTPS dependency

* use published version of build_cli
  • Loading branch information
johnpryan authored Mar 11, 2021
1 parent 7944dcd commit a4bd74b
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 79 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Created with package:mono_repo v3.4.6
# Created with package:mono_repo v3.4.7
name: Dart CI
on:
push:
Expand Down Expand Up @@ -27,13 +27,13 @@ jobs:
restore-keys: |
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
uses: actions/checkout@v2
- name: mono_repo self validate
run: pub global activate mono_repo 3.4.6
run: pub global activate mono_repo 3.4.7
- name: mono_repo self validate
run: pub global run mono_repo generate --validate
job_002:
Expand All @@ -50,7 +50,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
Expand Down Expand Up @@ -302,7 +302,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
Expand Down Expand Up @@ -335,7 +335,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
Expand Down Expand Up @@ -368,7 +368,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
Expand Down Expand Up @@ -401,7 +401,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
Expand Down Expand Up @@ -434,7 +434,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -467,7 +467,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -500,7 +500,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -533,7 +533,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand All @@ -556,7 +556,7 @@ jobs:
name: "unit_test; windows; Dart stable; PKG: extension_methods; `pub run test`"
runs-on: windows-latest
steps:
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
Expand All @@ -579,7 +579,7 @@ jobs:
name: "unit_test; windows; Dart stable; PKG: command_line; `pub run test`"
runs-on: windows-latest
steps:
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
Expand Down Expand Up @@ -612,7 +612,7 @@ jobs:
os:macos-latest;pub-cache-hosted;dart:stable
os:macos-latest;pub-cache-hosted
os:macos-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
Expand Down Expand Up @@ -645,7 +645,7 @@ jobs:
os:macos-latest;pub-cache-hosted;dart:stable
os:macos-latest;pub-cache-hosted
os:macos-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
Expand All @@ -668,7 +668,7 @@ jobs:
name: "unit_test; windows; Dart dev; PKG: extension_methods; `pub run test`"
runs-on: windows-latest
steps:
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand All @@ -691,7 +691,7 @@ jobs:
name: "unit_test; windows; Dart dev; PKG: command_line; `pub run test`"
runs-on: windows-latest
steps:
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -724,7 +724,7 @@ jobs:
os:macos-latest;pub-cache-hosted;dart:dev
os:macos-latest;pub-cache-hosted
os:macos-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -757,7 +757,7 @@ jobs:
os:macos-latest;pub-cache-hosted;dart:dev
os:macos-latest;pub-cache-hosted
os:macos-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down
5 changes: 3 additions & 2 deletions command_line/bin/github_activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ void main(List<String> args) {
return;
}

if (options.user == null || options.user.isEmpty) {
if (options.user?.isEmpty ?? true) {
_printUsage();
return;
}

var fetcher = ActivityService(options.user, options.verbose, options.interval,
var fetcher = ActivityService(
options.user!, options.verbose!, options.interval,
formatter: _getFormatter(options));

// Stream the github activity to the console
Expand Down
3 changes: 3 additions & 0 deletions command_line/lib/github_activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export 'src/options.dart';
/// API rate-limiting.
Authentication get authentication {
var ghStatsToken = Platform.environment['GITHUB_TOKEN'];
if (ghStatsToken == null) {
return Authentication.anonymous();
}
return Authentication.withToken(ghStatsToken);
}

Expand Down
8 changes: 4 additions & 4 deletions command_line/lib/src/formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class DefaultEventFormatter implements EventFormatter {

@override
String format(Event event) {
var date = dateFormat.format(event.createdAt.toLocal());
var date = dateFormat.format(event.createdAt!.toLocal());
var type = event.type;
var username = event.actor.login;
var username = event.actor!.login;
var url = util.getUrl(event);
if (url == null) {
return '$date: [$type]';
Expand All @@ -37,15 +37,15 @@ class MarkdownEventFormatter implements EventFormatter {
static final dateFormat = DateFormat('EEE, M/d/y');
@override
String format(Event event) {
var date = dateFormat.format(event.createdAt.toLocal());
var date = dateFormat.format(event.createdAt!.toLocal());
var type = event.type;
var action = util.getAction(event);
var url = util.getUrl(event);
if (url == null) {
return '- ($date): [$type]';
}
var title = util.getTitle(event);
var repoName = event.repo.name;
var repoName = event.repo!.name;
var issueNumber = util.getIssueNumber(event);

return '- ($date): $action "$title" ([$repoName/$issueNumber]($url))';
Expand Down
8 changes: 4 additions & 4 deletions command_line/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ArgParser get parser => _$populateOptionsParser(ArgParser(usageLineLength: 80));
@CliOptions()
class Options {
@CliOption(abbr: 'u', help: 'Required. The GitHub user')
final String user;
final String? user;

@CliOption(
abbr: 'i',
Expand All @@ -24,15 +24,15 @@ class Options {
)
Interval interval;

@CliOption(abbr: 'v', help: 'Print additional event types')
final bool verbose;
@CliOption(abbr: 'v', defaultsTo: false, help: 'Print additional event types')
final bool? verbose;

@CliOption(
abbr: 'f',
help: 'The format to display. Defaults to '
'"Friday, October 18 at 13:55 PM: <User> opened <URL>"',
allowed: ['default', 'markdown'])
final String format;
final String? format;

@CliOption(abbr: 'h', negatable: false, help: 'Prints usage information.')
final bool help;
Expand Down
27 changes: 12 additions & 15 deletions command_line/lib/src/options.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions command_line/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,61 @@ import 'package:github/github.dart';

import 'options.dart';

String getAction(Event event) {
return event.payload['action'];
String? getAction(Event event) {
return event.payload!['action'];
}

String getUrl(Event event) {
String? getUrl(Event event) {
var type = event.type;

if (type == 'PullRequestEvent') {
return event.payload['pull_request']['html_url'];
return event.payload!['pull_request']['html_url'];
}

if (type == 'IssuesEvent') {
return event.payload['issue']['html_url'];
return event.payload!['issue']['html_url'];
}

return null;
}

String getTitle(Event event) {
String? getTitle(Event event) {
var type = event.type;

if (type == 'PullRequestEvent') {
return event.payload['pull_request']['title'];
return event.payload!['pull_request']['title'];
}

if (type == 'IssuesEvent') {
return event.payload['issue']['title'];
return event.payload!['issue']['title'];
}

return null;
}

int getIssueNumber(Event event) {
int? getIssueNumber(Event event) {
var type = event.type;

if (type == 'PullRequestEvent') {
return event.payload['pull_request']['number'];
return event.payload!['pull_request']['number'];
}

if (type == 'IssuesEvent') {
return event.payload['issue']['number'];
return event.payload!['issue']['number'];
}

return null;
}

bool isTooOld(DateTime date, Interval interval) {
bool isTooOld(DateTime? date, Interval interval) {
var now = DateTime.now();
switch (interval) {
case Interval.day:
return date.isBefore(now.subtract(Duration(days: 1)));
return date!.isBefore(now.subtract(Duration(days: 1)));
case Interval.week:
return date.isBefore(now.subtract(Duration(days: 7)));
return date!.isBefore(now.subtract(Duration(days: 7)));
case Interval.month:
return date.isBefore(now.subtract(Duration(days: 30)));
return date!.isBefore(now.subtract(Duration(days: 30)));
default:
return true;
}
Expand Down
Loading

0 comments on commit a4bd74b

Please sign in to comment.