wemakecustom / gitlab-composer

Gitlab Composer repository
163 stars 44 forks source link

$repos->blob(..) returns array, updated to account #4

Closed CptLemming closed 10 years ago

CptLemming commented 10 years ago

Under my gitlab install, $repos->blob(..) returns an array, not a string as expected. As I'm not sure if this is the same behaviour across the board added ternary statement to catch this.

lemoinem commented 10 years ago

Hi!

Looking at https://github.com/m4tthumphrey/php-gitlab-api/blob/master/lib/Gitlab/HttpClient/Message/Response.php it looks like blob is supposed to return an array (since the json is decoded).

Could you ensure you have the latest version of php-gitlab-api (running composer update) and if this persist, could you paste what is returned by the call to blob, because it looks like invalid JSON is returned.

CptLemming commented 10 years ago

This function in packages.php tries to json_decode the output from $repos->blob

$fetch_composer = function($project, $ref) use ($repos) {
    try {
        $data = array();
        $c = $repos->blob($project['id'], $ref, 'composer.json');
        $composer = json_decode($c, true);

        if (empty($composer['name']) || $composer['name'] != $project['path_with_namespace']) {
            return false; // packages must have a name and must match
        }

        return $composer;
    } catch (RuntimeException $e) {
        return false;
    }
};

This was altered recently in 1d2d2d56. As I wasn't sure if this behaviour was required by others, instead of removing the json_decode I added an is_array check.

lemoinem commented 10 years ago

Very good point,

We will check this and come back to you with an update. Thanks!

2014/1/23 Ashley Wilson notifications@github.com

This function in packages.php tries to json_decode the output from $repos->blob

$fetch_composer = function($project, $ref) use ($repos) { try { $data = array(); $c = $repos->blob($project['id'], $ref, 'composer.json'); $composer = json_decode($c, true);

    if (empty($composer['name']) || $composer['name'] != $project['path_with_namespace']) {
        return false; // packages must have a name and must match
    }

    return $composer;
} catch (RuntimeException $e) {
    return false;
}

};

This was altered recently in 1d2d2d5https://github.com/wemakecustom/gitlab-composer/commit/1d2d2d56. As I wasn't sure if this behaviour was required by others, instead of removing the json_decode I added an is_array check.

— Reply to this email directly or view it on GitHubhttps://github.com/wemakecustom/gitlab-composer/pull/4#issuecomment-33146004 .

lavoiesl commented 10 years ago

I will be accepting this PR because the json_decode was introduced in #1 because it was incorrectly returning a string for unknown reasons. Using a ternary is the safest approach in the mean time.

Updating the API dependency should not change anything because the ->blob() function was never updated.