Skip to content

Commit

Permalink
Improve Linear issue menu
Browse files Browse the repository at this point in the history
  • Loading branch information
codener committed Nov 22, 2024
1 parent b447e90 commit 453076a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 36 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
### Compatible changes
* Add support for default branches other than "master" (e.g. "main"). Will read
this information from `origin`.
* `geordi branch` will not fail if it can't determine local branches.
* Improved Linear issue menu: now includes the issue id, truncates long issue
titles and puts metadata last


## 11.1.0 2024-11-20
Expand Down
5 changes: 0 additions & 5 deletions features/branch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,3 @@ Feature: Check out a feature branch based on an issue from Linear

When I run `geordi branch`
Then the output should contain "Util.run! git, checkout, testuser/team-123-test-issue"


Scenario: The command fails if local Git branches can not be determined
When I run `geordi branch`
Then the output should contain "Could not determine local Git branches"
50 changes: 21 additions & 29 deletions lib/geordi/gitlinear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ def local_branch_names
`git branch --format="%(refname:short)"`
end

if branch_list_string.strip.empty?
Interaction.fail 'Could not determine local Git branches.'
end

branch_list_string.split("\n")
branch_list_string.strip.split("\n")
end
end

Expand All @@ -65,42 +61,36 @@ def choose_issue
return dummy_issue_for_testing
end

loading_message = 'Connecting to Linear ...'
print(loading_message)
issues = fetch_linear_issues
reset_loading_message = "\r#{' ' * (loading_message.length + issues.length)}\r"

if issues.empty?
print reset_loading_message
Geordi::Interaction.fail('No issues to offer.')
end
issues.sort_by! { |i| -i.dig('state', 'position') }

highline.choose do |menu|
menu.header = 'Choose an issue'
max_label_length = 60
menu.header = 'Choose a started issue (ordered by state)'

issues.each do |issue|
id = issue['identifier']
title = issue['title']
state = issue['state']['name']
if issue['assignee']
assignee = issue['assignee']['name']
assignee_is_me = issue['assignee']['isMe']
else
assignee = "unassigned"
assignee_is_me = false
end

state += HighLine::BOLD if assignee_is_me
assignee = issue.dig('assignee', 'displayName') || 'unassigned'

label = "(#{assignee}, #{state}) #{issue['title']}"
label = bold(label) if assignee_is_me
label = "[#{id}] #{title}"
label = "#{label[0..(max_label_length - 5)]} ..." if label.length > max_label_length
label = HighLine::BLUE + HighLine::BOLD + label + HighLine::RESET if issue.dig('assignee', 'isMe')
label = "#{label} (#{assignee} / #{state})"

menu.choice(label) { return issue }
end

menu.hidden('') { Interaction.fail('No issue selected.') }
print reset_loading_message # Once menu is build
end

nil # Return nothing
# Selecting an issue will return that issue. If we ever get here, return
# nothing
nil
end

def dummy_issue_for_testing
Expand Down Expand Up @@ -144,11 +134,12 @@ def fetch_linear_issues
url
branchName
assignee {
name
displayName
isMe
}
state {
name
name
position
}
}
}
Expand All @@ -160,7 +151,10 @@ def fetch_linear_issues

def query_api(attributes, variables)
uri = URI(API_ENDPOINT)
loading_message = "Connecting to #{uri.host} ... "
clear_loading_message = "\r#{' ' * loading_message.length}\r"

print(loading_message)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true

Expand All @@ -173,6 +167,7 @@ def query_api(attributes, variables)
request['Authorization'] = settings.linear_api_key

response = https.request(request)
print clear_loading_message

parsed_response = JSON.parse(response.body)[0]
if parsed_response.key?('errors')
Expand All @@ -182,8 +177,5 @@ def query_api(attributes, variables)
end
end

def bold(string)
HighLine::BOLD + string + HighLine::RESET
end
end
end
4 changes: 2 additions & 2 deletions lib/geordi/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def linear_team_ids

if team_ids.empty?
Geordi::Interaction.warn 'No team id found.'
Interaction.note 'Please open a team in Linear, open the command menu with CTRL + K and choose'
Interaction.note "\"Copy model UUID\". Store that team id in #{LOCAL_SETTINGS_FILE_NAME}:"
puts 'Please open a team in Linear, open the command menu with CTRL + K and choose'
puts "\"Copy model UUID\". Store that team id in #{LOCAL_SETTINGS_FILE_NAME}:"
puts 'linear_team_ids: abc-123-123-abc, def-456-456-def'
exit 1
end
Expand Down

0 comments on commit 453076a

Please sign in to comment.