feat: add link issue API
This commit is contained in:
@@ -27,6 +27,17 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::Bas
|
||||
end
|
||||
end
|
||||
|
||||
def link_issue
|
||||
link = params[:link]
|
||||
issue_id = params[:issue_id]
|
||||
issue = linear_processor_service.link_issue(link, issue_id)
|
||||
if issue.is_a?(Hash) && issue[:error]
|
||||
render json: { error: issue[:error] }, status: :unprocessable_entity
|
||||
else
|
||||
render json: issue, status: :ok
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def linear_processor_service
|
||||
@@ -34,6 +45,6 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::Bas
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:team_id, :title, :description, :assignee_id, :priority, label_ids: [])
|
||||
params.permit(:team_id, :link, :issue_id, :title, :description, :assignee_id, :priority, label_ids: [])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -232,6 +232,7 @@ Rails.application.routes.draw do
|
||||
get :teams
|
||||
get :team_entites
|
||||
post :create_issue
|
||||
post :link_issue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,20 @@ class Integrations::Linear::ProcessorService
|
||||
response = linear_client.create_issue(params)
|
||||
return response if response[:error]
|
||||
|
||||
response
|
||||
{
|
||||
id: response['issueCreate']['issue']['id'],
|
||||
title: response['issueCreate']['issue']['title']
|
||||
}
|
||||
end
|
||||
|
||||
def link_issue(link, issue_id)
|
||||
response = linear_client.link_issue(link, issue_id)
|
||||
return response if response[:error]
|
||||
|
||||
{
|
||||
id: issue_id,
|
||||
link: link
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
+9
-2
@@ -46,6 +46,13 @@ class Linear
|
||||
execute_mutation(LinearMutations.issue_create(variables))
|
||||
end
|
||||
|
||||
def link_issue(link, issue_id)
|
||||
raise ArgumentError, 'Missing link' if link.blank?
|
||||
raise ArgumentError, 'Missing issue id' if issue_id.blank?
|
||||
|
||||
execute_mutation(LinearMutations.issue_link(issue_id, link))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_team_and_title(params)
|
||||
@@ -56,14 +63,14 @@ class Linear
|
||||
def validate_priority(priority)
|
||||
return if priority.nil? || PRIORITY_LEVELS.include?(priority)
|
||||
|
||||
raise ArgumentError, 'Invalid priority value. Allowed values: 0, 1, 2, 3, 4'
|
||||
raise ArgumentError, 'Invalid priority value. Priority must be 0, 1, 2, 3, or 4.'
|
||||
end
|
||||
|
||||
def validate_label_ids(label_ids)
|
||||
return if label_ids.nil?
|
||||
return if label_ids.is_a?(Array) && label_ids.all?(String)
|
||||
|
||||
raise ArgumentError, 'labelIds must be an array of strings'
|
||||
raise ArgumentError, 'label_ids must be an array of strings.'
|
||||
end
|
||||
|
||||
def execute_query(query)
|
||||
|
||||
@@ -31,4 +31,17 @@ module LinearMutations
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
|
||||
def self.issue_link(issue_id, link)
|
||||
<<~GRAPHQL
|
||||
mutation {
|
||||
attachmentLinkURL(url: "#{link}", issueId: "#{issue_id}") {
|
||||
success
|
||||
attachment {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user