tan-tan-kanarek/github-php-client

Bug with Function: editAnIssue

Closed this issue · 3 comments

Hey there,

I run into a problem when I tried updating the state of an issue.

Whenever I tried to update my issue, I got the following error code:

In GitHubClientBase.php line 436:
                                                                                 
Expected status [200], actual status [422], URL [/repos/testOwner/testRepo/issues/87] 

So naturally I turned on the debug-log and got the following message:

{"message":"Invalid request.\n\nFor 'links/1/schema', \"{\\\"state\\\":\\\"closed\\\"}\" is not an object or null.","documentation_url":"https://developer.github.com/v3/issues/#edit-an-issue"}

Looks like the json-object got kinda destroyed.

I then tried to remove the following line in your editAnIssue-Function and got it working:

$data = json_encode($data);

Anyway, if I print out $data after the json encode, it looks just fine.

{"state":"closed"}

It almost seems like it gets json_encoded multiple times?

Do you have an idea how this issue arises or how to fix it without removing the $data = json_encode($data); - line?

So I just found out it gets json_encoded another time in GitHubClientBase.php on line: 306

if (@count($data))
{
     $content = json_encode($data, JSON_FORCE_OBJECT);
}

Since (@count($data)) will always return 1 on a json-object and it will always be a json-object in $data whenever you edit an issue, since it gets json_encoded before, that object will always get encoded a second time, which in my opinion leads to the error 422.

In my opinion one of those json_encodings is too much, either the first or the second one.
Or am I missing something?

One example Request that leads to the error is the following:

$client->issues->editAnIssue('myOwner', 'myRepo', null, myNumber, null, null, 'closed', null, null);

Thank a lot, solved here: #135