Skip to content

[BUG]: Repos[owner][repo].Issues.Comments[comment_id].GetAsync() always throws #117

Open
@IEvangelist

Description

@IEvangelist

What happened?

When I attempt to perform the following REST call using the SDK client, it throws an error:

var tokenProvider = new TokenProvider(Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? "");
var adapter = RequestAdapter.Create(new TokenAuthProvider(tokenProvider));

var client = new GitHubClient(adapter);

var owner = "DecimalTurn";
var repo = "VBA-on-GitHub-Automations";
var issueCommentId = 2310943199;

try
{
    var issueComment = await client.Repos[owner][repo].Issues.Comments[(int)issueCommentId].GetAsync();
    if (issueComment is { })
    {
        // This is never hit, as the above API always throws.
    }
}
catch (Exception ex)
{
    if (Debugger.IsAttached)
    {
        Debugger.Break();
    }
}       

The error I'm seeing is as follows:

Message: 
GitHub.Models.BasicError : Exception of type 'GitHub.Models.BasicError' was thrown.

  Stack Trace: 
HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken)
HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
WithComment_ItemRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken)
GitHubClientTests.GitHubClientGetsIssueCommentTest() line 45
--- End of stack trace from previous location ---

However, if I run the following code-to manually use an HttpClient outside the library (it works!):

var client = new HttpClient();

client.DefaultRequestHeaders.UserAgent.Add(new("Test", "0.1"));

var token = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
client.DefaultRequestHeaders.Authorization = new("Bearer", token);

var owner = "DecimalTurn";
var repo = "VBA-on-GitHub-Automations";
var issueCommentId = 2310943199;

try
{
    var response = await client.GetAsync($"""
        https://api.github.com/repos/{owner}/{repo}/issues/comments/{issueCommentId}
        """);

    response.EnsureSuccessStatusCode();

    var json = await response.Content.ReadAsStringAsync();
    if (json is { })
    {
        // This gets here, and works with the expected JSON
    }
}
catch (Exception ex)
{
    if (Debugger.IsAttached)
    {
        Debugger.Break();
    }
}

The expected JSON payload is as follows:

Click to expand JSON
{
  "url": "https://api.github.com/repos/DecimalTurn/VBA-on-GitHub-Automations/issues/comments/2310943199",
  "html_url": "https://github.com/DecimalTurn/VBA-on-GitHub-Automations/issues/79#issuecomment-2310943199",
  "issue_url": "https://api.github.com/repos/DecimalTurn/VBA-on-GitHub-Automations/issues/79",
  "id": 2310943199,
  "node_id": "IC_kwDOMhkZW86JvjHf",
  "user": {
    "login": "DecimalTurn",
    "id": 31558169,
    "node_id": "MDQ6VXNlcjMxNTU4MTY5",
    "avatar_url": "https://avatars.githubusercontent.com/u/31558169?u=60e9c89711d781983b36f3701037bb2af138456c&v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/DecimalTurn",
    "html_url": "https://github.com/DecimalTurn",
    "followers_url": "https://api.github.com/users/DecimalTurn/followers",
    "following_url": "https://api.github.com/users/DecimalTurn/following{/other_user}",
    "gists_url": "https://api.github.com/users/DecimalTurn/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/DecimalTurn/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/DecimalTurn/subscriptions",
    "organizations_url": "https://api.github.com/users/DecimalTurn/orgs",
    "repos_url": "https://api.github.com/users/DecimalTurn/repos",
    "events_url": "https://api.github.com/users/DecimalTurn/events{/privacy}",
    "received_events_url": "https://api.github.com/users/DecimalTurn/received_events",
    "type": "User",
    "site_admin": false
  },
  "created_at": "2024-08-26T19:39:32Z",
  "updated_at": "2024-08-26T19:39:32Z",
  "author_association": "OWNER",
  "body": "Let's strap on your boots!",
  "reactions": {
    "url": "https://api.github.com/repos/DecimalTurn/VBA-on-GitHub-Automations/issues/comments/2310943199/reactions",
    "total_count": 1,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 1
  },
  "performed_via_github_app": null
}

Versions

  • GitHub.Octokit.SDK v0.0.26
  • .NET v8.0

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working as documented

    Type

    No type

    Projects

    Status

    📆 Monthly

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions