diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..b432662 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,18 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 90 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 10 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security + - contribution welcome +# Label to use when marking an issue as stale +staleLabel: stale +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false diff --git a/.rubocop.yml b/.rubocop.yml index 71ac139..0fb26b9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,33 +1,32 @@ -Layout/SpaceAroundEqualsInParameterDefault: - Enabled: false +--- +inherit_from: .rubocop_todo.yml -Style/Alias: - Enabled: false - -Style/PercentLiteralDelimiters: - Enabled: false - -Layout/DotPosition: - Enabled: false +AllCops: + TargetRubyVersion: 2.3 Metrics/LineLength: - Max: 100 + Max: 125 Exclude: - 'lib/gitlab/client/*' - - 'spec/**/*' - -Style/ClassAndModuleChildren: - Exclude: - - 'lib/gitlab/client/*' - -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'lib/gitlab/client/*' - -Style/StringLiterals: - Exclude: - 'spec/**/*' Metrics/BlockLength: Exclude: - 'spec/**/*' + +Style/Documentation: + Enabled: false + +Style/ClassAndModuleChildren: + Exclude: + - 'lib/gitlab/*' + - 'lib/gitlab/client/*' + +Style/FrozenStringLiteralComment: + Exclude: + - 'spec/gitlab/file_response_spec.rb' + - 'spec/gitlab/help_spec.rb' + +Style/SpecialGlobalVars: + Exclude: + - 'gitlab.gemspec' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..e7f445b --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,46 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2018-10-10 10:25:27 +0400 using RuboCop version 0.59.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +Lint/UriEscapeUnescape: + Exclude: + - 'lib/gitlab/client.rb' + +# Offense count: 5 +Metrics/AbcSize: + Max: 34 + +# Offense count: 4 +Metrics/CyclomaticComplexity: + Max: 14 + +# Offense count: 10 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 34 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/ModuleLength: + Max: 165 + +# Offense count: 2 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 6 + +# Offense count: 1 +Metrics/PerceivedComplexity: + Max: 10 + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect. +Security/JSONLoad: + Exclude: + - 'lib/gitlab/request.rb' diff --git a/.travis.yml b/.travis.yml index 2889199..0d64b20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,13 @@ +--- language: ruby rvm: - 2.3 - 2.4 - 2.5 -before_install: gem update bundler + - 2.6 -matrix: +jobs: include: - - rvm: 2.4 - env: "TRAVIS_CI_RUBOCOP=true" - allow_failures: - - env: "TRAVIS_CI_RUBOCOP=true" + - stage: lint + rvm: 2.3 + script: bundle exec rake rubocop diff --git a/Gemfile b/Gemfile index 54fbdf1..605173e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in gitlab.gemspec diff --git a/LICENSE.txt b/LICENSE.txt index 881faef..8e37cdb 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2012-2015 Nihad Abbasov +Copyright (c) 2012-2019 Nihad Abbasov All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 35d5c76..67bd849 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ # Gitlab [![Build Status](https://img.shields.io/travis/NARKOZ/gitlab.svg)](https://travis-ci.org/NARKOZ/gitlab) -[![Code Climate](https://img.shields.io/codeclimate/maintainability/NARKOZ/gitlab.svg)](https://codeclimate.com/github/NARKOZ/gitlab) -[![Inline docs](http://inch-ci.org/github/NARKOZ/gitlab.svg)](https://inch-ci.org/github/NARKOZ/gitlab) +[![Maintainability](https://api.codeclimate.com/v1/badges/2e310b334b1b5db4a7e1/maintainability)](https://codeclimate.com/github/NARKOZ/gitlab) +[![Inline docs](https://inch-ci.org/github/NARKOZ/gitlab.svg)](https://inch-ci.org/github/NARKOZ/gitlab) [![Gem version](https://img.shields.io/gem/v/gitlab.svg)](https://rubygems.org/gems/gitlab) [![License](https://img.shields.io/badge/license-BSD-red.svg)](https://github.com/NARKOZ/gitlab/blob/master/LICENSE.txt) -[website](http://narkoz.github.io/gitlab) | -[documentation](http://rubydoc.info/gems/gitlab/frames) | +[website](https://narkoz.github.io/gitlab) | +[documentation](https://rubydoc.info/gems/gitlab/frames) | [gitlab-live](https://github.com/NARKOZ/gitlab-live) Gitlab is a Ruby wrapper and CLI for the [GitLab API](https://docs.gitlab.com/ce/api/README.html). -As of version `4.0.0` this gem only supports Ruby 2.0+ and Gitlab API v4. +As of version `4.0.0` this gem only supports Ruby 2.0+ and GitLab API v4. ## Installation @@ -54,8 +54,8 @@ ```ruby # set an API endpoint -Gitlab.endpoint = 'http://example.net/api/v4' -# => "http://example.net/api/v4" +Gitlab.endpoint = 'https://example.net/api/v4' +# => "https://example.net/api/v4" # set a user private token Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG' @@ -63,8 +63,10 @@ # configure a proxy server Gitlab.http_proxy('proxyhost', 8888) -# proxy server w/ basic auth +# proxy server with basic auth Gitlab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere') +# set timeout for responses +ENV['GITLAB_API_HTTPARTY_OPTIONS'] = '{read_timeout: 60}' # list projects Gitlab.projects(per_page: 5) @@ -108,11 +110,11 @@ projects.auto_paginate ``` -For more information, refer to [documentation](http://rubydoc.info/gems/gitlab/frames). +For more information, refer to [documentation](https://rubydoc.info/gems/gitlab/frames). ## CLI -It is possible to use this gem as a command line interface to gitlab. In order to make that work you need to set a few environment variables: +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: ```sh export GITLAB_API_ENDPOINT=https://gitlab.yourcompany.com/api/v4 export GITLAB_API_PRIVATE_TOKEN= @@ -124,21 +126,21 @@ Usage: -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. +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. Usage examples: ```sh # list users -# see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#users-instance_method +# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#users-instance_method gitlab users # get current user -# see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method +# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method gitlab user # get a user -# see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method +# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method gitlab user 2 # filter output @@ -150,7 +152,7 @@ gitlab user 2 --json # passing options hash to a command (use YAML) -# see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method +# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method gitlab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}" ``` @@ -177,17 +179,17 @@ ``` Web version is available at https://gitlab-live.herokuapp.com -For more information, refer to [website](http://narkoz.github.io/gitlab). +For more information, refer to [website](https://narkoz.github.io/gitlab). ## Development -### With a dockerized Gitlab instance - -```shell -docker-compose up -d gitlab # Will start the gitlab instance in the background (approx. 3 minutes) -``` - -After a while, your Gitlab instance will be accessible on http://localhost:3000. +### With a dockerized GitLab instance + +```shell +docker-compose up -d gitlab # Will start the GitLab instance in the background (approx. 3 minutes) +``` + +After a while, your GitLab instance will be accessible on http://localhost:3000. Once you have set your new root password, you can login with the root user. @@ -206,17 +208,17 @@ => [#1, "name"=>"Administrator", "username"=>"root", ...] ``` -To launch the specs, +To launch the specs: ```shell docker-compose run app rake spec ``` -#### Want to use Gitlab Enterprise? +#### Want to use GitLab Enterprise? Just change the image from `gitlab/gitlab-ce:latest` to `gitlab/gitlab-ee:latest` in the `docker-compose.yml` file. -### With an external Gitlab instance +### With an external GitLab instance First, set the variables to the correct values in the `docker.env` file. diff --git a/Rakefile b/Rakefile index 7f078a0..3ffd91e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' @@ -10,8 +12,4 @@ task.options = ['-D', '--parallel'] end -if ENV['TRAVIS_CI_RUBOCOP'] - task default: :rubocop -else - task default: :spec -end +task default: :spec diff --git a/bin/console b/bin/console index 1b231af..282a073 100755 --- a/bin/console +++ b/bin/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true # ENV['GITLAB_API_ENDPOINT'] = '' # ENV['GITLAB_API_PRIVATE_TOKEN'] = '' diff --git a/exe/gitlab b/exe/gitlab index 7d4c31c..574f70e 100755 --- a/exe/gitlab +++ b/exe/gitlab @@ -1,6 +1,10 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) + +# Exit cleanly from an early interrupt +Signal.trap('INT') { exit 1 } require 'gitlab/cli' diff --git a/gitlab.gemspec b/gitlab.gemspec index 0da77b8..078f297 100644 --- a/gitlab.gemspec +++ b/gitlab.gemspec @@ -1,4 +1,6 @@ -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'gitlab/version' @@ -11,16 +13,17 @@ gem.summary = 'A Ruby wrapper and CLI for the GitLab API' gem.homepage = 'https://github.com/narkoz/gitlab' - gem.files = `git ls-files`.split($/). - reject { |f| f[/^spec/] } - - %w[Dockerfile docker-compose.yml docker.env .travis.yml .rubocop.yml .dockerignore] + gem.files = `git ls-files`.split($/) + .grep_v(/^spec/) - + %w[Dockerfile docker-compose.yml docker.env .travis.yml + .rubocop.yml .dockerignore] gem.bindir = 'exe' gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ['lib'] gem.license = 'BSD' - gem.required_ruby_version = '>= 2.0.0' + gem.required_ruby_version = '>= 2.3' gem.add_runtime_dependency 'httparty', '>= 0.14.0' gem.add_runtime_dependency 'terminal-table', '>= 1.5.1' @@ -28,6 +31,6 @@ gem.add_development_dependency 'pry' gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec' + gem.add_development_dependency 'rubocop' gem.add_development_dependency 'webmock' - gem.add_development_dependency 'rubocop' end diff --git a/lib/gitlab/api.rb b/lib/gitlab/api.rb index af78c5f..cc8c2b7 100644 --- a/lib/gitlab/api.rb +++ b/lib/gitlab/api.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + module Gitlab # @private class API < Request # @private attr_accessor(*Configuration::VALID_OPTIONS_KEYS) # @private - alias_method :auth_token=, :private_token= + alias auth_token= private_token= # Creates a new API. # @raise [Error:MissingCredentials] - def initialize(options={}) + def initialize(options = {}) options = Gitlab.options.merge(options) (Configuration::VALID_OPTIONS_KEYS + [:auth_token]).each do |key| send("#{key}=", options[key]) if options[key] end - request_defaults(@sudo) + request_defaults(sudo) self.class.headers 'User-Agent' => user_agent end end diff --git a/lib/gitlab/cli.rb b/lib/gitlab/cli.rb index cf10150..956cd77 100644 --- a/lib/gitlab/cli.rb +++ b/lib/gitlab/cli.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'gitlab' require 'terminal-table/import' require_relative 'cli_helpers' @@ -17,7 +19,11 @@ # # @param [Array] args The command and it's optional arguments. def self.start(args) - command = args.shift.strip rescue 'help' + command = begin + args.shift.strip + rescue StandardError + 'help' + end run(command, args) end @@ -30,13 +36,13 @@ # @param [String] cmd The name of a command. # @param [Array] args The optional arguments for a command. # @return [nil] - def self.run(cmd, args=[]) + def self.run(cmd, args = []) case cmd when 'help' puts help(args.shift) { |out| out.gsub!(/Gitlab\./, 'gitlab ') } when 'info' - endpoint = Gitlab.endpoint ? Gitlab.endpoint : 'not set' - private_token = Gitlab.private_token ? Gitlab.private_token : 'not set' + endpoint = Gitlab.endpoint || 'not set' + private_token = Gitlab.private_token || 'not set' puts "Gitlab endpoint is #{endpoint}" puts "Gitlab private token is #{private_token}" puts "Ruby Version is #{RUBY_VERSION}" @@ -60,7 +66,7 @@ begin command_args.map! { |arg| symbolize_keys(yaml_load(arg)) } - rescue => e + rescue StandardError => e puts e.message exit 1 end diff --git a/lib/gitlab/cli_helpers.rb b/lib/gitlab/cli_helpers.rb index 69893ec..e646515 100644 --- a/lib/gitlab/cli_helpers.rb +++ b/lib/gitlab/cli_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'yaml' require 'json' require 'base64' @@ -5,7 +7,7 @@ class Gitlab::CLI # Defines methods related to CLI output and formatting. module Helpers - extend self + module_function # Returns actions available to CLI & Shell # @@ -71,7 +73,7 @@ puts 'Are you sure? (y/n)' - if %w(y yes).include?($stdin.gets.to_s.strip.downcase) + if %w[y yes].include?($stdin.gets.to_s.strip.downcase) puts 'Proceeding..' else puts 'Command aborted.' @@ -82,7 +84,7 @@ # Gets defined help for a specific command/action. # # @return [String] - def help(cmd=nil, &block) + def help(cmd = nil, &block) if cmd.nil? || Gitlab::Help.help_map.key?(cmd) Gitlab::Help.actions_table(cmd) else @@ -90,14 +92,14 @@ end end - # Outputs a nicely formatted table or error msg. + # Outputs a nicely formatted table or error message. def output_table(cmd, args, data) case data when Gitlab::ObjectifiedHash, Gitlab::FileResponse puts record_table([data], cmd, args) when Gitlab::PaginatedResponse puts record_table(data, cmd, args) - else # probably just an error msg + else # probably just an error message puts data end end @@ -159,7 +161,7 @@ # @param [Array] args Options passed to the API call # @param [bool] single_value If set to true, a single result should be returned # @return [Hash] Result hash - def record_hash(data, cmd, args, single_value=false) + def record_hash(data, cmd, args, single_value = false) if data.empty? result = nil else @@ -169,21 +171,21 @@ row = {} keys.each do |key| - case hash[key] - when Hash - row[key] = 'Hash' - when StringIO - row[key] = Base64.encode64(hash[key].read) - when nil - row[key] = nil - else - row[key] = hash[key] - end + row[key] = case hash[key] + when Hash + 'Hash' + when StringIO + Base64.encode64(hash[key].read) + when nil + nil + else + hash[key] + end end result.push row end - result = result[0] if single_value && result.count > 0 + result = result[0] if single_value && result.count.positive? end { @@ -202,10 +204,10 @@ end # Helper function to call Gitlab commands with args. - def gitlab_helper(cmd, args=[]) + def gitlab_helper(cmd, args = []) begin data = args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd) - rescue => e + rescue StandardError => e puts e.message yield if block_given? end @@ -217,9 +219,9 @@ # @return [Hash] def symbolize_keys(hash) if hash.is_a?(Hash) - hash = hash.each_with_object({}) do |(key, value), newhash| + hash = hash.each_with_object({}) do |(key, value), new_hash| begin - newhash[key.to_sym] = symbolize_keys(value) + new_hash[key.to_sym] = symbolize_keys(value) rescue NoMethodError raise "Error: cannot convert hash key to symbol: #{key}" end @@ -229,9 +231,16 @@ hash end + # Check if arg is a color in 6-digit hex notation with leading '#' sign + def hex_color?(arg) + pattern = /\A#\h{6}\Z/ + + pattern.match(arg) + end + # YAML::load on a single argument def yaml_load(arg) - YAML.safe_load(arg) + hex_color?(arg) ? arg : YAML.safe_load(arg) rescue Psych::SyntaxError raise "Error: Argument is not valid YAML syntax: #{arg}" end diff --git a/lib/gitlab/client/access_requests.rb b/lib/gitlab/client/access_requests.rb index a80a288..aa62d46 100644 --- a/lib/gitlab/client/access_requests.rb +++ b/lib/gitlab/client/access_requests.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to Award Emojis. # @see https://docs.gitlab.com/ce/api/access_requests.html @@ -12,6 +14,7 @@ def project_access_requests(project) get("/projects/#{url_encode project}/access_requests") end + # Gets a list of access requests for a group viewable by the authenticated user. # # @example @@ -22,6 +25,7 @@ def group_access_requests(group) get("/groups/#{url_encode group}/access_requests") end + # Requests access for the authenticated user to a project. # # @example @@ -32,6 +36,7 @@ def request_project_access(project) post("/projects/#{url_encode project}/access_requests") end + # Requests access for the authenticated user to a group. # # @example @@ -42,6 +47,7 @@ def request_group_access(group) post("/groups/#{url_encode group}/access_requests") end + # Approves a project access request for the given user. # # @example @@ -55,6 +61,7 @@ def approve_project_access_request(project, user_id, options = {}) put("/projects/#{url_encode project}/access_requests/#{user_id}/approve", body: options) end + # Approves a group access request for the given user. # # @example @@ -68,6 +75,7 @@ def approve_group_access_request(group, user_id, options = {}) put("/groups/#{url_encode group}/access_requests/#{user_id}/approve", body: options) end + # Denies a project access request for the given user. # # @example @@ -79,6 +87,7 @@ def deny_project_access_request(project, user_id) delete("/projects/#{url_encode project}/access_requests/#{user_id}") end + # Denies a group access request for the given user. # # @example @@ -91,4 +100,4 @@ delete("/groups/#{url_encode group}/access_requests/#{user_id}") end end -end \ No newline at end of file +end diff --git a/lib/gitlab/client/award_emojis.rb b/lib/gitlab/client/award_emojis.rb index 931ae64..bdc61a5 100644 --- a/lib/gitlab/client/award_emojis.rb +++ b/lib/gitlab/client/award_emojis.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to Award Emojis. # @see https://docs.gitlab.com/ce/api/award_emoji.html @@ -79,7 +81,7 @@ # @param [String] emoji_name The name of the emoji, without colons. # @return [Gitlab::ObjectifiedHash] def create_award_emoji(project, awardable_id, awardable_type, emoji_name) - post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji", body: {name: emoji_name}) + post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji", body: { name: emoji_name }) end # Awards a new emoji to a note on an awardable(issue, merge request or snippet) @@ -96,7 +98,7 @@ # @param [String] emoji_name The name of the emoji, without colons. # @return [Gitlab::ObjectifiedHash] def create_note_award_emoji(project, awardable_id, awardable_type, note_id, emoji_name) - post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji", body: {name: emoji_name}) + post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji", body: { name: emoji_name }) end # Deletes a single award emoji from an awardable(issue, merge request or snippet) @@ -132,4 +134,4 @@ delete("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji/#{award_id}") end end -end \ No newline at end of file +end diff --git a/lib/gitlab/client/boards.rb b/lib/gitlab/client/boards.rb index 3886dcf..a1a41a1 100644 --- a/lib/gitlab/client/boards.rb +++ b/lib/gitlab/client/boards.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to issue boards. # @see https://docs.gitlab.com/ce/api/boards.html @@ -13,7 +15,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def boards(project, options={}) + def boards(project, options = {}) get("/projects/#{url_encode project}/boards", query: options) end @@ -28,6 +30,7 @@ def board_lists(project, id) get("/projects/#{url_encode project}/boards/#{id}/lists") end + # # Gets a single board list # @@ -53,7 +56,7 @@ # @param [Integer] label_id The ID of a label. # @return [Gitlab::ObjectifiedHash] Information about created list. def create_board_list(project, board_id, label_id) - post("/projects/#{url_encode project}/boards/#{board_id}/lists", body: {label_id: label_id}) + post("/projects/#{url_encode project}/boards/#{board_id}/lists", body: { label_id: label_id }) end # Updates a board list. @@ -67,7 +70,7 @@ # @param [Integer] id The ID of a list. # @return [Gitlab::ObjectifiedHash] Information about updated board list. def edit_board_list(project, board_id, id, position) - put("/projects/#{url_encode project}/boards/#{board_id}/lists/#{id}", body: {position: position}) + put("/projects/#{url_encode project}/boards/#{board_id}/lists/#{id}", body: { position: position }) end # Deletes a board list. @@ -85,4 +88,3 @@ end end end - diff --git a/lib/gitlab/client/branches.rb b/lib/gitlab/client/branches.rb index b6b2982..ca51e02 100644 --- a/lib/gitlab/client/branches.rb +++ b/lib/gitlab/client/branches.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to repositories. # @see https://docs.gitlab.com/ce/api/branches.html @@ -12,10 +14,10 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def branches(project, options={}) + def branches(project, options = {}) get("/projects/#{url_encode project}/repository/branches", query: options) end - alias_method :repo_branches, :branches + alias repo_branches branches # Gets information about a repository branch. # @@ -29,7 +31,7 @@ def branch(project, branch) get("/projects/#{url_encode project}/repository/branches/#{url_encode branch}") end - alias_method :repo_branch, :branch + alias repo_branch branch # Protects a repository branch. # @@ -47,9 +49,9 @@ # @option options [Boolean] :developers_can_merge True to allow developers to merge into the branch (default = false) # @return [Gitlab::ObjectifiedHash] Details about the branch def protect_branch(project, branch, options = {}) - post("/projects/#{url_encode project}/protected_branches", body: {name: branch}.merge(options)) + post("/projects/#{url_encode project}/protected_branches", body: { name: branch }.merge(options)) end - alias_method :repo_protect_branch, :protect_branch + alias repo_protect_branch protect_branch # Unprotects a repository branch. # @@ -63,7 +65,7 @@ def unprotect_branch(project, branch) delete("/projects/#{url_encode project}/protected_branches/#{url_encode branch}") end - alias_method :repo_unprotect_branch, :unprotect_branch + alias repo_unprotect_branch unprotect_branch # Creates a repository branch. Requires Gitlab >= 6.8.x # @@ -78,7 +80,7 @@ def create_branch(project, branch, ref) post("/projects/#{url_encode project}/repository/branches", query: { branch: branch, ref: ref }) end - alias_method :repo_create_branch, :create_branch + alias repo_create_branch create_branch # Deletes a repository branch. Requires Gitlab >= 6.8.x # @@ -91,6 +93,43 @@ def delete_branch(project, branch) delete("/projects/#{url_encode project}/repository/branches/#{url_encode branch}") end - alias_method :repo_delete_branch, :delete_branch + alias repo_delete_branch delete_branch + + # Delete all branches that are merged into the project default branch. Protected branches will not be deleted as part of this operation. + # + # @example + # Gitlab.delete_merged_branches(3) + # + # @param [Integer, String] project The ID or name of a project. + # @return [nil] This API call returns an empty response body. + def delete_merged_branches(project) + delete("/projects/#{url_encode project}/repository/merged_branches") + end + alias repo_delete_merged_branches delete_merged_branches + + # Gets a list of protected branches from a project. + # + # @example + # Gitlab.protected_branches(42) + # + # @param [Integer, String] project The ID or name of a project. + # @return [Array] + def protected_branches(project) + get("/projects/#{url_encode project}/protected_branches") + end + alias repo_protected_branches protected_branches + + # Gets a single protected branch or wildcard protected branch + # + # @example + # Gitlab.protected_branch(3, 'api') + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] name The name of the branch or wildcard + # @return [Gitlab::ObjectifiedHash] + def protected_branch(project, branch) + get("/projects/#{url_encode project}/protected_branches/#{url_encode branch}") + end + alias repo_protected_branch protected_branch end end diff --git a/lib/gitlab/client/broadcast_messages.rb b/lib/gitlab/client/broadcast_messages.rb new file mode 100644 index 0000000..33e8c23 --- /dev/null +++ b/lib/gitlab/client/broadcast_messages.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +class Gitlab::Client + # Defines methods related to broadcast messages (only accessible to administrators). + # @see https://docs.gitlab.com/ce/api/broadcast_messages.html + module BroadcastMessages + # Get all broadcast messages + # + # @example + # Gitlab.broadcast_messages + # + # @return [Array] + def broadcast_messages + get('/broadcast_messages') + end + + # Get a specific broadcast message + # + # @example + # Gitlab.broadcast_message(3) + # + # @param [Integer] id The ID of broadcast message + # @return [Gitlab::ObjectifiedHash] + def broadcast_message(id) + get("/broadcast_messages/#{id}") + end + + # Create a broadcast message. + # + # @example + # Gitlab.create_broadcast_message('Mayday') + # Gitlab.create_broadcast_message('Mayday', {starts_at: Time.zone.now, ends_at: Time.zone.now + 30.minutes, color: '#cecece', font: '#FFFFFF'}) + # + # @param [String] message Message to display + # @param [Hash] options A customizable set of options. + # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time) + # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time) + # @option options [String] :color(optional) Background color hex code + # @option options [String] :font(optional) Foreground color hex code + # @return [Gitlab::ObjectifiedHash] Information about created broadcast message. + def create_broadcast_message(message, options = {}) + body = { message: message }.merge(options) + post('/broadcast_messages', body: body) + end + + # Update a broadcast message + # + # @example + # Gitlab.edit_broadcast_message(6, { message: 'No Mayday' }) + # Gitlab.edit_broadcast_message(6, { font: '#FEFEFE' }) + # + # @param [Integer] id The ID of a broadcast message + # @param [Hash] options A customizable set of options. + # @option options [String] :message(optional) Message to display + # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time) + # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time) + # @option options [String] :color(optional) Background color hex code + # @option options [String] :font(optional) Foreground color hex code + # @return [Gitlab::ObjectifiedHash] Information about updated broadcast message. + def edit_broadcast_message(id, options = {}) + put("/broadcast_messages/#{id}", body: options) + end + + # Delete a broadcast message. + # + # @example + # Gitlab.delete_broadcast_message(3) + # + # @param [Integer] id The ID of a broadcast message. + # @return [nil] This API call returns an empty response body. + def delete_broadcast_message(id) + delete("/broadcast_messages/#{id}") + end + end +end diff --git a/lib/gitlab/client/build_variables.rb b/lib/gitlab/client/build_variables.rb index 573a559..fddd88d 100644 --- a/lib/gitlab/client/build_variables.rb +++ b/lib/gitlab/client/build_variables.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to builds. # @see https://docs.gitlab.com/ce/api/build_variables.html diff --git a/lib/gitlab/client/builds.rb b/lib/gitlab/client/builds.rb index 2f75827..58828bf 100644 --- a/lib/gitlab/client/builds.rb +++ b/lib/gitlab/client/builds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to builds. # @see https://docs.gitlab.com/ce/api/builds.html @@ -14,7 +16,7 @@ # @option options [Integer] :per_page The number of results per page. # @param [Integer, String] project The ID or name of a project. # @return [Array] - def builds(project, options={}) + def builds(project, options = {}) get("/projects/#{url_encode project}/builds", query: options) end @@ -40,15 +42,15 @@ # @return [Gitlab::FileResponse] def build_artifacts(project, id) get("/projects/#{url_encode project}/builds/#{id}/artifacts", - format: nil, - headers: { Accept: 'application/octet-stream' }, - parser: proc { |body, _| - if body.encoding == Encoding::ASCII_8BIT # binary response - ::Gitlab::FileResponse.new StringIO.new(body, 'rb+') - else # error with json response - ::Gitlab::Request.parse(body) - end - }) + format: nil, + headers: { Accept: 'application/octet-stream' }, + parser: proc { |body, _| + if body.encoding == Encoding::ASCII_8BIT # binary response + ::Gitlab::FileResponse.new StringIO.new(body, 'rb+') + else # error with json response + ::Gitlab::Request.parse(body) + end + }) end # Gets a list of builds for specific commit in a project. @@ -63,7 +65,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] The list of builds. - def commit_builds(project, sha, options={}) + def commit_builds(project, sha, options = {}) get("/projects/#{url_encode project}/repository/commits/#{sha}/builds", query: options) end diff --git a/lib/gitlab/client/commits.rb b/lib/gitlab/client/commits.rb index a86a2e1..0a3039e 100644 --- a/lib/gitlab/client/commits.rb +++ b/lib/gitlab/client/commits.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to repository commits. # @see https://docs.gitlab.com/ce/api/commits.html @@ -14,10 +16,10 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def commits(project, options={}) + def commits(project, options = {}) get("/projects/#{url_encode project}/repository/commits", query: options) end - alias_method :repo_commits, :commits + alias repo_commits commits # Gets a specific commit identified by the commit hash or name of a branch or tag. # @@ -31,7 +33,20 @@ def commit(project, sha) get("/projects/#{url_encode project}/repository/commits/#{sha}") end - alias_method :repo_commit, :commit + alias repo_commit commit + + # Cherry picks a commit to a given branch. + # + # @example + # Gitlab.cherry_pick_commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master') + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] sha The commit hash or name of a repository branch or tag + # @param [String] branch The name of the branch + # @return [Gitlab::ObjectifiedHash] + def cherry_pick_commit(project, sha, branch) + post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: { branch: branch }) + end # Get the diff of a commit in a project. # @@ -45,7 +60,7 @@ def commit_diff(project, sha) get("/projects/#{url_encode project}/repository/commits/#{sha}/diff") end - alias_method :repo_commit_diff, :commit_diff + alias repo_commit_diff commit_diff # Gets a list of comments for a commit. # @@ -57,10 +72,10 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def commit_comments(project, commit, options={}) + def commit_comments(project, commit, options = {}) get("/projects/#{url_encode project}/repository/commits/#{commit}/comments", query: options) end - alias_method :repo_commit_comments, :commit_comments + alias repo_commit_comments commit_comments # Creates a new comment for a commit. # @@ -75,10 +90,10 @@ # @option options [Integer] :line The line number. # @option options [String] :line_type The line type (new or old). # @return [Gitlab::ObjectifiedHash] Information about created comment. - def create_commit_comment(project, commit, note, options={}) + def create_commit_comment(project, commit, note, options = {}) post("/projects/#{url_encode project}/repository/commits/#{commit}/comments", body: options.merge(note: note)) end - alias_method :repo_create_commit_comment, :create_commit_comment + alias repo_create_commit_comment create_commit_comment # Get the status of a commit # @@ -94,10 +109,10 @@ # @option options [String] :stage Filter by stage # @option options [String] :name Filter by status name, eg. jenkins # @option options [Boolean] :all The flag to return all statuses, not only latest ones - def commit_status(project, sha, options={}) + def commit_status(project, sha, options = {}) get("/projects/#{url_encode project}/repository/commits/#{sha}/statuses", query: options) end - alias_method :repo_commit_status, :commit_status + alias repo_commit_status commit_status # Adds or updates a status of a commit. # @@ -113,10 +128,10 @@ # @option options [String] :ref The ref (branch or tag) to which the status refers # @option options [String] :name Filter by status name, eg. jenkins # @option options [String] :target_url The target URL to associate with this status - def update_commit_status(project, sha, state, options={}) + def update_commit_status(project, sha, state, options = {}) post("/projects/#{url_encode project}/statuses/#{sha}", query: options.merge(state: state)) end - alias_method :repo_update_commit_status, :update_commit_status + alias repo_update_commit_status update_commit_status # Creates a single commit with one or more changes # @@ -134,11 +149,11 @@ # @option options [String] :author_email the email address of the author # @option options [String] :author_name the name of the author # @return [Gitlab::ObjectifiedHash] hash of commit related data - def create_commit(project, branch, message, actions, options={}) + def create_commit(project, branch, message, actions, options = {}) payload = { - branch: branch, - commit_message: message, - actions: actions, + branch: branch, + commit_message: message, + actions: actions }.merge(options) post("/projects/#{url_encode project}/repository/commits", body: payload) end @@ -156,9 +171,9 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def commit_merge_requests(project, commit, options={}) + def commit_merge_requests(project, commit, options = {}) get("/projects/#{url_encode project}/repository/commits/#{commit}/merge_requests", query: options) end - alias_method :repo_commit_merge_requests, :commit_merge_requests + alias repo_commit_merge_requests commit_merge_requests end end diff --git a/lib/gitlab/client/deployments.rb b/lib/gitlab/client/deployments.rb index 7b1791d..b74f566 100644 --- a/lib/gitlab/client/deployments.rb +++ b/lib/gitlab/client/deployments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to deployments. # @see https://docs.gitlab.com/ce/api/deployments.html @@ -13,7 +15,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def deployments(project, options={}) + def deployments(project, options = {}) get("/projects/#{url_encode project}/deployments", query: options) end diff --git a/lib/gitlab/client/environments.rb b/lib/gitlab/client/environments.rb index a790b81..080071b 100644 --- a/lib/gitlab/client/environments.rb +++ b/lib/gitlab/client/environments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to environments. # @see https://docs.gitlab.com/ce/api/environments.html @@ -13,7 +15,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def environments(project, options={}) + def environments(project, options = {}) get("/projects/#{url_encode project}/environments", query: options) end @@ -40,7 +42,7 @@ # @option options [String] :external_url Optional URL for viewing the deployed project in this environment # @return [Gitlab::ObjectifiedHash] The updated environment. def create_environment(project, env_name, options = {}) - body = {name: env_name}.merge(options) + body = { name: env_name }.merge(options) post("/projects/#{url_encode project}/environments", body: body) end @@ -56,7 +58,7 @@ # @option options [String] env_name Name for the environment # @option options [String] external_url Optional URL for viewing the deployed project in this environment # @return [Gitlab::ObjectifiedHash] The updated environment. - def edit_environment(project, id, options={}) + def edit_environment(project, id, options = {}) put("/projects/#{url_encode project}/environments/#{id}", body: options) end diff --git a/lib/gitlab/client/events.rb b/lib/gitlab/client/events.rb index 8d92aa7..a98798a 100644 --- a/lib/gitlab/client/events.rb +++ b/lib/gitlab/client/events.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to events. # @see https://docs.gitlab.com/ce/api/events.html @@ -15,7 +17,7 @@ # @option options [String] :after Only events created after YYYY-MM-DD # @option options [String] :sort Sort by created_at either 'asc' or 'desc' # @return [Array] - def events(options={}) + def events(options = {}) get('/events', query: options) end @@ -33,7 +35,7 @@ # @option options [String] :after Only events created after YYYY-MM-DD # @option options [String] :sort Sort by created_at either 'asc' or 'desc' # @return [Array] - def user_events(user, options={}) + def user_events(user, options = {}) get("/users/#{url_encode user}/events", query: options) end @@ -51,8 +53,8 @@ # @option options [String] :after Only events created after YYYY-MM-DD # @option options [String] :sort Sort by created_at either 'asc' or 'desc' # @return [Array] - def project_events(project, options={}) - get("/#{url_encode project}/events", query: options) + def project_events(project, options = {}) + get("/projects/#{url_encode project}/events", query: options) end end end diff --git a/lib/gitlab/client/group_milestones.rb b/lib/gitlab/client/group_milestones.rb index 5825c7f..84765cd 100644 --- a/lib/gitlab/client/group_milestones.rb +++ b/lib/gitlab/client/group_milestones.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to group milestones. # @see https://docs.gitlab.com/ee/api/group_milestones.html @@ -12,7 +14,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def group_milestones(id, options={}) + def group_milestones(id, options = {}) get("/groups/#{url_encode id}/milestones", query: options) end @@ -39,7 +41,7 @@ # @option options [String] :description The description of a milestone. # @option options [String] :due_date The due date of a milestone. # @return [Gitlab::ObjectifiedHash] Information about created milestone. - def create_group_milestone(id, title, options={}) + def create_group_milestone(id, title, options = {}) body = { title: title }.merge(options) post("/groups/#{url_encode id}/milestones", body: body) end @@ -57,7 +59,7 @@ # @option options [String] :due_date The due date of a milestone. # @option options [String] :state_event The state of a milestone ('close' or 'activate'). # @return [Gitlab::ObjectifiedHash] Information about updated milestone. - def edit_group_milestone(id, milestone_id, options={}) + def edit_group_milestone(id, milestone_id, options = {}) put("/groups/#{url_encode id}/milestones/#{milestone_id}", body: options) end @@ -71,7 +73,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def group_milestone_issues(id, milestone_id, options={}) + def group_milestone_issues(id, milestone_id, options = {}) get("/groups/#{url_encode id}/milestones/#{milestone_id}/issues", query: options) end @@ -85,9 +87,8 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def group_milestone_merge_requests(id, milestone_id, options={}) + def group_milestone_merge_requests(id, milestone_id, options = {}) get("/groups/#{url_encode id}/milestones/#{milestone_id}/merge_requests", query: options) end end end - diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index 490a02e..6dd4b26 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to groups. # @see https://docs.gitlab.com/ce/api/groups.html @@ -12,8 +14,8 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def groups(options={}) - get("/groups", query: options) + def groups(options = {}) + get('/groups', query: options) end # Gets a single group. @@ -36,9 +38,9 @@ # @param [String] name The name of a group. # @param [String] path The path of a group. # @return [Gitlab::ObjectifiedHash] Information about created group. - def create_group(name, path, options={}) + def create_group(name, path, options = {}) body = { name: name, path: path }.merge(options) - post("/groups", body: body) + post('/groups', body: body) end # Delete's a group. @@ -62,7 +64,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def group_members(id, options={}) + def group_members(id, options = {}) get("/groups/#{url_encode id}/members", query: options) end @@ -138,9 +140,9 @@ # @option options [String] :per_page Number of projects to return per page # @option options [String] :page The page to retrieve # @return [Array] - def group_search(search, options={}) + def group_search(search, options = {}) options[:search] = search - get("/groups", query: options) + get('/groups', query: options) end # Get a list of projects under a group @@ -149,7 +151,7 @@ # # @param [Integer] id The ID of a group # @return [Array] List of projects under a group - def group_projects(id, options={}) + def group_projects(id, options = {}) get("/groups/#{url_encode id}/projects", query: options) end @@ -167,7 +169,7 @@ # @option options [String] :statistics Include group statistics (admins only). # @option options [String] :owned Limit to groups owned by the current user. # @return [Array] List of subgroups under a group - def group_subgroups(id, options={}) + def group_subgroups(id, options = {}) get("/groups/#{url_encode id}/subgroups", query: options) end @@ -186,7 +188,7 @@ # @option options [String] :lfs_enabled Enable/disable Large File Storage (LFS) for the projects in this groupr. # @option options [String] :request_access_enabled Allow users to request member access. # @return [Gitlab::ObjectifiedHash] Information about the edited group. - def edit_group(id, options={}) + def edit_group(id, options = {}) put("/groups/#{url_encode id}", body: options) end end diff --git a/lib/gitlab/client/issues.rb b/lib/gitlab/client/issues.rb index 2f1deda..6c87b96 100644 --- a/lib/gitlab/client/issues.rb +++ b/lib/gitlab/client/issues.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to issues. # @see https://docs.gitlab.com/ce/api/issues.html @@ -15,9 +17,9 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def issues(project=nil, options={}) + def issues(project = nil, options = {}) if project.to_s.empty? && project.to_i.zero? - get("/issues", query: options) + get('/issues', query: options) else get("/projects/#{url_encode project}/issues", query: options) end @@ -49,7 +51,7 @@ # @option options [Integer] :milestone_id The ID of a milestone to assign issue. # @option options [String] :labels Comma-separated label names for an issue. # @return [Gitlab::ObjectifiedHash] Information about created issue. - def create_issue(project, title, options={}) + def create_issue(project, title, options = {}) body = { title: title }.merge(options) post("/projects/#{url_encode project}/issues", body: body) end @@ -69,7 +71,7 @@ # @option options [String] :labels Comma-separated label names for an issue. # @option options [String] :state_event The state event of an issue ('close' or 'reopen'). # @return [Gitlab::ObjectifiedHash] Information about updated issue. - def edit_issue(project, id, options={}) + def edit_issue(project, id, options = {}) put("/projects/#{url_encode project}/issues/#{id}", body: options) end @@ -143,10 +145,10 @@ # @param [Integer] id The ID of an issue. # @option options [String] :to_project_id The ID of the new project. # @return [Gitlab::ObjectifiedHash] Information about moved issue. - def move_issue(project, id, options={}) + def move_issue(project, id, options = {}) post("/projects/#{url_encode project}/issues/#{id}/move", body: options) end - + # Sets an estimated time of work for an issue. # # @example @@ -158,8 +160,8 @@ def estimate_time_of_issue(project, id, duration) post("/projects/#{url_encode project}/issues/#{id}/time_estimate", body: { duration: url_encode(duration) }) end - - # Resets the estimated time for an issue to 0 seconds. + + # Resets the estimated time for an issue to 0 seconds. # # @example # Gitlab.reset_time_estimate_of_issue(3, 42) @@ -169,7 +171,7 @@ def reset_time_estimate_of_issue(project, id) post("/projects/#{url_encode project}/issues/#{id}/reset_time_estimate") end - + # Adds spent time for an issue # # @example @@ -181,7 +183,7 @@ def add_time_spent_on_issue(project, id, duration) post("/projects/#{url_encode project}/issues/#{id}/add_spent_time", body: { duration: url_encode(duration) }) end - + # Resets the total spent time for this issue to 0 seconds. # # @example @@ -192,7 +194,7 @@ def reset_time_spent_on_issue(project, id) post("/projects/#{url_encode project}/issues/#{id}/reset_spent_time") end - + # Get time tracking stats for an issue # # @example @@ -203,6 +205,27 @@ def time_stats_for_issue(project, id) get("/projects/#{url_encode project}/issues/#{id}/time_stats") end - + + # Get participants on issue + # + # @example + # @gitlab.participants_on_issue(3, 42) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of an issue. + def participants_on_issue(project, id) + get("/projects/#{url_encode project}/issues/#{id}/participants") + end + + # List merge requests that will close issue on merge + # + # @example + # Gitlab.merge_requests_closing_issue_on_merge(3, 42) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of an issue. + def merge_requests_closing_issue_on_merge(project, id) + get("/projects/#{url_encode project}/issues/#{id}/closed_by") + end end end diff --git a/lib/gitlab/client/jobs.rb b/lib/gitlab/client/jobs.rb index 68d6b36..cca66c5 100644 --- a/lib/gitlab/client/jobs.rb +++ b/lib/gitlab/client/jobs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to projects. # @see https://docs.gitlab.com/ee/api/jobs.html @@ -7,10 +9,13 @@ # @example # Gitlab.jobs(1) # Gitlab.jobs("project") + # Gitlab.jobs("project", {scope: ["manual", "success"], per_page: 100 }) # # @param [Integer, String] id The ID or name of a project. # @param [Hash] options A customizable set of options. # @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. + # @option options [Integer] :page The page number. + # @option options [Integer] :per_page The number of results per page. # @return [Array] def jobs(project_id, options = {}) get("/projects/#{url_encode project_id}/jobs", query: options) diff --git a/lib/gitlab/client/keys.rb b/lib/gitlab/client/keys.rb index 7d42a04..cbba34f 100644 --- a/lib/gitlab/client/keys.rb +++ b/lib/gitlab/client/keys.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to keys. # @see https://docs.gitlab.com/ce/api/keys.html diff --git a/lib/gitlab/client/labels.rb b/lib/gitlab/client/labels.rb index 6f35f44..81d2918 100644 --- a/lib/gitlab/client/labels.rb +++ b/lib/gitlab/client/labels.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to labels. # @see https://docs.gitlab.com/ce/api/labels.html @@ -9,7 +11,7 @@ # # @param [Integer, String] project The ID or name of a project. # @return [Array] - def labels(project, options={}) + def labels(project, options = {}) get("/projects/#{url_encode project}/labels", query: options) end @@ -43,7 +45,7 @@ # @option options [String] :description The description of the label. # @option options [String] :priority The priority of the label. Must be greater or equal than zero or null to remove the priority. # @return [Gitlab::ObjectifiedHash] Information about updated label. - def edit_label(project, name, options={}) + def edit_label(project, name, options = {}) put("/projects/#{url_encode project}/labels", body: options.merge(name: name)) end diff --git a/lib/gitlab/client/merge_request_approvals.rb b/lib/gitlab/client/merge_request_approvals.rb index 36ea9b8..f1c1dc4 100644 --- a/lib/gitlab/client/merge_request_approvals.rb +++ b/lib/gitlab/client/merge_request_approvals.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to MR Approvals. # @see https://docs.gitlab.com/ee/api/merge_request_approvals.html @@ -107,4 +109,4 @@ post("/projects/#{url_encode project}/merge_requests/#{merge_request}/unapprove") end end -end \ No newline at end of file +end diff --git a/lib/gitlab/client/merge_requests.rb b/lib/gitlab/client/merge_requests.rb index 8e3dbce..fa1ade7 100644 --- a/lib/gitlab/client/merge_requests.rb +++ b/lib/gitlab/client/merge_requests.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to merge requests. # @see https://docs.gitlab.com/ce/api/merge_requests.html @@ -25,7 +27,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def merge_requests(project, options={}) + def merge_requests(project, options = {}) get("/projects/#{url_encode project}/merge_requests", query: options) end @@ -39,6 +41,18 @@ # @return ] + def merge_request_pipelines(project, id) + get("/projects/#{url_encode project}/merge_requests/#{id}/pipelines") end # Creates a merge request. @@ -58,7 +72,7 @@ # @option options [Integer] :target_project_id (optional) The target project ID. # @option options [String] :labels (optional) Labels as a comma-separated list. # @return [Gitlab::ObjectifiedHash] Information about created merge request. - def create_merge_request(project, title, options={}) + def create_merge_request(project, title, options = {}) body = { title: title }.merge(options) post("/projects/#{url_encode project}/merge_requests", body: body) end @@ -77,7 +91,7 @@ # @option options [Integer] :assignee_id The ID of a user to assign merge request. # @option options [String] :state_event New state (close|reopen|merge). # @return [Gitlab::ObjectifiedHash] Information about updated merge request. - def update_merge_request(project, id, options={}) + def update_merge_request(project, id, options = {}) put("/projects/#{url_encode project}/merge_requests/#{id}", body: options) end @@ -91,7 +105,7 @@ # @param [Hash] options A customizable set of options. # @option options [String] :merge_commit_message Custom merge commit message # @return [Gitlab::ObjectifiedHash] Information about updated merge request. - def accept_merge_request(project, id, options={}) + def accept_merge_request(project, id, options = {}) put("/projects/#{url_encode project}/merge_requests/#{id}/merge", body: options) end @@ -205,7 +219,7 @@ # * :x (Integer) X coordinate (for 'image' diff notes) # * :y (Integer) Y coordinate (for 'image' diff notes) # @return [Gitlab::ObjectifiedHash] The created merge request discussion. - def create_merge_request_discussion(project, merge_request_id, options={}) + def create_merge_request_discussion(project, merge_request_id, options = {}) post("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions", body: options) end @@ -271,5 +285,30 @@ def delete_merge_request_discussion_note(project, merge_request_id, discussion_id, note_id) delete("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}/notes/#{note_id}") end + + # Gets a list of merge request diff versions + # + # @example + # Gitlab.merge_request_versions(5, 1) + # Gitlab.merge_request_versions('gitlab', 1) + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of a merge request. + # @return [Gitlab::ObjectifiedHash] A list of the merge request versions. + def merge_request_diff_versions(project, merge_request_id) + get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions") + end + + # Gets the diff a single merge request diff version\ + # + # @example + # Gitlab.merge_request_diff_version(5, 1, 1) + # Gitlab.merge_request_diff_version('gitlab', 1, 1) + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of a merge request. + # @param [Integer] id The ID of a merge request diff version. + # @return [Gitlab::ObjectifiedHash] Record of the specific diff + def merge_request_diff_version(project, merge_request_id, version_id) + get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions/#{version_id}") + end end end diff --git a/lib/gitlab/client/milestones.rb b/lib/gitlab/client/milestones.rb index ab8a4dd..cc2872f 100644 --- a/lib/gitlab/client/milestones.rb +++ b/lib/gitlab/client/milestones.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to milestones. # @see https://docs.gitlab.com/ce/api/milestones.html @@ -12,7 +14,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def milestones(project, options={}) + def milestones(project, options = {}) get("/projects/#{url_encode project}/milestones", query: options) end @@ -38,7 +40,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def milestone_issues(project, milestone, options={}) + def milestone_issues(project, milestone, options = {}) get("/projects/#{url_encode project}/milestones/#{milestone}/issues", query: options) end @@ -52,7 +54,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def milestone_merge_requests(project, milestone, options={}) + def milestone_merge_requests(project, milestone, options = {}) get("/projects/#{url_encode project}/milestones/#{milestone}/merge_requests", query: options) end @@ -67,7 +69,7 @@ # @option options [String] :description The description of a milestone. # @option options [String] :due_date The due date of a milestone. # @return [Gitlab::ObjectifiedHash] Information about created milestone. - def create_milestone(project, title, options={}) + def create_milestone(project, title, options = {}) body = { title: title }.merge(options) post("/projects/#{url_encode project}/milestones", body: body) end @@ -85,8 +87,20 @@ # @option options [String] :due_date The due date of a milestone. # @option options [String] :state_event The state of a milestone ('close' or 'activate'). # @return [Gitlab::ObjectifiedHash] Information about updated milestone. - def edit_milestone(project, id, options={}) + def edit_milestone(project, id, options = {}) put("/projects/#{url_encode project}/milestones/#{id}", body: options) + end + + # Delete a project milestone. + # + # @example + # Gitlab.delete_milestone(5, 2) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] id The ID of a milestone. + # @return [nil] This API call returns an empty response body. + def delete_milestone(project, id) + delete("/projects/#{url_encode project}/milestones/#{id}") end end end diff --git a/lib/gitlab/client/namespaces.rb b/lib/gitlab/client/namespaces.rb index 1979ce6..7a28c71 100644 --- a/lib/gitlab/client/namespaces.rb +++ b/lib/gitlab/client/namespaces.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to namespaces # @see https://docs.gitlab.com/ce/api/namespaces.html @@ -13,8 +15,8 @@ # @options options [Integer] :per_page The number of results per page. # @options opttion [String] :search The string to search for. # @return [Array] - def namespaces(options={}) - get("/namespaces", query: options) + def namespaces(options = {}) + get('/namespaces', query: options) end end end diff --git a/lib/gitlab/client/notes.rb b/lib/gitlab/client/notes.rb index 68c99be..f6450e7 100644 --- a/lib/gitlab/client/notes.rb +++ b/lib/gitlab/client/notes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to notes. # @see https://docs.gitlab.com/ce/api/notes.html @@ -11,7 +13,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def notes(project, options={}) + def notes(project, options = {}) get("/projects/#{url_encode project}/notes", query: options) end @@ -25,7 +27,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def issue_notes(project, issue, options={}) + def issue_notes(project, issue, options = {}) get("/projects/#{url_encode project}/issues/#{issue}/notes", query: options) end @@ -39,7 +41,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def snippet_notes(project, snippet, options={}) + def snippet_notes(project, snippet, options = {}) get("/projects/#{url_encode project}/snippets/#{snippet}/notes", query: options) end @@ -53,10 +55,10 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def merge_request_notes(project, merge_request, options={}) + def merge_request_notes(project, merge_request, options = {}) get("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes", query: options) end - alias_method :merge_request_comments, :merge_request_notes + alias merge_request_comments merge_request_notes # Gets a single wall note. # @@ -158,7 +160,7 @@ def create_merge_request_note(project, merge_request, body) post("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes", body: { body: body }) end - alias_method :create_merge_request_comment, :create_merge_request_note + alias create_merge_request_comment create_merge_request_note # Deletes a wall note. # @@ -210,7 +212,7 @@ def delete_merge_request_note(project, merge_request, id) delete("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes/#{id}") end - alias_method :delete_merge_request_comment, :delete_merge_request_note + alias delete_merge_request_comment delete_merge_request_note # Modifies a wall note. # @@ -266,7 +268,7 @@ def edit_merge_request_note(project, merge_request, id, body) put("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes/#{id}", body: note_content(body)) end - alias_method :edit_merge_request_comment, :edit_merge_request_note + alias edit_merge_request_comment edit_merge_request_note private @@ -274,7 +276,7 @@ # in the 'else'. def note_content(body) if body.is_a?(Hash) - STDERR.puts "Passing the note body as a Hash is deprecated. You should just pass the String." + STDERR.puts 'Passing the note body as a Hash is deprecated. You should just pass the String.' body else { body: body } diff --git a/lib/gitlab/client/pipeline_schedules.rb b/lib/gitlab/client/pipeline_schedules.rb index d212be8..9e9fe1e 100644 --- a/lib/gitlab/client/pipeline_schedules.rb +++ b/lib/gitlab/client/pipeline_schedules.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to pipeline schedules. # @see https://docs.gitlab.com/ce/api/pipeline_schedules.html @@ -12,7 +14,7 @@ # @param [Hash] options A customizable set of options. # @options options [String] :scope The scope of pipeline schedules, one of a 'active' or 'inactive'. # @return [Array] - def pipeline_schedules(project, options={}) + def pipeline_schedules(project, options = {}) get("/projects/#{url_encode project}/pipeline_schedules", query: options) end @@ -41,7 +43,7 @@ # @option options [String] :cron_timezone The timezone supproted by ActiveSupport::TimeZone (e.g. Pacific Time (US & Canada)) (default: 'UTC'). # @option options [Boolean] :active The activation of pipeline schedule. If false is set, the pipeline schedule will deactivated initially (default: true). # @return [Array] - def create_pipeline_schedule(project, options={}) + def create_pipeline_schedule(project, options = {}) post("/projects/#{url_encode project}/pipeline_schedules", query: options) end @@ -59,7 +61,7 @@ # @option options [String] :cron_timezone The timezone supproted by ActiveSupport::TimeZone (e.g. Pacific Time (US & Canada)) (default: 'UTC'). # @option options [Boolean] :active The activation of pipeline schedule. If false is set, the pipeline schedule will deactivated initially (default: true). # @return [Array] The updated pipeline schedule. - def edit_pipeline_schedule(project, pipeline_schedule_id, options={}) + def edit_pipeline_schedule(project, pipeline_schedule_id, options = {}) put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}", query: options) end @@ -98,7 +100,7 @@ # @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. # @option options [String] :value The value of a variable # @return [Array] The created pipeline schedule variable. - def create_pipeline_schedule_variable(project, pipeline_schedule_id, options={}) + def create_pipeline_schedule_variable(project, pipeline_schedule_id, options = {}) post("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables", query: options) end @@ -113,7 +115,7 @@ # @param [Hash] options A customizable set of options. # @option options [String] :value The value of a variable. # @return [Array] The updated pipeline schedule variable. - def edit_pipeline_schedule_variable(project, pipeline_schedule_id, key, options={}) + def edit_pipeline_schedule_variable(project, pipeline_schedule_id, key, options = {}) put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables/#{url_encode key}", query: options) end @@ -126,7 +128,7 @@ # @param [Integer] The pipeline schedule ID. # @param [String] The key of a variable. # @return [Array] The deleted pipeline schedule variable. - def delete_pipeline_schedule_variable(project, pipeline_schedule_id, key, options={}) + def delete_pipeline_schedule_variable(project, pipeline_schedule_id, key, _options = {}) delete("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables/#{url_encode key}") end end diff --git a/lib/gitlab/client/pipeline_triggers.rb b/lib/gitlab/client/pipeline_triggers.rb index cdb3ba3..d97099a 100644 --- a/lib/gitlab/client/pipeline_triggers.rb +++ b/lib/gitlab/client/pipeline_triggers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to pipelines. # @see https://docs.gitlab.com/ce/api/pipeline_triggers.html @@ -35,7 +37,7 @@ # @param [String] description The trigger name # @return [Gitlab::ObjectifiedHash] The created trigger. def create_trigger(project, description) - post("/projects/#{url_encode project}/triggers", body: {description: description}) + post("/projects/#{url_encode project}/triggers", body: { description: description }) end # Update a project trigger @@ -48,7 +50,7 @@ # @param [Hash] options A customizable set of options. # @option options [String] :description The trigger name. # @return [Gitlab::ObjectifiedHash] The updated trigger. - def update_trigger(project, trigger_id, options={}) + def update_trigger(project, trigger_id, options = {}) put("/projects/#{url_encode project}/triggers/#{trigger_id}", body: options) end @@ -75,7 +77,7 @@ def remove_trigger(project, trigger_id) delete("/projects/#{url_encode project}/triggers/#{trigger_id}") end - alias_method :delete_trigger, :remove_trigger + alias delete_trigger remove_trigger # Run the given project pipeline trigger. # @@ -90,12 +92,12 @@ # @param [String] ref Branch or tag name to build. # @param [Hash] variables A set of build variables to use for the build. (optional) # @return [Gitlab::ObjectifiedHash] The trigger. - def run_trigger(project, token, ref, variables={}) + def run_trigger(project, token, ref, variables = {}) post("/projects/#{url_encode project}/trigger/pipeline", unauthenticated: true, body: { - token: token, - ref: ref, - variables: variables - }) + token: token, + ref: ref, + variables: variables + }) end end end diff --git a/lib/gitlab/client/pipelines.rb b/lib/gitlab/client/pipelines.rb index fb140f3..3222d58 100644 --- a/lib/gitlab/client/pipelines.rb +++ b/lib/gitlab/client/pipelines.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to pipelines. # @see https://docs.gitlab.com/ce/api/pipelines.html @@ -13,7 +15,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def pipelines(project, options={}) + def pipelines(project, options = {}) get("/projects/#{url_encode project}/pipelines", query: options) end @@ -36,9 +38,20 @@ # # @param [Integer, String] project The ID or name of a project. # @param [String] ref Reference to commit. + # @param [Hash] variables Variables passed to pipelines # @return [Gitlab::ObjectifiedHash] The pipelines changes. - def create_pipeline(project, ref) - post("/projects/#{url_encode project}/pipeline?ref=#{ref}") + def create_pipeline(project, ref, variables = {}) + body = {} + + # This mapping is necessary, cause the API expects an array with objects (with `key` and `value` keys) + # See: https://docs.gitlab.com/ee/api/pipelines.html#create-a-new-pipeline + body[:variables] = variables.map { |(key, value)| { key: key, value: value } } if variables.any? + + post( + "/projects/#{url_encode project}/pipeline", + query: { ref: ref }, + body: body + ) end # Cancels a pipeline. diff --git a/lib/gitlab/client/project_badges.rb b/lib/gitlab/client/project_badges.rb new file mode 100644 index 0000000..00038c2 --- /dev/null +++ b/lib/gitlab/client/project_badges.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +class Gitlab::Client + # Defines methods related to project badges. + # @see https://docs.gitlab.com/ee/api/project_badges.html + module ProjectBadges + # Gets a list of a projects badges and its group badges. + # + # @example + # Gitlab.project_badges(5) + # + # @param [Integer, String] project The ID or name of a project. + # @return [Array] List of all badges of a project + def project_badges(project) + get("/projects/#{url_encode project}/badges") + end + + # Gets a badge of a project. + # + # @example + # Gitlab.project_badge(5, 42) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] badge_id The badge ID. + # @return [Gitlab::ObjectifiedHash] Information about the requested badge + def project_badge(project, badge_id) + get("/projects/#{url_encode project}/badges/#{badge_id}") + end + + # Adds a badge to a project. + # + # @example + # Gitlab.add_project_badge(5, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' }) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Hash] options A customizable set of options. + # @option options [String] :link_url(required) URL of the badge link + # @option options [String] :image_url(required) URL of the badge image + # @return [Gitlab::ObjectifiedHash] Information about the added project badge. + def add_project_badge(project, options = {}) + post("/projects/#{url_encode project}/badges", body: options) + end + + # Updates a badge of a project.. + # + # @example + # Gitlab.edit_project_badge(5, 1, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' }) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] badge_id The badge ID. + # @param [Hash] options A customizable set of options. + # @option options [String] :link_url(optional) URL of the badge link + # @option options [String] :image_url(optional) URL of the badge image + # @return [Gitlab::ObjectifiedHash] Information about the updated project badge. + def edit_project_badge(project, badge_id, options = {}) + put("/projects/#{url_encode project}/badges/#{badge_id}", body: options) + end + + # Removes a badge from a project. Only projects badges will be removed by using this endpoint. + # + # @example + # Gitlab.remove_project_badge(5, 42) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Integer] badge_id The badge ID. + # @return [nil] This API call returns an empty response body. + def remove_project_badge(project, badge_id) + delete("/projects/#{url_encode project}/badges/#{badge_id}") + end + + # Preview a badge from a project. + # + # @example + # Gitlab.preview_project_badge(3, 'https://abc.com/gitlab/gitlab-ce/commits/master', 'https://shields.io/my/badge1') + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] :link_url URL of the badge link + # @param [String] :image_url URL of the badge image + # @return [Gitlab::ObjectifiedHash] Returns how the link_url and image_url final URLs would be after resolving the placeholder interpolation. + def preview_project_badge(project, link_url, image_url) + query = { link_url: link_url, image_url: image_url } + get("/projects/#{url_encode project}/badges/render", query: query) + end + end +end diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index 9c062e5..340dcce 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to projects. # @see https://docs.gitlab.com/ce/api/projects.html @@ -13,8 +15,8 @@ # (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) # # @return [Array] - def projects(options={}) - get("/projects", query: options) + def projects(options = {}) + get('/projects', query: options) end # Search for projects by name. @@ -30,10 +32,10 @@ # @option options [String] :order_by Return requests ordered by id, name, created_at or last_activity_at fields # @option options [String] :sort Return requests sorted in asc or desc order # @return [Array] - def project_search(query, options={}) - get("/projects", query: options.merge(search:query)) - end - alias_method :search_projects, :project_search + def project_search(query, options = {}) + get('/projects', query: options.merge(search: query)) + end + alias search_projects project_search # Gets information about a project. # @@ -68,8 +70,8 @@ # @option options [Boolean] :public The setting for making a project public (0 = false, 1 = true). # @option options [Integer] :user_id The user/owner id of a project. # @return [Gitlab::ObjectifiedHash] Information about created project. - def create_project(name, options={}) - url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : "/projects" + def create_project(name, options = {}) + url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : '/projects' post(url, body: { name: name }.merge(options)) end @@ -96,7 +98,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def team_members(project, options={}) + def team_members(project, options = {}) get("/projects/#{url_encode project}/members", query: options) end @@ -116,28 +118,34 @@ # # @example # Gitlab.add_team_member('gitlab', 2, 40) + # Gitlab.add_team_member('gitlab', 2, 40, { expires_at: "2018-12-31"}) # # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a user. # @param [Integer] access_level The access level to project. # @param [Hash] options A customizable set of options. + # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY. # @return [Gitlab::ObjectifiedHash] Information about added team member. - def add_team_member(project, id, access_level) - post("/projects/#{url_encode project}/members", body: { user_id: id, access_level: access_level }) + def add_team_member(project, id, access_level, options = {}) + body = { user_id: id, access_level: access_level }.merge(options) + post("/projects/#{url_encode project}/members", body: body) end # Updates a team member's project access level. # # @example # Gitlab.edit_team_member('gitlab', 3, 20) + # Gitlab.edit_team_member('gitlab', 3, 20, { expires_at: "2018-12-31"}) # # @param [Integer, String] project The ID or path of a project. # @param [Integer] id The ID of a user. # @param [Integer] access_level The access level to project. # @param [Hash] options A customizable set of options. + # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY. # @return [Array] Information about updated team member. - def edit_team_member(project, id, access_level) - put("/projects/#{url_encode project}/members/#{id}", body: { access_level: access_level }) + def edit_team_member(project, id, access_level, options = {}) + body = { access_level: access_level }.merge(options) + put("/projects/#{url_encode project}/members/#{id}", body: body) end # Removes a user from project team. @@ -164,7 +172,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def project_hooks(project, options={}) + def project_hooks(project, options = {}) get("/projects/#{url_encode project}/hooks", query: options) end @@ -194,7 +202,7 @@ # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true) # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true) # @return [Gitlab::ObjectifiedHash] Information about added hook. - def add_project_hook(project, url, options={}) + def add_project_hook(project, url, options = {}) body = { url: url }.merge(options) post("/projects/#{url_encode project}/hooks", body: body) end @@ -213,7 +221,7 @@ # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true) # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true) # @return [Gitlab::ObjectifiedHash] Information about updated hook. - def edit_project_hook(project, id, url, options={}) + def edit_project_hook(project, id, url, options = {}) body = { url: url }.merge(options) put("/projects/#{url_encode project}/hooks/#{id}", body: body) end @@ -253,7 +261,7 @@ # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true) # @param option [String] :commit_message_regex Commit message regex # @return [Gitlab::ObjectifiedHash] Information about added push rule. - def add_push_rule(id, options={}) + def add_push_rule(id, options = {}) post("/projects/#{url_encode id}/push_rule", body: options) end @@ -268,7 +276,7 @@ # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true) # @param option [String] :commit_message_regex Commit message regex # @return [Gitlab::ObjectifiedHash] Information about updated push rule. - def edit_push_rule(id, options={}) + def edit_push_rule(id, options = {}) put("/projects/#{url_encode id}/push_rule", body: options) end @@ -318,7 +326,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def deploy_keys(project, options={}) + def deploy_keys(project, options = {}) get("/projects/#{url_encode project}/deploy_keys", query: options) end @@ -394,7 +402,7 @@ # @param [Hash] options A customizable set of options. # @option options [String] :sudo The username the project will be forked for # @return [Gitlab::ObjectifiedHash] Information about the forked project. - def create_fork(id, options={}) + def create_fork(id, options = {}) post("/projects/#{url_encode id}/fork", body: options) end @@ -412,7 +420,7 @@ # @option options [String] :order_by Return requests ordered by id, name, created_at or last_activity_at fields # @option options [String] :sort Return requests sorted in asc or desc order # @return [Array] - def project_forks(id, options={}) + def project_forks(id, options = {}) get("/projects/#{url_encode id}/forks", query: options) end @@ -431,7 +439,7 @@ # (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) # # @return [Gitlab::ObjectifiedHash] Information about the edited project. - def edit_project(id, options={}) + def edit_project(id, options = {}) put("/projects/#{url_encode id}", body: options) end @@ -459,6 +467,18 @@ delete("/projects/#{url_encode project}/share/#{id}") end + # Transfer a project to a new namespace. + # + # @example + # Gitlab.transfer_project(42, 'yolo') + # + # @param [Integer, String] project The ID or path of a project + # @param [Integer, String] namespace The ID or path of the namespace to transfer to project to + # @return [Gitlab::ObjectifiedHash] Information about transfered project. + def transfer_project(project, namespace) + put("/projects/#{url_encode project}/transfer", body: { namespace: namespace }) + end + # Stars a project. # @see https://docs.gitlab.com/ce/api/projects.html#star-a-project # @@ -500,8 +520,55 @@ # @option options [String] :order_by Return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields. # @option options [String] :sort Return projects sorted in asc or desc order. # @return [Array] - def user_projects(user_id, options={}) + def user_projects(user_id, options = {}) get("/users/#{url_encode user_id}/projects", query: options) + end + + # Uploads a file to the specified project to be used in an issue or + # merge request description, or a comment. + # @see https://docs.gitlab.com/ee/api/projects.html#upload-a-file + # + # @example + # Gitlab.upload_file(1, File.open(File::NULL, 'r')) + # File.open('myfile') { |file| Gitlab.upload_file(1, file) } + # + # @param [Integer, String] id The ID or path of a project. + # @param [File] The file you are interested to upload. + # @return [Gitlab::ObjectifiedHash] + def upload_file(id, file) + post("/projects/#{url_encode id}/uploads", body: { file: file }) + end + + # Get all project templates of a particular type + # @see https://docs.gitlab.com/ce/api/project_templates.html + # + # @example + # Gitlab.project_templates(1, 'dockerfiles') + # Gitlab.project_templates(1, 'licenses') + # + # @param [Integer, String] id The ID or URL-encoded path of the project. + # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template + # @return [Array] + def project_templates(project, type) + get("/projects/#{url_encode project}/templates/#{type}") + end + + # Get one project template of a particular type + # @see https://docs.gitlab.com/ce/api/project_templates.html + # + # @example + # Gitlab.project_template(1, 'dockerfiles', 'dockey') + # Gitlab.project_template(1, 'licenses', 'gpl', { project: 'some project', fullname: 'Holder Holding' }) + # + # @param [Integer, String] project The ID or URL-encoded path of the project. + # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template + # @param [String] key The key of the template, as obtained from the collection endpoint + # @param [Hash] options A customizable set of options. + # @option options [String] project(optional) The project name to use when expanding placeholders in the template. Only affects licenses + # @option options [String] fullname(optional) The full name of the copyright holder to use when expanding placeholders in the template. Only affects licenses + # @return [Gitlab::ObjectifiedHash] + def project_template(project, type, key, options = {}) + get("/projects/#{url_encode project}/templates/#{type}/#{key}", query: options) end end end diff --git a/lib/gitlab/client/protected_tags.rb b/lib/gitlab/client/protected_tags.rb new file mode 100644 index 0000000..d8410c8 --- /dev/null +++ b/lib/gitlab/client/protected_tags.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +class Gitlab::Client + # Defines methods related to Protected Tags. + # @see https://docs.gitlab.com/ce/api/protected_tags.html + module ProtectedTags + # Gets a list of protected tags from a project + # + # @example + # Gitlab.protected_tags(1) + # + # @param [Integer, String] project(required) The ID or name of a project. + # @option options [Integer] :page The page number. + # @option options [Integer] :per_page The number of results per page. + # @return [Array] List of all protected tags requested + def protected_tags(project, options = {}) + get("/projects/#{url_encode project}/protected_tags", query: options) + end + + # Gets a single protected tag or wildcard protected tag. + # + # @example + # Gitlab.protected_tag(1, 'release-1-0') + # + # @param [Integer, String] project(required) The ID or name of a project. + # @param [String] name(required) The name of the tag or wildcard + # @return ] def runners(options = {}) - get("/runners", query: options) + get('/runners', query: options) end # Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges. @@ -28,7 +29,7 @@ # @option options [String] :scope The scope of runners to show, one of: specific, shared, active, paused, online; showing all runners if none provided # @return [Array] def all_runners(options = {}) - get("/runners/all", query: options) + get('/runners/all', query: options) end # Get details of a runner.. @@ -56,7 +57,7 @@ # @option options [String] :active The state of a runner; can be set to true or false. # @option options [String] :tag_list The list of tags for a runner; put array of tags, that should be finally assigned to a runner # @return - def update_runner(id, options={}) + def update_runner(id, options = {}) put("/runners/#{id}", query: options) end @@ -121,6 +122,5 @@ def project_disable_runner(id, runner_id) delete("/projects/#{url_encode id}/runners/#{runner_id}") end - end end diff --git a/lib/gitlab/client/services.rb b/lib/gitlab/client/services.rb index 81bf940..fd47c94 100644 --- a/lib/gitlab/client/services.rb +++ b/lib/gitlab/client/services.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Third party services connected to a project. # @see https://docs.gitlab.com/ce/api/services.html @@ -43,8 +45,9 @@ end private + def correct_service_name(service) - service.to_s.gsub('_', '-') + service.to_s.tr('_', '-') end end end diff --git a/lib/gitlab/client/sidekiq.rb b/lib/gitlab/client/sidekiq.rb index 8c82f86..51dcfb5 100644 --- a/lib/gitlab/client/sidekiq.rb +++ b/lib/gitlab/client/sidekiq.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to sidekiq metrics. # @see https://docs.gitlab.com/ce/api/sidekiq_metrics.html diff --git a/lib/gitlab/client/snippets.rb b/lib/gitlab/client/snippets.rb index 7ae33e4..f14d80a 100644 --- a/lib/gitlab/client/snippets.rb +++ b/lib/gitlab/client/snippets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to snippets. # @see https://docs.gitlab.com/ce/api/project_snippets.html @@ -12,7 +14,7 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Gitlab::ObjectifiedHash] - def snippets(project, options={}) + def snippets(project, options = {}) get("/projects/#{url_encode project}/snippets", query: options) end @@ -41,7 +43,7 @@ # @option options [String] :lifetime (optional) The expiration date of a snippet. # @option options [String] :visibility (required) The visibility of a snippet # @return [Gitlab::ObjectifiedHash] Information about created snippet. - def create_snippet(project, options={}) + def create_snippet(project, options = {}) post("/projects/#{url_encode project}/snippets", body: options) end @@ -59,7 +61,7 @@ # @option options [String] :lifetime The expiration date of a snippet. # @option options [String] :visibility (optional) The visibility of a snippet # @return [Gitlab::ObjectifiedHash] Information about updated snippet. - def edit_snippet(project, id, options={}) + def edit_snippet(project, id, options = {}) put("/projects/#{url_encode project}/snippets/#{id}", body: options) end diff --git a/lib/gitlab/client/system_hooks.rb b/lib/gitlab/client/system_hooks.rb index 35896b3..d36d437 100644 --- a/lib/gitlab/client/system_hooks.rb +++ b/lib/gitlab/client/system_hooks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to system hooks. # @see https://docs.gitlab.com/ce/api/system_hooks.html @@ -12,10 +14,10 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def hooks(options={}) - get("/hooks", query: options) + def hooks(options = {}) + get('/hooks', query: options) end - alias_method :system_hooks, :hooks + alias system_hooks hooks # Adds a new system hook. # @@ -29,9 +31,9 @@ # @option options [boolean] :enable_ssl_verification `false` will cause Gitlab to ignore invalid/unsigned certificate errors (default is `true`) # @return [Gitlab::ObjectifiedHash] def add_hook(url, options = {}) - post("/hooks", body: options.merge(url: url)) + post('/hooks', body: options.merge(url: url)) end - alias_method :add_system_hook, :add_hook + alias add_system_hook add_hook # Tests a system hook. # @@ -44,7 +46,7 @@ def hook(id) get("/hooks/#{id}") end - alias_method :system_hook, :hook + alias system_hook hook # Deletes a new system hook. # @@ -57,6 +59,6 @@ def delete_hook(id) delete("/hooks/#{id}") end - alias_method :delete_system_hook, :delete_hook + alias delete_system_hook delete_hook end end diff --git a/lib/gitlab/client/tags.rb b/lib/gitlab/client/tags.rb index faeb719..c15ac8b 100644 --- a/lib/gitlab/client/tags.rb +++ b/lib/gitlab/client/tags.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to tags. # @see https://docs.gitlab.com/ce/api/tags.html @@ -12,10 +14,10 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def tags(project, options={}) + def tags(project, options = {}) get("/projects/#{url_encode project}/repository/tags", query: options) end - alias_method :repo_tags, :tags + alias repo_tags tags # Creates a new project repository tag. # @@ -29,10 +31,10 @@ # @param [String] message Optional message for tag, creates annotated tag if specified. # @param [String] description Optional release notes for tag. # @return [Gitlab::ObjectifiedHash] - def create_tag(project, tag_name, ref, message='', description=nil) + def create_tag(project, tag_name, ref, message = '', description = nil) post("/projects/#{url_encode project}/repository/tags", body: { tag_name: tag_name, ref: ref, message: message, release_description: description }) end - alias_method :repo_create_tag, :create_tag + alias repo_create_tag create_tag # Gets information about a repository tag. # @@ -46,7 +48,7 @@ def tag(project, tag) get("/projects/#{url_encode project}/repository/tags/#{url_encode tag}") end - alias_method :repo_tag, :tag + alias repo_tag tag # Deletes a repository tag. Requires Gitlab >= 6.8.x # @@ -60,7 +62,7 @@ def delete_tag(project, tag) delete("/projects/#{url_encode project}/repository/tags/#{url_encode tag}") end - alias_method :repo_delete_tag, :delete_tag + alias repo_delete_tag delete_tag # Adds release notes to an existing repository tag. Requires Gitlab >= 8.2.0 # @@ -75,7 +77,7 @@ def create_release(project, tag, description) post("/projects/#{url_encode project}/repository/tags/#{url_encode tag}/release", body: { description: description }) end - alias_method :repo_create_release, :create_release + alias repo_create_release create_release # Updates the release notes of a given release. Requires Gitlab >= 8.2.0 # @@ -90,7 +92,6 @@ def update_release(project, tag, description) put("/projects/#{url_encode project}/repository/tags/#{url_encode tag}/release", body: { description: description }) end - alias_method :repo_update_release, :update_release - + alias repo_update_release update_release end end diff --git a/lib/gitlab/client/templates.rb b/lib/gitlab/client/templates.rb new file mode 100644 index 0000000..6fcef9d --- /dev/null +++ b/lib/gitlab/client/templates.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +class Gitlab::Client + # Defines methods related to templates. + # @see https://docs.gitlab.com/ce/api/templates/dockerfiles.html + # @see https://docs.gitlab.com/ce/api/templates/gitignores.html + # @see https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html + # @see https://docs.gitlab.com/ce/api/templates/licenses.html + module Templates + # Get all Dockerfile templates. + # + # @example + # Gitlab.dockerfile_templates + # + # @return [Array] + def dockerfile_templates + get('/templates/dockerfiles') + end + + # Get a single Dockerfile template. + # + # @example + # Gitlab.dockerfile_template('Binary') + # + # @param [String] key The key of the Dockerfile template + # @return [Gitlab::ObjectifiedHash] + def dockerfile_template(key) + get("/templates/dockerfiles/#{key}") + end + + # Get all gitignore templates. + # + # @example + # Gitlab.gitignore_templates + # + # @return [Array] + def gitignore_templates + get('/templates/gitignores') + end + + # Get a single gitignore template. + # + # @example + # Gitlab.gitignore_template('Ruby') + # + # @param [String] key The key of the gitignore template + # @return [Gitlab::ObjectifiedHash] + def gitignore_template(key) + get("/templates/gitignores/#{key}") + end + + # Get all `gitlab_ci.yml` templates. + # + # @example + # Gitlab.gitlab_ci_yml_templates + # + # @return [Array] + def gitlab_ci_yml_templates + get('/templates/gitlab_ci_ymls') + end + + # Get a single `gitlab_ci.yml` template. + # + # @example + # Gitlab.gitlab_ci_yml_template('Ruby') + # + # @param [String] key The key of the gitlab_ci_yml template + # @return [Gitlab::ObjectifiedHash] + def gitlab_ci_yml_template(key) + get("/templates/gitlab_ci_ymls/#{key}") + end + + # Get all license templates. + # + # @example + # Gitlab.license_templates + # Gitlab.license_templates(popular: true) + # + # @param [Hash] options A customizable set of options. + # @option options [Boolean] popular(optional) If passed, returns only popular licenses. + # @return [Array] + def license_templates(options = {}) + get('/templates/licenses', query: options) + end + + # Get a single license template. You can pass parameters to replace the license placeholder. + # + # @example + # Gitlab.license_template('Ruby') + # + # @param [String] key The key of the license template + # @param [Hash] options A customizable set of options. + # @option options [String] project(optional) The copyrighted project name. + # @option options [String] fullname(optional) The full-name of the copyright holder + # @return [Gitlab::ObjectifiedHash] + def license_template(key, options = {}) + get("/templates/licenses/#{key}", query: options) + end + end +end diff --git a/lib/gitlab/client/todos.rb b/lib/gitlab/client/todos.rb index ee71766..3a60d2c 100644 --- a/lib/gitlab/client/todos.rb +++ b/lib/gitlab/client/todos.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to todos - # @see https://docs.gitlab.com/ce/api/todos.html + # @see https://docs.gitlab.com/ce/api/todos.html module Todos # Gets a list of todos. # @@ -16,8 +18,8 @@ # @option options [Integer] :state The state of the todo. Can be either `pending` or `done` # @option options [Integer] :type The type of a todo. Can be either `Issue` or `MergeRequest` # @return [Array] - def todos(options={}) - get("/todos", query: options) + def todos(options = {}) + get('/todos', query: options) end # Marks a single pending todo for the current user as done. @@ -38,7 +40,7 @@ # # @return [void] This API call returns an empty response body. def mark_all_todos_as_done - post("/todos/mark_as_done") + post('/todos/mark_as_done') end end -end \ No newline at end of file +end diff --git a/lib/gitlab/client/users.rb b/lib/gitlab/client/users.rb index f6a3703..bc0c03a 100644 --- a/lib/gitlab/client/users.rb +++ b/lib/gitlab/client/users.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Gitlab::Client # Defines methods related to users. # @see https://docs.gitlab.com/ce/api/users.html @@ -12,8 +14,8 @@ # @option options [Integer] :page The page number. # @option options [Integer] :per_page The number of results per page. # @return [Array] - def users(options={}) - get("/users", query: options) + def users(options = {}) + get('/users', query: options) end # Gets information about a user. @@ -25,8 +27,8 @@ # # @param [Integer] id The ID of a user. # @return [Gitlab::ObjectifiedHash] - def user(id=nil) - id.to_i.zero? ? get("/user") : get("/users/#{id}") + def user(id = nil) + id.to_i.zero? ? get('/user') : get("/users/#{id}") end # Creates a new user. @@ -48,7 +50,7 @@ # @option options [Integer] :projects_limit The limit of projects for a user. # @return [Gitlab::ObjectifiedHash] Information about created user. def create_user(*args) - options = Hash === args.last ? args.pop : {} + options = args.last.is_a?(Hash) ? args.pop : {} body = if args[2] { email: args[0], password: args[1], username: args[2] } else @@ -73,7 +75,7 @@ # @option options [String] :twitter The twitter of a user. # @option options [Integer] :projects_limit The limit of projects for a user. # @return [Gitlab::ObjectifiedHash] Information about created user. - def edit_user(user_id, options={}) + def edit_user(user_id, options = {}) put("/users/#{user_id}", body: options) end @@ -120,7 +122,7 @@ # @return [Gitlab::ObjectifiedHash] # @note This method doesn't require private_token to be set. def session(email, password) - post("/session", body: { email: email, password: password }, unauthenticated: true) + post('/session', body: { email: email, password: password }, unauthenticated: true) end # Gets a list of user's SSH keys. @@ -134,10 +136,10 @@ # @option options [Integer] :per_page The number of results per page. # @option options [Integer] :user_id The ID of the user to retrieve the keys for. # @return [Array] - def ssh_keys(options={}) + def ssh_keys(options = {}) user_id = options.delete :user_id if user_id.to_i.zero? - get("/user/keys", query: options) + get('/user/keys', query: options) else get("/users/#{user_id}/keys", query: options) end @@ -161,9 +163,16 @@ # # @param [String] title The title of an SSH key. # @param [String] key The SSH key body. + # @param [Hash] options A customizable set of options. + # @option options [Integer] :user_id id of the user to associate the key with # @return [Gitlab::ObjectifiedHash] Information about created SSH key. - def create_ssh_key(title, key) - post("/user/keys", body: { title: title, key: key }) + def create_ssh_key(title, key, options = {}) + user_id = options.delete :user_id + if user_id.to_i.zero? + post('/user/keys', body: { title: title, key: key }) + else + post("/users/#{user_id}/keys", body: { title: title, key: key }) + end end # Deletes an SSH key. @@ -172,9 +181,16 @@ # Gitlab.delete_ssh_key(1) # # @param [Integer] id The ID of a user's SSH key. + # @param [Hash] options A customizable set of options. + # @option options [Integer] :user_id id of the user to associate the key with # @return [Gitlab::ObjectifiedHash] Information about deleted SSH key. - def delete_ssh_key(id) - delete("/user/keys/#{id}") + def delete_ssh_key(id, options = {}) + user_id = options.delete :user_id + if user_id.to_i.zero? + delete("/user/keys/#{id}") + else + delete("/users/#{user_id}/keys/#{id}") + end end # Gets user emails. @@ -186,8 +202,8 @@ # # @param [Integer] user_id The ID of a user. # @return [Gitlab::ObjectifiedHash] - def emails(user_id=nil) - url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails" + def emails(user_id = nil) + url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails" get(url) end @@ -212,9 +228,9 @@ # @param [String] email Email address # @param [Integer] user_id The ID of a user. # @return [Gitlab::ObjectifiedHash] - def add_email(email, user_id=nil) - url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails" - post(url, body: {email: email}) + def add_email(email, user_id = nil) + url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails" + post(url, body: { email: email }) end # Delete email @@ -227,7 +243,7 @@ # @param [Integer] id Email address ID # @param [Integer] user_id The ID of a user. # @return [Boolean] - def delete_email(id, user_id=nil) + def delete_email(id, user_id = nil) url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}" delete(url) end @@ -242,9 +258,9 @@ # @option options [String] :per_page Number of user to return per page # @option options [String] :page The page to retrieve # @return [Array] - def user_search(search, options={}) + def user_search(search, options = {}) options[:search] = search - get("/users", query: options) + get('/users', query: options) end end end diff --git a/lib/gitlab/client/versions.rb b/lib/gitlab/client/versions.rb new file mode 100644 index 0000000..fb11ab1 --- /dev/null +++ b/lib/gitlab/client/versions.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class Gitlab::Client + # Defines methods related to version + # @see https://docs.gitlab.com/ce/api/version.html + module Versions + # Returns server version. + # @see https://docs.gitlab.com/ce/api/version.html + # + # @example + # Gitlab.version + # + # @return [Array] + def version + get('/version') + end + end +end diff --git a/lib/gitlab/client/wikis.rb b/lib/gitlab/client/wikis.rb new file mode 100644 index 0000000..2f617d1 --- /dev/null +++ b/lib/gitlab/client/wikis.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +class Gitlab::Client + # Defines methods related to wikis. + # @see https://docs.gitlab.com/ce/api/wikis.html + module Wikis + # Get all wiki pages for a given project. + # + # @example + # Gitlab.wikis(3) + # Gitlab.wikis(3, {with_content: 'Some wiki content'}) + # + # @param [Integer, String] project The ID or name of a project. + # @param [Hash] options A customizable set of options. + # @option options [String] with_content(optional) Include pages content + # @return [Array] + def wikis(project, options = {}) + get("/projects/#{url_encode project}/wikis", query: options) + end + + # Get a wiki page for a given project. + # + # @example + # Gitlab.wiki(3, 'home') + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] slug The slug (a unique string) of the wiki page + # @return [Gitlab::ObjectifiedHash] + def wiki(project, slug) + get("/projects/#{url_encode project}/wikis/#{slug}") + end + + # Creates a new wiki page for the given repository with the given title, slug, and content. + # + # @example + # Gitlab.create_wiki(3, 'Some Title', 'Some Content') + # Gitlab.create_wiki(3, 'Some Title', 'Some Content', { format: 'rdoc' }) + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] content The content of the wiki page. + # @param [String] title The title of the wiki page. + # @param [Hash] options A customizable set of options. + # @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc. + # @return [Gitlab::ObjectifiedHash] Information about created wiki page. + def create_wiki(project, title, content, options = {}) + body = { content: content, title: title }.merge(options) + post("/projects/#{url_encode project}/wikis", body: body) + end + + # Updates an existing wiki page. At least one parameter is required to update the wiki page. + # + # @example + # Gitlab.update_wiki(6, 'home', { title: 'New title' }) + # Gitlab.update_wiki(6, 'home', { title: 'New title', content: 'New Message', format: 'rdoc' }) + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] slug The slug (a unique string) of the wiki page. + # @param [Hash] options A customizable set of options. + # @option options [String] content The content of the wiki page. + # @option options [String] title The title of the wiki page. + # @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc. + # @return [Gitlab::ObjectifiedHash] Information about updated wiki page. + def update_wiki(project, slug, options = {}) + put("/projects/#{url_encode project}/wikis/#{slug}", body: options) + end + + # Deletes a wiki page with a given slug. + # + # @example + # Gitlab.delete_wiki(42, 'foo') + # + # @param [Integer, String] project The ID or name of a project. + # @param [String] slug The slug (a unique string) of the wiki page. + # @return [Gitlab::ObjectifiedHash] An empty objectified hash + def delete_wiki(project, slug) + delete("/projects/#{url_encode project}/wikis/#{slug}") + end + end +end diff --git a/lib/gitlab/client.rb b/lib/gitlab/client.rb index f6f32dc..a0b52f1 100644 --- a/lib/gitlab/client.rb +++ b/lib/gitlab/client.rb @@ -1,13 +1,16 @@ +# frozen_string_literal: true + module Gitlab # Wrapper for the Gitlab REST API. class Client < API - Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f } + Dir[File.expand_path('client/*.rb', __dir__)].each { |f| require f } # Please keep in alphabetical order include AccessRequests include AwardEmojis include Boards include Branches + include BroadcastMessages include BuildVariables include Builds include Commits @@ -28,33 +31,35 @@ include PipelineSchedules include PipelineTriggers include Pipelines + include ProjectBadges include Projects + include ProtectedTags include Repositories include RepositoryFiles + include RepositorySubmodules include Runners include Services include Sidekiq include Snippets include SystemHooks include Tags + include Templates include Todos include Users + include Versions + include Wikis # Text representation of the client, masking private token. # # @return [String] def inspect inspected = super - - if @private_token - inspected = inspected.sub! @private_token, only_show_last_four_chars(@private_token) - end - + inspected.sub! @private_token, only_show_last_four_chars(@private_token) if @private_token inspected end - def url_encode(s) - URI.encode(s.to_s, /\W/) + def url_encode(url) + URI.encode(url.to_s, /\W/) end private diff --git a/lib/gitlab/configuration.rb b/lib/gitlab/configuration.rb index 50e723b..dbe6486 100644 --- a/lib/gitlab/configuration.rb +++ b/lib/gitlab/configuration.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + require 'gitlab/cli_helpers' module Gitlab # Defines constants and methods related to configuration. module Configuration # An array of valid keys in the options hash when configuring a Gitlab::API. - VALID_OPTIONS_KEYS = %i(endpoint private_token user_agent sudo httparty).freeze + VALID_OPTIONS_KEYS = %i[endpoint private_token user_agent sudo httparty].freeze # The user agent that will be sent to the API endpoint if none is set. - DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}".freeze + DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}" # @private attr_accessor(*VALID_OPTIONS_KEYS) # @private - alias_method :auth_token=, :private_token= + alias auth_token= private_token= # Sets all configuration options to their default values # when this module is extended. @@ -44,11 +46,11 @@ # Allows HTTParty config to be specified in ENV using YAML hash. def get_httparty_config(options) - return options if options.nil? + return if options.nil? httparty = Gitlab::CLI::Helpers.yaml_load(options) + raise ArgumentError, 'HTTParty config should be a Hash.' unless httparty.is_a? Hash - raise ArgumentError, 'HTTParty config should be a Hash.' unless httparty.is_a? Hash Gitlab::CLI::Helpers.symbolize_keys httparty end end diff --git a/lib/gitlab/error.rb b/lib/gitlab/error.rb index 19f9383..6fc048d 100644 --- a/lib/gitlab/error.rb +++ b/lib/gitlab/error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Error # Custom error class for rescuing from all Gitlab errors. @@ -11,7 +13,7 @@ # Custom error class for rescuing from HTTP response errors. class ResponseError < Error - POSSIBLE_MESSAGE_KEYS = %i(message error_description error) + POSSIBLE_MESSAGE_KEYS = %i[message error_description error].freeze def initialize(response) @response = response @@ -57,7 +59,7 @@ case message when Gitlab::ObjectifiedHash message.to_h.sort.map do |key, val| - "'#{key}' #{(val.is_a?(Hash) ? val.sort.map { |k, v| "(#{k}: #{v.join(' ')})" } : val).join(' ')}" + "'#{key}' #{(val.is_a?(Hash) ? val.sort.map { |k, v| "(#{k}: #{v.join(' ')})" } : [val].flatten).join(' ')}" end.join(', ') when Array message.join(' ') diff --git a/lib/gitlab/file_response.rb b/lib/gitlab/file_response.rb index bbda811..eecd3fe 100644 --- a/lib/gitlab/file_response.rb +++ b/lib/gitlab/file_response.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module Gitlab # Wrapper class of file response. class FileResponse - HEADER_CONTENT_DISPOSITION = 'Content-Disposition'.freeze + HEADER_CONTENT_DISPOSITION = 'Content-Disposition' attr_reader :filename @@ -18,7 +20,7 @@ def to_hash { filename: @filename, data: @file } end - alias_method :to_h, :to_hash + alias to_h to_hash # @return [String] Formatted string with the class name, object id and filename. def inspect diff --git a/lib/gitlab/help.rb b/lib/gitlab/help.rb index fd81bae..99ac525 100644 --- a/lib/gitlab/help.rb +++ b/lib/gitlab/help.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'gitlab' require 'gitlab/cli_helpers' @@ -32,9 +34,7 @@ # @return [String] def ri_cmd which_ri = `which ri`.chomp - if which_ri.empty? - raise "'ri' tool not found in $PATH. Please install it to use the help." - end + raise "'ri' tool not found in $PATH. Please install it to use the help." if which_ri.empty? which_ri end @@ -47,8 +47,8 @@ def help_map @help_map ||= begin actions.each_with_object({}) do |action, hsh| - key = client.method(action). - owner.to_s.gsub(/Gitlab::(?:Client::)?/, '') + key = client.method(action) + .owner.to_s.gsub(/Gitlab::(?:Client::)?/, '') hsh[key] ||= [] hsh[key] << action.to_s end @@ -58,7 +58,7 @@ # Table with available commands. # # @return [Terminal::Table] - def actions_table(topic=nil) + def actions_table(topic = nil) rows = topic ? help_map[topic] : help_map.keys table do |t| t.title = topic || 'Help Topics' @@ -73,9 +73,9 @@ # Returns full namespace of a command (e.g. Gitlab::Client::Branches.cmd) def namespace(cmd) - method_owners.select { |method| method[:name] == cmd }. - map { |method| method[:owner] + '.' + method[:name] }. - shift + method_owners.select { |method| method[:name] == cmd } + .map { |method| method[:owner] + '.' + method[:name] } + .shift end # Massage output from 'ri'. diff --git a/lib/gitlab/objectified_hash.rb b/lib/gitlab/objectified_hash.rb index 571ad49..55d214a 100644 --- a/lib/gitlab/objectified_hash.rb +++ b/lib/gitlab/objectified_hash.rb @@ -1,13 +1,14 @@ +# frozen_string_literal: true + module Gitlab # Converts hashes to the objects. class ObjectifiedHash # Creates a new ObjectifiedHash object. def initialize(hash) @hash = hash - @data = hash.inject({}) do |data, (key, value)| + @data = hash.each_with_object({}) do |(key, value), data| value = ObjectifiedHash.new(value) if value.is_a? Hash data[key.to_s] = value - data end end @@ -15,7 +16,7 @@ def to_hash @hash end - alias_method :to_h, :to_hash + alias to_h to_hash # @return [String] Formatted string with the class name, object id and original hash. def inspect @@ -24,7 +25,7 @@ # Delegate to ObjectifiedHash. def method_missing(key) - @data.key?(key.to_s) ? @data[key.to_s] : nil + @data.key?(key.to_s) ? @data[key.to_s] : super end def respond_to_missing?(method_name, include_private = false) diff --git a/lib/gitlab/page_links.rb b/lib/gitlab/page_links.rb index 4687ffe..3c3c46b 100644 --- a/lib/gitlab/page_links.rb +++ b/lib/gitlab/page_links.rb @@ -1,21 +1,21 @@ +# frozen_string_literal: true + module Gitlab # Parses link header. # # @private class PageLinks - HEADER_LINK = 'Link'.freeze - DELIM_LINKS = ','.freeze - LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/ - METAS = %w(last next first prev).freeze + HEADER_LINK = 'Link' + DELIM_LINKS = ',' + LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/.freeze + METAS = %w[last next first prev].freeze attr_accessor(*METAS) def initialize(headers) link_header = headers[HEADER_LINK] - if link_header && link_header =~ /(next|first|last|prev)/ - extract_links(link_header) - end + extract_links(link_header) if link_header && link_header =~ /(next|first|last|prev)/ end private @@ -23,8 +23,10 @@ def extract_links(header) header.split(DELIM_LINKS).each do |link| LINK_REGEX.match(link.strip) do |match| - url, meta = match[1], match[2] + url = match[1] + meta = match[2] next if !url || !meta || METAS.index(meta).nil? + send("#{meta}=", url) end end diff --git a/lib/gitlab/paginated_response.rb b/lib/gitlab/paginated_response.rb index 186d0db..a0bdf0a 100644 --- a/lib/gitlab/paginated_response.rb +++ b/lib/gitlab/paginated_response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab # Wrapper class of paginated response. class PaginatedResponse @@ -54,42 +56,50 @@ response end - def has_last_page? + def last_page? !(@links.nil? || @links.last.nil?) end + alias has_last_page? last_page? def last_page return nil if @client.nil? || !has_last_page? + path = @links.last.sub(/#{@client.endpoint}/, '') @client.get(path) end - def has_first_page? + def first_page? !(@links.nil? || @links.first.nil?) end + alias has_first_page? first_page? def first_page return nil if @client.nil? || !has_first_page? + path = @links.first.sub(/#{@client.endpoint}/, '') @client.get(path) end - def has_next_page? + def next_page? !(@links.nil? || @links.next.nil?) end + alias has_next_page? next_page? def next_page return nil if @client.nil? || !has_next_page? + path = @links.next.sub(/#{@client.endpoint}/, '') @client.get(path) end - def has_prev_page? + def prev_page? !(@links.nil? || @links.prev.nil?) end + alias has_prev_page? prev_page? def prev_page return nil if @client.nil? || !has_prev_page? + path = @links.prev.sub(/#{@client.endpoint}/, '') @client.get(path) end diff --git a/lib/gitlab/request.rb b/lib/gitlab/request.rb index 8129cdc..cb7a59a 100644 --- a/lib/gitlab/request.rb +++ b/lib/gitlab/request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'httparty' require 'json' @@ -7,7 +9,7 @@ include HTTParty format :json headers 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' - parser proc { |body, _| parse(body) } + parser(proc { |body, _| parse(body) }) attr_accessor :private_token, :endpoint @@ -32,13 +34,13 @@ # Decodes a JSON response into Ruby object. def self.decode(response) - return response ? JSON.load(response) : {} + response ? JSON.load(response) : {} rescue JSON::ParserError raise Error::Parsing, 'The response is not a valid JSON' end - %w(get post put delete).each do |method| - define_method method do |path, options={}| + %w[get post put delete].each do |method| + define_method method do |path, options = {}| httparty_config(options) authorization_header(options) validate self.class.send(method, @endpoint + path, options) @@ -71,9 +73,10 @@ # Sets a base_uri and default_params for requests. # @raise [Error::MissingCredentials] if endpoint not set. - def request_defaults(sudo=nil) + def request_defaults(sudo = nil) self.class.default_params sudo: sudo raise Error::MissingCredentials, 'Please set an endpoint to API' unless @endpoint + self.class.default_params.delete(:sudo) if sudo.nil? end diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb index 620adf3..48e157f 100644 --- a/lib/gitlab/shell.rb +++ b/lib/gitlab/shell.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'gitlab' require 'gitlab/help' require 'gitlab/cli_helpers' @@ -15,7 +17,7 @@ trap('INT') { quit_shell } # capture ctrl-c setup - while buffer = Readline.readline('gitlab> ') + while (buffer = Readline.readline('gitlab> ')) begin parse_input buffer @@ -34,7 +36,7 @@ data = execute command, arguments output_table command, arguments, data end - rescue => e + rescue StandardError => e puts e.message end end @@ -46,7 +48,7 @@ buf = Shellwords.shellwords(buffer) @command = buf.shift - @arguments = buf.count > 0 ? buf : [] + @arguments = buf.count.positive? ? buf : [] end def setup @@ -62,7 +64,7 @@ end # Execute a given command with arguements - def execute(cmd=command, args=arguments) + def execute(cmd = command, args = arguments) raise "Unknown command: #{cmd}. See the 'help' for a list of valid commands." unless actions.include?(cmd.to_sym) confirm_command(cmd) diff --git a/lib/gitlab/shell_history.rb b/lib/gitlab/shell_history.rb index 8e9435d..62484c5 100644 --- a/lib/gitlab/shell_history.rb +++ b/lib/gitlab/shell_history.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class Gitlab::Shell class History DEFAULT_HISTFILESIZE = 200 DEFAULT_FILE_PATH = File.join(Dir.home, '.gitlab_shell_history') - def initialize(options={}) + def initialize(options = {}) @file_path = options[:file_path] || DEFAULT_FILE_PATH Readline::HISTORY.clear end @@ -13,13 +15,13 @@ end def save - lines.each { |line| history_file.puts line if history_file } + lines.each { |line| history_file&.puts line } end def push(line) Readline::HISTORY << line end - alias_method :<<, :push + alias << push def lines Readline::HISTORY.to_a.last(max_lines) @@ -31,7 +33,7 @@ if defined?(@history_file) @history_file else - @history_file = File.open(history_file_path, 'w', 0600).tap do |file| + @history_file = File.open(history_file_path, 'w', 0o600).tap do |file| file.sync = true end end @@ -48,7 +50,7 @@ path = history_file_path File.foreach(path) { |line| yield(line) } if File.exist?(path) - rescue => error + rescue StandardError => error warn "History file not loaded: #{error.message}" end diff --git a/lib/gitlab/version.rb b/lib/gitlab/version.rb index 50e7d36..24a605c 100644 --- a/lib/gitlab/version.rb +++ b/lib/gitlab/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab - VERSION = '4.5.0'.freeze + VERSION = '4.8.0' end diff --git a/lib/gitlab.rb b/lib/gitlab.rb index b7d5488..678f8c9 100644 --- a/lib/gitlab.rb +++ b/lib/gitlab.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'gitlab/version' require 'gitlab/objectified_hash' require 'gitlab/configuration' @@ -15,23 +17,24 @@ # Alias for Gitlab::Client.new # # @return [Gitlab::Client] - def self.client(options={}) + def self.client(options = {}) Gitlab::Client.new(options) end # Delegate to Gitlab::Client def self.method_missing(method, *args, &block) return super unless client.respond_to?(method) + client.send(method, *args, &block) end # Delegate to Gitlab::Client - def self.respond_to_missing?(method_name, include_private=false) + def self.respond_to_missing?(method_name, include_private = false) client.respond_to?(method_name) || super end # Delegate to HTTParty.http_proxy - def self.http_proxy(address=nil, port=nil, username=nil, password=nil) + def self.http_proxy(address = nil, port = nil, username = nil, password = nil) Gitlab::Request.http_proxy(address, port, username, password) end diff --git a/spec/fixtures/broadcast_message.json b/spec/fixtures/broadcast_message.json new file mode 100644 index 0000000..999892d --- /dev/null +++ b/spec/fixtures/broadcast_message.json @@ -0,0 +1,9 @@ +{ + "message":"Deploy in progress", + "starts_at":"2016-08-24T23:21:16.078Z", + "ends_at":"2016-08-26T23:21:16.080Z", + "color":"#cecece", + "font":"#FFFFFF", + "id":1, + "active":false +} diff --git a/spec/fixtures/broadcast_messages.json b/spec/fixtures/broadcast_messages.json new file mode 100644 index 0000000..92e6acd --- /dev/null +++ b/spec/fixtures/broadcast_messages.json @@ -0,0 +1,11 @@ +[ + { + "message":"Example broadcast message", + "starts_at":"2016-08-24T23:21:16.078Z", + "ends_at":"2016-08-26T23:21:16.080Z", + "color":"#E75E40", + "font":"#FFFFFF", + "id":1, + "active": false + } +] diff --git a/spec/fixtures/dockerfile_project_template.json b/spec/fixtures/dockerfile_project_template.json new file mode 100644 index 0000000..52baf26 --- /dev/null +++ b/spec/fixtures/dockerfile_project_template.json @@ -0,0 +1,5 @@ +{ + "name": "Binary", + "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" +} + diff --git a/spec/fixtures/dockerfile_templates.json b/spec/fixtures/dockerfile_templates.json new file mode 100644 index 0000000..257f8d6 --- /dev/null +++ b/spec/fixtures/dockerfile_templates.json @@ -0,0 +1,70 @@ +[ + { + "key": "Binary", + "name": "Binary" + }, + { + "key": "Binary-alpine", + "name": "Binary-alpine" + }, + { + "key": "Binary-scratch", + "name": "Binary-scratch" + }, + { + "key": "Golang", + "name": "Golang" + }, + { + "key": "Golang-alpine", + "name": "Golang-alpine" + }, + { + "key": "Golang-scratch", + "name": "Golang-scratch" + }, + { + "key": "HTTPd", + "name": "HTTPd" + }, + { + "key": "Node", + "name": "Node" + }, + { + "key": "Node-alpine", + "name": "Node-alpine" + }, + { + "key": "OpenJDK", + "name": "OpenJDK" + }, + { + "key": "OpenJDK-alpine", + "name": "OpenJDK-alpine" + }, + { + "key": "PHP", + "name": "PHP" + }, + { + "key": "Python", + "name": "Python" + }, + { + "key": "Python-alpine", + "name": "Python-alpine" + }, + { + "key": "Python2", + "name": "Python2" + }, + { + "key": "Ruby", + "name": "Ruby" + }, + { + "key": "Ruby-alpine", + "name": "Ruby-alpine" + } +] diff --git a/spec/fixtures/gitignore_template.json b/spec/fixtures/gitignore_template.json new file mode 100644 index 0000000..a19637a --- /dev/null +++ b/spec/fixtures/gitignore_template.json @@ -0,0 +1,4 @@ +{ + "name": "Ruby", + "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" +} diff --git a/spec/fixtures/gitignore_templates.json b/spec/fixtures/gitignore_templates.json new file mode 100644 index 0000000..156b14c --- /dev/null +++ b/spec/fixtures/gitignore_templates.json @@ -0,0 +1,82 @@ +[ + { + "key": "Actionscript", + "name": "Actionscript" + }, + { + "key": "Ada", + "name": "Ada" + }, + { + "key": "Agda", + "name": "Agda" + }, + { + "key": "Android", + "name": "Android" + }, + { + "key": "AppEngine", + "name": "AppEngine" + }, + { + "key": "AppceleratorTitanium", + "name": "AppceleratorTitanium" + }, + { + "key": "ArchLinuxPackages", + "name": "ArchLinuxPackages" + }, + { + "key": "Autotools", + "name": "Autotools" + }, + { + "key": "C", + "name": "C" + }, + { + "key": "C++", + "name": "C++" + }, + { + "key": "CFWheels", + "name": "CFWheels" + }, + { + "key": "CMake", + "name": "CMake" + }, + { + "key": "CUDA", + "name": "CUDA" + }, + { + "key": "CakePHP", + "name": "CakePHP" + }, + { + "key": "ChefCookbook", + "name": "ChefCookbook" + }, + { + "key": "Clojure", + "name": "Clojure" + }, + { + "key": "CodeIgniter", + "name": "CodeIgniter" + }, + { + "key": "CommonLisp", + "name": "CommonLisp" + }, + { + "key": "Composer", + "name": "Composer" + }, + { + "key": "Concrete5", + "name": "Concrete5" + } +] diff --git a/spec/fixtures/gitlab_ci_yml_template.json b/spec/fixtures/gitlab_ci_yml_template.json new file mode 100644 index 0000000..8f26cf1 --- /dev/null +++ b/spec/fixtures/gitlab_ci_yml_template.json @@ -0,0 +1,4 @@ +{ + "name": "Ruby", + "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" +} diff --git a/spec/fixtures/gitlab_ci_yml_templates.json b/spec/fixtures/gitlab_ci_yml_templates.json new file mode 100644 index 0000000..dee9d5f --- /dev/null +++ b/spec/fixtures/gitlab_ci_yml_templates.json @@ -0,0 +1,82 @@ +[ + { + "key": "Android", + "name": "Android" + }, + { + "key": "Auto-DevOps", + "name": "Auto-DevOps" + }, + { + "key": "Bash", + "name": "Bash" + }, + { + "key": "C++", + "name": "C++" + }, + { + "key": "Chef", + "name": "Chef" + }, + { + "key": "Clojure", + "name": "Clojure" + }, + { + "key": "Crystal", + "name": "Crystal" + }, + { + "key": "Django", + "name": "Django" + }, + { + "key": "Docker", + "name": "Docker" + }, + { + "key": "Elixir", + "name": "Elixir" + }, + { + "key": "Go", + "name": "Go" + }, + { + "key": "Gradle", + "name": "Gradle" + }, + { + "key": "Grails", + "name": "Grails" + }, + { + "key": "Julia", + "name": "Julia" + }, + { + "key": "LaTeX", + "name": "LaTeX" + }, + { + "key": "Laravel", + "name": "Laravel" + }, + { + "key": "Maven", + "name": "Maven" + }, + { + "key": "Mono", + "name": "Mono" + }, + { + "key": "Nodejs", + "name": "Nodejs" + }, + { + "key": "OpenShift", + "name": "OpenShift" + } +] diff --git a/spec/fixtures/license_project_template.json b/spec/fixtures/license_project_template.json new file mode 100644 index 0000000..7cf099d --- /dev/null +++ b/spec/fixtures/license_project_template.json @@ -0,0 +1,23 @@ +{ + "key": "mit", + "name": "MIT License", + "nickname": null, + "popular": true, + "html_url": "http://choosealicense.com/licenses/mit/", + "source_url": "https://opensource.org/licenses/MIT", + "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.", + "conditions": [ + "include-copyright" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "private-use" + ], + "limitations": [ + "liability", + "warranty" + ], + "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" +} \ No newline at end of file diff --git a/spec/fixtures/license_template.json b/spec/fixtures/license_template.json new file mode 100644 index 0000000..3c56b39 --- /dev/null +++ b/spec/fixtures/license_template.json @@ -0,0 +1,22 @@ +{ + "key": "mit", + "name": "MIT License", + "nickname": null, + "featured": true, + "html_url": "http://choosealicense.com/licenses/mit/", + "source_url": "http://opensource.org/licenses/MIT", + "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.", + "conditions": [ + "include-copyright" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "private-use" + ], + "limitations": [ + "no-liability" + ], + "content": "The MIT License (MIT)\n\nCopyright (c) 2016 John Doe\n [...]" +} diff --git a/spec/fixtures/license_templates.json b/spec/fixtures/license_templates.json new file mode 100644 index 0000000..b34d155 --- /dev/null +++ b/spec/fixtures/license_templates.json @@ -0,0 +1,75 @@ +[ + { + "key": "apache-2.0", + "name": "Apache License 2.0", + "nickname": null, + "featured": true, + "html_url": "http://choosealicense.com/licenses/apache-2.0/", + "source_url": "http://www.apache.org/licenses/LICENSE-2.0.html", + "description": "A permissive license that also provides an express grant of patent rights from contributors to users.", + "conditions": [ + "include-copyright", + "document-changes" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "patent-use", + "private-use" + ], + "limitations": [ + "trademark-use", + "no-liability" + ], + "content": " Apache License\n Version 2.0, January 2004\n [...]" + }, + { + "key": "gpl-3.0", + "name": "GNU General Public License v3.0", + "nickname": "GNU GPLv3", + "featured": true, + "html_url": "http://choosealicense.com/licenses/gpl-3.0/", + "source_url": "http://www.gnu.org/licenses/gpl-3.0.txt", + "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.", + "conditions": [ + "include-copyright", + "document-changes", + "disclose-source", + "same-license" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "patent-use", + "private-use" + ], + "limitations": [ + "no-liability" + ], + "content": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n [...]" + }, + { + "key": "mit", + "name": "MIT License", + "nickname": null, + "featured": true, + "html_url": "http://choosealicense.com/licenses/mit/", + "source_url": "http://opensource.org/licenses/MIT", + "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.", + "conditions": [ + "include-copyright" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "private-use" + ], + "limitations": [ + "no-liability" + ], + "content": "The MIT License (MIT)\n\nCopyright (c) [year] [fullname]\n [...]" + } +] diff --git a/spec/fixtures/merge_base.json b/spec/fixtures/merge_base.json new file mode 100644 index 0000000..09f5b3e --- /dev/null +++ b/spec/fixtures/merge_base.json @@ -0,0 +1,14 @@ +{ + "id": "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863", + "short_id": "1a0b36b3", + "title": "Initial commit", + "created_at": "2014-02-27T08:03:18.000Z", + "parent_ids": [], + "message": "Initial commit\n", + "author_name": "Dmitriy Zaporozhets", + "author_email": "dmitriy.zaporozhets@gmail.com", + "authored_date": "2014-02-27T08:03:18.000Z", + "committer_name": "Dmitriy Zaporozhets", + "committer_email": "dmitriy.zaporozhets@gmail.com", + "committed_date": "2014-02-27T08:03:18.000Z" +} diff --git a/spec/fixtures/merge_request_diff_version.json b/spec/fixtures/merge_request_diff_version.json new file mode 100644 index 0000000..91df5ca --- /dev/null +++ b/spec/fixtures/merge_request_diff_version.json @@ -0,0 +1,45 @@ +{ + "id": 110, + "head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", + "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", + "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", + "created_at": "2016-07-26T14:44:48.926Z", + "merge_request_id": 105, + "state": "collected", + "real_size": "1", + "commits": [{ + "id": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", + "short_id": "33e2ee85", + "title": "Change year to 2018", + "author_name": "Administrator", + "author_email": "admin@example.com", + "created_at": "2016-07-26T17:44:29.000+03:00", + "message": "Change year to 2018" + }, { + "id": "aa24655de48b36335556ac8a3cd8bb521f977cbd", + "short_id": "aa24655d", + "title": "Update LICENSE", + "author_name": "Administrator", + "author_email": "admin@example.com", + "created_at": "2016-07-25T17:21:53.000+03:00", + "message": "Update LICENSE" + }, { + "id": "3eed087b29835c48015768f839d76e5ea8f07a24", + "short_id": "3eed087b", + "title": "Add license", + "author_name": "Administrator", + "author_email": "admin@example.com", + "created_at": "2016-07-25T17:21:20.000+03:00", + "message": "Add license" + }], + "diffs": [{ + "old_path": "LICENSE", + "new_path": "LICENSE", + "a_mode": "0", + "b_mode": "100644", + "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", + "new_file": true, + "renamed_file": false, + "deleted_file": false + }] +} diff --git a/spec/fixtures/merge_request_diff_versions.json b/spec/fixtures/merge_request_diff_versions.json new file mode 100644 index 0000000..48ede0e --- /dev/null +++ b/spec/fixtures/merge_request_diff_versions.json @@ -0,0 +1,19 @@ +[{ + "id": 110, + "head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", + "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", + "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", + "created_at": "2016-07-26T14:44:48.926Z", + "merge_request_id": 105, + "state": "collected", + "real_size": "1" +}, { + "id": 108, + "head_commit_sha": "3eed087b29835c48015768f839d76e5ea8f07a24", + "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", + "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", + "created_at": "2016-07-25T14:21:33.028Z", + "merge_request_id": 105, + "state": "collected", + "real_size": "1" +}] diff --git a/spec/fixtures/merge_requests_closing_issue_on_merge.json b/spec/fixtures/merge_requests_closing_issue_on_merge.json new file mode 100644 index 0000000..0217ab3 --- /dev/null +++ b/spec/fixtures/merge_requests_closing_issue_on_merge.json @@ -0,0 +1 @@ +[{"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"}}] diff --git a/spec/fixtures/participants_on_issue.json b/spec/fixtures/participants_on_issue.json new file mode 100644 index 0000000..d15bb8f --- /dev/null +++ b/spec/fixtures/participants_on_issue.json @@ -0,0 +1,18 @@ +[ + { + "id": 1, + "name": "John Doe1", + "username": "user1", + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon", + "web_url": "http://localhost/user1" + }, + { + "id": 5, + "name": "John Doe5", + "username": "user5", + "state": "active", + "avatar_url": "http://www.gravatar.com/avatar/4aea8cf834ed91844a2da4ff7ae6b491?s=80&d=identicon", + "web_url": "http://localhost/user5" + } +] diff --git a/spec/fixtures/preview_project_badge.json b/spec/fixtures/preview_project_badge.json new file mode 100644 index 0000000..ea2ace2 --- /dev/null +++ b/spec/fixtures/preview_project_badge.json @@ -0,0 +1,6 @@ +{ + "link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}", + "image_url": "https://shields.io/my/badge", + "rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master", + "rendered_image_url": "https://shields.io/my/badge" +} diff --git a/spec/fixtures/project_badge.json b/spec/fixtures/project_badge.json new file mode 100644 index 0000000..ac66910 --- /dev/null +++ b/spec/fixtures/project_badge.json @@ -0,0 +1,8 @@ +{ + "id": 1, + "link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}", + "image_url": "https://shields.io/my/badge", + "rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master", + "rendered_image_url": "https://shields.io/my/badge", + "kind": "project" +} diff --git a/spec/fixtures/project_badges.json b/spec/fixtures/project_badges.json new file mode 100644 index 0000000..059a0e2 --- /dev/null +++ b/spec/fixtures/project_badges.json @@ -0,0 +1,18 @@ +[ + { + "id": 1, + "link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}", + "image_url": "https://shields.io/my/badge", + "rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master", + "rendered_image_url": "https://shields.io/my/badge", + "kind": "project" + }, + { + "id": 2, + "link_url": "http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}", + "image_url": "https://shields.io/my/badge", + "rendered_link_url": "http://example.com/ci_status.svg?project=example-org/example-project&ref=master", + "rendered_image_url": "https://shields.io/my/badge", + "kind": "group" + } +] diff --git a/spec/fixtures/project_templates.json b/spec/fixtures/project_templates.json new file mode 100644 index 0000000..01d2763 --- /dev/null +++ b/spec/fixtures/project_templates.json @@ -0,0 +1,50 @@ +[ + { + "key": "epl-1.0", + "name": "Eclipse Public License 1.0" + }, + { + "key": "lgpl-3.0", + "name": "GNU Lesser General Public License v3.0" + }, + { + "key": "unlicense", + "name": "The Unlicense" + }, + { + "key": "agpl-3.0", + "name": "GNU Affero General Public License v3.0" + }, + { + "key": "gpl-3.0", + "name": "GNU General Public License v3.0" + }, + { + "key": "bsd-3-clause", + "name": "BSD 3-clause \"New\" or \"Revised\" License" + }, + { + "key": "lgpl-2.1", + "name": "GNU Lesser General Public License v2.1" + }, + { + "key": "mit", + "name": "MIT License" + }, + { + "key": "apache-2.0", + "name": "Apache License 2.0" + }, + { + "key": "bsd-2-clause", + "name": "BSD 2-clause \"Simplified\" License" + }, + { + "key": "mpl-2.0", + "name": "Mozilla Public License 2.0" + }, + { + "key": "gpl-2.0", + "name": "GNU General Public License v2.0" + } +] diff --git a/spec/fixtures/protected_branch.json b/spec/fixtures/protected_branch.json new file mode 100644 index 0000000..e77622c --- /dev/null +++ b/spec/fixtures/protected_branch.json @@ -0,0 +1,15 @@ +{ + "name": "master", + "push_access_levels": [ + { + "access_level": 40, + "access_level_description": "Maintainers" + } + ], + "merge_access_levels": [ + { + "access_level": 40, + "access_level_description": "Maintainers" + } + ] +} diff --git a/spec/fixtures/protected_branches.json b/spec/fixtures/protected_branches.json new file mode 100644 index 0000000..fa00014 --- /dev/null +++ b/spec/fixtures/protected_branches.json @@ -0,0 +1,17 @@ +[ + { + "name": "master", + "push_access_levels": [ + { + "access_level": 40, + "access_level_description": "Maintainers" + } + ], + "merge_access_levels": [ + { + "access_level": 40, + "access_level_description": "Maintainers" + } + ] + } +] diff --git a/spec/fixtures/protected_tag.json b/spec/fixtures/protected_tag.json new file mode 100644 index 0000000..b804883 --- /dev/null +++ b/spec/fixtures/protected_tag.json @@ -0,0 +1,9 @@ +{ + "name": "release-1-0", + "create_access_levels": [ + { + "access_level": 40, + "access_level_description": "Maintainers" + } + ] +} diff --git a/spec/fixtures/protected_tags.json b/spec/fixtures/protected_tags.json new file mode 100644 index 0000000..a1675c1 --- /dev/null +++ b/spec/fixtures/protected_tags.json @@ -0,0 +1,11 @@ +[ + { + "name": "release-1-0", + "create_access_levels": [ + { + "access_level": 40, + "access_level_description": "Maintainers" + } + ] + } +] diff --git a/spec/fixtures/repository_submodule.json b/spec/fixtures/repository_submodule.json new file mode 100644 index 0000000..1afc08d --- /dev/null +++ b/spec/fixtures/repository_submodule.json @@ -0,0 +1,17 @@ +{ + "id": "ed899a2f4b50b4370feeea94676502b42383c746", + "short_id": "ed899a2f4b5", + "title": "Updated submodule example_submodule with oid 3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88", + "author_name": "Dmitriy Zaporozhets", + "author_email": "dzaporozhets@sphereconsultinginc.com", + "committer_name": "Dmitriy Zaporozhets", + "committer_email": "dzaporozhets@sphereconsultinginc.com", + "created_at": "2018-09-20T09:26:24.000-07:00", + "message": "Updated submodule example_submodule with oid 3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88", + "parent_ids": [ + "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" + ], + "committed_date": "2018-09-20T09:26:24.000-07:00", + "authored_date": "2018-09-20T09:26:24.000-07:00", + "status": null +} diff --git a/spec/fixtures/team_member.json b/spec/fixtures/team_member.json index fd3ac38..3009696 100644 --- a/spec/fixtures/team_member.json +++ b/spec/fixtures/team_member.json @@ -1 +1,10 @@ -{"id":1,"email":"john@example.com","name":"John Smith","blocked":false,"created_at":"2012-09-17T09:41:56Z","access_level":40} \ No newline at end of file +{ + "id": 1, + "username": "john_smith", + "name": "John Smith", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon", + "web_url": "http://192.168.1.8:3000/root", + "expires_at": "2018-12-31T00:00:00Z", + "access_level": 40 +} \ No newline at end of file diff --git a/spec/fixtures/transfer_project.json b/spec/fixtures/transfer_project.json new file mode 100644 index 0000000..27112a1 --- /dev/null +++ b/spec/fixtures/transfer_project.json @@ -0,0 +1,59 @@ +{ + "id": 1, + "description": null, + "name": "test", + "name_with_namespace": "Yolo / test", + "path": "test", + "path_with_namespace": "yolo/test", + "created_at": "2018-10-26T21:14:12.851Z", + "default_branch": "master", + "tag_list": [], + "ssh_url_to_repo": "git@gitlab.com:yolo/test.git", + "http_url_to_repo": "https://gitlab.com/yolo/test.git", + "web_url": "https://gitlab.com/yolo/test", + "readme_url": null, + "avatar_url": null, + "star_count": 0, + "forks_count": 0, + "last_activity_at": "2018-10-26T21:14:12.851Z", + "namespace": { + "id": 2, + "name": "Yolo", + "path": "yolo", + "kind": "group", + "full_path": "yolo", + "parent_id": null + }, + "_links": { + "self": "https://gitlab.com/api/v4/projects/1", + "issues": "https://gitlab.com/api/v4/projects/1/issues", + "merge_requests": "https://gitlab.com/api/v4/projects/1/merge_requests", + "repo_branches": "https://gitlab.com/api/v4/projects/1/repository/branches", + "labels": "https://gitlab.com/api/v4/projects/1/labels", + "events": "https://gitlab.com/api/v4/projects/1/events", + "members": "https://gitlab.com/api/v4/projects/1/members" + }, + "archived": false, + "visibility": "private", + "resolve_outdated_diff_discussions": false, + "container_registry_enabled": true, + "issues_enabled": true, + "merge_requests_enabled": true, + "wiki_enabled": true, + "jobs_enabled": true, + "snippets_enabled": true, + "shared_runners_enabled": true, + "lfs_enabled": true, + "creator_id": 42, + "import_status": "none", + "open_issues_count": 0, + "public_jobs": true, + "ci_config_path": null, + "shared_with_groups": [], + "only_allow_merge_if_pipeline_succeeds": false, + "request_access_enabled": false, + "only_allow_merge_if_all_discussions_are_resolved": false, + "printing_merge_request_link_enabled": true, + "merge_method": "merge", + "mirror": false +} diff --git a/spec/fixtures/upload_file.json b/spec/fixtures/upload_file.json new file mode 100644 index 0000000..ede0afb --- /dev/null +++ b/spec/fixtures/upload_file.json @@ -0,0 +1,5 @@ +{ + "alt": "null", + "url": "/uploads/f22e67e35e1bcb339058212c54bb8772/null", + "markdown": "[null](/uploads/f22e67e35e1bcb339058212c54bb8772/null)" +} diff --git a/spec/fixtures/version.json b/spec/fixtures/version.json new file mode 100644 index 0000000..abb214f --- /dev/null +++ b/spec/fixtures/version.json @@ -0,0 +1,4 @@ +{ + "version": "8.13.0-pre", + "revision": "4e963fe" +} diff --git a/spec/fixtures/wiki.json b/spec/fixtures/wiki.json new file mode 100644 index 0000000..a893abf --- /dev/null +++ b/spec/fixtures/wiki.json @@ -0,0 +1,7 @@ +{ + "content" : "home page", + "format" : "markdown", + "slug" : "home", + "title" : "home" +} + diff --git a/spec/fixtures/wiki_attachment.json b/spec/fixtures/wiki_attachment.json new file mode 100644 index 0000000..e984e73 --- /dev/null +++ b/spec/fixtures/wiki_attachment.json @@ -0,0 +1,9 @@ +{ + "file_name" : "dk.png", + "file_path" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png", + "branch" : "master", + "link" : { + "url" : "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png", + "markdown" : "![dk](uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png)" + } +} diff --git a/spec/fixtures/wikis.json b/spec/fixtures/wikis.json new file mode 100644 index 0000000..e2bba6c --- /dev/null +++ b/spec/fixtures/wikis.json @@ -0,0 +1,19 @@ +[ + { + "content" : "Here is an instruction how to deploy this project.", + "format" : "markdown", + "slug" : "deploy", + "title" : "deploy" + }, + { + "content" : "Our development process is described here.", + "format" : "markdown", + "slug" : "development", + "title" : "development" + },{ + "content" : "* [Deploy](deploy)\n* [Development](development)", + "format" : "markdown", + "slug" : "home", + "title" : "home" + } +] diff --git a/spec/gitlab/api_spec.rb b/spec/gitlab/api_spec.rb index decf760..603a70d 100644 --- a/spec/gitlab/api_spec.rb +++ b/spec/gitlab/api_spec.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::API do let(:default_headers) { subject.class.default_options[:headers] } - describe ".default_options[:headers]" do + describe '.default_options[:headers]' do it "has 'User-Agent'" do expect(default_headers).to include('User-Agent' => Gitlab::Configuration::DEFAULT_USER_AGENT) end diff --git a/spec/gitlab/cli_helpers_spec.rb b/spec/gitlab/cli_helpers_spec.rb index 35dc8ef..b8c918b 100644 --- a/spec/gitlab/cli_helpers_spec.rb +++ b/spec/gitlab/cli_helpers_spec.rb @@ -1,55 +1,58 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::CLI::Helpers do - describe ".method_owners" do - let(:methods) { Gitlab::CLI::Helpers.method_owners } + describe '.method_owners' do + let(:methods) { described_class.method_owners } - it "returns Array of Hashes containing method names and owners" do + it 'returns Array of Hashes containing method names and owners' do expect(methods).to be_a Array expect(methods.all? { |m| m.is_a? Hash }).to be true - expect(methods.all? { |m| m.keys.sort == %i(name owner) }).to be true + expect(methods.all? { |m| m.keys.sort == %i[name owner] }).to be true end end - describe ".valid_command?" do - it "returns true when command is valid" do - expect(Gitlab::CLI::Helpers.valid_command?('merge_requests')).to be_truthy + describe '.valid_command?' do + it 'returns true when command is valid' do + expect(described_class).to be_valid_command('merge_requests') end - it "returns false when command is NOT valid" do - expect(Gitlab::CLI::Helpers.valid_command?('mmmmmerge_requests')).to be_falsy + it 'returns false when command is NOT valid' do + expect(described_class).not_to be_valid_command('mmmmmerge_requests') end end - describe ".symbolize_keys" do - context "when input is a Hash" do - it "returns a Hash with symbols for keys" do + describe '.symbolize_keys' do + context 'when input is a Hash' do + it 'returns a Hash with symbols for keys' do hash = { 'key1' => 'val1', 'key2' => 'val2' } - symbolized_hash = Gitlab::CLI::Helpers.symbolize_keys(hash) + symbolized_hash = described_class.symbolize_keys(hash) expect(symbolized_hash).to eq(key1: 'val1', key2: 'val2') end end - context "when input is NOT a Hash" do - it "returns input untouched" do + + context 'when input is NOT a Hash' do + it 'returns input untouched' do array = [1, 2, 3] - new_array = Gitlab::CLI::Helpers.symbolize_keys(array) + new_array = described_class.symbolize_keys(array) expect(new_array).to eq([1, 2, 3]) end end end - describe ".yaml_load" do - context "when argument is a YAML string" do - it "returns Ruby objects" do - argument = "{foo: bar, sna: fu}" - output = Gitlab::CLI::Helpers.yaml_load argument + describe '.yaml_load' do + context 'when argument is a YAML string' do + it 'returns Ruby objects' do + argument = '{foo: bar, sna: fu}' + output = described_class.yaml_load argument expect(output).to eq('foo' => 'bar', 'sna' => 'fu') end end - context "when input is NOT valid YAML" do - it "raises a TypeError" do + context 'when input is NOT valid YAML' do + it 'raises a TypeError' do ruby_array = [1, 2, 3, 4] - expect { Gitlab::CLI::Helpers.yaml_load ruby_array }.to raise_error TypeError + expect { described_class.yaml_load ruby_array }.to raise_error TypeError end end end diff --git a/spec/gitlab/cli_spec.rb b/spec/gitlab/cli_spec.rb index d967297..3b1b768 100644 --- a/spec/gitlab/cli_spec.rb +++ b/spec/gitlab/cli_spec.rb @@ -1,117 +1,131 @@ +# frozen_string_literal: true + require 'spec_helper' require 'json' describe Gitlab::CLI do - describe ".run" do - context "when command is version" do - it "shows gem version" do - output = capture_output { Gitlab::CLI.run('-v') } + describe '.run' do + context 'when command is version' do + it 'shows gem version' do + output = capture_output { described_class.run('-v') } expect(output).to eq("Gitlab Ruby Gem #{Gitlab::VERSION}\n") end end - context "when command is info" do - it "shows environment info" do - output = capture_output { Gitlab::CLI.run('info') } - expect(output).to include("Gitlab endpoint is") - expect(output).to include("Gitlab private token is") - expect(output).to include("Ruby Version is") - expect(output).to include("Gitlab Ruby Gem") + context 'when command is info' do + it 'shows environment info' do + output = capture_output { described_class.run('info') } + expect(output).to include('Gitlab endpoint is') + expect(output).to include('Gitlab private token is') + expect(output).to include('Ruby Version is') + expect(output).to include('Gitlab Ruby Gem') end end - context "when command is help" do - it "shows available actions" do - output = capture_output { Gitlab::CLI.run('help') } + context 'when command is help' do + it 'shows available actions' do + output = capture_output { described_class.run('help') } expect(output).to include('Help Topics') expect(output).to include('MergeRequests') end end - context "when command is user" do + context 'when command is user' do before do - stub_get("/user", "user") - @output = capture_output { Gitlab::CLI.run('user') } + stub_get('/user', 'user') + @output = capture_output { described_class.run('user') } end - it "shows executed command" do + it 'shows executed command' do expect(@output).to include('Gitlab.user') end - it "shows user data" do + it 'shows user data' do expect(@output).to include('name') expect(@output).to include('John Smith') end end - context "when command is users" do + context 'when command is users' do before do - stub_get("/users", "users") - @output = capture_output { Gitlab::CLI.run('users') } + stub_get('/users', 'users') + @output = capture_output { described_class.run('users') } end - it "shows executed command" do + it 'shows executed command' do expect(@output).to include('Gitlab.users') end - it "shows users data" do + it 'shows users data' do expect(@output).to include('name') expect(@output).to include('John Smith') expect(@output).to include('Jack Smith') end end + + context 'when command is create_label' do + before do + stub_post('/projects/Project/labels', 'label') + args = ['Project', 'Backlog', '#DD10AA'] + @output = capture_output { described_class.run('create_label', args) } + end + + it 'shows executed command' do + expect(@output).to include('Gitlab.create_label Project, Backlog, #DD10AA') + end + end end - describe ".start" do - context "when command with excluded fields" do + describe '.start' do + context 'when command with excluded fields' do before do - stub_get("/user", "user") + stub_get('/user', 'user') args = ['user', '--except=id,email,name'] - @output = capture_output { Gitlab::CLI.start(args) } + @output = capture_output { described_class.start(args) } end - it "shows user data with excluded fields" do - expect(@output).to_not include('John Smith') + it 'shows user data with excluded fields' do + expect(@output).not_to include('John Smith') expect(@output).to include('bio') expect(@output).to include('created_at') end end - context "when command with json output" do + context 'when command with json output' do before do - stub_get("/user", "user") + stub_get('/user', 'user') args = ['user', '--json'] - @output = capture_output { Gitlab::CLI.start(args) } + @output = capture_output { described_class.start(args) } end - it "renders output as json" do + it 'renders output as json' do expect(JSON.parse(@output)['result']).to eq(JSON.parse(File.read(File.dirname(__FILE__) + '/../fixtures/user.json'))) expect(JSON.parse(@output)['cmd']).to eq('Gitlab.user') end end - context "when command with required fields" do + context 'when command with required fields' do before do - stub_get("/user", "user") + stub_get('/user', 'user') args = ['user', '--only=id,email,name'] - @output = capture_output { Gitlab::CLI.start(args) } + @output = capture_output { described_class.start(args) } end - it "shows user data with required fields" do + it 'shows user data with required fields' do expect(@output).to include('id') expect(@output).to include('name') expect(@output).to include('email') expect(@output).to include('John Smith') - expect(@output).to_not include('bio') - expect(@output).to_not include('created_at') + expect(@output).not_to include('bio') + expect(@output).not_to include('created_at') end end - context "fetch project with namespace/repo" do - it "encodes delimiter" do - stub_get("/projects/gitlab-org%2Fgitlab-ce", "project") + context 'fetch project with namespace/repo' do + it 'encodes delimiter' do + stub_get('/projects/gitlab-org%2Fgitlab-ce', 'project') args = ['project', 'gitlab-org/gitlab-ce'] - @output = capture_output { Gitlab::CLI.start(args) } + @output = capture_output { described_class.start(args) } expect(@output).to include('id') end end diff --git a/spec/gitlab/client/access_requests_spec.rb b/spec/gitlab/client/access_requests_spec.rb index 61d4471..67392e0 100644 --- a/spec/gitlab/client/access_requests_spec.rb +++ b/spec/gitlab/client/access_requests_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do describe '.project_access_requests' do before do - stub_get("/projects/1/access_requests", "access_requests") + stub_get('/projects/1/access_requests', 'access_requests') @access_requests = Gitlab.project_access_requests(1) end it 'gets the correct resources' do - expect(a_get("/projects/1/access_requests")).to have_been_made + expect(a_get('/projects/1/access_requests')).to have_been_made end it 'returns a paginated response of project access requests' do @@ -18,12 +20,12 @@ describe '.group_access_requests' do before do - stub_get("/groups/1/access_requests", "access_requests") + stub_get('/groups/1/access_requests', 'access_requests') @access_requests = Gitlab.group_access_requests(1) end it 'gets the correct resources' do - expect(a_get("/groups/1/access_requests")).to have_been_made + expect(a_get('/groups/1/access_requests')).to have_been_made end it 'returns a paginated response of group access requests' do @@ -33,53 +35,54 @@ describe '.request_project_access' do before do - stub_post("/projects/1/access_requests", "access_request") + stub_post('/projects/1/access_requests', 'access_request') @access_request = Gitlab.request_project_access(1) end it 'gets the correct resource' do - expect(a_post("/projects/1/access_requests")).to have_been_made + expect(a_post('/projects/1/access_requests')).to have_been_made end end describe '.request_group_access' do before do - stub_post("/groups/1/access_requests", "access_request") + stub_post('/groups/1/access_requests', 'access_request') @access_request = Gitlab.request_group_access(1) end it 'gets the correct resource' do - expect(a_post("/groups/1/access_requests")).to have_been_made + expect(a_post('/groups/1/access_requests')).to have_been_made end end describe '.approve_project_access_request' do context 'When no access level is given' do before do - stub_put("/projects/1/access_requests/1/approve", "default_approved_access_request") + stub_put('/projects/1/access_requests/1/approve', 'default_approved_access_request') @access_request = Gitlab.approve_project_access_request(1, 1) end it 'gets the correct resource' do - expect(a_put("/projects/1/access_requests/1/approve")).to have_been_made + expect(a_put('/projects/1/access_requests/1/approve')).to have_been_made end - it "returns information about the project access request" do + it 'returns information about the project access request' do expect(@access_request.access_level).to eq(30) end end + context 'When access level is given' do before do - stub_put("/projects/1/access_requests/1/approve", "approved_access_request").with(body: {access_level: '20'}) - @access_request = Gitlab.approve_project_access_request(1, 1, {access_level: '20'}) + stub_put('/projects/1/access_requests/1/approve', 'approved_access_request').with(body: { access_level: '20' }) + @access_request = Gitlab.approve_project_access_request(1, 1, access_level: '20') end it 'gets the correct resource' do - expect(a_put("/projects/1/access_requests/1/approve"). - with(body: { access_level: "20" })).to have_been_made + expect(a_put('/projects/1/access_requests/1/approve') + .with(body: { access_level: '20' })).to have_been_made end - it "returns information about the project access request" do + it 'returns information about the project access request' do expect(@access_request.access_level).to eq(20) end end @@ -88,30 +91,31 @@ describe '.approve_group_access_request' do context 'When no access level is given' do before do - stub_put("/groups/1/access_requests/1/approve", "default_approved_access_request") + stub_put('/groups/1/access_requests/1/approve', 'default_approved_access_request') @access_request = Gitlab.approve_group_access_request(1, 1) end it 'gets the correct resource' do - expect(a_put("/groups/1/access_requests/1/approve")).to have_been_made + expect(a_put('/groups/1/access_requests/1/approve')).to have_been_made end - it "returns information about the group access request" do + it 'returns information about the group access request' do expect(@access_request.access_level).to eq(30) end end + context 'When access level is given' do before do - stub_put("/groups/1/access_requests/1/approve", "approved_access_request").with(body: {access_level: '20'}) - @access_request = Gitlab.approve_group_access_request(1, 1, {access_level: '20'}) + stub_put('/groups/1/access_requests/1/approve', 'approved_access_request').with(body: { access_level: '20' }) + @access_request = Gitlab.approve_group_access_request(1, 1, access_level: '20') end it 'gets the correct resource' do - expect(a_put("/groups/1/access_requests/1/approve"). - with(body: { access_level: "20" })).to have_been_made + expect(a_put('/groups/1/access_requests/1/approve') + .with(body: { access_level: '20' })).to have_been_made end - it "returns information about the group access request" do + it 'returns information about the group access request' do expect(@access_request.access_level).to eq(20) end end @@ -119,23 +123,23 @@ describe '.deny_project_access_request' do before do - stub_delete("/projects/1/access_requests/1", "access_request") + stub_delete('/projects/1/access_requests/1', 'access_request') @access_request = Gitlab.deny_project_access_request(1, 1) end it 'gets the correct resource' do - expect(a_delete("/projects/1/access_requests/1")).to have_been_made + expect(a_delete('/projects/1/access_requests/1')).to have_been_made end end describe '.deny_group_access_request' do before do - stub_delete("/groups/1/access_requests/1", "access_request") + stub_delete('/groups/1/access_requests/1', 'access_request') @access_request = Gitlab.deny_group_access_request(1, 1) end it 'gets the correct resource' do - expect(a_delete("/groups/1/access_requests/1")).to have_been_made + expect(a_delete('/groups/1/access_requests/1')).to have_been_made end end -end \ No newline at end of file +end diff --git a/spec/gitlab/client/award_emojis_spec.rb b/spec/gitlab/client/award_emojis_spec.rb index 68f9616..c66448e 100644 --- a/spec/gitlab/client/award_emojis_spec.rb +++ b/spec/gitlab/client/award_emojis_spec.rb @@ -1,55 +1,57 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do describe '.award_emojis' do context 'when issue award emojis' do before do - stub_get("/projects/1/issues/80/award_emoji", "issue_award_emojis") + stub_get('/projects/1/issues/80/award_emoji', 'issue_award_emojis') @emojis = Gitlab.award_emojis(1, 80, 'issue') end - it "gets the correct resources" do - expect(a_get("/projects/1/issues/80/award_emoji")).to have_been_made - end - - it "returns a paginated response of issue award emojis" do + it 'gets the correct resources' do + expect(a_get('/projects/1/issues/80/award_emoji')).to have_been_made + end + + it 'returns a paginated response of issue award emojis' do expect(@emojis).to be_a Gitlab::PaginatedResponse expect(@emojis.first.awardable_id).to eq(80) - expect(@emojis.first.awardable_type).to eq("Issue") + expect(@emojis.first.awardable_type).to eq('Issue') end end context 'when merge request award emojis' do before do - stub_get("/projects/1/merge_requests/80/award_emoji", "merge_request_award_emojis") + stub_get('/projects/1/merge_requests/80/award_emoji', 'merge_request_award_emojis') @emojis = Gitlab.award_emojis(1, 80, 'merge_request') end - it "gets the correct resources" do - expect(a_get("/projects/1/merge_requests/80/award_emoji")).to have_been_made - end - - it "returns a paginated response of merge request award emojis" do + it 'gets the correct resources' do + expect(a_get('/projects/1/merge_requests/80/award_emoji')).to have_been_made + end + + it 'returns a paginated response of merge request award emojis' do expect(@emojis).to be_a Gitlab::PaginatedResponse expect(@emojis.first.awardable_id).to eq(80) - expect(@emojis.first.awardable_type).to eq("MergeRequest") + expect(@emojis.first.awardable_type).to eq('MergeRequest') end end context 'when snippet award emojis' do before do - stub_get("/projects/1/snippets/80/award_emoji", "snippet_award_emojis") + stub_get('/projects/1/snippets/80/award_emoji', 'snippet_award_emojis') @emojis = Gitlab.award_emojis(1, 80, 'snippet') end - it "gets the correct resources" do - expect(a_get("/projects/1/snippets/80/award_emoji")).to have_been_made - end - - it "returns a paginated response of snippet award emojis" do + it 'gets the correct resources' do + expect(a_get('/projects/1/snippets/80/award_emoji')).to have_been_made + end + + it 'returns a paginated response of snippet award emojis' do expect(@emojis).to be_a Gitlab::PaginatedResponse expect(@emojis.first.awardable_id).to eq(80) - expect(@emojis.first.awardable_type).to eq("Snippet") + expect(@emojis.first.awardable_type).to eq('Snippet') end end end @@ -57,52 +59,52 @@ describe '.note_award_emojis' do context 'when issue note award emojis' do before do - stub_get("/projects/1/issues/80/notes/1/award_emoji", "note_award_emojis") + stub_get('/projects/1/issues/80/notes/1/award_emoji', 'note_award_emojis') @note_emojis = Gitlab.note_award_emojis(1, 80, 'issue', 1) end - it "gets the correct resources" do - expect(a_get("/projects/1/issues/80/notes/1/award_emoji")).to have_been_made - end - - it "returns a paginated response of issue note award emojis" do + it 'gets the correct resources' do + expect(a_get('/projects/1/issues/80/notes/1/award_emoji')).to have_been_made + end + + it 'returns a paginated response of issue note award emojis' do expect(@note_emojis).to be_a Gitlab::PaginatedResponse expect(@note_emojis.first.awardable_id).to eq(1) - expect(@note_emojis.first.awardable_type).to eq("Note") + expect(@note_emojis.first.awardable_type).to eq('Note') end end context 'when merge request note award emojis' do before do - stub_get("/projects/1/merge_requests/80/notes/1/award_emoji", "note_award_emojis") + stub_get('/projects/1/merge_requests/80/notes/1/award_emoji', 'note_award_emojis') @note_emojis = Gitlab.note_award_emojis(1, 80, 'merge_request', 1) end - it "gets the correct resources" do - expect(a_get("/projects/1/merge_requests/80/notes/1/award_emoji")).to have_been_made - end - - it "returns a paginated response of merge request note award emojis" do + it 'gets the correct resources' do + expect(a_get('/projects/1/merge_requests/80/notes/1/award_emoji')).to have_been_made + end + + it 'returns a paginated response of merge request note award emojis' do expect(@note_emojis).to be_a Gitlab::PaginatedResponse expect(@note_emojis.first.awardable_id).to eq(1) - expect(@note_emojis.first.awardable_type).to eq("Note") + expect(@note_emojis.first.awardable_type).to eq('Note') end end context 'when snippet note award emojis' do before do - stub_get("/projects/1/snippets/80/notes/1/award_emoji", "note_award_emojis") + stub_get('/projects/1/snippets/80/notes/1/award_emoji', 'note_award_emojis') @note_emojis = Gitlab.note_award_emojis(1, 80, 'snippet', 1) end - it "gets the correct resources" do - expect(a_get("/projects/1/snippets/80/notes/1/award_emoji")).to have_been_made - end - - it "returns a paginated response of snippet note award emojis" do + it 'gets the correct resources' do + expect(a_get('/projects/1/snippets/80/notes/1/award_emoji')).to have_been_made + end + + it 'returns a paginated response of snippet note award emojis' do expect(@note_emojis).to be_a Gitlab::PaginatedResponse expect(@note_emojis.first.awardable_id).to eq(1) - expect(@note_emojis.first.awardable_type).to eq("Note") + expect(@note_emojis.first.awardable_type).to eq('Note') end end end @@ -110,51 +112,51 @@ describe '.award_emoji' do context 'when issue award emoji' do before do - stub_get("/projects/1/issues/80/award_emoji/4", "issue_award_emoji") + stub_get('/projects/1/issues/80/award_emoji/4', 'issue_award_emoji') @emoji = Gitlab.award_emoji(1, 80, 'issue', 4) end - it "gets the correct resource" do - expect(a_get("/projects/1/issues/80/award_emoji/4")).to have_been_made - end - - it "returns information about an issue award emoji" do + it 'gets the correct resource' do + expect(a_get('/projects/1/issues/80/award_emoji/4')).to have_been_made + end + + it 'returns information about an issue award emoji' do expect(@emoji.id).to eq(4) - expect(@emoji.awardable_type).to eq("Issue") + expect(@emoji.awardable_type).to eq('Issue') expect(@emoji.awardable_id).to eq(80) end end context 'when merge request award emoji' do before do - stub_get("/projects/1/merge_requests/80/award_emoji/4", "merge_request_award_emoji") + stub_get('/projects/1/merge_requests/80/award_emoji/4', 'merge_request_award_emoji') @emoji = Gitlab.award_emoji(1, 80, 'merge_request', 4) end - it "gets the correct resource" do - expect(a_get("/projects/1/merge_requests/80/award_emoji/4")).to have_been_made - end - - it "returns information about a merge request award emoji" do + it 'gets the correct resource' do + expect(a_get('/projects/1/merge_requests/80/award_emoji/4')).to have_been_made + end + + it 'returns information about a merge request award emoji' do expect(@emoji.id).to eq(4) - expect(@emoji.awardable_type).to eq("MergeRequest") + expect(@emoji.awardable_type).to eq('MergeRequest') expect(@emoji.awardable_id).to eq(80) end end context 'when snippet award emoji' do before do - stub_get("/projects/1/snippets/80/award_emoji/4", "snippet_award_emoji") + stub_get('/projects/1/snippets/80/award_emoji/4', 'snippet_award_emoji') @emoji = Gitlab.award_emoji(1, 80, 'snippet', 4) end - it "gets the correct resource" do - expect(a_get("/projects/1/snippets/80/award_emoji/4")).to have_been_made - end - - it "returns information about a snippet award emoji" do + it 'gets the correct resource' do + expect(a_get('/projects/1/snippets/80/award_emoji/4')).to have_been_made + end + + it 'returns information about a snippet award emoji' do expect(@emoji.id).to eq(4) - expect(@emoji.awardable_type).to eq("Snippet") + expect(@emoji.awardable_type).to eq('Snippet') expect(@emoji.awardable_id).to eq(80) end end @@ -163,51 +165,51 @@ describe '.note_award_emoji' do context 'when issue note award emoji' do before do - stub_get("/projects/1/issues/80/notes/1/award_emoji/4", "note_award_emoji") + stub_get('/projects/1/issues/80/notes/1/award_emoji/4', 'note_award_emoji') @note_emoji = Gitlab.note_award_emoji(1, 80, 'issue', 1, 4) end - it "gets the correct resource" do - expect(a_get("/projects/1/issues/80/notes/1/award_emoji/4")).to have_been_made - end - - it "returns information about an issue note award emoji" do + it 'gets the correct resource' do + expect(a_get('/projects/1/issues/80/notes/1/award_emoji/4')).to have_been_made + end + + it 'returns information about an issue note award emoji' do expect(@note_emoji.id).to eq(4) - expect(@note_emoji.awardable_type).to eq("Note") + expect(@note_emoji.awardable_type).to eq('Note') expect(@note_emoji.awardable_id).to eq(1) end end context 'when merge request note award emoji' do before do - stub_get("/projects/1/merge_requests/80/notes/1/award_emoji/4", "note_award_emoji") + stub_get('/projects/1/merge_requests/80/notes/1/award_emoji/4', 'note_award_emoji') @note_emoji = Gitlab.note_award_emoji(1, 80, 'merge_request', 1, 4) end - it "gets the correct resource" do - expect(a_get("/projects/1/merge_requests/80/notes/1/award_emoji/4")).to have_been_made - end - - it "returns information about a merge request note award emoji" do + it 'gets the correct resource' do + expect(a_get('/projects/1/merge_requests/80/notes/1/award_emoji/4')).to have_been_made + end + + it 'returns information about a merge request note award emoji' do expect(@note_emoji.id).to eq(4) - expect(@note_emoji.awardable_type).to eq("Note") + expect(@note_emoji.awardable_type).to eq('Note') expect(@note_emoji.awardable_id).to eq(1) end end context 'when snippet note award emoji' do before do - stub_get("/projects/1/snippets/80/notes/1/award_emoji/4", "note_award_emoji") + stub_get('/projects/1/snippets/80/notes/1/award_emoji/4', 'note_award_emoji') @note_emoji = Gitlab.note_award_emoji(1, 80, 'snippet', 1, 4) end - it "gets the correct resource" do - expect(a_get("/projects/1/snippets/80/notes/1/award_emoji/4")).to have_been_made - end - - it "returns information about a snippet note award emoji" do + it 'gets the correct resource' do + expect(a_get('/projects/1/snippets/80/notes/1/award_emoji/4')).to have_been_made + end + + it 'returns information about a snippet note award emoji' do expect(@note_emoji.id).to eq(4) - expect(@note_emoji.awardable_type).to eq("Note") + expect(@note_emoji.awardable_type).to eq('Note') expect(@note_emoji.awardable_id).to eq(1) end end @@ -216,16 +218,16 @@ describe '.create_award_emoji' do context 'when issue award emoji' do before do - stub_post("/projects/1/issues/80/award_emoji", "issue_award_emoji") - @emoji = Gitlab.create_award_emoji(1, 80, "issue", "blowfish") - end - - it "gets the correct resource" do - expect(a_post("/projects/1/issues/80/award_emoji"). - with(body: { name: 'blowfish' })).to have_been_made - end - - it "returns correct information about the created issue award emoji" do + stub_post('/projects/1/issues/80/award_emoji', 'issue_award_emoji') + @emoji = Gitlab.create_award_emoji(1, 80, 'issue', 'blowfish') + end + + it 'gets the correct resource' do + expect(a_post('/projects/1/issues/80/award_emoji') + .with(body: { name: 'blowfish' })).to have_been_made + end + + it 'returns correct information about the created issue award emoji' do expect(@emoji.name).to eq('blowfish') expect(@emoji.awardable_type).to eq('Issue') end @@ -233,16 +235,16 @@ context 'when merge request award emoji' do before do - stub_post("/projects/1/merge_requests/80/award_emoji", "merge_request_award_emoji") - @emoji = Gitlab.create_award_emoji(1, 80, "merge_request", "blowfish") - end - - it "gets the correct resource" do - expect(a_post("/projects/1/merge_requests/80/award_emoji"). - with(body: { name: 'blowfish' })).to have_been_made - end - - it "returns correct information about the created merge request award emoji" do + stub_post('/projects/1/merge_requests/80/award_emoji', 'merge_request_award_emoji') + @emoji = Gitlab.create_award_emoji(1, 80, 'merge_request', 'blowfish') + end + + it 'gets the correct resource' do + expect(a_post('/projects/1/merge_requests/80/award_emoji') + .with(body: { name: 'blowfish' })).to have_been_made + end + + it 'returns correct information about the created merge request award emoji' do expect(@emoji.name).to eq('blowfish') expect(@emoji.awardable_type).to eq('MergeRequest') end @@ -250,16 +252,16 @@ context 'when snippet award emoji' do before do - stub_post("/projects/1/snippets/80/award_emoji", "snippet_award_emoji") - @emoji = Gitlab.create_award_emoji(1, 80, "snippet", "blowfish") - end - - it "gets the correct resource" do - expect(a_post("/projects/1/snippets/80/award_emoji"). - with(body: { name: 'blowfish' })).to have_been_made - end - - it "returns correct information about the created snippet award emoji" do + stub_post('/projects/1/snippets/80/award_emoji', 'snippet_award_emoji') + @emoji = Gitlab.create_award_emoji(1, 80, 'snippet', 'blowfish') + end + + it 'gets the correct resource' do + expect(a_post('/projects/1/snippets/80/award_emoji') + .with(body: { name: 'blowfish' })).to have_been_made + end + + it 'returns correct information about the created snippet award emoji' do expect(@emoji.name).to eq('blowfish') expect(@emoji.awardable_type).to eq('Snippet') end @@ -269,16 +271,16 @@ describe '.create_note_award_emoji' do context 'when issue note award emoji' do before do - stub_post("/projects/1/issues/80/notes/1/award_emoji", "note_award_emoji") - @note_emoji = Gitlab.create_note_award_emoji(1, 80, "issue", 1, "mood_bubble_lightning") - end - - it "gets the correct resource" do - expect(a_post("/projects/1/issues/80/notes/1/award_emoji"). - with(body: { name: 'mood_bubble_lightning' })).to have_been_made - end - - it "returns correct information about the created issue note award emoji" do + stub_post('/projects/1/issues/80/notes/1/award_emoji', 'note_award_emoji') + @note_emoji = Gitlab.create_note_award_emoji(1, 80, 'issue', 1, 'mood_bubble_lightning') + end + + it 'gets the correct resource' do + expect(a_post('/projects/1/issues/80/notes/1/award_emoji') + .with(body: { name: 'mood_bubble_lightning' })).to have_been_made + end + + it 'returns correct information about the created issue note award emoji' do expect(@note_emoji.name).to eq('mood_bubble_lightning') expect(@note_emoji.awardable_type).to eq('Note') end @@ -286,16 +288,16 @@ context 'when merge request note award emoji' do before do - stub_post("/projects/1/merge_requests/80/notes/1/award_emoji", "note_award_emoji") - @note_emoji = Gitlab.create_note_award_emoji(1, 80, "merge_request", 1, "mood_bubble_lightning") - end - - it "gets the correct resource" do - expect(a_post("/projects/1/merge_requests/80/notes/1/award_emoji"). - with(body: { name: 'mood_bubble_lightning' })).to have_been_made - end - - it "returns correct information about the created merge request note award emoji" do + stub_post('/projects/1/merge_requests/80/notes/1/award_emoji', 'note_award_emoji') + @note_emoji = Gitlab.create_note_award_emoji(1, 80, 'merge_request', 1, 'mood_bubble_lightning') + end + + it 'gets the correct resource' do + expect(a_post('/projects/1/merge_requests/80/notes/1/award_emoji') + .with(body: { name: 'mood_bubble_lightning' })).to have_been_made + end + + it 'returns correct information about the created merge request note award emoji' do expect(@note_emoji.name).to eq('mood_bubble_lightning') expect(@note_emoji.awardable_type).to eq('Note') end @@ -303,16 +305,16 @@ context 'when snippet note award emoji' do before do - stub_post("/projects/1/snippets/80/notes/1/award_emoji", "note_award_emoji") - @note_emoji = Gitlab.create_note_award_emoji(1, 80, "snippet", 1, "mood_bubble_lightning") - end - - it "gets the correct resource" do - expect(a_post("/projects/1/snippets/80/notes/1/award_emoji"). - with(body: { name: 'mood_bubble_lightning' })).to have_been_made - end - - it "returns correct information about the created snippet note award emoji" do + stub_post('/projects/1/snippets/80/notes/1/award_emoji', 'note_award_emoji') + @note_emoji = Gitlab.create_note_award_emoji(1, 80, 'snippet', 1, 'mood_bubble_lightning') + end + + it 'gets the correct resource' do + expect(a_post('/projects/1/snippets/80/notes/1/award_emoji') + .with(body: { name: 'mood_bubble_lightning' })).to have_been_made + end + + it 'returns correct information about the created snippet note award emoji' do expect(@note_emoji.name).to eq('mood_bubble_lightning') expect(@note_emoji.awardable_type).to eq('Note') end @@ -322,34 +324,34 @@ describe '.delete_award_emoji' do context 'when issue award emoji' do before do - stub_delete("/projects/1/issues/80/award_emoji/4", "issue_award_emoji") - @emoji = Gitlab.delete_award_emoji(1, 80, "issue", 4) - end - - it "gets the correct resource" do - expect(a_delete("/projects/1/issues/80/award_emoji/4")).to have_been_made + stub_delete('/projects/1/issues/80/award_emoji/4', 'issue_award_emoji') + @emoji = Gitlab.delete_award_emoji(1, 80, 'issue', 4) + end + + it 'gets the correct resource' do + expect(a_delete('/projects/1/issues/80/award_emoji/4')).to have_been_made end end context 'when merge request award emoji' do before do - stub_delete("/projects/1/merge_requests/80/award_emoji/4", "merge_request_award_emoji") - @emoji = Gitlab.delete_award_emoji(1, 80, "merge_request", 4) - end - - it "gets the correct resource" do - expect(a_delete("/projects/1/merge_requests/80/award_emoji/4")).to have_been_made + stub_delete('/projects/1/merge_requests/80/award_emoji/4', 'merge_request_award_emoji') + @emoji = Gitlab.delete_award_emoji(1, 80, 'merge_request', 4) + end + + it 'gets the correct resource' do + expect(a_delete('/projects/1/merge_requests/80/award_emoji/4')).to have_been_made end end context 'when snippet award emoji' do before do - stub_delete("/projects/1/snippets/80/award_emoji/4", "snippet_award_emoji") - @emoji = Gitlab.delete_award_emoji(1, 80, "snippet", 4) - end - - it "gets the correct resource" do - expect(a_delete("/projects/1/snippets/80/award_emoji/4")).to have_been_made + stub_delete('/projects/1/snippets/80/award_emoji/4', 'snippet_award_emoji') + @emoji = Gitlab.delete_award_emoji(1, 80, 'snippet', 4) + end + + it 'gets the correct resource' do + expect(a_delete('/projects/1/snippets/80/award_emoji/4')).to have_been_made end end end @@ -357,34 +359,34 @@ describe '.delete_note_award_emoji' do context 'when issue note award emoji' do before do - stub_delete("/projects/1/issues/80/notes/1/award_emoji/4", "note_award_emoji") - @note_emoji = Gitlab.delete_note_award_emoji(1, 80, "issue", 1, 4) - end - - it "gets the correct resource" do - expect(a_delete("/projects/1/issues/80/notes/1/award_emoji/4")).to have_been_made + stub_delete('/projects/1/issues/80/notes/1/award_emoji/4', 'note_award_emoji') + @note_emoji = Gitlab.delete_note_award_emoji(1, 80, 'issue', 1, 4) + end + + it 'gets the correct resource' do + expect(a_delete('/projects/1/issues/80/notes/1/award_emoji/4')).to have_been_made end end context 'when merge request note award emoji' do before do - stub_delete("/projects/1/merge_requests/80/notes/1/award_emoji/4", "note_award_emoji") - @note_emoji = Gitlab.delete_note_award_emoji(1, 80, "merge_request", 1, 4) - end - - it "gets the correct resource" do - expect(a_delete("/projects/1/merge_requests/80/notes/1/award_emoji/4")).to have_been_made + stub_delete('/projects/1/merge_requests/80/notes/1/award_emoji/4', 'note_award_emoji') + @note_emoji = Gitlab.delete_note_award_emoji(1, 80, 'merge_request', 1, 4) + end + + it 'gets the correct resource' do + expect(a_delete('/projects/1/merge_requests/80/notes/1/award_emoji/4')).to have_been_made end end context 'when snippet note award emoji' do before do - stub_delete("/projects/1/snippets/80/notes/1/award_emoji/4", "note_award_emoji") - @note_emoji = Gitlab.delete_note_award_emoji(1, 80, "snippet", 1, 4) - end - - it "gets the correct resource" do - expect(a_delete("/projects/1/snippets/80/notes/1/award_emoji/4")).to have_been_made + stub_delete('/projects/1/snippets/80/notes/1/award_emoji/4', 'note_award_emoji') + @note_emoji = Gitlab.delete_note_award_emoji(1, 80, 'snippet', 1, 4) + end + + it 'gets the correct resource' do + expect(a_delete('/projects/1/snippets/80/notes/1/award_emoji/4')).to have_been_made end end end diff --git a/spec/gitlab/client/boards_spec.rb b/spec/gitlab/client/boards_spec.rb index bbfed54..551c328 100644 --- a/spec/gitlab/client/boards_spec.rb +++ b/spec/gitlab/client/boards_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".boards" do + describe '.boards' do before do - stub_get("/projects/3/boards", "boards") + stub_get('/projects/3/boards', 'boards') @boards = Gitlab.boards(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/boards")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/boards')).to have_been_made end it "returns a paginated response of project's boards" do @@ -16,14 +18,14 @@ end end - describe ".board_lists" do + describe '.board_lists' do before do - stub_get("/projects/3/boards/1/lists", "board_lists") + stub_get('/projects/3/boards/1/lists', 'board_lists') @board_lists = Gitlab.board_lists(3, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/boards/1/lists")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/boards/1/lists')).to have_been_made end it "returns a paginated response of board's lists" do @@ -32,62 +34,62 @@ end end - describe ".board_list" do + describe '.board_list' do before do - stub_get("/projects/3/boards/1/lists/1", "board_list") + stub_get('/projects/3/boards/1/lists/1', 'board_list') @board_list = Gitlab.board_list(3, 1, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/boards/1/lists/1")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/boards/1/lists/1')).to have_been_made end - it "returns information about the list" do + it 'returns information about the list' do expect(@board_list.id).to eq(1) end end - describe ".create_board_list" do + describe '.create_board_list' do before do - stub_post("/projects/3/boards/1/lists", "board_list") + stub_post('/projects/3/boards/1/lists', 'board_list') @board_list = Gitlab.create_board_list(3, 1, 4) end - it "gets the correct resource" do - expect(a_post("/projects/3/boards/1/lists")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/boards/1/lists')).to have_been_made end - it "returns information about a created board" do + it 'returns information about a created board' do expect(@board_list.position).to eq(1) end end - describe ".edit_board_list" do + describe '.edit_board_list' do before do - stub_put("/projects/3/boards/1/lists/1", "board_list") + stub_put('/projects/3/boards/1/lists/1', 'board_list') @board_list = Gitlab.edit_board_list(3, 1, 1, 3) end - it "gets the correct resource" do - expect(a_put("/projects/3/boards/1/lists/1")).to have_been_made + it 'gets the correct resource' do + expect(a_put('/projects/3/boards/1/lists/1')).to have_been_made end - it "returns information about an edited board" do + it 'returns information about an edited board' do expect(@board_list.id).to eq(1) end end - describe ".delete_board_list" do + describe '.delete_board_list' do before do - stub_delete("/projects/3/boards/1/lists/1", "board_list") + stub_delete('/projects/3/boards/1/lists/1', 'board_list') @board_list = Gitlab.delete_board_list(3, 1, 1) end - it "gets the correct resource" do - expect(a_delete("/projects/3/boards/1/lists/1")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/boards/1/lists/1')).to have_been_made end - it "returns information about the deleted board list" do + it 'returns information about the deleted board list' do expect(@board_list.id).to eq(1) end end diff --git a/spec/gitlab/client/branches_spec.rb b/spec/gitlab/client/branches_spec.rb index 423d5c7..fdf9ccc 100644 --- a/spec/gitlab/client/branches_spec.rb +++ b/spec/gitlab/client/branches_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do @@ -5,114 +7,164 @@ it { is_expected.to respond_to :repo_branch } it { is_expected.to respond_to :repo_protect_branch } it { is_expected.to respond_to :repo_unprotect_branch } + it { is_expected.to respond_to :repo_create_branch } + it { is_expected.to respond_to :repo_delete_branch } + it { is_expected.to respond_to :repo_delete_merged_branches } + it { is_expected.to respond_to :repo_protected_branches } + it { is_expected.to respond_to :repo_protected_branch } - describe ".branches" do + describe '.branches' do before do - stub_get("/projects/3/repository/branches", "branches") + stub_get('/projects/3/repository/branches', 'branches') @branches = Gitlab.branches(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/branches")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/branches')).to have_been_made end - it "returns a paginated response of repository branches" do + it 'returns a paginated response of repository branches' do expect(@branches).to be_a Gitlab::PaginatedResponse - expect(@branches.first.name).to eq("api") + expect(@branches.first.name).to eq('api') end end - describe ".branch" do + describe '.branch' do before do - stub_get("/projects/3/repository/branches/api", "branch") - @branch = Gitlab.branch(3, "api") + stub_get('/projects/3/repository/branches/api', 'branch') + @branch = Gitlab.branch(3, 'api') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/branches/api")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/branches/api')).to have_been_made end - it "returns information about a repository branch" do - expect(@branch.name).to eq("api") + it 'returns information about a repository branch' do + expect(@branch.name).to eq('api') end end - describe ".protect_branch" do + describe '.protect_branch' do before do - stub_post("/projects/3/protected_branches", "branch") + stub_post('/projects/3/protected_branches', 'branch') end - context "without options" do + context 'without options' do before do - @branch = Gitlab.protect_branch(3, "api") + @branch = Gitlab.protect_branch(3, 'api') end - it "updates the correct resource" do - expect(a_post("/projects/3/protected_branches")).to have_been_made + it 'updates the correct resource' do + expect(a_post('/projects/3/protected_branches')).to have_been_made end - it "returns information about a protected repository branch" do - expect(@branch.name).to eq("api") + it 'returns information about a protected repository branch' do + expect(@branch.name).to eq('api') end end - context "with options" do + context 'with options' do before do - @branch = Gitlab.protect_branch(3, "api", developers_can_push: true) + @branch = Gitlab.protect_branch(3, 'api', developers_can_push: true) end - it "updates the correct resource with the correct options" do + it 'updates the correct resource with the correct options' do expect( - a_post("/projects/3/protected_branches").with(body: { name: "api", developers_can_push: 'true' }) + a_post('/projects/3/protected_branches').with(body: { name: 'api', developers_can_push: 'true' }) ).to have_been_made end end end - describe ".unprotect_branch" do + describe '.unprotect_branch' do before do - stub_delete("/projects/3/protected_branches/api","branch") - @branch = Gitlab.unprotect_branch(3, "api") + stub_delete('/projects/3/protected_branches/api', 'branch') + @branch = Gitlab.unprotect_branch(3, 'api') end - it "gets the correct resource" do - expect(a_delete("/projects/3/protected_branches/api")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/protected_branches/api')).to have_been_made end - it "returns information about an unprotected repository branch" do - expect(@branch.name).to eq("api") + it 'returns information about an unprotected repository branch' do + expect(@branch.name).to eq('api') end end - describe ".create_branch" do + describe '.create_branch' do before do - stub_post("/projects/3/repository/branches", "branch").with(query: { branch: 'api', ref: "master"}) - @branch = Gitlab.create_branch(3, "api", "master") + stub_post('/projects/3/repository/branches', 'branch').with(query: { branch: 'api', ref: 'master' }) + @branch = Gitlab.create_branch(3, 'api', 'master') end - it "gets the correct resource" do + it 'gets the correct resource' do expect( - a_post("/projects/3/repository/branches").with(query: { branch: 'api', ref: "master"}) + a_post('/projects/3/repository/branches').with(query: { branch: 'api', ref: 'master' }) ).to have_been_made end - it "returns information about a new repository branch" do - expect(@branch.name).to eq("api") + it 'returns information about a new repository branch' do + expect(@branch.name).to eq('api') end end - describe ".delete_branch" do + describe '.delete_branch' do before do - stub_delete("/projects/3/repository/branches/api", "branch_delete") - @branch = Gitlab.delete_branch(3, "api") + stub_delete('/projects/3/repository/branches/api', 'branch_delete') + @branch = Gitlab.delete_branch(3, 'api') end - it "gets the correct resource" do - expect(a_delete("/projects/3/repository/branches/api")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/repository/branches/api')).to have_been_made end - it "returns information about the deleted repository branch" do - expect(@branch.branch_name).to eq("api") + it 'returns information about the deleted repository branch' do + expect(@branch.branch_name).to eq('api') + end + end + + describe '.delete_merged_branches' do + before do + stub_delete('/projects/3/repository/merged_branches', 'empty') + @branch = Gitlab.delete_merged_branches(3) + end + + it 'gets the correct resource' do + expect(a_delete('/projects/3/repository/merged_branches')).to have_been_made + end + end + + describe '.protected_branches' do + before do + stub_get('/projects/3/protected_branches', 'protected_branches') + @branches = Gitlab.protected_branches(3) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/protected_branches')).to have_been_made + end + + it 'returns information about the protected_branches' do + expect(@branches).to be_a Gitlab::PaginatedResponse + expect(@branches.first.merge_access_levels).to be_a Array + expect(@branches.first.push_access_levels).to be_a Array + end + end + + describe '.protected_branch' do + before do + stub_get('/projects/3/protected_branches/master', 'protected_branch') + @branch = Gitlab.protected_branch(3, 'master') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/protected_branches/master')).to have_been_made + end + + it 'returns correct information about the protected_branch' do + expect(@branch.name).to eq 'master' + expect(@branch.merge_access_levels).to be_a Array + expect(@branch.push_access_levels).to be_a Array end end end diff --git a/spec/gitlab/client/broadcast_messages_spec.rb b/spec/gitlab/client/broadcast_messages_spec.rb new file mode 100644 index 0000000..395b90e --- /dev/null +++ b/spec/gitlab/client/broadcast_messages_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.broadcast_messages' do + before do + stub_get('/broadcast_messages', 'broadcast_messages') + @broadcast_messages = Gitlab.broadcast_messages + end + + it 'gets the correct resource' do + expect(a_get('/broadcast_messages')).to have_been_made + end + + it 'returns a paginated response of broadcast messages' do + expect(@broadcast_messages).to be_a Gitlab::PaginatedResponse + end + end + + describe '.broadcast_message' do + before do + stub_get('/broadcast_messages/1', 'broadcast_message') + @broadcast_message = Gitlab.broadcast_message(1) + end + + it 'gets the correct resource' do + expect(a_get('/broadcast_messages/1')).to have_been_made + end + + it 'returns correct information about the broadcast message' do + expect(@broadcast_message.id).to eq 1 + end + end + + describe '.create_broadcast_message' do + before do + stub_post('/broadcast_messages', 'broadcast_message') + @broadcast_message = Gitlab.create_broadcast_message('Deploy in progress', color: '#cecece') + end + + it 'gets the correct resource' do + expect(a_post('/broadcast_messages') + .with(body: { message: 'Deploy in progress', color: '#cecece' })).to have_been_made + end + + it 'returns correct information about the broadcast message created' do + expect(@broadcast_message.message).to eq 'Deploy in progress' + expect(@broadcast_message.color).to eq '#cecece' + end + end + + describe '.edit_broadcast_message' do + before do + stub_put('/broadcast_messages/1', 'broadcast_message') + @broadcast_message = Gitlab.edit_broadcast_message(1, font: '#FFFFFF') + end + + it 'gets the correct resource' do + expect(a_put('/broadcast_messages/1') + .with(body: { font: '#FFFFFF' })).to have_been_made + end + + it 'returns correct information about the edited broadcast message' do + expect(@broadcast_message.font).to eq '#FFFFFF' + end + end + + describe '.delete_broadcast_message' do + before do + stub_delete('/broadcast_messages/1', 'empty') + @broadcast_message = Gitlab.delete_broadcast_message(1) + end + + it 'gets the correct resource' do + expect(a_delete('/broadcast_messages/1')).to have_been_made + end + end +end diff --git a/spec/gitlab/client/build_variables_spec.rb b/spec/gitlab/client/build_variables_spec.rb index 7c50a40..77672f5 100644 --- a/spec/gitlab/client/build_variables_spec.rb +++ b/spec/gitlab/client/build_variables_spec.rb @@ -1,169 +1,171 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".variables" do + describe '.variables' do before do - stub_get("/projects/3/variables", "variables") + stub_get('/projects/3/variables', 'variables') @variables = Gitlab.variables(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/variables")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/variables')).to have_been_made end it "returns an array of project's variables" do expect(@variables).to be_a Gitlab::PaginatedResponse - expect(@variables.first.key).to eq("TEST_VARIABLE_1") - expect(@variables.first.value).to eq("TEST_1") + expect(@variables.first.key).to eq('TEST_VARIABLE_1') + expect(@variables.first.value).to eq('TEST_1') end end - describe ".variable" do + describe '.variable' do before do - stub_get("/projects/3/variables/VARIABLE", "variable") - @variable = Gitlab.variable(3, "VARIABLE") + stub_get('/projects/3/variables/VARIABLE', 'variable') + @variable = Gitlab.variable(3, 'VARIABLE') end - it "gets the correct resource" do - expect(a_get("/projects/3/variables/VARIABLE")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/variables/VARIABLE')).to have_been_made end - it "returns information about a variable" do - expect(@variable.key).to eq("VARIABLE") - expect(@variable.value).to eq("the value") + it 'returns information about a variable' do + expect(@variable.key).to eq('VARIABLE') + expect(@variable.value).to eq('the value') end end - describe ".create_variable" do + describe '.create_variable' do before do - stub_post("/projects/3/variables", "variable") - @variable = Gitlab.create_variable(3, "NEW_VARIABLE", "new value") + stub_post('/projects/3/variables', 'variable') + @variable = Gitlab.create_variable(3, 'NEW_VARIABLE', 'new value') end - it "gets the correct resource" do - body = { key: "NEW_VARIABLE", value: "new value" } - expect(a_post("/projects/3/variables").with(body: body)).to have_been_made + it 'gets the correct resource' do + body = { key: 'NEW_VARIABLE', value: 'new value' } + expect(a_post('/projects/3/variables').with(body: body)).to have_been_made end - it "returns information about a new variable" do - expect(@variable.key).to eq("VARIABLE") - expect(@variable.value).to eq("the value") + it 'returns information about a new variable' do + expect(@variable.key).to eq('VARIABLE') + expect(@variable.value).to eq('the value') end end - describe ".update_variable" do + describe '.update_variable' do before do - stub_put("/projects/3/variables/UPD_VARIABLE", "variable") - @variable = Gitlab.update_variable(3, "UPD_VARIABLE", "updated value") + stub_put('/projects/3/variables/UPD_VARIABLE', 'variable') + @variable = Gitlab.update_variable(3, 'UPD_VARIABLE', 'updated value') end - it "puts the correct resource" do - body = { value: "updated value" } - expect(a_put("/projects/3/variables/UPD_VARIABLE").with(body: body)).to have_been_made + it 'puts the correct resource' do + body = { value: 'updated value' } + expect(a_put('/projects/3/variables/UPD_VARIABLE').with(body: body)).to have_been_made end - it "returns information about an updated variable" do - expect(@variable.key).to eq("VARIABLE") - expect(@variable.value).to eq("the value") + it 'returns information about an updated variable' do + expect(@variable.key).to eq('VARIABLE') + expect(@variable.value).to eq('the value') end end - describe ".remove_variable" do + describe '.remove_variable' do before do - stub_delete("/projects/3/variables/DEL_VARIABLE", "variable") - @variable = Gitlab.remove_variable(3, "DEL_VARIABLE") + stub_delete('/projects/3/variables/DEL_VARIABLE', 'variable') + @variable = Gitlab.remove_variable(3, 'DEL_VARIABLE') end - it "gets the correct resource" do - expect(a_delete("/projects/3/variables/DEL_VARIABLE")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/variables/DEL_VARIABLE')).to have_been_made end - it "returns information about a deleted variable" do - expect(@variable.key).to eq("VARIABLE") - expect(@variable.value).to eq("the value") + it 'returns information about a deleted variable' do + expect(@variable.key).to eq('VARIABLE') + expect(@variable.value).to eq('the value') end end - describe ".group_variables" do + describe '.group_variables' do before do - stub_get("/groups/3/variables", "variables") + stub_get('/groups/3/variables', 'variables') @variables = Gitlab.group_variables(3) end - it "gets the correct resource" do - expect(a_get("/groups/3/variables")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/groups/3/variables')).to have_been_made end it "returns an array of group's variables" do expect(@variables).to be_a Gitlab::PaginatedResponse - expect(@variables.first.key).to eq("TEST_VARIABLE_1") - expect(@variables.first.value).to eq("TEST_1") + expect(@variables.first.key).to eq('TEST_VARIABLE_1') + expect(@variables.first.value).to eq('TEST_1') end end - describe ".group_variable" do + describe '.group_variable' do before do - stub_get("/groups/3/variables/VARIABLE", "variable") - @variable = Gitlab.group_variable(3, "VARIABLE") + stub_get('/groups/3/variables/VARIABLE', 'variable') + @variable = Gitlab.group_variable(3, 'VARIABLE') end - it "gets the correct resource" do - expect(a_get("/groups/3/variables/VARIABLE")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/groups/3/variables/VARIABLE')).to have_been_made end - it "returns information about a variable" do - expect(@variable.key).to eq("VARIABLE") - expect(@variable.value).to eq("the value") + it 'returns information about a variable' do + expect(@variable.key).to eq('VARIABLE') + expect(@variable.value).to eq('the value') end end - describe ".create_group_variable" do + describe '.create_group_variable' do before do - stub_post("/groups/3/variables", "variable") - @variable = Gitlab.create_group_variable(3, "NEW_VARIABLE", "new value") + stub_post('/groups/3/variables', 'variable') + @variable = Gitlab.create_group_variable(3, 'NEW_VARIABLE', 'new value') end - it "gets the correct resource" do - body = { key: "NEW_VARIABLE", value: "new value" } - expect(a_post("/groups/3/variables").with(body: body)).to have_been_made + it 'gets the correct resource' do + body = { key: 'NEW_VARIABLE', value: 'new value' } + expect(a_post('/groups/3/variables').with(body: body)).to have_been_made end - it "returns information about a new variable" do - expect(@variable.key).to eq("VARIABLE") - expect(@variable.value).to eq("the value") + it 'returns information about a new variable' do + expect(@variable.key).to eq('VARIABLE') + expect(@variable.value).to eq('the value') end end - describe ".update_group_variable" do + describe '.update_group_variable' do before do - stub_put("/groups/3/variables/UPD_VARIABLE", "variable") - @variable = Gitlab.update_group_variable(3, "UPD_VARIABLE", "updated value") + stub_put('/groups/3/variables/UPD_VARIABLE', 'variable') + @variable = Gitlab.update_group_variable(3, 'UPD_VARIABLE', 'updated value') end - it "puts the correct resource" do - body = { value: "updated value" } - expect(a_put("/groups/3/variables/UPD_VARIABLE").with(body: body)).to have_been_made + it 'puts the correct resource' do + body = { value: 'updated value' } + expect(a_put('/groups/3/variables/UPD_VARIABLE').with(body: body)).to have_been_made end - it "returns information about an updated variable" do - expect(@variable.key).to eq("VARIABLE") - expect(@variable.value).to eq("the value") + it 'returns information about an updated variable' do + expect(@variable.key).to eq('VARIABLE') + expect(@variable.value).to eq('the value') end end - describe ".remove_group_variable" do + describe '.remove_group_variable' do before do - stub_delete("/groups/3/variables/DEL_VARIABLE", "variable") - @variable = Gitlab.remove_group_variable(3, "DEL_VARIABLE") + stub_delete('/groups/3/variables/DEL_VARIABLE', 'variable') + @variable = Gitlab.remove_group_variable(3, 'DEL_VARIABLE') end - it "gets the correct resource" do - expect(a_delete("/groups/3/variables/DEL_VARIABLE")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/groups/3/variables/DEL_VARIABLE')).to have_been_made end - it "returns information about a deleted variable" do - expect(@variable.key).to eq("VARIABLE") - expect(@variable.value).to eq("the value") + it 'returns information about a deleted variable' do + expect(@variable.key).to eq('VARIABLE') + expect(@variable.value).to eq('the value') end end end diff --git a/spec/gitlab/client/builds_spec.rb b/spec/gitlab/client/builds_spec.rb index 1b74e7e..46551cf 100644 --- a/spec/gitlab/client/builds_spec.rb +++ b/spec/gitlab/client/builds_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".builds" do + describe '.builds' do before do - stub_get("/projects/3/builds", "builds") + stub_get('/projects/3/builds', 'builds') @builds = Gitlab.builds(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/builds")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/builds')).to have_been_made end it "returns a paginated response of project's builds" do @@ -16,133 +18,131 @@ end end - describe ".build" do + describe '.build' do before do - stub_get("/projects/3/builds/8", "build") + stub_get('/projects/3/builds/8', 'build') @build = Gitlab.build(3, 8) end - it "gets the correct resource" do - expect(a_get("/projects/3/builds/8")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/builds/8')).to have_been_made end - it "returns a single build" do + it 'returns a single build' do expect(@build).to be_a Gitlab::ObjectifiedHash end - it "returns information about a build" do + it 'returns information about a build' do expect(@build.id).to eq(8) - expect(@build.user.name).to eq("John Smith") + expect(@build.user.name).to eq('John Smith') end end - describe ".build_artifacts" do - context "when successful request" do + describe '.build_artifacts' do + context 'when successful request' do before do fixture = load_fixture('build_artifacts') fixture.set_encoding(Encoding::ASCII_8BIT) - stub_request(:get, "#{Gitlab.endpoint}/projects/3/builds/8/artifacts"). - with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }). - to_return(body: fixture.read, headers: { 'Content-Disposition' => "attachment; filename=artifacts.zip" }) + stub_request(:get, "#{Gitlab.endpoint}/projects/3/builds/8/artifacts") + .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }) + .to_return(body: fixture.read, headers: { 'Content-Disposition' => 'attachment; filename=artifacts.zip' }) @build_artifacts = Gitlab.build_artifacts(3, 8) end - it "gets the correct resource" do - expect(a_get("/projects/3/builds/8/artifacts")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/builds/8/artifacts')).to have_been_made end - it "returns a FileResponse" do + it 'returns a FileResponse' do expect(@build_artifacts).to be_a Gitlab::FileResponse end - it "returns a file with filename" do - expect(@build_artifacts.filename).to eq "artifacts.zip" + it 'returns a file with filename' do + expect(@build_artifacts.filename).to eq 'artifacts.zip' end end - context "when bad request" do - it "throws an exception" do - stub_get("/projects/3/builds/8/artifacts", "error_project_not_found", 404) - 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") + context 'when bad request' do + it 'throws an exception' do + stub_get('/projects/3/builds/8/artifacts', 'error_project_not_found', 404) + 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") end end end - describe ".builds_commits" do + describe '.builds_commits' do before do - stub_get("/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds", "builds_commits") - @builds_commits = Gitlab.commit_builds(3, "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd") + stub_get('/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds', 'builds_commits') + @builds_commits = Gitlab.commit_builds(3, '0ff3ae198f8601a285adcf5c0fff204ee6fba5fd') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds')).to have_been_made end - it "returns a paginated response of commit builds" do + it 'returns a paginated response of commit builds' do expect(@builds_commits).to be_a Gitlab::PaginatedResponse end - it "returns information about the builds" do + it 'returns information about the builds' do expect(@builds_commits.count).to eq(2) end end - - - describe ".build_cancel" do + describe '.build_cancel' do before do - stub_post("/projects/3/builds/8/cancel", "build_cancel") + stub_post('/projects/3/builds/8/cancel', 'build_cancel') @build_cancel = Gitlab.build_cancel(3, 8) end - it "gets the correct resource" do - expect(a_post("/projects/3/builds/8/cancel")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/builds/8/cancel')).to have_been_made end - it "returns a single build" do + it 'returns a single build' do expect(@build_cancel).to be_a Gitlab::ObjectifiedHash end - it "returns information about a build" do - expect(@build_cancel.commit.author_name).to eq("John Smith") + it 'returns information about a build' do + expect(@build_cancel.commit.author_name).to eq('John Smith') end end - describe ".build_retry" do + describe '.build_retry' do before do - stub_post("/projects/3/builds/69/retry", "build_retry") + stub_post('/projects/3/builds/69/retry', 'build_retry') @build_retry = Gitlab.build_retry(3, 69) end - it "gets the correct resource" do - expect(a_post("/projects/3/builds/69/retry")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/builds/69/retry')).to have_been_made end - it "returns a single build" do + it 'returns a single build' do expect(@build_retry).to be_a Gitlab::ObjectifiedHash end - it "returns information about a build" do - expect(@build_retry.commit.author_name).to eq("John Smith") + it 'returns information about a build' do + expect(@build_retry.commit.author_name).to eq('John Smith') end end - describe ".build_erase" do + describe '.build_erase' do before do - stub_post("/projects/3/builds/69/erase", "build_erase") + stub_post('/projects/3/builds/69/erase', 'build_erase') @build_retry = Gitlab.build_erase(3, 69) end - it "gets the correct resource" do - expect(a_post("/projects/3/builds/69/erase")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/builds/69/erase')).to have_been_made end - it "returns a single build" do + it 'returns a single build' do expect(@build_retry).to be_a Gitlab::ObjectifiedHash end - it "returns information about a build" do - expect(@build_retry.commit.author_name).to eq("John Smith") + it 'returns information about a build' do + expect(@build_retry.commit.author_name).to eq('John Smith') end end end diff --git a/spec/gitlab/client/client_spec.rb b/spec/gitlab/client/client_spec.rb index ea0e8ac..73a7bfd 100644 --- a/spec/gitlab/client/client_spec.rb +++ b/spec/gitlab/client/client_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do diff --git a/spec/gitlab/client/commits_spec.rb b/spec/gitlab/client/commits_spec.rb index 59e25eb..7360185 100644 --- a/spec/gitlab/client/commits_spec.rb +++ b/spec/gitlab/client/commits_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do @@ -10,102 +12,120 @@ it { is_expected.to respond_to :repo_update_commit_status } it { is_expected.to respond_to :repo_commit_merge_requests } - describe ".commits" do - before do - stub_get("/projects/3/repository/commits", "project_commits"). - with(query: { ref_name: "api" }) - @commits = Gitlab.commits(3, ref_name: "api") - end - - it "gets the correct resource" do - expect(a_get("/projects/3/repository/commits"). - with(query: { ref_name: "api" })).to have_been_made - end - - it "returns a paginated response of repository commits" do + describe '.commits' do + before do + stub_get('/projects/3/repository/commits', 'project_commits') + .with(query: { ref_name: 'api' }) + @commits = Gitlab.commits(3, ref_name: 'api') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/commits') + .with(query: { ref_name: 'api' })).to have_been_made + end + + it 'returns a paginated response of repository commits' do expect(@commits).to be_a Gitlab::PaginatedResponse - expect(@commits.first.id).to eq("f7dd067490fe57505f7226c3b54d3127d2f7fd46") - end - end - - describe ".commit" do - before do - stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6", "project_commit") + expect(@commits.first.id).to eq('f7dd067490fe57505f7226c3b54d3127d2f7fd46') + end + end + + describe '.commit' do + before do + stub_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6', 'project_commit') @commit = Gitlab.commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6")). - to have_been_made - end - - it "returns a repository commit" do - expect(@commit.id).to eq("6104942438c14ec7bd21c6cd5bd995272b3faff6") - end - end - - describe ".commit_diff" do - before do - stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff", "project_commit_diff") + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6')) + .to have_been_made + end + + it 'returns a repository commit' do + expect(@commit.id).to eq('6104942438c14ec7bd21c6cd5bd995272b3faff6') + end + end + + describe '.cherry_pick_commit' do + before do + stub_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/cherry_pick', 'project_commit').with(body: { branch: 'master' }) + @cherry_pick_commit = Gitlab.cherry_pick_commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master') + end + + it 'gets the correct resource' do + expect(a_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/cherry_pick') + .with(body: { branch: 'master' })) + .to have_been_made + end + + it 'returns the correct response' do + expect(@cherry_pick_commit).to be_a Gitlab::ObjectifiedHash + expect(@cherry_pick_commit.id).to eq('6104942438c14ec7bd21c6cd5bd995272b3faff6') + end + end + + describe '.commit_diff' do + before do + stub_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff', 'project_commit_diff') @diff = Gitlab.commit_diff(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff")). - to have_been_made - end - - it "returns a diff of a commit" do - expect(@diff.new_path).to eq("doc/update/5.4-to-6.0.md") - end - end - - describe ".commit_comments" do - before do - stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments", "project_commit_comments") + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff')) + .to have_been_made + end + + it 'returns a diff of a commit' do + expect(@diff.new_path).to eq('doc/update/5.4-to-6.0.md') + end + end + + describe '.commit_comments' do + before do + stub_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments', 'project_commit_comments') @commit_comments = Gitlab.commit_comments(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments")). - to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments')) + .to have_been_made end it "returns commit's comments" do expect(@commit_comments).to be_a Gitlab::PaginatedResponse expect(@commit_comments.length).to eq(2) - expect(@commit_comments[0].note).to eq("this is the 1st comment on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6") + expect(@commit_comments[0].note).to eq('this is the 1st comment on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6') expect(@commit_comments[0].author.id).to eq(11) - expect(@commit_comments[1].note).to eq("another discussion point on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6") + expect(@commit_comments[1].note).to eq('another discussion point on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6') expect(@commit_comments[1].author.id).to eq(12) end end - describe ".create_commit_comment" do - before do - stub_post("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments", "project_commit_comment") + describe '.create_commit_comment' do + before do + stub_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments', 'project_commit_comment') @merge_request = Gitlab.create_commit_comment(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'Nice code!') end - it "returns information about the newly created comment" do + it 'returns information about the newly created comment' do expect(@merge_request.note).to eq('Nice code!') expect(@merge_request.author.id).to eq(1) end end - describe ".commit_status" do - before do - stub_get("/projects/6/repository/commits/7d938cb8ac15788d71f4b67c035515a160ea76d8/statuses", 'project_commit_status'). - with(query: { all: 'true' }) + describe '.commit_status' do + before do + stub_get('/projects/6/repository/commits/7d938cb8ac15788d71f4b67c035515a160ea76d8/statuses', 'project_commit_status') + .with(query: { all: 'true' }) @statuses = Gitlab.commit_status(6, '7d938cb8ac15788d71f4b67c035515a160ea76d8', all: true) end - it "gets the correct resource" do - expect(a_get("/projects/6/repository/commits/7d938cb8ac15788d71f4b67c035515a160ea76d8/statuses"). - with(query: { all: true })) - end - - it "gets statuses of a commit" do + it 'gets the correct resource' do + expect(a_get('/projects/6/repository/commits/7d938cb8ac15788d71f4b67c035515a160ea76d8/statuses') + .with(query: { all: true })) + end + + it 'gets statuses of a commit' do expect(@statuses).to be_kind_of Gitlab::PaginatedResponse expect(@statuses.first.sha).to eq('7d938cb8ac15788d71f4b67c035515a160ea76d8') expect(@statuses.first.ref).to eq('decreased-spec') @@ -115,19 +135,19 @@ end end - describe ".update_commit_status" do - before do - stub_post("/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8", 'project_update_commit_status'). - with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' }) + describe '.update_commit_status' do + before do + stub_post('/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8', 'project_update_commit_status') + .with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' }) @status = Gitlab.update_commit_status(6, '7d938cb8ac15788d71f4b67c035515a160ea76d8', 'failed', name: 'test', ref: 'decreased-spec') end - it "gets the correct resource" do - expect(a_post('/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8'). - with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' })) - end - - it "returns information about the newly created status" do + it 'gets the correct resource' do + expect(a_post('/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8') + .with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' })) + end + + it 'returns information about the newly created status' do expect(@status).to be_kind_of Gitlab::ObjectifiedHash expect(@status.id).to eq(498) expect(@status.sha).to eq('7d938cb8ac15788d71f4b67c035515a160ea76d8') @@ -136,13 +156,13 @@ end end - describe ".create_commit" do + describe '.create_commit' do let(:actions) do [ { - action: "create", - file_path: "foo/bar", - content: "some content" + action: 'create', + file_path: 'foo/bar', + content: 'some content' } ] end @@ -158,24 +178,24 @@ end before do - stub_post("/projects/6/repository/commits", 'project_commit_create').with(body: query) - @commit = Gitlab.create_commit(6, 'dev', 'refactors everything', actions, {author_email: 'joe@sample.org', author_name: 'Joe Sample'}) - end - - it "returns id of a created commit" do + stub_post('/projects/6/repository/commits', 'project_commit_create').with(body: query) + @commit = Gitlab.create_commit(6, 'dev', 'refactors everything', actions, author_email: 'joe@sample.org', author_name: 'Joe Sample') + end + + it 'returns id of a created commit' do expect(@commit.id).to eq('ed899a2f4b50b4370feeea94676502b42383c746') end end - describe ".repo_commit_merge_requests" do - before do - stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/merge_requests", "project_commit_merge_requests") + describe '.repo_commit_merge_requests' do + before do + stub_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/merge_requests', 'project_commit_merge_requests') @commit_merge_requests = Gitlab.commit_merge_requests(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/merge_requests")). - to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/merge_requests')) + .to have_been_made end it "returns commit's associated merge_requests" do diff --git a/spec/gitlab/client/deployments_spec.rb b/spec/gitlab/client/deployments_spec.rb index 1557d3c..389477d 100644 --- a/spec/gitlab/client/deployments_spec.rb +++ b/spec/gitlab/client/deployments_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".deployments" do + describe '.deployments' do before do - stub_get("/projects/3/deployments", "deployments") + stub_get('/projects/3/deployments', 'deployments') @deployments = Gitlab.deployments(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/deployments")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/deployments')).to have_been_made end it "returns a paginated response of project's deployments" do @@ -16,23 +18,23 @@ end end - describe ".deployment" do + describe '.deployment' do before do - stub_get("/projects/3/deployments/42", "deployment") + stub_get('/projects/3/deployments/42', 'deployment') @deployment = Gitlab.deployment(3, 42) end - it "gets the correct resource" do - expect(a_get("/projects/3/deployments/42")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/deployments/42')).to have_been_made end - it "returns a single deployment" do + it 'returns a single deployment' do expect(@deployment).to be_a Gitlab::ObjectifiedHash end - it "returns information about an deployment" do + it 'returns information about an deployment' do expect(@deployment.id).to eq(42) - expect(@deployment.deployable.commit.id).to eq("a91957a858320c0e17f3a0eca7cfacbff50ea29a") + expect(@deployment.deployable.commit.id).to eq('a91957a858320c0e17f3a0eca7cfacbff50ea29a') end end end diff --git a/spec/gitlab/client/environments_spec.rb b/spec/gitlab/client/environments_spec.rb index 84ff4e1..f47e2f5 100644 --- a/spec/gitlab/client/environments_spec.rb +++ b/spec/gitlab/client/environments_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".environments" do + describe '.environments' do before do - stub_get("/projects/3/environments", "environments") + stub_get('/projects/3/environments', 'environments') @environments = Gitlab.environments(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/environments")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/environments')).to have_been_made end it "returns a paginated response of project's environments" do @@ -16,117 +18,116 @@ end end - describe ".environment" do + describe '.environment' do before do - stub_get("/projects/3/environments/12", "environment") + stub_get('/projects/3/environments/12', 'environment') @environment = Gitlab.environment(3, 12) end - it "gets the correct resource" do - expect(a_get("/projects/3/environments/12")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/environments/12')).to have_been_made end - it "returns a single environment" do + it 'returns a single environment' do expect(@environment).to be_a Gitlab::ObjectifiedHash end - it "returns information about an environment" do + it 'returns information about an environment' do expect(@environment.id).to eq(12) - expect(@environment.name).to eq("staging") + expect(@environment.name).to eq('staging') end end - describe ".create_environment" do - context "without external_url" do + describe '.create_environment' do + context 'without external_url' do before do - stub_post("/projects/3/environments", "environment") + stub_post('/projects/3/environments', 'environment') @environment = Gitlab.create_environment(3, 'staging') end - it "gets the correct resource" do - expect(a_post("/projects/3/environments").with(body: { name: 'staging' })).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/environments').with(body: { name: 'staging' })).to have_been_made end - it "returns a single environment" do + it 'returns a single environment' do expect(@environment).to be_a Gitlab::ObjectifiedHash end - it "returns information about an environment" do - expect(@environment.name).to eq("staging") + it 'returns information about an environment' do + expect(@environment.name).to eq('staging') end end - context "with external_url" do + context 'with external_url' do before do - stub_post("/projects/3/environments", "environment") - @environment = Gitlab.create_environment(3, 'staging', external_url: "https://staging.example.gitlab.com") + stub_post('/projects/3/environments', 'environment') + @environment = Gitlab.create_environment(3, 'staging', external_url: 'https://staging.example.gitlab.com') end - it "gets the correct resource" do - expect(a_post("/projects/3/environments") - .with(body: { name: 'staging', external_url: "https://staging.example.gitlab.com" })).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/environments') + .with(body: { name: 'staging', external_url: 'https://staging.example.gitlab.com' })).to have_been_made end end end - describe ".edit_environment" do + describe '.edit_environment' do before do - stub_put("/projects/3/environments/12", "environment") - @environment = Gitlab.edit_environment(3, 12, { - name: 'staging', - external_url: "https://staging.example.gitlab.com" - }) + stub_put('/projects/3/environments/12', 'environment') + @environment = Gitlab.edit_environment(3, 12, + name: 'staging', + external_url: 'https://staging.example.gitlab.com') end - it "gets the correct resource" do - expect(a_put("/projects/3/environments/12") - .with(body: { name: 'staging', external_url: "https://staging.example.gitlab.com" })).to have_been_made + it 'gets the correct resource' do + expect(a_put('/projects/3/environments/12') + .with(body: { name: 'staging', external_url: 'https://staging.example.gitlab.com' })).to have_been_made end - it "returns a single environment" do + it 'returns a single environment' do expect(@environment).to be_a Gitlab::ObjectifiedHash end - it "returns information about an environment" do - expect(@environment.name).to eq("staging") + it 'returns information about an environment' do + expect(@environment.name).to eq('staging') end end - describe ".delete_environment" do + describe '.delete_environment' do before do - stub_delete("/projects/3/environments/12", "environment") + stub_delete('/projects/3/environments/12', 'environment') @environment = Gitlab.delete_environment(3, 12) end - it "gets the correct resource" do - expect(a_delete("/projects/3/environments/12")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/environments/12')).to have_been_made end - it "returns a single pipeline" do + it 'returns a single pipeline' do expect(@environment).to be_a Gitlab::ObjectifiedHash end - it "returns information about a pipeline" do - expect(@environment.name).to eq("staging") + it 'returns information about a pipeline' do + expect(@environment.name).to eq('staging') end end - describe ".stop_environment" do + describe '.stop_environment' do before do - stub_post("/projects/3/environments/12/stop", "environment") + stub_post('/projects/3/environments/12/stop', 'environment') @environment = Gitlab.stop_environment(3, 12) end - it "gets the correct resource" do - expect(a_post("/projects/3/environments/12/stop")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/environments/12/stop')).to have_been_made end - it "returns a single pipeline" do + it 'returns a single pipeline' do expect(@environment).to be_a Gitlab::ObjectifiedHash end - it "returns information about a pipeline" do - expect(@environment.name).to eq("staging") + it 'returns information about a pipeline' do + expect(@environment.name).to eq('staging') end end end diff --git a/spec/gitlab/client/events_spec.rb b/spec/gitlab/client/events_spec.rb index 33855d5..67d691a 100644 --- a/spec/gitlab/client/events_spec.rb +++ b/spec/gitlab/client/events_spec.rb @@ -1,29 +1,31 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".events" do + describe '.events' do before do - stub_get("/events", "user_events") - @events = Gitlab.events() + stub_get('/events', 'user_events') + @events = Gitlab.events end - it "gets the correct resource" do - expect(a_get("/events")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/events')).to have_been_made end - it "it returns a response of user's events" do + it "returns a response of user's events" do expect(@events).to be_a Gitlab::PaginatedResponse end end - describe ".user_events" do + describe '.user_events' do before do - stub_get("/users/1/events", "user_events") + stub_get('/users/1/events', 'user_events') @events = Gitlab.user_events(1) end - it "gets the correct resource" do - expect(a_get("/users/1/events")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/users/1/events')).to have_been_made end it "returns a response of user's contribution events" do @@ -33,12 +35,12 @@ describe '.project_events' do before do - stub_get("/1/events", "project_events") + stub_get('/projects/1/events', 'project_events') @events = Gitlab.project_events(1) end - it "gets the correct resource" do - expect(a_get("/1/events")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/1/events')).to have_been_made end it "returns a response of project's visible events" do diff --git a/spec/gitlab/client/group_milestones_spec.rb b/spec/gitlab/client/group_milestones_spec.rb index dbd962c..642df82 100644 --- a/spec/gitlab/client/group_milestones_spec.rb +++ b/spec/gitlab/client/group_milestones_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".group_milestones" do + describe '.group_milestones' do before do - stub_get("/groups/3/milestones", "group_milestones") + stub_get('/groups/3/milestones', 'group_milestones') @milestones = Gitlab.group_milestones(3) end - it "gets the correct resource" do - expect(a_get("/groups/3/milestones")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/groups/3/milestones')).to have_been_made end it "returns a paginated response of group's milestones" do @@ -17,61 +19,61 @@ end end - describe ".group_milestone" do + describe '.group_milestone' do before do - stub_get("/groups/3/milestones/1", "group_milestone") + stub_get('/groups/3/milestones/1', 'group_milestone') @milestone = Gitlab.group_milestone(3, 1) end - it "gets the correct resource" do - expect(a_get("/groups/3/milestones/1")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/groups/3/milestones/1')).to have_been_made end - it "returns information about a milestone" do + it 'returns information about a milestone' do expect(@milestone.group_id).to eq(3) end end - describe ".create_group_milestone" do + describe '.create_group_milestone' do before do - stub_post("/groups/3/milestones", "group_milestone") + stub_post('/groups/3/milestones', 'group_milestone') @milestone = Gitlab.create_group_milestone(3, 'title') end - it "gets the correct resource" do - expect(a_post("/groups/3/milestones"). - with(body: { title: 'title' })).to have_been_made + it 'gets the correct resource' do + expect(a_post('/groups/3/milestones') + .with(body: { title: 'title' })).to have_been_made end - it "returns information about a created milestone" do + it 'returns information about a created milestone' do expect(@milestone.group_id).to eq(3) end end - describe ".edit_group_milestone" do + describe '.edit_group_milestone' do before do - stub_put("/groups/3/milestones/33", "group_milestone") + stub_put('/groups/3/milestones/33', 'group_milestone') @milestone = Gitlab.edit_group_milestone(3, 33, title: 'title') end - it "gets the correct resource" do - expect(a_put("/groups/3/milestones/33"). - with(body: { title: 'title' })).to have_been_made + it 'gets the correct resource' do + expect(a_put('/groups/3/milestones/33') + .with(body: { title: 'title' })).to have_been_made end - it "returns information about an edited milestone" do + it 'returns information about an edited milestone' do expect(@milestone.group_id).to eq(3) end end - describe ".group_milestone_issues" do + describe '.group_milestone_issues' do before do - stub_get("/groups/3/milestones/1/issues", "group_milestone_issues") + stub_get('/groups/3/milestones/1/issues', 'group_milestone_issues') @milestone_issues = Gitlab.group_milestone_issues(3, 1) end - it "gets the correct resource" do - expect(a_get("/groups/3/milestones/1/issues")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/groups/3/milestones/1/issues')).to have_been_made end it "returns a paginated response of milestone's issues" do @@ -80,14 +82,14 @@ end end - describe ".group_milestone_merge_requests" do + describe '.group_milestone_merge_requests' do before do - stub_get("/groups/3/milestones/1/merge_requests", "group_milestone_merge_requests") + stub_get('/groups/3/milestones/1/merge_requests', 'group_milestone_merge_requests') @milestone_merge_requests = Gitlab.group_milestone_merge_requests(3, 1) end - it "gets the correct resource" do - expect(a_get("/groups/3/milestones/1/merge_requests")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/groups/3/milestones/1/merge_requests')).to have_been_made end it "returns a paginated response of milestone's merge_requests" do diff --git a/spec/gitlab/client/groups_spec.rb b/spec/gitlab/client/groups_spec.rb index 161fbcd..bba9c06 100644 --- a/spec/gitlab/client/groups_spec.rb +++ b/spec/gitlab/client/groups_spec.rb @@ -1,245 +1,247 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".groups" do - before do - stub_get("/groups", "groups") - stub_get("/groups/3", "group") + describe '.groups' do + before do + stub_get('/groups', 'groups') + stub_get('/groups/3', 'group') @group = Gitlab.group(3) @groups = Gitlab.groups end - it "gets the correct resource" do - expect(a_get("/groups")).to have_been_made - expect(a_get("/groups/3")).to have_been_made - end - - it "returns a paginated response of groups" do + it 'gets the correct resource' do + expect(a_get('/groups')).to have_been_made + expect(a_get('/groups/3')).to have_been_made + end + + it 'returns a paginated response of groups' do expect(@groups).to be_a Gitlab::PaginatedResponse - expect(@groups.first.path).to eq("threegroup") - end - end - - describe ".create_group" do - context "without description" do + expect(@groups.first.path).to eq('threegroup') + end + end + + describe '.create_group' do + context 'without description' do before do - stub_post("/groups", "group_create") + stub_post('/groups', 'group_create') @group = Gitlab.create_group('GitLab-Group', 'gitlab-path') end - it "gets the correct resource" do - expect(a_post("/groups"). - with(body: { path: 'gitlab-path', name: 'GitLab-Group' })).to have_been_made - end - - it "returns information about a created group" do - expect(@group.name).to eq("Gitlab-Group") - expect(@group.path).to eq("gitlab-group") - end - end - - context "with description" do + it 'gets the correct resource' do + expect(a_post('/groups') + .with(body: { path: 'gitlab-path', name: 'GitLab-Group' })).to have_been_made + end + + it 'returns information about a created group' do + expect(@group.name).to eq('Gitlab-Group') + expect(@group.path).to eq('gitlab-group') + end + end + + context 'with description' do before do - stub_post("/groups", "group_create_with_description") + stub_post('/groups', 'group_create_with_description') @group = Gitlab.create_group('GitLab-Group', 'gitlab-path', description: 'gitlab group description') end - it "gets the correct resource" do - expect(a_post("/groups"). - with(body: { path: 'gitlab-path', name: 'GitLab-Group', - description: 'gitlab group description' })).to have_been_made - end - - it "returns information about a created group" do - expect(@group.name).to eq("Gitlab-Group") - expect(@group.path).to eq("gitlab-group") - expect(@group.description).to eq("gitlab group description") - end - end - end - - describe ".delete_group" do - before do - stub_delete("/groups/42", "group_delete") + it 'gets the correct resource' do + expect(a_post('/groups') + .with(body: { path: 'gitlab-path', name: 'GitLab-Group', + description: 'gitlab group description' })).to have_been_made + end + + it 'returns information about a created group' do + expect(@group.name).to eq('Gitlab-Group') + expect(@group.path).to eq('gitlab-group') + expect(@group.description).to eq('gitlab group description') + end + end + end + + describe '.delete_group' do + before do + stub_delete('/groups/42', 'group_delete') @group = Gitlab.delete_group(42) end - it "gets the correct resource" do - expect(a_delete("/groups/42")).to have_been_made - end - - it "returns information about a deleted group" do - expect(@group.name).to eq("Gitlab-Group") - expect(@group.path).to eq("gitlab-group") - end - end - - describe ".transfer_project_to_group" do - before do - stub_post("/projects", "project") + it 'gets the correct resource' do + expect(a_delete('/groups/42')).to have_been_made + end + + it 'returns information about a deleted group' do + expect(@group.name).to eq('Gitlab-Group') + expect(@group.path).to eq('gitlab-group') + end + end + + describe '.transfer_project_to_group' do + before do + stub_post('/projects', 'project') @project = Gitlab.create_project('Gitlab') - stub_post("/groups", "group_create") + stub_post('/groups', 'group_create') @group = Gitlab.create_group('GitLab-Group', 'gitlab-path') - stub_post("/groups/#{@group.id}/projects/#{@project.id}", "group_create") + stub_post("/groups/#{@group.id}/projects/#{@project.id}", 'group_create') @group_transfer = Gitlab.transfer_project_to_group(@group.id, @project.id) end - it "posts to the correct resource" do + it 'posts to the correct resource' do 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 end - it "returns information about the group" do + it 'returns information about the group' do expect(@group_transfer.name).to eq(@group.name) expect(@group_transfer.path).to eq(@group.path) expect(@group_transfer.id).to eq(@group.id) end end - describe ".group_members" do - before do - stub_get("/groups/3/members", "group_members") + describe '.group_members' do + before do + stub_get('/groups/3/members', 'group_members') @members = Gitlab.group_members(3) end - it "gets the correct resource" do - expect(a_get("/groups/3/members")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/groups/3/members')).to have_been_made end it "returns information about a group's members" do expect(@members).to be_a Gitlab::PaginatedResponse expect(@members.size).to eq(2) - expect(@members[1].name).to eq("John Smith") - end - end - - describe ".group_member" do - before do - stub_get("/groups/3/members/2", "group_member") + expect(@members[1].name).to eq('John Smith') + end + end + + describe '.group_member' do + before do + stub_get('/groups/3/members/2', 'group_member') @member = Gitlab.group_member(3, 2) end - it "gets the correct resource" do - expect(a_get("/groups/3/members/2")).to have_been_made - end - - it "returns information about a group member" do + it 'gets the correct resource' do + expect(a_get('/groups/3/members/2')).to have_been_made + end + + it 'returns information about a group member' do expect(@member).to be_a Gitlab::ObjectifiedHash expect(@member.access_level).to eq(10) - expect(@member.name).to eq("John Smith") - end - end - - describe ".add_group_member" do - before do - stub_post("/groups/3/members", "group_member") + expect(@member.name).to eq('John Smith') + end + end + + describe '.add_group_member' do + before do + stub_post('/groups/3/members', 'group_member') @member = Gitlab.add_group_member(3, 1, 40) end - it "gets the correct resource" do - expect(a_post("/groups/3/members"). - with(body: { user_id: '1', access_level: '40' })).to have_been_made - end - - it "returns information about the added member" do - expect(@member.name).to eq("John Smith") - end - end - - describe ".edit_group_member" do - before do - stub_put("/groups/3/members/1", "group_member_edit") + it 'gets the correct resource' do + expect(a_post('/groups/3/members') + .with(body: { user_id: '1', access_level: '40' })).to have_been_made + end + + it 'returns information about the added member' do + expect(@member.name).to eq('John Smith') + end + end + + describe '.edit_group_member' do + before do + stub_put('/groups/3/members/1', 'group_member_edit') @member = Gitlab.edit_group_member(3, 1, 50) end - it "gets the correct resource" do - expect(a_put("/groups/3/members/1") - .with(body: { access_level: '50'})).to have_been_made - end - - it "returns information about the edited member" do + it 'gets the correct resource' do + expect(a_put('/groups/3/members/1') + .with(body: { access_level: '50' })).to have_been_made + end + + it 'returns information about the edited member' do expect(@member.access_level).to eq(50) end end - describe ".remove_group_member" do - before do - stub_delete("/groups/3/members/1", "group_member_delete") + describe '.remove_group_member' do + before do + stub_delete('/groups/3/members/1', 'group_member_delete') @group = Gitlab.remove_group_member(3, 1) end - it "gets the correct resource" do - expect(a_delete("/groups/3/members/1")).to have_been_made - end - - it "returns information about the group the member was removed from" do + it 'gets the correct resource' do + expect(a_delete('/groups/3/members/1')).to have_been_made + end + + it 'returns information about the group the member was removed from' do expect(@group.group_id).to eq(3) end end - describe ".group_projects" do - before do - stub_get("/groups/4/projects", "group_projects") + describe '.group_projects' do + before do + stub_get('/groups/4/projects', 'group_projects') @projects = Gitlab.group_projects(4) end - it "gets the list of projects" do - expect(a_get("/groups/4/projects")).to have_been_made - end - - it "returns a list of of projects under a group" do + it 'gets the list of projects' do + expect(a_get('/groups/4/projects')).to have_been_made + end + + it 'returns a list of of projects under a group' do expect(@projects).to be_a Gitlab::PaginatedResponse expect(@projects.size).to eq(1) - expect(@projects[0].name).to eq("Diaspora Client") - end - end - - describe ".group_search" do - before do - stub_get("/groups?search=Group", "group_search") + expect(@projects[0].name).to eq('Diaspora Client') + end + end + + describe '.group_search' do + before do + stub_get('/groups?search=Group', 'group_search') @groups = Gitlab.group_search('Group') end - it "gets the correct resource" do - expect(a_get("/groups?search=Group")).to have_been_made - end - - it "returns an array of groups found" do + it 'gets the correct resource' do + expect(a_get('/groups?search=Group')).to have_been_made + end + + it 'returns an array of groups found' do expect(@groups.first.id).to eq(5) expect(@groups.last.id).to eq(8) end end - describe ".group_subgroups" do - before do - stub_get("/groups/4/subgroups", "group_subgroups") + describe '.group_subgroups' do + before do + stub_get('/groups/4/subgroups', 'group_subgroups') @subgroups = Gitlab.group_subgroups(4) end - it "gets the list of subroups" do - expect(a_get("/groups/4/subgroups")).to have_been_made - end - - it "returns an array of subgroups under a group" do + it 'gets the list of subroups' do + expect(a_get('/groups/4/subgroups')).to have_been_made + end + + it 'returns an array of subgroups under a group' do expect(@subgroups).to be_a Gitlab::PaginatedResponse expect(@subgroups.size).to eq(1) - expect(@subgroups[0].name).to eq("Foobar Group") - end - end - - describe ".edit_group" do - context "using group ID" do + expect(@subgroups[0].name).to eq('Foobar Group') + end + end + + describe '.edit_group' do + context 'using group ID' do before do - stub_put("/groups/1", "group_edit").with(body: { description: "An interesting group" }) - @edited_project = Gitlab.edit_group(1, description: "An interesting group") - end - - it "gets the correct resource" do - expect(a_put("/groups/1").with(body: { description: "An interesting group" })).to have_been_made - end - - it "returns information about an edited group" do - expect(@edited_project.description).to eq("An interesting group") + stub_put('/groups/1', 'group_edit').with(body: { description: 'An interesting group' }) + @edited_project = Gitlab.edit_group(1, description: 'An interesting group') + end + + it 'gets the correct resource' do + expect(a_put('/groups/1').with(body: { description: 'An interesting group' })).to have_been_made + end + + it 'returns information about an edited group' do + expect(@edited_project.description).to eq('An interesting group') end end end diff --git a/spec/gitlab/client/issues_spec.rb b/spec/gitlab/client/issues_spec.rb index a139b77..9ec4439 100644 --- a/spec/gitlab/client/issues_spec.rb +++ b/spec/gitlab/client/issues_spec.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".issues" do - context "with project ID passed" do + describe '.issues' do + context 'with project ID passed' do before do - stub_get("/projects/3/issues", "project_issues") + stub_get('/projects/3/issues', 'project_issues') @issues = Gitlab.issues(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/issues")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/issues')).to have_been_made end it "returns a paginated response of project's issues" do @@ -20,12 +22,12 @@ context 'with literal project ID passed' do before do - stub_get("/projects/gitlab-org%2Fgitlab-ce/issues", "project_issues") + stub_get('/projects/gitlab-org%2Fgitlab-ce/issues', 'project_issues') @issues = Gitlab.issues('gitlab-org/gitlab-ce') end - it "gets the correct resource" do - expect(a_get("/projects/gitlab-org%2Fgitlab-ce/issues")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/gitlab-org%2Fgitlab-ce/issues')).to have_been_made end it "returns a paginated response of project's issues" do @@ -34,252 +36,284 @@ end end - context "without project ID passed" do + context 'without project ID passed' do before do - stub_get("/issues", "issues") + stub_get('/issues', 'issues') @issues = Gitlab.issues end - it "gets the correct resource" do - expect(a_get("/issues")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/issues')).to have_been_made end it "returns a paginated response of user's issues" do expect(@issues).to be_a Gitlab::PaginatedResponse expect(@issues.first.closed).to be_falsey - expect(@issues.first.author.name).to eq("John Smith") - end - end - end - - describe ".issue" do - before do - stub_get("/projects/3/issues/33", "issue") + expect(@issues.first.author.name).to eq('John Smith') + end + end + end + + describe '.issue' do + before do + stub_get('/projects/3/issues/33', 'issue') @issue = Gitlab.issue(3, 33) end - it "gets the correct resource" do - expect(a_get("/projects/3/issues/33")).to have_been_made - end - - it "returns information about an issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".create_issue" do - before do - stub_post("/projects/3/issues", "issue") + it 'gets the correct resource' do + expect(a_get('/projects/3/issues/33')).to have_been_made + end + + it 'returns information about an issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.create_issue' do + before do + stub_post('/projects/3/issues', 'issue') @issue = Gitlab.create_issue(3, 'title') end - it "gets the correct resource" do - expect(a_post("/projects/3/issues"). - with(body: { title: 'title' })).to have_been_made - end - - it "returns information about a created issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".edit_issue" do - before do - stub_put("/projects/3/issues/33", "issue") + it 'gets the correct resource' do + expect(a_post('/projects/3/issues') + .with(body: { title: 'title' })).to have_been_made + end + + it 'returns information about a created issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.edit_issue' do + before do + stub_put('/projects/3/issues/33', 'issue') @issue = Gitlab.edit_issue(3, 33, title: 'title') end - it "gets the correct resource" do - expect(a_put("/projects/3/issues/33"). - with(body: { title: 'title' })).to have_been_made - end - - it "returns information about an edited issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".close_issue" do - before do - stub_put("/projects/3/issues/33", "issue") + it 'gets the correct resource' do + expect(a_put('/projects/3/issues/33') + .with(body: { title: 'title' })).to have_been_made + end + + it 'returns information about an edited issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.close_issue' do + before do + stub_put('/projects/3/issues/33', 'issue') @issue = Gitlab.close_issue(3, 33) end - it "gets the correct resource" do - expect(a_put("/projects/3/issues/33"). - with(body: { state_event: 'close' })).to have_been_made - end - - it "returns information about an closed issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".reopen_issue" do - before do - stub_put("/projects/3/issues/33", "issue") + it 'gets the correct resource' do + expect(a_put('/projects/3/issues/33') + .with(body: { state_event: 'close' })).to have_been_made + end + + it 'returns information about an closed issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.reopen_issue' do + before do + stub_put('/projects/3/issues/33', 'issue') @issue = Gitlab.reopen_issue(3, 33) end - it "gets the correct resource" do - expect(a_put("/projects/3/issues/33"). - with(body: { state_event: 'reopen' })).to have_been_made - end - - it "returns information about an reopened issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".subscribe_to_issue" do - before do - stub_post("/projects/3/issues/33/subscribe", "issue") + it 'gets the correct resource' do + expect(a_put('/projects/3/issues/33') + .with(body: { state_event: 'reopen' })).to have_been_made + end + + it 'returns information about an reopened issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.subscribe_to_issue' do + before do + stub_post('/projects/3/issues/33/subscribe', 'issue') @issue = Gitlab.subscribe_to_issue(3, 33) end - it "gets the correct resource" do - expect(a_post("/projects/3/issues/33/subscribe")).to have_been_made - end - - it "returns information about the subscribed issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".unsubscribe_from_issue" do - before do - stub_post("/projects/3/issues/33/unsubscribe", "issue") + it 'gets the correct resource' do + expect(a_post('/projects/3/issues/33/subscribe')).to have_been_made + end + + it 'returns information about the subscribed issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.unsubscribe_from_issue' do + before do + stub_post('/projects/3/issues/33/unsubscribe', 'issue') @issue = Gitlab.unsubscribe_from_issue(3, 33) end - it "gets the correct resource" do - expect(a_post("/projects/3/issues/33/unsubscribe")).to have_been_made - end - - it "returns information about the unsubscribed issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".delete_issue" do - before do - stub_delete("/projects/3/issues/33", "issue") + it 'gets the correct resource' do + expect(a_post('/projects/3/issues/33/unsubscribe')).to have_been_made + end + + it 'returns information about the unsubscribed issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.delete_issue' do + before do + stub_delete('/projects/3/issues/33', 'issue') @issue = Gitlab.delete_issue(3, 33) end - it "gets the correct resource" do - expect(a_delete("/projects/3/issues/33")).to have_been_made - end - - it "returns information about a deleted issue" do + it 'gets the correct resource' do + expect(a_delete('/projects/3/issues/33')).to have_been_made + end + + it 'returns information about a deleted issue' do expect(@issue.project_id).to eq(3) expect(@issue.id).to eq(33) end end - describe ".move_issue" do - before do - stub_post("/projects/3/issues/33/move", "issue") + describe '.move_issue' do + before do + stub_post('/projects/3/issues/33/move', 'issue') @issue = Gitlab.move_issue(3, 33, to_project_id: '4') end - it "gets the correct resource" do - expect(a_post("/projects/3/issues/33/move"). - with(body: { to_project_id: '4' })).to have_been_made - end - - it "returns information about the moved issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".estimate_time_of_issue" do - before do - stub_post("/projects/3/issues/33/time_estimate", "issue") + it 'gets the correct resource' do + expect(a_post('/projects/3/issues/33/move') + .with(body: { to_project_id: '4' })).to have_been_made + end + + it 'returns information about the moved issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.estimate_time_of_issue' do + before do + stub_post('/projects/3/issues/33/time_estimate', 'issue') @issue = Gitlab.estimate_time_of_issue(3, 33, '3h30m') end - it "gets the correct resource" do - expect(a_post("/projects/3/issues/33/time_estimate"). - with(body: { duration: '3h30m' })).to have_been_made - end - - it "returns information about the estimated issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".reset_time_estimate_of_issue" do - before do - stub_post("/projects/3/issues/33/reset_time_estimate", "issue") + it 'gets the correct resource' do + expect(a_post('/projects/3/issues/33/time_estimate') + .with(body: { duration: '3h30m' })).to have_been_made + end + + it 'returns information about the estimated issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.reset_time_estimate_of_issue' do + before do + stub_post('/projects/3/issues/33/reset_time_estimate', 'issue') @issue = Gitlab.reset_time_estimate_of_issue(3, 33) end - it "gets the correct resource" do - expect(a_post("/projects/3/issues/33/reset_time_estimate")).to have_been_made - end - - it "returns information about the estimated issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".add_time_spent_on_issue" do - before do - stub_post("/projects/3/issues/33/add_spent_time", "issue") + it 'gets the correct resource' do + expect(a_post('/projects/3/issues/33/reset_time_estimate')).to have_been_made + end + + it 'returns information about the estimated issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.add_time_spent_on_issue' do + before do + stub_post('/projects/3/issues/33/add_spent_time', 'issue') @issue = Gitlab.add_time_spent_on_issue(3, 33, '3h30m') end - it "gets the correct resource" do - expect(a_post("/projects/3/issues/33/add_spent_time"). - with(body: { duration: '3h30m' })).to have_been_made - end - - it "returns information about the estimated issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".reset_time_spent_on_issue" do - before do - stub_post("/projects/3/issues/33/reset_spent_time", "issue") + it 'gets the correct resource' do + expect(a_post('/projects/3/issues/33/add_spent_time') + .with(body: { duration: '3h30m' })).to have_been_made + end + + it 'returns information about the estimated issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.reset_time_spent_on_issue' do + before do + stub_post('/projects/3/issues/33/reset_spent_time', 'issue') @issue = Gitlab.reset_time_spent_on_issue(3, 33) end - it "gets the correct resource" do - expect(a_post("/projects/3/issues/33/reset_spent_time")).to have_been_made - end - - it "returns information about the estimated issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") - end - end - - describe ".time_stats_for_issue" do - before do - stub_get("/projects/3/issues/33/time_stats", "issue") + it 'gets the correct resource' do + expect(a_post('/projects/3/issues/33/reset_spent_time')).to have_been_made + end + + it 'returns information about the estimated issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.time_stats_for_issue' do + before do + stub_get('/projects/3/issues/33/time_stats', 'issue') @issue = Gitlab.time_stats_for_issue(3, 33) end - it "gets the correct resource" do - expect(a_get("/projects/3/issues/33/time_stats")).to have_been_made - end - - it "returns information about the issue" do - expect(@issue.project_id).to eq(3) - expect(@issue.assignee.name).to eq("Jack Smith") + it 'gets the correct resource' do + expect(a_get('/projects/3/issues/33/time_stats')).to have_been_made + end + + it 'returns information about the issue' do + expect(@issue.project_id).to eq(3) + expect(@issue.assignee.name).to eq('Jack Smith') + end + end + + describe '.participants_on_issue' do + before do + stub_get('/projects/3/issues/33/participants', 'participants_on_issue') + @participants = Gitlab.participants_on_issue(3, 33) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/issues/33/participants')).to have_been_made + end + + it 'returns information about the participants on issue' do + expect(@participants.first.name).to eq('John Doe1') + expect(@participants.size).to eq(2) + end + end + + describe '.merge_requests_closing_issue_on_merge' do + before do + stub_get('/projects/3/issues/33/closed_by', 'merge_requests_closing_issue_on_merge') + @merge_requests = Gitlab.merge_requests_closing_issue_on_merge(3, 33) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/issues/33/closed_by')).to have_been_made + end + + it 'returns list of merge requests closing issue on merge' do + expect(@merge_requests.first.title).to eq('New feature') + expect(@merge_requests.size).to eq(2) end end end diff --git a/spec/gitlab/client/jobs_spec.rb b/spec/gitlab/client/jobs_spec.rb index 6e3fb7d..2341961 100644 --- a/spec/gitlab/client/jobs_spec.rb +++ b/spec/gitlab/client/jobs_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do @@ -28,6 +30,7 @@ stub_get('/projects/1/pipelines/1/jobs', 'pipeline_jobs') @projects = Gitlab.pipeline_jobs(1, 1) end + it 'gets the correct resource' do expect(a_get('/projects/1/pipelines/1/jobs')).to have_been_made end @@ -38,6 +41,7 @@ stub_get('/projects/1/pipelines/1/jobs?scope[]=running&scope[]=created', 'pipeline_jobs') @projects = Gitlab.pipeline_jobs(1, 1, scope: %w[running created]) end + it 'gets the correct resource' do expect(a_get('/projects/1/pipelines/1/jobs?scope[]=running&scope[]=created')).to have_been_made end @@ -48,6 +52,7 @@ stub_get('/projects/1/jobs/1', 'job') @projects = Gitlab.job(1, 1) end + it 'gets the correct resource' do expect(a_get('/projects/1/jobs/1')).to have_been_made end @@ -58,6 +63,7 @@ stub_get('/projects/1/jobs/1/artifacts', 'job') @projects = Gitlab.job_artifacts(1, 1) end + it 'gets the correct resource' do expect(a_get('/projects/1/jobs/1/artifacts')).to have_been_made end @@ -68,6 +74,7 @@ stub_get('/projects/1/jobs/artifacts/master/download?job=Release%20Build', 'job') @projects = Gitlab.job_artifacts_download(1, 'master', 'Release Build') end + it 'gets the correct resource' do expect(a_get('/projects/1/jobs/artifacts/master/download?job=Release%20Build')).to have_been_made end @@ -78,6 +85,7 @@ stub_get('/projects/1/jobs/1/trace', 'job_trace') @projects = Gitlab.job_trace(1, 1) end + it 'gets the correct resource' do expect(a_get('/projects/1/jobs/1/trace')).to have_been_made end @@ -88,6 +96,7 @@ stub_post('/projects/1/jobs/1/cancel', 'job') @projects = Gitlab.job_cancel(1, 1) end + it 'gets the correct resource' do expect(a_post('/projects/1/jobs/1/cancel')).to have_been_made end @@ -98,6 +107,7 @@ stub_post('/projects/1/jobs/1/retry', 'job') @projects = Gitlab.job_retry(1, 1) end + it 'gets the correct resource' do expect(a_post('/projects/1/jobs/1/retry')).to have_been_made end @@ -108,6 +118,7 @@ stub_post('/projects/1/jobs/1/erase', 'job') @projects = Gitlab.job_erase(1, 1) end + it 'gets the correct resource' do expect(a_post('/projects/1/jobs/1/erase')).to have_been_made end @@ -118,6 +129,7 @@ stub_post('/projects/1/jobs/1/play', 'job') @projects = Gitlab.job_play(1, 1) end + it 'gets the correct resource' do expect(a_post('/projects/1/jobs/1/play')).to have_been_made end @@ -128,6 +140,7 @@ stub_post('/projects/1/jobs/1/artifacts/keep', 'job') @projects = Gitlab.job_artifacts_keep(1, 1) end + it 'gets the correct resource' do expect(a_post('/projects/1/jobs/1/artifacts/keep')).to have_been_made end diff --git a/spec/gitlab/client/keys_spec.rb b/spec/gitlab/client/keys_spec.rb index 541ffb1..aa639e1 100644 --- a/spec/gitlab/client/keys_spec.rb +++ b/spec/gitlab/client/keys_spec.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".key" do + describe '.key' do before do - stub_get("/keys/1", "key") + stub_get('/keys/1', 'key') @key = Gitlab.key(1) end - it "gets the correct resource" do - expect(a_get("/keys/1")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/keys/1')).to have_been_made end - it "returns information about a key" do + it 'returns information about a key' do expect(@key.id).to eq(1) - expect(@key.title).to eq("narkoz@helium") + expect(@key.title).to eq('narkoz@helium') end end end diff --git a/spec/gitlab/client/labels_spec.rb b/spec/gitlab/client/labels_spec.rb index dc5d0bd..52651a7 100644 --- a/spec/gitlab/client/labels_spec.rb +++ b/spec/gitlab/client/labels_spec.rb @@ -1,98 +1,100 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".labels" do + describe '.labels' do before do - stub_get("/projects/3/labels", "labels") + stub_get('/projects/3/labels', 'labels') @labels = Gitlab.labels(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/labels")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/labels')).to have_been_made end it "returns a paginated response of project's labels" do expect(@labels).to be_a Gitlab::PaginatedResponse - expect(@labels.first.name).to eq("Backlog") + expect(@labels.first.name).to eq('Backlog') end end - describe ".delete" do + describe '.delete' do before do - stub_delete("/projects/3/labels", "label") - @label = Gitlab.delete_label(3, "Backlog") + stub_delete('/projects/3/labels', 'label') + @label = Gitlab.delete_label(3, 'Backlog') end - it "gets the correct resource" do - expect(a_delete("/projects/3/labels"). - with(body: { name: 'Backlog' })).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/labels') + .with(body: { name: 'Backlog' })).to have_been_made end - it "returns information about a deleted snippet" do - expect(@label.name).to eq("Backlog") + it 'returns information about a deleted snippet' do + expect(@label.name).to eq('Backlog') end end - describe ".edit_label" do + describe '.edit_label' do before do - stub_put("/projects/3/labels", "label") - @label = Gitlab.edit_label(3, "TODO", new_name: 'Backlog') + stub_put('/projects/3/labels', 'label') + @label = Gitlab.edit_label(3, 'TODO', new_name: 'Backlog') end - it "gets the correct resource" do - expect(a_put("/projects/3/labels"). - with(body: { name: 'TODO', new_name: "Backlog" })).to have_been_made + it 'gets the correct resource' do + expect(a_put('/projects/3/labels') + .with(body: { name: 'TODO', new_name: 'Backlog' })).to have_been_made end - it "returns information about an edited label" do - expect(@label.name).to eq("Backlog") + it 'returns information about an edited label' do + expect(@label.name).to eq('Backlog') end end - describe ".create_label" do + describe '.create_label' do before do - stub_post("/projects/3/labels", "label") + stub_post('/projects/3/labels', 'label') @label = Gitlab.create_label(3, 'Backlog', '#DD10AA') end - it "gets the correct resource" do - expect(a_post("/projects/3/labels"). - with(body: { name: 'Backlog', color: '#DD10AA' })).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/labels') + .with(body: { name: 'Backlog', color: '#DD10AA' })).to have_been_made end - it "returns information about a created label" do + it 'returns information about a created label' do expect(@label.name).to eq('Backlog') expect(@label.color).to eq('#DD10AA') end end - describe ".subscribe_to_label" do + describe '.subscribe_to_label' do before do - stub_post("/projects/3/labels/Backlog/subscribe", "label") + stub_post('/projects/3/labels/Backlog/subscribe', 'label') @label = Gitlab.subscribe_to_label(3, 'Backlog') end - it "gets the correct resource" do - expect(a_post("/projects/3/labels/Backlog/subscribe")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/labels/Backlog/subscribe')).to have_been_made end - it "returns information about the label subscribed to" do + it 'returns information about the label subscribed to' do expect(@label.name).to eq('Backlog') expect(@label.subscribed).to eq(true) end end - describe ".unsubscribe_from_label" do + describe '.unsubscribe_from_label' do before do - stub_post("/projects/3/labels/Backlog/unsubscribe", "label_unsubscribe") + stub_post('/projects/3/labels/Backlog/unsubscribe', 'label_unsubscribe') @label = Gitlab.unsubscribe_from_label(3, 'Backlog') end - it "gets the correct resource" do - expect(a_post("/projects/3/labels/Backlog/unsubscribe")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/labels/Backlog/unsubscribe')).to have_been_made end - it "returns information about the label subscribed to" do + it 'returns information about the label subscribed to' do expect(@label.name).to eq('Backlog') expect(@label.subscribed).to eq(false) end diff --git a/spec/gitlab/client/merge_request_approvals_spec.rb b/spec/gitlab/client/merge_request_approvals_spec.rb index 25bfa9e..d3ec0d4 100644 --- a/spec/gitlab/client/merge_request_approvals_spec.rb +++ b/spec/gitlab/client/merge_request_approvals_spec.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do describe '.project_merge_request_approvals' do before do - stub_get("/projects/1/approvals", 'project_merge_request_approvals') + stub_get('/projects/1/approvals', 'project_merge_request_approvals') @project_mr_approvals = Gitlab.project_merge_request_approvals(1) end - it "gets the correct resource" do - expect(a_get("/projects/1/approvals")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/1/approvals')).to have_been_made end - it "returns the correct objectified hash" do + it 'returns the correct objectified hash' do expect(@project_mr_approvals).to be_a Gitlab::ObjectifiedHash end end @@ -19,17 +21,17 @@ describe '.edit_project_merge_request_approvals' do before do body = { approvals_before_merge: '3', reset_approvals_on_push: 'false', disable_overriding_approvers_per_merge_request: 'true' } - stub_post("/projects/1/approvals", 'project_merge_request_approvals').with(body: body) + stub_post('/projects/1/approvals', 'project_merge_request_approvals').with(body: body) @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) end it 'gets the correct resource' do body = { approvals_before_merge: '3', reset_approvals_on_push: 'false', disable_overriding_approvers_per_merge_request: 'true' } - expect(a_post("/projects/1/approvals"). - with(body: body)).to have_been_made + expect(a_post('/projects/1/approvals') + .with(body: body)).to have_been_made end - it "returns the correct updated configuration" do + it 'returns the correct updated configuration' do expect(@project_mr_approvals).to be_a Gitlab::ObjectifiedHash expect(@project_mr_approvals.approvals_before_merge).to eq 3 expect(@project_mr_approvals.reset_approvals_on_push).to eq false @@ -39,32 +41,32 @@ describe '.edit_project_approvers' do before do - body = {"approver_ids": ['5'], "approver_group_ids": ['1']} - stub_put("/projects/1/approvals", 'project_merge_request_approvals').with(body: body) + body = { "approver_ids": ['5'], "approver_group_ids": ['1'] } + stub_put('/projects/1/approvals', 'project_merge_request_approvals').with(body: body) @project_mr_approvals = Gitlab.edit_project_approvers(1, approver_ids: [5], approver_group_ids: [1]) end it 'gets the correct resource' do - body = {"approver_ids": ['5'], "approver_group_ids": ['1']} - expect(a_put("/projects/1/approvals"). - with(body: body)).to have_been_made + body = { "approver_ids": ['5'], "approver_group_ids": ['1'] } + expect(a_put('/projects/1/approvals') + .with(body: body)).to have_been_made end it 'returns the correct updated configuration' do expect(@project_mr_approvals).to be_a Gitlab::ObjectifiedHash - expect(@project_mr_approvals.approvers.map{|approver| approver['user']['id']}).to eq [5] - expect(@project_mr_approvals.approver_groups.map{|approver_group| approver_group['group']['id']}).to eq [1] + expect(@project_mr_approvals.approvers.map { |approver| approver['user']['id'] }).to eq [5] + expect(@project_mr_approvals.approver_groups.map { |approver_group| approver_group['group']['id'] }).to eq [1] end end describe '.merge_request_approvals' do before do - stub_get("/projects/1/merge_requests/5/approvals", 'merge_request_approvals') + stub_get('/projects/1/merge_requests/5/approvals', 'merge_request_approvals') @merge_request_approvals = Gitlab.merge_request_approvals(1, 5) end it 'gets the correct resource' do - expect(a_get("/projects/1/merge_requests/5/approvals")).to have_been_made + expect(a_get('/projects/1/merge_requests/5/approvals')).to have_been_made end it 'returns the correct objectified hash' do @@ -77,13 +79,13 @@ describe '.edit_merge_request_approvals' do before do body = { approvals_required: '2' } - stub_post("/projects/1/merge_requests/5/approvals", 'merge_request_approvals').with(body: body) + stub_post('/projects/1/merge_requests/5/approvals', 'merge_request_approvals').with(body: body) @merge_request_approvals = Gitlab.edit_merge_request_approvals(1, 5, approvals_required: 2) end it 'gets the correct resource' do body = { approvals_required: '2' } - expect(a_post("/projects/1/merge_requests/5/approvals").with(body: body)).to have_been_made + expect(a_post('/projects/1/merge_requests/5/approvals').with(body: body)).to have_been_made end it 'returns the correct objectified hash' do @@ -94,32 +96,32 @@ describe '.edit_merge_request_approvers' do before do - body = {"approver_ids": ['1'], "approver_group_ids": ['5']} - stub_put("/projects/1/merge_requests/5/approvals", 'merge_request_approvals').with(body: body) + body = { "approver_ids": ['1'], "approver_group_ids": ['5'] } + stub_put('/projects/1/merge_requests/5/approvals', 'merge_request_approvals').with(body: body) @merge_request_approvals = Gitlab.edit_merge_request_approvers(1, 5, approver_ids: [1], approver_group_ids: [5]) end it 'gets the correct resource' do - body = {"approver_ids": ['1'], "approver_group_ids": ['5']} - expect(a_put("/projects/1/merge_requests/5/approvals"). - with(body: body)).to have_been_made + body = { "approver_ids": ['1'], "approver_group_ids": ['5'] } + expect(a_put('/projects/1/merge_requests/5/approvals') + .with(body: body)).to have_been_made end it 'returns the correct updated configuration' do expect(@merge_request_approvals).to be_a Gitlab::ObjectifiedHash - expect(@merge_request_approvals.approvers.map{|approver| approver['user']['id']}).to eq [1] - expect(@merge_request_approvals.approver_groups.map{|approver_group| approver_group['group']['id']}).to eq [5] + expect(@merge_request_approvals.approvers.map { |approver| approver['user']['id'] }).to eq [1] + expect(@merge_request_approvals.approver_groups.map { |approver_group| approver_group['group']['id'] }).to eq [5] end end describe '.approve_merge_request' do before do - stub_post("/projects/1/merge_requests/5/approve", 'merge_request_approvals') + stub_post('/projects/1/merge_requests/5/approve', 'merge_request_approvals') @merge_request_approvals = Gitlab.approve_merge_request(1, 5) end it 'gets the correct resource' do - expect(a_post("/projects/1/merge_requests/5/approve")).to have_been_made + expect(a_post('/projects/1/merge_requests/5/approve')).to have_been_made end it 'returns the correct updated configuration' do @@ -130,12 +132,12 @@ describe '.unapprove_merge_request' do before do - stub_post("/projects/1/merge_requests/5/unapprove", 'merge_request_approvals') + stub_post('/projects/1/merge_requests/5/unapprove', 'merge_request_approvals') @merge_request_approvals = Gitlab.unapprove_merge_request(1, 5) end it 'gets the correct resource' do - expect(a_post("/projects/1/merge_requests/5/unapprove")).to have_been_made + expect(a_post('/projects/1/merge_requests/5/unapprove')).to have_been_made end end -end \ No newline at end of file +end diff --git a/spec/gitlab/client/merge_requests_spec.rb b/spec/gitlab/client/merge_requests_spec.rb index b113cfa..27dd269 100644 --- a/spec/gitlab/client/merge_requests_spec.rb +++ b/spec/gitlab/client/merge_requests_spec.rb @@ -1,29 +1,31 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".user_merge_requests" do - before do - stub_get("/merge_requests", "merge_requests") + describe '.user_merge_requests' do + before do + stub_get('/merge_requests', 'merge_requests') @user_merge_requests = Gitlab.user_merge_requests end - it "gets the correct resource" do - expect(a_get("/merge_requests")).to have_been_made - end - - it "returns a paginated response of user merge requests" do + it 'gets the correct resource' do + expect(a_get('/merge_requests')).to have_been_made + end + + it 'returns a paginated response of user merge requests' do expect(@user_merge_requests).to be_a Gitlab::PaginatedResponse end end - describe ".merge_requests" do - before do - stub_get("/projects/3/merge_requests", "merge_requests") + describe '.merge_requests' do + before do + stub_get('/projects/3/merge_requests', 'merge_requests') @merge_requests = Gitlab.merge_requests(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/merge_requests")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests')).to have_been_made end it "returns a paginated response of project's merge requests" do @@ -32,132 +34,146 @@ end end - describe ".merge_request" do - before do - stub_get("/projects/3/merge_requests/1", "merge_request") + describe '.merge_request' do + before do + stub_get('/projects/3/merge_requests/1', 'merge_request') @merge_request = Gitlab.merge_request(3, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/merge_requests/1")).to have_been_made - end - - it "returns information about a merge request" do - expect(@merge_request.project_id).to eq(3) - expect(@merge_request.assignee.name).to eq("Jack Smith") - end - end - - describe ".create_merge_request" do - before do - stub_post("/projects/3/merge_requests", "merge_request") - end - - it "returns information about a merge request" do + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/1')).to have_been_made + end + + it 'returns information about a merge request' do + expect(@merge_request.project_id).to eq(3) + expect(@merge_request.assignee.name).to eq('Jack Smith') + end + end + + describe '.merge_request_pipelines' do + before do + stub_get('/projects/3/merge_requests/1/pipelines', 'pipelines') + @pipelines = Gitlab.merge_request_pipelines(3, 1) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/1/pipelines')).to have_been_made + end + + it 'returns information about all pipelines in merge request' do + expect(@pipelines.first.id).to eq(47) + expect(@pipelines.first.status).to eq('pending') + end + end + + describe '.create_merge_request' do + before do + stub_post('/projects/3/merge_requests', 'merge_request') + end + + it 'returns information about a merge request' do @merge_request = Gitlab.create_merge_request(3, 'New feature', source_branch: 'api', - target_branch: 'master' - ) - expect(@merge_request.project_id).to eq(3) - expect(@merge_request.assignee.name).to eq("Jack Smith") - end - end - - describe ".update_merge_request" do - before do - stub_put("/projects/3/merge_requests/2", "merge_request"). - with(body: { - assignee_id: '1', - target_branch: 'master', - title: 'A different new feature' - }) + target_branch: 'master') + expect(@merge_request.project_id).to eq(3) + expect(@merge_request.assignee.name).to eq('Jack Smith') + end + end + + describe '.update_merge_request' do + before do + stub_put('/projects/3/merge_requests/2', 'merge_request') + .with(body: { + assignee_id: '1', + target_branch: 'master', + title: 'A different new feature' + }) @merge_request = Gitlab.update_merge_request(3, 2, assignee_id: '1', target_branch: 'master', - title: 'A different new feature' - ) - end - - it "gets the correct resource" do - expect(a_put("/projects/3/merge_requests/2"). - with(body: { - assignee_id: '1', - target_branch: 'master', - title: 'A different new feature' - })).to have_been_made - end - - it "returns information about a merge request" do - expect(@merge_request.project_id).to eq(3) - expect(@merge_request.assignee.name).to eq("Jack Smith") - end - end - - describe ".accept_merge_request" do - before do - stub_put("/projects/5/merge_requests/42/merge", "merge_request"). - with(body: { merge_commit_message: 'Nice!' }) + title: 'A different new feature') + end + + it 'gets the correct resource' do + expect(a_put('/projects/3/merge_requests/2') + .with(body: { + assignee_id: '1', + target_branch: 'master', + title: 'A different new feature' + })).to have_been_made + end + + it 'returns information about a merge request' do + expect(@merge_request.project_id).to eq(3) + expect(@merge_request.assignee.name).to eq('Jack Smith') + end + end + + describe '.accept_merge_request' do + before do + stub_put('/projects/5/merge_requests/42/merge', 'merge_request') + .with(body: { merge_commit_message: 'Nice!' }) @merge_request = Gitlab.accept_merge_request(5, 42, merge_commit_message: 'Nice!') end - it "gets the correct resource" do - expect(a_put("/projects/5/merge_requests/42/merge"). - with(body: { merge_commit_message: 'Nice!' })).to have_been_made - end - - it "returns information about merged merge request" do - expect(@merge_request.project_id).to eq(3) - expect(@merge_request.assignee.name).to eq("Jack Smith") - end - end - - describe ".merge_request_comments" do - before do - stub_get("/projects/3/merge_requests/2/notes", "merge_request_comments") + it 'gets the correct resource' do + expect(a_put('/projects/5/merge_requests/42/merge') + .with(body: { merge_commit_message: 'Nice!' })).to have_been_made + end + + it 'returns information about merged merge request' do + expect(@merge_request.project_id).to eq(3) + expect(@merge_request.assignee.name).to eq('Jack Smith') + end + end + + describe '.merge_request_comments' do + before do + stub_get('/projects/3/merge_requests/2/notes', 'merge_request_comments') @merge_request = Gitlab.merge_request_comments(3, 2) end - it "gets the correct resource" do - expect(a_get("/projects/3/merge_requests/2/notes")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/2/notes')).to have_been_made end it "returns merge request's comments" do expect(@merge_request).to be_an Gitlab::PaginatedResponse expect(@merge_request.length).to eq(2) - expect(@merge_request[0].note).to eq("this is the 1st comment on the 2merge merge request") + expect(@merge_request[0].note).to eq('this is the 1st comment on the 2merge merge request') expect(@merge_request[0].author.id).to eq(11) - expect(@merge_request[1].note).to eq("another discussion point on the 2merge request") + expect(@merge_request[1].note).to eq('another discussion point on the 2merge request') expect(@merge_request[1].author.id).to eq(12) end end - describe ".create_merge_request_comment" do - before do - stub_post("/projects/3/merge_requests/2/notes", "merge_request_comment") + describe '.create_merge_request_comment' do + before do + stub_post('/projects/3/merge_requests/2/notes', 'merge_request_comment') @merge_request = Gitlab.create_merge_request_comment(3, 2, 'Cool Merge Request!') end - it "gets the correct resource" do - expect(a_post("/projects/3/merge_requests/2/notes")).to have_been_made - end - - it "returns information about a merge request" do + it 'gets the correct resource' do + expect(a_post('/projects/3/merge_requests/2/notes')).to have_been_made + end + + it 'returns information about a merge request' do expect(@merge_request.note).to eq('Cool Merge Request!') expect(@merge_request.author.id).to eq(1) end end - describe ".merge_request_changes" do - before do - stub_get("/projects/3/merge_requests/2/changes", "merge_request_changes") + describe '.merge_request_changes' do + before do + stub_get('/projects/3/merge_requests/2/changes', 'merge_request_changes') @mr_changes = Gitlab.merge_request_changes(3, 2) end - it "gets the correct resource" do - expect(a_get("/projects/3/merge_requests/2/changes")).to have_been_made - end - - it "returns the merge request changes" do + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/2/changes')).to have_been_made + end + + it 'returns the merge request changes' do expect(@mr_changes.changes).to be_a Array expect(@mr_changes.changes.first['old_path']).to eq('lib/omniauth/builder.rb') expect(@mr_changes.id).to eq(2) @@ -167,185 +183,217 @@ end end - describe ".merge_request_commits" do - before do - stub_get("/projects/3/merge_requests/2/commits", "merge_request_commits") + describe '.merge_request_commits' do + before do + stub_get('/projects/3/merge_requests/2/commits', 'merge_request_commits') @mr_commits = Gitlab.merge_request_commits(3, 2) end - it "gets the correct resource" do - expect(a_get("/projects/3/merge_requests/2/commits")).to have_been_made - end - - it "returns the merge request commits" do + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/2/commits')).to have_been_made + end + + it 'returns the merge request commits' do expect(@mr_commits).to be_a Gitlab::PaginatedResponse expect(@mr_commits.size).to eq 2 - expect(@mr_commits.first.id).to eq "a2da7552f26d5b46a6a09bb8b7b066e3a102be7d" - expect(@mr_commits.first.short_id).to eq "a2da7552" - expect(@mr_commits.first.title).to eq "piyo" - expect(@mr_commits.first.author_name).to eq "example" - expect(@mr_commits.first.author_email).to eq "example@example.com" - expect(@mr_commits[1].short_id).to eq "3ce50959" - expect(@mr_commits[1].title).to eq "hoge" - end - end - - describe ".merge_request_closes_issues" do - before do - stub_get("/projects/5/merge_requests/1/closes_issues", "merge_request_closes_issues") + expect(@mr_commits.first.id).to eq 'a2da7552f26d5b46a6a09bb8b7b066e3a102be7d' + expect(@mr_commits.first.short_id).to eq 'a2da7552' + expect(@mr_commits.first.title).to eq 'piyo' + expect(@mr_commits.first.author_name).to eq 'example' + expect(@mr_commits.first.author_email).to eq 'example@example.com' + expect(@mr_commits[1].short_id).to eq '3ce50959' + expect(@mr_commits[1].title).to eq 'hoge' + end + end + + describe '.merge_request_closes_issues' do + before do + stub_get('/projects/5/merge_requests/1/closes_issues', 'merge_request_closes_issues') @issues = Gitlab.merge_request_closes_issues(5, 1) end - it "gets the correct resource" do - expect(a_get("/projects/5/merge_requests/1/closes_issues")).to have_been_made - end - - it "returns a paginated response of the issues the merge_request will close" do + it 'gets the correct resource' do + expect(a_get('/projects/5/merge_requests/1/closes_issues')).to have_been_made + end + + it 'returns a paginated response of the issues the merge_request will close' do expect(@issues).to be_a(Gitlab::PaginatedResponse) - expect(@issues.first.title).to eq("Merge request 1 issue 1") + expect(@issues.first.title).to eq('Merge request 1 issue 1') expect(@issues.size).to eq(2) end end - describe ".subscribe_to_merge_request" do - before do - stub_post("/projects/3/merge_requests/2/subscribe", "merge_request") + describe '.subscribe_to_merge_request' do + before do + stub_post('/projects/3/merge_requests/2/subscribe', 'merge_request') @merge_request = Gitlab.subscribe_to_merge_request(3, 2) end - it "gets the correct resource" do - expect(a_post("/projects/3/merge_requests/2/subscribe")).to have_been_made - end - - it "returns information about a merge request" do - expect(@merge_request.project_id).to eq(3) - end - end - - describe ".unsubscribe_from_merge_request" do - before do - stub_post("/projects/3/merge_requests/2/unsubscribe", "merge_request") + it 'gets the correct resource' do + expect(a_post('/projects/3/merge_requests/2/subscribe')).to have_been_made + end + + it 'returns information about a merge request' do + expect(@merge_request.project_id).to eq(3) + end + end + + describe '.unsubscribe_from_merge_request' do + before do + stub_post('/projects/3/merge_requests/2/unsubscribe', 'merge_request') @merge_request = Gitlab.unsubscribe_from_merge_request(3, 2) end - it "gets the correct resource" do - expect(a_post("/projects/3/merge_requests/2/unsubscribe")).to have_been_made - end - - it "returns information about a merge request" do - expect(@merge_request.project_id).to eq(3) - end - end - - describe ".merge_request_discussions" do - before do - stub_get("/projects/3/merge_requests/2/discussions", "merge_request_discussions") + it 'gets the correct resource' do + expect(a_post('/projects/3/merge_requests/2/unsubscribe')).to have_been_made + end + + it 'returns information about a merge request' do + expect(@merge_request.project_id).to eq(3) + end + end + + describe '.merge_request_discussions' do + before do + stub_get('/projects/3/merge_requests/2/discussions', 'merge_request_discussions') @discussions = Gitlab.merge_request_discussions(3, 2) end - it "gets the correct resource" do - expect(a_get("/projects/3/merge_requests/2/discussions")).to have_been_made - end - - it "returns information about the discussions" do + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/2/discussions')).to have_been_made + end + + it 'returns information about the discussions' do expect(@discussions.length).to eq(1) expect(@discussions.first.id).to eq('7d66bf19bf835e6a4666130544ba1b5c343fc705') end end - describe ".merge_request_discussion" do - before do - stub_get("/projects/3/merge_requests/2/discussions/1", "merge_request_discussion") + describe '.merge_request_discussion' do + before do + stub_get('/projects/3/merge_requests/2/discussions/1', 'merge_request_discussion') @discussion = Gitlab.merge_request_discussion(3, 2, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/merge_requests/2/discussions/1")).to have_been_made - end - - it "returns information about the discussions" do + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/2/discussions/1')).to have_been_made + end + + it 'returns information about the discussions' do expect(@discussion.id).to eq('7d66bf19bf835e6a4666130544ba1b5c343fc705') end end - describe ".create_merge_request_discussion" do - before do - stub_post("/projects/3/merge_requests/2/discussions", "merge_request_discussion") - @discussion = Gitlab.create_merge_request_discussion(3, 2, body: 'Discussion', position: {old_line: 1}) - end - - it "posts the correct resource" do - expect(a_post("/projects/3/merge_requests/2/discussions"). - with(body: 'body=Discussion&position[old_line]=1')).to have_been_made - end - - it "returns information about the discussions" do + describe '.create_merge_request_discussion' do + before do + stub_post('/projects/3/merge_requests/2/discussions', 'merge_request_discussion') + @discussion = Gitlab.create_merge_request_discussion(3, 2, body: 'Discussion', position: { old_line: 1 }) + end + + it 'posts the correct resource' do + expect(a_post('/projects/3/merge_requests/2/discussions') + .with(body: 'body=Discussion&position[old_line]=1')).to have_been_made + end + + it 'returns information about the discussions' do expect(@discussion.id).to eq('7d66bf19bf835e6a4666130544ba1b5c343fc705') end end - describe ".resolve_merge_request_discussion" do - before do - stub_put("/projects/3/merge_requests/2/discussions/1", "merge_request_discussion") + describe '.resolve_merge_request_discussion' do + before do + stub_put('/projects/3/merge_requests/2/discussions/1', 'merge_request_discussion') @discussion = Gitlab.resolve_merge_request_discussion(3, 2, 1, resolved: true) end - it "puts the correct resource" do - expect(a_put("/projects/3/merge_requests/2/discussions/1"). - with(body: 'resolved=true')).to have_been_made - end - - it "returns information about the discussions" do + it 'puts the correct resource' do + expect(a_put('/projects/3/merge_requests/2/discussions/1') + .with(body: 'resolved=true')).to have_been_made + end + + it 'returns information about the discussions' do expect(@discussion.id).to eq('7d66bf19bf835e6a4666130544ba1b5c343fc705') note = @discussion.notes.first expect(note['id']).to eq(1758) end end - describe ".create_merge_request_discussion_note" do - before do - stub_post("/projects/3/merge_requests/2/discussions/1/notes", "merge_request_discussion_note") + describe '.create_merge_request_discussion_note' do + before do + stub_post('/projects/3/merge_requests/2/discussions/1/notes', 'merge_request_discussion_note') @note = Gitlab.create_merge_request_discussion_note(3, 2, 1, body: 'note') end - it "posts the correct resource" do - expect(a_post("/projects/3/merge_requests/2/discussions/1/notes"). - with(body: 'body=note')).to have_been_made - end - - it "returns information about the note" do + it 'posts the correct resource' do + expect(a_post('/projects/3/merge_requests/2/discussions/1/notes') + .with(body: 'body=note')).to have_been_made + end + + it 'returns information about the note' do expect(@note.id).to eq(1775) end end - describe ".update_merge_request_discussion_note" do - before do - stub_put("/projects/3/merge_requests/2/discussions/1/notes/1", "merge_request_discussion_note") + describe '.update_merge_request_discussion_note' do + before do + stub_put('/projects/3/merge_requests/2/discussions/1/notes/1', 'merge_request_discussion_note') @note = Gitlab.update_merge_request_discussion_note(3, 2, 1, 1, body: 'note2') end - it "puts the correct resource" do - expect(a_put("/projects/3/merge_requests/2/discussions/1/notes/1"). - with(body: 'body=note2')).to have_been_made - end - - it "returns information about the note" do + it 'puts the correct resource' do + expect(a_put('/projects/3/merge_requests/2/discussions/1/notes/1') + .with(body: 'body=note2')).to have_been_made + end + + it 'returns information about the note' do expect(@note.id).to eq(1775) end end - describe ".delete_merge_request_discussion_note" do - before do - stub_request(:delete, "https://api.example.com/projects/3/merge_requests/2/discussions/1/notes/1").to_return(body: '') + describe '.delete_merge_request_discussion_note' do + before do + stub_request(:delete, 'https://api.example.com/projects/3/merge_requests/2/discussions/1/notes/1').to_return(body: '') @note = Gitlab.delete_merge_request_discussion_note(3, 2, 1, 1) end - it "deletes the correct resource" do - expect(a_delete("/projects/3/merge_requests/2/discussions/1/notes/1")).to have_been_made - end - - it "returns nothing" do + it 'deletes the correct resource' do + expect(a_delete('/projects/3/merge_requests/2/discussions/1/notes/1')).to have_been_made + end + + it 'returns nothing' do expect(@note).to be_falsy end end + + describe '.merge_request_diff_versions' do + before do + stub_get('/projects/3/merge_requests/105/versions', 'merge_request_diff_versions') + @versions = Gitlab.merge_request_diff_versions(3, 105) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/105/versions')).to have_been_made + end + + it 'returns an array of the versions' do + expect(@versions.length).to eq(2) + expect(@versions.first.head_commit_sha).to eq('33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30') + end + end + + describe '.merge_request_diff_version' do + before do + stub_get('/projects/3/merge_requests/105/versions/1', 'merge_request_diff_version') + @diff = Gitlab.merge_request_diff_version(3, 105, 1) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/105/versions/1')).to have_been_made + end + + it 'returns diff, with array of diffs in version' do + expect(@diff.diffs).to be_a Array + expect(@diff.diffs.first['old_path']).to eq('LICENSE') + end + end end diff --git a/spec/gitlab/client/milestones_spec.rb b/spec/gitlab/client/milestones_spec.rb index 153a429..2d3b8cf 100644 --- a/spec/gitlab/client/milestones_spec.rb +++ b/spec/gitlab/client/milestones_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".milestones" do + describe '.milestones' do before do - stub_get("/projects/3/milestones", "milestones") + stub_get('/projects/3/milestones', 'milestones') @milestones = Gitlab.milestones(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/milestones")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/milestones')).to have_been_made end it "returns a paginated response of project's milestones" do @@ -17,29 +19,29 @@ end end - describe ".milestone" do + describe '.milestone' do before do - stub_get("/projects/3/milestones/1", "milestone") + stub_get('/projects/3/milestones/1', 'milestone') @milestone = Gitlab.milestone(3, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/milestones/1")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/milestones/1')).to have_been_made end - it "returns information about a milestone" do + it 'returns information about a milestone' do expect(@milestone.project_id).to eq(3) end end - describe ".milestone_issues" do + describe '.milestone_issues' do before do - stub_get("/projects/3/milestones/1/issues", "milestone_issues") + stub_get('/projects/3/milestones/1/issues', 'milestone_issues') @milestone_issues = Gitlab.milestone_issues(3, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/milestones/1/issues")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/milestones/1/issues')).to have_been_made end it "returns a paginated response of milestone's issues" do @@ -48,14 +50,14 @@ end end - describe ".milestone_merge_requests" do + describe '.milestone_merge_requests' do before do - stub_get("/projects/3/milestones/1/merge_requests", "milestone_merge_requests") + stub_get('/projects/3/milestones/1/merge_requests', 'milestone_merge_requests') @milestone_merge_requests = Gitlab.milestone_merge_requests(3, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/milestones/1/merge_requests")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/milestones/1/merge_requests')).to have_been_made end it "returns a paginated response of milestone's merge_requests" do @@ -64,35 +66,46 @@ end end - describe ".create_milestone" do + describe '.create_milestone' do before do - stub_post("/projects/3/milestones", "milestone") + stub_post('/projects/3/milestones', 'milestone') @milestone = Gitlab.create_milestone(3, 'title') end - it "gets the correct resource" do - expect(a_post("/projects/3/milestones"). - with(body: { title: 'title' })).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/milestones') + .with(body: { title: 'title' })).to have_been_made end - it "returns information about a created milestone" do + it 'returns information about a created milestone' do expect(@milestone.project_id).to eq(3) end end - describe ".edit_milestone" do + describe '.edit_milestone' do before do - stub_put("/projects/3/milestones/33", "milestone") + stub_put('/projects/3/milestones/33', 'milestone') @milestone = Gitlab.edit_milestone(3, 33, title: 'title') end - it "gets the correct resource" do - expect(a_put("/projects/3/milestones/33"). - with(body: { title: 'title' })).to have_been_made + it 'gets the correct resource' do + expect(a_put('/projects/3/milestones/33') + .with(body: { title: 'title' })).to have_been_made end - it "returns information about an edited milestone" do + it 'returns information about an edited milestone' do expect(@milestone.project_id).to eq(3) end end + + describe '.delete_milestone' do + before do + stub_delete('/projects/3/milestones/33', 'empty') + @milestone = Gitlab.delete_milestone(3, 33) + end + + it 'gets the correct resource' do + expect(a_delete('/projects/3/milestones/33')).to have_been_made + end + end end diff --git a/spec/gitlab/client/namespaces_spec.rb b/spec/gitlab/client/namespaces_spec.rb index 2212288..3d7ff9b 100644 --- a/spec/gitlab/client/namespaces_spec.rb +++ b/spec/gitlab/client/namespaces_spec.rb @@ -1,22 +1,24 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do it { is_expected.to respond_to :namespaces } - describe ".namespaces" do + describe '.namespaces' do before do - stub_get("/namespaces", "namespaces") + stub_get('/namespaces', 'namespaces') @namespaces = Gitlab.namespaces end - it "gets the correct resource" do - expect(a_get("/namespaces")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/namespaces')).to have_been_made end - it "returns a paginated response of namespaces" do + it 'returns a paginated response of namespaces' do expect(@namespaces).to be_a Gitlab::PaginatedResponse - expect(@namespaces.first.path).to eq("john") - expect(@namespaces.first.kind).to eq("user") + expect(@namespaces.first.path).to eq('john') + expect(@namespaces.first.kind).to eq('user') end end end diff --git a/spec/gitlab/client/notes_spec.rb b/spec/gitlab/client/notes_spec.rb index 994de56..43a3f18 100644 --- a/spec/gitlab/client/notes_spec.rb +++ b/spec/gitlab/client/notes_spec.rb @@ -1,331 +1,333 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe "notes" do - context "when wall notes" do - before do - stub_get("/projects/3/notes", "notes") + describe 'notes' do + context 'when wall notes' do + before do + stub_get('/projects/3/notes', 'notes') @notes = Gitlab.notes(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/notes")).to have_been_made - end - - it "returns a paginated response of notes" do + it 'gets the correct resource' do + expect(a_get('/projects/3/notes')).to have_been_made + end + + it 'returns a paginated response of notes' do expect(@notes).to be_a Gitlab::PaginatedResponse - expect(@notes.first.author.name).to eq("John Smith") - end - end - - context "when issue notes" do - before do - stub_get("/projects/3/issues/7/notes", "notes") + expect(@notes.first.author.name).to eq('John Smith') + end + end + + context 'when issue notes' do + before do + stub_get('/projects/3/issues/7/notes', 'notes') @notes = Gitlab.issue_notes(3, 7) end - it "gets the correct resource" do - expect(a_get("/projects/3/issues/7/notes")).to have_been_made - end - - it "returns a paginated response of notes" do + it 'gets the correct resource' do + expect(a_get('/projects/3/issues/7/notes')).to have_been_made + end + + it 'returns a paginated response of notes' do expect(@notes).to be_a Gitlab::PaginatedResponse - expect(@notes.first.author.name).to eq("John Smith") - end - end - - context "when snippet notes" do - before do - stub_get("/projects/3/snippets/7/notes", "notes") + expect(@notes.first.author.name).to eq('John Smith') + end + end + + context 'when snippet notes' do + before do + stub_get('/projects/3/snippets/7/notes', 'notes') @notes = Gitlab.snippet_notes(3, 7) end - it "gets the correct resource" do - expect(a_get("/projects/3/snippets/7/notes")).to have_been_made - end - - it "returns a paginated response of notes" do + it 'gets the correct resource' do + expect(a_get('/projects/3/snippets/7/notes')).to have_been_made + end + + it 'returns a paginated response of notes' do expect(@notes).to be_a Gitlab::PaginatedResponse - expect(@notes.first.author.name).to eq("John Smith") - end - end - - context "when merge_request notes" do - before do - stub_get("/projects/3/merge_requests/7/notes", "notes") + expect(@notes.first.author.name).to eq('John Smith') + end + end + + context 'when merge_request notes' do + before do + stub_get('/projects/3/merge_requests/7/notes', 'notes') @notes = Gitlab.merge_request_notes(3, 7) end - it "gets the correct resource" do - expect(a_get("/projects/3/merge_requests/7/notes")).to have_been_made - end - - it "returns a paginated response of notes" do + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/7/notes')).to have_been_made + end + + it 'returns a paginated response of notes' do expect(@notes).to be_a Gitlab::PaginatedResponse - expect(@notes.first.author.name).to eq("John Smith") - end - end - end - - describe "note" do - context "when wall note" do - before do - stub_get("/projects/3/notes/1201", "note") + expect(@notes.first.author.name).to eq('John Smith') + end + end + end + + describe 'note' do + context 'when wall note' do + before do + stub_get('/projects/3/notes/1201', 'note') @note = Gitlab.note(3, 1201) end - it "gets the correct resource" do - expect(a_get("/projects/3/notes/1201")).to have_been_made - end - - it "returns information about a note" do - expect(@note.body).to eq("The solution is rather tricky") - expect(@note.author.name).to eq("John Smith") - end - end - - context "when issue note" do - before do - stub_get("/projects/3/issues/7/notes/1201", "note") + it 'gets the correct resource' do + expect(a_get('/projects/3/notes/1201')).to have_been_made + end + + it 'returns information about a note' do + expect(@note.body).to eq('The solution is rather tricky') + expect(@note.author.name).to eq('John Smith') + end + end + + context 'when issue note' do + before do + stub_get('/projects/3/issues/7/notes/1201', 'note') @note = Gitlab.issue_note(3, 7, 1201) end - it "gets the correct resource" do - expect(a_get("/projects/3/issues/7/notes/1201")).to have_been_made - end - - it "returns information about a note" do - expect(@note.body).to eq("The solution is rather tricky") - expect(@note.author.name).to eq("John Smith") - end - end - - context "when snippet note" do - before do - stub_get("/projects/3/snippets/7/notes/1201", "note") + it 'gets the correct resource' do + expect(a_get('/projects/3/issues/7/notes/1201')).to have_been_made + end + + it 'returns information about a note' do + expect(@note.body).to eq('The solution is rather tricky') + expect(@note.author.name).to eq('John Smith') + end + end + + context 'when snippet note' do + before do + stub_get('/projects/3/snippets/7/notes/1201', 'note') @note = Gitlab.snippet_note(3, 7, 1201) end - it "gets the correct resource" do - expect(a_get("/projects/3/snippets/7/notes/1201")).to have_been_made - end - - it "returns information about a note" do - expect(@note.body).to eq("The solution is rather tricky") - expect(@note.author.name).to eq("John Smith") - end - end - - context "when merge request note" do - before do - stub_get("/projects/3/merge_requests/7/notes/1201", "note") + it 'gets the correct resource' do + expect(a_get('/projects/3/snippets/7/notes/1201')).to have_been_made + end + + it 'returns information about a note' do + expect(@note.body).to eq('The solution is rather tricky') + expect(@note.author.name).to eq('John Smith') + end + end + + context 'when merge request note' do + before do + stub_get('/projects/3/merge_requests/7/notes/1201', 'note') @note = Gitlab.merge_request_note(3, 7, 1201) end - it "gets the correct resource" do - expect(a_get("/projects/3/merge_requests/7/notes/1201")).to have_been_made - end - - it "returns information about a note" do - expect(@note.body).to eq("The solution is rather tricky") - expect(@note.author.name).to eq("John Smith") - end - end - end - - describe "create note" do - context "when wall note" do - before do - stub_post("/projects/3/notes", "note") - @note = Gitlab.create_note(3, "The solution is rather tricky") - end - - it "gets the correct resource" do - expect(a_post("/projects/3/notes"). - with(body: { body: 'The solution is rather tricky' })).to have_been_made - end - - it "returns information about a created note" do - expect(@note.body).to eq("The solution is rather tricky") - expect(@note.author.name).to eq("John Smith") - end - end - - context "when issue note" do - before do - stub_post("/projects/3/issues/7/notes", "note") - @note = Gitlab.create_issue_note(3, 7, "The solution is rather tricky") - end - - it "gets the correct resource" do - expect(a_post("/projects/3/issues/7/notes"). - with(body: { body: 'The solution is rather tricky' })).to have_been_made - end - - it "returns information about a created note" do - expect(@note.body).to eq("The solution is rather tricky") - expect(@note.author.name).to eq("John Smith") - end - end - - context "when snippet note" do - before do - stub_post("/projects/3/snippets/7/notes", "note") - @note = Gitlab.create_snippet_note(3, 7, "The solution is rather tricky") - end - - it "gets the correct resource" do - expect(a_post("/projects/3/snippets/7/notes"). - with(body: { body: 'The solution is rather tricky' })).to have_been_made - end - - it "returns information about a created note" do - expect(@note.body).to eq("The solution is rather tricky") - expect(@note.author.name).to eq("John Smith") - end - end - - context "when merge_request note" do - before do - stub_post("/projects/3/merge_requests/7/notes", "note") - @note = Gitlab.create_merge_request_note(3, 7, "The solution is rather tricky") - end - - it "gets the correct resource" do - expect(a_post("/projects/3/merge_requests/7/notes"). - with(body: { body: 'The solution is rather tricky' })).to have_been_made - end - - it "returns information about a created note" do - expect(@note.body).to eq("The solution is rather tricky") - expect(@note.author.name).to eq("John Smith") - end - end - end - - describe "delete note" do - context "when wall note" do - before do - stub_delete("/projects/3/notes/1201", "note") + it 'gets the correct resource' do + expect(a_get('/projects/3/merge_requests/7/notes/1201')).to have_been_made + end + + it 'returns information about a note' do + expect(@note.body).to eq('The solution is rather tricky') + expect(@note.author.name).to eq('John Smith') + end + end + end + + describe 'create note' do + context 'when wall note' do + before do + stub_post('/projects/3/notes', 'note') + @note = Gitlab.create_note(3, 'The solution is rather tricky') + end + + it 'gets the correct resource' do + expect(a_post('/projects/3/notes') + .with(body: { body: 'The solution is rather tricky' })).to have_been_made + end + + it 'returns information about a created note' do + expect(@note.body).to eq('The solution is rather tricky') + expect(@note.author.name).to eq('John Smith') + end + end + + context 'when issue note' do + before do + stub_post('/projects/3/issues/7/notes', 'note') + @note = Gitlab.create_issue_note(3, 7, 'The solution is rather tricky') + end + + it 'gets the correct resource' do + expect(a_post('/projects/3/issues/7/notes') + .with(body: { body: 'The solution is rather tricky' })).to have_been_made + end + + it 'returns information about a created note' do + expect(@note.body).to eq('The solution is rather tricky') + expect(@note.author.name).to eq('John Smith') + end + end + + context 'when snippet note' do + before do + stub_post('/projects/3/snippets/7/notes', 'note') + @note = Gitlab.create_snippet_note(3, 7, 'The solution is rather tricky') + end + + it 'gets the correct resource' do + expect(a_post('/projects/3/snippets/7/notes') + .with(body: { body: 'The solution is rather tricky' })).to have_been_made + end + + it 'returns information about a created note' do + expect(@note.body).to eq('The solution is rather tricky') + expect(@note.author.name).to eq('John Smith') + end + end + + context 'when merge_request note' do + before do + stub_post('/projects/3/merge_requests/7/notes', 'note') + @note = Gitlab.create_merge_request_note(3, 7, 'The solution is rather tricky') + end + + it 'gets the correct resource' do + expect(a_post('/projects/3/merge_requests/7/notes') + .with(body: { body: 'The solution is rather tricky' })).to have_been_made + end + + it 'returns information about a created note' do + expect(@note.body).to eq('The solution is rather tricky') + expect(@note.author.name).to eq('John Smith') + end + end + end + + describe 'delete note' do + context 'when wall note' do + before do + stub_delete('/projects/3/notes/1201', 'note') @note = Gitlab.delete_note(3, 1201) end - it "gets the correct resource" do - expect(a_delete("/projects/3/notes/1201")).to have_been_made - end - - it "returns information about a deleted note" do - expect(@note.id).to eq(1201) - end - end - - context "when issue note" do - before do - stub_delete("/projects/3/issues/7/notes/1201", "note") + it 'gets the correct resource' do + expect(a_delete('/projects/3/notes/1201')).to have_been_made + end + + it 'returns information about a deleted note' do + expect(@note.id).to eq(1201) + end + end + + context 'when issue note' do + before do + stub_delete('/projects/3/issues/7/notes/1201', 'note') @note = Gitlab.delete_issue_note(3, 7, 1201) end - it "gets the correct resource" do - expect(a_delete("/projects/3/issues/7/notes/1201")).to have_been_made - end - - it "returns information about a deleted issue note" do - expect(@note.id).to eq(1201) - end - end - - context "when snippet note" do - before do - stub_delete("/projects/3/snippets/7/notes/1201", "note") + it 'gets the correct resource' do + expect(a_delete('/projects/3/issues/7/notes/1201')).to have_been_made + end + + it 'returns information about a deleted issue note' do + expect(@note.id).to eq(1201) + end + end + + context 'when snippet note' do + before do + stub_delete('/projects/3/snippets/7/notes/1201', 'note') @note = Gitlab.delete_snippet_note(3, 7, 1201) end - it "gets the correct resource" do - expect(a_delete("/projects/3/snippets/7/notes/1201")).to have_been_made - end - - it "returns information about a deleted snippet note" do - expect(@note.id).to eq(1201) - end - end - - context "when merge request note" do - before do - stub_delete("/projects/3/merge_requests/7/notes/1201", "note") + it 'gets the correct resource' do + expect(a_delete('/projects/3/snippets/7/notes/1201')).to have_been_made + end + + it 'returns information about a deleted snippet note' do + expect(@note.id).to eq(1201) + end + end + + context 'when merge request note' do + before do + stub_delete('/projects/3/merge_requests/7/notes/1201', 'note') @note = Gitlab.delete_merge_request_note(3, 7, 1201) end - it "gets the correct resource" do - expect(a_delete("/projects/3/merge_requests/7/notes/1201")).to have_been_made - end - - it "returns information about a deleted merge request note" do - expect(@note.id).to eq(1201) - end - end - end - - describe "modify note" do - context "when wall note" do - before do - stub_put("/projects/3/notes/1201", "note") - @note = Gitlab.edit_note(3, 1201, "edited wall note content") - end - - it "gets the correct resource" do - expect(a_put("/projects/3/notes/1201"). - with(body: {body: 'edited wall note content'})).to have_been_made - end - - it "returns information about a modified note" do - expect(@note.id).to eq(1201) - end - end - - context "when issue note" do - before do - stub_put("/projects/3/issues/7/notes/1201", "note") - @note = Gitlab.edit_issue_note(3, 7, 1201, "edited issue note content") - end - - it "gets the correct resource" do - expect(a_put("/projects/3/issues/7/notes/1201"). - with(body: {body: 'edited issue note content'})).to have_been_made - end - - it "returns information about a modified issue note" do - expect(@note.id).to eq(1201) - end - end - - context "when snippet note" do - before do - stub_put("/projects/3/snippets/7/notes/1201", "note") - @note = Gitlab.edit_snippet_note(3, 7, 1201, "edited snippet note content") - end - - it "gets the correct resource" do - expect(a_put("/projects/3/snippets/7/notes/1201"). - with(body: {body: 'edited snippet note content'})).to have_been_made - end - - it "returns information about a modified snippet note" do - expect(@note.id).to eq(1201) - end - end - - context "when merge request note" do - before do - stub_put("/projects/3/merge_requests/7/notes/1201", "note") - @note = Gitlab.edit_merge_request_note(3, 7, 1201, "edited merge request note content") - end - - it "gets the correct resource" do - expect(a_put("/projects/3/merge_requests/7/notes/1201"). - with(body: {body: 'edited merge request note content'})).to have_been_made - end - - it "returns information about a modified request note" do + it 'gets the correct resource' do + expect(a_delete('/projects/3/merge_requests/7/notes/1201')).to have_been_made + end + + it 'returns information about a deleted merge request note' do + expect(@note.id).to eq(1201) + end + end + end + + describe 'modify note' do + context 'when wall note' do + before do + stub_put('/projects/3/notes/1201', 'note') + @note = Gitlab.edit_note(3, 1201, 'edited wall note content') + end + + it 'gets the correct resource' do + expect(a_put('/projects/3/notes/1201') + .with(body: { body: 'edited wall note content' })).to have_been_made + end + + it 'returns information about a modified note' do + expect(@note.id).to eq(1201) + end + end + + context 'when issue note' do + before do + stub_put('/projects/3/issues/7/notes/1201', 'note') + @note = Gitlab.edit_issue_note(3, 7, 1201, 'edited issue note content') + end + + it 'gets the correct resource' do + expect(a_put('/projects/3/issues/7/notes/1201') + .with(body: { body: 'edited issue note content' })).to have_been_made + end + + it 'returns information about a modified issue note' do + expect(@note.id).to eq(1201) + end + end + + context 'when snippet note' do + before do + stub_put('/projects/3/snippets/7/notes/1201', 'note') + @note = Gitlab.edit_snippet_note(3, 7, 1201, 'edited snippet note content') + end + + it 'gets the correct resource' do + expect(a_put('/projects/3/snippets/7/notes/1201') + .with(body: { body: 'edited snippet note content' })).to have_been_made + end + + it 'returns information about a modified snippet note' do + expect(@note.id).to eq(1201) + end + end + + context 'when merge request note' do + before do + stub_put('/projects/3/merge_requests/7/notes/1201', 'note') + @note = Gitlab.edit_merge_request_note(3, 7, 1201, 'edited merge request note content') + end + + it 'gets the correct resource' do + expect(a_put('/projects/3/merge_requests/7/notes/1201') + .with(body: { body: 'edited merge request note content' })).to have_been_made + end + + it 'returns information about a modified request note' do expect(@note.id).to eq(1201) end end diff --git a/spec/gitlab/client/pipeline_schedules_spec.rb b/spec/gitlab/client/pipeline_schedules_spec.rb index 232ebc2..9117b3d 100644 --- a/spec/gitlab/client/pipeline_schedules_spec.rb +++ b/spec/gitlab/client/pipeline_schedules_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".pipeline_schedules" do + describe '.pipeline_schedules' do before do - stub_get("/projects/3/pipeline_schedules", "pipeline_schedules") + stub_get('/projects/3/pipeline_schedules', 'pipeline_schedules') @pipeline_schedules = Gitlab.pipeline_schedules(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/pipeline_schedules")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/pipeline_schedules')).to have_been_made end it "returns a response of project's pipeline schedules" do @@ -16,14 +18,14 @@ end end - describe ".pipeline_schedule" do + describe '.pipeline_schedule' do before do - stub_get("/projects/3/pipeline_schedules/5", "pipeline_schedule") + stub_get('/projects/3/pipeline_schedules/5', 'pipeline_schedule') @pipeline_schedule = Gitlab.pipeline_schedule(3, 5) end - it "gets the correct resource" do - expect(a_get("/projects/3/pipeline_schedules/5")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/pipeline_schedules/5')).to have_been_made end it "returns a response of project's pipeline schedules" do @@ -31,128 +33,127 @@ end end - describe ".create_pipeline_schedule" do + describe '.create_pipeline_schedule' do before do - stub_post("/projects/3/pipeline_schedules", "pipeline_schedule_create") + stub_post('/projects/3/pipeline_schedules', 'pipeline_schedule_create') @pipeline_schedule_create = Gitlab.create_pipeline_schedule(3) end - it "gets the correct resource" do - expect(a_post("/projects/3/pipeline_schedules")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/pipeline_schedules')).to have_been_made end - it "returns a single pipeline schedule" do + it 'returns a single pipeline schedule' do expect(@pipeline_schedule_create).to be_a Gitlab::ObjectifiedHash end - it "returns information about a pipeline schedule" do - expect(@pipeline_schedule_create.owner.name).to eq("Administrator") + it 'returns information about a pipeline schedule' do + expect(@pipeline_schedule_create.owner.name).to eq('Administrator') end end - describe ".edit_pipeline_schedule" do + describe '.edit_pipeline_schedule' do before do - stub_put("/projects/3/pipeline_schedules/13", "pipeline_schedule_update") + stub_put('/projects/3/pipeline_schedules/13', 'pipeline_schedule_update') @pipeline_schedule_update = Gitlab.edit_pipeline_schedule(3, 13) end - it "gets the correct resource" do - expect(a_put("/projects/3/pipeline_schedules/13")).to have_been_made + it 'gets the correct resource' do + expect(a_put('/projects/3/pipeline_schedules/13')).to have_been_made end - it "returns a single pipeline schedule" do + it 'returns a single pipeline schedule' do expect(@pipeline_schedule_update).to be_a Gitlab::ObjectifiedHash end - it "returns information about a pipeline schedule" do - expect(@pipeline_schedule_update.owner.name).to eq("Administrator") + it 'returns information about a pipeline schedule' do + expect(@pipeline_schedule_update.owner.name).to eq('Administrator') end end - describe ".pipeline_schedule_take_ownership" do + describe '.pipeline_schedule_take_ownership' do before do - stub_post("/projects/3/pipeline_schedules/13/take_ownership", "pipeline_schedule") + stub_post('/projects/3/pipeline_schedules/13/take_ownership', 'pipeline_schedule') @pipeline_schedule = Gitlab.pipeline_schedule_take_ownership(3, 13) end - it "gets the correct resource" do - expect(a_post("/projects/3/pipeline_schedules/13/take_ownership")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/pipeline_schedules/13/take_ownership')).to have_been_made end - it "returns information about the pipeline schedule" do - expect(@pipeline_schedule.created_at).to eq("2017-05-19T13:31:08.849Z") - expect(@pipeline_schedule.description).to eq("Test schedule pipeline") + it 'returns information about the pipeline schedule' do + expect(@pipeline_schedule.created_at).to eq('2017-05-19T13:31:08.849Z') + expect(@pipeline_schedule.description).to eq('Test schedule pipeline') end end - describe ".delete_pipeline_schedule" do + describe '.delete_pipeline_schedule' do before do - stub_delete("/projects/3/pipeline_schedules/13", "pipeline_schedule") - @pipeline_schedule = Gitlab.delete_pipeline_schedule(3,13) + stub_delete('/projects/3/pipeline_schedules/13', 'pipeline_schedule') + @pipeline_schedule = Gitlab.delete_pipeline_schedule(3, 13) end - it "gets the correct resource" do - expect(a_delete("/projects/3/pipeline_schedules/13")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/pipeline_schedules/13')).to have_been_made end - it "returns a single pipeline" do + it 'returns a single pipeline' do expect(@pipeline_schedule).to be_a Gitlab::ObjectifiedHash end - it "returns information about the deleted pipeline" do + it 'returns information about the deleted pipeline' do # expect(@pipeline_schedule.id).to eq(13) end end - describe ".create_pipeline_schedule_variable" do + describe '.create_pipeline_schedule_variable' do before do - stub_post("/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value", "pipeline_schedule_variable") - @pipeline_schedule_variable = Gitlab.create_pipeline_schedule_variable(3, 13, { - key: "NEW VARIABLE", - value: "new value" - }) + stub_post('/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value', 'pipeline_schedule_variable') + @pipeline_schedule_variable = Gitlab.create_pipeline_schedule_variable(3, 13, + key: 'NEW VARIABLE', + value: 'new value') end - it "gets the correct resource" do - expect(a_post("/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value')).to have_been_made end - it "returns a single variable" do + it 'returns a single variable' do expect(@pipeline_schedule_variable).to be_a Gitlab::ObjectifiedHash end - it "returns the created variable" do - expect(@pipeline_schedule_variable.value).to eq("new value") + it 'returns the created variable' do + expect(@pipeline_schedule_variable.value).to eq('new value') end end - describe ".edit_pipeline_schedule_variable" do + describe '.edit_pipeline_schedule_variable' do before do - stub_put("/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE?value=update%20value", "pipeline_schedule_variable_update") - @pipeline_schedule_variable = Gitlab.edit_pipeline_schedule_variable(3, 13, "NEW VARIABLE", { value: "update value" }) + stub_put('/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE?value=update%20value', 'pipeline_schedule_variable_update') + @pipeline_schedule_variable = Gitlab.edit_pipeline_schedule_variable(3, 13, 'NEW VARIABLE', value: 'update value') end - it "returns a single variable" do + it 'returns a single variable' do expect(@pipeline_schedule_variable).to be_a Gitlab::ObjectifiedHash end - it "has the updated value" do - expect(@pipeline_schedule_variable.value).to eq("update value") + it 'has the updated value' do + expect(@pipeline_schedule_variable.value).to eq('update value') end end - describe ".delete_pipeline_schedule_variable" do + describe '.delete_pipeline_schedule_variable' do before do - stub_delete("/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE", "pipeline_schedule_variable") - @pipeline_schedule_variable = Gitlab.delete_pipeline_schedule_variable(3, 13, "NEW VARIABLE") + stub_delete('/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE', 'pipeline_schedule_variable') + @pipeline_schedule_variable = Gitlab.delete_pipeline_schedule_variable(3, 13, 'NEW VARIABLE') end - it "returns a single variable" do + it 'returns a single variable' do expect(@pipeline_schedule_variable).to be_a Gitlab::ObjectifiedHash end - it "has the value of the deleted variable" do - expect(@pipeline_schedule_variable.value).to eq("new value") + it 'has the value of the deleted variable' do + expect(@pipeline_schedule_variable.value).to eq('new value') end end end diff --git a/spec/gitlab/client/pipeline_triggers_spec.rb b/spec/gitlab/client/pipeline_triggers_spec.rb index e176fc5..29fbba7 100644 --- a/spec/gitlab/client/pipeline_triggers_spec.rb +++ b/spec/gitlab/client/pipeline_triggers_spec.rb @@ -1,114 +1,116 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do it { is_expected.to respond_to :delete_trigger } - describe ".triggers" do + describe '.triggers' do before do - stub_get("/projects/3/triggers", "triggers") + stub_get('/projects/3/triggers', 'triggers') @triggers = Gitlab.triggers(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/triggers")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/triggers')).to have_been_made end it "returns an array of project's triggers" do expect(@triggers).to be_a Gitlab::PaginatedResponse - expect(@triggers.first.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7") + expect(@triggers.first.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7') end end - describe ".trigger" do + describe '.trigger' do before do - stub_get("/projects/3/triggers/10", "trigger") + stub_get('/projects/3/triggers/10', 'trigger') @trigger = Gitlab.trigger(3, 10) end - it "gets the correct resource" do - expect(a_get("/projects/3/triggers/10")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/triggers/10')).to have_been_made end - it "returns information about a trigger" do - expect(@trigger.created_at).to eq("2016-01-07T09:53:58.235Z") - expect(@trigger.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7") + it 'returns information about a trigger' do + expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z') + expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7') end end - describe ".create_trigger" do + describe '.create_trigger' do before do - stub_post("/projects/3/triggers", "trigger") - @trigger = Gitlab.create_trigger(3, "my description") + stub_post('/projects/3/triggers', 'trigger') + @trigger = Gitlab.create_trigger(3, 'my description') end - it "gets the correct resource" do - expect(a_post("/projects/3/triggers"). - with(body: { description: "my description" })).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/triggers') + .with(body: { description: 'my description' })).to have_been_made end - it "returns information about a new trigger" do - expect(@trigger.created_at).to eq("2016-01-07T09:53:58.235Z") - expect(@trigger.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7") + it 'returns information about a new trigger' do + expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z') + expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7') end end - describe ".update_trigger" do + describe '.update_trigger' do before do - stub_put("/projects/3/triggers/1", "trigger") - @trigger = Gitlab.update_trigger(3, 1, description: "my description") + stub_put('/projects/3/triggers/1', 'trigger') + @trigger = Gitlab.update_trigger(3, 1, description: 'my description') end - it "gets the correct resource" do - expect(a_put("/projects/3/triggers/1"). - with(body: { description: "my description" })).to have_been_made + it 'gets the correct resource' do + expect(a_put('/projects/3/triggers/1') + .with(body: { description: 'my description' })).to have_been_made end - it "returns information about the trigger" do - expect(@trigger.created_at).to eq("2016-01-07T09:53:58.235Z") - expect(@trigger.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7") + it 'returns information about the trigger' do + expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z') + expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7') end end - describe ".trigger_take_ownership" do + describe '.trigger_take_ownership' do before do - stub_post("/projects/3/triggers/1/take_ownership", "trigger") + stub_post('/projects/3/triggers/1/take_ownership', 'trigger') @trigger = Gitlab.trigger_take_ownership(3, 1) end - it "gets the correct resource" do - expect(a_post("/projects/3/triggers/1/take_ownership")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/triggers/1/take_ownership')).to have_been_made end - it "returns information about the trigger" do - expect(@trigger.created_at).to eq("2016-01-07T09:53:58.235Z") - expect(@trigger.token).to eq("6d056f63e50fe6f8c5f8f4aa10edb7") + it 'returns information about the trigger' do + expect(@trigger.created_at).to eq('2016-01-07T09:53:58.235Z') + expect(@trigger.token).to eq('6d056f63e50fe6f8c5f8f4aa10edb7') end end - describe ".remove_trigger" do + describe '.remove_trigger' do before do - stub_delete("/projects/3/triggers/10", "empty") + stub_delete('/projects/3/triggers/10', 'empty') @trigger = Gitlab.remove_trigger(3, 10) end - it "gets the correct resource" do - expect(a_delete("/projects/3/triggers/10")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/triggers/10')).to have_been_made end end - describe ".run_trigger" do + describe '.run_trigger' do before do - stub_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline"). - to_return(body: load_fixture("run_trigger"), status: 200) + stub_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline") + .to_return(body: load_fixture('run_trigger'), status: 200) end - context "when private_token is not set" do + context 'when private_token is not set' do before do Gitlab.private_token = nil end - it "does not raise Error::MissingCredentials" do - expect { Gitlab.run_trigger(3, "7b9148c158980bbd9bcea92c17522d", "master", {a: 10}) }.to_not raise_error + it 'does not raise Error::MissingCredentials' do + expect { Gitlab.run_trigger(3, '7b9148c158980bbd9bcea92c17522d', 'master', a: 10) }.not_to raise_error end after do @@ -116,41 +118,41 @@ end end - context "without variables" do + context 'without variables' do before do - @trigger = Gitlab.run_trigger(3, "7b9148c158980bbd9bcea92c17522d", "master") + @trigger = Gitlab.run_trigger(3, '7b9148c158980bbd9bcea92c17522d', 'master') end - it "gets the correct resource" do - expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline"). - with(body: { - token: "7b9148c158980bbd9bcea92c17522d", - ref: "master" - })).to have_been_made + it 'gets the correct resource' do + expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline") + .with(body: { + token: '7b9148c158980bbd9bcea92c17522d', + ref: 'master' + })).to have_been_made end - it "returns information about the triggered build" do + it 'returns information about the triggered build' do expect(@trigger.id).to eq(8) end end - context "with variables" do + context 'with variables' do before do - @trigger = Gitlab.run_trigger(3, "7b9148c158980bbd9bcea92c17522d", "master", {a: 10}) + @trigger = Gitlab.run_trigger(3, '7b9148c158980bbd9bcea92c17522d', 'master', a: 10) end - it "gets the correct resource" do - expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline"). - with(body: { - token: "7b9148c158980bbd9bcea92c17522d", - ref: "master", - variables: {a: "10"} - })).to have_been_made + it 'gets the correct resource' do + expect(a_request(:post, "#{Gitlab.endpoint}/projects/3/trigger/pipeline") + .with(body: { + token: '7b9148c158980bbd9bcea92c17522d', + ref: 'master', + variables: { a: '10' } + })).to have_been_made end - it "returns information about the triggered build" do + it 'returns information about the triggered build' do expect(@trigger.id).to eq(8) - expect(@trigger.variables.a).to eq("10") + expect(@trigger.variables.a).to eq('10') end end end diff --git a/spec/gitlab/client/pipelines_spec.rb b/spec/gitlab/client/pipelines_spec.rb index 9550ec3..d483a3f 100644 --- a/spec/gitlab/client/pipelines_spec.rb +++ b/spec/gitlab/client/pipelines_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".pipelines" do + describe '.pipelines' do before do - stub_get("/projects/3/pipelines", "pipelines") + stub_get('/projects/3/pipelines', 'pipelines') @pipelines = Gitlab.pipelines(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/pipelines")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/pipelines')).to have_been_made end it "returns a paginated response of project's pipelines" do @@ -16,80 +18,95 @@ end end - describe ".pipeline" do + describe '.pipeline' do before do - stub_get("/projects/3/pipelines/46", "pipeline") + stub_get('/projects/3/pipelines/46', 'pipeline') @pipeline = Gitlab.pipeline(3, 46) end - it "gets the correct resource" do - expect(a_get("/projects/3/pipelines/46")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/pipelines/46')).to have_been_made end - it "returns a single pipeline" do + it 'returns a single pipeline' do expect(@pipeline).to be_a Gitlab::ObjectifiedHash end - it "returns information about a pipeline" do + it 'returns information about a pipeline' do expect(@pipeline.id).to eq(46) - expect(@pipeline.user.name).to eq("Administrator") + expect(@pipeline.user.name).to eq('Administrator') end end - describe ".create_pipeline" do + describe '.create_pipeline' do + let(:pipeline_path) { '/projects/3/pipeline?ref=master' } + before do - stub_post("/projects/3/pipeline?ref=master", "pipeline_create") + stub_post(pipeline_path, 'pipeline_create') @pipeline_create = Gitlab.create_pipeline(3, 'master') end - it "gets the correct resource" do - expect(a_post("/projects/3/pipeline?ref=master")).to have_been_made + it 'gets the correct resource' do + expect(a_post(pipeline_path)).to have_been_made end - it "returns a single pipeline" do + it 'returns a single pipeline' do expect(@pipeline_create).to be_a Gitlab::ObjectifiedHash end - it "returns information about a pipeline" do - expect(@pipeline_create.user.name).to eq("Administrator") + it 'returns information about a pipeline' do + expect(@pipeline_create.user.name).to eq('Administrator') + end + + context 'when variables are passed' do + before do + stub_post(pipeline_path, 'pipeline_create') + variables = { 'VAR1' => 'value', VAR2: :value } + @pipeline_create = Gitlab.create_pipeline(3, 'master', variables) + end + + it 'calls with the correct body' do + expected_body = 'variables[][key]=VAR1&variables[][value]=value&variables[][key]=VAR2&variables[][value]=value' + expect(a_post(pipeline_path).with(body: expected_body)).to have_been_made + end end end - describe ".cancel_pipeline" do + describe '.cancel_pipeline' do before do - stub_post("/projects/3/pipelines/46/cancel", "pipeline_cancel") + stub_post('/projects/3/pipelines/46/cancel', 'pipeline_cancel') @pipeline_cancel = Gitlab.cancel_pipeline(3, 46) end - it "gets the correct resource" do - expect(a_post("/projects/3/pipelines/46/cancel")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/pipelines/46/cancel')).to have_been_made end - it "returns a single pipeline" do + it 'returns a single pipeline' do expect(@pipeline_cancel).to be_a Gitlab::ObjectifiedHash end - it "returns information about a pipeline" do - expect(@pipeline_cancel.user.name).to eq("Administrator") + it 'returns information about a pipeline' do + expect(@pipeline_cancel.user.name).to eq('Administrator') end end - describe ".retry_pipeline" do + describe '.retry_pipeline' do before do - stub_post("/projects/3/pipelines/46/retry", "pipeline_retry") + stub_post('/projects/3/pipelines/46/retry', 'pipeline_retry') @pipeline_retry = Gitlab.retry_pipeline(3, 46) end - it "gets the correct resource" do - expect(a_post("/projects/3/pipelines/46/retry")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/pipelines/46/retry')).to have_been_made end - it "returns a single pipeline" do + it 'returns a single pipeline' do expect(@pipeline_retry).to be_a Gitlab::ObjectifiedHash end - it "returns information about a pipeline" do - expect(@pipeline_retry.user.name).to eq("Administrator") + it 'returns information about a pipeline' do + expect(@pipeline_retry.user.name).to eq('Administrator') end end end diff --git a/spec/gitlab/client/project_badges_spec.rb b/spec/gitlab/client/project_badges_spec.rb new file mode 100644 index 0000000..eb6eebf --- /dev/null +++ b/spec/gitlab/client/project_badges_spec.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: true + +# rubocop:disable Style/FormatStringToken + +require 'spec_helper' + +describe Gitlab::Client do + describe '.project_badges' do + before do + stub_get('/projects/3/badges', 'project_badges') + @project_badges = Gitlab.project_badges(3) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/badges')).to have_been_made + end + + it "returns a paginated response of project's badges" do + expect(@project_badges).to be_a Gitlab::PaginatedResponse + end + end + + describe '.project_badge' do + before do + stub_get('/projects/3/badges/3', 'project_badge') + @project_badge = Gitlab.project_badge(3, 3) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/badges/3')).to have_been_made + end + + it 'returns information about a badge' do + expect(@project_badge.id).to eq(1) + end + end + + describe '.add_project_badge' do + before do + stub_post('/projects/3/badges', 'project_badge') + @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') + end + + it 'gets the correct resource' do + expect(a_post('/projects/3/badges') + .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 + end + + it 'returns information about an added project badge' do + expect(@project_badge.link_url).to eq('http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}') + expect(@project_badge.image_url).to eq('https://shields.io/my/badge') + end + end + + describe '.edit_project_badge' do + before do + stub_put('/projects/3/badges/1', 'project_badge') + @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') + end + + it 'gets the correct resource' do + expect(a_put('/projects/3/badges/1') + .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 + end + + it 'returns information about an edited project badge' do + expect(@project_badge.link_url).to eq('http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}') + expect(@project_badge.image_url).to eq('https://shields.io/my/badge') + end + end + + describe '.remove_project_badge' do + before do + stub_delete('/projects/3/badges/3', 'empty') + @project_badge = Gitlab.remove_project_badge(3, 3) + end + + it 'gets the correct resource' do + expect(a_delete('/projects/3/badges/3')).to have_been_made + end + end + + describe '.preview_project_badge' do + before do + 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') + @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') + end + + it 'gets the correct resource' do + 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 + end + + it 'returns information about the rendered values of a badge' do + expect(@preview_project_badge.link_url).to eq('http://example.com/ci_status.svg?project=%{project_path}&ref=%{default_branch}') + expect(@preview_project_badge.image_url).to eq('https://shields.io/my/badge') + end + end +end +# rubocop:enable Style/FormatStringToken diff --git a/spec/gitlab/client/project_templates_spec.rb b/spec/gitlab/client/project_templates_spec.rb new file mode 100644 index 0000000..d35bea9 --- /dev/null +++ b/spec/gitlab/client/project_templates_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.project_templates' do + before do + stub_get('/projects/3/templates/licenses', 'project_templates') + @project_templates = Gitlab.project_templates(3, 'licenses') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/licenses')).to have_been_made + end + + it "returns a paginated response of project's templates" do + expect(@project_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.project_template' do + context 'when dockerfiles' do + before do + stub_get('/projects/3/templates/dockerfiles/dock', 'dockerfile_project_template') + @project_template = Gitlab.project_template(3, 'dockerfiles', 'dock') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/dockerfiles/dock')).to have_been_made + end + end + + context 'when licenses' do + before do + stub_get('/projects/3/templates/licenses/mit', 'license_project_template') + @project_template = Gitlab.project_template(3, 'licenses', 'mit') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/licenses/mit')).to have_been_made + end + end + end +end diff --git a/spec/gitlab/client/projects_spec.rb b/spec/gitlab/client/projects_spec.rb index dcfe227..8739900 100644 --- a/spec/gitlab/client/projects_spec.rb +++ b/spec/gitlab/client/projects_spec.rb @@ -1,133 +1,135 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do it { is_expected.to respond_to :search_projects } - describe ".projects" do - before do - stub_get("/projects", "projects") + describe '.projects' do + before do + stub_get('/projects', 'projects') @projects = Gitlab.projects end - it "gets the correct resource" do - expect(a_get("/projects")).to have_been_made - end - - it "returns a paginated response of projects" do + it 'gets the correct resource' do + expect(a_get('/projects')).to have_been_made + end + + it 'returns a paginated response of projects' do expect(@projects).to be_a Gitlab::PaginatedResponse - expect(@projects.first.name).to eq("Brute") - expect(@projects.first.owner.name).to eq("John Smith") - end - end - - describe ".project_search" do - before do - stub_get("/projects?search=Gitlab", "project_search") - @project_search = Gitlab.project_search("Gitlab") - end - - it "gets the correct resource" do - expect(a_get("/projects?search=Gitlab")).to have_been_made - end - - it "returns a paginated response of projects found" do + expect(@projects.first.name).to eq('Brute') + expect(@projects.first.owner.name).to eq('John Smith') + end + end + + describe '.project_search' do + before do + stub_get('/projects?search=Gitlab', 'project_search') + @project_search = Gitlab.project_search('Gitlab') + end + + it 'gets the correct resource' do + expect(a_get('/projects?search=Gitlab')).to have_been_made + end + + it 'returns a paginated response of projects found' do expect(@project_search).to be_a Gitlab::PaginatedResponse - expect(@project_search.first.name).to eq("Gitlab") - expect(@project_search.first.owner.name).to eq("John Smith") - end - end - - describe ".project" do - before do - stub_get("/projects/3", "project") + expect(@project_search.first.name).to eq('Gitlab') + expect(@project_search.first.owner.name).to eq('John Smith') + end + end + + describe '.project' do + before do + stub_get('/projects/3', 'project') @project = Gitlab.project(3) end - it "gets the correct resource" do - expect(a_get("/projects/3")).to have_been_made - end - - it "returns information about a project" do - expect(@project.name).to eq("Gitlab") - expect(@project.owner.name).to eq("John Smith") - end - end - - describe ".create_project" do - before do - stub_post("/projects", "project") + it 'gets the correct resource' do + expect(a_get('/projects/3')).to have_been_made + end + + it 'returns information about a project' do + expect(@project.name).to eq('Gitlab') + expect(@project.owner.name).to eq('John Smith') + end + end + + describe '.create_project' do + before do + stub_post('/projects', 'project') @project = Gitlab.create_project('Gitlab') end - it "gets the correct resource" do - expect(a_post("/projects")).to have_been_made - end - - it "returns information about a created project" do - expect(@project.name).to eq("Gitlab") - expect(@project.owner.name).to eq("John Smith") - end - end - - describe ".create_project for user" do - before do - stub_post("/users", "user") - @owner = Gitlab.create_user("john@example.com", "pass", name: 'John Owner') - stub_post("/projects/user/#{@owner.id}", "project_for_user") + it 'gets the correct resource' do + expect(a_post('/projects')).to have_been_made + end + + it 'returns information about a created project' do + expect(@project.name).to eq('Gitlab') + expect(@project.owner.name).to eq('John Smith') + end + end + + describe '.create_project for user' do + before do + stub_post('/users', 'user') + @owner = Gitlab.create_user('john@example.com', 'pass', name: 'John Owner') + stub_post("/projects/user/#{@owner.id}", 'project_for_user') @project = Gitlab.create_project('Brute', user_id: @owner.id) end - it "returns information about a created project" do - expect(@project.name).to eq("Brute") - expect(@project.owner.name).to eq("John Owner") - end - end - - describe ".delete_project" do - before do - stub_delete("/projects/Gitlab", "project") + it 'returns information about a created project' do + expect(@project.name).to eq('Brute') + expect(@project.owner.name).to eq('John Owner') + end + end + + describe '.delete_project' do + before do + stub_delete('/projects/Gitlab', 'project') @project = Gitlab.delete_project('Gitlab') end - it "gets the correct resource" do - expect(a_delete("/projects/Gitlab")).to have_been_made - end - - it "returns information about a deleted project" do - expect(@project.name).to eq("Gitlab") - expect(@project.owner.name).to eq("John Smith") - end - end - - describe ".create_fork" do - context "without sudo option" do - before do - stub_post("/projects/3/fork", "project_fork") + it 'gets the correct resource' do + expect(a_delete('/projects/Gitlab')).to have_been_made + end + + it 'returns information about a deleted project' do + expect(@project.name).to eq('Gitlab') + expect(@project.owner.name).to eq('John Smith') + end + end + + describe '.create_fork' do + context 'without sudo option' do + before do + stub_post('/projects/3/fork', 'project_fork') @project = Gitlab.create_fork(3) end - it "posts to the correct resource" do - expect(a_post("/projects/3/fork")).to have_been_made - end - - it "returns information about the forked project" do + it 'posts to the correct resource' do + expect(a_post('/projects/3/fork')).to have_been_made + end + + it 'returns information about the forked project' do expect(@project.forked_from_project.id).to eq(3) expect(@project.id).to eq(20) end end - context "with the sudo option" do - before do - stub_post("/projects/3/fork", "project_forked_for_user") + context 'with the sudo option' do + before do + stub_post('/projects/3/fork', 'project_forked_for_user') @sudoed_username = 'jack.smith' @project = Gitlab.create_fork(3, sudo: @sudoed_username) end - it "posts to the correct resource" do - expect(a_post("/projects/3/fork")).to have_been_made - end - - it "returns information about the forked project" do + it 'posts to the correct resource' do + expect(a_post('/projects/3/fork')).to have_been_made + end + + it 'returns information about the forked project' do expect(@project.forked_from_project.id).to eq(3) expect(@project.id).to eq(20) expect(@project.owner.username).to eq(@sudoed_username) @@ -135,541 +137,618 @@ end end - describe ".project_forks" do - before do - stub_get("/projects/3/forks", "project_forks") + describe '.project_forks' do + before do + stub_get('/projects/3/forks', 'project_forks') @project_forks = Gitlab.project_forks(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/forks")).to have_been_made - end - - it "returns a paginated response of projects found" do + it 'gets the correct resource' do + expect(a_get('/projects/3/forks')).to have_been_made + end + + it 'returns a paginated response of projects found' do expect(@project_forks).to be_a Gitlab::PaginatedResponse - expect(@project_forks.first.name).to eq("gitlab") - expect(@project_forks.first.owner.name).to eq("Administrator") - end - end - - describe ".team_members" do - before do - stub_get("/projects/3/members", "team_members") + expect(@project_forks.first.name).to eq('gitlab') + expect(@project_forks.first.owner.name).to eq('Administrator') + end + end + + describe '.team_members' do + before do + stub_get('/projects/3/members', 'team_members') @team_members = Gitlab.team_members(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/members")).to have_been_made - end - - it "returns a paginated response of team members" do + it 'gets the correct resource' do + expect(a_get('/projects/3/members')).to have_been_made + end + + it 'returns a paginated response of team members' do expect(@team_members).to be_a Gitlab::PaginatedResponse - expect(@team_members.first.name).to eq("John Smith") - end - end - - describe ".team_member" do - before do - stub_get("/projects/3/members/1", "team_member") + expect(@team_members.first.name).to eq('John Smith') + end + end + + describe '.team_member' do + before do + stub_get('/projects/3/members/1', 'team_member') @team_member = Gitlab.team_member(3, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/members/1")).to have_been_made - end - - it "returns information about a team member" do - expect(@team_member.name).to eq("John Smith") - end - end - - describe ".add_team_member" do - before do - stub_post("/projects/3/members", "team_member") - @team_member = Gitlab.add_team_member(3, 1, 40) - end - - it "gets the correct resource" do - expect(a_post("/projects/3/members"). - with(body: { user_id: '1', access_level: '40' })).to have_been_made - end - - it "returns information about an added team member" do - expect(@team_member.name).to eq("John Smith") - end - end - - describe ".edit_team_member" do - before do - stub_put("/projects/3/members/1", "team_member") - @team_member = Gitlab.edit_team_member(3, 1, 40) - end - - it "gets the correct resource" do - expect(a_put("/projects/3/members/1"). - with(body: { access_level: '40' })).to have_been_made - end - - it "returns information about an edited team member" do - expect(@team_member.name).to eq("John Smith") - end - end - - describe ".remove_team_member" do - before do - stub_delete("/projects/3/members/1", "team_member") + it 'gets the correct resource' do + expect(a_get('/projects/3/members/1')).to have_been_made + end + + it 'returns information about a team member' do + expect(@team_member.name).to eq('John Smith') + end + end + + describe '.add_team_member' do + before do + stub_post('/projects/3/members', 'team_member') + @team_member = Gitlab.add_team_member(3, 1, 40, expires_at: '2018-12-31') + end + + it 'gets the correct resource' do + expect(a_post('/projects/3/members') + .with(body: { user_id: '1', access_level: '40', expires_at: '2018-12-31' })).to have_been_made + end + + it 'returns information about an added team member' do + expect(@team_member.name).to eq('John Smith') + expect(@team_member.expires_at).to eq('2018-12-31T00:00:00Z') + end + end + + describe '.edit_team_member' do + before do + stub_put('/projects/3/members/1', 'team_member') + @team_member = Gitlab.edit_team_member(3, 1, 40, expires_at: '2018-12-31') + end + + it 'gets the correct resource' do + expect(a_put('/projects/3/members/1') + .with(body: { access_level: '40', expires_at: '2018-12-31' })).to have_been_made + end + + it 'returns information about an edited team member' do + expect(@team_member.name).to eq('John Smith') + expect(@team_member.expires_at).to eq('2018-12-31T00:00:00Z') + end + end + + describe '.remove_team_member' do + before do + stub_delete('/projects/3/members/1', 'team_member') @team_member = Gitlab.remove_team_member(3, 1) end - it "gets the correct resource" do - expect(a_delete("/projects/3/members/1")).to have_been_made - end - - it "returns information about a removed team member" do - expect(@team_member.name).to eq("John Smith") - end - end - - describe ".project_hooks" do - before do - stub_get("/projects/1/hooks", "project_hooks") + it 'gets the correct resource' do + expect(a_delete('/projects/3/members/1')).to have_been_made + end + + it 'returns information about a removed team member' do + expect(@team_member.name).to eq('John Smith') + end + end + + describe '.project_hooks' do + before do + stub_get('/projects/1/hooks', 'project_hooks') @hooks = Gitlab.project_hooks(1) end - it "gets the correct resource" do - expect(a_get("/projects/1/hooks")).to have_been_made - end - - it "returns a paginated response of hooks" do + it 'gets the correct resource' do + expect(a_get('/projects/1/hooks')).to have_been_made + end + + it 'returns a paginated response of hooks' do expect(@hooks).to be_a Gitlab::PaginatedResponse - expect(@hooks.first.url).to eq("https://api.example.net/v1/webhooks/ci") - end - end - - describe ".project_hook" do - before do - stub_get("/projects/1/hooks/1", "project_hook") + expect(@hooks.first.url).to eq('https://api.example.net/v1/webhooks/ci') + end + end + + describe '.project_hook' do + before do + stub_get('/projects/1/hooks/1', 'project_hook') @hook = Gitlab.project_hook(1, 1) end - it "gets the correct resource" do - expect(a_get("/projects/1/hooks/1")).to have_been_made - end - - it "returns information about a hook" do - expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci") - end - end - - describe ".add_project_hook" do - context "without specified events" do - before do - stub_post("/projects/1/hooks", "project_hook") - @hook = Gitlab.add_project_hook(1, "https://api.example.net/v1/webhooks/ci") - end - - it "gets the correct resource" do - body = { url: "https://api.example.net/v1/webhooks/ci" } - expect(a_post("/projects/1/hooks").with(body: body)).to have_been_made - end - - it "returns information about an added hook" do - expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci") - end - end - - context "with specified events" do - before do - stub_post("/projects/1/hooks", "project_hook") - @hook = Gitlab.add_project_hook(1, "https://api.example.net/v1/webhooks/ci", push_events: true, merge_requests_events: true) - end - - it "gets the correct resource" do - body = { url: "https://api.example.net/v1/webhooks/ci", push_events: "true", merge_requests_events: "true" } - expect(a_post("/projects/1/hooks").with(body: body)).to have_been_made - end - - it "returns information about an added hook" do - expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci") - end - end - end - - describe ".edit_project_hook" do - before do - stub_put("/projects/1/hooks/1", "project_hook") - @hook = Gitlab.edit_project_hook(1, 1, "https://api.example.net/v1/webhooks/ci") - end - - it "gets the correct resource" do - body = { url: "https://api.example.net/v1/webhooks/ci" } - expect(a_put("/projects/1/hooks/1").with(body: body)).to have_been_made - end - - it "returns information about an edited hook" do - expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci") - end - end - - describe ".edit_project" do - context "using project ID" do - before do - stub_put("/projects/3", "project_edit").with(body: { name: "Gitlab-edit" }) - @edited_project = Gitlab.edit_project(3, name: "Gitlab-edit") - end - - it "gets the correct resource" do - expect(a_put("/projects/3").with(body: { name: "Gitlab-edit" })).to have_been_made - end - - it "returns information about an edited project" do - expect(@edited_project.name).to eq("Gitlab-edit") - end - end - - context "using namespaced project path" do - it "encodes the path properly" do - stub = stub_put("/projects/namespace%2Fpath", "project_edit").with(body: { name: "Gitlab-edit" }) - Gitlab.edit_project('namespace/path', name: "Gitlab-edit") + it 'gets the correct resource' do + expect(a_get('/projects/1/hooks/1')).to have_been_made + end + + it 'returns information about a hook' do + expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci') + end + end + + describe '.add_project_hook' do + context 'without specified events' do + before do + stub_post('/projects/1/hooks', 'project_hook') + @hook = Gitlab.add_project_hook(1, 'https://api.example.net/v1/webhooks/ci') + end + + it 'gets the correct resource' do + body = { url: 'https://api.example.net/v1/webhooks/ci' } + expect(a_post('/projects/1/hooks').with(body: body)).to have_been_made + end + + it 'returns information about an added hook' do + expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci') + end + end + + context 'with specified events' do + before do + stub_post('/projects/1/hooks', 'project_hook') + @hook = Gitlab.add_project_hook(1, 'https://api.example.net/v1/webhooks/ci', push_events: true, merge_requests_events: true) + end + + it 'gets the correct resource' do + body = { url: 'https://api.example.net/v1/webhooks/ci', push_events: 'true', merge_requests_events: 'true' } + expect(a_post('/projects/1/hooks').with(body: body)).to have_been_made + end + + it 'returns information about an added hook' do + expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci') + end + end + end + + describe '.edit_project_hook' do + before do + stub_put('/projects/1/hooks/1', 'project_hook') + @hook = Gitlab.edit_project_hook(1, 1, 'https://api.example.net/v1/webhooks/ci') + end + + it 'gets the correct resource' do + body = { url: 'https://api.example.net/v1/webhooks/ci' } + expect(a_put('/projects/1/hooks/1').with(body: body)).to have_been_made + end + + it 'returns information about an edited hook' do + expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci') + end + end + + describe '.edit_project' do + context 'using project ID' do + before do + stub_put('/projects/3', 'project_edit').with(body: { name: 'Gitlab-edit' }) + @edited_project = Gitlab.edit_project(3, name: 'Gitlab-edit') + end + + it 'gets the correct resource' do + expect(a_put('/projects/3').with(body: { name: 'Gitlab-edit' })).to have_been_made + end + + it 'returns information about an edited project' do + expect(@edited_project.name).to eq('Gitlab-edit') + end + end + + context 'using namespaced project path' do + it 'encodes the path properly' do + stub = stub_put('/projects/namespace%2Fpath', 'project_edit').with(body: { name: 'Gitlab-edit' }) + Gitlab.edit_project('namespace/path', name: 'Gitlab-edit') expect(stub).to have_been_requested end end end - describe ".delete_project_hook" do - context "when empty response" do - before do - stub_request(:delete, "#{Gitlab.endpoint}/projects/1/hooks/1"). - with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }). - to_return(body: '') + describe '.delete_project_hook' do + context 'when empty response' do + before do + stub_request(:delete, "#{Gitlab.endpoint}/projects/1/hooks/1") + .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }) + .to_return(body: '') @hook = Gitlab.delete_project_hook(1, 1) end - it "gets the correct resource" do - expect(a_delete("/projects/1/hooks/1")).to have_been_made - end - - it "returns false" do + it 'gets the correct resource' do + expect(a_delete('/projects/1/hooks/1')).to have_been_made + end + + it 'returns false' do expect(@hook).to be(false) end end - context "when JSON response" do - before do - stub_delete("/projects/1/hooks/1", "project_hook") + context 'when JSON response' do + before do + stub_delete('/projects/1/hooks/1', 'project_hook') @hook = Gitlab.delete_project_hook(1, 1) end - it "gets the correct resource" do - expect(a_delete("/projects/1/hooks/1")).to have_been_made - end - - it "returns information about a deleted hook" do - expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci") - end - end - end - - describe ".push_rule" do - before do - stub_get("/projects/1/push_rule", "push_rule") + it 'gets the correct resource' do + expect(a_delete('/projects/1/hooks/1')).to have_been_made + end + + it 'returns information about a deleted hook' do + expect(@hook.url).to eq('https://api.example.net/v1/webhooks/ci') + end + end + end + + describe '.push_rule' do + before do + stub_get('/projects/1/push_rule', 'push_rule') @push_rule = Gitlab.push_rule(1) end - it "gets the correct resource" do - expect(a_get("/projects/1/push_rule")).to have_been_made - end - - it "returns information about a push rule" do - expect(@push_rule.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b") - end - end - - describe ".add_push_rule" do - before do - stub_post("/projects/1/push_rule", "push_rule") - @push_rule = Gitlab.add_push_rule(1, { deny_delete_tag: false, commit_message_regex: "\\b[A-Z]{3}-[0-9]+\\b" }) - end - - it "gets the correct resource" do - expect(a_post("/projects/1/push_rule")).to have_been_made - end - - it "returns information about an added push rule" do - expect(@push_rule.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b") - end - end - - describe ".edit_push_rule" do - before do - stub_put("/projects/1/push_rule", "push_rule") - @push_rule = Gitlab.edit_push_rule(1, { deny_delete_tag: false, commit_message_regex: "\\b[A-Z]{3}-[0-9]+\\b" }) - end - - it "gets the correct resource" do - expect(a_put("/projects/1/push_rule")).to have_been_made - end - - it "returns information about an edited push rule" do - expect(@push_rule.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b") - end - end - - describe ".delete_push_rule" do - context "when empty response" do - before do - stub_request(:delete, "#{Gitlab.endpoint}/projects/1/push_rule"). - with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }). - to_return(body: '') + it 'gets the correct resource' do + expect(a_get('/projects/1/push_rule')).to have_been_made + end + + it 'returns information about a push rule' do + expect(@push_rule.commit_message_regex).to eq('\\b[A-Z]{3}-[0-9]+\\b') + end + end + + describe '.add_push_rule' do + before do + stub_post('/projects/1/push_rule', 'push_rule') + @push_rule = Gitlab.add_push_rule(1, deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b') + end + + it 'gets the correct resource' do + expect(a_post('/projects/1/push_rule')).to have_been_made + end + + it 'returns information about an added push rule' do + expect(@push_rule.commit_message_regex).to eq('\\b[A-Z]{3}-[0-9]+\\b') + end + end + + describe '.edit_push_rule' do + before do + stub_put('/projects/1/push_rule', 'push_rule') + @push_rule = Gitlab.edit_push_rule(1, deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b') + end + + it 'gets the correct resource' do + expect(a_put('/projects/1/push_rule')).to have_been_made + end + + it 'returns information about an edited push rule' do + expect(@push_rule.commit_message_regex).to eq('\\b[A-Z]{3}-[0-9]+\\b') + end + end + + describe '.delete_push_rule' do + context 'when empty response' do + before do + stub_request(:delete, "#{Gitlab.endpoint}/projects/1/push_rule") + .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }) + .to_return(body: '') @push_rule = Gitlab.delete_push_rule(1) end - it "gets the correct resource" do - expect(a_delete("/projects/1/push_rule")).to have_been_made - end - - it "returns false" do + it 'gets the correct resource' do + expect(a_delete('/projects/1/push_rule')).to have_been_made + end + + it 'returns false' do expect(@push_rule).to be(false) end end - context "when JSON response" do - before do - stub_delete("/projects/1/push_rule", "push_rule") + context 'when JSON response' do + before do + stub_delete('/projects/1/push_rule', 'push_rule') @push_rule = Gitlab.delete_push_rule(1) end - it "gets the correct resource" do - expect(a_delete("/projects/1/push_rule")).to have_been_made - end - - it "returns information about a deleted push rule" do - expect(@push_rule.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b") - end - end - end - - describe ".make_forked_from" do - before do - stub_post("/projects/42/fork/24", "project_fork_link") + it 'gets the correct resource' do + expect(a_delete('/projects/1/push_rule')).to have_been_made + end + + it 'returns information about a deleted push rule' do + expect(@push_rule.commit_message_regex).to eq('\\b[A-Z]{3}-[0-9]+\\b') + end + end + end + + describe '.make_forked_from' do + before do + stub_post('/projects/42/fork/24', 'project_fork_link') @forked_project_link = Gitlab.make_forked_from(42, 24) end - it "gets the correct resource" do - expect(a_post("/projects/42/fork/24")).to have_been_made - end - - it "returns information about a forked project" do + it 'gets the correct resource' do + expect(a_post('/projects/42/fork/24')).to have_been_made + end + + it 'returns information about a forked project' do expect(@forked_project_link.forked_from_project_id).to eq(24) expect(@forked_project_link.forked_to_project_id).to eq(42) end end - describe ".remove_forked" do - before do - stub_delete("/projects/42/fork", "project_fork_link") + describe '.remove_forked' do + before do + stub_delete('/projects/42/fork', 'project_fork_link') @forked_project_link = Gitlab.remove_forked(42) end - it "gets the correct resource" do - expect(a_delete("/projects/42/fork")).to have_been_made - end - - it "returns information about an unforked project" do + it 'gets the correct resource' do + expect(a_delete('/projects/42/fork')).to have_been_made + end + + it 'returns information about an unforked project' do expect(@forked_project_link.forked_to_project_id).to eq(42) end end - describe ".deploy_keys" do - before do - stub_get("/projects/42/deploy_keys", "project_keys") + describe '.deploy_keys' do + before do + stub_get('/projects/42/deploy_keys', 'project_keys') @deploy_keys = Gitlab.deploy_keys(42) end - it "gets the correct resource" do - expect(a_get("/projects/42/deploy_keys")).to have_been_made - end - - it "returns project deploy keys" do + it 'gets the correct resource' do + expect(a_get('/projects/42/deploy_keys')).to have_been_made + end + + it 'returns project deploy keys' do expect(@deploy_keys).to be_a Gitlab::PaginatedResponse expect(@deploy_keys.first.id).to eq 2 - expect(@deploy_keys.first.title).to eq "Key Title" + expect(@deploy_keys.first.title).to eq 'Key Title' expect(@deploy_keys.first.key).to match(/ssh-rsa/) end end - describe ".deploy_key" do - before do - stub_get("/projects/42/deploy_keys/2", "project_key") + describe '.deploy_key' do + before do + stub_get('/projects/42/deploy_keys/2', 'project_key') @deploy_key = Gitlab.deploy_key(42, 2) end - it "gets the correct resource" do - expect(a_get("/projects/42/deploy_keys/2")).to have_been_made - end - - it "returns project deploy key" do + it 'gets the correct resource' do + expect(a_get('/projects/42/deploy_keys/2')).to have_been_made + end + + it 'returns project deploy key' do expect(@deploy_key.id).to eq 2 - expect(@deploy_key.title).to eq "Key Title" + expect(@deploy_key.title).to eq 'Key Title' expect(@deploy_key.key).to match(/ssh-rsa/) end end - describe ".create_deploy_key" do + describe '.create_deploy_key' do context 'no options' do before do - stub_post("/projects/42/deploy_keys", "project_key") + stub_post('/projects/42/deploy_keys', 'project_key') @deploy_key = Gitlab.create_deploy_key(42, 'My Key', 'Key contents') end - it "gets the correct resource" do - expect(a_post("/projects/42/deploy_keys"). - with(body: { title: 'My Key', key: 'Key contents' })).to have_been_made - end - - it "returns information about a created key" do + it 'gets the correct resource' do + expect(a_post('/projects/42/deploy_keys') + .with(body: { title: 'My Key', key: 'Key contents' })).to have_been_made + end + + it 'returns information about a created key' do expect(@deploy_key.id).to eq(2) end end context 'some options' do before do - stub_post("/projects/42/deploy_keys", "project_key") + stub_post('/projects/42/deploy_keys', 'project_key') @deploy_key = Gitlab.create_deploy_key(42, 'My Key', 'Key contents', can_push: true) end - it "gets the correct resource" do - expect(a_post("/projects/42/deploy_keys"). - with(body: { title: 'My Key', key: 'Key contents', can_push: true })).to have_been_made - end - - it "returns information about a created key" do + it 'gets the correct resource' do + expect(a_post('/projects/42/deploy_keys') + .with(body: { title: 'My Key', key: 'Key contents', can_push: true })).to have_been_made + end + + it 'returns information about a created key' do expect(@deploy_key.id).to eq(2) end end end - describe ".delete_deploy_key" do - before do - stub_delete("/projects/42/deploy_keys/2", "project_key") + describe '.delete_deploy_key' do + before do + stub_delete('/projects/42/deploy_keys/2', 'project_key') @deploy_key = Gitlab.delete_deploy_key(42, 2) end - it "gets the correct resource" do - expect(a_delete("/projects/42/deploy_keys/2")).to have_been_made - end - - it "returns information about a deleted key" do + it 'gets the correct resource' do + expect(a_delete('/projects/42/deploy_keys/2')).to have_been_made + end + + it 'returns information about a deleted key' do expect(@deploy_key.id).to eq(2) end end - describe ".enable_deploy_key" do - before do - stub_post("/projects/42/deploy_keys/2/enable", "project_key") + describe '.enable_deploy_key' do + before do + stub_post('/projects/42/deploy_keys/2/enable', 'project_key') @deploy_key = Gitlab.enable_deploy_key(42, 2) end - it "gets the correct resource" do - expect(a_post("/projects/42/deploy_keys/2/enable"). - with(body: { id: '42', key_id: '2' })).to have_been_made - end - - it "returns information about an enabled key" do + it 'gets the correct resource' do + expect(a_post('/projects/42/deploy_keys/2/enable') + .with(body: { id: '42', key_id: '2' })).to have_been_made + end + + it 'returns information about an enabled key' do expect(@deploy_key.id).to eq(2) end end - describe ".disable_deploy_key" do - before do - stub_post("/projects/42/deploy_keys/2/disable", "project_key") + describe '.disable_deploy_key' do + before do + stub_post('/projects/42/deploy_keys/2/disable', 'project_key') @deploy_key = Gitlab.disable_deploy_key(42, 2) end - it "gets the correct resource" do - expect(a_post("/projects/42/deploy_keys/2/disable"). - with(body: { id: '42', key_id: '2' })).to have_been_made - end - - it "returns information about a disabled key" do + it 'gets the correct resource' do + expect(a_post('/projects/42/deploy_keys/2/disable') + .with(body: { id: '42', key_id: '2' })).to have_been_made + end + + it 'returns information about a disabled key' do expect(@deploy_key.id).to eq(2) end end - describe ".share_project_with_group" do - before do - stub_post("/projects/3/share", "group") + describe '.share_project_with_group' do + before do + stub_post('/projects/3/share', 'group') @group = Gitlab.share_project_with_group(3, 10, 40) end - it "gets the correct resource" do - expect(a_post("/projects/3/share"). - with(body: { group_id: '10', group_access: '40' })).to have_been_made - end - - it "returns information about an added group" do + it 'gets the correct resource' do + expect(a_post('/projects/3/share') + .with(body: { group_id: '10', group_access: '40' })).to have_been_made + end + + it 'returns information about an added group' do expect(@group.id).to eq(10) end end - describe ".unshare_project_with_group" do - before do - stub_delete("/projects/3/share/10", "group") + describe '.unshare_project_with_group' do + before do + stub_delete('/projects/3/share/10', 'group') @group = Gitlab.unshare_project_with_group(3, 10) end - it "gets the correct resource" do - expect(a_delete("/projects/3/share/10")).to have_been_made - end - end - - describe ".star_project" do - before do - stub_post("/projects/3/star", "project_star") + it 'gets the correct resource' do + expect(a_delete('/projects/3/share/10')).to have_been_made + end + end + + describe '.transfer_project' do + before do + stub_put('/projects/3/transfer', 'transfer_project') + @transfered_project = Gitlab.transfer_project(3, 'yolo') + end + + it 'gets the correct resource' do + expect(a_put('/projects/3/transfer') + .with(body: { namespace: 'yolo' })).to have_been_made + end + + it 'returns information about the transfered project' do + expect(@transfered_project.id).to eq(1) + end + end + + describe '.star_project' do + before do + stub_post('/projects/3/star', 'project_star') @starred_project = Gitlab.star_project(3) end - it "gets the correct resource" do - expect(a_post("/projects/3/star")).to have_been_made - end - - it "returns information about the starred project" do + it 'gets the correct resource' do + expect(a_post('/projects/3/star')).to have_been_made + end + + it 'returns information about the starred project' do expect(@starred_project.id).to eq(3) end end - describe ".unstar_project" do - before do - stub_delete("/projects/3/star", "project_unstar") + describe '.unstar_project' do + before do + stub_delete('/projects/3/star', 'project_unstar') @unstarred_project = Gitlab.unstar_project(3) end - it "gets the correct resource" do - expect(a_delete("/projects/3/star")).to have_been_made - end - - it "returns information about the unstarred project" do + it 'gets the correct resource' do + expect(a_delete('/projects/3/star')).to have_been_made + end + + it 'returns information about the unstarred project' do expect(@unstarred_project.id).to eq(3) end end - describe ".user_projects" do + describe '.user_projects' do let(:user_id) { 1 } let(:project_id) { 1 } before do - stub_get("/users/#{user_id}/projects", "user_projects") + stub_get("/users/#{user_id}/projects", 'user_projects') @user_projects = Gitlab.user_projects(user_id) end - it "gets the correct resource" do + it 'gets the correct resource' do expect(a_get("/users/#{user_id}/projects")).to have_been_made end - it "returns a paginated response of projects" do + it 'returns a paginated response of projects' do expect(@user_projects).to be_a Gitlab::PaginatedResponse expect(@user_projects.first.id).to eq(project_id) expect(@user_projects.first.owner.id).to eq(user_id) end end + + describe '.upload_file' do + let(:id) { 1 } + let(:file) { File.open(File::NULL, 'r') } + + before do + stub_post("/projects/#{id}/uploads", 'upload_file') + @file = Gitlab.upload_file(id, file) + end + + it 'gets the correct resource' do + expect(a_post("/projects/#{id}/uploads")).to have_been_made + end + + it 'returns information about the uploaded file' do + expect(@file.alt).to eq('null') + expect(@file.url).to eq('/uploads/f22e67e35e1bcb339058212c54bb8772/null') + expect(@file.markdown).to eq('[null](/uploads/f22e67e35e1bcb339058212c54bb8772/null)') + end + end + + describe '.project_templates' do + before do + stub_get('/projects/3/templates/licenses', 'project_templates') + @project_templates = Gitlab.project_templates(3, 'licenses') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/licenses')).to have_been_made + end + + it "returns a paginated response of project's templates" do + expect(@project_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.project_template' do + context 'when dockerfiles' do + before do + stub_get('/projects/3/templates/dockerfiles/dock', 'dockerfile_project_template') + @project_template = Gitlab.project_template(3, 'dockerfiles', 'dock') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/dockerfiles/dock')).to have_been_made + end + end + + context 'when licenses' do + before do + stub_get('/projects/3/templates/licenses/mit', 'license_project_template') + @project_template = Gitlab.project_template(3, 'licenses', 'mit') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/licenses/mit')).to have_been_made + end + end + end end diff --git a/spec/gitlab/client/protected_tags_spec.rb b/spec/gitlab/client/protected_tags_spec.rb new file mode 100644 index 0000000..415d026 --- /dev/null +++ b/spec/gitlab/client/protected_tags_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.protected_tags' do + before do + stub_get('/projects/1/protected_tags', 'protected_tags') + @protected_tags = Gitlab.protected_tags(1) + end + + it 'gets the correct resource' do + expect(a_get('/projects/1/protected_tags')).to have_been_made + end + + it "returns a response of a project's protected_tags" do + expect(@protected_tags).to be_a Gitlab::PaginatedResponse + end + end + + describe '.protected_tag' do + before do + stub_get('/projects/1/protected_tags/release-1-0', 'protected_tag') + @protected_tag = Gitlab.protected_tag(1, 'release-1-0') + end + + it 'gets the correct resource' do + expect(a_get('/projects/1/protected_tags/release-1-0')).to have_been_made + end + + it 'returns correct information about the protected_tag' do + expect(@protected_tag.name).to eq 'release-1-0' + end + end + + describe '.protect_repository_tag' do + before do + stub_post('/projects/1/protected_tags', 'protected_tag') + @protected_tag = Gitlab.protect_repository_tag(1, 'release-1-0') + end + + it 'gets the correct resource' do + expect(a_post('/projects/1/protected_tags') + .with(body: { name: 'release-1-0' })).to have_been_made + end + + it 'returns correct information about the protected repository tag' do + expect(@protected_tag.name).to eq 'release-1-0' + end + end + + describe '.unprotect_repository_tag' do + before do + stub_delete('/projects/1/protected_tags/release-1-0', 'empty') + Gitlab.unprotect_repository_tag(1, 'release-1-0') + end + + it 'gets the correct resource' do + expect(a_delete('/projects/1/protected_tags/release-1-0')).to have_been_made + end + end +end diff --git a/spec/gitlab/client/repositories_spec.rb b/spec/gitlab/client/repositories_spec.rb index b103bf8..8ac104c 100644 --- a/spec/gitlab/client/repositories_spec.rb +++ b/spec/gitlab/client/repositories_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do @@ -8,87 +10,105 @@ it { is_expected.to respond_to :repo_tree } it { is_expected.to respond_to :repo_compare } - describe ".tags" do + describe '.tags' do before do - stub_get("/projects/3/repository/tags", "project_tags") + stub_get('/projects/3/repository/tags', 'project_tags') @tags = Gitlab.tags(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/tags")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/tags')).to have_been_made end - it "returns a paginated response of repository tags" do + it 'returns a paginated response of repository tags' do expect(@tags).to be_a Gitlab::PaginatedResponse - expect(@tags.first.name).to eq("v2.8.2") + expect(@tags.first.name).to eq('v2.8.2') end end - describe ".create_tag" do - context "when lightweight" do + describe '.create_tag' do + context 'when lightweight' do before do - stub_post("/projects/3/repository/tags", "project_tag_lightweight") + stub_post('/projects/3/repository/tags', 'project_tag_lightweight') @tag = Gitlab.create_tag(3, 'v1.0.0', '2695effb5807a22ff3d138d593fd856244e155e7') end - it "gets the correct resource" do - expect(a_post("/projects/3/repository/tags")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/repository/tags')).to have_been_made end - it "returns information about a new repository tag" do - expect(@tag.name).to eq("v1.0.0") + it 'returns information about a new repository tag' do + expect(@tag.name).to eq('v1.0.0') expect(@tag.message).to eq(nil) end end - context "when annotated" do + context 'when annotated' do before do - stub_post("/projects/3/repository/tags", "project_tag_annotated") + stub_post('/projects/3/repository/tags', 'project_tag_annotated') @tag = Gitlab.create_tag(3, 'v1.1.0', '2695effb5807a22ff3d138d593fd856244e155e7', 'Release 1.1.0') end - it "gets the correct resource" do - expect(a_post("/projects/3/repository/tags")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/repository/tags')).to have_been_made end - it "returns information about a new repository tag" do - expect(@tag.name).to eq("v1.1.0") - expect(@tag.message).to eq("Release 1.1.0") + it 'returns information about a new repository tag' do + expect(@tag.name).to eq('v1.1.0') + expect(@tag.message).to eq('Release 1.1.0') end end end - describe ".tree" do + describe '.tree' do before do - stub_get("/projects/3/repository/tree", "tree") + stub_get('/projects/3/repository/tree', 'tree') @tree = Gitlab.tree(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/tree")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/tree')).to have_been_made end - it "returns a paginated response of repository tree files (root level)" do + it 'returns a paginated response of repository tree files (root level)' do expect(@tree).to be_a Gitlab::PaginatedResponse - expect(@tree.first.name).to eq("app") + expect(@tree.first.name).to eq('app') end end - describe ".compare" do + describe '.compare' do before do - stub_get("/projects/3/repository/compare", "compare_merge_request_diff"). - with(query: { from: "master", to: "feature" }) + stub_get('/projects/3/repository/compare', 'compare_merge_request_diff') + .with(query: { from: 'master', to: 'feature' }) @diff = Gitlab.compare(3, 'master', 'feature') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/compare"). - with(query: { from: "master", to: "feature" })).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/compare') + .with(query: { from: 'master', to: 'feature' })).to have_been_made end - it "gets diffs of a merge request" do + it 'gets diffs of a merge request' do expect(@diff.diffs).to be_kind_of Array - expect(@diff.diffs.last["new_path"]).to eq "files/js/application.js" + expect(@diff.diffs.last['new_path']).to eq 'files/js/application.js' + end + end + + describe '.merge_base' do + before do + stub_get('/projects/3/repository/merge_base', 'merge_base') + .with(query: { refs: %w[master feature] }) + @response = Gitlab.merge_base(3, %w[master feature]) + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/merge_base') + .with(query: { refs: %w[master feature] })).to have_been_made + end + + it 'gets common ancestor of the two refs' do + expect(@response).to be_kind_of Gitlab::ObjectifiedHash + expect(@response.id).to eq '1a0b36b3cdad1d2ee32457c102a8c0b7056fa863' end end end diff --git a/spec/gitlab/client/repository_files_spec.rb b/spec/gitlab/client/repository_files_spec.rb index a05741b..15a3ce9 100644 --- a/spec/gitlab/client/repository_files_spec.rb +++ b/spec/gitlab/client/repository_files_spec.rb @@ -1,95 +1,97 @@ -require "spec_helper" +# frozen_string_literal: true + +require 'spec_helper' describe Gitlab::Client do - describe ".file_contents" do + describe '.file_contents' do before do - stub_get("/projects/3/repository/files/Gemfile/raw?ref=master", "raw_file") - @file_contents = Gitlab.file_contents(3, "Gemfile") + stub_get('/projects/3/repository/files/Gemfile/raw?ref=master', 'raw_file') + @file_contents = Gitlab.file_contents(3, 'Gemfile') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/files/Gemfile/raw?ref=master")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/files/Gemfile/raw?ref=master')).to have_been_made end - it "returns file contents" do + it 'returns file contents' do expect(@file_contents).to eq("source 'https://rubygems.org'\ngem 'rails', '4.1.2'\n") end end - describe ".get_file" do + describe '.get_file' do before do - stub_get("/projects/3/repository/files/README%2Emd?ref=master", "get_repository_file") + stub_get('/projects/3/repository/files/README%2Emd?ref=master', 'get_repository_file') @file = Gitlab.get_file(3, 'README.md', 'master') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/files/README%2Emd?ref=master")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/files/README%2Emd?ref=master')).to have_been_made end - it "returns the base64 encoded file" do - expect(@file.file_path).to eq "README.md" - expect(@file.ref).to eq "master" + it 'returns the base64 encoded file' do + expect(@file.file_path).to eq 'README.md' + expect(@file.ref).to eq 'master' expect(@file.content).to eq "VGhpcyBpcyBhICpSRUFETUUqIQ==\n" end end - describe ".create_file" do - let(:api_path) { "/projects/3/repository/files/path" } - let!(:request_stub) { stub_post(api_path, "repository_file") } - let!(:file) { Gitlab.create_file(3, "path", "branch", "content", "commit message", author_name: "joe") } + describe '.create_file' do + let(:api_path) { '/projects/3/repository/files/path' } + let!(:request_stub) { stub_post(api_path, 'repository_file') } + let!(:file) { Gitlab.create_file(3, 'path', 'branch', 'content', 'commit message', author_name: 'joe') } - it "creates the correct resource" do + it 'creates the correct resource' do expected_parameters = { - author_name: "joe", - branch: "branch", - commit_message: "commit message" + author_name: 'joe', + branch: 'branch', + commit_message: 'commit message' } expect(a_post(api_path).with(body: hash_including(expected_parameters))).to have_been_made end - it "returns information about the new file" do - expect(file.file_path).to eq "path" - expect(file.branch_name).to eq "branch" + it 'returns information about the new file' do + expect(file.file_path).to eq 'path' + expect(file.branch_name).to eq 'branch' end end - describe ".edit_file" do - let(:api_path) { "/projects/3/repository/files/path" } - let!(:request_stub) { stub_put(api_path, "repository_file") } - let!(:file) { Gitlab.edit_file(3, "path", "branch", "content", "commit message", author_name: "joe") } + describe '.edit_file' do + let(:api_path) { '/projects/3/repository/files/path' } + let!(:request_stub) { stub_put(api_path, 'repository_file') } + let!(:file) { Gitlab.edit_file(3, 'path', 'branch', 'content', 'commit message', author_name: 'joe') } - it "updates the correct resource" do + it 'updates the correct resource' do expected_parameters = { - author_name: "joe", - branch: "branch", - commit_message: "commit message" + author_name: 'joe', + branch: 'branch', + commit_message: 'commit message' } expect(a_put(api_path).with(body: hash_including(expected_parameters))).to have_been_made end - it "returns information about the new file" do - expect(file.file_path).to eq "path" - expect(file.branch_name).to eq "branch" + it 'returns information about the new file' do + expect(file.file_path).to eq 'path' + expect(file.branch_name).to eq 'branch' end end - describe ".remove_file" do - let(:api_path) { "/projects/3/repository/files/path" } - let!(:request_stub) { stub_delete(api_path, "repository_file") } - let!(:file) { Gitlab.remove_file(3, "path", "branch", "commit message", author_name: "joe") } + describe '.remove_file' do + let(:api_path) { '/projects/3/repository/files/path' } + let!(:request_stub) { stub_delete(api_path, 'repository_file') } + let!(:file) { Gitlab.remove_file(3, 'path', 'branch', 'commit message', author_name: 'joe') } - it "updates the correct resource" do + it 'updates the correct resource' do expected_parameters = { - author_name: "joe", - branch: "branch", - commit_message: "commit message" + author_name: 'joe', + branch: 'branch', + commit_message: 'commit message' } expect(a_delete(api_path).with(body: hash_including(expected_parameters))).to have_been_made end - it "returns information about the new file" do - expect(file.file_path).to eq "path" - expect(file.branch_name).to eq "branch" + it 'returns information about the new file' do + expect(file.file_path).to eq 'path' + expect(file.branch_name).to eq 'branch' end end end diff --git a/spec/gitlab/client/repository_submodules_spec.rb b/spec/gitlab/client/repository_submodules_spec.rb new file mode 100644 index 0000000..98a00eb --- /dev/null +++ b/spec/gitlab/client/repository_submodules_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.edit_submodule' do + let(:api_path) { '/projects/3/repository/submodules/submodule' } + let(:options) do + { + branch: 'branch', + commit_sha: '3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88', + commit_message: 'commit message' + } + end + + before do + stub_put(api_path, 'repository_submodule') + @submodule = Gitlab.edit_submodule(3, 'submodule', options) + end + + it 'updates the correct resource' do + expect(a_put(api_path).with(body: hash_including(options))).to have_been_made + end + + it 'returns information about the updated submodule' do + expect(@submodule.short_id).to eq 'ed899a2f4b5' + expect(@submodule.status).to be_nil + end + end +end diff --git a/spec/gitlab/client/runners_spec.rb b/spec/gitlab/client/runners_spec.rb index fa49a17..aaadba1 100644 --- a/spec/gitlab/client/runners_spec.rb +++ b/spec/gitlab/client/runners_spec.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - - describe ".runners" do + describe '.runners' do before do - stub_get("/runners", "runners") + stub_get('/runners', 'runners') end context 'without scope' do @@ -12,11 +13,11 @@ @runner = Gitlab.runners end - it "gets the correct resource" do - expect(a_get("/runners")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/runners')).to have_been_made end - it "returns a paginated response of runners" do + it 'returns a paginated response of runners' do expect(@runner).to be_a Gitlab::PaginatedResponse expect(@runner.first.id).to eq(6) expect(@runner.first.description).to eq('test-1-20150125') @@ -25,26 +26,25 @@ context 'with scope' do before do - stub_get("/runners?scope=online", "runners") - @runner = Gitlab.runners({scope: :online}) + stub_get('/runners?scope=online', 'runners') + @runner = Gitlab.runners(scope: :online) end - it "gets the correct resource" do - expect(a_get("/runners").with(query: { scope: :online })).to have_been_made + it 'gets the correct resource' do + expect(a_get('/runners').with(query: { scope: :online })).to have_been_made end - it "returns a paginated response of runners" do + it 'returns a paginated response of runners' do expect(@runner).to be_a Gitlab::PaginatedResponse expect(@runner.first.id).to eq(6) expect(@runner.first.description).to eq('test-1-20150125') end end - end - describe ".all_runners" do + describe '.all_runners' do before do - stub_get("/runners/all", "runners") + stub_get('/runners/all', 'runners') end context 'without scope' do @@ -52,11 +52,11 @@ @runner = Gitlab.all_runners end - it "gets the correct resource" do - expect(a_get("/runners/all")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/runners/all')).to have_been_made end - it "returns a paginated response of runners" do + it 'returns a paginated response of runners' do expect(@runner).to be_a Gitlab::PaginatedResponse expect(@runner.first.id).to eq(6) expect(@runner.first.description).to eq('test-1-20150125') @@ -65,15 +65,15 @@ context 'with scope' do before do - stub_get("/runners/all?scope=online", "runners") - @runner = Gitlab.all_runners({scope: :online}) + stub_get('/runners/all?scope=online', 'runners') + @runner = Gitlab.all_runners(scope: :online) end - it "gets the correct resource" do - expect(a_get("/runners/all").with(query: { scope: :online })).to have_been_made + it 'gets the correct resource' do + expect(a_get('/runners/all').with(query: { scope: :online })).to have_been_made end - it "returns a paginated response of runners" do + it 'returns a paginated response of runners' do expect(@runner).to be_a Gitlab::PaginatedResponse expect(@runner.first.id).to eq(6) expect(@runner.first.description).to eq('test-1-20150125') @@ -81,50 +81,50 @@ end end - describe ".runner" do + describe '.runner' do before do - stub_get("/runners/6", "runner") + stub_get('/runners/6', 'runner') @runners = Gitlab.runner(6) end - it "gets the correct resource" do - expect(a_get("/runners/6")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/runners/6')).to have_been_made end - it "returns a response of a runner" do + it 'returns a response of a runner' do expect(@runners).to be_a Gitlab::ObjectifiedHash expect(@runners.id).to eq(6) expect(@runners.description).to eq('test-1-20150125') end end - describe ".update_runner" do + describe '.update_runner' do before do - stub_put("/runners/6", "runner_edit").with(query: { description: "abcefg" }) - @runner = Gitlab.update_runner(6, description: "abcefg" ) + stub_put('/runners/6', 'runner_edit').with(query: { description: 'abcefg' }) + @runner = Gitlab.update_runner(6, description: 'abcefg') end - it "gets the correct resource" do - expect(a_put("/runners/6").with(query: { description: "abcefg" })).to have_been_made + it 'gets the correct resource' do + expect(a_put('/runners/6').with(query: { description: 'abcefg' })).to have_been_made end - it "returns an updated response of a runner" do + it 'returns an updated response of a runner' do expect(@runner).to be_a Gitlab::ObjectifiedHash expect(@runner.description).to eq('abcefg') end end - describe ".delete_runner" do + describe '.delete_runner' do before do - stub_delete("/runners/6", "runner_delete") + stub_delete('/runners/6', 'runner_delete') @runner = Gitlab.delete_runner(6) end - it "gets the correct resource" do - expect(a_delete("/runners/6")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/runners/6')).to have_been_made end - it "returns a response of the deleted runner" do + it 'returns a response of the deleted runner' do expect(@runner).to be_a Gitlab::ObjectifiedHash expect(@runner.id).to eq(6) end @@ -135,56 +135,57 @@ stub_get('/runners/1/jobs', 'runner_jobs') @jobs = Gitlab.runner_jobs(1) end + it 'gets the correct resource' do expect(a_get('/runners/1/jobs')).to have_been_made end end - describe ".project_runners" do + describe '.project_runners' do before do - stub_get("/projects/1/runners", "project_runners") + stub_get('/projects/1/runners', 'project_runners') @runners = Gitlab.project_runners(1) end - it "gets the correct resource" do - expect(a_get("/projects/1/runners")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/1/runners')).to have_been_made end - it "returns a paginated response of runners" do + it 'returns a paginated response of runners' do expect(@runners).to be_a Gitlab::PaginatedResponse expect(@runners.first.id).to eq(8) expect(@runners.first.description).to eq('test-2-20150125') end end - describe ".project_enable_runner" do + describe '.project_enable_runner' do before do - stub_post("/projects/1/runners", "runner") + stub_post('/projects/1/runners', 'runner') @runner = Gitlab.project_enable_runner(1, 6) end - it "gets the correct resource" do - expect(a_post("/projects/1/runners")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/1/runners')).to have_been_made end - it "returns a response of the enabled runner" do + it 'returns a response of the enabled runner' do expect(@runner).to be_a Gitlab::ObjectifiedHash expect(@runner.id).to eq(6) expect(@runner.description).to eq('test-1-20150125') end end - describe ".project_disable_runner" do + describe '.project_disable_runner' do before do - stub_delete("/projects/1/runners/6", "runner") + stub_delete('/projects/1/runners/6', 'runner') @runner = Gitlab.project_disable_runner(1, 6) end - it "gets the correct resource" do - expect(a_delete("/projects/1/runners/6")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/1/runners/6')).to have_been_made end - it "returns a response of the disabled runner" do + it 'returns a response of the disabled runner' do expect(@runner).to be_a Gitlab::ObjectifiedHash expect(@runner.id).to eq(6) expect(@runner.description).to eq('test-1-20150125') diff --git a/spec/gitlab/client/services_spec.rb b/spec/gitlab/client/services_spec.rb index e3f7ea5..14bcfbc 100644 --- a/spec/gitlab/client/services_spec.rb +++ b/spec/gitlab/client/services_spec.rb @@ -1,54 +1,56 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".service" do + describe '.service' do before do - stub_get("/projects/3/services/redmine", "service") + stub_get('/projects/3/services/redmine', 'service') @service = Gitlab.service(3, :redmine) end - it "gets the correct resource" do - expect(a_get("/projects/3/services/redmine")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/services/redmine')).to have_been_made end - it "returns a information about a service of project" do + it 'returns a information about a service of project' do expect(@service.id).to eq 38 - expect(@service.title).to eq("Redmine") - expect(@service.properties.project_url).to eq("https://example.com/projects/test_project/issue") + expect(@service.title).to eq('Redmine') + expect(@service.properties.project_url).to eq('https://example.com/projects/test_project/issue') end end - describe ".change_service" do + describe '.change_service' do before do - stub_put("/projects/3/services/redmine", "service") + stub_put('/projects/3/services/redmine', 'service') @service = Gitlab.change_service(3, :redmine, new_issue_url: 'https://example.com/projects/test_project/issues/new', project_url: 'https://example.com/projects/test_project/issues', issues_url: 'https://example.com/issues/:id') end - it "gets the correct resource" do - body = {new_issue_url: 'https://example.com/projects/test_project/issues/new', - project_url: 'https://example.com/projects/test_project/issues', - issues_url: 'https://example.com/issues/:id'} - expect(a_put("/projects/3/services/redmine").with(body: body)).to have_been_made + it 'gets the correct resource' do + body = { new_issue_url: 'https://example.com/projects/test_project/issues/new', + project_url: 'https://example.com/projects/test_project/issues', + issues_url: 'https://example.com/issues/:id' } + expect(a_put('/projects/3/services/redmine').with(body: body)).to have_been_made end - it "returns information about a new service" do + it 'returns information about a new service' do expect(@service).to be_truthy end end - describe ".delete_servoce" do + describe '.delete_servoce' do before do - stub_delete("/projects/3/services/redmine", "service") + stub_delete('/projects/3/services/redmine', 'service') @service = Gitlab.delete_service(3, :redmine) end - it "gets the correct resource" do - expect(a_delete("/projects/3/services/redmine")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/services/redmine')).to have_been_made end - it "returns information about a deleted service" do + it 'returns information about a deleted service' do expect(@service).to be_truthy end end diff --git a/spec/gitlab/client/sidekiq_spec.rb b/spec/gitlab/client/sidekiq_spec.rb index 1e6575a..3640392 100644 --- a/spec/gitlab/client/sidekiq_spec.rb +++ b/spec/gitlab/client/sidekiq_spec.rb @@ -1,63 +1,65 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".sidekiq_queue_metrics" do + describe '.sidekiq_queue_metrics' do before do - stub_get("/sidekiq/queue_metrics", 'sidekiq_queue_metrics') + stub_get('/sidekiq/queue_metrics', 'sidekiq_queue_metrics') @sidekiq_queue_metrics = Gitlab.sidekiq_queue_metrics end - it "gets the correct resource" do - expect(a_get("/sidekiq/queue_metrics")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/sidekiq/queue_metrics')).to have_been_made end - it "returns a information about a sidekiq default queue" do + it 'returns a information about a sidekiq default queue' do expect(@sidekiq_queue_metrics.queues.default.backlog).to eq 0 expect(@sidekiq_queue_metrics.queues.default.latency).to eq 0 end end - describe ".sidekiq_process_metrics" do + describe '.sidekiq_process_metrics' do before do - stub_get("/sidekiq/process_metrics", 'sidekiq_process_metrics') + stub_get('/sidekiq/process_metrics', 'sidekiq_process_metrics') @sidekiq_process_metrics = Gitlab.sidekiq_process_metrics end - it "gets the correct resource" do - expect(a_get("/sidekiq/process_metrics")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/sidekiq/process_metrics')).to have_been_made end - it "returns a information about a sidekiq process metrics" do + it 'returns a information about a sidekiq process metrics' do expect(@sidekiq_process_metrics.processes.first['busy']).to eq 0 end end - describe ".sidekiq_job_stats" do + describe '.sidekiq_job_stats' do before do - stub_get("/sidekiq/job_stats", 'sidekiq_job_stats') + stub_get('/sidekiq/job_stats', 'sidekiq_job_stats') @sidekiq_job_stats = Gitlab.sidekiq_job_stats end - it "gets the correct resource" do - expect(a_get("/sidekiq/job_stats")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/sidekiq/job_stats')).to have_been_made end - it "returns a information about a sidekiq process metrics" do + it 'returns a information about a sidekiq process metrics' do expect(@sidekiq_job_stats.jobs.processed).to eq 2 end end - describe ".sidekiq_compound_metrics" do + describe '.sidekiq_compound_metrics' do before do - stub_get("/sidekiq/compound_metrics", 'sidekiq_compound_metrics') + stub_get('/sidekiq/compound_metrics', 'sidekiq_compound_metrics') @sidekiq_compound_metrics = Gitlab.sidekiq_compound_metrics end - it "gets the correct resource" do - expect(a_get("/sidekiq/compound_metrics")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/sidekiq/compound_metrics')).to have_been_made end - it "returns a information about a sidekiq process metrics" do + it 'returns a information about a sidekiq process metrics' do expect(@sidekiq_compound_metrics.jobs.processed).to eq 2 end end diff --git a/spec/gitlab/client/snippets_spec.rb b/spec/gitlab/client/snippets_spec.rb index d279510..544303b 100644 --- a/spec/gitlab/client/snippets_spec.rb +++ b/spec/gitlab/client/snippets_spec.rb @@ -1,99 +1,101 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".snippets" do + describe '.snippets' do before do - stub_get("/projects/3/snippets", "snippets") + stub_get('/projects/3/snippets', 'snippets') @snippets = Gitlab.snippets(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/snippets")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/snippets')).to have_been_made end it "returns a paginated response of project's snippets" do expect(@snippets).to be_a Gitlab::PaginatedResponse - expect(@snippets.first.file_name).to eq("mailer_test.rb") + expect(@snippets.first.file_name).to eq('mailer_test.rb') end end - describe ".snippet" do + describe '.snippet' do before do - stub_get("/projects/3/snippets/1", "snippet") + stub_get('/projects/3/snippets/1', 'snippet') @snippet = Gitlab.snippet(3, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/snippets/1")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/snippets/1')).to have_been_made end - it "returns information about a snippet" do - expect(@snippet.file_name).to eq("mailer_test.rb") - expect(@snippet.author.name).to eq("John Smith") + it 'returns information about a snippet' do + expect(@snippet.file_name).to eq('mailer_test.rb') + expect(@snippet.author.name).to eq('John Smith') end end - describe ".create_snippet" do + describe '.create_snippet' do before do - stub_post("/projects/3/snippets", "snippet") + stub_post('/projects/3/snippets', 'snippet') @snippet = Gitlab.create_snippet(3, title: 'API', file_name: 'api.rb', code: 'code', visibility: 'public') end - it "gets the correct resource" do + it 'gets the correct resource' do body = { title: 'API', file_name: 'api.rb', code: 'code', visibility: 'public' } - expect(a_post("/projects/3/snippets").with(body: body)).to have_been_made + expect(a_post('/projects/3/snippets').with(body: body)).to have_been_made end - it "returns information about a new snippet" do - expect(@snippet.file_name).to eq("mailer_test.rb") - expect(@snippet.author.name).to eq("John Smith") + it 'returns information about a new snippet' do + expect(@snippet.file_name).to eq('mailer_test.rb') + expect(@snippet.author.name).to eq('John Smith') end end - describe ".edit_snippet" do + describe '.edit_snippet' do before do - stub_put("/projects/3/snippets/1", "snippet") + stub_put('/projects/3/snippets/1', 'snippet') @snippet = Gitlab.edit_snippet(3, 1, file_name: 'mailer_test.rb') end - it "gets the correct resource" do - expect(a_put("/projects/3/snippets/1"). - with(body: { file_name: 'mailer_test.rb' })).to have_been_made + it 'gets the correct resource' do + expect(a_put('/projects/3/snippets/1') + .with(body: { file_name: 'mailer_test.rb' })).to have_been_made end - it "returns information about an edited snippet" do - expect(@snippet.file_name).to eq("mailer_test.rb") - expect(@snippet.author.name).to eq("John Smith") + it 'returns information about an edited snippet' do + expect(@snippet.file_name).to eq('mailer_test.rb') + expect(@snippet.author.name).to eq('John Smith') end end - describe ".delete_snippet" do + describe '.delete_snippet' do before do - stub_delete("/projects/3/snippets/1", "snippet") + stub_delete('/projects/3/snippets/1', 'snippet') @snippet = Gitlab.delete_snippet(3, 1) end - it "gets the correct resource" do - expect(a_delete("/projects/3/snippets/1")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/snippets/1')).to have_been_made end - it "returns information about a deleted snippet" do - expect(@snippet.file_name).to eq("mailer_test.rb") - expect(@snippet.author.name).to eq("John Smith") + it 'returns information about a deleted snippet' do + expect(@snippet.file_name).to eq('mailer_test.rb') + expect(@snippet.author.name).to eq('John Smith') end end - describe ".snippet_content" do + describe '.snippet_content' do before do - stub_get("/projects/3/snippets/1/raw", "snippet_content") + stub_get('/projects/3/snippets/1/raw', 'snippet_content') @snippet_content = Gitlab.snippet_content(3, 1) end - it "gets the correct resource" do - expect(a_get("/projects/3/snippets/1/raw")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/snippets/1/raw')).to have_been_made end - it "returns raw content of a snippet" do + it 'returns raw content of a snippet' do expect(@snippet_content).to eq("#!/usr/bin/env ruby\n\nputs \"Cool snippet!\"\n") end end diff --git a/spec/gitlab/client/system_hooks_spec.rb b/spec/gitlab/client/system_hooks_spec.rb index 1b8a10b..bb7647f 100644 --- a/spec/gitlab/client/system_hooks_spec.rb +++ b/spec/gitlab/client/system_hooks_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do @@ -6,64 +8,64 @@ it { is_expected.to respond_to :system_hook } it { is_expected.to respond_to :delete_system_hook } - describe ".hooks" do + describe '.hooks' do before do - stub_get("/hooks", "system_hooks") + stub_get('/hooks', 'system_hooks') @hooks = Gitlab.hooks end - it "gets the correct resource" do - expect(a_get("/hooks")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/hooks')).to have_been_made end - it "returns a paginated response of system hooks" do + it 'returns a paginated response of system hooks' do expect(@hooks).to be_a Gitlab::PaginatedResponse - expect(@hooks.first.url).to eq("http://example.com/hook") + expect(@hooks.first.url).to eq('http://example.com/hook') end end - describe ".add_hook" do + describe '.add_hook' do before do - stub_post("/hooks", "system_hook") - @hook = Gitlab.add_hook("http://example.com/hook", token: 'secret-token') + stub_post('/hooks', 'system_hook') + @hook = Gitlab.add_hook('http://example.com/hook', token: 'secret-token') end - it "gets the correct resource" do - expect(a_post("/hooks").with(body: hash_including(token: 'secret-token'))).to have_been_made + it 'gets the correct resource' do + expect(a_post('/hooks').with(body: hash_including(token: 'secret-token'))).to have_been_made end - it "returns information about a added system hook" do - expect(@hook.url).to eq("http://example.com/hook") + it 'returns information about a added system hook' do + expect(@hook.url).to eq('http://example.com/hook') end end - describe ".hook" do + describe '.hook' do before do - stub_get("/hooks/3", "system_hook") + stub_get('/hooks/3', 'system_hook') @hook = Gitlab.hook(3) end - it "gets the correct resource" do - expect(a_get("/hooks/3")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/hooks/3')).to have_been_made end - it "returns information about a added system hook" do - expect(@hook.url).to eq("http://example.com/hook") + it 'returns information about a added system hook' do + expect(@hook.url).to eq('http://example.com/hook') end end - describe ".delete_hook" do + describe '.delete_hook' do before do - stub_delete("/hooks/3", "system_hook") + stub_delete('/hooks/3', 'system_hook') @hook = Gitlab.delete_hook(3) end - it "gets the correct resource" do - expect(a_delete("/hooks/3")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/hooks/3')).to have_been_made end - it "returns information about a deleted system hook" do - expect(@hook.url).to eq("http://example.com/hook") + it 'returns information about a deleted system hook' do + expect(@hook.url).to eq('http://example.com/hook') end end end diff --git a/spec/gitlab/client/tags_spec.rb b/spec/gitlab/client/tags_spec.rb index daaea9d..f2cb282 100644 --- a/spec/gitlab/client/tags_spec.rb +++ b/spec/gitlab/client/tags_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do @@ -10,142 +12,142 @@ describe '.tags' do before do - stub_get("/projects/3/repository/tags", "tags") + stub_get('/projects/3/repository/tags', 'tags') @tags = Gitlab.tags(3) end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/tags")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/tags')).to have_been_made end - it "returns a paginated response of repository tags" do + it 'returns a paginated response of repository tags' do expect(@tags).to be_a Gitlab::PaginatedResponse expect(@tags.map(&:name)).to eq(%w[0.0.2 0.0.1]) end end - describe ".tag" do + describe '.tag' do before do - stub_get("/projects/3/repository/tags/0.0.1", "tag") - @tag = Gitlab.tag(3, "0.0.1") + stub_get('/projects/3/repository/tags/0.0.1', 'tag') + @tag = Gitlab.tag(3, '0.0.1') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/tags/0.0.1")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/tags/0.0.1')).to have_been_made end - it "returns information about a repository tag" do - expect(@tag.name).to eq("0.0.1") + it 'returns information about a repository tag' do + expect(@tag.name).to eq('0.0.1') end - context "tag with special character" do + context 'tag with special character' do before do - stub_get("/projects/3/repository/tags/test%2Fme", "tag") - @tag = Gitlab.tag(3, "test/me") + stub_get('/projects/3/repository/tags/test%2Fme', 'tag') + @tag = Gitlab.tag(3, 'test/me') end - it "gets the correct resource" do - expect(a_get("/projects/3/repository/tags/test%2Fme")).to have_been_made + it 'gets the correct resource' do + expect(a_get('/projects/3/repository/tags/test%2Fme')).to have_been_made end end end - describe ".create_tag" do + describe '.create_tag' do before do - stub_post("/projects/3/repository/tags", "tag_create") - @tag = Gitlab.create_tag(3, "0.0.1", "master", 'this tag is annotated', 'and it has release notes') + stub_post('/projects/3/repository/tags', 'tag_create') + @tag = Gitlab.create_tag(3, '0.0.1', 'master', 'this tag is annotated', 'and it has release notes') end - it "gets the correct resource" do - expect(a_post("/projects/3/repository/tags")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/repository/tags')).to have_been_made end - it "returns information about a new repository tag" do - expect(@tag.name).to eq("0.0.1") + it 'returns information about a new repository tag' do + expect(@tag.name).to eq('0.0.1') expect(@tag.message).to eq('this tag is annotated') end - it "returns detailed information" do + it 'returns detailed information' do expect(@tag.release.description).to eq('and it has release notes') end end - describe ".delete_tag" do + describe '.delete_tag' do before do - stub_delete("/projects/3/repository/tags/0.0.1", "tag_delete") - @tag = Gitlab.delete_tag(3, "0.0.1") + stub_delete('/projects/3/repository/tags/0.0.1', 'tag_delete') + @tag = Gitlab.delete_tag(3, '0.0.1') end - it "gets the correct resource" do - expect(a_delete("/projects/3/repository/tags/0.0.1")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/repository/tags/0.0.1')).to have_been_made end - it "returns information about the deleted repository tag" do - expect(@tag.tag_name).to eq("0.0.1") + it 'returns information about the deleted repository tag' do + expect(@tag.tag_name).to eq('0.0.1') end - context "tag with special character" do + context 'tag with special character' do before do - stub_delete("/projects/3/repository/tags/test%2Fme", "tag_delete") - @tag = Gitlab.delete_tag(3, "test/me") + stub_delete('/projects/3/repository/tags/test%2Fme', 'tag_delete') + @tag = Gitlab.delete_tag(3, 'test/me') end - it "gets the correct resource" do - expect(a_delete("/projects/3/repository/tags/test%2Fme")).to have_been_made + it 'gets the correct resource' do + expect(a_delete('/projects/3/repository/tags/test%2Fme')).to have_been_made end end end - describe ".create_release" do + describe '.create_release' do before do - stub_post("/projects/3/repository/tags/0.0.1/release", "release_create") - @tag = Gitlab.create_release(3, "0.0.1", "Amazing release. Wow") + stub_post('/projects/3/repository/tags/0.0.1/release', 'release_create') + @tag = Gitlab.create_release(3, '0.0.1', 'Amazing release. Wow') end - it "gets the correct resource" do - expect(a_post("/projects/3/repository/tags/0.0.1/release")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/repository/tags/0.0.1/release')).to have_been_made end - it "returns information about the tag and the release" do - expect(@tag.tag_name).to eq("0.0.1") - expect(@tag.description).to eq("Amazing release. Wow") + it 'returns information about the tag and the release' do + expect(@tag.tag_name).to eq('0.0.1') + expect(@tag.description).to eq('Amazing release. Wow') end - context "tag with special character" do + context 'tag with special character' do before do - stub_post("/projects/3/repository/tags/test%2Fme/release", "release_create") - @tag = Gitlab.create_release(3, "test/me", "Amazing release. Wow") + stub_post('/projects/3/repository/tags/test%2Fme/release', 'release_create') + @tag = Gitlab.create_release(3, 'test/me', 'Amazing release. Wow') end - it "gets the correct resource" do - expect(a_post("/projects/3/repository/tags/test%2Fme/release")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/projects/3/repository/tags/test%2Fme/release')).to have_been_made end end end - describe ".update_release" do + describe '.update_release' do before do - stub_put("/projects/3/repository/tags/0.0.1/release", "release_update") - @tag = Gitlab.update_release(3, "0.0.1", 'Amazing release. Wow') + stub_put('/projects/3/repository/tags/0.0.1/release', 'release_update') + @tag = Gitlab.update_release(3, '0.0.1', 'Amazing release. Wow') end - it "updates the correct resource" do - expect(a_put("/projects/3/repository/tags/0.0.1/release")).to have_been_made + it 'updates the correct resource' do + expect(a_put('/projects/3/repository/tags/0.0.1/release')).to have_been_made end - it "returns information about the tag" do - expect(@tag.tag_name).to eq("0.0.1") + it 'returns information about the tag' do + expect(@tag.tag_name).to eq('0.0.1') expect(@tag.description).to eq('Amazing release. Wow') end - context "tag with special character" do + context 'tag with special character' do before do - stub_put("/projects/3/repository/tags/test%2Fme/release", "release_update") - @tag = Gitlab.update_release(3, "test/me", 'Amazing release. Wow') + stub_put('/projects/3/repository/tags/test%2Fme/release', 'release_update') + @tag = Gitlab.update_release(3, 'test/me', 'Amazing release. Wow') end - it "updates the correct resource" do - expect(a_put("/projects/3/repository/tags/test%2Fme/release")).to have_been_made + it 'updates the correct resource' do + expect(a_put('/projects/3/repository/tags/test%2Fme/release')).to have_been_made end end end diff --git a/spec/gitlab/client/templates_spec.rb b/spec/gitlab/client/templates_spec.rb new file mode 100644 index 0000000..6f16066 --- /dev/null +++ b/spec/gitlab/client/templates_spec.rb @@ -0,0 +1,125 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.dockerfile_templates' do + before do + stub_get('/templates/dockerfiles', 'dockerfile_templates') + @dockerfile_templates = Gitlab.dockerfile_templates + end + + it 'gets the correct resource' do + expect(a_get('/templates/dockerfiles')).to have_been_made + end + + it 'returns a paginated response of dockerfile templates' do + expect(@dockerfile_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.dockerfile_template' do + before do + stub_get('/templates/dockerfiles/Binary', 'dockerfile_project_template') + @dockerfile_template = Gitlab.dockerfile_template('Binary') + end + + it 'gets the correct resource' do + expect(a_get('/templates/dockerfiles/Binary')).to have_been_made + end + + it 'returns the correct information about the dockerfile template' do + expect(@dockerfile_template.name).to eq 'Binary' + end + end + + describe '.gitignore_templates' do + before do + stub_get('/templates/gitignores', 'gitignore_templates') + @gitignore_templates = Gitlab.gitignore_templates + end + + it 'gets the correct resource' do + expect(a_get('/templates/gitignores')).to have_been_made + end + + it 'returns a paginated response of gitignore templates' do + expect(@gitignore_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.gitignore_template' do + before do + stub_get('/templates/gitignores/Ruby', 'gitignore_template') + @gitignore_template = Gitlab.gitignore_template('Ruby') + end + + it 'gets the correct resource' do + expect(a_get('/templates/gitignores/Ruby')).to have_been_made + end + + it 'returns the correct information about the gitignore template' do + expect(@gitignore_template.name).to eq 'Ruby' + end + end + + describe '.gitlab_ci_yml_templates' do + before do + stub_get('/templates/gitlab_ci_ymls', 'gitlab_ci_yml_templates') + @gitlab_ci_yml_templates = Gitlab.gitlab_ci_yml_templates + end + + it 'gets the correct resource' do + expect(a_get('/templates/gitlab_ci_ymls')).to have_been_made + end + + it 'returns a paginated response of gitlab_ci_yml templates' do + expect(@gitlab_ci_yml_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.gitlab_ci_yml_template' do + before do + stub_get('/templates/gitlab_ci_ymls/Ruby', 'gitlab_ci_yml_template') + @gitlab_ci_yml_template = Gitlab.gitlab_ci_yml_template('Ruby') + end + + it 'gets the correct resource' do + expect(a_get('/templates/gitlab_ci_ymls/Ruby')).to have_been_made + end + + it 'returns the correct information about the gitlab_ci_yml template' do + expect(@gitlab_ci_yml_template.name).to eq 'Ruby' + end + end + + describe '.license_templates' do + before do + stub_get('/templates/licenses', 'license_templates') + @license_templates = Gitlab.license_templates + end + + it 'gets the correct resource' do + expect(a_get('/templates/licenses')).to have_been_made + end + + it 'returns a paginated response of license templates' do + expect(@license_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.license_template' do + before do + stub_get('/templates/licenses/mit', 'license_template') + @license_template = Gitlab.license_template('mit') + end + + it 'gets the correct resource' do + expect(a_get('/templates/licenses/mit')).to have_been_made + end + + it 'returns the correct information about the license template' do + expect(@license_template.key).to eq 'mit' + end + end +end diff --git a/spec/gitlab/client/todos_spec.rb b/spec/gitlab/client/todos_spec.rb index 130447c..c7815c9 100644 --- a/spec/gitlab/client/todos_spec.rb +++ b/spec/gitlab/client/todos_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do describe '.todos' do before do - stub_get("/todos", "todos") + stub_get('/todos', 'todos') @todos = Gitlab.todos end - it "gets the correct resources" do - expect(a_get("/todos")).to have_been_made + it 'gets the correct resources' do + expect(a_get('/todos')).to have_been_made end it "returns a paginated response of user's todos" do @@ -18,15 +20,15 @@ describe '.mark_todo_as_done' do before do - stub_post("/todos/102/mark_as_done", "todo") + stub_post('/todos/102/mark_as_done', 'todo') @todo = Gitlab.mark_todo_as_done(102) end - it "gets the correct resource" do - expect(a_post("/todos/102/mark_as_done")).to have_been_made + it 'gets the correct resource' do + expect(a_post('/todos/102/mark_as_done')).to have_been_made end - it "returns information about the todo marked as done" do + it 'returns information about the todo marked as done' do expect(@todo.id).to eq(102) expect(@todo.state).to eq('done') end @@ -34,12 +36,12 @@ describe '.mark_all_todos_as_done' do before do - stub_post("/todos/mark_as_done", "todos") + stub_post('/todos/mark_as_done', 'todos') @todos = Gitlab.mark_all_todos_as_done end - it "gets the correct resources" do - expect(a_post("/todos/mark_as_done")).to have_been_made + it 'gets the correct resources' do + expect(a_post('/todos/mark_as_done')).to have_been_made end end end diff --git a/spec/gitlab/client/users_spec.rb b/spec/gitlab/client/users_spec.rb index 4e30a2b..eaeb115 100644 --- a/spec/gitlab/client/users_spec.rb +++ b/spec/gitlab/client/users_spec.rb @@ -1,416 +1,455 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Client do - describe ".users" do - before do - stub_get("/users", "users") + describe '.users' do + before do + stub_get('/users', 'users') @users = Gitlab.users end - it "gets the correct resource" do - expect(a_get("/users")).to have_been_made - end - - it "returns a paginated response of users" do + it 'gets the correct resource' do + expect(a_get('/users')).to have_been_made + end + + it 'returns a paginated response of users' do expect(@users).to be_a Gitlab::PaginatedResponse - expect(@users.first.email).to eq("john@example.com") - end - end - - describe ".user" do - context "with user ID passed" do - before do - stub_get("/users/1", "user") + expect(@users.first.email).to eq('john@example.com') + end + end + + describe '.user' do + context 'with user ID passed' do + before do + stub_get('/users/1', 'user') @user = Gitlab.user(1) end - it "gets the correct resource" do - expect(a_get("/users/1")).to have_been_made - end - - it "returns information about a user" do - expect(@user.email).to eq("john@example.com") - end - end - - context "without user ID passed" do - before do - stub_get("/user", "user") + it 'gets the correct resource' do + expect(a_get('/users/1')).to have_been_made + end + + it 'returns information about a user' do + expect(@user.email).to eq('john@example.com') + end + end + + context 'without user ID passed' do + before do + stub_get('/user', 'user') @user = Gitlab.user end - it "gets the correct resource" do - expect(a_get("/user")).to have_been_made - end - - it "returns information about an authorized user" do - expect(@user.email).to eq("john@example.com") - end - end - end - - describe ".create_user" do - context "when successful request" do - before do - stub_post("/users", "user") - @user = Gitlab.create_user("email", "pass") - end - - it "gets the correct resource" do - body = { email: "email", password: "pass", name: "email" } - expect(a_post("/users").with(body: body)).to have_been_made - end - - it "returns information about a created user" do - expect(@user.email).to eq("john@example.com") - end - end - - context "when bad request" do - it "throws an exception" do - stub_post("/users", "error_already_exists", 409) + it 'gets the correct resource' do + expect(a_get('/user')).to have_been_made + end + + it 'returns information about an authorized user' do + expect(@user.email).to eq('john@example.com') + end + end + end + + describe '.create_user' do + context 'when successful request' do + before do + stub_post('/users', 'user') + @user = Gitlab.create_user('email', 'pass') + end + + it 'gets the correct resource' do + body = { email: 'email', password: 'pass', name: 'email' } + expect(a_post('/users').with(body: body)).to have_been_made + end + + it 'returns information about a created user' do + expect(@user.email).to eq('john@example.com') + end + end + + context 'when bad request' do + it 'throws an exception' do + stub_post('/users', 'error_already_exists', 409) expect do - Gitlab.create_user("email", "pass") + Gitlab.create_user('email', 'pass') end.to raise_error(Gitlab::Error::Conflict, "Server responded with code 409, message: 409 Already exists. Request URI: #{Gitlab.endpoint}/users") end end end - describe ".create_user_with_userame" do - context "when successful request" do - before do - stub_post("/users", "user") - @user = Gitlab.create_user("email", "pass", "username") - end - - it "gets the correct resource" do - body = { email: "email", password: "pass", username: "username" } - expect(a_post("/users").with(body: body)).to have_been_made - end - - it "returns information about a created user" do - expect(@user.email).to eq("john@example.com") - end - end - - context "when bad request" do - it "throws an exception" do - stub_post("/users", "error_already_exists", 409) + describe '.create_user_with_userame' do + context 'when successful request' do + before do + stub_post('/users', 'user') + @user = Gitlab.create_user('email', 'pass', 'username') + end + + it 'gets the correct resource' do + body = { email: 'email', password: 'pass', username: 'username' } + expect(a_post('/users').with(body: body)).to have_been_made + end + + it 'returns information about a created user' do + expect(@user.email).to eq('john@example.com') + end + end + + context 'when bad request' do + it 'throws an exception' do + stub_post('/users', 'error_already_exists', 409) expect do - Gitlab.create_user("email", "pass", "username") + Gitlab.create_user('email', 'pass', 'username') end.to raise_error(Gitlab::Error::Conflict, "Server responded with code 409, message: 409 Already exists. Request URI: #{Gitlab.endpoint}/users") end end end - describe ".edit_user" do - before do - @options = { name: "Roberto" } - stub_put("/users/1", "user").with(body: @options) + describe '.edit_user' do + before do + @options = { name: 'Roberto' } + stub_put('/users/1', 'user').with(body: @options) @user = Gitlab.edit_user(1, @options) end - it "gets the correct resource" do - expect(a_put("/users/1").with(body: @options)).to have_been_made - end - end - - describe ".delete_user" do - before do - stub_delete("/users/1", "user") + it 'gets the correct resource' do + expect(a_put('/users/1').with(body: @options)).to have_been_made + end + end + + describe '.delete_user' do + before do + stub_delete('/users/1', 'user') @user = Gitlab.delete_user(1) end - it "gets the correct resource" do - expect(a_delete("/users/1")).to have_been_made - end - - it "returns information about a deleted user" do - expect(@user.email).to eq("john@example.com") - end - end - - describe ".block_user" do - before do - stub_post("/users/1/block", "user_block_unblock") + it 'gets the correct resource' do + expect(a_delete('/users/1')).to have_been_made + end + + it 'returns information about a deleted user' do + expect(@user.email).to eq('john@example.com') + end + end + + describe '.block_user' do + before do + stub_post('/users/1/block', 'user_block_unblock') @result = Gitlab.block_user(1) end - it "gets the correct resource" do - expect(a_post("/users/1/block")).to have_been_made - end - - it "returns boolean" do + it 'gets the correct resource' do + expect(a_post('/users/1/block')).to have_been_made + end + + it 'returns boolean' do expect(@result).to eq(true) end end - describe ".unblock_user" do - before do - stub_post("/users/1/unblock", "user_block_unblock") + describe '.unblock_user' do + before do + stub_post('/users/1/unblock', 'user_block_unblock') @result = Gitlab.unblock_user(1) end - it "gets the correct resource" do - expect(a_post("/users/1/unblock")).to have_been_made - end - - it "returns boolean" do + it 'gets the correct resource' do + expect(a_post('/users/1/unblock')).to have_been_made + end + + it 'returns boolean' do expect(@result).to eq(true) end end - describe ".session" do + describe '.session' do after do Gitlab.endpoint = 'https://api.example.com' Gitlab.private_token = 'secret' end before do - stub_request(:post, "#{Gitlab.endpoint}/session"). - to_return(body: load_fixture('session'), status: 200) - @session = Gitlab.session("email", "pass") - end - - context "when endpoint is not set" do - it "raises Error::MissingCredentials" do + stub_request(:post, "#{Gitlab.endpoint}/session") + .to_return(body: load_fixture('session'), status: 200) + @session = Gitlab.session('email', 'pass') + end + + context 'when endpoint is not set' do + it 'raises Error::MissingCredentials' do Gitlab.endpoint = nil expect do - Gitlab.session("email", "pass") + Gitlab.session('email', 'pass') end.to raise_error(Gitlab::Error::MissingCredentials, 'Please set an endpoint to API') end end - context "when private_token is not set" do - it "does not raise Error::MissingCredentials" do + context 'when private_token is not set' do + it 'does not raise Error::MissingCredentials' do Gitlab.private_token = nil - expect { Gitlab.session("email", "pass") }.to_not raise_error - end - end - - context "when endpoint is set" do - it "gets the correct resource" do + expect { Gitlab.session('email', 'pass') }.not_to raise_error + end + end + + context 'when endpoint is set' do + it 'gets the correct resource' do expect(a_request(:post, "#{Gitlab.endpoint}/session")).to have_been_made end - it "returns information about a created session" do - expect(@session.email).to eq("john@example.com") - expect(@session.private_token).to eq("qEsq1pt6HJPaNciie3MG") - end - end - end - - describe ".ssh_keys" do - context "with user ID passed" do - before do - stub_get("/users/1/keys", "keys") - @keys = Gitlab.ssh_keys({ user_id: 1 }) - end - - it "gets the correct resource" do - expect(a_get("/users/1/keys")).to have_been_made - end - - it "returns a paginated response of SSH keys" do + it 'returns information about a created session' do + expect(@session.email).to eq('john@example.com') + expect(@session.private_token).to eq('qEsq1pt6HJPaNciie3MG') + end + end + end + + describe '.ssh_keys' do + context 'with user ID passed' do + before do + stub_get('/users/1/keys', 'keys') + @keys = Gitlab.ssh_keys(user_id: 1) + end + + it 'gets the correct resource' do + expect(a_get('/users/1/keys')).to have_been_made + end + + it 'returns a paginated response of SSH keys' do expect(@keys).to be_a Gitlab::PaginatedResponse - expect(@keys.first.title).to eq("narkoz@helium") - end - end - - context "without user ID passed" do - before do - stub_get("/user/keys", "keys") + expect(@keys.first.title).to eq('narkoz@helium') + end + end + + context 'without user ID passed' do + before do + stub_get('/user/keys', 'keys') @keys = Gitlab.ssh_keys end - it "gets the correct resource" do - expect(a_get("/user/keys")).to have_been_made - end - - it "returns a paginated response of SSH keys" do + it 'gets the correct resource' do + expect(a_get('/user/keys')).to have_been_made + end + + it 'returns a paginated response of SSH keys' do expect(@keys).to be_a Gitlab::PaginatedResponse - expect(@keys.first.title).to eq("narkoz@helium") - end - end - end - - describe ".ssh_key" do - before do - stub_get("/user/keys/1", "key") + expect(@keys.first.title).to eq('narkoz@helium') + end + end + end + + describe '.ssh_key' do + before do + stub_get('/user/keys/1', 'key') @key = Gitlab.ssh_key(1) end - it "gets the correct resource" do - expect(a_get("/user/keys/1")).to have_been_made - end - - it "returns information about an SSH key" do - expect(@key.title).to eq("narkoz@helium") - end - end - - describe ".create_ssh_key" do - before do - stub_post("/user/keys", "key") - @key = Gitlab.create_ssh_key("title", "body") - end - - it "gets the correct resource" do - body = { title: "title", key: "body" } - expect(a_post("/user/keys").with(body: body)).to have_been_made - end - - it "returns information about a created SSH key" do - expect(@key.title).to eq("narkoz@helium") - end - end - - describe ".delete_ssh_key" do - before do - stub_delete("/user/keys/1", "key") - @key = Gitlab.delete_ssh_key(1) - end - - it "gets the correct resource" do - expect(a_delete("/user/keys/1")).to have_been_made - end - - it "returns information about a deleted SSH key" do - expect(@key.title).to eq("narkoz@helium") - end - end - - describe ".emails" do - describe "without user ID" do - before do - stub_get("/user/emails", "user_emails") + it 'gets the correct resource' do + expect(a_get('/user/keys/1')).to have_been_made + end + + it 'returns information about an SSH key' do + expect(@key.title).to eq('narkoz@helium') + end + end + + describe '.create_ssh_key' do + describe 'without user ID' do + before do + stub_post('/user/keys', 'key') + @key = Gitlab.create_ssh_key('title', 'body') + end + + it 'gets the correct resource' do + body = { title: 'title', key: 'body' } + expect(a_post('/user/keys').with(body: body)).to have_been_made + end + + it 'returns information about a created SSH key' do + expect(@key.title).to eq('narkoz@helium') + end + end + + describe 'with user ID' do + before do + stub_post('/users/1/keys', 'key') + @options = { user_id: 1 } + @key = Gitlab.create_ssh_key('title', 'body', @options) + end + + it 'gets the correct resource' do + body = { title: 'title', key: 'body' } + expect(a_post('/users/1/keys').with(body: body)).to have_been_made + end + + it 'returns information about a created SSH key' do + expect(@key.title).to eq('narkoz@helium') + end + end + end + + describe '.delete_ssh_key' do + describe 'without user ID' do + before do + stub_delete('/user/keys/1', 'key') + @key = Gitlab.delete_ssh_key(1) + end + + it 'gets the correct resource' do + expect(a_delete('/user/keys/1')).to have_been_made + end + + it 'returns information about a deleted SSH key' do + expect(@key.title).to eq('narkoz@helium') + end + end + + describe 'with user ID' do + before do + stub_delete('/users/1/keys/1', 'key') + @options = { user_id: 1 } + @key = Gitlab.delete_ssh_key(1, @options) + end + + it 'gets the correct resource' do + expect(a_delete('/users/1/keys/1')).to have_been_made + end + + it 'returns information about a deleted SSH key' do + expect(@key.title).to eq('narkoz@helium') + end + end + end + + describe '.emails' do + describe 'without user ID' do + before do + stub_get('/user/emails', 'user_emails') @emails = Gitlab.emails end - it "gets the correct resource" do - expect(a_get("/user/emails")).to have_been_made - end - - it "returns a information about a emails of user" do + it 'gets the correct resource' do + expect(a_get('/user/emails')).to have_been_made + end + + it 'returns a information about a emails of user' do email = @emails.first expect(email.id).to eq 1 - expect(email.email).to eq("email@example.com") - end - end - - describe "with user ID" do - before do - stub_get("/users/2/emails", "user_emails") + expect(email.email).to eq('email@example.com') + end + end + + describe 'with user ID' do + before do + stub_get('/users/2/emails', 'user_emails') @emails = Gitlab.emails(2) end - it "gets the correct resource" do - expect(a_get("/users/2/emails")).to have_been_made - end - - it "returns a information about a emails of user" do + it 'gets the correct resource' do + expect(a_get('/users/2/emails')).to have_been_made + end + + it 'returns a information about a emails of user' do email = @emails.first expect(email.id).to eq 1 - expect(email.email).to eq("email@example.com") - end - end - end - - describe ".email" do - before do - stub_get("/user/emails/2", "user_email") + expect(email.email).to eq('email@example.com') + end + end + end + + describe '.email' do + before do + stub_get('/user/emails/2', 'user_email') @email = Gitlab.email(2) end - it "gets the correct resource" do - expect(a_get("/user/emails/2")).to have_been_made - end - - it "returns a information about a email of user" do + it 'gets the correct resource' do + expect(a_get('/user/emails/2')).to have_been_made + end + + it 'returns a information about a email of user' do expect(@email.id).to eq 1 - expect(@email.email).to eq("email@example.com") - end - end - - describe ".add_email" do - describe "without user ID" do - before do - stub_post("/user/emails", "user_email") - @email = Gitlab.add_email("email@example.com") - end - - it "gets the correct resource" do - body = { email: "email@example.com" } - expect(a_post("/user/emails").with(body: body)).to have_been_made - end - - it "returns information about a new email" do + expect(@email.email).to eq('email@example.com') + end + end + + describe '.add_email' do + describe 'without user ID' do + before do + stub_post('/user/emails', 'user_email') + @email = Gitlab.add_email('email@example.com') + end + + it 'gets the correct resource' do + body = { email: 'email@example.com' } + expect(a_post('/user/emails').with(body: body)).to have_been_made + end + + it 'returns information about a new email' do expect(@email.id).to eq(1) - expect(@email.email).to eq("email@example.com") - end - end - - describe "with user ID" do - before do - stub_post("/users/2/emails", "user_email") - @email = Gitlab.add_email("email@example.com", 2) - end - - it "gets the correct resource" do - body = { email: "email@example.com" } - expect(a_post("/users/2/emails").with(body: body)).to have_been_made - end - - it "returns information about a new email" do + expect(@email.email).to eq('email@example.com') + end + end + + describe 'with user ID' do + before do + stub_post('/users/2/emails', 'user_email') + @email = Gitlab.add_email('email@example.com', 2) + end + + it 'gets the correct resource' do + body = { email: 'email@example.com' } + expect(a_post('/users/2/emails').with(body: body)).to have_been_made + end + + it 'returns information about a new email' do expect(@email.id).to eq(1) - expect(@email.email).to eq("email@example.com") - end - end - end - - describe ".delete_email" do - describe "without user ID" do - before do - stub_delete("/user/emails/1", "user_email") + expect(@email.email).to eq('email@example.com') + end + end + end + + describe '.delete_email' do + describe 'without user ID' do + before do + stub_delete('/user/emails/1', 'user_email') @email = Gitlab.delete_email(1) end - it "gets the correct resource" do - expect(a_delete("/user/emails/1")).to have_been_made - end - - it "returns information about a deleted email" do + it 'gets the correct resource' do + expect(a_delete('/user/emails/1')).to have_been_made + end + + it 'returns information about a deleted email' do expect(@email).to be_truthy end end - describe "with user ID" do - before do - stub_delete("/users/2/emails/1", "user_email") + describe 'with user ID' do + before do + stub_delete('/users/2/emails/1', 'user_email') @email = Gitlab.delete_email(1, 2) end - it "gets the correct resource" do - expect(a_delete("/users/2/emails/1")).to have_been_made - end - - it "returns information about a deleted email" do + it 'gets the correct resource' do + expect(a_delete('/users/2/emails/1')).to have_been_made + end + + it 'returns information about a deleted email' do expect(@email).to be_truthy end end end - describe ".user_search" do - before do - stub_get("/users?search=User", "user_search") + describe '.user_search' do + before do + stub_get('/users?search=User', 'user_search') @users = Gitlab.user_search('User') end - it "gets the correct resource" do - expect(a_get("/users?search=User")).to have_been_made - end - - it "returns an array of users found" do + it 'gets the correct resource' do + expect(a_get('/users?search=User')).to have_been_made + end + + it 'returns an array of users found' do expect(@users.first.id).to eq(1) expect(@users.last.id).to eq(2) end diff --git a/spec/gitlab/client/versions_spec.rb b/spec/gitlab/client/versions_spec.rb new file mode 100644 index 0000000..61f9e53 --- /dev/null +++ b/spec/gitlab/client/versions_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.version' do + before do + stub_get('/version', 'version') + end + + let!(:version) { Gitlab.version } + + it 'gets the correct resource' do + expect(a_get('/version')).to have_been_made + end + + it 'returns information about gitlab server' do + expect(version.version).to eq('8.13.0-pre') + expect(version.revision).to eq('4e963fe') + end + end +end diff --git a/spec/gitlab/client/wikis_spec.rb b/spec/gitlab/client/wikis_spec.rb new file mode 100644 index 0000000..e8e7935 --- /dev/null +++ b/spec/gitlab/client/wikis_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.wikis' do + before do + stub_get('/projects/1/wikis', 'wikis') + @wikis = Gitlab.wikis(1) + end + + it 'gets the correct resource' do + expect(a_get('/projects/1/wikis')).to have_been_made + end + + it "returns a response of a project's wikis" do + expect(@wikis).to be_a Gitlab::PaginatedResponse + end + end + + describe '.wiki' do + before do + stub_get('/projects/1/wikis/home', 'wiki') + @wiki = Gitlab.wiki(1, 'home') + end + + it 'gets the correct resource' do + expect(a_get('/projects/1/wikis/home')).to have_been_made + end + + it 'returns correct information about the wiki' do + expect(@wiki.slug).to eq 'home' + end + end + + describe '.create_wiki' do + before do + stub_post('/projects/1/wikis', 'wiki') + @wiki = Gitlab.create_wiki(1, 'home', 'home page') + end + + it 'gets the correct resource' do + expect(a_post('/projects/1/wikis') + .with(body: { content: 'home page', title: 'home' })).to have_been_made + end + + it 'returns correct information about the created wiki' do + expect(@wiki.content).to eq 'home page' + expect(@wiki.title).to eq 'home' + end + end + + describe '.update_wiki' do + before do + stub_put('/projects/1/wikis/home', 'wiki') + @wiki = Gitlab.update_wiki(1, 'home', format: 'markdown') + end + + it 'gets the correct resource' do + expect(a_put('/projects/1/wikis/home') + .with(body: { format: 'markdown' })).to have_been_made + end + + it 'returns correct information about the updated wiki' do + expect(@wiki.format).to eq 'markdown' + end + end + + describe '.delete_wiki' do + before do + stub_delete('/projects/1/wikis/home', 'empty') + @wiki = Gitlab.delete_wiki(1, 'home') + end + + it 'gets the correct resource' do + expect(a_delete('/projects/1/wikis/home')).to have_been_made + end + end +end diff --git a/spec/gitlab/error_spec.rb b/spec/gitlab/error_spec.rb index 14f9ca3..26e3a52 100644 --- a/spec/gitlab/error_spec.rb +++ b/spec/gitlab/error_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Error::ResponseError do @@ -12,16 +14,19 @@ %r{Server responded with code \d+, message: Displayed error. Request URI: https://gitlab.com/api/v3/foo}, %r{Server responded with code \d+, message: 'embed_entity' \(foo: bar\) \(sna: fu\), 'password' too short. Request URI: https://gitlab.com/api/v3/foo}, %r{Server responded with code \d+, message: First message. Second message.. Request URI: https://gitlab.com/api/v3/foo}, + %r{Server responded with code \d+, message: 'error' Spam detected. Request URI: https://gitlab.com/api/v3/foo} ] end # Set up some response scenarios to test. [ - { code: 401, parsed_response: Gitlab::ObjectifiedHash.new(message: 'Displayed message', error_description: 'should not be displayed', error: 'also will not be displayed')}, - { code: 404, parsed_response: Gitlab::ObjectifiedHash.new(error_description: 'Displayed error_description', error: 'also will not be displayed')}, - { code: 401, parsed_response: Gitlab::ObjectifiedHash.new(error: 'Displayed error')}, - { code: 500, parsed_response: Gitlab::ObjectifiedHash.new(embed_entity: { foo: ['bar'], sna: ['fu']}, password: ['too short'])}, - { code: 403, parsed_response: Array.new(['First message.', 'Second message.'])}, + { code: 401, parsed_response: Gitlab::ObjectifiedHash.new(message: 'Displayed message', error_description: 'should not be displayed', error: 'also will not be displayed') }, + { code: 404, parsed_response: Gitlab::ObjectifiedHash.new(error_description: 'Displayed error_description', error: 'also will not be displayed') }, + { code: 401, parsed_response: Gitlab::ObjectifiedHash.new(error: 'Displayed error') }, + { code: 500, parsed_response: Gitlab::ObjectifiedHash.new(embed_entity: { foo: ['bar'], sna: ['fu'] }, password: ['too short']) }, + { code: 403, parsed_response: Array.new(['First message.', 'Second message.']) }, + { code: 400, parsed_response: Gitlab::ObjectifiedHash.new(message: { error: 'Spam detected' }) } + ].each_with_index do |data, index| it 'returns the expected message' do response_double = double(**data, request: @request_double) diff --git a/spec/gitlab/file_response_spec.rb b/spec/gitlab/file_response_spec.rb index b72c9b7..7aa2028 100644 --- a/spec/gitlab/file_response_spec.rb +++ b/spec/gitlab/file_response_spec.rb @@ -2,32 +2,32 @@ describe Gitlab::FileResponse do before do - @file_response = Gitlab::FileResponse.new StringIO.new("", 'rb+') + @file_response = described_class.new StringIO.new('', 'rb+') end context '.empty?' do - it "returns false" do + it 'returns false' do expect(@file_response.empty?).to be false end end context '.to_hash' do - it "has `filename` key and `data` key" do + it 'has `filename` key and `data` key' do h = @file_response.to_hash - expect(h.key?(:filename)).to be_truthy - expect(h.key?(:data)).to be_truthy + expect(h).to be_key(:filename) + expect(h).to be_key(:data) end end context '.parse_headers!' do - it "parses headers" do + it 'parses headers' do @file_response.parse_headers!('Content-Disposition' => 'attachment; filename=artifacts.zip') - expect(@file_response.filename).to eq "artifacts.zip" + expect(@file_response.filename).to eq 'artifacts.zip' end - it "handles quoted filenames" do + it 'handles quoted filenames' do @file_response.parse_headers!('Content-Disposition' => 'attachment; filename="artifacts.zip"') - expect(@file_response.filename).to eq "artifacts.zip" + expect(@file_response.filename).to eq 'artifacts.zip' end end end diff --git a/spec/gitlab/help_spec.rb b/spec/gitlab/help_spec.rb index 7d892f2..489d69d 100644 --- a/spec/gitlab/help_spec.rb +++ b/spec/gitlab/help_spec.rb @@ -1,44 +1,46 @@ require 'spec_helper' describe Gitlab::Help do - describe ".ri_cmd" do - context "ri command found" do - it "returns the path to RI" do - allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('/usr/bin/ri') - expect(Gitlab::Help.ri_cmd).to eq('/usr/bin/ri') + describe '.ri_cmd' do + context 'ri command found' do + it 'returns the path to RI' do + allow(described_class).to receive(:`).with(/which ri/).and_return('/usr/bin/ri') + expect(described_class.ri_cmd).to eq('/usr/bin/ri') end end - context "ri command NOT found" do - it "raises RuntimeError" do - allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('') - expect { Gitlab::Help.ri_cmd }.to raise_error RuntimeError + context 'ri command NOT found' do + it 'raises RuntimeError' do + allow(described_class).to receive(:`).with(/which ri/).and_return('') + expect { described_class.ri_cmd }.to raise_error RuntimeError end end end - describe ".change_help_output!" do + describe '.change_help_output!' do before do - @cmd = "create_branch" + @cmd = 'create_branch' @help_output = "Gitlab.#{@cmd}(4, 'new-branch', 'master')" - @help_output_with_options = "Gitlab.groups({ per_page: 3 })" + @help_output_with_options = 'Gitlab.groups({ per_page: 3 })' end - it "returns a String of modified output" do - Gitlab::Help.change_help_output! @cmd, @help_output + + it 'returns a String of modified output' do + described_class.change_help_output! @cmd, @help_output expect(@help_output).to eq("Gitlab.create_branch 4 'new-branch' 'master'") end - it "formats options hash and return a String of modified output" do - Gitlab::Help.change_help_output! 'groups', @help_output_with_options - expect(@help_output_with_options).to eq("Gitlab.groups \"{ per_page: 3 }\"") + it 'formats options hash and return a String of modified output' do + described_class.change_help_output! 'groups', @help_output_with_options + expect(@help_output_with_options).to eq('Gitlab.groups "{ per_page: 3 }"') end end - describe ".namespace" do + describe '.namespace' do before do @cmd = 'create_tag' - @namespace = Gitlab::Help.namespace @cmd + @namespace = described_class.namespace @cmd end - it "returns the full namespace for a command" do + + it 'returns the full namespace for a command' do expect(@namespace).to be_a String expect(@namespace).to eq("Gitlab::Client::Tags.#{@cmd}") end diff --git a/spec/gitlab/objectified_hash_spec.rb b/spec/gitlab/objectified_hash_spec.rb index cd162dc..1808a4f 100644 --- a/spec/gitlab/objectified_hash_spec.rb +++ b/spec/gitlab/objectified_hash_spec.rb @@ -1,48 +1,50 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::ObjectifiedHash do before do @hash = { a: 1, b: 2, 'string' => 'string', symbol: :symbol } - @oh = Gitlab::ObjectifiedHash.new @hash + @oh = described_class.new @hash end - it "objectifies a hash" do + it 'objectifies a hash' do expect(@oh.a).to eq(@hash[:a]) expect(@oh.b).to eq(@hash[:b]) end - describe "#to_hash" do - it "returns an original hash" do + describe '#to_hash' do + it 'returns an original hash' do expect(@oh.to_hash).to eq(@hash) end - it "has an alias #to_h" do - expect(@oh.respond_to?(:to_h)).to be_truthy + it 'has an alias #to_h' do + expect(@oh).to respond_to(:to_h) end end - describe "#inspect" do - it "returns a formatted string" do + describe '#inspect' do + it 'returns a formatted string' do pretty_string = "#<#{@oh.class.name}:#{@oh.object_id} {hash: #{@hash}}" expect(@oh.inspect).to eq(pretty_string) end end - describe "#respond_to" do - it "returns true for methods this object responds to through method_missing as sym" do - expect(@oh.respond_to?(:a)).to be_truthy + describe '#respond_to' do + it 'returns true for methods this object responds to through method_missing as sym' do + expect(@oh).to respond_to(:a) end - it "returns true for methods this object responds to through method_missing as string" do - expect(@oh.respond_to?('string')).to be_truthy + it 'returns true for methods this object responds to through method_missing as string' do + expect(@oh).to respond_to('string') end - it "does not care if you use a string or symbol to reference a method" do - expect(@oh.respond_to?(:string)).to be_truthy + it 'does not care if you use a string or symbol to reference a method' do + expect(@oh).to respond_to(:string) end - it "does not care if you use a string or symbol to reference a method" do - expect(@oh.respond_to?('symbol')).to be_truthy + it 'does not care if you use a string or symbol to reference a method' do + expect(@oh).to respond_to('symbol') end end end diff --git a/spec/gitlab/page_links_spec.rb b/spec/gitlab/page_links_spec.rb index 7efa7fd..7ce4c77 100644 --- a/spec/gitlab/page_links_spec.rb +++ b/spec/gitlab/page_links_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::PageLinks do before do - @page_links = Gitlab::PageLinks.new('Link' => "; rel=\"first\", ; rel=\"last\", ; rel=\"prev\", ; rel=\"next\"") + @page_links = described_class.new('Link' => '; rel="first", ; rel="last", ; rel="prev", ; rel="next"') end context '.extract_links' do diff --git a/spec/gitlab/paginated_response_spec.rb b/spec/gitlab/paginated_response_spec.rb index 30a4c73..e91c53b 100644 --- a/spec/gitlab/paginated_response_spec.rb +++ b/spec/gitlab/paginated_response_spec.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::PaginatedResponse do before do array = [1, 2, 3, 4] - @paginated_response = Gitlab::PaginatedResponse.new array + @paginated_response = described_class.new array end - it "responds to *_page and has_*_page methods" do + it 'responds to *_page and has_*_page methods' do expect(@paginated_response).to respond_to :first_page expect(@paginated_response).to respond_to :last_page expect(@paginated_response).to respond_to :next_page @@ -18,14 +20,14 @@ end context '.parse_headers!' do - it "parses headers" do - @paginated_response.parse_headers!('Link' => "; rel=\"first\", ; rel=\"last\"") + it 'parses headers' do + @paginated_response.parse_headers!('Link' => '; rel="first", ; rel="last"') client = @paginated_response.client = double('client') first_page_response = double('first_page_response') last_page_response = double('last_page_response') - allow(client).to receive(:endpoint).and_return("http://example.com/api/v3") - allow(client).to receive(:get).with("/projects?page=1&per_page=5").and_return(first_page_response) - allow(client).to receive(:get).with("/projects?page=20&per_page=5").and_return(last_page_response) + allow(client).to receive(:endpoint).and_return('http://example.com/api/v3') + allow(client).to receive(:get).with('/projects?page=1&per_page=5').and_return(first_page_response) + allow(client).to receive(:get).with('/projects?page=20&per_page=5').and_return(last_page_response) expect(@paginated_response.has_first_page?).to be true expect(@paginated_response.has_last_page?).to be true expect(@paginated_response.has_next_page?).to be false @@ -38,7 +40,7 @@ end context '.each_page' do - it "iterates pages" do + it 'iterates pages' do next_page = double('next_page') allow(@paginated_response).to receive(:has_next_page?).and_return(true) allow(@paginated_response).to receive(:next_page).and_return(next_page) @@ -48,7 +50,7 @@ end context '.auto_paginate' do - it "returns an array if block is not given" do + it 'returns an array if block is not given' do next_page = double('next_page') allow(@paginated_response).to receive(:has_next_page?).and_return(true) allow(@paginated_response).to receive(:next_page).and_return(next_page) diff --git a/spec/gitlab/request_spec.rb b/spec/gitlab/request_spec.rb index ecece7d..a3d45fd 100644 --- a/spec/gitlab/request_spec.rb +++ b/spec/gitlab/request_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Request do @@ -6,12 +8,12 @@ it { is_expected.to respond_to :put } it { is_expected.to respond_to :delete } before do - @request = Gitlab::Request.new + @request = described_class.new end - describe ".default_options" do - it "has default values" do - default_options = Gitlab::Request.default_options + describe '.default_options' do + it 'has default values' do + default_options = described_class.default_options expect(default_options).to be_a Hash expect(default_options[:parser]).to be_a Proc expect(default_options[:format]).to eq(:json) @@ -20,20 +22,20 @@ end end - describe ".parse" do - it "returns ObjectifiedHash" do + describe '.parse' do + it 'returns ObjectifiedHash' do body = JSON.unparse(a: 1, b: 2) - expect(Gitlab::Request.parse(body)).to be_an Gitlab::ObjectifiedHash - expect(Gitlab::Request.parse("true")).to be true - expect(Gitlab::Request.parse("false")).to be false + expect(described_class.parse(body)).to be_an Gitlab::ObjectifiedHash + expect(described_class.parse('true')).to be true + expect(described_class.parse('false')).to be false - expect { Gitlab::Request.parse("string") }.to raise_error(Gitlab::Error::Parsing) + expect { described_class.parse('string') }.to raise_error(Gitlab::Error::Parsing) end end - describe "#request_defaults" do - context "when endpoint is not set" do - it "raises Error::MissingCredentials" do + describe '#request_defaults' do + context 'when endpoint is not set' do + it 'raises Error::MissingCredentials' do @request.endpoint = nil expect do @request.request_defaults @@ -41,33 +43,33 @@ end end - context "when endpoint is set" do - before(:each) do + context 'when endpoint is set' do + before do @request.endpoint = 'http://rabbit-hole.example.com' end - it "sets default_params" do + it 'sets default_params' do @request.request_defaults('sudoer') - expect(Gitlab::Request.default_params).to eq(sudo: 'sudoer') + expect(described_class.default_params).to eq(sudo: 'sudoer') end end end - describe "#authorization_header" do - it "raises MissingCredentials when auth_token and private_token are not set" do + describe '#authorization_header' do + it 'raises MissingCredentials when auth_token and private_token are not set' do expect do @request.send(:authorization_header, {}) end.to raise_error(Gitlab::Error::MissingCredentials) end - it "sets the correct header when given a private_token" do + it 'sets the correct header when given a private_token' do @request.private_token = 'ys9BtunN3rDKbaJCYXaN' - expect(@request.send(:authorization_header, {})).to eq("PRIVATE-TOKEN" => 'ys9BtunN3rDKbaJCYXaN') + expect(@request.send(:authorization_header, {})).to eq('PRIVATE-TOKEN' => 'ys9BtunN3rDKbaJCYXaN') end - it "sets the correct header when setting an auth_token via the private_token config option" do + it 'sets the correct header when setting an auth_token via the private_token config option' do @request.private_token = '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603' - expect(@request.send(:authorization_header, {})).to eq("Authorization" => "Bearer 3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603") + expect(@request.send(:authorization_header, {})).to eq('Authorization' => 'Bearer 3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603') end end end diff --git a/spec/gitlab/shell_history_spec.rb b/spec/gitlab/shell_history_spec.rb index 897f335..e768617 100644 --- a/spec/gitlab/shell_history_spec.rb +++ b/spec/gitlab/shell_history_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'tempfile' @@ -5,7 +7,7 @@ context 'saving to a file' do before do @file = Tempfile.new('.gitlab_shell_history') - @history = Gitlab::Shell::History.new(file_path: @file.path) + @history = described_class.new(file_path: @file.path) end after { @file.close(true) } @@ -14,15 +16,15 @@ @history << 'party on, dudes' @history << 'be excellent to each other' @history.save - expect(File.read @file.path). - to eq("party on, dudes\nbe excellent to each other\n") + expect(File.read(@file.path)) + .to eq("party on, dudes\nbe excellent to each other\n") end it 'has the lines' do @history << 'party on, dudes' @history << 'be excellent to each other' - expect(@history.lines). - to eq(["party on, dudes", "be excellent to each other"]) + expect(@history.lines) + .to eq(['party on, dudes', 'be excellent to each other']) end it 'limits the lines to GITLAB_HISTFILESIZE' do @@ -31,23 +33,23 @@ @history << 'party on, dudes' @history << 'be excellent to each other' @history.save - expect(@history.lines). - to eq(["party on, dudes", "be excellent to each other"]) - expect(File.read @file.path). - to eq("party on, dudes\nbe excellent to each other\n") + expect(@history.lines) + .to eq(['party on, dudes', 'be excellent to each other']) + expect(File.read(@file.path)) + .to eq("party on, dudes\nbe excellent to each other\n") end end context 'loading a file' do before do @file = load_fixture('shell_history') - @history = Gitlab::Shell::History.new(file_path: @file.path) + @history = described_class.new(file_path: @file.path) end it 'has the lines' do @history.load - expect(@history.lines). - to eq(["party on, dudes", "be excellent to each other"]) + expect(@history.lines) + .to eq(['party on, dudes', 'be excellent to each other']) end end end diff --git a/spec/gitlab/shell_spec.rb b/spec/gitlab/shell_spec.rb index 0e2c528..d7decb8 100644 --- a/spec/gitlab/shell_spec.rb +++ b/spec/gitlab/shell_spec.rb @@ -1,79 +1,82 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::Shell do before do - Gitlab::Shell.setup + described_class.setup end - describe ".execute" do - context "invalid command" do - it "raises RuntimeError" do - expect { Gitlab::Shell.execute 'foobar', [] }.to raise_error(RuntimeError) + describe '.execute' do + context 'invalid command' do + it 'raises RuntimeError' do + expect { described_class.execute 'foobar', [] }.to raise_error(RuntimeError) end end end - describe ".history" do + describe '.history' do before do - @history = Gitlab::Shell.history + @history = described_class.history end - it "returns a Gitlab::Shell::History instance" do + it 'returns a Gitlab::Shell::History instance' do expect(@history).to be_a Gitlab::Shell::History end - it "responds to :save" do + it 'responds to :save' do expect(@history).to respond_to :save end - it "responds to :load" do + it 'responds to :load' do expect(@history).to respond_to :load end - it "responds to :<<" do + it 'responds to :<<' do expect(@history).to respond_to :<< end end - describe ".setup" do - it "sets the Readline completion_proc" do + describe '.setup' do + it 'sets the Readline completion_proc' do completion = Readline.completion_proc expect(completion).to be_truthy expect(completion).to be_a Proc end - it "sets the Readline completion_append_character" do + it 'sets the Readline completion_append_character' do completion_character = Readline.completion_append_character expect(completion_character).to eq(' ') end end - describe ".completion" do + describe '.completion' do before do - @comp = Gitlab::Shell.completion + @comp = described_class.completion end - it "returns a Proc object" do + + it 'returns a Proc object' do expect(@comp).to be_a Proc end - context "called with an argument" do - it "returns an Array of matching commands" do + context 'called with an argument' do + it 'returns an Array of matching commands' do completed_cmds = @comp.call 'group' expect(completed_cmds).to be_a Array - 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)) + 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]) end end end - describe ".parse_input" do - context "with arguments" do - it "sets command & arguments" do - Gitlab::Shell.parse_input('create_branch 1 "api" "master"') - expect(Gitlab::Shell.command).to eq('create_branch') - expect(Gitlab::Shell.arguments).to eq(%w(1 api master)) + describe '.parse_input' do + context 'with arguments' do + it 'sets command & arguments' do + described_class.parse_input('create_branch 1 "api" "master"') + expect(described_class.command).to eq('create_branch') + expect(described_class.arguments).to eq(%w[1 api master]) end end - context "without arguments" do + context 'without arguments' do it 'sets command & empty arguments' do - Gitlab::Shell.parse_input('exit') - expect(Gitlab::Shell.command).to eq('exit') - expect(Gitlab::Shell.arguments).to be_empty + described_class.parse_input('exit') + expect(described_class.command).to eq('exit') + expect(described_class.arguments).to be_empty end end end diff --git a/spec/gitlab_spec.rb b/spec/gitlab_spec.rb index 42c867a..6e906c0 100644 --- a/spec/gitlab_spec.rb +++ b/spec/gitlab_spec.rb @@ -1,95 +1,97 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab do - after { Gitlab.reset } + after { described_class.reset } - describe ".client" do - it "is a Gitlab::Client" do - expect(Gitlab.client).to be_a Gitlab::Client + describe '.client' do + it 'is a Gitlab::Client' do + expect(described_class.client).to be_a Gitlab::Client end - it "does not override each other" do - client1 = Gitlab.client(endpoint: 'https://api1.example.com', private_token: '001') - client2 = Gitlab.client(endpoint: 'https://api2.example.com', private_token: '002') + it 'does not override each other' do + client1 = described_class.client(endpoint: 'https://api1.example.com', private_token: '001') + client2 = described_class.client(endpoint: 'https://api2.example.com', private_token: '002') expect(client1.endpoint).to eq('https://api1.example.com') expect(client2.endpoint).to eq('https://api2.example.com') expect(client1.private_token).to eq('001') expect(client2.private_token).to eq('002') end - it "sets private_token to the auth_token when provided" do - client = Gitlab.client(endpoint: 'https://api2.example.com', auth_token: '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603') + it 'sets private_token to the auth_token when provided' do + client = described_class.client(endpoint: 'https://api2.example.com', auth_token: '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603') expect(client.private_token).to eq('3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603') end end - describe ".actions" do - it "returns an array of client methods" do - actions = Gitlab.actions + describe '.actions' do + it 'returns an array of client methods' do + actions = described_class.actions expect(actions).to be_an Array expect(actions.first).to be_a Symbol - expect(actions.sort.first).to eq(:accept_merge_request) + expect(actions.min).to eq(:accept_merge_request) end end - describe ".endpoint=" do - it "sets endpoint" do - Gitlab.endpoint = 'https://api.example.com' - expect(Gitlab.endpoint).to eq('https://api.example.com') + describe '.endpoint=' do + it 'sets endpoint' do + described_class.endpoint = 'https://api.example.com' + expect(described_class.endpoint).to eq('https://api.example.com') end end - describe ".private_token=" do - it "sets private_token" do - Gitlab.private_token = 'secret' - expect(Gitlab.private_token).to eq('secret') + describe '.private_token=' do + it 'sets private_token' do + described_class.private_token = 'secret' + expect(described_class.private_token).to eq('secret') end end - describe ".auth_token=" do - it "sets auth_token", focus: true do - Gitlab.auth_token = 'auth_secret' - expect(Gitlab.private_token).to eq('auth_secret') + describe '.auth_token=' do + it 'sets auth_token', focus: true do + described_class.auth_token = 'auth_secret' + expect(described_class.private_token).to eq('auth_secret') end end - describe ".sudo=" do - it "sets sudo" do - Gitlab.sudo = 'user' - expect(Gitlab.sudo).to eq('user') + describe '.sudo=' do + it 'sets sudo' do + described_class.sudo = 'user' + expect(described_class.sudo).to eq('user') end end - describe ".user_agent" do - it "returns default user_agent" do - expect(Gitlab.user_agent).to eq(Gitlab::Configuration::DEFAULT_USER_AGENT) + describe '.user_agent' do + it 'returns default user_agent' do + expect(described_class.user_agent).to eq(Gitlab::Configuration::DEFAULT_USER_AGENT) end end - describe ".user_agent=" do - it "sets user_agent" do - Gitlab.user_agent = 'Custom User Agent' - expect(Gitlab.user_agent).to eq('Custom User Agent') + describe '.user_agent=' do + it 'sets user_agent' do + described_class.user_agent = 'Custom User Agent' + expect(described_class.user_agent).to eq('Custom User Agent') end end - describe ".configure" do + describe '.configure' do Gitlab::Configuration::VALID_OPTIONS_KEYS.each do |key| it "sets #{key}" do - Gitlab.configure do |config| + described_class.configure do |config| config.send("#{key}=", key) - expect(Gitlab.send(key)).to eq(key) + expect(described_class.send(key)).to eq(key) end end end end - describe ".http_proxy" do - it "delegates the method to Gitlab::Request" do - Gitlab.endpoint = 'https://api.example.com' + describe '.http_proxy' do + it 'delegates the method to Gitlab::Request' do + described_class.endpoint = 'https://api.example.com' request = class_spy(Gitlab::Request).as_stubbed_const - Gitlab.http_proxy('proxy.example.net', 1987, 'user', 'pass') + described_class.http_proxy('proxy.example.net', 1987, 'user', 'pass') expect(request).to have_received(:http_proxy).with('proxy.example.net', 1987, 'user', 'pass') end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2b9640e..7591dd7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'rspec' require 'webmock/rspec' -require File.expand_path('../../lib/gitlab', __FILE__) -require File.expand_path('../../lib/gitlab/cli', __FILE__) +require File.expand_path('../lib/gitlab', __dir__) +require File.expand_path('../lib/gitlab/cli', __dir__) def capture_output out = StringIO.new @@ -25,8 +27,8 @@ end end -%i(get post put delete).each do |method| - define_method "stub_#{method}" do |path, fixture, status_code=200| +%i[get post put delete].each do |method| + define_method "stub_#{method}" do |path, fixture, status_code = 200| stub_request(method, "#{Gitlab.endpoint}#{path}") .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }) .to_return(body: load_fixture(fixture), status: status_code)