mirror of
https://github.com/git-touch/git-touch
synced 2025-03-05 19:57:42 +01:00
feat(gitee): commits screen
This commit is contained in:
parent
66ab665f31
commit
d9ca01b99d
@ -282,11 +282,14 @@ class AuthModel with ChangeNotifier {
|
||||
final res = await http.get(uri, headers: {'Authorization': 'token $token'});
|
||||
final info = json.decode(utf8.decode(res.bodyBytes));
|
||||
|
||||
final totalPage = int.tryParse(res.headers['total_page'] ?? '');
|
||||
final totalCount = int.tryParse(res.headers['total_count'] ?? '');
|
||||
|
||||
return DataWithPage(
|
||||
data: info,
|
||||
cursor: page + 1,
|
||||
hasMore: int.tryParse(res.headers['total_page']) > page,
|
||||
total: int.tryParse(res.headers['total_count'] ?? ''),
|
||||
hasMore: totalPage == null ? info.length > limit : totalPage > page,
|
||||
total: totalCount,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -71,3 +71,34 @@ class GiteeRepoNamespace {
|
||||
factory GiteeRepoNamespace.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteeRepoNamespaceFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GiteeCommit {
|
||||
GiteeUser author;
|
||||
GiteeCommitDetail commit;
|
||||
String sha;
|
||||
String htmlUrl;
|
||||
GiteeCommit();
|
||||
factory GiteeCommit.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteeCommitFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GiteeCommitDetail {
|
||||
String message;
|
||||
GiteeCommitAuthor author;
|
||||
GiteeCommitAuthor committer;
|
||||
GiteeCommitDetail();
|
||||
factory GiteeCommitDetail.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteeCommitDetailFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GiteeCommitAuthor {
|
||||
String name;
|
||||
String email;
|
||||
DateTime date;
|
||||
GiteeCommitAuthor();
|
||||
factory GiteeCommitAuthor.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteeCommitAuthorFromJson(json);
|
||||
}
|
||||
|
@ -120,3 +120,56 @@ Map<String, dynamic> _$GiteeRepoNamespaceToJson(GiteeRepoNamespace instance) =>
|
||||
<String, dynamic>{
|
||||
'path': instance.path,
|
||||
};
|
||||
|
||||
GiteeCommit _$GiteeCommitFromJson(Map<String, dynamic> json) {
|
||||
return GiteeCommit()
|
||||
..author = json['author'] == null
|
||||
? null
|
||||
: GiteeUser.fromJson(json['author'] as Map<String, dynamic>)
|
||||
..commit = json['commit'] == null
|
||||
? null
|
||||
: GiteeCommitDetail.fromJson(json['commit'] as Map<String, dynamic>)
|
||||
..sha = json['sha'] as String
|
||||
..htmlUrl = json['html_url'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteeCommitToJson(GiteeCommit instance) =>
|
||||
<String, dynamic>{
|
||||
'author': instance.author,
|
||||
'commit': instance.commit,
|
||||
'sha': instance.sha,
|
||||
'html_url': instance.htmlUrl,
|
||||
};
|
||||
|
||||
GiteeCommitDetail _$GiteeCommitDetailFromJson(Map<String, dynamic> json) {
|
||||
return GiteeCommitDetail()
|
||||
..message = json['message'] as String
|
||||
..author = json['author'] == null
|
||||
? null
|
||||
: GiteeCommitAuthor.fromJson(json['author'] as Map<String, dynamic>)
|
||||
..committer = json['committer'] == null
|
||||
? null
|
||||
: GiteeCommitAuthor.fromJson(json['committer'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteeCommitDetailToJson(GiteeCommitDetail instance) =>
|
||||
<String, dynamic>{
|
||||
'message': instance.message,
|
||||
'author': instance.author,
|
||||
'committer': instance.committer,
|
||||
};
|
||||
|
||||
GiteeCommitAuthor _$GiteeCommitAuthorFromJson(Map<String, dynamic> json) {
|
||||
return GiteeCommitAuthor()
|
||||
..name = json['name'] as String
|
||||
..email = json['email'] as String
|
||||
..date =
|
||||
json['date'] == null ? null : DateTime.parse(json['date'] as String);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteeCommitAuthorToJson(GiteeCommitAuthor instance) =>
|
||||
<String, dynamic>{
|
||||
'name': instance.name,
|
||||
'email': instance.email,
|
||||
'date': instance.date?.toIso8601String(),
|
||||
};
|
||||
|
@ -6,6 +6,7 @@ import 'package:git_touch/screens/bb_issues.dart';
|
||||
import 'package:git_touch/screens/bb_pulls.dart';
|
||||
import 'package:git_touch/screens/bb_user.dart';
|
||||
import 'package:git_touch/screens/code_theme.dart';
|
||||
import 'package:git_touch/screens/ge_commits.dart';
|
||||
import 'package:git_touch/screens/ge_repo.dart';
|
||||
import 'package:git_touch/screens/ge_repos.dart';
|
||||
import 'package:git_touch/screens/ge_user.dart';
|
||||
@ -384,6 +385,7 @@ class GiteeRouter {
|
||||
GiteeRouter.stargazers,
|
||||
GiteeRouter.watchers,
|
||||
GiteeRouter.forks,
|
||||
GiteeRouter.commits,
|
||||
];
|
||||
static final user = RouterScreen('/:login', (context, p) {
|
||||
final login = p['login'].first;
|
||||
@ -416,4 +418,8 @@ class GiteeRouter {
|
||||
static final forks = RouterScreen('/:owner/:name/forks', (_, p) {
|
||||
return GeReposScreen.forks(p['owner'].first, p['name'].first);
|
||||
});
|
||||
static final commits = RouterScreen(
|
||||
'/:owner/:name/commits',
|
||||
(_, p) => GeCommitsScreen(p['owner'].first, p['name'].first),
|
||||
);
|
||||
}
|
||||
|
41
lib/screens/ge_commits.dart
Normal file
41
lib/screens/ge_commits.dart
Normal file
@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/gitee.dart';
|
||||
import 'package:git_touch/scaffolds/list_stateful.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/commit_item.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class GeCommitsScreen extends StatelessWidget {
|
||||
final String owner;
|
||||
final String name;
|
||||
// final String branch; // TODO:
|
||||
GeCommitsScreen(this.owner, this.name);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListStatefulScaffold<GiteeCommit, int>(
|
||||
title: AppBarTitle('Commits'),
|
||||
fetch: (page) async {
|
||||
final res = await context
|
||||
.read<AuthModel>()
|
||||
.fetchGiteeWithPage('/repos/$owner/$name/commits', page: page);
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
items: [for (var v in res.data) GiteeCommit.fromJson(v)],
|
||||
);
|
||||
},
|
||||
itemBuilder: (c) {
|
||||
return CommitItem(
|
||||
author: c.commit.author.name,
|
||||
avatarUrl: c.author.avatarUrl,
|
||||
avatarLink: '/gitee/${c.author.login}',
|
||||
createdAt: c.commit.author.date,
|
||||
message: c.commit.message,
|
||||
url: c.htmlUrl,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -36,15 +36,15 @@ class GeReposScreen extends StatelessWidget {
|
||||
},
|
||||
itemBuilder: (v) {
|
||||
return RepositoryItem(
|
||||
owner: v.owner.login,
|
||||
owner: v.namespace.path,
|
||||
avatarUrl: v.owner.avatarUrl,
|
||||
name: v.path,
|
||||
description: v.description,
|
||||
starCount: v.stargazersCount,
|
||||
forkCount: v.forksCount,
|
||||
note: 'Updated ${timeago.format(v.updatedAt)}',
|
||||
url: '/gitea/${v.owner.login}/${v.path}',
|
||||
avatarLink: '/gitea/${v.owner.login}',
|
||||
url: '/gitea/${v.namespace.path}/${v.path}',
|
||||
avatarLink: '/gitea/${v.namespace.path}',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user