From 248212c95c702432b392a971173a020649a8a761 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Tue, 28 Jan 2020 21:01:06 +0800 Subject: [PATCH] feat(gitlab): repo size and commits --- lib/models/gitlab.dart | 18 ++++++++++++++---- lib/models/gitlab.g.dart | 28 ++++++++++++++++++++++++---- lib/screens/gitlab_project.dart | 15 ++++++++++++--- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/lib/models/gitlab.dart b/lib/models/gitlab.dart index febcd00..c8dd9c7 100644 --- a/lib/models/gitlab.dart +++ b/lib/models/gitlab.dart @@ -82,11 +82,20 @@ class GitlabIssueNote { } @JsonSerializable(fieldRename: FieldRename.snake) -class GitlabLabel { +class GitlabProjectBadge { String renderedImageUrl; - GitlabLabel(); - factory GitlabLabel.fromJson(Map json) => - _$GitlabLabelFromJson(json); + GitlabProjectBadge(); + factory GitlabProjectBadge.fromJson(Map json) => + _$GitlabProjectBadgeFromJson(json); +} + +@JsonSerializable(fieldRename: FieldRename.snake) +class GitlabProjectStatistics { + int commitCount; + int repositorySize; + GitlabProjectStatistics(); + factory GitlabProjectStatistics.fromJson(Map json) => + _$GitlabProjectStatisticsFromJson(json); } @JsonSerializable(fieldRename: FieldRename.snake) @@ -104,6 +113,7 @@ class GitlabProject { bool issuesEnabled; int openIssuesCount; bool mergeRequestsEnabled; + GitlabProjectStatistics statistics; GitlabProject(); factory GitlabProject.fromJson(Map json) => _$GitlabProjectFromJson(json); diff --git a/lib/models/gitlab.g.dart b/lib/models/gitlab.g.dart index 490936b..e27240c 100644 --- a/lib/models/gitlab.g.dart +++ b/lib/models/gitlab.g.dart @@ -116,15 +116,30 @@ Map _$GitlabIssueNoteToJson(GitlabIssueNote instance) => 'body': instance.body, }; -GitlabLabel _$GitlabLabelFromJson(Map json) { - return GitlabLabel()..renderedImageUrl = json['rendered_image_url'] as String; +GitlabProjectBadge _$GitlabProjectBadgeFromJson(Map json) { + return GitlabProjectBadge() + ..renderedImageUrl = json['rendered_image_url'] as String; } -Map _$GitlabLabelToJson(GitlabLabel instance) => +Map _$GitlabProjectBadgeToJson(GitlabProjectBadge instance) => { 'rendered_image_url': instance.renderedImageUrl, }; +GitlabProjectStatistics _$GitlabProjectStatisticsFromJson( + Map json) { + return GitlabProjectStatistics() + ..commitCount = json['commit_count'] as int + ..repositorySize = json['repository_size'] as int; +} + +Map _$GitlabProjectStatisticsToJson( + GitlabProjectStatistics instance) => + { + 'commit_count': instance.commitCount, + 'repository_size': instance.repositorySize, + }; + GitlabProject _$GitlabProjectFromJson(Map json) { return GitlabProject() ..id = json['id'] as int @@ -142,7 +157,11 @@ GitlabProject _$GitlabProjectFromJson(Map json) { json['namespace'] as Map) ..issuesEnabled = json['issues_enabled'] as bool ..openIssuesCount = json['open_issues_count'] as int - ..mergeRequestsEnabled = json['merge_requests_enabled'] as bool; + ..mergeRequestsEnabled = json['merge_requests_enabled'] as bool + ..statistics = json['statistics'] == null + ? null + : GitlabProjectStatistics.fromJson( + json['statistics'] as Map); } Map _$GitlabProjectToJson(GitlabProject instance) => @@ -160,6 +179,7 @@ Map _$GitlabProjectToJson(GitlabProject instance) => 'issues_enabled': instance.issuesEnabled, 'open_issues_count': instance.openIssuesCount, 'merge_requests_enabled': instance.mergeRequestsEnabled, + 'statistics': instance.statistics, }; GitlabProjectNamespace _$GitlabProjectNamespaceFromJson( diff --git a/lib/screens/gitlab_project.dart b/lib/screens/gitlab_project.dart index dac3f36..2dc7b58 100644 --- a/lib/screens/gitlab_project.dart +++ b/lib/screens/gitlab_project.dart @@ -1,3 +1,4 @@ +import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_svg/svg.dart'; @@ -26,12 +27,13 @@ class GitlabProjectScreen extends StatelessWidget { @override Widget build(BuildContext context) { return RefreshStatefulScaffold< - Tuple4, List, String>>( + Tuple4, List, + String>>( title: AppBarTitle('Project'), fetchData: () async { final auth = Provider.of(context); final res = await Future.wait([ - auth.fetchGitlab('/projects/$id'), + auth.fetchGitlab('/projects/$id?statistics=1'), auth.fetchGitlab('/projects/$id/languages'), auth.fetchGitlab('/projects/$id/badges'), ]); @@ -44,7 +46,7 @@ class GitlabProjectScreen extends StatelessWidget { return Tuple4( p, Map.from(res[1]), - (res[2] as List).map((v) => GitlabLabel.fromJson(v)).toList(), + (res[2] as List).map((v) => GitlabProjectBadge.fromJson(v)).toList(), readme, ); }, @@ -128,6 +130,7 @@ class GitlabProjectScreen extends StatelessWidget { TableViewItem( leftIconData: Octicons.code, text: Text(langs.keys.isEmpty ? 'Code' : langs.keys.first), + rightWidget: Text(filesize(p.statistics.repositorySize)), url: '/gitlab/projects/$id/tree', ), if (p.issuesEnabled) @@ -143,6 +146,12 @@ class GitlabProjectScreen extends StatelessWidget { text: Text('Merge requests'), url: '/gitlab/projects/$id/merge_requests', ), + TableViewItem( + leftIconData: Octicons.history, + text: Text('Commits'), + rightWidget: Text(p.statistics.commitCount.toString()), + url: '/gitlab/projects/$id/commits', + ), ], ), CommonStyle.verticalGap,