Module: Linear::Commands
Instance Method Summary collapse
- #add_comment(issue_id, body, client: Client.new) ⇒ Object
- #fetch_issue(issue_id, client: Client.new) ⇒ Object
- #list_issues(options = {}, client: Client.new) ⇒ Object
- #list_projects(client: Client.new) ⇒ Object
- #list_teams(client: Client.new) ⇒ Object
- #my_issues(client: Client.new) ⇒ Object
- #update_issue_description(issue_id, description, client: Client.new) ⇒ Object
- #update_issue_state(issue_id, state_name, client: Client.new) ⇒ Object
Instance Method Details
#add_comment(issue_id, body, client: Client.new) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/linear/commands.rb', line 64 def add_comment(issue_id, body, client: Client.new) # First get the issue to get its internal ID 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 result = client.query(Queries::CREATE_COMMENT, { issueId: issue['id'], body: body }) if result.dig("data", "commentCreate", "success") puts "Comment added to #{issue_id}" else puts "Error: Failed to add comment" end end |
#fetch_issue(issue_id, client: Client.new) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/linear/commands.rb', line 5 def fetch_issue(issue_id, client: Client.new) result = client.query(Queries::ISSUE, { id: issue_id }) issue = result.dig("data", "issue") if issue display_issue(issue) else puts "Issue not found: #{issue_id}" end end |
#list_issues(options = {}, client: Client.new) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/linear/commands.rb', line 16 def list_issues( = {}, client: Client.new) filter = {} filter[:title] = { contains: [:query] } if [:query] filter[:project] = { id: { eq: [:project] } } if [:project] filter[:state] = { name: { eqIgnoreCase: [:state] } } if [:state] filter[:team] = { key: { eq: [:team] } } if [:team] result = client.query(Queries::LIST_ISSUES, { filter: filter }) issues = result.dig("data", "issues", "nodes") || [] if issues.empty? puts "No issues found" else display_issue_list(issues) end end |
#list_projects(client: Client.new) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/linear/commands.rb', line 53 def list_projects(client: Client.new) result = client.query(Queries::PROJECTS) projects = result.dig("data", "projects", "nodes") || [] if projects.empty? puts "No projects found" else display_project_list(projects) end end |
#list_teams(client: Client.new) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/linear/commands.rb', line 44 def list_teams(client: Client.new) result = client.query(Queries::TEAMS) teams = result.dig("data", "teams", "nodes") || [] teams.each do |team| puts "#{team['key'].ljust(10)} #{team['name']}" end end |
#my_issues(client: Client.new) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/linear/commands.rb', line 33 def my_issues(client: Client.new) result = client.query(Queries::MY_ISSUES) issues = result.dig("data", "viewer", "assignedIssues", "nodes") || [] if issues.empty? puts "No issues assigned to you" else display_issue_list(issues) end end |
#update_issue_description(issue_id, description, client: Client.new) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/linear/commands.rb', line 135 def update_issue_description(issue_id, description, client: Client.new) # Get the issue to get its internal ID 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 # Update the issue description result = client.query(Queries::UPDATE_ISSUE, { issueId: issue['id'], description: description }) if result.dig("data", "issueUpdate", "success") puts "Updated #{issue_id} description" else puts "Error: Failed to update issue description" end end |
#update_issue_state(issue_id, state_name, client: Client.new) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/linear/commands.rb', line 86 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 |