Codebase list ruby-gitlab / 9962458
New upstream version 4.8.0 Utkarsh Gupta 5 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?
89
8290 path = @links.next.sub(/#{@client.endpoint}/, '')
8391 @client.get(path)
8492 end
8593
86 def has_prev_page?
94 def prev_page?
8795 !(@links.nil? || @links.prev.nil?)
8896 end
97 alias has_prev_page? prev_page?
8998
9099 def prev_page
91100 return nil if @client.nil? || !has_prev_page?
101
92102 path = @links.prev.sub(/#{@client.endpoint}/, '')
93103 @client.get(path)
94104 end
0 # frozen_string_literal: true
1
02 require 'httparty'
13 require 'json'
24
68 include HTTParty
79 format :json
810 headers 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'
9 parser proc { |body, _| parse(body) }
11 parser(proc { |body, _| parse(body) })
1012
1113 attr_accessor :private_token, :endpoint
1214
3133
3234 # Decodes a JSON response into Ruby object.
3335 def self.decode(response)
34 return response ? JSON.load(response) : {}
36 response ? JSON.load(response) : {}
3537 rescue JSON::ParserError
3638 raise Error::Parsing, 'The response is not a valid JSON'
3739 end
3840
39 %w(get post put delete).each do |method|
40 define_method method do |path, options={}|
41 %w[get post put delete].each do |method|
42 define_method method do |path, options = {}|
4143 httparty_config(options)
4244 authorization_header(options)
4345 validate self.class.send(method, @endpoint + path, options)
7072
7173 # Sets a base_uri and default_params for requests.
7274 # @raise [Error::MissingCredentials] if endpoint not set.
73 def request_defaults(sudo=nil)
75 def request_defaults(sudo = nil)
7476 self.class.default_params sudo: sudo
7577 raise Error::MissingCredentials, 'Please set an endpoint to API' unless @endpoint
78
7679 self.class.default_params.delete(:sudo) if sudo.nil?
7780 end
7881
0 # frozen_string_literal: true
1
02 require 'gitlab'
13 require 'gitlab/help'
24 require 'gitlab/cli_helpers'
1416 trap('INT') { quit_shell } # capture ctrl-c
1517 setup
1618
17 while buffer = Readline.readline('gitlab> ')
19 while (buffer = Readline.readline('gitlab> '))
1820 begin
1921 parse_input buffer
2022
3335 data = execute command, arguments
3436 output_table command, arguments, data
3537 end
36 rescue => e
38 rescue StandardError => e
3739 puts e.message
3840 end
3941 end
4547 buf = Shellwords.shellwords(buffer)
4648
4749 @command = buf.shift
48 @arguments = buf.count > 0 ? buf : []
50 @arguments = buf.count.positive? ? buf : []
4951 end
5052
5153 def setup
6163 end
6264
6365 # Execute a given command with arguements
64 def execute(cmd=command, args=arguments)
66 def execute(cmd = command, args = arguments)
6567 raise "Unknown command: #{cmd}. See the 'help' for a list of valid commands." unless actions.include?(cmd.to_sym)
6668
6769 confirm_command(cmd)
0 # frozen_string_literal: true
1
02 class Gitlab::Shell
13 class History
24 DEFAULT_HISTFILESIZE = 200
35 DEFAULT_FILE_PATH = File.join(Dir.home, '.gitlab_shell_history')
46
5 def initialize(options={})
7 def initialize(options = {})
68 @file_path = options[:file_path] || DEFAULT_FILE_PATH
79 Readline::HISTORY.clear
810 end
1214 end
1315
1416 def save
15 lines.each { |line| history_file.puts line if history_file }
17 lines.each { |line| history_file&.puts line }
1618 end
1719
1820 def push(line)
1921 Readline::HISTORY << line
2022 end
21 alias_method :<<, :push
23 alias << push
2224
2325 def lines
2426 Readline::HISTORY.to_a.last(max_lines)
3032 if defined?(@history_file)
3133 @history_file
3234 else
33 @history_file = File.open(history_file_path, 'w', 0600).tap do |file|
35 @history_file = File.open(history_file_path, 'w', 0o600).tap do |file|
3436 file.sync = true
3537 end
3638 end
4749 path = history_file_path
4850
4951 File.foreach(path) { |line| yield(line) } if File.exist?(path)
50 rescue => error
52 rescue StandardError => error
5153 warn "History file not loaded: #{error.message}"
5254 end
5355
0 # frozen_string_literal: true
1
02 module Gitlab
1 VERSION = '4.5.0'.freeze
3 VERSION = '4.8.0'
24 end
0 # frozen_string_literal: true
1
02 require 'gitlab/version'
13 require 'gitlab/objectified_hash'
24 require 'gitlab/configuration'
1416 # Alias for Gitlab::Client.new
1517 #
1618 # @return [Gitlab::Client]
17 def self.client(options={})
19 def self.client(options = {})
1820 Gitlab::Client.new(options)
1921 end
2022
2123 # Delegate to Gitlab::Client
2224 def self.method_missing(method, *args, &block)
2325 return super unless client.respond_to?(method)
26
2427 client.send(method, *args, &block)
2528 end
2629
2730 # Delegate to Gitlab::Client
28 def self.respond_to_missing?(method_name, include_private=false)
31 def self.respond_to_missing?(method_name, include_private = false)
2932 client.respond_to?(method_name) || super
3033 end
3134
3235 # Delegate to HTTParty.http_proxy
33 def self.http_proxy(address=nil, port=nil, username=nil, password=nil)
36 def self.http_proxy(address = nil, port = nil, username = nil, password = nil)
3437 Gitlab::Request.http_proxy(address, port, username, password)
3538 end
3639
0 {
1 "message":"Deploy in progress",
2 "starts_at":"2016-08-24T23:21:16.078Z",
3 "ends_at":"2016-08-26T23:21:16.080Z",
4 "color":"#cecece",
5 "font":"#FFFFFF",
6 "id":1,
7 "active":false
8 }
0 [
1 {
2 "message":"Example broadcast message",
3 "starts_at":"2016-08-24T23:21:16.078Z",
4 "ends_at":"2016-08-26T23:21:16.080Z",
5 "color":"#E75E40",
6 "font":"#FFFFFF",
7 "id":1,
8 "active": false
9 }
10 ]
0 {
1 "name": "Binary",
2 "content": "# This file is a template, and might need editing before it works on your project.\n# This Dockerfile installs a compiled binary into a bare system.\n# You must either commit your compiled binary into source control (not recommended)\n# or build the binary first as part of a CI/CD pipeline.\n\nFROM buildpack-deps:jessie\n\nWORKDIR /usr/local/bin\n\n# Change `app` to whatever your binary is called\nAdd app .\nCMD [\"./app\"]\n"
3 }
4
0 [
1 {
2 "key": "Binary",
3 "name": "Binary"
4 },
5 {
6 "key": "Binary-alpine",
7 "name": "Binary-alpine"
8 },
9 {
10 "key": "Binary-scratch",
11 "name": "Binary-scratch"
12 },
13 {
14 "key": "Golang",
15 "name": "Golang"
16 },
17 {
18 "key": "Golang-alpine",
19 "name": "Golang-alpine"
20 },
21 {
22 "key": "Golang-scratch",
23 "name": "Golang-scratch"
24 },
25 {
26 "key": "HTTPd",
27 "name": "HTTPd"
28 },
29 {
30 "key": "Node",
31 "name": "Node"
32 },
33 {
34 "key": "Node-alpine",
35 "name": "Node-alpine"
36 },
37 {
38 "key": "OpenJDK",
39 "name": "OpenJDK"
40 },
41 {
42 "key": "OpenJDK-alpine",
43 "name": "OpenJDK-alpine"
44 },
45 {
46 "key": "PHP",
47 "name": "PHP"
48 },
49 {
50 "key": "Python",
51 "name": "Python"
52 },
53 {
54 "key": "Python-alpine",
55 "name": "Python-alpine"
56 },
57 {
58 "key": "Python2",
59 "name": "Python2"
60 },
61 {
62 "key": "Ruby",
63 "name": "Ruby"
64 },
65 {
66 "key": "Ruby-alpine",
67 "name": "Ruby-alpine"
68 }
69 ]
0 {
1 "name": "Ruby",
2 "content": "*.gem\n*.rbc\n/.config\n/coverage/\n/InstalledFiles\n/pkg/\n/spec/reports/\n/spec/examples.txt\n/test/tmp/\n/test/version_tmp/\n/tmp/\n\n# Used by dotenv library to load environment variables.\n# .env\n\n## Specific to RubyMotion:\n.dat*\n.repl_history\nbuild/\n*.bridgesupport\nbuild-iPhoneOS/\nbuild-iPhoneSimulator/\n\n## Specific to RubyMotion (use of CocoaPods):\n#\n# We recommend against adding the Pods directory to your .gitignore. However\n# you should judge for yourself, the pros and cons are mentioned at:\n# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control\n#\n# vendor/Pods/\n\n## Documentation cache and generated files:\n/.yardoc/\n/_yardoc/\n/doc/\n/rdoc/\n\n## Environment normalization:\n/.bundle/\n/vendor/bundle\n/lib/bundler/man/\n\n# for a library or gem, you might want to ignore these files since the code is\n# intended to run in multiple environments; otherwise, check them in:\n# Gemfile.lock\n# .ruby-version\n# .ruby-gemset\n\n# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:\n.rvmrc\n"
3 }
0 [
1 {
2 "key": "Actionscript",
3 "name": "Actionscript"
4 },
5 {
6 "key": "Ada",
7 "name": "Ada"
8 },
9 {
10 "key": "Agda",
11 "name": "Agda"
12 },
13 {
14 "key": "Android",
15 "name": "Android"
16 },
17 {
18 "key": "AppEngine",
19 "name": "AppEngine"
20 },
21 {
22 "key": "AppceleratorTitanium",
23 "name": "AppceleratorTitanium"
24 },
25 {
26 "key": "ArchLinuxPackages",
27 "name": "ArchLinuxPackages"
28 },
29 {
30 "key": "Autotools",
31 "name": "Autotools"
32 },
33 {
34 "key": "C",
35 "name": "C"
36 },
37 {
38 "key": "C++",
39 "name": "C++"
40 },
41 {
42 "key": "CFWheels",
43 "name": "CFWheels"
44 },
45 {
46 "key": "CMake",
47 "name": "CMake"
48 },
49 {
50 "key": "CUDA",
51 "name": "CUDA"
52 },
53 {
54 "key": "CakePHP",
55 "name": "CakePHP"
56 },
57 {
58 "key": "ChefCookbook",
59 "name": "ChefCookbook"
60 },
61 {
62 "key": "Clojure",
63 "name": "Clojure"
64 },
65 {
66 "key": "CodeIgniter",
67 "name": "CodeIgniter"
68 },
69 {
70 "key": "CommonLisp",
71 "name": "CommonLisp"
72 },
73 {
74 "key": "Composer",
75 "name": "Composer"
76 },
77 {
78 "key": "Concrete5",
79 "name": "Concrete5"
80 }
81 ]
0 {
1 "name": "Ruby",
2 "content": "# This file is a template, and might need editing before it works on your project.\n# Official language image. Look for the different tagged releases at:\n# https://hub.docker.com/r/library/ruby/tags/\nimage: \"ruby:2.3\"\n\n# Pick zero or more services to be used on all builds.\n# Only needed when using a docker container to run your tests in.\n# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-service\nservices:\n - mysql:latest\n - redis:latest\n - postgres:latest\n\nvariables:\n POSTGRES_DB: database_name\n\n# Cache gems in between builds\ncache:\n paths:\n - vendor/ruby\n\n# This is a basic example for a gem or script which doesn't use\n# services such as redis or postgres\nbefore_script:\n - ruby -v # Print out ruby version for debugging\n # Uncomment next line if your rails app needs a JS runtime:\n # - apt-get update -q && apt-get install nodejs -yqq\n - gem install bundler --no-ri --no-rdoc # Bundler is not installed with the image\n - bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby\n\n# Optional - Delete if not using `rubocop`\nrubocop:\n script:\n - rubocop\n\nrspec:\n script:\n - rspec spec\n\nrails:\n variables:\n DATABASE_URL: \"postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB\"\n script:\n - bundle exec rake db:migrate\n - bundle exec rake db:seed\n - bundle exec rake test\n"
3 }
0 [
1 {
2 "key": "Android",
3 "name": "Android"
4 },
5 {
6 "key": "Auto-DevOps",
7 "name": "Auto-DevOps"
8 },
9 {
10 "key": "Bash",
11 "name": "Bash"
12 },
13 {
14 "key": "C++",
15 "name": "C++"
16 },
17 {
18 "key": "Chef",
19 "name": "Chef"
20 },
21 {
22 "key": "Clojure",
23 "name": "Clojure"
24 },
25 {
26 "key": "Crystal",
27 "name": "Crystal"
28 },
29 {
30 "key": "Django",
31 "name": "Django"
32 },
33 {
34 "key": "Docker",
35 "name": "Docker"
36 },
37 {
38 "key": "Elixir",
39 "name": "Elixir"
40 },
41 {
42 "key": "Go",
43 "name": "Go"
44 },
45 {
46 "key": "Gradle",
47 "name": "Gradle"
48 },
49 {
50 "key": "Grails",
51 "name": "Grails"
52 },
53 {
54 "key": "Julia",
55 "name": "Julia"
56 },
57 {
58 "key": "LaTeX",
59 "name": "LaTeX"
60 },
61 {
62 "key": "Laravel",
63 "name": "Laravel"
64 },
65 {
66 "key": "Maven",
67 "name": "Maven"
68 },
69 {
70 "key": "Mono",
71 "name": "Mono"
72 },
73 {
74 "key": "Nodejs",
75 "name": "Nodejs"
76 },
77 {
78 "key": "OpenShift",
79 "name": "OpenShift"
80 }
81 ]
0 {
1 "key": "mit",
2 "name": "MIT License",
3 "nickname": null,
4 "popular": true,
5 "html_url": "http://choosealicense.com/licenses/mit/",
6 "source_url": "https://opensource.org/licenses/MIT",
7 "description": "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.",
8 "conditions": [
9 "include-copyright"
10 ],
11 "permissions": [
12 "commercial-use",
13 "modifications",
14 "distribution",
15 "private-use"
16 ],
17 "limitations": [
18 "liability",
19 "warranty"
20 ],
21 "content": "MIT License\n\nCopyright (c) 2018 [fullname]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
22 }
0 {
1 "key": "mit",
2 "name": "MIT License",
3 "nickname": null,
4 "featured": true,
5 "html_url": "http://choosealicense.com/licenses/mit/",
6 "source_url": "http://opensource.org/licenses/MIT",
7 "description": "A permissive license that is short and to the point. It lets people do anything with your code with proper attribution and without warranty.",
8 "conditions": [
9 "include-copyright"
10 ],
11 "permissions": [
12 "commercial-use",
13 "modifications",
14 "distribution",
15 "private-use"
16 ],
17 "limitations": [
18 "no-liability"
19 ],
20 "content": "The MIT License (MIT)\n\nCopyright (c) 2016 John Doe\n [...]"
21 }
0 [
1 {
2 "key": "apache-2.0",
3 "name": "Apache License 2.0",
4 "nickname": null,
5 "featured": true,
6 "html_url": "http://choosealicense.com/licenses/apache-2.0/",
7 "source_url": "http://www.apache.org/licenses/LICENSE-2.0.html",
8 "description": "A permissive license that also provides an express grant of patent rights from contributors to users.",
9 "conditions": [
10 "include-copyright",
11 "document-changes"
12 ],
13 "permissions": [
14 "commercial-use",
15 "modifications",
16 "distribution",
17 "patent-use",
18 "private-use"
19 ],
20 "limitations": [
21 "trademark-use",
22 "no-liability"
23 ],
24 "content": " Apache License\n Version 2.0, January 2004\n [...]"
25 },
26 {
27 "key": "gpl-3.0",
28 "name": "GNU General Public License v3.0",
29 "nickname": "GNU GPLv3",
30 "featured": true,
31 "html_url": "http://choosealicense.com/licenses/gpl-3.0/",
32 "source_url": "http://www.gnu.org/licenses/gpl-3.0.txt",
33 "description": "The GNU GPL is the most widely used free software license and has a strong copyleft requirement. When distributing derived works, the source code of the work must be made available under the same license.",
34 "conditions": [
35 "include-copyright",
36 "document-changes",
37 "disclose-source",
38 "same-license"
39 ],
40 "permissions": [
41 "commercial-use",
42 "modifications",
43 "distribution",
44 "patent-use",
45 "private-use"
46 ],
47 "limitations": [
48 "no-liability"
49 ],
50 "content": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n [...]"
51 },
52 {
53 "key": "mit",
54 "name": "MIT License",
55 "nickname": null,
56 "featured": true,
57 "html_url": "http://choosealicense.com/licenses/mit/",
58 "source_url": "http://opensource.org/licenses/MIT",
59 "description": "A permissive license that is short and to the point. It lets people do anything with your code with proper attribution and without warranty.",
60 "conditions": [
61 "include-copyright"
62 ],
63 "permissions": [
64 "commercial-use",
65 "modifications",
66 "distribution",
67 "private-use"
68 ],
69 "limitations": [
70 "no-liability"
71 ],
72 "content": "The MIT License (MIT)\n\nCopyright (c) [year] [fullname]\n [...]"
73 }
74 ]
0 {
1 "id": "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
2 "short_id": "1a0b36b3",
3 "title": "Initial commit",
4 "created_at": "2014-02-27T08:03:18.000Z",
5 "parent_ids": [],
6 "message": "Initial commit\n",
7 "author_name": "Dmitriy Zaporozhets",
8 "author_email": "dmitriy.zaporozhets@gmail.com",
9 "authored_date": "2014-02-27T08:03:18.000Z",
10 "committer_name": "Dmitriy Zaporozhets",
11 "committer_email": "dmitriy.zaporozhets@gmail.com",
12 "committed_date": "2014-02-27T08:03:18.000Z"
13 }
0 {
1 "id": 110,
2 "head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
3 "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
4 "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
5 "created_at": "2016-07-26T14:44:48.926Z",
6 "merge_request_id": 105,
7 "state": "collected",
8 "real_size": "1",
9 "commits": [{
10 "id": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
11 "short_id": "33e2ee85",
12 "title": "Change year to 2018",
13 "author_name": "Administrator",
14 "author_email": "admin@example.com",
15 "created_at": "2016-07-26T17:44:29.000+03:00",
16 "message": "Change year to 2018"
17 }, {
18 "id": "aa24655de48b36335556ac8a3cd8bb521f977cbd",
19 "short_id": "aa24655d",
20 "title": "Update LICENSE",
21 "author_name": "Administrator",
22 "author_email": "admin@example.com",
23 "created_at": "2016-07-25T17:21:53.000+03:00",
24 "message": "Update LICENSE"
25 }, {
26 "id": "3eed087b29835c48015768f839d76e5ea8f07a24",
27 "short_id": "3eed087b",
28 "title": "Add license",
29 "author_name": "Administrator",
30 "author_email": "admin@example.com",
31 "created_at": "2016-07-25T17:21:20.000+03:00",
32 "message": "Add license"
33 }],
34 "diffs": [{
35 "old_path": "LICENSE",
36 "new_path": "LICENSE",
37 "a_mode": "0",
38 "b_mode": "100644",
39 "diff": "--- /dev/null\n+++ b/LICENSE\n@@ -0,0 +1,21 @@\n+The MIT License (MIT)\n+\n+Copyright (c) 2018 Administrator\n+\n+Permission is hereby granted, free of charge, to any person obtaining a copy\n+of this software and associated documentation files (the \"Software\"), to deal\n+in the Software without restriction, including without limitation the rights\n+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+copies of the Software, and to permit persons to whom the Software is\n+furnished to do so, subject to the following conditions:\n+\n+The above copyright notice and this permission notice shall be included in all\n+copies or substantial portions of the Software.\n+\n+THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n+SOFTWARE.\n",
40 "new_file": true,
41 "renamed_file": false,
42 "deleted_file": false
43 }]
44 }
0 [{
1 "id": 110,
2 "head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
3 "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
4 "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
5 "created_at": "2016-07-26T14:44:48.926Z",
6 "merge_request_id": 105,
7 "state": "collected",
8 "real_size": "1"
9 }, {
10 "id": 108,
11 "head_commit_sha": "3eed087b29835c48015768f839d76e5ea8f07a24",
12 "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
13 "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
14 "created_at": "2016-07-25T14:21:33.028Z",
15 "merge_request_id": 105,
16 "state": "collected",
17 "real_size": "1"
18 }]
0 [{"id":1,"target_branch":"master","source_branch":"api","project_id":3,"title":"New feature","closed":false,"merged":false,"author":{"id":2,"email":"john2@example.com","name":"John Smith 2","blocked":false,"created_at":"2012-10-19T05:56:05Z"},"assignee":{"id":2,"email":"jack@example.com","name":"Jack Smith 2","blocked":false,"created_at":"2012-10-19T05:56:14Z"}},{"id":2,"target_branch":"master","source_branch":"api","project_id":2,"title":"New feature 2","closed":false,"merged":false,"author":{"id":2,"email":"john@example.com","name":"John Smith","blocked":false,"created_at":"2012-10-19T05:56:05Z"},"assignee":{"id":4,"email":"jack@example.com","name":"Jack Smith","blocked":false,"created_at":"2012-10-19T05:56:14Z"}}]
0 [
1 {
2 "id": 1,
3 "name": "John Doe1",
4 "username": "user1",
5 "state": "active",
6 "avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon",
7 "web_url": "http://localhost/user1"
8 },
9 {
10 "id": 5,
11 "name": "John Doe5",
12 "username": "user5",
13 "state": "active",
14 "avatar_url": "http://www.gravatar.com/avatar/4aea8cf834ed91844a2da4ff7ae6b491?s=80&d=identicon",
15 "web_url": "http://localhost/user5"
16 }
17 ]
0 {
1 "link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}",
2 "image_url": "https://shields.io/my/badge",
3 "rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
4 "rendered_image_url": "https://shields.io/my/badge"
5 }
0 {
1 "id": 1,
2 "link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}",
3 "image_url": "https://shields.io/my/badge",
4 "rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
5 "rendered_image_url": "https://shields.io/my/badge",
6 "kind": "project"
7 }
0 [
1 {
2 "id": 1,
3 "link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}",
4 "image_url": "https://shields.io/my/badge",
5 "rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
6 "rendered_image_url": "https://shields.io/my/badge",
7 "kind": "project"
8 },
9 {
10 "id": 2,
11 "link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}",
12 "image_url": "https://shields.io/my/badge",
13 "rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
14 "rendered_image_url": "https://shields.io/my/badge",
15 "kind": "group"
16 }
17 ]
0 [
1 {
2 "key": "epl-1.0",
3 "name": "Eclipse Public License 1.0"
4 },
5 {
6 "key": "lgpl-3.0",
7 "name": "GNU Lesser General Public License v3.0"
8 },
9 {
10 "key": "unlicense",
11 "name": "The Unlicense"
12 },
13 {
14 "key": "agpl-3.0",
15 "name": "GNU Affero General Public License v3.0"
16 },
17 {
18 "key": "gpl-3.0",
19 "name": "GNU General Public License v3.0"
20 },
21 {
22 "key": "bsd-3-clause",
23 "name": "BSD 3-clause \"New\" or \"Revised\" License"
24 },
25 {
26 "key": "lgpl-2.1",
27 "name": "GNU Lesser General Public License v2.1"
28 },
29 {
30 "key": "mit",
31 "name": "MIT License"
32 },
33 {
34 "key": "apache-2.0",
35 "name": "Apache License 2.0"
36 },
37 {
38 "key": "bsd-2-clause",
39 "name": "BSD 2-clause \"Simplified\" License"
40 },
41 {
42 "key": "mpl-2.0",
43 "name": "Mozilla Public License 2.0"
44 },
45 {
46 "key": "gpl-2.0",
47 "name": "GNU General Public License v2.0"
48 }
49 ]
0 {
1 "name": "master",
2 "push_access_levels": [
3 {
4 "access_level": 40,
5 "access_level_description": "Maintainers"
6 }
7 ],
8 "merge_access_levels": [
9 {
10 "access_level": 40,
11 "access_level_description": "Maintainers"
12 }
13 ]
14 }
0 [
1 {
2 "name": "master",
3 "push_access_levels": [
4 {
5 "access_level": 40,
6 "access_level_description": "Maintainers"
7 }
8 ],
9 "merge_access_levels": [
10 {
11 "access_level": 40,
12 "access_level_description": "Maintainers"
13 }
14 ]
15 }
16 ]
0 {
1 "name": "release-1-0",
2 "create_access_levels": [
3 {
4 "access_level": 40,
5 "access_level_description": "Maintainers"
6 }
7 ]
8 }
0 [
1 {
2 "name": "release-1-0",
3 "create_access_levels": [
4 {
5 "access_level": 40,
6 "access_level_description": "Maintainers"
7 }
8 ]
9 }
10 ]
0 {
1 "id": "ed899a2f4b50b4370feeea94676502b42383c746",
2 "short_id": "ed899a2f4b5",
3 "title": "Updated submodule example_submodule with oid 3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88",
4 "author_name": "Dmitriy Zaporozhets",
5 "author_email": "dzaporozhets@sphereconsultinginc.com",
6 "committer_name": "Dmitriy Zaporozhets",
7 "committer_email": "dzaporozhets@sphereconsultinginc.com",
8 "created_at": "2018-09-20T09:26:24.000-07:00",
9 "message": "Updated submodule example_submodule with oid 3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88",
10 "parent_ids": [
11 "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
12 ],
13 "committed_date": "2018-09-20T09:26:24.000-07:00",
14 "authored_date": "2018-09-20T09:26:24.000-07:00",
15 "status": null
16 }
0 {"id":1,"email":"john@example.com","name":"John Smith","blocked":false,"created_at":"2012-09-17T09:41:56Z","access_level":40}
0 {
1 "id": 1,
2 "username": "john_smith",
3 "name": "John Smith",
4 "state": "active",
5 "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",
6 "web_url": "http://192.168.1.8:3000/root",
7 "expires_at": "2018-12-31T00:00:00Z",
8 "access_level": 40
9 }
0 {
1 "id": 1,
2 "description": null,
3 "name": "test",
4 "name_with_namespace": "Yolo / test",
5 "path": "test",
6 "path_with_namespace": "yolo/test",
7 "created_at": "2018-10-26T21:14:12.851Z",
8 "default_branch": "master",
9 "tag_list": [],
10 "ssh_url_to_repo": "git@gitlab.com:yolo/test.git",
11 "http_url_to_repo": "https://gitlab.com/yolo/test.git",
12 "web_url": "https://gitlab.com/yolo/test",
13 "readme_url": null,
14 "avatar_url": null,
15 "star_count": 0,
16 "forks_count": 0,
17 "last_activity_at": "2018-10-26T21:14:12.851Z",
18 "namespace": {
19 "id": 2,
20 "name": "Yolo",
21 "path": "yolo",
22 "kind": "group",
23 "full_path": "yolo",
24 "parent_id": null
25 },
26 "_links": {
27 "self": "https://gitlab.com/api/v4/projects/1",
28 "issues": "https://gitlab.com/api/v4/projects/1/issues",
29 "merge_requests": "https://gitlab.com/api/v4/projects/1/merge_requests",
30 "repo_branches": "https://gitlab.com/api/v4/projects/1/repository/branches",
31 "labels": "https://gitlab.com/api/v4/projects/1/labels",
32 "events": "https://gitlab.com/api/v4/projects/1/events",
33 "members": "https://gitlab.com/api/v4/projects/1/members"
34 },
35 "archived": false,
36 "visibility": "private",
37 "resolve_outdated_diff_discussions": false,
38 "container_registry_enabled": true,
39 "issues_enabled": true,
40 "merge_requests_enabled": true,
41 "wiki_enabled": true,
42 "jobs_enabled": true,
43 "snippets_enabled": true,
44 "shared_runners_enabled": true,
45 "lfs_enabled": true,
46 "creator_id": 42,
47 "import_status": "none",
48 "open_issues_count": 0,
49 "public_jobs": true,
50 "ci_config_path": null,
51 "shared_with_groups": [],
52 "only_allow_merge_if_pipeline_succeeds": false,
53 "request_access_enabled": false,
54 "only_allow_merge_if_all_discussions_are_resolved": false,
55 "printing_merge_request_link_enabled": true,
56 "merge_method": "merge",
57 "mirror": false
58 }
0 {
1 "alt": "null",
2 "url": "/uploads/f22e67e35e1bcb339058212c54bb8772/null",
3 "markdown": "[null](/uploads/f22e67e35e1bcb339058212c54bb8772/null)"
4 }
0 {
1 "version": "8.13.0-pre",
2 "revision": "4e963fe"
3 }
0 {
1 "content" : "home page",
2 "format" : "markdown",
3 "slug" : "home",
4 "title" : "home"
5 }
6
0 {
1 "file_name" : "dk.png",
2 "file_path" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",
3 "branch" : "master",
4 "link" : {
5 "url" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",
6 "markdown" : "![dk](uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png)"
7 }
8 }
0 [
1 {
2 "content" : "Here is an instruction how to deploy this project.",
3 "format" : "markdown",
4 "slug" : "deploy",
5 "title" : "deploy"
6 },
7 {
8 "content" : "Our development process is described here.",
9 "format" : "markdown",
10 "slug" : "development",
11 "title" : "development"
12 },{
13 "content" : "* [Deploy](deploy)\n* [Development](development)",
14 "format" : "markdown",
15 "slug" : "home",
16 "title" : "home"
17 }
18 ]
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::API do
35 let(:default_headers) { subject.class.default_options[:headers] }
46
5 describe ".default_options[:headers]" do
7 describe '.default_options[:headers]' do
68 it "has 'User-Agent'" do
79 expect(default_headers).to include('User-Agent' => Gitlab::Configuration::DEFAULT_USER_AGENT)
810 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::CLI::Helpers do
3 describe ".method_owners" do
4 let(:methods) { Gitlab::CLI::Helpers.method_owners }
5 describe '.method_owners' do
6 let(:methods) { described_class.method_owners }
57
6 it "returns Array of Hashes containing method names and owners" do
8 it 'returns Array of Hashes containing method names and owners' do
79 expect(methods).to be_a Array
810 expect(methods.all? { |m| m.is_a? Hash }).to be true
9 expect(methods.all? { |m| m.keys.sort == %i(name owner) }).to be true
11 expect(methods.all? { |m| m.keys.sort == %i[name owner] }).to be true
1012 end
1113 end
1214
13 describe ".valid_command?" do
14 it "returns true when command is valid" do
15 expect(Gitlab::CLI::Helpers.valid_command?('merge_requests')).to be_truthy
15 describe '.valid_command?' do
16 it 'returns true when command is valid' do
17 expect(described_class).to be_valid_command('merge_requests')
1618 end
17 it "returns false when command is NOT valid" do
18 expect(Gitlab::CLI::Helpers.valid_command?('mmmmmerge_requests')).to be_falsy
19 it 'returns false when command is NOT valid' do
20 expect(described_class).not_to be_valid_command('mmmmmerge_requests')
1921 end
2022 end
2123
22 describe ".symbolize_keys" do
23 context "when input is a Hash" do
24 it "returns a Hash with symbols for keys" do
24 describe '.symbolize_keys' do
25 context 'when input is a Hash' do
26 it 'returns a Hash with symbols for keys' do
2527 hash = { 'key1' => 'val1', 'key2' => 'val2' }
26 symbolized_hash = Gitlab::CLI::Helpers.symbolize_keys(hash)
28 symbolized_hash = described_class.symbolize_keys(hash)
2729 expect(symbolized_hash).to eq(key1: 'val1', key2: 'val2')
2830 end
2931 end
30 context "when input is NOT a Hash" do
31 it "returns input untouched" do
32
33 context 'when input is NOT a Hash' do
34 it 'returns input untouched' do
3235 array = [1, 2, 3]
33 new_array = Gitlab::CLI::Helpers.symbolize_keys(array)
36 new_array = described_class.symbolize_keys(array)
3437 expect(new_array).to eq([1, 2, 3])
3538 end
3639 end
3740 end
3841
39 describe ".yaml_load" do
40 context "when argument is a YAML string" do
41 it "returns Ruby objects" do
42 argument = "{foo: bar, sna: fu}"
43 output = Gitlab::CLI::Helpers.yaml_load argument
42 describe '.yaml_load' do
43 context 'when argument is a YAML string' do
44 it 'returns Ruby objects' do
45 argument = '{foo: bar, sna: fu}'
46 output = described_class.yaml_load argument
4447 expect(output).to eq('foo' => 'bar', 'sna' => 'fu')
4548 end
4649 end
4750
48 context "when input is NOT valid YAML" do
49 it "raises a TypeError" do
51 context 'when input is NOT valid YAML' do
52 it 'raises a TypeError' do
5053 ruby_array = [1, 2, 3, 4]
51 expect { Gitlab::CLI::Helpers.yaml_load ruby_array }.to raise_error TypeError
54 expect { described_class.yaml_load ruby_array }.to raise_error TypeError
5255 end
5356 end
5457 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13 require 'json'
24
35 describe Gitlab::CLI do
4 describe ".run" do
5 context "when command is version" do
6 it "shows gem version" do
7 output = capture_output { Gitlab::CLI.run('-v') }
6 describe '.run' do
7 context 'when command is version' do
8 it 'shows gem version' do
9 output = capture_output { described_class.run('-v') }
810 expect(output).to eq("Gitlab Ruby Gem #{Gitlab::VERSION}\n")
911 end
1012 end
1113
12 context "when command is info" do
13 it "shows environment info" do
14 output = capture_output { Gitlab::CLI.run('info') }
15 expect(output).to include("Gitlab endpoint is")
16 expect(output).to include("Gitlab private token is")
17 expect(output).to include("Ruby Version is")
18 expect(output).to include("Gitlab Ruby Gem")
14 context 'when command is info' do
15 it 'shows environment info' do
16 output = capture_output { described_class.run('info') }
17 expect(output).to include('Gitlab endpoint is')
18 expect(output).to include('Gitlab private token is')
19 expect(output).to include('Ruby Version is')
20 expect(output).to include('Gitlab Ruby Gem')
1921 end
2022 end
2123
22 context "when command is help" do
23 it "shows available actions" do
24 output = capture_output { Gitlab::CLI.run('help') }
24 context 'when command is help' do
25 it 'shows available actions' do
26 output = capture_output { described_class.run('help') }
2527 expect(output).to include('Help Topics')
2628 expect(output).to include('MergeRequests')
2729 end
2830 end
2931
30 context "when command is user" do
32 context 'when command is user' do
3133 before do
32 stub_get("/user", "user")
33 @output = capture_output { Gitlab::CLI.run('user') }
34 stub_get('/user', 'user')
35 @output = capture_output { described_class.run('user') }
3436 end
3537
36 it "shows executed command" do
38 it 'shows executed command' do
3739 expect(@output).to include('Gitlab.user')
3840 end
3941
40 it "shows user data" do
42 it 'shows user data' do
4143 expect(@output).to include('name')
4244 expect(@output).to include('John Smith')
4345 end
4446 end
4547
46 context "when command is users" do
48 context 'when command is users' do
4749 before do
48 stub_get("/users", "users")
49 @output = capture_output { Gitlab::CLI.run('users') }
50 stub_get('/users', 'users')
51 @output = capture_output { described_class.run('users') }
5052 end
5153
52 it "shows executed command" do
54 it 'shows executed command' do
5355 expect(@output).to include('Gitlab.users')
5456 end
5557
56 it "shows users data" do
58 it 'shows users data' do
5759 expect(@output).to include('name')
5860 expect(@output).to include('John Smith')
5961 expect(@output).to include('Jack Smith')
6062 end
6163 end
64
65 context 'when command is create_label' do
66 before do
67 stub_post('/projects/Project/labels', 'label')
68 args = ['Project', 'Backlog', '#DD10AA']
69 @output = capture_output { described_class.run('create_label', args) }
70 end
71
72 it 'shows executed command' do
73 expect(@output).to include('Gitlab.create_label Project, Backlog, #DD10AA')
74 end
75 end
6276 end
6377
64 describe ".start" do
65 context "when command with excluded fields" do
78 describe '.start' do
79 context 'when command with excluded fields' do
6680 before do
67 stub_get("/user", "user")
81 stub_get('/user', 'user')
6882 args = ['user', '--except=id,email,name']
69 @output = capture_output { Gitlab::CLI.start(args) }
83 @output = capture_output { described_class.start(args) }
7084 end
7185
72 it "shows user data with excluded fields" do
73 expect(@output).to_not include('John Smith')
86 it 'shows user data with excluded fields' do
87 expect(@output).not_to include('John Smith')
7488 expect(@output).to include('bio')
7589 expect(@output).to include('created_at')
7690 end
7791 end
7892
79 context "when command with json output" do
93 context 'when command with json output' do
8094 before do
81 stub_get("/user", "user")
95 stub_get('/user', 'user')
8296 args = ['user', '--json']
83 @output = capture_output { Gitlab::CLI.start(args) }
97 @output = capture_output { described_class.start(args) }
8498 end
8599
86 it "renders output as json" do
100 it 'renders output as json' do
87101 expect(JSON.parse(@output)['result']).to eq(JSON.parse(File.read(File.dirname(__FILE__) + '/../fixtures/user.json')))
88102 expect(JSON.parse(@output)['cmd']).to eq('Gitlab.user')
89103 end
90104 end
91105
92 context "when command with required fields" do
106 context 'when command with required fields' do
93107 before do
94 stub_get("/user", "user")
108 stub_get('/user', 'user')
95109 args = ['user', '--only=id,email,name']
96 @output = capture_output { Gitlab::CLI.start(args) }
110 @output = capture_output { described_class.start(args) }
97111 end
98112
99 it "shows user data with required fields" do
113 it 'shows user data with required fields' do
100114 expect(@output).to include('id')
101115 expect(@output).to include('name')
102116 expect(@output).to include('email')
103117 expect(@output).to include('John Smith')
104 expect(@output).to_not include('bio')
105 expect(@output).to_not include('created_at')
118 expect(@output).not_to include('bio')
119 expect(@output).not_to include('created_at')
106120 end
107121 end
108122
109 context "fetch project with namespace/repo" do
110 it "encodes delimiter" do
111 stub_get("/projects/gitlab-org%2Fgitlab-ce", "project")
123 context 'fetch project with namespace/repo' do
124 it 'encodes delimiter' do
125 stub_get('/projects/gitlab-org%2Fgitlab-ce', 'project')
112126 args = ['project', 'gitlab-org/gitlab-ce']
113 @output = capture_output { Gitlab::CLI.start(args) }
127 @output = capture_output { described_class.start(args) }
114128 expect(@output).to include('id')
115129 end
116130 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
35 describe '.project_access_requests' do
46 before do
5 stub_get("/projects/1/access_requests", "access_requests")
7 stub_get('/projects/1/access_requests', 'access_requests')
68 @access_requests = Gitlab.project_access_requests(1)
79 end
810
911 it 'gets the correct resources' do
10 expect(a_get("/projects/1/access_requests")).to have_been_made
12 expect(a_get('/projects/1/access_requests')).to have_been_made
1113 end
1214
1315 it 'returns a paginated response of project access requests' do
1719
1820 describe '.group_access_requests' do
1921 before do
20 stub_get("/groups/1/access_requests", "access_requests")
22 stub_get('/groups/1/access_requests', 'access_requests')
2123 @access_requests = Gitlab.group_access_requests(1)
2224 end
2325
2426 it 'gets the correct resources' do
25 expect(a_get("/groups/1/access_requests")).to have_been_made
27 expect(a_get('/groups/1/access_requests')).to have_been_made
2628 end
2729
2830 it 'returns a paginated response of group access requests' do
3234
3335 describe '.request_project_access' do
3436 before do
35 stub_post("/projects/1/access_requests", "access_request")
37 stub_post('/projects/1/access_requests', 'access_request')
3638 @access_request = Gitlab.request_project_access(1)
3739 end
3840
3941 it 'gets the correct resource' do
40 expect(a_post("/projects/1/access_requests")).to have_been_made
42 expect(a_post('/projects/1/access_requests')).to have_been_made
4143 end
4244 end
4345
4446 describe '.request_group_access' do
4547 before do
46 stub_post("/groups/1/access_requests", "access_request")
48 stub_post('/groups/1/access_requests', 'access_request')
4749 @access_request = Gitlab.request_group_access(1)
4850 end
4951
5052 it 'gets the correct resource' do
51 expect(a_post("/groups/1/access_requests")).to have_been_made
53 expect(a_post('/groups/1/access_requests')).to have_been_made
5254 end
5355 end
5456
5557 describe '.approve_project_access_request' do
5658 context 'When no access level is given' do
5759 before do
58 stub_put("/projects/1/access_requests/1/approve", "default_approved_access_request")
60 stub_put('/projects/1/access_requests/1/approve', 'default_approved_access_request')
5961 @access_request = Gitlab.approve_project_access_request(1, 1)
6062 end
6163
6264 it 'gets the correct resource' do
63 expect(a_put("/projects/1/access_requests/1/approve")).to have_been_made
65 expect(a_put('/projects/1/access_requests/1/approve')).to have_been_made
6466 end
6567
66 it "returns information about the project access request" do
68 it 'returns information about the project access request' do
6769 expect(@access_request.access_level).to eq(30)
6870 end
6971 end
72
7073 context 'When access level is given' do
7174 before do
72 stub_put("/projects/1/access_requests/1/approve", "approved_access_request").with(body: {access_level: '20'})
73 @access_request = Gitlab.approve_project_access_request(1, 1, {access_level: '20'})
75 stub_put('/projects/1/access_requests/1/approve', 'approved_access_request').with(body: { access_level: '20' })
76 @access_request = Gitlab.approve_project_access_request(1, 1, access_level: '20')
7477 end
7578
7679 it 'gets the correct resource' do
77 expect(a_put("/projects/1/access_requests/1/approve").
78 with(body: { access_level: "20" })).to have_been_made
80 expect(a_put('/projects/1/access_requests/1/approve')
81 .with(body: { access_level: '20' })).to have_been_made
7982 end
8083
81 it "returns information about the project access request" do
84 it 'returns information about the project access request' do
8285 expect(@access_request.access_level).to eq(20)
8386 end
8487 end
8790 describe '.approve_group_access_request' do
8891 context 'When no access level is given' do
8992 before do
90 stub_put("/groups/1/access_requests/1/approve", "default_approved_access_request")
93 stub_put('/groups/1/access_requests/1/approve', 'default_approved_access_request')
9194 @access_request = Gitlab.approve_group_access_request(1, 1)
9295 end
9396
9497 it 'gets the correct resource' do
95 expect(a_put("/groups/1/access_requests/1/approve")).to have_been_made
98 expect(a_put('/groups/1/access_requests/1/approve')).to have_been_made
9699 end
97100
98 it "returns information about the group access request" do
101 it 'returns information about the group access request' do
99102 expect(@access_request.access_level).to eq(30)
100103 end
101104 end
105
102106 context 'When access level is given' do
103107 before do
104 stub_put("/groups/1/access_requests/1/approve", "approved_access_request").with(body: {access_level: '20'})
105 @access_request = Gitlab.approve_group_access_request(1, 1, {access_level: '20'})
108 stub_put('/groups/1/access_requests/1/approve', 'approved_access_request').with(body: { access_level: '20' })
109 @access_request = Gitlab.approve_group_access_request(1, 1, access_level: '20')
106110 end
107111
108112 it 'gets the correct resource' do
109 expect(a_put("/groups/1/access_requests/1/approve").
110 with(body: { access_level: "20" })).to have_been_made
113 expect(a_put('/groups/1/access_requests/1/approve')
114 .with(body: { access_level: '20' })).to have_been_made
111115 end
112116
113 it "returns information about the group access request" do
117 it 'returns information about the group access request' do
114118 expect(@access_request.access_level).to eq(20)
115119 end
116120 end
118122
119123 describe '.deny_project_access_request' do
120124 before do
121 stub_delete("/projects/1/access_requests/1", "access_request")
125 stub_delete('/projects/1/access_requests/1', 'access_request')
122126 @access_request = Gitlab.deny_project_access_request(1, 1)
123127 end
124128
125129 it 'gets the correct resource' do
126 expect(a_delete("/projects/1/access_requests/1")).to have_been_made
130 expect(a_delete('/projects/1/access_requests/1')).to have_been_made
127131 end
128132 end
129133
130134 describe '.deny_group_access_request' do
131135 before do
132 stub_delete("/groups/1/access_requests/1", "access_request")
136 stub_delete('/groups/1/access_requests/1', 'access_request')
133137 @access_request = Gitlab.deny_group_access_request(1, 1)
134138 end
135139
136140 it 'gets the correct resource' do
137 expect(a_delete("/groups/1/access_requests/1")).to have_been_made
141 expect(a_delete('/groups/1/access_requests/1')).to have_been_made
138142 end
139143 end
140 end
144 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
35 describe '.award_emojis' do
46 context 'when issue award emojis' do
57 before do
6 stub_get("/projects/1/issues/80/award_emoji", "issue_award_emojis")
8 stub_get('/projects/1/issues/80/award_emoji', 'issue_award_emojis')
79 @emojis = Gitlab.award_emojis(1, 80, 'issue')
810 end
911
10 it "gets the correct resources" do
11 expect(a_get("/projects/1/issues/80/award_emoji")).to have_been_made
12 end
13
14 it "returns a paginated response of issue award emojis" do
12 it 'gets the correct resources' do
13 expect(a_get('/projects/1/issues/80/award_emoji')).to have_been_made
14 end
15
16 it 'returns a paginated response of issue award emojis' do
1517 expect(@emojis).to be_a Gitlab::PaginatedResponse
1618 expect(@emojis.first.awardable_id).to eq(80)
17 expect(@emojis.first.awardable_type).to eq("Issue")
19 expect(@emojis.first.awardable_type).to eq('Issue')
1820 end
1921 end
2022
2123 context 'when merge request award emojis' do
2224 before do
23 stub_get("/projects/1/merge_requests/80/award_emoji", "merge_request_award_emojis")
25 stub_get('/projects/1/merge_requests/80/award_emoji', 'merge_request_award_emojis')
2426 @emojis = Gitlab.award_emojis(1, 80, 'merge_request')
2527 end
2628
27 it "gets the correct resources" do
28 expect(a_get("/projects/1/merge_requests/80/award_emoji")).to have_been_made
29 end
30
31 it "returns a paginated response of merge request award emojis" do
29 it 'gets the correct resources' do
30 expect(a_get('/projects/1/merge_requests/80/award_emoji')).to have_been_made
31 end
32
33 it 'returns a paginated response of merge request award emojis' do
3234 expect(@emojis).to be_a Gitlab::PaginatedResponse
3335 expect(@emojis.first.awardable_id).to eq(80)
34 expect(@emojis.first.awardable_type).to eq("MergeRequest")
36 expect(@emojis.first.awardable_type).to eq('MergeRequest')
3537 end
3638 end
3739
3840 context 'when snippet award emojis' do
3941 before do
40 stub_get("/projects/1/snippets/80/award_emoji", "snippet_award_emojis")
42 stub_get('/projects/1/snippets/80/award_emoji', 'snippet_award_emojis')
4143 @emojis = Gitlab.award_emojis(1, 80, 'snippet')
4244 end
4345
44 it "gets the correct resources" do
45 expect(a_get("/projects/1/snippets/80/award_emoji")).to have_been_made
46 end
47
48 it "returns a paginated response of snippet award emojis" do
46 it 'gets the correct resources' do
47 expect(a_get('/projects/1/snippets/80/award_emoji')).to have_been_made
48 end
49
50 it 'returns a paginated response of snippet award emojis' do
4951 expect(@emojis).to be_a Gitlab::PaginatedResponse
5052 expect(@emojis.first.awardable_id).to eq(80)
51 expect(@emojis.first.awardable_type).to eq("Snippet")
53 expect(@emojis.first.awardable_type).to eq('Snippet')
5254 end
5355 end
5456 end
5658 describe '.note_award_emojis' do
5759 context 'when issue note award emojis' do
5860 before do
59 stub_get("/projects/1/issues/80/notes/1/award_emoji", "note_award_emojis")
61 stub_get('/projects/1/issues/80/notes/1/award_emoji', 'note_award_emojis')
6062 @note_emojis = Gitlab.note_award_emojis(1, 80, 'issue', 1)
6163 end
6264
63 it "gets the correct resources" do
64 expect(a_get("/projects/1/issues/80/notes/1/award_emoji")).to have_been_made
65 end
66
67 it "returns a paginated response of issue note award emojis" do
65 it 'gets the correct resources' do
66 expect(a_get('/projects/1/issues/80/notes/1/award_emoji')).to have_been_made
67 end
68
69 it 'returns a paginated response of issue note award emojis' do
6870 expect(@note_emojis).to be_a Gitlab::PaginatedResponse
6971 expect(@note_emojis.first.awardable_id).to eq(1)
70 expect(@note_emojis.first.awardable_type).to eq("Note")
72 expect(@note_emojis.first.awardable_type).to eq('Note')
7173 end
7274 end
7375
7476 context 'when merge request note award emojis' do
7577 before do
76 stub_get("/projects/1/merge_requests/80/notes/1/award_emoji", "note_award_emojis")
78 stub_get('/projects/1/merge_requests/80/notes/1/award_emoji', 'note_award_emojis')
7779 @note_emojis = Gitlab.note_award_emojis(1, 80, 'merge_request', 1)
7880 end
7981
80 it "gets the correct resources" do
81 expect(a_get("/projects/1/merge_requests/80/notes/1/award_emoji")).to have_been_made
82 end
83
84 it "returns a paginated response of merge request note award emojis" do
82 it 'gets the correct resources' do
83 expect(a_get('/projects/1/merge_requests/80/notes/1/award_emoji')).to have_been_made
84 end
85
86 it 'returns a paginated response of merge request note award emojis' do
8587 expect(@note_emojis).to be_a Gitlab::PaginatedResponse
8688 expect(@note_emojis.first.awardable_id).to eq(1)
87 expect(@note_emojis.first.awardable_type).to eq("Note")
89 expect(@note_emojis.first.awardable_type).to eq('Note')
8890 end
8991 end
9092
9193 context 'when snippet note award emojis' do
9294 before do
93 stub_get("/projects/1/snippets/80/notes/1/award_emoji", "note_award_emojis")
95 stub_get('/projects/1/snippets/80/notes/1/award_emoji', 'note_award_emojis')
9496 @note_emojis = Gitlab.note_award_emojis(1, 80, 'snippet', 1)
9597 end
9698
97 it "gets the correct resources" do
98 expect(a_get("/projects/1/snippets/80/notes/1/award_emoji")).to have_been_made
99 end
100
101 it "returns a paginated response of snippet note award emojis" do
99 it 'gets the correct resources' do
100 expect(a_get('/projects/1/snippets/80/notes/1/award_emoji')).to have_been_made
101 end
102
103 it 'returns a paginated response of snippet note award emojis' do
102104 expect(@note_emojis).to be_a Gitlab::PaginatedResponse
103105 expect(@note_emojis.first.awardable_id).to eq(1)
104 expect(@note_emojis.first.awardable_type).to eq("Note")
106 expect(@note_emojis.first.awardable_type).to eq('Note')
105107 end
106108 end
107109 end
109111 describe '.award_emoji' do
110112 context 'when issue award emoji' do
111113 before do
112 stub_get("/projects/1/issues/80/award_emoji/4", "issue_award_emoji")
114 stub_get('/projects/1/issues/80/award_emoji/4', 'issue_award_emoji')
113115 @emoji = Gitlab.award_emoji(1, 80, 'issue', 4)
114116 end
115117
116 it "gets the correct resource" do
117 expect(a_get("/projects/1/issues/80/award_emoji/4")).to have_been_made
118 end
119
120 it "returns information about an issue award emoji" do
118 it 'gets the correct resource' do
119 expect(a_get('/projects/1/issues/80/award_emoji/4')).to have_been_made
120 end
121
122 it 'returns information about an issue award emoji' do
121123 expect(@emoji.id).to eq(4)
122 expect(@emoji.awardable_type).to eq("Issue")
124 expect(@emoji.awardable_type).to eq('Issue')
123125 expect(@emoji.awardable_id).to eq(80)
124126 end
125127 end
126128
127129 context 'when merge request award emoji' do
128130 before do
129 stub_get("/projects/1/merge_requests/80/award_emoji/4", "merge_request_award_emoji")
131 stub_get('/projects/1/merge_requests/80/award_emoji/4', 'merge_request_award_emoji')
130132 @emoji = Gitlab.award_emoji(1, 80, 'merge_request', 4)
131133 end
132134
133 it "gets the correct resource" do
134 expect(a_get("/projects/1/merge_requests/80/award_emoji/4")).to have_been_made
135 end
136
137 it "returns information about a merge request award emoji" do
135 it 'gets the correct resource' do
136 expect(a_get('/projects/1/merge_requests/80/award_emoji/4')).to have_been_made
137 end
138
139 it 'returns information about a merge request award emoji' do
138140 expect(@emoji.id).to eq(4)
139 expect(@emoji.awardable_type).to eq("MergeRequest")
141 expect(@emoji.awardable_type).to eq('MergeRequest')
140142 expect(@emoji.awardable_id).to eq(80)
141143 end
142144 end
143145
144146 context 'when snippet award emoji' do
145147 before do
146 stub_get("/projects/1/snippets/80/award_emoji/4", "snippet_award_emoji")
148 stub_get('/projects/1/snippets/80/award_emoji/4', 'snippet_award_emoji')
147149 @emoji = Gitlab.award_emoji(1, 80, 'snippet', 4)
148150 end
149151
150 it "gets the correct resource" do
151 expect(a_get("/projects/1/snippets/80/award_emoji/4")).to have_been_made
152 end
153
154 it "returns information about a snippet award emoji" do
152 it 'gets the correct resource' do
153 expect(a_get('/projects/1/snippets/80/award_emoji/4')).to have_been_made
154 end
155
156 it 'returns information about a snippet award emoji' do
155157 expect(@emoji.id).to eq(4)
156 expect(@emoji.awardable_type).to eq("Snippet")
158 expect(@emoji.awardable_type).to eq('Snippet')
157159 expect(@emoji.awardable_id).to eq(80)
158160 end
159161 end
162164 describe '.note_award_emoji' do
163165 context 'when issue note award emoji' do
164166 before do
165 stub_get("/projects/1/issues/80/notes/1/award_emoji/4", "note_award_emoji")
167 stub_get('/projects/1/issues/80/notes/1/award_emoji/4', 'note_award_emoji')
166168 @note_emoji = Gitlab.note_award_emoji(1, 80, 'issue', 1, 4)
167169 end
168170
169 it "gets the correct resource" do
170 expect(a_get("/projects/1/issues/80/notes/1/award_emoji/4")).to have_been_made
171 end
172
173 it "returns information about an issue note award emoji" do
171 it 'gets the correct resource' do
172 expect(a_get('/projects/1/issues/80/notes/1/award_emoji/4')).to have_been_made
173 end
174
175 it 'returns information about an issue note award emoji' do
174176 expect(@note_emoji.id).to eq(4)
175 expect(@note_emoji.awardable_type).to eq("Note")
177 expect(@note_emoji.awardable_type).to eq('Note')
176178 expect(@note_emoji.awardable_id).to eq(1)
177179 end
178180 end
179181
180182 context 'when merge request note award emoji' do
181183 before do
182 stub_get("/projects/1/merge_requests/80/notes/1/award_emoji/4", "note_award_emoji")
184 stub_get('/projects/1/merge_requests/80/notes/1/award_emoji/4', 'note_award_emoji')
183185 @note_emoji = Gitlab.note_award_emoji(1, 80, 'merge_request', 1, 4)
184186 end
185187
186 it "gets the correct resource" do
187 expect(a_get("/projects/1/merge_requests/80/notes/1/award_emoji/4")).to have_been_made
188 end
189
190 it "returns information about a merge request note award emoji" do
188 it 'gets the correct resource' do
189 expect(a_get('/projects/1/merge_requests/80/notes/1/award_emoji/4')).to have_been_made
190 end
191
192 it 'returns information about a merge request note award emoji' do
191193 expect(@note_emoji.id).to eq(4)
192 expect(@note_emoji.awardable_type).to eq("Note")
194 expect(@note_emoji.awardable_type).to eq('Note')
193195 expect(@note_emoji.awardable_id).to eq(1)
194196 end
195197 end
196198
197199 context 'when snippet note award emoji' do
198200 before do
199 stub_get("/projects/1/snippets/80/notes/1/award_emoji/4", "note_award_emoji")
201 stub_get('/projects/1/snippets/80/notes/1/award_emoji/4', 'note_award_emoji')
200202 @note_emoji = Gitlab.note_award_emoji(1, 80, 'snippet', 1, 4)
201203 end
202204
203 it "gets the correct resource" do
204 expect(a_get("/projects/1/snippets/80/notes/1/award_emoji/4")).to have_been_made
205 end
206
207 it "returns information about a snippet note award emoji" do
205 it 'gets the correct resource' do
206 expect(a_get('/projects/1/snippets/80/notes/1/award_emoji/4')).to have_been_made
207 end
208
209 it 'returns information about a snippet note award emoji' do
208210 expect(@note_emoji.id).to eq(4)
209 expect(@note_emoji.awardable_type).to eq("Note")
211 expect(@note_emoji.awardable_type).to eq('Note')
210212 expect(@note_emoji.awardable_id).to eq(1)
211213 end
212214 end
215217 describe '.create_award_emoji' do
216218 context 'when issue award emoji' do
217219 before do
218 stub_post("/projects/1/issues/80/award_emoji", "issue_award_emoji")
219 @emoji = Gitlab.create_award_emoji(1, 80, "issue", "blowfish")
220 end
221
222 it "gets the correct resource" do
223 expect(a_post("/projects/1/issues/80/award_emoji").
224 with(body: { name: 'blowfish' })).to have_been_made
225 end
226
227 it "returns correct information about the created issue award emoji" do
220 stub_post('/projects/1/issues/80/award_emoji', 'issue_award_emoji')
221 @emoji = Gitlab.create_award_emoji(1, 80, 'issue', 'blowfish')
222 end
223
224 it 'gets the correct resource' do
225 expect(a_post('/projects/1/issues/80/award_emoji')
226 .with(body: { name: 'blowfish' })).to have_been_made
227 end
228
229 it 'returns correct information about the created issue award emoji' do
228230 expect(@emoji.name).to eq('blowfish')
229231 expect(@emoji.awardable_type).to eq('Issue')
230232 end
232234
233235 context 'when merge request award emoji' do
234236 before do
235 stub_post("/projects/1/merge_requests/80/award_emoji", "merge_request_award_emoji")
236 @emoji = Gitlab.create_award_emoji(1, 80, "merge_request", "blowfish")
237 end
238
239 it "gets the correct resource" do
240 expect(a_post("/projects/1/merge_requests/80/award_emoji").
241 with(body: { name: 'blowfish' })).to have_been_made
242 end
243
244 it "returns correct information about the created merge request award emoji" do
237 stub_post('/projects/1/merge_requests/80/award_emoji', 'merge_request_award_emoji')
238 @emoji = Gitlab.create_award_emoji(1, 80, 'merge_request', 'blowfish')
239 end
240
241 it 'gets the correct resource' do
242 expect(a_post('/projects/1/merge_requests/80/award_emoji')
243 .with(body: { name: 'blowfish' })).to have_been_made
244 end
245
246 it 'returns correct information about the created merge request award emoji' do
245247 expect(@emoji.name).to eq('blowfish')
246248 expect(@emoji.awardable_type).to eq('MergeRequest')
247249 end
249251
250252 context 'when snippet award emoji' do
251253 before do
252 stub_post("/projects/1/snippets/80/award_emoji", "snippet_award_emoji")
253 @emoji = Gitlab.create_award_emoji(1, 80, "snippet", "blowfish")
254 end
255
256 it "gets the correct resource" do
257 expect(a_post("/projects/1/snippets/80/award_emoji").
258 with(body: { name: 'blowfish' })).to have_been_made
259 end
260
261 it "returns correct information about the created snippet award emoji" do
254 stub_post('/projects/1/snippets/80/award_emoji', 'snippet_award_emoji')
255 @emoji = Gitlab.create_award_emoji(1, 80, 'snippet', 'blowfish')
256 end
257
258 it 'gets the correct resource' do
259 expect(a_post('/projects/1/snippets/80/award_emoji')
260 .with(body: { name: 'blowfish' })).to have_been_made
261 end
262
263 it 'returns correct information about the created snippet award emoji' do
262264 expect(@emoji.name).to eq('blowfish')
263265 expect(@emoji.awardable_type).to eq('Snippet')
264266 end
268270 describe '.create_note_award_emoji' do
269271 context 'when issue note award emoji' do
270272 before do
271 stub_post("/projects/1/issues/80/notes/1/award_emoji", "note_award_emoji")
272 @note_emoji = Gitlab.create_note_award_emoji(1, 80, "issue", 1, "mood_bubble_lightning")
273 end
274
275 it "gets the correct resource" do
276 expect(a_post("/projects/1/issues/80/notes/1/award_emoji").
277 with(body: { name: 'mood_bubble_lightning' })).to have_been_made
278 end
279
280 it "returns correct information about the created issue note award emoji" do
273 stub_post('/projects/1/issues/80/notes/1/award_emoji', 'note_award_emoji')
274 @note_emoji = Gitlab.create_note_award_emoji(1, 80, 'issue', 1, 'mood_bubble_lightning')
275 end
276
277 it 'gets the correct resource' do
278 expect(a_post('/projects/1/issues/80/notes/1/award_emoji')
279 .with(body: { name: 'mood_bubble_lightning' })).to have_been_made
280 end
281
282 it 'returns correct information about the created issue note award emoji' do
281283 expect(@note_emoji.name).to eq('mood_bubble_lightning')
282284 expect(@note_emoji.awardable_type).to eq('Note')
283285 end
285287
286288 context 'when merge request note award emoji' do
287289 before do
288 stub_post("/projects/1/merge_requests/80/notes/1/award_emoji", "note_award_emoji")
289 @note_emoji = Gitlab.create_note_award_emoji(1, 80, "merge_request", 1, "mood_bubble_lightning")
290 end
291
292 it "gets the correct resource" do
293 expect(a_post("/projects/1/merge_requests/80/notes/1/award_emoji").
294 with(body: { name: 'mood_bubble_lightning' })).to have_been_made
295 end
296
297 it "returns correct information about the created merge request note award emoji" do
290 stub_post('/projects/1/merge_requests/80/notes/1/award_emoji', 'note_award_emoji')
291 @note_emoji = Gitlab.create_note_award_emoji(1, 80, 'merge_request', 1, 'mood_bubble_lightning')
292 end
293
294 it 'gets the correct resource' do
295 expect(a_post('/projects/1/merge_requests/80/notes/1/award_emoji')
296 .with(body: { name: 'mood_bubble_lightning' })).to have_been_made
297 end
298
299 it 'returns correct information about the created merge request note award emoji' do
298300 expect(@note_emoji.name).to eq('mood_bubble_lightning')
299301 expect(@note_emoji.awardable_type).to eq('Note')
300302 end
302304
303305 context 'when snippet note award emoji' do
304306 before do
305 stub_post("/projects/1/snippets/80/notes/1/award_emoji", "note_award_emoji")
306 @note_emoji = Gitlab.create_note_award_emoji(1, 80, "snippet", 1, "mood_bubble_lightning")
307 end
308
309 it "gets the correct resource" do
310 expect(a_post("/projects/1/snippets/80/notes/1/award_emoji").
311 with(body: { name: 'mood_bubble_lightning' })).to have_been_made
312 end
313
314 it "returns correct information about the created snippet note award emoji" do
307 stub_post('/projects/1/snippets/80/notes/1/award_emoji', 'note_award_emoji')
308 @note_emoji = Gitlab.create_note_award_emoji(1, 80, 'snippet', 1, 'mood_bubble_lightning')
309 end
310
311 it 'gets the correct resource' do
312 expect(a_post('/projects/1/snippets/80/notes/1/award_emoji')
313 .with(body: { name: 'mood_bubble_lightning' })).to have_been_made
314 end
315
316 it 'returns correct information about the created snippet note award emoji' do
315317 expect(@note_emoji.name).to eq('mood_bubble_lightning')
316318 expect(@note_emoji.awardable_type).to eq('Note')
317319 end
321323 describe '.delete_award_emoji' do
322324 context 'when issue award emoji' do
323325 before do
324 stub_delete("/projects/1/issues/80/award_emoji/4", "issue_award_emoji")
325 @emoji = Gitlab.delete_award_emoji(1, 80, "issue", 4)
326 end
327
328 it "gets the correct resource" do
329 expect(a_delete("/projects/1/issues/80/award_emoji/4")).to have_been_made
326 stub_delete('/projects/1/issues/80/award_emoji/4', 'issue_award_emoji')
327 @emoji = Gitlab.delete_award_emoji(1, 80, 'issue', 4)
328 end
329
330 it 'gets the correct resource' do
331 expect(a_delete('/projects/1/issues/80/award_emoji/4')).to have_been_made
330332 end
331333 end
332334
333335 context 'when merge request award emoji' do
334336 before do
335 stub_delete("/projects/1/merge_requests/80/award_emoji/4", "merge_request_award_emoji")
336 @emoji = Gitlab.delete_award_emoji(1, 80, "merge_request", 4)
337 end
338
339 it "gets the correct resource" do
340 expect(a_delete("/projects/1/merge_requests/80/award_emoji/4")).to have_been_made
337 stub_delete('/projects/1/merge_requests/80/award_emoji/4', 'merge_request_award_emoji')
338 @emoji = Gitlab.delete_award_emoji(1, 80, 'merge_request', 4)
339 end
340
341 it 'gets the correct resource' do
342 expect(a_delete('/projects/1/merge_requests/80/award_emoji/4')).to have_been_made
341343 end
342344 end
343345
344346 context 'when snippet award emoji' do
345347 before do
346 stub_delete("/projects/1/snippets/80/award_emoji/4", "snippet_award_emoji")
347 @emoji = Gitlab.delete_award_emoji(1, 80, "snippet", 4)
348 end
349
350 it "gets the correct resource" do
351 expect(a_delete("/projects/1/snippets/80/award_emoji/4")).to have_been_made
348 stub_delete('/projects/1/snippets/80/award_emoji/4', 'snippet_award_emoji')
349 @emoji = Gitlab.delete_award_emoji(1, 80, 'snippet', 4)
350 end
351
352 it 'gets the correct resource' do
353 expect(a_delete('/projects/1/snippets/80/award_emoji/4')).to have_been_made
352354 end
353355 end
354356 end
356358 describe '.delete_note_award_emoji' do
357359 context 'when issue note award emoji' do
358360 before do
359 stub_delete("/projects/1/issues/80/notes/1/award_emoji/4", "note_award_emoji")
360 @note_emoji = Gitlab.delete_note_award_emoji(1, 80, "issue", 1, 4)
361 end
362
363 it "gets the correct resource" do
364 expect(a_delete("/projects/1/issues/80/notes/1/award_emoji/4")).to have_been_made
361 stub_delete('/projects/1/issues/80/notes/1/award_emoji/4', 'note_award_emoji')
362 @note_emoji = Gitlab.delete_note_award_emoji(1, 80, 'issue', 1, 4)
363 end
364
365 it 'gets the correct resource' do
366 expect(a_delete('/projects/1/issues/80/notes/1/award_emoji/4')).to have_been_made
365367 end
366368 end
367369
368370 context 'when merge request note award emoji' do
369371 before do
370 stub_delete("/projects/1/merge_requests/80/notes/1/award_emoji/4", "note_award_emoji")
371 @note_emoji = Gitlab.delete_note_award_emoji(1, 80, "merge_request", 1, 4)
372 end
373
374 it "gets the correct resource" do
375 expect(a_delete("/projects/1/merge_requests/80/notes/1/award_emoji/4")).to have_been_made
372 stub_delete('/projects/1/merge_requests/80/notes/1/award_emoji/4', 'note_award_emoji')
373 @note_emoji = Gitlab.delete_note_award_emoji(1, 80, 'merge_request', 1, 4)
374 end
375
376 it 'gets the correct resource' do
377 expect(a_delete('/projects/1/merge_requests/80/notes/1/award_emoji/4')).to have_been_made
376378 end
377379 end
378380
379381 context 'when snippet note award emoji' do
380382 before do
381 stub_delete("/projects/1/snippets/80/notes/1/award_emoji/4", "note_award_emoji")
382 @note_emoji = Gitlab.delete_note_award_emoji(1, 80, "snippet", 1, 4)
383 end
384
385 it "gets the correct resource" do
386 expect(a_delete("/projects/1/snippets/80/notes/1/award_emoji/4")).to have_been_made
383 stub_delete('/projects/1/snippets/80/notes/1/award_emoji/4', 'note_award_emoji')
384 @note_emoji = Gitlab.delete_note_award_emoji(1, 80, 'snippet', 1, 4)
385 end
386
387 it 'gets the correct resource' do
388 expect(a_delete('/projects/1/snippets/80/notes/1/award_emoji/4')).to have_been_made
387389 end
388390 end
389391 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".boards" do
5 describe '.boards' do
46 before do
5 stub_get("/projects/3/boards", "boards")
7 stub_get('/projects/3/boards', 'boards')
68 @boards = Gitlab.boards(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/boards")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/boards')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of project's boards" do
1517 end
1618 end
1719
18 describe ".board_lists" do
20 describe '.board_lists' do
1921 before do
20 stub_get("/projects/3/boards/1/lists", "board_lists")
22 stub_get('/projects/3/boards/1/lists', 'board_lists')
2123 @board_lists = Gitlab.board_lists(3, 1)
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_get("/projects/3/boards/1/lists")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_get('/projects/3/boards/1/lists')).to have_been_made
2628 end
2729
2830 it "returns a paginated response of board's lists" do
3133 end
3234 end
3335
34 describe ".board_list" do
36 describe '.board_list' do
3537 before do
36 stub_get("/projects/3/boards/1/lists/1", "board_list")
38 stub_get('/projects/3/boards/1/lists/1', 'board_list')
3739 @board_list = Gitlab.board_list(3, 1, 1)
3840 end
3941
40 it "gets the correct resource" do
41 expect(a_get("/projects/3/boards/1/lists/1")).to have_been_made
42 it 'gets the correct resource' do
43 expect(a_get('/projects/3/boards/1/lists/1')).to have_been_made
4244 end
4345
44 it "returns information about the list" do
46 it 'returns information about the list' do
4547 expect(@board_list.id).to eq(1)
4648 end
4749 end
4850
49 describe ".create_board_list" do
51 describe '.create_board_list' do
5052 before do
51 stub_post("/projects/3/boards/1/lists", "board_list")
53 stub_post('/projects/3/boards/1/lists', 'board_list')
5254 @board_list = Gitlab.create_board_list(3, 1, 4)
5355 end
5456
55 it "gets the correct resource" do
56 expect(a_post("/projects/3/boards/1/lists")).to have_been_made
57 it 'gets the correct resource' do
58 expect(a_post('/projects/3/boards/1/lists')).to have_been_made
5759 end
5860
59 it "returns information about a created board" do
61 it 'returns information about a created board' do
6062 expect(@board_list.position).to eq(1)
6163 end
6264 end
6365
64 describe ".edit_board_list" do
66 describe '.edit_board_list' do
6567 before do
66 stub_put("/projects/3/boards/1/lists/1", "board_list")
68 stub_put('/projects/3/boards/1/lists/1', 'board_list')
6769 @board_list = Gitlab.edit_board_list(3, 1, 1, 3)
6870 end
6971
70 it "gets the correct resource" do
71 expect(a_put("/projects/3/boards/1/lists/1")).to have_been_made
72 it 'gets the correct resource' do
73 expect(a_put('/projects/3/boards/1/lists/1')).to have_been_made
7274 end
7375
74 it "returns information about an edited board" do
76 it 'returns information about an edited board' do
7577 expect(@board_list.id).to eq(1)
7678 end
7779 end
7880
79 describe ".delete_board_list" do
81 describe '.delete_board_list' do
8082 before do
81 stub_delete("/projects/3/boards/1/lists/1", "board_list")
83 stub_delete('/projects/3/boards/1/lists/1', 'board_list')
8284 @board_list = Gitlab.delete_board_list(3, 1, 1)
8385 end
8486
85 it "gets the correct resource" do
86 expect(a_delete("/projects/3/boards/1/lists/1")).to have_been_made
87 it 'gets the correct resource' do
88 expect(a_delete('/projects/3/boards/1/lists/1')).to have_been_made
8789 end
8890
89 it "returns information about the deleted board list" do
91 it 'returns information about the deleted board list' do
9092 expect(@board_list.id).to eq(1)
9193 end
9294 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
46 it { is_expected.to respond_to :repo_branch }
57 it { is_expected.to respond_to :repo_protect_branch }
68 it { is_expected.to respond_to :repo_unprotect_branch }
9 it { is_expected.to respond_to :repo_create_branch }
10 it { is_expected.to respond_to :repo_delete_branch }
11 it { is_expected.to respond_to :repo_delete_merged_branches }
12 it { is_expected.to respond_to :repo_protected_branches }
13 it { is_expected.to respond_to :repo_protected_branch }
714
8 describe ".branches" do
15 describe '.branches' do
916 before do
10 stub_get("/projects/3/repository/branches", "branches")
17 stub_get('/projects/3/repository/branches', 'branches')
1118 @branches = Gitlab.branches(3)
1219 end
1320
14 it "gets the correct resource" do
15 expect(a_get("/projects/3/repository/branches")).to have_been_made
21 it 'gets the correct resource' do
22 expect(a_get('/projects/3/repository/branches')).to have_been_made
1623 end
1724
18 it "returns a paginated response of repository branches" do
25 it 'returns a paginated response of repository branches' do
1926 expect(@branches).to be_a Gitlab::PaginatedResponse
20 expect(@branches.first.name).to eq("api")
27 expect(@branches.first.name).to eq('api')
2128 end
2229 end
2330
24 describe ".branch" do
31 describe '.branch' do
2532 before do
26 stub_get("/projects/3/repository/branches/api", "branch")
27 @branch = Gitlab.branch(3, "api")
33 stub_get('/projects/3/repository/branches/api', 'branch')
34 @branch = Gitlab.branch(3, 'api')
2835 end
2936
30 it "gets the correct resource" do
31 expect(a_get("/projects/3/repository/branches/api")).to have_been_made
37 it 'gets the correct resource' do
38 expect(a_get('/projects/3/repository/branches/api')).to have_been_made
3239 end
3340
34 it "returns information about a repository branch" do
35 expect(@branch.name).to eq("api")
41 it 'returns information about a repository branch' do
42 expect(@branch.name).to eq('api')
3643 end
3744 end
3845
39 describe ".protect_branch" do
46 describe '.protect_branch' do
4047 before do
41 stub_post("/projects/3/protected_branches", "branch")
48 stub_post('/projects/3/protected_branches', 'branch')
4249 end
4350
44 context "without options" do
51 context 'without options' do
4552 before do
46 @branch = Gitlab.protect_branch(3, "api")
53 @branch = Gitlab.protect_branch(3, 'api')
4754 end
4855
49 it "updates the correct resource" do
50 expect(a_post("/projects/3/protected_branches")).to have_been_made
56 it 'updates the correct resource' do
57 expect(a_post('/projects/3/protected_branches')).to have_been_made
5158 end
5259
53 it "returns information about a protected repository branch" do
54 expect(@branch.name).to eq("api")
60 it 'returns information about a protected repository branch' do
61 expect(@branch.name).to eq('api')
5562 end
5663 end
5764
58 context "with options" do
65 context 'with options' do
5966 before do
60 @branch = Gitlab.protect_branch(3, "api", developers_can_push: true)
67 @branch = Gitlab.protect_branch(3, 'api', developers_can_push: true)
6168 end
6269
63 it "updates the correct resource with the correct options" do
70 it 'updates the correct resource with the correct options' do
6471 expect(
65 a_post("/projects/3/protected_branches").with(body: { name: "api", developers_can_push: 'true' })
72 a_post('/projects/3/protected_branches').with(body: { name: 'api', developers_can_push: 'true' })
6673 ).to have_been_made
6774 end
6875 end
6976 end
7077
71 describe ".unprotect_branch" do
78 describe '.unprotect_branch' do
7279 before do
73 stub_delete("/projects/3/protected_branches/api","branch")
74 @branch = Gitlab.unprotect_branch(3, "api")
80 stub_delete('/projects/3/protected_branches/api', 'branch')
81 @branch = Gitlab.unprotect_branch(3, 'api')
7582 end
7683
77 it "gets the correct resource" do
78 expect(a_delete("/projects/3/protected_branches/api")).to have_been_made
84 it 'gets the correct resource' do
85 expect(a_delete('/projects/3/protected_branches/api')).to have_been_made
7986 end
8087
81 it "returns information about an unprotected repository branch" do
82 expect(@branch.name).to eq("api")
88 it 'returns information about an unprotected repository branch' do
89 expect(@branch.name).to eq('api')
8390 end
8491 end
8592
86 describe ".create_branch" do
93 describe '.create_branch' do
8794 before do
88 stub_post("/projects/3/repository/branches", "branch").with(query: { branch: 'api', ref: "master"})
89 @branch = Gitlab.create_branch(3, "api", "master")
95 stub_post('/projects/3/repository/branches', 'branch').with(query: { branch: 'api', ref: 'master' })
96 @branch = Gitlab.create_branch(3, 'api', 'master')
9097 end
9198
92 it "gets the correct resource" do
99 it 'gets the correct resource' do
93100 expect(
94 a_post("/projects/3/repository/branches").with(query: { branch: 'api', ref: "master"})
101 a_post('/projects/3/repository/branches').with(query: { branch: 'api', ref: 'master' })
95102 ).to have_been_made
96103 end
97104
98 it "returns information about a new repository branch" do
99 expect(@branch.name).to eq("api")
105 it 'returns information about a new repository branch' do
106 expect(@branch.name).to eq('api')
100107 end
101108 end
102109
103 describe ".delete_branch" do
110 describe '.delete_branch' do
104111 before do
105 stub_delete("/projects/3/repository/branches/api", "branch_delete")
106 @branch = Gitlab.delete_branch(3, "api")
112 stub_delete('/projects/3/repository/branches/api', 'branch_delete')
113 @branch = Gitlab.delete_branch(3, 'api')
107114 end
108115
109 it "gets the correct resource" do
110 expect(a_delete("/projects/3/repository/branches/api")).to have_been_made
116 it 'gets the correct resource' do
117 expect(a_delete('/projects/3/repository/branches/api')).to have_been_made
111118 end
112119
113 it "returns information about the deleted repository branch" do
114 expect(@branch.branch_name).to eq("api")
120 it 'returns information about the deleted repository branch' do
121 expect(@branch.branch_name).to eq('api')
122 end
123 end
124
125 describe '.delete_merged_branches' do
126 before do
127 stub_delete('/projects/3/repository/merged_branches', 'empty')
128 @branch = Gitlab.delete_merged_branches(3)
129 end
130
131 it 'gets the correct resource' do
132 expect(a_delete('/projects/3/repository/merged_branches')).to have_been_made
133 end
134 end
135
136 describe '.protected_branches' do
137 before do
138 stub_get('/projects/3/protected_branches', 'protected_branches')
139 @branches = Gitlab.protected_branches(3)
140 end
141
142 it 'gets the correct resource' do
143 expect(a_get('/projects/3/protected_branches')).to have_been_made
144 end
145
146 it 'returns information about the protected_branches' do
147 expect(@branches).to be_a Gitlab::PaginatedResponse
148 expect(@branches.first.merge_access_levels).to be_a Array
149 expect(@branches.first.push_access_levels).to be_a Array
150 end
151 end
152
153 describe '.protected_branch' do
154 before do
155 stub_get('/projects/3/protected_branches/master', 'protected_branch')
156 @branch = Gitlab.protected_branch(3, 'master')
157 end
158
159 it 'gets the correct resource' do
160 expect(a_get('/projects/3/protected_branches/master')).to have_been_made
161 end
162
163 it 'returns correct information about the protected_branch' do
164 expect(@branch.name).to eq 'master'
165 expect(@branch.merge_access_levels).to be_a Array
166 expect(@branch.push_access_levels).to be_a Array
115167 end
116168 end
117169 end
0 # frozen_string_literal: true
1
2 require 'spec_helper'
3
4 describe Gitlab::Client do
5 describe '.broadcast_messages' do
6 before do
7 stub_get('/broadcast_messages', 'broadcast_messages')
8 @broadcast_messages = Gitlab.broadcast_messages
9 end
10
11 it 'gets the correct resource' do
12 expect(a_get('/broadcast_messages')).to have_been_made
13 end
14
15 it 'returns a paginated response of broadcast messages' do
16 expect(@broadcast_messages).to be_a Gitlab::PaginatedResponse
17 end
18 end
19
20 describe '.broadcast_message' do
21 before do
22 stub_get('/broadcast_messages/1', 'broadcast_message')
23 @broadcast_message = Gitlab.broadcast_message(1)
24 end
25
26 it 'gets the correct resource' do
27 expect(a_get('/broadcast_messages/1')).to have_been_made
28 end
29
30 it 'returns correct information about the broadcast message' do
31 expect(@broadcast_message.id).to eq 1
32 end
33 end
34
35 describe '.create_broadcast_message' do
36 before do
37 stub_post('/broadcast_messages', 'broadcast_message')
38 @broadcast_message = Gitlab.create_broadcast_message('Deploy in progress', color: '#cecece')
39 end
40
41 it 'gets the correct resource' do
42 expect(a_post('/broadcast_messages')
43 .with(body: { message: 'Deploy in progress', color: '#cecece' })).to have_been_made
44 end
45
46 it 'returns correct information about the broadcast message created' do
47 expect(@broadcast_message.message).to eq 'Deploy in progress'
48 expect(@broadcast_message.color).to eq '#cecece'
49 end
50 end
51
52 describe '.edit_broadcast_message' do
53 before do
54 stub_put('/broadcast_messages/1', 'broadcast_message')
55 @broadcast_message = Gitlab.edit_broadcast_message(1, font: '#FFFFFF')
56 end
57
58 it 'gets the correct resource' do
59 expect(a_put('/broadcast_messages/1')
60 .with(body: { font: '#FFFFFF' })).to have_been_made
61 end
62
63 it 'returns correct information about the edited broadcast message' do
64 expect(@broadcast_message.font).to eq '#FFFFFF'
65 end
66 end
67
68 describe '.delete_broadcast_message' do
69 before do
70 stub_delete('/broadcast_messages/1', 'empty')
71 @broadcast_message = Gitlab.delete_broadcast_message(1)
72 end
73
74 it 'gets the correct resource' do
75 expect(a_delete('/broadcast_messages/1')).to have_been_made
76 end
77 end
78 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".variables" do
5 describe '.variables' do
46 before do
5 stub_get("/projects/3/variables", "variables")
7 stub_get('/projects/3/variables', 'variables')
68 @variables = Gitlab.variables(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/variables")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/variables')).to have_been_made
1113 end
1214
1315 it "returns an array of project's variables" do
1416 expect(@variables).to be_a Gitlab::PaginatedResponse
15 expect(@variables.first.key).to eq("TEST_VARIABLE_1")
16 expect(@variables.first.value).to eq("TEST_1")
17 expect(@variables.first.key).to eq('TEST_VARIABLE_1')
18 expect(@variables.first.value).to eq('TEST_1')
1719 end
1820 end
1921
20 describe ".variable" do
22 describe '.variable' do
2123 before do
22 stub_get("/projects/3/variables/VARIABLE", "variable")
23 @variable = Gitlab.variable(3, "VARIABLE")
24 stub_get('/projects/3/variables/VARIABLE', 'variable')
25 @variable = Gitlab.variable(3, 'VARIABLE')
2426 end
2527
26 it "gets the correct resource" do
27 expect(a_get("/projects/3/variables/VARIABLE")).to have_been_made
28 it 'gets the correct resource' do
29 expect(a_get('/projects/3/variables/VARIABLE')).to have_been_made
2830 end
2931
30 it "returns information about a variable" do
31 expect(@variable.key).to eq("VARIABLE")
32 expect(@variable.value).to eq("the value")
32 it 'returns information about a variable' do
33 expect(@variable.key).to eq('VARIABLE')
34 expect(@variable.value).to eq('the value')
3335 end
3436 end
3537
36 describe ".create_variable" do
38 describe '.create_variable' do
3739 before do
38 stub_post("/projects/3/variables", "variable")
39 @variable = Gitlab.create_variable(3, "NEW_VARIABLE", "new value")
40 stub_post('/projects/3/variables', 'variable')
41 @variable = Gitlab.create_variable(3, 'NEW_VARIABLE', 'new value')
4042 end
4143
42 it "gets the correct resource" do
43 body = { key: "NEW_VARIABLE", value: "new value" }
44 expect(a_post("/projects/3/variables").with(body: body)).to have_been_made
44 it 'gets the correct resource' do
45 body = { key: 'NEW_VARIABLE', value: 'new value' }
46 expect(a_post('/projects/3/variables').with(body: body)).to have_been_made
4547 end
4648
47 it "returns information about a new variable" do
48 expect(@variable.key).to eq("VARIABLE")
49 expect(@variable.value).to eq("the value")
49 it 'returns information about a new variable' do
50 expect(@variable.key).to eq('VARIABLE')
51 expect(@variable.value).to eq('the value')
5052 end
5153 end
5254
53 describe ".update_variable" do
55 describe '.update_variable' do
5456 before do
55 stub_put("/projects/3/variables/UPD_VARIABLE", "variable")
56 @variable = Gitlab.update_variable(3, "UPD_VARIABLE", "updated value")
57 stub_put('/projects/3/variables/UPD_VARIABLE', 'variable')
58 @variable = Gitlab.update_variable(3, 'UPD_VARIABLE', 'updated value')
5759 end
5860
59 it "puts the correct resource" do
60 body = { value: "updated value" }
61 expect(a_put("/projects/3/variables/UPD_VARIABLE").with(body: body)).to have_been_made
61 it 'puts the correct resource' do
62 body = { value: 'updated value' }
63 expect(a_put('/projects/3/variables/UPD_VARIABLE').with(body: body)).to have_been_made
6264 end
6365
64 it "returns information about an updated variable" do
65 expect(@variable.key).to eq("VARIABLE")
66 expect(@variable.value).to eq("the value")
66 it 'returns information about an updated variable' do
67 expect(@variable.key).to eq('VARIABLE')
68 expect(@variable.value).to eq('the value')
6769 end
6870 end
6971
70 describe ".remove_variable" do
72 describe '.remove_variable' do
7173 before do
72 stub_delete("/projects/3/variables/DEL_VARIABLE", "variable")
73 @variable = Gitlab.remove_variable(3, "DEL_VARIABLE")
74 stub_delete('/projects/3/variables/DEL_VARIABLE', 'variable')
75 @variable = Gitlab.remove_variable(3, 'DEL_VARIABLE')
7476 end
7577
76 it "gets the correct resource" do
77 expect(a_delete("/projects/3/variables/DEL_VARIABLE")).to have_been_made
78 it 'gets the correct resource' do
79 expect(a_delete('/projects/3/variables/DEL_VARIABLE')).to have_been_made
7880 end
7981
80 it "returns information about a deleted variable" do
81 expect(@variable.key).to eq("VARIABLE")
82 expect(@variable.value).to eq("the value")
82 it 'returns information about a deleted variable' do
83 expect(@variable.key).to eq('VARIABLE')
84 expect(@variable.value).to eq('the value')
8385 end
8486 end
8587
86 describe ".group_variables" do
88 describe '.group_variables' do
8789 before do
88 stub_get("/groups/3/variables", "variables")
90 stub_get('/groups/3/variables', 'variables')
8991 @variables = Gitlab.group_variables(3)
9092 end
9193
92 it "gets the correct resource" do
93 expect(a_get("/groups/3/variables")).to have_been_made
94 it 'gets the correct resource' do
95 expect(a_get('/groups/3/variables')).to have_been_made
9496 end
9597
9698 it "returns an array of group's variables" do
9799 expect(@variables).to be_a Gitlab::PaginatedResponse
98 expect(@variables.first.key).to eq("TEST_VARIABLE_1")
99 expect(@variables.first.value).to eq("TEST_1")
100 expect(@variables.first.key).to eq('TEST_VARIABLE_1')
101 expect(@variables.first.value).to eq('TEST_1')
100102 end
101103 end
102104
103 describe ".group_variable" do
105 describe '.group_variable' do
104106 before do
105 stub_get("/groups/3/variables/VARIABLE", "variable")
106 @variable = Gitlab.group_variable(3, "VARIABLE")
107 stub_get('/groups/3/variables/VARIABLE', 'variable')
108 @variable = Gitlab.group_variable(3, 'VARIABLE')
107109 end
108110
109 it "gets the correct resource" do
110 expect(a_get("/groups/3/variables/VARIABLE")).to have_been_made
111 it 'gets the correct resource' do
112 expect(a_get('/groups/3/variables/VARIABLE')).to have_been_made
111113 end
112114
113 it "returns information about a variable" do
114 expect(@variable.key).to eq("VARIABLE")
115 expect(@variable.value).to eq("the value")
115 it 'returns information about a variable' do
116 expect(@variable.key).to eq('VARIABLE')
117 expect(@variable.value).to eq('the value')
116118 end
117119 end
118120
119 describe ".create_group_variable" do
121 describe '.create_group_variable' do
120122 before do
121 stub_post("/groups/3/variables", "variable")
122 @variable = Gitlab.create_group_variable(3, "NEW_VARIABLE", "new value")
123 stub_post('/groups/3/variables', 'variable')
124 @variable = Gitlab.create_group_variable(3, 'NEW_VARIABLE', 'new value')
123125 end
124126
125 it "gets the correct resource" do
126 body = { key: "NEW_VARIABLE", value: "new value" }
127 expect(a_post("/groups/3/variables").with(body: body)).to have_been_made
127 it 'gets the correct resource' do
128 body = { key: 'NEW_VARIABLE', value: 'new value' }
129 expect(a_post('/groups/3/variables').with(body: body)).to have_been_made
128130 end
129131
130 it "returns information about a new variable" do
131 expect(@variable.key).to eq("VARIABLE")
132 expect(@variable.value).to eq("the value")
132 it 'returns information about a new variable' do
133 expect(@variable.key).to eq('VARIABLE')
134 expect(@variable.value).to eq('the value')
133135 end
134136 end
135137
136 describe ".update_group_variable" do
138 describe '.update_group_variable' do
137139 before do
138 stub_put("/groups/3/variables/UPD_VARIABLE", "variable")
139 @variable = Gitlab.update_group_variable(3, "UPD_VARIABLE", "updated value")
140 stub_put('/groups/3/variables/UPD_VARIABLE', 'variable')
141 @variable = Gitlab.update_group_variable(3, 'UPD_VARIABLE', 'updated value')
140142 end
141143
142 it "puts the correct resource" do
143 body = { value: "updated value" }
144 expect(a_put("/groups/3/variables/UPD_VARIABLE").with(body: body)).to have_been_made
144 it 'puts the correct resource' do
145 body = { value: 'updated value' }
146 expect(a_put('/groups/3/variables/UPD_VARIABLE').with(body: body)).to have_been_made
145147 end
146148
147 it "returns information about an updated variable" do
148 expect(@variable.key).to eq("VARIABLE")
149 expect(@variable.value).to eq("the value")
149 it 'returns information about an updated variable' do
150 expect(@variable.key).to eq('VARIABLE')
151 expect(@variable.value).to eq('the value')
150152 end
151153 end
152154
153 describe ".remove_group_variable" do
155 describe '.remove_group_variable' do
154156 before do
155 stub_delete("/groups/3/variables/DEL_VARIABLE", "variable")
156 @variable = Gitlab.remove_group_variable(3, "DEL_VARIABLE")
157 stub_delete('/groups/3/variables/DEL_VARIABLE', 'variable')
158 @variable = Gitlab.remove_group_variable(3, 'DEL_VARIABLE')
157159 end
158160
159 it "gets the correct resource" do
160 expect(a_delete("/groups/3/variables/DEL_VARIABLE")).to have_been_made
161 it 'gets the correct resource' do
162 expect(a_delete('/groups/3/variables/DEL_VARIABLE')).to have_been_made
161163 end
162164
163 it "returns information about a deleted variable" do
164 expect(@variable.key).to eq("VARIABLE")
165 expect(@variable.value).to eq("the value")
165 it 'returns information about a deleted variable' do
166 expect(@variable.key).to eq('VARIABLE')
167 expect(@variable.value).to eq('the value')
166168 end
167169 end
168170 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".builds" do
5 describe '.builds' do
46 before do
5 stub_get("/projects/3/builds", "builds")
7 stub_get('/projects/3/builds', 'builds')
68 @builds = Gitlab.builds(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/builds")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/builds')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of project's builds" do
1517 end
1618 end
1719
18 describe ".build" do
20 describe '.build' do
1921 before do
20 stub_get("/projects/3/builds/8", "build")
22 stub_get('/projects/3/builds/8', 'build')
2123 @build = Gitlab.build(3, 8)
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_get("/projects/3/builds/8")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_get('/projects/3/builds/8')).to have_been_made
2628 end
2729
28 it "returns a single build" do
30 it 'returns a single build' do
2931 expect(@build).to be_a Gitlab::ObjectifiedHash
3032 end
3133
32 it "returns information about a build" do
34 it 'returns information about a build' do
3335 expect(@build.id).to eq(8)
34 expect(@build.user.name).to eq("John Smith")
36 expect(@build.user.name).to eq('John Smith')
3537 end
3638 end
3739
38 describe ".build_artifacts" do
39 context "when successful request" do
40 describe '.build_artifacts' do
41 context 'when successful request' do
4042 before do
4143 fixture = load_fixture('build_artifacts')
4244 fixture.set_encoding(Encoding::ASCII_8BIT)
43 stub_request(:get, "#{Gitlab.endpoint}/projects/3/builds/8/artifacts").
44 with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
45 to_return(body: fixture.read, headers: { 'Content-Disposition' => "attachment; filename=artifacts.zip" })
45 stub_request(:get, "#{Gitlab.endpoint}/projects/3/builds/8/artifacts")
46 .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
47 .to_return(body: fixture.read, headers: { 'Content-Disposition' => 'attachment; filename=artifacts.zip' })
4648 @build_artifacts = Gitlab.build_artifacts(3, 8)
4749 end
4850
49 it "gets the correct resource" do
50 expect(a_get("/projects/3/builds/8/artifacts")).to have_been_made
51 it 'gets the correct resource' do
52 expect(a_get('/projects/3/builds/8/artifacts')).to have_been_made
5153 end
5254
53 it "returns a FileResponse" do
55 it 'returns a FileResponse' do
5456 expect(@build_artifacts).to be_a Gitlab::FileResponse
5557 end
5658
57 it "returns a file with filename" do
58 expect(@build_artifacts.filename).to eq "artifacts.zip"
59 it 'returns a file with filename' do
60 expect(@build_artifacts.filename).to eq 'artifacts.zip'
5961 end
6062 end
6163
62 context "when bad request" do
63 it "throws an exception" do
64 stub_get("/projects/3/builds/8/artifacts", "error_project_not_found", 404)
65 expect{ Gitlab.build_artifacts(3, 8) }.to raise_error(Gitlab::Error::NotFound, "Server responded with code 404, message: 404 Project Not Found. Request URI: #{Gitlab.endpoint}/projects/3/builds/8/artifacts")
64 context 'when bad request' do
65 it 'throws an exception' do
66 stub_get('/projects/3/builds/8/artifacts', 'error_project_not_found', 404)
67 expect { Gitlab.build_artifacts(3, 8) }.to raise_error(Gitlab::Error::NotFound, "Server responded with code 404, message: 404 Project Not Found. Request URI: #{Gitlab.endpoint}/projects/3/builds/8/artifacts")
6668 end
6769 end
6870 end
6971
70 describe ".builds_commits" do
72 describe '.builds_commits' do
7173 before do
72 stub_get("/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds", "builds_commits")
73 @builds_commits = Gitlab.commit_builds(3, "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd")
74 stub_get('/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds', 'builds_commits')
75 @builds_commits = Gitlab.commit_builds(3, '0ff3ae198f8601a285adcf5c0fff204ee6fba5fd')
7476 end
7577
76 it "gets the correct resource" do
77 expect(a_get("/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds")).to have_been_made
78 it 'gets the correct resource' do
79 expect(a_get('/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds')).to have_been_made
7880 end
7981
80 it "returns a paginated response of commit builds" do
82 it 'returns a paginated response of commit builds' do
8183 expect(@builds_commits).to be_a Gitlab::PaginatedResponse
8284 end
8385
84 it "returns information about the builds" do
86 it 'returns information about the builds' do
8587 expect(@builds_commits.count).to eq(2)
8688 end
8789 end
8890
89
90
91 describe ".build_cancel" do
91 describe '.build_cancel' do
9292 before do
93 stub_post("/projects/3/builds/8/cancel", "build_cancel")
93 stub_post('/projects/3/builds/8/cancel', 'build_cancel')
9494 @build_cancel = Gitlab.build_cancel(3, 8)
9595 end
9696
97 it "gets the correct resource" do
98 expect(a_post("/projects/3/builds/8/cancel")).to have_been_made
97 it 'gets the correct resource' do
98 expect(a_post('/projects/3/builds/8/cancel')).to have_been_made
9999 end
100100
101 it "returns a single build" do
101 it 'returns a single build' do
102102 expect(@build_cancel).to be_a Gitlab::ObjectifiedHash
103103 end
104104
105 it "returns information about a build" do
106 expect(@build_cancel.commit.author_name).to eq("John Smith")
105 it 'returns information about a build' do
106 expect(@build_cancel.commit.author_name).to eq('John Smith')
107107 end
108108 end
109109
110 describe ".build_retry" do
110 describe '.build_retry' do
111111 before do
112 stub_post("/projects/3/builds/69/retry", "build_retry")
112 stub_post('/projects/3/builds/69/retry', 'build_retry')
113113 @build_retry = Gitlab.build_retry(3, 69)
114114 end
115115
116 it "gets the correct resource" do
117 expect(a_post("/projects/3/builds/69/retry")).to have_been_made
116 it 'gets the correct resource' do
117 expect(a_post('/projects/3/builds/69/retry')).to have_been_made
118118 end
119119
120 it "returns a single build" do
120 it 'returns a single build' do
121121 expect(@build_retry).to be_a Gitlab::ObjectifiedHash
122122 end
123123
124 it "returns information about a build" do
125 expect(@build_retry.commit.author_name).to eq("John Smith")
124 it 'returns information about a build' do
125 expect(@build_retry.commit.author_name).to eq('John Smith')
126126 end
127127 end
128128
129 describe ".build_erase" do
129 describe '.build_erase' do
130130 before do
131 stub_post("/projects/3/builds/69/erase", "build_erase")
131 stub_post('/projects/3/builds/69/erase', 'build_erase')
132132 @build_retry = Gitlab.build_erase(3, 69)
133133 end
134134
135 it "gets the correct resource" do
136 expect(a_post("/projects/3/builds/69/erase")).to have_been_made
135 it 'gets the correct resource' do
136 expect(a_post('/projects/3/builds/69/erase')).to have_been_made
137137 end
138138
139 it "returns a single build" do
139 it 'returns a single build' do
140140 expect(@build_retry).to be_a Gitlab::ObjectifiedHash
141141 end
142142
143 it "returns information about a build" do
144 expect(@build_retry.commit.author_name).to eq("John Smith")
143 it 'returns information about a build' do
144 expect(@build_retry.commit.author_name).to eq('John Smith')
145145 end
146146 end
147147 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
911 it { is_expected.to respond_to :repo_update_commit_status }
1012 it { is_expected.to respond_to :repo_commit_merge_requests }
1113
12 describe ".commits" do
13 before do
14 stub_get("/projects/3/repository/commits", "project_commits").
15 with(query: { ref_name: "api" })
16 @commits = Gitlab.commits(3, ref_name: "api")
17 end
18
19 it "gets the correct resource" do
20 expect(a_get("/projects/3/repository/commits").
21 with(query: { ref_name: "api" })).to have_been_made
22 end
23
24 it "returns a paginated response of repository commits" do
14 describe '.commits' do
15 before do
16 stub_get('/projects/3/repository/commits', 'project_commits')
17 .with(query: { ref_name: 'api' })
18 @commits = Gitlab.commits(3, ref_name: 'api')
19 end
20
21 it 'gets the correct resource' do
22 expect(a_get('/projects/3/repository/commits')
23 .with(query: { ref_name: 'api' })).to have_been_made
24 end
25
26 it 'returns a paginated response of repository commits' do
2527 expect(@commits).to be_a Gitlab::PaginatedResponse
26 expect(@commits.first.id).to eq("f7dd067490fe57505f7226c3b54d3127d2f7fd46")
27 end
28 end
29
30 describe ".commit" do
31 before do
32 stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6", "project_commit")
28 expect(@commits.first.id).to eq('f7dd067490fe57505f7226c3b54d3127d2f7fd46')
29 end
30 end
31
32 describe '.commit' do
33 before do
34 stub_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6', 'project_commit')
3335 @commit = Gitlab.commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
3436 end
3537
36 it "gets the correct resource" do
37 expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6")).
38 to have_been_made
39 end
40
41 it "returns a repository commit" do
42 expect(@commit.id).to eq("6104942438c14ec7bd21c6cd5bd995272b3faff6")
43 end
44 end
45
46 describe ".commit_diff" do
47 before do
48 stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff", "project_commit_diff")
38 it 'gets the correct resource' do
39 expect(a_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6'))
40 .to have_been_made
41 end
42
43 it 'returns a repository commit' do
44 expect(@commit.id).to eq('6104942438c14ec7bd21c6cd5bd995272b3faff6')
45 end
46 end
47
48 describe '.cherry_pick_commit' do
49 before do
50 stub_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/cherry_pick', 'project_commit').with(body: { branch: 'master' })
51 @cherry_pick_commit = Gitlab.cherry_pick_commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master')
52 end
53
54 it 'gets the correct resource' do
55 expect(a_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/cherry_pick')
56 .with(body: { branch: 'master' }))
57 .to have_been_made
58 end
59
60 it 'returns the correct response' do
61 expect(@cherry_pick_commit).to be_a Gitlab::ObjectifiedHash
62 expect(@cherry_pick_commit.id).to eq('6104942438c14ec7bd21c6cd5bd995272b3faff6')
63 end
64 end
65
66 describe '.commit_diff' do
67 before do
68 stub_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff', 'project_commit_diff')
4969 @diff = Gitlab.commit_diff(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
5070 end
5171
52 it "gets the correct resource" do
53 expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff")).
54 to have_been_made
55 end
56
57 it "returns a diff of a commit" do
58 expect(@diff.new_path).to eq("doc/update/5.4-to-6.0.md")
59 end
60 end
61
62 describe ".commit_comments" do
63 before do
64 stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments", "project_commit_comments")
72 it 'gets the correct resource' do
73 expect(a_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff'))
74 .to have_been_made
75 end
76
77 it 'returns a diff of a commit' do
78 expect(@diff.new_path).to eq('doc/update/5.4-to-6.0.md')
79 end
80 end
81
82 describe '.commit_comments' do
83 before do
84 stub_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments', 'project_commit_comments')
6585 @commit_comments = Gitlab.commit_comments(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
6686 end
6787
68 it "gets the correct resource" do
69 expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments")).
70 to have_been_made
88 it 'gets the correct resource' do
89 expect(a_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments'))
90 .to have_been_made
7191 end
7292
7393 it "returns commit's comments" do
7494 expect(@commit_comments).to be_a Gitlab::PaginatedResponse
7595 expect(@commit_comments.length).to eq(2)
76 expect(@commit_comments[0].note).to eq("this is the 1st comment on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6")
96 expect(@commit_comments[0].note).to eq('this is the 1st comment on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6')
7797 expect(@commit_comments[0].author.id).to eq(11)
78 expect(@commit_comments[1].note).to eq("another discussion point on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6")
98 expect(@commit_comments[1].note).to eq('another discussion point on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6')
7999 expect(@commit_comments[1].author.id).to eq(12)
80100 end
81101 end
82102
83 describe ".create_commit_comment" do
84 before do
85 stub_post("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments", "project_commit_comment")
103 describe '.create_commit_comment' do
104 before do
105 stub_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments', 'project_commit_comment')
86106 @merge_request = Gitlab.create_commit_comment(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'Nice code!')
87107 end
88108
89 it "returns information about the newly created comment" do
109 it 'returns information about the newly created comment' do
90110 expect(@merge_request.note).to eq('Nice code!')
91111 expect(@merge_request.author.id).to eq(1)
92112 end
93113 end
94114
95 describe ".commit_status" do
96 before do
97 stub_get("/projects/6/repository/commits/7d938cb8ac15788d71f4b67c035515a160ea76d8/statuses", 'project_commit_status').
98 with(query: { all: 'true' })
115 describe '.commit_status' do
116 before do
117 stub_get('/projects/6/repository/commits/7d938cb8ac15788d71f4b67c035515a160ea76d8/statuses', 'project_commit_status')
118 .with(query: { all: 'true' })
99119 @statuses = Gitlab.commit_status(6, '7d938cb8ac15788d71f4b67c035515a160ea76d8', all: true)
100120 end
101121
102 it "gets the correct resource" do
103 expect(a_get("/projects/6/repository/commits/7d938cb8ac15788d71f4b67c035515a160ea76d8/statuses").
104 with(query: { all: true }))
105 end
106
107 it "gets statuses of a commit" do
122 it 'gets the correct resource' do
123 expect(a_get('/projects/6/repository/commits/7d938cb8ac15788d71f4b67c035515a160ea76d8/statuses')
124 .with(query: { all: true }))
125 end
126
127 it 'gets statuses of a commit' do
108128 expect(@statuses).to be_kind_of Gitlab::PaginatedResponse
109129 expect(@statuses.first.sha).to eq('7d938cb8ac15788d71f4b67c035515a160ea76d8')
110130 expect(@statuses.first.ref).to eq('decreased-spec')
114134 end
115135 end
116136
117 describe ".update_commit_status" do
118 before do
119 stub_post("/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8", 'project_update_commit_status').
120 with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' })
137 describe '.update_commit_status' do
138 before do
139 stub_post('/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8', 'project_update_commit_status')
140 .with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' })
121141 @status = Gitlab.update_commit_status(6, '7d938cb8ac15788d71f4b67c035515a160ea76d8', 'failed', name: 'test', ref: 'decreased-spec')
122142 end
123143
124 it "gets the correct resource" do
125 expect(a_post('/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8').
126 with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' }))
127 end
128
129 it "returns information about the newly created status" do
144 it 'gets the correct resource' do
145 expect(a_post('/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8')
146 .with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' }))
147 end
148
149 it 'returns information about the newly created status' do
130150 expect(@status).to be_kind_of Gitlab::ObjectifiedHash
131151 expect(@status.id).to eq(498)
132152 expect(@status.sha).to eq('7d938cb8ac15788d71f4b67c035515a160ea76d8')
135155 end
136156 end
137157
138 describe ".create_commit" do
158 describe '.create_commit' do
139159 let(:actions) do
140160 [
141161 {
142 action: "create",
143 file_path: "foo/bar",
144 content: "some content"
162 action: 'create',
163 file_path: 'foo/bar',
164 content: 'some content'
145165 }
146166 ]
147167 end
157177 end
158178
159179 before do
160 stub_post("/projects/6/repository/commits", 'project_commit_create').with(body: query)
161 @commit = Gitlab.create_commit(6, 'dev', 'refactors everything', actions, {author_email: 'joe@sample.org', author_name: 'Joe Sample'})
162 end
163
164 it "returns id of a created commit" do
180 stub_post('/projects/6/repository/commits', 'project_commit_create').with(body: query)
181 @commit = Gitlab.create_commit(6, 'dev', 'refactors everything', actions, author_email: 'joe@sample.org', author_name: 'Joe Sample')
182 end
183
184 it 'returns id of a created commit' do
165185 expect(@commit.id).to eq('ed899a2f4b50b4370feeea94676502b42383c746')
166186 end
167187 end
168188
169 describe ".repo_commit_merge_requests" do
170 before do
171 stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/merge_requests", "project_commit_merge_requests")
189 describe '.repo_commit_merge_requests' do
190 before do
191 stub_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/merge_requests', 'project_commit_merge_requests')
172192 @commit_merge_requests = Gitlab.commit_merge_requests(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
173193 end
174194
175 it "gets the correct resource" do
176 expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/merge_requests")).
177 to have_been_made
195 it 'gets the correct resource' do
196 expect(a_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/merge_requests'))
197 .to have_been_made
178198 end
179199
180200 it "returns commit's associated merge_requests" do
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".deployments" do
5 describe '.deployments' do
46 before do
5 stub_get("/projects/3/deployments", "deployments")
7 stub_get('/projects/3/deployments', 'deployments')
68 @deployments = Gitlab.deployments(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/deployments")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/deployments')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of project's deployments" do
1517 end
1618 end
1719
18 describe ".deployment" do
20 describe '.deployment' do
1921 before do
20 stub_get("/projects/3/deployments/42", "deployment")
22 stub_get('/projects/3/deployments/42', 'deployment')
2123 @deployment = Gitlab.deployment(3, 42)
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_get("/projects/3/deployments/42")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_get('/projects/3/deployments/42')).to have_been_made
2628 end
2729
28 it "returns a single deployment" do
30 it 'returns a single deployment' do
2931 expect(@deployment).to be_a Gitlab::ObjectifiedHash
3032 end
3133
32 it "returns information about an deployment" do
34 it 'returns information about an deployment' do
3335 expect(@deployment.id).to eq(42)
34 expect(@deployment.deployable.commit.id).to eq("a91957a858320c0e17f3a0eca7cfacbff50ea29a")
36 expect(@deployment.deployable.commit.id).to eq('a91957a858320c0e17f3a0eca7cfacbff50ea29a')
3537 end
3638 end
3739 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".environments" do
5 describe '.environments' do
46 before do
5 stub_get("/projects/3/environments", "environments")
7 stub_get('/projects/3/environments', 'environments')
68 @environments = Gitlab.environments(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/environments")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/environments')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of project's environments" do
1517 end
1618 end
1719
18 describe ".environment" do
20 describe '.environment' do
1921 before do
20 stub_get("/projects/3/environments/12", "environment")
22 stub_get('/projects/3/environments/12', 'environment')
2123 @environment = Gitlab.environment(3, 12)
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_get("/projects/3/environments/12")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_get('/projects/3/environments/12')).to have_been_made
2628 end
2729
28 it "returns a single environment" do
30 it 'returns a single environment' do
2931 expect(@environment).to be_a Gitlab::ObjectifiedHash
3032 end
3133
32 it "returns information about an environment" do
34 it 'returns information about an environment' do
3335 expect(@environment.id).to eq(12)
34 expect(@environment.name).to eq("staging")
36 expect(@environment.name).to eq('staging')
3537 end
3638 end
3739
38 describe ".create_environment" do
39 context "without external_url" do
40 describe '.create_environment' do
41 context 'without external_url' do
4042 before do
41 stub_post("/projects/3/environments", "environment")
43 stub_post('/projects/3/environments', 'environment')
4244 @environment = Gitlab.create_environment(3, 'staging')
4345 end
4446
45 it "gets the correct resource" do
46 expect(a_post("/projects/3/environments").with(body: { name: 'staging' })).to have_been_made
47 it 'gets the correct resource' do
48 expect(a_post('/projects/3/environments').with(body: { name: 'staging' })).to have_been_made
4749 end
4850
49 it "returns a single environment" do
51 it 'returns a single environment' do
5052 expect(@environment).to be_a Gitlab::ObjectifiedHash
5153 end
5254
53 it "returns information about an environment" do
54 expect(@environment.name).to eq("staging")
55 it 'returns information about an environment' do
56 expect(@environment.name).to eq('staging')
5557 end
5658 end
5759
58 context "with external_url" do
60 context 'with external_url' do
5961 before do
60 stub_post("/projects/3/environments", "environment")
61 @environment = Gitlab.create_environment(3, 'staging', external_url: "https://staging.example.gitlab.com")
62 stub_post('/projects/3/environments', 'environment')
63 @environment = Gitlab.create_environment(3, 'staging', external_url: 'https://staging.example.gitlab.com')
6264 end
6365
64 it "gets the correct resource" do
65 expect(a_post("/projects/3/environments")
66 .with(body: { name: 'staging', external_url: "https://staging.example.gitlab.com" })).to have_been_made
66 it 'gets the correct resource' do
67 expect(a_post('/projects/3/environments')
68 .with(body: { name: 'staging', external_url: 'https://staging.example.gitlab.com' })).to have_been_made
6769 end
6870 end
6971 end
7072
71 describe ".edit_environment" do
73 describe '.edit_environment' do
7274 before do
73 stub_put("/projects/3/environments/12", "environment")
74 @environment = Gitlab.edit_environment(3, 12, {
75 name: 'staging',
76 external_url: "https://staging.example.gitlab.com"
77 })
75 stub_put('/projects/3/environments/12', 'environment')
76 @environment = Gitlab.edit_environment(3, 12,
77 name: 'staging',
78 external_url: 'https://staging.example.gitlab.com')
7879 end
7980
80 it "gets the correct resource" do
81 expect(a_put("/projects/3/environments/12")
82 .with(body: { name: 'staging', external_url: "https://staging.example.gitlab.com" })).to have_been_made
81 it 'gets the correct resource' do
82 expect(a_put('/projects/3/environments/12')
83 .with(body: { name: 'staging', external_url: 'https://staging.example.gitlab.com' })).to have_been_made
8384 end
8485
85 it "returns a single environment" do
86 it 'returns a single environment' do
8687 expect(@environment).to be_a Gitlab::ObjectifiedHash
8788 end
8889
89 it "returns information about an environment" do
90 expect(@environment.name).to eq("staging")
90 it 'returns information about an environment' do
91 expect(@environment.name).to eq('staging')
9192 end
9293 end
9394
94 describe ".delete_environment" do
95 describe '.delete_environment' do
9596 before do
96 stub_delete("/projects/3/environments/12", "environment")
97 stub_delete('/projects/3/environments/12', 'environment')
9798 @environment = Gitlab.delete_environment(3, 12)
9899 end
99100
100 it "gets the correct resource" do
101 expect(a_delete("/projects/3/environments/12")).to have_been_made
101 it 'gets the correct resource' do
102 expect(a_delete('/projects/3/environments/12')).to have_been_made
102103 end
103104
104 it "returns a single pipeline" do
105 it 'returns a single pipeline' do
105106 expect(@environment).to be_a Gitlab::ObjectifiedHash
106107 end
107108
108 it "returns information about a pipeline" do
109 expect(@environment.name).to eq("staging")
109 it 'returns information about a pipeline' do
110 expect(@environment.name).to eq('staging')
110111 end
111112 end
112113
113 describe ".stop_environment" do
114 describe '.stop_environment' do
114115 before do
115 stub_post("/projects/3/environments/12/stop", "environment")
116 stub_post('/projects/3/environments/12/stop', 'environment')
116117 @environment = Gitlab.stop_environment(3, 12)
117118 end
118119
119 it "gets the correct resource" do
120 expect(a_post("/projects/3/environments/12/stop")).to have_been_made
120 it 'gets the correct resource' do
121 expect(a_post('/projects/3/environments/12/stop')).to have_been_made
121122 end
122123
123 it "returns a single pipeline" do
124 it 'returns a single pipeline' do
124125 expect(@environment).to be_a Gitlab::ObjectifiedHash
125126 end
126127
127 it "returns information about a pipeline" do
128 expect(@environment.name).to eq("staging")
128 it 'returns information about a pipeline' do
129 expect(@environment.name).to eq('staging')
129130 end
130131 end
131132 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".events" do
5 describe '.events' do
46 before do
5 stub_get("/events", "user_events")
6 @events = Gitlab.events()
7 stub_get('/events', 'user_events')
8 @events = Gitlab.events
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/events")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/events')).to have_been_made
1113 end
1214
13 it "it returns a response of user's events" do
15 it "returns a response of user's events" do
1416 expect(@events).to be_a Gitlab::PaginatedResponse
1517 end
1618 end
1719
18 describe ".user_events" do
20 describe '.user_events' do
1921 before do
20 stub_get("/users/1/events", "user_events")
22 stub_get('/users/1/events', 'user_events')
2123 @events = Gitlab.user_events(1)
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_get("/users/1/events")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_get('/users/1/events')).to have_been_made
2628 end
2729
2830 it "returns a response of user's contribution events" do
3234
3335 describe '.project_events' do
3436 before do
35 stub_get("/1/events", "project_events")
37 stub_get('/projects/1/events', 'project_events')
3638 @events = Gitlab.project_events(1)
3739 end
3840
39 it "gets the correct resource" do
40 expect(a_get("/1/events")).to have_been_made
41 it 'gets the correct resource' do
42 expect(a_get('/projects/1/events')).to have_been_made
4143 end
4244
4345 it "returns a response of project's visible events" do
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".group_milestones" do
5 describe '.group_milestones' do
46 before do
5 stub_get("/groups/3/milestones", "group_milestones")
7 stub_get('/groups/3/milestones', 'group_milestones')
68 @milestones = Gitlab.group_milestones(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/groups/3/milestones")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/groups/3/milestones')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of group's milestones" do
1618 end
1719 end
1820
19 describe ".group_milestone" do
21 describe '.group_milestone' do
2022 before do
21 stub_get("/groups/3/milestones/1", "group_milestone")
23 stub_get('/groups/3/milestones/1', 'group_milestone')
2224 @milestone = Gitlab.group_milestone(3, 1)
2325 end
2426
25 it "gets the correct resource" do
26 expect(a_get("/groups/3/milestones/1")).to have_been_made
27 it 'gets the correct resource' do
28 expect(a_get('/groups/3/milestones/1')).to have_been_made
2729 end
2830
29 it "returns information about a milestone" do
31 it 'returns information about a milestone' do
3032 expect(@milestone.group_id).to eq(3)
3133 end
3234 end
3335
34 describe ".create_group_milestone" do
36 describe '.create_group_milestone' do
3537 before do
36 stub_post("/groups/3/milestones", "group_milestone")
38 stub_post('/groups/3/milestones', 'group_milestone')
3739 @milestone = Gitlab.create_group_milestone(3, 'title')
3840 end
3941
40 it "gets the correct resource" do
41 expect(a_post("/groups/3/milestones").
42 with(body: { title: 'title' })).to have_been_made
42 it 'gets the correct resource' do
43 expect(a_post('/groups/3/milestones')
44 .with(body: { title: 'title' })).to have_been_made
4345 end
4446
45 it "returns information about a created milestone" do
47 it 'returns information about a created milestone' do
4648 expect(@milestone.group_id).to eq(3)
4749 end
4850 end
4951
50 describe ".edit_group_milestone" do
52 describe '.edit_group_milestone' do
5153 before do
52 stub_put("/groups/3/milestones/33", "group_milestone")
54 stub_put('/groups/3/milestones/33', 'group_milestone')
5355 @milestone = Gitlab.edit_group_milestone(3, 33, title: 'title')
5456 end
5557
56 it "gets the correct resource" do
57 expect(a_put("/groups/3/milestones/33").
58 with(body: { title: 'title' })).to have_been_made
58 it 'gets the correct resource' do
59 expect(a_put('/groups/3/milestones/33')
60 .with(body: { title: 'title' })).to have_been_made
5961 end
6062
61 it "returns information about an edited milestone" do
63 it 'returns information about an edited milestone' do
6264 expect(@milestone.group_id).to eq(3)
6365 end
6466 end
6567
66 describe ".group_milestone_issues" do
68 describe '.group_milestone_issues' do
6769 before do
68 stub_get("/groups/3/milestones/1/issues", "group_milestone_issues")
70 stub_get('/groups/3/milestones/1/issues', 'group_milestone_issues')
6971 @milestone_issues = Gitlab.group_milestone_issues(3, 1)
7072 end
7173
72 it "gets the correct resource" do
73 expect(a_get("/groups/3/milestones/1/issues")).to have_been_made
74 it 'gets the correct resource' do
75 expect(a_get('/groups/3/milestones/1/issues')).to have_been_made
7476 end
7577
7678 it "returns a paginated response of milestone's issues" do
7981 end
8082 end
8183
82 describe ".group_milestone_merge_requests" do
84 describe '.group_milestone_merge_requests' do
8385 before do
84 stub_get("/groups/3/milestones/1/merge_requests", "group_milestone_merge_requests")
86 stub_get('/groups/3/milestones/1/merge_requests', 'group_milestone_merge_requests')
8587 @milestone_merge_requests = Gitlab.group_milestone_merge_requests(3, 1)
8688 end
8789
88 it "gets the correct resource" do
89 expect(a_get("/groups/3/milestones/1/merge_requests")).to have_been_made
90 it 'gets the correct resource' do
91 expect(a_get('/groups/3/milestones/1/merge_requests')).to have_been_made
9092 end
9193
9294 it "returns a paginated response of milestone's merge_requests" do
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".groups" do
4 before do
5 stub_get("/groups", "groups")
6 stub_get("/groups/3", "group")
5 describe '.groups' do
6 before do
7 stub_get('/groups', 'groups')
8 stub_get('/groups/3', 'group')
79 @group = Gitlab.group(3)
810 @groups = Gitlab.groups
911 end
1012
11 it "gets the correct resource" do
12 expect(a_get("/groups")).to have_been_made
13 expect(a_get("/groups/3")).to have_been_made
14 end
15
16 it "returns a paginated response of groups" do
13 it 'gets the correct resource' do
14 expect(a_get('/groups')).to have_been_made
15 expect(a_get('/groups/3')).to have_been_made
16 end
17
18 it 'returns a paginated response of groups' do
1719 expect(@groups).to be_a Gitlab::PaginatedResponse
18 expect(@groups.first.path).to eq("threegroup")
19 end
20 end
21
22 describe ".create_group" do
23 context "without description" do
20 expect(@groups.first.path).to eq('threegroup')
21 end
22 end
23
24 describe '.create_group' do
25 context 'without description' do
2426 before do
25 stub_post("/groups", "group_create")
27 stub_post('/groups', 'group_create')
2628 @group = Gitlab.create_group('GitLab-Group', 'gitlab-path')
2729 end
2830
29 it "gets the correct resource" do
30 expect(a_post("/groups").
31 with(body: { path: 'gitlab-path', name: 'GitLab-Group' })).to have_been_made
32 end
33
34 it "returns information about a created group" do
35 expect(@group.name).to eq("Gitlab-Group")
36 expect(@group.path).to eq("gitlab-group")
37 end
38 end
39
40 context "with description" do
31 it 'gets the correct resource' do
32 expect(a_post('/groups')
33 .with(body: { path: 'gitlab-path', name: 'GitLab-Group' })).to have_been_made
34 end
35
36 it 'returns information about a created group' do
37 expect(@group.name).to eq('Gitlab-Group')
38 expect(@group.path).to eq('gitlab-group')
39 end
40 end
41
42 context 'with description' do
4143 before do
42 stub_post("/groups", "group_create_with_description")
44 stub_post('/groups', 'group_create_with_description')
4345 @group = Gitlab.create_group('GitLab-Group', 'gitlab-path', description: 'gitlab group description')
4446 end
4547
46 it "gets the correct resource" do
47 expect(a_post("/groups").
48 with(body: { path: 'gitlab-path', name: 'GitLab-Group',
49 description: 'gitlab group description' })).to have_been_made
50 end
51
52 it "returns information about a created group" do
53 expect(@group.name).to eq("Gitlab-Group")
54 expect(@group.path).to eq("gitlab-group")
55 expect(@group.description).to eq("gitlab group description")
56 end
57 end
58 end
59
60 describe ".delete_group" do
61 before do
62 stub_delete("/groups/42", "group_delete")
48 it 'gets the correct resource' do
49 expect(a_post('/groups')
50 .with(body: { path: 'gitlab-path', name: 'GitLab-Group',
51 description: 'gitlab group description' })).to have_been_made
52 end
53
54 it 'returns information about a created group' do
55 expect(@group.name).to eq('Gitlab-Group')
56 expect(@group.path).to eq('gitlab-group')
57 expect(@group.description).to eq('gitlab group description')
58 end
59 end
60 end
61
62 describe '.delete_group' do
63 before do
64 stub_delete('/groups/42', 'group_delete')
6365 @group = Gitlab.delete_group(42)
6466 end
6567
66 it "gets the correct resource" do
67 expect(a_delete("/groups/42")).to have_been_made
68 end
69
70 it "returns information about a deleted group" do
71 expect(@group.name).to eq("Gitlab-Group")
72 expect(@group.path).to eq("gitlab-group")
73 end
74 end
75
76 describe ".transfer_project_to_group" do
77 before do
78 stub_post("/projects", "project")
68 it 'gets the correct resource' do
69 expect(a_delete('/groups/42')).to have_been_made
70 end
71
72 it 'returns information about a deleted group' do
73 expect(@group.name).to eq('Gitlab-Group')
74 expect(@group.path).to eq('gitlab-group')
75 end
76 end
77
78 describe '.transfer_project_to_group' do
79 before do
80 stub_post('/projects', 'project')
7981 @project = Gitlab.create_project('Gitlab')
80 stub_post("/groups", "group_create")
82 stub_post('/groups', 'group_create')
8183 @group = Gitlab.create_group('GitLab-Group', 'gitlab-path')
8284
83 stub_post("/groups/#{@group.id}/projects/#{@project.id}", "group_create")
85 stub_post("/groups/#{@group.id}/projects/#{@project.id}", 'group_create')
8486 @group_transfer = Gitlab.transfer_project_to_group(@group.id, @project.id)
8587 end
8688
87 it "posts to the correct resource" do
89 it 'posts to the correct resource' do
8890 expect(a_post("/groups/#{@group.id}/projects/#{@project.id}").with(body: { id: @group.id.to_s, project_id: @project.id.to_s })).to have_been_made
8991 end
9092
91 it "returns information about the group" do
93 it 'returns information about the group' do
9294 expect(@group_transfer.name).to eq(@group.name)
9395 expect(@group_transfer.path).to eq(@group.path)
9496 expect(@group_transfer.id).to eq(@group.id)
9597 end
9698 end
9799
98 describe ".group_members" do
99 before do
100 stub_get("/groups/3/members", "group_members")
100 describe '.group_members' do
101 before do
102 stub_get('/groups/3/members', 'group_members')
101103 @members = Gitlab.group_members(3)
102104 end
103105
104 it "gets the correct resource" do
105 expect(a_get("/groups/3/members")).to have_been_made
106 it 'gets the correct resource' do
107 expect(a_get('/groups/3/members')).to have_been_made
106108 end
107109
108110 it "returns information about a group's members" do
109111 expect(@members).to be_a Gitlab::PaginatedResponse
110112 expect(@members.size).to eq(2)
111 expect(@members[1].name).to eq("John Smith")
112 end
113 end
114
115 describe ".group_member" do
116 before do
117 stub_get("/groups/3/members/2", "group_member")
113 expect(@members[1].name).to eq('John Smith')
114 end
115 end
116
117 describe '.group_member' do
118 before do
119 stub_get('/groups/3/members/2', 'group_member')
118120 @member = Gitlab.group_member(3, 2)
119121 end
120122
121 it "gets the correct resource" do
122 expect(a_get("/groups/3/members/2")).to have_been_made
123 end
124
125 it "returns information about a group member" do
123 it 'gets the correct resource' do
124 expect(a_get('/groups/3/members/2')).to have_been_made
125 end
126
127 it 'returns information about a group member' do
126128 expect(@member).to be_a Gitlab::ObjectifiedHash
127129 expect(@member.access_level).to eq(10)
128 expect(@member.name).to eq("John Smith")
129 end
130 end
131
132 describe ".add_group_member" do
133 before do
134 stub_post("/groups/3/members", "group_member")
130 expect(@member.name).to eq('John Smith')
131 end
132 end
133
134 describe '.add_group_member' do
135 before do
136 stub_post('/groups/3/members', 'group_member')
135137 @member = Gitlab.add_group_member(3, 1, 40)
136138 end
137139
138 it "gets the correct resource" do
139 expect(a_post("/groups/3/members").
140 with(body: { user_id: '1', access_level: '40' })).to have_been_made
141 end
142
143 it "returns information about the added member" do
144 expect(@member.name).to eq("John Smith")
145 end
146 end
147
148 describe ".edit_group_member" do
149 before do
150 stub_put("/groups/3/members/1", "group_member_edit")
140 it 'gets the correct resource' do
141 expect(a_post('/groups/3/members')
142 .with(body: { user_id: '1', access_level: '40' })).to have_been_made
143 end
144
145 it 'returns information about the added member' do
146 expect(@member.name).to eq('John Smith')
147 end
148 end
149
150 describe '.edit_group_member' do
151 before do
152 stub_put('/groups/3/members/1', 'group_member_edit')
151153 @member = Gitlab.edit_group_member(3, 1, 50)
152154 end
153155
154 it "gets the correct resource" do
155 expect(a_put("/groups/3/members/1")
156 .with(body: { access_level: '50'})).to have_been_made
157 end
158
159 it "returns information about the edited member" do
156 it 'gets the correct resource' do
157 expect(a_put('/groups/3/members/1')
158 .with(body: { access_level: '50' })).to have_been_made
159 end
160
161 it 'returns information about the edited member' do
160162 expect(@member.access_level).to eq(50)
161163 end
162164 end
163165
164 describe ".remove_group_member" do
165 before do
166 stub_delete("/groups/3/members/1", "group_member_delete")
166 describe '.remove_group_member' do
167 before do
168 stub_delete('/groups/3/members/1', 'group_member_delete')
167169 @group = Gitlab.remove_group_member(3, 1)
168170 end
169171
170 it "gets the correct resource" do
171 expect(a_delete("/groups/3/members/1")).to have_been_made
172 end
173
174 it "returns information about the group the member was removed from" do
172 it 'gets the correct resource' do
173 expect(a_delete('/groups/3/members/1')).to have_been_made
174 end
175
176 it 'returns information about the group the member was removed from' do
175177 expect(@group.group_id).to eq(3)
176178 end
177179 end
178180
179 describe ".group_projects" do
180 before do
181 stub_get("/groups/4/projects", "group_projects")
181 describe '.group_projects' do
182 before do
183 stub_get('/groups/4/projects', 'group_projects')
182184 @projects = Gitlab.group_projects(4)
183185 end
184186
185 it "gets the list of projects" do
186 expect(a_get("/groups/4/projects")).to have_been_made
187 end
188
189 it "returns a list of of projects under a group" do
187 it 'gets the list of projects' do
188 expect(a_get('/groups/4/projects')).to have_been_made
189 end
190
191 it 'returns a list of of projects under a group' do
190192 expect(@projects).to be_a Gitlab::PaginatedResponse
191193 expect(@projects.size).to eq(1)
192 expect(@projects[0].name).to eq("Diaspora Client")
193 end
194 end
195
196 describe ".group_search" do
197 before do
198 stub_get("/groups?search=Group", "group_search")
194 expect(@projects[0].name).to eq('Diaspora Client')
195 end
196 end
197
198 describe '.group_search' do
199 before do
200 stub_get('/groups?search=Group', 'group_search')
199201 @groups = Gitlab.group_search('Group')
200202 end
201203
202 it "gets the correct resource" do
203 expect(a_get("/groups?search=Group")).to have_been_made
204 end
205
206 it "returns an array of groups found" do
204 it 'gets the correct resource' do
205 expect(a_get('/groups?search=Group')).to have_been_made
206 end
207
208 it 'returns an array of groups found' do
207209 expect(@groups.first.id).to eq(5)
208210 expect(@groups.last.id).to eq(8)
209211 end
210212 end
211213
212 describe ".group_subgroups" do
213 before do
214 stub_get("/groups/4/subgroups", "group_subgroups")
214 describe '.group_subgroups' do
215 before do
216 stub_get('/groups/4/subgroups', 'group_subgroups')
215217 @subgroups = Gitlab.group_subgroups(4)
216218 end
217219
218 it "gets the list of subroups" do
219 expect(a_get("/groups/4/subgroups")).to have_been_made
220 end
221
222 it "returns an array of subgroups under a group" do
220 it 'gets the list of subroups' do
221 expect(a_get('/groups/4/subgroups')).to have_been_made
222 end
223
224 it 'returns an array of subgroups under a group' do
223225 expect(@subgroups).to be_a Gitlab::PaginatedResponse
224226 expect(@subgroups.size).to eq(1)
225 expect(@subgroups[0].name).to eq("Foobar Group")
226 end
227 end
228
229 describe ".edit_group" do
230 context "using group ID" do
227 expect(@subgroups[0].name).to eq('Foobar Group')
228 end
229 end
230
231 describe '.edit_group' do
232 context 'using group ID' do
231233 before do
232 stub_put("/groups/1", "group_edit").with(body: { description: "An interesting group" })
233 @edited_project = Gitlab.edit_group(1, description: "An interesting group")
234 end
235
236 it "gets the correct resource" do
237 expect(a_put("/groups/1").with(body: { description: "An interesting group" })).to have_been_made
238 end
239
240 it "returns information about an edited group" do
241 expect(@edited_project.description).to eq("An interesting group")
234 stub_put('/groups/1', 'group_edit').with(body: { description: 'An interesting group' })
235 @edited_project = Gitlab.edit_group(1, description: 'An interesting group')
236 end
237
238 it 'gets the correct resource' do
239 expect(a_put('/groups/1').with(body: { description: 'An interesting group' })).to have_been_made
240 end
241
242 it 'returns information about an edited group' do
243 expect(@edited_project.description).to eq('An interesting group')
242244 end
243245 end
244246 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".issues" do
4 context "with project ID passed" do
5 describe '.issues' do
6 context 'with project ID passed' do
57 before do
6 stub_get("/projects/3/issues", "project_issues")
8 stub_get('/projects/3/issues', 'project_issues')
79 @issues = Gitlab.issues(3)
810 end
911
10 it "gets the correct resource" do
11 expect(a_get("/projects/3/issues")).to have_been_made
12 it 'gets the correct resource' do
13 expect(a_get('/projects/3/issues')).to have_been_made
1214 end
1315
1416 it "returns a paginated response of project's issues" do
1921
2022 context 'with literal project ID passed' do
2123 before do
22 stub_get("/projects/gitlab-org%2Fgitlab-ce/issues", "project_issues")
24 stub_get('/projects/gitlab-org%2Fgitlab-ce/issues', 'project_issues')
2325 @issues = Gitlab.issues('gitlab-org/gitlab-ce')
2426 end
2527
26 it "gets the correct resource" do
27 expect(a_get("/projects/gitlab-org%2Fgitlab-ce/issues")).to have_been_made
28 it 'gets the correct resource' do
29 expect(a_get('/projects/gitlab-org%2Fgitlab-ce/issues')).to have_been_made
2830 end
2931
3032 it "returns a paginated response of project's issues" do
3335 end
3436 end
3537
36 context "without project ID passed" do
38 context 'without project ID passed' do
3739 before do
38 stub_get("/issues", "issues")
40 stub_get('/issues', 'issues')
3941 @issues = Gitlab.issues
4042 end
4143
42 it "gets the correct resource" do
43 expect(a_get("/issues")).to have_been_made
44 it 'gets the correct resource' do
45 expect(a_get('/issues')).to have_been_made
4446 end
4547
4648 it "returns a paginated response of user's issues" do
4749 expect(@issues).to be_a Gitlab::PaginatedResponse
4850 expect(@issues.first.closed).to be_falsey
49 expect(@issues.first.author.name).to eq("John Smith")
50 end
51 end
52 end
53
54 describe ".issue" do
55 before do
56 stub_get("/projects/3/issues/33", "issue")
51 expect(@issues.first.author.name).to eq('John Smith')
52 end
53 end
54 end
55
56 describe '.issue' do
57 before do
58 stub_get('/projects/3/issues/33', 'issue')
5759 @issue = Gitlab.issue(3, 33)
5860 end
5961
60 it "gets the correct resource" do
61 expect(a_get("/projects/3/issues/33")).to have_been_made
62 end
63
64 it "returns information about an issue" do
65 expect(@issue.project_id).to eq(3)
66 expect(@issue.assignee.name).to eq("Jack Smith")
67 end
68 end
69
70 describe ".create_issue" do
71 before do
72 stub_post("/projects/3/issues", "issue")
62 it 'gets the correct resource' do
63 expect(a_get('/projects/3/issues/33')).to have_been_made
64 end
65
66 it 'returns information about an issue' do
67 expect(@issue.project_id).to eq(3)
68 expect(@issue.assignee.name).to eq('Jack Smith')
69 end
70 end
71
72 describe '.create_issue' do
73 before do
74 stub_post('/projects/3/issues', 'issue')
7375 @issue = Gitlab.create_issue(3, 'title')
7476 end
7577
76 it "gets the correct resource" do
77 expect(a_post("/projects/3/issues").
78 with(body: { title: 'title' })).to have_been_made
79 end
80
81 it "returns information about a created issue" do
82 expect(@issue.project_id).to eq(3)
83 expect(@issue.assignee.name).to eq("Jack Smith")
84 end
85 end
86
87 describe ".edit_issue" do
88 before do
89 stub_put("/projects/3/issues/33", "issue")
78 it 'gets the correct resource' do
79 expect(a_post('/projects/3/issues')
80 .with(body: { title: 'title' })).to have_been_made
81 end
82
83 it 'returns information about a created issue' do
84 expect(@issue.project_id).to eq(3)
85 expect(@issue.assignee.name).to eq('Jack Smith')
86 end
87 end
88
89 describe '.edit_issue' do
90 before do
91 stub_put('/projects/3/issues/33', 'issue')
9092 @issue = Gitlab.edit_issue(3, 33, title: 'title')
9193 end
9294
93 it "gets the correct resource" do
94 expect(a_put("/projects/3/issues/33").
95 with(body: { title: 'title' })).to have_been_made
96 end
97
98 it "returns information about an edited issue" do
99 expect(@issue.project_id).to eq(3)
100 expect(@issue.assignee.name).to eq("Jack Smith")
101 end
102 end
103
104 describe ".close_issue" do
105 before do
106 stub_put("/projects/3/issues/33", "issue")
95 it 'gets the correct resource' do
96 expect(a_put('/projects/3/issues/33')
97 .with(body: { title: 'title' })).to have_been_made
98 end
99
100 it 'returns information about an edited issue' do
101 expect(@issue.project_id).to eq(3)
102 expect(@issue.assignee.name).to eq('Jack Smith')
103 end
104 end
105
106 describe '.close_issue' do
107 before do
108 stub_put('/projects/3/issues/33', 'issue')
107109 @issue = Gitlab.close_issue(3, 33)
108110 end
109111
110 it "gets the correct resource" do
111 expect(a_put("/projects/3/issues/33").
112 with(body: { state_event: 'close' })).to have_been_made
113 end
114
115 it "returns information about an closed issue" do
116 expect(@issue.project_id).to eq(3)
117 expect(@issue.assignee.name).to eq("Jack Smith")
118 end
119 end
120
121 describe ".reopen_issue" do
122 before do
123 stub_put("/projects/3/issues/33", "issue")
112 it 'gets the correct resource' do
113 expect(a_put('/projects/3/issues/33')
114 .with(body: { state_event: 'close' })).to have_been_made
115 end
116
117 it 'returns information about an closed issue' do
118 expect(@issue.project_id).to eq(3)
119 expect(@issue.assignee.name).to eq('Jack Smith')
120 end
121 end
122
123 describe '.reopen_issue' do
124 before do
125 stub_put('/projects/3/issues/33', 'issue')
124126 @issue = Gitlab.reopen_issue(3, 33)
125127 end
126128
127 it "gets the correct resource" do
128 expect(a_put("/projects/3/issues/33").
129 with(body: { state_event: 'reopen' })).to have_been_made
130 end
131
132 it "returns information about an reopened issue" do
133 expect(@issue.project_id).to eq(3)
134 expect(@issue.assignee.name).to eq("Jack Smith")
135 end
136 end
137
138 describe ".subscribe_to_issue" do
139 before do
140 stub_post("/projects/3/issues/33/subscribe", "issue")
129 it 'gets the correct resource' do
130 expect(a_put('/projects/3/issues/33')
131 .with(body: { state_event: 'reopen' })).to have_been_made
132 end
133
134 it 'returns information about an reopened issue' do
135 expect(@issue.project_id).to eq(3)
136 expect(@issue.assignee.name).to eq('Jack Smith')
137 end
138 end
139
140 describe '.subscribe_to_issue' do
141 before do
142 stub_post('/projects/3/issues/33/subscribe', 'issue')
141143 @issue = Gitlab.subscribe_to_issue(3, 33)
142144 end
143145
144 it "gets the correct resource" do
145 expect(a_post("/projects/3/issues/33/subscribe")).to have_been_made
146 end
147
148 it "returns information about the subscribed issue" do
149 expect(@issue.project_id).to eq(3)
150 expect(@issue.assignee.name).to eq("Jack Smith")
151 end
152 end
153
154 describe ".unsubscribe_from_issue" do
155 before do
156 stub_post("/projects/3/issues/33/unsubscribe", "issue")
146 it 'gets the correct resource' do
147 expect(a_post('/projects/3/issues/33/subscribe')).to have_been_made
148 end
149
150 it 'returns information about the subscribed issue' do
151 expect(@issue.project_id).to eq(3)
152 expect(@issue.assignee.name).to eq('Jack Smith')
153 end
154 end
155
156 describe '.unsubscribe_from_issue' do
157 before do
158 stub_post('/projects/3/issues/33/unsubscribe', 'issue')
157159 @issue = Gitlab.unsubscribe_from_issue(3, 33)
158160 end
159161
160 it "gets the correct resource" do
161 expect(a_post("/projects/3/issues/33/unsubscribe")).to have_been_made
162 end
163
164 it "returns information about the unsubscribed issue" do
165 expect(@issue.project_id).to eq(3)
166 expect(@issue.assignee.name).to eq("Jack Smith")
167 end
168 end
169
170 describe ".delete_issue" do
171 before do
172 stub_delete("/projects/3/issues/33", "issue")
162 it 'gets the correct resource' do
163 expect(a_post('/projects/3/issues/33/unsubscribe')).to have_been_made
164 end
165
166 it 'returns information about the unsubscribed issue' do
167 expect(@issue.project_id).to eq(3)
168 expect(@issue.assignee.name).to eq('Jack Smith')
169 end
170 end
171
172 describe '.delete_issue' do
173 before do
174 stub_delete('/projects/3/issues/33', 'issue')
173175 @issue = Gitlab.delete_issue(3, 33)
174176 end
175177
176 it "gets the correct resource" do
177 expect(a_delete("/projects/3/issues/33")).to have_been_made
178 end
179
180 it "returns information about a deleted issue" do
178 it 'gets the correct resource' do
179 expect(a_delete('/projects/3/issues/33')).to have_been_made
180 end
181
182 it 'returns information about a deleted issue' do
181183 expect(@issue.project_id).to eq(3)
182184 expect(@issue.id).to eq(33)
183185 end
184186 end
185187
186 describe ".move_issue" do
187 before do
188 stub_post("/projects/3/issues/33/move", "issue")
188 describe '.move_issue' do
189 before do
190 stub_post('/projects/3/issues/33/move', 'issue')
189191 @issue = Gitlab.move_issue(3, 33, to_project_id: '4')
190192 end
191193
192 it "gets the correct resource" do
193 expect(a_post("/projects/3/issues/33/move").
194 with(body: { to_project_id: '4' })).to have_been_made
195 end
196
197 it "returns information about the moved issue" do
198 expect(@issue.project_id).to eq(3)
199 expect(@issue.assignee.name).to eq("Jack Smith")
200 end
201 end
202
203 describe ".estimate_time_of_issue" do
204 before do
205 stub_post("/projects/3/issues/33/time_estimate", "issue")
194 it 'gets the correct resource' do
195 expect(a_post('/projects/3/issues/33/move')
196 .with(body: { to_project_id: '4' })).to have_been_made
197 end
198
199 it 'returns information about the moved issue' do
200 expect(@issue.project_id).to eq(3)
201 expect(@issue.assignee.name).to eq('Jack Smith')
202 end
203 end
204
205 describe '.estimate_time_of_issue' do
206 before do
207 stub_post('/projects/3/issues/33/time_estimate', 'issue')
206208 @issue = Gitlab.estimate_time_of_issue(3, 33, '3h30m')
207209 end
208210
209 it "gets the correct resource" do
210 expect(a_post("/projects/3/issues/33/time_estimate").
211 with(body: { duration: '3h30m' })).to have_been_made
212 end
213
214 it "returns information about the estimated issue" do
215 expect(@issue.project_id).to eq(3)
216 expect(@issue.assignee.name).to eq("Jack Smith")
217 end
218 end
219
220 describe ".reset_time_estimate_of_issue" do
221 before do
222 stub_post("/projects/3/issues/33/reset_time_estimate", "issue")
211 it 'gets the correct resource' do
212 expect(a_post('/projects/3/issues/33/time_estimate')
213 .with(body: { duration: '3h30m' })).to have_been_made
214 end
215
216 it 'returns information about the estimated issue' do
217 expect(@issue.project_id).to eq(3)
218 expect(@issue.assignee.name).to eq('Jack Smith')
219 end
220 end
221
222 describe '.reset_time_estimate_of_issue' do
223 before do
224 stub_post('/projects/3/issues/33/reset_time_estimate', 'issue')
223225 @issue = Gitlab.reset_time_estimate_of_issue(3, 33)
224226 end
225227
226 it "gets the correct resource" do
227 expect(a_post("/projects/3/issues/33/reset_time_estimate")).to have_been_made
228 end
229
230 it "returns information about the estimated issue" do
231 expect(@issue.project_id).to eq(3)
232 expect(@issue.assignee.name).to eq("Jack Smith")
233 end
234 end
235
236 describe ".add_time_spent_on_issue" do
237 before do
238 stub_post("/projects/3/issues/33/add_spent_time", "issue")
228 it 'gets the correct resource' do
229 expect(a_post('/projects/3/issues/33/reset_time_estimate')).to have_been_made
230 end
231
232 it 'returns information about the estimated issue' do
233 expect(@issue.project_id).to eq(3)
234 expect(@issue.assignee.name).to eq('Jack Smith')
235 end
236 end
237
238 describe '.add_time_spent_on_issue' do
239 before do
240 stub_post('/projects/3/issues/33/add_spent_time', 'issue')
239241 @issue = Gitlab.add_time_spent_on_issue(3, 33, '3h30m')
240242 end
241243
242 it "gets the correct resource" do
243 expect(a_post("/projects/3/issues/33/add_spent_time").
244 with(body: { duration: '3h30m' })).to have_been_made
245 end
246
247 it "returns information about the estimated issue" do
248 expect(@issue.project_id).to eq(3)
249 expect(@issue.assignee.name).to eq("Jack Smith")
250 end
251 end
252
253 describe ".reset_time_spent_on_issue" do
254 before do
255 stub_post("/projects/3/issues/33/reset_spent_time", "issue")
244 it 'gets the correct resource' do
245 expect(a_post('/projects/3/issues/33/add_spent_time')
246 .with(body: { duration: '3h30m' })).to have_been_made
247 end
248
249 it 'returns information about the estimated issue' do
250 expect(@issue.project_id).to eq(3)
251 expect(@issue.assignee.name).to eq('Jack Smith')
252 end
253 end
254
255 describe '.reset_time_spent_on_issue' do
256 before do
257 stub_post('/projects/3/issues/33/reset_spent_time', 'issue')
256258 @issue = Gitlab.reset_time_spent_on_issue(3, 33)
257259 end
258260
259 it "gets the correct resource" do
260 expect(a_post("/projects/3/issues/33/reset_spent_time")).to have_been_made
261 end
262
263 it "returns information about the estimated issue" do
264 expect(@issue.project_id).to eq(3)
265 expect(@issue.assignee.name).to eq("Jack Smith")
266 end
267 end
268
269 describe ".time_stats_for_issue" do
270 before do
271 stub_get("/projects/3/issues/33/time_stats", "issue")
261 it 'gets the correct resource' do
262 expect(a_post('/projects/3/issues/33/reset_spent_time')).to have_been_made
263 end
264
265 it 'returns information about the estimated issue' do
266 expect(@issue.project_id).to eq(3)
267 expect(@issue.assignee.name).to eq('Jack Smith')
268 end
269 end
270
271 describe '.time_stats_for_issue' do
272 before do
273 stub_get('/projects/3/issues/33/time_stats', 'issue')
272274 @issue = Gitlab.time_stats_for_issue(3, 33)
273275 end
274276
275 it "gets the correct resource" do
276 expect(a_get("/projects/3/issues/33/time_stats")).to have_been_made
277 end
278
279 it "returns information about the issue" do
280 expect(@issue.project_id).to eq(3)
281 expect(@issue.assignee.name).to eq("Jack Smith")
277 it 'gets the correct resource' do
278 expect(a_get('/projects/3/issues/33/time_stats')).to have_been_made
279 end
280
281 it 'returns information about the issue' do
282 expect(@issue.project_id).to eq(3)
283 expect(@issue.assignee.name).to eq('Jack Smith')
284 end
285 end
286
287 describe '.participants_on_issue' do
288 before do
289 stub_get('/projects/3/issues/33/participants', 'participants_on_issue')
290 @participants = Gitlab.participants_on_issue(3, 33)
291 end
292
293 it 'gets the correct resource' do
294 expect(a_get('/projects/3/issues/33/participants')).to have_been_made
295 end
296
297 it 'returns information about the participants on issue' do
298 expect(@participants.first.name).to eq('John Doe1')
299 expect(@participants.size).to eq(2)
300 end
301 end
302
303 describe '.merge_requests_closing_issue_on_merge' do
304 before do
305 stub_get('/projects/3/issues/33/closed_by', 'merge_requests_closing_issue_on_merge')
306 @merge_requests = Gitlab.merge_requests_closing_issue_on_merge(3, 33)
307 end
308
309 it 'gets the correct resource' do
310 expect(a_get('/projects/3/issues/33/closed_by')).to have_been_made
311 end
312
313 it 'returns list of merge requests closing issue on merge' do
314 expect(@merge_requests.first.title).to eq('New feature')
315 expect(@merge_requests.size).to eq(2)
282316 end
283317 end
284318 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
2729 stub_get('/projects/1/pipelines/1/jobs', 'pipeline_jobs')
2830 @projects = Gitlab.pipeline_jobs(1, 1)
2931 end
32
3033 it 'gets the correct resource' do
3134 expect(a_get('/projects/1/pipelines/1/jobs')).to have_been_made
3235 end
3740 stub_get('/projects/1/pipelines/1/jobs?scope[]=running&scope[]=created', 'pipeline_jobs')
3841 @projects = Gitlab.pipeline_jobs(1, 1, scope: %w[running created])
3942 end
43
4044 it 'gets the correct resource' do
4145 expect(a_get('/projects/1/pipelines/1/jobs?scope[]=running&scope[]=created')).to have_been_made
4246 end
4751 stub_get('/projects/1/jobs/1', 'job')
4852 @projects = Gitlab.job(1, 1)
4953 end
54
5055 it 'gets the correct resource' do
5156 expect(a_get('/projects/1/jobs/1')).to have_been_made
5257 end
5762 stub_get('/projects/1/jobs/1/artifacts', 'job')
5863 @projects = Gitlab.job_artifacts(1, 1)
5964 end
65
6066 it 'gets the correct resource' do
6167 expect(a_get('/projects/1/jobs/1/artifacts')).to have_been_made
6268 end
6773 stub_get('/projects/1/jobs/artifacts/master/download?job=Release%20Build', 'job')
6874 @projects = Gitlab.job_artifacts_download(1, 'master', 'Release Build')
6975 end
76
7077 it 'gets the correct resource' do
7178 expect(a_get('/projects/1/jobs/artifacts/master/download?job=Release%20Build')).to have_been_made
7279 end
7784 stub_get('/projects/1/jobs/1/trace', 'job_trace')
7885 @projects = Gitlab.job_trace(1, 1)
7986 end
87
8088 it 'gets the correct resource' do
8189 expect(a_get('/projects/1/jobs/1/trace')).to have_been_made
8290 end
8795 stub_post('/projects/1/jobs/1/cancel', 'job')
8896 @projects = Gitlab.job_cancel(1, 1)
8997 end
98
9099 it 'gets the correct resource' do
91100 expect(a_post('/projects/1/jobs/1/cancel')).to have_been_made
92101 end
97106 stub_post('/projects/1/jobs/1/retry', 'job')
98107 @projects = Gitlab.job_retry(1, 1)
99108 end
109
100110 it 'gets the correct resource' do
101111 expect(a_post('/projects/1/jobs/1/retry')).to have_been_made
102112 end
107117 stub_post('/projects/1/jobs/1/erase', 'job')
108118 @projects = Gitlab.job_erase(1, 1)
109119 end
120
110121 it 'gets the correct resource' do
111122 expect(a_post('/projects/1/jobs/1/erase')).to have_been_made
112123 end
117128 stub_post('/projects/1/jobs/1/play', 'job')
118129 @projects = Gitlab.job_play(1, 1)
119130 end
131
120132 it 'gets the correct resource' do
121133 expect(a_post('/projects/1/jobs/1/play')).to have_been_made
122134 end
127139 stub_post('/projects/1/jobs/1/artifacts/keep', 'job')
128140 @projects = Gitlab.job_artifacts_keep(1, 1)
129141 end
142
130143 it 'gets the correct resource' do
131144 expect(a_post('/projects/1/jobs/1/artifacts/keep')).to have_been_made
132145 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".key" do
5 describe '.key' do
46 before do
5 stub_get("/keys/1", "key")
7 stub_get('/keys/1', 'key')
68 @key = Gitlab.key(1)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/keys/1")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/keys/1')).to have_been_made
1113 end
1214
13 it "returns information about a key" do
15 it 'returns information about a key' do
1416 expect(@key.id).to eq(1)
15 expect(@key.title).to eq("narkoz@helium")
17 expect(@key.title).to eq('narkoz@helium')
1618 end
1719 end
1820 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".labels" do
5 describe '.labels' do
46 before do
5 stub_get("/projects/3/labels", "labels")
7 stub_get('/projects/3/labels', 'labels')
68 @labels = Gitlab.labels(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/labels")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/labels')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of project's labels" do
1416 expect(@labels).to be_a Gitlab::PaginatedResponse
15 expect(@labels.first.name).to eq("Backlog")
17 expect(@labels.first.name).to eq('Backlog')
1618 end
1719 end
1820
19 describe ".delete" do
21 describe '.delete' do
2022 before do
21 stub_delete("/projects/3/labels", "label")
22 @label = Gitlab.delete_label(3, "Backlog")
23 stub_delete('/projects/3/labels', 'label')
24 @label = Gitlab.delete_label(3, 'Backlog')
2325 end
2426
25 it "gets the correct resource" do
26 expect(a_delete("/projects/3/labels").
27 with(body: { name: 'Backlog' })).to have_been_made
27 it 'gets the correct resource' do
28 expect(a_delete('/projects/3/labels')
29 .with(body: { name: 'Backlog' })).to have_been_made
2830 end
2931
30 it "returns information about a deleted snippet" do
31 expect(@label.name).to eq("Backlog")
32 it 'returns information about a deleted snippet' do
33 expect(@label.name).to eq('Backlog')
3234 end
3335 end
3436
35 describe ".edit_label" do
37 describe '.edit_label' do
3638 before do
37 stub_put("/projects/3/labels", "label")
38 @label = Gitlab.edit_label(3, "TODO", new_name: 'Backlog')
39 stub_put('/projects/3/labels', 'label')
40 @label = Gitlab.edit_label(3, 'TODO', new_name: 'Backlog')
3941 end
4042
41 it "gets the correct resource" do
42 expect(a_put("/projects/3/labels").
43 with(body: { name: 'TODO', new_name: "Backlog" })).to have_been_made
43 it 'gets the correct resource' do
44 expect(a_put('/projects/3/labels')
45 .with(body: { name: 'TODO', new_name: 'Backlog' })).to have_been_made
4446 end
4547
46 it "returns information about an edited label" do
47 expect(@label.name).to eq("Backlog")
48 it 'returns information about an edited label' do
49 expect(@label.name).to eq('Backlog')
4850 end
4951 end
5052
51 describe ".create_label" do
53 describe '.create_label' do
5254 before do
53 stub_post("/projects/3/labels", "label")
55 stub_post('/projects/3/labels', 'label')
5456 @label = Gitlab.create_label(3, 'Backlog', '#DD10AA')
5557 end
5658
57 it "gets the correct resource" do
58 expect(a_post("/projects/3/labels").
59 with(body: { name: 'Backlog', color: '#DD10AA' })).to have_been_made
59 it 'gets the correct resource' do
60 expect(a_post('/projects/3/labels')
61 .with(body: { name: 'Backlog', color: '#DD10AA' })).to have_been_made
6062 end
6163
62 it "returns information about a created label" do
64 it 'returns information about a created label' do
6365 expect(@label.name).to eq('Backlog')
6466 expect(@label.color).to eq('#DD10AA')
6567 end
6668 end
6769
68 describe ".subscribe_to_label" do
70 describe '.subscribe_to_label' do
6971 before do
70 stub_post("/projects/3/labels/Backlog/subscribe", "label")
72 stub_post('/projects/3/labels/Backlog/subscribe', 'label')
7173 @label = Gitlab.subscribe_to_label(3, 'Backlog')
7274 end
7375
74 it "gets the correct resource" do
75 expect(a_post("/projects/3/labels/Backlog/subscribe")).to have_been_made
76 it 'gets the correct resource' do
77 expect(a_post('/projects/3/labels/Backlog/subscribe')).to have_been_made
7678 end
7779
78 it "returns information about the label subscribed to" do
80 it 'returns information about the label subscribed to' do
7981 expect(@label.name).to eq('Backlog')
8082 expect(@label.subscribed).to eq(true)
8183 end
8284 end
8385
84 describe ".unsubscribe_from_label" do
86 describe '.unsubscribe_from_label' do
8587 before do
86 stub_post("/projects/3/labels/Backlog/unsubscribe", "label_unsubscribe")
88 stub_post('/projects/3/labels/Backlog/unsubscribe', 'label_unsubscribe')
8789 @label = Gitlab.unsubscribe_from_label(3, 'Backlog')
8890 end
8991
90 it "gets the correct resource" do
91 expect(a_post("/projects/3/labels/Backlog/unsubscribe")).to have_been_made
92 it 'gets the correct resource' do
93 expect(a_post('/projects/3/labels/Backlog/unsubscribe')).to have_been_made
9294 end
9395
94 it "returns information about the label subscribed to" do
96 it 'returns information about the label subscribed to' do
9597 expect(@label.name).to eq('Backlog')
9698 expect(@label.subscribed).to eq(false)
9799 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
35 describe '.project_merge_request_approvals' do
46 before do
5 stub_get("/projects/1/approvals", 'project_merge_request_approvals')
7 stub_get('/projects/1/approvals', 'project_merge_request_approvals')
68 @project_mr_approvals = Gitlab.project_merge_request_approvals(1)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/1/approvals")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/1/approvals')).to have_been_made
1113 end
1214
13 it "returns the correct objectified hash" do
15 it 'returns the correct objectified hash' do
1416 expect(@project_mr_approvals).to be_a Gitlab::ObjectifiedHash
1517 end
1618 end
1820 describe '.edit_project_merge_request_approvals' do
1921 before do
2022 body = { approvals_before_merge: '3', reset_approvals_on_push: 'false', disable_overriding_approvers_per_merge_request: 'true' }
21 stub_post("/projects/1/approvals", 'project_merge_request_approvals').with(body: body)
23 stub_post('/projects/1/approvals', 'project_merge_request_approvals').with(body: body)
2224 @project_mr_approvals = Gitlab.edit_project_merge_request_approvals(1, approvals_before_merge: 3, reset_approvals_on_push: false, disable_overriding_approvers_per_merge_request: true)
2325 end
2426
2527 it 'gets the correct resource' do
2628 body = { approvals_before_merge: '3', reset_approvals_on_push: 'false', disable_overriding_approvers_per_merge_request: 'true' }
27 expect(a_post("/projects/1/approvals").
28 with(body: body)).to have_been_made
29 expect(a_post('/projects/1/approvals')
30 .with(body: body)).to have_been_made
2931 end
3032
31 it "returns the correct updated configuration" do
33 it 'returns the correct updated configuration' do
3234 expect(@project_mr_approvals).to be_a Gitlab::ObjectifiedHash
3335 expect(@project_mr_approvals.approvals_before_merge).to eq 3
3436 expect(@project_mr_approvals.reset_approvals_on_push).to eq false
3840
3941 describe '.edit_project_approvers' do
4042 before do
41 body = {"approver_ids": ['5'], "approver_group_ids": ['1']}
42 stub_put("/projects/1/approvals", 'project_merge_request_approvals').with(body: body)
43 body = { "approver_ids": ['5'], "approver_group_ids": ['1'] }
44 stub_put('/projects/1/approvals', 'project_merge_request_approvals').with(body: body)
4345 @project_mr_approvals = Gitlab.edit_project_approvers(1, approver_ids: [5], approver_group_ids: [1])
4446 end
4547
4648 it 'gets the correct resource' do
47 body = {"approver_ids": ['5'], "approver_group_ids": ['1']}
48 expect(a_put("/projects/1/approvals").
49 with(body: body)).to have_been_made
49 body = { "approver_ids": ['5'], "approver_group_ids": ['1'] }
50 expect(a_put('/projects/1/approvals')
51 .with(body: body)).to have_been_made
5052 end
5153
5254 it 'returns the correct updated configuration' do
5355 expect(@project_mr_approvals).to be_a Gitlab::ObjectifiedHash
54 expect(@project_mr_approvals.approvers.map{|approver| approver['user']['id']}).to eq [5]
55 expect(@project_mr_approvals.approver_groups.map{|approver_group| approver_group['group']['id']}).to eq [1]
56 expect(@project_mr_approvals.approvers.map { |approver| approver['user']['id'] }).to eq [5]
57 expect(@project_mr_approvals.approver_groups.map { |approver_group| approver_group['group']['id'] }).to eq [1]
5658 end
5759 end
5860
5961 describe '.merge_request_approvals' do
6062 before do
61 stub_get("/projects/1/merge_requests/5/approvals", 'merge_request_approvals')
63 stub_get('/projects/1/merge_requests/5/approvals', 'merge_request_approvals')
6264 @merge_request_approvals = Gitlab.merge_request_approvals(1, 5)
6365 end
6466
6567 it 'gets the correct resource' do
66 expect(a_get("/projects/1/merge_requests/5/approvals")).to have_been_made
68 expect(a_get('/projects/1/merge_requests/5/approvals')).to have_been_made
6769 end
6870
6971 it 'returns the correct objectified hash' do
7678 describe '.edit_merge_request_approvals' do
7779 before do
7880 body = { approvals_required: '2' }
79 stub_post("/projects/1/merge_requests/5/approvals", 'merge_request_approvals').with(body: body)
81 stub_post('/projects/1/merge_requests/5/approvals', 'merge_request_approvals').with(body: body)
8082 @merge_request_approvals = Gitlab.edit_merge_request_approvals(1, 5, approvals_required: 2)
8183 end
8284
8385 it 'gets the correct resource' do
8486 body = { approvals_required: '2' }
85 expect(a_post("/projects/1/merge_requests/5/approvals").with(body: body)).to have_been_made
87 expect(a_post('/projects/1/merge_requests/5/approvals').with(body: body)).to have_been_made
8688 end
8789
8890 it 'returns the correct objectified hash' do
9395
9496 describe '.edit_merge_request_approvers' do
9597 before do
96 body = {"approver_ids": ['1'], "approver_group_ids": ['5']}
97 stub_put("/projects/1/merge_requests/5/approvals", 'merge_request_approvals').with(body: body)
98 body = { "approver_ids": ['1'], "approver_group_ids": ['5'] }
99 stub_put('/projects/1/merge_requests/5/approvals', 'merge_request_approvals').with(body: body)
98100 @merge_request_approvals = Gitlab.edit_merge_request_approvers(1, 5, approver_ids: [1], approver_group_ids: [5])
99101 end
100102
101103 it 'gets the correct resource' do
102 body = {"approver_ids": ['1'], "approver_group_ids": ['5']}
103 expect(a_put("/projects/1/merge_requests/5/approvals").
104 with(body: body)).to have_been_made
104 body = { "approver_ids": ['1'], "approver_group_ids": ['5'] }
105 expect(a_put('/projects/1/merge_requests/5/approvals')
106 .with(body: body)).to have_been_made
105107 end
106108
107109 it 'returns the correct updated configuration' do
108110 expect(@merge_request_approvals).to be_a Gitlab::ObjectifiedHash
109 expect(@merge_request_approvals.approvers.map{|approver| approver['user']['id']}).to eq [1]
110 expect(@merge_request_approvals.approver_groups.map{|approver_group| approver_group['group']['id']}).to eq [5]
111 expect(@merge_request_approvals.approvers.map { |approver| approver['user']['id'] }).to eq [1]
112 expect(@merge_request_approvals.approver_groups.map { |approver_group| approver_group['group']['id'] }).to eq [5]
111113 end
112114 end
113115
114116 describe '.approve_merge_request' do
115117 before do
116 stub_post("/projects/1/merge_requests/5/approve", 'merge_request_approvals')
118 stub_post('/projects/1/merge_requests/5/approve', 'merge_request_approvals')
117119 @merge_request_approvals = Gitlab.approve_merge_request(1, 5)
118120 end
119121
120122 it 'gets the correct resource' do
121 expect(a_post("/projects/1/merge_requests/5/approve")).to have_been_made
123 expect(a_post('/projects/1/merge_requests/5/approve')).to have_been_made
122124 end
123125
124126 it 'returns the correct updated configuration' do
129131
130132 describe '.unapprove_merge_request' do
131133 before do
132 stub_post("/projects/1/merge_requests/5/unapprove", 'merge_request_approvals')
134 stub_post('/projects/1/merge_requests/5/unapprove', 'merge_request_approvals')
133135 @merge_request_approvals = Gitlab.unapprove_merge_request(1, 5)
134136 end
135137
136138 it 'gets the correct resource' do
137 expect(a_post("/projects/1/merge_requests/5/unapprove")).to have_been_made
139 expect(a_post('/projects/1/merge_requests/5/unapprove')).to have_been_made
138140 end
139141 end
140 end
142 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".user_merge_requests" do
4 before do
5 stub_get("/merge_requests", "merge_requests")
5 describe '.user_merge_requests' do
6 before do
7 stub_get('/merge_requests', 'merge_requests')
68 @user_merge_requests = Gitlab.user_merge_requests
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/merge_requests")).to have_been_made
11 end
12
13 it "returns a paginated response of user merge requests" do
11 it 'gets the correct resource' do
12 expect(a_get('/merge_requests')).to have_been_made
13 end
14
15 it 'returns a paginated response of user merge requests' do
1416 expect(@user_merge_requests).to be_a Gitlab::PaginatedResponse
1517 end
1618 end
1719
18 describe ".merge_requests" do
19 before do
20 stub_get("/projects/3/merge_requests", "merge_requests")
20 describe '.merge_requests' do
21 before do
22 stub_get('/projects/3/merge_requests', 'merge_requests')
2123 @merge_requests = Gitlab.merge_requests(3)
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_get("/projects/3/merge_requests")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_get('/projects/3/merge_requests')).to have_been_made
2628 end
2729
2830 it "returns a paginated response of project's merge requests" do
3133 end
3234 end
3335
34 describe ".merge_request" do
35 before do
36 stub_get("/projects/3/merge_requests/1", "merge_request")
36 describe '.merge_request' do
37 before do
38 stub_get('/projects/3/merge_requests/1', 'merge_request')
3739 @merge_request = Gitlab.merge_request(3, 1)
3840 end
3941
40 it "gets the correct resource" do
41 expect(a_get("/projects/3/merge_requests/1")).to have_been_made
42 end
43
44 it "returns information about a merge request" do
45 expect(@merge_request.project_id).to eq(3)
46 expect(@merge_request.assignee.name).to eq("Jack Smith")
47 end
48 end
49
50 describe ".create_merge_request" do
51 before do
52 stub_post("/projects/3/merge_requests", "merge_request")
53 end
54
55 it "returns information about a merge request" do
42 it 'gets the correct resource' do
43 expect(a_get('/projects/3/merge_requests/1')).to have_been_made
44 end
45
46 it 'returns information about a merge request' do
47 expect(@merge_request.project_id).to eq(3)
48 expect(@merge_request.assignee.name).to eq('Jack Smith')
49 end
50 end
51
52 describe '.merge_request_pipelines' do
53 before do
54 stub_get('/projects/3/merge_requests/1/pipelines', 'pipelines')
55 @pipelines = Gitlab.merge_request_pipelines(3, 1)
56 end
57
58 it 'gets the correct resource' do
59 expect(a_get('/projects/3/merge_requests/1/pipelines')).to have_been_made
60 end
61
62 it 'returns information about all pipelines in merge request' do
63 expect(@pipelines.first.id).to eq(47)
64 expect(@pipelines.first.status).to eq('pending')
65 end
66 end
67
68 describe '.create_merge_request' do
69 before do
70 stub_post('/projects/3/merge_requests', 'merge_request')
71 end
72
73 it 'returns information about a merge request' do
5674 @merge_request = Gitlab.create_merge_request(3, 'New feature',
5775 source_branch: 'api',
58 target_branch: 'master'
59 )
60 expect(@merge_request.project_id).to eq(3)
61 expect(@merge_request.assignee.name).to eq("Jack Smith")
62 end
63 end
64
65 describe ".update_merge_request" do
66 before do
67 stub_put("/projects/3/merge_requests/2", "merge_request").
68 with(body: {
69 assignee_id: '1',
70 target_branch: 'master',
71 title: 'A different new feature'
72 })
76 target_branch: 'master')
77 expect(@merge_request.project_id).to eq(3)
78 expect(@merge_request.assignee.name).to eq('Jack Smith')
79 end
80 end
81
82 describe '.update_merge_request' do
83 before do
84 stub_put('/projects/3/merge_requests/2', 'merge_request')
85 .with(body: {
86 assignee_id: '1',
87 target_branch: 'master',
88 title: 'A different new feature'
89 })
7390 @merge_request = Gitlab.update_merge_request(3, 2,
7491 assignee_id: '1',
7592 target_branch: 'master',
76 title: 'A different new feature'
77 )
78 end
79
80 it "gets the correct resource" do
81 expect(a_put("/projects/3/merge_requests/2").
82 with(body: {
83 assignee_id: '1',
84 target_branch: 'master',
85 title: 'A different new feature'
86 })).to have_been_made
87 end
88
89 it "returns information about a merge request" do
90 expect(@merge_request.project_id).to eq(3)
91 expect(@merge_request.assignee.name).to eq("Jack Smith")
92 end
93 end
94
95 describe ".accept_merge_request" do
96 before do
97 stub_put("/projects/5/merge_requests/42/merge", "merge_request").
98 with(body: { merge_commit_message: 'Nice!' })
93 title: 'A different new feature')
94 end
95
96 it 'gets the correct resource' do
97 expect(a_put('/projects/3/merge_requests/2')
98 .with(body: {
99 assignee_id: '1',
100 target_branch: 'master',
101 title: 'A different new feature'
102 })).to have_been_made
103 end
104
105 it 'returns information about a merge request' do
106 expect(@merge_request.project_id).to eq(3)
107 expect(@merge_request.assignee.name).to eq('Jack Smith')
108 end
109 end
110
111 describe '.accept_merge_request' do
112 before do
113 stub_put('/projects/5/merge_requests/42/merge', 'merge_request')
114 .with(body: { merge_commit_message: 'Nice!' })
99115 @merge_request = Gitlab.accept_merge_request(5, 42, merge_commit_message: 'Nice!')
100116 end
101117
102 it "gets the correct resource" do
103 expect(a_put("/projects/5/merge_requests/42/merge").
104 with(body: { merge_commit_message: 'Nice!' })).to have_been_made
105 end
106
107 it "returns information about merged merge request" do
108 expect(@merge_request.project_id).to eq(3)
109 expect(@merge_request.assignee.name).to eq("Jack Smith")
110 end
111 end
112
113 describe ".merge_request_comments" do
114 before do
115 stub_get("/projects/3/merge_requests/2/notes", "merge_request_comments")
118 it 'gets the correct resource' do
119 expect(a_put('/projects/5/merge_requests/42/merge')
120 .with(body: { merge_commit_message: 'Nice!' })).to have_been_made
121 end
122
123 it 'returns information about merged merge request' do
124 expect(@merge_request.project_id).to eq(3)
125 expect(@merge_request.assignee.name).to eq('Jack Smith')
126 end
127 end
128
129 describe '.merge_request_comments' do
130 before do
131 stub_get('/projects/3/merge_requests/2/notes', 'merge_request_comments')
116132 @merge_request = Gitlab.merge_request_comments(3, 2)
117133 end
118134
119 it "gets the correct resource" do
120 expect(a_get("/projects/3/merge_requests/2/notes")).to have_been_made
135 it 'gets the correct resource' do
136 expect(a_get('/projects/3/merge_requests/2/notes')).to have_been_made
121137 end
122138
123139 it "returns merge request's comments" do
124140 expect(@merge_request).to be_an Gitlab::PaginatedResponse
125141 expect(@merge_request.length).to eq(2)
126 expect(@merge_request[0].note).to eq("this is the 1st comment on the 2merge merge request")
142 expect(@merge_request[0].note).to eq('this is the 1st comment on the 2merge merge request')
127143 expect(@merge_request[0].author.id).to eq(11)
128 expect(@merge_request[1].note).to eq("another discussion point on the 2merge request")
144 expect(@merge_request[1].note).to eq('another discussion point on the 2merge request')
129145 expect(@merge_request[1].author.id).to eq(12)
130146 end
131147 end
132148
133 describe ".create_merge_request_comment" do
134 before do
135 stub_post("/projects/3/merge_requests/2/notes", "merge_request_comment")
149 describe '.create_merge_request_comment' do
150 before do
151 stub_post('/projects/3/merge_requests/2/notes', 'merge_request_comment')
136152 @merge_request = Gitlab.create_merge_request_comment(3, 2, 'Cool Merge Request!')
137153 end
138154
139 it "gets the correct resource" do
140 expect(a_post("/projects/3/merge_requests/2/notes")).to have_been_made
141 end
142
143 it "returns information about a merge request" do
155 it 'gets the correct resource' do
156 expect(a_post('/projects/3/merge_requests/2/notes')).to have_been_made
157 end
158
159 it 'returns information about a merge request' do
144160 expect(@merge_request.note).to eq('Cool Merge Request!')
145161 expect(@merge_request.author.id).to eq(1)
146162 end
147163 end
148164
149 describe ".merge_request_changes" do
150 before do
151 stub_get("/projects/3/merge_requests/2/changes", "merge_request_changes")
165 describe '.merge_request_changes' do
166 before do
167 stub_get('/projects/3/merge_requests/2/changes', 'merge_request_changes')
152168 @mr_changes = Gitlab.merge_request_changes(3, 2)
153169 end
154170
155 it "gets the correct resource" do
156 expect(a_get("/projects/3/merge_requests/2/changes")).to have_been_made
157 end
158
159 it "returns the merge request changes" do
171 it 'gets the correct resource' do
172 expect(a_get('/projects/3/merge_requests/2/changes')).to have_been_made
173 end
174
175 it 'returns the merge request changes' do
160176 expect(@mr_changes.changes).to be_a Array
161177 expect(@mr_changes.changes.first['old_path']).to eq('lib/omniauth/builder.rb')
162178 expect(@mr_changes.id).to eq(2)
166182 end
167183 end
168184
169 describe ".merge_request_commits" do
170 before do
171 stub_get("/projects/3/merge_requests/2/commits", "merge_request_commits")
185 describe '.merge_request_commits' do
186 before do
187 stub_get('/projects/3/merge_requests/2/commits', 'merge_request_commits')
172188 @mr_commits = Gitlab.merge_request_commits(3, 2)
173189 end
174190
175 it "gets the correct resource" do
176 expect(a_get("/projects/3/merge_requests/2/commits")).to have_been_made
177 end
178
179 it "returns the merge request commits" do
191 it 'gets the correct resource' do
192 expect(a_get('/projects/3/merge_requests/2/commits')).to have_been_made
193 end
194
195 it 'returns the merge request commits' do
180196 expect(@mr_commits).to be_a Gitlab::PaginatedResponse
181197 expect(@mr_commits.size).to eq 2
182 expect(@mr_commits.first.id).to eq "a2da7552f26d5b46a6a09bb8b7b066e3a102be7d"
183 expect(@mr_commits.first.short_id).to eq "a2da7552"
184 expect(@mr_commits.first.title).to eq "piyo"
185 expect(@mr_commits.first.author_name).to eq "example"
186 expect(@mr_commits.first.author_email).to eq "example@example.com"
187 expect(@mr_commits[1].short_id).to eq "3ce50959"
188 expect(@mr_commits[1].title).to eq "hoge"
189 end
190 end
191
192 describe ".merge_request_closes_issues" do
193 before do
194 stub_get("/projects/5/merge_requests/1/closes_issues", "merge_request_closes_issues")
198 expect(@mr_commits.first.id).to eq 'a2da7552f26d5b46a6a09bb8b7b066e3a102be7d'
199 expect(@mr_commits.first.short_id).to eq 'a2da7552'
200 expect(@mr_commits.first.title).to eq 'piyo'
201 expect(@mr_commits.first.author_name).to eq 'example'
202 expect(@mr_commits.first.author_email).to eq 'example@example.com'
203 expect(@mr_commits[1].short_id).to eq '3ce50959'
204 expect(@mr_commits[1].title).to eq 'hoge'
205 end
206 end
207
208 describe '.merge_request_closes_issues' do
209 before do
210 stub_get('/projects/5/merge_requests/1/closes_issues', 'merge_request_closes_issues')
195211 @issues = Gitlab.merge_request_closes_issues(5, 1)
196212 end
197213
198 it "gets the correct resource" do
199 expect(a_get("/projects/5/merge_requests/1/closes_issues")).to have_been_made
200 end
201
202 it "returns a paginated response of the issues the merge_request will close" do
214 it 'gets the correct resource' do
215 expect(a_get('/projects/5/merge_requests/1/closes_issues')).to have_been_made
216 end
217
218 it 'returns a paginated response of the issues the merge_request will close' do
203219 expect(@issues).to be_a(Gitlab::PaginatedResponse)
204 expect(@issues.first.title).to eq("Merge request 1 issue 1")
220 expect(@issues.first.title).to eq('Merge request 1 issue 1')
205221 expect(@issues.size).to eq(2)
206222 end
207223 end
208224
209 describe ".subscribe_to_merge_request" do
210 before do
211 stub_post("/projects/3/merge_requests/2/subscribe", "merge_request")
225 describe '.subscribe_to_merge_request' do
226 before do
227 stub_post('/projects/3/merge_requests/2/subscribe', 'merge_request')
212228 @merge_request = Gitlab.subscribe_to_merge_request(3, 2)
213229 end
214230
215 it "gets the correct resource" do
216 expect(a_post("/projects/3/merge_requests/2/subscribe")).to have_been_made
217 end
218
219 it "returns information about a merge request" do
220 expect(@merge_request.project_id).to eq(3)
221 end
222 end
223
224 describe ".unsubscribe_from_merge_request" do
225 before do
226 stub_post("/projects/3/merge_requests/2/unsubscribe", "merge_request")
231 it 'gets the correct resource' do
232 expect(a_post('/projects/3/merge_requests/2/subscribe')).to have_been_made
233 end
234
235 it 'returns information about a merge request' do
236 expect(@merge_request.project_id).to eq(3)
237 end
238 end
239
240 describe '.unsubscribe_from_merge_request' do
241 before do
242 stub_post('/projects/3/merge_requests/2/unsubscribe', 'merge_request')
227243 @merge_request = Gitlab.unsubscribe_from_merge_request(3, 2)
228244 end
229245
230 it "gets the correct resource" do
231 expect(a_post("/projects/3/merge_requests/2/unsubscribe")).to have_been_made
232 end
233
234 it "returns information about a merge request" do
235 expect(@merge_request.project_id).to eq(3)
236 end
237 end
238
239 describe ".merge_request_discussions" do
240 before do
241 stub_get("/projects/3/merge_requests/2/discussions", "merge_request_discussions")
246 it 'gets the correct resource' do
247 expect(a_post('/projects/3/merge_requests/2/unsubscribe')).to have_been_made
248 end
249
250 it 'returns information about a merge request' do
251 expect(@merge_request.project_id).to eq(3)
252 end
253 end
254
255 describe '.merge_request_discussions' do
256 before do
257 stub_get('/projects/3/merge_requests/2/discussions', 'merge_request_discussions')
242258 @discussions = Gitlab.merge_request_discussions(3, 2)
243259 end
244260
245 it "gets the correct resource" do
246 expect(a_get("/projects/3/merge_requests/2/discussions")).to have_been_made
247 end
248
249 it "returns information about the discussions" do
261 it 'gets the correct resource' do
262 expect(a_get('/projects/3/merge_requests/2/discussions')).to have_been_made
263 end
264
265 it 'returns information about the discussions' do
250266 expect(@discussions.length).to eq(1)
251267 expect(@discussions.first.id).to eq('7d66bf19bf835e6a4666130544ba1b5c343fc705')
252268 end
253269 end
254270
255 describe ".merge_request_discussion" do
256 before do
257 stub_get("/projects/3/merge_requests/2/discussions/1", "merge_request_discussion")
271 describe '.merge_request_discussion' do
272 before do
273 stub_get('/projects/3/merge_requests/2/discussions/1', 'merge_request_discussion')
258274 @discussion = Gitlab.merge_request_discussion(3, 2, 1)
259275 end
260276
261 it "gets the correct resource" do
262 expect(a_get("/projects/3/merge_requests/2/discussions/1")).to have_been_made
263 end
264
265 it "returns information about the discussions" do
277 it 'gets the correct resource' do
278 expect(a_get('/projects/3/merge_requests/2/discussions/1')).to have_been_made
279 end
280
281 it 'returns information about the discussions' do
266282 expect(@discussion.id).to eq('7d66bf19bf835e6a4666130544ba1b5c343fc705')
267283 end
268284 end
269285
270 describe ".create_merge_request_discussion" do
271 before do
272 stub_post("/projects/3/merge_requests/2/discussions", "merge_request_discussion")
273 @discussion = Gitlab.create_merge_request_discussion(3, 2, body: 'Discussion', position: {old_line: 1})
274 end
275
276 it "posts the correct resource" do
277 expect(a_post("/projects/3/merge_requests/2/discussions").
278 with(body: 'body=Discussion&position[old_line]=1')).to have_been_made
279 end
280
281 it "returns information about the discussions" do
286 describe '.create_merge_request_discussion' do
287 before do
288 stub_post('/projects/3/merge_requests/2/discussions', 'merge_request_discussion')
289 @discussion = Gitlab.create_merge_request_discussion(3, 2, body: 'Discussion', position: { old_line: 1 })
290 end
291
292 it 'posts the correct resource' do
293 expect(a_post('/projects/3/merge_requests/2/discussions')
294 .with(body: 'body=Discussion&position[old_line]=1')).to have_been_made
295 end
296
297 it 'returns information about the discussions' do
282298 expect(@discussion.id).to eq('7d66bf19bf835e6a4666130544ba1b5c343fc705')
283299 end
284300 end
285301
286 describe ".resolve_merge_request_discussion" do
287 before do
288 stub_put("/projects/3/merge_requests/2/discussions/1", "merge_request_discussion")
302 describe '.resolve_merge_request_discussion' do
303 before do
304 stub_put('/projects/3/merge_requests/2/discussions/1', 'merge_request_discussion')
289305 @discussion = Gitlab.resolve_merge_request_discussion(3, 2, 1, resolved: true)
290306 end
291307
292 it "puts the correct resource" do
293 expect(a_put("/projects/3/merge_requests/2/discussions/1").
294 with(body: 'resolved=true')).to have_been_made
295 end
296
297 it "returns information about the discussions" do
308 it 'puts the correct resource' do
309 expect(a_put('/projects/3/merge_requests/2/discussions/1')
310 .with(body: 'resolved=true')).to have_been_made
311 end
312
313 it 'returns information about the discussions' do
298314 expect(@discussion.id).to eq('7d66bf19bf835e6a4666130544ba1b5c343fc705')
299315 note = @discussion.notes.first
300316 expect(note['id']).to eq(1758)
301317 end
302318 end
303319
304 describe ".create_merge_request_discussion_note" do
305 before do
306 stub_post("/projects/3/merge_requests/2/discussions/1/notes", "merge_request_discussion_note")
320 describe '.create_merge_request_discussion_note' do
321 before do
322 stub_post('/projects/3/merge_requests/2/discussions/1/notes', 'merge_request_discussion_note')
307323 @note = Gitlab.create_merge_request_discussion_note(3, 2, 1, body: 'note')
308324 end
309325
310 it "posts the correct resource" do
311 expect(a_post("/projects/3/merge_requests/2/discussions/1/notes").
312 with(body: 'body=note')).to have_been_made
313 end
314
315 it "returns information about the note" do
326 it 'posts the correct resource' do
327 expect(a_post('/projects/3/merge_requests/2/discussions/1/notes')
328 .with(body: 'body=note')).to have_been_made
329 end
330
331 it 'returns information about the note' do
316332 expect(@note.id).to eq(1775)
317333 end
318334 end
319335
320 describe ".update_merge_request_discussion_note" do
321 before do
322 stub_put("/projects/3/merge_requests/2/discussions/1/notes/1", "merge_request_discussion_note")
336 describe '.update_merge_request_discussion_note' do
337 before do
338 stub_put('/projects/3/merge_requests/2/discussions/1/notes/1', 'merge_request_discussion_note')
323339 @note = Gitlab.update_merge_request_discussion_note(3, 2, 1, 1, body: 'note2')
324340 end
325341
326 it "puts the correct resource" do
327 expect(a_put("/projects/3/merge_requests/2/discussions/1/notes/1").
328 with(body: 'body=note2')).to have_been_made
329 end
330
331 it "returns information about the note" do
342 it 'puts the correct resource' do
343 expect(a_put('/projects/3/merge_requests/2/discussions/1/notes/1')
344 .with(body: 'body=note2')).to have_been_made
345 end
346
347 it 'returns information about the note' do
332348 expect(@note.id).to eq(1775)
333349 end
334350 end
335351
336 describe ".delete_merge_request_discussion_note" do
337 before do
338 stub_request(:delete, "https://api.example.com/projects/3/merge_requests/2/discussions/1/notes/1").to_return(body: '')
352 describe '.delete_merge_request_discussion_note' do
353 before do
354 stub_request(:delete, 'https://api.example.com/projects/3/merge_requests/2/discussions/1/notes/1').to_return(body: '')
339355 @note = Gitlab.delete_merge_request_discussion_note(3, 2, 1, 1)
340356 end
341357
342 it "deletes the correct resource" do
343 expect(a_delete("/projects/3/merge_requests/2/discussions/1/notes/1")).to have_been_made
344 end
345
346 it "returns nothing" do
358 it 'deletes the correct resource' do
359 expect(a_delete('/projects/3/merge_requests/2/discussions/1/notes/1')).to have_been_made
360 end
361
362 it 'returns nothing' do
347363 expect(@note).to be_falsy
348364 end
349365 end
366
367 describe '.merge_request_diff_versions' do
368 before do
369 stub_get('/projects/3/merge_requests/105/versions', 'merge_request_diff_versions')
370 @versions = Gitlab.merge_request_diff_versions(3, 105)
371 end
372
373 it 'gets the correct resource' do
374 expect(a_get('/projects/3/merge_requests/105/versions')).to have_been_made
375 end
376
377 it 'returns an array of the versions' do
378 expect(@versions.length).to eq(2)
379 expect(@versions.first.head_commit_sha).to eq('33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30')
380 end
381 end
382
383 describe '.merge_request_diff_version' do
384 before do
385 stub_get('/projects/3/merge_requests/105/versions/1', 'merge_request_diff_version')
386 @diff = Gitlab.merge_request_diff_version(3, 105, 1)
387 end
388
389 it 'gets the correct resource' do
390 expect(a_get('/projects/3/merge_requests/105/versions/1')).to have_been_made
391 end
392
393 it 'returns diff, with array of diffs in version' do
394 expect(@diff.diffs).to be_a Array
395 expect(@diff.diffs.first['old_path']).to eq('LICENSE')
396 end
397 end
350398 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".milestones" do
5 describe '.milestones' do
46 before do
5 stub_get("/projects/3/milestones", "milestones")
7 stub_get('/projects/3/milestones', 'milestones')
68 @milestones = Gitlab.milestones(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/milestones")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/milestones')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of project's milestones" do
1618 end
1719 end
1820
19 describe ".milestone" do
21 describe '.milestone' do
2022 before do
21 stub_get("/projects/3/milestones/1", "milestone")
23 stub_get('/projects/3/milestones/1', 'milestone')
2224 @milestone = Gitlab.milestone(3, 1)
2325 end
2426
25 it "gets the correct resource" do
26 expect(a_get("/projects/3/milestones/1")).to have_been_made
27 it 'gets the correct resource' do
28 expect(a_get('/projects/3/milestones/1')).to have_been_made
2729 end
2830
29 it "returns information about a milestone" do
31 it 'returns information about a milestone' do
3032 expect(@milestone.project_id).to eq(3)
3133 end
3234 end
3335
34 describe ".milestone_issues" do
36 describe '.milestone_issues' do
3537 before do
36 stub_get("/projects/3/milestones/1/issues", "milestone_issues")
38 stub_get('/projects/3/milestones/1/issues', 'milestone_issues')
3739 @milestone_issues = Gitlab.milestone_issues(3, 1)
3840 end
3941
40 it "gets the correct resource" do
41 expect(a_get("/projects/3/milestones/1/issues")).to have_been_made
42 it 'gets the correct resource' do
43 expect(a_get('/projects/3/milestones/1/issues')).to have_been_made
4244 end
4345
4446 it "returns a paginated response of milestone's issues" do
4749 end
4850 end
4951
50 describe ".milestone_merge_requests" do
52 describe '.milestone_merge_requests' do
5153 before do
52 stub_get("/projects/3/milestones/1/merge_requests", "milestone_merge_requests")
54 stub_get('/projects/3/milestones/1/merge_requests', 'milestone_merge_requests')
5355 @milestone_merge_requests = Gitlab.milestone_merge_requests(3, 1)
5456 end
5557
56 it "gets the correct resource" do
57 expect(a_get("/projects/3/milestones/1/merge_requests")).to have_been_made
58 it 'gets the correct resource' do
59 expect(a_get('/projects/3/milestones/1/merge_requests')).to have_been_made
5860 end
5961
6062 it "returns a paginated response of milestone's merge_requests" do
6365 end
6466 end
6567
66 describe ".create_milestone" do
68 describe '.create_milestone' do
6769 before do
68 stub_post("/projects/3/milestones", "milestone")
70 stub_post('/projects/3/milestones', 'milestone')
6971 @milestone = Gitlab.create_milestone(3, 'title')
7072 end
7173
72 it "gets the correct resource" do
73 expect(a_post("/projects/3/milestones").
74 with(body: { title: 'title' })).to have_been_made
74 it 'gets the correct resource' do
75 expect(a_post('/projects/3/milestones')
76 .with(body: { title: 'title' })).to have_been_made
7577 end
7678
77 it "returns information about a created milestone" do
79 it 'returns information about a created milestone' do
7880 expect(@milestone.project_id).to eq(3)
7981 end
8082 end
8183
82 describe ".edit_milestone" do
84 describe '.edit_milestone' do
8385 before do
84 stub_put("/projects/3/milestones/33", "milestone")
86 stub_put('/projects/3/milestones/33', 'milestone')
8587 @milestone = Gitlab.edit_milestone(3, 33, title: 'title')
8688 end
8789
88 it "gets the correct resource" do
89 expect(a_put("/projects/3/milestones/33").
90 with(body: { title: 'title' })).to have_been_made
90 it 'gets the correct resource' do
91 expect(a_put('/projects/3/milestones/33')
92 .with(body: { title: 'title' })).to have_been_made
9193 end
9294
93 it "returns information about an edited milestone" do
95 it 'returns information about an edited milestone' do
9496 expect(@milestone.project_id).to eq(3)
9597 end
9698 end
99
100 describe '.delete_milestone' do
101 before do
102 stub_delete('/projects/3/milestones/33', 'empty')
103 @milestone = Gitlab.delete_milestone(3, 33)
104 end
105
106 it 'gets the correct resource' do
107 expect(a_delete('/projects/3/milestones/33')).to have_been_made
108 end
109 end
97110 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
35 it { is_expected.to respond_to :namespaces }
46
5 describe ".namespaces" do
7 describe '.namespaces' do
68 before do
7 stub_get("/namespaces", "namespaces")
9 stub_get('/namespaces', 'namespaces')
810 @namespaces = Gitlab.namespaces
911 end
1012
11 it "gets the correct resource" do
12 expect(a_get("/namespaces")).to have_been_made
13 it 'gets the correct resource' do
14 expect(a_get('/namespaces')).to have_been_made
1315 end
1416
15 it "returns a paginated response of namespaces" do
17 it 'returns a paginated response of namespaces' do
1618 expect(@namespaces).to be_a Gitlab::PaginatedResponse
17 expect(@namespaces.first.path).to eq("john")
18 expect(@namespaces.first.kind).to eq("user")
19 expect(@namespaces.first.path).to eq('john')
20 expect(@namespaces.first.kind).to eq('user')
1921 end
2022 end
2123 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe "notes" do
4 context "when wall notes" do
5 before do
6 stub_get("/projects/3/notes", "notes")
5 describe 'notes' do
6 context 'when wall notes' do
7 before do
8 stub_get('/projects/3/notes', 'notes')
79 @notes = Gitlab.notes(3)
810 end
911
10 it "gets the correct resource" do
11 expect(a_get("/projects/3/notes")).to have_been_made
12 end
13
14 it "returns a paginated response of notes" do
12 it 'gets the correct resource' do
13 expect(a_get('/projects/3/notes')).to have_been_made
14 end
15
16 it 'returns a paginated response of notes' do
1517 expect(@notes).to be_a Gitlab::PaginatedResponse
16 expect(@notes.first.author.name).to eq("John Smith")
17 end
18 end
19
20 context "when issue notes" do
21 before do
22 stub_get("/projects/3/issues/7/notes", "notes")
18 expect(@notes.first.author.name).to eq('John Smith')
19 end
20 end
21
22 context 'when issue notes' do
23 before do
24 stub_get('/projects/3/issues/7/notes', 'notes')
2325 @notes = Gitlab.issue_notes(3, 7)
2426 end
2527
26 it "gets the correct resource" do
27 expect(a_get("/projects/3/issues/7/notes")).to have_been_made
28 end
29
30 it "returns a paginated response of notes" do
28 it 'gets the correct resource' do
29 expect(a_get('/projects/3/issues/7/notes')).to have_been_made
30 end
31
32 it 'returns a paginated response of notes' do
3133 expect(@notes).to be_a Gitlab::PaginatedResponse
32 expect(@notes.first.author.name).to eq("John Smith")
33 end
34 end
35
36 context "when snippet notes" do
37 before do
38 stub_get("/projects/3/snippets/7/notes", "notes")
34 expect(@notes.first.author.name).to eq('John Smith')
35 end
36 end
37
38 context 'when snippet notes' do
39 before do
40 stub_get('/projects/3/snippets/7/notes', 'notes')
3941 @notes = Gitlab.snippet_notes(3, 7)
4042 end
4143
42 it "gets the correct resource" do
43 expect(a_get("/projects/3/snippets/7/notes")).to have_been_made
44 end
45
46 it "returns a paginated response of notes" do
44 it 'gets the correct resource' do
45 expect(a_get('/projects/3/snippets/7/notes')).to have_been_made
46 end
47
48 it 'returns a paginated response of notes' do
4749 expect(@notes).to be_a Gitlab::PaginatedResponse
48 expect(@notes.first.author.name).to eq("John Smith")
49 end
50 end
51
52 context "when merge_request notes" do
53 before do
54 stub_get("/projects/3/merge_requests/7/notes", "notes")
50 expect(@notes.first.author.name).to eq('John Smith')
51 end
52 end
53
54 context 'when merge_request notes' do
55 before do
56 stub_get('/projects/3/merge_requests/7/notes', 'notes')
5557 @notes = Gitlab.merge_request_notes(3, 7)
5658 end
5759
58 it "gets the correct resource" do
59 expect(a_get("/projects/3/merge_requests/7/notes")).to have_been_made
60 end
61
62 it "returns a paginated response of notes" do
60 it 'gets the correct resource' do
61 expect(a_get('/projects/3/merge_requests/7/notes')).to have_been_made
62 end
63
64 it 'returns a paginated response of notes' do
6365 expect(@notes).to be_a Gitlab::PaginatedResponse
64 expect(@notes.first.author.name).to eq("John Smith")
65 end
66 end
67 end
68
69 describe "note" do
70 context "when wall note" do
71 before do
72 stub_get("/projects/3/notes/1201", "note")
66 expect(@notes.first.author.name).to eq('John Smith')
67 end
68 end
69 end
70
71 describe 'note' do
72 context 'when wall note' do
73 before do
74 stub_get('/projects/3/notes/1201', 'note')
7375 @note = Gitlab.note(3, 1201)
7476 end
7577
76 it "gets the correct resource" do
77 expect(a_get("/projects/3/notes/1201")).to have_been_made
78 end
79
80 it "returns information about a note" do
81 expect(@note.body).to eq("The solution is rather tricky")
82 expect(@note.author.name).to eq("John Smith")
83 end
84 end
85
86 context "when issue note" do
87 before do
88 stub_get("/projects/3/issues/7/notes/1201", "note")
78 it 'gets the correct resource' do
79 expect(a_get('/projects/3/notes/1201')).to have_been_made
80 end
81
82 it 'returns information about a note' do
83 expect(@note.body).to eq('The solution is rather tricky')
84 expect(@note.author.name).to eq('John Smith')
85 end
86 end
87
88 context 'when issue note' do
89 before do
90 stub_get('/projects/3/issues/7/notes/1201', 'note')
8991 @note = Gitlab.issue_note(3, 7, 1201)
9092 end
9193
92 it "gets the correct resource" do
93 expect(a_get("/projects/3/issues/7/notes/1201")).to have_been_made
94 end
95
96 it "returns information about a note" do
97 expect(@note.body).to eq("The solution is rather tricky")
98 expect(@note.author.name).to eq("John Smith")
99 end
100 end
101
102 context "when snippet note" do
103 before do
104 stub_get("/projects/3/snippets/7/notes/1201", "note")
94 it 'gets the correct resource' do
95 expect(a_get('/projects/3/issues/7/notes/1201')).to have_been_made
96 end
97
98 it 'returns information about a note' do
99 expect(@note.body).to eq('The solution is rather tricky')
100 expect(@note.author.name).to eq('John Smith')
101 end
102 end
103
104 context 'when snippet note' do
105 before do
106 stub_get('/projects/3/snippets/7/notes/1201', 'note')
105107 @note = Gitlab.snippet_note(3, 7, 1201)
106108 end
107109
108 it "gets the correct resource" do
109 expect(a_get("/projects/3/snippets/7/notes/1201")).to have_been_made
110 end
111
112 it "returns information about a note" do
113 expect(@note.body).to eq("The solution is rather tricky")
114 expect(@note.author.name).to eq("John Smith")
115 end
116 end
117
118 context "when merge request note" do
119 before do
120 stub_get("/projects/3/merge_requests/7/notes/1201", "note")
110 it 'gets the correct resource' do
111 expect(a_get('/projects/3/snippets/7/notes/1201')).to have_been_made
112 end
113
114 it 'returns information about a note' do
115 expect(@note.body).to eq('The solution is rather tricky')
116 expect(@note.author.name).to eq('John Smith')
117 end
118 end
119
120 context 'when merge request note' do
121 before do
122 stub_get('/projects/3/merge_requests/7/notes/1201', 'note')
121123 @note = Gitlab.merge_request_note(3, 7, 1201)
122124 end
123125
124 it "gets the correct resource" do
125 expect(a_get("/projects/3/merge_requests/7/notes/1201")).to have_been_made
126 end
127
128 it "returns information about a note" do
129 expect(@note.body).to eq("The solution is rather tricky")
130 expect(@note.author.name).to eq("John Smith")
131 end
132 end
133 end
134
135 describe "create note" do
136 context "when wall note" do
137 before do
138 stub_post("/projects/3/notes", "note")
139 @note = Gitlab.create_note(3, "The solution is rather tricky")
140 end
141
142 it "gets the correct resource" do
143 expect(a_post("/projects/3/notes").
144 with(body: { body: 'The solution is rather tricky' })).to have_been_made
145 end
146
147 it "returns information about a created note" do
148 expect(@note.body).to eq("The solution is rather tricky")
149 expect(@note.author.name).to eq("John Smith")
150 end
151 end
152
153 context "when issue note" do
154 before do
155 stub_post("/projects/3/issues/7/notes", "note")
156 @note = Gitlab.create_issue_note(3, 7, "The solution is rather tricky")
157 end
158
159 it "gets the correct resource" do
160 expect(a_post("/projects/3/issues/7/notes").
161 with(body: { body: 'The solution is rather tricky' })).to have_been_made
162 end
163
164 it "returns information about a created note" do
165 expect(@note.body).to eq("The solution is rather tricky")
166 expect(@note.author.name).to eq("John Smith")
167 end
168 end
169
170 context "when snippet note" do
171 before do
172 stub_post("/projects/3/snippets/7/notes", "note")
173 @note = Gitlab.create_snippet_note(3, 7, "The solution is rather tricky")
174 end
175
176 it "gets the correct resource" do
177 expect(a_post("/projects/3/snippets/7/notes").
178 with(body: { body: 'The solution is rather tricky' })).to have_been_made
179 end
180
181 it "returns information about a created note" do
182 expect(@note.body).to eq("The solution is rather tricky")
183 expect(@note.author.name).to eq("John Smith")
184 end
185 end
186
187 context "when merge_request note" do
188 before do
189 stub_post("/projects/3/merge_requests/7/notes", "note")
190 @note = Gitlab.create_merge_request_note(3, 7, "The solution is rather tricky")
191 end
192
193 it "gets the correct resource" do
194 expect(a_post("/projects/3/merge_requests/7/notes").
195 with(body: { body: 'The solution is rather tricky' })).to have_been_made
196 end
197
198 it "returns information about a created note" do
199 expect(@note.body).to eq("The solution is rather tricky")
200 expect(@note.author.name).to eq("John Smith")
201 end
202 end
203 end
204
205 describe "delete note" do
206 context "when wall note" do
207 before do
208 stub_delete("/projects/3/notes/1201", "note")
126 it 'gets the correct resource' do
127 expect(a_get('/projects/3/merge_requests/7/notes/1201')).to have_been_made
128 end
129
130 it 'returns information about a note' do
131 expect(@note.body).to eq('The solution is rather tricky')
132 expect(@note.author.name).to eq('John Smith')
133 end
134 end
135 end
136
137 describe 'create note' do
138 context 'when wall note' do
139 before do
140 stub_post('/projects/3/notes', 'note')
141 @note = Gitlab.create_note(3, 'The solution is rather tricky')
142 end
143
144 it 'gets the correct resource' do
145 expect(a_post('/projects/3/notes')
146 .with(body: { body: 'The solution is rather tricky' })).to have_been_made
147 end
148
149 it 'returns information about a created note' do
150 expect(@note.body).to eq('The solution is rather tricky')
151 expect(@note.author.name).to eq('John Smith')
152 end
153 end
154
155 context 'when issue note' do
156 before do
157 stub_post('/projects/3/issues/7/notes', 'note')
158 @note = Gitlab.create_issue_note(3, 7, 'The solution is rather tricky')
159 end
160
161 it 'gets the correct resource' do
162 expect(a_post('/projects/3/issues/7/notes')
163 .with(body: { body: 'The solution is rather tricky' })).to have_been_made
164 end
165
166 it 'returns information about a created note' do
167 expect(@note.body).to eq('The solution is rather tricky')
168 expect(@note.author.name).to eq('John Smith')
169 end
170 end
171
172 context 'when snippet note' do
173 before do
174 stub_post('/projects/3/snippets/7/notes', 'note')
175 @note = Gitlab.create_snippet_note(3, 7, 'The solution is rather tricky')
176 end
177
178 it 'gets the correct resource' do
179 expect(a_post('/projects/3/snippets/7/notes')
180 .with(body: { body: 'The solution is rather tricky' })).to have_been_made
181 end
182
183 it 'returns information about a created note' do
184 expect(@note.body).to eq('The solution is rather tricky')
185 expect(@note.author.name).to eq('John Smith')
186 end
187 end
188
189 context 'when merge_request note' do
190 before do
191 stub_post('/projects/3/merge_requests/7/notes', 'note')
192 @note = Gitlab.create_merge_request_note(3, 7, 'The solution is rather tricky')
193 end
194
195 it 'gets the correct resource' do
196 expect(a_post('/projects/3/merge_requests/7/notes')
197 .with(body: { body: 'The solution is rather tricky' })).to have_been_made
198 end
199
200 it 'returns information about a created note' do
201 expect(@note.body).to eq('The solution is rather tricky')
202 expect(@note.author.name).to eq('John Smith')
203 end
204 end
205 end
206
207 describe 'delete note' do
208 context 'when wall note' do
209 before do
210 stub_delete('/projects/3/notes/1201', 'note')
209211 @note = Gitlab.delete_note(3, 1201)
210212 end
211213
212 it "gets the correct resource" do
213 expect(a_delete("/projects/3/notes/1201")).to have_been_made
214 end
215
216 it "returns information about a deleted note" do
217 expect(@note.id).to eq(1201)
218 end
219 end
220
221 context "when issue note" do
222 before do
223 stub_delete("/projects/3/issues/7/notes/1201", "note")
214 it 'gets the correct resource' do
215 expect(a_delete('/projects/3/notes/1201')).to have_been_made
216 end
217
218 it 'returns information about a deleted note' do
219 expect(@note.id).to eq(1201)
220 end
221 end
222
223 context 'when issue note' do
224 before do
225 stub_delete('/projects/3/issues/7/notes/1201', 'note')
224226 @note = Gitlab.delete_issue_note(3, 7, 1201)
225227 end
226228
227 it "gets the correct resource" do
228 expect(a_delete("/projects/3/issues/7/notes/1201")).to have_been_made
229 end
230
231 it "returns information about a deleted issue note" do
232 expect(@note.id).to eq(1201)
233 end
234 end
235
236 context "when snippet note" do
237 before do
238 stub_delete("/projects/3/snippets/7/notes/1201", "note")
229 it 'gets the correct resource' do
230 expect(a_delete('/projects/3/issues/7/notes/1201')).to have_been_made
231 end
232
233 it 'returns information about a deleted issue note' do
234 expect(@note.id).to eq(1201)
235 end
236 end
237
238 context 'when snippet note' do
239 before do
240 stub_delete('/projects/3/snippets/7/notes/1201', 'note')
239241 @note = Gitlab.delete_snippet_note(3, 7, 1201)
240242 end
241243
242 it "gets the correct resource" do
243 expect(a_delete("/projects/3/snippets/7/notes/1201")).to have_been_made
244 end
245
246 it "returns information about a deleted snippet note" do
247 expect(@note.id).to eq(1201)
248 end
249 end
250
251 context "when merge request note" do
252 before do
253 stub_delete("/projects/3/merge_requests/7/notes/1201", "note")
244 it 'gets the correct resource' do
245 expect(a_delete('/projects/3/snippets/7/notes/1201')).to have_been_made
246 end
247
248 it 'returns information about a deleted snippet note' do
249 expect(@note.id).to eq(1201)
250 end
251 end
252
253 context 'when merge request note' do
254 before do
255 stub_delete('/projects/3/merge_requests/7/notes/1201', 'note')
254256 @note = Gitlab.delete_merge_request_note(3, 7, 1201)
255257 end
256258
257 it "gets the correct resource" do
258 expect(a_delete("/projects/3/merge_requests/7/notes/1201")).to have_been_made
259 end
260
261 it "returns information about a deleted merge request note" do
262 expect(@note.id).to eq(1201)
263 end
264 end
265 end
266
267 describe "modify note" do
268 context "when wall note" do
269 before do
270 stub_put("/projects/3/notes/1201", "note")
271 @note = Gitlab.edit_note(3, 1201, "edited wall note content")
272 end
273
274 it "gets the correct resource" do
275 expect(a_put("/projects/3/notes/1201").
276 with(body: {body: 'edited wall note content'})).to have_been_made
277 end
278
279 it "returns information about a modified note" do
280 expect(@note.id).to eq(1201)
281 end
282 end
283
284 context "when issue note" do
285 before do
286 stub_put("/projects/3/issues/7/notes/1201", "note")
287 @note = Gitlab.edit_issue_note(3, 7, 1201, "edited issue note content")
288 end
289
290 it "gets the correct resource" do
291 expect(a_put("/projects/3/issues/7/notes/1201").
292 with(body: {body: 'edited issue note content'})).to have_been_made
293 end
294
295 it "returns information about a modified issue note" do
296 expect(@note.id).to eq(1201)
297 end
298 end
299
300 context "when snippet note" do
301 before do
302 stub_put("/projects/3/snippets/7/notes/1201", "note")
303 @note = Gitlab.edit_snippet_note(3, 7, 1201, "edited snippet note content")
304 end
305
306 it "gets the correct resource" do
307 expect(a_put("/projects/3/snippets/7/notes/1201").
308 with(body: {body: 'edited snippet note content'})).to have_been_made
309 end
310
311 it "returns information about a modified snippet note" do
312 expect(@note.id).to eq(1201)
313 end
314 end
315
316 context "when merge request note" do
317 before do
318 stub_put("/projects/3/merge_requests/7/notes/1201", "note")
319 @note = Gitlab.edit_merge_request_note(3, 7, 1201, "edited merge request note content")
320 end
321
322 it "gets the correct resource" do
323 expect(a_put("/projects/3/merge_requests/7/notes/1201").
324 with(body: {body: 'edited merge request note content'})).to have_been_made
325 end
326
327 it "returns information about a modified request note" do
259 it 'gets the correct resource' do
260 expect(a_delete('/projects/3/merge_requests/7/notes/1201')).to have_been_made
261 end
262
263 it 'returns information about a deleted merge request note' do
264 expect(@note.id).to eq(1201)
265 end
266 end
267 end
268
269 describe 'modify note' do
270 context 'when wall note' do
271 before do
272 stub_put('/projects/3/notes/1201', 'note')
273 @note = Gitlab.edit_note(3, 1201, 'edited wall note content')
274 end
275
276 it 'gets the correct resource' do
277 expect(a_put('/projects/3/notes/1201')
278 .with(body: { body: 'edited wall note content' })).to have_been_made
279 end
280
281 it 'returns information about a modified note' do
282 expect(@note.id).to eq(1201)
283 end
284 end
285
286 context 'when issue note' do
287 before do
288 stub_put('/projects/3/issues/7/notes/1201', 'note')
289 @note = Gitlab.edit_issue_note(3, 7, 1201, 'edited issue note content')
290 end
291
292 it 'gets the correct resource' do
293 expect(a_put('/projects/3/issues/7/notes/1201')
294 .with(body: { body: 'edited issue note content' })).to have_been_made
295 end
296
297 it 'returns information about a modified issue note' do
298 expect(@note.id).to eq(1201)
299 end
300 end
301
302 context 'when snippet note' do
303 before do
304 stub_put('/projects/3/snippets/7/notes/1201', 'note')
305 @note = Gitlab.edit_snippet_note(3, 7, 1201, 'edited snippet note content')
306 end
307
308 it 'gets the correct resource' do
309 expect(a_put('/projects/3/snippets/7/notes/1201')
310 .with(body: { body: 'edited snippet note content' })).to have_been_made
311 end
312
313 it 'returns information about a modified snippet note' do
314 expect(@note.id).to eq(1201)
315 end
316 end
317
318 context 'when merge request note' do
319 before do
320 stub_put('/projects/3/merge_requests/7/notes/1201', 'note')
321 @note = Gitlab.edit_merge_request_note(3, 7, 1201, 'edited merge request note content')
322 end
323
324 it 'gets the correct resource' do
325 expect(a_put('/projects/3/merge_requests/7/notes/1201')
326 .with(body: { body: 'edited merge request note content' })).to have_been_made
327 end
328
329 it 'returns information about a modified request note' do
328330 expect(@note.id).to eq(1201)
329331 end
330332 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".pipeline_schedules" do
5 describe '.pipeline_schedules' do
46 before do
5 stub_get("/projects/3/pipeline_schedules", "pipeline_schedules")
7 stub_get('/projects/3/pipeline_schedules', 'pipeline_schedules')
68 @pipeline_schedules = Gitlab.pipeline_schedules(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/pipeline_schedules")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/pipeline_schedules')).to have_been_made
1113 end
1214
1315 it "returns a response of project's pipeline schedules" do
1517 end
1618 end
1719
18 describe ".pipeline_schedule" do
20 describe '.pipeline_schedule' do
1921 before do
20 stub_get("/projects/3/pipeline_schedules/5", "pipeline_schedule")
22 stub_get('/projects/3/pipeline_schedules/5', 'pipeline_schedule')
2123 @pipeline_schedule = Gitlab.pipeline_schedule(3, 5)
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_get("/projects/3/pipeline_schedules/5")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_get('/projects/3/pipeline_schedules/5')).to have_been_made
2628 end
2729
2830 it "returns a response of project's pipeline schedules" do
3032 end
3133 end
3234
33 describe ".create_pipeline_schedule" do
35 describe '.create_pipeline_schedule' do
3436 before do
35 stub_post("/projects/3/pipeline_schedules", "pipeline_schedule_create")
37 stub_post('/projects/3/pipeline_schedules', 'pipeline_schedule_create')
3638 @pipeline_schedule_create = Gitlab.create_pipeline_schedule(3)
3739 end
3840
39 it "gets the correct resource" do
40 expect(a_post("/projects/3/pipeline_schedules")).to have_been_made
41 it 'gets the correct resource' do
42 expect(a_post('/projects/3/pipeline_schedules')).to have_been_made
4143 end
4244
43 it "returns a single pipeline schedule" do
45 it 'returns a single pipeline schedule' do
4446 expect(@pipeline_schedule_create).to be_a Gitlab::ObjectifiedHash
4547 end
4648
47 it "returns information about a pipeline schedule" do
48 expect(@pipeline_schedule_create.owner.name).to eq("Administrator")
49 it 'returns information about a pipeline schedule' do
50 expect(@pipeline_schedule_create.owner.name).to eq('Administrator')
4951 end
5052 end
5153
52 describe ".edit_pipeline_schedule" do
54 describe '.edit_pipeline_schedule' do
5355 before do
54 stub_put("/projects/3/pipeline_schedules/13", "pipeline_schedule_update")
56 stub_put('/projects/3/pipeline_schedules/13', 'pipeline_schedule_update')
5557 @pipeline_schedule_update = Gitlab.edit_pipeline_schedule(3, 13)
5658 end
5759
58 it "gets the correct resource" do
59 expect(a_put("/projects/3/pipeline_schedules/13")).to have_been_made
60 it 'gets the correct resource' do
61 expect(a_put('/projects/3/pipeline_schedules/13')).to have_been_made
6062 end
6163
62 it "returns a single pipeline schedule" do
64 it 'returns a single pipeline schedule' do
6365 expect(@pipeline_schedule_update).to be_a Gitlab::ObjectifiedHash
6466 end
6567
66 it "returns information about a pipeline schedule" do
67 expect(@pipeline_schedule_update.owner.name).to eq("Administrator")
68 it 'returns information about a pipeline schedule' do
69 expect(@pipeline_schedule_update.owner.name).to eq('Administrator')
6870 end
6971 end
7072
71 describe ".pipeline_schedule_take_ownership" do
73 describe '.pipeline_schedule_take_ownership' do
7274 before do
73 stub_post("/projects/3/pipeline_schedules/13/take_ownership", "pipeline_schedule")
75 stub_post('/projects/3/pipeline_schedules/13/take_ownership', 'pipeline_schedule')
7476 @pipeline_schedule = Gitlab.pipeline_schedule_take_ownership(3, 13)
7577 end
7678
77 it "gets the correct resource" do
78 expect(a_post("/projects/3/pipeline_schedules/13/take_ownership")).to have_been_made
79 it 'gets the correct resource' do
80 expect(a_post('/projects/3/pipeline_schedules/13/take_ownership')).to have_been_made
7981 end
8082
81 it "returns information about the pipeline schedule" do
82 expect(@pipeline_schedule.created_at).to eq("2017-05-19T13:31:08.849Z")
83 expect(@pipeline_schedule.description).to eq("Test schedule pipeline")
83 it 'returns information about the pipeline schedule' do
84 expect(@pipeline_schedule.created_at).to eq('2017-05-19T13:31:08.849Z')
85 expect(@pipeline_schedule.description).to eq('Test schedule pipeline')
8486 end
8587 end
8688
87 describe ".delete_pipeline_schedule" do
89 describe '.delete_pipeline_schedule' do
8890 before do
89 stub_delete("/projects/3/pipeline_schedules/13", "pipeline_schedule")
90 @pipeline_schedule = Gitlab.delete_pipeline_schedule(3,13)
91 stub_delete('/projects/3/pipeline_schedules/13', 'pipeline_schedule')
92 @pipeline_schedule = Gitlab.delete_pipeline_schedule(3, 13)
9193 end
9294
93 it "gets the correct resource" do
94 expect(a_delete("/projects/3/pipeline_schedules/13")).to have_been_made
95 it 'gets the correct resource' do
96 expect(a_delete('/projects/3/pipeline_schedules/13')).to have_been_made
9597 end
9698
97 it "returns a single pipeline" do
99 it 'returns a single pipeline' do
98100 expect(@pipeline_schedule).to be_a Gitlab::ObjectifiedHash
99101 end
100102
101 it "returns information about the deleted pipeline" do
103 it 'returns information about the deleted pipeline' do
102104 # expect(@pipeline_schedule.id).to eq(13)
103105 end
104106 end
105107
106 describe ".create_pipeline_schedule_variable" do
108 describe '.create_pipeline_schedule_variable' do
107109 before do
108 stub_post("/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value", "pipeline_schedule_variable")
109 @pipeline_schedule_variable = Gitlab.create_pipeline_schedule_variable(3, 13, {
110 key: "NEW VARIABLE",
111 value: "new value"
112 })
110 stub_post('/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value', 'pipeline_schedule_variable')
111 @pipeline_schedule_variable = Gitlab.create_pipeline_schedule_variable(3, 13,
112 key: 'NEW VARIABLE',
113 value: 'new value')
113114 end
114115
115 it "gets the correct resource" do
116 expect(a_post("/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value")).to have_been_made
116 it 'gets the correct resource' do
117 expect(a_post('/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value')).to have_been_made
117118 end
118119
119 it "returns a single variable" do
120 it 'returns a single variable' do
120121 expect(@pipeline_schedule_variable).to be_a Gitlab::ObjectifiedHash
121122 end
122123
123 it "returns the created variable" do
124 expect(@pipeline_schedule_variable.value).to eq("new value")
124 it 'returns the created variable' do
125 expect(@pipeline_schedule_variable.value).to eq('new value')
125126 end
126127 end
127128
128 describe ".edit_pipeline_schedule_variable" do
129 describe '.edit_pipeline_schedule_variable' do
129130 before do
130 stub_put("/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE?value=update%20value", "pipeline_schedule_variable_update")
131 @pipeline_schedule_variable = Gitlab.edit_pipeline_schedule_variable(3, 13, "NEW VARIABLE", { value: "update value" })
131 stub_put('/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE?value=update%20value', 'pipeline_schedule_variable_update')
132 @pipeline_schedule_variable = Gitlab.edit_pipeline_schedule_variable(3, 13, 'NEW VARIABLE', value: 'update value')
132133 end
133134
134 it "returns a single variable" do
135 it 'returns a single variable' do
135136 expect(@pipeline_schedule_variable).to be_a Gitlab::ObjectifiedHash
136137 end
137138
138 it "has the updated value" do
139 expect(@pipeline_schedule_variable.value).to eq("update value")
139 it 'has the updated value' do
140 expect(@pipeline_schedule_variable.value).to eq('update value')
140141 end
141142 end
142143
143 describe ".delete_pipeline_schedule_variable" do
144 describe '.delete_pipeline_schedule_variable' do
144145 before do
145 stub_delete("/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE", "pipeline_schedule_variable")
146 @pipeline_schedule_variable = Gitlab.delete_pipeline_schedule_variable(3, 13, "NEW VARIABLE")
146 stub_delete('/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE', 'pipeline_schedule_variable')
147 @pipeline_schedule_variable = Gitlab.delete_pipeline_schedule_variable(3, 13, 'NEW VARIABLE')
147148 end
148149
149 it "returns a single variable" do
150 it 'returns a single variable' do
150151 expect(@pipeline_schedule_variable).to be_a Gitlab::ObjectifiedHash
151152 end
152153
153 it "has the value of the deleted variable" do
154 expect(@pipeline_schedule_variable.value).to eq("new value")
154 it 'has the value of the deleted variable' do
155 expect(@pipeline_schedule_variable.value).to eq('new value')
155156 end
156157 end
157158 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
35 it { is_expected.to respond_to :delete_trigger }
46
5 describe ".triggers" do
7 describe '.triggers' do
68 before do
7 stub_get("/projects/3/triggers", "triggers")
9 stub_get('/projects/3/triggers', 'triggers')
810 @triggers = Gitlab.triggers(3)
911 end
1012
11 it "gets the correct resource" do
12 expect(a_get("/projects/3/triggers")).to have_been_made
13 it 'gets the correct resource' do
14 expect(a_get('/projects/3/triggers')).to have_been_made
1315 end
1416
1517 it "returns an array of project's triggers" do
1618 expect(@triggers).to be_a Gitlab::PaginatedResponse
17 expect(@triggers.first.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7")
19 expect(@triggers.first.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
1820 end
1921 end
2022
21 describe ".trigger" do
23 describe '.trigger' do
2224 before do
23 stub_get("/projects/3/triggers/10", "trigger")
25 stub_get('/projects/3/triggers/10', 'trigger')
2426 @trigger = Gitlab.trigger(3, 10)
2527 end
2628
27 it "gets the correct resource" do
28 expect(a_get("/projects/3/triggers/10")).to have_been_made
29 it 'gets the correct resource' do
30 expect(a_get('/projects/3/triggers/10')).to have_been_made
2931 end
3032
31 it "returns information about a trigger" do
32 expect(@trigger.created_at).to eq("2016-01-07T09:53:58.235Z")
33 expect(@trigger.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7")
33 it 'returns information about a trigger' do
34 expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z')
35 expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
3436 end
3537 end
3638
37 describe ".create_trigger" do
39 describe '.create_trigger' do
3840 before do
39 stub_post("/projects/3/triggers", "trigger")
40 @trigger = Gitlab.create_trigger(3, "my description")
41 stub_post('/projects/3/triggers', 'trigger')
42 @trigger = Gitlab.create_trigger(3, 'my description')
4143 end
4244
43 it "gets the correct resource" do
44 expect(a_post("/projects/3/triggers").
45 with(body: { description: "my description" })).to have_been_made
45 it 'gets the correct resource' do
46 expect(a_post('/projects/3/triggers')
47 .with(body: { description: 'my description' })).to have_been_made
4648 end
4749
48 it "returns information about a new trigger" do
49 expect(@trigger.created_at).to eq("2016-01-07T09:53:58.235Z")
50 expect(@trigger.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7")
50 it 'returns information about a new trigger' do
51 expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z')
52 expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
5153 end
5254 end
5355
54 describe ".update_trigger" do
56 describe '.update_trigger' do
5557 before do
56 stub_put("/projects/3/triggers/1", "trigger")
57 @trigger = Gitlab.update_trigger(3, 1, description: "my description")
58 stub_put('/projects/3/triggers/1', 'trigger')
59 @trigger = Gitlab.update_trigger(3, 1, description: 'my description')
5860 end
5961
60 it "gets the correct resource" do
61 expect(a_put("/projects/3/triggers/1").
62 with(body: { description: "my description" })).to have_been_made
62 it 'gets the correct resource' do
63 expect(a_put('/projects/3/triggers/1')
64 .with(body: { description: 'my description' })).to have_been_made
6365 end
6466
65 it "returns information about the trigger" do
66 expect(@trigger.created_at).to eq("2016-01-07T09:53:58.235Z")
67 expect(@trigger.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7")
67 it 'returns information about the trigger' do
68 expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z')
69 expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
6870 end
6971 end
7072
71 describe ".trigger_take_ownership" do
73 describe '.trigger_take_ownership' do
7274 before do
73 stub_post("/projects/3/triggers/1/take_ownership", "trigger")
75 stub_post('/projects/3/triggers/1/take_ownership', 'trigger')
7476 @trigger = Gitlab.trigger_take_ownership(3, 1)
7577 end
7678
77 it "gets the correct resource" do
78 expect(a_post("/projects/3/triggers/1/take_ownership")).to have_been_made
79 it 'gets the correct resource' do
80 expect(a_post('/projects/3/triggers/1/take_ownership')).to have_been_made
7981 end
8082
81 it "returns information about the trigger" do
82 expect(@trigger.created_at).to eq("2016-01-07T09:53:58.235Z")
83 expect(@trigger.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7")
83 it 'returns information about the trigger' do
84 expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z')
85 expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7')
8486 end
8587 end
8688
87 describe ".remove_trigger" do
89 describe '.remove_trigger' do
8890 before do
89 stub_delete("/projects/3/triggers/10", "empty")
91 stub_delete('/projects/3/triggers/10', 'empty')
9092 @trigger = Gitlab.remove_trigger(3, 10)
9193 end
9294
93 it "gets the correct resource" do
94 expect(a_delete("/projects/3/triggers/10")).to have_been_made
95 it 'gets the correct resource' do
96 expect(a_delete('/projects/3/triggers/10')).to have_been_made
9597 end
9698 end
9799
98 describe ".run_trigger" do
100 describe '.run_trigger' do
99101 before do
100 stub_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline").
101 to_return(body: load_fixture("run_trigger"), status: 200)
102 stub_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline")
103 .to_return(body: load_fixture('run_trigger'), status: 200)
102104 end
103105
104 context "when private_token is not set" do
106 context 'when private_token is not set' do
105107 before do
106108 Gitlab.private_token = nil
107109 end
108110
109 it "does not raise Error::MissingCredentials" do
110 expect { Gitlab.run_trigger(3, "7b9148c158980bbd9bcea92c17522d", "master", {a: 10}) }.to_not raise_error
111 it 'does not raise Error::MissingCredentials' do
112 expect { Gitlab.run_trigger(3, '7b9148c158980bbd9bcea92c17522d', 'master', a: 10) }.not_to raise_error
111113 end
112114
113115 after do
115117 end
116118 end
117119
118 context "without variables" do
120 context 'without variables' do
119121 before do
120 @trigger = Gitlab.run_trigger(3, "7b9148c158980bbd9bcea92c17522d", "master")
122 @trigger = Gitlab.run_trigger(3, '7b9148c158980bbd9bcea92c17522d', 'master')
121123 end
122124
123 it "gets the correct resource" do
124 expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline").
125 with(body: {
126 token: "7b9148c158980bbd9bcea92c17522d",
127 ref: "master"
128 })).to have_been_made
125 it 'gets the correct resource' do
126 expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline")
127 .with(body: {
128 token: '7b9148c158980bbd9bcea92c17522d',
129 ref: 'master'
130 })).to have_been_made
129131 end
130132
131 it "returns information about the triggered build" do
133 it 'returns information about the triggered build' do
132134 expect(@trigger.id).to eq(8)
133135 end
134136 end
135137
136 context "with variables" do
138 context 'with variables' do
137139 before do
138 @trigger = Gitlab.run_trigger(3, "7b9148c158980bbd9bcea92c17522d", "master", {a: 10})
140 @trigger = Gitlab.run_trigger(3, '7b9148c158980bbd9bcea92c17522d', 'master', a: 10)
139141 end
140142
141 it "gets the correct resource" do
142 expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline").
143 with(body: {
144 token: "7b9148c158980bbd9bcea92c17522d",
145 ref: "master",
146 variables: {a: "10"}
147 })).to have_been_made
143 it 'gets the correct resource' do
144 expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline")
145 .with(body: {
146 token: '7b9148c158980bbd9bcea92c17522d',
147 ref: 'master',
148 variables: { a: '10' }
149 })).to have_been_made
148150 end
149151
150 it "returns information about the triggered build" do
152 it 'returns information about the triggered build' do
151153 expect(@trigger.id).to eq(8)
152 expect(@trigger.variables.a).to eq("10")
154 expect(@trigger.variables.a).to eq('10')
153155 end
154156 end
155157 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".pipelines" do
5 describe '.pipelines' do
46 before do
5 stub_get("/projects/3/pipelines", "pipelines")
7 stub_get('/projects/3/pipelines', 'pipelines')
68 @pipelines = Gitlab.pipelines(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/pipelines")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/pipelines')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of project's pipelines" do
1517 end
1618 end
1719
18 describe ".pipeline" do
20 describe '.pipeline' do
1921 before do
20 stub_get("/projects/3/pipelines/46", "pipeline")
22 stub_get('/projects/3/pipelines/46', 'pipeline')
2123 @pipeline = Gitlab.pipeline(3, 46)
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_get("/projects/3/pipelines/46")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_get('/projects/3/pipelines/46')).to have_been_made
2628 end
2729
28 it "returns a single pipeline" do
30 it 'returns a single pipeline' do
2931 expect(@pipeline).to be_a Gitlab::ObjectifiedHash
3032 end
3133
32 it "returns information about a pipeline" do
34 it 'returns information about a pipeline' do
3335 expect(@pipeline.id).to eq(46)
34 expect(@pipeline.user.name).to eq("Administrator")
36 expect(@pipeline.user.name).to eq('Administrator')
3537 end
3638 end
3739
38 describe ".create_pipeline" do
40 describe '.create_pipeline' do
41 let(:pipeline_path) { '/projects/3/pipeline?ref=master' }
42
3943 before do
40 stub_post("/projects/3/pipeline?ref=master", "pipeline_create")
44 stub_post(pipeline_path, 'pipeline_create')
4145 @pipeline_create = Gitlab.create_pipeline(3, 'master')
4246 end
4347
44 it "gets the correct resource" do
45 expect(a_post("/projects/3/pipeline?ref=master")).to have_been_made
48 it 'gets the correct resource' do
49 expect(a_post(pipeline_path)).to have_been_made
4650 end
4751
48 it "returns a single pipeline" do
52 it 'returns a single pipeline' do
4953 expect(@pipeline_create).to be_a Gitlab::ObjectifiedHash
5054 end
5155
52 it "returns information about a pipeline" do
53 expect(@pipeline_create.user.name).to eq("Administrator")
56 it 'returns information about a pipeline' do
57 expect(@pipeline_create.user.name).to eq('Administrator')
58 end
59
60 context 'when variables are passed' do
61 before do
62 stub_post(pipeline_path, 'pipeline_create')
63 variables = { 'VAR1' => 'value', VAR2: :value }
64 @pipeline_create = Gitlab.create_pipeline(3, 'master', variables)
65 end
66
67 it 'calls with the correct body' do
68 expected_body = 'variables[][key]=VAR1&variables[][value]=value&variables[][key]=VAR2&variables[][value]=value'
69 expect(a_post(pipeline_path).with(body: expected_body)).to have_been_made
70 end
5471 end
5572 end
5673
57 describe ".cancel_pipeline" do
74 describe '.cancel_pipeline' do
5875 before do
59 stub_post("/projects/3/pipelines/46/cancel", "pipeline_cancel")
76 stub_post('/projects/3/pipelines/46/cancel', 'pipeline_cancel')
6077 @pipeline_cancel = Gitlab.cancel_pipeline(3, 46)
6178 end
6279
63 it "gets the correct resource" do
64 expect(a_post("/projects/3/pipelines/46/cancel")).to have_been_made
80 it 'gets the correct resource' do
81 expect(a_post('/projects/3/pipelines/46/cancel')).to have_been_made
6582 end
6683
67 it "returns a single pipeline" do
84 it 'returns a single pipeline' do
6885 expect(@pipeline_cancel).to be_a Gitlab::ObjectifiedHash
6986 end
7087
71 it "returns information about a pipeline" do
72 expect(@pipeline_cancel.user.name).to eq("Administrator")
88 it 'returns information about a pipeline' do
89 expect(@pipeline_cancel.user.name).to eq('Administrator')
7390 end
7491 end
7592
76 describe ".retry_pipeline" do
93 describe '.retry_pipeline' do
7794 before do
78 stub_post("/projects/3/pipelines/46/retry", "pipeline_retry")
95 stub_post('/projects/3/pipelines/46/retry', 'pipeline_retry')
7996 @pipeline_retry = Gitlab.retry_pipeline(3, 46)
8097 end
8198
82 it "gets the correct resource" do
83 expect(a_post("/projects/3/pipelines/46/retry")).to have_been_made
99 it 'gets the correct resource' do
100 expect(a_post('/projects/3/pipelines/46/retry')).to have_been_made
84101 end
85102
86 it "returns a single pipeline" do
103 it 'returns a single pipeline' do
87104 expect(@pipeline_retry).to be_a Gitlab::ObjectifiedHash
88105 end
89106
90 it "returns information about a pipeline" do
91 expect(@pipeline_retry.user.name).to eq("Administrator")
107 it 'returns information about a pipeline' do
108 expect(@pipeline_retry.user.name).to eq('Administrator')
92109 end
93110 end
94111 end
0 # frozen_string_literal: true
1
2 # rubocop:disable Style/FormatStringToken
3
4 require 'spec_helper'
5
6 describe Gitlab::Client do
7 describe '.project_badges' do
8 before do
9 stub_get('/projects/3/badges', 'project_badges')
10 @project_badges = Gitlab.project_badges(3)
11 end
12
13 it 'gets the correct resource' do
14 expect(a_get('/projects/3/badges')).to have_been_made
15 end
16
17 it "returns a paginated response of project's badges" do
18 expect(@project_badges).to be_a Gitlab::PaginatedResponse
19 end
20 end
21
22 describe '.project_badge' do
23 before do
24 stub_get('/projects/3/badges/3', 'project_badge')
25 @project_badge = Gitlab.project_badge(3, 3)
26 end
27
28 it 'gets the correct resource' do
29 expect(a_get('/projects/3/badges/3')).to have_been_made
30 end
31
32 it 'returns information about a badge' do
33 expect(@project_badge.id).to eq(1)
34 end
35 end
36
37 describe '.add_project_badge' do
38 before do
39 stub_post('/projects/3/badges', 'project_badge')
40 @project_badge = Gitlab.add_project_badge(3, link_url: 'http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}', image_url: 'https://shields.io/my/badge')
41 end
42
43 it 'gets the correct resource' do
44 expect(a_post('/projects/3/badges')
45 .with(body: { link_url: 'http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}', image_url: 'https://shields.io/my/badge' })).to have_been_made
46 end
47
48 it 'returns information about an added project badge' do
49 expect(@project_badge.link_url).to eq('http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}')
50 expect(@project_badge.image_url).to eq('https://shields.io/my/badge')
51 end
52 end
53
54 describe '.edit_project_badge' do
55 before do
56 stub_put('/projects/3/badges/1', 'project_badge')
57 @project_badge = Gitlab.edit_project_badge(3, 1, link_url: 'http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}', image_url: 'https://shields.io/my/badge')
58 end
59
60 it 'gets the correct resource' do
61 expect(a_put('/projects/3/badges/1')
62 .with(body: { link_url: 'http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}', image_url: 'https://shields.io/my/badge' })).to have_been_made
63 end
64
65 it 'returns information about an edited project badge' do
66 expect(@project_badge.link_url).to eq('http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}')
67 expect(@project_badge.image_url).to eq('https://shields.io/my/badge')
68 end
69 end
70
71 describe '.remove_project_badge' do
72 before do
73 stub_delete('/projects/3/badges/3', 'empty')
74 @project_badge = Gitlab.remove_project_badge(3, 3)
75 end
76
77 it 'gets the correct resource' do
78 expect(a_delete('/projects/3/badges/3')).to have_been_made
79 end
80 end
81
82 describe '.preview_project_badge' do
83 before do
84 stub_get('/projects/3/badges/render?image_url=https://shields.io/my/badge&link_url=http://example.com/ci_status.svg?project=%25%7Bproject_path%7D%26ref=%25%7Bdefault_branch%7D', 'preview_project_badge')
85 @preview_project_badge = Gitlab.preview_project_badge(3, 'http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}', 'https://shields.io/my/badge')
86 end
87
88 it 'gets the correct resource' do
89 expect(a_get('/projects/3/badges/render?image_url=https://shields.io/my/badge&link_url=http://example.com/ci_status.svg?project=%25%7Bproject_path%7D%26ref=%25%7Bdefault_branch%7D')).to have_been_made
90 end
91
92 it 'returns information about the rendered values of a badge' do
93 expect(@preview_project_badge.link_url).to eq('http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}')
94 expect(@preview_project_badge.image_url).to eq('https://shields.io/my/badge')
95 end
96 end
97 end
98 # rubocop:enable Style/FormatStringToken
0 # frozen_string_literal: true
1
2 require 'spec_helper'
3
4 describe Gitlab::Client do
5 describe '.project_templates' do
6 before do
7 stub_get('/projects/3/templates/licenses', 'project_templates')
8 @project_templates = Gitlab.project_templates(3, 'licenses')
9 end
10
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/templates/licenses')).to have_been_made
13 end
14
15 it "returns a paginated response of project's templates" do
16 expect(@project_templates).to be_a Gitlab::PaginatedResponse
17 end
18 end
19
20 describe '.project_template' do
21 context 'when dockerfiles' do
22 before do
23 stub_get('/projects/3/templates/dockerfiles/dock', 'dockerfile_project_template')
24 @project_template = Gitlab.project_template(3, 'dockerfiles', 'dock')
25 end
26
27 it 'gets the correct resource' do
28 expect(a_get('/projects/3/templates/dockerfiles/dock')).to have_been_made
29 end
30 end
31
32 context 'when licenses' do
33 before do
34 stub_get('/projects/3/templates/licenses/mit', 'license_project_template')
35 @project_template = Gitlab.project_template(3, 'licenses', 'mit')
36 end
37
38 it 'gets the correct resource' do
39 expect(a_get('/projects/3/templates/licenses/mit')).to have_been_made
40 end
41 end
42 end
43 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
35 it { is_expected.to respond_to :search_projects }
46
5 describe ".projects" do
6 before do
7 stub_get("/projects", "projects")
7 describe '.projects' do
8 before do
9 stub_get('/projects', 'projects')
810 @projects = Gitlab.projects
911 end
1012
11 it "gets the correct resource" do
12 expect(a_get("/projects")).to have_been_made
13 end
14
15 it "returns a paginated response of projects" do
13 it 'gets the correct resource' do
14 expect(a_get('/projects')).to have_been_made
15 end
16
17 it 'returns a paginated response of projects' do
1618 expect(@projects).to be_a Gitlab::PaginatedResponse
17 expect(@projects.first.name).to eq("Brute")
18 expect(@projects.first.owner.name).to eq("John Smith")
19 end
20 end
21
22 describe ".project_search" do
23 before do
24 stub_get("/projects?search=Gitlab", "project_search")
25 @project_search = Gitlab.project_search("Gitlab")
26 end
27
28 it "gets the correct resource" do
29 expect(a_get("/projects?search=Gitlab")).to have_been_made
30 end
31
32 it "returns a paginated response of projects found" do
19 expect(@projects.first.name).to eq('Brute')
20 expect(@projects.first.owner.name).to eq('John Smith')
21 end
22 end
23
24 describe '.project_search' do
25 before do
26 stub_get('/projects?search=Gitlab', 'project_search')
27 @project_search = Gitlab.project_search('Gitlab')
28 end
29
30 it 'gets the correct resource' do
31 expect(a_get('/projects?search=Gitlab')).to have_been_made
32 end
33
34 it 'returns a paginated response of projects found' do
3335 expect(@project_search).to be_a Gitlab::PaginatedResponse
34 expect(@project_search.first.name).to eq("Gitlab")
35 expect(@project_search.first.owner.name).to eq("John Smith")
36 end
37 end
38
39 describe ".project" do
40 before do
41 stub_get("/projects/3", "project")
36 expect(@project_search.first.name).to eq('Gitlab')
37 expect(@project_search.first.owner.name).to eq('John Smith')
38 end
39 end
40
41 describe '.project' do
42 before do
43 stub_get('/projects/3', 'project')
4244 @project = Gitlab.project(3)
4345 end
4446
45 it "gets the correct resource" do
46 expect(a_get("/projects/3")).to have_been_made
47 end
48
49 it "returns information about a project" do
50 expect(@project.name).to eq("Gitlab")
51 expect(@project.owner.name).to eq("John Smith")
52 end
53 end
54
55 describe ".create_project" do
56 before do
57 stub_post("/projects", "project")
47 it 'gets the correct resource' do
48 expect(a_get('/projects/3')).to have_been_made
49 end
50
51 it 'returns information about a project' do
52 expect(@project.name).to eq('Gitlab')
53 expect(@project.owner.name).to eq('John Smith')
54 end
55 end
56
57 describe '.create_project' do
58 before do
59 stub_post('/projects', 'project')
5860 @project = Gitlab.create_project('Gitlab')
5961 end
6062
61 it "gets the correct resource" do
62 expect(a_post("/projects")).to have_been_made
63 end
64
65 it "returns information about a created project" do
66 expect(@project.name).to eq("Gitlab")
67 expect(@project.owner.name).to eq("John Smith")
68 end
69 end
70
71 describe ".create_project for user" do
72 before do
73 stub_post("/users", "user")
74 @owner = Gitlab.create_user("john@example.com", "pass", name: 'John Owner')
75 stub_post("/projects/user/#{@owner.id}", "project_for_user")
63 it 'gets the correct resource' do
64 expect(a_post('/projects')).to have_been_made
65 end
66
67 it 'returns information about a created project' do
68 expect(@project.name).to eq('Gitlab')
69 expect(@project.owner.name).to eq('John Smith')
70 end
71 end
72
73 describe '.create_project for user' do
74 before do
75 stub_post('/users', 'user')
76 @owner = Gitlab.create_user('john@example.com', 'pass', name: 'John Owner')
77 stub_post("/projects/user/#{@owner.id}", 'project_for_user')
7678 @project = Gitlab.create_project('Brute', user_id: @owner.id)
7779 end
7880
79 it "returns information about a created project" do
80 expect(@project.name).to eq("Brute")
81 expect(@project.owner.name).to eq("John Owner")
82 end
83 end
84
85 describe ".delete_project" do
86 before do
87 stub_delete("/projects/Gitlab", "project")
81 it 'returns information about a created project' do
82 expect(@project.name).to eq('Brute')
83 expect(@project.owner.name).to eq('John Owner')
84 end
85 end
86
87 describe '.delete_project' do
88 before do
89 stub_delete('/projects/Gitlab', 'project')
8890 @project = Gitlab.delete_project('Gitlab')
8991 end
9092
91 it "gets the correct resource" do
92 expect(a_delete("/projects/Gitlab")).to have_been_made
93 end
94
95 it "returns information about a deleted project" do
96 expect(@project.name).to eq("Gitlab")
97 expect(@project.owner.name).to eq("John Smith")
98 end
99 end
100
101 describe ".create_fork" do
102 context "without sudo option" do
103 before do
104 stub_post("/projects/3/fork", "project_fork")
93 it 'gets the correct resource' do
94 expect(a_delete('/projects/Gitlab')).to have_been_made
95 end
96
97 it 'returns information about a deleted project' do
98 expect(@project.name).to eq('Gitlab')
99 expect(@project.owner.name).to eq('John Smith')
100 end
101 end
102
103 describe '.create_fork' do
104 context 'without sudo option' do
105 before do
106 stub_post('/projects/3/fork', 'project_fork')
105107 @project = Gitlab.create_fork(3)
106108 end
107109
108 it "posts to the correct resource" do
109 expect(a_post("/projects/3/fork")).to have_been_made
110 end
111
112 it "returns information about the forked project" do
110 it 'posts to the correct resource' do
111 expect(a_post('/projects/3/fork')).to have_been_made
112 end
113
114 it 'returns information about the forked project' do
113115 expect(@project.forked_from_project.id).to eq(3)
114116 expect(@project.id).to eq(20)
115117 end
116118 end
117119
118 context "with the sudo option" do
119 before do
120 stub_post("/projects/3/fork", "project_forked_for_user")
120 context 'with the sudo option' do
121 before do
122 stub_post('/projects/3/fork', 'project_forked_for_user')
121123 @sudoed_username = 'jack.smith'
122124 @project = Gitlab.create_fork(3, sudo: @sudoed_username)
123125 end
124126
125 it "posts to the correct resource" do
126 expect(a_post("/projects/3/fork")).to have_been_made
127 end
128
129 it "returns information about the forked project" do
127 it 'posts to the correct resource' do
128 expect(a_post('/projects/3/fork')).to have_been_made
129 end
130
131 it 'returns information about the forked project' do
130132 expect(@project.forked_from_project.id).to eq(3)
131133 expect(@project.id).to eq(20)
132134 expect(@project.owner.username).to eq(@sudoed_username)
134136 end
135137 end
136138
137 describe ".project_forks" do
138 before do
139 stub_get("/projects/3/forks", "project_forks")
139 describe '.project_forks' do
140 before do
141 stub_get('/projects/3/forks', 'project_forks')
140142 @project_forks = Gitlab.project_forks(3)
141143 end
142144
143 it "gets the correct resource" do
144 expect(a_get("/projects/3/forks")).to have_been_made
145 end
146
147 it "returns a paginated response of projects found" do
145 it 'gets the correct resource' do
146 expect(a_get('/projects/3/forks')).to have_been_made
147 end
148
149 it 'returns a paginated response of projects found' do
148150 expect(@project_forks).to be_a Gitlab::PaginatedResponse
149 expect(@project_forks.first.name).to eq("gitlab")
150 expect(@project_forks.first.owner.name).to eq("Administrator")
151 end
152 end
153
154 describe ".team_members" do
155 before do
156 stub_get("/projects/3/members", "team_members")
151 expect(@project_forks.first.name).to eq('gitlab')
152 expect(@project_forks.first.owner.name).to eq('Administrator')
153 end
154 end
155
156 describe '.team_members' do
157 before do
158 stub_get('/projects/3/members', 'team_members')
157159 @team_members = Gitlab.team_members(3)
158160 end
159161
160 it "gets the correct resource" do
161 expect(a_get("/projects/3/members")).to have_been_made
162 end
163
164 it "returns a paginated response of team members" do
162 it 'gets the correct resource' do
163 expect(a_get('/projects/3/members')).to have_been_made
164 end
165
166 it 'returns a paginated response of team members' do
165167 expect(@team_members).to be_a Gitlab::PaginatedResponse
166 expect(@team_members.first.name).to eq("John Smith")
167 end
168 end
169
170 describe ".team_member" do
171 before do
172 stub_get("/projects/3/members/1", "team_member")
168 expect(@team_members.first.name).to eq('John Smith')
169 end
170 end
171
172 describe '.team_member' do
173 before do
174 stub_get('/projects/3/members/1', 'team_member')
173175 @team_member = Gitlab.team_member(3, 1)
174176 end
175177
176 it "gets the correct resource" do
177 expect(a_get("/projects/3/members/1")).to have_been_made
178 end
179
180 it "returns information about a team member" do
181 expect(@team_member.name).to eq("John Smith")
182 end
183 end
184
185 describe ".add_team_member" do
186 before do
187 stub_post("/projects/3/members", "team_member")
188 @team_member = Gitlab.add_team_member(3, 1, 40)
189 end
190
191 it "gets the correct resource" do
192 expect(a_post("/projects/3/members").
193 with(body: { user_id: '1', access_level: '40' })).to have_been_made
194 end
195
196 it "returns information about an added team member" do
197 expect(@team_member.name).to eq("John Smith")
198 end
199 end
200
201 describe ".edit_team_member" do
202 before do
203 stub_put("/projects/3/members/1", "team_member")
204 @team_member = Gitlab.edit_team_member(3, 1, 40)
205 end
206
207 it "gets the correct resource" do
208 expect(a_put("/projects/3/members/1").
209 with(body: { access_level: '40' })).to have_been_made
210 end
211
212 it "returns information about an edited team member" do
213 expect(@team_member.name).to eq("John Smith")
214 end
215 end
216
217 describe ".remove_team_member" do
218 before do
219 stub_delete("/projects/3/members/1", "team_member")
178 it 'gets the correct resource' do
179 expect(a_get('/projects/3/members/1')).to have_been_made
180 end
181
182 it 'returns information about a team member' do
183 expect(@team_member.name).to eq('John Smith')
184 end
185 end
186
187 describe '.add_team_member' do
188 before do
189 stub_post('/projects/3/members', 'team_member')
190 @team_member = Gitlab.add_team_member(3, 1, 40, expires_at: '2018-12-31')
191 end
192
193 it 'gets the correct resource' do
194 expect(a_post('/projects/3/members')
195 .with(body: { user_id: '1', access_level: '40', expires_at: '2018-12-31' })).to have_been_made
196 end
197
198 it 'returns information about an added team member' do
199 expect(@team_member.name).to eq('John Smith')
200 expect(@team_member.expires_at).to eq('2018-12-31T00:00:00Z')
201 end
202 end
203
204 describe '.edit_team_member' do
205 before do
206 stub_put('/projects/3/members/1', 'team_member')
207 @team_member = Gitlab.edit_team_member(3, 1, 40, expires_at: '2018-12-31')
208 end
209
210 it 'gets the correct resource' do
211 expect(a_put('/projects/3/members/1')
212 .with(body: { access_level: '40', expires_at: '2018-12-31' })).to have_been_made
213 end
214
215 it 'returns information about an edited team member' do
216 expect(@team_member.name).to eq('John Smith')
217 expect(@team_member.expires_at).to eq('2018-12-31T00:00:00Z')
218 end
219 end
220
221 describe '.remove_team_member' do
222 before do
223 stub_delete('/projects/3/members/1', 'team_member')
220224 @team_member = Gitlab.remove_team_member(3, 1)
221225 end
222226
223 it "gets the correct resource" do
224 expect(a_delete("/projects/3/members/1")).to have_been_made
225 end
226
227 it "returns information about a removed team member" do
228 expect(@team_member.name).to eq("John Smith")
229 end
230 end
231
232 describe ".project_hooks" do
233 before do
234 stub_get("/projects/1/hooks", "project_hooks")
227 it 'gets the correct resource' do
228 expect(a_delete('/projects/3/members/1')).to have_been_made
229 end
230
231 it 'returns information about a removed team member' do
232 expect(@team_member.name).to eq('John Smith')
233 end
234 end
235
236 describe '.project_hooks' do
237 before do
238 stub_get('/projects/1/hooks', 'project_hooks')
235239 @hooks = Gitlab.project_hooks(1)
236240 end
237241
238 it "gets the correct resource" do
239 expect(a_get("/projects/1/hooks")).to have_been_made
240 end
241
242 it "returns a paginated response of hooks" do
242 it 'gets the correct resource' do
243 expect(a_get('/projects/1/hooks')).to have_been_made
244 end
245
246 it 'returns a paginated response of hooks' do
243247 expect(@hooks).to be_a Gitlab::PaginatedResponse
244 expect(@hooks.first.url).to eq("https://api.example.net/v1/webhooks/ci")
245 end
246 end
247
248 describe ".project_hook" do
249 before do
250 stub_get("/projects/1/hooks/1", "project_hook")
248 expect(@hooks.first.url).to eq('https://api.example.net/v1/webhooks/ci')
249 end
250 end
251
252 describe '.project_hook' do
253 before do
254 stub_get('/projects/1/hooks/1', 'project_hook')
251255 @hook = Gitlab.project_hook(1, 1)
252256 end
253257
254 it "gets the correct resource" do
255 expect(a_get("/projects/1/hooks/1")).to have_been_made
256 end
257
258 it "returns information about a hook" do
259 expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
260 end
261 end
262
263 describe ".add_project_hook" do
264 context "without specified events" do
265 before do
266 stub_post("/projects/1/hooks", "project_hook")
267 @hook = Gitlab.add_project_hook(1, "https://api.example.net/v1/webhooks/ci")
268 end
269
270 it "gets the correct resource" do
271 body = { url: "https://api.example.net/v1/webhooks/ci" }
272 expect(a_post("/projects/1/hooks").with(body: body)).to have_been_made
273 end
274
275 it "returns information about an added hook" do
276 expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
277 end
278 end
279
280 context "with specified events" do
281 before do
282 stub_post("/projects/1/hooks", "project_hook")
283 @hook = Gitlab.add_project_hook(1, "https://api.example.net/v1/webhooks/ci", push_events: true, merge_requests_events: true)
284 end
285
286 it "gets the correct resource" do
287 body = { url: "https://api.example.net/v1/webhooks/ci", push_events: "true", merge_requests_events: "true" }
288 expect(a_post("/projects/1/hooks").with(body: body)).to have_been_made
289 end
290
291 it "returns information about an added hook" do
292 expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
293 end
294 end
295 end
296
297 describe ".edit_project_hook" do
298 before do
299 stub_put("/projects/1/hooks/1", "project_hook")
300 @hook = Gitlab.edit_project_hook(1, 1, "https://api.example.net/v1/webhooks/ci")
301 end
302
303 it "gets the correct resource" do
304 body = { url: "https://api.example.net/v1/webhooks/ci" }
305 expect(a_put("/projects/1/hooks/1").with(body: body)).to have_been_made
306 end
307
308 it "returns information about an edited hook" do
309 expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
310 end
311 end
312
313 describe ".edit_project" do
314 context "using project ID" do
315 before do
316 stub_put("/projects/3", "project_edit").with(body: { name: "Gitlab-edit" })
317 @edited_project = Gitlab.edit_project(3, name: "Gitlab-edit")
318 end
319
320 it "gets the correct resource" do
321 expect(a_put("/projects/3").with(body: { name: "Gitlab-edit" })).to have_been_made
322 end
323
324 it "returns information about an edited project" do
325 expect(@edited_project.name).to eq("Gitlab-edit")
326 end
327 end
328
329 context "using namespaced project path" do
330 it "encodes the path properly" do
331 stub = stub_put("/projects/namespace%2Fpath", "project_edit").with(body: { name: "Gitlab-edit" })
332 Gitlab.edit_project('namespace/path', name: "Gitlab-edit")
258 it 'gets the correct resource' do
259 expect(a_get('/projects/1/hooks/1')).to have_been_made
260 end
261
262 it 'returns information about a hook' do
263 expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci')
264 end
265 end
266
267 describe '.add_project_hook' do
268 context 'without specified events' do
269 before do
270 stub_post('/projects/1/hooks', 'project_hook')
271 @hook = Gitlab.add_project_hook(1, 'https://api.example.net/v1/webhooks/ci')
272 end
273
274 it 'gets the correct resource' do
275 body = { url: 'https://api.example.net/v1/webhooks/ci' }
276 expect(a_post('/projects/1/hooks').with(body: body)).to have_been_made
277 end
278
279 it 'returns information about an added hook' do
280 expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci')
281 end
282 end
283
284 context 'with specified events' do
285 before do
286 stub_post('/projects/1/hooks', 'project_hook')
287 @hook = Gitlab.add_project_hook(1, 'https://api.example.net/v1/webhooks/ci', push_events: true, merge_requests_events: true)
288 end
289
290 it 'gets the correct resource' do
291 body = { url: 'https://api.example.net/v1/webhooks/ci', push_events: 'true', merge_requests_events: 'true' }
292 expect(a_post('/projects/1/hooks').with(body: body)).to have_been_made
293 end
294
295 it 'returns information about an added hook' do
296 expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci')
297 end
298 end
299 end
300
301 describe '.edit_project_hook' do
302 before do
303 stub_put('/projects/1/hooks/1', 'project_hook')
304 @hook = Gitlab.edit_project_hook(1, 1, 'https://api.example.net/v1/webhooks/ci')
305 end
306
307 it 'gets the correct resource' do
308 body = { url: 'https://api.example.net/v1/webhooks/ci' }
309 expect(a_put('/projects/1/hooks/1').with(body: body)).to have_been_made
310 end
311
312 it 'returns information about an edited hook' do
313 expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci')
314 end
315 end
316
317 describe '.edit_project' do
318 context 'using project ID' do
319 before do
320 stub_put('/projects/3', 'project_edit').with(body: { name: 'Gitlab-edit' })
321 @edited_project = Gitlab.edit_project(3, name: 'Gitlab-edit')
322 end
323
324 it 'gets the correct resource' do
325 expect(a_put('/projects/3').with(body: { name: 'Gitlab-edit' })).to have_been_made
326 end
327
328 it 'returns information about an edited project' do
329 expect(@edited_project.name).to eq('Gitlab-edit')
330 end
331 end
332
333 context 'using namespaced project path' do
334 it 'encodes the path properly' do
335 stub = stub_put('/projects/namespace%2Fpath', 'project_edit').with(body: { name: 'Gitlab-edit' })
336 Gitlab.edit_project('namespace/path', name: 'Gitlab-edit')
333337 expect(stub).to have_been_requested
334338 end
335339 end
336340 end
337341
338 describe ".delete_project_hook" do
339 context "when empty response" do
340 before do
341 stub_request(:delete, "#{Gitlab.endpoint}/projects/1/hooks/1").
342 with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
343 to_return(body: '')
342 describe '.delete_project_hook' do
343 context 'when empty response' do
344 before do
345 stub_request(:delete, "#{Gitlab.endpoint}/projects/1/hooks/1")
346 .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
347 .to_return(body: '')
344348 @hook = Gitlab.delete_project_hook(1, 1)
345349 end
346350
347 it "gets the correct resource" do
348 expect(a_delete("/projects/1/hooks/1")).to have_been_made
349 end
350
351 it "returns false" do
351 it 'gets the correct resource' do
352 expect(a_delete('/projects/1/hooks/1')).to have_been_made
353 end
354
355 it 'returns false' do
352356 expect(@hook).to be(false)
353357 end
354358 end
355359
356 context "when JSON response" do
357 before do
358 stub_delete("/projects/1/hooks/1", "project_hook")
360 context 'when JSON response' do
361 before do
362 stub_delete('/projects/1/hooks/1', 'project_hook')
359363 @hook = Gitlab.delete_project_hook(1, 1)
360364 end
361365
362 it "gets the correct resource" do
363 expect(a_delete("/projects/1/hooks/1")).to have_been_made
364 end
365
366 it "returns information about a deleted hook" do
367 expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
368 end
369 end
370 end
371
372 describe ".push_rule" do
373 before do
374 stub_get("/projects/1/push_rule", "push_rule")
366 it 'gets the correct resource' do
367 expect(a_delete('/projects/1/hooks/1')).to have_been_made
368 end
369
370 it 'returns information about a deleted hook' do
371 expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci')
372 end
373 end
374 end
375
376 describe '.push_rule' do
377 before do
378 stub_get('/projects/1/push_rule', 'push_rule')
375379 @push_rule = Gitlab.push_rule(1)
376380 end
377381
378 it "gets the correct resource" do
379 expect(a_get("/projects/1/push_rule")).to have_been_made
380 end
381
382 it "returns information about a push rule" do
383 expect(@push_rule.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b")
384 end
385 end
386
387 describe ".add_push_rule" do
388 before do
389 stub_post("/projects/1/push_rule", "push_rule")
390 @push_rule = Gitlab.add_push_rule(1, { deny_delete_tag: false, commit_message_regex: "\\b[A-Z]{3}-[0-9]+\\b" })
391 end
392
393 it "gets the correct resource" do
394 expect(a_post("/projects/1/push_rule")).to have_been_made
395 end
396
397 it "returns information about an added push rule" do
398 expect(@push_rule.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b")
399 end
400 end
401
402 describe ".edit_push_rule" do
403 before do
404 stub_put("/projects/1/push_rule", "push_rule")
405 @push_rule = Gitlab.edit_push_rule(1, { deny_delete_tag: false, commit_message_regex: "\\b[A-Z]{3}-[0-9]+\\b" })
406 end
407
408 it "gets the correct resource" do
409 expect(a_put("/projects/1/push_rule")).to have_been_made
410 end
411
412 it "returns information about an edited push rule" do
413 expect(@push_rule.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b")
414 end
415 end
416
417 describe ".delete_push_rule" do
418 context "when empty response" do
419 before do
420 stub_request(:delete, "#{Gitlab.endpoint}/projects/1/push_rule").
421 with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
422 to_return(body: '')
382 it 'gets the correct resource' do
383 expect(a_get('/projects/1/push_rule')).to have_been_made
384 end
385
386 it 'returns information about a push rule' do
387 expect(@push_rule.commit_message_regex).to eq('\\b[A-Z]{3}-[0-9]+\\b')
388 end
389 end
390
391 describe '.add_push_rule' do
392 before do
393 stub_post('/projects/1/push_rule', 'push_rule')
394 @push_rule = Gitlab.add_push_rule(1, deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b')
395 end
396
397 it 'gets the correct resource' do
398 expect(a_post('/projects/1/push_rule')).to have_been_made
399 end
400
401 it 'returns information about an added push rule' do
402 expect(@push_rule.commit_message_regex).to eq('\\b[A-Z]{3}-[0-9]+\\b')
403 end
404 end
405
406 describe '.edit_push_rule' do
407 before do
408 stub_put('/projects/1/push_rule', 'push_rule')
409 @push_rule = Gitlab.edit_push_rule(1, deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b')
410 end
411
412 it 'gets the correct resource' do
413 expect(a_put('/projects/1/push_rule')).to have_been_made
414 end
415
416 it 'returns information about an edited push rule' do
417 expect(@push_rule.commit_message_regex).to eq('\\b[A-Z]{3}-[0-9]+\\b')
418 end
419 end
420
421 describe '.delete_push_rule' do
422 context 'when empty response' do
423 before do
424 stub_request(:delete, "#{Gitlab.endpoint}/projects/1/push_rule")
425 .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
426 .to_return(body: '')
423427 @push_rule = Gitlab.delete_push_rule(1)
424428 end
425429
426 it "gets the correct resource" do
427 expect(a_delete("/projects/1/push_rule")).to have_been_made
428 end
429
430 it "returns false" do
430 it 'gets the correct resource' do
431 expect(a_delete('/projects/1/push_rule')).to have_been_made
432 end
433
434 it 'returns false' do
431435 expect(@push_rule).to be(false)
432436 end
433437 end
434438
435 context "when JSON response" do
436 before do
437 stub_delete("/projects/1/push_rule", "push_rule")
439 context 'when JSON response' do
440 before do
441 stub_delete('/projects/1/push_rule', 'push_rule')
438442 @push_rule = Gitlab.delete_push_rule(1)
439443 end
440444
441 it "gets the correct resource" do
442 expect(a_delete("/projects/1/push_rule")).to have_been_made
443 end
444
445 it "returns information about a deleted push rule" do
446 expect(@push_rule.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b")
447 end
448 end
449 end
450
451 describe ".make_forked_from" do
452 before do
453 stub_post("/projects/42/fork/24", "project_fork_link")
445 it 'gets the correct resource' do
446 expect(a_delete('/projects/1/push_rule')).to have_been_made
447 end
448
449 it 'returns information about a deleted push rule' do
450 expect(@push_rule.commit_message_regex).to eq('\\b[A-Z]{3}-[0-9]+\\b')
451 end
452 end
453 end
454
455 describe '.make_forked_from' do
456 before do
457 stub_post('/projects/42/fork/24', 'project_fork_link')
454458 @forked_project_link = Gitlab.make_forked_from(42, 24)
455459 end
456460
457 it "gets the correct resource" do
458 expect(a_post("/projects/42/fork/24")).to have_been_made
459 end
460
461 it "returns information about a forked project" do
461 it 'gets the correct resource' do
462 expect(a_post('/projects/42/fork/24')).to have_been_made
463 end
464
465 it 'returns information about a forked project' do
462466 expect(@forked_project_link.forked_from_project_id).to eq(24)
463467 expect(@forked_project_link.forked_to_project_id).to eq(42)
464468 end
465469 end
466470
467 describe ".remove_forked" do
468 before do
469 stub_delete("/projects/42/fork", "project_fork_link")
471 describe '.remove_forked' do
472 before do
473 stub_delete('/projects/42/fork', 'project_fork_link')
470474 @forked_project_link = Gitlab.remove_forked(42)
471475 end
472476
473 it "gets the correct resource" do
474 expect(a_delete("/projects/42/fork")).to have_been_made
475 end
476
477 it "returns information about an unforked project" do
477 it 'gets the correct resource' do
478 expect(a_delete('/projects/42/fork')).to have_been_made
479 end
480
481 it 'returns information about an unforked project' do
478482 expect(@forked_project_link.forked_to_project_id).to eq(42)
479483 end
480484 end
481485
482 describe ".deploy_keys" do
483 before do
484 stub_get("/projects/42/deploy_keys", "project_keys")
486 describe '.deploy_keys' do
487 before do
488 stub_get('/projects/42/deploy_keys', 'project_keys')
485489 @deploy_keys = Gitlab.deploy_keys(42)
486490 end
487491
488 it "gets the correct resource" do
489 expect(a_get("/projects/42/deploy_keys")).to have_been_made
490 end
491
492 it "returns project deploy keys" do
492 it 'gets the correct resource' do
493 expect(a_get('/projects/42/deploy_keys')).to have_been_made
494 end
495
496 it 'returns project deploy keys' do
493497 expect(@deploy_keys).to be_a Gitlab::PaginatedResponse
494498 expect(@deploy_keys.first.id).to eq 2
495 expect(@deploy_keys.first.title).to eq "Key Title"
499 expect(@deploy_keys.first.title).to eq 'Key Title'
496500 expect(@deploy_keys.first.key).to match(/ssh-rsa/)
497501 end
498502 end
499503
500 describe ".deploy_key" do
501 before do
502 stub_get("/projects/42/deploy_keys/2", "project_key")
504 describe '.deploy_key' do
505 before do
506 stub_get('/projects/42/deploy_keys/2', 'project_key')
503507 @deploy_key = Gitlab.deploy_key(42, 2)
504508 end
505509
506 it "gets the correct resource" do
507 expect(a_get("/projects/42/deploy_keys/2")).to have_been_made
508 end
509
510 it "returns project deploy key" do
510 it 'gets the correct resource' do
511 expect(a_get('/projects/42/deploy_keys/2')).to have_been_made
512 end
513
514 it 'returns project deploy key' do
511515 expect(@deploy_key.id).to eq 2
512 expect(@deploy_key.title).to eq "Key Title"
516 expect(@deploy_key.title).to eq 'Key Title'
513517 expect(@deploy_key.key).to match(/ssh-rsa/)
514518 end
515519 end
516520
517 describe ".create_deploy_key" do
521 describe '.create_deploy_key' do
518522 context 'no options' do
519523 before do
520 stub_post("/projects/42/deploy_keys", "project_key")
524 stub_post('/projects/42/deploy_keys', 'project_key')
521525 @deploy_key = Gitlab.create_deploy_key(42, 'My Key', 'Key contents')
522526 end
523527
524 it "gets the correct resource" do
525 expect(a_post("/projects/42/deploy_keys").
526 with(body: { title: 'My Key', key: 'Key contents' })).to have_been_made
527 end
528
529 it "returns information about a created key" do
528 it 'gets the correct resource' do
529 expect(a_post('/projects/42/deploy_keys')
530 .with(body: { title: 'My Key', key: 'Key contents' })).to have_been_made
531 end
532
533 it 'returns information about a created key' do
530534 expect(@deploy_key.id).to eq(2)
531535 end
532536 end
533537
534538 context 'some options' do
535539 before do
536 stub_post("/projects/42/deploy_keys", "project_key")
540 stub_post('/projects/42/deploy_keys', 'project_key')
537541 @deploy_key = Gitlab.create_deploy_key(42, 'My Key', 'Key contents', can_push: true)
538542 end
539543
540 it "gets the correct resource" do
541 expect(a_post("/projects/42/deploy_keys").
542 with(body: { title: 'My Key', key: 'Key contents', can_push: true })).to have_been_made
543 end
544
545 it "returns information about a created key" do
544 it 'gets the correct resource' do
545 expect(a_post('/projects/42/deploy_keys')
546 .with(body: { title: 'My Key', key: 'Key contents', can_push: true })).to have_been_made
547 end
548
549 it 'returns information about a created key' do
546550 expect(@deploy_key.id).to eq(2)
547551 end
548552 end
549553 end
550554
551 describe ".delete_deploy_key" do
552 before do
553 stub_delete("/projects/42/deploy_keys/2", "project_key")
555 describe '.delete_deploy_key' do
556 before do
557 stub_delete('/projects/42/deploy_keys/2', 'project_key')
554558 @deploy_key = Gitlab.delete_deploy_key(42, 2)
555559 end
556560
557 it "gets the correct resource" do
558 expect(a_delete("/projects/42/deploy_keys/2")).to have_been_made
559 end
560
561 it "returns information about a deleted key" do
561 it 'gets the correct resource' do
562 expect(a_delete('/projects/42/deploy_keys/2')).to have_been_made
563 end
564
565 it 'returns information about a deleted key' do
562566 expect(@deploy_key.id).to eq(2)
563567 end
564568 end
565569
566 describe ".enable_deploy_key" do
567 before do
568 stub_post("/projects/42/deploy_keys/2/enable", "project_key")
570 describe '.enable_deploy_key' do
571 before do
572 stub_post('/projects/42/deploy_keys/2/enable', 'project_key')
569573 @deploy_key = Gitlab.enable_deploy_key(42, 2)
570574 end
571575
572 it "gets the correct resource" do
573 expect(a_post("/projects/42/deploy_keys/2/enable").
574 with(body: { id: '42', key_id: '2' })).to have_been_made
575 end
576
577 it "returns information about an enabled key" do
576 it 'gets the correct resource' do
577 expect(a_post('/projects/42/deploy_keys/2/enable')
578 .with(body: { id: '42', key_id: '2' })).to have_been_made
579 end
580
581 it 'returns information about an enabled key' do
578582 expect(@deploy_key.id).to eq(2)
579583 end
580584 end
581585
582 describe ".disable_deploy_key" do
583 before do
584 stub_post("/projects/42/deploy_keys/2/disable", "project_key")
586 describe '.disable_deploy_key' do
587 before do
588 stub_post('/projects/42/deploy_keys/2/disable', 'project_key')
585589 @deploy_key = Gitlab.disable_deploy_key(42, 2)
586590 end
587591
588 it "gets the correct resource" do
589 expect(a_post("/projects/42/deploy_keys/2/disable").
590 with(body: { id: '42', key_id: '2' })).to have_been_made
591 end
592
593 it "returns information about a disabled key" do
592 it 'gets the correct resource' do
593 expect(a_post('/projects/42/deploy_keys/2/disable')
594 .with(body: { id: '42', key_id: '2' })).to have_been_made
595 end
596
597 it 'returns information about a disabled key' do
594598 expect(@deploy_key.id).to eq(2)
595599 end
596600 end
597601
598 describe ".share_project_with_group" do
599 before do
600 stub_post("/projects/3/share", "group")
602 describe '.share_project_with_group' do
603 before do
604 stub_post('/projects/3/share', 'group')
601605 @group = Gitlab.share_project_with_group(3, 10, 40)
602606 end
603607
604 it "gets the correct resource" do
605 expect(a_post("/projects/3/share").
606 with(body: { group_id: '10', group_access: '40' })).to have_been_made
607 end
608
609 it "returns information about an added group" do
608 it 'gets the correct resource' do
609 expect(a_post('/projects/3/share')
610 .with(body: { group_id: '10', group_access: '40' })).to have_been_made
611 end
612
613 it 'returns information about an added group' do
610614 expect(@group.id).to eq(10)
611615 end
612616 end
613617
614 describe ".unshare_project_with_group" do
615 before do
616 stub_delete("/projects/3/share/10", "group")
618 describe '.unshare_project_with_group' do
619 before do
620 stub_delete('/projects/3/share/10', 'group')
617621 @group = Gitlab.unshare_project_with_group(3, 10)
618622 end
619623
620 it "gets the correct resource" do
621 expect(a_delete("/projects/3/share/10")).to have_been_made
622 end
623 end
624
625 describe ".star_project" do
626 before do
627 stub_post("/projects/3/star", "project_star")
624 it 'gets the correct resource' do
625 expect(a_delete('/projects/3/share/10')).to have_been_made
626 end
627 end
628
629 describe '.transfer_project' do
630 before do
631 stub_put('/projects/3/transfer', 'transfer_project')
632 @transfered_project = Gitlab.transfer_project(3, 'yolo')
633 end
634
635 it 'gets the correct resource' do
636 expect(a_put('/projects/3/transfer')
637 .with(body: { namespace: 'yolo' })).to have_been_made
638 end
639
640 it 'returns information about the transfered project' do
641 expect(@transfered_project.id).to eq(1)
642 end
643 end
644
645 describe '.star_project' do
646 before do
647 stub_post('/projects/3/star', 'project_star')
628648 @starred_project = Gitlab.star_project(3)
629649 end
630650
631 it "gets the correct resource" do
632 expect(a_post("/projects/3/star")).to have_been_made
633 end
634
635 it "returns information about the starred project" do
651 it 'gets the correct resource' do
652 expect(a_post('/projects/3/star')).to have_been_made
653 end
654
655 it 'returns information about the starred project' do
636656 expect(@starred_project.id).to eq(3)
637657 end
638658 end
639659
640 describe ".unstar_project" do
641 before do
642 stub_delete("/projects/3/star", "project_unstar")
660 describe '.unstar_project' do
661 before do
662 stub_delete('/projects/3/star', 'project_unstar')
643663 @unstarred_project = Gitlab.unstar_project(3)
644664 end
645665
646 it "gets the correct resource" do
647 expect(a_delete("/projects/3/star")).to have_been_made
648 end
649
650 it "returns information about the unstarred project" do
666 it 'gets the correct resource' do
667 expect(a_delete('/projects/3/star')).to have_been_made
668 end
669
670 it 'returns information about the unstarred project' do
651671 expect(@unstarred_project.id).to eq(3)
652672 end
653673 end
654674
655 describe ".user_projects" do
675 describe '.user_projects' do
656676 let(:user_id) { 1 }
657677 let(:project_id) { 1 }
658678
659679 before do
660 stub_get("/users/#{user_id}/projects", "user_projects")
680 stub_get("/users/#{user_id}/projects", 'user_projects')
661681 @user_projects = Gitlab.user_projects(user_id)
662682 end
663683
664 it "gets the correct resource" do
684 it 'gets the correct resource' do
665685 expect(a_get("/users/#{user_id}/projects")).to have_been_made
666686 end
667687
668 it "returns a paginated response of projects" do
688 it 'returns a paginated response of projects' do
669689 expect(@user_projects).to be_a Gitlab::PaginatedResponse
670690 expect(@user_projects.first.id).to eq(project_id)
671691 expect(@user_projects.first.owner.id).to eq(user_id)
672692 end
673693 end
694
695 describe '.upload_file' do
696 let(:id) { 1 }
697 let(:file) { File.open(File::NULL, 'r') }
698
699 before do
700 stub_post("/projects/#{id}/uploads", 'upload_file')
701 @file = Gitlab.upload_file(id, file)
702 end
703
704 it 'gets the correct resource' do
705 expect(a_post("/projects/#{id}/uploads")).to have_been_made
706 end
707
708 it 'returns information about the uploaded file' do
709 expect(@file.alt).to eq('null')
710 expect(@file.url).to eq('/uploads/f22e67e35e1bcb339058212c54bb8772/null')
711 expect(@file.markdown).to eq('[null](/uploads/f22e67e35e1bcb339058212c54bb8772/null)')
712 end
713 end
714
715 describe '.project_templates' do
716 before do
717 stub_get('/projects/3/templates/licenses', 'project_templates')
718 @project_templates = Gitlab.project_templates(3, 'licenses')
719 end
720
721 it 'gets the correct resource' do
722 expect(a_get('/projects/3/templates/licenses')).to have_been_made
723 end
724
725 it "returns a paginated response of project's templates" do
726 expect(@project_templates).to be_a Gitlab::PaginatedResponse
727 end
728 end
729
730 describe '.project_template' do
731 context 'when dockerfiles' do
732 before do
733 stub_get('/projects/3/templates/dockerfiles/dock', 'dockerfile_project_template')
734 @project_template = Gitlab.project_template(3, 'dockerfiles', 'dock')
735 end
736
737 it 'gets the correct resource' do
738 expect(a_get('/projects/3/templates/dockerfiles/dock')).to have_been_made
739 end
740 end
741
742 context 'when licenses' do
743 before do
744 stub_get('/projects/3/templates/licenses/mit', 'license_project_template')
745 @project_template = Gitlab.project_template(3, 'licenses', 'mit')
746 end
747
748 it 'gets the correct resource' do
749 expect(a_get('/projects/3/templates/licenses/mit')).to have_been_made
750 end
751 end
752 end
674753 end
0 # frozen_string_literal: true
1
2 require 'spec_helper'
3
4 describe Gitlab::Client do
5 describe '.protected_tags' do
6 before do
7 stub_get('/projects/1/protected_tags', 'protected_tags')
8 @protected_tags = Gitlab.protected_tags(1)
9 end
10
11 it 'gets the correct resource' do
12 expect(a_get('/projects/1/protected_tags')).to have_been_made
13 end
14
15 it "returns a response of a project's protected_tags" do
16 expect(@protected_tags).to be_a Gitlab::PaginatedResponse
17 end
18 end
19
20 describe '.protected_tag' do
21 before do
22 stub_get('/projects/1/protected_tags/release-1-0', 'protected_tag')
23 @protected_tag = Gitlab.protected_tag(1, 'release-1-0')
24 end
25
26 it 'gets the correct resource' do
27 expect(a_get('/projects/1/protected_tags/release-1-0')).to have_been_made
28 end
29
30 it 'returns correct information about the protected_tag' do
31 expect(@protected_tag.name).to eq 'release-1-0'
32 end
33 end
34
35 describe '.protect_repository_tag' do
36 before do
37 stub_post('/projects/1/protected_tags', 'protected_tag')
38 @protected_tag = Gitlab.protect_repository_tag(1, 'release-1-0')
39 end
40
41 it 'gets the correct resource' do
42 expect(a_post('/projects/1/protected_tags')
43 .with(body: { name: 'release-1-0' })).to have_been_made
44 end
45
46 it 'returns correct information about the protected repository tag' do
47 expect(@protected_tag.name).to eq 'release-1-0'
48 end
49 end
50
51 describe '.unprotect_repository_tag' do
52 before do
53 stub_delete('/projects/1/protected_tags/release-1-0', 'empty')
54 Gitlab.unprotect_repository_tag(1, 'release-1-0')
55 end
56
57 it 'gets the correct resource' do
58 expect(a_delete('/projects/1/protected_tags/release-1-0')).to have_been_made
59 end
60 end
61 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
79 it { is_expected.to respond_to :repo_tree }
810 it { is_expected.to respond_to :repo_compare }
911
10 describe ".tags" do
12 describe '.tags' do
1113 before do
12 stub_get("/projects/3/repository/tags", "project_tags")
14 stub_get('/projects/3/repository/tags', 'project_tags')
1315 @tags = Gitlab.tags(3)
1416 end
1517
16 it "gets the correct resource" do
17 expect(a_get("/projects/3/repository/tags")).to have_been_made
18 it 'gets the correct resource' do
19 expect(a_get('/projects/3/repository/tags')).to have_been_made
1820 end
1921
20 it "returns a paginated response of repository tags" do
22 it 'returns a paginated response of repository tags' do
2123 expect(@tags).to be_a Gitlab::PaginatedResponse
22 expect(@tags.first.name).to eq("v2.8.2")
24 expect(@tags.first.name).to eq('v2.8.2')
2325 end
2426 end
2527
26 describe ".create_tag" do
27 context "when lightweight" do
28 describe '.create_tag' do
29 context 'when lightweight' do
2830 before do
29 stub_post("/projects/3/repository/tags", "project_tag_lightweight")
31 stub_post('/projects/3/repository/tags', 'project_tag_lightweight')
3032 @tag = Gitlab.create_tag(3, 'v1.0.0', '2695effb5807a22ff3d138d593fd856244e155e7')
3133 end
3234
33 it "gets the correct resource" do
34 expect(a_post("/projects/3/repository/tags")).to have_been_made
35 it 'gets the correct resource' do
36 expect(a_post('/projects/3/repository/tags')).to have_been_made
3537 end
3638
37 it "returns information about a new repository tag" do
38 expect(@tag.name).to eq("v1.0.0")
39 it 'returns information about a new repository tag' do
40 expect(@tag.name).to eq('v1.0.0')
3941 expect(@tag.message).to eq(nil)
4042 end
4143 end
4244
43 context "when annotated" do
45 context 'when annotated' do
4446 before do
45 stub_post("/projects/3/repository/tags", "project_tag_annotated")
47 stub_post('/projects/3/repository/tags', 'project_tag_annotated')
4648 @tag = Gitlab.create_tag(3, 'v1.1.0', '2695effb5807a22ff3d138d593fd856244e155e7', 'Release 1.1.0')
4749 end
4850
49 it "gets the correct resource" do
50 expect(a_post("/projects/3/repository/tags")).to have_been_made
51 it 'gets the correct resource' do
52 expect(a_post('/projects/3/repository/tags')).to have_been_made
5153 end
5254
53 it "returns information about a new repository tag" do
54 expect(@tag.name).to eq("v1.1.0")
55 expect(@tag.message).to eq("Release 1.1.0")
55 it 'returns information about a new repository tag' do
56 expect(@tag.name).to eq('v1.1.0')
57 expect(@tag.message).to eq('Release 1.1.0')
5658 end
5759 end
5860 end
5961
60 describe ".tree" do
62 describe '.tree' do
6163 before do
62 stub_get("/projects/3/repository/tree", "tree")
64 stub_get('/projects/3/repository/tree', 'tree')
6365 @tree = Gitlab.tree(3)
6466 end
6567
66 it "gets the correct resource" do
67 expect(a_get("/projects/3/repository/tree")).to have_been_made
68 it 'gets the correct resource' do
69 expect(a_get('/projects/3/repository/tree')).to have_been_made
6870 end
6971
70 it "returns a paginated response of repository tree files (root level)" do
72 it 'returns a paginated response of repository tree files (root level)' do
7173 expect(@tree).to be_a Gitlab::PaginatedResponse
72 expect(@tree.first.name).to eq("app")
74 expect(@tree.first.name).to eq('app')
7375 end
7476 end
7577
76 describe ".compare" do
78 describe '.compare' do
7779 before do
78 stub_get("/projects/3/repository/compare", "compare_merge_request_diff").
79 with(query: { from: "master", to: "feature" })
80 stub_get('/projects/3/repository/compare', 'compare_merge_request_diff')
81 .with(query: { from: 'master', to: 'feature' })
8082 @diff = Gitlab.compare(3, 'master', 'feature')
8183 end
8284
83 it "gets the correct resource" do
84 expect(a_get("/projects/3/repository/compare").
85 with(query: { from: "master", to: "feature" })).to have_been_made
85 it 'gets the correct resource' do
86 expect(a_get('/projects/3/repository/compare')
87 .with(query: { from: 'master', to: 'feature' })).to have_been_made
8688 end
8789
88 it "gets diffs of a merge request" do
90 it 'gets diffs of a merge request' do
8991 expect(@diff.diffs).to be_kind_of Array
90 expect(@diff.diffs.last["new_path"]).to eq "files/js/application.js"
92 expect(@diff.diffs.last['new_path']).to eq 'files/js/application.js'
93 end
94 end
95
96 describe '.merge_base' do
97 before do
98 stub_get('/projects/3/repository/merge_base', 'merge_base')
99 .with(query: { refs: %w[master feature] })
100 @response = Gitlab.merge_base(3, %w[master feature])
101 end
102
103 it 'gets the correct resource' do
104 expect(a_get('/projects/3/repository/merge_base')
105 .with(query: { refs: %w[master feature] })).to have_been_made
106 end
107
108 it 'gets common ancestor of the two refs' do
109 expect(@response).to be_kind_of Gitlab::ObjectifiedHash
110 expect(@response.id).to eq '1a0b36b3cdad1d2ee32457c102a8c0b7056fa863'
91111 end
92112 end
93113 end
0 require "spec_helper"
0 # frozen_string_literal: true
1
2 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".file_contents" do
5 describe '.file_contents' do
46 before do
5 stub_get("/projects/3/repository/files/Gemfile/raw?ref=master", "raw_file")
6 @file_contents = Gitlab.file_contents(3, "Gemfile")
7 stub_get('/projects/3/repository/files/Gemfile/raw?ref=master', 'raw_file')
8 @file_contents = Gitlab.file_contents(3, 'Gemfile')
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/repository/files/Gemfile/raw?ref=master")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/repository/files/Gemfile/raw?ref=master')).to have_been_made
1113 end
1214
13 it "returns file contents" do
15 it 'returns file contents' do
1416 expect(@file_contents).to eq("source 'https://rubygems.org'\ngem 'rails', '4.1.2'\n")
1517 end
1618 end
1719
18 describe ".get_file" do
20 describe '.get_file' do
1921 before do
20 stub_get("/projects/3/repository/files/README%2Emd?ref=master", "get_repository_file")
22 stub_get('/projects/3/repository/files/README%2Emd?ref=master', 'get_repository_file')
2123 @file = Gitlab.get_file(3, 'README.md', 'master')
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_get("/projects/3/repository/files/README%2Emd?ref=master")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_get('/projects/3/repository/files/README%2Emd?ref=master')).to have_been_made
2628 end
2729
28 it "returns the base64 encoded file" do
29 expect(@file.file_path).to eq "README.md"
30 expect(@file.ref).to eq "master"
30 it 'returns the base64 encoded file' do
31 expect(@file.file_path).to eq 'README.md'
32 expect(@file.ref).to eq 'master'
3133 expect(@file.content).to eq "VGhpcyBpcyBhICpSRUFETUUqIQ==\n"
3234 end
3335 end
3436
35 describe ".create_file" do
36 let(:api_path) { "/projects/3/repository/files/path" }
37 let!(:request_stub) { stub_post(api_path, "repository_file") }
38 let!(:file) { Gitlab.create_file(3, "path", "branch", "content", "commit message", author_name: "joe") }
37 describe '.create_file' do
38 let(:api_path) { '/projects/3/repository/files/path' }
39 let!(:request_stub) { stub_post(api_path, 'repository_file') }
40 let!(:file) { Gitlab.create_file(3, 'path', 'branch', 'content', 'commit message', author_name: 'joe') }
3941
40 it "creates the correct resource" do
42 it 'creates the correct resource' do
4143 expected_parameters = {
42 author_name: "joe",
43 branch: "branch",
44 commit_message: "commit message"
44 author_name: 'joe',
45 branch: 'branch',
46 commit_message: 'commit message'
4547 }
4648 expect(a_post(api_path).with(body: hash_including(expected_parameters))).to have_been_made
4749 end
4850
49 it "returns information about the new file" do
50 expect(file.file_path).to eq "path"
51 expect(file.branch_name).to eq "branch"
51 it 'returns information about the new file' do
52 expect(file.file_path).to eq 'path'
53 expect(file.branch_name).to eq 'branch'
5254 end
5355 end
5456
55 describe ".edit_file" do
56 let(:api_path) { "/projects/3/repository/files/path" }
57 let!(:request_stub) { stub_put(api_path, "repository_file") }
58 let!(:file) { Gitlab.edit_file(3, "path", "branch", "content", "commit message", author_name: "joe") }
57 describe '.edit_file' do
58 let(:api_path) { '/projects/3/repository/files/path' }
59 let!(:request_stub) { stub_put(api_path, 'repository_file') }
60 let!(:file) { Gitlab.edit_file(3, 'path', 'branch', 'content', 'commit message', author_name: 'joe') }
5961
60 it "updates the correct resource" do
62 it 'updates the correct resource' do
6163 expected_parameters = {
62 author_name: "joe",
63 branch: "branch",
64 commit_message: "commit message"
64 author_name: 'joe',
65 branch: 'branch',
66 commit_message: 'commit message'
6567 }
6668 expect(a_put(api_path).with(body: hash_including(expected_parameters))).to have_been_made
6769 end
6870
69 it "returns information about the new file" do
70 expect(file.file_path).to eq "path"
71 expect(file.branch_name).to eq "branch"
71 it 'returns information about the new file' do
72 expect(file.file_path).to eq 'path'
73 expect(file.branch_name).to eq 'branch'
7274 end
7375 end
7476
75 describe ".remove_file" do
76 let(:api_path) { "/projects/3/repository/files/path" }
77 let!(:request_stub) { stub_delete(api_path, "repository_file") }
78 let!(:file) { Gitlab.remove_file(3, "path", "branch", "commit message", author_name: "joe") }
77 describe '.remove_file' do
78 let(:api_path) { '/projects/3/repository/files/path' }
79 let!(:request_stub) { stub_delete(api_path, 'repository_file') }
80 let!(:file) { Gitlab.remove_file(3, 'path', 'branch', 'commit message', author_name: 'joe') }
7981
80 it "updates the correct resource" do
82 it 'updates the correct resource' do
8183 expected_parameters = {
82 author_name: "joe",
83 branch: "branch",
84 commit_message: "commit message"
84 author_name: 'joe',
85 branch: 'branch',
86 commit_message: 'commit message'
8587 }
8688 expect(a_delete(api_path).with(body: hash_including(expected_parameters))).to have_been_made
8789 end
8890
89 it "returns information about the new file" do
90 expect(file.file_path).to eq "path"
91 expect(file.branch_name).to eq "branch"
91 it 'returns information about the new file' do
92 expect(file.file_path).to eq 'path'
93 expect(file.branch_name).to eq 'branch'
9294 end
9395 end
9496 end
0 # frozen_string_literal: true
1
2 require 'spec_helper'
3
4 describe Gitlab::Client do
5 describe '.edit_submodule' do
6 let(:api_path) { '/projects/3/repository/submodules/submodule' }
7 let(:options) do
8 {
9 branch: 'branch',
10 commit_sha: '3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88',
11 commit_message: 'commit message'
12 }
13 end
14
15 before do
16 stub_put(api_path, 'repository_submodule')
17 @submodule = Gitlab.edit_submodule(3, 'submodule', options)
18 end
19
20 it 'updates the correct resource' do
21 expect(a_put(api_path).with(body: hash_including(options))).to have_been_made
22 end
23
24 it 'returns information about the updated submodule' do
25 expect(@submodule.short_id).to eq 'ed899a2f4b5'
26 expect(@submodule.status).to be_nil
27 end
28 end
29 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3
4 describe ".runners" do
5 describe '.runners' do
56 before do
6 stub_get("/runners", "runners")
7 stub_get('/runners', 'runners')
78 end
89
910 context 'without scope' do
1112 @runner = Gitlab.runners
1213 end
1314
14 it "gets the correct resource" do
15 expect(a_get("/runners")).to have_been_made
15 it 'gets the correct resource' do
16 expect(a_get('/runners')).to have_been_made
1617 end
1718
18 it "returns a paginated response of runners" do
19 it 'returns a paginated response of runners' do
1920 expect(@runner).to be_a Gitlab::PaginatedResponse
2021 expect(@runner.first.id).to eq(6)
2122 expect(@runner.first.description).to eq('test-1-20150125')
2425
2526 context 'with scope' do
2627 before do
27 stub_get("/runners?scope=online", "runners")
28 @runner = Gitlab.runners({scope: :online})
28 stub_get('/runners?scope=online', 'runners')
29 @runner = Gitlab.runners(scope: :online)
2930 end
3031
31 it "gets the correct resource" do
32 expect(a_get("/runners").with(query: { scope: :online })).to have_been_made
32 it 'gets the correct resource' do
33 expect(a_get('/runners').with(query: { scope: :online })).to have_been_made
3334 end
3435
35 it "returns a paginated response of runners" do
36 it 'returns a paginated response of runners' do
3637 expect(@runner).to be_a Gitlab::PaginatedResponse
3738 expect(@runner.first.id).to eq(6)
3839 expect(@runner.first.description).to eq('test-1-20150125')
3940 end
4041 end
41
4242 end
4343
44 describe ".all_runners" do
44 describe '.all_runners' do
4545 before do
46 stub_get("/runners/all", "runners")
46 stub_get('/runners/all', 'runners')
4747 end
4848
4949 context 'without scope' do
5151 @runner = Gitlab.all_runners
5252 end
5353
54 it "gets the correct resource" do
55 expect(a_get("/runners/all")).to have_been_made
54 it 'gets the correct resource' do
55 expect(a_get('/runners/all')).to have_been_made
5656 end
5757
58 it "returns a paginated response of runners" do
58 it 'returns a paginated response of runners' do
5959 expect(@runner).to be_a Gitlab::PaginatedResponse
6060 expect(@runner.first.id).to eq(6)
6161 expect(@runner.first.description).to eq('test-1-20150125')
6464
6565 context 'with scope' do
6666 before do
67 stub_get("/runners/all?scope=online", "runners")
68 @runner = Gitlab.all_runners({scope: :online})
67 stub_get('/runners/all?scope=online', 'runners')
68 @runner = Gitlab.all_runners(scope: :online)
6969 end
7070
71 it "gets the correct resource" do
72 expect(a_get("/runners/all").with(query: { scope: :online })).to have_been_made
71 it 'gets the correct resource' do
72 expect(a_get('/runners/all').with(query: { scope: :online })).to have_been_made
7373 end
7474
75 it "returns a paginated response of runners" do
75 it 'returns a paginated response of runners' do
7676 expect(@runner).to be_a Gitlab::PaginatedResponse
7777 expect(@runner.first.id).to eq(6)
7878 expect(@runner.first.description).to eq('test-1-20150125')
8080 end
8181 end
8282
83 describe ".runner" do
83 describe '.runner' do
8484 before do
85 stub_get("/runners/6", "runner")
85 stub_get('/runners/6', 'runner')
8686 @runners = Gitlab.runner(6)
8787 end
8888
89 it "gets the correct resource" do
90 expect(a_get("/runners/6")).to have_been_made
89 it 'gets the correct resource' do
90 expect(a_get('/runners/6')).to have_been_made
9191 end
9292
93 it "returns a response of a runner" do
93 it 'returns a response of a runner' do
9494 expect(@runners).to be_a Gitlab::ObjectifiedHash
9595 expect(@runners.id).to eq(6)
9696 expect(@runners.description).to eq('test-1-20150125')
9797 end
9898 end
9999
100 describe ".update_runner" do
100 describe '.update_runner' do
101101 before do
102 stub_put("/runners/6", "runner_edit").with(query: { description: "abcefg" })
103 @runner = Gitlab.update_runner(6, description: "abcefg" )
102 stub_put('/runners/6', 'runner_edit').with(query: { description: 'abcefg' })
103 @runner = Gitlab.update_runner(6, description: 'abcefg')
104104 end
105105
106 it "gets the correct resource" do
107 expect(a_put("/runners/6").with(query: { description: "abcefg" })).to have_been_made
106 it 'gets the correct resource' do
107 expect(a_put('/runners/6').with(query: { description: 'abcefg' })).to have_been_made
108108 end
109109
110 it "returns an updated response of a runner" do
110 it 'returns an updated response of a runner' do
111111 expect(@runner).to be_a Gitlab::ObjectifiedHash
112112 expect(@runner.description).to eq('abcefg')
113113 end
114114 end
115115
116 describe ".delete_runner" do
116 describe '.delete_runner' do
117117 before do
118 stub_delete("/runners/6", "runner_delete")
118 stub_delete('/runners/6', 'runner_delete')
119119 @runner = Gitlab.delete_runner(6)
120120 end
121121
122 it "gets the correct resource" do
123 expect(a_delete("/runners/6")).to have_been_made
122 it 'gets the correct resource' do
123 expect(a_delete('/runners/6')).to have_been_made
124124 end
125125
126 it "returns a response of the deleted runner" do
126 it 'returns a response of the deleted runner' do
127127 expect(@runner).to be_a Gitlab::ObjectifiedHash
128128 expect(@runner.id).to eq(6)
129129 end
134134 stub_get('/runners/1/jobs', 'runner_jobs')
135135 @jobs = Gitlab.runner_jobs(1)
136136 end
137
137138 it 'gets the correct resource' do
138139 expect(a_get('/runners/1/jobs')).to have_been_made
139140 end
140141 end
141142
142 describe ".project_runners" do
143 describe '.project_runners' do
143144 before do
144 stub_get("/projects/1/runners", "project_runners")
145 stub_get('/projects/1/runners', 'project_runners')
145146 @runners = Gitlab.project_runners(1)
146147 end
147148
148 it "gets the correct resource" do
149 expect(a_get("/projects/1/runners")).to have_been_made
149 it 'gets the correct resource' do
150 expect(a_get('/projects/1/runners')).to have_been_made
150151 end
151152
152 it "returns a paginated response of runners" do
153 it 'returns a paginated response of runners' do
153154 expect(@runners).to be_a Gitlab::PaginatedResponse
154155 expect(@runners.first.id).to eq(8)
155156 expect(@runners.first.description).to eq('test-2-20150125')
156157 end
157158 end
158159
159 describe ".project_enable_runner" do
160 describe '.project_enable_runner' do
160161 before do
161 stub_post("/projects/1/runners", "runner")
162 stub_post('/projects/1/runners', 'runner')
162163 @runner = Gitlab.project_enable_runner(1, 6)
163164 end
164165
165 it "gets the correct resource" do
166 expect(a_post("/projects/1/runners")).to have_been_made
166 it 'gets the correct resource' do
167 expect(a_post('/projects/1/runners')).to have_been_made
167168 end
168169
169 it "returns a response of the enabled runner" do
170 it 'returns a response of the enabled runner' do
170171 expect(@runner).to be_a Gitlab::ObjectifiedHash
171172 expect(@runner.id).to eq(6)
172173 expect(@runner.description).to eq('test-1-20150125')
173174 end
174175 end
175176
176 describe ".project_disable_runner" do
177 describe '.project_disable_runner' do
177178 before do
178 stub_delete("/projects/1/runners/6", "runner")
179 stub_delete('/projects/1/runners/6', 'runner')
179180 @runner = Gitlab.project_disable_runner(1, 6)
180181 end
181182
182 it "gets the correct resource" do
183 expect(a_delete("/projects/1/runners/6")).to have_been_made
183 it 'gets the correct resource' do
184 expect(a_delete('/projects/1/runners/6')).to have_been_made
184185 end
185186
186 it "returns a response of the disabled runner" do
187 it 'returns a response of the disabled runner' do
187188 expect(@runner).to be_a Gitlab::ObjectifiedHash
188189 expect(@runner.id).to eq(6)
189190 expect(@runner.description).to eq('test-1-20150125')
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".service" do
5 describe '.service' do
46 before do
5 stub_get("/projects/3/services/redmine", "service")
7 stub_get('/projects/3/services/redmine', 'service')
68 @service = Gitlab.service(3, :redmine)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/services/redmine")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/services/redmine')).to have_been_made
1113 end
1214
13 it "returns a information about a service of project" do
15 it 'returns a information about a service of project' do
1416 expect(@service.id).to eq 38
15 expect(@service.title).to eq("Redmine")
16 expect(@service.properties.project_url).to eq("https://example.com/projects/test_project/issue")
17 expect(@service.title).to eq('Redmine')
18 expect(@service.properties.project_url).to eq('https://example.com/projects/test_project/issue')
1719 end
1820 end
1921
20 describe ".change_service" do
22 describe '.change_service' do
2123 before do
22 stub_put("/projects/3/services/redmine", "service")
24 stub_put('/projects/3/services/redmine', 'service')
2325 @service = Gitlab.change_service(3, :redmine, new_issue_url: 'https://example.com/projects/test_project/issues/new',
2426 project_url: 'https://example.com/projects/test_project/issues',
2527 issues_url: 'https://example.com/issues/:id')
2628 end
2729
28 it "gets the correct resource" do
29 body = {new_issue_url: 'https://example.com/projects/test_project/issues/new',
30 project_url: 'https://example.com/projects/test_project/issues',
31 issues_url: 'https://example.com/issues/:id'}
32 expect(a_put("/projects/3/services/redmine").with(body: body)).to have_been_made
30 it 'gets the correct resource' do
31 body = { new_issue_url: 'https://example.com/projects/test_project/issues/new',
32 project_url: 'https://example.com/projects/test_project/issues',
33 issues_url: 'https://example.com/issues/:id' }
34 expect(a_put('/projects/3/services/redmine').with(body: body)).to have_been_made
3335 end
3436
35 it "returns information about a new service" do
37 it 'returns information about a new service' do
3638 expect(@service).to be_truthy
3739 end
3840 end
3941
40 describe ".delete_servoce" do
42 describe '.delete_servoce' do
4143 before do
42 stub_delete("/projects/3/services/redmine", "service")
44 stub_delete('/projects/3/services/redmine', 'service')
4345 @service = Gitlab.delete_service(3, :redmine)
4446 end
4547
46 it "gets the correct resource" do
47 expect(a_delete("/projects/3/services/redmine")).to have_been_made
48 it 'gets the correct resource' do
49 expect(a_delete('/projects/3/services/redmine')).to have_been_made
4850 end
4951
50 it "returns information about a deleted service" do
52 it 'returns information about a deleted service' do
5153 expect(@service).to be_truthy
5254 end
5355 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".sidekiq_queue_metrics" do
5 describe '.sidekiq_queue_metrics' do
46 before do
5 stub_get("/sidekiq/queue_metrics", 'sidekiq_queue_metrics')
7 stub_get('/sidekiq/queue_metrics', 'sidekiq_queue_metrics')
68 @sidekiq_queue_metrics = Gitlab.sidekiq_queue_metrics
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/sidekiq/queue_metrics")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/sidekiq/queue_metrics')).to have_been_made
1113 end
1214
13 it "returns a information about a sidekiq default queue" do
15 it 'returns a information about a sidekiq default queue' do
1416 expect(@sidekiq_queue_metrics.queues.default.backlog).to eq 0
1517 expect(@sidekiq_queue_metrics.queues.default.latency).to eq 0
1618 end
1719 end
1820
19 describe ".sidekiq_process_metrics" do
21 describe '.sidekiq_process_metrics' do
2022 before do
21 stub_get("/sidekiq/process_metrics", 'sidekiq_process_metrics')
23 stub_get('/sidekiq/process_metrics', 'sidekiq_process_metrics')
2224 @sidekiq_process_metrics = Gitlab.sidekiq_process_metrics
2325 end
2426
25 it "gets the correct resource" do
26 expect(a_get("/sidekiq/process_metrics")).to have_been_made
27 it 'gets the correct resource' do
28 expect(a_get('/sidekiq/process_metrics')).to have_been_made
2729 end
2830
29 it "returns a information about a sidekiq process metrics" do
31 it 'returns a information about a sidekiq process metrics' do
3032 expect(@sidekiq_process_metrics.processes.first['busy']).to eq 0
3133 end
3234 end
3335
34 describe ".sidekiq_job_stats" do
36 describe '.sidekiq_job_stats' do
3537 before do
36 stub_get("/sidekiq/job_stats", 'sidekiq_job_stats')
38 stub_get('/sidekiq/job_stats', 'sidekiq_job_stats')
3739 @sidekiq_job_stats = Gitlab.sidekiq_job_stats
3840 end
3941
40 it "gets the correct resource" do
41 expect(a_get("/sidekiq/job_stats")).to have_been_made
42 it 'gets the correct resource' do
43 expect(a_get('/sidekiq/job_stats')).to have_been_made
4244 end
4345
44 it "returns a information about a sidekiq process metrics" do
46 it 'returns a information about a sidekiq process metrics' do
4547 expect(@sidekiq_job_stats.jobs.processed).to eq 2
4648 end
4749 end
4850
49 describe ".sidekiq_compound_metrics" do
51 describe '.sidekiq_compound_metrics' do
5052 before do
51 stub_get("/sidekiq/compound_metrics", 'sidekiq_compound_metrics')
53 stub_get('/sidekiq/compound_metrics', 'sidekiq_compound_metrics')
5254 @sidekiq_compound_metrics = Gitlab.sidekiq_compound_metrics
5355 end
5456
55 it "gets the correct resource" do
56 expect(a_get("/sidekiq/compound_metrics")).to have_been_made
57 it 'gets the correct resource' do
58 expect(a_get('/sidekiq/compound_metrics')).to have_been_made
5759 end
5860
59 it "returns a information about a sidekiq process metrics" do
61 it 'returns a information about a sidekiq process metrics' do
6062 expect(@sidekiq_compound_metrics.jobs.processed).to eq 2
6163 end
6264 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".snippets" do
5 describe '.snippets' do
46 before do
5 stub_get("/projects/3/snippets", "snippets")
7 stub_get('/projects/3/snippets', 'snippets')
68 @snippets = Gitlab.snippets(3)
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/projects/3/snippets")).to have_been_made
11 it 'gets the correct resource' do
12 expect(a_get('/projects/3/snippets')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of project's snippets" do
1416 expect(@snippets).to be_a Gitlab::PaginatedResponse
15 expect(@snippets.first.file_name).to eq("mailer_test.rb")
17 expect(@snippets.first.file_name).to eq('mailer_test.rb')
1618 end
1719 end
1820
19 describe ".snippet" do
21 describe '.snippet' do
2022 before do
21 stub_get("/projects/3/snippets/1", "snippet")
23 stub_get('/projects/3/snippets/1', 'snippet')
2224 @snippet = Gitlab.snippet(3, 1)
2325 end
2426
25 it "gets the correct resource" do
26 expect(a_get("/projects/3/snippets/1")).to have_been_made
27 it 'gets the correct resource' do
28 expect(a_get('/projects/3/snippets/1')).to have_been_made
2729 end
2830
29 it "returns information about a snippet" do
30 expect(@snippet.file_name).to eq("mailer_test.rb")
31 expect(@snippet.author.name).to eq("John Smith")
31 it 'returns information about a snippet' do
32 expect(@snippet.file_name).to eq('mailer_test.rb')
33 expect(@snippet.author.name).to eq('John Smith')
3234 end
3335 end
3436
35 describe ".create_snippet" do
37 describe '.create_snippet' do
3638 before do
37 stub_post("/projects/3/snippets", "snippet")
39 stub_post('/projects/3/snippets', 'snippet')
3840 @snippet = Gitlab.create_snippet(3, title: 'API', file_name: 'api.rb', code: 'code', visibility: 'public')
3941 end
4042
41 it "gets the correct resource" do
43 it 'gets the correct resource' do
4244 body = { title: 'API', file_name: 'api.rb', code: 'code', visibility: 'public' }
43 expect(a_post("/projects/3/snippets").with(body: body)).to have_been_made
45 expect(a_post('/projects/3/snippets').with(body: body)).to have_been_made
4446 end
4547
46 it "returns information about a new snippet" do
47 expect(@snippet.file_name).to eq("mailer_test.rb")
48 expect(@snippet.author.name).to eq("John Smith")
48 it 'returns information about a new snippet' do
49 expect(@snippet.file_name).to eq('mailer_test.rb')
50 expect(@snippet.author.name).to eq('John Smith')
4951 end
5052 end
5153
52 describe ".edit_snippet" do
54 describe '.edit_snippet' do
5355 before do
54 stub_put("/projects/3/snippets/1", "snippet")
56 stub_put('/projects/3/snippets/1', 'snippet')
5557 @snippet = Gitlab.edit_snippet(3, 1, file_name: 'mailer_test.rb')
5658 end
5759
58 it "gets the correct resource" do
59 expect(a_put("/projects/3/snippets/1").
60 with(body: { file_name: 'mailer_test.rb' })).to have_been_made
60 it 'gets the correct resource' do
61 expect(a_put('/projects/3/snippets/1')
62 .with(body: { file_name: 'mailer_test.rb' })).to have_been_made
6163 end
6264
63 it "returns information about an edited snippet" do
64 expect(@snippet.file_name).to eq("mailer_test.rb")
65 expect(@snippet.author.name).to eq("John Smith")
65 it 'returns information about an edited snippet' do
66 expect(@snippet.file_name).to eq('mailer_test.rb')
67 expect(@snippet.author.name).to eq('John Smith')
6668 end
6769 end
6870
69 describe ".delete_snippet" do
71 describe '.delete_snippet' do
7072 before do
71 stub_delete("/projects/3/snippets/1", "snippet")
73 stub_delete('/projects/3/snippets/1', 'snippet')
7274 @snippet = Gitlab.delete_snippet(3, 1)
7375 end
7476
75 it "gets the correct resource" do
76 expect(a_delete("/projects/3/snippets/1")).to have_been_made
77 it 'gets the correct resource' do
78 expect(a_delete('/projects/3/snippets/1')).to have_been_made
7779 end
7880
79 it "returns information about a deleted snippet" do
80 expect(@snippet.file_name).to eq("mailer_test.rb")
81 expect(@snippet.author.name).to eq("John Smith")
81 it 'returns information about a deleted snippet' do
82 expect(@snippet.file_name).to eq('mailer_test.rb')
83 expect(@snippet.author.name).to eq('John Smith')
8284 end
8385 end
8486
85 describe ".snippet_content" do
87 describe '.snippet_content' do
8688 before do
87 stub_get("/projects/3/snippets/1/raw", "snippet_content")
89 stub_get('/projects/3/snippets/1/raw', 'snippet_content')
8890 @snippet_content = Gitlab.snippet_content(3, 1)
8991 end
9092
91 it "gets the correct resource" do
92 expect(a_get("/projects/3/snippets/1/raw")).to have_been_made
93 it 'gets the correct resource' do
94 expect(a_get('/projects/3/snippets/1/raw')).to have_been_made
9395 end
9496
95 it "returns raw content of a snippet" do
97 it 'returns raw content of a snippet' do
9698 expect(@snippet_content).to eq("#!/usr/bin/env ruby\n\nputs \"Cool snippet!\"\n")
9799 end
98100 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
57 it { is_expected.to respond_to :system_hook }
68 it { is_expected.to respond_to :delete_system_hook }
79
8 describe ".hooks" do
10 describe '.hooks' do
911 before do
10 stub_get("/hooks", "system_hooks")
12 stub_get('/hooks', 'system_hooks')
1113 @hooks = Gitlab.hooks
1214 end
1315
14 it "gets the correct resource" do
15 expect(a_get("/hooks")).to have_been_made
16 it 'gets the correct resource' do
17 expect(a_get('/hooks')).to have_been_made
1618 end
1719
18 it "returns a paginated response of system hooks" do
20 it 'returns a paginated response of system hooks' do
1921 expect(@hooks).to be_a Gitlab::PaginatedResponse
20 expect(@hooks.first.url).to eq("http://example.com/hook")
22 expect(@hooks.first.url).to eq('http://example.com/hook')
2123 end
2224 end
2325
24 describe ".add_hook" do
26 describe '.add_hook' do
2527 before do
26 stub_post("/hooks", "system_hook")
27 @hook = Gitlab.add_hook("http://example.com/hook", token: 'secret-token')
28 stub_post('/hooks', 'system_hook')
29 @hook = Gitlab.add_hook('http://example.com/hook', token: 'secret-token')
2830 end
2931
30 it "gets the correct resource" do
31 expect(a_post("/hooks").with(body: hash_including(token: 'secret-token'))).to have_been_made
32 it 'gets the correct resource' do
33 expect(a_post('/hooks').with(body: hash_including(token: 'secret-token'))).to have_been_made
3234 end
3335
34 it "returns information about a added system hook" do
35 expect(@hook.url).to eq("http://example.com/hook")
36 it 'returns information about a added system hook' do
37 expect(@hook.url).to eq('http://example.com/hook')
3638 end
3739 end
3840
39 describe ".hook" do
41 describe '.hook' do
4042 before do
41 stub_get("/hooks/3", "system_hook")
43 stub_get('/hooks/3', 'system_hook')
4244 @hook = Gitlab.hook(3)
4345 end
4446
45 it "gets the correct resource" do
46 expect(a_get("/hooks/3")).to have_been_made
47 it 'gets the correct resource' do
48 expect(a_get('/hooks/3')).to have_been_made
4749 end
4850
49 it "returns information about a added system hook" do
50 expect(@hook.url).to eq("http://example.com/hook")
51 it 'returns information about a added system hook' do
52 expect(@hook.url).to eq('http://example.com/hook')
5153 end
5254 end
5355
54 describe ".delete_hook" do
56 describe '.delete_hook' do
5557 before do
56 stub_delete("/hooks/3", "system_hook")
58 stub_delete('/hooks/3', 'system_hook')
5759 @hook = Gitlab.delete_hook(3)
5860 end
5961
60 it "gets the correct resource" do
61 expect(a_delete("/hooks/3")).to have_been_made
62 it 'gets the correct resource' do
63 expect(a_delete('/hooks/3')).to have_been_made
6264 end
6365
64 it "returns information about a deleted system hook" do
65 expect(@hook.url).to eq("http://example.com/hook")
66 it 'returns information about a deleted system hook' do
67 expect(@hook.url).to eq('http://example.com/hook')
6668 end
6769 end
6870 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
911
1012 describe '.tags' do
1113 before do
12 stub_get("/projects/3/repository/tags", "tags")
14 stub_get('/projects/3/repository/tags', 'tags')
1315 @tags = Gitlab.tags(3)
1416 end
1517
16 it "gets the correct resource" do
17 expect(a_get("/projects/3/repository/tags")).to have_been_made
18 it 'gets the correct resource' do
19 expect(a_get('/projects/3/repository/tags')).to have_been_made
1820 end
1921
20 it "returns a paginated response of repository tags" do
22 it 'returns a paginated response of repository tags' do
2123 expect(@tags).to be_a Gitlab::PaginatedResponse
2224 expect(@tags.map(&:name)).to eq(%w[0.0.2 0.0.1])
2325 end
2426 end
2527
26 describe ".tag" do
28 describe '.tag' do
2729 before do
28 stub_get("/projects/3/repository/tags/0.0.1", "tag")
29 @tag = Gitlab.tag(3, "0.0.1")
30 stub_get('/projects/3/repository/tags/0.0.1', 'tag')
31 @tag = Gitlab.tag(3, '0.0.1')
3032 end
3133
32 it "gets the correct resource" do
33 expect(a_get("/projects/3/repository/tags/0.0.1")).to have_been_made
34 it 'gets the correct resource' do
35 expect(a_get('/projects/3/repository/tags/0.0.1')).to have_been_made
3436 end
3537
36 it "returns information about a repository tag" do
37 expect(@tag.name).to eq("0.0.1")
38 it 'returns information about a repository tag' do
39 expect(@tag.name).to eq('0.0.1')
3840 end
3941
40 context "tag with special character" do
42 context 'tag with special character' do
4143 before do
42 stub_get("/projects/3/repository/tags/test%2Fme", "tag")
43 @tag = Gitlab.tag(3, "test/me")
44 stub_get('/projects/3/repository/tags/test%2Fme', 'tag')
45 @tag = Gitlab.tag(3, 'test/me')
4446 end
4547
46 it "gets the correct resource" do
47 expect(a_get("/projects/3/repository/tags/test%2Fme")).to have_been_made
48 it 'gets the correct resource' do
49 expect(a_get('/projects/3/repository/tags/test%2Fme')).to have_been_made
4850 end
4951 end
5052 end
5153
52 describe ".create_tag" do
54 describe '.create_tag' do
5355 before do
54 stub_post("/projects/3/repository/tags", "tag_create")
55 @tag = Gitlab.create_tag(3, "0.0.1", "master", 'this tag is annotated', 'and it has release notes')
56 stub_post('/projects/3/repository/tags', 'tag_create')
57 @tag = Gitlab.create_tag(3, '0.0.1', 'master', 'this tag is annotated', 'and it has release notes')
5658 end
5759
58 it "gets the correct resource" do
59 expect(a_post("/projects/3/repository/tags")).to have_been_made
60 it 'gets the correct resource' do
61 expect(a_post('/projects/3/repository/tags')).to have_been_made
6062 end
6163
62 it "returns information about a new repository tag" do
63 expect(@tag.name).to eq("0.0.1")
64 it 'returns information about a new repository tag' do
65 expect(@tag.name).to eq('0.0.1')
6466 expect(@tag.message).to eq('this tag is annotated')
6567 end
6668
67 it "returns detailed information" do
69 it 'returns detailed information' do
6870 expect(@tag.release.description).to eq('and it has release notes')
6971 end
7072 end
7173
72 describe ".delete_tag" do
74 describe '.delete_tag' do
7375 before do
74 stub_delete("/projects/3/repository/tags/0.0.1", "tag_delete")
75 @tag = Gitlab.delete_tag(3, "0.0.1")
76 stub_delete('/projects/3/repository/tags/0.0.1', 'tag_delete')
77 @tag = Gitlab.delete_tag(3, '0.0.1')
7678 end
7779
78 it "gets the correct resource" do
79 expect(a_delete("/projects/3/repository/tags/0.0.1")).to have_been_made
80 it 'gets the correct resource' do
81 expect(a_delete('/projects/3/repository/tags/0.0.1')).to have_been_made
8082 end
8183
82 it "returns information about the deleted repository tag" do
83 expect(@tag.tag_name).to eq("0.0.1")
84 it 'returns information about the deleted repository tag' do
85 expect(@tag.tag_name).to eq('0.0.1')
8486 end
8587
86 context "tag with special character" do
88 context 'tag with special character' do
8789 before do
88 stub_delete("/projects/3/repository/tags/test%2Fme", "tag_delete")
89 @tag = Gitlab.delete_tag(3, "test/me")
90 stub_delete('/projects/3/repository/tags/test%2Fme', 'tag_delete')
91 @tag = Gitlab.delete_tag(3, 'test/me')
9092 end
9193
92 it "gets the correct resource" do
93 expect(a_delete("/projects/3/repository/tags/test%2Fme")).to have_been_made
94 it 'gets the correct resource' do
95 expect(a_delete('/projects/3/repository/tags/test%2Fme')).to have_been_made
9496 end
9597 end
9698 end
9799
98 describe ".create_release" do
100 describe '.create_release' do
99101 before do
100 stub_post("/projects/3/repository/tags/0.0.1/release", "release_create")
101 @tag = Gitlab.create_release(3, "0.0.1", "Amazing release. Wow")
102 stub_post('/projects/3/repository/tags/0.0.1/release', 'release_create')
103 @tag = Gitlab.create_release(3, '0.0.1', 'Amazing release. Wow')
102104 end
103105
104 it "gets the correct resource" do
105 expect(a_post("/projects/3/repository/tags/0.0.1/release")).to have_been_made
106 it 'gets the correct resource' do
107 expect(a_post('/projects/3/repository/tags/0.0.1/release')).to have_been_made
106108 end
107109
108 it "returns information about the tag and the release" do
109 expect(@tag.tag_name).to eq("0.0.1")
110 expect(@tag.description).to eq("Amazing release. Wow")
110 it 'returns information about the tag and the release' do
111 expect(@tag.tag_name).to eq('0.0.1')
112 expect(@tag.description).to eq('Amazing release. Wow')
111113 end
112114
113 context "tag with special character" do
115 context 'tag with special character' do
114116 before do
115 stub_post("/projects/3/repository/tags/test%2Fme/release", "release_create")
116 @tag = Gitlab.create_release(3, "test/me", "Amazing release. Wow")
117 stub_post('/projects/3/repository/tags/test%2Fme/release', 'release_create')
118 @tag = Gitlab.create_release(3, 'test/me', 'Amazing release. Wow')
117119 end
118120
119 it "gets the correct resource" do
120 expect(a_post("/projects/3/repository/tags/test%2Fme/release")).to have_been_made
121 it 'gets the correct resource' do
122 expect(a_post('/projects/3/repository/tags/test%2Fme/release')).to have_been_made
121123 end
122124 end
123125 end
124126
125 describe ".update_release" do
127 describe '.update_release' do
126128 before do
127 stub_put("/projects/3/repository/tags/0.0.1/release", "release_update")
128 @tag = Gitlab.update_release(3, "0.0.1", 'Amazing release. Wow')
129 stub_put('/projects/3/repository/tags/0.0.1/release', 'release_update')
130 @tag = Gitlab.update_release(3, '0.0.1', 'Amazing release. Wow')
129131 end
130132
131 it "updates the correct resource" do
132 expect(a_put("/projects/3/repository/tags/0.0.1/release")).to have_been_made
133 it 'updates the correct resource' do
134 expect(a_put('/projects/3/repository/tags/0.0.1/release')).to have_been_made
133135 end
134136
135 it "returns information about the tag" do
136 expect(@tag.tag_name).to eq("0.0.1")
137 it 'returns information about the tag' do
138 expect(@tag.tag_name).to eq('0.0.1')
137139 expect(@tag.description).to eq('Amazing release. Wow')
138140 end
139141
140 context "tag with special character" do
142 context 'tag with special character' do
141143 before do
142 stub_put("/projects/3/repository/tags/test%2Fme/release", "release_update")
143 @tag = Gitlab.update_release(3, "test/me", 'Amazing release. Wow')
144 stub_put('/projects/3/repository/tags/test%2Fme/release', 'release_update')
145 @tag = Gitlab.update_release(3, 'test/me', 'Amazing release. Wow')
144146 end
145147
146 it "updates the correct resource" do
147 expect(a_put("/projects/3/repository/tags/test%2Fme/release")).to have_been_made
148 it 'updates the correct resource' do
149 expect(a_put('/projects/3/repository/tags/test%2Fme/release')).to have_been_made
148150 end
149151 end
150152 end
0 # frozen_string_literal: true
1
2 require 'spec_helper'
3
4 describe Gitlab::Client do
5 describe '.dockerfile_templates' do
6 before do
7 stub_get('/templates/dockerfiles', 'dockerfile_templates')
8 @dockerfile_templates = Gitlab.dockerfile_templates
9 end
10
11 it 'gets the correct resource' do
12 expect(a_get('/templates/dockerfiles')).to have_been_made
13 end
14
15 it 'returns a paginated response of dockerfile templates' do
16 expect(@dockerfile_templates).to be_a Gitlab::PaginatedResponse
17 end
18 end
19
20 describe '.dockerfile_template' do
21 before do
22 stub_get('/templates/dockerfiles/Binary', 'dockerfile_project_template')
23 @dockerfile_template = Gitlab.dockerfile_template('Binary')
24 end
25
26 it 'gets the correct resource' do
27 expect(a_get('/templates/dockerfiles/Binary')).to have_been_made
28 end
29
30 it 'returns the correct information about the dockerfile template' do
31 expect(@dockerfile_template.name).to eq 'Binary'
32 end
33 end
34
35 describe '.gitignore_templates' do
36 before do
37 stub_get('/templates/gitignores', 'gitignore_templates')
38 @gitignore_templates = Gitlab.gitignore_templates
39 end
40
41 it 'gets the correct resource' do
42 expect(a_get('/templates/gitignores')).to have_been_made
43 end
44
45 it 'returns a paginated response of gitignore templates' do
46 expect(@gitignore_templates).to be_a Gitlab::PaginatedResponse
47 end
48 end
49
50 describe '.gitignore_template' do
51 before do
52 stub_get('/templates/gitignores/Ruby', 'gitignore_template')
53 @gitignore_template = Gitlab.gitignore_template('Ruby')
54 end
55
56 it 'gets the correct resource' do
57 expect(a_get('/templates/gitignores/Ruby')).to have_been_made
58 end
59
60 it 'returns the correct information about the gitignore template' do
61 expect(@gitignore_template.name).to eq 'Ruby'
62 end
63 end
64
65 describe '.gitlab_ci_yml_templates' do
66 before do
67 stub_get('/templates/gitlab_ci_ymls', 'gitlab_ci_yml_templates')
68 @gitlab_ci_yml_templates = Gitlab.gitlab_ci_yml_templates
69 end
70
71 it 'gets the correct resource' do
72 expect(a_get('/templates/gitlab_ci_ymls')).to have_been_made
73 end
74
75 it 'returns a paginated response of gitlab_ci_yml templates' do
76 expect(@gitlab_ci_yml_templates).to be_a Gitlab::PaginatedResponse
77 end
78 end
79
80 describe '.gitlab_ci_yml_template' do
81 before do
82 stub_get('/templates/gitlab_ci_ymls/Ruby', 'gitlab_ci_yml_template')
83 @gitlab_ci_yml_template = Gitlab.gitlab_ci_yml_template('Ruby')
84 end
85
86 it 'gets the correct resource' do
87 expect(a_get('/templates/gitlab_ci_ymls/Ruby')).to have_been_made
88 end
89
90 it 'returns the correct information about the gitlab_ci_yml template' do
91 expect(@gitlab_ci_yml_template.name).to eq 'Ruby'
92 end
93 end
94
95 describe '.license_templates' do
96 before do
97 stub_get('/templates/licenses', 'license_templates')
98 @license_templates = Gitlab.license_templates
99 end
100
101 it 'gets the correct resource' do
102 expect(a_get('/templates/licenses')).to have_been_made
103 end
104
105 it 'returns a paginated response of license templates' do
106 expect(@license_templates).to be_a Gitlab::PaginatedResponse
107 end
108 end
109
110 describe '.license_template' do
111 before do
112 stub_get('/templates/licenses/mit', 'license_template')
113 @license_template = Gitlab.license_template('mit')
114 end
115
116 it 'gets the correct resource' do
117 expect(a_get('/templates/licenses/mit')).to have_been_made
118 end
119
120 it 'returns the correct information about the license template' do
121 expect(@license_template.key).to eq 'mit'
122 end
123 end
124 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
35 describe '.todos' do
46 before do
5 stub_get("/todos", "todos")
7 stub_get('/todos', 'todos')
68 @todos = Gitlab.todos
79 end
810
9 it "gets the correct resources" do
10 expect(a_get("/todos")).to have_been_made
11 it 'gets the correct resources' do
12 expect(a_get('/todos')).to have_been_made
1113 end
1214
1315 it "returns a paginated response of user's todos" do
1719
1820 describe '.mark_todo_as_done' do
1921 before do
20 stub_post("/todos/102/mark_as_done", "todo")
22 stub_post('/todos/102/mark_as_done', 'todo')
2123 @todo = Gitlab.mark_todo_as_done(102)
2224 end
2325
24 it "gets the correct resource" do
25 expect(a_post("/todos/102/mark_as_done")).to have_been_made
26 it 'gets the correct resource' do
27 expect(a_post('/todos/102/mark_as_done')).to have_been_made
2628 end
2729
28 it "returns information about the todo marked as done" do
30 it 'returns information about the todo marked as done' do
2931 expect(@todo.id).to eq(102)
3032 expect(@todo.state).to eq('done')
3133 end
3335
3436 describe '.mark_all_todos_as_done' do
3537 before do
36 stub_post("/todos/mark_as_done", "todos")
38 stub_post('/todos/mark_as_done', 'todos')
3739 @todos = Gitlab.mark_all_todos_as_done
3840 end
3941
40 it "gets the correct resources" do
41 expect(a_post("/todos/mark_as_done")).to have_been_made
42 it 'gets the correct resources' do
43 expect(a_post('/todos/mark_as_done')).to have_been_made
4244 end
4345 end
4446 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Client do
3 describe ".users" do
4 before do
5 stub_get("/users", "users")
5 describe '.users' do
6 before do
7 stub_get('/users', 'users')
68 @users = Gitlab.users
79 end
810
9 it "gets the correct resource" do
10 expect(a_get("/users")).to have_been_made
11 end
12
13 it "returns a paginated response of users" do
11 it 'gets the correct resource' do
12 expect(a_get('/users')).to have_been_made
13 end
14
15 it 'returns a paginated response of users' do
1416 expect(@users).to be_a Gitlab::PaginatedResponse
15 expect(@users.first.email).to eq("john@example.com")
16 end
17 end
18
19 describe ".user" do
20 context "with user ID passed" do
21 before do
22 stub_get("/users/1", "user")
17 expect(@users.first.email).to eq('john@example.com')
18 end
19 end
20
21 describe '.user' do
22 context 'with user ID passed' do
23 before do
24 stub_get('/users/1', 'user')
2325 @user = Gitlab.user(1)
2426 end
2527
26 it "gets the correct resource" do
27 expect(a_get("/users/1")).to have_been_made
28 end
29
30 it "returns information about a user" do
31 expect(@user.email).to eq("john@example.com")
32 end
33 end
34
35 context "without user ID passed" do
36 before do
37 stub_get("/user", "user")
28 it 'gets the correct resource' do
29 expect(a_get('/users/1')).to have_been_made
30 end
31
32 it 'returns information about a user' do
33 expect(@user.email).to eq('john@example.com')
34 end
35 end
36
37 context 'without user ID passed' do
38 before do
39 stub_get('/user', 'user')
3840 @user = Gitlab.user
3941 end
4042
41 it "gets the correct resource" do
42 expect(a_get("/user")).to have_been_made
43 end
44
45 it "returns information about an authorized user" do
46 expect(@user.email).to eq("john@example.com")
47 end
48 end
49 end
50
51 describe ".create_user" do
52 context "when successful request" do
53 before do
54 stub_post("/users", "user")
55 @user = Gitlab.create_user("email", "pass")
56 end
57
58 it "gets the correct resource" do
59 body = { email: "email", password: "pass", name: "email" }
60 expect(a_post("/users").with(body: body)).to have_been_made
61 end
62
63 it "returns information about a created user" do
64 expect(@user.email).to eq("john@example.com")
65 end
66 end
67
68 context "when bad request" do
69 it "throws an exception" do
70 stub_post("/users", "error_already_exists", 409)
43 it 'gets the correct resource' do
44 expect(a_get('/user')).to have_been_made
45 end
46
47 it 'returns information about an authorized user' do
48 expect(@user.email).to eq('john@example.com')
49 end
50 end
51 end
52
53 describe '.create_user' do
54 context 'when successful request' do
55 before do
56 stub_post('/users', 'user')
57 @user = Gitlab.create_user('email', 'pass')
58 end
59
60 it 'gets the correct resource' do
61 body = { email: 'email', password: 'pass', name: 'email' }
62 expect(a_post('/users').with(body: body)).to have_been_made
63 end
64
65 it 'returns information about a created user' do
66 expect(@user.email).to eq('john@example.com')
67 end
68 end
69
70 context 'when bad request' do
71 it 'throws an exception' do
72 stub_post('/users', 'error_already_exists', 409)
7173 expect do
72 Gitlab.create_user("email", "pass")
74 Gitlab.create_user('email', 'pass')
7375 end.to raise_error(Gitlab::Error::Conflict, "Server responded with code 409, message: 409 Already exists. Request URI: #{Gitlab.endpoint}/users")
7476 end
7577 end
7678 end
7779
78 describe ".create_user_with_userame" do
79 context "when successful request" do
80 before do
81 stub_post("/users", "user")
82 @user = Gitlab.create_user("email", "pass", "username")
83 end
84
85 it "gets the correct resource" do
86 body = { email: "email", password: "pass", username: "username" }
87 expect(a_post("/users").with(body: body)).to have_been_made
88 end
89
90 it "returns information about a created user" do
91 expect(@user.email).to eq("john@example.com")
92 end
93 end
94
95 context "when bad request" do
96 it "throws an exception" do
97 stub_post("/users", "error_already_exists", 409)
80 describe '.create_user_with_userame' do
81 context 'when successful request' do
82 before do
83 stub_post('/users', 'user')
84 @user = Gitlab.create_user('email', 'pass', 'username')
85 end
86
87 it 'gets the correct resource' do
88 body = { email: 'email', password: 'pass', username: 'username' }
89 expect(a_post('/users').with(body: body)).to have_been_made
90 end
91
92 it 'returns information about a created user' do
93 expect(@user.email).to eq('john@example.com')
94 end
95 end
96
97 context 'when bad request' do
98 it 'throws an exception' do
99 stub_post('/users', 'error_already_exists', 409)
98100 expect do
99 Gitlab.create_user("email", "pass", "username")
101 Gitlab.create_user('email', 'pass', 'username')
100102 end.to raise_error(Gitlab::Error::Conflict, "Server responded with code 409, message: 409 Already exists. Request URI: #{Gitlab.endpoint}/users")
101103 end
102104 end
103105 end
104106
105 describe ".edit_user" do
106 before do
107 @options = { name: "Roberto" }
108 stub_put("/users/1", "user").with(body: @options)
107 describe '.edit_user' do
108 before do
109 @options = { name: 'Roberto' }
110 stub_put('/users/1', 'user').with(body: @options)
109111 @user = Gitlab.edit_user(1, @options)
110112 end
111113
112 it "gets the correct resource" do
113 expect(a_put("/users/1").with(body: @options)).to have_been_made
114 end
115 end
116
117 describe ".delete_user" do
118 before do
119 stub_delete("/users/1", "user")
114 it 'gets the correct resource' do
115 expect(a_put('/users/1').with(body: @options)).to have_been_made
116 end
117 end
118
119 describe '.delete_user' do
120 before do
121 stub_delete('/users/1', 'user')
120122 @user = Gitlab.delete_user(1)
121123 end
122124
123 it "gets the correct resource" do
124 expect(a_delete("/users/1")).to have_been_made
125 end
126
127 it "returns information about a deleted user" do
128 expect(@user.email).to eq("john@example.com")
129 end
130 end
131
132 describe ".block_user" do
133 before do
134 stub_post("/users/1/block", "user_block_unblock")
125 it 'gets the correct resource' do
126 expect(a_delete('/users/1')).to have_been_made
127 end
128
129 it 'returns information about a deleted user' do
130 expect(@user.email).to eq('john@example.com')
131 end
132 end
133
134 describe '.block_user' do
135 before do
136 stub_post('/users/1/block', 'user_block_unblock')
135137 @result = Gitlab.block_user(1)
136138 end
137139
138 it "gets the correct resource" do
139 expect(a_post("/users/1/block")).to have_been_made
140 end
141
142 it "returns boolean" do
140 it 'gets the correct resource' do
141 expect(a_post('/users/1/block')).to have_been_made
142 end
143
144 it 'returns boolean' do
143145 expect(@result).to eq(true)
144146 end
145147 end
146148
147 describe ".unblock_user" do
148 before do
149 stub_post("/users/1/unblock", "user_block_unblock")
149 describe '.unblock_user' do
150 before do
151 stub_post('/users/1/unblock', 'user_block_unblock')
150152 @result = Gitlab.unblock_user(1)
151153 end
152154
153 it "gets the correct resource" do
154 expect(a_post("/users/1/unblock")).to have_been_made
155 end
156
157 it "returns boolean" do
155 it 'gets the correct resource' do
156 expect(a_post('/users/1/unblock')).to have_been_made
157 end
158
159 it 'returns boolean' do
158160 expect(@result).to eq(true)
159161 end
160162 end
161163
162 describe ".session" do
164 describe '.session' do
163165 after do
164166 Gitlab.endpoint = 'https://api.example.com'
165167 Gitlab.private_token = 'secret'
166168 end
167169
168170 before do
169 stub_request(:post, "#{Gitlab.endpoint}/session").
170 to_return(body: load_fixture('session'), status: 200)
171 @session = Gitlab.session("email", "pass")
172 end
173
174 context "when endpoint is not set" do
175 it "raises Error::MissingCredentials" do
171 stub_request(:post, "#{Gitlab.endpoint}/session")
172 .to_return(body: load_fixture('session'), status: 200)
173 @session = Gitlab.session('email', 'pass')
174 end
175
176 context 'when endpoint is not set' do
177 it 'raises Error::MissingCredentials' do
176178 Gitlab.endpoint = nil
177179 expect do
178 Gitlab.session("email", "pass")
180 Gitlab.session('email', 'pass')
179181 end.to raise_error(Gitlab::Error::MissingCredentials, 'Please set an endpoint to API')
180182 end
181183 end
182184
183 context "when private_token is not set" do
184 it "does not raise Error::MissingCredentials" do
185 context 'when private_token is not set' do
186 it 'does not raise Error::MissingCredentials' do
185187 Gitlab.private_token = nil
186 expect { Gitlab.session("email", "pass") }.to_not raise_error
187 end
188 end
189
190 context "when endpoint is set" do
191 it "gets the correct resource" do
188 expect { Gitlab.session('email', 'pass') }.not_to raise_error
189 end
190 end
191
192 context 'when endpoint is set' do
193 it 'gets the correct resource' do
192194 expect(a_request(:post, "#{Gitlab.endpoint}/session")).to have_been_made
193195 end
194196
195 it "returns information about a created session" do
196 expect(@session.email).to eq("john@example.com")
197 expect(@session.private_token).to eq("qEsq1pt6HJPaNciie3MG")
198 end
199 end
200 end
201
202 describe ".ssh_keys" do
203 context "with user ID passed" do
204 before do
205 stub_get("/users/1/keys", "keys")
206 @keys = Gitlab.ssh_keys({ user_id: 1 })
207 end
208
209 it "gets the correct resource" do
210 expect(a_get("/users/1/keys")).to have_been_made
211 end
212
213 it "returns a paginated response of SSH keys" do
197 it 'returns information about a created session' do
198 expect(@session.email).to eq('john@example.com')
199 expect(@session.private_token).to eq('qEsq1pt6HJPaNciie3MG')
200 end
201 end
202 end
203
204 describe '.ssh_keys' do
205 context 'with user ID passed' do
206 before do
207 stub_get('/users/1/keys', 'keys')
208 @keys = Gitlab.ssh_keys(user_id: 1)
209 end
210
211 it 'gets the correct resource' do
212 expect(a_get('/users/1/keys')).to have_been_made
213 end
214
215 it 'returns a paginated response of SSH keys' do
214216 expect(@keys).to be_a Gitlab::PaginatedResponse
215 expect(@keys.first.title).to eq("narkoz@helium")
216 end
217 end
218
219 context "without user ID passed" do
220 before do
221 stub_get("/user/keys", "keys")
217 expect(@keys.first.title).to eq('narkoz@helium')
218 end
219 end
220
221 context 'without user ID passed' do
222 before do
223 stub_get('/user/keys', 'keys')
222224 @keys = Gitlab.ssh_keys
223225 end
224226
225 it "gets the correct resource" do
226 expect(a_get("/user/keys")).to have_been_made
227 end
228
229 it "returns a paginated response of SSH keys" do
227 it 'gets the correct resource' do
228 expect(a_get('/user/keys')).to have_been_made
229 end
230
231 it 'returns a paginated response of SSH keys' do
230232 expect(@keys).to be_a Gitlab::PaginatedResponse
231 expect(@keys.first.title).to eq("narkoz@helium")
232 end
233 end
234 end
235
236 describe ".ssh_key" do
237 before do
238 stub_get("/user/keys/1", "key")
233 expect(@keys.first.title).to eq('narkoz@helium')
234 end
235 end
236 end
237
238 describe '.ssh_key' do
239 before do
240 stub_get('/user/keys/1', 'key')
239241 @key = Gitlab.ssh_key(1)
240242 end
241243
242 it "gets the correct resource" do
243 expect(a_get("/user/keys/1")).to have_been_made
244 end
245
246 it "returns information about an SSH key" do
247 expect(@key.title).to eq("narkoz@helium")
248 end
249 end
250
251 describe ".create_ssh_key" do
252 before do
253 stub_post("/user/keys", "key")
254 @key = Gitlab.create_ssh_key("title", "body")
255 end
256
257 it "gets the correct resource" do
258 body = { title: "title", key: "body" }
259 expect(a_post("/user/keys").with(body: body)).to have_been_made
260 end
261
262 it "returns information about a created SSH key" do
263 expect(@key.title).to eq("narkoz@helium")
264 end
265 end
266
267 describe ".delete_ssh_key" do
268 before do
269 stub_delete("/user/keys/1", "key")
270 @key = Gitlab.delete_ssh_key(1)
271 end
272
273 it "gets the correct resource" do
274 expect(a_delete("/user/keys/1")).to have_been_made
275 end
276
277 it "returns information about a deleted SSH key" do
278 expect(@key.title).to eq("narkoz@helium")
279 end
280 end
281
282 describe ".emails" do
283 describe "without user ID" do
284 before do
285 stub_get("/user/emails", "user_emails")
244 it 'gets the correct resource' do
245 expect(a_get('/user/keys/1')).to have_been_made
246 end
247
248 it 'returns information about an SSH key' do
249 expect(@key.title).to eq('narkoz@helium')
250 end
251 end
252
253 describe '.create_ssh_key' do
254 describe 'without user ID' do
255 before do
256 stub_post('/user/keys', 'key')
257 @key = Gitlab.create_ssh_key('title', 'body')
258 end
259
260 it 'gets the correct resource' do
261 body = { title: 'title', key: 'body' }
262 expect(a_post('/user/keys').with(body: body)).to have_been_made
263 end
264
265 it 'returns information about a created SSH key' do
266 expect(@key.title).to eq('narkoz@helium')
267 end
268 end
269
270 describe 'with user ID' do
271 before do
272 stub_post('/users/1/keys', 'key')
273 @options = { user_id: 1 }
274 @key = Gitlab.create_ssh_key('title', 'body', @options)
275 end
276
277 it 'gets the correct resource' do
278 body = { title: 'title', key: 'body' }
279 expect(a_post('/users/1/keys').with(body: body)).to have_been_made
280 end
281
282 it 'returns information about a created SSH key' do
283 expect(@key.title).to eq('narkoz@helium')
284 end
285 end
286 end
287
288 describe '.delete_ssh_key' do
289 describe 'without user ID' do
290 before do
291 stub_delete('/user/keys/1', 'key')
292 @key = Gitlab.delete_ssh_key(1)
293 end
294
295 it 'gets the correct resource' do
296 expect(a_delete('/user/keys/1')).to have_been_made
297 end
298
299 it 'returns information about a deleted SSH key' do
300 expect(@key.title).to eq('narkoz@helium')
301 end
302 end
303
304 describe 'with user ID' do
305 before do
306 stub_delete('/users/1/keys/1', 'key')
307 @options = { user_id: 1 }
308 @key = Gitlab.delete_ssh_key(1, @options)
309 end
310
311 it 'gets the correct resource' do
312 expect(a_delete('/users/1/keys/1')).to have_been_made
313 end
314
315 it 'returns information about a deleted SSH key' do
316 expect(@key.title).to eq('narkoz@helium')
317 end
318 end
319 end
320
321 describe '.emails' do
322 describe 'without user ID' do
323 before do
324 stub_get('/user/emails', 'user_emails')
286325 @emails = Gitlab.emails
287326 end
288327
289 it "gets the correct resource" do
290 expect(a_get("/user/emails")).to have_been_made
291 end
292
293 it "returns a information about a emails of user" do
328 it 'gets the correct resource' do
329 expect(a_get('/user/emails')).to have_been_made
330 end
331
332 it 'returns a information about a emails of user' do
294333 email = @emails.first
295334 expect(email.id).to eq 1
296 expect(email.email).to eq("email@example.com")
297 end
298 end
299
300 describe "with user ID" do
301 before do
302 stub_get("/users/2/emails", "user_emails")
335 expect(email.email).to eq('email@example.com')
336 end
337 end
338
339 describe 'with user ID' do
340 before do
341 stub_get('/users/2/emails', 'user_emails')
303342 @emails = Gitlab.emails(2)
304343 end
305344
306 it "gets the correct resource" do
307 expect(a_get("/users/2/emails")).to have_been_made
308 end
309
310 it "returns a information about a emails of user" do
345 it 'gets the correct resource' do
346 expect(a_get('/users/2/emails')).to have_been_made
347 end
348
349 it 'returns a information about a emails of user' do
311350 email = @emails.first
312351 expect(email.id).to eq 1
313 expect(email.email).to eq("email@example.com")
314 end
315 end
316 end
317
318 describe ".email" do
319 before do
320 stub_get("/user/emails/2", "user_email")
352 expect(email.email).to eq('email@example.com')
353 end
354 end
355 end
356
357 describe '.email' do
358 before do
359 stub_get('/user/emails/2', 'user_email')
321360 @email = Gitlab.email(2)
322361 end
323362
324 it "gets the correct resource" do
325 expect(a_get("/user/emails/2")).to have_been_made
326 end
327
328 it "returns a information about a email of user" do
363 it 'gets the correct resource' do
364 expect(a_get('/user/emails/2')).to have_been_made
365 end
366
367 it 'returns a information about a email of user' do
329368 expect(@email.id).to eq 1
330 expect(@email.email).to eq("email@example.com")
331 end
332 end
333
334 describe ".add_email" do
335 describe "without user ID" do
336 before do
337 stub_post("/user/emails", "user_email")
338 @email = Gitlab.add_email("email@example.com")
339 end
340
341 it "gets the correct resource" do
342 body = { email: "email@example.com" }
343 expect(a_post("/user/emails").with(body: body)).to have_been_made
344 end
345
346 it "returns information about a new email" do
369 expect(@email.email).to eq('email@example.com')
370 end
371 end
372
373 describe '.add_email' do
374 describe 'without user ID' do
375 before do
376 stub_post('/user/emails', 'user_email')
377 @email = Gitlab.add_email('email@example.com')
378 end
379
380 it 'gets the correct resource' do
381 body = { email: 'email@example.com' }
382 expect(a_post('/user/emails').with(body: body)).to have_been_made
383 end
384
385 it 'returns information about a new email' do
347386 expect(@email.id).to eq(1)
348 expect(@email.email).to eq("email@example.com")
349 end
350 end
351
352 describe "with user ID" do
353 before do
354 stub_post("/users/2/emails", "user_email")
355 @email = Gitlab.add_email("email@example.com", 2)
356 end
357
358 it "gets the correct resource" do
359 body = { email: "email@example.com" }
360 expect(a_post("/users/2/emails").with(body: body)).to have_been_made
361 end
362
363 it "returns information about a new email" do
387 expect(@email.email).to eq('email@example.com')
388 end
389 end
390
391 describe 'with user ID' do
392 before do
393 stub_post('/users/2/emails', 'user_email')
394 @email = Gitlab.add_email('email@example.com', 2)
395 end
396
397 it 'gets the correct resource' do
398 body = { email: 'email@example.com' }
399 expect(a_post('/users/2/emails').with(body: body)).to have_been_made
400 end
401
402 it 'returns information about a new email' do
364403 expect(@email.id).to eq(1)
365 expect(@email.email).to eq("email@example.com")
366 end
367 end
368 end
369
370 describe ".delete_email" do
371 describe "without user ID" do
372 before do
373 stub_delete("/user/emails/1", "user_email")
404 expect(@email.email).to eq('email@example.com')
405 end
406 end
407 end
408
409 describe '.delete_email' do
410 describe 'without user ID' do
411 before do
412 stub_delete('/user/emails/1', 'user_email')
374413 @email = Gitlab.delete_email(1)
375414 end
376415
377 it "gets the correct resource" do
378 expect(a_delete("/user/emails/1")).to have_been_made
379 end
380
381 it "returns information about a deleted email" do
416 it 'gets the correct resource' do
417 expect(a_delete('/user/emails/1')).to have_been_made
418 end
419
420 it 'returns information about a deleted email' do
382421 expect(@email).to be_truthy
383422 end
384423 end
385424
386 describe "with user ID" do
387 before do
388 stub_delete("/users/2/emails/1", "user_email")
425 describe 'with user ID' do
426 before do
427 stub_delete('/users/2/emails/1', 'user_email')
389428 @email = Gitlab.delete_email(1, 2)
390429 end
391430
392 it "gets the correct resource" do
393 expect(a_delete("/users/2/emails/1")).to have_been_made
394 end
395
396 it "returns information about a deleted email" do
431 it 'gets the correct resource' do
432 expect(a_delete('/users/2/emails/1')).to have_been_made
433 end
434
435 it 'returns information about a deleted email' do
397436 expect(@email).to be_truthy
398437 end
399438 end
400439 end
401440
402 describe ".user_search" do
403 before do
404 stub_get("/users?search=User", "user_search")
441 describe '.user_search' do
442 before do
443 stub_get('/users?search=User', 'user_search')
405444 @users = Gitlab.user_search('User')
406445 end
407446
408 it "gets the correct resource" do
409 expect(a_get("/users?search=User")).to have_been_made
410 end
411
412 it "returns an array of users found" do
447 it 'gets the correct resource' do
448 expect(a_get('/users?search=User')).to have_been_made
449 end
450
451 it 'returns an array of users found' do
413452 expect(@users.first.id).to eq(1)
414453 expect(@users.last.id).to eq(2)
415454 end
0 # frozen_string_literal: true
1
2 require 'spec_helper'
3
4 describe Gitlab::Client do
5 describe '.version' do
6 before do
7 stub_get('/version', 'version')
8 end
9
10 let!(:version) { Gitlab.version }
11
12 it 'gets the correct resource' do
13 expect(a_get('/version')).to have_been_made
14 end
15
16 it 'returns information about gitlab server' do
17 expect(version.version).to eq('8.13.0-pre')
18 expect(version.revision).to eq('4e963fe')
19 end
20 end
21 end
0 # frozen_string_literal: true
1
2 require 'spec_helper'
3
4 describe Gitlab::Client do
5 describe '.wikis' do
6 before do
7 stub_get('/projects/1/wikis', 'wikis')
8 @wikis = Gitlab.wikis(1)
9 end
10
11 it 'gets the correct resource' do
12 expect(a_get('/projects/1/wikis')).to have_been_made
13 end
14
15 it "returns a response of a project's wikis" do
16 expect(@wikis).to be_a Gitlab::PaginatedResponse
17 end
18 end
19
20 describe '.wiki' do
21 before do
22 stub_get('/projects/1/wikis/home', 'wiki')
23 @wiki = Gitlab.wiki(1, 'home')
24 end
25
26 it 'gets the correct resource' do
27 expect(a_get('/projects/1/wikis/home')).to have_been_made
28 end
29
30 it 'returns correct information about the wiki' do
31 expect(@wiki.slug).to eq 'home'
32 end
33 end
34
35 describe '.create_wiki' do
36 before do
37 stub_post('/projects/1/wikis', 'wiki')
38 @wiki = Gitlab.create_wiki(1, 'home', 'home page')
39 end
40
41 it 'gets the correct resource' do
42 expect(a_post('/projects/1/wikis')
43 .with(body: { content: 'home page', title: 'home' })).to have_been_made
44 end
45
46 it 'returns correct information about the created wiki' do
47 expect(@wiki.content).to eq 'home page'
48 expect(@wiki.title).to eq 'home'
49 end
50 end
51
52 describe '.update_wiki' do
53 before do
54 stub_put('/projects/1/wikis/home', 'wiki')
55 @wiki = Gitlab.update_wiki(1, 'home', format: 'markdown')
56 end
57
58 it 'gets the correct resource' do
59 expect(a_put('/projects/1/wikis/home')
60 .with(body: { format: 'markdown' })).to have_been_made
61 end
62
63 it 'returns correct information about the updated wiki' do
64 expect(@wiki.format).to eq 'markdown'
65 end
66 end
67
68 describe '.delete_wiki' do
69 before do
70 stub_delete('/projects/1/wikis/home', 'empty')
71 @wiki = Gitlab.delete_wiki(1, 'home')
72 end
73
74 it 'gets the correct resource' do
75 expect(a_delete('/projects/1/wikis/home')).to have_been_made
76 end
77 end
78 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Error::ResponseError do
1113 %r{Server responded with code \d+, message: Displayed error. Request URI: https://gitlab.com/api/v3/foo},
1214 %r{Server responded with code \d+, message: 'embed_entity' \(foo: bar\) \(sna: fu\), 'password' too short. Request URI: https://gitlab.com/api/v3/foo},
1315 %r{Server responded with code \d+, message: First message. Second message.. Request URI: https://gitlab.com/api/v3/foo},
16 %r{Server responded with code \d+, message: 'error' Spam detected. Request URI: https://gitlab.com/api/v3/foo}
1417 ]
1518 end
1619
1720 # Set up some response scenarios to test.
1821 [
19 { code: 401, parsed_response: Gitlab::ObjectifiedHash.new(message: 'Displayed message', error_description: 'should not be displayed', error: 'also will not be displayed')},
20 { code: 404, parsed_response: Gitlab::ObjectifiedHash.new(error_description: 'Displayed error_description', error: 'also will not be displayed')},
21 { code: 401, parsed_response: Gitlab::ObjectifiedHash.new(error: 'Displayed error')},
22 { code: 500, parsed_response: Gitlab::ObjectifiedHash.new(embed_entity: { foo: ['bar'], sna: ['fu']}, password: ['too short'])},
23 { code: 403, parsed_response: Array.new(['First message.', 'Second message.'])},
22 { code: 401, parsed_response: Gitlab::ObjectifiedHash.new(message: 'Displayed message', error_description: 'should not be displayed', error: 'also will not be displayed') },
23 { code: 404, parsed_response: Gitlab::ObjectifiedHash.new(error_description: 'Displayed error_description', error: 'also will not be displayed') },
24 { code: 401, parsed_response: Gitlab::ObjectifiedHash.new(error: 'Displayed error') },
25 { code: 500, parsed_response: Gitlab::ObjectifiedHash.new(embed_entity: { foo: ['bar'], sna: ['fu'] }, password: ['too short']) },
26 { code: 403, parsed_response: Array.new(['First message.', 'Second message.']) },
27 { code: 400, parsed_response: Gitlab::ObjectifiedHash.new(message: { error: 'Spam detected' }) }
28
2429 ].each_with_index do |data, index|
2530 it 'returns the expected message' do
2631 response_double = double(**data, request: @request_double)
11
22 describe Gitlab::FileResponse do
33 before do
4 @file_response = Gitlab::FileResponse.new StringIO.new("", 'rb+')
4 @file_response = described_class.new StringIO.new('', 'rb+')
55 end
66
77 context '.empty?' do
8 it "returns false" do
8 it 'returns false' do
99 expect(@file_response.empty?).to be false
1010 end
1111 end
1212
1313 context '.to_hash' do
14 it "has `filename` key and `data` key" do
14 it 'has `filename` key and `data` key' do
1515 h = @file_response.to_hash
16 expect(h.key?(:filename)).to be_truthy
17 expect(h.key?(:data)).to be_truthy
16 expect(h).to be_key(:filename)
17 expect(h).to be_key(:data)
1818 end
1919 end
2020
2121 context '.parse_headers!' do
22 it "parses headers" do
22 it 'parses headers' do
2323 @file_response.parse_headers!('Content-Disposition' => 'attachment; filename=artifacts.zip')
24 expect(@file_response.filename).to eq "artifacts.zip"
24 expect(@file_response.filename).to eq 'artifacts.zip'
2525 end
2626
27 it "handles quoted filenames" do
27 it 'handles quoted filenames' do
2828 @file_response.parse_headers!('Content-Disposition' => 'attachment; filename="artifacts.zip"')
29 expect(@file_response.filename).to eq "artifacts.zip"
29 expect(@file_response.filename).to eq 'artifacts.zip'
3030 end
3131 end
3232 end
00 require 'spec_helper'
11
22 describe Gitlab::Help do
3 describe ".ri_cmd" do
4 context "ri command found" do
5 it "returns the path to RI" do
6 allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('/usr/bin/ri')
7 expect(Gitlab::Help.ri_cmd).to eq('/usr/bin/ri')
3 describe '.ri_cmd' do
4 context 'ri command found' do
5 it 'returns the path to RI' do
6 allow(described_class).to receive(:`).with(/which ri/).and_return('/usr/bin/ri')
7 expect(described_class.ri_cmd).to eq('/usr/bin/ri')
88 end
99 end
1010
11 context "ri command NOT found" do
12 it "raises RuntimeError" do
13 allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('')
14 expect { Gitlab::Help.ri_cmd }.to raise_error RuntimeError
11 context 'ri command NOT found' do
12 it 'raises RuntimeError' do
13 allow(described_class).to receive(:`).with(/which ri/).and_return('')
14 expect { described_class.ri_cmd }.to raise_error RuntimeError
1515 end
1616 end
1717 end
1818
19 describe ".change_help_output!" do
19 describe '.change_help_output!' do
2020 before do
21 @cmd = "create_branch"
21 @cmd = 'create_branch'
2222 @help_output = "Gitlab.#{@cmd}(4, 'new-branch', 'master')"
23 @help_output_with_options = "Gitlab.groups({ per_page: 3 })"
23 @help_output_with_options = 'Gitlab.groups({ per_page: 3 })'
2424 end
25 it "returns a String of modified output" do
26 Gitlab::Help.change_help_output! @cmd, @help_output
25
26 it 'returns a String of modified output' do
27 described_class.change_help_output! @cmd, @help_output
2728 expect(@help_output).to eq("Gitlab.create_branch 4 'new-branch' 'master'")
2829 end
29 it "formats options hash and return a String of modified output" do
30 Gitlab::Help.change_help_output! 'groups', @help_output_with_options
31 expect(@help_output_with_options).to eq("Gitlab.groups \"{ per_page: 3 }\"")
30 it 'formats options hash and return a String of modified output' do
31 described_class.change_help_output! 'groups', @help_output_with_options
32 expect(@help_output_with_options).to eq('Gitlab.groups "{ per_page: 3 }"')
3233 end
3334 end
3435
35 describe ".namespace" do
36 describe '.namespace' do
3637 before do
3738 @cmd = 'create_tag'
38 @namespace = Gitlab::Help.namespace @cmd
39 @namespace = described_class.namespace @cmd
3940 end
40 it "returns the full namespace for a command" do
41
42 it 'returns the full namespace for a command' do
4143 expect(@namespace).to be_a String
4244 expect(@namespace).to eq("Gitlab::Client::Tags.#{@cmd}")
4345 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::ObjectifiedHash do
35 before do
46 @hash = { a: 1, b: 2, 'string' => 'string', symbol: :symbol }
5 @oh = Gitlab::ObjectifiedHash.new @hash
7 @oh = described_class.new @hash
68 end
79
8 it "objectifies a hash" do
10 it 'objectifies a hash' do
911 expect(@oh.a).to eq(@hash[:a])
1012 expect(@oh.b).to eq(@hash[:b])
1113 end
1214
13 describe "#to_hash" do
14 it "returns an original hash" do
15 describe '#to_hash' do
16 it 'returns an original hash' do
1517 expect(@oh.to_hash).to eq(@hash)
1618 end
1719
18 it "has an alias #to_h" do
19 expect(@oh.respond_to?(:to_h)).to be_truthy
20 it 'has an alias #to_h' do
21 expect(@oh).to respond_to(:to_h)
2022 end
2123 end
2224
23 describe "#inspect" do
24 it "returns a formatted string" do
25 describe '#inspect' do
26 it 'returns a formatted string' do
2527 pretty_string = "#<#{@oh.class.name}:#{@oh.object_id} {hash: #{@hash}}"
2628 expect(@oh.inspect).to eq(pretty_string)
2729 end
2830 end
2931
30 describe "#respond_to" do
31 it "returns true for methods this object responds to through method_missing as sym" do
32 expect(@oh.respond_to?(:a)).to be_truthy
32 describe '#respond_to' do
33 it 'returns true for methods this object responds to through method_missing as sym' do
34 expect(@oh).to respond_to(:a)
3335 end
3436
35 it "returns true for methods this object responds to through method_missing as string" do
36 expect(@oh.respond_to?('string')).to be_truthy
37 it 'returns true for methods this object responds to through method_missing as string' do
38 expect(@oh).to respond_to('string')
3739 end
3840
39 it "does not care if you use a string or symbol to reference a method" do
40 expect(@oh.respond_to?(:string)).to be_truthy
41 it 'does not care if you use a string or symbol to reference a method' do
42 expect(@oh).to respond_to(:string)
4143 end
4244
43 it "does not care if you use a string or symbol to reference a method" do
44 expect(@oh.respond_to?('symbol')).to be_truthy
45 it 'does not care if you use a string or symbol to reference a method' do
46 expect(@oh).to respond_to('symbol')
4547 end
4648 end
4749 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::PageLinks do
35 before do
4 @page_links = Gitlab::PageLinks.new('Link' => "<http://example.com/api/v3/projects?page=1&per_page=5>; rel=\"first\", <http://example.com/api/v3/projects?page=20&per_page=5>; rel=\"last\", <http://example.com/api/v3/projects?page=7&per_page=5>; rel=\"prev\", <http://example.com/api/v3/projects?page=9&per_page=5>; rel=\"next\"")
6 @page_links = described_class.new('Link' => '<http://example.com/api/v3/projects?page=1&per_page=5>; rel="first", <http://example.com/api/v3/projects?page=20&per_page=5>; rel="last", <http://example.com/api/v3/projects?page=7&per_page=5>; rel="prev", <http://example.com/api/v3/projects?page=9&per_page=5>; rel="next"')
57 end
68
79 context '.extract_links' do
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::PaginatedResponse do
35 before do
46 array = [1, 2, 3, 4]
5 @paginated_response = Gitlab::PaginatedResponse.new array
7 @paginated_response = described_class.new array
68 end
79
8 it "responds to *_page and has_*_page methods" do
10 it 'responds to *_page and has_*_page methods' do
911 expect(@paginated_response).to respond_to :first_page
1012 expect(@paginated_response).to respond_to :last_page
1113 expect(@paginated_response).to respond_to :next_page
1719 end
1820
1921 context '.parse_headers!' do
20 it "parses headers" do
21 @paginated_response.parse_headers!('Link' => "<http://example.com/api/v3/projects?page=1&per_page=5>; rel=\"first\", <http://example.com/api/v3/projects?page=20&per_page=5>; rel=\"last\"")
22 it 'parses headers' do
23 @paginated_response.parse_headers!('Link' => '<http://example.com/api/v3/projects?page=1&per_page=5>; rel="first", <http://example.com/api/v3/projects?page=20&per_page=5>; rel="last"')
2224 client = @paginated_response.client = double('client')
2325 first_page_response = double('first_page_response')
2426 last_page_response = double('last_page_response')
25 allow(client).to receive(:endpoint).and_return("http://example.com/api/v3")
26 allow(client).to receive(:get).with("/projects?page=1&per_page=5").and_return(first_page_response)
27 allow(client).to receive(:get).with("/projects?page=20&per_page=5").and_return(last_page_response)
27 allow(client).to receive(:endpoint).and_return('http://example.com/api/v3')
28 allow(client).to receive(:get).with('/projects?page=1&per_page=5').and_return(first_page_response)
29 allow(client).to receive(:get).with('/projects?page=20&per_page=5').and_return(last_page_response)
2830 expect(@paginated_response.has_first_page?).to be true
2931 expect(@paginated_response.has_last_page?).to be true
3032 expect(@paginated_response.has_next_page?).to be false
3739 end
3840
3941 context '.each_page' do
40 it "iterates pages" do
42 it 'iterates pages' do
4143 next_page = double('next_page')
4244 allow(@paginated_response).to receive(:has_next_page?).and_return(true)
4345 allow(@paginated_response).to receive(:next_page).and_return(next_page)
4749 end
4850
4951 context '.auto_paginate' do
50 it "returns an array if block is not given" do
52 it 'returns an array if block is not given' do
5153 next_page = double('next_page')
5254 allow(@paginated_response).to receive(:has_next_page?).and_return(true)
5355 allow(@paginated_response).to receive(:next_page).and_return(next_page)
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Request do
57 it { is_expected.to respond_to :put }
68 it { is_expected.to respond_to :delete }
79 before do
8 @request = Gitlab::Request.new
10 @request = described_class.new
911 end
1012
11 describe ".default_options" do
12 it "has default values" do
13 default_options = Gitlab::Request.default_options
13 describe '.default_options' do
14 it 'has default values' do
15 default_options = described_class.default_options
1416 expect(default_options).to be_a Hash
1517 expect(default_options[:parser]).to be_a Proc
1618 expect(default_options[:format]).to eq(:json)
1921 end
2022 end
2123
22 describe ".parse" do
23 it "returns ObjectifiedHash" do
24 describe '.parse' do
25 it 'returns ObjectifiedHash' do
2426 body = JSON.unparse(a: 1, b: 2)
25 expect(Gitlab::Request.parse(body)).to be_an Gitlab::ObjectifiedHash
26 expect(Gitlab::Request.parse("true")).to be true
27 expect(Gitlab::Request.parse("false")).to be false
27 expect(described_class.parse(body)).to be_an Gitlab::ObjectifiedHash
28 expect(described_class.parse('true')).to be true
29 expect(described_class.parse('false')).to be false
2830
29 expect { Gitlab::Request.parse("string") }.to raise_error(Gitlab::Error::Parsing)
31 expect { described_class.parse('string') }.to raise_error(Gitlab::Error::Parsing)
3032 end
3133 end
3234
33 describe "#request_defaults" do
34 context "when endpoint is not set" do
35 it "raises Error::MissingCredentials" do
35 describe '#request_defaults' do
36 context 'when endpoint is not set' do
37 it 'raises Error::MissingCredentials' do
3638 @request.endpoint = nil
3739 expect do
3840 @request.request_defaults
4042 end
4143 end
4244
43 context "when endpoint is set" do
44 before(:each) do
45 context 'when endpoint is set' do
46 before do
4547 @request.endpoint = 'http://rabbit-hole.example.com'
4648 end
4749
48 it "sets default_params" do
50 it 'sets default_params' do
4951 @request.request_defaults('sudoer')
50 expect(Gitlab::Request.default_params).to eq(sudo: 'sudoer')
52 expect(described_class.default_params).to eq(sudo: 'sudoer')
5153 end
5254 end
5355 end
5456
55 describe "#authorization_header" do
56 it "raises MissingCredentials when auth_token and private_token are not set" do
57 describe '#authorization_header' do
58 it 'raises MissingCredentials when auth_token and private_token are not set' do
5759 expect do
5860 @request.send(:authorization_header, {})
5961 end.to raise_error(Gitlab::Error::MissingCredentials)
6062 end
6163
62 it "sets the correct header when given a private_token" do
64 it 'sets the correct header when given a private_token' do
6365 @request.private_token = 'ys9BtunN3rDKbaJCYXaN'
64 expect(@request.send(:authorization_header, {})).to eq("PRIVATE-TOKEN" => 'ys9BtunN3rDKbaJCYXaN')
66 expect(@request.send(:authorization_header, {})).to eq('PRIVATE-TOKEN' => 'ys9BtunN3rDKbaJCYXaN')
6567 end
6668
67 it "sets the correct header when setting an auth_token via the private_token config option" do
69 it 'sets the correct header when setting an auth_token via the private_token config option' do
6870 @request.private_token = '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603'
69 expect(@request.send(:authorization_header, {})).to eq("Authorization" => "Bearer 3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603")
71 expect(@request.send(:authorization_header, {})).to eq('Authorization' => 'Bearer 3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603')
7072 end
7173 end
7274 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13 require 'tempfile'
24
46 context 'saving to a file' do
57 before do
68 @file = Tempfile.new('.gitlab_shell_history')
7 @history = Gitlab::Shell::History.new(file_path: @file.path)
9 @history = described_class.new(file_path: @file.path)
810 end
911
1012 after { @file.close(true) }
1315 @history << 'party on, dudes'
1416 @history << 'be excellent to each other'
1517 @history.save
16 expect(File.read @file.path).
17 to eq("party on, dudes\nbe excellent to each other\n")
18 expect(File.read(@file.path))
19 .to eq("party on, dudes\nbe excellent to each other\n")
1820 end
1921
2022 it 'has the lines' do
2123 @history << 'party on, dudes'
2224 @history << 'be excellent to each other'
23 expect(@history.lines).
24 to eq(["party on, dudes", "be excellent to each other"])
25 expect(@history.lines)
26 .to eq(['party on, dudes', 'be excellent to each other'])
2527 end
2628
2729 it 'limits the lines to GITLAB_HISTFILESIZE' do
3032 @history << 'party on, dudes'
3133 @history << 'be excellent to each other'
3234 @history.save
33 expect(@history.lines).
34 to eq(["party on, dudes", "be excellent to each other"])
35 expect(File.read @file.path).
36 to eq("party on, dudes\nbe excellent to each other\n")
35 expect(@history.lines)
36 .to eq(['party on, dudes', 'be excellent to each other'])
37 expect(File.read(@file.path))
38 .to eq("party on, dudes\nbe excellent to each other\n")
3739 end
3840 end
3941
4042 context 'loading a file' do
4143 before do
4244 @file = load_fixture('shell_history')
43 @history = Gitlab::Shell::History.new(file_path: @file.path)
45 @history = described_class.new(file_path: @file.path)
4446 end
4547
4648 it 'has the lines' do
4749 @history.load
48 expect(@history.lines).
49 to eq(["party on, dudes", "be excellent to each other"])
50 expect(@history.lines)
51 .to eq(['party on, dudes', 'be excellent to each other'])
5052 end
5153 end
5254 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab::Shell do
35 before do
4 Gitlab::Shell.setup
6 described_class.setup
57 end
68
7 describe ".execute" do
8 context "invalid command" do
9 it "raises RuntimeError" do
10 expect { Gitlab::Shell.execute 'foobar', [] }.to raise_error(RuntimeError)
9 describe '.execute' do
10 context 'invalid command' do
11 it 'raises RuntimeError' do
12 expect { described_class.execute 'foobar', [] }.to raise_error(RuntimeError)
1113 end
1214 end
1315 end
1416
15 describe ".history" do
17 describe '.history' do
1618 before do
17 @history = Gitlab::Shell.history
19 @history = described_class.history
1820 end
1921
20 it "returns a Gitlab::Shell::History instance" do
22 it 'returns a Gitlab::Shell::History instance' do
2123 expect(@history).to be_a Gitlab::Shell::History
2224 end
23 it "responds to :save" do
25 it 'responds to :save' do
2426 expect(@history).to respond_to :save
2527 end
26 it "responds to :load" do
28 it 'responds to :load' do
2729 expect(@history).to respond_to :load
2830 end
29 it "responds to :<<" do
31 it 'responds to :<<' do
3032 expect(@history).to respond_to :<<
3133 end
3234 end
3335
34 describe ".setup" do
35 it "sets the Readline completion_proc" do
36 describe '.setup' do
37 it 'sets the Readline completion_proc' do
3638 completion = Readline.completion_proc
3739 expect(completion).to be_truthy
3840 expect(completion).to be_a Proc
3941 end
40 it "sets the Readline completion_append_character" do
42 it 'sets the Readline completion_append_character' do
4143 completion_character = Readline.completion_append_character
4244 expect(completion_character).to eq(' ')
4345 end
4446 end
4547
46 describe ".completion" do
48 describe '.completion' do
4749 before do
48 @comp = Gitlab::Shell.completion
50 @comp = described_class.completion
4951 end
50 it "returns a Proc object" do
52
53 it 'returns a Proc object' do
5154 expect(@comp).to be_a Proc
5255 end
53 context "called with an argument" do
54 it "returns an Array of matching commands" do
56 context 'called with an argument' do
57 it 'returns an Array of matching commands' do
5558 completed_cmds = @comp.call 'group'
5659 expect(completed_cmds).to be_a Array
57 expect(completed_cmds.sort).to eq(%w(group group_access_requests group_member group_members group_milestone group_milestone_issues group_milestone_merge_requests group_milestones group_projects group_search group_subgroups group_variable group_variables groups))
60 expect(completed_cmds.sort).to eq(%w[group group_access_requests group_member group_members group_milestone group_milestone_issues group_milestone_merge_requests group_milestones group_projects group_search group_subgroups group_variable group_variables groups])
5861 end
5962 end
6063 end
6164
62 describe ".parse_input" do
63 context "with arguments" do
64 it "sets command & arguments" do
65 Gitlab::Shell.parse_input('create_branch 1 "api" "master"')
66 expect(Gitlab::Shell.command).to eq('create_branch')
67 expect(Gitlab::Shell.arguments).to eq(%w(1 api master))
65 describe '.parse_input' do
66 context 'with arguments' do
67 it 'sets command & arguments' do
68 described_class.parse_input('create_branch 1 "api" "master"')
69 expect(described_class.command).to eq('create_branch')
70 expect(described_class.arguments).to eq(%w[1 api master])
6871 end
6972 end
7073
71 context "without arguments" do
74 context 'without arguments' do
7275 it 'sets command & empty arguments' do
73 Gitlab::Shell.parse_input('exit')
74 expect(Gitlab::Shell.command).to eq('exit')
75 expect(Gitlab::Shell.arguments).to be_empty
76 described_class.parse_input('exit')
77 expect(described_class.command).to eq('exit')
78 expect(described_class.arguments).to be_empty
7679 end
7780 end
7881 end
0 # frozen_string_literal: true
1
02 require 'spec_helper'
13
24 describe Gitlab do
3 after { Gitlab.reset }
5 after { described_class.reset }
46
5 describe ".client" do
6 it "is a Gitlab::Client" do
7 expect(Gitlab.client).to be_a Gitlab::Client
7 describe '.client' do
8 it 'is a Gitlab::Client' do
9 expect(described_class.client).to be_a Gitlab::Client
810 end
911
10 it "does not override each other" do
11 client1 = Gitlab.client(endpoint: 'https://api1.example.com', private_token: '001')
12 client2 = Gitlab.client(endpoint: 'https://api2.example.com', private_token: '002')
12 it 'does not override each other' do
13 client1 = described_class.client(endpoint: 'https://api1.example.com', private_token: '001')
14 client2 = described_class.client(endpoint: 'https://api2.example.com', private_token: '002')
1315 expect(client1.endpoint).to eq('https://api1.example.com')
1416 expect(client2.endpoint).to eq('https://api2.example.com')
1517 expect(client1.private_token).to eq('001')
1618 expect(client2.private_token).to eq('002')
1719 end
1820
19 it "sets private_token to the auth_token when provided" do
20 client = Gitlab.client(endpoint: 'https://api2.example.com', auth_token: '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603')
21 it 'sets private_token to the auth_token when provided' do
22 client = described_class.client(endpoint: 'https://api2.example.com', auth_token: '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603')
2123 expect(client.private_token).to eq('3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603')
2224 end
2325 end
2426
25 describe ".actions" do
26 it "returns an array of client methods" do
27 actions = Gitlab.actions
27 describe '.actions' do
28 it 'returns an array of client methods' do
29 actions = described_class.actions
2830 expect(actions).to be_an Array
2931 expect(actions.first).to be_a Symbol
30 expect(actions.sort.first).to eq(:accept_merge_request)
32 expect(actions.min).to eq(:accept_merge_request)
3133 end
3234 end
3335
34 describe ".endpoint=" do
35 it "sets endpoint" do
36 Gitlab.endpoint = 'https://api.example.com'
37 expect(Gitlab.endpoint).to eq('https://api.example.com')
36 describe '.endpoint=' do
37 it 'sets endpoint' do
38 described_class.endpoint = 'https://api.example.com'
39 expect(described_class.endpoint).to eq('https://api.example.com')
3840 end
3941 end
4042
41 describe ".private_token=" do
42 it "sets private_token" do
43 Gitlab.private_token = 'secret'
44 expect(Gitlab.private_token).to eq('secret')
43 describe '.private_token=' do
44 it 'sets private_token' do
45 described_class.private_token = 'secret'
46 expect(described_class.private_token).to eq('secret')
4547 end
4648 end
4749
48 describe ".auth_token=" do
49 it "sets auth_token", focus: true do
50 Gitlab.auth_token = 'auth_secret'
51 expect(Gitlab.private_token).to eq('auth_secret')
50 describe '.auth_token=' do
51 it 'sets auth_token', focus: true do
52 described_class.auth_token = 'auth_secret'
53 expect(described_class.private_token).to eq('auth_secret')
5254 end
5355 end
5456
55 describe ".sudo=" do
56 it "sets sudo" do
57 Gitlab.sudo = 'user'
58 expect(Gitlab.sudo).to eq('user')
57 describe '.sudo=' do
58 it 'sets sudo' do
59 described_class.sudo = 'user'
60 expect(described_class.sudo).to eq('user')
5961 end
6062 end
6163
62 describe ".user_agent" do
63 it "returns default user_agent" do
64 expect(Gitlab.user_agent).to eq(Gitlab::Configuration::DEFAULT_USER_AGENT)
64 describe '.user_agent' do
65 it 'returns default user_agent' do
66 expect(described_class.user_agent).to eq(Gitlab::Configuration::DEFAULT_USER_AGENT)
6567 end
6668 end
6769
68 describe ".user_agent=" do
69 it "sets user_agent" do
70 Gitlab.user_agent = 'Custom User Agent'
71 expect(Gitlab.user_agent).to eq('Custom User Agent')
70 describe '.user_agent=' do
71 it 'sets user_agent' do
72 described_class.user_agent = 'Custom User Agent'
73 expect(described_class.user_agent).to eq('Custom User Agent')
7274 end
7375 end
7476
75 describe ".configure" do
77 describe '.configure' do
7678 Gitlab::Configuration::VALID_OPTIONS_KEYS.each do |key|
7779 it "sets #{key}" do
78 Gitlab.configure do |config|
80 described_class.configure do |config|
7981 config.send("#{key}=", key)
80 expect(Gitlab.send(key)).to eq(key)
82 expect(described_class.send(key)).to eq(key)
8183 end
8284 end
8385 end
8486 end
8587
86 describe ".http_proxy" do
87 it "delegates the method to Gitlab::Request" do
88 Gitlab.endpoint = 'https://api.example.com'
88 describe '.http_proxy' do
89 it 'delegates the method to Gitlab::Request' do
90 described_class.endpoint = 'https://api.example.com'
8991 request = class_spy(Gitlab::Request).as_stubbed_const
9092
91 Gitlab.http_proxy('proxy.example.net', 1987, 'user', 'pass')
93 described_class.http_proxy('proxy.example.net', 1987, 'user', 'pass')
9294 expect(request).to have_received(:http_proxy).with('proxy.example.net', 1987, 'user', 'pass')
9395 end
9496 end
0 # frozen_string_literal: true
1
02 require 'rspec'
13 require 'webmock/rspec'
24
3 require File.expand_path('../../lib/gitlab', __FILE__)
4 require File.expand_path('../../lib/gitlab/cli', __FILE__)
5 require File.expand_path('../lib/gitlab', __dir__)
6 require File.expand_path('../lib/gitlab/cli', __dir__)
57
68 def capture_output
79 out = StringIO.new
2426 end
2527 end
2628
27 %i(get post put delete).each do |method|
28 define_method "stub_#{method}" do |path, fixture, status_code=200|
29 %i[get post put delete].each do |method|
30 define_method "stub_#{method}" do |path, fixture, status_code = 200|
2931 stub_request(method, "#{Gitlab.endpoint}#{path}")
3032 .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
3133 .to_return(body: load_fixture(fixture), status: status_code)