Skip to content

Commit b4462d7

Browse files
authored
Merge pull request #286 from dkrutskikh/update-comment
feat: implement update an issue comment
2 parents e631e50 + 038001e commit b4462d7

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

lib/src/common/github.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22
import 'dart:convert';
3+
34
import 'package:github/src/common.dart';
45
import 'package:github/src/common/util/utils.dart';
56
import 'package:http/http.dart' as http;
@@ -245,6 +246,48 @@ class GitHub {
245246
preview: preview,
246247
);
247248

249+
/// Handles PATCH Requests that respond with JSON
250+
///
251+
/// [path] can either be a path like '/repos' or a full url.
252+
/// [statusCode] is the expected status code. If it is null, it is ignored.
253+
/// If the status code that the response returns is not the status code you provide
254+
/// then the [fail] function will be called with the HTTP Response.
255+
///
256+
/// If you don't throw an error or break out somehow, it will go into some error checking
257+
/// that throws exceptions when it finds a 404 or 401. If it doesn't find a general HTTP Status Code
258+
/// for errors, it throws an Unknown Error.
259+
///
260+
/// [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
261+
/// [params] are query string parameters.
262+
/// [convert] is a simple function that is passed this [GitHub] instance and a JSON object.
263+
///
264+
/// The future will pass the object returned from this function to the then method.
265+
/// The default [convert] function returns the input object.
266+
/// [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
267+
/// [S] represents the input type.
268+
/// [T] represents the type return from this function after conversion
269+
Future<T> patchJSON<S, T>(
270+
String path, {
271+
int? statusCode,
272+
void Function(http.Response response)? fail,
273+
Map<String, String>? headers,
274+
Map<String, dynamic>? params,
275+
JSONConverter<S, T>? convert,
276+
dynamic body,
277+
String? preview,
278+
}) =>
279+
requestJson(
280+
'PATCH',
281+
path,
282+
statusCode: statusCode,
283+
fail: fail,
284+
headers: headers,
285+
params: params,
286+
convert: convert,
287+
body: body,
288+
preview: preview,
289+
);
290+
248291
Future<T> requestJson<S, T>(
249292
String method,
250293
String path, {

lib/src/common/issues_service.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,18 @@ class IssuesService extends Service {
251251
);
252252
}
253253

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

256267
/// Deletes an issue comment.
257268
///

0 commit comments

Comments
 (0)