mirror of
https://github.com/git-touch/git-touch
synced 2025-03-03 10:47:47 +01:00
feat(gitea): repo screen
This commit is contained in:
parent
3272780515
commit
1aa7f0d130
@ -7,6 +7,8 @@ import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/screens/about.dart';
|
||||
import 'package:git_touch/screens/code_theme.dart';
|
||||
import 'package:git_touch/screens/commits.dart';
|
||||
import 'package:git_touch/screens/gitea_repo.dart';
|
||||
import 'package:git_touch/screens/gitea_user.dart';
|
||||
import 'package:git_touch/screens/gitlab_blob.dart';
|
||||
import 'package:git_touch/screens/gitlab_commits.dart';
|
||||
import 'package:git_touch/screens/gitlab_issue.dart';
|
||||
@ -74,6 +76,8 @@ void main() async {
|
||||
gitlabIssuesRouter,
|
||||
gitlabMergeRequestsRouter,
|
||||
gitlabCommitsRouter,
|
||||
giteaUserRouter,
|
||||
giteaRepoRouter,
|
||||
loginRouter,
|
||||
settingsRouter,
|
||||
userRouter,
|
||||
|
@ -23,6 +23,10 @@ class GiteaRepository {
|
||||
int starsCount;
|
||||
int forksCount;
|
||||
DateTime updatedAt;
|
||||
String website;
|
||||
int size;
|
||||
int openIssuesCount;
|
||||
int openPrCounter;
|
||||
GiteaRepository();
|
||||
factory GiteaRepository.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteaRepositoryFromJson(json);
|
||||
|
@ -37,7 +37,11 @@ GiteaRepository _$GiteaRepositoryFromJson(Map<String, dynamic> json) {
|
||||
..forksCount = json['forks_count'] as int
|
||||
..updatedAt = json['updated_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['updated_at'] as String);
|
||||
: DateTime.parse(json['updated_at'] as String)
|
||||
..website = json['website'] as String
|
||||
..size = json['size'] as int
|
||||
..openIssuesCount = json['open_issues_count'] as int
|
||||
..openPrCounter = json['open_pr_counter'] as int;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteaRepositoryToJson(GiteaRepository instance) =>
|
||||
@ -49,4 +53,8 @@ Map<String, dynamic> _$GiteaRepositoryToJson(GiteaRepository instance) =>
|
||||
'stars_count': instance.starsCount,
|
||||
'forks_count': instance.forksCount,
|
||||
'updated_at': instance.updatedAt?.toIso8601String(),
|
||||
'website': instance.website,
|
||||
'size': instance.size,
|
||||
'open_issues_count': instance.openIssuesCount,
|
||||
'open_pr_counter': instance.openPrCounter,
|
||||
};
|
||||
|
111
lib/screens/gitea_repo.dart
Normal file
111
lib/screens/gitea_repo.dart
Normal file
@ -0,0 +1,111 @@
|
||||
import 'package:filesize/filesize.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/gitea.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/entry_item.dart';
|
||||
import 'package:git_touch/widgets/markdown_view.dart';
|
||||
import 'package:git_touch/widgets/repo_header.dart';
|
||||
import 'package:git_touch/widgets/table_view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
final giteaRepoRouter = RouterScreen(
|
||||
'/gitea/:owner/:name',
|
||||
(context, params) =>
|
||||
GiteaRepoScreen(params['owner'].first, params['name'].first),
|
||||
);
|
||||
|
||||
class GiteaRepoScreen extends StatelessWidget {
|
||||
final String owner;
|
||||
final String name;
|
||||
GiteaRepoScreen(this.owner, this.name);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<Tuple2<GiteaRepository, String>>(
|
||||
title: AppBarTitle('Repository'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await Future.wait([
|
||||
auth.fetchGitea('/repos/$owner/$name'),
|
||||
auth.fetchGitea('/repos/$owner/$name/contents/README.md'),
|
||||
]);
|
||||
return Tuple2(
|
||||
GiteaRepository.fromJson(res[0]),
|
||||
convertBase64ToString(res[1]['content']),
|
||||
);
|
||||
},
|
||||
bodyBuilder: (t, setState) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
final p = t.item1;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
RepoHeader(
|
||||
avatarUrl: p.owner.avatarUrl,
|
||||
avatarLink: '/gitea/${p.owner.login}',
|
||||
owner: p.owner.login,
|
||||
name: p.name,
|
||||
description: p.description,
|
||||
homepageUrl: p.website,
|
||||
),
|
||||
CommonStyle.border,
|
||||
Row(
|
||||
children: <Widget>[
|
||||
EntryItem(
|
||||
count: p.starsCount,
|
||||
text: 'Stars',
|
||||
),
|
||||
EntryItem(
|
||||
count: p.forksCount,
|
||||
text: 'Forks', // TODO:
|
||||
),
|
||||
],
|
||||
),
|
||||
CommonStyle.border,
|
||||
TableView(
|
||||
hasIcon: true,
|
||||
items: [
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.code,
|
||||
text: Text('Code'),
|
||||
rightWidget: Text(filesize(p.size * 1000)),
|
||||
url: '/gitea/blob',
|
||||
),
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.issue_opened,
|
||||
text: Text('Issues'),
|
||||
rightWidget: Text(numberFormat.format(p.openIssuesCount)),
|
||||
url: '/gitea/$owner/$name/issues',
|
||||
),
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.git_pull_request,
|
||||
text: Text('Pull requests'),
|
||||
rightWidget: Text(numberFormat.format(p.openPrCounter)),
|
||||
url: '/gitea/$owner/$name/pulls',
|
||||
),
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.history,
|
||||
text: Text('Commits'),
|
||||
url: '/gitea/$owner/$name/commits',
|
||||
),
|
||||
],
|
||||
),
|
||||
CommonStyle.verticalGap,
|
||||
if (t.item2 != null)
|
||||
Container(
|
||||
padding: CommonStyle.padding,
|
||||
color: theme.palette.background,
|
||||
child: MarkdownView(t.item2),
|
||||
),
|
||||
CommonStyle.verticalGap,
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -12,6 +12,11 @@ import 'package:provider/provider.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
final giteaUserRouter = RouterScreen(
|
||||
'/gitea/:login',
|
||||
(context, params) => GiteaUserScreen(params['login'].first),
|
||||
);
|
||||
|
||||
class GiteaUserScreen extends StatelessWidget {
|
||||
final String login;
|
||||
GiteaUserScreen(this.login);
|
||||
@ -66,7 +71,7 @@ class GiteaUserScreen extends StatelessWidget {
|
||||
starCount: v.starsCount,
|
||||
forkCount: v.forksCount,
|
||||
note: 'Updated ${timeago.format(v.updatedAt)}',
|
||||
url: '', // TODO:
|
||||
url: '/gitea/${v.owner.login}/${v.name}', // TODO:
|
||||
)
|
||||
],
|
||||
)
|
||||
|
@ -47,16 +47,9 @@ class RepositoryScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
Future<String> _fetchReadme(BuildContext context) async {
|
||||
var data = await Provider.of<AuthModel>(context)
|
||||
final data = await Provider.of<AuthModel>(context)
|
||||
.getWithCredentials('/repos/$owner/$name/readme');
|
||||
|
||||
if (data['content'] == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var bits = base64.decode((data['content'] as String).replaceAll('\n', ''));
|
||||
var str = utf8.decode(bits);
|
||||
return str;
|
||||
return convertBase64ToString(data['content']);
|
||||
}
|
||||
|
||||
Widget _buildLanguages(BuildContext context, GhRepoRepository repo) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:fluro/fluro.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -187,3 +188,9 @@ class RouterScreen {
|
||||
}
|
||||
|
||||
final dateFormat = DateFormat.yMMMMd();
|
||||
|
||||
String convertBase64ToString(String input) {
|
||||
if (input == null) return null;
|
||||
final bits = base64.decode(input.replaceAll('\n', ''));
|
||||
return utf8.decode(bits);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user