GitHostRepo: Add name and username

Instead of having to parse this from the fullName. This way the code is
easier to read and it's more reliable.
This commit is contained in:
Vishesh Handa
2020-11-13 15:36:24 +01:00
parent 819702bc6c
commit df78b24542
4 changed files with 36 additions and 13 deletions

View File

@ -28,6 +28,8 @@ class UserInfo {
} }
class GitHostRepo { class GitHostRepo {
final String name;
final String username;
final String fullName; final String fullName;
final String description; final String description;
@ -44,6 +46,8 @@ class GitHostRepo {
final List<String> tags; final List<String> tags;
GitHostRepo({ GitHostRepo({
@required this.name,
@required this.username,
@required this.fullName, @required this.fullName,
@required this.description, @required this.description,
@required this.cloneUrl, @required this.cloneUrl,
@ -58,6 +62,8 @@ class GitHostRepo {
}); });
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
'name': name,
'username': username,
'fullName': fullName, 'fullName': fullName,
'description': description, 'description': description,
'cloneUrl': cloneUrl, 'cloneUrl': cloneUrl,

View File

@ -226,6 +226,15 @@ class GitHub implements GitHost {
Log.e(e); Log.e(e);
} }
var licenseMap = parsedJson['license']; var licenseMap = parsedJson['license'];
var fullName = parsedJson['full_name'].toString();
var owner = parsedJson['owner'];
var username = "";
if (owner != null) {
username = (owner as Map)["login"];
} else {
username = fullName.split('/').first;
}
/* /*
print(""); print("");
@ -234,7 +243,9 @@ class GitHub implements GitHost {
*/ */
return GitHostRepo( return GitHostRepo(
fullName: parsedJson['full_name'], name: parsedJson['name'],
username: username,
fullName: fullName,
cloneUrl: parsedJson['ssh_url'], cloneUrl: parsedJson['ssh_url'],
updatedAt: updatedAt, updatedAt: updatedAt,
description: parsedJson['description'], description: parsedJson['description'],

View File

@ -217,8 +217,19 @@ class GitLab implements GitHost {
tags = tagList.map((e) => e.toString()).toList(); tags = tagList.map((e) => e.toString()).toList();
} }
var fullName = parsedJson['path_with_namespace'].toString();
var namespace = parsedJson['namespace'];
var username = "";
if (namespace != null) {
username = (namespace as Map)["path"];
} else {
username = fullName.split('/').first;
}
return GitHostRepo( return GitHostRepo(
fullName: parsedJson['path_with_namespace'], name: parsedJson["name"],
username: username,
fullName: fullName,
cloneUrl: parsedJson['ssh_url_to_repo'], cloneUrl: parsedJson['ssh_url_to_repo'],
updatedAt: updatedAt, updatedAt: updatedAt,
description: parsedJson['description'], description: parsedJson['description'],

View File

@ -123,19 +123,14 @@ class GitHostSetupRepoSelectorState extends State<GitHostSetupRepoSelector> {
} }
var q = _textController.text.toLowerCase(); var q = _textController.text.toLowerCase();
var filteredRepos = repos.where((r) { var filteredRepos =
var repoName = r.fullName.split('/').last; repos.where((r) => r.name.toLowerCase().contains(q)).toList();
return repoName.toLowerCase().contains(q);
}).toList();
var repoExists = filteredRepos.indexWhere((r) { var repoExists = filteredRepos.indexWhere((r) =>
var l = r.fullName.split('/'); r.name.toLowerCase() == q &&
var username = l.first; r.username == widget.userInfo.username) !=
var repoName = l.last;
return repoName.toLowerCase() == _textController.text &&
username == widget.userInfo.username;
}) !=
-1; -1;
var createRepoTile = _textController.text.isNotEmpty && !repoExists; var createRepoTile = _textController.text.isNotEmpty && !repoExists;
Widget repoBuilder = ListView( Widget repoBuilder = ListView(