initial support for comparing commits
MODIFY
CHANGELOG.md
CHANGELOG.md
## v4.0.0
-* Make fields in many objects read-only.
+- Make fields in many objects read-only.
+- Initial support for comparing commits.
## v3.0.0

MODIFY
lib/src/common.g.dart
lib/src/common.g.dart
@@ -28,6 +28,18 @@ GitTreeEntry _$GitTreeEntryFromJson(Map json) => new GitTreeEntry(
json['sha'] as String,
json['url'] as String);
+// **************************************************************************
+// Generator: JsonSerializableGenerator
+// Target: class GitHubComparison
+// **************************************************************************
+
+GitHubComparison _$GitHubComparisonFromJson(Map json) => new GitHubComparison(
+ json['url'] as String,
+ json['status'] as String,
+ json['ahead_by'] as int,
+ json['behind_by'] as int,
+ json['total_commits'] as int);
+
// **************************************************************************
// Generator: JsonSerializableGenerator
// Target: class Tag

MODIFY
lib/src/common/model/repos.dart
lib/src/common/model/repos.dart
part of github.common;
+@JsonSerializable(createToJson: false)
+class GitHubComparison {
+ final String url;
+
+ final String status;
+
+ @JsonKey('ahead_by')
+ final int aheadBy;
+
+ @JsonKey('behind_by')
+ final int behindBy;
+
+ @JsonKey('total_commits')
+ final int totalCommits;
+
+ GitHubComparison(
+ this.url, this.status, this.aheadBy, this.behindBy, this.totalCommits);
+
+ factory GitHubComparison.fromJson(Map<String, dynamic> json) =>
+ _$GitHubComparisonFromJson(json);
+
+ String toString() {
+ switch (status) {
+ case 'identical':
+ return "GitHubComparison: identical";
+ case 'behind':
+ return "GitHubComparison: behind ($behindBy)";
+ case 'diverged':
+ return "GitHubComparison: diverged";
+ case 'ahead':
+ return "GitHubComparison: ahead ($aheadBy)";
+ default:
+ return "Huh??? - $status";
+ }
+ }
+}
+
/// Model class for a repository.
class Repository {
/// Repository Name

MODIFY
lib/src/common/repos_service.dart
lib/src/common/repos_service.dart
@@ -270,7 +270,14 @@ class RepositoriesService extends Service {
convert: RepositoryCommit.fromJSON) as Future<RepositoryCommit>;
}
- // TODO: Implement compareCommits: https://developer.github.com/v3/repos/commits/#compare-two-commits
+ /// [refBase] and [refHead] can be the same value for a branch, commit, or ref
+ /// in [slug] or specify other repositories by using `repo:ref` syntax.
+ ///
+ /// API docs: https://developer.github.com/v3/repos/commits/#compare-two-commits
+ Future<GitHubComparison> compareCommits(
+ RepositorySlug slug, String refBase, String refHead) =>
+ _github.getJSON("/repos/${slug.fullName}/compare/${refBase}...${refHead}",
+ convert: (j) => new GitHubComparison.fromJson(j));
/// Fetches the readme file for a repository.
///

initial support for comparing commits