SpinlockLabs / github.dart

GitHub Client Library for Dart

Home Page:https://pub.dev/packages/github

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

await github.pullRequests.createComment throwing type exception: 'Future<PullRequestComment>' is not a subtype of type 'Future<IssueComment>' in type cast

alexrintt opened this issue · comments

commented

Context

I'm trying to push a new comment to a existing pull request as follow:

final pullRequestNumber = 10; /// A existing PR

final slug = RepositorySlug.full('LaksCastro/<my-repo-name>');

final text = 'I\'m using Github API to comment on this Pull Request';

final comment = CreatePullRequestComment(text, null, null, null);

await github.pullRequests.createComment(slug, pullRequestNumber, comment);

but it's throwing an exception:

type 'Future<PullRequestComment>' is not a subtype of type 'Future<IssueComment>' in type cast
#0      PullRequestsService.createComment (package:github/src/common/pulls_service.dart:163:26)

Exception Source

Following the exception source. I think that the mistmatch is at:

lib/src/common/pulls_service.dart

class PullsService extends Service {
  ...other method
  Future<IssueComment> createComment( /// This line (1)
      RepositorySlug slug, int number, CreatePullRequestComment comment) {
    return github.postJSON('/repos/${slug.fullName}/pulls/$number/comments',
        body: GitHubJson.encode(comment.toJson()),
        convert: (dynamic i) => PullRequestComment.fromJson(i),
        statusCode: 201) as Future<IssueComment>; /// This line (2)
  }
}

1. I think the correct return type is Future<PullRequestComment> because by the docs: Creates a new pull request comment.
2. The same reason, we are trying to cast the return type to Future<IssueComment> but at line 162 we are using a PullRequestComment to convert from Json:

/// ...
convert: (dynamic i) => PullRequestComment.fromJson(i),
/// ...

Anyway, I don't know if has a special reason for this type casting, any help is appreciate

Enviroment

  • Target library version:
dependencies:
  github: ^8.2.1
  • Flutter enviroment:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19043.1237], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[√] Android Studio
[√] Connected device (2 available)

• No issues found!

👋 Thanks for reporting! @robrbecker will take a look.

So believe it or not all PRs are issues (but not all issues are PRs). So to make a comment on a PR that isn't attached to content, you would create an issue comment with the same ID (The PR number). Want to give that a try and let me know if that works for you?

commented

Yeah, I saw that to create a pull request comment I need to use issues getter, it's very confusing if you are not aware about API specifications, thx for the fast reply and the solution!

final pullRequestNumber = 10; /// A existing PR

final slug = RepositorySlug.full('LaksCastro/<my-repo-name>');

final text = 'I\'m using Github API to comment on this Pull Request';

await github.issues.createComment(slug, pullRequestNumber, text);