From 5647e0d1674ee74f84fe9db79e4ac3492527f7e2 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 24 Feb 2023 02:27:02 -0800 Subject: [PATCH 1/3] expose IssueLabel.description; update labels REST APIs --- lib/src/common/issues_service.dart | 40 +++++++++++++++++++++++------- lib/src/common/model/issues.dart | 3 +++ lib/src/common/model/issues.g.dart | 2 ++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/src/common/issues_service.dart b/lib/src/common/issues_service.dart index 490396fb..67d5873a 100644 --- a/lib/src/common/issues_service.dart +++ b/lib/src/common/issues_service.dart @@ -290,19 +290,41 @@ class IssuesService extends Service { /// /// API docs: https://developer.github.com/v3/issues/labels/#create-a-label Future createLabel( - RepositorySlug slug, String name, String color) { - return github.postJSON('/repos/${slug.fullName}/labels', - body: GitHubJson.encode({'name': name, 'color': color}), - convert: IssueLabel.fromJson); + RepositorySlug slug, + String name, { + String? color, + String? description, + }) { + return github.postJSON( + '/repos/${slug.fullName}/labels', + body: GitHubJson.encode({ + 'name': name, + if (color != null) 'color': color, + if (description != null) 'description': description, + }), + convert: IssueLabel.fromJson, + ); } - /// Edits a label. + /// Update a label. /// /// API docs: https://developer.github.com/v3/issues/labels/#update-a-label - Future editLabel(RepositorySlug slug, String name, String color) { - return github.postJSON('/repos/${slug.fullName}/labels/$name', - body: GitHubJson.encode({'name': name, 'color': color}), - convert: IssueLabel.fromJson); + Future updateLabel( + RepositorySlug slug, + String name, { + String? newName, + String? color, + String? description, + }) { + return github.patchJSON( + '/repos/${slug.fullName}/labels/$name', + body: GitHubJson.encode({ + if (newName != null) 'new_name': newName, + if (color != null) 'color': color, + if (description != null) 'description': description, + }), + convert: IssueLabel.fromJson, + ); } /// Deletes a label. diff --git a/lib/src/common/model/issues.dart b/lib/src/common/model/issues.dart index 4534892e..6746a305 100644 --- a/lib/src/common/model/issues.dart +++ b/lib/src/common/model/issues.dart @@ -172,12 +172,15 @@ class IssueLabel { IssueLabel({ this.name = '', this.color = '', + this.description = '', }); String name; String color; + String description; + factory IssueLabel.fromJson(Map input) => _$IssueLabelFromJson(input); Map toJson() => _$IssueLabelToJson(this); diff --git a/lib/src/common/model/issues.g.dart b/lib/src/common/model/issues.g.dart index 12e03103..0a027f67 100644 --- a/lib/src/common/model/issues.g.dart +++ b/lib/src/common/model/issues.g.dart @@ -142,12 +142,14 @@ Map _$IssueCommentToJson(IssueComment instance) => IssueLabel _$IssueLabelFromJson(Map json) => IssueLabel( name: json['name'] as String? ?? '', color: json['color'] as String? ?? '', + description: json['description'] as String? ?? '', ); Map _$IssueLabelToJson(IssueLabel instance) => { 'name': instance.name, 'color': instance.color, + 'description': instance.description, }; Milestone _$MilestoneFromJson(Map json) => Milestone( From d08614574a4b0c7672b823418b90d79f06c3f9fa Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 24 Feb 2023 10:38:08 -0800 Subject: [PATCH 2/3] add a deprecated forwarding method --- lib/src/common/issues_service.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/src/common/issues_service.dart b/lib/src/common/issues_service.dart index 67d5873a..b989989c 100644 --- a/lib/src/common/issues_service.dart +++ b/lib/src/common/issues_service.dart @@ -306,6 +306,14 @@ class IssuesService extends Service { ); } + /// Edits a label. + /// + /// API docs: https://developer.github.com/v3/issues/labels/#update-a-label + @Deprecated('See updateLabel insead.') + Future editLabel(RepositorySlug slug, String name, String color) { + return updateLabel(slug, name, color: color); + } + /// Update a label. /// /// API docs: https://developer.github.com/v3/issues/labels/#update-a-label From 78a885dd67f9e0f72e5795dfe303baf8f87d76e6 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 24 Feb 2023 18:36:28 -0800 Subject: [PATCH 3/3] Update issues_service.dart --- lib/src/common/issues_service.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/common/issues_service.dart b/lib/src/common/issues_service.dart index b989989c..9d8eb4ab 100644 --- a/lib/src/common/issues_service.dart +++ b/lib/src/common/issues_service.dart @@ -309,7 +309,7 @@ class IssuesService extends Service { /// Edits a label. /// /// API docs: https://developer.github.com/v3/issues/labels/#update-a-label - @Deprecated('See updateLabel insead.') + @Deprecated('See updateLabel instead.') Future editLabel(RepositorySlug slug, String name, String color) { return updateLabel(slug, name, color: color); }