# Path: valohai_cli/api.py
# def request(self, method, url, **kwargs) -> Response:  # type: ignore
#     api_error_class = kwargs.pop('api_error_class', APIError)
#     handle_errors = bool(kwargs.pop('handle_errors', True))
#     try:
#         resp = super().request(method, url, **kwargs)
#     except requests.ConnectionError as ce:
#         host = urlparse(ce.request.url).netloc
#         if 'Connection refused' in str(ce):
#             raise CLIException(
#                 f'Unable to connect to {host} (connection refused); try again soon.'
#             ) from ce
#         raise
# 
#     if handle_errors and resp.status_code >= 400:
#         cls = (APINotFoundError if resp.status_code == 404 else api_error_class)
#         raise cls(resp)
#     return resp
# 
# Path: valohai_cli/ctx.py
# @overload
# def get_project(dir: Optional[str] = None, require: Literal[True] = True) -> ProjectOrRemoteProject:
#     ...
# 
# Path: valohai_cli/git.py
# def get_current_commit(directory: str) -> str:
#     """
#     (Try to) get the current commit of the Git working copy in `directory`.
#     :param directory: Directory path.
#     :return: Commit SHA
#     """
#     return check_git_output(['git', 'rev-parse', 'HEAD'], directory).strip().decode()
# 
# Path: valohai_cli/table.py
# def print_table(
#     data: Any,
#     columns: Sequence[str] = (),
#     headers: Optional[Sequence[str]] = None,
#     format: Optional[str] = None,
#     **kwargs: Any,
# ) -> None:
#     if isinstance(data, dict) and not columns:
#         data = [{'key': key, 'value': value} for (key, value) in sorted(data.items())]
#         columns = ('key', 'value')
#     if not columns:
#         columns = sorted(data[0].keys())
#     if not headers:
#         headers = columns
#     assert len(headers) == len(columns), 'Must have equal amount of columns and headers'
# 
#     if not format:  # Auto-determine format from settings
#         format = settings.output_format
# 
#     if format == 'human':
#         htf = HumanTableFormatter(data=data, columns=columns, headers=headers, **kwargs)
#         htf.echo()
#     elif format == 'json':
#         print_json(data)
#     elif format in SV_SEPARATORS:
#         import csv
#         writer = csv.writer(sys.stdout, delimiter=SV_SEPARATORS[format], quoting=csv.QUOTE_MINIMAL)
#         writer.writerow(headers)
#         writer.writerows(pluck_printable_data(data, columns, lambda col_val: (n_str(col_val), str)))
#     else:
#         raise RuntimeError(f'Unknown print_table format: {format}')


import click
from valohai_cli.api import request
from valohai_cli.ctx import get_project
from valohai_cli.git import get_current_commit
from valohai_cli.table import print_table



@click.command()
def commits() -> None:
    """
    List the commits for the linked project.
    """

# Path: valohai_cli/api.py
# def request(self, method, url, **kwargs) -> Response:  # type: ignore
#     api_error_class = kwargs.pop('api_error_class', APIError)
#     handle_errors = bool(kwargs.pop('handle_errors', True))
#     try:
#         resp = super().request(method, url, **kwargs)
#     except requests.ConnectionError as ce:
#         host = urlparse(ce.request.url).netloc
#         if 'Connection refused' in str(ce):
#             raise CLIException(
#                 f'Unable to connect to {host} (connection refused); try again soon.'
#             ) from ce
#         raise
# 
#     if handle_errors and resp.status_code >= 400:
#         cls = (APINotFoundError if resp.status_code == 404 else api_error_class)
#         raise cls(resp)
#     return resp
# 
# Path: valohai_cli/ctx.py
# @overload
# def get_project(dir: Optional[str] = None, require: Literal[True] = True) -> ProjectOrRemoteProject:
#     ...
# 
# Path: valohai_cli/git.py
# def get_current_commit(directory: str) -> str:
#     """
#     (Try to) get the current commit of the Git working copy in `directory`.
#     :param directory: Directory path.
#     :return: Commit SHA
#     """
#     return check_git_output(['git', 'rev-parse', 'HEAD'], directory).strip().decode()
# 
# Path: valohai_cli/table.py
# def print_table(
#     data: Any,
#     columns: Sequence[str] = (),
#     headers: Optional[Sequence[str]] = None,
#     format: Optional[str] = None,
#     **kwargs: Any,
# ) -> None:
#     if isinstance(data, dict) and not columns:
#         data = [{'key': key, 'value': value} for (key, value) in sorted(data.items())]
#         columns = ('key', 'value')
#     if not columns:
#         columns = sorted(data[0].keys())
#     if not headers:
#         headers = columns
#     assert len(headers) == len(columns), 'Must have equal amount of columns and headers'
# 
#     if not format:  # Auto-determine format from settings
#         format = settings.output_format
# 
#     if format == 'human':
#         htf = HumanTableFormatter(data=data, columns=columns, headers=headers, **kwargs)
#         htf.echo()
#     elif format == 'json':
#         print_json(data)
#     elif format in SV_SEPARATORS:
#         import csv
#         writer = csv.writer(sys.stdout, delimiter=SV_SEPARATORS[format], quoting=csv.QUOTE_MINIMAL)
#         writer.writerow(headers)
#         writer.writerows(pluck_printable_data(data, columns, lambda col_val: (n_str(col_val), str)))
#     else:
#         raise RuntimeError(f'Unknown print_table format: {format}')


# Path: valohai_cli/commands/project/commits.py
import click
from valohai_cli.api import request
from valohai_cli.ctx import get_project
from valohai_cli.git import get_current_commit
from valohai_cli.table import print_table




@click.command()
def commits() -> None:
    """
    List the commits for the linked project.
    """

    project = get_project(require=True)