2020-11-24 15:15:51 +05:30
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
module API
|
2021-01-03 14:25:43 +05:30
|
|
|
|
class IssueLinks < ::API::Base
|
2020-11-24 15:15:51 +05:30
|
|
|
|
include PaginationParams
|
|
|
|
|
|
|
|
|
|
before { authenticate! }
|
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
|
ISSUE_LINKS_TAGS = %w[issue_links].freeze
|
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
|
feature_category :team_planning
|
2022-07-16 23:28:13 +05:30
|
|
|
|
urgency :low
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
|
requires :id, types: [String, Integer],
|
|
|
|
|
desc: 'The ID or URL-encoded path of the project owned by the authenticated user'
|
|
|
|
|
requires :issue_iid, type: Integer, desc: 'The internal ID of a project’s issue'
|
2020-11-24 15:15:51 +05:30
|
|
|
|
end
|
|
|
|
|
resource :projects, requirements: { id: %r{[^/]+} } do
|
2023-01-13 00:05:48 +05:30
|
|
|
|
desc 'List issue relations' do
|
|
|
|
|
detail 'Get a list of a given issue’s linked issues, sorted by the relationship creation datetime (ascending).'\
|
|
|
|
|
'Issues are filtered according to the user authorizations.'
|
2020-11-24 15:15:51 +05:30
|
|
|
|
success Entities::RelatedIssue
|
2023-01-13 00:05:48 +05:30
|
|
|
|
is_array true
|
|
|
|
|
failure [
|
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
|
]
|
|
|
|
|
tags ISSUE_LINKS_TAGS
|
2020-11-24 15:15:51 +05:30
|
|
|
|
end
|
|
|
|
|
get ':id/issues/:issue_iid/links' do
|
|
|
|
|
source_issue = find_project_issue(params[:issue_iid])
|
2021-04-29 21:17:54 +05:30
|
|
|
|
related_issues = source_issue.related_issues(current_user) do |issues|
|
|
|
|
|
issues.with_api_entity_associations.preload_awardable
|
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
|
|
present related_issues,
|
|
|
|
|
with: Entities::RelatedIssue,
|
|
|
|
|
current_user: current_user,
|
2021-06-08 01:23:25 +05:30
|
|
|
|
project: user_project,
|
|
|
|
|
include_subscribed: false
|
2020-11-24 15:15:51 +05:30
|
|
|
|
end
|
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
|
desc 'Create an issue link' do
|
|
|
|
|
detail 'Creates a two-way relation between two issues.'\
|
|
|
|
|
'The user must be allowed to update both issues to succeed.'
|
2020-11-24 15:15:51 +05:30
|
|
|
|
success Entities::IssueLink
|
2023-01-13 00:05:48 +05:30
|
|
|
|
failure [
|
|
|
|
|
{ code: 400, message: 'Bad Request' },
|
|
|
|
|
{ code: 401, message: 'Unauthorized' }
|
|
|
|
|
]
|
|
|
|
|
tags ISSUE_LINKS_TAGS
|
2020-11-24 15:15:51 +05:30
|
|
|
|
end
|
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
|
requires :target_project_id, types: [String, Integer],
|
|
|
|
|
desc: 'The ID or URL-encoded path of a target project'
|
|
|
|
|
requires :target_issue_iid, types: [String, Integer], desc: 'The internal ID of a target project’s issue'
|
2020-11-24 15:15:51 +05:30
|
|
|
|
optional :link_type, type: String, values: IssueLink.link_types.keys,
|
2023-01-13 00:05:48 +05:30
|
|
|
|
desc: 'The type of the relation (“relates_to”, “blocks”, “is_blocked_by”),'\
|
|
|
|
|
'defaults to “relates_to”)'
|
2020-11-24 15:15:51 +05:30
|
|
|
|
end
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
|
post ':id/issues/:issue_iid/links' do
|
|
|
|
|
source_issue = find_project_issue(params[:issue_iid])
|
|
|
|
|
target_issue = find_project_issue(declared_params[:target_issue_iid],
|
|
|
|
|
declared_params[:target_project_id])
|
|
|
|
|
|
|
|
|
|
create_params = { target_issuable: target_issue, link_type: declared_params[:link_type] }
|
|
|
|
|
|
|
|
|
|
result = ::IssueLinks::CreateService
|
|
|
|
|
.new(source_issue, current_user, create_params)
|
|
|
|
|
.execute
|
|
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
|
issue_link = IssueLink.find_by!(source: source_issue, target: target_issue)
|
|
|
|
|
|
|
|
|
|
present issue_link, with: Entities::IssueLink
|
|
|
|
|
else
|
|
|
|
|
render_api_error!(result[:message], result[:http_status])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
|
desc 'Get an issue link' do
|
|
|
|
|
detail 'Gets details about an issue link. This feature was introduced in GitLab 15.1.'
|
2022-07-23 23:45:48 +05:30
|
|
|
|
success Entities::IssueLink
|
2023-01-13 00:05:48 +05:30
|
|
|
|
failure [
|
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
|
]
|
|
|
|
|
tags ISSUE_LINKS_TAGS
|
2022-07-23 23:45:48 +05:30
|
|
|
|
end
|
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
|
requires :issue_link_id, types: [String, Integer], desc: 'ID of an issue relationship'
|
2022-07-23 23:45:48 +05:30
|
|
|
|
end
|
|
|
|
|
get ':id/issues/:issue_iid/links/:issue_link_id' do
|
|
|
|
|
issue = find_project_issue(params[:issue_iid])
|
|
|
|
|
issue_link = IssueLink.for_source_or_target(issue).find(declared_params[:issue_link_id])
|
|
|
|
|
|
|
|
|
|
find_project_issue(issue_link.target.iid.to_s, issue_link.target.project_id.to_s)
|
|
|
|
|
|
|
|
|
|
present issue_link, with: Entities::IssueLink
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
|
desc 'Delete an issue link' do
|
|
|
|
|
detail 'Deletes an issue link, thus removes the two-way relationship.'
|
2020-11-24 15:15:51 +05:30
|
|
|
|
success Entities::IssueLink
|
2023-01-13 00:05:48 +05:30
|
|
|
|
failure [
|
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
|
]
|
|
|
|
|
tags ISSUE_LINKS_TAGS
|
2020-11-24 15:15:51 +05:30
|
|
|
|
end
|
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
|
requires :issue_link_id, types: [String, Integer], desc: 'The ID of an issue relationship'
|
2020-11-24 15:15:51 +05:30
|
|
|
|
end
|
|
|
|
|
delete ':id/issues/:issue_iid/links/:issue_link_id' do
|
2022-06-21 17:19:12 +05:30
|
|
|
|
issue = find_project_issue(params[:issue_iid])
|
|
|
|
|
issue_link = IssueLink
|
|
|
|
|
.for_source_or_target(issue)
|
|
|
|
|
.find(declared_params[:issue_link_id])
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
|
|
find_project_issue(issue_link.target.iid.to_s, issue_link.target.project_id.to_s)
|
|
|
|
|
|
|
|
|
|
result = ::IssueLinks::DestroyService
|
2022-06-21 17:19:12 +05:30
|
|
|
|
.new(issue_link, current_user)
|
|
|
|
|
.execute
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
|
present issue_link, with: Entities::IssueLink
|
|
|
|
|
else
|
|
|
|
|
render_api_error!(result[:message], result[:http_status])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|