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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.packages
.pub/

ios/Flutter/flutter_export_environment.sh
ios/.generated/
ios/Pods/
ios/Podfile.lock
Expand Down
12 changes: 6 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -42,7 +41,6 @@
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
3C7768A1A9B58B43E3392FD3 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -58,6 +56,8 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B741F99116C4D73239D86FB5 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
D4DA25AA4E199BEC1F6A1526 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -85,14 +85,15 @@
5873D7D88706813638AF142B /* Pods */ = {
isa = PBXGroup;
children = (
B741F99116C4D73239D86FB5 /* Pods-Runner.debug.xcconfig */,
D4DA25AA4E199BEC1F6A1526 /* Pods-Runner.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
Expand Down Expand Up @@ -213,7 +214,6 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -255,7 +255,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
Expand All @@ -264,7 +264,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
F297033013D4A6E17D61E7E7 /* [CP] Check Pods Manifest.lock */ = {
Expand Down
112 changes: 87 additions & 25 deletions lib/github/graphql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:async';
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:graphql/client.dart';

import 'parsers.dart';
import 'pullrequest.dart';
Expand All @@ -18,11 +19,28 @@ import 'token.dart';
import 'user.dart';
import 'label.dart';

final url = 'https://api.github.com/graphql';
// final url = 'https://api.github.com/graphql';
// updated this to allow use of preview stuff in the GraphQL API
final headers = {'Authorization': 'bearer $token', 'Accept': 'application/vnd.github.starfire-preview+json'};
// final headers = {'Authorization': 'bearer $token', 'Accept': 'application/vnd.github.starfire-preview+json'};
final postHeaders = {'Authorization': 'token $token'};

final HttpLink _httpLink = HttpLink(
uri: 'https://api.github.com/graphql',
headers: {'Accept': 'application/vnd.github.starfire-preview+json'}
);

final AuthLink _authLink = AuthLink(
getToken: () async => 'bearer $token',

);

final Link _link = _authLink.concat(_httpLink);

final GraphQLClient _client = GraphQLClient(
cache: InMemoryCache(),
link: _link,
);

/// Fetches the details of the specified user
Future<User> user(String login) async {
final query = '''
Expand Down Expand Up @@ -98,39 +116,83 @@ addEmoji(String id, String reaction) async {
}
}
''';
await _query(query);
await _mutation(query);
}

acceptPR(String reviewUrl) async {
var response = await http.put('$reviewUrl/merge', headers: postHeaders);
return response.statusCode == 200
? response.body
: throw Exception('Error: ${response.statusCode} ${response.body}');
acceptPR(String pullRequestID) async {
var mutation = '''
mutation MergePullRequest {
mergePullRequest(input:{pullRequestID:"$pullRequestID"}) {
clientMutationId
pullRequest {
url
title
id
number
labels (first: 30) {
nodes {
name
color
id
}
}
author {
login
}
}
}
}
''';
return await _mutation(mutation);
}

closePR(String reviewUrl) async {
var response = await http.patch(reviewUrl,
headers: postHeaders, body: '{"state": "closed"}');
return response.statusCode == 200
? response.body
: throw Exception('Error: ${response.statusCode} ${response.body}');
closePR(String pullRequestID) async {
var mutation = '''
mutation ClosePullRequest {
closePullRequest(input:{pullRequestID:"$pullRequestID"}) {
clientMutationId
pullRequest {
url
title
id
number
labels (first: 30) {
nodes {
name
color
id
}
}
author {
login
}
}
}
}
''';
return await _mutation(mutation);
}

getDiff(PullRequest pullRequest) async {
var response = await http.get(pullRequest.diffUrl);
return response.body;
}

/// Sends a GraphQL query to Github and returns raw response
Future<String> _query(String query) async {
final gqlQuery = json.encode({'query': _removeSpuriousSpacing(query)});
final response = await http.post(url, headers: headers, body: gqlQuery);
return response.statusCode == 200
? response.body
: throw Exception('Error: ${response.statusCode}');
/// Sends a GraphQL query to Github and returns response
Future<dynamic> _query(String query) async {
final QueryResult response = await _client.query(QueryOptions(document: query));
return !response.hasErrors
? response.data
: throw Exception('Error: ${response.errors}');
}

_removeSpuriousSpacing(String str) => str.replaceAll(RegExp(r'\s+'), ' ');
/// Sends a GraphQL mutation to Github and returns response
Future<dynamic> _mutation(String mutation) async {
final QueryResult response = await _client.mutate(MutationOptions(document: mutation));
return !response.hasErrors
? response.data
: throw Exception('Error: ${response.errors}');
}


// -------------------------------------------------------------------------------------
Expand Down Expand Up @@ -377,7 +439,7 @@ Future<IssueComment> addComment(Issue issue, PullRequest pr, String commentBody)
}
''';

final result = await _query(mutation);
final result = await _mutation(mutation);
return parseAddedComment(result, pr, issue);

}
Expand Down Expand Up @@ -414,7 +476,7 @@ Future<List> addLabel(Issue issue, PullRequest pr, List<String> labelIds) async
}
}
''';
result = await _query(mutationPR);
result = await _mutation(mutationPR);
}
else {
print("issue id: " + id);
Expand All @@ -438,7 +500,7 @@ Future<List> addLabel(Issue issue, PullRequest pr, List<String> labelIds) async
}
''';
print(mutationIss);
result = await _query(mutationIss);
result = await _mutation(mutationIss);
print('issue');
}
print(result);
Expand Down
45 changes: 22 additions & 23 deletions lib/github/parsers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import 'user.dart';
import 'label.dart';

/// Parses a Github GraphQL user response
User parseUser(String resBody) {
final jsonRes = json.decode(resBody)['data'];
User parseUser(Map<String,dynamic> jsonRes) {
final userJson = jsonRes['viewer'] ?? jsonRes['user'];
return User(userJson['login'], userJson['name'], userJson['avatarUrl']);
}
Expand Down Expand Up @@ -44,23 +43,23 @@ User parseUser(String resBody) {
// NON CHROMIUM AUTHOR CODE BELOW (the code below is under MIT license)

// parseBranches parses the result from the GraphQL query for fetching the # of branches
int parseBranches(String resBody) {
int parseBranches(Map<String,dynamic> resBody) {
int jsonRes =
json.decode(resBody)['data']['repository']['refs']['totalCount'];
resBody['repository']['refs']['totalCount'];
return jsonRes;
}

// parseReleases parses the result from the GraphQL query for fetching the # of releases
int parseReleases(String resBody) {
int parseReleases(Map<String,dynamic> resBody) {
int jsonRes =
json.decode(resBody)['data']['repository']['refs']['totalCount'];
resBody['repository']['refs']['totalCount'];
return jsonRes;
}

// parsePullRequests parses the result from the GraphQL query for fetching the PRs for a repo
List<PullRequest> parsePullRequests(
String resBody, Repository repo) {
List jsonRes = json.decode(resBody)['data']['search']['edges'];
Map<String,dynamic> resBody, Repository repo) {
List jsonRes = resBody['search']['edges'];


List<PullRequest> prs = [];
Expand Down Expand Up @@ -114,8 +113,8 @@ List<PullRequest> parsePullRequests(
}

// parseIssues parses the result from the GraphQL query for fetching the issues for a repo
List<Issue> parseIssues(String resBody, Repository repo) {
List jsonRes = json.decode(resBody)['data']['search']['edges'];
List<Issue> parseIssues(Map<String,dynamic> resBody, Repository repo) {
List jsonRes = resBody['search']['edges'];

List<Issue> issues = [];
for (var i = 0; i < jsonRes.length; i++) {
Expand Down Expand Up @@ -171,12 +170,12 @@ List<Issue> parseIssues(String resBody, Repository repo) {
}

// parsePRTimeline parses the result from the GraphQL query for fetching the timeline for a PR
List<TimelineItem> parsePRTimeline(String resBody, PullRequest pr) {
List jsonRes = json.decode(resBody)['data']['repository']['pullRequest']
List<TimelineItem> parsePRTimeline(Map<String,dynamic> resBody, PullRequest pr) {
List jsonRes = resBody['repository']['pullRequest']
['timeline']['edges'];

List<TimelineItem> prTimeline = [];
Map tmp = json.decode(resBody)['data']['repository']['pullRequest'];
Map tmp = resBody['repository']['pullRequest'];
prTimeline.add(
IssueComment(pr, null, "", "", "", tmp['author']['login'], tmp['body']));
for (var i = 0; i < jsonRes.length; i++) {
Expand Down Expand Up @@ -222,12 +221,12 @@ List<TimelineItem> parsePRTimeline(String resBody, PullRequest pr) {
}

// parseIssueTimeline parses the result from the GraphQL query for fetching the timeline for an issue
List<TimelineItem> parseIssueTimeline(String resBody, Issue issue) {
List<TimelineItem> parseIssueTimeline(Map<String,dynamic> resBody, Issue issue) {
List jsonRes =
json.decode(resBody)['data']['repository']['issue']['timeline']['edges'];
resBody['repository']['issue']['timeline']['edges'];

List<TimelineItem> issueTimeline = [];
Map tmp = json.decode(resBody)['data']['repository']['issue'];
Map tmp = resBody['repository']['issue'];
issueTimeline.add(IssueComment(
null, issue, "", "", "", tmp['author']['login'], tmp['body']));
for (var i = 0; i < jsonRes.length; i++) {
Expand Down Expand Up @@ -273,9 +272,9 @@ List<TimelineItem> parseIssueTimeline(String resBody, Issue issue) {
}

// parseUserRepos parses the result from the GraphQL query for fetching the repositories for a user
List<Repository> parseUserRepos(String resBody) {
List<Repository> parseUserRepos(Map<String,dynamic> resBody) {
List jsonRes =
json.decode(resBody)['data']['viewer']['repositories']['nodes'];
resBody['viewer']['repositories']['nodes'];

List<Repository> repos = [];

Expand All @@ -294,17 +293,17 @@ List<Repository> parseUserRepos(String resBody) {
}

// parseAddedComment parses the response received after calling addComment mutation
IssueComment parseAddedComment(String resBody, PullRequest pr, Issue issue) {
IssueComment parseAddedComment(Map<String,dynamic> resBody, PullRequest pr, Issue issue) {
Map jsonRes =
json.decode(resBody)['data']['addComment']['commentEdge']['node'];
Map jsonTemp = json.decode(resBody)['data']['addComment'];
resBody['addComment']['commentEdge']['node'];
Map jsonTemp = resBody['addComment'];

return IssueComment(pr, issue, "", jsonRes['url'], jsonTemp['subject']['id'],
jsonRes['author']['login'], jsonRes['bodyText']);
}

List parseAddedLabels(String resBody, PullRequest pr, Issue issue) {
List parseAddedLabels(Map<String,dynamic> resBody, PullRequest pr, Issue issue) {
List labels =
json.decode(resBody)['data']['addLabelsToLabelable']['labelable']['labels']['nodes'];
resBody['addLabelsToLabelable']['labelable']['labels']['nodes'];
return labels;
}
5 changes: 2 additions & 3 deletions lib/pages/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,14 @@ class _DashboardState extends State<Dashboard> {

}

void _refreshDashboard(bool b) {
void _refreshDashboard() {
setState(() {
prList = graphql.getPRs(widget.repo);
issueList = graphql.getIssues(widget.repo);
branches = graphql.getBranches(widget.repo);
releases = graphql.getReleases(widget.repo);

rc.sendBack(true, RefreshStatus.completed);
rc.loadComplete();

Navigator.pushReplacement(
context,
Expand Down Expand Up @@ -404,7 +404,6 @@ class _DashboardState extends State<Dashboard> {
);
});

b = true;
}
}

Expand Down
Loading