2019-09-23 13:45:47 +02:00
|
|
|
import 'dart:convert';
|
2019-09-12 15:19:17 +02:00
|
|
|
import 'package:filesize/filesize.dart';
|
2019-01-27 17:37:44 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:git_touch/models/settings.dart';
|
2019-09-25 11:06:36 +02:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
2019-09-09 16:50:22 +02:00
|
|
|
import 'package:git_touch/screens/users.dart';
|
2019-09-08 16:17:29 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2019-09-11 13:59:47 +02:00
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
2019-09-13 10:27:33 +02:00
|
|
|
import 'package:git_touch/widgets/markdown_view.dart';
|
2019-09-08 16:17:29 +02:00
|
|
|
import 'package:git_touch/widgets/table_view.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-08-30 10:26:56 +02:00
|
|
|
import 'package:git_touch/screens/commits.dart';
|
2019-08-30 08:08:09 +02:00
|
|
|
import 'package:git_touch/screens/object.dart';
|
2019-02-10 11:50:40 +01:00
|
|
|
import 'package:share/share.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2019-09-23 12:28:33 +02:00
|
|
|
import 'package:git_touch/widgets/repository_item.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import '../widgets/entry_item.dart';
|
|
|
|
import '../screens/issues.dart';
|
2019-03-10 14:53:35 +01:00
|
|
|
import '../screens/user.dart';
|
2019-03-10 16:34:34 +01:00
|
|
|
import '../screens/organization.dart';
|
2019-02-20 09:31:22 +01:00
|
|
|
import '../widgets/action.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
|
2019-09-23 12:28:33 +02:00
|
|
|
class RepositoryScreen extends StatelessWidget {
|
2019-02-07 07:35:19 +01:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
2019-09-23 11:08:51 +02:00
|
|
|
final String branch;
|
2019-02-07 07:35:19 +01:00
|
|
|
|
2019-09-08 16:17:29 +02:00
|
|
|
static const _languageBarPadding = 10.0;
|
|
|
|
|
2019-09-23 12:28:33 +02:00
|
|
|
RepositoryScreen(this.owner, this.name, {this.branch});
|
|
|
|
RepositoryScreen.fromFullName(String fullName, {this.branch})
|
2019-09-08 14:33:04 +02:00
|
|
|
: owner = fullName.split('/')[0],
|
|
|
|
name = fullName.split('/')[1];
|
2019-02-10 11:50:40 +01:00
|
|
|
|
2019-09-23 14:04:53 +02:00
|
|
|
get branchInfoKey => getBranchQueryKey(branch);
|
2019-09-23 11:08:51 +02:00
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
Future queryRepo(BuildContext context) async {
|
2019-09-23 14:04:53 +02:00
|
|
|
var branchKey = getBranchQueryKey(branch, withParams: true);
|
2019-09-08 14:07:35 +02:00
|
|
|
var data = await Provider.of<SettingsModel>(context).query('''
|
2019-02-04 14:38:29 +01:00
|
|
|
{
|
|
|
|
repository(owner: "$owner", name: "$name") {
|
2019-02-10 11:50:40 +01:00
|
|
|
id
|
2019-02-04 14:38:29 +01:00
|
|
|
owner {
|
2019-03-10 14:53:35 +01:00
|
|
|
__typename
|
2019-02-04 14:38:29 +01:00
|
|
|
login
|
2019-09-08 15:20:12 +02:00
|
|
|
avatarUrl
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
name
|
|
|
|
isPrivate
|
|
|
|
isFork
|
|
|
|
description
|
2019-09-22 05:34:25 +02:00
|
|
|
diskUsage
|
2019-09-23 10:01:55 +02:00
|
|
|
hasIssuesEnabled
|
2019-09-23 11:08:51 +02:00
|
|
|
url
|
|
|
|
viewerHasStarred
|
|
|
|
viewerSubscription
|
2019-09-09 16:50:22 +02:00
|
|
|
watchers {
|
|
|
|
totalCount
|
|
|
|
}
|
2019-02-04 14:38:29 +01:00
|
|
|
stargazers {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
forks {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
primaryLanguage {
|
|
|
|
color
|
|
|
|
name
|
2019-09-08 16:17:29 +02:00
|
|
|
}
|
2019-02-04 14:38:29 +01:00
|
|
|
issues(states: OPEN) {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
pullRequests(states: OPEN) {
|
|
|
|
totalCount
|
|
|
|
}
|
2019-09-23 18:34:51 +02:00
|
|
|
releases {
|
|
|
|
totalCount
|
|
|
|
}
|
2019-09-08 16:17:29 +02:00
|
|
|
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
|
|
|
|
totalSize
|
|
|
|
edges {
|
|
|
|
size
|
|
|
|
node {
|
|
|
|
name
|
|
|
|
color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-23 14:04:53 +02:00
|
|
|
$branchKey {
|
2019-02-10 07:26:51 +01:00
|
|
|
name
|
2019-08-30 10:26:56 +02:00
|
|
|
target {
|
|
|
|
... on Commit {
|
|
|
|
history {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-10 07:26:51 +01:00
|
|
|
}
|
2019-09-23 11:08:51 +02:00
|
|
|
refs(first: 10, refPrefix: "refs/heads/") {
|
|
|
|
totalCount
|
|
|
|
nodes {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2019-09-12 15:19:17 +02:00
|
|
|
licenseInfo {
|
|
|
|
name
|
2019-09-13 08:54:18 +02:00
|
|
|
spdxId
|
2019-09-12 15:19:17 +02:00
|
|
|
}
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
2019-02-07 07:35:19 +01:00
|
|
|
return data['repository'];
|
|
|
|
}
|
2019-02-06 15:28:04 +01:00
|
|
|
|
2019-09-23 13:45:47 +02:00
|
|
|
Future<String> fetchReadme(BuildContext context) async {
|
|
|
|
var data = await Provider.of<SettingsModel>(context)
|
|
|
|
.getWithCredentials('/repos/$owner/$name/readme');
|
|
|
|
|
|
|
|
if (data['content'] == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var bits = base64.decode((data['content'] as String).replaceAll('\n', ''));
|
|
|
|
var str = utf8.decode(bits);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2019-01-25 13:35:20 +01:00
|
|
|
@override
|
2019-01-27 17:37:44 +01:00
|
|
|
Widget build(BuildContext context) {
|
2019-09-25 11:06:36 +02:00
|
|
|
return RefreshStatefulScaffold(
|
2019-09-11 13:59:47 +02:00
|
|
|
title: AppBarTitle('Repository'),
|
2019-09-24 13:58:34 +02:00
|
|
|
onRefresh: () => Future.wait([
|
2019-09-23 14:04:53 +02:00
|
|
|
queryRepo(context),
|
|
|
|
fetchReadme(context),
|
|
|
|
]),
|
2019-09-23 13:45:47 +02:00
|
|
|
trailingBuilder: (data) {
|
2019-09-25 15:41:44 +02:00
|
|
|
return ActionButton(
|
|
|
|
title: 'Repository Actions',
|
|
|
|
actions: [
|
|
|
|
MyAction(
|
|
|
|
text: '@$owner',
|
|
|
|
onPress: () {
|
|
|
|
if (data == null) return;
|
|
|
|
WidgetBuilder builder;
|
2019-03-10 14:53:35 +01:00
|
|
|
|
2019-09-25 15:41:44 +02:00
|
|
|
switch (data[0]['owner']['__typename']) {
|
|
|
|
case 'Organization':
|
|
|
|
builder = (_) => OrganizationScreen(owner);
|
|
|
|
break;
|
|
|
|
case 'User':
|
|
|
|
builder = (_) => UserScreen(owner);
|
|
|
|
break;
|
|
|
|
}
|
2019-03-10 14:53:35 +01:00
|
|
|
|
2019-09-25 15:41:44 +02:00
|
|
|
Provider.of<ThemeModel>(context).pushRoute(context, builder);
|
|
|
|
},
|
|
|
|
),
|
2019-09-25 16:01:00 +02:00
|
|
|
if (data != null) ...[
|
2019-09-25 15:41:44 +02:00
|
|
|
MyAction(
|
|
|
|
text: data[0]['viewerHasStarred'] ? 'Unstar' : 'Star',
|
|
|
|
onPress: () async {
|
|
|
|
if (data[0]['viewerHasStarred']) {
|
|
|
|
await Provider.of<SettingsModel>(context)
|
|
|
|
.deleteWithCredentials('/user/starred/$owner/$name');
|
|
|
|
data[0]['viewerHasStarred'] = false;
|
|
|
|
} else {
|
|
|
|
Provider.of<SettingsModel>(context)
|
|
|
|
.putWithCredentials('/user/starred/$owner/$name');
|
|
|
|
data[0]['viewerHasStarred'] = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2019-09-25 16:01:00 +02:00
|
|
|
MyAction(
|
|
|
|
text: data[0]['viewerSubscription'] == 'SUBSCRIBED'
|
|
|
|
? 'Unwatch'
|
|
|
|
: 'Watch',
|
|
|
|
onPress: () async {
|
|
|
|
if (data[0]['viewerSubscription'] == 'SUBSCRIBED') {
|
|
|
|
await Provider.of<SettingsModel>(context)
|
|
|
|
.deleteWithCredentials(
|
|
|
|
'/repos/$owner/$name/subscription');
|
|
|
|
data[0]['viewerSubscription'] = 'UNSUBSCRIBED';
|
|
|
|
} else {
|
|
|
|
Provider.of<SettingsModel>(context)
|
|
|
|
.putWithCredentials('/repos/$owner/$name/subscription');
|
|
|
|
data[0]['viewerSubscription'] = 'SUBSCRIBED';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2019-09-25 15:41:44 +02:00
|
|
|
MyAction(
|
|
|
|
text: 'Share',
|
|
|
|
onPress: () {
|
|
|
|
if (data != null) {
|
|
|
|
Share.share(data[0]['url']);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
MyAction(
|
|
|
|
text: 'Open in Browser',
|
|
|
|
onPress: () {
|
|
|
|
if (data != null) {
|
|
|
|
launch(data[0]['url']);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2019-02-10 11:50:40 +01:00
|
|
|
},
|
2019-09-23 13:45:47 +02:00
|
|
|
bodyBuilder: (data) {
|
|
|
|
var payload = data[0];
|
|
|
|
var readme = data[1] as String;
|
|
|
|
|
2019-09-14 18:34:10 +02:00
|
|
|
final langWidth = MediaQuery.of(context).size.width -
|
|
|
|
_languageBarPadding * 2 -
|
|
|
|
(payload['languages']['edges'] as List).length +
|
|
|
|
1;
|
2019-09-08 16:17:29 +02:00
|
|
|
|
2019-02-04 14:38:29 +01:00
|
|
|
return Column(
|
2019-09-08 16:17:29 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
2019-02-04 14:38:29 +01:00
|
|
|
children: <Widget>[
|
2019-09-23 12:28:33 +02:00
|
|
|
RepositoryItem(payload, inRepoScreen: true),
|
2019-09-14 17:48:01 +02:00
|
|
|
borderView,
|
2019-09-08 16:17:29 +02:00
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
EntryItem(
|
2019-09-09 16:50:22 +02:00
|
|
|
count: payload['watchers']['totalCount'],
|
|
|
|
text: 'Watchers',
|
2019-09-23 15:25:18 +02:00
|
|
|
screenBuilder: (context) => UsersScreen.watchers(owner, name),
|
2019-09-08 16:17:29 +02:00
|
|
|
),
|
|
|
|
EntryItem(
|
2019-09-09 16:50:22 +02:00
|
|
|
count: payload['stargazers']['totalCount'],
|
|
|
|
text: 'Stars',
|
2019-09-23 15:25:18 +02:00
|
|
|
screenBuilder: (context) => UsersScreen.stars(owner, name),
|
2019-09-08 16:17:29 +02:00
|
|
|
),
|
|
|
|
EntryItem(
|
2019-09-09 16:50:22 +02:00
|
|
|
count: payload['forks']['totalCount'],
|
|
|
|
text: 'Forks',
|
2019-09-13 10:55:27 +02:00
|
|
|
// screenBuilder: (context) => UsersScreen(),
|
2019-09-08 16:17:29 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2019-09-14 20:05:34 +02:00
|
|
|
borderView1,
|
2019-09-23 10:10:46 +02:00
|
|
|
if ((payload['languages']['edges'] as List).isNotEmpty)
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.all(_languageBarPadding),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(2),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 10,
|
|
|
|
child: Row(
|
|
|
|
children: join(
|
|
|
|
SizedBox(width: 1),
|
|
|
|
(payload['languages']['edges'] as List)
|
|
|
|
.map((lang) => Container(
|
|
|
|
color: convertColor(lang['node']['color']),
|
|
|
|
width: langWidth *
|
|
|
|
lang['size'] /
|
|
|
|
payload['languages']['totalSize']))
|
|
|
|
.toList())),
|
|
|
|
),
|
2019-02-04 14:38:29 +01:00
|
|
|
),
|
|
|
|
),
|
2019-09-15 09:08:09 +02:00
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
2019-09-23 11:08:51 +02:00
|
|
|
if (payload[branchInfoKey] != null)
|
2019-09-23 10:08:53 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.code,
|
|
|
|
text: Text('Code'),
|
|
|
|
rightWidget:
|
|
|
|
Text(filesize((payload['diskUsage'] as int) * 1000)),
|
|
|
|
screenBuilder: (_) => ObjectScreen(
|
2019-09-23 14:04:53 +02:00
|
|
|
owner: owner,
|
|
|
|
name: name,
|
|
|
|
branch: payload[branchInfoKey]['name'],
|
|
|
|
),
|
2019-09-15 09:08:09 +02:00
|
|
|
),
|
2019-09-23 10:01:55 +02:00
|
|
|
if (payload['hasIssuesEnabled'] as bool)
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.issue_opened,
|
|
|
|
text: Text('Issues'),
|
|
|
|
rightWidget: Text(
|
|
|
|
numberFormat.format(payload['issues']['totalCount'])),
|
|
|
|
screenBuilder: (_) =>
|
|
|
|
IssuesScreen(owner: owner, name: name),
|
|
|
|
),
|
2019-09-15 09:08:09 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.git_pull_request,
|
|
|
|
text: Text('Pull requests'),
|
|
|
|
rightWidget: Text(numberFormat
|
|
|
|
.format(payload['pullRequests']['totalCount'])),
|
|
|
|
screenBuilder: (_) => IssuesScreen(
|
|
|
|
owner: owner, name: name, isPullRequest: true),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2019-09-14 20:05:34 +02:00
|
|
|
borderView1,
|
2019-09-15 09:08:09 +02:00
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
2019-09-23 13:51:49 +02:00
|
|
|
if (payload[branchInfoKey] != null) ...[
|
2019-09-23 10:08:53 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.history,
|
|
|
|
text: Text('Commits'),
|
2019-09-23 11:08:51 +02:00
|
|
|
rightWidget: Text(numberFormat.format(payload[branchInfoKey]
|
|
|
|
['target']['history']['totalCount'])),
|
|
|
|
screenBuilder: (_) =>
|
|
|
|
CommitsScreen(owner, name, branch: branch),
|
|
|
|
),
|
2019-09-23 13:51:49 +02:00
|
|
|
if (payload['refs'] != null)
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.git_branch,
|
|
|
|
text: Text('Branches'),
|
|
|
|
rightWidget: Text(payload[branchInfoKey]['name'] +
|
|
|
|
' • ' +
|
|
|
|
numberFormat.format(payload['refs']['totalCount'])),
|
|
|
|
onTap: () async {
|
2019-09-25 14:55:06 +02:00
|
|
|
var refs = payload['refs']['nodes'] as List;
|
|
|
|
if (refs.length < 2) return;
|
|
|
|
|
2019-09-23 13:51:49 +02:00
|
|
|
// FIXME: Show all branches
|
|
|
|
var result = await Provider.of<ThemeModel>(context)
|
|
|
|
.showDialogOptions(
|
|
|
|
context,
|
2019-09-25 14:55:06 +02:00
|
|
|
refs
|
2019-09-23 13:51:49 +02:00
|
|
|
.map((b) => DialogOption(
|
|
|
|
value: b['name'] as String,
|
|
|
|
widget: Text(b['name'] as String)))
|
|
|
|
.toList());
|
2019-09-23 12:13:21 +02:00
|
|
|
|
2019-09-23 13:51:49 +02:00
|
|
|
if (result != null) {
|
|
|
|
Provider.of<ThemeModel>(context).pushReplacementRoute(
|
|
|
|
context,
|
|
|
|
(_) => RepositoryScreen(owner, name,
|
|
|
|
branch: result));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2019-09-23 18:34:51 +02:00
|
|
|
if ((payload['releases']['totalCount'] as int) > 0)
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.tag,
|
|
|
|
text: Text('Releases'),
|
|
|
|
rightWidget: Text(
|
|
|
|
(payload['releases']['totalCount'] as int).toString()),
|
|
|
|
url: payload['url'] + '/releases',
|
|
|
|
),
|
2019-09-15 09:08:09 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.law,
|
|
|
|
text: Text('License'),
|
|
|
|
rightWidget: Text(payload['licenseInfo'] == null
|
|
|
|
? 'Unknown'
|
|
|
|
: (payload['licenseInfo']['spdxId'] ??
|
|
|
|
payload['licenseInfo']['name'])),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2019-09-14 20:05:34 +02:00
|
|
|
borderView1,
|
2019-09-23 13:45:47 +02:00
|
|
|
if (readme != null)
|
2019-09-12 14:52:07 +02:00
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.all(16),
|
2019-09-23 13:45:47 +02:00
|
|
|
child: MarkdownView(readme),
|
2019-09-12 14:52:07 +02:00
|
|
|
),
|
2019-02-04 14:38:29 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2019-01-25 13:35:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|