Module: Linear::Commands::UpdateIssueState

Extended by:
UpdateIssueState
Included in:
Linear::Commands, UpdateIssueState
Defined in:
lib/linear/commands/update_issue_state.rb

Instance Method Summary collapse

Instance Method Details

#update_issue_state(issue_id, state_name, 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
# File 'lib/linear/commands/update_issue_state.rb', line 6

def update_issue_state(issue_id, state_name, client: Client.new)
  # Get the issue details including team
  issue_result = client.query(Queries::ISSUE, { id: issue_id })
  issue = issue_result.dig("data", "issue")

  unless issue
    puts "Error: Issue not found: #{issue_id}"
    return
  end

  # Get team states - need to find team ID first
  teams_result = client.query(Queries::TEAMS)
  teams = teams_result.dig("data", "teams", "nodes") || []

  # Find the team from the issue identifier prefix (e.g., "FAT" from "FAT-85")
  team_key = issue_id.split('-').first
  team = teams.find { |t| t['key'] == team_key }

  unless team
    puts "Error: Team not found for issue #{issue_id}"
    return
  end

  # Get workflow states for the team
  states_result = client.query(Queries::WORKFLOW_STATES, { teamId: team['id'] })
  states = states_result.dig("data", "team", "states", "nodes") || []

  # Find the state by name (case-insensitive)
  target_state = states.find { |s| s['name'].downcase == state_name.downcase }

  unless target_state
    puts "Error: State '#{state_name}' not found. Available states:"
    states.each { |s| puts "  - #{s['name']}" }
    return
  end

  # Update the issue
  result = client.query(Queries::UPDATE_ISSUE, {
    issueId: issue['id'],
    stateId: target_state['id']
  })

  if result.dig("data", "issueUpdate", "success")
    puts "Updated #{issue_id} to '#{target_state['name']}'"
  else
    puts "Error: Failed to update issue state"
  end
end