Skip to content

Commit

Permalink
Merge pull request #286 from dkrutskikh/update-comment
Browse files Browse the repository at this point in the history
feat: implement update an issue comment
  • Loading branch information
robrbecker authored Dec 19, 2021
2 parents e631e50 + 038001e commit b4462d7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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

0 comments on commit b4462d7

Please sign in to comment.