From a3081681da68383d9a5f18ef3502f47f7144e7d8 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Mon, 17 Apr 2023 07:50:18 -0700 Subject: [PATCH] Add support for Timeline events (#366) This is primarily based on the timeline API response schema (using code generated from the schema by the script in `tool/process_github_schema.dart`). Where I could find existing model classes compatible with bits of that schema I tried to re-use them, extending them as necessary. I took some liberties where the GitHub API documentation was vague, contradictory, or otherwise dubious. The comments on the new code are based on the comments in the response schema. They're not super helpful, if I'm honest. I found that some of the model classes were inconsistent in various ways and tried to clean up the code near what I touched to be more consistent. For example, I made a bunch of fields on a bunch of model classes mutable where previously they were `final`, to be more consistent with other model classes. I also moved some constructors to be above their corresponding fields to be more consistent with other code that already did that. --- CHANGELOG.md | 4 + CONTRIBUTING.md | 8 + lib/src/common.dart | 2 + lib/src/common/issues_service.dart | 11 + lib/src/common/model/issues.dart | 82 ++- lib/src/common/model/issues.g.dart | 51 ++ lib/src/common/model/orgs.dart | 173 +++-- lib/src/common/model/orgs.g.dart | 55 +- lib/src/common/model/pulls.dart | 211 +++++- lib/src/common/model/pulls.g.dart | 83 +++ lib/src/common/model/reaction.dart | 49 +- lib/src/common/model/reaction.g.dart | 28 + lib/src/common/model/repos.dart | 557 +++++++++++---- lib/src/common/model/repos.g.dart | 138 ++++ lib/src/common/model/repos_commits.dart | 39 +- lib/src/common/model/repos_commits.g.dart | 12 + lib/src/common/model/timeline.dart | 582 ++++++++++++++++ lib/src/common/model/timeline.g.dart | 671 +++++++++++++++++++ lib/src/common/model/timeline_support.dart | 562 ++++++++++++++++ lib/src/common/model/timeline_support.g.dart | 409 +++++++++++ lib/src/common/model/users.dart | 73 +- lib/src/common/model/users.g.dart | 60 ++ tool/process_github_schema.dart | 621 +++++++++++++++++ 23 files changed, 4264 insertions(+), 217 deletions(-) create mode 100644 lib/src/common/model/timeline.dart create mode 100644 lib/src/common/model/timeline.g.dart create mode 100644 lib/src/common/model/timeline_support.dart create mode 100644 lib/src/common/model/timeline_support.g.dart create mode 100644 tool/process_github_schema.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 7456f7d4..df8472a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 9.12.0 + +* Add support for issue and PR timeline events via `Issue.listTimeline`. + ## 9.11.0 * expose IssueLabel.description; update labels REST APIs by @devoncarew in https://github.com/SpinlockLabs/github.dart/pull/355 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 15f2d03b..47a2036f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,6 +30,14 @@ GitHub.dart is committed to efficiency as much as possible. If your code is not Pull Request rejections are not a bad thing. It just means you need to fix something. Perhaps it is important to define 'rejection' as it is used in this case. A rejection is when a GitHub.dart committer comments on a Pull Request with a comment like 'rejected due to incorrect formatting'. +## Generated code + +To regenerate the JSON logic for the models, run: + +``` +dart run build_runner build -d +``` + ## Tests To run the complete test suite you will need to install diff --git a/lib/src/common.dart b/lib/src/common.dart index f8be345c..8ec0f7ae 100644 --- a/lib/src/common.dart +++ b/lib/src/common.dart @@ -31,6 +31,8 @@ export 'package:github/src/common/model/repos_releases.dart'; export 'package:github/src/common/model/repos_stats.dart'; export 'package:github/src/common/model/repos_statuses.dart'; export 'package:github/src/common/model/search.dart'; +export 'package:github/src/common/model/timeline.dart'; +export 'package:github/src/common/model/timeline_support.dart'; export 'package:github/src/common/model/users.dart'; export 'package:github/src/common/orgs_service.dart'; export 'package:github/src/common/pulls_service.dart'; diff --git a/lib/src/common/issues_service.dart b/lib/src/common/issues_service.dart index 9d8eb4ab..3b5e013f 100644 --- a/lib/src/common/issues_service.dart +++ b/lib/src/common/issues_service.dart @@ -432,4 +432,15 @@ class IssuesService extends Service { .request('DELETE', '/repos/${slug.fullName}/milestones/$number') .then((response) => response.statusCode == StatusCodes.NO_CONTENT); } + + /// Lists all timeline events for an issue. + /// + /// API docs: https://docs.github.com/en/rest/issues/timeline?apiVersion=2022-11-28 + Stream listTimeline(RepositorySlug slug, int issueNumber) { + return PaginationHelper(github).objects( + 'GET', + '/repos/${slug.fullName}/issues/$issueNumber/timeline', + TimelineEvent.fromJson, + ); + } } diff --git a/lib/src/common/model/issues.dart b/lib/src/common/model/issues.dart index 6746a305..12b40172 100644 --- a/lib/src/common/model/issues.dart +++ b/lib/src/common/model/issues.dart @@ -1,5 +1,4 @@ import 'package:github/src/common.dart'; -import 'package:github/src/common/model/users.dart'; import 'package:json_annotation/json_annotation.dart'; part 'issues.g.dart'; @@ -26,6 +25,24 @@ class Issue { this.updatedAt, this.body = '', this.closedBy, + + // Properties from the Timeline API + this.activeLockReason, + this.authorAssociation, + this.bodyHtml, + this.bodyText, + this.commentsUrl, + this.draft, + this.eventsUrl, + this.labelsUrl, + this.locked, + this.nodeId, + this.performedViaGithubApp, + this.reactions, + this.repository, + this.repositoryUrl, + this.stateReason, + this.timelineUrl, }) { if (labels != null) { this.labels = labels; @@ -89,6 +106,46 @@ class Issue { bool get isOpen => state == 'open'; bool get isClosed => state == 'closed'; + // The following properties were added to support the Timeline API. + + String? activeLockReason; + + /// How the author is associated with the repository. + /// + /// Example: `OWNER` + String? authorAssociation; + + String? bodyHtml; + + String? bodyText; + + String? commentsUrl; + + bool? draft; + + String? eventsUrl; + + String? labelsUrl; + + bool? locked; + + String? nodeId; + + GitHubApp? performedViaGithubApp; + + ReactionRollup? reactions; + + Repository? repository; + + String? repositoryUrl; + + /// The reason for the current state + /// + /// Example: `not_planned` + String? stateReason; + + String? timelineUrl; + factory Issue.fromJson(Map input) => _$IssueFromJson(input); Map toJson() => _$IssueToJson(this); } @@ -204,6 +261,13 @@ class Milestone { this.createdAt, this.updatedAt, this.dueOn, + + // Properties from the Timeline API + this.closedAt, + this.htmlUrl, + this.labelsUrl, + this.nodeId, + this.url, }); /// Unique Identifier for Milestone @@ -241,6 +305,22 @@ class Milestone { /// The due date for this milestone DateTime? dueOn; + // The following properties were added to support the Timeline API. + + DateTime? closedAt; + + /// Example: `https://github.com/octocat/Hello-World/milestones/v1.0` + String? htmlUrl; + + /// Example: `https://api.github.com/repos/octocat/Hello-World/milestones/1/labels` + String? labelsUrl; + + /// Example: `MDk6TWlsZXN0b25lMTAwMjYwNA==` + String? nodeId; + + /// Example: `https://api.github.com/repos/octocat/Hello-World/milestones/1` + String? url; + factory Milestone.fromJson(Map input) => _$MilestoneFromJson(input); Map toJson() => _$MilestoneToJson(this); diff --git a/lib/src/common/model/issues.g.dart b/lib/src/common/model/issues.g.dart index 0a027f67..40bbfa94 100644 --- a/lib/src/common/model/issues.g.dart +++ b/lib/src/common/model/issues.g.dart @@ -47,6 +47,29 @@ Issue _$IssueFromJson(Map json) => Issue( closedBy: json['closed_by'] == null ? null : User.fromJson(json['closed_by'] as Map), + activeLockReason: json['active_lock_reason'] as String?, + authorAssociation: json['author_association'] as String?, + bodyHtml: json['body_html'] as String?, + bodyText: json['body_text'] as String?, + commentsUrl: json['comments_url'] as String?, + draft: json['draft'] as bool?, + eventsUrl: json['events_url'] as String?, + labelsUrl: json['labels_url'] as String?, + locked: json['locked'] as bool?, + nodeId: json['node_id'] as String?, + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + reactions: json['reactions'] == null + ? null + : ReactionRollup.fromJson(json['reactions'] as Map), + repository: json['repository'] == null + ? null + : Repository.fromJson(json['repository'] as Map), + repositoryUrl: json['repository_url'] as String?, + stateReason: json['state_reason'] as String?, + timelineUrl: json['timeline_url'] as String?, ); Map _$IssueToJson(Issue instance) => { @@ -68,6 +91,22 @@ Map _$IssueToJson(Issue instance) => { 'updated_at': instance.updatedAt?.toIso8601String(), 'body': instance.body, 'closed_by': instance.closedBy, + 'active_lock_reason': instance.activeLockReason, + 'author_association': instance.authorAssociation, + 'body_html': instance.bodyHtml, + 'body_text': instance.bodyText, + 'comments_url': instance.commentsUrl, + 'draft': instance.draft, + 'events_url': instance.eventsUrl, + 'labels_url': instance.labelsUrl, + 'locked': instance.locked, + 'node_id': instance.nodeId, + 'performed_via_github_app': instance.performedViaGithubApp, + 'reactions': instance.reactions, + 'repository': instance.repository, + 'repository_url': instance.repositoryUrl, + 'state_reason': instance.stateReason, + 'timeline_url': instance.timelineUrl, }; IssueRequest _$IssueRequestFromJson(Map json) => IssueRequest( @@ -172,6 +211,13 @@ Milestone _$MilestoneFromJson(Map json) => Milestone( dueOn: json['due_on'] == null ? null : DateTime.parse(json['due_on'] as String), + closedAt: json['closed_at'] == null + ? null + : DateTime.parse(json['closed_at'] as String), + htmlUrl: json['html_url'] as String?, + labelsUrl: json['labels_url'] as String?, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, ); Map _$MilestoneToJson(Milestone instance) => { @@ -186,6 +232,11 @@ Map _$MilestoneToJson(Milestone instance) => { 'created_at': instance.createdAt?.toIso8601String(), 'updated_at': instance.updatedAt?.toIso8601String(), 'due_on': instance.dueOn?.toIso8601String(), + 'closed_at': instance.closedAt?.toIso8601String(), + 'html_url': instance.htmlUrl, + 'labels_url': instance.labelsUrl, + 'node_id': instance.nodeId, + 'url': instance.url, }; CreateMilestone _$CreateMilestoneFromJson(Map json) => diff --git a/lib/src/common/model/orgs.dart b/lib/src/common/model/orgs.dart index 21f7b417..5a26bb2c 100644 --- a/lib/src/common/model/orgs.dart +++ b/lib/src/common/model/orgs.dart @@ -24,57 +24,57 @@ class Organization { }); /// Organization Login - final String? login; + String? login; /// Organization ID - final int? id; + int? id; /// Url to Organization Profile @JsonKey(name: 'html_url') - final String? htmlUrl; + String? htmlUrl; /// Url to the Organization Avatar @JsonKey(name: 'avatar_url') - final String? avatarUrl; + String? avatarUrl; /// Organization Name - final String? name; + String? name; /// Organization Company - final String? company; + String? company; /// Organization Blog - final String? blog; + String? blog; /// Organization Location - final String? location; + String? location; /// Organization Email - final String? email; + String? email; /// Number of Public Repositories @JsonKey(name: 'public_repos') - final int? publicReposCount; + int? publicReposCount; /// Number of Public Gists @JsonKey(name: 'public_gists') - final int? publicGistsCount; + int? publicGistsCount; /// Number of Followers @JsonKey(name: 'followers') - final int? followersCount; + int? followersCount; /// Number of People this Organization is Following @JsonKey(name: 'following') - final int? followingCount; + int? followingCount; /// Time this organization was created @JsonKey(name: 'created_at') - final DateTime? createdAt; + DateTime? createdAt; /// Time this organization was updated @JsonKey(name: 'updated_at') - final DateTime? updatedAt; + DateTime? updatedAt; factory Organization.fromJson(Map input) => _$OrganizationFromJson(input); @@ -88,8 +88,9 @@ class OrganizationMembership { this.state, this.organization, }); - final String? state; - final Organization? organization; + + String? state; + Organization? organization; factory OrganizationMembership.fromJson(Map input) { return _$OrganizationMembershipFromJson(input); @@ -98,49 +99,139 @@ class OrganizationMembership { } /// Model class for a GitHub team. +/// +/// Different end-points populate different sets of properties. +/// +/// Groups of organization members that gives permissions on specified repositories. @JsonSerializable() class Team { Team({ - this.name, + this.description, + this.htmlUrl, this.id, - this.permission, + this.ldapDn, this.membersCount, - this.reposCount, + this.membersUrl, + this.name, + this.nodeId, this.organization, + this.parent, + this.permission, + this.permissions, + this.privacy, + this.reposCount, + this.repositoriesUrl, + this.slug, + this.url, }); - /// Team Name - final String? name; + /// Description of the team + /// + /// Example: `A great team.` + String? description; - /// Team ID - final int? id; + /// Format: uri + /// + /// Example: `https://github.com/orgs/rails/teams/core` + String? htmlUrl; - /// Team Permission - final String? permission; + /// Unique identifier of the team + /// + /// Example: `1` + int? id; + + /// Distinguished Name (DN) that team maps to within LDAP environment + /// + /// Example: `uid=example,ou=users,dc=github,dc=com` + String? ldapDn; /// Number of Members @JsonKey(name: 'members_count') - final int? membersCount; + int? membersCount; + + /// Example: `https://api.github.com/organizations/1/team/1/members{/member}` + String? membersUrl; + + /// Name of the team + /// + /// Example: `Justice League` + String? name; + + /// Example: `MDQ6VGVhbTE=` + String? nodeId; + + /// Organization + Organization? organization; + + /// Team Simple + /// + /// Groups of organization members that gives permissions on specified repositories. + Team? parent; + + /// Permission that the team will have for its repositories + /// + /// Example: `admin` + String? permission; + + Permissions? permissions; + + /// The level of privacy this team should have + /// + /// Example: `closed` + String? privacy; /// Number of Repositories @JsonKey(name: 'repos_count') - final int? reposCount; + int? reposCount; - /// Organization - final Organization? organization; + /// Format: uri + /// + /// Example: `https://api.github.com/organizations/1/team/1/repos` + String? repositoriesUrl; + + /// Example: `justice-league` + String? slug; + + /// URL for the team + /// + /// Format: uri + /// + /// Example: `https://api.github.com/organizations/1/team/1` + String? url; - factory Team.fromJson(Map input) { - return _$TeamFromJson(input); - } Map toJson() => _$TeamToJson(this); + + factory Team.fromJson(Map input) => _$TeamFromJson(input); +} + +@JsonSerializable() +class Permissions { + Permissions({ + this.admin, + this.maintain, + this.pull, + this.push, + this.triage, + }); + + bool? admin; + bool? maintain; + bool? pull; + bool? push; + bool? triage; + + Map toJson() => _$PermissionsToJson(this); + + factory Permissions.fromJson(Map input) => + _$PermissionsFromJson(input); } /// Model class for the team membership state. class TeamMembershipState { - final String? name; - TeamMembershipState(this.name); + String? name; + bool get isPending => name == 'pending'; bool get isActive => name == 'active'; bool get isInactive => name == null; @@ -158,25 +249,25 @@ class TeamMember { this.htmlUrl}); /// Member Username - final String? login; + String? login; /// Member ID - final int? id; + int? id; /// Url to Member Avatar @JsonKey(name: 'avatar_url') - final String? avatarUrl; + String? avatarUrl; /// Member Type - final String? type; + String? type; /// If the member is a site administrator @JsonKey(name: 'site_admin') - final bool? siteAdmin; + bool? siteAdmin; /// Profile of the Member @JsonKey(name: 'html_url') - final String? htmlUrl; + String? htmlUrl; factory TeamMember.fromJson(Map input) { return _$TeamMemberFromJson(input); diff --git a/lib/src/common/model/orgs.g.dart b/lib/src/common/model/orgs.g.dart index 0e19f2cf..c32f6702 100644 --- a/lib/src/common/model/orgs.g.dart +++ b/lib/src/common/model/orgs.g.dart @@ -64,23 +64,66 @@ Map _$OrganizationMembershipToJson( }; Team _$TeamFromJson(Map json) => Team( - name: json['name'] as String?, + description: json['description'] as String?, + htmlUrl: json['html_url'] as String?, id: json['id'] as int?, - permission: json['permission'] as String?, + ldapDn: json['ldap_dn'] as String?, membersCount: json['members_count'] as int?, - reposCount: json['repos_count'] as int?, + membersUrl: json['members_url'] as String?, + name: json['name'] as String?, + nodeId: json['node_id'] as String?, organization: json['organization'] == null ? null : Organization.fromJson(json['organization'] as Map), + parent: json['parent'] == null + ? null + : Team.fromJson(json['parent'] as Map), + permission: json['permission'] as String?, + permissions: json['permissions'] == null + ? null + : Permissions.fromJson(json['permissions'] as Map), + privacy: json['privacy'] as String?, + reposCount: json['repos_count'] as int?, + repositoriesUrl: json['repositories_url'] as String?, + slug: json['slug'] as String?, + url: json['url'] as String?, ); Map _$TeamToJson(Team instance) => { - 'name': instance.name, + 'description': instance.description, + 'html_url': instance.htmlUrl, 'id': instance.id, - 'permission': instance.permission, + 'ldap_dn': instance.ldapDn, 'members_count': instance.membersCount, - 'repos_count': instance.reposCount, + 'members_url': instance.membersUrl, + 'name': instance.name, + 'node_id': instance.nodeId, 'organization': instance.organization, + 'parent': instance.parent, + 'permission': instance.permission, + 'permissions': instance.permissions, + 'privacy': instance.privacy, + 'repos_count': instance.reposCount, + 'repositories_url': instance.repositoriesUrl, + 'slug': instance.slug, + 'url': instance.url, + }; + +Permissions _$PermissionsFromJson(Map json) => Permissions( + admin: json['admin'] as bool?, + maintain: json['maintain'] as bool?, + pull: json['pull'] as bool?, + push: json['push'] as bool?, + triage: json['triage'] as bool?, + ); + +Map _$PermissionsToJson(Permissions instance) => + { + 'admin': instance.admin, + 'maintain': instance.maintain, + 'pull': instance.pull, + 'push': instance.push, + 'triage': instance.triage, }; TeamMember _$TeamMemberFromJson(Map json) => TeamMember( diff --git a/lib/src/common/model/pulls.dart b/lib/src/common/model/pulls.dart index fd6e8d70..b6f20e55 100644 --- a/lib/src/common/model/pulls.dart +++ b/lib/src/common/model/pulls.dart @@ -90,6 +90,7 @@ class PullRequest { /// Whether or not the pull request is a draft bool? draft; + String? mergeCommitSha; /// If the pull request was merged @@ -157,6 +158,7 @@ class PullRequestMerge { this.sha, this.message, }); + bool? merged; String? sha; String? message; @@ -194,16 +196,16 @@ class CreatePullRequest { CreatePullRequest(this.title, this.head, this.base, {this.draft = false, this.body}); - final String? title; - final String? head; - final String? base; + String? title; + String? head; + String? base; /// Whether a draft PR should be created. /// /// This is currently experimental functionality since the way draft PRs are /// created through Github's REST API is in developer preview only - and could change at any time. @experimental - final bool? draft; + bool? draft; String? body; @@ -231,6 +233,7 @@ class PullRequestComment { this.pullRequestUrl, this.links, }); + int? id; String? diffHunk; String? path; @@ -280,6 +283,7 @@ class PullRequestFile { this.contentsUrl, this.patch, }); + String? sha; String? filename; String? status; @@ -308,6 +312,7 @@ class PullRequestReview { this.state, this.htmlUrl, this.pullRequestUrl}); + int id; User user; String? body; @@ -326,17 +331,209 @@ class PullRequestReview { @JsonSerializable() class CreatePullRequestReview { CreatePullRequestReview(this.owner, this.repo, this.pullNumber, this.event, - {this.body}); + {this.body, this.comments}); String owner; String repo; String event; String? body; int pullNumber; - // TODO List comments; + List? comments; factory CreatePullRequestReview.fromJson(Map input) => _$CreatePullRequestReviewFromJson(input); Map toJson() => _$CreatePullRequestReviewToJson(this); } -// TODO PullRequestReviewComment https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request + +/// Pull Request Review Comment +/// +/// Pull Request Review Comments are comments on a portion of the Pull Request's +/// diff. +@JsonSerializable() +class PullRequestReviewComment { + PullRequestReviewComment({ + this.authorAssociation, + this.body, + this.bodyHtml, + this.bodyText, + this.commitId, + this.createdAt, + this.diffHunk, + this.htmlUrl, + this.id, + this.inReplyToId, + this.line, + this.links, + this.nodeId, + this.originalCommitId, + this.originalLine, + this.originalPosition, + this.originalStartLine, + this.path, + this.position, + this.pullRequestReviewId, + this.pullRequestUrl, + this.reactions, + this.side, + this.startLine, + this.startSide, + this.subjectType, + this.updatedAt, + this.url, + this.user, + }); + + /// How the author is associated with the repository. + /// + /// Example: `OWNER` + String? authorAssociation; + + /// The text of the comment. + /// + /// Example: `We should probably include a check for null values here.` + String? body; + + /// Example: `"

comment body

"` + String? bodyHtml; + + /// Example: `"comment body"` + String? bodyText; + + /// The SHA of the commit to which the comment applies. + /// + /// Example: `6dcb09b5b57875f334f61aebed695e2e4193db5e` + String? commitId; + + DateTime? createdAt; + + /// The diff of the line that the comment refers to. + /// + /// Example: `@@ -16,33 +16,40 @@ public class Connection : IConnection...` + String? diffHunk; + + /// HTML URL for the pull request review comment. + /// + /// Example: `https://github.com/octocat/Hello-World/pull/1#discussion-diff-1` + String? htmlUrl; + + /// The ID of the pull request review comment. + int? id; + + /// The comment ID to reply to. + int? inReplyToId; + + /// The line of the blob to which the comment applies. The last line of the range + /// for a multi-line comment + int? line; + + @JsonKey(name: '_links') + ReviewLinks? links; + + /// The node ID of the pull request review comment. + /// + /// Example: `MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDEw` + String? nodeId; + + /// The SHA of the original commit to which the comment applies. + /// + /// Example: `9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840` + String? originalCommitId; + + /// The line of the blob to which the comment applies. The last line of the range + /// for a multi-line comment + int? originalLine; + + /// The index of the original line in the diff to which the comment applies. This + /// field is deprecated; use `original_line` instead. + int? originalPosition; + + /// The first line of the range for a multi-line comment. + int? originalStartLine; + + /// The relative path of the file to which the comment applies. + /// + /// Example: `config/database.yaml` + String? path; + + /// The line index in the diff to which the comment applies. This field is deprecated; + /// use `line` instead. + int? position; + + /// The ID of the pull request review to which the comment belongs. + int? pullRequestReviewId; + + /// URL for the pull request that the review comment belongs to. + /// + /// Example: `https://api.github.com/repos/octocat/Hello-World/pulls/1` + String? pullRequestUrl; + + /// Reaction Rollup + ReactionRollup? reactions; + + /// The side of the diff to which the comment applies. The side of the last line + /// of the range for a multi-line comment + String? side; + + /// The first line of the range for a multi-line comment. + int? startLine; + + /// The side of the first line of the range for a multi-line comment. + String? startSide; + + /// The level at which the comment is targeted, can be a diff line or a file. + String? subjectType; + + DateTime? updatedAt; + + /// URL for the pull request review comment + /// + /// Example: `https://api.github.com/repos/octocat/Hello-World/pulls/comments/1` + String? url; + + User? user; + + Map toJson() => _$PullRequestReviewCommentToJson(this); + + factory PullRequestReviewComment.fromJson(Map input) => + _$PullRequestReviewCommentFromJson(input); +} + +/// This is similar to [Links] but represents a different serialization +/// in the GitHub API. +/// +/// It is used for [PullRequestReviewComment.links] and +/// [ReviewEvent.links]. +class ReviewLinks { + ReviewLinks({ + this.html, + this.pullRequest, + this.self, + }); + + Uri? html; + Uri? pullRequest; + Uri? self; + + Map toJson() { + return { + 'html': {'href': html?.toString()}, + 'pullRequest': {'href': pullRequest?.toString()}, + 'self': {'href': self?.toString()}, + }; + } + + static Uri? _parseBlock(Map input, String key) { + if (input[key] is Map && input[key]['href'] is String) { + return Uri.parse(input[key]['href']! as String); + } + return null; + } + + factory ReviewLinks.fromJson(Map input) { + return ReviewLinks( + html: _parseBlock(input, 'html'), + pullRequest: _parseBlock(input, 'pull_request'), + self: _parseBlock(input, 'self'), + ); + } +} diff --git a/lib/src/common/model/pulls.g.dart b/lib/src/common/model/pulls.g.dart index 62d2bba6..3608260c 100644 --- a/lib/src/common/model/pulls.g.dart +++ b/lib/src/common/model/pulls.g.dart @@ -284,6 +284,10 @@ CreatePullRequestReview _$CreatePullRequestReviewFromJson( json['pull_number'] as int, json['event'] as String, body: json['body'] as String?, + comments: (json['comments'] as List?) + ?.map((e) => + PullRequestReviewComment.fromJson(e as Map)) + .toList(), ); Map _$CreatePullRequestReviewToJson( @@ -294,4 +298,83 @@ Map _$CreatePullRequestReviewToJson( 'event': instance.event, 'body': instance.body, 'pull_number': instance.pullNumber, + 'comments': instance.comments, + }; + +PullRequestReviewComment _$PullRequestReviewCommentFromJson( + Map json) => + PullRequestReviewComment( + authorAssociation: json['author_association'] as String?, + body: json['body'] as String?, + bodyHtml: json['body_html'] as String?, + bodyText: json['body_text'] as String?, + commitId: json['commit_id'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + diffHunk: json['diff_hunk'] as String?, + htmlUrl: json['html_url'] as String?, + id: json['id'] as int?, + inReplyToId: json['in_reply_to_id'] as int?, + line: json['line'] as int?, + links: json['_links'] == null + ? null + : ReviewLinks.fromJson(json['_links'] as Map), + nodeId: json['node_id'] as String?, + originalCommitId: json['original_commit_id'] as String?, + originalLine: json['original_line'] as int?, + originalPosition: json['original_position'] as int?, + originalStartLine: json['original_start_line'] as int?, + path: json['path'] as String?, + position: json['position'] as int?, + pullRequestReviewId: json['pull_request_review_id'] as int?, + pullRequestUrl: json['pull_request_url'] as String?, + reactions: json['reactions'] == null + ? null + : ReactionRollup.fromJson(json['reactions'] as Map), + side: json['side'] as String?, + startLine: json['start_line'] as int?, + startSide: json['start_side'] as String?, + subjectType: json['subject_type'] as String?, + updatedAt: json['updated_at'] == null + ? null + : DateTime.parse(json['updated_at'] as String), + url: json['url'] as String?, + user: json['user'] == null + ? null + : User.fromJson(json['user'] as Map), + ); + +Map _$PullRequestReviewCommentToJson( + PullRequestReviewComment instance) => + { + 'author_association': instance.authorAssociation, + 'body': instance.body, + 'body_html': instance.bodyHtml, + 'body_text': instance.bodyText, + 'commit_id': instance.commitId, + 'created_at': instance.createdAt?.toIso8601String(), + 'diff_hunk': instance.diffHunk, + 'html_url': instance.htmlUrl, + 'id': instance.id, + 'in_reply_to_id': instance.inReplyToId, + 'line': instance.line, + '_links': instance.links, + 'node_id': instance.nodeId, + 'original_commit_id': instance.originalCommitId, + 'original_line': instance.originalLine, + 'original_position': instance.originalPosition, + 'original_start_line': instance.originalStartLine, + 'path': instance.path, + 'position': instance.position, + 'pull_request_review_id': instance.pullRequestReviewId, + 'pull_request_url': instance.pullRequestUrl, + 'reactions': instance.reactions, + 'side': instance.side, + 'start_line': instance.startLine, + 'start_side': instance.startSide, + 'subject_type': instance.subjectType, + 'updated_at': instance.updatedAt?.toIso8601String(), + 'url': instance.url, + 'user': instance.user, }; diff --git a/lib/src/common/model/reaction.dart b/lib/src/common/model/reaction.dart index 00b8e4ac..a9b73d7f 100644 --- a/lib/src/common/model/reaction.dart +++ b/lib/src/common/model/reaction.dart @@ -10,12 +10,6 @@ part 'reaction.g.dart'; /// See https://developer.github.com/v3/reactions/ @JsonSerializable() class Reaction { - final int? id; - final String? nodeId; - final User? user; - final String? content; - final DateTime? createdAt; - Reaction({ this.id, this.nodeId, @@ -24,6 +18,12 @@ class Reaction { this.createdAt, }); + int? id; + String? nodeId; + User? user; + String? content; + DateTime? createdAt; + ReactionType? get type => ReactionType.fromString(content); factory Reaction.fromJson(Map json) => @@ -34,9 +34,10 @@ class Reaction { @immutable class ReactionType { + const ReactionType._(this.content, this.emoji); + final String content; final String emoji; - const ReactionType._(this.content, this.emoji); @override String toString() => content; @@ -71,3 +72,37 @@ class ReactionType { static ReactionType? fromString(String? content) => _types[content!]; } + +@JsonSerializable() +class ReactionRollup { + ReactionRollup({ + this.plusOne, + this.minusOne, + this.confused, + this.eyes, + this.heart, + this.hooray, + this.laugh, + this.rocket, + this.totalCount, + this.url, + }); + + @JsonKey(name: '+1') + int? plusOne; + @JsonKey(name: '-1') + int? minusOne; + int? confused; + int? eyes; + int? heart; + int? hooray; + int? laugh; + int? rocket; + int? totalCount; + String? url; + + Map toJson() => _$ReactionRollupToJson(this); + + factory ReactionRollup.fromJson(Map input) => + _$ReactionRollupFromJson(input); +} diff --git a/lib/src/common/model/reaction.g.dart b/lib/src/common/model/reaction.g.dart index dc2ff705..d94eede4 100644 --- a/lib/src/common/model/reaction.g.dart +++ b/lib/src/common/model/reaction.g.dart @@ -25,3 +25,31 @@ Map _$ReactionToJson(Reaction instance) => { 'content': instance.content, 'created_at': instance.createdAt?.toIso8601String(), }; + +ReactionRollup _$ReactionRollupFromJson(Map json) => + ReactionRollup( + plusOne: json['+1'] as int?, + minusOne: json['-1'] as int?, + confused: json['confused'] as int?, + eyes: json['eyes'] as int?, + heart: json['heart'] as int?, + hooray: json['hooray'] as int?, + laugh: json['laugh'] as int?, + rocket: json['rocket'] as int?, + totalCount: json['total_count'] as int?, + url: json['url'] as String?, + ); + +Map _$ReactionRollupToJson(ReactionRollup instance) => + { + '+1': instance.plusOne, + '-1': instance.minusOne, + 'confused': instance.confused, + 'eyes': instance.eyes, + 'heart': instance.heart, + 'hooray': instance.hooray, + 'laugh': instance.laugh, + 'rocket': instance.rocket, + 'total_count': instance.totalCount, + 'url': instance.url, + }; diff --git a/lib/src/common/model/repos.dart b/lib/src/common/model/repos.dart index 3612aa34..d09c1a7e 100644 --- a/lib/src/common/model/repos.dart +++ b/lib/src/common/model/repos.dart @@ -5,17 +5,17 @@ part 'repos.g.dart'; @JsonSerializable() class GitHubComparison { - final String? url; - final String? status; - final int? aheadBy; - final int? behindBy; - final int? totalCommits; - final List? files; - final List? commits; - GitHubComparison(this.url, this.status, this.aheadBy, this.behindBy, this.totalCommits, this.files, this.commits); + String? url; + String? status; + int? aheadBy; + int? behindBy; + int? totalCommits; + List? files; + List? commits; + factory GitHubComparison.fromJson(Map json) => _$GitHubComparisonFromJson(json); Map toJson() => _$GitHubComparisonToJson(this); @@ -40,135 +40,416 @@ class GitHubComparison { /// Model class for a repository. @JsonSerializable() class Repository { - Repository( - {this.name = '', - this.id = 0, - this.fullName = '', - this.owner, - this.htmlUrl = '', - this.description = '', - this.cloneUrl = '', - this.gitUrl = '', - this.sshUrl = '', - this.svnUrl = '', - this.defaultBranch = '', - this.createdAt, - this.isPrivate = false, - this.isFork = false, - this.stargazersCount = 0, - this.watchersCount = 0, - this.language = '', - this.hasWiki = false, - this.hasDownloads = false, - this.forksCount = 0, - this.openIssuesCount = 0, - this.subscribersCount = 0, - this.networkCount = 0, - this.hasIssues = false, - this.size = 0, - this.archived = false, - this.disabled = false, - this.homepage = '', - this.updatedAt, - this.pushedAt, - this.license, - this.hasPages = false, - this.permissions}); + Repository({ + this.name = '', + this.id = 0, + this.fullName = '', + this.owner, + this.htmlUrl = '', + this.description = '', + this.cloneUrl = '', + this.gitUrl = '', + this.sshUrl = '', + this.svnUrl = '', + this.defaultBranch = '', + this.createdAt, + this.isPrivate = false, + this.isFork = false, + this.stargazersCount = 0, + this.watchersCount = 0, + this.language = '', + this.hasWiki = false, + this.hasDownloads = false, + this.forksCount = 0, + this.openIssuesCount = 0, + this.subscribersCount = 0, + this.networkCount = 0, + this.hasIssues = false, + this.size = 0, + this.archived = false, + this.disabled = false, + this.homepage = '', + this.updatedAt, + this.pushedAt, + this.license, + this.hasPages = false, + this.permissions, + + // Properties from the Timeline API + this.allowAutoMerge, + this.allowForking, + this.allowMergeCommit, + this.allowRebaseMerge, + this.allowSquashMerge, + this.allowUpdateBranch, + this.anonymousAccessEnabled, + this.archiveUrl, + this.assigneesUrl, + this.blobsUrl, + this.branchesUrl, + this.collaboratorsUrl, + this.commentsUrl, + this.commitsUrl, + this.compareUrl, + this.contentsUrl, + this.contributorsUrl, + this.deleteBranchOnMerge, + this.deploymentsUrl, + this.downloadsUrl, + this.eventsUrl, + this.forks, + this.forksUrl, + this.gitCommitsUrl, + this.gitRefsUrl, + this.gitTagsUrl, + this.hasDiscussions, + this.hasProjects, + this.hooksUrl, + this.isTemplate, + this.issueCommentUrl, + this.issueEventsUrl, + this.issuesUrl, + this.keysUrl, + this.labelsUrl, + this.languagesUrl, + this.masterBranch, + this.mergeCommitMessage, + this.mergeCommitTitle, + this.mergesUrl, + this.milestonesUrl, + this.mirrorUrl, + this.nodeId, + this.notificationsUrl, + this.openIssues, + this.organization, + this.pullsUrl, + this.releasesUrl, + this.squashMergeCommitMessage, + this.squashMergeCommitTitle, + this.stargazersUrl, + this.starredAt, + this.statusesUrl, + this.subscribersUrl, + this.subscriptionUrl, + this.tagsUrl, + this.teamsUrl, + this.tempCloneToken, + this.templateRepository, + this.topics, + this.treesUrl, + this.url, + this.visibility, + this.watchers, + this.webCommitSignoffRequired, + }); /// Repository Name - final String name; + String name; /// Repository ID - final int id; + int id; /// Full Repository Name - final String fullName; + String fullName; /// Repository Owner @JsonKey(defaultValue: null) - final UserInformation? owner; + UserInformation? owner; /// If the Repository is Private @JsonKey(name: 'private') - final bool isPrivate; + bool isPrivate; /// If the Repository is a fork @JsonKey(name: 'fork') - final bool isFork; + bool isFork; /// Url to the GitHub Repository Page - final String htmlUrl; + String htmlUrl; /// Repository Description - final String description; + String description; // https clone URL - final String cloneUrl; + String cloneUrl; - final String sshUrl; + String sshUrl; - final String svnUrl; + String svnUrl; - final String gitUrl; + String gitUrl; /// Url to the Repository Homepage - final String homepage; + String homepage; /// Repository Size - final int size; + // + /// The size of the repository. Size is calculated hourly. When a repository is + /// initially created, the size is 0. + int size; /// Repository Stars - final int stargazersCount; + int stargazersCount; /// Repository Watchers - final int watchersCount; + int watchersCount; /// Repository Language - final String language; + String language; /// If the Repository has Issues Enabled - final bool hasIssues; + bool hasIssues; /// If the Repository has the Wiki Enabled - final bool hasWiki; + bool hasWiki; /// If the Repository has any Downloads - final bool hasDownloads; + bool hasDownloads; /// If the Repository has any Github Pages - final bool hasPages; + bool hasPages; /// Number of Forks - final int forksCount; + int forksCount; /// Number of Open Issues - final int openIssuesCount; + int openIssuesCount; /// Repository Default Branch - final String defaultBranch; + String defaultBranch; /// Number of Subscribers - final int subscribersCount; + int subscribersCount; /// Number of users in the network - final int networkCount; + int networkCount; /// The time the repository was created at - final DateTime? createdAt; + DateTime? createdAt; /// The last time the repository was pushed at - final DateTime? pushedAt; + DateTime? pushedAt; - final DateTime? updatedAt; + DateTime? updatedAt; - final LicenseKind? license; + LicenseKind? license; - final bool archived; + bool archived; - final bool disabled; + bool disabled; RepositoryPermissions? permissions; + // The following properties were added to support the Timeline API. + + /// Whether to allow Auto-merge to be used on pull requests. + bool? allowAutoMerge; + + /// Whether to allow forking this repo + bool? allowForking; + + /// Whether to allow merge commits for pull requests. + bool? allowMergeCommit; + + /// Whether to allow rebase merges for pull requests. + bool? allowRebaseMerge; + + /// Whether to allow squash merges for pull requests. + bool? allowSquashMerge; + + /// Whether or not a pull request head branch that is behind its base branch can + /// always be updated even if it is not required to be up to date before merging. + bool? allowUpdateBranch; + + /// Whether anonymous git access is enabled for this repository + bool? anonymousAccessEnabled; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}` + String? archiveUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/assignees{/user}` + String? assigneesUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}` + String? blobsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/branches{/branch}` + String? branchesUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}` + String? collaboratorsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/comments{/number}` + String? commentsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/commits{/sha}` + String? commitsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}` + String? compareUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/contents/{+path}` + String? contentsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/contributors` + String? contributorsUrl; + + /// Whether to delete head branches when pull requests are merged + bool? deleteBranchOnMerge; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/deployments` + String? deploymentsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/downloads` + String? downloadsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/events` + String? eventsUrl; + + int? forks; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/forks` + String? forksUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/git/commits{/sha}` + String? gitCommitsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/git/refs{/sha}` + String? gitRefsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/git/tags{/sha}` + String? gitTagsUrl; + + /// Whether discussions are enabled. + bool? hasDiscussions; + + /// Whether projects are enabled. + bool? hasProjects; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/hooks` + String? hooksUrl; + + /// Whether this repository acts as a template that can be used to generate new + /// repositories. + bool? isTemplate; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/issues/comments{/number}` + String? issueCommentUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/issues/events{/number}` + String? issueEventsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/issues{/number}` + String? issuesUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/keys{/key_id}` + String? keysUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/labels{/name}` + String? labelsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/languages` + String? languagesUrl; + + String? masterBranch; + + /// The default value for a merge commit message. + /// + /// - `PR_TITLE` - default to the pull request's title. + /// - `PR_BODY` - default to the pull request's body. + /// - `BLANK` - default to a blank commit message. + String? mergeCommitMessage; + + /// The default value for a merge commit title. + /// + /// - `PR_TITLE` - default to the pull request's title. + /// - `MERGE_MESSAGE` - default to the classic title for a merge message (e.g., + /// Merge pull request #123 from branch-name). + String? mergeCommitTitle; + + /// Format: uri + /// + /// Example: `http://api.github.com/repos/octocat/Hello-World/merges` + String? mergesUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/milestones{/number}` + String? milestonesUrl; + + /// Format: uri + /// + /// Example: `git:git.example.com/octocat/Hello-World` + String? mirrorUrl; + + /// Example: `MDEwOlJlcG9zaXRvcnkxMjk2MjY5` + String? nodeId; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}` + String? notificationsUrl; + + int? openIssues; + + User? organization; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/pulls{/number}` + String? pullsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/releases{/id}` + String? releasesUrl; + + /// The default value for a squash merge commit message: + /// + /// - `PR_BODY` - default to the pull request's body. + /// - `COMMIT_MESSAGES` - default to the branch's commit messages. + /// - `BLANK` - default to a blank commit message. + String? squashMergeCommitMessage; + + /// The default value for a squash merge commit title: + /// + /// - `PR_TITLE` - default to the pull request's title. + /// - `COMMIT_OR_PR_TITLE` - default to the commit's title (if only one commit) + /// or the pull request's title (when more than one commit). + String? squashMergeCommitTitle; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/stargazers` + String? stargazersUrl; + + DateTime? starredAt; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/statuses/{sha}` + String? statusesUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/subscribers` + String? subscribersUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/subscription` + String? subscriptionUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/tags` + String? tagsUrl; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/teams` + String? teamsUrl; + + String? tempCloneToken; + + TemplateRepository? templateRepository; + + List? topics; + + /// Example: `http://api.github.com/repos/octocat/Hello-World/git/trees{/sha}` + String? treesUrl; + + /// Example: `https://api.github.com/repos/octocat/Hello-World` + String? url; + + /// The repository visibility: public, private, or internal. + String? visibility; + + int? watchers; + + /// Whether to require contributors to sign off on web-based commits + bool? webCommitSignoffRequired; + factory Repository.fromJson(Map input) => _$RepositoryFromJson(input); Map toJson() => _$RepositoryToJson(this); @@ -187,13 +468,13 @@ class RepositoryPermissions { {this.admin = false, this.push = false, this.pull = false}); /// Administrative Access - final bool admin; + bool admin; /// Push Access - final bool push; + bool push; /// Pull Access - final bool pull; + bool pull; factory RepositoryPermissions.fromJson(Map json) => _$RepositoryPermissionsFromJson(json); @@ -203,14 +484,14 @@ class RepositoryPermissions { @JsonSerializable() class Tag { - final String name; - final CommitInfo commit; + Tag(this.name, this.commit, this.zipUrl, this.tarUrl); + + String name; + CommitInfo commit; @JsonKey(name: 'zipball_url') - final String zipUrl; + String zipUrl; @JsonKey(name: 'tarball_url') - final String tarUrl; - - Tag(this.name, this.commit, this.zipUrl, this.tarUrl); + String tarUrl; factory Tag.fromJson(Map input) => _$TagFromJson(input); Map toJson() => _$TagToJson(this); @@ -221,18 +502,18 @@ class Tag { @JsonSerializable() class CommitData { - final String? sha; - final GitCommit? commit; - final String? url; - final String? htmlUrl; - final String? commentsUrl; - - final CommitDataUser? author, committer; - final List>? parents; - CommitData(this.sha, this.commit, this.url, this.htmlUrl, this.commentsUrl, this.author, this.committer, this.parents); + String? sha; + GitCommit? commit; + String? url; + String? htmlUrl; + String? commentsUrl; + + CommitDataUser? author, committer; + List>? parents; + factory CommitData.fromJson(Map input) => _$CommitDataFromJson(input); Map toJson() => _$CommitDataToJson(this); @@ -240,11 +521,11 @@ class CommitData { @JsonSerializable() class CommitDataUser { - final String? login, type; + CommitDataUser(this.login, this.id, this.type); - final int? id; + String? login, type; - CommitDataUser(this.login, this.id, this.type); + int? id; factory CommitDataUser.fromJson(Map input) => _$CommitDataUserFromJson(input); @@ -253,11 +534,11 @@ class CommitDataUser { @JsonSerializable() class CommitInfo { - final String? sha; - final GitTree? tree; - CommitInfo(this.sha, this.tree); + String? sha; + GitTree? tree; + factory CommitInfo.fromJson(Map input) => _$CommitInfoFromJson(input); Map toJson() => _$CommitInfoToJson(this); @@ -266,19 +547,19 @@ class CommitInfo { /// User Information @JsonSerializable() class UserInformation { + UserInformation(this.login, this.id, this.avatarUrl, this.htmlUrl); + /// Owner Username - final String login; + String login; /// Owner ID - final int id; + int id; /// Avatar Url - final String avatarUrl; + String avatarUrl; /// Url to the user's GitHub Profile - final String htmlUrl; - - UserInformation(this.login, this.id, this.avatarUrl, this.htmlUrl); + String htmlUrl; factory UserInformation.fromJson(Map input) => _$UserInformationFromJson(input); @@ -288,14 +569,14 @@ class UserInformation { /// A Repository Slug @JsonSerializable() class RepositorySlug { + RepositorySlug(this.owner, this.name); + /// Repository Owner String owner; /// Repository Name String name; - RepositorySlug(this.owner, this.name); - /// Creates a Repository Slug from a full name. factory RepositorySlug.full(String f) { final split = f.split('/'); @@ -340,7 +621,7 @@ class CreateRepository { this.hasWiki}); /// Repository Name - final String? name; + String? name; /// Repository Description String? description; @@ -383,13 +664,13 @@ class CreateRepository { /// Model class for a branch. @JsonSerializable() class Branch { + Branch(this.name, this.commit); + /// The name of the branch. - final String? name; + String? name; /// Commit Information - final CommitData? commit; - - Branch(this.name, this.commit); + CommitData? commit; factory Branch.fromJson(Map json) => _$BranchFromJson(json); Map toJson() => _$BranchToJson(this); @@ -397,10 +678,10 @@ class Branch { /// A Breakdown of the Languages a repository uses. class LanguageBreakdown { - final Map _data; - LanguageBreakdown(Map data) : _data = data; + final Map _data; + /// The Primary Language String get primary { final list = mapToList(_data); @@ -439,25 +720,6 @@ class LanguageBreakdown { @JsonSerializable() class LicenseDetails { - final String? name; - final String? path; - final String? sha; - final int? size; - final Uri? url; - - final Uri? htmlUrl; - final Uri? gitUrl; - 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, @@ -473,6 +735,25 @@ class LicenseDetails { this.links, this.license}); + String? name; + String? path; + String? sha; + int? size; + Uri? url; + + Uri? htmlUrl; + Uri? gitUrl; + Uri? downloadUrl; + + String? type; + String? content; + String? encoding; + + @JsonKey(name: '_links') + Links? links; + + LicenseKind? license; + factory LicenseDetails.fromJson(Map json) => _$LicenseDetailsFromJson(json); @@ -481,14 +762,14 @@ class LicenseDetails { @JsonSerializable() class LicenseKind { - final String? key; - final String? name; - final String? spdxId; - final Uri? url; - final String? nodeId; - LicenseKind({this.key, this.name, this.spdxId, this.url, this.nodeId}); + String? key; + String? name; + String? spdxId; + Uri? url; + String? nodeId; + factory LicenseKind.fromJson(Map json) => _$LicenseKindFromJson(json); diff --git a/lib/src/common/model/repos.g.dart b/lib/src/common/model/repos.g.dart index b2e395bd..490b18b1 100644 --- a/lib/src/common/model/repos.g.dart +++ b/lib/src/common/model/repos.g.dart @@ -79,6 +79,79 @@ Repository _$RepositoryFromJson(Map json) => Repository( ? null : RepositoryPermissions.fromJson( json['permissions'] as Map), + allowAutoMerge: json['allow_auto_merge'] as bool?, + allowForking: json['allow_forking'] as bool?, + allowMergeCommit: json['allow_merge_commit'] as bool?, + allowRebaseMerge: json['allow_rebase_merge'] as bool?, + allowSquashMerge: json['allow_squash_merge'] as bool?, + allowUpdateBranch: json['allow_update_branch'] as bool?, + anonymousAccessEnabled: json['anonymous_access_enabled'] as bool?, + archiveUrl: json['archive_url'] as String?, + assigneesUrl: json['assignees_url'] as String?, + blobsUrl: json['blobs_url'] as String?, + branchesUrl: json['branches_url'] as String?, + collaboratorsUrl: json['collaborators_url'] as String?, + commentsUrl: json['comments_url'] as String?, + commitsUrl: json['commits_url'] as String?, + compareUrl: json['compare_url'] as String?, + contentsUrl: json['contents_url'] as String?, + contributorsUrl: json['contributors_url'] as String?, + deleteBranchOnMerge: json['delete_branch_on_merge'] as bool?, + deploymentsUrl: json['deployments_url'] as String?, + downloadsUrl: json['downloads_url'] as String?, + eventsUrl: json['events_url'] as String?, + forks: json['forks'] as int?, + forksUrl: json['forks_url'] as String?, + gitCommitsUrl: json['git_commits_url'] as String?, + gitRefsUrl: json['git_refs_url'] as String?, + gitTagsUrl: json['git_tags_url'] as String?, + hasDiscussions: json['has_discussions'] as bool?, + hasProjects: json['has_projects'] as bool?, + hooksUrl: json['hooks_url'] as String?, + isTemplate: json['is_template'] as bool?, + issueCommentUrl: json['issue_comment_url'] as String?, + issueEventsUrl: json['issue_events_url'] as String?, + issuesUrl: json['issues_url'] as String?, + keysUrl: json['keys_url'] as String?, + labelsUrl: json['labels_url'] as String?, + languagesUrl: json['languages_url'] as String?, + masterBranch: json['master_branch'] as String?, + mergeCommitMessage: json['merge_commit_message'] as String?, + mergeCommitTitle: json['merge_commit_title'] as String?, + mergesUrl: json['merges_url'] as String?, + milestonesUrl: json['milestones_url'] as String?, + mirrorUrl: json['mirror_url'] as String?, + nodeId: json['node_id'] as String?, + notificationsUrl: json['notifications_url'] as String?, + openIssues: json['open_issues'] as int?, + organization: json['organization'] == null + ? null + : User.fromJson(json['organization'] as Map), + pullsUrl: json['pulls_url'] as String?, + releasesUrl: json['releases_url'] as String?, + squashMergeCommitMessage: json['squash_merge_commit_message'] as String?, + squashMergeCommitTitle: json['squash_merge_commit_title'] as String?, + stargazersUrl: json['stargazers_url'] as String?, + starredAt: json['starred_at'] == null + ? null + : DateTime.parse(json['starred_at'] as String), + statusesUrl: json['statuses_url'] as String?, + subscribersUrl: json['subscribers_url'] as String?, + subscriptionUrl: json['subscription_url'] as String?, + tagsUrl: json['tags_url'] as String?, + teamsUrl: json['teams_url'] as String?, + tempCloneToken: json['temp_clone_token'] as String?, + templateRepository: json['template_repository'] == null + ? null + : TemplateRepository.fromJson( + json['template_repository'] as Map), + topics: + (json['topics'] as List?)?.map((e) => e as String).toList(), + treesUrl: json['trees_url'] as String?, + url: json['url'] as String?, + visibility: json['visibility'] as String?, + watchers: json['watchers'] as int?, + webCommitSignoffRequired: json['web_commit_signoff_required'] as bool?, ); Map _$RepositoryToJson(Repository instance) => @@ -116,6 +189,71 @@ Map _$RepositoryToJson(Repository instance) => 'archived': instance.archived, 'disabled': instance.disabled, 'permissions': instance.permissions, + 'allow_auto_merge': instance.allowAutoMerge, + 'allow_forking': instance.allowForking, + 'allow_merge_commit': instance.allowMergeCommit, + 'allow_rebase_merge': instance.allowRebaseMerge, + 'allow_squash_merge': instance.allowSquashMerge, + 'allow_update_branch': instance.allowUpdateBranch, + 'anonymous_access_enabled': instance.anonymousAccessEnabled, + 'archive_url': instance.archiveUrl, + 'assignees_url': instance.assigneesUrl, + 'blobs_url': instance.blobsUrl, + 'branches_url': instance.branchesUrl, + 'collaborators_url': instance.collaboratorsUrl, + 'comments_url': instance.commentsUrl, + 'commits_url': instance.commitsUrl, + 'compare_url': instance.compareUrl, + 'contents_url': instance.contentsUrl, + 'contributors_url': instance.contributorsUrl, + 'delete_branch_on_merge': instance.deleteBranchOnMerge, + 'deployments_url': instance.deploymentsUrl, + 'downloads_url': instance.downloadsUrl, + 'events_url': instance.eventsUrl, + 'forks': instance.forks, + 'forks_url': instance.forksUrl, + 'git_commits_url': instance.gitCommitsUrl, + 'git_refs_url': instance.gitRefsUrl, + 'git_tags_url': instance.gitTagsUrl, + 'has_discussions': instance.hasDiscussions, + 'has_projects': instance.hasProjects, + 'hooks_url': instance.hooksUrl, + 'is_template': instance.isTemplate, + 'issue_comment_url': instance.issueCommentUrl, + 'issue_events_url': instance.issueEventsUrl, + 'issues_url': instance.issuesUrl, + 'keys_url': instance.keysUrl, + 'labels_url': instance.labelsUrl, + 'languages_url': instance.languagesUrl, + 'master_branch': instance.masterBranch, + 'merge_commit_message': instance.mergeCommitMessage, + 'merge_commit_title': instance.mergeCommitTitle, + 'merges_url': instance.mergesUrl, + 'milestones_url': instance.milestonesUrl, + 'mirror_url': instance.mirrorUrl, + 'node_id': instance.nodeId, + 'notifications_url': instance.notificationsUrl, + 'open_issues': instance.openIssues, + 'organization': instance.organization, + 'pulls_url': instance.pullsUrl, + 'releases_url': instance.releasesUrl, + 'squash_merge_commit_message': instance.squashMergeCommitMessage, + 'squash_merge_commit_title': instance.squashMergeCommitTitle, + 'stargazers_url': instance.stargazersUrl, + 'starred_at': instance.starredAt?.toIso8601String(), + 'statuses_url': instance.statusesUrl, + 'subscribers_url': instance.subscribersUrl, + 'subscription_url': instance.subscriptionUrl, + 'tags_url': instance.tagsUrl, + 'teams_url': instance.teamsUrl, + 'temp_clone_token': instance.tempCloneToken, + 'template_repository': instance.templateRepository, + 'topics': instance.topics, + 'trees_url': instance.treesUrl, + 'url': instance.url, + 'visibility': instance.visibility, + 'watchers': instance.watchers, + 'web_commit_signoff_required': instance.webCommitSignoffRequired, }; RepositoryPermissions _$RepositoryPermissionsFromJson( diff --git a/lib/src/common/model/repos_commits.dart b/lib/src/common/model/repos_commits.dart index 940917ab..f79c774f 100644 --- a/lib/src/common/model/repos_commits.dart +++ b/lib/src/common/model/repos_commits.dart @@ -133,37 +133,56 @@ class CommitComment { this.htmlUrl, this.updatedAt, this.body, + + // Properties from the Timeline API + this.authorAssociation, + this.nodeId, + this.reactions, + this.user, }); /// Id of the comment - final int? id; + int? id; /// Relative path of the file on which the comment has been posted - final String? path; + String? path; /// Line on file - final int? line; + int? line; /// Position on the diff - final int? position; + int? position; /// SHA of the commit where the comment has been made - final String? commitId; + String? commitId; - final DateTime? createdAt; + DateTime? createdAt; /// Can be equals to [createdAt] - final DateTime? updatedAt; + DateTime? updatedAt; /// Ex: https://github.com/... - final String? htmlUrl; + String? htmlUrl; /// Ex: https://api.github.com/... @JsonKey(name: 'url') - final String? apiUrl; + String? apiUrl; /// Content of the comment - final String? body; + String? body; + + // The following properties were added to support the Timeline API. + + /// How the author is associated with the repository. + /// + /// Example: `OWNER` + String? authorAssociation; + + String? nodeId; + + ReactionRollup? reactions; + + User? user; factory CommitComment.fromJson(Map input) => _$CommitCommentFromJson(input); diff --git a/lib/src/common/model/repos_commits.g.dart b/lib/src/common/model/repos_commits.g.dart index c91901fc..5e74c999 100644 --- a/lib/src/common/model/repos_commits.g.dart +++ b/lib/src/common/model/repos_commits.g.dart @@ -98,6 +98,14 @@ CommitComment _$CommitCommentFromJson(Map json) => ? null : DateTime.parse(json['updated_at'] as String), body: json['body'] as String?, + authorAssociation: json['author_association'] as String?, + nodeId: json['node_id'] as String?, + reactions: json['reactions'] == null + ? null + : ReactionRollup.fromJson(json['reactions'] as Map), + user: json['user'] == null + ? null + : User.fromJson(json['user'] as Map), ); Map _$CommitCommentToJson(CommitComment instance) => @@ -112,4 +120,8 @@ Map _$CommitCommentToJson(CommitComment instance) => 'html_url': instance.htmlUrl, 'url': instance.apiUrl, 'body': instance.body, + 'author_association': instance.authorAssociation, + 'node_id': instance.nodeId, + 'reactions': instance.reactions, + 'user': instance.user, }; diff --git a/lib/src/common/model/timeline.dart b/lib/src/common/model/timeline.dart new file mode 100644 index 00000000..ae2c48ef --- /dev/null +++ b/lib/src/common/model/timeline.dart @@ -0,0 +1,582 @@ +import 'package:github/src/common.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'timeline.g.dart'; + +// Parts of this file were originally automatically generated from the response +// schema provided in the API documentation for GitHub's "List timeline events +// for an issue" API [1], using the `tool/process_github_schema.dart` script. +// +// Unfortunately, that schema contradicts the prose documentation [2] in a great +// variety of ways (for example none of the "common properties" are actually +// common to all the event types), so this code is an attempt to find the most +// pragmatic middleground between what is documented and what actually works. +// +// [1] https://docs.github.com/en/rest/issues/timeline?apiVersion=2022-11-28 +// [2] https://docs.github.com/en/webhooks-and-events/events/issue-event-types + +/// Model class for an issue or PR timeline event. +/// +/// This is a base class for the various event types. Events that only use the +/// default fields use this class; events that have additional fields use one +/// of the subclasses. +/// +/// The [TimelineEvent.fromJson] factory selects the right subclass based on +/// the [event] field. +/// +/// If the [event] type is not known, [TimelineEvent] is used. +/// +/// See also: https://docs.github.com/en/webhooks-and-events/events/issue-event-types +@JsonSerializable() +class TimelineEvent { + TimelineEvent({ + this.id = 0, + this.nodeId, + this.url, + this.actor, + this.event = '', + this.commitId, + this.commitUrl, + this.createdAt, + this.performedViaGithubApp, + }); + + int id; + String? nodeId; + String? url; + User? actor; + String event; + String? commitId; + String? commitUrl; + DateTime? createdAt; + GitHubApp? performedViaGithubApp; + + Map toJson() => _$TimelineEventToJson(this); + + factory TimelineEvent.fromJson(Map input) { + switch (input['event']) { + case 'added_to_project': + return ProjectEvent.fromJson(input); + case 'assigned': + return AssigneeEvent.fromJson(input); + case 'commented': + return CommentEvent.fromJson(input); + case 'committed': + return TimelineCommitEvent.fromJson(input); + case 'cross-referenced': + return CrossReferenceEvent.fromJson(input); + case 'demilestoned': + return MilestoneEvent.fromJson(input); + case 'labeled': + return LabelEvent.fromJson(input); + case 'locked': + return LockEvent.fromJson(input); + case 'milestoned': + return MilestoneEvent.fromJson(input); + case 'moved_columns_in_project': + return ProjectEvent.fromJson(input); + case 'removed_from_project': + return ProjectEvent.fromJson(input); + case 'renamed': + return RenameEvent.fromJson(input); + case 'review_dismissed': + return ReviewDismissedEvent.fromJson(input); + case 'review_requested': + return ReviewRequestEvent.fromJson(input); + case 'review_request_removed': + return ReviewRequestEvent.fromJson(input); + case 'reviewed': + return ReviewEvent.fromJson(input); + case 'unassigned': + return AssigneeEvent.fromJson(input); + case 'unlabeled': + return LabelEvent.fromJson(input); + default: + return _$TimelineEventFromJson(input); + } + } +} + +/// Labeled and Unlabeled Issue Events +@JsonSerializable() +class LabelEvent extends TimelineEvent { + LabelEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = '', // typically 'labeled' or 'unlabeled' + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.label, + }); + + IssueLabel? label; + + @override + Map toJson() => _$LabelEventToJson(this); + + factory LabelEvent.fromJson(Map input) => + _$LabelEventFromJson(input); +} + +/// Milestoned and Demilestoned Issue Event +@JsonSerializable() +class MilestoneEvent extends TimelineEvent { + MilestoneEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = '', // typically 'milestoned' or 'demilestoned' + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.milestone, + }); + + Milestone? milestone; + + @override + Map toJson() => _$MilestoneEventToJson(this); + + factory MilestoneEvent.fromJson(Map input) => + _$MilestoneEventFromJson(input); +} + +/// Renamed Issue Event +@JsonSerializable() +class RenameEvent extends TimelineEvent { + RenameEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = 'renamed', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.rename, + }); + + Rename? rename; + + @override + Map toJson() => _$RenameEventToJson(this); + + factory RenameEvent.fromJson(Map input) => + _$RenameEventFromJson(input); +} + +/// Review Requested and Review Request Removed Issue Events +@JsonSerializable() +class ReviewRequestEvent extends TimelineEvent { + ReviewRequestEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = + '', // typically 'review_requested' or 'review_request_removed' + super.commitId, + super.commitUrl, + super.createdAt, + this.requestedReviewer, + this.requestedTeam, + this.reviewRequester, + }); + + User? requestedReviewer; + + /// Team + /// + /// Groups of organization members that gives permissions on specified repositories. + Team? requestedTeam; + + User? reviewRequester; + + @override + Map toJson() => _$ReviewRequestEventToJson(this); + + factory ReviewRequestEvent.fromJson(Map input) => + _$ReviewRequestEventFromJson(input); +} + +/// Review Dismissed Issue Event +@JsonSerializable() +class ReviewDismissedEvent extends TimelineEvent { + ReviewDismissedEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = 'review_dismissed', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.dismissedReview, + }); + + DismissedReview? dismissedReview; + + @override + Map toJson() => _$ReviewDismissedEventToJson(this); + + factory ReviewDismissedEvent.fromJson(Map input) => + _$ReviewDismissedEventFromJson(input); +} + +/// Locked Issue Event +@JsonSerializable() +class LockEvent extends TimelineEvent { + LockEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = 'locked', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.lockReason, + }); + + /// Example: `"off-topic"` + String? lockReason; + + @override + Map toJson() => _$LockEventToJson(this); + + factory LockEvent.fromJson(Map input) => + _$LockEventFromJson(input); +} + +/// Added to Project, +/// Moved Columns in Project, +/// Removed from Project, and +/// Converted Note to Issue +/// Issue Events. +@JsonSerializable() +class ProjectEvent extends TimelineEvent { + ProjectEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event, // typically one of 'added_to_project', 'moved_columns_in_project', 'removed_from_project', 'converted_note_to_issue' + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.projectCard, + }); + + ProjectCard? projectCard; + + @override + Map toJson() => _$ProjectEventToJson(this); + + factory ProjectEvent.fromJson(Map input) => + _$ProjectEventFromJson(input); +} + +/// Timeline Comment Event +@JsonSerializable() +class CommentEvent extends TimelineEvent { + CommentEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = 'commented', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.authorAssociation, + this.body, + this.bodyHtml, + this.bodyText, + this.htmlUrl, + this.issueUrl, + this.reactions, + this.updatedAt, + this.user, + }); + + /// How the author is associated with the repository. + /// + /// Example: `OWNER` + String? authorAssociation; + + /// Contents of the issue comment + /// + /// Example: `What version of Safari were you using when you observed this bug?` + String? body; + + String? bodyHtml; + String? bodyText; + + String? htmlUrl; + + String? issueUrl; + + ReactionRollup? reactions; + + DateTime? updatedAt; + + User? user; + + @override + Map toJson() => _$CommentEventToJson(this); + + factory CommentEvent.fromJson(Map input) => + _$CommentEventFromJson(input); +} + +/// Timeline Cross Referenced Event +@JsonSerializable() +class CrossReferenceEvent extends TimelineEvent { + CrossReferenceEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = 'cross-referenced', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.source, + this.updatedAt, + }); + + Source? source; + + DateTime? updatedAt; + + @override + Map toJson() => _$CrossReferenceEventToJson(this); + + factory CrossReferenceEvent.fromJson(Map input) => + _$CrossReferenceEventFromJson(input); +} + +/// Timeline Committed Event +@JsonSerializable() +class TimelineCommitEvent extends TimelineEvent { + TimelineCommitEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = 'committed', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.author, + this.committer, + this.htmlUrl, + this.message, + this.parents, + this.sha, + this.tree, + this.verification, + }); + + User? author; + + /// Identifying information for the git-user + User? committer; + + /// Format: uri + String? htmlUrl; + + /// Message describing the purpose of the commit + String? message; + + List? parents; + + /// SHA for the commit + /// + /// Example: `7638417db6d59f3c431d3e1f261cc637155684cd` + String? sha; + + Tree? tree; + + Verification? verification; + + @override + Map toJson() => _$TimelineCommitEventToJson(this); + + factory TimelineCommitEvent.fromJson(Map input) => + _$TimelineCommitEventFromJson(input); +} + +/// Timeline Reviewed Event +@JsonSerializable() +class ReviewEvent extends TimelineEvent { + ReviewEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = 'reviewed', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.authorAssociation, + this.body, + this.bodyHtml, + this.bodyText, + this.htmlUrl, + this.links, + this.pullRequestUrl, + this.state, + this.submittedAt, + this.user, + }); + + /// How the author is associated with the repository. + /// + /// Example: `OWNER` + String? authorAssociation; + + /// The text of the review. + /// + /// Example: `This looks great.` + String? body; + + String? bodyHtml; + String? bodyText; + + /// Example: `https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80` + String? htmlUrl; + + @JsonKey(name: '_links') + ReviewLinks? links; + + /// Example: `https://api.github.com/repos/octocat/Hello-World/pulls/12` + String? pullRequestUrl; + + /// Example: `CHANGES_REQUESTED` + String? state; + + DateTime? submittedAt; + + User? user; + + @override + Map toJson() => _$ReviewEventToJson(this); + + factory ReviewEvent.fromJson(Map input) => + _$ReviewEventFromJson(input); +} + +/// Timeline Line Commented Event +@JsonSerializable() +class TimelineLineCommentedEvent extends TimelineEvent { + TimelineLineCommentedEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = '', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.comments, + }); + + List? comments; + + @override + Map toJson() => _$TimelineLineCommentedEventToJson(this); + + factory TimelineLineCommentedEvent.fromJson(Map input) => + _$TimelineLineCommentedEventFromJson(input); +} + +/// Timeline Commit Commented Event +@JsonSerializable() +class TimelineCommitCommentedEvent extends TimelineEvent { + TimelineCommitCommentedEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = '', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.comments, + }); + + List? comments; + + @override + Map toJson() => _$TimelineCommitCommentedEventToJson(this); + + factory TimelineCommitCommentedEvent.fromJson(Map input) => + _$TimelineCommitCommentedEventFromJson(input); +} + +/// Timeline Assigned and Timeline Unassigned Issue Events +@JsonSerializable() +class AssigneeEvent extends TimelineEvent { + AssigneeEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event, // typically 'assigned' or 'unassigned' + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.assignee, + }); + + User? assignee; + + @override + Map toJson() => _$AssigneeEventToJson(this); + + factory AssigneeEvent.fromJson(Map input) => + _$AssigneeEventFromJson(input); +} + +/// State Change Issue Event +@JsonSerializable() +class StateChangeIssueEvent extends TimelineEvent { + StateChangeIssueEvent({ + super.id = 0, + super.nodeId, + super.url, + super.actor, + super.event = '', + super.commitId, + super.commitUrl, + super.createdAt, + super.performedViaGithubApp, + this.stateReason, + }); + + String? stateReason; + + @override + Map toJson() => _$StateChangeIssueEventToJson(this); + + factory StateChangeIssueEvent.fromJson(Map input) => + _$StateChangeIssueEventFromJson(input); +} diff --git a/lib/src/common/model/timeline.g.dart b/lib/src/common/model/timeline.g.dart new file mode 100644 index 00000000..9d0bfc5a --- /dev/null +++ b/lib/src/common/model/timeline.g.dart @@ -0,0 +1,671 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'timeline.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +TimelineEvent _$TimelineEventFromJson(Map json) => + TimelineEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? '', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + ); + +Map _$TimelineEventToJson(TimelineEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + }; + +LabelEvent _$LabelEventFromJson(Map json) => LabelEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? '', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + label: json['label'] == null + ? null + : IssueLabel.fromJson(json['label'] as Map), + ); + +Map _$LabelEventToJson(LabelEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'label': instance.label, + }; + +MilestoneEvent _$MilestoneEventFromJson(Map json) => + MilestoneEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? '', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + milestone: json['milestone'] == null + ? null + : Milestone.fromJson(json['milestone'] as Map), + ); + +Map _$MilestoneEventToJson(MilestoneEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'milestone': instance.milestone, + }; + +RenameEvent _$RenameEventFromJson(Map json) => RenameEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? 'renamed', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + rename: json['rename'] == null + ? null + : Rename.fromJson(json['rename'] as Map), + ); + +Map _$RenameEventToJson(RenameEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'rename': instance.rename, + }; + +ReviewRequestEvent _$ReviewRequestEventFromJson(Map json) => + ReviewRequestEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? '', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + requestedReviewer: json['requested_reviewer'] == null + ? null + : User.fromJson(json['requested_reviewer'] as Map), + requestedTeam: json['requested_team'] == null + ? null + : Team.fromJson(json['requested_team'] as Map), + reviewRequester: json['review_requester'] == null + ? null + : User.fromJson(json['review_requester'] as Map), + )..performedViaGithubApp = json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map); + +Map _$ReviewRequestEventToJson(ReviewRequestEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'requested_reviewer': instance.requestedReviewer, + 'requested_team': instance.requestedTeam, + 'review_requester': instance.reviewRequester, + }; + +ReviewDismissedEvent _$ReviewDismissedEventFromJson( + Map json) => + ReviewDismissedEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? 'review_dismissed', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + dismissedReview: json['dismissed_review'] == null + ? null + : DismissedReview.fromJson( + json['dismissed_review'] as Map), + ); + +Map _$ReviewDismissedEventToJson( + ReviewDismissedEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'dismissed_review': instance.dismissedReview, + }; + +LockEvent _$LockEventFromJson(Map json) => LockEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? 'locked', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + lockReason: json['lock_reason'] as String?, + ); + +Map _$LockEventToJson(LockEvent instance) => { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'lock_reason': instance.lockReason, + }; + +ProjectEvent _$ProjectEventFromJson(Map json) => ProjectEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? '', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + projectCard: json['project_card'] == null + ? null + : ProjectCard.fromJson(json['project_card'] as Map), + ); + +Map _$ProjectEventToJson(ProjectEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'project_card': instance.projectCard, + }; + +CommentEvent _$CommentEventFromJson(Map json) => CommentEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? 'commented', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + authorAssociation: json['author_association'] as String?, + body: json['body'] as String?, + bodyHtml: json['body_html'] as String?, + bodyText: json['body_text'] as String?, + htmlUrl: json['html_url'] as String?, + issueUrl: json['issue_url'] as String?, + reactions: json['reactions'] == null + ? null + : ReactionRollup.fromJson(json['reactions'] as Map), + updatedAt: json['updated_at'] == null + ? null + : DateTime.parse(json['updated_at'] as String), + user: json['user'] == null + ? null + : User.fromJson(json['user'] as Map), + ); + +Map _$CommentEventToJson(CommentEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'author_association': instance.authorAssociation, + 'body': instance.body, + 'body_html': instance.bodyHtml, + 'body_text': instance.bodyText, + 'html_url': instance.htmlUrl, + 'issue_url': instance.issueUrl, + 'reactions': instance.reactions, + 'updated_at': instance.updatedAt?.toIso8601String(), + 'user': instance.user, + }; + +CrossReferenceEvent _$CrossReferenceEventFromJson(Map json) => + CrossReferenceEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? 'cross-referenced', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + source: json['source'] == null + ? null + : Source.fromJson(json['source'] as Map), + updatedAt: json['updated_at'] == null + ? null + : DateTime.parse(json['updated_at'] as String), + ); + +Map _$CrossReferenceEventToJson( + CrossReferenceEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'source': instance.source, + 'updated_at': instance.updatedAt?.toIso8601String(), + }; + +TimelineCommitEvent _$TimelineCommitEventFromJson(Map json) => + TimelineCommitEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? 'committed', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + author: json['author'] == null + ? null + : User.fromJson(json['author'] as Map), + committer: json['committer'] == null + ? null + : User.fromJson(json['committer'] as Map), + htmlUrl: json['html_url'] as String?, + message: json['message'] as String?, + parents: (json['parents'] as List?) + ?.map((e) => Tree.fromJson(e as Map)) + .toList(), + sha: json['sha'] as String?, + tree: json['tree'] == null + ? null + : Tree.fromJson(json['tree'] as Map), + verification: json['verification'] == null + ? null + : Verification.fromJson(json['verification'] as Map), + ); + +Map _$TimelineCommitEventToJson( + TimelineCommitEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'author': instance.author, + 'committer': instance.committer, + 'html_url': instance.htmlUrl, + 'message': instance.message, + 'parents': instance.parents, + 'sha': instance.sha, + 'tree': instance.tree, + 'verification': instance.verification, + }; + +ReviewEvent _$ReviewEventFromJson(Map json) => ReviewEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? 'reviewed', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + authorAssociation: json['author_association'] as String?, + body: json['body'] as String?, + bodyHtml: json['body_html'] as String?, + bodyText: json['body_text'] as String?, + htmlUrl: json['html_url'] as String?, + links: json['_links'] == null + ? null + : ReviewLinks.fromJson(json['_links'] as Map), + pullRequestUrl: json['pull_request_url'] as String?, + state: json['state'] as String?, + submittedAt: json['submitted_at'] == null + ? null + : DateTime.parse(json['submitted_at'] as String), + user: json['user'] == null + ? null + : User.fromJson(json['user'] as Map), + ); + +Map _$ReviewEventToJson(ReviewEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'author_association': instance.authorAssociation, + 'body': instance.body, + 'body_html': instance.bodyHtml, + 'body_text': instance.bodyText, + 'html_url': instance.htmlUrl, + '_links': instance.links, + 'pull_request_url': instance.pullRequestUrl, + 'state': instance.state, + 'submitted_at': instance.submittedAt?.toIso8601String(), + 'user': instance.user, + }; + +TimelineLineCommentedEvent _$TimelineLineCommentedEventFromJson( + Map json) => + TimelineLineCommentedEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? '', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + comments: (json['comments'] as List?) + ?.map((e) => + PullRequestReviewComment.fromJson(e as Map)) + .toList(), + ); + +Map _$TimelineLineCommentedEventToJson( + TimelineLineCommentedEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'comments': instance.comments, + }; + +TimelineCommitCommentedEvent _$TimelineCommitCommentedEventFromJson( + Map json) => + TimelineCommitCommentedEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? '', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + comments: (json['comments'] as List?) + ?.map((e) => CommitComment.fromJson(e as Map)) + .toList(), + ); + +Map _$TimelineCommitCommentedEventToJson( + TimelineCommitCommentedEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'comments': instance.comments, + }; + +AssigneeEvent _$AssigneeEventFromJson(Map json) => + AssigneeEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? '', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + assignee: json['assignee'] == null + ? null + : User.fromJson(json['assignee'] as Map), + ); + +Map _$AssigneeEventToJson(AssigneeEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'assignee': instance.assignee, + }; + +StateChangeIssueEvent _$StateChangeIssueEventFromJson( + Map json) => + StateChangeIssueEvent( + id: json['id'] as int? ?? 0, + nodeId: json['node_id'] as String?, + url: json['url'] as String?, + actor: json['actor'] == null + ? null + : User.fromJson(json['actor'] as Map), + event: json['event'] as String? ?? '', + commitId: json['commit_id'] as String?, + commitUrl: json['commit_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + performedViaGithubApp: json['performed_via_github_app'] == null + ? null + : GitHubApp.fromJson( + json['performed_via_github_app'] as Map), + stateReason: json['state_reason'] as String?, + ); + +Map _$StateChangeIssueEventToJson( + StateChangeIssueEvent instance) => + { + 'id': instance.id, + 'node_id': instance.nodeId, + 'url': instance.url, + 'actor': instance.actor, + 'event': instance.event, + 'commit_id': instance.commitId, + 'commit_url': instance.commitUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'performed_via_github_app': instance.performedViaGithubApp, + 'state_reason': instance.stateReason, + }; diff --git a/lib/src/common/model/timeline_support.dart b/lib/src/common/model/timeline_support.dart new file mode 100644 index 00000000..f2b03c62 --- /dev/null +++ b/lib/src/common/model/timeline_support.dart @@ -0,0 +1,562 @@ +import 'package:github/src/common.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'timeline_support.g.dart'; + +/// GitHub app +/// +/// GitHub apps are a new way to extend GitHub. They can be installed directly +/// on organizations and user accounts and granted access to specific repositories. +/// They come with granular permissions and built-in webhooks. GitHub apps are +/// first class actors within GitHub. +@JsonSerializable() +class GitHubApp { + GitHubApp({ + this.clientId, + this.clientSecret, + this.createdAt, + this.description, + this.events, + this.externalUrl, + this.htmlUrl, + this.id, + this.installationsCount, + this.name, + this.nodeId, + this.owner, + this.pem, + this.permissions, + this.slug, + this.updatedAt, + this.webhookSecret, + }); + + /// Example: `"Iv1.25b5d1e65ffc4022"` + final String? clientId; + + /// Example: `"1d4b2097ac622ba702d19de498f005747a8b21d3"` + final String? clientSecret; + + final DateTime? createdAt; + + final String? description; + + /// The list of events for the GitHub app + /// + /// Example: `label` + /// + /// Example: `deployment` + final List? events; + + /// Example: `https://example.com` + final String? externalUrl; + + /// Example: `https://github.com/apps/super-ci` + final String? htmlUrl; + + /// Unique identifier of the GitHub app + final int? id; + + /// The number of installations associated with the GitHub app + final int? installationsCount; + + /// The name of the GitHub app + /// + /// Example: `Probot Owners` + final String? name; + + /// Example: `MDExOkludGVncmF0aW9uMQ==` + final String? nodeId; + + final User? owner; + + /// Example: + /// + /// ``` + /// -----BEGIN RSA PRIVATE KEY----- + /// MIIEogIBAAKCAQEArYxrNYD/iT5CZVpRJu4rBKmmze3PVmT/gCo2ATUvDvZTPTey + /// xcGJ3vvrJXazKk06pN05TN29o98jrYz4cengG3YGsXPNEpKsIrEl8NhbnxapEnM9 + /// JCMRe0P5JcPsfZlX6hmiT7136GRWiGOUba2X9+HKh8QJVLG5rM007TBER9/z9mWm + /// rJuNh+m5l320oBQY/Qq3A7wzdEfZw8qm/mIN0FCeoXH1L6B8xXWaAYBwhTEh6SSn + /// ZHlO1Xu1JWDmAvBCi0RO5aRSKM8q9QEkvvHP4yweAtK3N8+aAbZ7ovaDhyGz8r6r + /// zhU1b8Uo0Z2ysf503WqzQgIajr7Fry7/kUwpgQIDAQABAoIBADwJp80Ko1xHPZDy + /// fcCKBDfIuPvkmSW6KumbsLMaQv1aGdHDwwTGv3t0ixSay8CGlxMRtRDyZPib6SvQ + /// 6OH/lpfpbMdW2ErkksgtoIKBVrDilfrcAvrNZu7NxRNbhCSvN8q0s4ICecjbbVQh + /// nueSdlA6vGXbW58BHMq68uRbHkP+k+mM9U0mDJ1HMch67wlg5GbayVRt63H7R2+r + /// Vxcna7B80J/lCEjIYZznawgiTvp3MSanTglqAYi+m1EcSsP14bJIB9vgaxS79kTu + /// oiSo93leJbBvuGo8QEiUqTwMw4tDksmkLsoqNKQ1q9P7LZ9DGcujtPy4EZsamSJT + /// y8OJt0ECgYEA2lxOxJsQk2kI325JgKFjo92mQeUObIvPfSNWUIZQDTjniOI6Gv63 + /// GLWVFrZcvQBWjMEQraJA9xjPbblV8PtfO87MiJGLWCHFxmPz2dzoedN+2Coxom8m + /// V95CLz8QUShuao6u/RYcvUaZEoYs5bHcTmy5sBK80JyEmafJPtCQVxMCgYEAy3ar + /// Zr3yv4xRPEPMat4rseswmuMooSaK3SKub19WFI5IAtB/e7qR1Rj9JhOGcZz+OQrl + /// T78O2OFYlgOIkJPvRMrPpK5V9lslc7tz1FSh3BZMRGq5jSyD7ETSOQ0c8T2O/s7v + /// beEPbVbDe4mwvM24XByH0GnWveVxaDl51ABD65sCgYB3ZAspUkOA5egVCh8kNpnd + /// Sd6SnuQBE3ySRlT2WEnCwP9Ph6oPgn+oAfiPX4xbRqkL8q/k0BdHQ4h+zNwhk7+h + /// WtPYRAP1Xxnc/F+jGjb+DVaIaKGU18MWPg7f+FI6nampl3Q0KvfxwX0GdNhtio8T + /// Tj1E+SnFwh56SRQuxSh2gwKBgHKjlIO5NtNSflsUYFM+hyQiPiqnHzddfhSG+/3o + /// m5nNaSmczJesUYreH5San7/YEy2UxAugvP7aSY2MxB+iGsiJ9WD2kZzTUlDZJ7RV + /// UzWsoqBR+eZfVJ2FUWWvy8TpSG6trh4dFxImNtKejCR1TREpSiTV3Zb1dmahK9GV + /// rK9NAoGAbBxRLoC01xfxCTgt5BDiBcFVh4fp5yYKwavJPLzHSpuDOrrI9jDn1oKN + /// onq5sDU1i391zfQvdrbX4Ova48BN+B7p63FocP/MK5tyyBoT8zQEk2+vWDOw7H/Z + /// u5dTCPxTIsoIwUw1I+7yIxqJzLPFgR2gVBwY1ra/8iAqCj+zeBw= + /// -----END RSA PRIVATE KEY----- + /// ``` + final String? pem; + + /// The set of permissions for the GitHub app + final Permissions? permissions; + + /// The slug name of the GitHub app + /// + /// Example: `probot-owners` + final String? slug; + + final DateTime? updatedAt; + + /// Example: `"6fba8f2fc8a7e8f2cca5577eddd82ca7586b3b6b"` + final String? webhookSecret; + + Map toJson() => _$GitHubAppToJson(this); + + factory GitHubApp.fromJson(Map input) => + _$GitHubAppFromJson(input); +} + +@JsonSerializable() +class Rename { + Rename({ + this.from, + this.to, + }); + + final String? from; + final String? to; + + Map toJson() => _$RenameToJson(this); + + factory Rename.fromJson(Map input) => + _$RenameFromJson(input); +} + +@JsonSerializable() +class DismissedReview { + DismissedReview({ + this.dismissalCommitId, + this.dismissalMessage, + this.reviewId, + this.state, + }); + + final String? dismissalCommitId; + final String? dismissalMessage; + final int? reviewId; + final String? state; + + Map toJson() => _$DismissedReviewToJson(this); + + factory DismissedReview.fromJson(Map input) => + _$DismissedReviewFromJson(input); +} + +@JsonSerializable() +class ProjectCard { + ProjectCard({ + this.columnName, + this.id, + this.previousColumnName, + this.projectId, + this.projectUrl, + this.url, + }); + + final String? columnName; + final int? id; + final String? previousColumnName; + final int? projectId; + final String? projectUrl; + final String? url; + + Map toJson() => _$ProjectCardToJson(this); + + factory ProjectCard.fromJson(Map input) => + _$ProjectCardFromJson(input); +} + +@JsonSerializable() +class Source { + Source({ + this.issue, + this.type, + }); + + final Issue? issue; + final String? type; + + Map toJson() => _$SourceToJson(this); + + factory Source.fromJson(Map input) => + _$SourceFromJson(input); +} + +/// License +@JsonSerializable() +class License { + License({ + this.htmlUrl, + this.key, + this.name, + this.nodeId, + this.spdxId, + this.url, + }); + + final String? htmlUrl; + + /// Example: `mit` + final String? key; + + /// Example: `MIT License` + final String? name; + + /// Example: `MDc6TGljZW5zZW1pdA==` + final String? nodeId; + + /// Example: `MIT` + final String? spdxId; + + /// Example: `https://api.github.com/licenses/mit` + final String? url; + + Map toJson() => _$LicenseToJson(this); + + factory License.fromJson(Map input) => + _$LicenseFromJson(input); +} + +@JsonSerializable() +class TemplateRepository { + TemplateRepository({ + this.allowAutoMerge, + this.allowMergeCommit, + this.allowRebaseMerge, + this.allowSquashMerge, + this.allowUpdateBranch, + this.archiveUrl, + this.archived, + this.assigneesUrl, + this.blobsUrl, + this.branchesUrl, + this.cloneUrl, + this.collaboratorsUrl, + this.commentsUrl, + this.commitsUrl, + this.compareUrl, + this.contentsUrl, + this.contributorsUrl, + this.createdAt, + this.defaultBranch, + this.deleteBranchOnMerge, + this.deploymentsUrl, + this.description, + this.disabled, + this.downloadsUrl, + this.eventsUrl, + this.fork, + this.forksCount, + this.forksUrl, + this.fullName, + this.gitCommitsUrl, + this.gitRefsUrl, + this.gitTagsUrl, + this.gitUrl, + this.hasDownloads, + this.hasIssues, + this.hasPages, + this.hasProjects, + this.hasWiki, + this.homepage, + this.hooksUrl, + this.htmlUrl, + this.id, + this.isTemplate, + this.issueCommentUrl, + this.issueEventsUrl, + this.issuesUrl, + this.keysUrl, + this.labelsUrl, + this.language, + this.languagesUrl, + this.mergeCommitMessage, + this.mergeCommitTitle, + this.mergesUrl, + this.milestonesUrl, + this.mirrorUrl, + this.name, + this.networkCount, + this.nodeId, + this.notificationsUrl, + this.openIssuesCount, + this.owner, + this.permissions, + this.private, + this.pullsUrl, + this.pushedAt, + this.releasesUrl, + this.size, + this.squashMergeCommitMessage, + this.squashMergeCommitTitle, + this.sshUrl, + this.stargazersCount, + this.stargazersUrl, + this.statusesUrl, + this.subscribersCount, + this.subscribersUrl, + this.subscriptionUrl, + this.svnUrl, + this.tagsUrl, + this.teamsUrl, + this.tempCloneToken, + this.topics, + this.treesUrl, + this.updatedAt, + this.url, + this.visibility, + this.watchersCount, + }); + + final bool? allowAutoMerge; + final bool? allowMergeCommit; + final bool? allowRebaseMerge; + final bool? allowSquashMerge; + final bool? allowUpdateBranch; + final String? archiveUrl; + final bool? archived; + final String? assigneesUrl; + final String? blobsUrl; + final String? branchesUrl; + final String? cloneUrl; + final String? collaboratorsUrl; + final String? commentsUrl; + final String? commitsUrl; + final String? compareUrl; + final String? contentsUrl; + final String? contributorsUrl; + final DateTime? createdAt; + final String? defaultBranch; + final bool? deleteBranchOnMerge; + final String? deploymentsUrl; + final String? description; + final bool? disabled; + final String? downloadsUrl; + final String? eventsUrl; + final bool? fork; + final int? forksCount; + final String? forksUrl; + final String? fullName; + final String? gitCommitsUrl; + final String? gitRefsUrl; + final String? gitTagsUrl; + final String? gitUrl; + final bool? hasDownloads; + final bool? hasIssues; + final bool? hasPages; + final bool? hasProjects; + final bool? hasWiki; + final String? homepage; + final String? hooksUrl; + final String? htmlUrl; + final int? id; + final bool? isTemplate; + final String? issueCommentUrl; + final String? issueEventsUrl; + final String? issuesUrl; + final String? keysUrl; + final String? labelsUrl; + final String? language; + final String? languagesUrl; + + /// The default value for a merge commit message. + /// + /// - `PR_TITLE` - default to the pull request's title. + /// - `PR_BODY` - default to the pull request's body. + /// - `BLANK` - default to a blank commit message. + final String? mergeCommitMessage; + + /// The default value for a merge commit title. + /// + /// - `PR_TITLE` - default to the pull request's title. + /// - `MERGE_MESSAGE` - default to the classic title for a merge message (e.g., + /// Merge pull request #123 from branch-name). + final String? mergeCommitTitle; + + final String? mergesUrl; + final String? milestonesUrl; + final String? mirrorUrl; + final String? name; + final int? networkCount; + final String? nodeId; + final String? notificationsUrl; + final int? openIssuesCount; + final Owner? owner; + final Permissions? permissions; + final bool? private; + final String? pullsUrl; + final DateTime? pushedAt; + final String? releasesUrl; + final int? size; + + /// The default value for a squash merge commit message: + /// + /// - `PR_BODY` - default to the pull request's body. + /// - `COMMIT_MESSAGES` - default to the branch's commit messages. + /// - `BLANK` - default to a blank commit message. + final String? squashMergeCommitMessage; + + /// The default value for a squash merge commit title: + /// + /// - `PR_TITLE` - default to the pull request's title. + /// - `COMMIT_OR_PR_TITLE` - default to the commit's title (if only one commit) + /// or the pull request's title (when more than one commit). + final String? squashMergeCommitTitle; + + final String? sshUrl; + final int? stargazersCount; + final String? stargazersUrl; + final String? statusesUrl; + final int? subscribersCount; + final String? subscribersUrl; + final String? subscriptionUrl; + final String? svnUrl; + final String? tagsUrl; + final String? teamsUrl; + final String? tempCloneToken; + final List? topics; + final String? treesUrl; + final DateTime? updatedAt; + final String? url; + final String? visibility; + final int? watchersCount; + + Map toJson() => _$TemplateRepositoryToJson(this); + + factory TemplateRepository.fromJson(Map input) => + _$TemplateRepositoryFromJson(input); +} + +@JsonSerializable() +class Owner { + Owner({ + this.avatarUrl, + this.eventsUrl, + this.followersUrl, + this.followingUrl, + this.gistsUrl, + this.gravatarId, + this.htmlUrl, + this.id, + this.login, + this.nodeId, + this.organizationsUrl, + this.receivedEventsUrl, + this.reposUrl, + this.siteAdmin, + this.starredUrl, + this.subscriptionsUrl, + this.type, + this.url, + }); + + final String? avatarUrl; + final String? eventsUrl; + final String? followersUrl; + final String? followingUrl; + final String? gistsUrl; + final String? gravatarId; + final String? htmlUrl; + final int? id; + final String? login; + final String? nodeId; + final String? organizationsUrl; + final String? receivedEventsUrl; + final String? reposUrl; + final bool? siteAdmin; + final String? starredUrl; + final String? subscriptionsUrl; + final String? type; + final String? url; + + Map toJson() => _$OwnerToJson(this); + + factory Owner.fromJson(Map input) => _$OwnerFromJson(input); +} + +@JsonSerializable() +class Tree { + Tree({ + this.sha, + this.url, + this.htmlUrl, + }); + + /// SHA for the commit + /// + /// Example: `7638417db6d59f3c431d3e1f261cc637155684cd` + final String? sha; + + final String? url; + + final String? htmlUrl; + + Map toJson() => _$TreeToJson(this); + + factory Tree.fromJson(Map input) => _$TreeFromJson(input); +} + +@JsonSerializable() +class Verification { + Verification({ + this.payload, + this.reason, + this.signature, + this.verified, + }); + + final String? payload; + final String? reason; + final String? signature; + final bool? verified; + + Map toJson() => _$VerificationToJson(this); + + factory Verification.fromJson(Map input) => + _$VerificationFromJson(input); +} + +@JsonSerializable() +class HtmlLink { + HtmlLink({ + this.href, + }); + + final String? href; + + Map toJson() => _$HtmlLinkToJson(this); + + factory HtmlLink.fromJson(Map input) => + _$HtmlLinkFromJson(input); +} + +@JsonSerializable() +class PullRequestLink { + PullRequestLink({ + this.href, + }); + + /// Example: `https://api.github.com/repos/octocat/Hello-World/pulls/1` + final String? href; + + Map toJson() => _$PullRequestLinkToJson(this); + + factory PullRequestLink.fromJson(Map input) => + _$PullRequestLinkFromJson(input); +} diff --git a/lib/src/common/model/timeline_support.g.dart b/lib/src/common/model/timeline_support.g.dart new file mode 100644 index 00000000..c1e441f2 --- /dev/null +++ b/lib/src/common/model/timeline_support.g.dart @@ -0,0 +1,409 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'timeline_support.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GitHubApp _$GitHubAppFromJson(Map json) => GitHubApp( + clientId: json['client_id'] as String?, + clientSecret: json['client_secret'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + description: json['description'] as String?, + events: + (json['events'] as List?)?.map((e) => e as String).toList(), + externalUrl: json['external_url'] as String?, + htmlUrl: json['html_url'] as String?, + id: json['id'] as int?, + installationsCount: json['installations_count'] as int?, + name: json['name'] as String?, + nodeId: json['node_id'] as String?, + owner: json['owner'] == null + ? null + : User.fromJson(json['owner'] as Map), + pem: json['pem'] as String?, + permissions: json['permissions'] == null + ? null + : Permissions.fromJson(json['permissions'] as Map), + slug: json['slug'] as String?, + updatedAt: json['updated_at'] == null + ? null + : DateTime.parse(json['updated_at'] as String), + webhookSecret: json['webhook_secret'] as String?, + ); + +Map _$GitHubAppToJson(GitHubApp instance) => { + 'client_id': instance.clientId, + 'client_secret': instance.clientSecret, + 'created_at': instance.createdAt?.toIso8601String(), + 'description': instance.description, + 'events': instance.events, + 'external_url': instance.externalUrl, + 'html_url': instance.htmlUrl, + 'id': instance.id, + 'installations_count': instance.installationsCount, + 'name': instance.name, + 'node_id': instance.nodeId, + 'owner': instance.owner, + 'pem': instance.pem, + 'permissions': instance.permissions, + 'slug': instance.slug, + 'updated_at': instance.updatedAt?.toIso8601String(), + 'webhook_secret': instance.webhookSecret, + }; + +Rename _$RenameFromJson(Map json) => Rename( + from: json['from'] as String?, + to: json['to'] as String?, + ); + +Map _$RenameToJson(Rename instance) => { + 'from': instance.from, + 'to': instance.to, + }; + +DismissedReview _$DismissedReviewFromJson(Map json) => + DismissedReview( + dismissalCommitId: json['dismissal_commit_id'] as String?, + dismissalMessage: json['dismissal_message'] as String?, + reviewId: json['review_id'] as int?, + state: json['state'] as String?, + ); + +Map _$DismissedReviewToJson(DismissedReview instance) => + { + 'dismissal_commit_id': instance.dismissalCommitId, + 'dismissal_message': instance.dismissalMessage, + 'review_id': instance.reviewId, + 'state': instance.state, + }; + +ProjectCard _$ProjectCardFromJson(Map json) => ProjectCard( + columnName: json['column_name'] as String?, + id: json['id'] as int?, + previousColumnName: json['previous_column_name'] as String?, + projectId: json['project_id'] as int?, + projectUrl: json['project_url'] as String?, + url: json['url'] as String?, + ); + +Map _$ProjectCardToJson(ProjectCard instance) => + { + 'column_name': instance.columnName, + 'id': instance.id, + 'previous_column_name': instance.previousColumnName, + 'project_id': instance.projectId, + 'project_url': instance.projectUrl, + 'url': instance.url, + }; + +Source _$SourceFromJson(Map json) => Source( + issue: json['issue'] == null + ? null + : Issue.fromJson(json['issue'] as Map), + type: json['type'] as String?, + ); + +Map _$SourceToJson(Source instance) => { + 'issue': instance.issue, + 'type': instance.type, + }; + +License _$LicenseFromJson(Map json) => License( + htmlUrl: json['html_url'] as String?, + key: json['key'] as String?, + name: json['name'] as String?, + nodeId: json['node_id'] as String?, + spdxId: json['spdx_id'] as String?, + url: json['url'] as String?, + ); + +Map _$LicenseToJson(License instance) => { + 'html_url': instance.htmlUrl, + 'key': instance.key, + 'name': instance.name, + 'node_id': instance.nodeId, + 'spdx_id': instance.spdxId, + 'url': instance.url, + }; + +TemplateRepository _$TemplateRepositoryFromJson(Map json) => + TemplateRepository( + allowAutoMerge: json['allow_auto_merge'] as bool?, + allowMergeCommit: json['allow_merge_commit'] as bool?, + allowRebaseMerge: json['allow_rebase_merge'] as bool?, + allowSquashMerge: json['allow_squash_merge'] as bool?, + allowUpdateBranch: json['allow_update_branch'] as bool?, + archiveUrl: json['archive_url'] as String?, + archived: json['archived'] as bool?, + assigneesUrl: json['assignees_url'] as String?, + blobsUrl: json['blobs_url'] as String?, + branchesUrl: json['branches_url'] as String?, + cloneUrl: json['clone_url'] as String?, + collaboratorsUrl: json['collaborators_url'] as String?, + commentsUrl: json['comments_url'] as String?, + commitsUrl: json['commits_url'] as String?, + compareUrl: json['compare_url'] as String?, + contentsUrl: json['contents_url'] as String?, + contributorsUrl: json['contributors_url'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + defaultBranch: json['default_branch'] as String?, + deleteBranchOnMerge: json['delete_branch_on_merge'] as bool?, + deploymentsUrl: json['deployments_url'] as String?, + description: json['description'] as String?, + disabled: json['disabled'] as bool?, + downloadsUrl: json['downloads_url'] as String?, + eventsUrl: json['events_url'] as String?, + fork: json['fork'] as bool?, + forksCount: json['forks_count'] as int?, + forksUrl: json['forks_url'] as String?, + fullName: json['full_name'] as String?, + gitCommitsUrl: json['git_commits_url'] as String?, + gitRefsUrl: json['git_refs_url'] as String?, + gitTagsUrl: json['git_tags_url'] as String?, + gitUrl: json['git_url'] as String?, + hasDownloads: json['has_downloads'] as bool?, + hasIssues: json['has_issues'] as bool?, + hasPages: json['has_pages'] as bool?, + hasProjects: json['has_projects'] as bool?, + hasWiki: json['has_wiki'] as bool?, + homepage: json['homepage'] as String?, + hooksUrl: json['hooks_url'] as String?, + htmlUrl: json['html_url'] as String?, + id: json['id'] as int?, + isTemplate: json['is_template'] as bool?, + issueCommentUrl: json['issue_comment_url'] as String?, + issueEventsUrl: json['issue_events_url'] as String?, + issuesUrl: json['issues_url'] as String?, + keysUrl: json['keys_url'] as String?, + labelsUrl: json['labels_url'] as String?, + language: json['language'] as String?, + languagesUrl: json['languages_url'] as String?, + mergeCommitMessage: json['merge_commit_message'] as String?, + mergeCommitTitle: json['merge_commit_title'] as String?, + mergesUrl: json['merges_url'] as String?, + milestonesUrl: json['milestones_url'] as String?, + mirrorUrl: json['mirror_url'] as String?, + name: json['name'] as String?, + networkCount: json['network_count'] as int?, + nodeId: json['node_id'] as String?, + notificationsUrl: json['notifications_url'] as String?, + openIssuesCount: json['open_issues_count'] as int?, + owner: json['owner'] == null + ? null + : Owner.fromJson(json['owner'] as Map), + permissions: json['permissions'] == null + ? null + : Permissions.fromJson(json['permissions'] as Map), + private: json['private'] as bool?, + pullsUrl: json['pulls_url'] as String?, + pushedAt: json['pushed_at'] == null + ? null + : DateTime.parse(json['pushed_at'] as String), + releasesUrl: json['releases_url'] as String?, + size: json['size'] as int?, + squashMergeCommitMessage: json['squash_merge_commit_message'] as String?, + squashMergeCommitTitle: json['squash_merge_commit_title'] as String?, + sshUrl: json['ssh_url'] as String?, + stargazersCount: json['stargazers_count'] as int?, + stargazersUrl: json['stargazers_url'] as String?, + statusesUrl: json['statuses_url'] as String?, + subscribersCount: json['subscribers_count'] as int?, + subscribersUrl: json['subscribers_url'] as String?, + subscriptionUrl: json['subscription_url'] as String?, + svnUrl: json['svn_url'] as String?, + tagsUrl: json['tags_url'] as String?, + teamsUrl: json['teams_url'] as String?, + tempCloneToken: json['temp_clone_token'] as String?, + topics: + (json['topics'] as List?)?.map((e) => e as String).toList(), + treesUrl: json['trees_url'] as String?, + updatedAt: json['updated_at'] == null + ? null + : DateTime.parse(json['updated_at'] as String), + url: json['url'] as String?, + visibility: json['visibility'] as String?, + watchersCount: json['watchers_count'] as int?, + ); + +Map _$TemplateRepositoryToJson(TemplateRepository instance) => + { + 'allow_auto_merge': instance.allowAutoMerge, + 'allow_merge_commit': instance.allowMergeCommit, + 'allow_rebase_merge': instance.allowRebaseMerge, + 'allow_squash_merge': instance.allowSquashMerge, + 'allow_update_branch': instance.allowUpdateBranch, + 'archive_url': instance.archiveUrl, + 'archived': instance.archived, + 'assignees_url': instance.assigneesUrl, + 'blobs_url': instance.blobsUrl, + 'branches_url': instance.branchesUrl, + 'clone_url': instance.cloneUrl, + 'collaborators_url': instance.collaboratorsUrl, + 'comments_url': instance.commentsUrl, + 'commits_url': instance.commitsUrl, + 'compare_url': instance.compareUrl, + 'contents_url': instance.contentsUrl, + 'contributors_url': instance.contributorsUrl, + 'created_at': instance.createdAt?.toIso8601String(), + 'default_branch': instance.defaultBranch, + 'delete_branch_on_merge': instance.deleteBranchOnMerge, + 'deployments_url': instance.deploymentsUrl, + 'description': instance.description, + 'disabled': instance.disabled, + 'downloads_url': instance.downloadsUrl, + 'events_url': instance.eventsUrl, + 'fork': instance.fork, + 'forks_count': instance.forksCount, + 'forks_url': instance.forksUrl, + 'full_name': instance.fullName, + 'git_commits_url': instance.gitCommitsUrl, + 'git_refs_url': instance.gitRefsUrl, + 'git_tags_url': instance.gitTagsUrl, + 'git_url': instance.gitUrl, + 'has_downloads': instance.hasDownloads, + 'has_issues': instance.hasIssues, + 'has_pages': instance.hasPages, + 'has_projects': instance.hasProjects, + 'has_wiki': instance.hasWiki, + 'homepage': instance.homepage, + 'hooks_url': instance.hooksUrl, + 'html_url': instance.htmlUrl, + 'id': instance.id, + 'is_template': instance.isTemplate, + 'issue_comment_url': instance.issueCommentUrl, + 'issue_events_url': instance.issueEventsUrl, + 'issues_url': instance.issuesUrl, + 'keys_url': instance.keysUrl, + 'labels_url': instance.labelsUrl, + 'language': instance.language, + 'languages_url': instance.languagesUrl, + 'merge_commit_message': instance.mergeCommitMessage, + 'merge_commit_title': instance.mergeCommitTitle, + 'merges_url': instance.mergesUrl, + 'milestones_url': instance.milestonesUrl, + 'mirror_url': instance.mirrorUrl, + 'name': instance.name, + 'network_count': instance.networkCount, + 'node_id': instance.nodeId, + 'notifications_url': instance.notificationsUrl, + 'open_issues_count': instance.openIssuesCount, + 'owner': instance.owner, + 'permissions': instance.permissions, + 'private': instance.private, + 'pulls_url': instance.pullsUrl, + 'pushed_at': instance.pushedAt?.toIso8601String(), + 'releases_url': instance.releasesUrl, + 'size': instance.size, + 'squash_merge_commit_message': instance.squashMergeCommitMessage, + 'squash_merge_commit_title': instance.squashMergeCommitTitle, + 'ssh_url': instance.sshUrl, + 'stargazers_count': instance.stargazersCount, + 'stargazers_url': instance.stargazersUrl, + 'statuses_url': instance.statusesUrl, + 'subscribers_count': instance.subscribersCount, + 'subscribers_url': instance.subscribersUrl, + 'subscription_url': instance.subscriptionUrl, + 'svn_url': instance.svnUrl, + 'tags_url': instance.tagsUrl, + 'teams_url': instance.teamsUrl, + 'temp_clone_token': instance.tempCloneToken, + 'topics': instance.topics, + 'trees_url': instance.treesUrl, + 'updated_at': instance.updatedAt?.toIso8601String(), + 'url': instance.url, + 'visibility': instance.visibility, + 'watchers_count': instance.watchersCount, + }; + +Owner _$OwnerFromJson(Map json) => Owner( + avatarUrl: json['avatar_url'] as String?, + eventsUrl: json['events_url'] as String?, + followersUrl: json['followers_url'] as String?, + followingUrl: json['following_url'] as String?, + gistsUrl: json['gists_url'] as String?, + gravatarId: json['gravatar_id'] as String?, + htmlUrl: json['html_url'] as String?, + id: json['id'] as int?, + login: json['login'] as String?, + nodeId: json['node_id'] as String?, + organizationsUrl: json['organizations_url'] as String?, + receivedEventsUrl: json['received_events_url'] as String?, + reposUrl: json['repos_url'] as String?, + siteAdmin: json['site_admin'] as bool?, + starredUrl: json['starred_url'] as String?, + subscriptionsUrl: json['subscriptions_url'] as String?, + type: json['type'] as String?, + url: json['url'] as String?, + ); + +Map _$OwnerToJson(Owner instance) => { + 'avatar_url': instance.avatarUrl, + 'events_url': instance.eventsUrl, + 'followers_url': instance.followersUrl, + 'following_url': instance.followingUrl, + 'gists_url': instance.gistsUrl, + 'gravatar_id': instance.gravatarId, + 'html_url': instance.htmlUrl, + 'id': instance.id, + 'login': instance.login, + 'node_id': instance.nodeId, + 'organizations_url': instance.organizationsUrl, + 'received_events_url': instance.receivedEventsUrl, + 'repos_url': instance.reposUrl, + 'site_admin': instance.siteAdmin, + 'starred_url': instance.starredUrl, + 'subscriptions_url': instance.subscriptionsUrl, + 'type': instance.type, + 'url': instance.url, + }; + +Tree _$TreeFromJson(Map json) => Tree( + sha: json['sha'] as String?, + url: json['url'] as String?, + htmlUrl: json['html_url'] as String?, + ); + +Map _$TreeToJson(Tree instance) => { + 'sha': instance.sha, + 'url': instance.url, + 'html_url': instance.htmlUrl, + }; + +Verification _$VerificationFromJson(Map json) => Verification( + payload: json['payload'] as String?, + reason: json['reason'] as String?, + signature: json['signature'] as String?, + verified: json['verified'] as bool?, + ); + +Map _$VerificationToJson(Verification instance) => + { + 'payload': instance.payload, + 'reason': instance.reason, + 'signature': instance.signature, + 'verified': instance.verified, + }; + +HtmlLink _$HtmlLinkFromJson(Map json) => HtmlLink( + href: json['href'] as String?, + ); + +Map _$HtmlLinkToJson(HtmlLink instance) => { + 'href': instance.href, + }; + +PullRequestLink _$PullRequestLinkFromJson(Map json) => + PullRequestLink( + href: json['href'] as String?, + ); + +Map _$PullRequestLinkToJson(PullRequestLink instance) => + { + 'href': instance.href, + }; diff --git a/lib/src/common/model/users.dart b/lib/src/common/model/users.dart index 8044983a..f66fd395 100644 --- a/lib/src/common/model/users.dart +++ b/lib/src/common/model/users.dart @@ -24,6 +24,22 @@ class User { this.followingCount, this.createdAt, this.updatedAt, + + // Properties from the Timeline API + this.eventsUrl, + this.followersUrl, + this.followingUrl, + this.gistsUrl, + this.gravatarId, + this.nodeId, + this.organizationsUrl, + this.receivedEventsUrl, + this.reposUrl, + this.starredAt, + this.starredUrl, + this.subscriptionsUrl, + this.type, + this.url, }); @JsonKey(includeToJson: false, includeFromJson: false) @@ -90,6 +106,49 @@ class User { /// The username of the twitter account (without leading @) String? twitterUsername; + // The following properties were added to support the Timeline API. + + /// Example: `https://api.github.com/users/octocat/events{/privacy}` + String? eventsUrl; + + /// Example: `https://api.github.com/users/octocat/followers` + String? followersUrl; + + /// Example: `https://api.github.com/users/octocat/following{/other_user}` + String? followingUrl; + + /// Example: `https://api.github.com/users/octocat/gists{/gist_id}` + String? gistsUrl; + + /// Example: `41d064eb2195891e12d0413f63227ea7` + String? gravatarId; + + /// Example: `MDQ6VXNlcjE=` + String? nodeId; + + /// Example: `https://api.github.com/users/octocat/orgs` + String? organizationsUrl; + + /// Example: `https://api.github.com/users/octocat/received_events` + String? receivedEventsUrl; + + /// Example: `https://api.github.com/users/octocat/repos` + String? reposUrl; + + DateTime? starredAt; + + /// Example: `https://api.github.com/users/octocat/starred{/owner}{/repo}` + String? starredUrl; + + /// Example: `https://api.github.com/users/octocat/subscriptions` + String? subscriptionsUrl; + + /// Example: `User` + String? type; + + /// Example: `https://api.github.com/users/octocat` + String? url; + factory User.fromJson(Map input) => _$UserFromJson(input); Map toJson() => _$UserToJson(this); } @@ -98,13 +157,6 @@ class User { // https://developer.github.com/v3/repos/collaborators/#response @JsonSerializable() class Collaborator { - final String? login; - final int? id; - final String? htmlUrl; - final String? type; - final bool? siteAdmin; - final Map? permissions; - Collaborator( this.login, this.id, @@ -114,6 +166,13 @@ class Collaborator { this.permissions, ); + String? login; + int? id; + String? htmlUrl; + String? type; + bool? siteAdmin; + Map? permissions; + factory Collaborator.fromJson(Map json) => _$CollaboratorFromJson(json); Map toJson() => _$CollaboratorToJson(this); diff --git a/lib/src/common/model/users.g.dart b/lib/src/common/model/users.g.dart index 2713125a..40e4a306 100644 --- a/lib/src/common/model/users.g.dart +++ b/lib/src/common/model/users.g.dart @@ -29,6 +29,22 @@ User _$UserFromJson(Map json) => User( updatedAt: json['updated_at'] == null ? null : DateTime.parse(json['updated_at'] as String), + eventsUrl: json['events_url'] as String?, + followersUrl: json['followers_url'] as String?, + followingUrl: json['following_url'] as String?, + gistsUrl: json['gists_url'] as String?, + gravatarId: json['gravatar_id'] as String?, + nodeId: json['node_id'] as String?, + organizationsUrl: json['organizations_url'] as String?, + receivedEventsUrl: json['received_events_url'] as String?, + reposUrl: json['repos_url'] as String?, + starredAt: json['starred_at'] == null + ? null + : DateTime.parse(json['starred_at'] as String), + starredUrl: json['starred_url'] as String?, + subscriptionsUrl: json['subscriptions_url'] as String?, + type: json['type'] as String?, + url: json['url'] as String?, )..twitterUsername = json['twitter_username'] as String?; Map _$UserToJson(User instance) => { @@ -51,6 +67,20 @@ Map _$UserToJson(User instance) => { 'created_at': instance.createdAt?.toIso8601String(), 'updated_at': instance.updatedAt?.toIso8601String(), 'twitter_username': instance.twitterUsername, + 'events_url': instance.eventsUrl, + 'followers_url': instance.followersUrl, + 'following_url': instance.followingUrl, + 'gists_url': instance.gistsUrl, + 'gravatar_id': instance.gravatarId, + 'node_id': instance.nodeId, + 'organizations_url': instance.organizationsUrl, + 'received_events_url': instance.receivedEventsUrl, + 'repos_url': instance.reposUrl, + 'starred_at': instance.starredAt?.toIso8601String(), + 'starred_url': instance.starredUrl, + 'subscriptions_url': instance.subscriptionsUrl, + 'type': instance.type, + 'url': instance.url, }; Collaborator _$CollaboratorFromJson(Map json) => Collaborator( @@ -119,6 +149,22 @@ CurrentUser _$CurrentUserFromJson(Map json) => CurrentUser() ? null : DateTime.parse(json['updated_at'] as String) ..twitterUsername = json['twitter_username'] as String? + ..eventsUrl = json['events_url'] as String? + ..followersUrl = json['followers_url'] as String? + ..followingUrl = json['following_url'] as String? + ..gistsUrl = json['gists_url'] as String? + ..gravatarId = json['gravatar_id'] as String? + ..nodeId = json['node_id'] as String? + ..organizationsUrl = json['organizations_url'] as String? + ..receivedEventsUrl = json['received_events_url'] as String? + ..reposUrl = json['repos_url'] as String? + ..starredAt = json['starred_at'] == null + ? null + : DateTime.parse(json['starred_at'] as String) + ..starredUrl = json['starred_url'] as String? + ..subscriptionsUrl = json['subscriptions_url'] as String? + ..type = json['type'] as String? + ..url = json['url'] as String? ..privateReposCount = json['total_private_repos'] as int? ..ownedPrivateReposCount = json['owned_private_repos'] as int? ..diskUsage = json['disk_usage'] as int? @@ -147,6 +193,20 @@ Map _$CurrentUserToJson(CurrentUser instance) => 'created_at': instance.createdAt?.toIso8601String(), 'updated_at': instance.updatedAt?.toIso8601String(), 'twitter_username': instance.twitterUsername, + 'events_url': instance.eventsUrl, + 'followers_url': instance.followersUrl, + 'following_url': instance.followingUrl, + 'gists_url': instance.gistsUrl, + 'gravatar_id': instance.gravatarId, + 'node_id': instance.nodeId, + 'organizations_url': instance.organizationsUrl, + 'received_events_url': instance.receivedEventsUrl, + 'repos_url': instance.reposUrl, + 'starred_at': instance.starredAt?.toIso8601String(), + 'starred_url': instance.starredUrl, + 'subscriptions_url': instance.subscriptionsUrl, + 'type': instance.type, + 'url': instance.url, 'total_private_repos': instance.privateReposCount, 'owned_private_repos': instance.ownedPrivateReposCount, 'disk_usage': instance.diskUsage, diff --git a/tool/process_github_schema.dart b/tool/process_github_schema.dart new file mode 100644 index 00000000..e3850df5 --- /dev/null +++ b/tool/process_github_schema.dart @@ -0,0 +1,621 @@ +import 'dart:convert'; +import 'dart:io'; + +const int width = 72; + +List wordWrap(String body) { + var result = []; + var start = 0; + for (var index = 0; index < body.length; index += 1) { + if ((index == body.length - 1) || + (body[index] == '\n') || + ((body[index] == ' ') && (index - start > width))) { + result.add(body.substring(start, index + 1).trimRight()); + start = index + 1; + } + } + assert(start == body.length); + return result; +} + +typedef GenTypeVisitor = void Function(GenType type); + +abstract class GenType extends Comparable { + GenType(); + + String get name; + String get comment => ''; + + String get signature; + + void cleanup() {} + + String generateDeclaration(); + + void visit(GenTypeVisitor visitor) { + visitor(this); + } + + GenType mergeWith(GenType other, GenAbstractClass? superclass) { + assert(signature == other.signature, + 'cannot merge types with different signatures'); + throw StateError( + 'not sure how to merge $runtimeType with ${other.runtimeType}'); + } + + @override + int compareTo(GenType other) { + return signature.compareTo(other.signature); + } + + @override + String toString() => '$runtimeType($name)'; +} + +class GenPrimitive extends GenType { + GenPrimitive(this.type, this.comment); + + @override + String get name => type.toString(); + + @override + String get signature => name; + + @override + String generateDeclaration() => ''; + + @override + final String comment; + + final Type type; + + @override + GenType mergeWith(GenType other, GenAbstractClass? superclass) { + assert(superclass == null); + if (other is GenPrimitive) { + assert(type == other.type); + if (comment != other.comment) { + return GenPrimitive( + type, + '$comment\n\n${other.comment}', + ); + } + return this; + } + return super.mergeWith(other, superclass); + } +} + +class GenUnion extends GenType { + GenUnion(this.subtypes); + + @override + String get name => 'Object'; + + @override + String get comment { + var result = StringBuffer(); + result.writeln('One of the following:'); + for (final subtype in subtypes) { + if (subtype.comment.isNotEmpty) { + result.writeln( + ' * [${subtype.name}]: ${subtype.comment.split('\n').first}'); + } else { + result.writeln(' * [${subtype.name}]'); + } + } + return result.toString(); + } + + @override + String get signature { + var subsignatures = + subtypes.map((GenType type) => type.signature).toList() + ..sort() + ..join(','); + return 'Union<$subsignatures>'; + } + + final List subtypes; + + @override + String generateDeclaration() => ''; + + @override + void visit(GenTypeVisitor visitor) { + super.visit(visitor); + for (final subtype in subtypes) { + subtype.visit(visitor); + } + } + + @override + GenType mergeWith(GenType other, GenAbstractClass? superclass) { + assert(superclass == null); + if (other is GenUnion) { + assert(subtypes.length == other.subtypes.length); + var subtypesA = subtypes..sort(); + var subtypesB = other.subtypes..sort(); + var subtypesC = []; + for (var index = 0; index < subtypesA.length; index += 1) { + subtypesC.add(subtypesA[index].mergeWith(subtypesB[index], null)); + } + return GenUnion(subtypesC); + } + return super.mergeWith(other, superclass); + } +} + +class GenList extends GenType { + GenList(this.members, this.comment); + + @override + String get name => 'List<${members.name}>'; + + @override + final String comment; + + final GenType members; + + @override + String get signature { + return 'List<${members.signature}>'; + } + + @override + String generateDeclaration() => ''; + + @override + void visit(GenTypeVisitor visitor) { + super.visit(visitor); + members.visit(visitor); + } + + @override + GenType mergeWith(GenType other, GenAbstractClass? superclass) { + assert(superclass == null); + if (other is GenList) { + var newComment = + comment != other.comment ? '$comment\n\n${other.comment}' : comment; + var newMembers = members.mergeWith(other.members, null); + return GenList(newMembers, newComment); + } + return super.mergeWith(other, superclass); + } +} + +class GenAbstractClass extends GenType { + GenAbstractClass(this.name, this.comment, {Map? properties}) + : properties = properties ?? {}; + + @override + final String name; + + @override + final String comment; + + final List subclasses = []; + final Map properties; + + @override + String get signature { + var propertySignatures = properties.keys + .map((String propertyName) => + '$propertyName:${properties[propertyName]!.signature}') + .toList() + ..sort() + ..join(','); + return 'abstract class $name { $propertySignatures }'; + } + + @override + void cleanup() { + if (subclasses.length > 1) { + var names = subclasses.first.properties.keys.toSet(); + properties: + for (final name in names) { + var signature = subclasses.first.properties[name]!.signature; + for (final subclass in subclasses.skip(1)) { + if (!subclass.properties.containsKey(name) || + subclass.properties[name]!.signature != signature) { + continue properties; + } + } + var property = subclasses.first.properties[name]!; + for (final subclass in subclasses.skip(1)) { + property = property.mergeWith(subclass.properties[name]!, null); + } + properties[name] = property; + for (final subclass in subclasses) { + subclass.properties.remove(name); + } + } + } + } + + @override + String generateDeclaration() { + var output = StringBuffer(); + if (comment.isNotEmpty) { + for (final line in wordWrap(comment)) { + output.writeln('/// $line'); + } + } + output.writeln('@JsonSerializable()'); + output.writeln('abstract class $name {'); + output.write(' $name('); + if (properties.isNotEmpty) { + output.writeln('{'); + for (final propertyName in properties.keys.toList()..sort()) { + output.writeln(' this.$propertyName,'); + } + output.write(' }'); + } + output.writeln(');'); + output.writeln(''); + var lastLineWasBlank = true; + for (final propertyName in properties.keys.toList()..sort()) { + if (properties[propertyName]!.comment.isNotEmpty) { + if (!lastLineWasBlank) { + output.writeln(''); + lastLineWasBlank = true; + } + for (final line in wordWrap(properties[propertyName]!.comment)) { + output.writeln(' /// $line'); + } + } else { + lastLineWasBlank = false; + } + output.writeln(' ${properties[propertyName]!.name}? $propertyName;'); + if (lastLineWasBlank) { + output.writeln(''); + lastLineWasBlank = true; + } + } + output.writeln('}'); + return output.toString(); + } + + @override + void visit(GenTypeVisitor visitor) { + super.visit(visitor); + for (final subclass in subclasses) { + subclass.visit(visitor); + } + } + + @override + GenType mergeWith(GenType other, GenAbstractClass? superclass) { + assert(superclass == null); + if (other is GenAbstractClass) { + assert(name == other.name); + assert(properties.length == other.properties.length); + var newComment = + comment != other.comment ? '$comment\n\n${other.comment}' : comment; + var newProperties = {}; + for (final propertyName in properties.keys) { + newProperties[propertyName] = properties[propertyName]! + .mergeWith(other.properties[propertyName]!, null); + } + var result = + GenAbstractClass(name, newComment, properties: newProperties); + var subclassesA = subclasses..sort(); + var subclassesB = other.subclasses..sort(); + for (var index = 0; index < subclassesA.length; index += 1) { + subclassesA[index].mergeWith(subclassesB[index], result); + } + assert(result.subclasses.length == subclasses.length); + assert(result.subclasses.length == other.subclasses.length); + return result; + } + return super.mergeWith(other, superclass); + } +} + +class GenClass extends GenType { + GenClass(this.name, this.comment, this.superclass, this.properties) { + if (superclass != null) { + superclass!.subclasses.add(this); + } + } + + @override + final String name; + + @override + final String comment; + + final GenAbstractClass? superclass; + final Map properties; + + @override + String get signature { + var propertySignatures = properties.keys + .map((String propertyName) => + '$propertyName:${properties[propertyName]!.signature}') + .toList() + ..sort() + ..join(','); + return 'class $name extends { ${superclass?.signature} } with { $propertySignatures }'; + } + + @override + String generateDeclaration() { + var output = StringBuffer(); + if (comment.isNotEmpty) { + for (final line in wordWrap(comment)) { + output.writeln('/// $line'); + } + } + output.writeln('@JsonSerializable()'); + output.write('class $name '); + if (superclass != null) { + output.write('extends ${superclass!.name} '); + } + output.writeln('{'); + output.writeln(' $name({'); + if (superclass != null) { + for (final propertyName in superclass!.properties.keys.toList()..sort()) { + output.writeln(' super.$propertyName,'); + } + } + for (final propertyName in properties.keys.toList()..sort()) { + output.writeln(' this.$propertyName,'); + } + output.writeln(' });'); + output.writeln(''); + var lastLineWasBlank = true; + for (final propertyName in properties.keys.toList()..sort()) { + if (properties[propertyName]!.comment.isNotEmpty) { + if (!lastLineWasBlank) { + output.writeln(''); + lastLineWasBlank = true; + } + for (final line in wordWrap(properties[propertyName]!.comment)) { + output.writeln(' /// $line'); + } + } else { + lastLineWasBlank = false; + } + output.writeln(' ${properties[propertyName]!.name}? $propertyName;'); + if (lastLineWasBlank) { + output.writeln(''); + lastLineWasBlank = true; + } + } + if (!lastLineWasBlank) { + output.writeln(''); + } + output + .writeln(' Map toJson() => _\$${name}ToJson(this);'); + output.writeln(''); + output.writeln(' factory $name.fromJson(Map input) =>'); + output.writeln(' _\$${name}FromJson(input);'); + output.writeln('}'); + return output.toString(); + } + + @override + void visit(GenTypeVisitor visitor) { + super.visit(visitor); + for (final property in properties.values) { + property.visit(visitor); + } + } + + @override + GenType mergeWith(GenType other, GenAbstractClass? superclass) { + assert((superclass == null) == (this.superclass == null)); + if (other is GenClass) { + assert((other.superclass == null) == (this.superclass == null)); + assert(name == other.name); + assert(properties.length == other.properties.length); + var newComment = + comment != other.comment ? '$comment\n\n${other.comment}' : comment; + var newProperties = {}; + for (final propertyName in properties.keys) { + newProperties[propertyName] = properties[propertyName]! + .mergeWith(other.properties[propertyName]!, null); + } + return GenClass(name, newComment, superclass, newProperties); + } + return super.mergeWith(other, superclass); + } +} + +void assure(bool condition, String Function() callback) { + if (!condition) { + print(callback()); + exit(1); + } +} + +String? camelCase(String? text, {bool uppercase = false}) { + if (text == null) { + return null; + } + var bits = text.split(RegExp('[- _]')); + var result = StringBuffer(); + for (final bit in bits) { + if (bit.isNotEmpty) { + if (result.isNotEmpty || uppercase) { + result.write(String.fromCharCode(bit.runes.first).toUpperCase()); + result.write(String.fromCharCodes(bit.runes.skip(1))); + } else { + result.write(bit); + } + } + } + return result.toString(); +} + +String buildComment(Map schema) { + var description = StringBuffer(); + if (schema['title'] != null) { + description.writeln(schema['title']); + } + if (schema['description'] != null && + schema['description'] != schema['title']) { + if (description.isNotEmpty) { + description.writeln(''); + } + description.writeln(schema['description']); + } + if (schema['format'] != null) { + if (description.isNotEmpty) { + description.writeln(''); + } + description.write('Format: '); + description.writeln(schema['format']); + } + if (schema['examples'] != null) { + assure(schema['examples'] is List, + () => 'examples should be a list, not as in $schema'); + for (final example in schema['examples'] as List) { + if (description.isNotEmpty) { + description.writeln(''); + } + description.writeln('Example: `$example`'); + } + } + return description.toString().trimRight(); +} + +GenType process(Map schema, {String? defaultName}) { + final comment = buildComment(schema); + String type; + if (schema['type'] is List) { + var types = schema['type'] as List; + if (types.length == 2) { + if (types[0] == 'null' && types[1] is String) { + type = types[1] as String; + } else if (types[1] == 'null' && types[0] is String) { + type = types[0] as String; + } else { + print('Arbitrary union types not supported: $types'); + exit(1); + } + } else { + print('Arbitrary union types not supported: $types'); + exit(1); + } + } else if (schema['type'] is String) { + type = schema['type'] as String; + } else { + var anyOf = schema['anyOf'] ?? schema['oneOf']; + if (anyOf != null) { + assure(comment.isEmpty, () => 'lost comment to anyOf/oneOf: $comment'); + assure( + anyOf is List, () => 'anyOf/oneOf key is not a JSON list'); + var subtypes = []; + for (final subtype in anyOf as List) { + assure(subtype is Map, + () => 'type in anyOf/oneOf is not a JSON object'); + subtypes.add(process(subtype as Map)); + } + if (subtypes.length == 2) { + if (subtypes[0] is GenPrimitive && + (subtypes[0] as GenPrimitive).type == Null) { + return subtypes[1]; + } + if (subtypes[1] is GenPrimitive && + (subtypes[1] as GenPrimitive).type == Null) { + return subtypes[0]; + } + } + return GenUnion(subtypes); + } + if (schema['type'] == null) { + print('missing type: $schema'); + exit(1); + } + print('unknown type ${schema['type']}'); + exit(1); + } + if (type == 'array') { + assure(schema['items'] is Map, + () => 'array items are not a JSON object'); + return GenList(process(schema['items'] as Map), comment); + } + if (type == 'object') { + var anyOf = schema['anyOf']; + if (anyOf != null) { + assure(anyOf is List, () => 'anyOf key is not a JSON list'); + var result = GenAbstractClass( + camelCase(schema['title'] as String?) ?? '##unnamed##', + comment, + ); + for (final subschema in anyOf as List) { + assure(subschema is Map, + () => 'anyOf value is not a JSON object'); + var subclass = processObject(subschema as Map, + superclass: result); + assert(result.subclasses.last == subclass); + } + return result; + } + return processObject(schema, defaultName: defaultName); + } + if (type == 'null') { + return GenPrimitive(Null, comment); + } + if (type == 'boolean') { + return GenPrimitive(bool, comment); + } + if (type == 'integer') { + return GenPrimitive(int, comment); + } + if (type == 'string') { + return GenPrimitive(String, comment); + } + print('unknown type $type'); + exit(1); +} + +GenClass processObject(Map schema, + {GenAbstractClass? superclass, String? comment, String? defaultName}) { + assert(schema['anyOf'] == null); + comment ??= buildComment(schema); + var properties = {}; + var propertiesData = schema['properties']; + assure(propertiesData is Map, + () => 'properties key is not a JSON map'); + for (final propertyName in (propertiesData as Map).keys) { + var propertyData = propertiesData[propertyName]; + assure(propertyData is Map, + () => 'property $propertyName is not a JSON object'); + properties[camelCase(propertyName)!] = process( + propertyData as Map, + defaultName: camelCase(propertyName, uppercase: true)); + } + return GenClass( + camelCase(schema['title'] as String?) ?? defaultName ?? '##unnamed##', + comment, + superclass, + properties, + ); +} + +void main(List arguments) { + if (arguments.length != 1) { + print( + 'Command must be run with one argument, the file name of the schema to process.'); + exit(1); + } + Object schema = json.decode(File(arguments.single).readAsStringSync()); + assure(schema is Map, () => 'schema is not a JSON object'); + var rootType = process(schema as Map); + rootType.visit((GenType type) { + type.cleanup(); + }); + var declarations = {}; + rootType.visit((GenType type) { + var declaration = type.generateDeclaration().trimRight(); + declarations.add(declaration); + }); + for (final declaration in declarations) { + print(declaration); + print(''); + } + print('// root type is: ${rootType.name}'); +}