summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-02-24 09:23:19 +0100
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-03-03 10:29:37 +0100
commitb795e3a069ec3d6fdfb5fc5942310166de349cd9 (patch)
treebea0b9710e628ab1e26fc48fcf6204869592a716
parent93ed053359f7ece17c97f7c3d15f79821159a522 (diff)
downloadgitlab-ce-zj-api-rename-v2.tar.gz
Update tests to passzj-api-rename-v2
-rw-r--r--db/schema.rb2
-rw-r--r--lib/api/api.rb2
-rw-r--r--lib/api/merge_requests.rb2
-rw-r--r--lib/api/projects.rb1
-rw-r--r--lib/api/v3/builds.rb40
-rw-r--r--lib/api/v3/deployments.rb58
-rw-r--r--lib/api/v3/entities.rb96
-rw-r--r--lib/api/v3/groups.rb28
-rw-r--r--lib/api/v3/merge_request_diffs.rb74
-rw-r--r--lib/api/v3/merge_requests.rb7
-rw-r--r--lib/api/v3/notes.rb48
-rw-r--r--lib/api/v3/project_hooks.rb164
-rw-r--r--lib/api/v3/projects.rb1
-rw-r--r--lib/api/v3/services.rb59
-rw-r--r--spec/requests/api/groups_spec.rb2
-rw-r--r--spec/requests/api/merge_requests_spec.rb2
-rw-r--r--spec/requests/api/project_hooks_spec.rb9
-rw-r--r--spec/requests/api/projects_spec.rb7
-rw-r--r--spec/requests/api/v3/deployments_spec.rb14
-rw-r--r--spec/requests/api/v3/merge_request_diffs_spec.rb12
-rw-r--r--spec/requests/api/v3/merge_requests_spec.rb2
-rw-r--r--spec/requests/api/v3/notes_spec.rb64
-rw-r--r--spec/requests/api/v3/project_hooks_spec.rb42
23 files changed, 395 insertions, 341 deletions
diff --git a/db/schema.rb b/db/schema.rb
index cd5aa339269..eb30f720683 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -581,9 +581,9 @@ ActiveRecord::Schema.define(version: 20170217151947) do
end
add_index "labels", ["group_id", "project_id", "title"], name: "index_labels_on_group_id_and_project_id_and_title", unique: true, using: :btree
- add_index "labels", ["type", "project_id"], name: "index_labels_on_type_and_project_id", using: :btree
add_index "labels", ["project_id"], name: "index_labels_on_project_id", using: :btree
add_index "labels", ["title"], name: "index_labels_on_title", using: :btree
+ add_index "labels", ["type", "project_id"], name: "index_labels_on_type_and_project_id", using: :btree
create_table "lfs_objects", force: :cascade do |t|
t.string "oid", null: false
diff --git a/lib/api/api.rb b/lib/api/api.rb
index af92ff9de4c..0b888cf8589 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -12,11 +12,13 @@ module API
mount ::API::V3::Builds
mount ::API::V3::Commits
mount ::API::V3::DeployKeys
+ mount ::API::V3::Deployments
mount ::API::V3::Environments
mount ::API::V3::Files
mount ::API::V3::Groups
mount ::API::V3::Issues
mount ::API::V3::Labels
+ mount ::API::V3::Groups
mount ::API::V3::Members
mount ::API::V3::MergeRequestDiffs
mount ::API::V3::MergeRequests
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 4638a66811d..5819fa05d2c 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -169,7 +169,7 @@ module API
optional :should_remove_source_branch, type: Boolean,
desc: 'When true, the source branch will be deleted if possible'
optional :merge_when_pipeline_succeeds, type: Boolean,
- desc: 'When true, this merge request will be merged when the pipeline succeeds'
+ desc: 'When true, this merge request will be merged when the pipeline succeeds'
optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch'
end
put ':id/merge_requests/:merge_request_id/merge' do
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index f302496c12b..ace3067d3d2 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -98,6 +98,7 @@ module API
end
post do
attrs = declared_params(include_missing: false)
+
project = ::Projects::CreateService.new(current_user, attrs).execute
if project.saved?
diff --git a/lib/api/v3/builds.rb b/lib/api/v3/builds.rb
index 33f9cfa6927..f467fabe8e1 100644
--- a/lib/api/v3/builds.rb
+++ b/lib/api/v3/builds.rb
@@ -12,21 +12,21 @@ module API
helpers do
params :optional_scope do
optional :scope, types: [String, Array[String]], desc: 'The scope of builds to show',
- values: ['pending', 'running', 'failed', 'success', 'canceled'],
- coerce_with: ->(scope) {
- if scope.is_a?(String)
- [scope]
- elsif scope.is_a?(Hashie::Mash)
- scope.values
- else
- ['unknown']
- end
- }
+ values: ['pending', 'running', 'failed', 'success', 'canceled'],
+ coerce_with: ->(scope) {
+ if scope.is_a?(String)
+ [scope]
+ elsif scope.is_a?(Hashie::Mash)
+ scope.values
+ else
+ ['unknown']
+ end
+ }
end
end
desc 'Get a project builds' do
- success V3::Entities::Build
+ success ::API::V3::Entities::Build
end
params do
use :optional_scope
@@ -36,8 +36,8 @@ module API
builds = user_project.builds.order('id DESC')
builds = filter_builds(builds, params[:scope])
- present paginate(builds), with: Entities::Build,
- user_can_download_artifacts: can?(current_user, :read_build, user_project)
+ present paginate(builds), with: ::API::V3::Entities::Build,
+ user_can_download_artifacts: can?(current_user, :read_build, user_project)
end
desc 'Get builds for a specific commit of a project' do
@@ -58,7 +58,7 @@ module API
builds = filter_builds(builds, params[:scope])
present paginate(builds), with: Entities::Build,
- user_can_download_artifacts: can?(current_user, :read_build, user_project)
+ user_can_download_artifacts: can?(current_user, :read_build, user_project)
end
desc 'Get a specific build of a project' do
@@ -73,7 +73,7 @@ module API
build = get_build!(params[:build_id])
present build, with: Entities::Build,
- user_can_download_artifacts: can?(current_user, :read_build, user_project)
+ user_can_download_artifacts: can?(current_user, :read_build, user_project)
end
desc 'Download the artifacts file from build' do
@@ -141,7 +141,7 @@ module API
build.cancel
present build, with: Entities::Build,
- user_can_download_artifacts: can?(current_user, :read_build, user_project)
+ user_can_download_artifacts: can?(current_user, :read_build, user_project)
end
desc 'Retry a specific build of a project' do
@@ -159,7 +159,7 @@ module API
build = Ci::Build.retry(build, current_user)
present build, with: Entities::Build,
- user_can_download_artifacts: can?(current_user, :read_build, user_project)
+ user_can_download_artifacts: can?(current_user, :read_build, user_project)
end
desc 'Erase build (remove artifacts and build trace)' do
@@ -176,7 +176,7 @@ module API
build.erase(erased_by: current_user)
present build, with: Entities::Build,
- user_can_download_artifacts: can?(current_user, :download_build_artifacts, user_project)
+ user_can_download_artifacts: can?(current_user, :download_build_artifacts, user_project)
end
desc 'Keep the artifacts to prevent them from being deleted' do
@@ -195,7 +195,7 @@ module API
status 200
present build, with: Entities::Build,
- user_can_download_artifacts: can?(current_user, :read_build, user_project)
+ user_can_download_artifacts: can?(current_user, :read_build, user_project)
end
desc 'Trigger a manual build' do
@@ -216,7 +216,7 @@ module API
status 200
present build, with: Entities::Build,
- user_can_download_artifacts: can?(current_user, :read_build, user_project)
+ user_can_download_artifacts: can?(current_user, :read_build, user_project)
end
end
diff --git a/lib/api/v3/deployments.rb b/lib/api/v3/deployments.rb
index c5feb49b22f..81673ae8814 100644
--- a/lib/api/v3/deployments.rb
+++ b/lib/api/v3/deployments.rb
@@ -1,40 +1,42 @@
module API
- # Deployments RESTfull API endpoints
- class Deployments < Grape::API
- include PaginationParams
+ module V3
+ # Deployments RESTfull API endpoints
+ class Deployments < Grape::API
+ include PaginationParams
- before { authenticate! }
+ before { authenticate! }
- params do
- requires :id, type: String, desc: 'The project ID'
- end
- resource :projects do
- desc 'Get all deployments of the project' do
- detail 'This feature was introduced in GitLab 8.11.'
- success Entities::Deployment
- end
params do
- use :pagination
+ requires :id, type: String, desc: 'The project ID'
end
- get ':id/deployments' do
- authorize! :read_deployment, user_project
+ resource :projects do
+ desc 'Get all deployments of the project' do
+ detail 'This feature was introduced in GitLab 8.11.'
+ success Entities::Deployment
+ end
+ params do
+ use :pagination
+ end
+ get ':id/deployments' do
+ authorize! :read_deployment, user_project
- present paginate(user_project.deployments), with: Entities::Deployment
- end
+ present paginate(user_project.deployments), with: Entities::Deployment
+ end
- desc 'Gets a specific deployment' do
- detail 'This feature was introduced in GitLab 8.11.'
- success Entities::Deployment
- end
- params do
- requires :deployment_id, type: Integer, desc: 'The deployment ID'
- end
- get ':id/deployments/:deployment_id' do
- authorize! :read_deployment, user_project
+ desc 'Gets a specific deployment' do
+ detail 'This feature was introduced in GitLab 8.11.'
+ success Entities::Deployment
+ end
+ params do
+ requires :deployment_id, type: Integer, desc: 'The deployment ID'
+ end
+ get ':id/deployments/:deployment_id' do
+ authorize! :read_deployment, user_project
- deployment = user_project.deployments.find(params[:deployment_id])
+ deployment = user_project.deployments.find(params[:deployment_id])
- present deployment, with: Entities::Deployment
+ present deployment, with: Entities::Deployment
+ end
end
end
end
diff --git a/lib/api/v3/entities.rb b/lib/api/v3/entities.rb
index 4c5dbebf150..b488e850093 100644
--- a/lib/api/v3/entities.rb
+++ b/lib/api/v3/entities.rb
@@ -191,12 +191,47 @@ module API
expose :id, :status, :stage, :name, :ref, :tag, :coverage
expose :created_at, :started_at, :finished_at
expose :user, with: ::API::Entities::User
- expose :artifacts_file, using: ::API::Entities::JobArtifactFile, if: -> (build, opts) { build.artifacts? }
+ expose :artifacts_file, using: ::API::Entities::JobArtifactFile, if: -> (build, _opts) { build.artifacts? }
expose :commit, with: ::API::Entities::RepoCommit
expose :runner, with: ::API::Entities::Runner
expose :pipeline, with: ::API::Entities::PipelineBasic
end
+ class Project < Grape::Entity
+ expose :id, :description, :default_branch, :tag_list
+ expose :public?, as: :public
+ expose :archived?, as: :archived
+ expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url
+ expose :owner, using: ::API::Entities::UserBasic, unless: ->(project, options) { project.group }
+ expose :name, :name_with_namespace
+ expose :path, :path_with_namespace
+ expose :container_registry_enabled
+ # Expose old field names with the new permissions methods to keep API compatible
+ expose(:issues_enabled) { |project, options| project.feature_available?(:issues, options[:current_user]) }
+ expose(:merge_requests_enabled) { |project, options| project.feature_available?(:merge_requests, options[:current_user]) }
+ expose(:wiki_enabled) { |project, options| project.feature_available?(:wiki, options[:current_user]) }
+ expose(:builds_enabled) { |project, options| project.feature_available?(:builds, options[:current_user]) }
+ expose(:snippets_enabled) { |project, options| project.feature_available?(:snippets, options[:current_user]) }
+ expose :created_at, :last_activity_at
+ expose :shared_runners_enabled
+ expose :lfs_enabled?, as: :lfs_enabled
+ expose :creator_id
+ expose :namespace, using: ::API::Entities::Namespace
+ expose :forked_from_project, using: ::API::Entities::BasicProjectDetails, if: lambda{ |project, _options| project.forked? }
+ expose :avatar_url
+ expose :star_count, :forks_count
+ expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) && project.default_issues_tracker? }
+ expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
+ expose :public_builds
+ expose :shared_with_groups do |project, options|
+ ::API::Entities::SharedGroup.represent(project.project_group_links.all, options)
+ end
+ expose :only_allow_merge_if_build_succeeds
+ expose :request_access_enabled
+ expose :only_allow_merge_if_all_discussions_are_resolved
+ expose :statistics, using: ::API::V3::Entities::ProjectStatistics, if: :statistics
+ end
+
class BuildArtifactFile < Grape::Entity
expose :filename, :size
end
@@ -206,14 +241,14 @@ module API
end
class Environment < EnvironmentBasic
- expose :project, using: Entities::Project
+ expose :project, using: ::API::V3::Entities::Project
end
class Deployment < Grape::Entity
expose :id, :iid, :ref, :sha, :created_at
- expose :user, using: Entities::UserBasic
- expose :environment, using: Entities::EnvironmentBasic
- expose :deployable, using: Entities::Build
+ expose :user, using: ::API::Entities::UserBasic
+ expose :environment, using: V3::Entities::EnvironmentBasic
+ expose :deployable, using: V3::Entities::Build
end
class Group < Grape::Entity
@@ -237,14 +272,14 @@ module API
expose :shared_projects, using: Entities::Project
end
- class MergeRequest < ProjectEntity
+ class MergeRequest < ::API::Entities::ProjectEntity
expose :target_branch, :source_branch
expose :upvotes, :downvotes
- expose :author, :assignee, using: Entities::UserBasic
+ expose :author, :assignee, using: ::API::Entities::UserBasic
expose :source_project_id, :target_project_id
expose :label_names, as: :labels
expose :work_in_progress?, as: :work_in_progress
- expose :milestone, using: Entities::Milestone
+ expose :milestone, using: ::API::Entities::Milestone
expose :merge_when_build_succeeds
expose :merge_status
expose :diff_head_sha, as: :sha
@@ -261,46 +296,11 @@ module API
end
class MergeRequestChanges < MergeRequest
- expose :diffs, as: :changes, using: Entities::RepoDiff do |compare, _|
+ expose :diffs, as: :changes, using: ::API::Entities::RepoDiff do |compare, _|
compare.raw_diffs(all_diffs: true).to_a
end
end
- class Project < Grape::Entity
- expose :id, :description, :default_branch, :tag_list
- expose :public?, as: :public
- expose :archived?, as: :archived
- expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url
- expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
- expose :name, :name_with_namespace
- expose :path, :path_with_namespace
- expose :container_registry_enabled
- # Expose old field names with the new permissions methods to keep API compatible
- expose(:issues_enabled) { |project, options| project.feature_available?(:issues, options[:current_user]) }
- expose(:merge_requests_enabled) { |project, options| project.feature_available?(:merge_requests, options[:current_user]) }
- expose(:wiki_enabled) { |project, options| project.feature_available?(:wiki, options[:current_user]) }
- expose(:builds_enabled) { |project, options| project.feature_available?(:builds, options[:current_user]) }
- expose(:snippets_enabled) { |project, options| project.feature_available?(:snippets, options[:current_user]) }
- expose :created_at, :last_activity_at
- expose :shared_runners_enabled
- expose :lfs_enabled?, as: :lfs_enabled
- expose :creator_id
- expose :namespace, using: 'API::Entities::Namespace'
- expose :forked_from_project, using: Entities::BasicProjectDetails, if: lambda{ |project, options| project.forked? }
- expose :avatar_url
- expose :star_count, :forks_count
- expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) && project.default_issues_tracker? }
- expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
- expose :public_builds
- expose :shared_with_groups do |project, options|
- SharedGroup.represent(project.project_group_links.all, options)
- end
- expose :only_allow_merge_if_build_succeeds
- expose :request_access_enabled
- expose :only_allow_merge_if_all_discussions_are_resolved
- expose :statistics, using: 'API::Entities::ProjectStatistics', if: :statistics
- end
-
class ProjectStatistics < Grape::Entity
expose :commit_count
expose :storage_size
@@ -322,17 +322,17 @@ module API
end
end
- class ProjectHook < Hook
+ class ProjectHook < ::API::Entities::Hook
expose :project_id, :issues_events, :merge_requests_events
expose :note_events, :build_events, :pipeline_events, :wiki_page_events
end
- class ProjectWithAccess < Project
+ class ProjectWithAccess < V3::Entities::Project
expose :permissions do
- expose :project_access, using: Entities::ProjectAccess do |project, options|
+ expose :project_access, using: ::API::Entities::ProjectAccess do |project, options|
project.project_members.find_by(user_id: options[:current_user].id)
end
- expose :group_access, using: Entities::GroupAccess do |project, options|
+ expose :group_access, using: ::API::Entities::GroupAccess do |project, options|
if project.group
project.group.group_members.find_by(user_id: options[:current_user].id)
end
diff --git a/lib/api/v3/groups.rb b/lib/api/v3/groups.rb
index 0aad87a3f58..2a79ae6f6c3 100644
--- a/lib/api/v3/groups.rb
+++ b/lib/api/v3/groups.rb
@@ -19,7 +19,7 @@ module API
def present_groups(groups, options = {})
options = options.reverse_merge(
- with: Entities::Group,
+ with: ::API::V3::Entities::Group,
current_user: current_user,
)
@@ -30,7 +30,7 @@ module API
resource :groups do
desc 'Get a groups list' do
- success Entities::Group
+ success ::API::V3::Entities::Group
end
params do
use :statistics_params
@@ -58,7 +58,7 @@ module API
end
desc 'Get list of owned groups for authenticated user' do
- success Entities::Group
+ success ::API::V3::Entities::Group
end
params do
use :pagination
@@ -69,7 +69,7 @@ module API
end
desc 'Create a group. Available only for users who can create groups.' do
- success Entities::Group
+ success ::API::V3::Entities::Group
end
params do
requires :name, type: String, desc: 'The name of the group'
@@ -83,7 +83,7 @@ module API
group = ::Groups::CreateService.new(current_user, declared_params(include_missing: false)).execute
if group.persisted?
- present group, with: Entities::Group, current_user: current_user
+ present group, with: ::API::V3::Entities::Group, current_user: current_user
else
render_api_error!("Failed to save group #{group.errors.messages}", 400)
end
@@ -95,7 +95,7 @@ module API
end
resource :groups do
desc 'Update a group. Available only for users who can administrate groups.' do
- success Entities::Group
+ success ::API::V3::Entities::Group
end
params do
optional :name, type: String, desc: 'The name of the group'
@@ -109,29 +109,29 @@ module API
authorize! :admin_group, group
if ::Groups::UpdateService.new(group, current_user, declared_params(include_missing: false)).execute
- present group, with: Entities::GroupDetail, current_user: current_user
+ present group, with: ::API::V3::Entities::GroupDetail, current_user: current_user
else
render_validation_error!(group)
end
end
desc 'Get a single group, with containing projects.' do
- success Entities::GroupDetail
+ success ::API::V3::Entities::GroupDetail
end
get ":id" do
group = find_group!(params[:id])
- present group, with: Entities::GroupDetail, current_user: current_user
+ present group, with: ::API::V3::Entities::GroupDetail, current_user: current_user
end
desc 'Remove a group.'
delete ":id" do
group = find_group!(params[:id])
authorize! :admin_group, group
- present ::Groups::DestroyService.new(group, current_user).execute, with: Entities::GroupDetail, current_user: current_user
+ present ::Groups::DestroyService.new(group, current_user).execute, with: ::API::V3::Entities::GroupDetail, current_user: current_user
end
desc 'Get a list of projects in this group.' do
- success Entities::Project
+ success V3::Entities::Project
end
params do
optional :archived, type: Boolean, default: false, desc: 'Limit by archived status'
@@ -153,12 +153,12 @@ module API
group = find_group!(params[:id])
projects = GroupProjectsFinder.new(group).execute(current_user)
projects = filter_projects(projects)
- entity = params[:simple] ? ::API::Entities::BasicProjectDetails : Entities::Project
+ entity = params[:simple] ? ::API::Entities::BasicProjectDetails : ::API::V3::Entities::Project
present paginate(projects), with: entity, current_user: current_user
end
desc 'Transfer a project to the group namespace. Available only for admin.' do
- success Entities::GroupDetail
+ success ::API::V3::Entities::GroupDetail
end
params do
requires :project_id, type: String, desc: 'The ID or path of the project'
@@ -170,7 +170,7 @@ module API
result = ::Projects::TransferService.new(project, current_user).execute(group)
if result
- present group, with: Entities::GroupDetail, current_user: current_user
+ present group, with: ::API::V3::Entities::GroupDetail, current_user: current_user
else
render_api_error!("Failed to transfer project #{project.errors.messages}", 400)
end
diff --git a/lib/api/v3/merge_request_diffs.rb b/lib/api/v3/merge_request_diffs.rb
index bc3d69f6904..a462803e26c 100644
--- a/lib/api/v3/merge_request_diffs.rb
+++ b/lib/api/v3/merge_request_diffs.rb
@@ -1,40 +1,42 @@
module API
- # MergeRequestDiff API
- class MergeRequestDiffs < Grape::API
- before { authenticate! }
-
- resource :projects do
- desc 'Get a list of merge request diff versions' do
- detail 'This feature was introduced in GitLab 8.12.'
- success Entities::MergeRequestDiff
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
- end
-
- get ":id/merge_requests/:merge_request_id/versions" do
- merge_request = find_merge_request_with_access(params[:merge_request_id])
-
- present merge_request.merge_request_diffs, with: Entities::MergeRequestDiff
- end
-
- desc 'Get a single merge request diff version' do
- detail 'This feature was introduced in GitLab 8.12.'
- success Entities::MergeRequestDiffFull
- end
-
- params do
- requires :id, type: String, desc: 'The ID of a project'
- requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
- requires :version_id, type: Integer, desc: 'The ID of a merge request diff version'
- end
-
- get ":id/merge_requests/:merge_request_id/versions/:version_id" do
- merge_request = find_merge_request_with_access(params[:merge_request_id])
-
- present merge_request.merge_request_diffs.find(params[:version_id]), with: Entities::MergeRequestDiffFull
+ module V3
+ # MergeRequestDiff API
+ class MergeRequestDiffs < Grape::API
+ before { authenticate! }
+
+ resource :projects do
+ desc 'Get a list of merge request diff versions' do
+ detail 'This feature was introduced in GitLab 8.12.'
+ success ::API::Entities::MergeRequestDiff
+ end
+
+ params do
+ requires :id, type: String, desc: 'The ID of a project'
+ requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
+ end
+
+ get ":id/merge_requests/:merge_request_id/versions" do
+ merge_request = find_merge_request_with_access(params[:merge_request_id])
+
+ present merge_request.merge_request_diffs, with: ::API::Entities::MergeRequestDiff
+ end
+
+ desc 'Get a single merge request diff version' do
+ detail 'This feature was introduced in GitLab 8.12.'
+ success ::API::Entities::MergeRequestDiffFull
+ end
+
+ params do
+ requires :id, type: String, desc: 'The ID of a project'
+ requires :merge_request_id, type: Integer, desc: 'The ID of a merge request'
+ requires :version_id, type: Integer, desc: 'The ID of a merge request diff version'
+ end
+
+ get ":id/merge_requests/:merge_request_id/versions/:version_id" do
+ merge_request = find_merge_request_with_access(params[:merge_request_id])
+
+ present merge_request.merge_request_diffs.find(params[:version_id]), with: ::API::Entities::MergeRequestDiffFull
+ end
end
end
end
diff --git a/lib/api/v3/merge_requests.rb b/lib/api/v3/merge_requests.rb
index 654e818e1b5..7142376303c 100644
--- a/lib/api/v3/merge_requests.rb
+++ b/lib/api/v3/merge_requests.rb
@@ -134,12 +134,12 @@ module API
end
desc 'Show the merge request changes' do
- success ::API::Entities::MergeRequestChanges
+ success ::API::V3::Entities::MergeRequestChanges
end
get "#{path}/changes" do
merge_request = find_merge_request_with_access(params[:merge_request_id])
- present merge_request, with: ::API::Entities::MergeRequestChanges, current_user: current_user
+ present merge_request, with: ::API::V3::Entities::MergeRequestChanges, current_user: current_user
end
desc 'Update a merge request' do
@@ -160,6 +160,7 @@ module API
mr_params = declared_params(include_missing: false)
mr_params[:force_remove_source_branch] = mr_params.delete(:remove_source_branch) if mr_params[:remove_source_branch].present?
+ mr_params[:merge_when_pipeline_succeeds] = mr_params.delete(:merge_when_build_succeeds) if mr_params[:merge_when_build_succeeds].present?
merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, mr_params).execute(merge_request)
@@ -214,7 +215,7 @@ module API
present merge_request, with: ::API::V3::Entities::MergeRequest, current_user: current_user, project: user_project
end
- desc 'Cancel merge if "Merge When Build succeeds" is enabled' do
+ desc 'Cancel merge if "Merge When Pipeline Succeeds" is enabled' do
success ::API::V3::Entities::MergeRequest
end
post "#{path}/cancel_merge_when_build_succeeds" do
diff --git a/lib/api/v3/notes.rb b/lib/api/v3/notes.rb
index 0796bb62e68..a3bb2d86e3a 100644
--- a/lib/api/v3/notes.rb
+++ b/lib/api/v3/notes.rb
@@ -5,7 +5,11 @@ module API
before { authenticate! }
+<<<<<<< HEAD
NOTEABLE_TYPES = [Issue, MergeRequest, Snippet].freeze
+=======
+ NOTEABLE_TYPES = [Issue, MergeRequest, Snippet]
+>>>>>>> 629355a06c... WIP
params do
requires :id, type: String, desc: 'The ID of a project'
@@ -15,7 +19,11 @@ module API
noteables_str = noteable_type.to_s.underscore.pluralize
desc 'Get a list of project +noteable+ notes' do
+<<<<<<< HEAD
success ::API::V3::Entities::Note
+=======
+ success ::API::Entities::Note
+>>>>>>> 629355a06c... WIP
end
params do
requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
@@ -36,14 +44,22 @@ module API
# array returned, but this is really a edge-case.
paginate(noteable.notes).
reject { |n| n.cross_reference_not_visible_for?(current_user) }
+<<<<<<< HEAD
present notes, with: ::API::V3::Entities::Note
+=======
+ present notes, with: ::API::Entities::Note
+>>>>>>> 629355a06c... WIP
else
not_found!("Notes")
end
end
desc 'Get a single +noteable+ note' do
+<<<<<<< HEAD
success ::API::V3::Entities::Note
+=======
+ success ::API::Entities::Note
+>>>>>>> 629355a06c... WIP
end
params do
requires :note_id, type: Integer, desc: 'The ID of a note'
@@ -55,14 +71,22 @@ module API
can_read_note = can?(current_user, noteable_read_ability_name(noteable), noteable) && !note.cross_reference_not_visible_for?(current_user)
if can_read_note
+<<<<<<< HEAD
present note, with: ::API::V3::Entities::Note
+=======
+ present note, with: ::API::Entities::Note
+>>>>>>> 629355a06c... WIP
else
not_found!("Note")
end
end
desc 'Create a new +noteable+ note' do
+<<<<<<< HEAD
success ::API::V3::Entities::Note
+=======
+ success ::API::Entities::Note
+>>>>>>> 629355a06c... WIP
end
params do
requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
@@ -84,8 +108,14 @@ module API
end
note = ::Notes::CreateService.new(user_project, current_user, opts).execute
+<<<<<<< HEAD
if note.valid?
present note, with: ::API::V3::Entities.const_get(note.class.name)
+=======
+
+ if note.valid?
+ present note, with: Entities::const_get(note.class.name)
+>>>>>>> 629355a06c... WIP
else
not_found!("Note #{note.errors.messages}")
end
@@ -95,7 +125,11 @@ module API
end
desc 'Update an existing +noteable+ note' do
+<<<<<<< HEAD
success ::API::V3::Entities::Note
+=======
+ success ::API::Entities::Note
+>>>>>>> 629355a06c... WIP
end
params do
requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
@@ -114,14 +148,22 @@ module API
note = ::Notes::UpdateService.new(user_project, current_user, opts).execute(note)
if note.valid?
+<<<<<<< HEAD
present note, with: ::API::V3::Entities::Note
+=======
+ present note, with: ::API::Entities::Note
+>>>>>>> 629355a06c... WIP
else
render_api_error!("Failed to save note #{note.errors.messages}", 400)
end
end
desc 'Delete a +noteable+ note' do
+<<<<<<< HEAD
success ::API::V3::Entities::Note
+=======
+ success ::API::Entities::Note
+>>>>>>> 629355a06c... WIP
end
params do
requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
@@ -131,9 +173,15 @@ module API
note = user_project.notes.find(params[:note_id])
authorize! :admin_note, note
+<<<<<<< HEAD
::Notes::DestroyService.new(user_project, current_user).execute(note)
present note, with: ::API::V3::Entities::Note
+=======
+ ::Notes::DeleteService.new(user_project, current_user).execute(note)
+
+ present note, with: ::API::Entities::Note
+>>>>>>> 629355a06c... WIP
end
end
end
diff --git a/lib/api/v3/project_hooks.rb b/lib/api/v3/project_hooks.rb
index cb679e6658a..861b991b8e1 100644
--- a/lib/api/v3/project_hooks.rb
+++ b/lib/api/v3/project_hooks.rb
@@ -1,102 +1,104 @@
module API
- class ProjectHooks < Grape::API
- include PaginationParams
+ module V3
+ class ProjectHooks < Grape::API
+ include PaginationParams
- before { authenticate! }
- before { authorize_admin_project }
+ before { authenticate! }
+ before { authorize_admin_project }
- helpers do
- params :project_hook_properties do
- requires :url, type: String, desc: "The URL to send the request to"
- optional :push_events, type: Boolean, desc: "Trigger hook on push events"
- optional :issues_events, type: Boolean, desc: "Trigger hook on issues events"
- optional :merge_requests_events, type: Boolean, desc: "Trigger hook on merge request events"
- optional :tag_push_events, type: Boolean, desc: "Trigger hook on tag push events"
- optional :note_events, type: Boolean, desc: "Trigger hook on note(comment) events"
- optional :build_events, type: Boolean, desc: "Trigger hook on build events"
- optional :pipeline_events, type: Boolean, desc: "Trigger hook on pipeline events"
- optional :wiki_page_events, type: Boolean, desc: "Trigger hook on wiki events"
- optional :enable_ssl_verification, type: Boolean, desc: "Do SSL verification when triggering the hook"
- optional :token, type: String, desc: "Secret token to validate received payloads; this will not be returned in the response"
+ helpers do
+ params :project_hook_properties do
+ requires :url, type: String, desc: "The URL to send the request to"
+ optional :push_events, type: Boolean, desc: "Trigger hook on push events"
+ optional :issues_events, type: Boolean, desc: "Trigger hook on issues events"
+ optional :merge_requests_events, type: Boolean, desc: "Trigger hook on merge request events"
+ optional :tag_push_events, type: Boolean, desc: "Trigger hook on tag push events"
+ optional :note_events, type: Boolean, desc: "Trigger hook on note(comment) events"
+ optional :build_events, type: Boolean, desc: "Trigger hook on build events"
+ optional :pipeline_events, type: Boolean, desc: "Trigger hook on pipeline events"
+ optional :wiki_page_events, type: Boolean, desc: "Trigger hook on wiki events"
+ optional :enable_ssl_verification, type: Boolean, desc: "Do SSL verification when triggering the hook"
+ optional :token, type: String, desc: "Secret token to validate received payloads; this will not be returned in the response"
+ end
end
- end
- params do
- requires :id, type: String, desc: 'The ID of a project'
- end
- resource :projects do
- desc 'Get project hooks' do
- success Entities::ProjectHook
- end
params do
- use :pagination
+ requires :id, type: String, desc: 'The ID of a project'
end
- get ":id/hooks" do
- hooks = paginate user_project.hooks
+ resource :projects do
+ desc 'Get project hooks' do
+ success ::API::V3::Entities::ProjectHook
+ end
+ params do
+ use :pagination
+ end
+ get ":id/hooks" do
+ hooks = paginate user_project.hooks
- present hooks, with: Entities::ProjectHook
- end
+ present hooks, with: ::API::V3::Entities::ProjectHook
+ end
- desc 'Get a project hook' do
- success Entities::ProjectHook
- end
- params do
- requires :hook_id, type: Integer, desc: 'The ID of a project hook'
- end
- get ":id/hooks/:hook_id" do
- hook = user_project.hooks.find(params[:hook_id])
- present hook, with: Entities::ProjectHook
- end
+ desc 'Get a project hook' do
+ success ::API::V3::Entities::ProjectHook
+ end
+ params do
+ requires :hook_id, type: Integer, desc: 'The ID of a project hook'
+ end
+ get ":id/hooks/:hook_id" do
+ hook = user_project.hooks.find(params[:hook_id])
+ present hook, with: ::API::V3::Entities::ProjectHook
+ end
- desc 'Add hook to project' do
- success Entities::ProjectHook
- end
- params do
- use :project_hook_properties
- end
- post ":id/hooks" do
- hook = user_project.hooks.new(declared_params(include_missing: false))
+ desc 'Add hook to project' do
+ success ::API::V3::Entities::ProjectHook
+ end
+ params do
+ use :project_hook_properties
+ end
+ post ":id/hooks" do
+ hook = user_project.hooks.new(declared_params(include_missing: false))
- if hook.save
- present hook, with: Entities::ProjectHook
- else
- error!("Invalid url given", 422) if hook.errors[:url].present?
+ if hook.save
+ present hook, with: ::API::V3::Entities::ProjectHook
+ else
+ error!("Invalid url given", 422) if hook.errors[:url].present?
- not_found!("Project hook #{hook.errors.messages}")
+ not_found!("Project hook #{hook.errors.messages}")
+ end
end
- end
- desc 'Update an existing project hook' do
- success Entities::ProjectHook
- end
- params do
- requires :hook_id, type: Integer, desc: "The ID of the hook to update"
- use :project_hook_properties
- end
- put ":id/hooks/:hook_id" do
- hook = user_project.hooks.find(params.delete(:hook_id))
+ desc 'Update an existing project hook' do
+ success ::API::V3::Entities::ProjectHook
+ end
+ params do
+ requires :hook_id, type: Integer, desc: "The ID of the hook to update"
+ use :project_hook_properties
+ end
+ put ":id/hooks/:hook_id" do
+ hook = user_project.hooks.find(params.delete(:hook_id))
- if hook.update_attributes(declared_params(include_missing: false))
- present hook, with: Entities::ProjectHook
- else
- error!("Invalid url given", 422) if hook.errors[:url].present?
+ if hook.update_attributes(declared_params(include_missing: false))
+ present hook, with: ::API::V3::Entities::ProjectHook
+ else
+ error!("Invalid url given", 422) if hook.errors[:url].present?
- not_found!("Project hook #{hook.errors.messages}")
+ not_found!("Project hook #{hook.errors.messages}")
+ end
end
- end
- desc 'Deletes project hook' do
- success Entities::ProjectHook
- end
- params do
- requires :hook_id, type: Integer, desc: 'The ID of the hook to delete'
- end
- delete ":id/hooks/:hook_id" do
- begin
- present user_project.hooks.destroy(params[:hook_id]), with: Entities::ProjectHook
- rescue
- # ProjectHook can raise Error if hook_id not found
- not_found!("Error deleting hook #{params[:hook_id]}")
+ desc 'Deletes project hook' do
+ success ::API::V3::Entities::ProjectHook
+ end
+ params do
+ requires :hook_id, type: Integer, desc: 'The ID of the hook to delete'
+ end
+ delete ":id/hooks/:hook_id" do
+ begin
+ present user_project.hooks.destroy(params[:hook_id]), with: ::API::V3::Entities::ProjectHook
+ rescue
+ # ProjectHook can raise Error if hook_id not found
+ not_found!("Error deleting hook #{params[:hook_id]}")
+ end
end
end
end
diff --git a/lib/api/v3/projects.rb b/lib/api/v3/projects.rb
index 47bfc12035a..8758acd2fc1 100644
--- a/lib/api/v3/projects.rb
+++ b/lib/api/v3/projects.rb
@@ -158,6 +158,7 @@ module API
use :statistics_params
end
get '/all' do
+ byebug
authenticated_as_admin!
present_projects Project.all, with: ::API::V3::Entities::ProjectWithAccess, statistics: params[:statistics]
diff --git a/lib/api/v3/services.rb b/lib/api/v3/services.rb
index de24e6418c7..3a150705275 100644
--- a/lib/api/v3/services.rb
+++ b/lib/api/v3/services.rb
@@ -146,7 +146,11 @@ module API
name: :room,
type: String,
desc: 'Campfire room'
+<<<<<<< HEAD
}
+=======
+ },
+>>>>>>> 629355a06c... WIP
],
'custom-issue-tracker' => [
{
@@ -535,8 +539,30 @@ module API
desc: 'The password of the user'
}
]
+<<<<<<< HEAD
}
+=======
+ }.freeze
+
+ trigger_services = {
+ 'mattermost-slash-commands' => [
+ {
+ name: :token,
+ type: String,
+ desc: 'The Mattermost token'
+ }
+ ],
+ 'slack-slash-commands' => [
+ {
+ name: :token,
+ type: String,
+ desc: 'The Slack token'
+ }
+ ]
+ }.freeze
+
+>>>>>>> 629355a06c... WIP
resource :projects do
before { authenticate! }
before { authorize_admin_project }
@@ -549,6 +575,38 @@ module API
end
end
+<<<<<<< HEAD
+ desc "Delete a service for project"
+ params do
+ requires :service_slug, type: String, values: services.keys, desc: 'The name of the service'
+ end
+ delete ":id/services/:service_slug" do
+ service = user_project.find_or_initialize_service(params[:service_slug].underscore)
+
+=======
+ services.each do |service_slug, settings|
+ desc "Set #{service_slug} service for project"
+ params do
+ settings.each do |setting|
+ if setting[:required]
+ requires setting[:name], type: setting[:type], desc: setting[:desc]
+ else
+ optional setting[:name], type: setting[:type], desc: setting[:desc]
+ end
+ end
+ end
+ put ":id/services/#{service_slug}" do
+ service = user_project.find_or_initialize_service(service_slug.underscore)
+ service_params = declared_params(include_missing: false).merge(active: true)
+
+ if service.update_attributes(service_params)
+ true
+ else
+ render_api_error!('400 Bad Request', 400)
+ end
+ end
+ end
+
desc "Delete a service for project"
params do
requires :service_slug, type: String, values: services.keys, desc: 'The name of the service'
@@ -556,6 +614,7 @@ module API
delete ":id/services/:service_slug" do
service = user_project.find_or_initialize_service(params[:service_slug].underscore)
+>>>>>>> 629355a06c... WIP
attrs = service_attributes(service).inject({}) do |hash, key|
hash.merge!(key => nil)
end
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index 858eb6a9635..36082f0f0f9 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -88,7 +88,7 @@ describe API::Groups, api: true do
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response)
- .to satisfy_one { |group| group['statistics'] == attributes }
+ .to satisfy_one { |group| group['statistics'] == exposed_attributes }
end
end
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index b3f0876c822..aca65434a2e 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -487,7 +487,7 @@ describe API::MergeRequests, api: true do
expect(response).to have_http_status(200)
expect(json_response['title']).to eq('Test')
- expect(json_response['merge_when_pipeline_succeeds']).to eq(true)
+ expect(json_response['merge_when_pipeline_succeeds']).to be_truthy
end
end
diff --git a/spec/requests/api/project_hooks_spec.rb b/spec/requests/api/project_hooks_spec.rb
index f286568547d..d15c9c6e5bd 100644
--- a/spec/requests/api/project_hooks_spec.rb
+++ b/spec/requests/api/project_hooks_spec.rb
@@ -33,7 +33,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
expect(json_response.first['merge_requests_events']).to eq(true)
expect(json_response.first['tag_push_events']).to eq(true)
expect(json_response.first['note_events']).to eq(true)
- expect(json_response.first['build_events']).to eq(true)
+ expect(json_response.first['job_events']).to eq(true)
expect(json_response.first['pipeline_events']).to eq(true)
expect(json_response.first['wiki_page_events']).to eq(true)
expect(json_response.first['enable_ssl_verification']).to eq(true)
@@ -52,6 +52,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
context "authorized user" do
it "returns a project hook" do
get api("/projects/#{project.id}/hooks/#{hook.id}", user)
+
expect(response).to have_http_status(200)
expect(json_response['url']).to eq(hook.url)
expect(json_response['issues_events']).to eq(hook.issues_events)
@@ -59,7 +60,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
expect(json_response['merge_requests_events']).to eq(hook.merge_requests_events)
expect(json_response['tag_push_events']).to eq(hook.tag_push_events)
expect(json_response['note_events']).to eq(hook.note_events)
- expect(json_response['build_events']).to eq(hook.build_events)
+ expect(json_response['job_events']).to eq(hook.build_events)
expect(json_response['pipeline_events']).to eq(hook.pipeline_events)
expect(json_response['wiki_page_events']).to eq(hook.wiki_page_events)
expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification)
@@ -98,7 +99,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
expect(json_response['merge_requests_events']).to eq(false)
expect(json_response['tag_push_events']).to eq(false)
expect(json_response['note_events']).to eq(false)
- expect(json_response['build_events']).to eq(false)
+ expect(json_response['job_events']).to eq(false)
expect(json_response['pipeline_events']).to eq(false)
expect(json_response['wiki_page_events']).to eq(true)
expect(json_response['enable_ssl_verification']).to eq(true)
@@ -144,7 +145,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
expect(json_response['merge_requests_events']).to eq(hook.merge_requests_events)
expect(json_response['tag_push_events']).to eq(hook.tag_push_events)
expect(json_response['note_events']).to eq(hook.note_events)
- expect(json_response['build_events']).to eq(hook.build_events)
+ expect(json_response['job_events']).to eq(hook.build_events)
expect(json_response['pipeline_events']).to eq(hook.pipeline_events)
expect(json_response['wiki_page_events']).to eq(hook.wiki_page_events)
expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification)
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 2e8b557e9e2..3bf16adcf7d 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -490,9 +490,10 @@ describe API::Projects, api: true do
expect(json_response['only_allow_merge_if_pipeline_succeeds']).to be_falsey
end
- it 'sets a project as allowing merge only if merge_when_pipeline_succeeds' do
+ it 'sets a project as allowing merge only if build succeeds' do
project = attributes_for(:project, { only_allow_merge_if_pipeline_succeeds: true })
post api("/projects/user/#{user.id}", admin), project
+
expect(json_response['only_allow_merge_if_pipeline_succeeds']).to be_truthy
end
@@ -569,7 +570,7 @@ describe API::Projects, api: true do
expect(json_response['issues_enabled']).to be_present
expect(json_response['merge_requests_enabled']).to be_present
expect(json_response['wiki_enabled']).to be_present
- expect(json_response['builds_enabled']).to be_present
+ expect(json_response['jobs_enabled']).to be_present
expect(json_response['snippets_enabled']).to be_present
expect(json_response['container_registry_enabled']).to be_present
expect(json_response['created_at']).to be_present
@@ -580,7 +581,7 @@ describe API::Projects, api: true do
expect(json_response['avatar_url']).to be_nil
expect(json_response['star_count']).to be_present
expect(json_response['forks_count']).to be_present
- expect(json_response['public_builds']).to be_present
+ expect(json_response['public_jobs']).to be_present
expect(json_response['shared_with_groups']).to be_an Array
expect(json_response['shared_with_groups'].length).to eq(1)
expect(json_response['shared_with_groups'][0]['group_id']).to eq(group.id)
diff --git a/spec/requests/api/v3/deployments_spec.rb b/spec/requests/api/v3/deployments_spec.rb
index 31e3cfa1b2f..e49da09b9d0 100644
--- a/spec/requests/api/v3/deployments_spec.rb
+++ b/spec/requests/api/v3/deployments_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe API::Deployments, api: true do
+describe API::V3::Deployments, api: true do
include ApiHelpers
let(:user) { create(:user) }
@@ -14,12 +14,8 @@ describe API::Deployments, api: true do
describe 'GET /projects/:id/deployments' do
context 'as member of the project' do
- it_behaves_like 'a paginated resources' do
- let(:request) { get api("/projects/#{project.id}/deployments", user) }
- end
-
it 'returns projects deployments' do
- get api("/projects/#{project.id}/deployments", user)
+ get v3_api("/projects/#{project.id}/deployments", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
@@ -31,7 +27,7 @@ describe API::Deployments, api: true do
context 'as non member' do
it 'returns a 404 status code' do
- get api("/projects/#{project.id}/deployments", non_member)
+ get v3_api("/projects/#{project.id}/deployments", non_member)
expect(response).to have_http_status(404)
end
@@ -41,7 +37,7 @@ describe API::Deployments, api: true do
describe 'GET /projects/:id/deployments/:deployment_id' do
context 'as a member of the project' do
it 'returns the projects deployment' do
- get api("/projects/#{project.id}/deployments/#{deployment.id}", user)
+ get v3_api("/projects/#{project.id}/deployments/#{deployment.id}", user)
expect(response).to have_http_status(200)
expect(json_response['sha']).to match /\A\h{40}\z/
@@ -51,7 +47,7 @@ describe API::Deployments, api: true do
context 'as non member' do
it 'returns a 404 status code' do
- get api("/projects/#{project.id}/deployments/#{deployment.id}", non_member)
+ get v3_api("/projects/#{project.id}/deployments/#{deployment.id}", non_member)
expect(response).to have_http_status(404)
end
diff --git a/spec/requests/api/v3/merge_request_diffs_spec.rb b/spec/requests/api/v3/merge_request_diffs_spec.rb
index e1887138aab..e099496fd21 100644
--- a/spec/requests/api/v3/merge_request_diffs_spec.rb
+++ b/spec/requests/api/v3/merge_request_diffs_spec.rb
@@ -1,6 +1,6 @@
require "spec_helper"
-describe API::MergeRequestDiffs, 'MergeRequestDiffs', api: true do
+describe API::V3::MergeRequestDiffs, 'MergeRequestDiffs', api: true do
include ApiHelpers
let!(:user) { create(:user) }
@@ -15,7 +15,7 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs', api: true do
describe 'GET /projects/:id/merge_requests/:merge_request_id/versions' do
it 'returns 200 for a valid merge request' do
- get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user)
+ get v3_api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user)
merge_request_diff = merge_request.merge_request_diffs.first
expect(response.status).to eq 200
@@ -25,7 +25,8 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs', api: true do
end
it 'returns a 404 when merge_request_id not found' do
- get api("/projects/#{project.id}/merge_requests/999/versions", user)
+ get v3_api("/projects/#{project.id}/merge_requests/999/versions", user)
+
expect(response).to have_http_status(404)
end
end
@@ -33,7 +34,7 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs', api: true do
describe 'GET /projects/:id/merge_requests/:merge_request_id/versions/:version_id' do
it 'returns a 200 for a valid merge request' do
merge_request_diff = merge_request.merge_request_diffs.first
- get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user)
+ get v3_api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user)
expect(response.status).to eq 200
expect(json_response['id']).to eq(merge_request_diff.id)
@@ -42,7 +43,8 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs', api: true do
end
it 'returns a 404 when merge_request_id not found' do
- get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/999", user)
+ get v3_api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/999", user)
+
expect(response).to have_http_status(404)
end
end
diff --git a/spec/requests/api/v3/merge_requests_spec.rb b/spec/requests/api/v3/merge_requests_spec.rb
index 51764d1000e..98dc3ebcc27 100644
--- a/spec/requests/api/v3/merge_requests_spec.rb
+++ b/spec/requests/api/v3/merge_requests_spec.rb
@@ -1,6 +1,6 @@
require "spec_helper"
-describe API::MergeRequests, api: true do
+describe API::V3::MergeRequests, api: true do
include ApiHelpers
let(:base_time) { Time.now }
let(:user) { create(:user) }
diff --git a/spec/requests/api/v3/notes_spec.rb b/spec/requests/api/v3/notes_spec.rb
index a2228132ba9..ddef2d5eb04 100644
--- a/spec/requests/api/v3/notes_spec.rb
+++ b/spec/requests/api/v3/notes_spec.rb
@@ -328,11 +328,7 @@ describe API::V3::Notes, api: true do
end
it 'returns a 400 bad request error if body not given' do
-<<<<<<< HEAD
put v3_api("/projects/#{project.id}/issues/#{issue.id}/"\
-=======
- put api("/projects/#{project.id}/issues/#{issue.id}/"\
->>>>>>> e306055d88... Pick API files from 8.16.6
"notes/#{issue_note.id}", user)
expect(response).to have_http_status(400)
@@ -341,11 +337,7 @@ describe API::V3::Notes, api: true do
context 'when noteable is a Snippet' do
it 'returns modified note' do
-<<<<<<< HEAD
put v3_api("/projects/#{project.id}/snippets/#{snippet.id}/"\
-=======
- put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
->>>>>>> e306055d88... Pick API files from 8.16.6
"notes/#{snippet_note.id}", user), body: 'Hello!'
expect(response).to have_http_status(200)
@@ -353,11 +345,7 @@ describe API::V3::Notes, api: true do
end
it 'returns a 404 error when note id not found' do
-<<<<<<< HEAD
put v3_api("/projects/#{project.id}/snippets/#{snippet.id}/"\
-=======
- put api("/projects/#{project.id}/snippets/#{snippet.id}/"\
->>>>>>> e306055d88... Pick API files from 8.16.6
"notes/12345", user), body: "Hello!"
expect(response).to have_http_status(404)
@@ -366,11 +354,7 @@ describe API::V3::Notes, api: true do
context 'when noteable is a Merge Request' do
it 'returns modified note' do
-<<<<<<< HEAD
put v3_api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
-=======
- put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
->>>>>>> e306055d88... Pick API files from 8.16.6
"notes/#{merge_request_note.id}", user), body: 'Hello!'
expect(response).to have_http_status(200)
@@ -378,11 +362,7 @@ describe API::V3::Notes, api: true do
end
it 'returns a 404 error when note id not found' do
-<<<<<<< HEAD
put v3_api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
-=======
- put api("/projects/#{project.id}/merge_requests/#{merge_request.id}/"\
->>>>>>> e306055d88... Pick API files from 8.16.6
"notes/12345", user), body: "Hello!"
expect(response).to have_http_status(404)
@@ -393,7 +373,6 @@ describe API::V3::Notes, api: true do
describe 'DELETE /projects/:id/noteable/:noteable_id/notes/:note_id' do
context 'when noteable is an Issue' do
it 'deletes a note' do
-<<<<<<< HEAD
delete v3_api("/projects/#{project.id}/issues/#{issue.id}/"\
"notes/#{issue_note.id}", user)
@@ -401,24 +380,11 @@ describe API::V3::Notes, api: true do
# Check if note is really deleted
delete v3_api("/projects/#{project.id}/issues/#{issue.id}/"\
"notes/#{issue_note.id}", user)
-=======
- delete api("/projects/#{project.id}/issues/#{issue.id}/"\
- "notes/#{issue_note.id}", user)
-
- expect(response).to have_http_status(200)
- # Check if note is really deleted
- delete api("/projects/#{project.id}/issues/#{issue.id}/"\
- "notes/#{issue_note.id}", user)
->>>>>>> e306055d88... Pick API files from 8.16.6
expect(response).to have_http_status(404)
end
it 'returns a 404 error when note id not found' do
-<<<<<<< HEAD
delete v3_api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user)
-=======
- delete api("/projects/#{project.id}/issues/#{issue.id}/notes/12345", user)
->>>>>>> e306055d88... Pick API files from 8.16.6
expect(response).to have_http_status(404)
end
@@ -426,7 +392,6 @@ describe API::V3::Notes, api: true do
context 'when noteable is a Snippet' do
it 'deletes a note' do
-<<<<<<< HEAD
delete v3_api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/#{snippet_note.id}", user)
@@ -434,26 +399,12 @@ describe API::V3::Notes, api: true do
# Check if note is really deleted
delete v3_api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/#{snippet_note.id}", user)
-=======
- delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
- "notes/#{snippet_note.id}", user)
-
- expect(response).to have_http_status(200)
- # Check if note is really deleted
- delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
- "notes/#{snippet_note.id}", user)
->>>>>>> e306055d88... Pick API files from 8.16.6
expect(response).to have_http_status(404)
end
it 'returns a 404 error when note id not found' do
-<<<<<<< HEAD
delete v3_api("/projects/#{project.id}/snippets/#{snippet.id}/"\
"notes/12345", user)
-=======
- delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\
- "notes/12345", user)
->>>>>>> e306055d88... Pick API files from 8.16.6
expect(response).to have_http_status(404)
end
@@ -461,7 +412,6 @@ describe API::V3::Notes, api: true do
context 'when noteable is a Merge Request' do
it 'deletes a note' do
-<<<<<<< HEAD
delete v3_api("/projects/#{project.id}/merge_requests/"\
"#{merge_request.id}/notes/#{merge_request_note.id}", user)
@@ -469,26 +419,12 @@ describe API::V3::Notes, api: true do
# Check if note is really deleted
delete v3_api("/projects/#{project.id}/merge_requests/"\
"#{merge_request.id}/notes/#{merge_request_note.id}", user)
-=======
- delete api("/projects/#{project.id}/merge_requests/"\
- "#{merge_request.id}/notes/#{merge_request_note.id}", user)
-
- expect(response).to have_http_status(200)
- # Check if note is really deleted
- delete api("/projects/#{project.id}/merge_requests/"\
- "#{merge_request.id}/notes/#{merge_request_note.id}", user)
->>>>>>> e306055d88... Pick API files from 8.16.6
expect(response).to have_http_status(404)
end
it 'returns a 404 error when note id not found' do
-<<<<<<< HEAD
delete v3_api("/projects/#{project.id}/merge_requests/"\
"#{merge_request.id}/notes/12345", user)
-=======
- delete api("/projects/#{project.id}/merge_requests/"\
- "#{merge_request.id}/notes/12345", user)
->>>>>>> e306055d88... Pick API files from 8.16.6
expect(response).to have_http_status(404)
end
diff --git a/spec/requests/api/v3/project_hooks_spec.rb b/spec/requests/api/v3/project_hooks_spec.rb
index 36fbcf088e7..be17273e628 100644
--- a/spec/requests/api/v3/project_hooks_spec.rb
+++ b/spec/requests/api/v3/project_hooks_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe API::ProjectHooks, 'ProjectHooks', api: true do
+describe API::V3::ProjectHooks, 'ProjectHooks', api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:user3) { create(:user) }
@@ -21,7 +21,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
describe "GET /projects/:id/hooks" do
context "authorized user" do
it "returns project hooks" do
- get api("/projects/#{project.id}/hooks", user)
+ get v3_api("/projects/#{project.id}/hooks", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
@@ -41,7 +41,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
context "unauthorized user" do
it "does not access project hooks" do
- get api("/projects/#{project.id}/hooks", user3)
+ get v3_api("/projects/#{project.id}/hooks", user3)
expect(response).to have_http_status(403)
end
end
@@ -50,7 +50,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
describe "GET /projects/:id/hooks/:hook_id" do
context "authorized user" do
it "returns a project hook" do
- get api("/projects/#{project.id}/hooks/#{hook.id}", user)
+ get v3_api("/projects/#{project.id}/hooks/#{hook.id}", user)
expect(response).to have_http_status(200)
expect(json_response['url']).to eq(hook.url)
expect(json_response['issues_events']).to eq(hook.issues_events)
@@ -65,20 +65,20 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
end
it "returns a 404 error if hook id is not available" do
- get api("/projects/#{project.id}/hooks/1234", user)
+ get v3_api("/projects/#{project.id}/hooks/1234", user)
expect(response).to have_http_status(404)
end
end
context "unauthorized user" do
it "does not access an existing hook" do
- get api("/projects/#{project.id}/hooks/#{hook.id}", user3)
+ get v3_api("/projects/#{project.id}/hooks/#{hook.id}", user3)
expect(response).to have_http_status(403)
end
end
it "returns a 404 error if hook id is not available" do
- get api("/projects/#{project.id}/hooks/1234", user)
+ get v3_api("/projects/#{project.id}/hooks/1234", user)
expect(response).to have_http_status(404)
end
end
@@ -86,7 +86,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
describe "POST /projects/:id/hooks" do
it "adds hook to project" do
expect do
- post api("/projects/#{project.id}/hooks", user),
+ post v3_api("/projects/#{project.id}/hooks", user),
url: "http://example.com", issues_events: true, wiki_page_events: true
end.to change {project.hooks.count}.by(1)
@@ -108,7 +108,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
token = "secret token"
expect do
- post api("/projects/#{project.id}/hooks", user), url: "http://example.com", token: token
+ post v3_api("/projects/#{project.id}/hooks", user), url: "http://example.com", token: token
end.to change {project.hooks.count}.by(1)
expect(response).to have_http_status(201)
@@ -122,19 +122,19 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
end
it "returns a 400 error if url not given" do
- post api("/projects/#{project.id}/hooks", user)
+ post v3_api("/projects/#{project.id}/hooks", user)
expect(response).to have_http_status(400)
end
it "returns a 422 error if url not valid" do
- post api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com"
+ post v3_api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com"
expect(response).to have_http_status(422)
end
end
describe "PUT /projects/:id/hooks/:hook_id" do
it "updates an existing project hook" do
- put api("/projects/#{project.id}/hooks/#{hook.id}", user),
+ put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user),
url: 'http://example.org', push_events: false
expect(response).to have_http_status(200)
expect(json_response['url']).to eq('http://example.org')
@@ -152,7 +152,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
it "adds the token without including it in the response" do
token = "secret token"
- put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: "http://example.org", token: token
+ put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user), url: "http://example.org", token: token
expect(response).to have_http_status(200)
expect(json_response["url"]).to eq("http://example.org")
@@ -163,17 +163,17 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
end
it "returns 404 error if hook id not found" do
- put api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org'
+ put v3_api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org'
expect(response).to have_http_status(404)
end
it "returns 400 error if url is not given" do
- put api("/projects/#{project.id}/hooks/#{hook.id}", user)
+ put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user)
expect(response).to have_http_status(400)
end
it "returns a 422 error if url is not valid" do
- put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com'
+ put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com'
expect(response).to have_http_status(422)
end
end
@@ -181,23 +181,23 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
describe "DELETE /projects/:id/hooks/:hook_id" do
it "deletes hook from project" do
expect do
- delete api("/projects/#{project.id}/hooks/#{hook.id}", user)
+ delete v3_api("/projects/#{project.id}/hooks/#{hook.id}", user)
end.to change {project.hooks.count}.by(-1)
expect(response).to have_http_status(200)
end
it "returns success when deleting hook" do
- delete api("/projects/#{project.id}/hooks/#{hook.id}", user)
+ delete v3_api("/projects/#{project.id}/hooks/#{hook.id}", user)
expect(response).to have_http_status(200)
end
it "returns a 404 error when deleting non existent hook" do
- delete api("/projects/#{project.id}/hooks/42", user)
+ delete v3_api("/projects/#{project.id}/hooks/42", user)
expect(response).to have_http_status(404)
end
it "returns a 404 error if hook id not given" do
- delete api("/projects/#{project.id}/hooks", user)
+ delete v3_api("/projects/#{project.id}/hooks", user)
expect(response).to have_http_status(404)
end
@@ -207,7 +207,7 @@ describe API::ProjectHooks, 'ProjectHooks', api: true do
other_project = create(:project)
other_project.team << [test_user, :master]
- delete api("/projects/#{other_project.id}/hooks/#{hook.id}", test_user)
+ delete v3_api("/projects/#{other_project.id}/hooks/#{hook.id}", test_user)
expect(response).to have_http_status(404)
expect(WebHook.exists?(hook.id)).to be_truthy
end