- edited description
create repo error
the following code errors
$repo = new Bitbucket\API\Repositories\Repository;
$repo->getClient()->addListener(
new Bitbucket\API\Http\Listener\OAuthListener($oauth_params)
);
// now you can access protected endpoints as consumer owner
$response = $repo->create('company','new_repo');
investigating this the problem lays with in the create method currently the method test the $param parameter like so
// allow developer to directly specify params as json if (s)he wants.
if (!empty($params) && is_array($params)) {
$params = json_encode(array_merge(
array(
'scm' => 'git',
'name' => $repo,
'is_private' => true,
'description' => 'My secret repo',
'forking_policy' => 'no_forks',
),
$params
));
}
but as the default is array()
the above test will always return false if $params
is supplied.
this can be fixed multiple way but the easiest would be to remove the test and to all way merge the arrays, and to force $params
by altering the signature
like so array $params = array()
then the if statement could be removed completely and would look something liike this.
$params = json_encode(array_merge(
array(
'scm' => 'git',
'name' => $repo,
'is_private' => true,
'description' => 'My secret repo',
'forking_policy' => 'no_forks',
),
$params
));
Comments (10)
-
reporter -
@gerryghall Can you please run a test with develop branch and confirm that the issue is fixed before I tag ?
-
reporter I have ran 3 tests 2 of which passed the third passed an empty sting like so.
$response = $repo->create('company','repo', '');
this fails as I would except a
InvalidArgumentException
to be thrown but gotWarning: array_merge(): Argument #2 is not an array
which then escalates to a500
by the REST API"{"error": {"message": "'NoneType' object has no attribute 'iteritems'", "id": "c792d08035c44f14b5e8c3807e90ee22"}}"
I do believe using type hinting will simplify the method.
-
Added verification for empty string. You can test the develop branch.
I do believe using type hinting will simplify the method.
I can't typehint $params as array, because it can also be a JSON string and on top of that I would prefer not breaking the API before 1.0 release.
-
reporter far point.
-
reporter this may provide the desired effect
// allow developer to directly specify params as json if (s)he wants. if ('string' === gettype($params)) { if(!($params = json_decode($params, true))){ throw new \InvalidArgumentException('Invalid JSON provided.'); } }
-
Did you tried again the develop branch and you still have problems ?
-
reporter I have retested and all passes I hadn't pulled your changes. I have also created a test that asserts the exception ill send thought a Pull request just shortly.
FYI the about yields the same with only 1 conditional statement
-
I have retested and all passes I hadn't pulled your changes.
Please be more explicit.
- Did you test the latest changes from develop branch ?
- The reported problem has been solved ?
- Do you still have problems regarding reported issue ?
-
reporter - changed status to resolved
fixed
- Log in to comment