Class: Gitlab::Triage::Linear::Migrator::LinearConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/triage/linear/migrator/linear_connector.rb

Overview

Connects to Linear and creates stuff.

Constant Summary collapse

MIGRATION_LABEL_NAME =
"Migrated from GitLab"
MIGRATION_IN_PROGRESS_LABEL_NAME =
"Migrating from GitLab - in progress"
MIGRATION_LABEL_NAME_DRY_RUN =
"Migrated from GitLab (DRY-RUN)"
MIGRATION_IN_PROGRESS_LABEL_NAME_DRY_RUN =
"Migrating from GitLab - in progress (DRY-RUN)"
LINEAR_STATE_MAP =
{
  "Inbox" => nil,
  "InProgress" => "In Progress",
  "OnHold" => "Blocked",
  "PendingRelease" => "Pending Release",
  "Planned" => "Planned",
  "Review" => "In Review",
  "Candidate" => "Candidate",
  "Blocked" => "Blocked",
  "Closed" => "Done",
  "Testing" => "Testing",
  "NeedsQA" => "Needs QA",
  "DesignReview" => "Design Review",
  "CodeReview" => "Code Review",
  "ReadyForDev" => "Planned"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gitlab_dry_run: false, linear_dry_run: false, client: nil, interface: nil, team_label_prefix: "Team") ⇒ LinearConnector

Returns a new instance of LinearConnector.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gitlab/triage/linear/migrator/linear_connector.rb', line 35

def initialize(gitlab_dry_run: false, linear_dry_run: false, client: nil, interface: nil, team_label_prefix: "Team")
  @gitlab_dry_run = gitlab_dry_run
  @linear_dry_run = linear_dry_run
  @team_label_prefix = team_label_prefix

  # @todo: Find a better solution to set the Linear API token.
  @graphql_client = client || GraphqlClient.new("https://api.linear.app/graphql", {
                                                  "Authorization" => ENV.fetch("LINEAR_API_TOKEN", nil)
                                                }, dry_run: @linear_dry_run)
  @id_map = []

  @query_count = 0
  @mutation_count = 0
  @query_count_by_function = []

  @linear_interface = interface || LinearInterface.new(graphql_client: @graphql_client)
end

Instance Attribute Details

#gitlab_dry_runObject

Returns the value of attribute gitlab_dry_run.



53
54
55
# File 'lib/gitlab/triage/linear/migrator/linear_connector.rb', line 53

def gitlab_dry_run
  @gitlab_dry_run
end

#linear_dry_runObject

Returns the value of attribute linear_dry_run.



54
55
56
# File 'lib/gitlab/triage/linear/migrator/linear_connector.rb', line 54

def linear_dry_run
  @linear_dry_run
end

#team_label_prefixObject

Returns the value of attribute team_label_prefix.



53
54
55
# File 'lib/gitlab/triage/linear/migrator/linear_connector.rb', line 53

def team_label_prefix
  @team_label_prefix
end

Instance Method Details

#import_comments(_gitlab_issue, discussions, linear_id) ⇒ Object



85
86
87
88
89
# File 'lib/gitlab/triage/linear/migrator/linear_connector.rb', line 85

def import_comments(_gitlab_issue, discussions, linear_id)
  discussions.each do |discussion|
    process_discussion(discussion["notes"], linear_id) if valid_discussion?(discussion["notes"])
  end
end

#import_issue(gitlab_issue, set_state: false, project_name: nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gitlab/triage/linear/migrator/linear_connector.rb', line 61

def import_issue(gitlab_issue, set_state: false, project_name: nil)
  linear_team_data = fetch_linear_team_data(gitlab_issue)
  linear_label_ids = get_linear_label_ids(gitlab_issue.labels, linear_team_data["id"])

  issue_data = prepare_issue_data(gitlab_issue, linear_label_ids, linear_team_data, project_name, set_state)
  issue_created = @linear_interface.create_issue(issue_data)

  return unless issue_created

  if gitlab_issue.instance_of?(Gitlab::Triage::Resource::Issue)
    import_mr_links(gitlab_issue,
                    issue_created["id"])
  end

  import_comments(gitlab_issue, gitlab_issue.discussions, issue_created["id"])

  if issue_created
    handle_post_creation_tasks(gitlab_issue, issue_created["id"], issue_data["parent_id"], linear_label_ids,
                               issue_created["url"])
  end

  issue_created
end