Gitlab
website |
documentation |
gitlab-live
Gitlab is a Ruby wrapper and CLI for the GitLab API.
Installation
Install it from rubygems:
gem install fs-gitlab
Or add to a Gemfile:
gem 'fs-gitlab'
Usage
Configuration example:
Gitlab.configure do |config|
config.endpoint = 'https://example.net/api/v4'
config.private_token = 'qEsq1pt6HJPaNciie3MG'
end
(Note: If you are using GitLab.com's hosted service, your endpoint will be https://gitlab.com/api/v4
)
Usage examples:
Gitlab.endpoint = 'https://example.net/api/v4'
Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
Gitlab.http_proxy('proxyhost', 8888)
Gitlab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere')
ENV['GITLAB_API_HTTPARTY_OPTIONS'] = '{read_timeout: 60}'
Gitlab.projects(per_page: 5)
g = Gitlab.client(
endpoint: 'https://example.com/api/v4',
private_token: 'qEsq1pt6HJPaNciie3MG',
httparty: {
headers: { 'Cookie' => 'gitlab_canary=true' }
}
)
user = g.user
user.email
Gitlab.sudo = 'other_user'
Gitlab.sudo = nil
Gitlab.private_token = ''
projects = Gitlab.projects(per_page: 5)
projects.has_next_page?
projects.next_page
projects.auto_paginate do |project|
end
projects.auto_paginate
For more information, refer to documentation.
CLI
It is possible to use this gem as a command line interface to GitLab. In order to make that work you need to set a few environment variables:
export GITLAB_API_ENDPOINT=https://gitlab.example.com/api/v4
export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/personal_access_tokens>
export GITLAB_API_HTTPARTY_OPTIONS="{verify: false}"
Usage:
When you want to know which CLI commands are supported, take a look at the client commands implemented in this gem. Any of those methods can be called as a command by passing the parameters of the commands as parameters of the CLI.
Usage examples:
gitlab users
gitlab user
gitlab user 2
gitlab user --only=id,username
gitlab user --except=email,bio
gitlab user 2 --json
gitlab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
CLI Shell
Usage examples:
gitlab shell
gitlab> help
gitlab> groups
gitlab> protect_branch 1 master
gitlab> create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
Web version is available at https://gitlab-live.herokuapp.com
For more information, refer to website.
Development
With a dockerized GitLab instance
docker-compose up -d gitlab # Will start the GitLab instance in the background (approx. 3 minutes)
After a while, your GitLab instance will be accessible on http://localhost:3000.
Once you have set your new root password, you can login with the root user.
You can now setup a personal access token here: http://localhost:3000/profile/personal_access_tokens
Once you have your token, set the variables to the correct values in the docker.env
file.
Then, launch the tool:
docker-compose run app
Gitlab.users
=> [#<Gitlab::ObjectifiedHash:47231290771040 {hash: {"id"=>1, "name"=>"Administrator", "username"=>"root", ...]
To launch the specs:
docker-compose run app rake spec
Want to use GitLab Enterprise?
Just change the image from gitlab/gitlab-ce:latest
to gitlab/gitlab-ee:latest
in the docker-compose.yml
file.
With an external GitLab instance
First, set the variables to the correct values in the docker.env
file.
Then, launch the tool:
docker-compose run app
Gitlab.users
=> [#<Gitlab::ObjectifiedHash:47231290771040 {hash: {"id"=>1, "name"=>"Administrator", "username"=>"root", ...]
To launch the specs,
docker-compose run app rake spec
Without Docker
After checking out the repo, run bin/setup
to install dependencies. Then, run
rake spec
to run the tests. You can also run bin/console
for an interactive
prompt that will allow you to experiment.
For more information see CONTRIBUTING.md.
License
Released under the BSD 2-clause license. See LICENSE.txt for details.