Draft: feat: Add url subcommand to glab project

Description

Added subcommand for printing URLs to files/branches

  • Support for permalinks
  • Open in browser
$ glab repo url -h
Display the URL of a project or its' file, or open it in the browser.


USAGE
  glab repo url [repository] [flags]

FLAGS
  -b, --branch string   Generate URL for a specific branch of the repository.
  -p, --permalink       Convert URL to permalink
  -w, --web             Open a project in the browser.

INHERITED FLAGS
  --help   Show help for this command.

EXAMPLES
  # View project URL for the current directory.
  # Must be a Git repository.
  $ glab repo url
  # Open repository in the web browser
  $ glab repo url -w                # same as glab repo view -w
  $ glab repo url -w -b branch name # same as glab repo view -w -b branch name

  # View project URL of specified name.
  # NOTE: If file or a directory exists at this path, it will be displayed instead.
  $ glab repo url my-project
  $ glab repo url user/repo
  $ glab repo url group/namespace/repo

  # View file/directory URL
  # Must be in a Git repository
  $ glab repo url path/to/existing/file

  # Open given file/directory in the web browser
  $ glab repo url path/to/existing/file -w
  # Permalink
  $ glab repo url path/to/existing/file -w -p

LEARN MORE
  Use 'glab <command> <subcommand> --help' for more information about a command.

Motivation

My current workflow is to find a specific line/file in a codebase, then glab repo view -w and clicking to the same line/file in the web UI, then sharing it with a colleague.

New workflow is to glab repo url -f path/to/file -p and this spits the link for me in the command line. I don't have to interface with the browser at all. This gets especially useful when the gitlab instance is down for some reason.

TODO: -l for specific line TODO: -s for specific source revision (commit)

Related Issues

Did not find a related issue.

How has this been tested?

The change to git.LatestCommit doesn't break other areas of the code, as the function is unused.

Tested manually with a repo on gitlab.com and one private repo:

$ glab repo url                                     # works
$ glab repo url -w                                  # works
$ glab repo url my-project                          # works
$ glab repo url user/repo                           # this gives 404 on private instance
$ glab repo url group/namespace/repo                # this too
$ glab repo url -f path/to/file                     # works
$ glab repo url -f path/to/file -w                  # works
$ glab repo url -f path/to/file -w -p               # works
$ glab repo url -f path/to/file -b branchname       # works
$ glab repo url -f path/to/file -b branchname -w    # works
$ glab repo url -f path/to/file -b branchname -w -p # works

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation
  • Chore (Related to CI or Packaging to platforms)
  • Test gap
Edited by Adam Procio

Merge request reports

Loading