Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<a href="https://github.com/">GitHub</a>,
<a href="https://gitlab.com/">GitLab</a>,
<a href="https://bitbucket.org/">Bitbucket</a>,
<a href="https://gitea.com/">Gitea</a> and
<a href="https://gitee.com/">Gitee(码云)</a>, built with Flutter
<a href="https://gitea.com/">Gitea</a>,
<a href="https://gitee.com/">Gitee(码云)</a> and
<a href="https://rhodecode.com/">Rhodecode</a>, built with Flutter
</p>
<p align="center">
<a href="https://apps.apple.com/us/app/gittouch/id1452042346"><img src="https://tools.applemediaservices.com/api/badges/download-on-the-app-store/black/en-US" alt="Download on the App Store" height="48"></a>
Expand Down Expand Up @@ -44,6 +45,7 @@ https://github.com/git-touch/git-touch/issues/29
| Gogs | https://try.gogs.io/ | [Gogs API](https://github.com/gogs/docs-api) | 🚧 | ✅ |
| Gitea | https://gitea.com/ | [Gitea API](https://try.gitea.io/api/swagger#/) | ✅ | ✅ |
| Gitee | https://gitee.com/ | [Gitee API](https://gitee.com/api/v5/swagger) | ✅ | 💬 |
| Rhodecode | https://rhodecode.com | [Rhodecode API](https://docs.rhodecode.com/5.x/rce/api/api.html) | 🚧 | ✅ |

## Contributing

Expand Down
13 changes: 13 additions & 0 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:git_touch/screens/go_user.dart';
import 'package:git_touch/screens/gt_orgs.dart';
import 'package:git_touch/screens/gt_user.dart';
import 'package:git_touch/screens/login.dart';
import 'package:git_touch/screens/rh_explore.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:github/github.dart';
import 'package:launch_review/launch_review.dart';
Expand All @@ -32,6 +33,8 @@ import 'package:provider/provider.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:universal_io/io.dart';

import 'screens/rh_user.dart';

class Home extends StatefulWidget {
@override
State<Home> createState() => _HomeState();
Expand Down Expand Up @@ -140,6 +143,14 @@ class _HomeState extends State<Home> {
case 1:
return GoUserScreen(auth.activeAccount!.login, isViewer: true);
}
break;
case PlatformType.rhodecode:
switch (index) {
case 0:
return RhExploreScreen();
case 1:
return RhUserScreen(null);
}
}
}

Expand Down Expand Up @@ -232,6 +243,8 @@ class _HomeState extends State<Home> {
case PlatformType.gitee:
case PlatformType.gogs:
return [search, me];
case PlatformType.rhodecode:
return [explore, me];
default:
return [];
}
Expand Down
69 changes: 68 additions & 1 deletion lib/models/auth.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:ferry/ferry.dart';
import 'package:fimber/fimber.dart';
Expand All @@ -11,14 +12,14 @@ import 'package:git_touch/models/gitea.dart';
import 'package:git_touch/models/gitee.dart';
import 'package:git_touch/models/gitlab.dart';
import 'package:git_touch/models/gogs.dart';
import 'package:git_touch/models/rhodecode.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:github/github.dart';
import 'package:gql_http_link/gql_http_link.dart';
import 'package:http/http.dart' as http;
import 'package:nanoid/nanoid.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:uni_links/uni_links.dart';
// import 'package:in_app_review/in_app_review.dart';
import 'package:universal_io/io.dart';
import 'package:url_launcher/url_launcher.dart';

Expand All @@ -31,6 +32,7 @@ class PlatformType {
static const gitea = 'gitea';
static const gitee = 'gitee';
static const gogs = 'gogs';
static const rhodecode = 'rhodecode';
}

class DataWithPage<T> {
Expand Down Expand Up @@ -334,6 +336,71 @@ class AuthModel with ChangeNotifier {
}
}

Future loginToRhodecode(String domain, String token) async {
domain = domain.trim();
token = token.trim();
final bodys =
'{"id":1,"auth_token":"$token","method":"get_user", "args":"{}"}';
try {
loading = true;
notifyListeners();
final res = await http.post(Uri.parse('$domain/_admin/api'),
headers: {'content-type': 'text/plain'}, body: bodys);
final info = json.decode(res.body);
if (info['error'] != null) {
throw info['error'];
}
final userResponse = GetUserResponse.fromJson(info);

await _addAccount(Account(
platform: PlatformType.rhodecode,
domain: domain,
token: token,
login: userResponse.result!.username!,
avatarUrl: 'TODO', // user.avatarUrl!,
));
} finally {
loading = false;
notifyListeners();
}
}

// TODO there is no real pagination
Future<DataWithPage> fetchRhodecodeWithPage(
String p, {
requestType = 'POST',
Map<String, dynamic> body = const {},
}) async {
final info = await fetchRhodecode(p, requestType: requestType, body: body);
var next = null;
return DataWithPage(
data: info,
cursor: next ?? 1,
hasMore: next != null,
total: info['result'].length ?? kTotalCountFallback,
);
}

Future fetchRhodecode(
String p, {
requestType = 'POST',
Map<String, dynamic> body = const {},
}) async {
late http.Response res;
final encoded = json.encode(body);
final fullBody =
'{"id":1,"auth_token":"${activeAccount!.token}","method":"$p", "args":$encoded}';
res = await http.post(Uri.parse('${activeAccount!.domain}/_admin/api'),
headers: {'content-type': 'text/plain'}, body: fullBody);
final info = json.decode(res.body);
if (info['error'] != null) {
// throw Exception(info['error']);
throw Error();
}

return info;
}

// TODO: refactor
Future fetchGogs(
String p, {
Expand Down
Loading