fix: commit status

This commit is contained in:
Rongjian Zhang 2020-01-03 14:47:07 +08:00
parent ac27c704d2
commit bd9703e443
5 changed files with 142 additions and 17 deletions

View File

@ -123,6 +123,8 @@ class GithubCommitsCommit extends GithubCommitsPullRequestTimelineItem
GithubCommitsGitActor author;
GithubCommitsStatus status;
GithubCommitsCommitHistoryConnection history;
@override
@ -130,8 +132,16 @@ class GithubCommitsCommit extends GithubCommitsPullRequestTimelineItem
String resolveType;
@override
List<Object> get props =>
[oid, url, messageHeadline, committedDate, author, history, resolveType];
List<Object> get props => [
oid,
url,
messageHeadline,
committedDate,
author,
status,
history,
resolveType
];
Map<String, dynamic> toJson() => _$GithubCommitsCommitToJson(this);
}
@ -342,6 +352,24 @@ class GithubCommitsSponsorable with EquatableMixin {
Map<String, dynamic> toJson() => _$GithubCommitsSponsorableToJson(this);
}
@JsonSerializable(explicitToJson: true)
class GithubCommitsStatus with EquatableMixin implements GithubCommitsNode {
GithubCommitsStatus();
factory GithubCommitsStatus.fromJson(Map<String, dynamic> json) =>
_$GithubCommitsStatusFromJson(json);
GithubCommitsStatusState state;
@override
@JsonKey(name: '__typename')
String resolveType;
@override
List<Object> get props => [state, resolveType];
Map<String, dynamic> toJson() => _$GithubCommitsStatusToJson(this);
}
@JsonSerializable(explicitToJson: true)
class GithubCommitsCommitHistoryConnection with EquatableMixin {
GithubCommitsCommitHistoryConnection();
@ -447,6 +475,14 @@ class GithubCommitsRepositoryInfo with EquatableMixin {
Map<String, dynamic> toJson() => _$GithubCommitsRepositoryInfoToJson(this);
}
enum GithubCommitsStatusState {
EXPECTED,
ERROR,
FAILURE,
PENDING,
SUCCESS,
}
@JsonSerializable(explicitToJson: true)
class GithubCommitsArguments extends JsonSerializable with EquatableMixin {
GithubCommitsArguments(
@ -556,6 +592,19 @@ class GithubCommitsQuery
selectionSet: null)
]))
])),
FieldNode(
name: NameNode(value: 'status'),
alias: null,
arguments: [],
directives: [],
selectionSet: SelectionSetNode(selections: [
FieldNode(
name: NameNode(value: 'state'),
alias: null,
arguments: [],
directives: [],
selectionSet: null)
])),
FieldNode(
name: NameNode(value: 'history'),
alias: null,
@ -653,6 +702,20 @@ class GithubCommitsQuery
directives: [],
selectionSet: null)
]))
])),
FieldNode(
name: NameNode(value: 'status'),
alias: null,
arguments: [],
directives: [],
selectionSet:
SelectionSetNode(selections: [
FieldNode(
name: NameNode(value: 'state'),
alias: null,
arguments: [],
directives: [],
selectionSet: null)
]))
]))
]))

View File

@ -77,6 +77,9 @@ GithubCommitsCommit _$GithubCommitsCommitFromJson(Map<String, dynamic> json) {
..author = json['author'] == null
? null
: GithubCommitsGitActor.fromJson(json['author'] as Map<String, dynamic>)
..status = json['status'] == null
? null
: GithubCommitsStatus.fromJson(json['status'] as Map<String, dynamic>)
..history = json['history'] == null
? null
: GithubCommitsCommitHistoryConnection.fromJson(
@ -92,6 +95,7 @@ Map<String, dynamic> _$GithubCommitsCommitToJson(
'messageHeadline': instance.messageHeadline,
'committedDate': instance.committedDate?.toIso8601String(),
'author': instance.author?.toJson(),
'status': instance.status?.toJson(),
'history': instance.history?.toJson(),
'__typename': instance.resolveType,
};
@ -243,6 +247,60 @@ Map<String, dynamic> _$GithubCommitsSponsorableToJson(
'__typename': instance.resolveType,
};
GithubCommitsStatus _$GithubCommitsStatusFromJson(Map<String, dynamic> json) {
return GithubCommitsStatus()
..state =
_$enumDecodeNullable(_$GithubCommitsStatusStateEnumMap, json['state'])
..resolveType = json['__typename'] as String;
}
Map<String, dynamic> _$GithubCommitsStatusToJson(
GithubCommitsStatus instance) =>
<String, dynamic>{
'state': _$GithubCommitsStatusStateEnumMap[instance.state],
'__typename': instance.resolveType,
};
T _$enumDecode<T>(
Map<T, dynamic> enumValues,
dynamic source, {
T unknownValue,
}) {
if (source == null) {
throw ArgumentError('A value must be provided. Supported values: '
'${enumValues.values.join(', ')}');
}
final value = enumValues.entries
.singleWhere((e) => e.value == source, orElse: () => null)
?.key;
if (value == null && unknownValue == null) {
throw ArgumentError('`$source` is not one of the supported values: '
'${enumValues.values.join(', ')}');
}
return value ?? unknownValue;
}
T _$enumDecodeNullable<T>(
Map<T, dynamic> enumValues,
dynamic source, {
T unknownValue,
}) {
if (source == null) {
return null;
}
return _$enumDecode<T>(enumValues, source, unknownValue: unknownValue);
}
const _$GithubCommitsStatusStateEnumMap = {
GithubCommitsStatusState.EXPECTED: 'EXPECTED',
GithubCommitsStatusState.ERROR: 'ERROR',
GithubCommitsStatusState.FAILURE: 'FAILURE',
GithubCommitsStatusState.PENDING: 'PENDING',
GithubCommitsStatusState.SUCCESS: 'SUCCESS',
};
GithubCommitsCommitHistoryConnection
_$GithubCommitsCommitHistoryConnectionFromJson(Map<String, dynamic> json) {
return GithubCommitsCommitHistoryConnection()

View File

@ -13,9 +13,9 @@ fragment T on Ref {
login
}
}
# status {
# state
# }
status {
state
}
history(first: 30, after: $after) {
pageInfo {
hasNextPage
@ -33,9 +33,9 @@ fragment T on Ref {
login
}
}
# status {
# state
# }
status {
state
}
}
}
}

View File

@ -41,12 +41,12 @@ class CommitsScreen extends StatelessWidget {
);
}
Widget _buildStatus(String state) {
var size = 18.0;
Widget _buildStatus(GithubCommitsStatusState state) {
const size = 18.0;
switch (state) {
case 'SUCCESS':
case GithubCommitsStatusState.SUCCESS:
return Icon(Octicons.check, color: GithubPalette.open, size: size);
case 'FAILURE':
case GithubCommitsStatusState.FAILURE:
return Icon(Octicons.x, color: GithubPalette.closed, size: size);
default:
return Container();
@ -97,10 +97,10 @@ class CommitsScreen extends StatelessWidget {
fontSize: 15,
),
),
// if (payload['status'] != null) ...[
// SizedBox(width: 4),
// _buildStatus(payload['status']['state'])
// ], TODO:
if (payload.status != null) ...[
SizedBox(width: 4),
_buildStatus(payload.status.state),
],
],
)
],

View File

@ -36,7 +36,11 @@ dependencies:
uri: ^0.11.3
fimber: ^0.3.2
photo_view: ^0.7.0
artemis: ^2.1.2
artemis: #^2.1.2
# path: ../../github/artemis
git:
url: git://github.com/pd4d10/artemis.git
ref: patch-1
gql_link: ^0.2.0
fluro: ^1.5.1
charts_flutter: ^0.8.1