Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nullsafe migration #244

Merged
merged 18 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: google/dart:latest
image: google/dart:2.12-beta

steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 2 additions & 2 deletions example/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export 'package:github/browser_helper.dart';
/// view source button, then you don't need to call this method
Future<void> initViewSourceButton(String script) async {
// query the DOM for the view source button, handle clicks
document.querySelector('#view-source')?.onClick?.listen((_) {
document.querySelector('#view-source')?.onClick.listen((_) {
final popup = window.open('view_source.html?script=$script', 'View Source');
String code;
String? code;

var fetched = false;
var ready = false;
Expand Down
16 changes: 8 additions & 8 deletions example/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:html';

import 'common.dart';

Element emojiDiv;
Element? emojiDiv;

Future<void> main() async {
await initViewSourceButton('emoji.dart');
Expand All @@ -25,23 +25,23 @@ Future<void> loadEmojis() async {
h.append(
ImageElement(src: url, width: 64, height: 64)..classes.add('emoji'));
h.append(ParagraphElement()..text = ':$name:');
emojiDiv.append(h);
emojiDiv!.append(h);
});
}

String lastQuery;
String? lastQuery;

void filter(String query) {
void filter(String? query) {
if (lastQuery != null && lastQuery == query) {
return;
}
lastQuery = query;
final boxes = emojiDiv.children;
final boxes = emojiDiv!.children;
for (final box in boxes) {
final boxName = box.querySelector('p');
final t = boxName.text;
final boxName = box.querySelector('p')!;
final t = boxName.text!;
final name = t.substring(1, t.length - 1);
if (name.contains(query)) {
if (name.contains(query!)) {
box.style.display = 'inline';
} else {
box.style.display = 'none';
Expand Down
8 changes: 4 additions & 4 deletions example/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'dart:html';
import 'common.dart';

void main() {
final InputElement tokenInput = querySelector('#token');
tokenInput.value = github.auth.token ?? '';
window.sessionStorage['GITHUB_TOKEN'] = tokenInput.value;
final tokenInput = querySelector('#token') as InputElement;
tokenInput.value = github.auth!.token ?? '';
window.sessionStorage['GITHUB_TOKEN'] = tokenInput.value!;
tokenInput.onKeyUp.listen((_) {
window.sessionStorage['GITHUB_TOKEN'] = tokenInput.value;
window.sessionStorage['GITHUB_TOKEN'] = tokenInput.value!;
});
}
16 changes: 8 additions & 8 deletions example/languages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import 'dart:html';
import 'package:github/github.dart';
import 'common.dart';

DivElement tableDiv;
DivElement? tableDiv;

LanguageBreakdown breakdown;
late LanguageBreakdown breakdown;

Future<void> main() async {
await initViewSourceButton('languages.dart');
tableDiv = querySelector('#table');
tableDiv = querySelector('#table') as DivElement?;
await loadRepository();
}

Future<void> loadRepository() async {
var user = 'dart-lang';
var reponame = 'sdk';
String? user = 'dart-lang';
String? reponame = 'sdk';

final params = queryString;

Expand All @@ -27,7 +27,7 @@ Future<void> loadRepository() async {
reponame = params['repo'];
}

document.getElementById('name').setInnerHtml('$user/$reponame');
document.getElementById('name')!.setInnerHtml('$user/$reponame');

final repo = RepositorySlug(user, reponame);
breakdown = await github.repositories.listLanguages(repo);
Expand All @@ -44,7 +44,7 @@ void reloadTable({int accuracy = 4}) {
isReloadingTable = true;
final md = generateMarkdown(accuracy);
github.misc.renderMarkdown(md).then((html) {
tableDiv.setInnerHtml(html, treeSanitizer: NodeTreeSanitizer.trusted);
tableDiv!.setInnerHtml(html, treeSanitizer: NodeTreeSanitizer.trusted);
isReloadingTable = false;
});
}
Expand All @@ -62,7 +62,7 @@ String generateMarkdown(int accuracy) {
data.sort((a, b) => b[1].compareTo(a[1]));

data.forEach((info) {
final String name = info[0];
final String? name = info[0];
final int bytes = info[1];
final num percentage = (bytes / total) * 100;
md += '|$name|$bytes|${percentage.toStringAsFixed(accuracy)}|\n';
Expand Down
28 changes: 14 additions & 14 deletions example/organization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import 'dart:html';
import 'package:github/github.dart';
import 'common.dart';

DivElement $output;
InputElement $input;
ButtonElement $btn;
DivElement? $output;
InputElement? $input;
ButtonElement? $btn;

Future<void> main() async {
await initViewSourceButton('organization.dart');
$output = querySelector('#output');
$input = querySelector('#input');
$btn = querySelector('#submit');
$input.onChange.listen((_) {
loadOrganization($input.value);
$output = querySelector('#output') as DivElement?;
$input = querySelector('#input') as InputElement?;
$btn = querySelector('#submit') as ButtonElement?;
$input!.onChange.listen((_) {
loadOrganization($input!.value);
});
$btn.onClick.listen((_) {
loadOrganization($input.value);
$btn!.onClick.listen((_) {
loadOrganization($input!.value);
});
$btn.click();
$btn!.click();
}

Future<void> loadOrganization(String orgToLoad) async {
Future<void> loadOrganization(String? orgToLoad) async {
try {
final org = await github.organizations.get(orgToLoad);
final html = '''
Expand All @@ -32,8 +32,8 @@ Future<void> loadOrganization(String orgToLoad) async {
<br/>Followers: ${org.followersCount}
<br/>Following: ${org.followingCount}
''';
$output.innerHtml = html;
$output!.innerHtml = html;
} on OrganizationNotFound {
$output.innerHtml = 'Not found.';
$output!.innerHtml = 'Not found.';
}
}
4 changes: 1 addition & 3 deletions example/readme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import 'package:github/github.dart';

import 'common.dart';

DivElement readmeDiv;

Future<void> main() async {
await initViewSourceButton('readme.dart');
readmeDiv = querySelector('#readme');
var readmeDiv = querySelector('#readme')!;
var repo = RepositorySlug('SpinlockLabs', 'github.dart');
final readme = await github.repositories.getReadme(repo);
final html = await github.misc.renderMarkdown(readme.text);
Expand Down
13 changes: 5 additions & 8 deletions example/releases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import 'package:github/github.dart';

import 'common.dart';

DivElement releasesDiv;
DivElement? releasesDiv;

Future<void> main() async {
await initViewSourceButton('releases.dart');
releasesDiv = querySelector('#releases');
releasesDiv = querySelector('#releases') as DivElement?;
loadReleases();
}

Expand All @@ -19,17 +19,14 @@ void loadReleases() {
.toList()
.then((releases) {
for (final release in releases) {
releasesDiv.appendHtml('''
releasesDiv!.appendHtml('''
<div class="repo box" id="release-${release.id}">
<h1>${release.name}</h1>
</div>
''', treeSanitizer: NodeTreeSanitizer.trusted);
final rel = releasesDiv.querySelector('#release-${release.id}');
final rel = releasesDiv!.querySelector('#release-${release.id}');
void append(String key, String value) {
if (value == null) {
return;
}
rel.appendHtml('<br/><b>$key</b>: $value',
rel!.appendHtml('<br/><b>$key</b>: $value',
treeSanitizer: NodeTreeSanitizer.trusted);
}

Expand Down
46 changes: 24 additions & 22 deletions example/repos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,51 @@ import 'package:github/github.dart';

import 'common.dart';

DivElement repositoriesDiv;
List<Repository> repos;
DivElement? repositoriesDiv;
List<Repository>? repos;

Map<String, Comparator<Repository>> sorts = {
'stars': (Repository a, Repository b) =>
b.stargazersCount.compareTo(a.stargazersCount),
'forks': (Repository a, Repository b) => b.forksCount.compareTo(a.forksCount),
'created': (Repository a, Repository b) => b.createdAt.compareTo(a.createdAt),
'pushed': (Repository a, Repository b) => b.pushedAt.compareTo(a.pushedAt),
'size': (Repository a, Repository b) => b.size.compareTo(a.size)
b.stargazersCount!.compareTo(a.stargazersCount!),
'forks': (Repository a, Repository b) =>
b.forksCount!.compareTo(a.forksCount!),
'created': (Repository a, Repository b) =>
b.createdAt!.compareTo(a.createdAt!),
'pushed': (Repository a, Repository b) => b.pushedAt!.compareTo(a.pushedAt!),
'size': (Repository a, Repository b) => b.size!.compareTo(a.size!)
};

Future<void> main() async {
await initViewSourceButton('repos.dart');

repositoriesDiv = querySelector('#repos');
repositoriesDiv = querySelector('#repos') as DivElement?;

loadRepos();

querySelector('#reload').onClick.listen((event) {
querySelector('#reload')!.onClick.listen((event) {
loadRepos();
});

sorts.keys.forEach((name) {
querySelector('#sort-$name').onClick.listen((event) {
querySelector('#sort-$name')!.onClick.listen((event) {
if (_reposCache == null) {
loadRepos(sorts[name]);
}
updateRepos(_reposCache, sorts[name]);
updateRepos(_reposCache!, sorts[name]);
});
});
}

List<Repository> _reposCache;
List<Repository>? _reposCache;

void updateRepos(
List<Repository> repos, [
int Function(Repository a, Repository b) compare,
int Function(Repository a, Repository b)? compare,
]) {
document.querySelector('#repos').children.clear();
document.querySelector('#repos')!.children.clear();
repos.sort(compare);
for (final repo in repos) {
repositoriesDiv.appendHtml('''
repositoriesDiv!.appendHtml('''
<div class="repo" id="repo_${repo.name}">
<div class="line"></div>
<h2><a href="${repo.htmlUrl}">${repo.name}</a></h2>
Expand All @@ -69,15 +71,15 @@ void updateRepos(
}
}

void loadRepos([int Function(Repository a, Repository b) compare]) {
final title = querySelector('#title');
if (title.text.contains('(')) {
void loadRepos([int Function(Repository a, Repository b)? compare]) {
final title = querySelector('#title')!;
if (title.text!.contains('(')) {
title.replaceWith(HeadingElement.h2()
..text = 'GitHub for Dart - Repositories'
..id = 'title');
}

var user = 'SpinlockLabs';
String? user = 'SpinlockLabs';

if (queryString.containsKey('user')) {
user = queryString['user'];
Expand All @@ -86,13 +88,13 @@ void loadRepos([int Function(Repository a, Repository b) compare]) {
if (queryString.containsKey('sort') && compare == null) {
final sorter = queryString['sort'];
if (sorts.containsKey(sorter)) {
compare = sorts[sorter];
compare = sorts[sorter!];
}
}

compare ??= (a, b) => a.name.compareTo(b.name);
compare ??= (a, b) => a.name!.compareTo(b.name!);

github.repositories.listUserRepositories(user).toList().then((repos) {
github.repositories.listUserRepositories(user!).toList().then((repos) {
_reposCache = repos;
updateRepos(repos, compare);
});
Expand Down
24 changes: 12 additions & 12 deletions example/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import 'common.dart';
Future<void> main() async {
await initViewSourceButton('search.dart');

final searchBtn = querySelector('#submit');
final searchBtn = querySelector('#submit')!;
searchBtn.onClick.listen(search);
}

Future<void> search(_) async {
final resultsStream = github.search.code(
val('query'),
val('query')!,
language: val('language'),
filename: val('filename'),
user: val('user'),
Expand All @@ -20,21 +20,21 @@ Future<void> search(_) async {
fork: val('fork'),
path: val('path'),
size: val('size'),
inFile: isChecked('infile'),
inPath: isChecked('inpath'),
perPage: int.tryParse(val('perpage')),
pages: int.tryParse(val('pages')),
inFile: isChecked('infile')!,
inPath: isChecked('inpath')!,
perPage: int.tryParse(val('perpage')!),
pages: int.tryParse(val('pages')!),
);
final DivElement resultsDiv = querySelector('#results');
final resultsDiv = querySelector('#results') as DivElement;
resultsDiv.innerHtml = '';

var count = 0;
await for (final results in resultsStream) {
count += results.items.length;
querySelector('#nresults').text =
count += results.items!.length;
querySelector('#nresults')!.text =
'${results.totalCount} result${results.totalCount == 1 ? "" : "s"} (showing $count)';

for (final item in results.items) {
for (final item in results.items!) {
final url = item.htmlUrl;
final path = item.path;
resultsDiv.append(DivElement()
Expand All @@ -45,6 +45,6 @@ Future<void> search(_) async {
}
}

String val(String id) => (querySelector('#$id') as InputElement).value;
bool isChecked(String id) =>
String? val(String id) => (querySelector('#$id') as InputElement).value;
bool? isChecked(String id) =>
(querySelector('#$id') as CheckboxInputElement).checked;
Loading