github gitlab twitter linkedin email
gitlab-cli : Interact with Gitlab from the command line, currently focusing on issues
Dec 9, 2016
4 minutes read

gitlab-cli a cli tool that I have written for interacting with Gitlab. Currently the tool focuses on working with issues for a project. It is written in Go and works cross-platform (works with Windows, Linux and OS X).

Refer to the project README page for installation instructions.

Here is what the command help says:

⏚ [shank:~] % gitlab

Usage: gitlab [OPTIONS] COMMAND [arg...]

Gitlab-CLI

Options:
  -v, --version    Show the version and exit

Commands:
  members      Work with project members
  issues       Work with project issues
  labels       Work with labels in this project

Run 'gitlab COMMAND --help' for more information on a command.

Whenever you run the gitlab command, it tries to find the Gitlab.com repository with which it has to interact. The tool does this by reading the remote-url for the remote titled origin in the current folder. Alternatively it supports the --pid flag for specifying the project in the form of <namespace>/<repositor-name> from any folder.

All the following examples are run from a demo project folder, which, on my pc, resides at /Users/shank/Projects/gitlab-cli-demo

⏚ [shank:~/Projects/gitlab-cli-demo] master ± git remote -v
origin  git@gitlab.com:shank/gitlab-cli-demo.git (fetch)
origin  git@gitlab.com:shank/gitlab-cli-demo.git (push)

The remote titled origin for my repository points to git@gitlab.com:shank/gitlab-cli-demo.git. So gitlab would identify my project id as shank/gitlab-cli-demo.

Lets try some commands.

So, what can I do with issues?

⏚ [shank:~/Projects/gitlab-cli-demo] master 2 ± gitlab issues --help

Usage: gitlab issues COMMAND [arg...]

Work with project issues

Commands:
  list         list the project issues
  create       Create issue
  delete       Delete issues
  close        Close Issues
  reopen       Reopen Issues
  assign       Assign Issues
  addlabel     Add label to Issues

Run 'gitlab issues COMMAND --help' for more information on a command.

Lets see how to create an issue.

⏚ [shank:~/Projects/gitlab-cli-demo] master 2 ± gitlab issues create --help

Usage: gitlab issues create [--pid] (--title | TITLE) [--assignee]

Create issue

Arguments:
  TITLE=""     title of the issue

Options:
  -p, --pid=""        / for the project with which to work. Default value is extracted from the url for remote 'origin'
  -t, --title=""      title of the issue
  -a, --assignee=""   username of the dev to whom the issue is to be assigned

Lets go ahead and create some issues.

⏚ [shank:~/Projects/gitlab-cli-demo] master ± gitlab issues create "first issue"
2016/12/09 19:35:49 pid: shank/gitlab-cli-demo
Issue created: 2
⏚ [shank:~/Projects/gitlab-cli-demo] master ± gitlab issues create "second issue"
2016/12/09 19:36:57 pid: shank/gitlab-cli-demo
Issue created: 3

Let’s list the current issues for this project.

⏚ [shank:~/Projects/gitlab-cli-demo] master ± gitlab issues list
2016/12/09 19:37:17 pid: shank/gitlab-cli-demo
    #ID #IID    TITLE           STATUS  ASSIGNED TO LABELS
3706109    3    second issue    opened
3706097    2    first issue     opened
*Close issue 3*.
⏚ [shank:~/Projects/gitlab-cli-demo] master 2 ± gitlab issues close 3
2016/12/09 19:38:04 pid: shank/gitlab-cli-demo
Issue #3706109 closeed

List the issues again.

⏚ [shank:~/Projects/gitlab-cli-demo] master ± gitlab issues list
2016/12/09 19:38:45 pid: shank/gitlab-cli-demo
    #ID #IID    TITLE           STATUS  ASSIGNED TO LABELS
3706109    3    second issue    closed
3706097    2    first issue     opened

The status for issue 3 is updated. But I wish to see only the issues that are currently open.

⏚ [shank:~/Projects/gitlab-cli-demo] master ± gitlab issues list -o
2016/12/09 19:43:31 pid: shank/gitlab-cli-demo
    #ID #IID    TITLE       STATUS  ASSIGNED TO LABELS
3706097    2    first issue opened

List the members for this project

⏚ [shank:~/Projects/gitlab-cli-demo] master ± gitlab members list
2016/12/09 19:43:52 pid: shank/gitlab-cli-demo
    #   USERNAME    NAME
18022   shank       Shashank Sharma

Assign this issue to shank

⏚ [shank:~/Projects/gitlab-cli-demo] master 2 ± gitlab issues assign shank 2
2016/12/09 19:44:49 pid: shank/gitlab-cli-demo
Issue #2 assigned to shank

List the issues again.

⏚ [shank:~/Projects/gitlab-cli-demo] master ± gitlab issues list
2016/12/09 19:45:33 pid: shank/gitlab-cli-demo
    #ID #IID    TITLE           STATUS  ASSIGNED TO     LABELS
3706109    3    second issue    closed
3706097    2    first issue     opened  Shashank Sharma

The “Assigned To” column has been updated correctly.

This is just a glimpse of what this tool is currently capable of. It is very much a work-in-progress. Please let me know which features should I add to it next by filing an issue on the project issues page.

Head over to the project and give it a go!

BTW, here is the screenshot of the issues page after running the above command :) issues



Back to posts