mirror of
https://github.com/git-touch/git-touch
synced 2025-02-20 13:30:38 +01:00
feat(gitea): commits screen
This commit is contained in:
parent
084aec4453
commit
7d1065eaae
@ -208,6 +208,18 @@ class AuthModel with ChangeNotifier {
|
||||
return info;
|
||||
}
|
||||
|
||||
Future<DataWithPage> fetchGiteaWithPage(String p) async {
|
||||
final res = await http.get('${activeAccount.domain}/api/v1$p',
|
||||
headers: {'Authorization': 'token $token'});
|
||||
final info = json.decode(utf8.decode(res.bodyBytes));
|
||||
return DataWithPage(
|
||||
data: info,
|
||||
cursor: int.tryParse(res.headers["x-page"]) + 1,
|
||||
hasMore: res.headers['x-hasmore'] != null,
|
||||
total: int.tryParse(res.headers['x-total'] ?? ''),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
// Listen scheme
|
||||
_sub = getUriLinksStream().listen(_onSchemeDetected, onError: (err) {
|
||||
|
@ -51,3 +51,37 @@ class GiteaBlob extends GiteaTree {
|
||||
factory GiteaBlob.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteaBlobFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GiteaCommit {
|
||||
int number;
|
||||
GiteaUser author;
|
||||
String title;
|
||||
String body;
|
||||
GiteaCommitDetail commit;
|
||||
String sha;
|
||||
String htmlUrl;
|
||||
GiteaCommit();
|
||||
factory GiteaCommit.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteaCommitFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GiteaCommitDetail {
|
||||
String message;
|
||||
GiteaCommitAuthor author;
|
||||
GiteaCommitAuthor committer;
|
||||
GiteaCommitDetail();
|
||||
factory GiteaCommitDetail.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteaCommitDetailFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GiteaCommitAuthor {
|
||||
String name;
|
||||
String email;
|
||||
DateTime date;
|
||||
GiteaCommitAuthor();
|
||||
factory GiteaCommitAuthor.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteaCommitAuthorFromJson(json);
|
||||
}
|
||||
|
@ -94,3 +94,62 @@ Map<String, dynamic> _$GiteaBlobToJson(GiteaBlob instance) => <String, dynamic>{
|
||||
'download_url': instance.downloadUrl,
|
||||
'content': instance.content,
|
||||
};
|
||||
|
||||
GiteaCommit _$GiteaCommitFromJson(Map<String, dynamic> json) {
|
||||
return GiteaCommit()
|
||||
..number = json['number'] as int
|
||||
..author = json['author'] == null
|
||||
? null
|
||||
: GiteaUser.fromJson(json['author'] as Map<String, dynamic>)
|
||||
..title = json['title'] as String
|
||||
..body = json['body'] as String
|
||||
..commit = json['commit'] == null
|
||||
? null
|
||||
: GiteaCommitDetail.fromJson(json['commit'] as Map<String, dynamic>)
|
||||
..sha = json['sha'] as String
|
||||
..htmlUrl = json['html_url'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteaCommitToJson(GiteaCommit instance) =>
|
||||
<String, dynamic>{
|
||||
'number': instance.number,
|
||||
'author': instance.author,
|
||||
'title': instance.title,
|
||||
'body': instance.body,
|
||||
'commit': instance.commit,
|
||||
'sha': instance.sha,
|
||||
'html_url': instance.htmlUrl,
|
||||
};
|
||||
|
||||
GiteaCommitDetail _$GiteaCommitDetailFromJson(Map<String, dynamic> json) {
|
||||
return GiteaCommitDetail()
|
||||
..message = json['message'] as String
|
||||
..author = json['author'] == null
|
||||
? null
|
||||
: GiteaCommitAuthor.fromJson(json['author'] as Map<String, dynamic>)
|
||||
..committer = json['committer'] == null
|
||||
? null
|
||||
: GiteaCommitAuthor.fromJson(json['committer'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteaCommitDetailToJson(GiteaCommitDetail instance) =>
|
||||
<String, dynamic>{
|
||||
'message': instance.message,
|
||||
'author': instance.author,
|
||||
'committer': instance.committer,
|
||||
};
|
||||
|
||||
GiteaCommitAuthor _$GiteaCommitAuthorFromJson(Map<String, dynamic> json) {
|
||||
return GiteaCommitAuthor()
|
||||
..name = json['name'] as String
|
||||
..email = json['email'] as String
|
||||
..date =
|
||||
json['date'] == null ? null : DateTime.parse(json['date'] as String);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteaCommitAuthorToJson(GiteaCommitAuthor instance) =>
|
||||
<String, dynamic>{
|
||||
'name': instance.name,
|
||||
'email': instance.email,
|
||||
'date': instance.date?.toIso8601String(),
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:fluro/fluro.dart';
|
||||
import 'package:git_touch/screens/code_theme.dart';
|
||||
import 'package:git_touch/screens/commits.dart';
|
||||
import 'package:git_touch/screens/gitea_commits.dart';
|
||||
import 'package:git_touch/screens/gitea_object.dart';
|
||||
import 'package:git_touch/screens/gitea_repo.dart';
|
||||
import 'package:git_touch/screens/gitea_user.dart';
|
||||
@ -194,7 +195,8 @@ class GiteaRouter {
|
||||
static final routes = [
|
||||
GiteaRouter.user,
|
||||
GiteaRouter.repo,
|
||||
GiteaRouter.object
|
||||
GiteaRouter.object,
|
||||
GiteaRouter.commits,
|
||||
];
|
||||
static final user = RouterScreen(
|
||||
'/:login',
|
||||
@ -206,11 +208,13 @@ class GiteaRouter {
|
||||
GiteaRepoScreen(params['owner'].first, params['name'].first),
|
||||
);
|
||||
static final object = RouterScreen(
|
||||
'/gitea/:owner/:name/blob',
|
||||
'/:owner/:name/blob',
|
||||
(context, params) => GiteaObjectScreen(
|
||||
params['owner'].first,
|
||||
params['name'].first,
|
||||
path: params['path']?.first,
|
||||
),
|
||||
);
|
||||
static final commits = RouterScreen('/:owner/:name/commits',
|
||||
(_, p) => GiteaCommitsScreen(p['owner'].first, p['name'].first));
|
||||
}
|
||||
|
44
lib/screens/gitea_commits.dart
Normal file
44
lib/screens/gitea_commits.dart
Normal file
@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/gitea.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 GiteaCommitsScreen extends StatelessWidget {
|
||||
final String owner;
|
||||
final String name;
|
||||
// final String branch; // TODO:
|
||||
GiteaCommitsScreen(this.owner, this.name);
|
||||
|
||||
Future<ListPayload<GiteaCommit, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth
|
||||
.fetchGiteaWithPage('/repos/$owner/$name/commits?page=$page&limit=20');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
items: (res.data as List).map((v) => GiteaCommit.fromJson(v)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListStatefulScaffold<GiteaCommit, int>(
|
||||
title: AppBarTitle('Commits'),
|
||||
onRefresh: () => _query(context),
|
||||
onLoadMore: (cursor) => _query(context, cursor),
|
||||
itemBuilder: (c) {
|
||||
return CommitItem(
|
||||
author: c.author?.login ?? c.commit.author.name,
|
||||
avatarUrl: null,
|
||||
createdAt: c.commit.author.date,
|
||||
message: c.commit.message,
|
||||
url: c.htmlUrl,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user