|
| 1 | +# gitlab-cli [](https://travis-ci.org/clns/gitlab-cli) |
| 2 | + |
| 3 | +Cli commands for performing actions against GitLab repositories. |
| 4 | + |
| 5 | +- [Usage](#usage) |
| 6 | +- [Install](#install) |
| 7 | +- [Development](#development) |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +See help for all available commands (`gitlab-cli -h`). |
| 12 | + |
| 13 | +### Labels |
| 14 | + |
| 15 | +##### Copy global labels into a target repository |
| 16 | + |
| 17 | +> GitLab Limitation: Currently there's no way to [access global labels through the API](https://twitter.com/gitlab/status/724619173477924865), so this tool provides a workaround for copying them into a repository. Note that you should configure the global labels manually in GitLab. |
| 18 | +
|
| 19 | +```sh |
| 20 | +gitlab-cli label copy -u https://gitlab.com/<USER>/<REPO> -t <TOKEN> |
| 21 | +``` |
| 22 | + |
| 23 | +> Tip: To avoid specifying `-u` and `-t` every time you refer to a repository, you can save the details of it into the config file with `gitlab-cli config repo save -r <NAME> -u <URL> -t <TOKEN>`, then refer to it simply as `-r <NAME>`. |
| 24 | +
|
| 25 | +##### Copy labels from one repository to another |
| 26 | + |
| 27 | +```sh |
| 28 | +gitlab-cli label copy -r <NAME> <USER>/<SOURCE_REPO> |
| 29 | +``` |
| 30 | + |
| 31 | +> Tip: The above command copies labels between repositories on the same GitLab instance. To copy from a different GitLab instance, first save the source repo in the config as explained above and specify its name as argument instead of the path. |
| 32 | +
|
| 33 | +##### Update label(s) based on a regex match |
| 34 | + |
| 35 | +```sh |
| 36 | +gitlab-cli label update -r <NAME> --match <REGEX> --replace <REPLACE> --color <COLOR> |
| 37 | +``` |
| 38 | + |
| 39 | +> Note: `<REGEX>` is a Go regex string as in <https://golang.org/pkg/regexp/syntax> and `<REPLACE>` is a replacement string as in <https://golang.org/pkg/regexp/#Regexp.FindAllString>. |
| 40 | +
|
| 41 | +##### Delete label(s) that match a regex |
| 42 | + |
| 43 | +```sh |
| 44 | +gitlab-cli label update -r <NAME> --regex <REGEX> |
| 45 | +``` |
| 46 | + |
| 47 | +### TODO |
| 48 | + |
| 49 | +Currently only the label commands are useful. Other commands can be added as needed. |
| 50 | + |
| 51 | +## Install |
| 52 | + |
| 53 | +1. Follow the instructions from the [releases page](https://github.com/clns/gitlab-cli/releases) and run the `curl` command, which the releases page specifies, in your terminal. |
| 54 | + |
| 55 | + > Note: If you get a "Permission denied" error, your `/usr/local/bin` directory probably isn't writable and you'll need to install Compose as the superuser. Run `sudo -i`, then the commands from the release page, then `exit`. |
| 56 | +
|
| 57 | +2. Test the installation. |
| 58 | + |
| 59 | + ```sh |
| 60 | + gitlab-cli version |
| 61 | + ``` |
| 62 | + |
| 63 | +## Development |
| 64 | + |
| 65 | +You'll need a [Go dev environment](https://golang.org/doc/install). |
| 66 | +
|
| 67 | +### Build |
| 68 | +
|
| 69 | +```sh |
| 70 | +go run build/build.go |
| 71 | +``` |
| 72 | +
|
| 73 | +This will build all the executables into the [build/](build) directory. |
| 74 | +
|
| 75 | +### Test |
| 76 | +
|
| 77 | +You need to provide a GitLab URL and private token to be able to create temporary repositories for the tests. |
| 78 | +
|
| 79 | +```sh |
| 80 | +GITLAB_URL="<URL>" GITLAB_TOKEN="<TOKEN>" go test -v ./gitlab |
| 81 | +``` |
| 82 | +
|
| 83 | +You can spin up a GitLab instance using [Docker](https://www.docker.com/): |
| 84 | +
|
| 85 | +```sh |
| 86 | +docker pull gitlab/gitlab-ce |
| 87 | +docker run -d --name gitlab -p 8055:80 gitlab/gitlab-ce |
| 88 | +sleep 60 # allow enough time for GitLab to start |
| 89 | +docker exec gitlab \ |
| 90 | + sudo -u gitlab-psql \ |
| 91 | + /opt/gitlab/embedded/bin/psql --port 5432 -h /var/opt/gitlab/postgresql -d gitlabhq_production -c " \ |
| 92 | + INSERT INTO labels (title, color, template) VALUES ('feature', '#000000', true); \ |
| 93 | + INSERT INTO labels (title, color, template) VALUES ('bug', '#ff0000', true); \ |
| 94 | + UPDATE users SET authentication_token='secret' WHERE username='root';" |
| 95 | +
|
| 96 | +# Note: you may need to change GITLAB_URL to point to your docker container. |
| 97 | +# 'http://docker' is for Docker beta for Windows. |
| 98 | +GITLAB_URL="http://docker:8055" GITLAB_TOKEN="secret" go test -v ./gitlab |
| 99 | +``` |
0 commit comments