Codebase list ruby-gitlab / 9962458
New upstream version 4.8.0 Utkarsh Gupta 4 years ago
159 changed file(s) with 6018 addition(s) and 3435 deletion(s). Raw diff Collapse all Expand all
0 # Number of days of inactivity before an issue becomes stale
1 daysUntilStale: 90
2 # Number of days of inactivity before a stale issue is closed
3 daysUntilClose: 10
4 # Issues with these labels will never be considered stale
5 exemptLabels:
6 - pinned
7 - security
8 - contribution welcome
9 # Label to use when marking an issue as stale
10 staleLabel: stale
11 # Comment to post when marking an issue as stale. Set to `false` to disable
12 markComment: >
13 This issue has been automatically marked as stale because it has not had
14 recent activity. It will be closed if no further activity occurs. Thank you
15 for your contributions.
16 # Comment to post when closing a stale issue. Set to `false` to disable
17 closeComment: false
0 Layout/SpaceAroundEqualsInParameterDefault:
1 Enabled: false
0 ---
1 inherit_from: .rubocop_todo.yml
22
3 Style/Alias:
4 Enabled: false
5
6 Style/PercentLiteralDelimiters:
7 Enabled: false
8
9 Layout/DotPosition:
10 Enabled: false
3 AllCops:
4 TargetRubyVersion: 2.3
115
126 Metrics/LineLength:
13 Max: 100
7 Max: 125
148 Exclude:
159 - 'lib/gitlab/client/*'
16 - 'spec/**/*'
17
18 Style/ClassAndModuleChildren:
19 Exclude:
20 - 'lib/gitlab/client/*'
21
22 Layout/SpaceInsideHashLiteralBraces:
23 Exclude:
24 - 'lib/gitlab/client/*'
25
26 Style/StringLiterals:
27 Exclude:
2810 - 'spec/**/*'
2911
3012 Metrics/BlockLength:
3113 Exclude:
3214 - 'spec/**/*'
15
16 Style/Documentation:
17 Enabled: false
18
19 Style/ClassAndModuleChildren:
20 Exclude:
21 - 'lib/gitlab/*'
22 - 'lib/gitlab/client/*'
23
24 Style/FrozenStringLiteralComment:
25 Exclude:
26 - 'spec/gitlab/file_response_spec.rb'
27 - 'spec/gitlab/help_spec.rb'
28
29 Style/SpecialGlobalVars:
30 Exclude:
31 - 'gitlab.gemspec'
0 # This configuration was generated by
1 # `rubocop --auto-gen-config`
2 # on 2018-10-10 10:25:27 +0400 using RuboCop version 0.59.2.
3 # The point is for the user to remove these configuration records
4 # one by one as the offenses are removed from the code base.
5 # Note that changes in the inspected code, or installation of new
6 # versions of RuboCop, may require this file to be generated again.
7
8 # Offense count: 1
9 Lint/UriEscapeUnescape:
10 Exclude:
11 - 'lib/gitlab/client.rb'
12
13 # Offense count: 5
14 Metrics/AbcSize:
15 Max: 34
16
17 # Offense count: 4
18 Metrics/CyclomaticComplexity:
19 Max: 14
20
21 # Offense count: 10
22 # Configuration parameters: CountComments, ExcludedMethods.
23 Metrics/MethodLength:
24 Max: 34
25
26 # Offense count: 2
27 # Configuration parameters: CountComments.
28 Metrics/ModuleLength:
29 Max: 165
30
31 # Offense count: 2
32 # Configuration parameters: CountKeywordArgs.
33 Metrics/ParameterLists:
34 Max: 6
35
36 # Offense count: 1
37 Metrics/PerceivedComplexity:
38 Max: 10
39
40 # Offense count: 1
41 # Cop supports --auto-correct.
42 # Configuration parameters: AutoCorrect.
43 Security/JSONLoad:
44 Exclude:
45 - 'lib/gitlab/request.rb'
0 ---
01 language: ruby
12 rvm:
23 - 2.3
34 - 2.4
45 - 2.5
5 before_install: gem update bundler
6 - 2.6
67
7 matrix:
8 jobs:
89 include:
9 - rvm: 2.4
10 env: "TRAVIS_CI_RUBOCOP=true"
11 allow_failures:
12 - env: "TRAVIS_CI_RUBOCOP=true"
10 - stage: lint
11 rvm: 2.3
12 script: bundle exec rake rubocop
0 # frozen_string_literal: true
1
02 source 'https://rubygems.org'
13
24 # Specify your gem's dependencies in gitlab.gemspec
0 Copyright (c) 2012-2015 Nihad Abbasov <mail@narkoz.me>
0 Copyright (c) 2012-2019 Nihad Abbasov <nihad@42na.in>
11 All rights reserved.
22
33 Redistribution and use in source and binary forms, with or without
00 # Gitlab
11
22 [![Build Status](https://img.shields.io/travis/NARKOZ/gitlab.svg)](https://travis-ci.org/NARKOZ/gitlab)
3 [![Code Climate](https://img.shields.io/codeclimate/maintainability/NARKOZ/gitlab.svg)](https://codeclimate.com/github/NARKOZ/gitlab)
4 [![Inline docs](http://inch-ci.org/github/NARKOZ/gitlab.svg)](https://inch-ci.org/github/NARKOZ/gitlab)
3 [![Maintainability](https://api.codeclimate.com/v1/badges/2e310b334b1b5db4a7e1/maintainability)](https://codeclimate.com/github/NARKOZ/gitlab)
4 [![Inline docs](https://inch-ci.org/github/NARKOZ/gitlab.svg)](https://inch-ci.org/github/NARKOZ/gitlab)
55 [![Gem version](https://img.shields.io/gem/v/gitlab.svg)](https://rubygems.org/gems/gitlab)
66 [![License](https://img.shields.io/badge/license-BSD-red.svg)](https://github.com/NARKOZ/gitlab/blob/master/LICENSE.txt)
77
8 [website](http://narkoz.github.io/gitlab) |
9 [documentation](http://rubydoc.info/gems/gitlab/frames) |
8 [website](https://narkoz.github.io/gitlab) |
9 [documentation](https://rubydoc.info/gems/gitlab/frames) |
1010 [gitlab-live](https://github.com/NARKOZ/gitlab-live)
1111
1212 Gitlab is a Ruby wrapper and CLI for the [GitLab API](https://docs.gitlab.com/ce/api/README.html).
13 As of version `4.0.0` this gem only supports Ruby 2.0+ and Gitlab API v4.
13 As of version `4.0.0` this gem only supports Ruby 2.0+ and GitLab API v4.
1414
1515 ## Installation
1616
5353
5454 ```ruby
5555 # set an API endpoint
56 Gitlab.endpoint = 'http://example.net/api/v4'
57 # => "http://example.net/api/v4"
56 Gitlab.endpoint = 'https://example.net/api/v4'
57 # => "https://example.net/api/v4"
5858
5959 # set a user private token
6060 Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
6262
6363 # configure a proxy server
6464 Gitlab.http_proxy('proxyhost', 8888)
65 # proxy server w/ basic auth
65 # proxy server with basic auth
6666 Gitlab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere')
67 # set timeout for responses
68 ENV['GITLAB_API_HTTPARTY_OPTIONS'] = '{read_timeout: 60}'
6769
6870 # list projects
6971 Gitlab.projects(per_page: 5)
107109 projects.auto_paginate
108110 ```
109111
110 For more information, refer to [documentation](http://rubydoc.info/gems/gitlab/frames).
112 For more information, refer to [documentation](https://rubydoc.info/gems/gitlab/frames).
111113
112114 ## CLI
113115
114 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:
116 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:
115117 ```sh
116118 export GITLAB_API_ENDPOINT=https://gitlab.yourcompany.com/api/v4
117119 export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/account>
123125
124126 Usage:
125127
126 When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client). Any of those methods can be called as a command by passing the parameters of the commands as parameters of the CLI.
128 When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client). Any of those methods can be called as a command by passing the parameters of the commands as parameters of the CLI.
127129
128130 Usage examples:
129131
130132 ```sh
131133 # list users
132 # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#users-instance_method
134 # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#users-instance_method
133135 gitlab users
134136
135137 # get current user
136 # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
138 # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method
137139 gitlab user
138140
139141 # get a user
140 # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
142 # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method
141143 gitlab user 2
142144
143145 # filter output
149151 gitlab user 2 --json
150152
151153 # passing options hash to a command (use YAML)
152 # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method
154 # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method
153155 gitlab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
154156
155157 ```
176178 ```
177179
178180 Web version is available at https://gitlab-live.herokuapp.com
179 For more information, refer to [website](http://narkoz.github.io/gitlab).
181 For more information, refer to [website](https://narkoz.github.io/gitlab).
180182
181183 ## Development
182184
183 ### With a dockerized Gitlab instance
184
185 ```shell
186 docker-compose up -d gitlab # Will start the gitlab instance in the background (approx. 3 minutes)
187 ```
188
189 After a while, your Gitlab instance will be accessible on http://localhost:3000.
185 ### With a dockerized GitLab instance
186
187 ```shell
188 docker-compose up -d gitlab # Will start the GitLab instance in the background (approx. 3 minutes)
189 ```
190
191 After a while, your GitLab instance will be accessible on http://localhost:3000.
190192
191193 Once you have set your new root password, you can login with the root user.
192194
205207 => [#<Gitlab::ObjectifiedHash:47231290771040 {hash: {"id"=>1, "name"=>"Administrator", "username"=>"root", ...]
206208 ```
207209
208 To launch the specs,
210 To launch the specs:
209211
210212 ```shell
211213 docker-compose run app rake spec
212214 ```
213215
214 #### Want to use Gitlab Enterprise?
216 #### Want to use GitLab Enterprise?
215217
216218 Just change the image from `gitlab/gitlab-ce:latest` to `gitlab/gitlab-ee:latest` in the `docker-compose.yml` file.
217219
218 ### With an external Gitlab instance
220 ### With an external GitLab instance
219221
220222 First, set the variables to the correct values in the `docker.env` file.
221223
0 # frozen_string_literal: true
1
02 require 'bundler/gem_tasks'
13
24 require 'rspec/core/rake_task'
911 task.options = ['-D', '--parallel']
1012 end
1113
12 if ENV['TRAVIS_CI_RUBOCOP']
13 task default: :rubocop
14 else
15 task default: :spec
16 end
14 task default: :spec
00 #!/usr/bin/env ruby
1 # frozen_string_literal: true
12
23 # ENV['GITLAB_API_ENDPOINT'] = ''
34 # ENV['GITLAB_API_PRIVATE_TOKEN'] = ''
00 #!/usr/bin/env ruby
1 # frozen_string_literal: true
12
2 $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3 $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
5 # Exit cleanly from an early interrupt
6 Signal.trap('INT') { exit 1 }
37
48 require 'gitlab/cli'
59
0 lib = File.expand_path('../lib', __FILE__)
0 # frozen_string_literal: true
1
2 lib = File.expand_path('lib', __dir__)
13 $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
24 require 'gitlab/version'
35
1012 gem.summary = 'A Ruby wrapper and CLI for the GitLab API'
1113 gem.homepage = 'https://github.com/narkoz/gitlab'
1214
13 gem.files = `git ls-files`.split($/).
14 reject { |f| f[/^spec/] } -
15 %w[Dockerfile docker-compose.yml docker.env .travis.yml .rubocop.yml .dockerignore]
15 gem.files = `git ls-files`.split($/)
16 .grep_v(/^spec/) -
17 %w[Dockerfile docker-compose.yml docker.env .travis.yml
18 .rubocop.yml .dockerignore]
1619 gem.bindir = 'exe'
1720 gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
1821 gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
1922 gem.require_paths = ['lib']
2023 gem.license = 'BSD'
2124
22 gem.required_ruby_version = '>= 2.0.0'
25 gem.required_ruby_version = '>= 2.3'
2326
2427 gem.add_runtime_dependency 'httparty', '>= 0.14.0'
2528 gem.add_runtime_dependency 'terminal-table', '>= 1.5.1'
2730 gem.add_development_dependency 'pry'
2831 gem.add_development_dependency 'rake'
2932 gem.add_development_dependency 'rspec'
33 gem.add_development_dependency 'rubocop'
3034 gem.add_development_dependency 'webmock'
31 gem.add_development_dependency 'rubocop'
3235 end
0 # frozen_string_literal: true
1
02 module Gitlab
13 # @private
24 class API < Request
35 # @private
46 attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
57 # @private
6 alias_method :auth_token=, :private_token=
8 alias auth_token= private_token=
79
810 # Creates a new API.
911 # @raise [Error:MissingCredentials]
10 def initialize(options={})
12 def initialize(options = {})
1113 options = Gitlab.options.merge(options)
1214 (Configuration::VALID_OPTIONS_KEYS + [:auth_token]).each do |key|
1315 send("#{key}=", options[key]) if options[key]
1416 end
15 request_defaults(@sudo)
17 request_defaults(sudo)
1618 self.class.headers 'User-Agent' => user_agent
1719 end
1820 end
0 # frozen_string_literal: true
1
02 require 'gitlab'
13 require 'terminal-table/import'
24 require_relative 'cli_helpers'
1618 #
1719 # @param [Array] args The command and it's optional arguments.
1820 def self.start(args)
19 command = args.shift.strip rescue 'help'
21 command = begin
22 args.shift.strip
23 rescue StandardError
24 'help'
25 end
2026 run(command, args)
2127 end
2228
2935 # @param [String] cmd The name of a command.
3036 # @param [Array] args The optional arguments for a command.
3137 # @return [nil]
32 def self.run(cmd, args=[])
38 def self.run(cmd, args = [])
3339 case cmd
3440 when 'help'
3541 puts help(args.shift) { |out| out.gsub!(/Gitlab\./, 'gitlab ') }
3642 when 'info'
37 endpoint = Gitlab.endpoint ? Gitlab.endpoint : 'not set'
38 private_token = Gitlab.private_token ? Gitlab.private_token : 'not set'
43 endpoint = Gitlab.endpoint || 'not set'
44 private_token = Gitlab.private_token || 'not set'
3945 puts "Gitlab endpoint is #{endpoint}"
4046 puts "Gitlab private token is #{private_token}"
4147 puts "Ruby Version is #{RUBY_VERSION}"
5965
6066 begin
6167 command_args.map! { |arg| symbolize_keys(yaml_load(arg)) }
62 rescue => e
68 rescue StandardError => e
6369 puts e.message
6470 exit 1
6571 end
0 # frozen_string_literal: true
1
02 require 'yaml'
13 require 'json'
24 require 'base64'
46 class Gitlab::CLI
57 # Defines methods related to CLI output and formatting.
68 module Helpers
7 extend self
9 module_function
810
911 # Returns actions available to CLI & Shell
1012 #
7072
7173 puts 'Are you sure? (y/n)'
7274
73 if %w(y yes).include?($stdin.gets.to_s.strip.downcase)
75 if %w[y yes].include?($stdin.gets.to_s.strip.downcase)
7476 puts 'Proceeding..'
7577 else
7678 puts 'Command aborted.'
8183 # Gets defined help for a specific command/action.
8284 #
8385 # @return [String]
84 def help(cmd=nil, &block)
86 def help(cmd = nil, &block)
8587 if cmd.nil? || Gitlab::Help.help_map.key?(cmd)
8688 Gitlab::Help.actions_table(cmd)
8789 else
8991 end
9092 end
9193
92 # Outputs a nicely formatted table or error msg.
94 # Outputs a nicely formatted table or error message.
9395 def output_table(cmd, args, data)
9496 case data
9597 when Gitlab::ObjectifiedHash, Gitlab::FileResponse
9698 puts record_table([data], cmd, args)
9799 when Gitlab::PaginatedResponse
98100 puts record_table(data, cmd, args)
99 else # probably just an error msg
101 else # probably just an error message
100102 puts data
101103 end
102104 end
158160 # @param [Array] args Options passed to the API call
159161 # @param [bool] single_value If set to true, a single result should be returned
160162 # @return [Hash] Result hash
161 def record_hash(data, cmd, args, single_value=false)
163 def record_hash(data, cmd, args, single_value = false)
162164 if data.empty?
163165 result = nil
164166 else
168170 row = {}
169171
170172 keys.each do |key|
171 case hash[key]
172 when Hash
173 row[key] = 'Hash'
174 when StringIO
175 row[key] = Base64.encode64(hash[key].read)
176 when nil
177 row[key] = nil
178 else
179 row[key] = hash[key]
180 end
173 row[key] = case hash[key]
174 when Hash
175 'Hash'
176 when StringIO
177 Base64.encode64(hash[key].read)
178 when nil
179 nil
180 else
181 hash[key]
182 end
181183 end
182184
183185 result.push row
184186 end
185 result = result[0] if single_value && result.count > 0
187 result = result[0] if single_value && result.count.positive?
186188 end
187189
188190 {
201203 end
202204
203205 # Helper function to call Gitlab commands with args.
204 def gitlab_helper(cmd, args=[])
206 def gitlab_helper(cmd, args = [])
205207 begin
206208 data = args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd)
207 rescue => e
209 rescue StandardError => e
208210 puts e.message
209211 yield if block_given?
210212 end
216218 # @return [Hash]
217219 def symbolize_keys(hash)
218220 if hash.is_a?(Hash)
219 hash = hash.each_with_object({}) do |(key, value), newhash|
221 hash = hash.each_with_object({}) do |(key, value), new_hash|
220222 begin
221 newhash[key.to_sym] = symbolize_keys(value)
223 new_hash[key.to_sym] = symbolize_keys(value)
222224 rescue NoMethodError
223225 raise "Error: cannot convert hash key to symbol: #{key}"
224226 end
228230 hash
229231 end
230232
233 # Check if arg is a color in 6-digit hex notation with leading '#' sign
234 def hex_color?(arg)
235 pattern = /\A#\h{6}\Z/
236
237 pattern.match(arg)
238 end
239
231240 # YAML::load on a single argument
232241 def yaml_load(arg)
233 YAML.safe_load(arg)
242 hex_color?(arg) ? arg : YAML.safe_load(arg)
234243 rescue Psych::SyntaxError
235244 raise "Error: Argument is not valid YAML syntax: #{arg}"
236245 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to Award Emojis.
24 # @see https://docs.gitlab.com/ce/api/access_requests.html
1113 def project_access_requests(project)
1214 get("/projects/#{url_encode project}/access_requests")
1315 end
16
1417 # Gets a list of access requests for a group viewable by the authenticated user.
1518 #
1619 # @example
2124 def group_access_requests(group)
2225 get("/groups/#{url_encode group}/access_requests")
2326 end
27
2428 # Requests access for the authenticated user to a project.
2529 #
2630 # @example
3135 def request_project_access(project)
3236 post("/projects/#{url_encode project}/access_requests")
3337 end
38
3439 # Requests access for the authenticated user to a group.
3540 #
3641 # @example
4146 def request_group_access(group)
4247 post("/groups/#{url_encode group}/access_requests")
4348 end
49
4450 # Approves a project access request for the given user.
4551 #
4652 # @example
5460 def approve_project_access_request(project, user_id, options = {})
5561 put("/projects/#{url_encode project}/access_requests/#{user_id}/approve", body: options)
5662 end
63
5764 # Approves a group access request for the given user.
5865 #
5966 # @example
6774 def approve_group_access_request(group, user_id, options = {})
6875 put("/groups/#{url_encode group}/access_requests/#{user_id}/approve", body: options)
6976 end
77
7078 # Denies a project access request for the given user.
7179 #
7280 # @example
7886 def deny_project_access_request(project, user_id)
7987 delete("/projects/#{url_encode project}/access_requests/#{user_id}")
8088 end
89
8190 # Denies a group access request for the given user.
8291 #
8392 # @example
9099 delete("/groups/#{url_encode group}/access_requests/#{user_id}")
91100 end
92101 end
93 end
102 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to Award Emojis.
24 # @see https://docs.gitlab.com/ce/api/award_emoji.html
7880 # @param [String] emoji_name The name of the emoji, without colons.
7981 # @return [Gitlab::ObjectifiedHash]
8082 def create_award_emoji(project, awardable_id, awardable_type, emoji_name)
81 post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji", body: {name: emoji_name})
83 post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji", body: { name: emoji_name })
8284 end
8385
8486 # Awards a new emoji to a note on an awardable(issue, merge request or snippet)
9597 # @param [String] emoji_name The name of the emoji, without colons.
9698 # @return [Gitlab::ObjectifiedHash]
9799 def create_note_award_emoji(project, awardable_id, awardable_type, note_id, emoji_name)
98 post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji", body: {name: emoji_name})
100 post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji", body: { name: emoji_name })
99101 end
100102
101103 # Deletes a single award emoji from an awardable(issue, merge request or snippet)
131133 delete("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji/#{award_id}")
132134 end
133135 end
134 end
136 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to issue boards.
24 # @see https://docs.gitlab.com/ce/api/boards.html
1214 # @option options [Integer] :page The page number.
1315 # @option options [Integer] :per_page The number of results per page.
1416 # @return [Array<Gitlab::ObjectifiedHash>]
15 def boards(project, options={})
17 def boards(project, options = {})
1618 get("/projects/#{url_encode project}/boards", query: options)
1719 end
1820
2729 def board_lists(project, id)
2830 get("/projects/#{url_encode project}/boards/#{id}/lists")
2931 end
32
3033 #
3134 # Gets a single board list
3235 #
5255 # @param [Integer] label_id The ID of a label.
5356 # @return [Gitlab::ObjectifiedHash] Information about created list.
5457 def create_board_list(project, board_id, label_id)
55 post("/projects/#{url_encode project}/boards/#{board_id}/lists", body: {label_id: label_id})
58 post("/projects/#{url_encode project}/boards/#{board_id}/lists", body: { label_id: label_id })
5659 end
5760
5861 # Updates a board list.
6669 # @param [Integer] id The ID of a list.
6770 # @return [Gitlab::ObjectifiedHash] Information about updated board list.
6871 def edit_board_list(project, board_id, id, position)
69 put("/projects/#{url_encode project}/boards/#{board_id}/lists/#{id}", body: {position: position})
72 put("/projects/#{url_encode project}/boards/#{board_id}/lists/#{id}", body: { position: position })
7073 end
7174
7275 # Deletes a board list.
8487 end
8588 end
8689 end
87
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to repositories.
24 # @see https://docs.gitlab.com/ce/api/branches.html
1113 # @option options [Integer] :page The page number.
1214 # @option options [Integer] :per_page The number of results per page.
1315 # @return [Array<Gitlab::ObjectifiedHash>]
14 def branches(project, options={})
16 def branches(project, options = {})
1517 get("/projects/#{url_encode project}/repository/branches", query: options)
1618 end
17 alias_method :repo_branches, :branches
19 alias repo_branches branches
1820
1921 # Gets information about a repository branch.
2022 #
2830 def branch(project, branch)
2931 get("/projects/#{url_encode project}/repository/branches/#{url_encode branch}")
3032 end
31 alias_method :repo_branch, :branch
33 alias repo_branch branch
3234
3335 # Protects a repository branch.
3436 #
4648 # @option options [Boolean] :developers_can_merge True to allow developers to merge into the branch (default = false)
4749 # @return [Gitlab::ObjectifiedHash] Details about the branch
4850 def protect_branch(project, branch, options = {})
49 post("/projects/#{url_encode project}/protected_branches", body: {name: branch}.merge(options))
51 post("/projects/#{url_encode project}/protected_branches", body: { name: branch }.merge(options))
5052 end
51 alias_method :repo_protect_branch, :protect_branch
53 alias repo_protect_branch protect_branch
5254
5355 # Unprotects a repository branch.
5456 #
6264 def unprotect_branch(project, branch)
6365 delete("/projects/#{url_encode project}/protected_branches/#{url_encode branch}")
6466 end
65 alias_method :repo_unprotect_branch, :unprotect_branch
67 alias repo_unprotect_branch unprotect_branch
6668
6769 # Creates a repository branch. Requires Gitlab >= 6.8.x
6870 #
7779 def create_branch(project, branch, ref)
7880 post("/projects/#{url_encode project}/repository/branches", query: { branch: branch, ref: ref })
7981 end
80 alias_method :repo_create_branch, :create_branch
82 alias repo_create_branch create_branch
8183
8284 # Deletes a repository branch. Requires Gitlab >= 6.8.x
8385 #
9092 def delete_branch(project, branch)
9193 delete("/projects/#{url_encode project}/repository/branches/#{url_encode branch}")
9294 end
93 alias_method :repo_delete_branch, :delete_branch
95 alias repo_delete_branch delete_branch
96
97 # Delete all branches that are merged into the project default branch. Protected branches will not be deleted as part of this operation.
98 #
99 # @example
100 # Gitlab.delete_merged_branches(3)
101 #
102 # @param [Integer, String] project The ID or name of a project.
103 # @return [nil] This API call returns an empty response body.
104 def delete_merged_branches(project)
105 delete("/projects/#{url_encode project}/repository/merged_branches")
106 end
107 alias repo_delete_merged_branches delete_merged_branches
108
109 # Gets a list of protected branches from a project.
110 #
111 # @example
112 # Gitlab.protected_branches(42)
113 #
114 # @param [Integer, String] project The ID or name of a project.
115 # @return [Array<Gitlab::ObjectifiedHash>]
116 def protected_branches(project)
117 get("/projects/#{url_encode project}/protected_branches")
118 end
119 alias repo_protected_branches protected_branches
120
121 # Gets a single protected branch or wildcard protected branch
122 #
123 # @example
124 # Gitlab.protected_branch(3, 'api')
125 #
126 # @param [Integer, String] project The ID or name of a project.
127 # @param [String] name The name of the branch or wildcard
128 # @return [Gitlab::ObjectifiedHash]
129 def protected_branch(project, branch)
130 get("/projects/#{url_encode project}/protected_branches/#{url_encode branch}")
131 end
132 alias repo_protected_branch protected_branch
94133 end
95134 end
0 # frozen_string_literal: true
1
2 class Gitlab::Client
3 # Defines methods related to broadcast messages (only accessible to administrators).
4 # @see https://docs.gitlab.com/ce/api/broadcast_messages.html
5 module BroadcastMessages
6 # Get all broadcast messages
7 #
8 # @example
9 # Gitlab.broadcast_messages
10 #
11 # @return [Array<Gitlab::ObjectifiedHash>]
12 def broadcast_messages
13 get('/broadcast_messages')
14 end
15
16 # Get a specific broadcast message
17 #
18 # @example
19 # Gitlab.broadcast_message(3)
20 #
21 # @param [Integer] id The ID of broadcast message
22 # @return [Gitlab::ObjectifiedHash]
23 def broadcast_message(id)
24 get("/broadcast_messages/#{id}")
25 end
26
27 # Create a broadcast message.
28 #
29 # @example
30 # Gitlab.create_broadcast_message('Mayday')
31 # Gitlab.create_broadcast_message('Mayday', {starts_at: Time.zone.now, ends_at: Time.zone.now + 30.minutes, color: '#cecece', font: '#FFFFFF'})
32 #
33 # @param [String] message Message to display
34 # @param [Hash] options A customizable set of options.
35 # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time)
36 # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time)
37 # @option options [String] :color(optional) Background color hex code
38 # @option options [String] :font(optional) Foreground color hex code
39 # @return [Gitlab::ObjectifiedHash] Information about created broadcast message.
40 def create_broadcast_message(message, options = {})
41 body = { message: message }.merge(options)
42 post('/broadcast_messages', body: body)
43 end
44
45 # Update a broadcast message
46 #
47 # @example
48 # Gitlab.edit_broadcast_message(6, { message: 'No Mayday' })
49 # Gitlab.edit_broadcast_message(6, { font: '#FEFEFE' })
50 #
51 # @param [Integer] id The ID of a broadcast message
52 # @param [Hash] options A customizable set of options.
53 # @option options [String] :message(optional) Message to display
54 # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time)
55 # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time)
56 # @option options [String] :color(optional) Background color hex code
57 # @option options [String] :font(optional) Foreground color hex code
58 # @return [Gitlab::ObjectifiedHash] Information about updated broadcast message.
59 def edit_broadcast_message(id, options = {})
60 put("/broadcast_messages/#{id}", body: options)
61 end
62
63 # Delete a broadcast message.
64 #
65 # @example
66 # Gitlab.delete_broadcast_message(3)
67 #
68 # @param [Integer] id The ID of a broadcast message.
69 # @return [nil] This API call returns an empty response body.
70 def delete_broadcast_message(id)
71 delete("/broadcast_messages/#{id}")
72 end
73 end
74 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to builds.
24 # @see https://docs.gitlab.com/ce/api/build_variables.html
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to builds.
24 # @see https://docs.gitlab.com/ce/api/builds.html
1315 # @option options [Integer] :per_page The number of results per page.
1416 # @param [Integer, String] project The ID or name of a project.
1517 # @return [Array<Gitlab::ObjectifiedHash>]
16 def builds(project, options={})
18 def builds(project, options = {})
1719 get("/projects/#{url_encode project}/builds", query: options)
1820 end
1921
3941 # @return [Gitlab::FileResponse]
4042 def build_artifacts(project, id)
4143 get("/projects/#{url_encode project}/builds/#{id}/artifacts",
42 format: nil,
43 headers: { Accept: 'application/octet-stream' },
44 parser: proc { |body, _|
45 if body.encoding == Encoding::ASCII_8BIT # binary response
46 ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
47 else # error with json response
48 ::Gitlab::Request.parse(body)
49 end
50 })
44 format: nil,
45 headers: { Accept: 'application/octet-stream' },
46 parser: proc { |body, _|
47 if body.encoding == Encoding::ASCII_8BIT # binary response
48 ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
49 else # error with json response
50 ::Gitlab::Request.parse(body)
51 end
52 })
5153 end
5254
5355 # Gets a list of builds for specific commit in a project.
6264 # @option options [Integer] :page The page number.
6365 # @option options [Integer] :per_page The number of results per page.
6466 # @return [Array<Gitlab::ObjectifiedHash>] The list of builds.
65 def commit_builds(project, sha, options={})
67 def commit_builds(project, sha, options = {})
6668 get("/projects/#{url_encode project}/repository/commits/#{sha}/builds", query: options)
6769 end
6870
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to repository commits.
24 # @see https://docs.gitlab.com/ce/api/commits.html
1315 # @option options [Integer] :page The page number.
1416 # @option options [Integer] :per_page The number of results per page.
1517 # @return [Array<Gitlab::ObjectifiedHash>]
16 def commits(project, options={})
18 def commits(project, options = {})
1719 get("/projects/#{url_encode project}/repository/commits", query: options)
1820 end
19 alias_method :repo_commits, :commits
21 alias repo_commits commits
2022
2123 # Gets a specific commit identified by the commit hash or name of a branch or tag.
2224 #
3032 def commit(project, sha)
3133 get("/projects/#{url_encode project}/repository/commits/#{sha}")
3234 end
33 alias_method :repo_commit, :commit
35 alias repo_commit commit
36
37 # Cherry picks a commit to a given branch.
38 #
39 # @example
40 # Gitlab.cherry_pick_commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master')
41 #
42 # @param [Integer, String] project The ID or name of a project.
43 # @param [String] sha The commit hash or name of a repository branch or tag
44 # @param [String] branch The name of the branch
45 # @return [Gitlab::ObjectifiedHash]
46 def cherry_pick_commit(project, sha, branch)
47 post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: { branch: branch })
48 end
3449
3550 # Get the diff of a commit in a project.
3651 #
4459 def commit_diff(project, sha)
4560 get("/projects/#{url_encode project}/repository/commits/#{sha}/diff")
4661 end
47 alias_method :repo_commit_diff, :commit_diff
62 alias repo_commit_diff commit_diff
4863
4964 # Gets a list of comments for a commit.
5065 #
5671 # @option options [Integer] :page The page number.
5772 # @option options [Integer] :per_page The number of results per page.
5873 # @return [Array<Gitlab::ObjectifiedHash>]
59 def commit_comments(project, commit, options={})
74 def commit_comments(project, commit, options = {})
6075 get("/projects/#{url_encode project}/repository/commits/#{commit}/comments", query: options)
6176 end
62 alias_method :repo_commit_comments, :commit_comments
77 alias repo_commit_comments commit_comments
6378
6479 # Creates a new comment for a commit.
6580 #
7489 # @option options [Integer] :line The line number.
7590 # @option options [String] :line_type The line type (new or old).
7691 # @return [Gitlab::ObjectifiedHash] Information about created comment.
77 def create_commit_comment(project, commit, note, options={})
92 def create_commit_comment(project, commit, note, options = {})
7893 post("/projects/#{url_encode project}/repository/commits/#{commit}/comments", body: options.merge(note: note))
7994 end
80 alias_method :repo_create_commit_comment, :create_commit_comment
95 alias repo_create_commit_comment create_commit_comment
8196
8297 # Get the status of a commit
8398 #
93108 # @option options [String] :stage Filter by stage
94109 # @option options [String] :name Filter by status name, eg. jenkins
95110 # @option options [Boolean] :all The flag to return all statuses, not only latest ones
96 def commit_status(project, sha, options={})
111 def commit_status(project, sha, options = {})
97112 get("/projects/#{url_encode project}/repository/commits/#{sha}/statuses", query: options)
98113 end
99 alias_method :repo_commit_status, :commit_status
114 alias repo_commit_status commit_status
100115
101116 # Adds or updates a status of a commit.
102117 #
112127 # @option options [String] :ref The ref (branch or tag) to which the status refers
113128 # @option options [String] :name Filter by status name, eg. jenkins
114129 # @option options [String] :target_url The target URL to associate with this status
115 def update_commit_status(project, sha, state, options={})
130 def update_commit_status(project, sha, state, options = {})
116131 post("/projects/#{url_encode project}/statuses/#{sha}", query: options.merge(state: state))
117132 end
118 alias_method :repo_update_commit_status, :update_commit_status
133 alias repo_update_commit_status update_commit_status
119134
120135 # Creates a single commit with one or more changes
121136 #
133148 # @option options [String] :author_email the email address of the author
134149 # @option options [String] :author_name the name of the author
135150 # @return [Gitlab::ObjectifiedHash] hash of commit related data
136 def create_commit(project, branch, message, actions, options={})
151 def create_commit(project, branch, message, actions, options = {})
137152 payload = {
138 branch: branch,
139 commit_message: message,
140 actions: actions,
153 branch: branch,
154 commit_message: message,
155 actions: actions
141156 }.merge(options)
142157 post("/projects/#{url_encode project}/repository/commits", body: payload)
143158 end
155170 # @option options [Integer] :page The page number.
156171 # @option options [Integer] :per_page The number of results per page.
157172 # @return [Array<Gitlab::ObjectifiedHash>]
158 def commit_merge_requests(project, commit, options={})
173 def commit_merge_requests(project, commit, options = {})
159174 get("/projects/#{url_encode project}/repository/commits/#{commit}/merge_requests", query: options)
160175 end
161 alias_method :repo_commit_merge_requests, :commit_merge_requests
176 alias repo_commit_merge_requests commit_merge_requests
162177 end
163178 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to deployments.
24 # @see https://docs.gitlab.com/ce/api/deployments.html
1214 # @option options [Integer] :page The page number.
1315 # @option options [Integer] :per_page The number of results per page.
1416 # @return [Array<Gitlab::ObjectifiedHash>]
15 def deployments(project, options={})
17 def deployments(project, options = {})
1618 get("/projects/#{url_encode project}/deployments", query: options)
1719 end
1820
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to environments.
24 # @see https://docs.gitlab.com/ce/api/environments.html
1214 # @option options [Integer] :page The page number.
1315 # @option options [Integer] :per_page The number of results per page.
1416 # @return [Array<Gitlab::ObjectifiedHash>]
15 def environments(project, options={})
17 def environments(project, options = {})
1618 get("/projects/#{url_encode project}/environments", query: options)
1719 end
1820
3941 # @option options [String] :external_url Optional URL for viewing the deployed project in this environment
4042 # @return [Gitlab::ObjectifiedHash] The updated environment.
4143 def create_environment(project, env_name, options = {})
42 body = {name: env_name}.merge(options)
44 body = { name: env_name }.merge(options)
4345 post("/projects/#{url_encode project}/environments", body: body)
4446 end
4547
5557 # @option options [String] env_name Name for the environment
5658 # @option options [String] external_url Optional URL for viewing the deployed project in this environment
5759 # @return [Gitlab::ObjectifiedHash] The updated environment.
58 def edit_environment(project, id, options={})
60 def edit_environment(project, id, options = {})
5961 put("/projects/#{url_encode project}/environments/#{id}", body: options)
6062 end
6163
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to events.
24 # @see https://docs.gitlab.com/ce/api/events.html
1416 # @option options [String] :after Only events created after YYYY-MM-DD
1517 # @option options [String] :sort Sort by created_at either 'asc' or 'desc'
1618 # @return [Array<Gitlab::ObjectifiedHash>]
17 def events(options={})
19 def events(options = {})
1820 get('/events', query: options)
1921 end
2022
3234 # @option options [String] :after Only events created after YYYY-MM-DD
3335 # @option options [String] :sort Sort by created_at either 'asc' or 'desc'
3436 # @return [Array<Gitlab::ObjectifiedHash>]
35 def user_events(user, options={})
37 def user_events(user, options = {})
3638 get("/users/#{url_encode user}/events", query: options)
3739 end
3840
5052 # @option options [String] :after Only events created after YYYY-MM-DD
5153 # @option options [String] :sort Sort by created_at either 'asc' or 'desc'
5254 # @return [Array<Gitlab::ObjectifiedHash>]
53 def project_events(project, options={})
54 get("/#{url_encode project}/events", query: options)
55 def project_events(project, options = {})
56 get("/projects/#{url_encode project}/events", query: options)
5557 end
5658 end
5759 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to group milestones.
24 # @see https://docs.gitlab.com/ee/api/group_milestones.html
1113 # @option options [Integer] :page The page number.
1214 # @option options [Integer] :per_page The number of results per page.
1315 # @return [Array<Gitlab::ObjectifiedHash>]
14 def group_milestones(id, options={})
16 def group_milestones(id, options = {})
1517 get("/groups/#{url_encode id}/milestones", query: options)
1618 end
1719
3840 # @option options [String] :description The description of a milestone.
3941 # @option options [String] :due_date The due date of a milestone.
4042 # @return [Gitlab::ObjectifiedHash] Information about created milestone.
41 def create_group_milestone(id, title, options={})
43 def create_group_milestone(id, title, options = {})
4244 body = { title: title }.merge(options)
4345 post("/groups/#{url_encode id}/milestones", body: body)
4446 end
5658 # @option options [String] :due_date The due date of a milestone.
5759 # @option options [String] :state_event The state of a milestone ('close' or 'activate').
5860 # @return [Gitlab::ObjectifiedHash] Information about updated milestone.
59 def edit_group_milestone(id, milestone_id, options={})
61 def edit_group_milestone(id, milestone_id, options = {})
6062 put("/groups/#{url_encode id}/milestones/#{milestone_id}", body: options)
6163 end
6264
7072 # @option options [Integer] :page The page number.
7173 # @option options [Integer] :per_page The number of results per page.
7274 # @return [Array<Gitlab::ObjectifiedHash>]
73 def group_milestone_issues(id, milestone_id, options={})
75 def group_milestone_issues(id, milestone_id, options = {})
7476 get("/groups/#{url_encode id}/milestones/#{milestone_id}/issues", query: options)
7577 end
7678
8486 # @option options [Integer] :page The page number.
8587 # @option options [Integer] :per_page The number of results per page.
8688 # @return [Array<Gitlab::ObjectifiedHash>]
87 def group_milestone_merge_requests(id, milestone_id, options={})
89 def group_milestone_merge_requests(id, milestone_id, options = {})
8890 get("/groups/#{url_encode id}/milestones/#{milestone_id}/merge_requests", query: options)
8991 end
9092 end
9193 end
92
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to groups.
24 # @see https://docs.gitlab.com/ce/api/groups.html
1113 # @option options [Integer] :page The page number.
1214 # @option options [Integer] :per_page The number of results per page.
1315 # @return [Array<Gitlab::ObjectifiedHash>]
14 def groups(options={})
15 get("/groups", query: options)
16 def groups(options = {})
17 get('/groups', query: options)
1618 end
1719
1820 # Gets a single group.
3537 # @param [String] name The name of a group.
3638 # @param [String] path The path of a group.
3739 # @return [Gitlab::ObjectifiedHash] Information about created group.
38 def create_group(name, path, options={})
40 def create_group(name, path, options = {})
3941 body = { name: name, path: path }.merge(options)
40 post("/groups", body: body)
42 post('/groups', body: body)
4143 end
4244
4345 # Delete's a group.
6163 # @option options [Integer] :page The page number.
6264 # @option options [Integer] :per_page The number of results per page.
6365 # @return [Array<Gitlab::ObjectifiedHash>]
64 def group_members(id, options={})
66 def group_members(id, options = {})
6567 get("/groups/#{url_encode id}/members", query: options)
6668 end
6769
137139 # @option options [String] :per_page Number of projects to return per page
138140 # @option options [String] :page The page to retrieve
139141 # @return [Array<Gitlab::ObjectifiedHash>]
140 def group_search(search, options={})
142 def group_search(search, options = {})
141143 options[:search] = search
142 get("/groups", query: options)
144 get('/groups', query: options)
143145 end
144146
145147 # Get a list of projects under a group
148150 #
149151 # @param [Integer] id The ID of a group
150152 # @return [Array<Gitlab::ObjectifiedHash>] List of projects under a group
151 def group_projects(id, options={})
153 def group_projects(id, options = {})
152154 get("/groups/#{url_encode id}/projects", query: options)
153155 end
154156
166168 # @option options [String] :statistics Include group statistics (admins only).
167169 # @option options [String] :owned Limit to groups owned by the current user.
168170 # @return [Array<Gitlab::ObjectifiedHash>] List of subgroups under a group
169 def group_subgroups(id, options={})
171 def group_subgroups(id, options = {})
170172 get("/groups/#{url_encode id}/subgroups", query: options)
171173 end
172174
185187 # @option options [String] :lfs_enabled Enable/disable Large File Storage (LFS) for the projects in this groupr.
186188 # @option options [String] :request_access_enabled Allow users to request member access.
187189 # @return [Gitlab::ObjectifiedHash] Information about the edited group.
188 def edit_group(id, options={})
190 def edit_group(id, options = {})
189191 put("/groups/#{url_encode id}", body: options)
190192 end
191193 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to issues.
24 # @see https://docs.gitlab.com/ce/api/issues.html
1416 # @option options [Integer] :page The page number.
1517 # @option options [Integer] :per_page The number of results per page.
1618 # @return [Array<Gitlab::ObjectifiedHash>]
17 def issues(project=nil, options={})
19 def issues(project = nil, options = {})
1820 if project.to_s.empty? && project.to_i.zero?
19 get("/issues", query: options)
21 get('/issues', query: options)
2022 else
2123 get("/projects/#{url_encode project}/issues", query: options)
2224 end
4850 # @option options [Integer] :milestone_id The ID of a milestone to assign issue.
4951 # @option options [String] :labels Comma-separated label names for an issue.
5052 # @return [Gitlab::ObjectifiedHash] Information about created issue.
51 def create_issue(project, title, options={})
53 def create_issue(project, title, options = {})
5254 body = { title: title }.merge(options)
5355 post("/projects/#{url_encode project}/issues", body: body)
5456 end
6870 # @option options [String] :labels Comma-separated label names for an issue.
6971 # @option options [String] :state_event The state event of an issue ('close' or 'reopen').
7072 # @return [Gitlab::ObjectifiedHash] Information about updated issue.
71 def edit_issue(project, id, options={})
73 def edit_issue(project, id, options = {})
7274 put("/projects/#{url_encode project}/issues/#{id}", body: options)
7375 end
7476
142144 # @param [Integer] id The ID of an issue.
143145 # @option options [String] :to_project_id The ID of the new project.
144146 # @return [Gitlab::ObjectifiedHash] Information about moved issue.
145 def move_issue(project, id, options={})
147 def move_issue(project, id, options = {})
146148 post("/projects/#{url_encode project}/issues/#{id}/move", body: options)
147149 end
148
150
149151 # Sets an estimated time of work for an issue.
150152 #
151153 # @example
157159 def estimate_time_of_issue(project, id, duration)
158160 post("/projects/#{url_encode project}/issues/#{id}/time_estimate", body: { duration: url_encode(duration) })
159161 end
160
161 # Resets the estimated time for an issue to 0 seconds.
162
163 # Resets the estimated time for an issue to 0 seconds.
162164 #
163165 # @example
164166 # Gitlab.reset_time_estimate_of_issue(3, 42)
168170 def reset_time_estimate_of_issue(project, id)
169171 post("/projects/#{url_encode project}/issues/#{id}/reset_time_estimate")
170172 end
171
173
172174 # Adds spent time for an issue
173175 #
174176 # @example
180182 def add_time_spent_on_issue(project, id, duration)
181183 post("/projects/#{url_encode project}/issues/#{id}/add_spent_time", body: { duration: url_encode(duration) })
182184 end
183
185
184186 # Resets the total spent time for this issue to 0 seconds.
185187 #
186188 # @example
191193 def reset_time_spent_on_issue(project, id)
192194 post("/projects/#{url_encode project}/issues/#{id}/reset_spent_time")
193195 end
194
196
195197 # Get time tracking stats for an issue
196198 #
197199 # @example
202204 def time_stats_for_issue(project, id)
203205 get("/projects/#{url_encode project}/issues/#{id}/time_stats")
204206 end
205
207
208 # Get participants on issue
209 #
210 # @example
211 # @gitlab.participants_on_issue(3, 42)
212 #
213 # @param [Integer, String] project The ID or name of a project.
214 # @param [Integer] id The ID of an issue.
215 def participants_on_issue(project, id)
216 get("/projects/#{url_encode project}/issues/#{id}/participants")
217 end
218
219 # List merge requests that will close issue on merge
220 #
221 # @example
222 # Gitlab.merge_requests_closing_issue_on_merge(3, 42)
223 #
224 # @param [Integer, String] project The ID or name of a project.
225 # @param [Integer] id The ID of an issue.
226 def merge_requests_closing_issue_on_merge(project, id)
227 get("/projects/#{url_encode project}/issues/#{id}/closed_by")
228 end
206229 end
207230 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to projects.
24 # @see https://docs.gitlab.com/ee/api/jobs.html
68 # @example
79 # Gitlab.jobs(1)
810 # Gitlab.jobs("project")
11 # Gitlab.jobs("project", {scope: ["manual", "success"], per_page: 100 })
912 #
1013 # @param [Integer, String] id The ID or name of a project.
1114 # @param [Hash] options A customizable set of options.
1215 # @option options [Array] :scope The scope of jobs to show, one or array of: created, pending, running, failed, success, canceled, skipped, manual; showing all jobs if none provided.
16 # @option options [Integer] :page The page number.
17 # @option options [Integer] :per_page The number of results per page.
1318 # @return [Array<Gitlab::ObjectifiedHash>]
1419 def jobs(project_id, options = {})
1520 get("/projects/#{url_encode project_id}/jobs", query: options)
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to keys.
24 # @see https://docs.gitlab.com/ce/api/keys.html
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to labels.
24 # @see https://docs.gitlab.com/ce/api/labels.html
810 #
911 # @param [Integer, String] project The ID or name of a project.
1012 # @return [Array<Gitlab::ObjectifiedHash>]
11 def labels(project, options={})
13 def labels(project, options = {})
1214 get("/projects/#{url_encode project}/labels", query: options)
1315 end
1416
4244 # @option options [String] :description The description of the label.
4345 # @option options [String] :priority The priority of the label. Must be greater or equal than zero or null to remove the priority.
4446 # @return [Gitlab::ObjectifiedHash] Information about updated label.
45 def edit_label(project, name, options={})
47 def edit_label(project, name, options = {})
4648 put("/projects/#{url_encode project}/labels", body: options.merge(name: name))
4749 end
4850
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to MR Approvals.
24 # @see https://docs.gitlab.com/ee/api/merge_request_approvals.html
106108 post("/projects/#{url_encode project}/merge_requests/#{merge_request}/unapprove")
107109 end
108110 end
109 end
111 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to merge requests.
24 # @see https://docs.gitlab.com/ce/api/merge_requests.html
2426 # @option options [Integer] :page The page number.
2527 # @option options [Integer] :per_page The number of results per page.
2628 # @return [Array<Gitlab::ObjectifiedHash>]
27 def merge_requests(project, options={})
29 def merge_requests(project, options = {})
2830 get("/projects/#{url_encode project}/merge_requests", query: options)
2931 end
3032
3840 # @return <Gitlab::ObjectifiedHash]
3941 def merge_request(project, id)
4042 get("/projects/#{url_encode project}/merge_requests/#{id}")
43 end
44
45 # Gets a list of merge request pipelines.
46 #
47 # @example
48 # Gitlab.merge_request_pipelines(5, 36)
49 #
50 # @param [Integer, String] project The ID or name of a project.
51 # @param [Integer] id The ID of a merge request.
52 # @return [Array<Gitlab::ObjectifiedHash>]
53 def merge_request_pipelines(project, id)
54 get("/projects/#{url_encode project}/merge_requests/#{id}/pipelines")
4155 end
4256
4357 # Creates a merge request.
5771 # @option options [Integer] :target_project_id (optional) The target project ID.
5872 # @option options [String] :labels (optional) Labels as a comma-separated list.
5973 # @return [Gitlab::ObjectifiedHash] Information about created merge request.
60 def create_merge_request(project, title, options={})
74 def create_merge_request(project, title, options = {})
6175 body = { title: title }.merge(options)
6276 post("/projects/#{url_encode project}/merge_requests", body: body)
6377 end
7690 # @option options [Integer] :assignee_id The ID of a user to assign merge request.
7791 # @option options [String] :state_event New state (close|reopen|merge).
7892 # @return [Gitlab::ObjectifiedHash] Information about updated merge request.
79 def update_merge_request(project, id, options={})
93 def update_merge_request(project, id, options = {})
8094 put("/projects/#{url_encode project}/merge_requests/#{id}", body: options)
8195 end
8296
90104 # @param [Hash] options A customizable set of options.
91105 # @option options [String] :merge_commit_message Custom merge commit message
92106 # @return [Gitlab::ObjectifiedHash] Information about updated merge request.
93 def accept_merge_request(project, id, options={})
107 def accept_merge_request(project, id, options = {})
94108 put("/projects/#{url_encode project}/merge_requests/#{id}/merge", body: options)
95109 end
96110
204218 # * :x (Integer) X coordinate (for 'image' diff notes)
205219 # * :y (Integer) Y coordinate (for 'image' diff notes)
206220 # @return [Gitlab::ObjectifiedHash] The created merge request discussion.
207 def create_merge_request_discussion(project, merge_request_id, options={})
221 def create_merge_request_discussion(project, merge_request_id, options = {})
208222 post("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions", body: options)
209223 end
210224
270284 def delete_merge_request_discussion_note(project, merge_request_id, discussion_id, note_id)
271285 delete("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}/notes/#{note_id}")
272286 end
287
288 # Gets a list of merge request diff versions
289 #
290 # @example
291 # Gitlab.merge_request_versions(5, 1)
292 # Gitlab.merge_request_versions('gitlab', 1)
293 # @param [Integer, String] project The ID or name of a project.
294 # @param [Integer] id The ID of a merge request.
295 # @return [Gitlab::ObjectifiedHash] A list of the merge request versions.
296 def merge_request_diff_versions(project, merge_request_id)
297 get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions")
298 end
299
300 # Gets the diff a single merge request diff version\
301 #
302 # @example
303 # Gitlab.merge_request_diff_version(5, 1, 1)
304 # Gitlab.merge_request_diff_version('gitlab', 1, 1)
305 # @param [Integer, String] project The ID or name of a project.
306 # @param [Integer] id The ID of a merge request.
307 # @param [Integer] id The ID of a merge request diff version.
308 # @return [Gitlab::ObjectifiedHash] Record of the specific diff
309 def merge_request_diff_version(project, merge_request_id, version_id)
310 get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions/#{version_id}")
311 end
273312 end
274313 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to milestones.
24 # @see https://docs.gitlab.com/ce/api/milestones.html
1113 # @option options [Integer] :page The page number.
1214 # @option options [Integer] :per_page The number of results per page.
1315 # @return [Array<Gitlab::ObjectifiedHash>]
14 def milestones(project, options={})
16 def milestones(project, options = {})
1517 get("/projects/#{url_encode project}/milestones", query: options)
1618 end
1719
3739 # @option options [Integer] :page The page number.
3840 # @option options [Integer] :per_page The number of results per page.
3941 # @return [Array<Gitlab::ObjectifiedHash>]
40 def milestone_issues(project, milestone, options={})
42 def milestone_issues(project, milestone, options = {})
4143 get("/projects/#{url_encode project}/milestones/#{milestone}/issues", query: options)
4244 end
4345
5153 # @option options [Integer] :page The page number.
5254 # @option options [Integer] :per_page The number of results per page.
5355 # @return [Array<Gitlab::ObjectifiedHash>]
54 def milestone_merge_requests(project, milestone, options={})
56 def milestone_merge_requests(project, milestone, options = {})
5557 get("/projects/#{url_encode project}/milestones/#{milestone}/merge_requests", query: options)
5658 end
5759
6668 # @option options [String] :description The description of a milestone.
6769 # @option options [String] :due_date The due date of a milestone.
6870 # @return [Gitlab::ObjectifiedHash] Information about created milestone.
69 def create_milestone(project, title, options={})
71 def create_milestone(project, title, options = {})
7072 body = { title: title }.merge(options)
7173 post("/projects/#{url_encode project}/milestones", body: body)
7274 end
8486 # @option options [String] :due_date The due date of a milestone.
8587 # @option options [String] :state_event The state of a milestone ('close' or 'activate').
8688 # @return [Gitlab::ObjectifiedHash] Information about updated milestone.
87 def edit_milestone(project, id, options={})
89 def edit_milestone(project, id, options = {})
8890 put("/projects/#{url_encode project}/milestones/#{id}", body: options)
91 end
92
93 # Delete a project milestone.
94 #
95 # @example
96 # Gitlab.delete_milestone(5, 2)
97 #
98 # @param [Integer, String] project The ID or name of a project.
99 # @param [Integer] id The ID of a milestone.
100 # @return [nil] This API call returns an empty response body.
101 def delete_milestone(project, id)
102 delete("/projects/#{url_encode project}/milestones/#{id}")
89103 end
90104 end
91105 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to namespaces
24 # @see https://docs.gitlab.com/ce/api/namespaces.html
1214 # @options options [Integer] :per_page The number of results per page.
1315 # @options opttion [String] :search The string to search for.
1416 # @return [Array<Gitlab::ObjectifiedHash>]
15 def namespaces(options={})
16 get("/namespaces", query: options)
17 def namespaces(options = {})
18 get('/namespaces', query: options)
1719 end
1820 end
1921 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to notes.
24 # @see https://docs.gitlab.com/ce/api/notes.html
1012 # @option options [Integer] :page The page number.
1113 # @option options [Integer] :per_page The number of results per page.
1214 # @return [Array<Gitlab::ObjectifiedHash>]
13 def notes(project, options={})
15 def notes(project, options = {})
1416 get("/projects/#{url_encode project}/notes", query: options)
1517 end
1618
2426 # @option options [Integer] :page The page number.
2527 # @option options [Integer] :per_page The number of results per page.
2628 # @return [Array<Gitlab::ObjectifiedHash>]
27 def issue_notes(project, issue, options={})
29 def issue_notes(project, issue, options = {})
2830 get("/projects/#{url_encode project}/issues/#{issue}/notes", query: options)
2931 end
3032
3840 # @option options [Integer] :page The page number.
3941 # @option options [Integer] :per_page The number of results per page.
4042 # @return [Array<Gitlab::ObjectifiedHash>]
41 def snippet_notes(project, snippet, options={})
43 def snippet_notes(project, snippet, options = {})
4244 get("/projects/#{url_encode project}/snippets/#{snippet}/notes", query: options)
4345 end
4446
5254 # @option options [Integer] :page The page number.
5355 # @option options [Integer] :per_page The number of results per page.
5456 # @return [Array<Gitlab::ObjectifiedHash>]
55 def merge_request_notes(project, merge_request, options={})
57 def merge_request_notes(project, merge_request, options = {})
5658 get("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes", query: options)
5759 end
58 alias_method :merge_request_comments, :merge_request_notes
60 alias merge_request_comments merge_request_notes
5961
6062 # Gets a single wall note.
6163 #
157159 def create_merge_request_note(project, merge_request, body)
158160 post("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes", body: { body: body })
159161 end
160 alias_method :create_merge_request_comment, :create_merge_request_note
162 alias create_merge_request_comment create_merge_request_note
161163
162164 # Deletes a wall note.
163165 #
209211 def delete_merge_request_note(project, merge_request, id)
210212 delete("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes/#{id}")
211213 end
212 alias_method :delete_merge_request_comment, :delete_merge_request_note
214 alias delete_merge_request_comment delete_merge_request_note
213215
214216 # Modifies a wall note.
215217 #
265267 def edit_merge_request_note(project, merge_request, id, body)
266268 put("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes/#{id}", body: note_content(body))
267269 end
268 alias_method :edit_merge_request_comment, :edit_merge_request_note
270 alias edit_merge_request_comment edit_merge_request_note
269271
270272 private
271273
273275 # in the 'else'.
274276 def note_content(body)
275277 if body.is_a?(Hash)
276 STDERR.puts "Passing the note body as a Hash is deprecated. You should just pass the String."
278 STDERR.puts 'Passing the note body as a Hash is deprecated. You should just pass the String.'
277279 body
278280 else
279281 { body: body }
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to pipeline schedules.
24 # @see https://docs.gitlab.com/ce/api/pipeline_schedules.html
1113 # @param [Hash] options A customizable set of options.
1214 # @options options [String] :scope The scope of pipeline schedules, one of a 'active' or 'inactive'.
1315 # @return [Array<Gitlab::ObjectifiedHash>]
14 def pipeline_schedules(project, options={})
16 def pipeline_schedules(project, options = {})
1517 get("/projects/#{url_encode project}/pipeline_schedules", query: options)
1618 end
1719
4042 # @option options [String] :cron_timezone The timezone supproted by ActiveSupport::TimeZone (e.g. Pacific Time (US & Canada)) (default: 'UTC').
4143 # @option options [Boolean] :active The activation of pipeline schedule. If false is set, the pipeline schedule will deactivated initially (default: true).
4244 # @return [Array<Gitlab::ObjectifiedHash>]
43 def create_pipeline_schedule(project, options={})
45 def create_pipeline_schedule(project, options = {})
4446 post("/projects/#{url_encode project}/pipeline_schedules", query: options)
4547 end
4648
5860 # @option options [String] :cron_timezone The timezone supproted by ActiveSupport::TimeZone (e.g. Pacific Time (US & Canada)) (default: 'UTC').
5961 # @option options [Boolean] :active The activation of pipeline schedule. If false is set, the pipeline schedule will deactivated initially (default: true).
6062 # @return [Array<Gitlab::ObjectifiedHash>] The updated pipeline schedule.
61 def edit_pipeline_schedule(project, pipeline_schedule_id, options={})
63 def edit_pipeline_schedule(project, pipeline_schedule_id, options = {})
6264 put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}", query: options)
6365 end
6466
9799 # @option options [String] :key The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed.
98100 # @option options [String] :value The value of a variable
99101 # @return [Array<Gitlab::ObjectifiedHash>] The created pipeline schedule variable.
100 def create_pipeline_schedule_variable(project, pipeline_schedule_id, options={})
102 def create_pipeline_schedule_variable(project, pipeline_schedule_id, options = {})
101103 post("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables", query: options)
102104 end
103105
112114 # @param [Hash] options A customizable set of options.
113115 # @option options [String] :value The value of a variable.
114116 # @return [Array<Gitlab::ObjectifiedHash>] The updated pipeline schedule variable.
115 def edit_pipeline_schedule_variable(project, pipeline_schedule_id, key, options={})
117 def edit_pipeline_schedule_variable(project, pipeline_schedule_id, key, options = {})
116118 put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables/#{url_encode key}", query: options)
117119 end
118120
125127 # @param [Integer] The pipeline schedule ID.
126128 # @param [String] The key of a variable.
127129 # @return [Array<Gitlab::ObjectifiedHash>] The deleted pipeline schedule variable.
128 def delete_pipeline_schedule_variable(project, pipeline_schedule_id, key, options={})
130 def delete_pipeline_schedule_variable(project, pipeline_schedule_id, key, _options = {})
129131 delete("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables/#{url_encode key}")
130132 end
131133 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to pipelines.
24 # @see https://docs.gitlab.com/ce/api/pipeline_triggers.html
3436 # @param [String] description The trigger name
3537 # @return [Gitlab::ObjectifiedHash] The created trigger.
3638 def create_trigger(project, description)
37 post("/projects/#{url_encode project}/triggers", body: {description: description})
39 post("/projects/#{url_encode project}/triggers", body: { description: description })
3840 end
3941
4042 # Update a project trigger
4749 # @param [Hash] options A customizable set of options.
4850 # @option options [String] :description The trigger name.
4951 # @return [Gitlab::ObjectifiedHash] The updated trigger.
50 def update_trigger(project, trigger_id, options={})
52 def update_trigger(project, trigger_id, options = {})
5153 put("/projects/#{url_encode project}/triggers/#{trigger_id}", body: options)
5254 end
5355
7476 def remove_trigger(project, trigger_id)
7577 delete("/projects/#{url_encode project}/triggers/#{trigger_id}")
7678 end
77 alias_method :delete_trigger, :remove_trigger
79 alias delete_trigger remove_trigger
7880
7981 # Run the given project pipeline trigger.
8082 #
8991 # @param [String] ref Branch or tag name to build.
9092 # @param [Hash] variables A set of build variables to use for the build. (optional)
9193 # @return [Gitlab::ObjectifiedHash] The trigger.
92 def run_trigger(project, token, ref, variables={})
94 def run_trigger(project, token, ref, variables = {})
9395 post("/projects/#{url_encode project}/trigger/pipeline", unauthenticated: true, body: {
94 token: token,
95 ref: ref,
96 variables: variables
97 })
96 token: token,
97 ref: ref,
98 variables: variables
99 })
98100 end
99101 end
100102 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to pipelines.
24 # @see https://docs.gitlab.com/ce/api/pipelines.html
1214 # @option options [Integer] :page The page number.
1315 # @option options [Integer] :per_page The number of results per page.
1416 # @return [Array<Gitlab::ObjectifiedHash>]
15 def pipelines(project, options={})
17 def pipelines(project, options = {})
1618 get("/projects/#{url_encode project}/pipelines", query: options)
1719 end
1820
3537 #
3638 # @param [Integer, String] project The ID or name of a project.
3739 # @param [String] ref Reference to commit.
40 # @param [Hash] variables Variables passed to pipelines
3841 # @return [Gitlab::ObjectifiedHash] The pipelines changes.
39 def create_pipeline(project, ref)
40 post("/projects/#{url_encode project}/pipeline?ref=#{ref}")
42 def create_pipeline(project, ref, variables = {})
43 body = {}
44
45 # This mapping is necessary, cause the API expects an array with objects (with `key` and `value` keys)
46 # See: https://docs.gitlab.com/ee/api/pipelines.html#create-a-new-pipeline
47 body[:variables] = variables.map { |(key, value)| { key: key, value: value } } if variables.any?
48
49 post(
50 "/projects/#{url_encode project}/pipeline",
51 query: { ref: ref },
52 body: body
53 )
4154 end
4255
4356 # Cancels a pipeline.
0 # frozen_string_literal: true
1
2 class Gitlab::Client
3 # Defines methods related to project badges.
4 # @see https://docs.gitlab.com/ee/api/project_badges.html
5 module ProjectBadges
6 # Gets a list of a projects badges and its group badges.
7 #
8 # @example
9 # Gitlab.project_badges(5)
10 #
11 # @param [Integer, String] project The ID or name of a project.
12 # @return [Array<Gitlab::ObjectifiedHash>] List of all badges of a project
13 def project_badges(project)
14 get("/projects/#{url_encode project}/badges")
15 end
16
17 # Gets a badge of a project.
18 #
19 # @example
20 # Gitlab.project_badge(5, 42)
21 #
22 # @param [Integer, String] project The ID or name of a project.
23 # @param [Integer] badge_id The badge ID.
24 # @return [Gitlab::ObjectifiedHash] Information about the requested badge
25 def project_badge(project, badge_id)
26 get("/projects/#{url_encode project}/badges/#{badge_id}")
27 end
28
29 # Adds a badge to a project.
30 #
31 # @example
32 # Gitlab.add_project_badge(5, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' })
33 #
34 # @param [Integer, String] project The ID or name of a project.
35 # @param [Hash] options A customizable set of options.
36 # @option options [String] :link_url(required) URL of the badge link
37 # @option options [String] :image_url(required) URL of the badge image
38 # @return [Gitlab::ObjectifiedHash] Information about the added project badge.
39 def add_project_badge(project, options = {})
40 post("/projects/#{url_encode project}/badges", body: options)
41 end
42
43 # Updates a badge of a project..
44 #
45 # @example
46 # Gitlab.edit_project_badge(5, 1, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' })
47 #
48 # @param [Integer, String] project The ID or name of a project.
49 # @param [Integer] badge_id The badge ID.
50 # @param [Hash] options A customizable set of options.
51 # @option options [String] :link_url(optional) URL of the badge link
52 # @option options [String] :image_url(optional) URL of the badge image
53 # @return [Gitlab::ObjectifiedHash] Information about the updated project badge.
54 def edit_project_badge(project, badge_id, options = {})
55 put("/projects/#{url_encode project}/badges/#{badge_id}", body: options)
56 end
57
58 # Removes a badge from a project. Only projects badges will be removed by using this endpoint.
59 #
60 # @example
61 # Gitlab.remove_project_badge(5, 42)
62 #
63 # @param [Integer, String] project The ID or name of a project.
64 # @param [Integer] badge_id The badge ID.
65 # @return [nil] This API call returns an empty response body.
66 def remove_project_badge(project, badge_id)
67 delete("/projects/#{url_encode project}/badges/#{badge_id}")
68 end
69
70 # Preview a badge from a project.
71 #
72 # @example
73 # Gitlab.preview_project_badge(3, 'https://abc.com/gitlab/gitlab-ce/commits/master', 'https://shields.io/my/badge1')
74 #
75 # @param [Integer, String] project The ID or name of a project.
76 # @param [String] :link_url URL of the badge link
77 # @param [String] :image_url URL of the badge image
78 # @return [Gitlab::ObjectifiedHash] Returns how the link_url and image_url final URLs would be after resolving the placeholder interpolation.
79 def preview_project_badge(project, link_url, image_url)
80 query = { link_url: link_url, image_url: image_url }
81 get("/projects/#{url_encode project}/badges/render", query: query)
82 end
83 end
84 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to projects.
24 # @see https://docs.gitlab.com/ce/api/projects.html
1214 # (Any provided options will be passed to Gitlab. See {https://docs.gitlab.com/ce/api/projects.html#list-all-projects Gitlab docs} for all valid options)
1315 #
1416 # @return [Array<Gitlab::ObjectifiedHash>]
15 def projects(options={})
16 get("/projects", query: options)
17 def projects(options = {})
18 get('/projects', query: options)
1719 end
1820
1921 # Search for projects by name.
2931 # @option options [String] :order_by Return requests ordered by id, name, created_at or last_activity_at fields
3032 # @option options [String] :sort Return requests sorted in asc or desc order
3133 # @return [Array<Gitlab::ObjectifiedHash>]
32 def project_search(query, options={})
33 get("/projects", query: options.merge(search:query))
34 end
35 alias_method :search_projects, :project_search
34 def project_search(query, options = {})
35 get('/projects', query: options.merge(search: query))
36 end
37 alias search_projects project_search
3638
3739 # Gets information about a project.
3840 #
6769 # @option options [Boolean] :public The setting for making a project public (0 = false, 1 = true).
6870 # @option options [Integer] :user_id The user/owner id of a project.
6971 # @return [Gitlab::ObjectifiedHash] Information about created project.
70 def create_project(name, options={})
71 url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : "/projects"
72 def create_project(name, options = {})
73 url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : '/projects'
7274 post(url, body: { name: name }.merge(options))
7375 end
7476
9597 # @option options [Integer] :page The page number.
9698 # @option options [Integer] :per_page The number of results per page.
9799 # @return [Array<Gitlab::ObjectifiedHash>]
98 def team_members(project, options={})
100 def team_members(project, options = {})
99101 get("/projects/#{url_encode project}/members", query: options)
100102 end
101103
115117 #
116118 # @example
117119 # Gitlab.add_team_member('gitlab', 2, 40)
120 # Gitlab.add_team_member('gitlab', 2, 40, { expires_at: "2018-12-31"})
118121 #
119122 # @param [Integer, String] project The ID or path of a project.
120123 # @param [Integer] id The ID of a user.
121124 # @param [Integer] access_level The access level to project.
122125 # @param [Hash] options A customizable set of options.
126 # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY.
123127 # @return [Gitlab::ObjectifiedHash] Information about added team member.
124 def add_team_member(project, id, access_level)
125 post("/projects/#{url_encode project}/members", body: { user_id: id, access_level: access_level })
128 def add_team_member(project, id, access_level, options = {})
129 body = { user_id: id, access_level: access_level }.merge(options)
130 post("/projects/#{url_encode project}/members", body: body)
126131 end
127132
128133 # Updates a team member's project access level.
129134 #
130135 # @example
131136 # Gitlab.edit_team_member('gitlab', 3, 20)
137 # Gitlab.edit_team_member('gitlab', 3, 20, { expires_at: "2018-12-31"})
132138 #
133139 # @param [Integer, String] project The ID or path of a project.
134140 # @param [Integer] id The ID of a user.
135141 # @param [Integer] access_level The access level to project.
136142 # @param [Hash] options A customizable set of options.
143 # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY.
137144 # @return [Array<Gitlab::ObjectifiedHash>] Information about updated team member.
138 def edit_team_member(project, id, access_level)
139 put("/projects/#{url_encode project}/members/#{id}", body: { access_level: access_level })
145 def edit_team_member(project, id, access_level, options = {})
146 body = { access_level: access_level }.merge(options)
147 put("/projects/#{url_encode project}/members/#{id}", body: body)
140148 end
141149
142150 # Removes a user from project team.
163171 # @option options [Integer] :page The page number.
164172 # @option options [Integer] :per_page The number of results per page.
165173 # @return [Array<Gitlab::ObjectifiedHash>]
166 def project_hooks(project, options={})
174 def project_hooks(project, options = {})
167175 get("/projects/#{url_encode project}/hooks", query: options)
168176 end
169177
193201 # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true)
194202 # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true)
195203 # @return [Gitlab::ObjectifiedHash] Information about added hook.
196 def add_project_hook(project, url, options={})
204 def add_project_hook(project, url, options = {})
197205 body = { url: url }.merge(options)
198206 post("/projects/#{url_encode project}/hooks", body: body)
199207 end
212220 # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true)
213221 # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true)
214222 # @return [Gitlab::ObjectifiedHash] Information about updated hook.
215 def edit_project_hook(project, id, url, options={})
223 def edit_project_hook(project, id, url, options = {})
216224 body = { url: url }.merge(options)
217225 put("/projects/#{url_encode project}/hooks/#{id}", body: body)
218226 end
252260 # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true)
253261 # @param option [String] :commit_message_regex Commit message regex
254262 # @return [Gitlab::ObjectifiedHash] Information about added push rule.
255 def add_push_rule(id, options={})
263 def add_push_rule(id, options = {})
256264 post("/projects/#{url_encode id}/push_rule", body: options)
257265 end
258266
267275 # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true)
268276 # @param option [String] :commit_message_regex Commit message regex
269277 # @return [Gitlab::ObjectifiedHash] Information about updated push rule.
270 def edit_push_rule(id, options={})
278 def edit_push_rule(id, options = {})
271279 put("/projects/#{url_encode id}/push_rule", body: options)
272280 end
273281
317325 # @option options [Integer] :page The page number.
318326 # @option options [Integer] :per_page The number of results per page.
319327 # @return [Array<Gitlab::ObjectifiedHash>]
320 def deploy_keys(project, options={})
328 def deploy_keys(project, options = {})
321329 get("/projects/#{url_encode project}/deploy_keys", query: options)
322330 end
323331
393401 # @param [Hash] options A customizable set of options.
394402 # @option options [String] :sudo The username the project will be forked for
395403 # @return [Gitlab::ObjectifiedHash] Information about the forked project.
396 def create_fork(id, options={})
404 def create_fork(id, options = {})
397405 post("/projects/#{url_encode id}/fork", body: options)
398406 end
399407
411419 # @option options [String] :order_by Return requests ordered by id, name, created_at or last_activity_at fields
412420 # @option options [String] :sort Return requests sorted in asc or desc order
413421 # @return [Array<Gitlab::ObjectifiedHash>]
414 def project_forks(id, options={})
422 def project_forks(id, options = {})
415423 get("/projects/#{url_encode id}/forks", query: options)
416424 end
417425
430438 # (Any provided options will be passed to Gitlab. See {https://docs.gitlab.com/ce/api/projects.html#edit-project Gitlab docs} for all valid options)
431439 #
432440 # @return [Gitlab::ObjectifiedHash] Information about the edited project.
433 def edit_project(id, options={})
441 def edit_project(id, options = {})
434442 put("/projects/#{url_encode id}", body: options)
435443 end
436444
458466 delete("/projects/#{url_encode project}/share/#{id}")
459467 end
460468
469 # Transfer a project to a new namespace.
470 #
471 # @example
472 # Gitlab.transfer_project(42, 'yolo')
473 #
474 # @param [Integer, String] project The ID or path of a project
475 # @param [Integer, String] namespace The ID or path of the namespace to transfer to project to
476 # @return [Gitlab::ObjectifiedHash] Information about transfered project.
477 def transfer_project(project, namespace)
478 put("/projects/#{url_encode project}/transfer", body: { namespace: namespace })
479 end
480
461481 # Stars a project.
462482 # @see https://docs.gitlab.com/ce/api/projects.html#star-a-project
463483 #
499519 # @option options [String] :order_by Return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields.
500520 # @option options [String] :sort Return projects sorted in asc or desc order.
501521 # @return [Array<Gitlab::ObjectifiedHash>]
502 def user_projects(user_id, options={})
522 def user_projects(user_id, options = {})
503523 get("/users/#{url_encode user_id}/projects", query: options)
524 end
525
526 # Uploads a file to the specified project to be used in an issue or
527 # merge request description, or a comment.
528 # @see https://docs.gitlab.com/ee/api/projects.html#upload-a-file
529 #
530 # @example
531 # Gitlab.upload_file(1, File.open(File::NULL, 'r'))
532 # File.open('myfile') { |file| Gitlab.upload_file(1, file) }
533 #
534 # @param [Integer, String] id The ID or path of a project.
535 # @param [File] The file you are interested to upload.
536 # @return [Gitlab::ObjectifiedHash]
537 def upload_file(id, file)
538 post("/projects/#{url_encode id}/uploads", body: { file: file })
539 end
540
541 # Get all project templates of a particular type
542 # @see https://docs.gitlab.com/ce/api/project_templates.html
543 #
544 # @example
545 # Gitlab.project_templates(1, 'dockerfiles')
546 # Gitlab.project_templates(1, 'licenses')
547 #
548 # @param [Integer, String] id The ID or URL-encoded path of the project.
549 # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template
550 # @return [Array<Gitlab::ObjectifiedHash>]
551 def project_templates(project, type)
552 get("/projects/#{url_encode project}/templates/#{type}")
553 end
554
555 # Get one project template of a particular type
556 # @see https://docs.gitlab.com/ce/api/project_templates.html
557 #
558 # @example
559 # Gitlab.project_template(1, 'dockerfiles', 'dockey')
560 # Gitlab.project_template(1, 'licenses', 'gpl', { project: 'some project', fullname: 'Holder Holding' })
561 #
562 # @param [Integer, String] project The ID or URL-encoded path of the project.
563 # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template
564 # @param [String] key The key of the template, as obtained from the collection endpoint
565 # @param [Hash] options A customizable set of options.
566 # @option options [String] project(optional) The project name to use when expanding placeholders in the template. Only affects licenses
567 # @option options [String] fullname(optional) The full name of the copyright holder to use when expanding placeholders in the template. Only affects licenses
568 # @return [Gitlab::ObjectifiedHash]
569 def project_template(project, type, key, options = {})
570 get("/projects/#{url_encode project}/templates/#{type}/#{key}", query: options)
504571 end
505572 end
506573 end
0 # frozen_string_literal: true
1
2 class Gitlab::Client
3 # Defines methods related to Protected Tags.
4 # @see https://docs.gitlab.com/ce/api/protected_tags.html
5 module ProtectedTags
6 # Gets a list of protected tags from a project
7 #
8 # @example
9 # Gitlab.protected_tags(1)
10 #
11 # @param [Integer, String] project(required) The ID or name of a project.
12 # @option options [Integer] :page The page number.
13 # @option options [Integer] :per_page The number of results per page.
14 # @return [Array<Gitlab::ObjectifiedHash>] List of all protected tags requested
15 def protected_tags(project, options = {})
16 get("/projects/#{url_encode project}/protected_tags", query: options)
17 end
18
19 # Gets a single protected tag or wildcard protected tag.
20 #
21 # @example
22 # Gitlab.protected_tag(1, 'release-1-0')
23 #
24 # @param [Integer, String] project(required) The ID or name of a project.
25 # @param [String] name(required) The name of the tag or wildcard
26 # @return <Gitlab::ObjectifiedHash] Information about the requested protected tag
27 def protected_tag(project, name)
28 get("/projects/#{url_encode project}/protected_tags/#{name}")
29 end
30
31 # Protects a single repository tag or several project repository tags using a wildcard protected tag.
32 #
33 # @example
34 # Gitlab.protect_repository_tag(1, 'release-1-0')
35 # Gitlab.protect_repository_tag(1, 'release-1-0', create_access_level: 30)
36 #
37 # @param [Integer, String] project(required) The ID or name of a project.
38 # @param [String] name(required) The name of the tag or wildcard
39 # @option options [Integer] :create_access_level Access levels allowed to create (defaults: 40, maintainer access level)
40 # @return <Gitlab::ObjectifiedHash] Information about the protected repository tag
41 def protect_repository_tag(project, name, options = {})
42 body = { name: name }.merge(options)
43 post("/projects/#{url_encode project}/protected_tags", body: body)
44 end
45
46 # Unprotects the given protected tag or wildcard protected tag.
47 #
48 # @example
49 # Gitlab.unprotect_repository_tag(1, 'release-1-0')
50 #
51 # @param [Integer, String] project(required) The ID or name of a project.
52 # @param [String] name(required) The name of the tag or wildcard
53 # @return [nil] This API call returns an empty response body.
54 def unprotect_repository_tag(project, name)
55 delete("/projects/#{url_encode project}/protected_tags/#{name}")
56 end
57 end
58 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to repositories.
24 # @see https://docs.gitlab.com/ce/api/repositories.html
1214 # @option options [String] :path The path inside repository.
1315 # @option options [String] :ref_name The name of a repository branch or tag.
1416 # @return [Gitlab::ObjectifiedHash]
15 def tree(project, options={})
17 def tree(project, options = {})
1618 get("/projects/#{url_encode project}/repository/tree", query: options)
1719 end
18 alias_method :repo_tree, :tree
20 alias repo_tree tree
1921
2022 # Get project repository archive
2123 #
5355 def compare(project, from, to)
5456 get("/projects/#{url_encode project}/repository/compare", query: { from: from, to: to })
5557 end
56 alias_method :repo_compare, :compare
58 alias repo_compare compare
59
60 # Get the common ancestor for 2 refs (commit SHAs, branch names or tags).
61 #
62 # @example
63 # Gitlab.merge_base(42, ['master', 'feature/branch'])
64 # Gitlab.merge_base(42, ['master', 'feature/branch'])
65 #
66 # @param [Integer, String] project The ID or URL-encoded path of the project.
67 # @param [Array] refs Array containing 2 commit SHAs, branch names, or tags.
68 # @return [Gitlab::ObjectifiedHash]
69 def merge_base(project, refs)
70 get("/projects/#{url_encode project}/repository/merge_base", query: { refs: refs })
71 end
5772 end
5873 end
0 # frozen_string_literal: true
1
02 require 'base64'
13
24 class Gitlab::Client
1315 # @param [String] filepath The relative path of the file in the repository
1416 # @param [String] ref The name of a repository branch or tag or if not given the default branch.
1517 # @return [String]
16 def file_contents(project, filepath, ref='master')
18 def file_contents(project, filepath, ref = 'master')
1719 get "/projects/#{url_encode project}/repository/files/#{url_encode filepath}/raw",
18 query: { ref: ref},
20 query: { ref: ref },
1921 format: nil,
2022 headers: { Accept: 'text/plain' },
2123 parser: ::Gitlab::Request::Parser
2224 end
23 alias_method :repo_file_contents, :file_contents
25 alias repo_file_contents file_contents
2426
2527 # Gets a repository file.
2628 #
0 # frozen_string_literal: true
1
2 class Gitlab::Client
3 # Defines methods related to repository submodules.
4 # @see https://docs.gitlab.com/ce/api/repository_submodules.html
5 module RepositorySubmodules
6 # Edits an existing repository submodule.
7 #
8 # @example
9 # Gitlab.edit_file(42, "submodule", {
10 # branch: "branch",
11 # commit_sha: "3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88",
12 # commit_message: "commit message"
13 # })
14 #
15 # @param [Integer, String] project The ID or name of a project.
16 # @param [String] submodule full path of submodule to update.
17 # @param [Hash] options A customizable set of options.
18 # @param options [String] :branch the name of the branch to commit changes to.
19 # @param options [String] :commit_sha commit SHA to update the submodule to.
20 # @param options [String] :commit_message commit message text.
21 # @return [Gitlab::ObjectifiedHash]
22 def edit_submodule(project, submodule, options = {})
23 put("/projects/#{url_encode project}/repository/submodules/#{url_encode submodule}", body: options)
24 end
25 end
26 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to runners.
24 # @see https://docs.gitlab.com/ce/api/runners.html
35 module Runners
4
56 # Get a list of specific runners available to the user.
67 # @see https://docs.gitlab.com/ce/api/runners.html#list-owned-runners
78 #
1415 # @option options [String] :scope The scope of specific runners to show, one of: active, paused, online; showing all runners if none provided
1516 # @return [Array<Gitlab::ObjectifiedHash>]
1617 def runners(options = {})
17 get("/runners", query: options)
18 get('/runners', query: options)
1819 end
1920
2021 # Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
2728 # @option options [String] :scope The scope of runners to show, one of: specific, shared, active, paused, online; showing all runners if none provided
2829 # @return [Array<Gitlab::ObjectifiedHash>]
2930 def all_runners(options = {})
30 get("/runners/all", query: options)
31 get('/runners/all', query: options)
3132 end
3233
3334 # Get details of a runner..
5556 # @option options [String] :active The state of a runner; can be set to true or false.
5657 # @option options [String] :tag_list The list of tags for a runner; put array of tags, that should be finally assigned to a runner
5758 # @return <Gitlab::ObjectifiedHash>
58 def update_runner(id, options={})
59 def update_runner(id, options = {})
5960 put("/runners/#{id}", query: options)
6061 end
6162
120121 def project_disable_runner(id, runner_id)
121122 delete("/projects/#{url_encode id}/runners/#{runner_id}")
122123 end
123
124124 end
125125 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Third party services connected to a project.
24 # @see https://docs.gitlab.com/ce/api/services.html
4244 end
4345
4446 private
47
4548 def correct_service_name(service)
46 service.to_s.gsub('_', '-')
49 service.to_s.tr('_', '-')
4750 end
4851 end
4952 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to sidekiq metrics.
24 # @see https://docs.gitlab.com/ce/api/sidekiq_metrics.html
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to snippets.
24 # @see https://docs.gitlab.com/ce/api/project_snippets.html
1113 # @option options [Integer] :page The page number.
1214 # @option options [Integer] :per_page The number of results per page.
1315 # @return [Gitlab::ObjectifiedHash]
14 def snippets(project, options={})
16 def snippets(project, options = {})
1517 get("/projects/#{url_encode project}/snippets", query: options)
1618 end
1719
4042 # @option options [String] :lifetime (optional) The expiration date of a snippet.
4143 # @option options [String] :visibility (required) The visibility of a snippet
4244 # @return [Gitlab::ObjectifiedHash] Information about created snippet.
43 def create_snippet(project, options={})
45 def create_snippet(project, options = {})
4446 post("/projects/#{url_encode project}/snippets", body: options)
4547 end
4648
5860 # @option options [String] :lifetime The expiration date of a snippet.
5961 # @option options [String] :visibility (optional) The visibility of a snippet
6062 # @return [Gitlab::ObjectifiedHash] Information about updated snippet.
61 def edit_snippet(project, id, options={})
63 def edit_snippet(project, id, options = {})
6264 put("/projects/#{url_encode project}/snippets/#{id}", body: options)
6365 end
6466
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to system hooks.
24 # @see https://docs.gitlab.com/ce/api/system_hooks.html
1113 # @option options [Integer] :page The page number.
1214 # @option options [Integer] :per_page The number of results per page.
1315 # @return [Array<Gitlab::ObjectifiedHash>]
14 def hooks(options={})
15 get("/hooks", query: options)
16 def hooks(options = {})
17 get('/hooks', query: options)
1618 end
17 alias_method :system_hooks, :hooks
19 alias system_hooks hooks
1820
1921 # Adds a new system hook.
2022 #
2830 # @option options [boolean] :enable_ssl_verification `false` will cause Gitlab to ignore invalid/unsigned certificate errors (default is `true`)
2931 # @return [Gitlab::ObjectifiedHash]
3032 def add_hook(url, options = {})
31 post("/hooks", body: options.merge(url: url))
33 post('/hooks', body: options.merge(url: url))
3234 end
33 alias_method :add_system_hook, :add_hook
35 alias add_system_hook add_hook
3436
3537 # Tests a system hook.
3638 #
4345 def hook(id)
4446 get("/hooks/#{id}")
4547 end
46 alias_method :system_hook, :hook
48 alias system_hook hook
4749
4850 # Deletes a new system hook.
4951 #
5658 def delete_hook(id)
5759 delete("/hooks/#{id}")
5860 end
59 alias_method :delete_system_hook, :delete_hook
61 alias delete_system_hook delete_hook
6062 end
6163 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to tags.
24 # @see https://docs.gitlab.com/ce/api/tags.html
1113 # @option options [Integer] :page The page number.
1214 # @option options [Integer] :per_page The number of results per page.
1315 # @return [Array<Gitlab::ObjectifiedHash>]
14 def tags(project, options={})
16 def tags(project, options = {})
1517 get("/projects/#{url_encode project}/repository/tags", query: options)
1618 end
17 alias_method :repo_tags, :tags
19 alias repo_tags tags
1820
1921 # Creates a new project repository tag.
2022 #
2830 # @param [String] message Optional message for tag, creates annotated tag if specified.
2931 # @param [String] description Optional release notes for tag.
3032 # @return [Gitlab::ObjectifiedHash]
31 def create_tag(project, tag_name, ref, message='', description=nil)
33 def create_tag(project, tag_name, ref, message = '', description = nil)
3234 post("/projects/#{url_encode project}/repository/tags", body: { tag_name: tag_name, ref: ref, message: message, release_description: description })
3335 end
34 alias_method :repo_create_tag, :create_tag
36 alias repo_create_tag create_tag
3537
3638 # Gets information about a repository tag.
3739 #
4547 def tag(project, tag)
4648 get("/projects/#{url_encode project}/repository/tags/#{url_encode tag}")
4749 end
48 alias_method :repo_tag, :tag
50 alias repo_tag tag
4951
5052 # Deletes a repository tag. Requires Gitlab >= 6.8.x
5153 #
5961 def delete_tag(project, tag)
6062 delete("/projects/#{url_encode project}/repository/tags/#{url_encode tag}")
6163 end
62 alias_method :repo_delete_tag, :delete_tag
64 alias repo_delete_tag delete_tag
6365
6466 # Adds release notes to an existing repository tag. Requires Gitlab >= 8.2.0
6567 #
7476 def create_release(project, tag, description)
7577 post("/projects/#{url_encode project}/repository/tags/#{url_encode tag}/release", body: { description: description })
7678 end
77 alias_method :repo_create_release, :create_release
79 alias repo_create_release create_release
7880
7981 # Updates the release notes of a given release. Requires Gitlab >= 8.2.0
8082 #
8991 def update_release(project, tag, description)
9092 put("/projects/#{url_encode project}/repository/tags/#{url_encode tag}/release", body: { description: description })
9193 end
92 alias_method :repo_update_release, :update_release
93
94 alias repo_update_release update_release
9495 end
9596 end
0 # frozen_string_literal: true
1
2 class Gitlab::Client
3 # Defines methods related to templates.
4 # @see https://docs.gitlab.com/ce/api/templates/dockerfiles.html
5 # @see https://docs.gitlab.com/ce/api/templates/gitignores.html
6 # @see https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html
7 # @see https://docs.gitlab.com/ce/api/templates/licenses.html
8 module Templates
9 # Get all Dockerfile templates.
10 #
11 # @example
12 # Gitlab.dockerfile_templates
13 #
14 # @return [Array<Gitlab::ObjectifiedHash>]
15 def dockerfile_templates
16 get('/templates/dockerfiles')
17 end
18
19 # Get a single Dockerfile template.
20 #
21 # @example
22 # Gitlab.dockerfile_template('Binary')
23 #
24 # @param [String] key The key of the Dockerfile template
25 # @return [Gitlab::ObjectifiedHash]
26 def dockerfile_template(key)
27 get("/templates/dockerfiles/#{key}")
28 end
29
30 # Get all gitignore templates.
31 #
32 # @example
33 # Gitlab.gitignore_templates
34 #
35 # @return [Array<Gitlab::ObjectifiedHash>]
36 def gitignore_templates
37 get('/templates/gitignores')
38 end
39
40 # Get a single gitignore template.
41 #
42 # @example
43 # Gitlab.gitignore_template('Ruby')
44 #
45 # @param [String] key The key of the gitignore template
46 # @return [Gitlab::ObjectifiedHash]
47 def gitignore_template(key)
48 get("/templates/gitignores/#{key}")
49 end
50
51 # Get all `gitlab_ci.yml` templates.
52 #
53 # @example
54 # Gitlab.gitlab_ci_yml_templates
55 #
56 # @return [Array<Gitlab::ObjectifiedHash>]
57 def gitlab_ci_yml_templates
58 get('/templates/gitlab_ci_ymls')
59 end
60
61 # Get a single `gitlab_ci.yml` template.
62 #
63 # @example
64 # Gitlab.gitlab_ci_yml_template('Ruby')
65 #
66 # @param [String] key The key of the gitlab_ci_yml template
67 # @return [Gitlab::ObjectifiedHash]
68 def gitlab_ci_yml_template(key)
69 get("/templates/gitlab_ci_ymls/#{key}")
70 end
71
72 # Get all license templates.
73 #
74 # @example
75 # Gitlab.license_templates
76 # Gitlab.license_templates(popular: true)
77 #
78 # @param [Hash] options A customizable set of options.
79 # @option options [Boolean] popular(optional) If passed, returns only popular licenses.
80 # @return [Array<Gitlab::ObjectifiedHash>]
81 def license_templates(options = {})
82 get('/templates/licenses', query: options)
83 end
84
85 # Get a single license template. You can pass parameters to replace the license placeholder.
86 #
87 # @example
88 # Gitlab.license_template('Ruby')
89 #
90 # @param [String] key The key of the license template
91 # @param [Hash] options A customizable set of options.
92 # @option options [String] project(optional) The copyrighted project name.
93 # @option options [String] fullname(optional) The full-name of the copyright holder
94 # @return [Gitlab::ObjectifiedHash]
95 def license_template(key, options = {})
96 get("/templates/licenses/#{key}", query: options)
97 end
98 end
99 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to todos
2 # @see https://docs.gitlab.com/ce/api/todos.html
4 # @see https://docs.gitlab.com/ce/api/todos.html
35 module Todos
46 # Gets a list of todos.
57 #
1517 # @option options [Integer] :state The state of the todo. Can be either `pending` or `done`
1618 # @option options [Integer] :type The type of a todo. Can be either `Issue` or `MergeRequest`
1719 # @return [Array<Gitlab::ObjectifiedHash>]
18 def todos(options={})
19 get("/todos", query: options)
20 def todos(options = {})
21 get('/todos', query: options)
2022 end
2123
2224 # Marks a single pending todo for the current user as done.
3739 #
3840 # @return [void] This API call returns an empty response body.
3941 def mark_all_todos_as_done
40 post("/todos/mark_as_done")
42 post('/todos/mark_as_done')
4143 end
4244 end
43 end
45 end
0 # frozen_string_literal: true
1
02 class Gitlab::Client
13 # Defines methods related to users.
24 # @see https://docs.gitlab.com/ce/api/users.html
1113 # @option options [Integer] :page The page number.
1214 # @option options [Integer] :per_page The number of results per page.
1315 # @return [Array<Gitlab::ObjectifiedHash>]
14 def users(options={})
15 get("/users", query: options)
16 def users(options = {})
17 get('/users', query: options)
1618 end
1719
1820 # Gets information about a user.
2426 #
2527 # @param [Integer] id The ID of a user.
2628 # @return [Gitlab::ObjectifiedHash]
27 def user(id=nil)
28 id.to_i.zero? ? get("/user") : get("/users/#{id}")
29 def user(id = nil)
30 id.to_i.zero? ? get('/user') : get("/users/#{id}")
2931 end
3032
3133 # Creates a new user.
4749 # @option options [Integer] :projects_limit The limit of projects for a user.
4850 # @return [Gitlab::ObjectifiedHash] Information about created user.
4951 def create_user(*args)
50 options = Hash === args.last ? args.pop : {}
52 options = args.last.is_a?(Hash) ? args.pop : {}
5153 body = if args[2]
5254 { email: args[0], password: args[1], username: args[2] }
5355 else
7274 # @option options [String] :twitter The twitter of a user.
7375 # @option options [Integer] :projects_limit The limit of projects for a user.
7476 # @return [Gitlab::ObjectifiedHash] Information about created user.
75 def edit_user(user_id, options={})
77 def edit_user(user_id, options = {})
7678 put("/users/#{user_id}", body: options)
7779 end
7880
119121 # @return [Gitlab::ObjectifiedHash]
120122 # @note This method doesn't require private_token to be set.
121123 def session(email, password)
122 post("/session", body: { email: email, password: password }, unauthenticated: true)
124 post('/session', body: { email: email, password: password }, unauthenticated: true)
123125 end
124126
125127 # Gets a list of user's SSH keys.
133135 # @option options [Integer] :per_page The number of results per page.
134136 # @option options [Integer] :user_id The ID of the user to retrieve the keys for.
135137 # @return [Array<Gitlab::ObjectifiedHash>]
136 def ssh_keys(options={})
138 def ssh_keys(options = {})
137139 user_id = options.delete :user_id
138140 if user_id.to_i.zero?
139 get("/user/keys", query: options)
141 get('/user/keys', query: options)
140142 else
141143 get("/users/#{user_id}/keys", query: options)
142144 end
160162 #
161163 # @param [String] title The title of an SSH key.
162164 # @param [String] key The SSH key body.
165 # @param [Hash] options A customizable set of options.
166 # @option options [Integer] :user_id id of the user to associate the key with
163167 # @return [Gitlab::ObjectifiedHash] Information about created SSH key.
164 def create_ssh_key(title, key)
165 post("/user/keys", body: { title: title, key: key })
168 def create_ssh_key(title, key, options = {})
169 user_id = options.delete :user_id
170 if user_id.to_i.zero?
171 post('/user/keys', body: { title: title, key: key })
172 else
173 post("/users/#{user_id}/keys", body: { title: title, key: key })
174 end
166175 end
167176
168177 # Deletes an SSH key.
171180 # Gitlab.delete_ssh_key(1)
172181 #
173182 # @param [Integer] id The ID of a user's SSH key.
183 # @param [Hash] options A customizable set of options.
184 # @option options [Integer] :user_id id of the user to associate the key with
174185 # @return [Gitlab::ObjectifiedHash] Information about deleted SSH key.
175 def delete_ssh_key(id)
176 delete("/user/keys/#{id}")
186 def delete_ssh_key(id, options = {})
187 user_id = options.delete :user_id
188 if user_id.to_i.zero?
189 delete("/user/keys/#{id}")
190 else
191 delete("/users/#{user_id}/keys/#{id}")
192 end
177193 end
178194
179195 # Gets user emails.
185201 #
186202 # @param [Integer] user_id The ID of a user.
187203 # @return [Gitlab::ObjectifiedHash]
188 def emails(user_id=nil)
189 url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails"
204 def emails(user_id = nil)
205 url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
190206 get(url)
191207 end
192208
211227 # @param [String] email Email address
212228 # @param [Integer] user_id The ID of a user.
213229 # @return [Gitlab::ObjectifiedHash]
214 def add_email(email, user_id=nil)
215 url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails"
216 post(url, body: {email: email})
230 def add_email(email, user_id = nil)
231 url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
232 post(url, body: { email: email })
217233 end
218234
219235 # Delete email
226242 # @param [Integer] id Email address ID
227243 # @param [Integer] user_id The ID of a user.
228244 # @return [Boolean]
229 def delete_email(id, user_id=nil)
245 def delete_email(id, user_id = nil)
230246 url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}"
231247 delete(url)
232248 end
241257 # @option options [String] :per_page Number of user to return per page
242258 # @option options [String] :page The page to retrieve
243259 # @return [Array<Gitlab::ObjectifiedHash>]
244 def user_search(search, options={})
260 def user_search(search, options = {})
245261 options[:search] = search
246 get("/users", query: options)
262 get('/users', query: options)
247263 end
248264 end
249265 end
0 # frozen_string_literal: true
1
2 class Gitlab::Client
3 # Defines methods related to version
4 # @see https://docs.gitlab.com/ce/api/version.html
5 module Versions
6 # Returns server version.
7 # @see https://docs.gitlab.com/ce/api/version.html
8 #
9 # @example
10 # Gitlab.version
11 #
12 # @return [Array<Gitlab::ObjectifiedHash>]
13 def version
14 get('/version')
15 end
16 end
17 end
0 # frozen_string_literal: true
1
2 class Gitlab::Client
3 # Defines methods related to wikis.
4 # @see https://docs.gitlab.com/ce/api/wikis.html
5 module Wikis
6 # Get all wiki pages for a given project.
7 #
8 # @example
9 # Gitlab.wikis(3)
10 # Gitlab.wikis(3, {with_content: 'Some wiki content'})
11 #
12 # @param [Integer, String] project The ID or name of a project.
13 # @param [Hash] options A customizable set of options.
14 # @option options [String] with_content(optional) Include pages content
15 # @return [Array<Gitlab::ObjectifiedHash>]
16 def wikis(project, options = {})
17 get("/projects/#{url_encode project}/wikis", query: options)
18 end
19
20 # Get a wiki page for a given project.
21 #
22 # @example
23 # Gitlab.wiki(3, 'home')
24 #
25 # @param [Integer, String] project The ID or name of a project.
26 # @param [String] slug The slug (a unique string) of the wiki page
27 # @return [Gitlab::ObjectifiedHash]
28 def wiki(project, slug)
29 get("/projects/#{url_encode project}/wikis/#{slug}")
30 end
31
32 # Creates a new wiki page for the given repository with the given title, slug, and content.
33 #
34 # @example
35 # Gitlab.create_wiki(3, 'Some Title', 'Some Content')
36 # Gitlab.create_wiki(3, 'Some Title', 'Some Content', { format: 'rdoc' })
37 #
38 # @param [Integer, String] project The ID or name of a project.
39 # @param [String] content The content of the wiki page.
40 # @param [String] title The title of the wiki page.
41 # @param [Hash] options A customizable set of options.
42 # @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc.
43 # @return [Gitlab::ObjectifiedHash] Information about created wiki page.
44 def create_wiki(project, title, content, options = {})
45 body = { content: content, title: title }.merge(options)
46 post("/projects/#{url_encode project}/wikis", body: body)
47 end
48
49 # Updates an existing wiki page. At least one parameter is required to update the wiki page.
50 #
51 # @example
52 # Gitlab.update_wiki(6, 'home', { title: 'New title' })
53 # Gitlab.update_wiki(6, 'home', { title: 'New title', content: 'New Message', format: 'rdoc' })
54 #
55 # @param [Integer, String] project The ID or name of a project.
56 # @param [String] slug The slug (a unique string) of the wiki page.
57 # @param [Hash] options A customizable set of options.
58 # @option options [String] content The content of the wiki page.
59 # @option options [String] title The title of the wiki page.
60 # @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc.
61 # @return [Gitlab::ObjectifiedHash] Information about updated wiki page.
62 def update_wiki(project, slug, options = {})
63 put("/projects/#{url_encode project}/wikis/#{slug}", body: options)
64 end
65
66 # Deletes a wiki page with a given slug.
67 #
68 # @example
69 # Gitlab.delete_wiki(42, 'foo')
70 #
71 # @param [Integer, String] project The ID or name of a project.
72 # @param [String] slug The slug (a unique string) of the wiki page.
73 # @return [Gitlab::ObjectifiedHash] An empty objectified hash
74 def delete_wiki(project, slug)
75 delete("/projects/#{url_encode project}/wikis/#{slug}")
76 end
77 end
78 end
0 # frozen_string_literal: true
1
02 module Gitlab
13 # Wrapper for the Gitlab REST API.
24 class Client < API
3 Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
5 Dir[File.expand_path('client/*.rb', __dir__)].each { |f| require f }
46
57 # Please keep in alphabetical order
68 include AccessRequests
79 include AwardEmojis
810 include Boards
911 include Branches
12 include BroadcastMessages
1013 include BuildVariables
1114 include Builds
1215 include Commits
2730 include PipelineSchedules
2831 include PipelineTriggers
2932 include Pipelines
33 include ProjectBadges
3034 include Projects
35 include ProtectedTags
3136 include Repositories
3237 include RepositoryFiles
38 include RepositorySubmodules
3339 include Runners
3440 include Services
3541 include Sidekiq
3642 include Snippets
3743 include SystemHooks
3844 include Tags
45 include Templates
3946 include Todos
4047 include Users
48 include Versions
49 include Wikis
4150
4251 # Text representation of the client, masking private token.
4352 #
4453 # @return [String]
4554 def inspect
4655 inspected = super
47
48 if @private_token
49 inspected = inspected.sub! @private_token, only_show_last_four_chars(@private_token)
50 end
51
56 inspected.sub! @private_token, only_show_last_four_chars(@private_token) if @private_token
5257 inspected
5358 end
5459
55 def url_encode(s)
56 URI.encode(s.to_s, /\W/)
60 def url_encode(url)
61 URI.encode(url.to_s, /\W/)
5762 end
5863
5964 private
0 # frozen_string_literal: true
1
02 require 'gitlab/cli_helpers'
13 module Gitlab
24 # Defines constants and methods related to configuration.
35 module Configuration
46 # An array of valid keys in the options hash when configuring a Gitlab::API.
5 VALID_OPTIONS_KEYS = %i(endpoint private_token user_agent sudo httparty).freeze
7 VALID_OPTIONS_KEYS = %i[endpoint private_token user_agent sudo httparty].freeze
68
79 # The user agent that will be sent to the API endpoint if none is set.
8 DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}".freeze
10 DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}"
911
1012 # @private
1113 attr_accessor(*VALID_OPTIONS_KEYS)
1214 # @private
13 alias_method :auth_token=, :private_token=
15 alias auth_token= private_token=
1416
1517 # Sets all configuration options to their default values
1618 # when this module is extended.
4345
4446 # Allows HTTParty config to be specified in ENV using YAML hash.
4547 def get_httparty_config(options)
46 return options if options.nil?
48 return if options.nil?
4749
4850 httparty = Gitlab::CLI::Helpers.yaml_load(options)
51 raise ArgumentError, 'HTTParty config should be a Hash.' unless httparty.is_a? Hash
4952
50 raise ArgumentError, 'HTTParty config should be a Hash.' unless httparty.is_a? Hash
5153 Gitlab::CLI::Helpers.symbolize_keys httparty
5254 end
5355 end
0 # frozen_string_literal: true
1
02 module Gitlab
13 module Error
24 # Custom error class for rescuing from all Gitlab errors.
1012
1113 # Custom error class for rescuing from HTTP response errors.
1214 class ResponseError < Error
13 POSSIBLE_MESSAGE_KEYS = %i(message error_description error)
15 POSSIBLE_MESSAGE_KEYS = %i[message error_description error].freeze
1416
1517 def initialize(response)
1618 @response = response
5658 case message
5759 when Gitlab::ObjectifiedHash
5860 message.to_h.sort.map do |key, val|
59 "'#{key}' #{(val.is_a?(Hash) ? val.sort.map { |k, v| "(#{k}: #{v.join(' ')})" } : val).join(' ')}"
61 "'#{key}' #{(val.is_a?(Hash) ? val.sort.map { |k, v| "(#{k}: #{v.join(' ')})" } : [val].flatten).join(' ')}"
6062 end.join(', ')
6163 when Array
6264 message.join(' ')
0 # frozen_string_literal: true
1
02 module Gitlab
13 # Wrapper class of file response.
24 class FileResponse
3 HEADER_CONTENT_DISPOSITION = 'Content-Disposition'.freeze
5 HEADER_CONTENT_DISPOSITION = 'Content-Disposition'
46
57 attr_reader :filename
68
1719 def to_hash
1820 { filename: @filename, data: @file }
1921 end
20 alias_method :to_h, :to_hash
22 alias to_h to_hash
2123
2224 # @return [String] Formatted string with the class name, object id and filename.
2325 def inspect
0 # frozen_string_literal: true
1
02 require 'gitlab'
13 require 'gitlab/cli_helpers'
24
3133 # @return [String]
3234 def ri_cmd
3335 which_ri = `which ri`.chomp
34 if which_ri.empty?
35 raise "'ri' tool not found in $PATH. Please install it to use the help."
36 end
36 raise "'ri' tool not found in $PATH. Please install it to use the help." if which_ri.empty?
3737
3838 which_ri
3939 end
4646 def help_map
4747 @help_map ||= begin
4848 actions.each_with_object({}) do |action, hsh|
49 key = client.method(action).
50 owner.to_s.gsub(/Gitlab::(?:Client::)?/, '')
49 key = client.method(action)
50 .owner.to_s.gsub(/Gitlab::(?:Client::)?/, '')
5151 hsh[key] ||= []
5252 hsh[key] << action.to_s
5353 end
5757 # Table with available commands.
5858 #
5959 # @return [Terminal::Table]
60 def actions_table(topic=nil)
60 def actions_table(topic = nil)
6161 rows = topic ? help_map[topic] : help_map.keys
6262 table do |t|
6363 t.title = topic || 'Help Topics'
7272
7373 # Returns full namespace of a command (e.g. Gitlab::Client::Branches.cmd)
7474 def namespace(cmd)
75 method_owners.select { |method| method[:name] == cmd }.
76 map { |method| method[:owner] + '.' + method[:name] }.
77 shift
75 method_owners.select { |method| method[:name] == cmd }
76 .map { |method| method[:owner] + '.' + method[:name] }
77 .shift
7878 end
7979
8080 # Massage output from 'ri'.
0 # frozen_string_literal: true
1
02 module Gitlab
13 # Converts hashes to the objects.
24 class ObjectifiedHash
35 # Creates a new ObjectifiedHash object.
46 def initialize(hash)
57 @hash = hash
6 @data = hash.inject({}) do |data, (key, value)|
8 @data = hash.each_with_object({}) do |(key, value), data|
79 value = ObjectifiedHash.new(value) if value.is_a? Hash
810 data[key.to_s] = value
9 data
1011 end
1112 end
1213
1415 def to_hash
1516 @hash
1617 end
17 alias_method :to_h, :to_hash
18 alias to_h to_hash
1819
1920 # @return [String] Formatted string with the class name, object id and original hash.
2021 def inspect
2324
2425 # Delegate to ObjectifiedHash.
2526 def method_missing(key)
26 @data.key?(key.to_s) ? @data[key.to_s] : nil
27 @data.key?(key.to_s) ? @data[key.to_s] : super
2728 end
2829
2930 def respond_to_missing?(method_name, include_private = false)
0 # frozen_string_literal: true
1
02 module Gitlab
13 # Parses link header.
24 #
35 # @private
46 class PageLinks
5 HEADER_LINK = 'Link'.freeze
6 DELIM_LINKS = ','.freeze
7 LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/
8 METAS = %w(last next first prev).freeze
7 HEADER_LINK = 'Link'
8 DELIM_LINKS = ','
9 LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/.freeze
10 METAS = %w[last next first prev].freeze
911
1012 attr_accessor(*METAS)
1113
1214 def initialize(headers)
1315 link_header = headers[HEADER_LINK]
1416
15 if link_header && link_header =~ /(next|first|last|prev)/
16 extract_links(link_header)
17 end
17 extract_links(link_header) if link_header && link_header =~ /(next|first|last|prev)/
1818 end
1919
2020 private
2222 def extract_links(header)
2323 header.split(DELIM_LINKS).each do |link|
2424 LINK_REGEX.match(link.strip) do |match|
25 url, meta = match[1], match[2]
25 url = match[1]
26 meta = match[2]
2627 next if !url || !meta || METAS.index(meta).nil?
28
2729 send("#{meta}=", url)
2830 end
2931 end
0 # frozen_string_literal: true
1
02 module Gitlab
13 # Wrapper class of paginated response.
24 class PaginatedResponse
5355 response
5456 end
5557
56 def has_last_page?
58 def last_page?
5759 !(@links.nil? || @links.last.nil?)
5860 end
61 alias has_last_page? last_page?
5962
6063 def last_page
6164 return nil if @client.nil? || !has_last_page?
65
6266 path = @links.last.sub(/#{@client.endpoint}/, '')
6367 @client.get(path)
6468 end
6569
66 def has_first_page?
70 def first_page?
6771 !(@links.nil? || @links.first.nil?)
6872 end
73 alias has_first_page? first_page?
6974
7075 def first_page
7176 return nil if @client.nil? || !has_first_page?
77
7278 path = @links.first.sub(/#{@client.endpoint}/, '')
7379 @client.get(path)
7480 end
7581
76 def has_next_page?
82 def next_page?
7783 !(@links.nil? || @links.next.nil?)
7884 end
85 alias has_next_page? next_page?
7986
8087 def next_page
8188 return nil if @client.nil? || !has_next_page?