sparkfabrik / sparktool

Sparktool CLI
3 stars 0 forks source link

Gitlab: Auto append of trailing slash and api version on gitlab url #73

Closed paolomainardi closed 9 years ago

paolomainardi commented 9 years ago

Right now we have to specify the full url, fe: "http://gitlab.example.com/api/v3/" including the trailing slash.

We should accept url on this form:

Checking at runtime the appropriate values.

A quick fix:

    protected function initClient()
    {
        if (empty($this->client)) {
            $gitlab_url = $this->config['gitlab_url'];
            if (substr($gitlab_url, -1) !== '/') {
                $gitlab_url .= '/';
            }
            $gitlab_url .= 'api/v3/';
            $this->client = new \Gitlab\Client(
                $gitlab_url
            );
            $this->client->authenticate($this->config['gitlab_token'], \Gitlab\Client::AUTH_URL_TOKEN);
            if (empty($this->client)) {
                throw new \Exception('Cannot connect to redmine client, check your configurations.');
            }
        }
    }

Take note that we are hardcoding the "api/v3" to the URL, to me now is acceptable.

vincenzodibiaggio commented 9 years ago

Ok for the trailing slash but I guess that is better If we manage the api version in a more transparent way (with a configuration tool maybe? see https://github.com/sparkfabrik/sparktool/issues/72#issuecomment-134894998)

paolomainardi commented 9 years ago

Yep, we can implement a new default configuration parameter that can be ovverided by the user, for example `gitlab_api_version: v3' where v3 is the default value auto-created by the tool.

vincenzodibiaggio commented 9 years ago

MR https://github.com/sparkfabrik/sparktool/pull/74

paolomainardi commented 9 years ago

Merged.