azure-devops-cli-extension icon indicating copy to clipboard operation
azure-devops-cli-extension copied to clipboard

[Feature Request] `az repos show` should auto-detect `--repository` via git config

Open MattKotsenas opened this issue 1 year ago • 1 comments

Related command

az repos show

Is your feature request related to a problem? Please describe.

I work across many repos, and it's often useful to jump to the Azure DevOps repo that corresponds to a locally cloned repository.

It would be nice if I could run az repos show --open and have the CLI automatically detect the repository from the git config, as it does for --org and --project. Instead, I have to pass the repository name explicitly via the --repository parameter.

Describe the solution you'd like

I would like for --repository to be auto-detected when inside a git repo, as it already is for --organization and --project.

Describe alternatives you've considered

Currently I have a cumbersome PowerShell workaround like this:

az repos show --open --repository "$(((git config --get remote.origin.url) -split '_git/')[-1])"

MattKotsenas avatar Feb 02 '24 07:02 MattKotsenas

I've never contributed to the repo before, but following the dev setup guide I was able to get a local version of the extension running, and it appears that a change like this should be sufficient:

diff --git a/azure-devops/azext_devops/dev/repos/repository.py b/azure-devops/azext_devops/dev/repos/repository.py
index f5baa86..4b4de04 100644
--- a/azure-devops/azext_devops/dev/repos/repository.py
+++ b/azure-devops/azext_devops/dev/repos/repository.py
@@ -95,7 +95,7 @@ def update_repo(repository, default_branch=None, name=None, organization=None, p
     return repository
 
 
-def show_repo(repository, organization=None, project=None, detect=None, open=False):  # pylint: disable=redefined-builtin
+def show_repo(repository=None, organization=None, project=None, detect=None, open=False):  # pylint: disable=redefined-builtin
     """Get the details of a Git repository.
     :param repository: Name or ID of the repository.
     :type repository: str
@@ -108,7 +108,8 @@ def show_repo(repository, organization=None, project=None, detect=None, open=Fal
         organization=organization,
         project=project,
         project_required=True,
-        repo=repository)
+        repo=repository,
+        repo_required=True)
     git_client = get_git_client(organization)
     repository = git_client.get_repository(project=project, repository_id=repository)
     if open:

MattKotsenas avatar Feb 02 '24 07:02 MattKotsenas