From 453076a71b234f9ff02e766b1851dbbee9b43f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=B6ler?= Date: Fri, 22 Nov 2024 10:28:43 +0100 Subject: [PATCH] Improve Linear issue menu --- CHANGELOG.md | 3 +++ features/branch.feature | 5 ----- lib/geordi/gitlinear.rb | 50 +++++++++++++++++------------------------ lib/geordi/settings.rb | 4 ++-- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9f8d55..55dd2e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/features/branch.feature b/features/branch.feature index 748cd56..a6678a2 100644 --- a/features/branch.feature +++ b/features/branch.feature @@ -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" diff --git a/lib/geordi/gitlinear.rb b/lib/geordi/gitlinear.rb index d79fd3b..2ea2dc2 100644 --- a/lib/geordi/gitlinear.rb +++ b/lib/geordi/gitlinear.rb @@ -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 @@ -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 @@ -144,11 +134,12 @@ def fetch_linear_issues url branchName assignee { - name + displayName isMe } state { - name + name + position } } } @@ -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 @@ -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') @@ -182,8 +177,5 @@ def query_api(attributes, variables) end end - def bold(string) - HighLine::BOLD + string + HighLine::RESET - end end end diff --git a/lib/geordi/settings.rb b/lib/geordi/settings.rb index 8a8cea9..7e390b4 100644 --- a/lib/geordi/settings.rb +++ b/lib/geordi/settings.rb @@ -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