kenju
kenju

Reputation: 5954

How to use issues of Gitlab from terminal?

I know you can use Github issues on the command line by installing ghi.

However, is there any way to use similar tools for listing/adding/removing/editing issues of repositories on Gitlab ?

Upvotes: 19

Views: 8022

Answers (5)

Saaru Lindestøkke
Saaru Lindestøkke

Reputation: 2564

This answer does not address your whole question, just a small part.

To create an issue programmatically you can use the New issue via URL feature.

It allows you to create an issue with a title and description (using a template if needed) via an URL with parameters.

The URL looks like this:

https://gitlab.instance.url/group_name/project_name/issues/new?issue[title]=Your%20issue%20title&issue[description]=Issue%20description

I've wrapped that in an AHK shortcut bound to CTRLALTT. I've inlcuded the URLEncode function for completeness.

;; Create issue on Gitlab tasks list with selected text as issue title
^!t::
ClipSaved := ClipboardAll
Sleep, 300
Send ^c
title := URLEncode(clipboard)
mainURL := "https://gitlab.instance.com/gitlab/group_name/project/issues/new?issue[title]="
fullURL := mainURL title
Run, %fullURL%
Clipboard := ClipSaved
return

UrlEncode( String )
{
    OldFormat := A_FormatInteger
    SetFormat, Integer, H

    Loop, Parse, String
    {
        if A_LoopField is alnum
        {
            Out .= A_LoopField
            continue
        }
        Hex := SubStr( Asc( A_LoopField ), 3 )
        Out .= "%" . ( StrLen( Hex ) = 1 ? "0" . Hex : Hex )
    }

    SetFormat, Integer, %OldFormat%

    return Out
}

Upvotes: 1

Daniel da Rosa
Daniel da Rosa

Reputation: 101

GLab seems to be a great option.

GLab is an open source Gitlab Cli tool written in Go (golang) to help work seamlessly with Gitlab from the command line. Work with issues, merge requests, watch running pipelines directly from your CLI among other features.

https://github.com/profclems/glab

Upvotes: 10

djsumdog
djsumdog

Reputation: 2710

It looks like someone has written a CLI tool for gitlab's API:

https://python-gitlab.readthedocs.io/en/stable/cli.html

pip3 install --user python-gitlab
$EDITOR ~/.python-gitlab.cfg 

Sample config for gitlab's main site, but you can add your own local instances too:

[global]
default = gitlab
ssl_verify = true
timeout = 5

[gitlab]
url = https://gitlab.com
private_token = <insert API token here>
api_version = 4

Make sure your path inlcudes /home/<username>/.local/bin/

Then from within your gitlab repo:

gitlab issue list

I'm not sure if it's as complete as ghi, but it looks like it supports a good amount of the API.

Upvotes: 2

kenju
kenju

Reputation: 5954

Answering my own question.

At first I thought ghi would be also available on Gitlab, but after that I found out below issues of ghi, in which the owner of ghi says currently it does not support Gitlab.

Just in case you spend time searching for the compatibility between ghi and Gitlab usage.

I'm not opposed to the feature (if introduced simply), but G.H.I. is definitely built around GitHub Issues. I'm also not a user of GitLab, so the enhancement would have to come from someone else.

https://github.com/stephencelis/ghi/issues/135

Upvotes: 1

VonC
VonC

Reputation: 1328332

You have a similar wrapper (in python, not ruby) with Itxaka/pyapi-gitlab

git = gitlab.Gitlab(host=host)
git.login(user=user, password=password)
git.getall(git.getprojects)

git.getissues(page=1, per_page=40)

In ruby, that would be NARKOZ/gitlab:

# set an API endpoint
Gitlab.endpoint = 'http://example.net/api/v3'
# => "http://example.net/api/v3"

# set a user private token
Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
# => "qEsq1pt6HJPaNciie3MG"

# configure a proxy server
Gitlab.http_proxy('proxyhost', 8888)
# proxy server w/ basic auth
Gitlab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere')

# list projects
Gitlab.projects(per_page: 5)

It can fetch issues.

Upvotes: 5

Related Questions