geet 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +3 -3
  3. data/README.md +25 -24
  4. data/bin/geet +21 -3
  5. data/geet.gemspec +2 -2
  6. data/lib/geet/commandline/configuration.rb +5 -5
  7. data/lib/geet/git/repository.rb +34 -15
  8. data/lib/geet/services/abstract_create_issue.rb +33 -0
  9. data/lib/geet/services/create_gist.rb +6 -4
  10. data/lib/geet/services/create_issue.rb +33 -87
  11. data/lib/geet/services/create_label.rb +7 -6
  12. data/lib/geet/services/create_pr.rb +42 -86
  13. data/lib/geet/services/list_issues.rb +13 -14
  14. data/lib/geet/services/list_labels.rb +4 -3
  15. data/lib/geet/services/list_milestones.rb +12 -11
  16. data/lib/geet/services/list_prs.rb +4 -3
  17. data/lib/geet/services/merge_pr.rb +12 -11
  18. data/lib/geet/shared/constants.rb +9 -0
  19. data/lib/geet/utils/attributes_selection_manager.rb +87 -0
  20. data/lib/geet/utils/manual_list_selection.rb +41 -27
  21. data/lib/geet/utils/string_matching_selection.rb +32 -0
  22. data/lib/geet/version.rb +1 -1
  23. data/spec/integration/create_gist_spec.rb +4 -4
  24. data/spec/integration/create_issue_spec.rb +6 -6
  25. data/spec/integration/create_label_spec.rb +3 -3
  26. data/spec/integration/create_pr_spec.rb +13 -13
  27. data/spec/integration/list_issues_spec.rb +5 -5
  28. data/spec/integration/list_labels_spec.rb +3 -3
  29. data/spec/integration/list_milestones_spec.rb +2 -2
  30. data/spec/integration/list_prs_spec.rb +2 -2
  31. data/spec/integration/merge_pr_spec.rb +2 -2
  32. data/spec/vcr_cassettes/create_issue_upstream.yml +1 -1
  33. data/spec/vcr_cassettes/create_pr.yml +181 -102
  34. data/spec/vcr_cassettes/create_pr_in_auto_mode_create_upstream.yml +1 -1
  35. data/spec/vcr_cassettes/create_pr_in_auto_mode_with_push.yml +1 -1
  36. data/spec/vcr_cassettes/create_pr_upstream.yml +2 -2
  37. metadata +8 -5
  38. data/lib/geet/utils/pattern_matching_selection.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a73b4ce8509349204e7abc8c667856acf8baa421
4
- data.tar.gz: b94ef51efb18f859f7aa547cb718861a2ca03eeb
3
+ metadata.gz: e527c60073723a00c502f04f5546b599f708cb71
4
+ data.tar.gz: efd1663ae8d3673833302dff6a1ffaf14ff61f87
5
5
  SHA512:
6
- metadata.gz: f07424e685a1265e5e083889c9ee627893f63bbcb56d268b2fe5cfabd2e475f98bade4c9eca5e67da4a84e53e6652c3dbecb05fd5f4b3acbc8fe05819b9250d5
7
- data.tar.gz: acabfcbaa84a7e3f0423706ca3a84a95ce779f8bf6771a6b1b02a7920a54b3068922ec241c61ad275af12fd7b08469ffd78fb91e575ecc0d8e335278a4aac968
6
+ metadata.gz: b7f2f095998602114752cf4ce083384715ac6d22a9bfe6814dc783a4f92ba581907f1212ce787b1af5345a59f68d3989150cc89bcd595ae53b3e7170fb0409e7
7
+ data.tar.gz: 438049ec26fedbf656f2909b1b307f91901b5d91a1f9e90d23f6dc64817f10461c7c4319786963a0af8949d9f371aa00495883556ef46bc1b813caebaff2cf02
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geet (0.3.0)
5
- simple_scripting (~> 0.9.3)
4
+ geet (0.3.1)
5
+ simple_scripting (~> 0.9.4)
6
6
  temp-fork-tp-filter (= 0.0.3)
7
7
 
8
8
  GEM
@@ -52,7 +52,7 @@ GEM
52
52
  unicode-display_width (~> 1.0, >= 1.0.1)
53
53
  ruby-progressbar (1.9.0)
54
54
  safe_yaml (1.0.4)
55
- simple_scripting (0.9.3)
55
+ simple_scripting (0.9.4)
56
56
  parseconfig (~> 1.0)
57
57
  temp-fork-tp-filter (0.0.3)
58
58
  necromancer (~> 0.4.0)
data/README.md CHANGED
@@ -47,38 +47,19 @@ The default editor will be used for title/description:
47
47
 
48
48
  ![Issue creation editing screenshot](/extra/issue_editing.png?raw=true)
49
49
 
50
- More advanced issue creation, with labels and assignees:
51
-
52
- $ geet issue create --label-patterns bug,wip --assignee-patterns john
53
-
54
- patterns are partial matches, so, for example, `johncarmack` will be matched as assignee in the first case.
55
-
56
- After creation, the issue page will be automatically opened in the default browser.
57
-
58
- ### Using menus for options selection
59
-
60
- Geet supports selecting options (labels, collaborators, etc.), using the `-` parameter:
61
-
62
- $ geet issue create --label-patterns -
63
-
64
- This will show a menu like the following:
50
+ Labels, milestone and assignees will be asked with menu selection:
65
51
 
66
52
  Please select the label(s): (Use arrow keys, press Space to select and Enter to finish, and alphanumeric/underscore characters to filter)
67
53
  ‣ ⬡ bug
68
54
  ⬡ enhancement
69
55
  ⬡ not_an_issue
70
56
  ⬡ requires_design
71
- ⬡ technical_debt
72
- ⬡ top_priority
73
- ⬡ ux
74
57
 
75
- Typing alphanumeric keys and underscore will enable filtering:
58
+ Labels, milestone and assignees can be directly specified with the respective parameters:
76
59
 
77
- Please select the label(s): (Filter: "b")
78
- ‣ ⬡ bug
79
- ⬡ technical_debt
60
+ $ geet issue create --labels bug,wip --assignees johncarmark --milestone 1.0
80
61
 
81
- When a filter is active, use `Backspace` to cancel the last character, and `Canc` to reset it.
62
+ After creation, the issue page will be automatically opened in the default browser.
82
63
 
83
64
  ### Create a PR (with label, reviewers, and assigned to self)
84
65
 
@@ -92,7 +73,7 @@ The default editor will be used for title/description:
92
73
 
93
74
  More advanced PR creation, with label and reviewers, assigned to self:
94
75
 
95
- $ geet pr create --label-patterns "code review" --reviewer-patterns kevin,tom,adrian
76
+ $ geet pr create --labels "code review" --reviewers kevin,tom,adrian
96
77
 
97
78
  After creation, the issue page will be automatically opened in the default browser.
98
79
 
@@ -143,6 +124,26 @@ Create a public gist, with description:
143
124
 
144
125
  $ geet gist create --public /path/to/myfile 'Gist description'
145
126
 
127
+ ### Using menus for options selection
128
+
129
+ Menus can be used for selecting attributes (labels, collaborators, milestones...).
130
+
131
+ This is an example of multiple choice selection:
132
+
133
+ Please select the label(s): (Use arrow keys, press Space to select and Enter to finish, and alphanumeric/underscore characters to filter)
134
+ ‣ ⬡ bug
135
+ ⬡ enhancement
136
+ ⬡ not_an_issue
137
+ ⬡ requires_design
138
+
139
+ Typing alphanumeric keys and underscore will enable filtering:
140
+
141
+ Please select the label(s): (Filter: "b")
142
+ ‣ ⬡ bug
143
+ ⬡ technical_debt
144
+
145
+ When a filter is active, use `Backspace` to cancel the last character, and `Canc` to reset it.
146
+
146
147
  ### Help
147
148
 
148
149
  Display the help:
data/bin/geet CHANGED
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'simple_scripting/configuration'
4
5
  require_relative '../lib/geet/commandline/configuration.rb'
5
6
  require_relative '../lib/geet/commandline/commands.rb'
6
7
  require_relative '../lib/geet/commandline/editor.rb'
7
8
  require_relative '../lib/geet/git/repository.rb'
8
9
  require_relative '../lib/geet/helpers/summary_helper.rb'
10
+ require_relative '../lib/geet/shared/constants.rb'
9
11
  require_relative '../lib/geet/utils/git_client.rb'
10
12
  Dir[File.join(__dir__, '../lib/geet/services/*.rb')].each { |filename| require filename }
11
13
 
@@ -19,7 +21,7 @@ class GeetLauncher
19
21
  def launch
20
22
  command, options = Commandline::Configuration.new.decode_argv || exit
21
23
 
22
- repository = Git::Repository.new(upstream: !!options[:upstream])
24
+ repository = Git::Repository.new(upstream: !!options[:upstream], protected_repositories: protected_repositories)
23
25
 
24
26
  case command
25
27
  when GIST_CREATE_COMMAND
@@ -31,7 +33,7 @@ class GeetLauncher
31
33
  summary = options[:summary] || Commandline::Editor.new.edit_content(help: SUMMARY_TEMPLATE)
32
34
  title, description = split_summary(summary)
33
35
 
34
- options[:milestone_pattern] = options.delete(:milestone) if options.key?(:milestone)
36
+ options = default_to_manual_selection(options, :labels, :milestone, :assignees)
35
37
 
36
38
  Services::CreateIssue.new(repository).execute(title, description, options)
37
39
  when LABEL_CREATE_COMMAND
@@ -39,6 +41,8 @@ class GeetLauncher
39
41
 
40
42
  Services::CreateLabel.new(repository).execute(name, options)
41
43
  when ISSUE_LIST_COMMAND
44
+ options = default_to_manual_selection(options, :assignee)
45
+
42
46
  Services::ListIssues.new(repository).execute(options)
43
47
  when LABEL_LIST_COMMAND
44
48
  Services::ListLabels.new(repository).execute
@@ -48,7 +52,7 @@ class GeetLauncher
48
52
  summary = options[:summary] || edit_pr_summary
49
53
  title, description = split_summary(summary)
50
54
 
51
- options[:milestone_pattern] = options.delete(:milestone) if options.key?(:milestone)
55
+ options = default_to_manual_selection(options, :labels, :milestone, :reviewers)
52
56
 
53
57
  Services::CreatePr.new(repository).execute(title, description, options)
54
58
  when PR_LIST_COMMAND
@@ -77,6 +81,20 @@ class GeetLauncher
77
81
  Commandline::Editor.new.edit_content(help: SUMMARY_TEMPLATE)
78
82
  end
79
83
  end
84
+
85
+ def default_to_manual_selection(options, *params)
86
+ params.each do |param|
87
+ options[param] ||= Shared::Constants::MANUAL_LIST_SELECTION_FLAG
88
+ end
89
+
90
+ options
91
+ end
92
+
93
+ def protected_repositories
94
+ configuration = SimpleScripting::Configuration.load
95
+
96
+ configuration.protected_repositories.to_s.split(':')
97
+ end
80
98
  end
81
99
 
82
100
  GeetLauncher.new.launch if $PROGRAM_NAME == __FILE__
data/geet.gemspec CHANGED
@@ -10,14 +10,14 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.required_ruby_version = '>= 2.3.0'
12
12
  s.authors = ['Saverio Miroddi']
13
- s.date = '2018-01-25'
13
+ s.date = '2018-01-28'
14
14
  s.email = ['saverio.pub2@gmail.com']
15
15
  s.homepage = 'https://github.com/saveriomiroddi/geet'
16
16
  s.summary = 'Commandline interface for performing SCM (eg. GitHub) operations (eg. PR creation).'
17
17
  s.description = 'Commandline interface for performing SCM (eg. GitHub) operations (eg. PR creation).'
18
18
  s.license = 'GPL-3.0'
19
19
 
20
- s.add_runtime_dependency 'simple_scripting', '~> 0.9.3'
20
+ s.add_runtime_dependency 'simple_scripting', '~> 0.9.4'
21
21
  s.add_runtime_dependency 'temp-fork-tp-filter', '= 0.0.3'
22
22
 
23
23
  s.add_development_dependency 'rake', '~> 12.3.0'
@@ -22,9 +22,9 @@ module Geet
22
22
  # rubocop:disable Style/MutableConstant
23
23
  ISSUE_CREATE_OPTIONS = [
24
24
  ['-n', '--no-open-issue', "Don't open the issue link in the browser after creation"],
25
- ['-l', '--label-patterns "bug,help wanted"', 'Label patterns'],
25
+ ['-l', '--labels "bug,help wanted"', 'Labels'],
26
26
  ['-m', '--milestone 1.5.0', 'Milestone title pattern'],
27
- ['-a', '--assignee-patterns john,tom,adrian,kevin', 'Assignee login patterns'],
27
+ ['-a', '--assignees john,tom,adrian,kevin', 'Assignee logins'],
28
28
  ['-s', '--summary title_and_description', 'Set the summary (title and optionally description'],
29
29
  ['-u', '--upstream', 'Create on the upstream repository'],
30
30
  long_help: 'The default editor will be opened for editing title and description.'
@@ -37,7 +37,7 @@ module Geet
37
37
  ].freeze
38
38
 
39
39
  ISSUE_LIST_OPTIONS = [
40
- ['-a', '--assignee-pattern john', 'Assignee pattern'],
40
+ ['-a', '--assignee john', 'Assignee login'],
41
41
  ['-u', '--upstream', 'List on the upstream repository'],
42
42
  ].freeze
43
43
 
@@ -52,9 +52,9 @@ module Geet
52
52
  PR_CREATE_OPTIONS = [
53
53
  ['-A', '--automated-mode', "Automate the branch operations (see long help)"],
54
54
  ['-n', '--no-open-pr', "Don't open the PR link in the browser after creation"],
55
- ['-l', '--label-patterns "legacy,code review"', 'Label patterns'],
55
+ ['-l', '--labels "legacy,code review"', 'Labels'],
56
56
  ['-m', '--milestone 1.5.0', 'Milestone title pattern'],
57
- ['-r', '--reviewer-patterns john,tom,adrian,kevin', 'Reviewer login patterns'],
57
+ ['-r', '--reviewers john,tom,adrian,kevin', 'Reviewer logins'],
58
58
  ['-s', '--summary title_and_description', 'Set the summary (title and optionally description'],
59
59
  ['-u', '--upstream', 'Create on the upstream repository'],
60
60
  long_help: <<~STR
@@ -8,18 +8,26 @@ module Geet
8
8
  # This class represents, for convenience, both the local and the remote repository, but the
9
9
  # remote code is separated in each provider module.
10
10
  class Repository
11
- CONFIRM_ACTION_TEXT = <<~STR
12
- WARNING! The action will be performed on a fork, but an upstream repository has been found!
13
- Press Enter to continue, or Ctrl+C to exit now.
11
+ LOCAL_ACTION_ON_UPSTREAM_REPOSITORY_MESSAGE = <<~STR
12
+ The action will be performed on a fork, but an upstream repository has been found!
13
+ STR
14
+
15
+ ACTION_ON_PROTECTED_REPOSITORY_MESSAGE = <<~STR
16
+ This action will be performed on a protected repository!
14
17
  STR
15
18
 
16
19
  DEFAULT_GIT_CLIENT = Geet::Utils::GitClient.new
17
20
 
18
- def initialize(upstream: false, git_client: DEFAULT_GIT_CLIENT, warnings: true)
21
+ # warnings: disable all the warnings.
22
+ # protected_repositories: warn when creating an issue/pr on this repositories (entry format:
23
+ # `owner/repo`).
24
+ #
25
+ def initialize(upstream: false, git_client: DEFAULT_GIT_CLIENT, warnings: true, protected_repositories: [])
19
26
  @upstream = upstream
20
27
  @git_client = git_client
21
28
  @api_token = extract_env_api_token
22
29
  @warnings = warnings
30
+ @protected_repositories = protected_repositories
23
31
  end
24
32
 
25
33
  # REMOTE FUNCTIONALITIES (REPOSITORY)
@@ -33,7 +41,9 @@ module Geet
33
41
  end
34
42
 
35
43
  def create_issue(title, description)
36
- ask_confirm_action if local_action_with_upstream_repository? && @warnings
44
+ confirm(LOCAL_ACTION_ON_UPSTREAM_REPOSITORY_MESSAGE) if local_action_on_upstream_repository? && @warnings
45
+ confirm(ACTION_ON_PROTECTED_REPOSITORY_MESSAGE) if action_on_protected_repository? && @warnings
46
+
37
47
  attempt_provider_call(:Issue, :create, title, description, api_interface)
38
48
  end
39
49
 
@@ -62,7 +72,9 @@ module Geet
62
72
  end
63
73
 
64
74
  def create_pr(title, description, head)
65
- ask_confirm_action if local_action_with_upstream_repository? && @warnings
75
+ confirm(LOCAL_ACTION_ON_UPSTREAM_REPOSITORY_MESSAGE) if local_action_on_upstream_repository? && @warnings
76
+ confirm(ACTION_ON_PROTECTED_REPOSITORY_MESSAGE) if action_on_protected_repository? && @warnings
77
+
66
78
  attempt_provider_call(:PR, :create, title, description, head, api_interface)
67
79
  end
68
80
 
@@ -87,7 +99,6 @@ module Geet
87
99
  # PROVIDER
88
100
 
89
101
  def extract_env_api_token
90
- provider_name = @git_client.provider_domain[/(.*)\.\w+/, 1]
91
102
  env_variable_name = "#{provider_name.upcase}_API_TOKEN"
92
103
 
93
104
  ENV[env_variable_name] || raise("#{env_variable_name} not set!")
@@ -121,22 +132,30 @@ module Geet
121
132
  Dir[files_pattern].each { |filename| require filename }
122
133
  end
123
134
 
124
- # OTHER HELPERS
135
+ # WARNINGS
125
136
 
126
- def api_interface
127
- path = @git_client.path(upstream: @upstream)
128
- attempt_provider_call(:ApiInterface, :new, @api_token, repo_path: path, upstream: @upstream)
137
+ def confirm(message)
138
+ full_message = "WARNING! #{message.strip}\nPress Enter to continue, or Ctrl+C to exit now."
139
+ print full_message
140
+ gets
129
141
  end
130
142
 
131
- def ask_confirm_action
132
- print CONFIRM_ACTION_TEXT.rstrip
133
- gets
143
+ def action_on_protected_repository?
144
+ path = @git_client.path(upstream: @upstream)
145
+ @protected_repositories.include?(path)
134
146
  end
135
147
 
136
- def local_action_with_upstream_repository?
148
+ def local_action_on_upstream_repository?
137
149
  @git_client.remote_defined?('upstream') && !@upstream
138
150
  end
139
151
 
152
+ # OTHER HELPERS
153
+
154
+ def api_interface
155
+ path = @git_client.path(upstream: @upstream)
156
+ attempt_provider_call(:ApiInterface, :new, @api_token, repo_path: path, upstream: @upstream)
157
+ end
158
+
140
159
  # Bare downcase provider name, eg. `github`
141
160
  #
142
161
  def provider_name
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tmpdir'
4
+
5
+ require_relative '../helpers/os_helper'
6
+ require_relative '../utils/attributes_selection_manager'
7
+ require_relative '../utils/manual_list_selection'
8
+ require_relative '../utils/string_matching_selection'
9
+
10
+ module Geet
11
+ module Services
12
+ class AbstractCreateIssue
13
+ include Geet::Helpers::OsHelper
14
+
15
+ SUMMARY_BACKUP_FILENAME = File.join(Dir.tmpdir, 'last_geet_edited_summary.md')
16
+
17
+ def initialize(repository, out: $stdout)
18
+ @repository = repository
19
+ @out = out
20
+ end
21
+
22
+ private
23
+
24
+ def save_summary(title, description)
25
+ summary = "#{title}\n\n#{description}".strip + "\n"
26
+
27
+ IO.write(SUMMARY_BACKUP_FILENAME, summary)
28
+
29
+ @out.puts "Error! Saved summary to #{SUMMARY_BACKUP_FILENAME}"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -12,7 +12,9 @@ module Geet
12
12
  API_TOKEN_KEY = 'GITHUB_API_TOKEN'
13
13
  DEFAULT_GIT_CLIENT = Geet::Utils::GitClient.new
14
14
 
15
- def initialize
15
+ def initialize(out: $stdout)
16
+ @out = out
17
+
16
18
  api_token = extract_env_api_token
17
19
  @api_interface = Geet::Github::ApiInterface.new(api_token)
18
20
  end
@@ -22,17 +24,17 @@ module Geet
22
24
  # :publik: defaults to false
23
25
  # :no_browse defaults to false
24
26
  #
25
- def execute(full_filename, description: nil, publik: false, no_browse: false, output: $stdout)
27
+ def execute(full_filename, description: nil, publik: false, no_browse: false)
26
28
  content = IO.read(full_filename)
27
29
 
28
30
  gist_access = publik ? 'public' : 'private'
29
- output.puts "Creating a #{gist_access} gist..."
31
+ @out.puts "Creating a #{gist_access} gist..."
30
32
 
31
33
  filename = File.basename(full_filename)
32
34
  gist = Geet::Github::Gist.create(filename, content, @api_interface, description: description, publik: publik)
33
35
 
34
36
  if no_browse
35
- output.puts "Gist address: #{gist.link}"
37
+ @out.puts "Gist address: #{gist.link}"
36
38
  else
37
39
  open_file_with_default_application(gist.link)
38
40
  end
@@ -1,55 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'tmpdir'
4
- require_relative '../helpers/os_helper.rb'
5
- require_relative '../utils/manual_list_selection.rb'
6
- require_relative '../utils/pattern_matching_selection.rb'
3
+ require_relative 'abstract_create_issue'
7
4
 
8
5
  module Geet
9
6
  module Services
10
- class CreateIssue
11
- include Geet::Helpers::OsHelper
12
-
13
- MANUAL_LIST_SELECTION_FLAG = '-'.freeze
14
-
15
- SUMMARY_BACKUP_FILENAME = File.join(Dir.tmpdir, 'last_geet_edited_summary.md')
16
-
17
- def initialize(repository)
18
- @repository = repository
19
- end
20
-
7
+ class CreateIssue < AbstractCreateIssue
21
8
  # options:
22
- # :label_patterns
23
- # :milestone_pattern: number or description pattern.
24
- # :assignee_patterns
9
+ # :labels
10
+ # :milestone: number or description pattern.
11
+ # :assignees
25
12
  # :no_open_issue
26
13
  #
27
14
  def execute(
28
15
  title, description,
29
- label_patterns: nil, milestone_pattern: nil, assignee_patterns: nil, no_open_issue: nil,
30
- output: $stdout, **
16
+ labels: nil, milestone: nil, assignees: nil, no_open_issue: nil,
17
+ **
31
18
  )
32
- all_labels, all_milestones, all_collaborators = find_all_attribute_entries(
33
- label_patterns, milestone_pattern, assignee_patterns, output
34
- )
35
-
36
- labels = select_entries('label', all_labels, label_patterns, :multiple, :name) if label_patterns
37
- milestone, _ = select_entries('milestone', all_milestones, milestone_pattern, :single, :title) if milestone_pattern
38
- assignees = select_entries('assignee', all_collaborators, assignee_patterns, :multiple, nil) if assignee_patterns
19
+ selected_labels, selected_milestone, selected_assignees = find_and_select_attributes(labels, milestone, assignees)
39
20
 
40
- issue = create_issue(title, description, output)
21
+ issue = create_issue(title, description)
41
22
 
42
- edit_issue(issue, labels, milestone, assignees, output)
23
+ edit_issue(issue, selected_labels, selected_milestone, selected_assignees)
43
24
 
44
25
  if no_open_issue
45
- output.puts "Issue address: #{issue.link}"
26
+ @out.puts "Issue address: #{issue.link}"
46
27
  else
47
28
  open_file_with_default_application(issue.link)
48
29
  end
49
30
 
50
31
  issue
51
32
  rescue => error
52
- save_summary(title, description, output) if title
33
+ save_summary(title, description) if title
53
34
  raise
54
35
  end
55
36
 
@@ -57,50 +38,33 @@ module Geet
57
38
 
58
39
  # Internal actions
59
40
 
60
- def find_all_attribute_entries(label_patterns, milestone_pattern, assignee_patterns, output)
61
- if label_patterns
62
- output.puts 'Finding labels...'
63
- labels_thread = Thread.new { @repository.labels }
64
- end
65
-
66
- if milestone_pattern
67
- output.puts 'Finding milestone...'
68
- milestone_thread = Thread.new { @repository.milestones }
69
- end
70
-
71
- if assignee_patterns
72
- output.puts 'Finding collaborators...'
73
- assignees_thread = Thread.new { @repository.collaborators }
74
- end
41
+ def find_and_select_attributes(labels, milestone, assignees)
42
+ selection_manager = Geet::Utils::AttributesSelectionManager.new(@repository, out: @out)
75
43
 
76
- labels = labels_thread&.value
77
- milestones = milestone_thread&.value
78
- assignees = assignees_thread&.value
44
+ selection_manager.add_attribute(:labels, 'label', labels, :multiple, name_method: :name) if labels
45
+ selection_manager.add_attribute(:milestones, 'milestone', milestone, :single, name_method: :title) if milestone
46
+ selection_manager.add_attribute(:collaborators, 'assignee', assignees, :multiple) if assignees
79
47
 
80
- raise "No labels found!" if label_patterns && labels.empty?
81
- raise "No milestones found!" if milestone_pattern && milestones.empty?
82
- raise "No collaborators found!" if assignee_patterns && assignees.empty?
83
-
84
- [labels, milestones, assignees]
48
+ selection_manager.select_attributes
85
49
  end
86
50
 
87
- def create_issue(title, description, output)
88
- output.puts 'Creating the issue...'
51
+ def create_issue(title, description)
52
+ @out.puts 'Creating the issue...'
89
53
 
90
54
  issue = @repository.create_issue(title, description)
91
55
  end
92
56
 
93
- def edit_issue(issue, labels, milestone, assignees, output)
57
+ def edit_issue(issue, labels, milestone, assignees)
94
58
  # labels can be nil (parameter not passed) or empty array (parameter passed, but nothing
95
59
  # selected)
96
- add_labels_thread = add_labels(issue, labels, output) if labels && !labels.empty?
97
- set_milestone_thread = set_milestone(issue, milestone, output) if milestone
60
+ add_labels_thread = add_labels(issue, labels) if labels && !labels.empty?
61
+ set_milestone_thread = set_milestone(issue, milestone) if milestone
98
62
 
99
63
  # same considerations as above, but with additional upstream case.
100
64
  if assignees
101
- assign_users_thread = assign_users(issue, assignees, output) if !assignees.empty?
65
+ assign_users_thread = assign_users(issue, assignees) if !assignees.empty?
102
66
  elsif !@repository.upstream?
103
- assign_users_thread = assign_authenticated_user(issue, output)
67
+ assign_users_thread = assign_authenticated_user(issue)
104
68
  end
105
69
 
106
70
  add_labels_thread&.join
@@ -108,57 +72,39 @@ module Geet
108
72
  assign_users_thread&.join
109
73
  end
110
74
 
111
- def add_labels(issue, selected_labels, output)
75
+ def add_labels(issue, selected_labels)
112
76
  labels_list = selected_labels.map(&:name).join(', ')
113
77
 
114
- output.puts "Adding labels #{labels_list}..."
78
+ @out.puts "Adding labels #{labels_list}..."
115
79
 
116
80
  Thread.new do
117
81
  issue.add_labels(selected_labels.map(&:name))
118
82
  end
119
83
  end
120
84
 
121
- def set_milestone(issue, milestone, output)
122
- output.puts "Setting milestone #{milestone.title}..."
85
+ def set_milestone(issue, milestone)
86
+ @out.puts "Setting milestone #{milestone.title}..."
123
87
 
124
88
  Thread.new do
125
89
  issue.edit(milestone: milestone.number)
126
90
  end
127
91
  end
128
92
 
129
- def assign_users(issue, users, output)
130
- output.puts "Assigning users #{users.join(', ')}..."
93
+ def assign_users(issue, users)
94
+ @out.puts "Assigning users #{users.join(', ')}..."
131
95
 
132
96
  Thread.new do
133
97
  issue.assign_users(users)
134
98
  end
135
99
  end
136
100
 
137
- def assign_authenticated_user(issue, output)
138
- output.puts 'Assigning authenticated user...'
101
+ def assign_authenticated_user(issue)
102
+ @out.puts 'Assigning authenticated user...'
139
103
 
140
104
  Thread.new do
141
105
  issue.assign_users(@repository.authenticated_user)
142
106
  end
143
107
  end
144
-
145
- def save_summary(title, description, output)
146
- summary = "#{title}\n\n#{description}".strip + "\n"
147
-
148
- IO.write(SUMMARY_BACKUP_FILENAME, summary)
149
-
150
- output.puts "Error! Saved summary to #{SUMMARY_BACKUP_FILENAME}"
151
- end
152
-
153
- # Generic helpers
154
-
155
- def select_entries(entry_type, entries, raw_patterns, selection_type, instance_method)
156
- if raw_patterns == MANUAL_LIST_SELECTION_FLAG
157
- Geet::Utils::ManualListSelection.new.select(entry_type, entries, selection_type, instance_method: instance_method)
158
- else
159
- Geet::Utils::PatternMatchingSelection.new.select(entry_type, entries, raw_patterns, instance_method: instance_method)
160
- end
161
- end
162
108
  end
163
109
  end
164
110
  end