add getLicense to repo service
MODIFY
lib/src/common.g.dart
lib/src/common.g.dart
@@ -91,3 +91,102 @@ Branch _$BranchFromJson(Map<String, dynamic> json) {
? null
: new CommitData.fromJson(json['commit'] as Map<String, dynamic>));
}
+
+LicenseDetails _$LicenseDetailsFromJson(Map<String, dynamic> json) {
+ return new LicenseDetails(
+ name: json['name'] as String,
+ path: json['path'] as String,
+ sha: json['sha'] as String,
+ size: json['size'] as int,
+ url: json['url'] == null ? null : Uri.parse(json['url'] as String),
+ htmlUrl: json['html_url'] == null
+ ? null
+ : Uri.parse(json['html_url'] as String),
+ gitUrl:
+ json['git_url'] == null ? null : Uri.parse(json['git_url'] as String),
+ downloadUrl: json['download_url'] == null
+ ? null
+ : Uri.parse(json['download_url'] as String),
+ type: json['type'] as String,
+ content: json['content'] as String,
+ encoding: json['encoding'] as String,
+ links: json['_links'] == null
+ ? null
+ : new Links.fromJson(json['_links'] as Map<String, dynamic>),
+ license: json['license'] == null
+ ? null
+ : new LicenseKind.fromJson(json['license'] as Map<String, dynamic>));
+}
+
+abstract class _$LicenseDetailsSerializerMixin {
+ String get name;
+ String get path;
+ String get sha;
+ int get size;
+ Uri get url;
+ Uri get htmlUrl;
+ Uri get gitUrl;
+ Uri get downloadUrl;
+ String get type;
+ String get content;
+ String get encoding;
+ Links get links;
+ LicenseKind get license;
+ Map<String, dynamic> toJson() => <String, dynamic>{
+ 'name': name,
+ 'path': path,
+ 'sha': sha,
+ 'size': size,
+ 'url': url?.toString(),
+ 'html_url': htmlUrl?.toString(),
+ 'git_url': gitUrl?.toString(),
+ 'download_url': downloadUrl?.toString(),
+ 'type': type,
+ 'content': content,
+ 'encoding': encoding,
+ '_links': links,
+ 'license': license
+ };
+}
+
+LicenseKind _$LicenseKindFromJson(Map<String, dynamic> json) {
+ return new LicenseKind(
+ key: json['key'] as String,
+ name: json['name'] as String,
+ spdxId: json['spdx_id'] as String,
+ url: json['url'] == null ? null : Uri.parse(json['url'] as String),
+ nodeId: json['node_id'] as String);
+}
+
+abstract class _$LicenseKindSerializerMixin {
+ String get key;
+ String get name;
+ String get spdxId;
+ Uri get url;
+ String get nodeId;
+ Map<String, dynamic> toJson() => <String, dynamic>{
+ 'key': key,
+ 'name': name,
+ 'spdx_id': spdxId,
+ 'url': url?.toString(),
+ 'node_id': nodeId
+ };
+}
+
+Links _$LinksFromJson(Map<String, dynamic> json) {
+ return new Links(
+ git: json['git'] == null ? null : Uri.parse(json['git'] as String),
+ self: json['self'] == null ? null : Uri.parse(json['self'] as String),
+ html: json['html'] == null ? null : Uri.parse(json['html'] as String));
+}
+
+abstract class _$LinksSerializerMixin {
+ Uri get self;
+ Uri get git;
+ Uri get html;
+ Map<String, dynamic> toJson() => <String, dynamic>{
+ 'self': self?.toString(),
+ 'git': git?.toString(),
+ 'html': html?.toString()
+ };
+}

MODIFY
lib/src/common/model/pulls.dart
lib/src/common/model/pulls.dart
@@ -258,7 +258,7 @@ class PullRequestComment {
..updatedAt = parseDateTime(input['updated_at'])
..url = input['html_url']
..pullRequestUrl = input['pull_request_url']
- ..links = Links.fromJSON(input['_links'] as Map<String, dynamic>);
+ ..links = new Links.fromJson(input['_links'] as Map<String, dynamic>);
}
}

MODIFY
lib/src/common/model/repos.dart
lib/src/common/model/repos.dart
@@ -453,3 +453,64 @@ class LanguageBreakdown {
return buffer.toString();
}
}
+
+@JsonSerializable()
+class LicenseDetails extends Object with _$LicenseDetailsSerializerMixin {
+ final String name;
+ final String path;
+ final String sha;
+ final int size;
+ final Uri url;
+
+ @JsonKey(name: 'html_url')
+ final Uri htmlUrl;
+ @JsonKey(name: 'git_url')
+ final Uri gitUrl;
+ @JsonKey(name: 'download_url')
+ final Uri downloadUrl;
+
+ final String type;
+ final String content;
+ final String encoding;
+
+ @JsonKey(name: '_links')
+ final Links links;
+
+ final LicenseKind license;
+
+ LicenseDetails(
+ {this.name,
+ this.path,
+ this.sha,
+ this.size,
+ this.url,
+ this.htmlUrl,
+ this.gitUrl,
+ this.downloadUrl,
+ this.type,
+ this.content,
+ this.encoding,
+ this.links,
+ this.license});
+
+ factory LicenseDetails.fromJson(Map<String, dynamic> json) =>
+ _$LicenseDetailsFromJson(json);
+}
+
+@JsonSerializable()
+class LicenseKind extends Object with _$LicenseKindSerializerMixin {
+ final String key;
+ final String name;
+
+ @JsonKey(name: 'spdx_id')
+ final String spdxId;
+ final Uri url;
+
+ @JsonKey(name: 'node_id')
+ final String nodeId;
+
+ LicenseKind({this.key, this.name, this.spdxId, this.url, this.nodeId});
+
+ factory LicenseKind.fromJson(Map<String, dynamic> json) =>
+ _$LicenseKindFromJson(json);
+}

MODIFY
lib/src/common/model/repos_contents.dart
lib/src/common/model/repos_contents.dart
@@ -64,33 +64,23 @@ class GitHubFile {
..sha = input['sha']
..gitUrl = input['git_url']
..htmlUrl = input['html_url']
- ..links = Links.fromJSON(input['_links'] as Map<String, dynamic>)
+ ..links = new Links.fromJson(input['_links'] as Map<String, dynamic>)
..sourceRepository = slug;
}
}
-/// File links.
-class Links {
- /// Git Link
- @ApiName("git")
- String git;
+@JsonSerializable()
+class Links extends Object with _$LinksSerializerMixin {
+ final Uri self;
+ final Uri git;
+ final Uri html;
- /// Self Link
- @ApiName("self")
- String self;
+ Links({this.git, this.self, this.html});
- /// HTML Link
- @ApiName("html")
- String html;
-
- static Links fromJSON(Map<String, dynamic> input) {
+ factory Links.fromJson(Map<String, dynamic> input) {
if (input == null) return null;
- var links = new Links();
- links.git = input['git'];
- links.self = input['self'];
- links.html = input['html'];
- return links;
+ return _$LinksFromJson(input);
}
}

MODIFY
lib/src/common/repos_service.dart
lib/src/common/repos_service.dart
@@ -89,6 +89,10 @@ class RepositoriesService extends Service {
}
}
+ Future<LicenseDetails> getLicense(RepositorySlug slug) =>
+ _github.getJSON("/repos/${slug.owner}/${slug.name}/license",
+ convert: (json) => new LicenseDetails.fromJson(json));
+
/// Fetches the repository specified by the [slug].
///
/// API docs: https://developer.github.com/v3/repos/#get

ADD
test/data_object_test.dart
+import 'dart:convert';
+
+import 'package:test/test.dart';
+import 'package:github/server.dart';
+
+final _licenseJson = r''' {
+ "name": "LICENSE",
+ "path": "LICENSE",
+ "sha": "68bcabfb39b7af5a1f5efbb8f651d51e16d60398",
+ "size": 2500,
+ "url": "https://api.github.com/repos/dart-lang/sdk/contents/LICENSE?ref=master",
+ "html_url": "https://github.com/dart-lang/sdk/blob/master/LICENSE",
+ "git_url": "https://api.github.com/repos/dart-lang/sdk/git/blobs/68bcabfb39b7af5a1f5efbb8f651d51e16d60398",
+ "download_url": "https://raw.githubusercontent.com/dart-lang/sdk/master/LICENSE",
+ "type": "file",
+ "content": "VGhpcyBsaWNlbnNlIGFwcGxpZXMgdG8gYWxsIHBhcnRzIG9mIERhcnQgdGhh\ndCBhcmUgbm90IGV4dGVybmFsbHkKbWFpbnRhaW5lZCBsaWJyYXJpZXMuIFRo\nZSBleHRlcm5hbCBtYWludGFpbmVkIGxpYnJhcmllcyB1c2VkIGJ5CkRhcnQg\nYXJlOgoKNy1aaXAgLSBpbiB0aGlyZF9wYXJ0eS83emlwCkpTQ1JFIC0gaW4g\ncnVudGltZS90aGlyZF9wYXJ0eS9qc2NyZQpBbnQgLSBpbiB0aGlyZF9wYXJ0\neS9hcGFjaGVfYW50CmFyZ3M0aiAtIGluIHRoaXJkX3BhcnR5L2FyZ3M0agpi\nemlwMiAtIGluIHRoaXJkX3BhcnR5L2J6aXAyCkNvbW1vbnMgSU8gLSBpbiB0\naGlyZF9wYXJ0eS9jb21tb25zLWlvCkNvbW1vbnMgTGFuZyBpbiB0aGlyZF9w\nYXJ0eS9jb21tb25zLWxhbmcKRWNsaXBzZSAtIGluIHRoaXJkX3BhcnR5L2Vj\nbGlwc2UKZ3N1dGlsIC0gaW4gdGhpcmRfcGFydHkvZ3N1dGlsCkd1YXZhIC0g\naW4gdGhpcmRfcGFydHkvZ3VhdmEKaGFtY3Jlc3QgLSBpbiB0aGlyZF9wYXJ0\neS9oYW1jcmVzdApIdHRwbGliMiAtIGluIHNhbXBsZXMvd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DVCwgSU5DSURFTlRBTCwKU1BFQ0lBTCwgRVhFTVBMQVJZLCBPUiBDT05T\nRVFVRU5USUFMIERBTUFHRVMgKElOQ0xVRElORywgQlVUIE5PVApMSU1JVEVE\nIFRPLCBQUk9DVVJFTUVOVCBPRiBTVUJTVElUVVRFIEdPT0RTIE9SIFNFUlZJ\nQ0VTOyBMT1NTIE9GIFVTRSwKREFUQSwgT1IgUFJPRklUUzsgT1IgQlVTSU5F\nU1MgSU5URVJSVVBUSU9OKSBIT1dFVkVSIENBVVNFRCBBTkQgT04gQU5ZClRI\nRU9SWSBPRiBMSUFCSUxJVFksIFdIRVRIRVIgSU4gQ09OVFJBQ1QsIFNUUklD\nVCBMSUFCSUxJVFksIE9SIFRPUlQKKElOQ0xVRElORyBORUdMSUdFTkNFIE9S\nIE9USEVSV0lTRSkgQVJJU0lORyBJTiBBTlkgV0FZIE9VVCBPRiBUSEUgVVNF\nCk9GIFRISVMgU09GVFdBUkUsIEVWRU4gSUYgQURWSVNFRCBPRiBUSEUgUE9T\nU0lCSUxJVFkgT0YgU1VDSCBEQU1BR0UuCg==\n",
+ "encoding": "base64",
+ "_links": {
+ "self": "https://api.github.com/repos/dart-lang/sdk/contents/LICENSE?ref=master",
+ "git": "https://api.github.com/repos/dart-lang/sdk/git/blobs/68bcabfb39b7af5a1f5efbb8f651d51e16d60398",
+ "html": "https://github.com/dart-lang/sdk/blob/master/LICENSE"
+ },
+ "license": {
+ "key": "other",
+ "name": "Other",
+ "spdx_id": null,
+ "url": null,
+ "node_id": "MDc6TGljZW5zZTA="
+ }
+}''';
+
+void main() {
+ test('License round-trip', () {
+ var licenseJson = jsonDecode(_licenseJson) as Map<String, dynamic>;
+
+ var instance = new LicenseDetails.fromJson(licenseJson);
+
+ var toJson = instance.toJson();
+
+ expect(_prettyEncode(toJson), _prettyEncode(licenseJson));
+ });
+}
+
+String _prettyEncode(obj) => const JsonEncoder.withIndent(' ').convert(obj);

add getLicense to repo service