mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 08:04:51 +01:00
feat: gitea api
This commit is contained in:
parent
ee027bb0d2
commit
405cc03a30
@ -140,6 +140,13 @@ class AuthModel with ChangeNotifier {
|
||||
return info;
|
||||
}
|
||||
|
||||
Future fetchGitea(String p) async {
|
||||
final res = await http.get('https://try.gitea.io' + '/api/v1' + p,
|
||||
headers: {'Authorization': ''});
|
||||
final info = json.decode(utf8.decode(res.bodyBytes));
|
||||
return info;
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
// Listen scheme
|
||||
_sub = getUriLinksStream().listen(_onSchemeDetected, onError: (err) {
|
||||
|
31
lib/models/gitea.dart
Normal file
31
lib/models/gitea.dart
Normal file
@ -0,0 +1,31 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'gitea.g.dart';
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GiteaUser {
|
||||
int id;
|
||||
String login;
|
||||
String fullName;
|
||||
String avatarUrl;
|
||||
|
||||
GiteaUser();
|
||||
|
||||
factory GiteaUser.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteaUserFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class GiteaRepository {
|
||||
int id;
|
||||
GiteaUser owner;
|
||||
String name;
|
||||
String description;
|
||||
int starsCount;
|
||||
int forksCount;
|
||||
|
||||
GiteaRepository();
|
||||
|
||||
factory GiteaRepository.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteaRepositoryFromJson(json);
|
||||
}
|
44
lib/models/gitea.g.dart
Normal file
44
lib/models/gitea.g.dart
Normal file
@ -0,0 +1,44 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'gitea.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GiteaUser _$GiteaUserFromJson(Map<String, dynamic> json) {
|
||||
return GiteaUser()
|
||||
..id = json['id'] as int
|
||||
..login = json['login'] as String
|
||||
..fullName = json['full_name'] as String
|
||||
..avatarUrl = json['avatar_url'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteaUserToJson(GiteaUser instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'login': instance.login,
|
||||
'full_name': instance.fullName,
|
||||
'avatar_url': instance.avatarUrl,
|
||||
};
|
||||
|
||||
GiteaRepository _$GiteaRepositoryFromJson(Map<String, dynamic> json) {
|
||||
return GiteaRepository()
|
||||
..id = json['id'] as int
|
||||
..owner = json['owner'] == null
|
||||
? null
|
||||
: GiteaUser.fromJson(json['owner'] as Map<String, dynamic>)
|
||||
..name = json['name'] as String
|
||||
..description = json['description'] as String
|
||||
..starsCount = json['starsCount'] as int
|
||||
..forksCount = json['forksCount'] as int;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteaRepositoryToJson(GiteaRepository instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'owner': instance.owner,
|
||||
'name': instance.name,
|
||||
'description': instance.description,
|
||||
'starsCount': instance.starsCount,
|
||||
'forksCount': instance.forksCount,
|
||||
};
|
52
lib/screens/gitea/user.dart
Normal file
52
lib/screens/gitea/user.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/gitea.dart';
|
||||
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||
import 'package:git_touch/widgets/border_view.dart';
|
||||
import 'package:git_touch/widgets/repository_item.dart';
|
||||
import 'package:git_touch/widgets/user_item.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class GiteaUserScreen extends StatelessWidget {
|
||||
final String username;
|
||||
|
||||
GiteaUserScreen(this.username);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<
|
||||
Tuple2<GiteaUser, Iterable<GiteaRepository>>>(
|
||||
title: Text('User'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final items = await Future.wait([
|
||||
auth.fetchGitea('/users/$username'),
|
||||
auth.fetchGitea('/users/$username/repos'),
|
||||
]);
|
||||
return Tuple2(GiteaUser.fromJson(items[0]),
|
||||
(items[1] as List).map((v) => GiteaRepository.fromJson(v)));
|
||||
},
|
||||
bodyBuilder: (data, _) {
|
||||
final user = data.item1;
|
||||
final repos = data.item2;
|
||||
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
UserItem(
|
||||
login: user.login,
|
||||
avatarUrl: user.avatarUrl,
|
||||
name: user.fullName,
|
||||
),
|
||||
BorderView(height: 10),
|
||||
Column(
|
||||
children: repos.map((v) {
|
||||
return RepositoryItem.gitea(v);
|
||||
}).toList(),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/models/gitea.dart';
|
||||
import 'package:git_touch/models/gitlab.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/screens/repository.dart';
|
||||
@ -80,6 +81,19 @@ class RepositoryItem extends StatelessWidget {
|
||||
((_) => RepositoryScreen(payload.owner.username, payload.name)),
|
||||
this.topics = [];
|
||||
|
||||
RepositoryItem.gitea(GiteaRepository payload, {this.inRepoScreen = false})
|
||||
: this.owner = payload.owner.login,
|
||||
this.avatarUrl = payload.owner.avatarUrl,
|
||||
this.name = payload.name,
|
||||
this.description = payload.description,
|
||||
this.iconData = Octicons.repo,
|
||||
this.starCount = payload.starsCount,
|
||||
this.forkCount = payload.forksCount,
|
||||
this.primaryLanguageName = null,
|
||||
this.primaryLanguageColor = null,
|
||||
this.screenBuilder = ((_) => RepositoryScreen('', '')), // TODO:
|
||||
this.topics = [];
|
||||
|
||||
static IconData _buildIconData(payload) {
|
||||
if (payload['isPrivate']) {
|
||||
return Octicons.lock;
|
||||
|
Loading…
x
Reference in New Issue
Block a user