Giter VIP home page Giter VIP logo

lab's Introduction

git + = gitlab

Build Status Go Report Card codecov Join the chat

Donate

lab interacts with repositories on GitLab, including creating/editing merge requests, issues, milestones, snippets and CI pipelines.

The development team has focused on keeping lab a simple and intuitive command line interface for commands provided in the GitLab API. lab's aim is to provide GitLab users an experience similar to the GitLab WebUI with respect to errors and messages.

Usage recommendation

One can use lab as a Git alias, integrating seamlessly to their Git workflow.

$ cat ~/.gitconfig
...
[alias]
    lab = "!lab"
    lab-i = "!lab issue"
    li = "!lab issue"

$ git lab mr list
$ git lab-i close
$ git li create

Also, lab can be set as shell aliases:

alias mrlist="lab mr list"

Installation

In compilation-time, lab depends only on other Go external modules, defined at go.mod. At runtime, git is required as many git commands are used by lab to retrieve local repository information.

Homebrew

brew install lab

NixOS

nix-env -f '<nixpkgs>' -iA gitAndTools.lab

Scoop

scoop install lab

Alpine

apk add lab

Bash

In case you don't want to install lab using any of the above package managers you can use the Bash script available:

⚠️ The script will install lab into /usr/local/bin/.

curl -s https://raw.githubusercontent.com/zaquestion/lab/master/install.sh | sudo bash

⚠️ Please take care when executing scripts in this fashion. Make sure you trust the developer providing the script and consider peeking at the install script itself (ours is pretty simple ;)

PreBuilt Binaries

Head to the releases page and download your preferred release.

Source

For building lab from source it's required Go 1.17+. Older versions (ie. 1.15) might still be able to build lab, but warnings related to unsupported go.mod format might be prompted.

git clone [email protected]:zaquestion/lab
cd lab
go install -ldflags "-X \"main.version=$(git rev-parse --short=10 HEAD)\"" .

or

make install

Configuration

lab needs your GitLab information in order to interact with to your GitLab instance. There are several ways to provide this information to lab:

Fresh start

When lab is executed for the first time, no suitable configuration found, it will prompt for your GitLab information. For example:

$ lab
Enter default GitLab host (default: https://gitlab.com):
Enter default GitLab token:

These informations are going to be save it into ~/.config/lab/lab.toml and won't be asked again. In case multiple projects require different information (ie. gitlab.com and a self-hosted GitLab service), using different configuration files as explained in the section below.

Configuration file

The most common option is to use lab configuration files, which can be placed in different places in an hierarchical style. The Tom's Obvious, Minimal Language (TOML) is used for the configuration file.

When a local configuration file is present (./lab.toml), no other configuration file will be checked, this will be the only one used for looking up required information.

However, other two options are possible:

  1. User-specific: ~/.config/lab/lab.toml
  2. Worktree-specific: .git/lab/lab.toml

These two files are merged before lab runs, meaning that they're complementary to each other. One thing is important to note though, options set in the worktree configuration file overrides (take precedence over) any value set in the user-specific file.

An example of user-specific configurations can be found below. As seen in the example file below, any command options specified by --help (for example lab mr show --help, or lab issue edit --help) can be set in the configuration file using TOML format.

[core]
  host = "https://gitlab.com"
  token = "1223334444555556789K"
  user = "yourusername"

[mr_checkout]
  force = true

[mr_create]
  force-linebreak = true
  draft = true

[mr_edit]
  force-linebreak = true

Local environment variables

If running lab locally, the variables LAB_CORE_HOST and LAB_CORE_TOKEN can be used, preventing configuration file creation/update. For example to use gitlab.com do:

export LAB_CORE_HOST="https://gitlab.com"

CI environment variables

The environment variables CI_PROJECT_URL, CI_JOB_TOKEN and GITLAB_USER_LOGIN, intended to be used in a CI environment, can be set to prevent any configuration file creation/update. Also, any of these take precedence over all other options.

Completions

lab provides completions for Bash, Elvish, Fish, Oil, Powershell, Xonsh and Zsh. Scripts can be directly sourced (though using pre-generated versions is recommended to avoid shell startup delay):

# bash (~/.bashrc)
source <(lab completion)

# elvish (~/.elvish/rc.elv)
eval (lab completion|slurp)

# fish (~/.config/fish/config.fish)
lab completion | source

# oil
source <(lab completion)

# powershell (~/.config/powershell/Microsoft.PowerShell_profile.ps1)
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
lab completion | Out-String | Invoke-Expression

# xonsh (~/.config/xonsh/rc.xsh)
COMPLETIONS_CONFIRM=True
exec($(lab completion xonsh))

# zsh (~/.zshrc)
source <(lab completion zsh)

Contributing

We welcome all contributors and their contributions to lab! See the contribution guide.

What about GLab?

Both glab and lab are open-source tools with the same goal of bringing GitLab to your command line and simplifying the developer workflow. In many ways lab is to hub, what glab is to gh.

If you're looking for a tool like hub, less opinionated, that feels like using git and allows you to interact with GitLab then lab is for you. However, if you're looking for a more opinionated tool intended to simplify your GitLab workflows, you might consider using glab.

CC0
To the extent possible under law, Zaq? Wiedmann has waived all copyright and related or neighboring rights to Lab. This work is published from: United States.

lab's People

Contributors

1ace avatar adamryman avatar alexkalderimis avatar atenart avatar bmeneg avatar bmess avatar ch00k avatar claytonrcarter avatar craftamap avatar dependabot[bot] avatar doits avatar fmuellner avatar ianfoo avatar johnvillalovos avatar kovetskiy avatar krobelus avatar leipert avatar letientai299 avatar lukmdo avatar marionebl avatar martindelille avatar marwatk avatar matthewdale avatar nkprince007 avatar prarit avatar rsteube avatar sding3 avatar tydavis avatar zampierilucas avatar zaquestion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lab's Issues

Addition of verbose flag

$ lab issue ls --verbose
#1 Issue title
        Issue link
        Issue description
        Assignees, Labels
#2 Issue title
        Issue link
        Issue description
        Assignees, Labels
...

Would love to have such an interface.

lab mr merge

lab mr merge [remote] <id>

Merge the checked out or provided mr

Lab shouldn't store access credentials in .gitconfig

It's not uncommon for users to version control their dotfiles. A common file to version control is ~/.gitconfig.

Lab currently stores and retrieves a users access token from git config. Having my Gitlab access token stored in .gitconfig means that I can no longer version control this file, which it important to me as this file contains shared configuration for all of my projects on my system.

If I understand the documentation for Lab currently, I could add my access credentials to .git/config in each projects repository on my system, but this is a very tedious and cumbersome workaround to the issue.

github/hub Helps it's users in this case by storing access tokens in an application specific config file ~/.config/hub, which is a file that's less likely to be version controlled by users. I think Lab should use a similar solution, or at least provide it as an alternative credential store to the current git config system.

github/hubs implementation is here, if it helps.

SIGSEGV in gitlab.FindProject

#Most commands I try end with the same error, e.g.:

$ lab snippet list
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x13d6564]

goroutine 1 [running]:
github.com/zaquestion/lab/internal/gitlab.FindProject(0xc42001c18c, 0x13, 0xc42001c18c, 0x13, 0x0)
	/home/travis/gopath/src/github.com/zaquestion/lab/internal/gitlab/gitlab.go:98 +0x144
github.com/zaquestion/lab/cmd.glob..func23(0x1768f00, 0x178fbc8, 0x0, 0x0)
	/home/travis/gopath/src/github.com/zaquestion/lab/cmd/snippetList.go:48 +0x2fe
github.com/zaquestion/lab/vendor/github.com/spf13/cobra.(*Command).execute(0x1768f00, 0x178fbc8, 0x0, 0x0, 0x1768f00, 0x178fbc8)
	/home/travis/gopath/src/github.com/zaquestion/lab/vendor/github.com/spf13/cobra/command.go:702 +0x2c6
github.com/zaquestion/lab/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x1768ac0, 0x178fbc8, 0xc42017c020, 0xc4201ba000)
	/home/travis/gopath/src/github.com/zaquestion/lab/vendor/github.com/spf13/cobra/command.go:783 +0x30e
github.com/zaquestion/lab/vendor/github.com/spf13/cobra.(*Command).Execute(0x1768ac0, 0xc420080190, 0x2)
	/home/travis/gopath/src/github.com/zaquestion/lab/vendor/github.com/spf13/cobra/command.go:736 +0x2b
github.com/zaquestion/lab/cmd.Execute()
	/home/travis/gopath/src/github.com/zaquestion/lab/cmd/root.go:168 +0x2d7
main.main()
	/home/travis/gopath/src/github.com/zaquestion/lab/main.go:65 +0x499

My company runs GitLab on internal VPN with custom domain git.ccl, so my lab.hcl looks like this:

"core" = {
  "host" = "https://git.ccl"

  "token" = "<removed>"

  "user" = "<removed>"
}

The project where I try to run lab in has SSH remote (i.e.: origin [email protected]:group/project-name.git).

Version info:
macOS 10.13.3 (17D47)
git version 2.16.1
hub version 2.2.9
lab version 0.9.4 (via brew)

I am not sure if there is any flag or env variable to crank up verbosity. What other information can help you?

Support setting the remote during `lab mr checkout`

Flags:
-t, --track set checked out branch to track mr source remote, adds remote if needed

It probably makes since to detect if the mr source remote matches the forkedFromRemote, or forkRemote and to set tracking. Otherwise adding a new remote using the username scheme.

Add additional validation when creating merge requests

I've run into 2 cases where lab permitted creating an MR when it really shouldn't have.

  • source branch was not present on source remote (creates an MR with an unavailable branch)
  • source branch is already up to day with target
    • observed when forgetting to commit changes and starting an MR

token asked for wrong domain

$ lab remote -v
Enter default GitLab host (default: https://gitlab.com): https://gitlab.example.net 
Enter default GitLab user: glen
Enter default GitLab token (scope: api ):
Create here: https://gitlab.com/profile/personal_access_tokens[]

should say: https://gitlab.example.net/profile/personal_access_tokens

also, there's some usability issue, the cursor is placed in [], i.e without newline. perhaps print that information before prompting user (swap two last lines)

also, the stty echo needs to be trurned off, not to show token when pasting it to terminal.

Proposal: Handling for "upstream" remote naming scheme

In Short

We can leverage the GitLab API to inform us if a repo is a fork or not and transparently support the "upstream" remote naming scheme.

Context

Currently a user clones a non-fork repo with the expectation that it will be setup as the "origin" remote. Later using lab fork to create a remote with their username. This is a somewhat newer approach to managing remotes.

Many people still use the strategy described and recommend here: https://help.github.com/articles/fork-a-repo/ and clone their personal fork as "origin". Later using git remote add upstream <repo> to configure their remote.

lab bias toward the former approach inline with how hub operates.

Proposed

If a solution can be reached that allows both approaches to transparently coexist without additional configuration by the user it would be highly considered. Otherwise the former approach will take precedent.

When cloning:

lab clone <personal-fork> 
  1. lab clones repo (remote is "origin")
  2. lab checks if repo is a fork
  3. If so, lab adds the forked-from repo as a remote named "upstream"

When forking an unforked repo:
The bare lab fork command is not useful for "upstream" usecases, instead we'll optionally accept an argument for this case

lab fork <repo>
  1. lab forks repo in GitLab
  2. lab clones forked repo
  3. lab adds forked-from repo as remote "upstream"

When creating merge requests:
lab always uses the tracked remote and current branch as the sourceRemote and soureceBranch, this will work the same for "upstream" cases. Currently lab defaults to and only support merge requests into "origin", to support "upstream" we will simply check for the existence of that remote and use that instead.

Finally
These changes should transparently support both world views and are able to be implemented cleanly within lab minimizing longer term maintenance costs for both approaches.

lab mr checkout is checking out from the current branch

ref is getting fetched to head instead of branch name. So the branch doesn't point to the ref and the checkout is incorrect.

$ git mr checkout 587
From gitlab.com/phony
 * branch              refs/merge-requests/111/head -> FETCH_HEAD
   1234567..1234567             -> phony
Switched to branch 'phony'

Support mr create target

It would be awesome, if a target could be specified during a merge request. I was thinking something like:

$ lab mr create --target play-1.2

Command `lab mr` returns error

After running lab mr and writing a message and exiting the editor I get the error:

2017/09/06 17:42:14 POST https:/URL_RETRACTED/api/v4/projects/PROJECT_ID_RETRACTED/merge_requests: 403 {message: 403 Forbidden}

Not sure what went wrong.

Possibly need to add more debug logging.

--help, help, and lab/git are all inconsistent

After aliasing git to lab, I noticed there are several inconsistencies to the help dialog. git --help, git help and git all return different output. git --help returns the output of lab --help, git help returns the output of hub --help and git returns the output of lab which is a combination of hub + lab.

All of these should be returning the same output. If hub isn't installed, lab and lab --help should both be returning the decorated git --help output. If it is installed, it should be decorating the hub --help output.

CI Pipeline interface

NOTICE: Description fully cannibalized by @zaquestion
Still debating if such a thing should be in lab, but could always move it into its own tool and be called by lab.
Support

  • Running jobs
  • Viewing jobs status (live)
  • Viewing environments
    • Include re-deploying jobs

Also add lab ci lint command
Ref: https://docs.gitlab.com/ce/api/lint.html

Proposal: Alias `lab mr ls` to `lab mr list`

I remembered that lab can checkout MR's and could list them as well.

Attempted lab mr ls. Which did not work. Though it did print out a nice help message which told me lab mr list had the desired functionality.

Thoughts on aliasing lab mr ls to lab mr list?

I would be happy to submit a PR if the feature sounds good.

Use git --porcelain

Use --porcelain for commands where it makes sense.

git help status
...
       --porcelain
           Give the output in an easy-to-parse format for
           scripts. This is similar to the short output, but
           will remain stable across Git versions and
           regardless of user configuration. See below for
           details.
git help show

           porcelain
               Use a special line-based format intended for
               script consumption. Added/removed/unchanged
               runs are printed in the usual unified diff
               format, starting with a +/-/` ` character at
               the beginning of the line and extending to the
               end of the line. Newlines in the input are
               represented by a tilde ~ on a line of its own.
git help log

           porcelain
               Use a special line-based format intended for
               script consumption. Added/removed/unchanged
               runs are printed in the usual unified diff
               format, starting with a +/-/` ` character at
               the beginning of the line and extending to the
               end of the line. Newlines in the input are
               represented by a tilde ~ on a line of its own.

lab mr note

Help for command

lab mr note [remote] <id> 

Add comment to an mr using provided message or in $EDITOR

Operates on the checked out or provided merge request. Notes can be added to a specific line or to the merge request itself. Notes on the same line are appended to the same thread.

Flags
--message, -m stringSlice  msg to use for note
--line, -l                 Line to add comment
--right                    Add comment on new code
--left                     Add comment on existing code

Ref: https://docs.gitlab.com/ce/api/notes.html#merge-requests

Support edit functionality on mrs, issues, and snippets

Wondering if this should be a edit sub command or a flag --amend (like git)

Want to support setting/updating properties without having to edit the message. The flag approach would make sense to use --no-edit. Not sure the best choice for the sub command route...

That said, leaning towards the sub command to be consistent with other commands, and optionally support --amend as the flag off the parent command.

Possible bug with `lab fork`

Saw an error today on a new installation of lab, on a macbook, where lab fork successfully created the fork, set the remote, but failed to fetch insisting that the fork/remote didn't exist.

lab mr diff

Show changes annotated with comments

Flags:

 --ours, --left       Show only left hand side of diff
 --theirs, --right     Show only right hand side of diff
 --only                   Show only diff, removing notes

lab mr complains that gitlab project not found

I am kind of lost.

I cloned a self-hosted repo on gitlab and I am trying to create a merge request or list all merge requests, but I am getting:

[dpetrov@macbook-pro /tmp/apps (master)]$ lab mr list
2018/03/06 22:40:58 mrList.go:38: gitlab project not found

Is there something that i am missing?

Thanks

install script doesn't work on linux.

On ubuntu 17.10 with go version go1.9.1 linux/amd64. running the install script gets:

./install.sh: 4: ./install.sh: [[: not found
+ go get -u -d github.com/zaquestion/lab
+ cd /src/github.com/zaquestion/lab
./install.sh: 9: cd: can't cd to /src/github.com/zaquestion/lab

I'm not really a gopher so I don't get why is searching for source files in that path.
How do I get around this to install lab?

somewhat related PD: Is there a way to provide linux binaries?

`lab clone` without url causes panic instead of printing help

What was expected?

When running git clone without specifying a url, I get a help message:

$ git clone
You must specify a repository to clone.

usage: git clone [<options>] [--] <repo> [<dir>]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
...
...

What happened instead?

When I ran lab clone without a url, lab panic'd:

$ lab clone
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x58350f]

goroutine 1 [running]:
github.com/zaquestion/lab/vendor/github.com/spf13/cobra.(*Command).ParseFlags(0x9c6a40, 0xc42000c310, 0x1, 0x1, 0x9c6a40, 0x9e69a0)
	/home/leland/projects/go-projects/src/github.com/zaquestion/lab/vendor/github.com/spf13/cobra/command.go:1267 +0x3f
github.com/zaquestion/lab/cmd.Execute()
	/home/leland/projects/go-projects/src/github.com/zaquestion/lab/cmd/root.go:81 +0x122
main.main()
	/home/leland/projects/go-projects/src/github.com/zaquestion/lab/main.go:6 +0x20

How might this be fixed?

From what I can see in the cmd/root.go file, the problem is in an unchecked slice of the os.Args slice on line 81. Directly above that line is a somewhat confusing comment which may or may not have anything to do with this issue, I had a hard time understanding it, though it may be of some use to whoever choses to fix this.

The change would be to check if clone has been provided without any additional arguments/parameters, and if it has, to print a help message in some way. The printing of a help message could be done by dropping down to gits help message or by printing labs own custom help message.

Support remote origin over http or https

lab seems to have issues if remote origin is of type http or https rather than ssh in the .git/config file.

To illustrate:

This works:

[remote "origin"]
	url = [email protected]:foo/bar.git
	fetch = +refs/heads/*:refs/remotes/origin/*

This does not work:

[remote "origin"]
	url = https://gitlab.com/foo/bar.git
	fetch = +refs/heads/*:refs/remotes/origin/*

git/hub still being called after successful clone with lab

$ git clone <gitlab_repo>
Cloning into '<gitlab_repo>'...
remote: Counting objects: 5077, done.
remote: Compressing objects: 100% (2024/2024), done.
remote: Total 5077 (delta 3050), reused 4956 (delta 2980)
Receiving objects: 100% (5077/5077), 2.50 MiB | 0 bytes/s, done.
Resolving deltas: 100% (3050/3050), done.
github.com username:

GitLab filtering by issue labels

$ lab issue list by-labels "bug, help wanted"

should list the issues based on labels. An addition to MRs by labels and assignees would be a better addition too.

Create Homebrew Formula

Hi, I'd like to create a Homebrew formula for this project, but it seems there are no releases or tags, so I cannot point to a stable version. Do you think you could add tags as part of your release process? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.