Skip to content

Commit f0f817d

Browse files
committed
We have issue creation now. \o/
1 parent 7e4e0bc commit f0f817d

5 files changed

Lines changed: 45 additions & 3 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
linear-cli (0.3.11)
4+
linear-cli (0.3.12)
55
base64 (~> 0.2)
66
dry-cli (~> 1.0)
77
dry-cli-completion (~> 1.0)

lib/linear/commands/issue.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Issue
1212
include CLI::SubCommands
1313
# Aliases for Issue commands
1414
ALIASES = {
15-
create: %w[new add c], # aliases for the create command
15+
create: %w[c new add], # aliases for the create command
1616
list: %w[l ls], # aliases for the list command
1717
show: %w[s view v display d], # aliases for the show command
1818
issue: %w[i issues] # aliases for the main issue command itself
@@ -23,6 +23,7 @@ def make_da_issue!(**options)
2323
title = title_for options[:title]
2424
description = description_for options[:description]
2525
team = team_for options[:team]
26+
require 'pry'; binding.pry
2627
labels = labels_for team, options[:labels]
2728
Rubyists::Linear::Issue.create(title:, description:, team:, labels:)
2829
end

lib/linear/commands/issue/create.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def call(**options)
2525
logger.debug('Creating issue', options:)
2626
issue = make_da_issue!(**options)
2727
logger.debug('Issue created', issue:)
28+
prompt.yes?('Do you want to take this issue?') && gimme_da_issue!(issue.id, User.me)
29+
display issue, options
2830
end
2931
end
3032
end

lib/linear/models/issue.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ def find(slug)
3434

3535
new(data[:issue])
3636
end
37+
38+
def create(title:, description:, team:, labels: [])
39+
team_id = team.id
40+
label_ids = labels.map(&:id)
41+
input = { title:, description:, teamId: team_id }
42+
input.merge!(labelIds: label_ids) unless label_ids.empty?
43+
m = mutation { issueCreate(input:) { issue { ___ Base } } }
44+
data = Api.query(m)
45+
new(data[:issueCreate][:issue])
46+
end
3747
end
3848

3949
def assign!(user)

lib/linear/models/team.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ module Linear
1212
class Team
1313
include SemanticLogger::Loggable
1414

15+
# TODO: Make this configurable
16+
IgnoredLabels = [/-ios$/, /-android$/].freeze # rubocop:disable Naming/ConstantName
17+
1518
Base = fragment('BaseTeam', 'Team') do
1619
description
1720
id
@@ -44,8 +47,34 @@ def full
4447
format('%<key>-6s %<to_s>s', key:, to_s:)
4548
end
4649

50+
def label_query
51+
team_id = id
52+
query do
53+
team(id: team_id) do
54+
labels do
55+
nodes { ___ Label::Base }
56+
end
57+
end
58+
end
59+
end
60+
61+
def label_filter(labels = nil)
62+
return [] unless labels
63+
64+
labels.reject { |label| IgnoredLabels.detect { |i| label.name.match? i } }
65+
end
66+
67+
def labels
68+
return @labels if @labels && !@labels.empty?
69+
70+
all = Api.query(label_query).dig(:team, :labels, :nodes)&.map do |label|
71+
Label.new label
72+
end
73+
@labels = label_filter(all)
74+
end
75+
4776
def members
48-
return @members unless @members.empty?
77+
return @members if @members && !@members.empty?
4978

5079
q = query do
5180
team(id:) do

0 commit comments

Comments
 (0)