1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-15 17:59:35 +01:00

feat(gitlab): repo size and commits

This commit is contained in:
Rongjian Zhang 2020-01-28 21:01:06 +08:00
parent f5ad1acd25
commit 248212c95c
3 changed files with 50 additions and 11 deletions

View File

@ -82,11 +82,20 @@ class GitlabIssueNote {
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GitlabLabel {
class GitlabProjectBadge {
String renderedImageUrl;
GitlabLabel();
factory GitlabLabel.fromJson(Map<String, dynamic> json) =>
_$GitlabLabelFromJson(json);
GitlabProjectBadge();
factory GitlabProjectBadge.fromJson(Map<String, dynamic> json) =>
_$GitlabProjectBadgeFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GitlabProjectStatistics {
int commitCount;
int repositorySize;
GitlabProjectStatistics();
factory GitlabProjectStatistics.fromJson(Map<String, dynamic> 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<String, dynamic> json) =>
_$GitlabProjectFromJson(json);

View File

@ -116,15 +116,30 @@ Map<String, dynamic> _$GitlabIssueNoteToJson(GitlabIssueNote instance) =>
'body': instance.body,
};
GitlabLabel _$GitlabLabelFromJson(Map<String, dynamic> json) {
return GitlabLabel()..renderedImageUrl = json['rendered_image_url'] as String;
GitlabProjectBadge _$GitlabProjectBadgeFromJson(Map<String, dynamic> json) {
return GitlabProjectBadge()
..renderedImageUrl = json['rendered_image_url'] as String;
}
Map<String, dynamic> _$GitlabLabelToJson(GitlabLabel instance) =>
Map<String, dynamic> _$GitlabProjectBadgeToJson(GitlabProjectBadge instance) =>
<String, dynamic>{
'rendered_image_url': instance.renderedImageUrl,
};
GitlabProjectStatistics _$GitlabProjectStatisticsFromJson(
Map<String, dynamic> json) {
return GitlabProjectStatistics()
..commitCount = json['commit_count'] as int
..repositorySize = json['repository_size'] as int;
}
Map<String, dynamic> _$GitlabProjectStatisticsToJson(
GitlabProjectStatistics instance) =>
<String, dynamic>{
'commit_count': instance.commitCount,
'repository_size': instance.repositorySize,
};
GitlabProject _$GitlabProjectFromJson(Map<String, dynamic> json) {
return GitlabProject()
..id = json['id'] as int
@ -142,7 +157,11 @@ GitlabProject _$GitlabProjectFromJson(Map<String, dynamic> json) {
json['namespace'] as Map<String, dynamic>)
..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<String, dynamic>);
}
Map<String, dynamic> _$GitlabProjectToJson(GitlabProject instance) =>
@ -160,6 +179,7 @@ Map<String, dynamic> _$GitlabProjectToJson(GitlabProject instance) =>
'issues_enabled': instance.issuesEnabled,
'open_issues_count': instance.openIssuesCount,
'merge_requests_enabled': instance.mergeRequestsEnabled,
'statistics': instance.statistics,
};
GitlabProjectNamespace _$GitlabProjectNamespaceFromJson(

View File

@ -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<GitlabProject, Map<String, double>, List<GitlabLabel>, String>>(
Tuple4<GitlabProject, Map<String, double>, List<GitlabProjectBadge>,
String>>(
title: AppBarTitle('Project'),
fetchData: () async {
final auth = Provider.of<AuthModel>(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<String, double>.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,