story_branch 1.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './pivotal/tracker'
4
- require_relative './github/tracker'
5
- require_relative './jira/tracker'
6
3
  require_relative './git_utils'
7
4
  require_relative './git_wrapper'
8
5
  require_relative './config_manager'
9
6
  require_relative './url_opener'
7
+ require_relative 'tracker_initializer'
8
+
10
9
  require 'tty-prompt'
11
10
 
12
11
  module StoryBranch
@@ -20,7 +19,7 @@ module StoryBranch
20
19
  def initialize
21
20
  @config = ConfigManager.new
22
21
  abort(@config.errors.join("\n")) unless @config.valid?
23
- @tracker = initialize_tracker
22
+ @tracker = StoryBranch::TrackerInitializer.initialize_tracker(config: @config)
24
23
  abort('Invalid tracker configuration setting.') unless @tracker.valid?
25
24
  end
26
25
 
@@ -114,7 +113,6 @@ module StoryBranch
114
113
  true
115
114
  end
116
115
 
117
- # rubocop:disable Metrics/AbcSize
118
116
  # rubocop:disable Metrics/MethodLength
119
117
  def update_status(current_status, next_status, action)
120
118
  stories = @tracker.stories_with_state(current_status)
@@ -139,7 +137,6 @@ module StoryBranch
139
137
  story
140
138
  end
141
139
  # rubocop:enable Metrics/MethodLength
142
- # rubocop:enable Metrics/AbcSize
143
140
 
144
141
  def build_stories_structure(stories)
145
142
  options = {}
@@ -198,30 +195,19 @@ module StoryBranch
198
195
  # rubocop:enable Metrics/MethodLength
199
196
 
200
197
  def build_branch_name(branch_name, story_id)
201
- if @config.issue_placement.casecmp('beginning').zero?
202
- "#{story_id}-#{branch_name}"
203
- else
204
- "#{branch_name}-#{story_id}"
205
- end
198
+ branch_name = if @config.issue_placement.casecmp('beginning').zero?
199
+ "#{story_id}-#{branch_name}"
200
+ else
201
+ "#{branch_name}-#{story_id}"
202
+ end
203
+ return branch_name unless @config.branch_username
204
+
205
+ "#{@config.branch_username}/#{branch_name}"
206
206
  end
207
207
 
208
208
  def current_branch
209
209
  @current_branch ||= GitWrapper.current_branch
210
210
  end
211
-
212
- def initialize_tracker
213
- # TODO: Ideally this would be mapped out somewhere so we don't need to
214
- # evaluate anything from the config here
215
- tracker_type = @config.tracker_type
216
- case tracker_type
217
- when 'github'
218
- StoryBranch::Github::Tracker.new(**@config.tracker_params)
219
- when 'pivotal-tracker'
220
- StoryBranch::Pivotal::Tracker.new(**@config.tracker_params)
221
- when 'jira'
222
- StoryBranch::Jira::Tracker.new(**@config.tracker_params)
223
- end
224
- end
225
211
  end
226
212
  # rubocop:enable Metrics/ClassLength
227
213
  end
@@ -10,17 +10,17 @@ module StoryBranch
10
10
  @project = blanket_project
11
11
  end
12
12
 
13
+ private
14
+
13
15
  # Returns an array of PT Stories (Story Class)
14
16
  # TODO: add other possible args
15
- def stories(options = {}, estimated = true)
17
+ def stories(options = {})
16
18
  stories = if options[:id]
17
19
  [@project.stories(options[:id]).get.payload]
18
20
  else
19
21
  @project.stories.get(params: options)
20
22
  end
21
23
  stories = stories.map { |s| Story.new(s, @project) }
22
- return stories if estimated == false
23
-
24
24
  stories.select(&:estimated)
25
25
  end
26
26
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './constants'
4
+ require_relative './pivotal/tracker'
5
+ require_relative './github/tracker'
6
+ require_relative './jira/tracker'
7
+ require_relative './linear_app/tracker'
8
+
9
+ module StoryBranch
10
+ # helper class to find out which tracker should be initialized based on the
11
+ # configuration values
12
+ class TrackerInitializer
13
+ def self.initialize_tracker(config:)
14
+ tracker_class = find_tracker_class(config.tracker_type)
15
+ raise 'Invalid tracker configuration' unless tracker_class
16
+
17
+ tracker_class.new(**config.tracker_params)
18
+ end
19
+
20
+ def self.find_tracker_class(tracker_type)
21
+ tracker_str = StoryBranch::TRACKERS_CLASSES[tracker_type]
22
+ return nil unless tracker_str
23
+
24
+ Kernel.const_get(tracker_str)
25
+ end
26
+ end
27
+ end
@@ -5,11 +5,12 @@ module StoryBranch
5
5
  class UrlOpener
6
6
  def self.open_url(url)
7
7
  url = "https://#{url}" unless url.start_with?('http')
8
- if RbConfig::CONFIG['host_os'].match?(/mswin|mingw|cygwin/)
8
+ case RbConfig::CONFIG['host_os']
9
+ when /mswin|mingw|cygwin/
9
10
  system "start #{url}"
10
- elsif RbConfig::CONFIG['host_os'].match?(/darwin/)
11
+ when /darwin/
11
12
  system "open #{url}"
12
- elsif RbConfig::CONFIG['host_os'].match?(/linux|bsd/)
13
+ when /linux|bsd/
13
14
  system "xdg-open #{url}"
14
15
  end
15
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StoryBranch
4
- VERSION = '1.0.0'
4
+ VERSION = '2.2.0'
5
5
  end
data/story_branch.gemspec CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
  'documentation_uri' => 'https://github.com/story-branch/story_branch/blob/master/README.md',
40
40
  'source_code_uri' => 'https://github.com/story-branch/story_branch'
41
41
  }
42
- spec.required_ruby_version = ['>= 2.4', '< 3']
42
+ spec.required_ruby_version = ['>= 2.4', '< 3.1']
43
43
 
44
44
  # Specify which files should be added to the gem when it is released.
45
45
  # The `git ls-files -z` loads the files in the RubyGem that have been
@@ -53,25 +53,27 @@ Gem::Specification.new do |spec|
53
53
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
54
54
  spec.require_paths = ['lib']
55
55
 
56
- spec.add_runtime_dependency 'blanket_wrapper', '~> 3.0'
57
- spec.add_runtime_dependency 'damerau-levenshtein', '~> 1.3'
58
- spec.add_runtime_dependency 'jira-ruby', '~> 1.7'
59
- spec.add_runtime_dependency 'thor', '~> 0.20'
60
- spec.add_runtime_dependency 'tty-command', '~> 0.8'
61
- spec.add_runtime_dependency 'tty-config', '~> 0.2'
62
- spec.add_runtime_dependency 'tty-pager', '~> 0.12'
63
- spec.add_runtime_dependency 'tty-prompt', '~> 0.18'
64
- spec.add_runtime_dependency 'xdg', '~> 3.0'
56
+ spec.add_runtime_dependency 'blanket_wrapper', '~> 3.0', '> 3.0'
57
+ spec.add_runtime_dependency 'damerau-levenshtein', '~> 1.3', '> 1.3'
58
+ spec.add_runtime_dependency 'httparty', '>0'
59
+ spec.add_runtime_dependency 'jira-ruby', '> 1.7', '< 3'
60
+ spec.add_runtime_dependency 'story_branch-graphql', '~> 0.0.1'
61
+ spec.add_runtime_dependency 'thor', '> 0.20', '< 2'
62
+ spec.add_runtime_dependency 'tty-command', '~> 0.8', '> 0.8'
63
+ spec.add_runtime_dependency 'tty-config', '~> 0.2', '> 0.2'
64
+ spec.add_runtime_dependency 'tty-pager', '~> 0.12', '> 0.12'
65
+ spec.add_runtime_dependency 'tty-prompt', '~> 0.18', '> 0.18'
66
+ spec.add_runtime_dependency 'xdg', '> 3.0', '< 6'
65
67
 
66
- spec.add_development_dependency 'bundler', '~> 2.1'
67
- spec.add_development_dependency 'simplecov', '~> 0.16'
68
- spec.add_development_dependency 'fakefs', '~> 0.14'
69
- spec.add_development_dependency 'git', '~> 1.5'
70
- spec.add_development_dependency 'ostruct', '~> 0.1'
71
- spec.add_development_dependency 'pry', '~> 0.11'
72
- spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
73
- spec.add_development_dependency 'rspec', '~> 3'
74
- spec.add_development_dependency 'rubocop', '~> 0.86'
75
- spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
68
+ spec.add_development_dependency 'bundler', '~> 2.1', '> 2.1'
69
+ spec.add_development_dependency 'fakefs', '> 0.14', '< 2'
70
+ spec.add_development_dependency 'git', '~> 1.5', '> 1.5'
71
+ spec.add_development_dependency 'ostruct', '~> 0.1', '> 0.1'
72
+ spec.add_development_dependency 'pry', '~> 0.11', '> 0.11'
73
+ spec.add_development_dependency 'rake', '>= 12.3.3', '< 14'
74
+ spec.add_development_dependency 'rubocop', '~> 1.22'
75
+ spec.add_development_dependency 'rspec', '~> 3', '> 3'
76
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4', '> 0.4'
77
+ spec.add_development_dependency 'simplecov', '~> 0.16', '> 0.16'
76
78
  end
77
79
  # rubocop:enable Metrics/BlockLength
@@ -17,6 +17,7 @@ def grab_and_print_log(from, to)
17
17
  end
18
18
 
19
19
  # rubocop:disable Metrics/MethodLength
20
+ # rubocop:disable Metrics/AbcSize
20
21
  def print_all_logs
21
22
  all_tags = StoryBranch::GitWrapper.command_lines('tag --list')
22
23
  cleanup_tags = all_tags.map do |t|
@@ -36,6 +37,7 @@ def print_all_logs
36
37
  grab_and_print_log(from, to)
37
38
  end
38
39
  end
40
+ # rubocop:enable Metrics/AbcSize
39
41
  # rubocop:enable Metrics/MethodLength
40
42
 
41
43
  all_logs = ARGV[0] == 'all'