Skip to content

Commit

Permalink
expose IssueLabel.description; update labels REST APIs (#355)
Browse files Browse the repository at this point in the history
* expose IssueLabel.description; update labels REST APIs

* add a deprecated forwarding method

* Update issues_service.dart

---------

Co-authored-by: Rob Becker <robrbecker@gmail.com>
  • Loading branch information
devoncarew and robrbecker committed Mar 15, 2023
1 parent 0a0ab45 commit 1586738
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
44 changes: 37 additions & 7 deletions lib/src/common/issues_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,49 @@ class IssuesService extends Service {
///
/// API docs: https://developer.github.com/v3/issues/labels/#create-a-label
Future<IssueLabel> 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.
///
/// API docs: https://developer.github.com/v3/issues/labels/#update-a-label
@Deprecated('See updateLabel instead.')
Future<IssueLabel> 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);
return updateLabel(slug, name, color: color);
}

/// Update a label.
///
/// API docs: https://developer.github.com/v3/issues/labels/#update-a-label
Future<IssueLabel> 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.
Expand Down
3 changes: 3 additions & 0 deletions lib/src/common/model/issues.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,15 @@ class IssueLabel {
IssueLabel({
this.name = '',
this.color = '',
this.description = '',
});

String name;

String color;

String description;

factory IssueLabel.fromJson(Map<String, dynamic> input) =>
_$IssueLabelFromJson(input);
Map<String, dynamic> toJson() => _$IssueLabelToJson(this);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/common/model/issues.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1586738

Please sign in to comment.