feat: Add APIs for linear integration (#9346)
This commit is contained in:
56
lib/linear/mutations.rb
Normal file
56
lib/linear/mutations.rb
Normal file
@@ -0,0 +1,56 @@
|
||||
module Linear::Mutations
|
||||
def self.graphql_value(value)
|
||||
case value
|
||||
when String
|
||||
# Strings must be enclosed in double quotes
|
||||
"\"#{value}\""
|
||||
when Array
|
||||
# Arrays need to be recursively converted
|
||||
"[#{value.map { |v| graphql_value(v) }.join(', ')}]"
|
||||
else
|
||||
# Other types (numbers, booleans) can be directly converted to strings
|
||||
value.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def self.graphql_input(input)
|
||||
input.map { |key, value| "#{key}: #{graphql_value(value)}" }.join(', ')
|
||||
end
|
||||
|
||||
def self.issue_create(input)
|
||||
<<~GRAPHQL
|
||||
mutation {
|
||||
issueCreate(input: { #{graphql_input(input)} }) {
|
||||
success
|
||||
issue {
|
||||
id
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
|
||||
def self.issue_link(issue_id, link, title)
|
||||
<<~GRAPHQL
|
||||
mutation {
|
||||
attachmentLinkURL(url: "#{link}", issueId: "#{issue_id}", title: "#{title}") {
|
||||
success
|
||||
attachment {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
|
||||
def self.unlink_issue(link_id)
|
||||
<<~GRAPHQL
|
||||
mutation {
|
||||
attachmentDelete(id: "#{link_id}") {
|
||||
success
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
end
|
||||
100
lib/linear/queries.rb
Normal file
100
lib/linear/queries.rb
Normal file
@@ -0,0 +1,100 @@
|
||||
module Linear::Queries
|
||||
TEAMS_QUERY = <<~GRAPHQL.freeze
|
||||
query {
|
||||
teams {
|
||||
nodes {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
|
||||
def self.team_entities_query(team_id)
|
||||
<<~GRAPHQL
|
||||
query {
|
||||
users {
|
||||
nodes {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
projects {
|
||||
nodes {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
workflowStates(
|
||||
filter: { team: { id: { eq: "#{team_id}" } } }
|
||||
) {
|
||||
nodes {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
issueLabels(
|
||||
filter: { team: { id: { eq: "#{team_id}" } } }
|
||||
) {
|
||||
nodes {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
|
||||
def self.search_issue(term)
|
||||
<<~GRAPHQL
|
||||
query {
|
||||
searchIssues(term: "#{term}") {
|
||||
nodes {
|
||||
id
|
||||
title
|
||||
description
|
||||
identifier
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
|
||||
def self.linked_issues(url)
|
||||
<<~GRAPHQL
|
||||
query {
|
||||
attachmentsForURL(url: "#{url}") {
|
||||
nodes {
|
||||
id
|
||||
title
|
||||
issue {
|
||||
id
|
||||
identifier
|
||||
title
|
||||
description
|
||||
priority
|
||||
createdAt
|
||||
url
|
||||
assignee {
|
||||
name
|
||||
avatarUrl
|
||||
}
|
||||
state {
|
||||
name
|
||||
color
|
||||
}
|
||||
labels {
|
||||
nodes{
|
||||
id
|
||||
name
|
||||
color
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user