branch-name 2.0.1.pre.beta → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98513393fd480585d05e2e733a6a5174db7dc07e04f561fde59cd927a11af3c9
4
- data.tar.gz: f4b7171f6c4dbd8f817b7c0d2f41bc56b4d4fa194ba2c33465b63135e18f2b03
3
+ metadata.gz: c79db6ebf8cf49b09e86cc7ffff4bbe74fe88981da302cf83231cbce59a8ec0d
4
+ data.tar.gz: 15f849bc8342043994590d68b2caa5ea439a7c9a9c89a16a04a03211d3f47250
5
5
  SHA512:
6
- metadata.gz: c66f3841c5aa04056f19556423a5ee358e8635a59dc328346a623c730d611600c8fbca1064a4819cd77fc145f72e6ade2aa2e073fa997576a9c206eb9619a68c
7
- data.tar.gz: d8cdcfa78609de1af4b2661f7a871c292e3f78bd24352aeaf9c94645ac05964f3a5460574cd5dcac78aa6fcc4472a4f92213f3d041ed63cbbeef91f946f26f42
6
+ metadata.gz: edd5e60ccba0dd53b403290dc1956df060e2d31ca61c2959feb97d9ee80f8cda6802e8b90c441f8571fbf254e93929c9ba382af284cfda5ef3de997319a7e52d
7
+ data.tar.gz: 866f0482f61a59968b7b8fe3c4923551e3e0920416383aa5aa146ce1c4a827fb5f917bceef4297d020058c6e4a76f047c3027166937ff05ba9d1adc3216292b9
data/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
- ## [Unreleased]
1
+ ## ['2.2.0'] - 2022-09-24
2
+ * Enhancements:
3
+ * Add support for `branch-name create` `-x` argument (see `branch-name help create`) which allows you to position the ticket and ticket description within the forulated branch name.
4
+ * The `branch-name create :project_location` option string now accepts any [`Time.strftime`](`https://apidock.com/ruby/Time/strftime`) format directive.
5
+ * Add better test coverage, although not what it should be (I'm working on it); this started a "quick and dirty" tool.
6
+ * `branch-name create` will now create the PROJECT_LOCATION if it does not exist.
7
+ * Update README.md file.
8
+
9
+ ## ['2.1.0'] - 2022-09-22
10
+ * Enhancements: Add support for Windows clipboard. Branch names created are copied to the clibboard for macOS and Windows now.
2
11
 
3
12
  ## ['2.0.1-beta] - 2022-09-20
4
13
  * Bug fixes: ticket description was not joined properly (without token separator).
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- branch-name (2.0.1.pre.beta)
4
+ branch-name (2.2.0)
5
5
  activesupport (~> 7.0, >= 7.0.4)
6
6
  colorize (~> 0.8.1)
7
+ os (~> 1.1, >= 1.1.4)
7
8
  thor (~> 1.2, >= 1.2.1)
8
9
 
9
10
  GEM
@@ -27,6 +28,7 @@ GEM
27
28
  kwalify (0.7.2)
28
29
  method_source (1.0.0)
29
30
  minitest (5.16.3)
31
+ os (1.1.4)
30
32
  parallel (1.22.1)
31
33
  parser (3.1.2.1)
32
34
  ast (~> 2.4.1)
data/README.md CHANGED
@@ -8,9 +8,9 @@
8
8
 
9
9
  ## Caveats
10
10
 
11
- NOTE: This documentation assumes *macos* and any reference to `<username>` should be assumed to equal `$ whoami` unless otherwise noted.
11
+ NOTE: This documentation assumes *macOS* and any reference to `<username>` should be assumed to equal `$ whoami` unless otherwise noted.
12
12
 
13
- NOTE: This documentation makes reference to *cards* and/or *tickets*; these terms should be considered synonymous, and are used to refer to *user stories*, *tasks*, *bugs*, etc.: work that is normally created against a software development team's [Jira](https://www.atlassian.com/software/jira) Project board while adhering to [Agile development methodology](https://www.atlassian.com/agile#:~:text=Agile%20is%20an%20iterative%20approach,small%2C%20but%20consumable%2C%20increments.). While `branch-name` was created to be used while practicing Agile, `branch-name` can be used outside the Agile context as well.
13
+ NOTE: This documentation makes reference to *cards* and/or *tickets*; these terms should be considered synonymous, and are used to refer to *user stories*, *tasks*, *bugs*, etc.; that is, work that is normally created against a software development team's [Jira](https://www.atlassian.com/software/jira) Project board while adhering to [Agile development methodology](https://www.atlassian.com/agile#:~:text=Agile%20is%20an%20iterative%20approach,small%2C%20but%20consumable%2C%20increments.). While `branch-name` was created to be used while practicing Agile, `branch-name` can be used outside the Agile context as well.
14
14
 
15
15
 
16
16
  ## Installation
@@ -19,7 +19,7 @@ NOTE: This documentation makes reference to *cards* and/or *tickets*; these term
19
19
 
20
20
  ## Usage/Examples
21
21
 
22
- ### `branch-name` help
22
+ ### `branch-name` Help
23
23
  ```shell
24
24
  # Display general branch-name help
25
25
  $ branch-name help
@@ -34,7 +34,7 @@ $ branch-name config help init
34
34
  $ branch-name config help delete
35
35
  ```
36
36
 
37
- ### Initialize `branch-name` configuration files
37
+ ### Initialize `branch-name` Configuration Files
38
38
  Setting up *global* settings would be a good place to start:
39
39
 
40
40
  ```
@@ -42,9 +42,9 @@ $ branch-name config init global
42
42
  #=> Configuration file (/Users/<username>/.branch-name) created
43
43
  ```
44
44
 
45
- This creates a `.branch-name` .yaml configuration file the home folder of the current user (`$ whoami` on *macos*) with the following option defaults. The option defaults created will be used with their respective `branch-name` command indicated by the `branch-name` command name under which each option resides. You may manually alter any of the option values to suite your needs. To determine what options are available for each `branch-name` command, simply view help for that particular command. If a `brnch-name` command is *not* found in the `.branch-name` confg file when it is first initialized (e.g. `$ branch-name config init global #=> /Users/<username>/.branch-name`), default options for that particular `branch-name` command is not currently supported.
45
+ This creates a `.branch-name` yaml configuration file the home folder of the current user (`$ whoami` on *macOS*) with the below option defaults. The option defaults created will be used with their respective `branch-name` command indicated by the `branch-name` command name under which each option resides. You may manually alter any of the option values to suite your needs. To determine what options are available for each `branch-name` command, simply view help for that particular command. If a `branch-name` command is *not* found in the `.branch-name` config file when it is first initialized (e.g. `$ branch-name config init global #=> /Users/<username>/.branch-name`), default options for that particular `branch-name` command are not currently supported.
46
46
 
47
- For example, the following default options will be used whenever the `branch-name create` command is executed for the user "`<username>`":
47
+ Below is a list of _default_ options created when initializing _global_ options; consequently, these default options will be used whenever the `branch-name create` command is executed for the user "`<username>`":
48
48
 
49
49
  ```yaml
50
50
  # /Users/<username>/.branch-name
@@ -52,23 +52,27 @@ For example, the following default options will be used whenever the `branch-nam
52
52
  create:
53
53
  downcase: false
54
54
  separator: _
55
+ format_string: "%t %d"
55
56
  project: false
56
- project_location: "/Users/<username>"
57
+ project_location: "/Users/<username>/branch-name/projects/%Y/%m (%B)"
57
58
  project_files:
58
- - scratch.rb
59
59
  - readme.txt
60
+ - scratch.rb
61
+ - snippets.rb
60
62
  ```
61
63
 
62
- NOTE: It is recommended that you change the default `create: project_location` to a more suitable location depending on your *os*. For example, on *macos* you might want to change this to `"/Users/<username>/Documents"`, `"/Users/<username>/Documents/features"`, or something similar.
64
+ NOTE: You can manually change any of the options you wish. It is recommended that you change the default `create: project_location` to meet your needs, depending on your *os*. For example, on *macOS* you might want to change this to `"/Users/<username>/Documents"`, `"/Users/<username>/Documents/features"`, or something similar.
65
+
66
+ The `create: project_location` option string also accepts any [`Time.strftime`](`https://apidock.com/ruby/Time/strftime`) format directives.
63
67
 
64
- Any or all of these options can be overwritten on the command-line:
68
+ The `create: format_string` option string can be used to position the *ticket* (`%t`) and *ticket description* (`%d`) within the branch name formulated. You can also include any other information you wish in the format string, for example: "`<username> %t %d`". However, non-word characters will be stripped (see `Branch::Name::Normalizable::NON_WORD_CHARS_REGEX` which equates to `/[\W_]/`)
65
69
 
66
- For more information:
70
+ Any or all of these options can also be overwritten on the command-line. For more information:
67
71
  `$ branch-name config help init`
68
72
 
69
73
  ### Creating Feature Branch Names and Projects Examples
70
74
 
71
- NOTE: `branch-name create` really doesn't "create" anything (unless you use the `-p` option, in which case it will create a "project" for you); rather, `branch-name create` simply formulates a suitable feature branch name given a *jira* ticket and *jira* ticket description.
75
+ NOTE: `branch-name create` really doesn't "create" anything (unless you use the `-p` option, in which case it will create a "project" for you); rather, `branch-name create` simply _formulates_ a suitable feature branch name given a *jira* ticket and *jira* ticket description.
72
76
 
73
77
  NOTE: The below examples will assume the following `global` config file defaults (`$ branch-name config init global`) that have been *manually* manipulated to have the following options:
74
78
 
@@ -79,14 +83,14 @@ create:
79
83
  downcase: false
80
84
  separator: _
81
85
  project: false
82
- project_location: "/Users/<username>/feature-branches/2022"
86
+ project_location: "/Users/<username>/feature-branches/%Y"
83
87
  project_files:
84
88
  - readme.txt
85
89
  - scratch.rb
86
90
  - snippets.rb
87
91
  ```
88
92
 
89
- This example formulates feature a branch named *lg-12345-pay-down-tech-debt-on-user-model* by converting the ticket and ticket description to lowercase (`-d`) and delimiting the feature branch name tokens with a "-" character (`-s -`). The `-p` option instructs `branch-name create` to create the project folder */Users/<username>/feature-branches/2022/lg-12345-pay-down-tech-debt-on-user-model*. The aforementioned project folder will also contain the following files: readme.txt, scratch.rb and snippets.rb. In addition to this, `branch-name create` will also copy the feature brach name to the clipboard for you. This is convienient when you need to create a feature branch in github, or from the command-line.
93
+ This example formulates feature a branch named *lg-12345-pay-down-tech-debt-on-user-model* by converting the ticket and ticket description to lowercase (`-d`) and delimiting the feature branch name tokens with a "-" character (`-s -`). The `-p` option instructs `branch-name create` to create the project folder */Users/<username>/feature-branches/2022/lg-12345-pay-down-tech-debt-on-user-model*. The aforementioned project folder will also contain the following files: readme.txt, scratch.rb and snippets.rb. In addition to this, `branch-name create` will also copy the feature brach name to the clipboard for you (macOS and Windows currently supported). This is convenient when you need to create a feature branch in github, or from the command-line.
90
94
 
91
95
  ```shell
92
96
  $ branch-name create -p -d -s - "Pay down tech debt on User model" LG-12345
data/branch-name.gemspec CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
 
35
35
  spec.add_dependency 'activesupport', '~> 7.0', '>= 7.0.4'
36
36
  spec.add_dependency 'colorize', '~> 0.8.1'
37
+ spec.add_dependency 'os', '~> 1.1', '>= 1.1.4'
37
38
  spec.add_dependency 'thor', '~> 1.2', '>= 1.2.1'
38
39
 
39
40
  # Remove this for now.
@@ -43,7 +43,7 @@ module Branch
43
43
 
44
44
  SYNOPSIS
45
45
  \x5
46
- branch-name create [-l|-f|-d|-s|-p] DESCRIPTION [TICKET]
46
+ branch-name create [-l|-f|-d|-s|-p|-x] DESCRIPTION [TICKET]
47
47
 
48
48
  \x5
49
49
  The following options are available:
@@ -69,9 +69,17 @@ module Branch
69
69
  A "project" is a folder that is created in the PROJECT_LOCATION specified,
70
70
  whose name is equivalent to the branch name that is formulated.
71
71
  The default is: "#{Locatable.project_folder(options: options)}".
72
+
73
+ \x5 -x FORMAT_STRING: This is a string that determines the format of the branch name
74
+ that is formulated. The following are a list of required placeholders you must put
75
+ in your format string to format the brach name: [%t, %d].
76
+ \x5Where %t will be replaced by the ticket.
77
+ \x5Where %d will be replaced by the ticket description.
78
+ \x5The default is: "#{DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']}".
72
79
  LONG_DESC
73
80
  method_option :downcase, type: :boolean, aliases: '-d'
74
81
  method_option :separator, type: :string, aliases: '-s'
82
+ method_option :format_string, type: :string, aliases: '-x'
75
83
  method_option :project, type: :boolean, aliases: '-p'
76
84
  method_option :project_location, type: :string, aliases: '-l'
77
85
  method_option :project_files, type: :array, aliases: '-f'
@@ -84,7 +92,10 @@ module Branch
84
92
 
85
93
  init_options_for! command: :create
86
94
 
87
- branch_name = normalize_branch_name(ticket_description, ticket)
95
+ branch_name = normalize_branch_name(ticket_description, ticket) do |error|
96
+ say_error error.message
97
+ exit 1
98
+ end
88
99
 
89
100
  say "Branch name: #{branch_name}", :cyan
90
101
 
@@ -1,16 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'os'
4
+
3
5
  module Branch
4
6
  module Name
5
7
  module Clipable
6
8
  module_function
7
9
 
8
10
  def copy_to_clipboard(text)
9
- if /darwin/.match?(RUBY_PLATFORM)
10
- IO.popen('pbcopy', 'w') { |pipe| pipe.puts text }
11
+ if OS.mac?
12
+ copy_to_clipboard_macos text
13
+ true
14
+ elsif OS.windows?
15
+ copy_to_clipboard_windows text
11
16
  true
17
+ else
18
+ false
12
19
  end
13
20
  end
21
+
22
+ def copy_to_clipboard_macos(text)
23
+ copy_to_clipboard_with(app: 'pbcopy', text: text)
24
+ end
25
+
26
+ def copy_to_clipboard_windows(text)
27
+ copy_to_clipboard_with(app: 'clip', text: text)
28
+ end
29
+
30
+ def copy_to_clipboard_with(app:, text:)
31
+ IO.popen(app, 'w') { |pipe| pipe.puts text }
32
+ end
14
33
  end
15
34
  end
16
35
  end
@@ -16,8 +16,9 @@ module Branch
16
16
  'create' => {
17
17
  'downcase' => false,
18
18
  'separator' => '_',
19
+ 'format_string' => '%t %d',
19
20
  'project' => false,
20
- 'project_location' => Locatable.project_folder,
21
+ 'project_location' => "#{Locatable.project_folder}/branch-name/projects/%Y/%m (%B)",
21
22
  'project_files' => %w[readme.txt scratch.rb snippets.rb]
22
23
  }
23
24
  }.freeze
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/object/blank'
3
4
  require 'colorize'
4
5
  require 'pathname'
5
6
 
@@ -1,25 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'option_error'
4
+
3
5
  module Branch
4
6
  module Name
5
7
  module Normalizable
6
8
  NON_WORD_CHARS_REGEX = /[\W_]/
7
9
 
8
10
  def normalize_branch_name(ticket_description, ticket)
9
- normalized_ticket_description = normalize_ticket_description ticket_description
10
- return normalized_ticket_description if ticket.blank?
11
+ formatted_branch_name = format_string_or_default
12
+ formatted_branch_name = formatted_branch_name.gsub('%t', ticket || '')
13
+ formatted_branch_name = formatted_branch_name.gsub('%d', ticket_description)
14
+ formatted_branch_name = normalize_token formatted_branch_name
15
+ rescue Branch::Name::OptionError => e
16
+ raise unless block_given?
11
17
 
12
- normalized_ticket = normalize_ticket ticket
13
- "#{normalized_ticket}#{options[:separator]}#{normalized_ticket_description}"
18
+ yield e
14
19
  end
15
20
 
16
21
  private
17
22
 
23
+ def format_string_or_default
24
+ format_string = options[:format_string].presence ||
25
+ Configurable::DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']
26
+ unless %w[%t %d].all? { |o| format_string.include?(o) }
27
+ raise Branch::Name::OptionError.new(
28
+ 'was called having argument [-x/--format-string] ' \
29
+ 'which did not contain %t and %d format placeholders',
30
+ current_command_chain.first
31
+ )
32
+ end
33
+
34
+ format_string
35
+ end
36
+
18
37
  def normalize_ticket_description(ticket_description)
19
38
  normalize_token ticket_description
20
39
  end
21
40
 
22
41
  def normalize_ticket(ticket)
42
+ return if ticket.blank?
43
+
23
44
  ticket.split(NON_WORD_CHARS_REGEX).filter_map do |token|
24
45
  normalize_token(token)
25
46
  end.join(options[:separator])
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Branch
4
+ module Name
5
+ class OptionError < StandardError
6
+ attr_reader :command
7
+
8
+ def initialize(msg, command)
9
+ super(msg)
10
+
11
+ @command = command
12
+ end
13
+
14
+ def message
15
+ "ERROR: \"branch-name #{command}\" #{super}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -11,7 +11,8 @@ module Branch
11
11
  def create_project!(branch_name)
12
12
  raise 'options[:project] is false' unless options[:project]
13
13
 
14
- project_folder = "#{options[:project_location]}/#{branch_name}"
14
+ project_location = Time.new.strftime(options[:project_location])
15
+ project_folder = "#{project_location}/#{branch_name}"
15
16
 
16
17
  if Dir.exist? project_folder
17
18
  puts "Project folder \"#{project_folder}\" already exists"
@@ -19,7 +20,7 @@ module Branch
19
20
  return
20
21
  end
21
22
 
22
- Dir.mkdir project_folder
23
+ FileUtils.mkdir_p(project_folder)
23
24
  create_project_files!(project_folder)
24
25
 
25
26
  puts "Project folder \"#{project_folder}\" with project files #{options[:project_files]} was created".green
@@ -3,6 +3,6 @@
3
3
  module Branch
4
4
  module Name
5
5
  # branch-name version
6
- VERSION = '2.0.1-beta'
6
+ VERSION = '2.2.0'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branch-name
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1.pre.beta
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gene M. Angelo, Jr.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-20 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,6 +44,26 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.8.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: os
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.1'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 1.1.4
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '1.1'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.1.4
47
67
  - !ruby/object:Gem::Dependency
48
68
  name: thor
49
69
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +115,7 @@ files:
95
115
  - lib/branch/name/loadable.rb
96
116
  - lib/branch/name/locatable.rb
97
117
  - lib/branch/name/normalizable.rb
118
+ - lib/branch/name/option_error.rb
98
119
  - lib/branch/name/projectable.rb
99
120
  - lib/branch/name/subcommands/config.rb
100
121
  - lib/branch/name/subcommands/init.rb
@@ -119,9 +140,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
140
  version: 3.0.1
120
141
  required_rubygems_version: !ruby/object:Gem::Requirement
121
142
  requirements:
122
- - - ">"
143
+ - - ">="
123
144
  - !ruby/object:Gem::Version
124
- version: 1.3.1
145
+ version: '0'
125
146
  requirements: []
126
147
  rubygems_version: 3.3.22
127
148
  signing_key: