From 8cfe4b318d8683dc6be59ab0c6d5968325a461d9 Mon Sep 17 00:00:00 2001 From: Kenneth Endfinger Date: Sat, 30 Aug 2014 14:38:31 -0400 Subject: [PATCH] Label Management for Issues --- lib/src/common/issues.dart | 48 +++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/lib/src/common/issues.dart b/lib/src/common/issues.dart index 21255a64..b8506016 100644 --- a/lib/src/common/issues.dart +++ b/lib/src/common/issues.dart @@ -86,7 +86,7 @@ class Issue { Issue(this.github); Map json; - + static Issue fromJSON(GitHub github, input) { if (input == null) return null; return new Issue(github) @@ -106,37 +106,63 @@ class Issue { ..closedBy = User.fromJSON(github, input['closed_by']) ..json = input; } - + Future comment(String body) { - var it = JSON.encode({ "body": body }); + var it = JSON.encode({ + "body": body + }); return github.postJSON(json['_links']['comments']['href'], body: it, convert: IssueComment.fromJSON, statusCode: 201); } - + Stream comments() { return new PaginationHelper(github).objects("GET", "${this.json['url']}/comments", IssueComment.fromJSON); } - + Future changeBody(String newBody) { - return github.request("POST", json['url'], body: JSON.encode({ "body": newBody })).then((response) { + return github.request("POST", json['url'], body: JSON.encode({ + "body": newBody + })).then((response) { return Issue.fromJSON(github, JSON.decode(response.body)); }); } - + Future changeTitle(String title) { - return github.request("POST", json['url'], body: JSON.encode({ "title": title })).then((response) { + return github.request("POST", json['url'], body: JSON.encode({ + "title": title + })).then((response) { return Issue.fromJSON(github, JSON.decode(response.body)); }); } - + Future changeState(String state) { - return github.request("POST", json['url'], body: JSON.encode({ "state": state })).then((response) { + return github.request("POST", json['url'], body: JSON.encode({ + "state": state + })).then((response) { return Issue.fromJSON(github, JSON.decode(response.body)); }); } - + Future close() => changeState("closed"); Future open() => changeState("open"); Future reopen() => changeState("open"); + + Future> addLabels(List labels) { + return github.postJSON("${json['url']}/labels", body: JSON.encode(labels), convert: (github, input) => input.map((it) => IssueLabel.fromJSON(github, it))); + } + + Future> replaceLabels(List labels) { + return github.request("PUT", "${json['url']}/labels", body: JSON.encode(labels)).then((response) { + return JSON.decode(response.body).map((it) => IssueLabel.fromJSON(github, it)); + }); + } + + Future removeAllLabels() { + return github.request("DELETE", "${json['url']}/labels").then((response) => response.statusCode == StatusCodes.NO_CONTENT); + } + + Future removeLabel(String name) { + return github.request("DELETE", "${json['url']}/labels/${name}").then((response) => response.statusCode == StatusCodes.NO_CONTENT); + } } /**