feat: add teams end point
This commit is contained in:
+2
-1
@@ -228,7 +228,8 @@ Rails.application.routes.draw do
|
||||
end
|
||||
resource :linear, controller: 'linear', only: [] do
|
||||
collection do
|
||||
post :list
|
||||
get :teams
|
||||
get :labels
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
class Integrations::Linear::ProcessorService
|
||||
pattr_initialize [:account!, :conversation!]
|
||||
|
||||
def create_issue; end
|
||||
def teams
|
||||
response = linear_client.teams
|
||||
return response if response[:error]
|
||||
|
||||
def link_issue; end
|
||||
response['teams']['nodes'].map(&:as_json)
|
||||
end
|
||||
|
||||
def list_issues
|
||||
issues = linear_client.list_issues
|
||||
issues.map(&:as_json)
|
||||
# get labels for a team
|
||||
def labels(team_id)
|
||||
response = linear_client.labels(team_id)
|
||||
return response if response[:error]
|
||||
|
||||
response['team']['labels']['nodes'].map(&:as_json)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def conversation_link
|
||||
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{account.id}/conversations/#{conversation.display_id}"
|
||||
end
|
||||
|
||||
def linear_hook
|
||||
@linear_hook ||= account.hooks.find_by!(app_id: 'linear')
|
||||
end
|
||||
|
||||
+31
-10
@@ -16,24 +16,45 @@ class Linear
|
||||
)
|
||||
end
|
||||
|
||||
def list_issues
|
||||
def teams
|
||||
query = <<~GRAPHQL
|
||||
query {
|
||||
issues(first: 5) {
|
||||
teams {
|
||||
nodes {
|
||||
id
|
||||
title
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
execute_query(query)
|
||||
end
|
||||
|
||||
begin
|
||||
response = @client.query(query)
|
||||
response.data.issues.nodes
|
||||
rescue StandardError => e
|
||||
# return error message
|
||||
e.message
|
||||
end
|
||||
def labels(team_id)
|
||||
query = <<~GRAPHQL
|
||||
query {
|
||||
team(id: "#{team_id}") {
|
||||
labels {
|
||||
nodes {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
execute_query(query)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def execute_query(query)
|
||||
@client.query(query).data.to_h
|
||||
rescue Graphlient::Errors::GraphQLError => e
|
||||
{ error: "GraphQL Error: #{e.message}" }
|
||||
rescue Graphlient::Errors::ServerError => e
|
||||
{ error: "Server Error: #{e.message}" }
|
||||
rescue StandardError => e
|
||||
{ error: "Unexpected Error: #{e.message}" }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user