Skip to content

Commit e46a2f6

Browse files
authored
Merge pull request SpinlockLabs#79 from kevmoo/kevmoo_tweaks
More cleanup
2 parents d472530 + effe7f6 commit e46a2f6

19 files changed

+198
-210
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v3.0.0
2+
3+
- *BREAKING* Removed a number of top-level methods from the public API.
4+
15
## v2.3.2
26

37
- Automatically attempt to find GitHub user information in the process environment when running on the standalone VM.

example/common.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ void init(String script, {void onReady()}) {
2424
var ready = false;
2525

2626
void sendCode() {
27-
popup.postMessage(
28-
{"command": "code", "code": code}, window.location.href);
27+
popup
28+
.postMessage({"command": "code", "code": code}, window.location.href);
2929
}
3030

3131
window.addEventListener("message", (event) {
@@ -52,10 +52,9 @@ Map<String, String> queryString =
5252

5353
GitHub _createGitHub() {
5454
initGitHub();
55-
return new GitHub(
56-
auth: queryString["token"] != null
57-
? new Authentication.withToken(queryString["token"])
58-
: new Authentication.anonymous());
55+
return new GitHub(auth: queryString["token"] != null
56+
? new Authentication.withToken(queryString["token"])
57+
: new Authentication.anonymous());
5958
}
6059

6160
GitHub github = _createGitHub();

lib/common.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
library github.common;
77

88
import "dart:async";
9-
import "dart:convert" show
10-
JSON,
11-
UTF8,
12-
JsonEncoder,
13-
JsonDecoder,
14-
Utf8Encoder,
15-
Utf8Decoder;
16-
import "package:crypto/crypto.dart" show CryptoUtils;
9+
import "dart:convert" show BASE64, JSON, UTF8;
1710

1811
import "package:html/parser.dart" as htmlParser;
1912
import "package:html/dom.dart" as html;
@@ -24,11 +17,12 @@ import "package:xml/xml.dart" as xml;
2417

2518
import "http.dart" as http;
2619

20+
import 'src/util.dart';
21+
2722
part "src/common/github.dart";
2823

2924
// Util
3025
part "src/common/util/auth.dart";
31-
part "src/common/util/encoding_utils.dart";
3226
part "src/common/util/json.dart";
3327
part "src/common/util/oauth2.dart";
3428
part "src/common/util/errors.dart";

lib/server.dart

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ const List<String> COMMON_GITHUB_TOKEN_ENV_KEYS = const [
5050
Authentication findAuthenticationFromEnvironment() {
5151
if (Platform.isMacOS) {
5252
try {
53-
var result = Process.runSync("security", const [
54-
"find-internet-password",
55-
"-g",
56-
"-s",
57-
"github.com"
58-
]);
53+
var result = Process.runSync("security",
54+
const ["find-internet-password", "-g", "-s", "github.com"]);
5955

6056
if (result.exitCode != 0) {
6157
throw "Don't use keychain.";
@@ -68,8 +64,7 @@ Authentication findAuthenticationFromEnvironment() {
6864
String password = result.stderr.toString().split("password:")[1].trim();
6965
password = password.substring(1, password.length - 1);
7066
return new Authentication.basic(username.trim(), password.trim());
71-
} catch (e) {
72-
}
67+
} catch (e) {}
7368
}
7469

7570
Map<String, String> env = Platform.environment;
@@ -82,9 +77,7 @@ Authentication findAuthenticationFromEnvironment() {
8277

8378
if (env["GITHUB_USERNAME"] is String && env["GITHUB_PASSWORD"] is String) {
8479
return new Authentication.basic(
85-
env["GITHUB_USERNAME"],
86-
env["GITHUB_PASSWORD"]
87-
);
80+
env["GITHUB_USERNAME"], env["GITHUB_PASSWORD"]);
8881
}
8982

9083
return new Authentication.anonymous();

lib/src/common/explore_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class ExploreService extends Service {
1212

1313
if (language != null) url += "?l=${language}";
1414

15-
if (since != null) url +=
16-
language == null ? "?since=${since}" : "&since=${since}";
15+
if (since != null)
16+
url += language == null ? "?since=${since}" : "&since=${since}";
1717

1818
var controller = new StreamController();
1919

lib/src/common/github.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class GitHub {
314314
*/
315315
void handleStatusCode(http.Response response) {
316316
String message;
317-
List<String> errors;
317+
List<Map<String, String>> errors;
318318
if (response.headers['content-type'].contains('application/json')) {
319319
var json = response.asJSON();
320320
message = json['message'];
@@ -331,7 +331,8 @@ class GitHub {
331331
throw new InvalidJSON(this, message);
332332
} else if (message == "Body should be a JSON Hash") {
333333
throw new InvalidJSON(this, message);
334-
} else throw new BadRequest(this);
334+
} else
335+
throw new BadRequest(this);
335336
break;
336337
case 422:
337338
var buff = new StringBuffer();
@@ -379,7 +380,8 @@ class GitHub {
379380
if (auth.isToken) {
380381
headers.putIfAbsent("Authorization", () => "token ${auth.token}");
381382
} else if (auth.isBasic) {
382-
var userAndPass = utf8ToBase64('${auth.username}:${auth.password}');
383+
var userAndPass =
384+
BASE64.encode(UTF8.encode('${auth.username}:${auth.password}'));
383385
headers.putIfAbsent("Authorization", () => "basic ${userAndPass}");
384386
}
385387

@@ -416,7 +418,8 @@ class GitHub {
416418
fail != null ? fail(response) : null;
417419
handleStatusCode(response);
418420
return null;
419-
} else return response;
421+
} else
422+
return response;
420423
});
421424
}
422425

lib/src/common/issues_service.dart

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ class IssuesService extends Service {
1717
String direction,
1818
String sort,
1919
DateTime since,
20-
int perPage}) {
21-
return _listIssues("/issues",
22-
milestoneNumber, state, direction, sort, since, perPage);
20+
int perPage,
21+
List<String> labels}) {
22+
return _listIssues("/issues", milestoneNumber, state, direction, sort,
23+
since, perPage, labels);
2324
}
2425

2526
/// List all issues across owned and member repositories for the authenticated
@@ -32,9 +33,10 @@ class IssuesService extends Service {
3233
String direction,
3334
String sort,
3435
DateTime since,
35-
int perPage}) {
36-
return _listIssues("/user/issues",
37-
milestoneNumber, state, direction, sort, since, perPage);
36+
int perPage,
37+
List<String> labels}) {
38+
return _listIssues("/user/issues", milestoneNumber, state, direction, sort,
39+
since, perPage, labels);
3840
}
3941

4042
/// List all issues for a given organization for the authenticated user.
@@ -46,9 +48,10 @@ class IssuesService extends Service {
4648
String direction,
4749
String sort,
4850
DateTime since,
49-
int perPage}) {
50-
return _listIssues("/orgs/${org}/issues",
51-
milestoneNumber, state, direction, sort, since, perPage);
51+
int perPage,
52+
List<String> labels}) {
53+
return _listIssues("/orgs/${org}/issues", milestoneNumber, state, direction,
54+
sort, since, perPage, labels);
5255
}
5356

5457
/// Lists the issues for the specified repository.
@@ -62,14 +65,21 @@ class IssuesService extends Service {
6265
String direction,
6366
String sort,
6467
DateTime since,
65-
int perPage}) {
66-
return _listIssues("/repos/${slug.fullName}/issues",
67-
milestoneNumber, state, direction, sort, since, perPage);
68+
int perPage,
69+
List<String> labels}) {
70+
return _listIssues("/repos/${slug.fullName}/issues", milestoneNumber, state,
71+
direction, sort, since, perPage, labels);
6872
}
6973

70-
Stream<Issue> _listIssues(String pathSegment, int milestoneNumber,
71-
String state, String direction, String sort, DateTime since,
72-
int perPage) {
74+
Stream<Issue> _listIssues(
75+
String pathSegment,
76+
int milestoneNumber,
77+
String state,
78+
String direction,
79+
String sort,
80+
DateTime since,
81+
int perPage,
82+
List<String> labels) {
7383
var params = <String, String>{};
7484

7585
if (perPage != null) {
@@ -103,6 +113,10 @@ class IssuesService extends Service {
103113
params['since'] = since.toUtc().toIso8601String();
104114
}
105115

116+
if (labels != null && labels.isNotEmpty) {
117+
params['labels'] = labels.join(',');
118+
}
119+
106120
return new PaginationHelper(_github)
107121
.objects("GET", pathSegment, Issue.fromJSON, params: params);
108122
}
@@ -252,10 +266,11 @@ class IssuesService extends Service {
252266
/// Deletes a label.
253267
///
254268
/// API docs: https://developer.github.com/v3/issues/labels/#delete-a-label
255-
Future<bool> deleteLabel(RepositorySlug slug, String name) {
256-
return _github
257-
.request("DELETE", "/repos/${slug.fullName}/labels/${name}")
258-
.then((response) => response.statusCode == StatusCodes.NO_CONTENT);
269+
Future<bool> deleteLabel(RepositorySlug slug, String name) async {
270+
var response = await _github.request(
271+
"DELETE", "/repos/${slug.fullName}/labels/${name}");
272+
273+
return response.statusCode == StatusCodes.NO_CONTENT;
259274
}
260275

261276
/// Lists all labels for an issue.
@@ -296,11 +311,11 @@ class IssuesService extends Service {
296311
///
297312
/// API docs: https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
298313
Future<bool> removeLabelForIssue(
299-
RepositorySlug slug, int issueNumber, String label) {
300-
return _github
301-
.request("DELETE",
302-
"/repos/${slug.fullName}/issues/${issueNumber}/labels/${label}")
303-
.then((response) => response.statusCode == StatusCodes.NO_CONTENT);
314+
RepositorySlug slug, int issueNumber, String label) async {
315+
var response = await _github.request("DELETE",
316+
"/repos/${slug.fullName}/issues/${issueNumber}/labels/${label}");
317+
318+
return response.statusCode == StatusCodes.OK;
304319
}
305320

306321
/// Removes all labels for an issue.

lib/src/common/model/repos_contents.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class GitHubFile {
3838
/// Text Content
3939
String get text {
4040
if (_text == null) {
41-
_text =
42-
new String.fromCharCodes(CryptoUtils.base64StringToBytes(content));
41+
_text = UTF8.decode(BASE64.decode(content));
4342
}
4443
return _text;
4544
}

lib/src/common/orgs_service.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ class OrganizationsService extends Service {
174174
var completer = new Completer();
175175

176176
_github.getJSON("/teams/${teamId}/memberships/${user}", statusCode: 200,
177-
fail: (http.Response response) {
177+
fail: (http.Response response) {
178178
if (response.statusCode == 404) {
179179
completer.complete(new TeamMembershipState(null));
180180
} else {
181181
_github.handleStatusCode(response);
182182
}
183-
}, convert: (json) => new TeamMembershipState(json['state']))
184-
.then(completer.complete);
183+
}, convert: (json) => new TeamMembershipState(json['state'])).then(
184+
completer.complete);
185185

186186
return completer.future;
187187
}

lib/src/common/util/encoding_utils.dart

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/src/common/util/pagination.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ class PaginationHelper<T> {
9292
int statusCode: 200,
9393
String preview}) {
9494
return jsonObjects(method, path,
95-
pages: pages,
96-
headers: headers,
97-
params: params,
98-
body: body,
99-
statusCode: statusCode,
100-
preview: preview).map(converter);
95+
pages: pages,
96+
headers: headers,
97+
params: params,
98+
body: body,
99+
statusCode: statusCode,
100+
preview: preview)
101+
.map(converter);
101102
}
102103
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy