Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement update an issue comment #286

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions lib/src/common/github.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';

import 'package:github/src/common.dart';
import 'package:github/src/common/util/utils.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -245,6 +246,48 @@ class GitHub {
preview: preview,
);

/// Handles PATCH Requests that respond with JSON
///
/// [path] can either be a path like '/repos' or a full url.
/// [statusCode] is the expected status code. If it is null, it is ignored.
/// If the status code that the response returns is not the status code you provide
/// then the [fail] function will be called with the HTTP Response.
///
/// If you don't throw an error or break out somehow, it will go into some error checking
/// that throws exceptions when it finds a 404 or 401. If it doesn't find a general HTTP Status Code
/// for errors, it throws an Unknown Error.
///
/// [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
/// [params] are query string parameters.
/// [convert] is a simple function that is passed this [GitHub] instance and a JSON object.
///
/// The future will pass the object returned from this function to the then method.
/// The default [convert] function returns the input object.
/// [body] is the data to send to the server. Pass in a List<int> if you want to post binary body data. Everything else will have .toString() called on it and set as text content
/// [S] represents the input type.
/// [T] represents the type return from this function after conversion
Future<T> patchJSON<S, T>(
String path, {
int? statusCode,
void Function(http.Response response)? fail,
Map<String, String>? headers,
Map<String, dynamic>? params,
JSONConverter<S, T>? convert,
dynamic body,
String? preview,
}) =>
requestJson(
'PATCH',
path,
statusCode: statusCode,
fail: fail,
headers: headers,
params: params,
convert: convert,
body: body,
preview: preview,
);

Future<T> requestJson<S, T>(
String method,
String path, {
Expand Down
13 changes: 12 additions & 1 deletion lib/src/common/issues_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,18 @@ class IssuesService extends Service {
);
}

// TODO: Implement editComment: https://developer.github.com/v3/issues/comments/#edit-a-comment
/// Update an issue comment.
///
/// API docs: https://docs.github.com/en/rest/reference/issues#update-an-issue-comment
Future<IssueComment> updateComment(RepositorySlug slug, int id, String body) {
final it = GitHubJson.encode({'body': body});
return github.postJSON(
'/repos/${slug.fullName}/issues/comments/$id',
body: it,
convert: (dynamic i) => IssueComment.fromJson(i),
statusCode: StatusCodes.OK,
);
}

/// Deletes an issue comment.
///
Expand Down