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(issue_id, state: nil, title: nil, description: nil, 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(issue_id, state: nil, title: nil, description: nil, 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/linear/commands.rb', line 86 def update_issue(issue_id, state: nil, title: nil, description: nil, client: Client.new) # 1. Validate at least one change provided if state.nil? && title.nil? && description.nil? puts "Error: At least one of --state, --title, or --description must be provided" return end # 2. Fetch issue to get internal UUID 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 # 3. If state provided, resolve state ID (existing logic) state_id = nil target_state = nil if state team_key = issue_id.split('-').first teams_result = client.query(Queries::TEAMS) teams = teams_result.dig("data", "teams", "nodes") || [] 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.downcase } unless target_state puts "Error: State '#{state}' not found. Available states:" states.each { |s| puts " - #{s['name']}" } return end state_id = target_state['id'] end # 4. Build mutation parameters params = { issueId: issue['id'] } params[:stateId] = state_id if state_id params[:title] = title if title params[:description] = description if description # 5. Execute mutation result = client.query(Queries::UPDATE_ISSUE, params) # 6. Display results if result.dig("data", "issueUpdate", "success") changes = [] changes << "state to '#{target_state['name']}'" if state changes << "title" if title changes << "description" if description puts "Updated #{issue_id}: #{changes.join(', ')}" else puts "Error: Failed to update issue" end end |