Giter Club home page Giter Club logo

gitlab-cli's Introduction

gitlab-cli Build Status

CLI commands for performing actions against GitLab repositories.

Installation

Follow the instructions from the releases page.

Usage

For all available commands see the command's help: gitlab-cli -h. The most common commands are documented below.

Labels

Copy global labels into a repository

GitLab Limitation: Currently there's no way to access global labels through the API, so this tool provides a workaround to copy them.

gitlab-cli label copy -U https://gitlab.com/<USER>/<REPO> -t <TOKEN>

Tip: To avoid specifying -U and -t every time you refer to a repository, you can use the config file to save the details of it. See Specifying a repository.

Copy labels from repoA to repoB

gitlab-cli label copy --from <repoA> -r <repoB>

repoA and repoB are repository names saved in the config file.

Tip: For repositories on the same installation, you can specify the --from repo as group/repo, as a convenience, in which case the repository is considered on the same GitLab instance as the target repo.

Update labels that match a regex

gitlab-cli label update -r <NAME> --match <REGEX> --name <NAME> --color <COLOR> --description <DESC>

Note: <REGEX> is a Go regex string as in https://golang.org/pkg/regexp/syntax and <NAME> is a replacement string as in https://golang.org/pkg/regexp/#Regexp.FindAllString.

Delete labels that match a regex

gitlab-cli label delete -r <NAME> --match <REGEX>

TODO

Other commands can be added as needed. Feel free to open pull requests or issues.

Specifying a repository

There are 2 ways to specify a repository:

  1. By using the --url (-U) and --token (-t) flags (or --user (-u) and --password (-p) instead of token) with each command. This is the easiest to get started but requires a lot of typing.
  2. By saving the repository details in the config file and referring to it by its saved name using --repo (-r) (e.g. -r myrepo)

Example:

Instead of this:

gitlab-cli label copy -U https://git.my-site.com/my_group/my_repo -t ghs93hska

you can first save the repo in the config file and refer to it by name on all subsequent commands:

gitlab-cli config repo save -r myrepo -U https://git.my-site.com/my_group/my_repo -t ghs93hska
gitlab-cli label copy -r myrepo

Using user and password instead of token

You can specify your GitLab login (user or email) - --user (-u) - and password - --password (-p) - instead of the token in any command, if this is easier for you. Example:

gitlab-cli config repo save -r myrepo -U https://git.my-site.com/my_group/my_repo -u my_user -p my_pass

The config file

The default location of the config file is $HOME/.gitlab-cli.yaml and it is useful for saving repositories and then refer to them by their names. A sample config file looks like this:

repos:
  myrepo1:
    url: https://git.mysite.com/group/repo1
    token: Nahs93hdl3shjf
  myrepo2:
    url: https://git.mysite.com/group/repo2
    token: Nahs93hdl3shjf
  myother:
    url: https://git.myothersite.com/group/repo1
    token: OA23spfwuSalos

But there's no need to manually edit this file. Instead use the config commands to modify it (see gitlab-cli config -h). Some useful config commands are:

  • gitlab-cli config cat - print the entire config file contents
  • gitlab-cli config repo ls - list all saved repositories
  • gitlab-cli config repo save ... - save a repository
  • gitlab-cli config repo show -r <repo> - show the details of a saved repository

Development

You'll need a Go dev environment.

git clone https://github.com/clns/gitlab-cli
cd gitlab-cli
git submodule --init update

Build

go run build/build.go

This will build all the executables into the build/ directory.

Test

You need to provide a GitLab URL and private token to be able to create temporary repositories for the tests.

GITLAB_URL="<URL>" GITLAB_TOKEN="<TOKEN>" go test -v ./gitlab

You can spin up a GitLab instance using Docker:

docker pull gitlab/gitlab-ce
docker run -d --name gitlab -p 8055:80 gitlab/gitlab-ce
sleep 60 # allow enough time for GitLab to start
docker exec -ti gitlab bash
su gitlab-psql
/opt/gitlab/embedded/bin/psql --port 5432 -h /var/opt/gitlab/postgresql -d gitlabhq_production -c " \
          INSERT INTO labels (title, color, template, description, description_html) VALUES ('feature', '#000000', true, 'represents a feature', 'represents a <b>feature</b>'); \
          INSERT INTO labels (title, color, template, description, description_html) VALUES ('bug', '#ff0000', true, 'represents a bug', 'represents a <b>bug</b>'); \
          UPDATE users SET authentication_token='secret' WHERE username='root';"

# Note: you may need to change GITLAB_URL to point to your docker container.
# 'http://docker' is for Docker beta for Windows. 
GITLAB_URL="http://localhost:8055" GITLAB_TOKEN="secret" go test -v ./gitlab

Vendored dependencies

All external dependencies should be available in the vendor/ directory.

To list all dependencies run go list -f '{{.ImportPath}}:{{"\n"}} {{join .Imports "\n "}}' ./....

To vendor a package run git submodule add https://github.com/google/go-github vendor/github.com/google/go-github.

gitlab-cli's People

Contributors

bollenn avatar clns avatar jollheef 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

gitlab-cli's Issues

Multiple group inclusion failed to copy label

When you have a repo which is in a group which is also in a group. I use the command:
gitlab-cli label copy -U https://<URL>/<group1>/<group2>/<project> -t <token>
it returns
error: invalid target repository: failed to get Gitlab project 'https://...': repository with path <group1>/<group2>/<project> was not found

PS: thanks for your work.

Need to increase timeouts

Gitlab.com is convenient for those that need a public repository or a private one shared by others, however this script cannot run against Gitlab.com as the timeout is always reached. Gitlab.com can be sluggish.

Please increase timeouts so we can use this with Gitlab.com.

Errors flip back and forth between these two:

error: invalid source repository: empty repo url

False: The source repo is in the config, and trying this command intermittently throws this. Seems to be a timeout when reading the source repo.

error: invalid target repository: failed to get GitLab project '<private repo': Get https:/api/v3/projects/search/<repo>: net/http: request canceled (Client.Timeout exceeded while awaiting headers)

Copy error + how to use the local config YAML?

Cool project!

I can't seem to find any info on what I should put in the config YAML, and I'm not familiar enough with Go to try and figure out the required YAML structure.

I ask because I get an error when I try this (my .gitlab-cli.yaml is empty):

gitlab-cli label copy -u "https://git.my-site.com/my_group/my_project" -t "MY_TOKEN"
Using config file: /root/.gitlab-cli.yaml
error: invalid target repository: failed to get GitLab project 'https://git.my-site.com/my_group/my_project':
  Get https:/api/v3/projects/search/my_project:
    net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

I see a few interesting things here:

  1. The output seems to indicate that the API request is using an invalid URL
  2. Doing a search for project by name will be problematic for me as I'm dealing w/ many groups having the same projects
  • Hopefully, your code accounts for that and filters through the list of search results to get the project matching the group

Please let me know what I'm doing wrong here and what the config file should contain.

Thanks

repository/group wildcard

I think that it might be interesting to allow label management (copy/update) for more than one project/group (or even a whole GitLab instance) at once.

E.g.

gitlab-cli label copy -U https://mygitlab.example.com/mygroup/*  -t xxxxxx

gitlab-cli label copy -U https://mygitlab.example.com/mygroup/linux-*  -t xxxxxx

gitlab-cli label update -r "linux-*" --match <REGEX> --name <NAME> --color <COLOR> --description <DESC>

WDYT? Any clue in how to add this feature?

Release or artifact

Could we create a new release for this project, or can we add some artifacts which we can download from CI?

error on use

every use generates the same:
error: open : no such file or directory

  • run as typical user
  • run as priv user
  • run as root

...same result

"incorrect path" Error when using a repo with subgroups.

When accessing a repo within a sub group, for example:

https://gitlab.com/maingroup/subgroup/project

The following error is returned:

error: invalid target repository: failed to get GitLab project https://gitlab.com/maingroup/subgroup/project': incorrect path: maingroup/subgroup/project

Documentation for copying is unclear

I want to copy the labels from Repository A to Repository B. I can't work out from the docs how to do that, and the various I'm trying don't seem to work. how might I do that given that I've configured repoA and repoB in the yaml file?

Upgrade to API version 4?

Hi. This is an excellent tool, thanks for this! Are there any plans to upgrade this to use the V4 version of the GitLab API? V3 has been deprecated as of GitLab 9.5 (we're past version 10 now).

Update for those in search of a solution: since I wasn't able to find any other tools that can propagate my global admin labels across my instance that also work with the latest version of GitLab, I made one myself: https://www.npmjs.com/package/gitlab-fix-labels. It also addresses #11.

Cheers!

git submodule update --init

Hi,
I guess
in README.md, Devlopment, git submodule --init update should be git submodule update --init

Best regards

Cannot find module '@babel/runtime/core-js/object/define-property'

Hi, thank you for developing this cli, after install I got this error. Any suggestion?

module.js:549
throw err;
^

Error: Cannot find module '@babel/runtime/core-js/object/define-property'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (/usr/local/lib/node_modules/git-lab-cli/node_modules/gitlab/dist/es5/index.js:7:30)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)

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.