completed handling all event types (#49)

This commit is contained in:
Shreyas Thirumalai 2020-04-08 08:21:04 +05:30 committed by GitHub
parent a2d771cc84
commit 99ef399280
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 439 additions and 34 deletions

View File

@ -67,7 +67,15 @@ class GithubEventPayload {
String head;
List<GithubEventCommit> commits;
Map<String, dynamic> forkee;
List<GithubPagesItem> pages;
GithubSecurityItem securityAdvisory;
GithubAlertItem alert;
GithubProjectItem project;
GithubProjectColumnItem projectColumn;
GithubInstallationRepositoriesItem installation;
GithubCheckrunItem checkRun;
GithubCheckSuiteItem checkSuite;
GithubContentReferenceItem contentReference;
GithubEventPayload();
factory GithubEventPayload.fromJson(Map<String, dynamic> json) =>
@ -204,3 +212,92 @@ class GithubTreeItem {
factory GithubTreeItem.fromJson(Map<String, dynamic> json) =>
_$GithubTreeItemFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GithubPagesItem {
String pageName;
String title;
String action;
GithubPagesItem();
factory GithubPagesItem.fromJson(Map<String, dynamic> json) =>
_$GithubPagesItemFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GithubSecurityItem {
String summary;
String description;
String severity;
GithubSecurityItem();
factory GithubSecurityItem.fromJson(Map<String, dynamic> json) =>
_$GithubSecurityItemFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GithubAlertItem {
String affectedPackageName;
String affectedRange;
GithubAlertItem();
factory GithubAlertItem.fromJson(Map<String, dynamic> json) =>
_$GithubAlertItemFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GithubProjectItem {
String name;
String state;
String body;
String htmlUrl;
GithubProjectItem();
factory GithubProjectItem.fromJson(Map<String, dynamic> json) =>
_$GithubProjectItemFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GithubProjectColumnItem {
String htmlUrl;
String columnsUrl;
String name;
GithubProjectColumnItem();
factory GithubProjectColumnItem.fromJson(Map<String, dynamic> json) =>
_$GithubProjectColumnItemFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GithubInstallationRepositoriesItem {
List<GithubNotificationItemRepo> repositoriesAdded, repositoriesRemoved;
String repositoriesSelection;
int id;
GithubInstallationRepositoriesItem();
factory GithubInstallationRepositoriesItem.fromJson(Map<String, dynamic> json) =>
_$GithubInstallationRepositoriesItemFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GithubCheckrunItem {
String status;
String name;
int id;
GithubCheckrunItem();
factory GithubCheckrunItem.fromJson(Map<String, dynamic> json) =>
_$GithubCheckrunItemFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GithubCheckSuiteItem {
String status;
String conclusion;
GithubCheckSuiteItem();
factory GithubCheckSuiteItem.fromJson(Map<String, dynamic> json) =>
_$GithubCheckSuiteItemFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GithubContentReferenceItem {
int id;
String reference;
GithubContentReferenceItem();
factory GithubContentReferenceItem.fromJson(Map<String, dynamic> json) =>
_$GithubContentReferenceItemFromJson(json);
}

View File

@ -78,7 +78,37 @@ GithubEventPayload _$GithubEventPayloadFromJson(Map<String, dynamic> json) {
? null
: GithubEventCommit.fromJson(e as Map<String, dynamic>))
?.toList()
..forkee = json['forkee'] as Map<String, dynamic>;
..forkee = json['forkee'] as Map<String, dynamic>
..pages = (json['pages'] as List)
?.map((e) => e == null
? null
: GithubPagesItem.fromJson(e as Map<String, dynamic>))
?.toList()
..securityAdvisory = json['security_advisory'] == null
? null
: GithubSecurityItem.fromJson(
json['security_advisory'] as Map<String, dynamic>)
..alert = json['alert'] == null
? null
: GithubAlertItem.fromJson(json['alert'] as Map<String, dynamic>)
..project = json['project'] == null
? null
: GithubProjectItem.fromJson(json['project'] as Map<String, dynamic>)
..projectColumn = json['project_column'] == null
? null
: GithubProjectColumnItem.fromJson(
json['project_column'] as Map<String, dynamic>)
..installation = json['installation'] == null
? null
: GithubInstallationRepositoriesItem.fromJson(
json['installation'] as Map<String, dynamic>)
..checkRun = json['check_run'] == null
? null
: GithubCheckrunItem.fromJson(json['check_run'] as Map<String, dynamic>)
..checkSuite = json['check_suite'] == null
? null
: GithubCheckSuiteItem.fromJson(
json['check_suite'] as Map<String, dynamic>);
}
Map<String, dynamic> _$GithubEventPayloadToJson(GithubEventPayload instance) =>
@ -94,6 +124,14 @@ Map<String, dynamic> _$GithubEventPayloadToJson(GithubEventPayload instance) =>
'head': instance.head,
'commits': instance.commits,
'forkee': instance.forkee,
'pages': instance.pages,
'security_advisory': instance.securityAdvisory,
'alert': instance.alert,
'project': instance.project,
'project_column': instance.projectColumn,
'installation': instance.installation,
'check_run': instance.checkRun,
'check_suite': instance.checkSuite,
};
GithubEventIssue _$GithubEventIssueFromJson(Map<String, dynamic> json) {
@ -238,3 +276,142 @@ Map<String, dynamic> _$GithubTreeItemToJson(GithubTreeItem instance) =>
'download_url': instance.downloadUrl,
'content': instance.content,
};
GithubPagesItem _$GithubPagesItemFromJson(Map<String, dynamic> json) {
return GithubPagesItem()
..pageName = json['page_name'] as String
..title = json['title'] as String
..action = json['action'] as String;
}
Map<String, dynamic> _$GithubPagesItemToJson(GithubPagesItem instance) =>
<String, dynamic>{
'page_name': instance.pageName,
'title': instance.title,
'action': instance.action,
};
GithubSecurityItem _$GithubSecurityItemFromJson(Map<String, dynamic> json) {
return GithubSecurityItem()
..summary = json['summary'] as String
..description = json['description'] as String
..severity = json['severity'] as String;
}
Map<String, dynamic> _$GithubSecurityItemToJson(GithubSecurityItem instance) =>
<String, dynamic>{
'summary': instance.summary,
'description': instance.description,
'severity': instance.severity,
};
GithubAlertItem _$GithubAlertItemFromJson(Map<String, dynamic> json) {
return GithubAlertItem()
..affectedPackageName = json['affected_package_name'] as String
..affectedRange = json['affected_range'] as String;
}
Map<String, dynamic> _$GithubAlertItemToJson(GithubAlertItem instance) =>
<String, dynamic>{
'affected_package_name': instance.affectedPackageName,
'affected_range': instance.affectedRange,
};
GithubProjectItem _$GithubProjectItemFromJson(Map<String, dynamic> json) {
return GithubProjectItem()
..name = json['name'] as String
..state = json['state'] as String
..body = json['body'] as String
..htmlUrl = json['html_url'] as String;
}
Map<String, dynamic> _$GithubProjectItemToJson(GithubProjectItem instance) =>
<String, dynamic>{
'name': instance.name,
'state': instance.state,
'body': instance.body,
'html_url': instance.htmlUrl,
};
GithubProjectColumnItem _$GithubProjectColumnItemFromJson(
Map<String, dynamic> json) {
return GithubProjectColumnItem()
..htmlUrl = json['html_url'] as String
..columnsUrl = json['columns_url'] as String
..name = json['name'] as String;
}
Map<String, dynamic> _$GithubProjectColumnItemToJson(
GithubProjectColumnItem instance) =>
<String, dynamic>{
'html_url': instance.htmlUrl,
'columns_url': instance.columnsUrl,
'name': instance.name,
};
GithubInstallationRepositoriesItem _$GithubInstallationRepositoriesItemFromJson(
Map<String, dynamic> json) {
return GithubInstallationRepositoriesItem()
..repositoriesAdded = (json['repositories_added'] as List)
?.map((e) => e == null
? null
: GithubNotificationItemRepo.fromJson(e as Map<String, dynamic>))
?.toList()
..repositoriesRemoved = (json['repositories_removed'] as List)
?.map((e) => e == null
? null
: GithubNotificationItemRepo.fromJson(e as Map<String, dynamic>))
?.toList()
..repositoriesSelection = json['repositories_selection'] as String
..id = json['id'] as int;
}
Map<String, dynamic> _$GithubInstallationRepositoriesItemToJson(
GithubInstallationRepositoriesItem instance) =>
<String, dynamic>{
'repositories_added': instance.repositoriesAdded,
'repositories_removed': instance.repositoriesRemoved,
'repositories_selection': instance.repositoriesSelection,
'id': instance.id,
};
GithubCheckrunItem _$GithubCheckrunItemFromJson(Map<String, dynamic> json) {
return GithubCheckrunItem()
..status = json['status'] as String
..name = json['name'] as String
..id = json['id'] as int;
}
Map<String, dynamic> _$GithubCheckrunItemToJson(GithubCheckrunItem instance) =>
<String, dynamic>{
'status': instance.status,
'name': instance.name,
'id': instance.id,
};
GithubCheckSuiteItem _$GithubCheckSuiteItemFromJson(Map<String, dynamic> json) {
return GithubCheckSuiteItem()
..status = json['status'] as String
..conclusion = json['conclusion'] as String;
}
Map<String, dynamic> _$GithubCheckSuiteItemToJson(
GithubCheckSuiteItem instance) =>
<String, dynamic>{
'status': instance.status,
'conclusion': instance.conclusion,
};
GithubContentReferenceItem _$GithubContentReferenceItemFromJson(
Map<String, dynamic> json) {
return GithubContentReferenceItem()
..id = json['id'] as int
..reference = json['reference'] as String;
}
Map<String, dynamic> _$GithubContentReferenceItemToJson(
GithubContentReferenceItem instance) =>
<String, dynamic>{
'id': instance.id,
'reference': instance.reference,
};

View File

@ -257,9 +257,55 @@ class EventItem extends StatelessWidget {
// https://developer.github.com/v3/activity/events/types/#event-types--payloads
switch (e.type) {
case 'CheckRunEvent':
return _buildItem(
context: context,
spans: [
TextSpan(text: ' ${e.payload.action} a check run for ${e.payload.checkRun.name} '),
]
);
case 'CheckSuiteEvent':
// Needs checks permission
String conclusion = "";
switch(e.payload.checkSuite.conclusion) {
case 'success':
case 'failure':
conclusion = 'it is a ' + e.payload.checkSuite.conclusion;
break;
case 'neutral':
case 'cancelled':
case 'timed_out':
case 'stale':
conclusion = 'it is ' + e.payload.checkSuite.conclusion;
break;
case 'action_required':
conclusion = ' it requires more action';
break;
}
return _buildItem(
context: context,
spans: [
TextSpan(text: ' ${e.payload.action} the check suite and the conclusion is that $conclusion'),
],
);
case 'CommitCommentEvent':
return _buildItem(
context: context,
spans: [
TextSpan(text: ' ${e.payload.action} a comment on the commit at '),
_buildRepo(context),
TextSpan(text: ' ${e.payload.comment.body} '),
],
card: _buildCommitsCard(context),
);
case 'ContentReferenceEvent':
return _buildItem(
context: context,
spans: [
TextSpan(text: ' ${e.payload.action} a content reference at '),
_buildLinkSpan(
context, e.payload.contentReference.reference, e.payload.contentReference.reference),
]
);
case 'CreateEvent':
return _buildItem(
context: context,
@ -279,12 +325,6 @@ class EventItem extends StatelessWidget {
_buildRepo(context),
],
);
case 'DeploymentEvent':
case 'DeploymentStatusEvent':
case 'DownloadEvent':
case 'FollowEvent':
// TODO:
return _buildDefaultItem(context);
case 'ForkEvent':
final forkeeOwner = e.payload.forkee['owner']['login'] as String;
final forkeeName = e.payload.forkee['name'] as String;
@ -297,14 +337,66 @@ class EventItem extends StatelessWidget {
_buildRepo(context),
],
);
case 'ForkApplyEvent':
case 'GitHubAppAuthorizationEvent':
case 'GistEvent':
case 'GollumEvent':
String pageNamesCreated = "";
String pageNamesEdited = "";
for(GithubPagesItem page in e.payload.pages) {
if(page.action == "edited") {
pageNamesEdited += ", " + page.pageName;
} else {
pageNamesCreated += ", " + page.pageName;
}
}
if(pageNamesCreated.length > 0) {
pageNamesCreated = " created the pages: \n" + pageNamesCreated + "\n";
}
if(pageNamesEdited.length > 0) {
pageNamesEdited = " edited the pages: \n" + pageNamesEdited + "\n";
}
return _buildItem(
context: context,
spans: [
TextSpan(
text: ' $pageNamesCreated\n$pageNamesEdited '
)
]
);
case 'InstallationEvent':
String action = e.payload.action;
if(action == 'new_permissions_accepted') {
action = "new permission were accepted for";
}
return _buildItem(
context: context,
spans: [
TextSpan(text: ' $action for the Github App with id ${e.payload.installation.id}'),
],
);
case 'InstallationRepositoriesEvent':
// TODO:
return _buildDefaultItem(context);
List<GithubNotificationItemRepo> repositoriesAdded = e.payload.installation.repositoriesAdded;
List<GithubNotificationItemRepo> repositoriesRemoved = e.payload.installation.repositoriesRemoved;
String addedRepos = "";
String removedRepos = "";
for(GithubNotificationItemRepo repo in repositoriesAdded) {
addedRepos += repo.fullName + ", ";
}
for(GithubNotificationItemRepo repo in repositoriesRemoved) {
removedRepos += repo.fullName + ", ";
}
String finalListOfRepos = "";
if(addedRepos != "") {
finalListOfRepos += addedRepos + " were added to\n ";
}
if(removedRepos != "") {
finalListOfRepos += removedRepos + " were removed from";
}
return _buildItem(
context: context,
spans: [
TextSpan(text: ' $finalListOfRepos the installation id ${e.payload.installation.id} '),
],
);
case 'IssueCommentEvent':
return _buildItem(
context: context,
@ -339,7 +431,6 @@ class EventItem extends StatelessWidget {
],
card: _buildIssueCard(context, issue, issue.body),
);
case 'LabelEvent':
case 'MarketplacePurchaseEvent':
final action = e.payload.action;
var messageToDisplay;
@ -380,22 +471,43 @@ class EventItem extends StatelessWidget {
_buildRepo(context),
],
);
case 'MembershipEvent':
case 'MilestoneEvent':
case 'OrganizationEvent':
case 'OrgBlockEvent':
case 'PageBuildEvent':
case 'ProjectCardEvent':
String action = e.payload.action;
if(action == 'converted') {
action = ' converted the project card into an issue ';
} else {
action = action + ' the project card ';
}
return _buildItem(
context: context,
spans: [
TextSpan(text: ' $action at '),
_buildRepo(context),
],
);
case 'ProjectColumnEvent':
return _buildItem(
context: context,
spans: [
TextSpan(text: ' ${e.payload.action} the project column ${e.payload.projectColumn.name} at '),
_buildRepo(context),
]
);
case 'ProjectEvent':
return _buildItem(
context: context,
spans: [
TextSpan(text: ' ${e.payload.action} the project ${e.payload.project.name} '),
]
);
case 'PublicEvent':
return _buildItem(
context: context,
spans: [
TextSpan(text: ' made '),
_buildRepo(context),
TextSpan(text: ' public'),
],
context: context,
spans: [
TextSpan(text: ' made '),
_buildRepo(context),
TextSpan(text: ' public'),
],
);
case 'PullRequestEvent':
final pr = e.payload.pullRequest;
@ -410,8 +522,16 @@ class EventItem extends StatelessWidget {
card: _buildIssueCard(context, pr, pr.body, isPullRequest: true),
);
case 'PullRequestReviewEvent':
// TODO:
return _buildDefaultItem(context);
final pr = e.payload.pullRequest;
return _buildItem(
context: context,
spans: [
TextSpan(text: ' ${e.payload.action} the pull request review '),
_buildIssue(context, pr.number, isPullRequest: true),
TextSpan(text: ' at '),
_buildRepo(context),
]
);
case 'PullRequestReviewCommentEvent':
final pr = e.payload.pullRequest;
return _buildItem(
@ -442,15 +562,26 @@ class EventItem extends StatelessWidget {
_buildRepo(context)
],
);
case 'RepositoryEvent':
case 'RepositoryImportEvent':
// case 'RepositoryImportEvent':
// // Uses Source Imports API
case 'RepositoryVulnerabilityAlertEvent':
return _buildItem(
context: context,
spans: [
TextSpan(
text: ' Security alert involving the package ${e.payload.alert.affectedPackageName} between versions ${e.payload.alert.affectedRange} was {e.payload.action}ed',
)
]
);
case 'SecurityAdvisoryEvent':
case 'StatusEvent':
case 'TeamEvent':
case 'TeamAddEvent':
// TODO:
return _buildDefaultItem(context);
return _buildItem(
context: context,
spans: [
TextSpan(
text: ' Security advisory regarding ${e.payload.securityAdvisory.summary} was ${e.payload.action} ',
)
]
);
case 'WatchEvent':
return _buildItem(
context: context,