Module: Rubyists::Linear::CLI::Issue

Includes:
SubCommands
Included in:
Create, Develop, Pr, Take, Update
Defined in:
lib/linear/commands/issue.rb,
lib/linear/commands/issue/pr.rb,
lib/linear/commands/issue/list.rb,
lib/linear/commands/issue/take.rb,
lib/linear/commands/issue/create.rb,
lib/linear/commands/issue/update.rb,
lib/linear/commands/issue/develop.rb

Overview

The Issue module is the namespace for all issue-related commands, and should be included in any command that deals with issues

Defined Under Namespace

Classes: Create, Develop, List, Pr, Take, Update

Constant Summary collapse

DESCRIPTION =
'Manage issues'
ALIASES =

Aliases for Issue commands

{
  create: %w[c new add], # aliases for the create command
  develop: %w[d dev],    # aliases for the develop command
  list: %w[l ls],        # aliases for the list command
  update: %w[u],         # aliases for the close command
  pr: %w[pull-request],  # aliases for the pr command
  issue: %w[i issues]    # aliases for the main issue command itself
}.freeze

Constants included from WhatFor

WhatFor::ALLOWED_PR_TYPES, WhatFor::PR_TYPES, WhatFor::PR_TYPE_SELECTIONS

Instance Method Summary collapse

Methods included from SubCommands

#ask_for_team, #branch_for, #choose_a_team!, #current_branch, #default_branch, #git, included, #prompt, #pull_or_push_new_branch!

Methods included from WhatFor

#ask_for_projects, #ask_or_edit, #cancelled_state_for, #comment_for, #completed_state_for, #description_for, #editor_for, #labels_for, #pr_description_for, #pr_scope_for, #pr_title_for, #pr_type_for, #project_for, #project_scores, #reason_for, #team_for, #title_for

Instance Method Details

#attach_project(issue, project_search) ⇒ Object



67
68
69
70
71
# File 'lib/linear/commands/issue.rb', line 67

def attach_project(issue, project_search)
  project = project_for(issue.team, project_search)
  issue.attach_to_project project
  prompt.ok "#{issue.identifier} was attached to #{project.name}"
end

#cancel_issue(issue, **options) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/linear/commands/issue.rb', line 36

def cancel_issue(issue, **options)
  reason = reason_for(options[:reason], four: "cancelling #{issue.identifier} - #{issue.title}")
  issue_comment issue, reason
  cancel_state = cancelled_state_for(issue)
  issue.close! state: cancel_state, trash: options[:trash]
  prompt.ok "#{issue.identifier} was cancelled"
end

#close_issue(issue, **options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/linear/commands/issue.rb', line 44

def close_issue(issue, **options)
  cancelled = options[:cancel]
  doing = cancelled ? 'cancelling' : 'closing'
  done = cancelled ? 'cancelled' : 'closed'
  workflow_state = cancelled ? cancelled_state_for(issue) : completed_state_for(issue)
  reason = reason_for(options[:reason], four: "#{doing} *#{issue.identifier} - #{issue.title}*")
  issue_comment issue, reason
  issue.close! state: workflow_state, trash: options[:trash]
  prompt.ok "#{issue.identifier} was #{done}"
end

#create_pr!(title:, body:) ⇒ Object



55
56
57
58
59
# File 'lib/linear/commands/issue.rb', line 55

def create_pr!(title:, body:)
  return `gh pr create -a @me --title "#{title}" --body-file "#{body.path}"` if body.respond_to?(:path)

  `gh pr create -a @me --title "#{title}" --body "#{body}"`
end

#gimme_da_issue!(issue_id, me: Rubyists::Linear::User.me) ⇒ Object

rubocop:disable Naming/MethodParameterName



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/linear/commands/issue.rb', line 95

def gimme_da_issue!(issue_id, me: Rubyists::Linear::User.me) # rubocop:disable Naming/MethodParameterName
  logger.trace('Looking up issue', issue_id:, me:)
  issue = Rubyists::Linear::Issue.find(issue_id)
  if issue.assignee && issue.assignee.id == me.id
    prompt.say "You are already assigned #{issue_id}"
    return issue
  end

  prompt.say "Assigning issue #{issue_id} to ya"
  updated = issue.assign!(me)
  logger.trace 'Issue taken', issue: updated
  updated
end

#issue_comment(issue, comment) ⇒ Object



31
32
33
34
# File 'lib/linear/commands/issue.rb', line 31

def issue_comment(issue, comment)
  issue.add_comment comment_for(issue, comment)
  prompt.ok "Comment added to #{issue.identifier}"
end

#issue_pr(issue, **options) ⇒ Object



61
62
63
64
65
# File 'lib/linear/commands/issue.rb', line 61

def issue_pr(issue, **options)
  title = options[:title] || pr_title_for(issue)
  body = options[:description] || pr_description_for(issue)
  prompt.warn create_pr!(title:, body:)
end

#make_da_issue!(**options) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/linear/commands/issue.rb', line 85

def make_da_issue!(**options)
  # These *_for methods are defined in Rubyists::Linear::CLI::SubCommands
  title = title_for(options[:title])
  description = description_for(options[:description])
  team = team_for(options[:team])
  labels = labels_for(team, options[:labels])
  project = project_for(team, options[:project])
  Rubyists::Linear::Issue.create(title:, description:, team:, labels:, project:)
end

#update_issue(issue, **options) ⇒ Object

rubocop:disable Metrics/AbcSize



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/linear/commands/issue.rb', line 73

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]

  prompt.warn 'No action taken, no options specified'
  prompt.ok 'Issue was not updated'
end