chaoss / grimoirelab-elk

GNU General Public License v3.0
60 stars 121 forks source link

GitlabOcean backend doesn't cater for subgroups #946

Open StingRayZA opened 4 years ago

StingRayZA commented 4 years ago

Hi

(apologies if this should rather be logged at https://github.com/chaoss/grimoirelab-perceval)

I have a gitlab site URL that looks something like this:

https://my.gitlab.instance.internal.com/groupname/subgroupname/projectname

When the GitlabOcean gets initialised and get_perceval_params_from_url is called, the 'groupname' from the URL gets lost. As a result, all the future interactions that try to 'rebuild' the URL and/or the API URL get a 404 error as they build the following URLs, which don't exist:

https://my.gitlab.instance.internal.com/subgroupname/projectname or https://my.gitlab.instance.internal.com/api/v4/projects/subgroupname%2Fprojectname

I've hacked in a fix by replacing this line in grimoire_elk/raw/gitlab.py:

        owner = repo.split('/')[-2]

with this:

        fields = len(repo.split('/'))
        if fields == 5:
            owner = repo.split('/')[-2]
        else:
            grouplayers = fields - 4
            grouplist = []
            for i in range(grouplayers):
                grouplist.append(repo.split('/')[3+i])
            owner = "%2F".join(grouplist)

In any case, I think we should be perhaps be preserving the / characters, and then when the url gets assembled passing the owner through a urllib.parse.quote('/', safe='') call.