Skip to content

Bad URL construction when querying commits containing path parameters #3229

@tiborballa

Description

@tiborballa

Description of the problem, including code/CLI snippet

When using the path parameter in a project.commits.list query, an incorrect URL is constructed.

import gitlab
import logging
logging.basicConfig(level=logging.DEBUG)

GITLAB_TOKEN = ''
GITLAB_URL = 'https://gitlab.example.com'  # Fake url
PROJECT_ID = '7813'   
TARGET_PATH = 'test_folder'         

def list_commits_for_path(gl, project_id, path):
    project = gl.projects.get(project_id)

    new_commits = project.commits.list(path=path)
    return new_commits

if __name__ == "__main__":
    gl = gitlab.Gitlab(GITLAB_URL, private_token=GITLAB_TOKEN, ssl_verify=False)
    commits = list_commits_for_path(gl, PROJECT_ID, TARGET_PATH)
    for commit in commits:
        print(f"- {commit.id[:8]} | {commit.author_name} | {commit.created_at} | {commit.title}")

Expected Behavior

The correct URL should look like this:
https://gitlab.example.com/api/v4/projects/7813/repository/commits?path=test_folder

Actual Behavior

Debug level log message:

DEBUG:urllib3.connectionpool:https://gitlab.example.com:443 "GET /api/v4test_folder HTTP/1.1" 404 37

Based on the log, it seems the URL might be the following:

https://gitlab.example.com/api/v4test_folder

Specifications

  • python-gitlab version: 6.1.0
  • Gitlab server version (or gitlab.com): GitLab Enterprise Edition - v17.5.5-ee

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions