chore: add create comment api
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="resolve-actions relative flex items-center justify-end">
|
||||
<div class="relative flex items-center justify-end resolve-actions">
|
||||
<div class="button-group">
|
||||
<woot-button
|
||||
v-if="isOpen"
|
||||
@@ -94,6 +94,7 @@ import keyboardEventListenerMixins from 'shared/mixins/keyboardEventListenerMixi
|
||||
import { findSnoozeTime } from 'dashboard/helper/snoozeHelpers';
|
||||
import WootDropdownItem from 'shared/components/ui/dropdown/DropdownItem.vue';
|
||||
import WootDropdownMenu from 'shared/components/ui/dropdown/DropdownMenu.vue';
|
||||
import LinearAPI from 'dashboard/api/integrations/linear';
|
||||
|
||||
import wootConstants from 'dashboard/constants/globals';
|
||||
import {
|
||||
@@ -119,7 +120,10 @@ export default {
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapGetters({ currentChat: 'getSelectedChat' }),
|
||||
...mapGetters({
|
||||
currentChat: 'getSelectedChat',
|
||||
currentUser: 'getCurrentUser',
|
||||
}),
|
||||
isOpen() {
|
||||
return this.currentChat.status === wootConstants.STATUS_TYPE.OPEN;
|
||||
},
|
||||
@@ -248,6 +252,7 @@ export default {
|
||||
snoozedUntil,
|
||||
})
|
||||
.then(() => {
|
||||
this.updateLinearComment(status);
|
||||
this.showAlert(this.$t('CONVERSATION.CHANGE_STATUS'));
|
||||
this.isLoading = false;
|
||||
});
|
||||
@@ -256,6 +261,20 @@ export default {
|
||||
const ninja = document.querySelector('ninja-keys');
|
||||
ninja.open({ parent: 'snooze_conversation' });
|
||||
},
|
||||
async updateLinearComment(status) {
|
||||
if (status !== 'resolved') {
|
||||
return;
|
||||
}
|
||||
const response = await LinearAPI.getLinkedIssue(this.currentChat.id);
|
||||
const { data: issues } = response;
|
||||
const linkedIssue = issues && issues.length ? issues[0] : null;
|
||||
if (linkedIssue) {
|
||||
await LinearAPI.createComment({
|
||||
issue_id: linkedIssue.issue.id,
|
||||
comment: `*The conversation has been resolved by **${this.currentUser.name}***`,
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -21,5 +21,6 @@ defineProps({
|
||||
size="18"
|
||||
class="flex-shrink-0 text-slate-900 dark:text-slate-50"
|
||||
/>
|
||||
<slot name="dropdown" />
|
||||
</button>
|
||||
</template>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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?
|
||||
|
||||
+14
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user