Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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
13 files changed, 349 insertions, 231 deletions
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