2019-01-27 17:37:44 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import '../providers/settings.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
import '../utils/utils.dart';
|
2019-02-08 07:06:48 +01:00
|
|
|
import '../scaffolds/long_list.dart';
|
2019-02-03 07:42:50 +01:00
|
|
|
import '../widgets/timeline_item.dart';
|
|
|
|
import '../widgets/comment_item.dart';
|
2019-01-27 17:37:44 +01:00
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
class PullRequestScreen extends StatefulWidget {
|
2019-02-08 07:01:25 +01:00
|
|
|
final int number;
|
2019-02-07 07:35:19 +01:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
|
2019-02-08 07:01:25 +01:00
|
|
|
PullRequestScreen({
|
|
|
|
@required this.number,
|
|
|
|
@required this.owner,
|
|
|
|
@required this.name,
|
|
|
|
});
|
|
|
|
|
|
|
|
PullRequestScreen.fromFullName(
|
|
|
|
{@required this.number, @required String fullName})
|
|
|
|
: this.owner = fullName.split('/')[0],
|
|
|
|
this.name = fullName.split('/')[1];
|
2019-02-07 07:35:19 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
_PullRequestScreenState createState() => _PullRequestScreenState();
|
|
|
|
}
|
|
|
|
|
2019-02-08 07:01:25 +01:00
|
|
|
var commonChunk = '''
|
|
|
|
$graghqlChunk
|
|
|
|
... on ReviewRequestedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
requestedReviewer {
|
|
|
|
... on User {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on PullRequestReview {
|
|
|
|
createdAt
|
|
|
|
state
|
|
|
|
author {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on MergedEvent {
|
|
|
|
createdAt
|
|
|
|
mergeRefName
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
commit {
|
|
|
|
oid
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on HeadRefDeletedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
headRefName
|
|
|
|
}
|
|
|
|
''';
|
2019-02-07 07:35:19 +01:00
|
|
|
|
2019-02-08 07:01:25 +01:00
|
|
|
class _PullRequestScreenState extends State<PullRequestScreen> {
|
|
|
|
get owner => widget.owner;
|
|
|
|
get id => widget.number;
|
|
|
|
get name => widget.name;
|
2019-02-07 07:35:19 +01:00
|
|
|
|
2019-02-08 07:01:25 +01:00
|
|
|
Future queryPullRequest() async {
|
2019-02-07 07:35:19 +01:00
|
|
|
var data = await SettingsProvider.of(context).query('''
|
2019-01-27 17:37:44 +01:00
|
|
|
{
|
|
|
|
repository(owner: "$owner", name: "$name") {
|
|
|
|
pullRequest(number: $id) {
|
2019-01-28 14:32:01 +01:00
|
|
|
$graphqlChunk1
|
2019-01-27 17:37:44 +01:00
|
|
|
merged
|
|
|
|
additions
|
|
|
|
deletions
|
|
|
|
commits {
|
|
|
|
totalCount
|
|
|
|
}
|
2019-01-28 14:32:01 +01:00
|
|
|
timeline(first: $pageSize) {
|
2019-02-08 07:01:25 +01:00
|
|
|
totalCount
|
|
|
|
pageInfo {
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
nodes {
|
|
|
|
$commonChunk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
|
|
|
return data['repository']['pullRequest'];
|
|
|
|
}
|
|
|
|
|
|
|
|
Future queryMore(String cursor) async {
|
|
|
|
var data = await SettingsProvider.of(context).query('''
|
|
|
|
{
|
|
|
|
repository(owner: "$owner", name: "$name") {
|
|
|
|
pullRequest(number: $id) {
|
|
|
|
timeline(first: $pageSize, after: $cursor) {
|
|
|
|
totalCount
|
2019-01-27 17:37:44 +01:00
|
|
|
pageInfo {
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
nodes {
|
2019-02-08 07:01:25 +01:00
|
|
|
$commonChunk
|
2019-01-27 17:37:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
2019-02-07 07:35:19 +01:00
|
|
|
return data['repository']['pullRequest'];
|
|
|
|
}
|
2019-02-03 07:42:50 +01:00
|
|
|
|
2019-02-08 07:01:25 +01:00
|
|
|
Future<List> queryTrailing() async {
|
|
|
|
var data = await SettingsProvider.of(context).query('''
|
|
|
|
{
|
|
|
|
repository(owner: "$owner", name: "$name") {
|
|
|
|
pullRequest(number: $id) {
|
|
|
|
timeline(last: $pageSize) {
|
|
|
|
nodes {
|
|
|
|
$commonChunk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
|
|
|
return data['repository']['pullRequest']['timeline']['nodes'];
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildBadge(payload) {
|
2019-02-09 08:33:06 +01:00
|
|
|
Color bgColor;
|
|
|
|
IconData iconData;
|
|
|
|
String text;
|
|
|
|
|
|
|
|
if (payload['merged']) {
|
|
|
|
bgColor = Palette.purple;
|
|
|
|
iconData = Octicons.git_merge;
|
|
|
|
text = 'Merged';
|
|
|
|
} else if (payload['closed']) {
|
|
|
|
bgColor = Palette.red;
|
|
|
|
iconData = Octicons.git_pull_request;
|
|
|
|
text = 'Closed';
|
|
|
|
} else {
|
|
|
|
bgColor = Palette.green;
|
|
|
|
iconData = Octicons.git_pull_request;
|
|
|
|
text = 'Open';
|
|
|
|
}
|
|
|
|
|
2019-02-03 07:42:50 +01:00
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
2019-02-06 12:14:11 +01:00
|
|
|
color: bgColor,
|
2019-02-03 07:42:50 +01:00
|
|
|
borderRadius: BorderRadius.all(Radius.circular(4)),
|
|
|
|
),
|
|
|
|
padding: EdgeInsets.all(6),
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(iconData, color: Colors.white, size: 15),
|
2019-02-09 08:33:06 +01:00
|
|
|
Padding(padding: EdgeInsets.only(left: 2)),
|
2019-02-06 06:06:11 +01:00
|
|
|
Text(
|
|
|
|
text,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontWeight: FontWeight.w600,
|
2019-02-09 08:33:06 +01:00
|
|
|
fontSize: 14,
|
2019-02-06 06:06:11 +01:00
|
|
|
),
|
|
|
|
),
|
2019-02-03 07:42:50 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get _fullName => widget.owner + '/' + widget.name;
|
|
|
|
|
2019-01-27 17:37:44 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-02-08 07:01:25 +01:00
|
|
|
return LongListScaffold(
|
|
|
|
title: Text(_fullName + ' #' + widget.number.toString()),
|
|
|
|
headerBuilder: (payload) {
|
|
|
|
return Column(children: <Widget>[
|
|
|
|
Container(
|
2019-02-09 08:33:06 +01:00
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.black12)),
|
|
|
|
),
|
2019-02-08 07:01:25 +01:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2019-02-09 08:33:06 +01:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
payload['title'],
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(right: 8)),
|
|
|
|
_buildBadge(payload),
|
|
|
|
],
|
2019-02-08 07:01:25 +01:00
|
|
|
),
|
2019-02-09 08:33:06 +01:00
|
|
|
Padding(padding: EdgeInsets.only(bottom: 16)),
|
2019-02-08 07:01:25 +01:00
|
|
|
CommentItem(payload),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
itemBuilder: (itemPayload) => TimelineItem(itemPayload),
|
2019-02-03 07:42:50 +01:00
|
|
|
onRefresh: () async {
|
2019-02-08 07:01:25 +01:00
|
|
|
var res = await queryPullRequest();
|
|
|
|
int totalCount = res['timeline']['totalCount'];
|
|
|
|
String cursor = res['timeline']['pageInfo']['endCursor'];
|
|
|
|
List leadingItems = res['timeline']['nodes'];
|
|
|
|
|
|
|
|
var payload = LongListPayload(
|
|
|
|
header: res,
|
|
|
|
totalCount: totalCount,
|
|
|
|
cursor: cursor,
|
|
|
|
leadingItems: leadingItems,
|
|
|
|
trailingItems: [],
|
|
|
|
);
|
|
|
|
|
|
|
|
if (totalCount > 2 * pageSize) {
|
|
|
|
payload.trailingItems = await queryTrailing();
|
2019-02-06 14:35:52 +01:00
|
|
|
}
|
2019-02-08 07:01:25 +01:00
|
|
|
|
|
|
|
return payload;
|
|
|
|
},
|
|
|
|
onLoadMore: (String _cursor) async {
|
|
|
|
var res = await queryMore(_cursor);
|
|
|
|
int totalCount = res['timeline']['totalCount'];
|
|
|
|
String cursor = res['timeline']['pageInfo']['endCursor'];
|
|
|
|
List leadingItems = res['timeline']['nodes'];
|
|
|
|
|
|
|
|
var payload = LongListPayload(
|
|
|
|
totalCount: totalCount,
|
|
|
|
cursor: cursor,
|
|
|
|
leadingItems: leadingItems,
|
|
|
|
);
|
|
|
|
|
|
|
|
return payload;
|
2019-02-03 07:42:50 +01:00
|
|
|
},
|
2019-01-27 17:37:44 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|