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)
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
teams_result = client.query(Queries::TEAMS)
teams = teams_result.dig("data", "teams", "nodes") || []
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
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 == state_name.downcase }
unless target_state
puts "Error: State '#{state_name}' not found. Available states:"
states.each { |s| puts " - #{s['name']}" }
return
end
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
|