Exposes some of the Gitlab API functionality for operations on files
    in a Gitlab repository.

    Example:

        nornir.run(files.gitlab,
                   action="create",
                   url="https://gitlab.localhost.com",
                   token="ABCD1234",
                   repository="test",
                   filename="config",
                   ref="master")

    Arguments:
        dry_run: Whether to apply changes or not
        url: Gitlab instance URL
        token: Personal access token
        repository: source/destination repository
        filename: source/destination file name
        content: content to write
        action: ``create``, ``update``, ``get``
        branch: destination branch
        destination: local destination filename (only used in get action)
        ref: branch, commit hash or tag (only used in get action)
        commit_message: commit message

    Returns:
        Result object with the following attributes set:
            * changed (``bool``):
            * diff (``str``): unified diff

def gitlab(
    task: Task,
    url: str,
    token: str,
    repository: str,
    filename: str,
    content: str = "",
    action: str = "create",
    dry_run: bool = False,
    branch: str = "master",
    destination: str = "",
    ref: str = "master",
    commit_message: str = "",
) -> Result:
    """
    Exposes some of the Gitlab API functionality for operations on files
    in a Gitlab repository.

    Example:

        nornir.run(files.gitlab,
                   action="create",
                   url="https://gitlab.localhost.com",
                   token="ABCD1234",
                   repository="test",
                   filename="config",
                   ref="master")

    Arguments:
        dry_run: Whether to apply changes or not
        url: Gitlab instance URL
        token: Personal access token
        repository: source/destination repository
        filename: source/destination file name
        content: content to write
        action: ``create``, ``update``, ``get``
        branch: destination branch
        destination: local destination filename (only used in get action)
        ref: branch, commit hash or tag (only used in get action)
        commit_message: commit message

    Returns:
        Result object with the following attributes set:
            * changed (``bool``):
            * diff (``str``): unified diff

    """
    dry_run = task.is_dry_run(dry_run)

    session = requests.session()
    session.headers.update({"PRIVATE-TOKEN": token})

    if commit_message == "":
        commit_message = "File created with nornir"

    pid = _get_repository(session, url, repository)

    if action == "create":
        diff = _create(
            task, session, url, pid, filename, content, branch, commit_message, dry_run
        )
    elif action == "update":
        diff = _update(
            task, session, url, pid, filename, content, branch, commit_message, dry_run
        )
    elif action == "get":
        diff = _get(task, session, url, pid, filename, destination, ref, dry_run)
    return Result(host=task.host, diff=diff, changed=bool(diff))