diff --git a/app/controllers/api/v1/accounts/integrations/linear_controller.rb b/app/controllers/api/v1/accounts/integrations/linear_controller.rb index ef9fcf235..9b5e57620 100644 --- a/app/controllers/api/v1/accounts/integrations/linear_controller.rb +++ b/app/controllers/api/v1/accounts/integrations/linear_controller.rb @@ -29,6 +29,17 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::Bas end end + def create_comment + issue_id = params[:issue_id] + comment = permitted_params[:comment] + issue = linear_processor_service.create_comment(issue_id, comment) + if issue.is_a?(Hash) && issue[:error] + render json: { error: issue[:error] }, status: :unprocessable_entity + else + render json: issue, status: :ok + end + end + def link_issue issue_id = params[:issue_id] issue = linear_processor_service.link_issue(conversation_link, issue_id) @@ -87,6 +98,6 @@ class Api::V1::Accounts::Integrations::LinearController < Api::V1::Accounts::Bas end def permitted_params - params.permit(:team_id, :conversation_id, :issue_id, :link_id, :title, :description, :assignee_id, :priority, label_ids: []) + params.permit(:team_id, :conversation_id, :issue_id, :comment, :link_id, :title, :description, :assignee_id, :priority, label_ids: []) end end diff --git a/app/javascript/dashboard/api/integrations/linear.js b/app/javascript/dashboard/api/integrations/linear.js index 41008278b..6e0c70a97 100644 --- a/app/javascript/dashboard/api/integrations/linear.js +++ b/app/javascript/dashboard/api/integrations/linear.js @@ -41,6 +41,10 @@ class LinearAPI extends ApiClient { searchIssues(query) { return axios.get(`${this.url}/search_issue?q=${query}`); } + + createComment(data) { + return axios.post(`${this.url}/create_comment`, data); + } } export default new LinearAPI(); diff --git a/app/javascript/dashboard/components/buttons/ResolveAction.vue b/app/javascript/dashboard/components/buttons/ResolveAction.vue index 61375dc21..bc16539af 100644 --- a/app/javascript/dashboard/components/buttons/ResolveAction.vue +++ b/app/javascript/dashboard/components/buttons/ResolveAction.vue @@ -1,5 +1,5 @@ diff --git a/config/routes.rb b/config/routes.rb index 20696fdee..f1675291b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -233,6 +233,7 @@ Rails.application.routes.draw do get :team_entities post :create_issue post :link_issue + post :create_comment post :unlink_issue get :search_issue get :linked_issue diff --git a/lib/integrations/linear/processor_service.rb b/lib/integrations/linear/processor_service.rb index ab5c4f3c9..8c7747848 100644 --- a/lib/integrations/linear/processor_service.rb +++ b/lib/integrations/linear/processor_service.rb @@ -41,6 +41,17 @@ class Integrations::Linear::ProcessorService } end + def create_comment(issue_id, comment) + response = linear_client.create_comment(issue_id, comment) + + return response if response[:error] + + { + id: response['commentCreate']['comment']['id'], + body: response['commentCreate']['comment']['body'] + } + end + def unlink_issue(link_id) response = linear_client.unlink_issue(link_id) return response if response[:error] diff --git a/lib/linear.rb b/lib/linear.rb index 804ea9e5e..f5abe6e27 100644 --- a/lib/linear.rb +++ b/lib/linear.rb @@ -66,6 +66,20 @@ class Linear process_response(response) end + def create_comment(issue_id, body) + raise ArgumentError, 'Missing issue id' if issue_id.blank? + raise ArgumentError, 'Missing body' if body.blank? + + variables = { + issueId: issue_id, + body: body + } + + mutation = LinearMutations.create_comment(variables) + response = post({ query: mutation }) + process_response(response) + end + def link_issue(link, issue_id) raise ArgumentError, 'Missing link' if link.blank? raise ArgumentError, 'Missing issue id' if issue_id.blank? diff --git a/lib/linear_mutations.rb b/lib/linear_mutations.rb index e34fdcd43..912802cad 100644 --- a/lib/linear_mutations.rb +++ b/lib/linear_mutations.rb @@ -17,7 +17,6 @@ module LinearMutations input.map { |key, value| "#{key}: #{graphql_value(value)}" }.join(', ') end - # Main mutation creation function def self.issue_create(input) <<~GRAPHQL mutation { @@ -32,6 +31,20 @@ module LinearMutations GRAPHQL end + def self.create_comment(input) + <<~GRAPHQL + mutation { + commentCreate(input: { #{graphql_input(input)} }) { + success + comment { + id + body + } + } + } + GRAPHQL + end + def self.issue_link(issue_id, link) <<~GRAPHQL mutation {