Skip to content

Commit

Permalink
Corrects the editor_for method to fix the tempfile prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
bougyman committed Feb 7, 2024
1 parent eba4702 commit e9464d6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
linear-cli (0.9.1)
linear-cli (0.9.2)
base64 (~> 0.2)
dry-cli (~> 1.0)
dry-cli-completion (~> 1.0)
Expand Down
4 changes: 4 additions & 0 deletions lib/linear/cli/sub_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def current_branch
git.current_branch
end

def branch_for(branch_name)
git.branches.local.detect { |b| b.name == branch_name } || git.branch(branch_name)
end

# Horrible way to do this, but it is working for now
def pull_or_push_new_branch!(branch_name)
git.pull
Expand Down
6 changes: 3 additions & 3 deletions lib/linear/cli/what_for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def ask_or_edit(thing, question)
answer = prompt.ask("#{question}: ('-' to open an editor)", default: '-')
return answer unless answer == '-'

answer = editor_for [thing, '.md']
answer = editor_for [question.downcase, '.md']
raise SmellsBad, "No content provided for #{question}" if answer.empty?

answer
Expand All @@ -78,11 +78,11 @@ 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)
def project_for(team, project = nil) # rubocop:disable Metrics/AbcSize
projects = team.projects
return nil if projects.empty?

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

first = possibles.first
Expand Down
31 changes: 31 additions & 0 deletions lib/linear/models/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'gqli'

module Rubyists
# Namespace for Linear
module Linear
M :base_model
Comment = Class.new(BaseModel)
# The Comment class represents a Linear issue comment.
class Comment
include SemanticLogger::Loggable

Base = fragment('BaseComment', 'Comment') do
id
body
url
createdAt
updatedAt
end

def to_s
format('%<id>-12s %<url>s', id:, url:)
end

def inspection
format('id: "%<id>s" url: "%<url>s"', id:, url:)
end
end
end
end
13 changes: 11 additions & 2 deletions lib/linear/models/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Issue
include SemanticLogger::Loggable
extend ClassMethods
many_to_one :assignee, :User
many_to_one :team, :Team
many_to_one :team
one_to_many :comments

BASIC_FILTER = { completedAt: { null: true } }.freeze

Expand Down Expand Up @@ -117,9 +118,17 @@ def parsed_description
"Description was unparsable: #{description}\n"
end

def display_comments
comments.map { |c| "--- #{c.createdAt} ---\n#{TTY::Markdown.parse(c.body)}" }.join("\n")
end

def full
sep = '-' * to_s.length
format("%<to_s>s\n%<sep>s\n%<description>s\n", sep:, to_s:, description: parsed_description)
format("%<to_s>s\n%<sep>s\n%<description>s\n%<comments>s",
sep:,
to_s:,
description: parsed_description,
comments: display_comments)
end

def display(options)
Expand Down
3 changes: 2 additions & 1 deletion lib/linear/models/issue/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Rubyists
# Namespace for Linear
module Linear
M :user, :team
M :user, :team, :comment
# The Issue class represents a Linear issue.
class Issue
# Class methods for Issue
Expand All @@ -21,6 +21,7 @@ def full_fragment
___ Base
assignee { ___ User.full_fragment }
team { ___ Team.full_fragment }
comments { nodes { ___ Comment.base_fragment } }
end
end

Expand Down

0 comments on commit e9464d6

Please sign in to comment.