Class: Gitlab::Triage::Linear::Migrator::LinearInterface
- Inherits:
-
Object
- Object
- Gitlab::Triage::Linear::Migrator::LinearInterface
- Defined in:
- lib/gitlab/triage/linear/migrator/linear_interface.rb
Overview
An interface class that provides functions to get and send data from/to Linear
Constant Summary collapse
- FIND_LABEL_QUERY =
<<~GRAPHQL query($label: String!) { issueLabels( filter: { name: { eq: $label } } ) { nodes { id name } } } GRAPHQL
- UPDATE_LABELS_MUTATION =
<<~GRAPHQL mutation($issueId: String!, $labels: [String!]!) { issueUpdate(input: { labelIds: $labels }, id: $issueId) { lastSyncId success } } GRAPHQL
- LIST_LABELS_QUERY =
<<~GRAPHQL query($labels: [String!], $teamId: ID) { issueLabels( filter: { name: { in: $labels } or: [ { team: { id: { eq: $teamId } } } { team: { null: true } } ] } ) { nodes { id name } } } GRAPHQL
- GET_USER_ID_BY_EMAIL_QUERY =
<<~GRAPHQL query($email: String!) { users(filter: { email: { eq: $email } }) { nodes { id } } } GRAPHQL
- GET_TEAM_BY_NAME_QUERY =
<<~GRAPHQL query($name: String!) { teams(filter: { name: { eq: $name } }) { nodes { id name states { nodes { id name } } } } } GRAPHQL
- FIND_LINEAR_ISSUE_BY_GITLAB_URL_QUERY =
<<~GRAPHQL query($gitlabUrl: String!) { issueSearch( filter: { comments: { body: { contains: "Original issue: $gitlabUrl" } } } ) { nodes { id } } } GRAPHQL
Instance Method Summary collapse
- #create_comment(body: "", linear_issue_id: nil, author_name: nil, parent_id: nil, created_at: Time.now) ⇒ Object
- #create_issue(issue_data) ⇒ Object
- #create_mr_link(linear_id, url, path, number, title) ⇒ Object
- #create_url_link(linear_id, url, title = nil) ⇒ Object
- #find_label(label) ⇒ Object
- #find_linear_issue_by_gitlab_url(gitlab_url) ⇒ Object
- #get_team_by_name(name) ⇒ Object
- #get_user_id_by_email(email) ⇒ Object
-
#initialize(graphql_client: GraphqlClient) ⇒ LinearInterface
constructor
A new instance of LinearInterface.
- #list_labels(labels, team_id) ⇒ Object
- #update_labels(issue_id, labels) ⇒ Object
Constructor Details
#initialize(graphql_client: GraphqlClient) ⇒ LinearInterface
Returns a new instance of LinearInterface.
97 98 99 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 97 def initialize(graphql_client: GraphqlClient) @graphql_client = graphql_client end |
Instance Method Details
#create_comment(body: "", linear_issue_id: nil, author_name: nil, parent_id: nil, created_at: Time.now) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 154 def create_comment(body: "", linear_issue_id: nil, author_name: nil, parent_id: nil, created_at: Time.now) query = build_graphql_mutation("commentCreate", { input: { body: body.gsub("...", ". . . "), issueId: linear_issue_id, parentId: parent_id, createAsUser: , createdAt: created_at } }, ["lastSyncId", "success", "comment { id }"]) response = @graphql_client.mutation(query) response["data"]["commentCreate"]["comment"] end |
#create_issue(issue_data) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 133 def create_issue(issue_data) query = build_graphql_mutation("issueCreate", { input: { title: issue_data[:title], teamId: issue_data[:team_id], description: issue_data[:description], createAsUser: issue_data[:create_as_user], assigneeId: issue_data[:assignee_id], stateId: issue_data[:state_id], parentId: issue_data[:parent_id], createdAt: issue_data[:created_at], labelIds: issue_data[:label_ids], dueDate: issue_data[:due_date], sortOrder: issue_data[:sort_order] } }, ["lastSyncId", "success", "issue { id, url }"]) linear_issue = @graphql_client.mutation(query) linear_issue&.dig("data", "issueCreate", "issue") end |
#create_mr_link(linear_id, url, path, number, title) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 169 def create_mr_link(linear_id, url, path, number, title) query = build_graphql_mutation("attachmentLinkGitLabMR", { issueId: linear_id, url:, projectPathWithNamespace: path, number:, title: }, %w[lastSyncId success]) @graphql_client.mutation(query) end |
#create_url_link(linear_id, url, title = nil) ⇒ Object
181 182 183 184 185 186 187 188 189 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 181 def create_url_link(linear_id, url, title = nil) query = build_graphql_mutation("attachmentLinkURL", { issueId: linear_id, url:, title: }, %w[lastSyncId success]) @graphql_client.mutation(query) end |
#find_label(label) ⇒ Object
101 102 103 104 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 101 def find_label(label) response = @graphql_client.query(FIND_LABEL_QUERY, { label: }) response["data"]["issueLabels"]["nodes"].first["id"] end |
#find_linear_issue_by_gitlab_url(gitlab_url) ⇒ Object
128 129 130 131 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 128 def find_linear_issue_by_gitlab_url(gitlab_url) response = @graphql_client.query(FIND_LINEAR_ISSUE_BY_GITLAB_URL_QUERY, { gitlabUrl: gitlab_url }) response["data"]["issueSearch"]["nodes"].first["id"] end |
#get_team_by_name(name) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 121 def get_team_by_name(name) response = @graphql_client.query(GET_TEAM_BY_NAME_QUERY, { name: }) raise StandardError, "Team #{name} not found in Linear." if response["data"]["teams"]["nodes"].empty? response["data"]["teams"]["nodes"].first end |
#get_user_id_by_email(email) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 114 def get_user_id_by_email(email) return nil if email.nil? || email.empty? response = @graphql_client.query(GET_USER_ID_BY_EMAIL_QUERY, { email: }) response["data"]["users"]["nodes"].first["id"] end |
#list_labels(labels, team_id) ⇒ Object
110 111 112 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 110 def list_labels(labels, team_id) @graphql_client.query(LIST_LABELS_QUERY, { labels:, teamId: team_id }) end |
#update_labels(issue_id, labels) ⇒ Object
106 107 108 |
# File 'lib/gitlab/triage/linear/migrator/linear_interface.rb', line 106 def update_labels(issue_id, labels) @graphql_client.mutation(UPDATE_LABELS_MUTATION, { issueId: issue_id, labels: }) end |