story_branch 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1826485750874314fb2570c93b1330a89f88e36571a84fe63482a33ffbb50d34
4
- data.tar.gz: 2914e9113a13b0ab0546485faa0b8acea1906f84b459f54c2d835433891bbb0c
3
+ metadata.gz: 0adf65a12d1ab52998ada7760645345d76c1dbe817ce52724005a71cf1b7bb30
4
+ data.tar.gz: 63a19f6f253be9459618ecfb8d23f099c1e2ea5c65b3152394b49a6dce335094
5
5
  SHA512:
6
- metadata.gz: baf40433309c1939869490828cdb7cbd2749ba9cb22f09579e0003f989fecf84ced996bc0ae64a6babc58debc43c601093659a231c1c3ef5a12e31055f9badde
7
- data.tar.gz: b24f7b09b8eadee1960cd4a053f6007c23bb46535af08667e5fab08b6bbb15e622664110e05ba2783eacb6e07fe4033d901bd9b0e8d5ab5abd4c71e38fc359d2
6
+ metadata.gz: c7a2c1923c37f423f7f2a946e6ecf19371cae814b33489ec59069567711b3de50a3c49e054d4c30042c04ebfe4b16c032584f854a758ab1f0871bb7f27d67ca7
7
+ data.tar.gz: a59cb14660ed656598170978e63ccc2e51e414028d28a6af35c3e0de82d96fd9cea10c93e033c4c9a12850b880fbd922b1b60a035e700fea8b73ee292b59ad11
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- story_branch (0.6.0)
4
+ story_branch (0.6.1)
5
5
  blanket_wrapper (~> 3.0)
6
6
  damerau-levenshtein (~> 1.3)
7
7
  jira-ruby (~> 1.7)
@@ -14,12 +14,12 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- activesupport (6.0.0)
17
+ activesupport (6.0.2.1)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (>= 0.7, < 2)
20
20
  minitest (~> 5.1)
21
21
  tzinfo (~> 1.1)
22
- zeitwerk (~> 2.1, >= 2.1.8)
22
+ zeitwerk (~> 2.2)
23
23
  atlassian-jwt (0.2.0)
24
24
  jwt (~> 2.1.0)
25
25
  blanket_wrapper (3.0.2)
@@ -27,12 +27,12 @@ GEM
27
27
  recursive-open-struct
28
28
  coderay (1.1.2)
29
29
  concurrent-ruby (1.1.5)
30
- damerau-levenshtein (1.3.1)
30
+ damerau-levenshtein (1.3.2)
31
31
  diff-lcs (1.3)
32
32
  equatable (0.6.1)
33
33
  fakefs (0.20.1)
34
34
  git (1.5.0)
35
- httparty (0.17.1)
35
+ httparty (0.17.3)
36
36
  mime-types (~> 3.0)
37
37
  multi_xml (>= 0.5.2)
38
38
  i18n (1.7.0)
@@ -46,41 +46,41 @@ GEM
46
46
  method_source (0.9.2)
47
47
  mime-types (3.3)
48
48
  mime-types-data (~> 3.2015)
49
- mime-types-data (3.2019.0904)
50
- minitest (5.12.2)
49
+ mime-types-data (3.2019.1009)
50
+ minitest (5.13.0)
51
51
  multi_xml (0.6.0)
52
52
  multipart-post (2.1.1)
53
- necromancer (0.5.0)
53
+ necromancer (0.5.1)
54
54
  oauth (0.5.4)
55
55
  ostruct (0.1.0)
56
56
  pastel (0.7.3)
57
57
  equatable (~> 0.6)
58
58
  tty-color (~> 0.5)
59
- pry (0.11.3)
59
+ pry (0.12.2)
60
60
  coderay (~> 1.1.0)
61
61
  method_source (~> 0.9.0)
62
62
  rake (10.5.0)
63
63
  recursive-open-struct (1.1.0)
64
- rspec (3.8.0)
65
- rspec-core (~> 3.8.0)
66
- rspec-expectations (~> 3.8.0)
67
- rspec-mocks (~> 3.8.0)
68
- rspec-core (3.8.2)
69
- rspec-support (~> 3.8.0)
70
- rspec-expectations (3.8.5)
64
+ rspec (3.9.0)
65
+ rspec-core (~> 3.9.0)
66
+ rspec-expectations (~> 3.9.0)
67
+ rspec-mocks (~> 3.9.0)
68
+ rspec-core (3.9.0)
69
+ rspec-support (~> 3.9.0)
70
+ rspec-expectations (3.9.0)
71
71
  diff-lcs (>= 1.2.0, < 2.0)
72
- rspec-support (~> 3.8.0)
73
- rspec-mocks (3.8.2)
72
+ rspec-support (~> 3.9.0)
73
+ rspec-mocks (3.9.0)
74
74
  diff-lcs (>= 1.2.0, < 2.0)
75
- rspec-support (~> 3.8.0)
76
- rspec-support (3.8.3)
75
+ rspec-support (~> 3.9.0)
76
+ rspec-support (3.9.0)
77
77
  rspec_junit_formatter (0.4.1)
78
78
  rspec-core (>= 2, < 4, != 2.12.0)
79
- strings (0.1.6)
79
+ strings (0.1.8)
80
80
  strings-ansi (~> 0.1)
81
81
  unicode-display_width (~> 1.5)
82
82
  unicode_utils (~> 1.4)
83
- strings-ansi (0.1.0)
83
+ strings-ansi (0.2.0)
84
84
  thor (0.20.3)
85
85
  thread_safe (0.3.6)
86
86
  tty-color (0.5.0)
@@ -92,11 +92,11 @@ GEM
92
92
  strings (~> 0.1.4)
93
93
  tty-screen (~> 0.6)
94
94
  tty-which (~> 0.4)
95
- tty-prompt (0.19.0)
95
+ tty-prompt (0.20.0)
96
96
  necromancer (~> 0.5.0)
97
97
  pastel (~> 0.7.0)
98
- tty-reader (~> 0.6.0)
99
- tty-reader (0.6.0)
98
+ tty-reader (~> 0.7.0)
99
+ tty-reader (0.7.0)
100
100
  tty-cursor (~> 0.7)
101
101
  tty-screen (~> 0.7)
102
102
  wisper (~> 2.0.0)
@@ -106,8 +106,8 @@ GEM
106
106
  thread_safe (~> 0.1)
107
107
  unicode-display_width (1.6.0)
108
108
  unicode_utils (1.4.0)
109
- wisper (2.0.0)
110
- zeitwerk (2.1.10)
109
+ wisper (2.0.1)
110
+ zeitwerk (2.2.2)
111
111
 
112
112
  PLATFORMS
113
113
  ruby
@@ -124,4 +124,4 @@ DEPENDENCIES
124
124
  story_branch!
125
125
 
126
126
  BUNDLED WITH
127
- 1.17.3
127
+ 2.1.2
data/exe/git-finish CHANGED
@@ -1,3 +1,3 @@
1
- # !/usr/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  `story_branch finish`
@@ -46,10 +46,10 @@ module StoryBranch
46
46
 
47
47
  return unless tracker == 'jira'
48
48
 
49
- # rubocop:disable Metrics/LineLength
49
+ # rubocop:disable Layout/LineLength
50
50
  username = prompt.ask('Please provide username (email most of the times) for this key:',
51
51
  required: true)
52
- # rubocop:enable Metrics/LineLength
52
+ # rubocop:enable Layout/LineLength
53
53
  @config.set(project_id, :username, value: username)
54
54
  @config.write(force: true)
55
55
  end
@@ -58,15 +58,15 @@ module StoryBranch
58
58
  return @project_id if @project_id
59
59
 
60
60
  if tracker == 'jira'
61
- # rubocop:disable Metrics/LineLength
61
+ # rubocop:disable Layout/LineLength
62
62
  project_domain = prompt.ask("What is your JIRA's subdomain?", required: true)
63
63
  project_key = prompt.ask("What is your JIRA's project key?", required: true)
64
- # rubocop:enable Metrics/LineLength
64
+ # rubocop:enable Layout/LineLength
65
65
  @project_id = "#{project_domain}|#{project_key}"
66
66
  else
67
- # rubocop:disable Metrics/LineLength
67
+ # rubocop:disable Layout/LineLength
68
68
  @project_id = prompt.ask("Please provide this project's id:", required: true)
69
- # rubocop:enable Metrics/LineLength
69
+ # rubocop:enable Layout/LineLength
70
70
  end
71
71
  end
72
72
 
@@ -7,7 +7,7 @@ module StoryBranch
7
7
  # Class used to interact with git. It relies on git gem as the wrapper
8
8
  # and levenshtein algo to determine branch name proximity
9
9
  class GitUtils
10
- def self.existing_branch?(name)
10
+ def self.similar_branch?(name)
11
11
  GitWrapper.branch_names.each do |n|
12
12
  return true if DamerauLevenshtein.distance(n, name) < 3
13
13
 
@@ -35,7 +35,7 @@ module StoryBranch
35
35
 
36
36
  def self.current_branch_story_parts
37
37
  matches = current_story
38
- return {} unless matches.length == 3
38
+ return {} unless matches&.length == 3
39
39
 
40
40
  title = matches[1].tr('-', ' ').strip
41
41
  { title: title, id: matches[2].to_i }
@@ -12,7 +12,7 @@ module StoryBranch
12
12
 
13
13
  def stories(options = {})
14
14
  stories = if options[:id]
15
- [@repo.issues(options[:id]).get]
15
+ [@repo.issues(options[:id]).get.payload]
16
16
  else
17
17
  @repo.issues.get(params: options)
18
18
  end
@@ -17,11 +17,11 @@ module StoryBranch
17
17
  stories = if options[:id]
18
18
  [@project.issues.find(options[:id])]
19
19
  else
20
- # rubocop:disable Metrics/LineLength
20
+ # rubocop:disable Layout/LineLength
21
21
  @project.client.Issue.jql(
22
22
  "project=#{@project.key} AND status='To Do' AND assignee=currentUser()"
23
23
  )
24
- # rubocop:enable Metrics/LineLength
24
+ # rubocop:enable Layout/LineLength
25
25
  end
26
26
 
27
27
  stories.map { |s| Issue.new(s, @project) }
@@ -25,7 +25,7 @@ module StoryBranch
25
25
  @local_config = ConfigManager.init_config('.')
26
26
  @global_config = ConfigManager.init_config(Dir.home)
27
27
  initialize_tracker
28
- exit unless @tracker.valid?
28
+ abort('Invalid tracker configuration setting.') unless @tracker.valid?
29
29
  end
30
30
 
31
31
  def create_story_branch
@@ -42,7 +42,7 @@ module StoryBranch
42
42
  end
43
43
 
44
44
  def story_finish
45
- current_story
45
+ return unless current_story
46
46
  return if unstaged_changes?
47
47
  return if nothing_to_add?
48
48
 
@@ -93,6 +93,7 @@ module StoryBranch
93
93
  end
94
94
 
95
95
  prompt.error('No tracked feature associated with this branch')
96
+ nil
96
97
  end
97
98
 
98
99
  def unstaged_changes?
@@ -168,6 +169,17 @@ module StoryBranch
168
169
  @finish_tag
169
170
  end
170
171
 
172
+ def issue_placement
173
+ return @issue_placement if @issue_placement
174
+
175
+ fallback = @global_config.fetch(project_id,
176
+ :issue_placement,
177
+ default: 'End')
178
+ @issue_placement = @local_config.fetch(:issue_placement,
179
+ default: fallback)
180
+ @issue_placement
181
+ end
182
+
171
183
  def build_finish_message
172
184
  message_tag = [finish_tag, "##{current_story.id}"].join(' ').strip
173
185
  "[#{message_tag}] #{current_story.title}"
@@ -176,33 +188,56 @@ module StoryBranch
176
188
  def create_feature_branch(story)
177
189
  return if story.nil?
178
190
 
179
- current_branch = GitWrapper.current_branch
191
+ if GitUtils.branch_for_story_exists? story.id
192
+ prompt.error("An existing branch has the same story id: #{story.id}")
193
+ return
194
+ end
195
+
196
+ branch_name = valid_branch_name(story)
197
+ return unless branch_name
198
+
199
+ # rubocop:disable Layout/LineLength
200
+ feature_branch_name_with_story_id = build_branch_name(branch_name, story.id)
201
+ prompt.say("Creating: #{feature_branch_name_with_story_id} with #{current_branch} as parent")
202
+ # rubocop:enable Layout/LineLength
203
+ GitWrapper.create_branch feature_branch_name_with_story_id
204
+ end
205
+
206
+ def valid_branch_name(story)
180
207
  prompt.say "You are checked out at: #{current_branch}"
181
208
  branch_name = prompt.ask('Provide a new branch name',
182
209
  default: story.dashed_title)
183
- feature_branch_name = branch_name.chomp
184
- return unless validate_branch_name(feature_branch_name, story.id)
210
+ feature_branch_name = StringUtils.truncate(branch_name.chomp)
185
211
 
186
- feature_branch_name_with_story_id = "#{feature_branch_name}-#{story.id}"
187
- # rubocop:disable Metrics/LineLength
188
- prompt.say("Creating: #{feature_branch_name_with_story_id} with #{current_branch} as parent")
189
- # rubocop:enable Metrics/LineLength
190
- GitWrapper.create_branch feature_branch_name_with_story_id
212
+ validate_branch_name(feature_branch_name)
191
213
  end
192
214
 
193
215
  # Branch name validation
194
- def validate_branch_name(name, id)
195
- if GitUtils.branch_for_story_exists? id
196
- prompt.error("An existing branch has the same story id: #{id}")
197
- return false
216
+ # rubocop:disable Metrics/MethodLength
217
+ def validate_branch_name(name)
218
+ if GitUtils.similar_branch? name
219
+ prompt.warn('This name is very similar to an existing branch.'\
220
+ ' It is recommended to use a more unique name.')
221
+ decision = prompt.select('What to do?') do |menu|
222
+ menu.choice 'Rename the branch', 1
223
+ menu.choice 'Proceed with branch name', 2
224
+ menu.choice 'Abort branch creation', 3
225
+ end
226
+ return nil if decision == 3
227
+ return name if decision == 2
228
+
229
+ return prompt.ask('Provide a new branch name', default: name)
198
230
  end
199
- if GitUtils.existing_branch? name
200
- # rubocop:disable Metrics/LineLength
201
- prompt.error('This name is very similar to an existing branch. Avoid confusion and use a more unique name.')
202
- # rubocop:enable Metrics/LineLength
203
- return false
231
+ name
232
+ end
233
+ # rubocop:enable Metrics/MethodLength
234
+
235
+ def build_branch_name(branch_name, story_id)
236
+ if issue_placement.casecmp('beginning').zero?
237
+ "#{story_id}-#{branch_name}"
238
+ else
239
+ "#{branch_name}-#{story_id}"
204
240
  end
205
- true
206
241
  end
207
242
 
208
243
  def project_id
@@ -227,6 +262,10 @@ module StoryBranch
227
262
  @username ||= @global_config.fetch(project_id, :username)
228
263
  end
229
264
 
265
+ def current_branch
266
+ @current_branch ||= GitWrapper.current_branch
267
+ end
268
+
230
269
  # rubocop:disable Metrics/AbcSize
231
270
  # rubocop:disable Metrics/MethodLength
232
271
  def initialize_tracker
@@ -14,7 +14,7 @@ module StoryBranch
14
14
  # TODO: add other possible args
15
15
  def stories(options = {}, estimated = true)
16
16
  stories = if options[:id]
17
- [@project.stories(options[:id]).get]
17
+ [@project.stories(options[:id]).get.payload]
18
18
  else
19
19
  @project.stories.get(params: options)
20
20
  end
@@ -25,5 +25,11 @@ module StoryBranch
25
25
  def self.undashed(text)
26
26
  text.tr('-', ' ').squeeze(' ').strip.capitalize
27
27
  end
28
+
29
+ def self.truncate(text, max_length = 40)
30
+ return text if text.length <= max_length
31
+
32
+ text[0..max_length - 1]
33
+ end
28
34
  end
29
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StoryBranch
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
  end
data/story_branch.gemspec CHANGED
@@ -31,11 +31,12 @@ Gem::Specification.new do |spec|
31
31
  JIRA. Different workflows shall be supported in the next versions.
32
32
  DESCRIPTION
33
33
 
34
+ spec.homepage = 'https://github.com/story-branch/story_branch'
35
+
34
36
  spec.metadata = {
35
37
  'bug_tracker_uri' => 'https://github.com/story-branch/story_branch/issues',
36
38
  'changelog_uri' => 'https://github.com/story-branch/story_branch/blob/master/Changelog.md',
37
39
  'documentation_uri' => 'https://github.com/story-branch/story_branch/blob/master/README.md',
38
- 'homepage_uri' => 'https://github.com/story-branch/story_branch',
39
40
  'source_code_uri' => 'https://github.com/story-branch/story_branch'
40
41
  }
41
42
  spec.required_ruby_version = ['>= 2.4', '< 2.7']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: story_branch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rui Baltazar
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2019-10-27 00:00:00.000000000 Z
15
+ date: 2019-12-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: blanket_wrapper
@@ -315,14 +315,13 @@ files:
315
315
  - lib/story_branch/templates/unstart/.gitkeep
316
316
  - lib/story_branch/version.rb
317
317
  - story_branch.gemspec
318
- homepage:
318
+ homepage: https://github.com/story-branch/story_branch
319
319
  licenses:
320
320
  - MIT
321
321
  metadata:
322
322
  bug_tracker_uri: https://github.com/story-branch/story_branch/issues
323
323
  changelog_uri: https://github.com/story-branch/story_branch/blob/master/Changelog.md
324
324
  documentation_uri: https://github.com/story-branch/story_branch/blob/master/README.md
325
- homepage_uri: https://github.com/story-branch/story_branch
326
325
  source_code_uri: https://github.com/story-branch/story_branch
327
326
  post_install_message:
328
327
  rdoc_options: []
@@ -342,7 +341,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
342
341
  - !ruby/object:Gem::Version
343
342
  version: '0'
344
343
  requirements: []
345
- rubygems_version: 3.0.3
344
+ rubygems_version: 3.0.1
346
345
  signing_key:
347
346
  specification_version: 4
348
347
  summary: Create git branches based on your preferred tracker tickets