Skip to content

Commit

Permalink
Corrects the handling of issue cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
bougyman committed Apr 12, 2024
1 parent a7bb252 commit 7024cd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/linear/commands/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def issue_comment(issue, comment)
def cancel_issue(issue, **options)
reason = reason_for(options[:reason], four: "cancelling #{issue.identifier} - #{issue.title}")
issue_comment issue, reason
cancel_state = cancel_state_for(issue)
cancel_state = cancelled_state_for(issue)
issue.close! state: cancel_state, trash: options[:trash]
prompt.ok "#{issue.identifier} was cancelled"
end
Expand Down Expand Up @@ -70,9 +70,10 @@ def attach_project(issue, project_search)
prompt.ok "#{issue.identifier} was attached to #{project.name}"
end

def update_issue(issue, **options)
def update_issue(issue, **options) # rubocop:disable Metrics/AbcSize
issue_comment(issue, options[:comment]) if options[:comment]
return close_issue(issue, **options) if options[:close]
return cancel_issue(issue, **options) if options[:cancel]
return issue_pr(issue) if options[:pr]
return attach_project(issue, options[:project]) if options[:project]
return if options[:comment]
Expand Down
12 changes: 9 additions & 3 deletions lib/linear/models/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,22 @@ def add_comment(comment)
def close_mutation(close_state, trash: false)
id_for_this = identifier
input = { stateId: close_state.id }
input[:trash] = true if trash
input[:trashed] = true if trash
mutation { issueUpdate(id: id_for_this, input:) { issue { ___ Issue.full_fragment } } }
end

def close!(state: nil, trash: false)
def close!(state: nil, trash: false) # rubocop:disable Metrics/MethodLength
logger.warn "Using first completed state found: #{completed_states.first}" if state.nil?
state ||= completed_states.first
query_data = Api.query close_mutation(state, trash:)
unless query_data.respond_to?(:dig)
raise SmellsBad, "Unknown response (#{query_data || "NULL"}) updating #{self} to #{state}, trash: #{trash}"
end

updated = query_data.dig(:issueUpdate, :issue)
raise SmellsBad, "Unknown response for issue close: #{data} (should have :issueUpdate key)" if updated.nil?
if updated.nil?
raise SmellsBad, "Unknown response for issue close: #{query_data} (should have :issueUpdate key)"
end

@data = @updated_data = updated
self
Expand Down

0 comments on commit 7024cd3

Please sign in to comment.