Skip to content

Commit 72eeb05

Browse files
xunkerbougyman
andauthored
Filter issue list by project (#7)
* add --project filter * WIP support methods for filtering issue list by Project * Allow projects to be found with ID or URL as well * move project finder methods to separate module * Use the new common project finder methods in CLI::Projects * Appease the cyclic complexity gods * tests around Project#match_score? * Need to include CLI::SubCommands here to get #prompt support * improve comment * Abstract #project_for so it can be used in both Listing Issues and Creating Issues * removed by rubocop * prefer #fetch so we know if we try to query on a nonexistant key * remove the safe-nav operator that could end up doing the exact opposite of what I want * chore: Remove Gemfile.lock * fix(linting): Corrects rubocop offenses --------- Co-authored-by: Tj (bougyman) Vanderpoel <[email protected]>
1 parent c4c4349 commit 72eeb05

File tree

10 files changed

+121
-288
lines changed

10 files changed

+121
-288
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
# dotenv
1515
.envrc
1616

17-
# built gems
17+
# Gem stuff/Gemfile.lock
1818
*.gem
19+
Gemfile.lock

Gemfile.lock

Lines changed: 0 additions & 252 deletions
This file was deleted.

lib/linear.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def self.verbosity=(debug)
5353
@verbosity = debug
5454
level = @verbosity > (DEBUG_LEVELS.size - 1) ? :trace : DEBUG_LEVELS[@verbosity]
5555
SemanticLogger.default_level = level
56-
@verbosity
5756
end
5857
end
5958
end

lib/linear/cli/projects.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
module Rubyists
4+
module Linear
5+
module CLI
6+
# The Project module contains support for finding and selecting projects
7+
# as part of a filter or query
8+
module Projects
9+
def ask_for_projects(projects, search: true)
10+
prompt.warn("No project found matching #{search}.") if search
11+
return projects.first if projects.size == 1
12+
13+
prompt.select('Project:', projects.to_h { |p| [p.name, p] })
14+
end
15+
16+
def project_scores(projects, search_term)
17+
projects.select { |p| p.match_score?(search_term).positive? }.sort_by { |p| p.match_score?(search_term) }
18+
end
19+
20+
def project_for(project = nil, projects: Project.all)
21+
return nil if projects.empty?
22+
23+
possibles = project ? project_scores(projects, project) : []
24+
return ask_for_projects(projects, search: project) if possibles.empty?
25+
26+
first = possibles.first
27+
return first if first.match_score?(project) == 100
28+
29+
selections = possibles + (projects - possibles)
30+
prompt.select('Project:', selections.to_h { |p| [p.name, p] }) if possibles.size.positive?
31+
end
32+
end
33+
end
34+
end
35+
end

lib/linear/cli/what_for.rb

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module Rubyists
44
module Linear
55
module CLI
66
# Module for the _for methods
7-
module WhatFor # rubocop:disable Metrics/ModuleLength
7+
module WhatFor
8+
include CLI::Projects # for methods called within #project_for
9+
810
# TODO: Make this configurable
911
PR_TYPES = {
1012
fix: 'Bug fixes',
@@ -87,31 +89,6 @@ def title_for(title = nil)
8789
prompt.ask('Title:')
8890
end
8991

90-
def ask_for_projects(projects, search: true)
91-
prompt.warn("No project found matching #{search}.") if search
92-
return projects.first if projects.size == 1
93-
94-
prompt.select('Project:', projects.to_h { |p| [p.name, p] })
95-
end
96-
97-
def project_scores(projects, search_term)
98-
projects.select { |p| p.match_score?(search_term).positive? }.sort_by { |p| p.match_score?(search_term) }
99-
end
100-
101-
def project_for(team, project = nil) # rubocop:disable Metrics/AbcSize
102-
projects = team.projects
103-
return nil if projects.empty?
104-
105-
possibles = project ? project_scores(projects, project) : []
106-
return ask_for_projects(projects, search: project) if possibles.empty?
107-
108-
first = possibles.first
109-
return first if first.match_score?(project) == 100
110-
111-
selections = possibles + (projects - possibles)
112-
prompt.select('Project:', selections.to_h { |p| [p.name, p] }) if possibles.size.positive?
113-
end
114-
11592
def pr_title_for(issue)
11693
proposed = [pr_type_for(issue)]
11794
proposed_scope = pr_scope_for(issue.title)

lib/linear/commands/issue.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def issue_pr(issue, **options)
6565
end
6666

6767
def attach_project(issue, project_search)
68-
project = project_for(issue.team, project_search)
68+
project = project_for(project_search, projects: issue.team.projects)
6969
issue.attach_to_project project
7070
prompt.ok "#{issue.identifier} was attached to #{project.name}"
7171
end
@@ -88,7 +88,7 @@ def make_da_issue!(**options)
8888
description = description_for(options[:description])
8989
team = team_for(options[:team])
9090
labels = labels_for(team, options[:labels])
91-
project = project_for(team, options[:project])
91+
project = project_for(options[:project], projects: team.projects)
9292
Rubyists::Linear::Issue.create(title:, description:, team:, labels:, project:)
9393
end
9494

0 commit comments

Comments
 (0)