diff --git a/lib/src/common/github.dart b/lib/src/common/github.dart index f69288a6..b92749f0 100644 --- a/lib/src/common/github.dart +++ b/lib/src/common/github.dart @@ -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; @@ -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 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 patchJSON( + String path, { + int? statusCode, + void Function(http.Response response)? fail, + Map? headers, + Map? params, + JSONConverter? convert, + dynamic body, + String? preview, + }) => + requestJson( + 'PATCH', + path, + statusCode: statusCode, + fail: fail, + headers: headers, + params: params, + convert: convert, + body: body, + preview: preview, + ); + Future requestJson( String method, String path, { diff --git a/lib/src/common/issues_service.dart b/lib/src/common/issues_service.dart index 448da36f..8fcc9a1a 100644 --- a/lib/src/common/issues_service.dart +++ b/lib/src/common/issues_service.dart @@ -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 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. ///