Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter issue list by project #7

Merged
merged 15 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
# dotenv
.envrc

# built gems
# Gem stuff/Gemfile.lock
*.gem
Gemfile.lock
252 changes: 0 additions & 252 deletions Gemfile.lock

This file was deleted.

1 change: 0 additions & 1 deletion lib/linear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def self.verbosity=(debug)
@verbosity = debug
level = @verbosity > (DEBUG_LEVELS.size - 1) ? :trace : DEBUG_LEVELS[@verbosity]
SemanticLogger.default_level = level
@verbosity
end
end
end
35 changes: 35 additions & 0 deletions lib/linear/cli/projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module Rubyists
module Linear
module CLI
# The Project module contains support for finding and selecting projects
# as part of a filter or query
module Projects
def ask_for_projects(projects, search: true)
prompt.warn("No project found matching #{search}.") if search
return projects.first if projects.size == 1

prompt.select('Project:', projects.to_h { |p| [p.name, p] })
end

def project_scores(projects, search_term)
projects.select { |p| p.match_score?(search_term).positive? }.sort_by { |p| p.match_score?(search_term) }
end

def project_for(project = nil, projects: Project.all)
return nil if projects.empty?

possibles = project ? project_scores(projects, project) : []
return ask_for_projects(projects, search: project) if possibles.empty?

first = possibles.first
return first if first.match_score?(project) == 100

selections = possibles + (projects - possibles)
prompt.select('Project:', selections.to_h { |p| [p.name, p] }) if possibles.size.positive?
end
end
end
end
end
29 changes: 3 additions & 26 deletions lib/linear/cli/what_for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module Rubyists
module Linear
module CLI
# Module for the _for methods
module WhatFor # rubocop:disable Metrics/ModuleLength
module WhatFor
include CLI::Projects # for methods called within #project_for

# TODO: Make this configurable
PR_TYPES = {
fix: 'Bug fixes',
Expand Down Expand Up @@ -87,31 +89,6 @@ def title_for(title = nil)
prompt.ask('Title:')
end

def ask_for_projects(projects, search: true)
prompt.warn("No project found matching #{search}.") if search
return projects.first if projects.size == 1

prompt.select('Project:', projects.to_h { |p| [p.name, p] })
end

def project_scores(projects, search_term)
projects.select { |p| p.match_score?(search_term).positive? }.sort_by { |p| p.match_score?(search_term) }
end

def project_for(team, project = nil) # rubocop:disable Metrics/AbcSize
projects = team.projects
return nil if projects.empty?

possibles = project ? project_scores(projects, project) : []
return ask_for_projects(projects, search: project) if possibles.empty?

first = possibles.first
return first if first.match_score?(project) == 100

selections = possibles + (projects - possibles)
prompt.select('Project:', selections.to_h { |p| [p.name, p] }) if possibles.size.positive?
end

def pr_title_for(issue)
proposed = [pr_type_for(issue)]
proposed_scope = pr_scope_for(issue.title)
Expand Down
4 changes: 2 additions & 2 deletions lib/linear/commands/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def issue_pr(issue, **options)
end

def attach_project(issue, project_search)
project = project_for(issue.team, project_search)
project = project_for(project_search, projects: issue.team.projects)
issue.attach_to_project project
prompt.ok "#{issue.identifier} was attached to #{project.name}"
end
Expand All @@ -88,7 +88,7 @@ def make_da_issue!(**options)
description = description_for(options[:description])
team = team_for(options[:team])
labels = labels_for(team, options[:labels])
project = project_for(team, options[:project])
project = project_for(options[:project], projects: team.projects)
Rubyists::Linear::Issue.create(title:, description:, team:, labels:, project:)
end

Expand Down
Loading