octokit / dotnet-sdk

MIT License
58 stars 8 forks source link

The SDK return a List of String when it should return a List of Label [BUG]: #112

Closed Hossain2024 closed 3 months ago

Hossain2024 commented 3 months ago

What happened?

I am encountering an issue while trying to retrieve Label objects for an issue on GitHub.

https://github.dev/octokit/dotnet-sdk/blob/main/src/GitHub/Repos/Item/Item/Issues/IssuesRequestBuilder.cs

The GitHub.Models.Issue class defines the label property as a List. Based on the API response it should be a List<Label>

Here is the API call I used:

https://api.github.com/repos/microsoft/kiota/issues/5037

response from the API call (taken from postman)

    "url": "https://api.github.com/repos/microsoft/kiota/issues/5037",
    "repository_url": "https://api.github.com/repos/microsoft/kiota",
    "labels_url": "https://api.github.com/repos/microsoft/kiota/issues/5037/labels{/name}",
    "comments_url": "https://api.github.com/repos/microsoft/kiota/issues/5037/comments",
    "events_url": "https://api.github.com/repos/microsoft/kiota/issues/5037/events",
    "html_url": "https://github.com/microsoft/kiota/issues/5037",
    "id": 2437123502,
    "node_id": "I_kwDOE0q91s6RQ42u",
    "number": 5037,
    "title": "Missing properties on generated Python code models if `additionalProperties: false` on OpenAPI component schema",
    "user": {
        "login": "geometrikal",
        "id": 1187528,
        "node_id": "MDQ6VXNlcjExODc1Mjg=",
        "avatar_url": "https://avatars.githubusercontent.com/u/1187528?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/geometrikal",
        "html_url": "https://github.com/geometrikal",
        "followers_url": "https://api.github.com/users/geometrikal/followers",
        "following_url": "https://api.github.com/users/geometrikal/following{/other_user}",
        "gists_url": "https://api.github.com/users/geometrikal/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/geometrikal/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/geometrikal/subscriptions",
        "organizations_url": "https://api.github.com/users/geometrikal/orgs",
        "repos_url": "https://api.github.com/users/geometrikal/repos",
        "events_url": "https://api.github.com/users/geometrikal/events{/privacy}",
        "received_events_url": "https://api.github.com/users/geometrikal/received_events",
        "type": "User",
        "site_admin": false
    },
    "labels": [
        {
            "id": 2603543073,
            "node_id": "MDU6TGFiZWwyNjAzNTQzMDcz",
            "url": "https://api.github.com/repos/microsoft/kiota/labels/type:bug",
            "name": "type:bug",
            "color": "d73a4a",
            "default": false,
            "description": "A broken experience"
        },
        {
            "id": 3016728568,
            "node_id": "MDU6TGFiZWwzMDE2NzI4NTY4",
            "url": "https://api.github.com/repos/microsoft/kiota/labels/Python",
            "name": "Python",
            "color": "0BBE2D",
            "default": false,
            "description": ""
        },
        {
            "id": 3162613472,
            "node_id": "MDU6TGFiZWwzMTYyNjEzNDcy",
            "url": "https://api.github.com/repos/microsoft/kiota/labels/WIP",
            "name": "WIP",
            "color": "F683F1",
            "default": false,
            "description": ""
        }
    ],
    "state": "closed",
    "locked": false,
    "assignee": {
        "login": "baywet",
        "id": 7905502,
        "node_id": "MDQ6VXNlcjc5MDU1MDI=",
        "avatar_url": "https://avatars.githubusercontent.com/u/7905502?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/baywet",
        "html_url": "https://github.com/baywet",
        "followers_url": "https://api.github.com/users/baywet/followers",
        "following_url": "https://api.github.com/users/baywet/following{/other_user}",
        "gists_url": "https://api.github.com/users/baywet/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/baywet/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/baywet/subscriptions",
        "organizations_url": "https://api.github.com/users/baywet/orgs",
        "repos_url": "https://api.github.com/users/baywet/repos",
        "events_url": "https://api.github.com/users/baywet/events{/privacy}",
        "received_events_url": "https://api.github.com/users/baywet/received_events",
        "type": "User",
        "site_admin": false
    },
    "assignees": [
        {
            "login": "baywet",
            "id": 7905502,
            "node_id": "MDQ6VXNlcjc5MDU1MDI=",
            "avatar_url": "https://avatars.githubusercontent.com/u/7905502?v=4",
            "gravatar_id": "",
            "url": "https://api.github.com/users/baywet",
            "html_url": "https://github.com/baywet",
            "followers_url": "https://api.github.com/users/baywet/followers",
            "following_url": "https://api.github.com/users/baywet/following{/other_user}",
            "gists_url": "https://api.github.com/users/baywet/gists{/gist_id}",
            "starred_url": "https://api.github.com/users/baywet/starred{/owner}{/repo}",
            "subscriptions_url": "https://api.github.com/users/baywet/subscriptions",
            "organizations_url": "https://api.github.com/users/baywet/orgs",
            "repos_url": "https://api.github.com/users/baywet/repos",
            "events_url": "https://api.github.com/users/baywet/events{/privacy}",
            "received_events_url": "https://api.github.com/users/baywet/received_events",
            "type": "User",
            "site_admin": false
        }
    ],

I want to get the Labels field of this issue which is a List<Label>.

"labels": [
        {
            "id": 2603543073,
            "node_id": "MDU6TGFiZWwyNjAzNTQzMDcz",
            "url": "https://api.github.com/repos/microsoft/kiota/labels/type:bug",
            "name": "type:bug",
            "color": "d73a4a",
            "default": false,
            "description": "A broken experience"
        },
        {
            "id": 3016728568,
            "node_id": "MDU6TGFiZWwzMDE2NzI4NTY4",
            "url": "https://api.github.com/repos/microsoft/kiota/labels/Python",
            "name": "Python",
            "color": "0BBE2D",
            "default": false,
            "description": ""
        }
   ]

Here I am trying to get the Labels field of an issue. The type of the label field is a List<String> but I expect the labels field to be a List

  {
            "id": 2603543073,
            "node_id": "MDU6TGFiZWwyNjAzNTQzMDcz",
            "url": "https://api.github.com/repos/microsoft/kiota/labels/type:bug",
            "name": "type:bug",
            "color": "d73a4a",
            "default": false,
            "description": "A broken experience"
  },
image

on line 3 I get the following error message

 Cannot implicitly convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.List<Label>'[CS0029](https://msdn.microsoft.com/query/roslyn.query?appId%3Droslyn%26k%3Dk%28CS0029%29)
Converting null literal or possible null value to non-nullable type.[CS8600](https://msdn.microsoft.com/query/roslyn.query?appId%3Droslyn%26k%3Dk%28CS8600%29)
List<string>? GitHub.Models.Issue.Labels { get; set; }
'Labels' may be null here.

I am currently receiving a List where the size is 2(for example) and both string [0] and string [1] are null even when [0] has a value and [1] has a value. This is contrary to the actual values in the response. Why is the labels field from the API returning a List instead of a List

Versions

0.0.24

Code of Conduct

github-actions[bot] commented 3 months ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

kfcampbell commented 3 months ago

Hi @Hossain2024, you're simply confusing two endpoints. The GetAllIssuesAsync endpoint (returning multiple issues from the GitHub API) returns a list of label strings. The request to return a single issue returns a more fleshed-out labels object.

If you want to get a single issue that contains all the information about its labels, you can make a request like this:

            var labels = await gitHubClient.Repos["microsoft"]["kiota"].Issues[5037].Labels.GetAsync();
            foreach (var label in labels)
            {
                Console.WriteLine("Label: " + label.Name);
                Console.WriteLine("Label ID: " + label.Id);
                Console.WriteLine("Label Description: " + label.Description);
                Console.WriteLine("Label Color: " + label.Color);
            }

which, if you've initialized your client correctly, will print something like the following:

Label: type:bug
Label ID: 2603543073
Label Description: A broken experience
Label Color: d73a4a
Label: Python
Label ID: 3016728568
Label Description:
Label Color: 0BBE2D
Label: WIP
Label ID: 3162613472
Label Description:
Label Color: F683F1

I hope that helps!