Name: gitlab
Owner: Libraries.io
Description: Ruby wrapper and CLI for GitLab REST API
Forked from: NARKOZ/gitlab
Created: 2017-02-09 17:48:38.0
Updated: 2017-02-09 17:48:40.0
Pushed: 2017-04-11 09:21:31.0
Homepage: http://narkoz.github.io/gitlab
Size: 833
Language: Ruby
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
website | documentation | gitlab-live
Gitlab is a Ruby wrapper and CLI for the GitLab API.
As of version 4.0.0
this gem will only support Ruby 2.0+ and Gitlab API v4.
Install it from rubygems:
install gitlab
Or add to a Gemfile:
'gitlab'
m 'gitlab', github: 'NARKOZ/gitlab'
Configuration example:
ab.configure do |config|
nfig.endpoint = 'https://example.net/api/v4' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
nfig.private_token = 'qEsq1pt6HJPaNciie3MG' # user's private token or OAuth2 access token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
Optional
config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
config.sudo = 'user' # username for sudo mode, default: nil
(Note: If you are using GitLab.com's hosted service, your endpoint will be https://gitlab.com/api/v4
)
Usage examples:
t an API endpoint
ab.endpoint = 'http://example.net/api/v4'
"http://example.net/api/v4"
t a user private token
ab.private_token = 'qEsq1pt6HJPaNciie3MG'
"qEsq1pt6HJPaNciie3MG"
nfigure a proxy server
ab.http_proxy('proxyhost', 8888)
oxy server w/ basic auth
ab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere')
st projects
ab.projects(per_page: 5)
[#<Gitlab::ObjectifiedHash:0x000000023326e0 @data={"id"=>1, "code"=>"brute", "name"=>"Brute", "description"=>nil, "path"=>"brute", "default_branch"=>nil, "owner"=>#<Gitlab::ObjectifiedHash:0x00000002331600 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>, "private"=>true, "issues_enabled"=>true, "merge_requests_enabled"=>true, "wall_enabled"=>true, "wiki_enabled"=>true, "created_at"=>"2012-09-17T09:41:56Z"}>, #<Gitlab::ObjectifiedHash:0x000000023450d8 @data={"id"=>2, "code"=>"mozart", "name"=>"Mozart", "description"=>nil, "path"=>"mozart", "default_branch"=>nil, "owner"=>#<Gitlab::ObjectifiedHash:0x00000002344ca0 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>, "private"=>true, "issues_enabled"=>true, "merge_requests_enabled"=>true, "wall_enabled"=>true, "wiki_enabled"=>true, "created_at"=>"2012-09-17T09:41:57Z"}>, #<Gitlab::ObjectifiedHash:0x00000002344958 @data={"id"=>3, "code"=>"gitlab", "name"=>"Gitlab", "description"=>nil, "path"=>"gitlab", "default_branch"=>nil, "owner"=>#<Gitlab::ObjectifiedHash:0x000000023447a0 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>, "private"=>true, "issues_enabled"=>true, "merge_requests_enabled"=>true, "wall_enabled"=>true, "wiki_enabled"=>true, "created_at"=>"2012-09-17T09:41:58Z"}>]
itialize a new client
Gitlab.client(endpoint: 'https://api.example.com', private_token: 'qEsq1pt6HJPaNciie3MG')
#<Gitlab::Client:0x00000001e62408 @endpoint="https://api.example.com", @private_token="qEsq1pt6HJPaNciie3MG", @user_agent="Gitlab Ruby Gem 2.0.0">
t a user
= g.user
#<Gitlab::ObjectifiedHash:0x00000002217990 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "bio"=>nil, "skype"=>"", "linkedin"=>"", "twitter"=>"john", "dark_scheme"=>false, "theme_id"=>1, "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>
t a user's email
.email
"john@example.com"
t a sudo mode to perform API calls as another user
ab.sudo = 'other_user'
"other_user"
sable a sudo mode
ab.sudo = nil
nil
paginated response
ects = Gitlab.projects(per_page: 5)
eck existence of the next page
ects.has_next_page?
trieve the next page
ects.next_page
erate all projects
ects.auto_paginate do |project|
do something
trieve all projects as an array
ects.auto_paginate
For more information, refer to documentation.
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:
rt GITLAB_API_ENDPOINT=https://gitlab.yourcompany.com/api/v4
rt GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/account>
is one is optional and can be used to set any HTTParty option you may need
ing YAML hash syntax. For example, this is how you would disable SSL
rification (useful if using a self-signed cert).
rt 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:
st users
e: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#users-instance_method
ab users
t current user
e: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
ab user
t a user
e: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
ab user 2
lter output
ab user --only=id,username
ab user --except=email,bio
t a user and render result as json
ab user 2 --json
ssing options hash to a command (use YAML)
e: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method
ab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
Usage examples:
art shell session
ab shell
st available commands
ab> help
st groups
ab> groups
otect a branch
ab> protect_branch 1 master
ssing options hash to a command (use YAML)
ab> 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.
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.
Released under the BSD 2-clause license. See LICENSE.txt for details.