branch-name 3.5.0 → 3.6.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: c3591154bdf0c66a468e6d3d9d6fc06eab5a6a26f1d08abd193c0d9edbdec38c
4
- data.tar.gz: b07809b34114ec1ac53a36934d1e2c81530e9ab3f8f7c08bdfb6c1353d99b86d
3
+ metadata.gz: ab4e1d2055038b5a1dc390420951edc3a1b359f359804b10b8699d67548a0dd2
4
+ data.tar.gz: d002928e6ede613707e119f3703f7724444e443a607eea8729cd15fda7c9636a
5
5
  SHA512:
6
- metadata.gz: 0d66fb0d787e92b8747bc8d3defbe1bba52930118e03a8eef7eeb910632239a046825876ef3a1bde27e65943767792b72925dab6281601c95208d99746619564
7
- data.tar.gz: 0772f605b9f5995a442c970199011ebdbe73da4a92b6521e6d92b7d7b62fbe4f7861d868bdd8ab91c71870378373b1caa4759e2caf91ae6cdb37c459579f7e38
6
+ metadata.gz: 7e20a24062daf1a3707fddbb6f809e1753c22e5ab61e8309a394a729f083e93147316b7b8e5fa07e611f82cbb117e41aacc198266fc979169e1b4de74249fd6a
7
+ data.tar.gz: 3d760194ca03920161ddef676b2d0f12c2519e9350fb5221d6fe667bf79a6965e6bb3c3e3b1e4e24be586d47e8d88acccb63069c87883f07e7990e90476c376d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## ['3.6.0'] - 2022-10-06
2
+ * Changes
3
+ * Added a `-i` (interactive) option to `branch-name create`. When used in conjunction with the `-p` option (project creation), if the `-i` option is used, the user will be prompted to create the project. If the `-i` option is NOT used, the user will NOT be prompted when creating the project.
4
+ * Update the README.md file accordign to the aforementioned.
5
+
6
+ ## ['3.5.1'] - 2022-10-05
7
+ * Bug Fixes
8
+ * Fix bug that failed to remove underscore (_) characters in ticket and ticket descriptions from folder and branch name formulation.
9
+ * Fix bug that allowed unacceptable project folder token separators in the project folder name (-p option). The rule is now: for `branch-name create`, if the `options[:separator]` option (-s) is included in `Branch::Name::Normalizable::PROJECT_FOLDER_TOKEN_SEPARATORS`, `options[:separator]` (-s) will be used as the project folder token separator; otherwise, `Branch::Name::Normalizable::DEFAULT_PROJECT_FOLDER_TOKEN_SEPARATOR` will be used.
10
+ * Changes
11
+ * Add test coverage for the above scenarios.
12
+ * Use File.join to join paths and files safely where appropriate.
13
+ * Update .gemspec gem description with more detail.
14
+
1
15
  ## ['3.5.0'] - 2022-10-04
2
16
  * Changes
3
17
  * Fix broken link to CHANGELOG.md in .gemspec file.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- branch-name (3.5.0)
4
+ branch-name (3.6.0)
5
5
  activesupport (~> 7.0, >= 7.0.4)
6
6
  colorize (~> 0.8.1)
7
7
  os (~> 1.1, >= 1.1.4)
data/README.md CHANGED
@@ -76,7 +76,7 @@ NOTE: You can manually change any of the options you wish. It is recommended tha
76
76
 
77
77
  The `create: project_location` option string also accepts any [`Time.strftime`](`https://apidock.com/ruby/Time/strftime`) format directives.
78
78
 
79
- 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_]/`)
79
+ 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, particular characters will be stripped to formulate the branch name (see `Branch::Name::Normalizable::BRANCH_NAME_REGEX` which equates to `%r{[^/\w\x20]|_}`).
80
80
 
81
81
  Any or all of these options can also be overwritten on the command-line. For more information:
82
82
  `$ branch-name config help init`
@@ -100,14 +100,17 @@ create:
100
100
  - readme.txt
101
101
  - scratch.rb
102
102
  - snippets.rb
103
+ interactive: true
103
104
  ```
104
105
 
105
- 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.
106
+ 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*, and finally, the `-i false` option instructs `branch-name` to *not* prompt the user when creating projects. 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.
106
107
 
107
108
  ```shell
108
- $ branch-name create -p -d -s - "Pay down tech debt on User model" LG-12345
109
+ $ branch-name create -i false -p -d -s - "Pay down tech debt on User model" LG-12345
109
110
  ```
110
111
 
112
+ NOTE: When creating projects, `branch-name` will prompt you if the `interactive` option is true (`-i`).
113
+
111
114
  This example simply formulates feature a branch named *Add_create_and_destroy_session_controller_actions* and copies it to the clipboard.
112
115
 
113
116
  ```shell
@@ -133,7 +136,7 @@ $ branch-name create "<username>/UX-54321 Remove debug code"
133
136
  ...
134
137
  ```
135
138
 
136
- NOTE: Project folders created (`--project/-p`) will replace any forward-slash with the `create: :separator` option value.
139
+ NOTE: Project folders that are formulated (`branch-name create [-p|--project] ...`), will have any tokens comprising the project folder name delimited according to the following rules: if the `options[:separator]` option (-s) is included in `Branch::Name::Normalizable::PROJECT_FOLDER_TOKEN_SEPARATORS`, `options[:separator]` (-s) will be used as the project folder token delimiter; otherwise, `Branch::Name::Normalizable::DEFAULT_PROJECT_FOLDER_TOKEN_SEPARATOR` will be used.
137
140
 
138
141
  ## Development
139
142
 
data/branch-name.gemspec CHANGED
@@ -9,7 +9,13 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ['public.gma@gmail.com']
10
10
 
11
11
  spec.summary = 'Generates a branch name based on a JIRA ticket/ticket number.'
12
- spec.description = 'Generates a branch name based on a JIRA ticket/ticket number.'
12
+ spec.description = <<-EOF
13
+ branch-name is a gem that provides a command-line interface that allows you to accomplish several tasks, tasks I personally find myself having to carry out every time I work on a feature branch. I created this gem for myself; however, you are free to use it yourself, if any of these tasks fits into your personal routine:
14
+
15
+ 1. Formulate a git feature branch name, given a jira ticket and jira ticket description. Why? Because I am constantly having to create git feature branch names that are based on jira ticket and jira ticket descriptions.
16
+ 2. Optionally create a "project" based on the branch name (formulated in step 1 above). Why? Because I'm constantly having to create folders to manage files associated with the feature branches I am working on.
17
+ 3. Optionally use and manage default options that determine the git feature branch name formulated, project greated, and default files associated with the project.Why? Because I routinely have to create files to support the feature I am working on and associate them with the feature I am working on. For example: scratch.rb to hold scratch code, snippets.rb to hold code to execute to perform redundant tasks, and readme.txt files to document things I need to remember.
18
+ EOF
13
19
  spec.homepage = 'https://github.com/gangelo/branch-name'
14
20
  spec.license = 'MIT'
15
21
 
@@ -44,42 +44,46 @@ module Branch
44
44
 
45
45
  SYNOPSIS
46
46
  \x5
47
- branch-name create [-l|-f|-d|-s|-p|-x] DESCRIPTION [TICKET]
47
+ branch-name create [-i|-l|-f|-d|-s|-p|-x] DESCRIPTION [TICKET]
48
48
 
49
49
  \x5
50
50
  The following options are available:
51
51
 
52
52
  \x5 NOTE: Default option values will be overidden if .branch-name config files
53
- are present. Run `branch-name config info` to determine what config files
54
- are present.
53
+ are present. Run `branch-name config info` to determine what config files
54
+ are present.
55
55
 
56
56
  \x5 -d: Forces the branch name to lower case.
57
- The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['downcase']}.
58
-
59
- \x5\x5 -s SEPARATOR: Indicates the SEPARATOR that will be used to delimit tokens in the branch name.
60
- The default SEPARATOR is: '#{DEFAULT_BRANCH_NAME_OPTIONS['create']['separator']}'.
61
-
62
- \x5\x5 -p: Indicates that a project should be created.
63
- The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['project']}.
57
+ The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['downcase']}.
64
58
 
65
59
  \x5 -f: Used with the -p option. If -f is specified, project files
66
- will be created in the PROJECT_LOCATION specified by the -l option.
67
- The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['project_files']}.
60
+ will be created in the PROJECT_LOCATION specified by the -l option.
61
+ The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['project_files']}.
62
+
63
+ \x5 -i: Interactive. Used with the -p option. If -i is specified, you will
64
+ be prompted when creating project folders. If -i is not specified, you will
65
+ NOT be prompted when creating project folders.
68
66
 
69
67
  \x5\x5 -l PROJECT_LOCATION: Indicates where the project should be created.
70
- A "project" is a folder that is created in the PROJECT_LOCATION specified,
71
- whose name is equivalent to the branch name that is formulated.
72
- The default is: "#{Locatable.project_folder(options: options)}".
68
+ A "project" is a folder that is created in the PROJECT_LOCATION specified,
69
+ whose name is equivalent to the branch name that is formulated.
70
+ The default is: "#{Locatable.project_folder(options: options)}".
71
+
72
+ \x5\x5 -p: Indicates that a project should be created.
73
+ The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['project']}.
74
+
75
+ \x5\x5 -s SEPARATOR: Indicates the SEPARATOR that will be used to delimit tokens in the branch name.
76
+ The default SEPARATOR is: '#{DEFAULT_BRANCH_NAME_OPTIONS['create']['separator']}'.
73
77
 
74
78
  \x5 -x FORMAT_STRING: This is a string that determines the format of the branch name
75
- that is formulated. The following is a list of required placeholders you must put
76
- in your format string to format the branch name: [%t, %d].
77
- \x5Where %t will be replaced by the ticket.
78
- \x5Where %d will be replaced by the ticket description.
79
- \x5The following is a list of optional placeholders you may put
80
- in your format string to format the branch name: [%u].
81
- \x5Where %u will be replaced with your username (`Etc.getlogin`, https://rubygems.org/gems/etc).
82
- \x5The default format string is: "#{DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']}".
79
+ that is formulated. The following is a list of required placeholders you must put
80
+ in your format string to format the branch name: [%t, %d].
81
+ \x5Where %t will be replaced by the ticket.
82
+ \x5Where %d will be replaced by the ticket description.
83
+ \x5The following is a list of optional placeholders you may put
84
+ in your format string to format the branch name: [%u].
85
+ \x5Where %u will be replaced with your username (`Etc.getlogin`, https://rubygems.org/gems/etc).
86
+ \x5The default format string is: "#{DEFAULT_BRANCH_NAME_OPTIONS['create']['format_string']}".
83
87
  LONG_DESC
84
88
  method_option :downcase, type: :boolean, aliases: '-d'
85
89
  method_option :separator, type: :string, aliases: '-s'
@@ -87,6 +91,7 @@ module Branch
87
91
  method_option :project, type: :boolean, aliases: '-p'
88
92
  method_option :project_location, type: :string, aliases: '-l'
89
93
  method_option :project_files, type: :array, aliases: '-f'
94
+ method_option :interactive, type: :boolean, aliases: '-i'
90
95
 
91
96
  def create(ticket_description, ticket = nil)
92
97
  if ticket_description.blank?
@@ -108,11 +113,13 @@ module Branch
108
113
  say_error error.message
109
114
  exit 1
110
115
  end
111
- project_folder = project_folder_for branch_name
112
- unless yes? "Create project for branch \"#{branch_name}\" " \
113
- "in folder \"#{project_folder}\" (y/n)?", :cyan
114
- say 'Aborted.', ABORTED
115
- return
116
+ if options[:interactive]
117
+ project_folder = project_folder_for branch_name
118
+ unless yes? "Create project for branch \"#{branch_name}\" " \
119
+ "in folder \"#{project_folder}\" (y/n)?", :cyan
120
+ say 'Aborted.', ABORTED
121
+ return
122
+ end
116
123
  end
117
124
 
118
125
  say "Project folder name: \"#{project_folder_name}\"", :cyan
@@ -22,7 +22,8 @@ module Branch
22
22
  'format_string' => '%t %d',
23
23
  'project' => false,
24
24
  'project_location' => "#{Locatable.project_folder}/branch-name/projects/%Y/%m (%B)",
25
- 'project_files' => %w[readme.txt scratch.rb snippets.rb]
25
+ 'project_files' => %w[readme.txt scratch.rb snippets.rb],
26
+ 'interactive' => true
26
27
  }
27
28
  }.freeze
28
29
  # rubocop:enable Style/StringHashKeys
@@ -7,18 +7,28 @@ module Branch
7
7
  module Normalizable
8
8
  # The regex used to split ticket and ticket description tokens
9
9
  # to formulate a source control branch name.
10
- BRANCH_NAME_REGEX = %r{[^/\w\x20]}
10
+ BRANCH_NAME_REGEX = %r{[^/\w\x20]|_}
11
11
 
12
12
  # The regex used to split ticket and ticket description tokens
13
13
  # to formulate a project folder based on the branch name formulated.
14
14
  PROJECT_FOLDER_REGEX = /[\W_]/
15
15
 
16
+ # Acceptable project folder token separators. If options[:separator]
17
+ # returns one of these acceptable values, it will be used; otherwise
18
+ # DEFAULT_PROJECT_FOLDER_TOKEN_SEPARATOR will be used.
19
+ PROJECT_FOLDER_TOKEN_SEPARATORS = %w[- _].freeze
20
+
21
+ # The default project folder token separator if options[:separator] is
22
+ # not an acceptable project folder token separator
23
+ # (i.e. PROJECT_FOLDER_TOKEN_SEPARATORS).
24
+ DEFAULT_PROJECT_FOLDER_TOKEN_SEPARATOR = PROJECT_FOLDER_TOKEN_SEPARATORS.first
25
+
16
26
  def normalize_branch_name(ticket_description, ticket)
17
27
  formatted_branch_name = format_string_or_default
18
28
  formatted_branch_name = formatted_branch_name.gsub('%t', ticket || '')
19
29
  formatted_branch_name = formatted_branch_name.gsub('%d', ticket_description)
20
30
  formatted_branch_name = formatted_branch_name.gsub('%u', Etc.getlogin)
21
- normalize_token formatted_branch_name, BRANCH_NAME_REGEX
31
+ normalize_token formatted_branch_name, BRANCH_NAME_REGEX, options[:separator]
22
32
  rescue Branch::Name::OptionError => e
23
33
  raise unless block_given?
24
34
 
@@ -29,7 +39,7 @@ module Branch
29
39
  # The location of the folder is not included; that is, the
30
40
  # folder returned is not fully qualified.
31
41
  def project_folder_name_from(normalized_branch_name)
32
- normalize_token normalized_branch_name, PROJECT_FOLDER_REGEX
42
+ normalize_token normalized_branch_name, PROJECT_FOLDER_REGEX, project_folder_separator
33
43
  rescue Branch::Name::OptionError => e
34
44
  raise unless block_given?
35
45
 
@@ -52,15 +62,22 @@ module Branch
52
62
  format_string
53
63
  end
54
64
 
55
- def normalize_token(token, regex)
65
+ def normalize_token(token, regex, separator)
56
66
  token = token.gsub(regex, ' ')
57
67
  token = token.strip
58
68
  .squeeze(' ')
59
- .split.join(options[:separator])
60
- token = token.squeeze(options[:separator])
69
+ .split.join(separator)
70
+ token = token.squeeze(separator)
61
71
  token = token.downcase if options[:downcase]
62
72
  token
63
73
  end
74
+
75
+ def project_folder_separator
76
+ separator = options[:separator]
77
+ return options[:separator] if PROJECT_FOLDER_TOKEN_SEPARATORS.include? separator
78
+
79
+ DEFAULT_PROJECT_FOLDER_TOKEN_SEPARATOR
80
+ end
64
81
  end
65
82
  end
66
83
  end
@@ -2,11 +2,13 @@
2
2
 
3
3
  require 'fileutils'
4
4
  require_relative 'locatable'
5
+ require_relative 'normalizable'
5
6
 
6
7
  module Branch
7
8
  module Name
8
9
  module Projectable
9
10
  include Locatable
11
+ include Normalizable
10
12
 
11
13
  def create_project!(branch_name)
12
14
  raise 'options[:project] is false' unless options[:project]
@@ -52,8 +54,9 @@ module Branch
52
54
  end
53
55
 
54
56
  def project_folder_for(branch_name)
57
+ branch_name = project_folder_name_from branch_name
55
58
  project_location = Time.new.strftime(options[:project_location])
56
- "#{project_location}/#{branch_name}"
59
+ File.join(project_location, branch_name)
57
60
  end
58
61
  end
59
62
  end
@@ -3,6 +3,6 @@
3
3
  module Branch
4
4
  module Name
5
5
  # branch-name version
6
- VERSION = '3.5.0'
6
+ VERSION = '3.6.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: 3.5.0
4
+ version: 3.6.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-10-04 00:00:00.000000000 Z
11
+ date: 2022-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -84,7 +84,12 @@ dependencies:
84
84
  - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: 1.2.1
87
- description: Generates a branch name based on a JIRA ticket/ticket number.
87
+ description: |2
88
+ branch-name is a gem that provides a command-line interface that allows you to accomplish several tasks, tasks I personally find myself having to carry out every time I work on a feature branch. I created this gem for myself; however, you are free to use it yourself, if any of these tasks fits into your personal routine:
89
+
90
+ 1. Formulate a git feature branch name, given a jira ticket and jira ticket description. Why? Because I am constantly having to create git feature branch names that are based on jira ticket and jira ticket descriptions.
91
+ 2. Optionally create a "project" based on the branch name (formulated in step 1 above). Why? Because I'm constantly having to create folders to manage files associated with the feature branches I am working on.
92
+ 3. Optionally use and manage default options that determine the git feature branch name formulated, project greated, and default files associated with the project.Why? Because I routinely have to create files to support the feature I am working on and associate them with the feature I am working on. For example: scratch.rb to hold scratch code, snippets.rb to hold code to execute to perform redundant tasks, and readme.txt files to document things I need to remember.
88
93
  email:
89
94
  - public.gma@gmail.com
90
95
  executables: