Module: Linear::Commands::CreateIssue

Extended by:
CreateIssue
Included in:
Linear::Commands, CreateIssue
Defined in:
lib/linear/commands/create_issue.rb

Instance Method Summary collapse

Instance Method Details

#create_issue(options, client: Client.new) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/linear/commands/create_issue.rb', line 6

def create_issue(options, client: Client.new)
  # Get team ID from team key
  teams_result = client.query(Queries::TEAMS)
  teams = teams_result.dig("data", "teams", "nodes") || []
  team = teams.find { |t| t['key'].upcase == options[:team].upcase }

  unless team
    puts "Error: Team '#{options[:team]}' not found. Available teams:"
    teams.each { |t| puts "  #{t['key']} - #{t['name']}" }
    return
  end

  variables = {
    teamId: team['id'],
    title: options[:title]
  }

  # Add optional description
  variables[:description] = options[:description] if options[:description]

  # Add optional project
  variables[:projectId] = options[:project] if options[:project]

  # Handle priority (convert string to integer if needed)
  if options[:priority]
    variables[:priority] = options[:priority].to_i
  end

  # Handle state (need to look up state ID from name)
  if options[:state]
    states_result = client.query(Queries::WORKFLOW_STATES, { teamId: team['id'] })
    states = states_result.dig("data", "team", "states", "nodes") || []
    target_state = states.find { |s| s['name'].downcase == options[:state].downcase }

    if target_state
      variables[:stateId] = target_state['id']
    else
      puts "Warning: State '#{options[:state]}' not found, using default"
    end
  end

  # Handle assignee (need to look up user ID from email)
  if options[:assignee]
    # Would need a new USER_BY_EMAIL query
    puts "Warning: Assignee lookup not yet implemented"
  end

  # Create the issue
  result = client.query(Queries::CREATE_ISSUE, variables)

  if result.dig("data", "issueCreate", "success")
    issue = result.dig("data", "issueCreate", "issue")
    puts "Created issue: #{issue['identifier']}"
    puts "Title: #{issue['title']}"
    puts "URL: #{issue['url']}"
  else
    puts "Error: Failed to create issue"
  end
end