summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-22 15:08:48 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-22 15:08:48 +0000
commit180cd023a11c0eb413ad0de124d9758ea25672bd (patch)
tree63d77be00a22dc637daa0b6d5b644e230f5f4890 /lib
parentbe3e24ea3c9f497efde85900df298ce9bc42fce8 (diff)
downloadgitlab-ce-180cd023a11c0eb413ad0de124d9758ea25672bd.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb9
-rw-r--r--lib/api/users.rb26
-rw-r--r--lib/sentry/client.rb6
-rw-r--r--lib/sentry/client/issue_link.rb35
4 files changed, 71 insertions, 5 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 97be90030c8..899418831bf 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -2,6 +2,15 @@
module API
module Entities
+ class Membership < Grape::Entity
+ expose :source_id
+ expose :source_name do |member|
+ member.source.name
+ end
+ expose :source_type
+ expose :access_level
+ end
+
class BlameRangeCommit < Grape::Entity
expose :id
expose :parent_ids
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 120f66b6a71..eba7c50435c 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -533,6 +533,32 @@ module API
end
# rubocop: enable CodeReuse/ActiveRecord
+ desc 'Get memberships' do
+ success Entities::Membership
+ end
+ params do
+ requires :user_id, type: Integer, desc: 'The ID of the user'
+ optional :type, type: String, values: %w[Project Namespace]
+ use :pagination
+ end
+ get ":user_id/memberships" do
+ authenticated_as_admin!
+ user = find_user_by_id(params)
+
+ members = case params[:type]
+ when 'Project'
+ user.project_members
+ when 'Namespace'
+ user.group_members
+ else
+ user.members
+ end
+
+ members = members.including_source
+
+ present paginate(members), with: Entities::Membership
+ end
+
params do
requires :user_id, type: Integer, desc: 'The ID of the user'
end
diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb
index 8898960c24d..36ec1caf80c 100644
--- a/lib/sentry/client.rb
+++ b/lib/sentry/client.rb
@@ -54,6 +54,12 @@ module Sentry
end
end
+ def http_post(url, params = {})
+ http_request do
+ Gitlab::HTTP.post(url, **request_params.merge(body: params.to_json))
+ end
+ end
+
def http_request
response = handle_request_exceptions do
yield
diff --git a/lib/sentry/client/issue_link.rb b/lib/sentry/client/issue_link.rb
index 200b1a6b435..91498c19f8b 100644
--- a/lib/sentry/client/issue_link.rb
+++ b/lib/sentry/client/issue_link.rb
@@ -3,8 +3,22 @@
module Sentry
class Client
module IssueLink
- def create_issue_link(integration_id, sentry_issue_identifier, issue)
- issue_link_url = issue_link_api_url(integration_id, sentry_issue_identifier)
+ # Creates a link in Sentry corresponding to the provided
+ # Sentry issue and GitLab issue
+ # @param integration_id [Integer, nil] Representing a global
+ # GitLab integration in Sentry. Nil for plugins.
+ # @param sentry_issue_id [Integer] Id for an issue from Sentry
+ # @param issue [Issue] Issue for which the link should be created
+ def create_issue_link(integration_id, sentry_issue_id, issue)
+ return create_plugin_link(sentry_issue_id, issue) unless integration_id
+
+ create_global_integration_link(integration_id, sentry_issue_id, issue)
+ end
+
+ private
+
+ def create_global_integration_link(integration_id, sentry_issue_id, issue)
+ issue_link_url = global_integration_link_api_url(integration_id, sentry_issue_id)
params = {
project: issue.project.id,
@@ -14,11 +28,22 @@ module Sentry
http_put(issue_link_url, params)
end
- private
+ def global_integration_link_api_url(integration_id, sentry_issue_id)
+ issue_link_url = URI(url)
+ issue_link_url.path = "/api/0/groups/#{sentry_issue_id}/integrations/#{integration_id}/"
+
+ issue_link_url
+ end
+
+ def create_plugin_link(sentry_issue_id, issue)
+ issue_link_url = plugin_link_api_url(sentry_issue_id)
+
+ http_post(issue_link_url, issue_id: issue.iid)
+ end
- def issue_link_api_url(integration_id, sentry_issue_identifier)
+ def plugin_link_api_url(sentry_issue_id)
issue_link_url = URI(url)
- issue_link_url.path = "/api/0/groups/#{sentry_issue_identifier}/integrations/#{integration_id}/"
+ issue_link_url.path = "/api/0/issues/#{sentry_issue_id}/plugins/gitlab/link/"
issue_link_url
end