branch-name 1.0.0.pre.beta → 2.0.0.pre.beta

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: b7dad0772990843cd87dc265aa42d9ddd8fc91c0c50db1c8d0e7d48be3ca7129
4
- data.tar.gz: 6b64ae358a4105d1495f10a5d5d4e24997ee0c45fbdb9e10135e295d3ff686ae
3
+ metadata.gz: 166d6b67749f23a48cca5435c6b4b923d57b9e8f4e716ff61c5765da932b686a
4
+ data.tar.gz: e5c041c60834c56da210d0843e0bf099e62fa21adb120f46a1d58b07793f2cbb
5
5
  SHA512:
6
- metadata.gz: b90aa2baa2030cd11a7ded0189f3efc273d923e42dad82f6150b670570cf95375930948fb05aaa5a7348429e32a53f2de8a91fbc5f9dfdabf5315851c7078db4
7
- data.tar.gz: ca83be22b65d2174bfb88ab3cf971306008179856557f4c39870cd427b0cbcfcda921646cb78cd51110b8b0b3eee8e97d54868f61567848fe52cb8d964962668
6
+ metadata.gz: 48334163ec2756cdebfd45344ec91b34e602d0b78573e52aa61418ff8915b77107513e3745cf0cd10c353cb84f669993ff0835c37b964500405c67b9b46cc9ce
7
+ data.tar.gz: f3ec35602f29a9edcd699383697fcb5aac3773122f9db42f82dc7748f646fa2c20bedf6fbaf0cb48d716b93a6d154ce2d5c1a5e34a657f0ea8d6c23265bff976
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- branch-name (1.0.0.pre.beta)
4
+ branch-name (2.0.0.pre.beta)
5
5
  activesupport (~> 7.0, >= 7.0.4)
6
6
  colorize (~> 0.8.1)
7
7
  thor (~> 1.2, >= 1.2.1)
data/README.md CHANGED
@@ -1,28 +1,102 @@
1
- # Branch::Name
1
+ # `branch-name`
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/branch/name`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ `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:
4
+
5
+ 1. Formulate a git *feature branch name*, given a [jira](https://www.atlassian.com/software/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.**
6
+ 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.**
7
+ 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.**
8
+
9
+ ## Caveats
10
+
11
+ NOTE: This documentation assumes *macos* and any reference to `<username>` should be assumed to equal `$ whoami` unless otherwise noted.
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.
4
14
 
5
- TODO: Delete this and the text above, and describe your gem
6
15
 
7
16
  ## Installation
8
17
 
9
- Add this line to your application's Gemfile:
18
+ $ gem install branch-name
19
+
20
+ ## Usage/Examples
10
21
 
11
- ```ruby
12
- gem 'branch-name'
22
+ ### `branch-name` help
23
+ ```shell
24
+ # Display general branch-name help
25
+ $ branch-name help
26
+
27
+ # Display help for the 'create' command
28
+ $ branch-name help create
29
+
30
+ # Display help for the 'config' command and subsommands
31
+ $ branch-name help config
32
+ $ branch-name config help info
33
+ $ branch-name config help init
34
+ $ branch-name config help delete
13
35
  ```
14
36
 
15
- And then execute:
37
+ ### Initialize `branch-name` configuration files
38
+ Setting up *global* settings would be a good place to start:
39
+
40
+ ```
41
+ $ branch-name config init global
42
+ #=> Configuration file (/Users/<username>/.branch-name) created
43
+ ```
16
44
 
17
- $ bundle install
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.
18
46
 
19
- Or install it yourself as:
47
+ For example, the following default options will be used whenever the `branch-name create` command is executed for the user "`<username>`":
20
48
 
21
- $ gem install branch-name
49
+ ```yaml
50
+ # /Users/<username>/.branch-name
51
+ ---
52
+ create:
53
+ downcase: false
54
+ separator: _
55
+ project: false
56
+ project_location: "/Users/<username>"
57
+ project_files:
58
+ - scratch.rb
59
+ - readme.txt
60
+ ```
22
61
 
23
- ## Usage
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.
24
63
 
25
- TODO: Write usage instructions here
64
+ Any or all of these options can be overwritten on the command-line:
65
+
66
+ For more information:
67
+ `$ branch-name config help init`
68
+
69
+ ### Creating Feature Branch Names and Projects Examples
70
+
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.
72
+
73
+ 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
+
75
+ ```yaml
76
+ # /Users/<username>/.branch-name
77
+ ---
78
+ create:
79
+ downcase: false
80
+ separator: _
81
+ project: false
82
+ project_location: "/Users/<username>/feature-branches/2022"
83
+ project_files:
84
+ - readme.txt
85
+ - scratch.rb
86
+ - snippets.rb
87
+ ```
88
+
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.
90
+
91
+ ```shell
92
+ $ branch-name create -p -d -s - "Pay down tech debt on User model" LG-12345
93
+ ```
94
+
95
+ This example simply formulates feature a branch named *Add_create_and_destroy_session_controller_actions* and copies it to the clipboard.
96
+
97
+ ```shell
98
+ $ branch-name create "Add #create and #destroy session controller actions"
99
+ ```
26
100
 
27
101
  ## Development
28
102
 
data/branch-name.gemspec CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Gene M. Angelo, Jr.']
9
9
  spec.email = ['public.gma@gmail.com']
10
10
 
11
- spec.summary = 'Generates a branch name based on a JIRA card/ticket number.'
12
- spec.description = 'Generates a branch name based on a JIRA card/ticket number.'
13
- spec.homepage = 'https://github.com/gangelo/branch_name'
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.'
13
+ spec.homepage = 'https://github.com/gangelo/branch-name'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.required_ruby_version = '>= 3.0.1'
@@ -9,7 +9,7 @@ require_relative 'configurable'
9
9
  require_relative 'exitable'
10
10
  require_relative 'loadable'
11
11
  require_relative 'locatable'
12
- require_relative 'nameable'
12
+ require_relative 'normalizable'
13
13
  require_relative 'projectable'
14
14
  require_relative 'subcommands/config'
15
15
  require_relative 'version'
@@ -24,7 +24,7 @@ module Branch
24
24
  include Exitable
25
25
  include Loadable
26
26
  include Locatable
27
- include Nameable
27
+ include Normalizable
28
28
  include Projectable
29
29
 
30
30
  class_option :debug, type: :boolean, default: false
@@ -33,21 +33,27 @@ module Branch
33
33
  default_task :create
34
34
  map %w[--version -v] => :version
35
35
 
36
- desc 'create [OPTIONS] TICKET [DESCRIPTION]', 'Formulate a branch name based on a ticket and optional description'
36
+ desc 'create [OPTIONS] DESCRIPTION [TICKET]', 'Formulate a branch name based on a ticket
37
+ description and optional ticket'
37
38
  long_desc <<-LONG_DESC
38
39
  NAME
39
40
  \x5
40
- `branch-name create` -- will formulate a Git branch name based on the TICKET and optional DECRIPTION provided.
41
+ `branch-name create` -- will formulate a Git branch name based on the
42
+ DESCRIPTION and optional TICKET provided.
41
43
 
42
44
  SYNOPSIS
43
45
  \x5
44
- branch-name create [-d|-s|-p|-pL|-pF] TICKET [DESCRIPTION]
46
+ branch-name create [-l|-f|-d|-s|-p] DESCRIPTION [TICKET]
45
47
 
46
48
  \x5
47
49
  The following options are available:
48
50
 
51
+ \x5 NOTE: Default option values will be overidden if .branch-name config files
52
+ are present. Run `branch-name config info` to determine what config files
53
+ are present.
54
+
49
55
  \x5 -d: Forces the branch name to lower case.
50
- The default is --no-downcase
56
+ The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['downcase']}.
51
57
 
52
58
  \x5\x5 -s SEPARATOR: Indicates the SEPARATOR that will be used to delimit tokens in the branch name.
53
59
  The default SEPARATOR is: '#{DEFAULT_BRANCH_NAME_OPTIONS['create']['separator']}'.
@@ -55,11 +61,11 @@ module Branch
55
61
  \x5\x5 -p: Indicates that a project should be created.
56
62
  The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['project']}.
57
63
 
58
- \x5 -pF: Used with the -p option. If -pF is specified, project files
59
- will be created in the PROJECT_LOCATION specified by the -pL option.
64
+ \x5 -f: Used with the -p option. If -f is specified, project files
65
+ will be created in the PROJECT_LOCATION specified by the -l option.
60
66
  The default is: #{DEFAULT_BRANCH_NAME_OPTIONS['create']['project_files']}.
61
67
 
62
- \x5\x5 -pL PROJECT_LOCATION: Indicates where the project should be created.
68
+ \x5\x5 -l PROJECT_LOCATION: Indicates where the project should be created.
63
69
  A "project" is a folder that is created in the PROJECT_LOCATION specified,
64
70
  whose name is equivalent to the branch name that is formulated.
65
71
  The default is: "#{Locatable.project_folder(options: options)}".
@@ -67,19 +73,18 @@ module Branch
67
73
  method_option :downcase, type: :boolean, aliases: '-d'
68
74
  method_option :separator, type: :string, aliases: '-s'
69
75
  method_option :project, type: :boolean, aliases: '-p'
70
- method_option :project_location, type: :string, aliases: '-pL'
71
- method_option :project_files, type: :array, aliases: '-pF'
76
+ method_option :project_location, type: :string, aliases: '-l'
77
+ method_option :project_files, type: :array, aliases: '-f'
72
78
 
73
- def create(ticket, ticket_description = nil)
74
- if ticket.blank?
75
- say_error 'ticket is required', :red
79
+ def create(ticket_description, ticket = nil)
80
+ if ticket_description.blank?
81
+ say_error 'description is required', :red
76
82
  exit 1
77
83
  end
78
84
 
79
85
  init_options_for! command: :create
80
86
 
81
- branch_name = "#{ticket} #{ticket_description}"
82
- branch_name = normalize_branch_name branch_name
87
+ branch_name = normalize_branch_name(ticket_description, ticket)
83
88
 
84
89
  say "Branch name: #{branch_name}", :cyan
85
90
 
@@ -18,7 +18,7 @@ module Branch
18
18
  'separator' => '_',
19
19
  'project' => false,
20
20
  'project_location' => Locatable.project_folder,
21
- 'project_files' => %w[scratch.rb readme.txt]
21
+ 'project_files' => %w[readme.txt scratch.rb snippets.rb]
22
22
  }
23
23
  }.freeze
24
24
  # rubocop:enable Style/StringHashKeys
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Branch
4
+ module Name
5
+ module Normalizable
6
+ NON_WORD_CHARS_REGEX = /[^\w]/
7
+
8
+ 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
+
12
+ normalized_ticket = normalize_ticket ticket
13
+ "#{normalized_ticket}#{options[:separator]}#{normalized_ticket_description}"
14
+ end
15
+
16
+ private
17
+
18
+ def normalize_ticket_description(ticket_description)
19
+ normalize_token ticket_description
20
+ end
21
+
22
+ def normalize_ticket(ticket)
23
+ ticket.split(NON_WORD_CHARS_REGEX).filter_map do |token|
24
+ normalize_token(token)
25
+ end.join(options[:separator])
26
+ end
27
+
28
+ def normalize_token(token)
29
+ token = token.strip
30
+ .squeeze(' ')
31
+ .split.join(options[:separator])
32
+ token = token.gsub(NON_WORD_CHARS_REGEX, '')
33
+ token = token.squeeze(options[:separator])
34
+ token = token.downcase if options[:downcase]
35
+ token
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require 'fileutils'
3
4
  require_relative 'locatable'
@@ -3,6 +3,6 @@
3
3
  module Branch
4
4
  module Name
5
5
  # branch-name version
6
- VERSION = '1.0.0-beta'
6
+ VERSION = '2.0.0-beta'
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: 1.0.0.pre.beta
4
+ version: 2.0.0.pre.beta
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-18 00:00:00.000000000 Z
11
+ date: 2022-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -64,7 +64,7 @@ dependencies:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: 1.2.1
67
- description: Generates a branch name based on a JIRA card/ticket number.
67
+ description: Generates a branch name based on a JIRA ticket/ticket number.
68
68
  email:
69
69
  - public.gma@gmail.com
70
70
  executables:
@@ -94,17 +94,17 @@ files:
94
94
  - lib/branch/name/exitable.rb
95
95
  - lib/branch/name/loadable.rb
96
96
  - lib/branch/name/locatable.rb
97
- - lib/branch/name/nameable.rb
97
+ - lib/branch/name/normalizable.rb
98
98
  - lib/branch/name/projectable.rb
99
99
  - lib/branch/name/subcommands/config.rb
100
100
  - lib/branch/name/subcommands/init.rb
101
101
  - lib/branch/name/version.rb
102
102
  - sig/branch/name.rbs
103
- homepage: https://github.com/gangelo/branch_name
103
+ homepage: https://github.com/gangelo/branch-name
104
104
  licenses:
105
105
  - MIT
106
106
  metadata:
107
- homepage_uri: https://github.com/gangelo/branch_name
107
+ homepage_uri: https://github.com/gangelo/branch-name
108
108
  source_code_uri: https://github.com/gangelo/branch-name
109
109
  changelog_uri: https://github.com/gangelo/branch-name/CHANGELOG.md
110
110
  rubygems_mfa_required: 'true'
@@ -126,5 +126,5 @@ requirements: []
126
126
  rubygems_version: 3.3.22
127
127
  signing_key:
128
128
  specification_version: 4
129
- summary: Generates a branch name based on a JIRA card/ticket number.
129
+ summary: Generates a branch name based on a JIRA ticket/ticket number.
130
130
  test_files: []
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Branch
4
- module Name
5
- module Nameable
6
- def normalize_branch_name(branch_name)
7
- branch_name.strip!
8
- branch_name = branch_name.split.join options[:separator]
9
- branch_name.downcase! if options[:downcase]
10
- branch_name.tr!('_', '-') if options[:separator] == '-'
11
- branch_name.tr!('-', '_') if options[:separator] == '_'
12
- branch_name.squeeze!('-') if options[:separator] == '-'
13
- branch_name.squeeze!('_') if options[:separator] == '_'
14
- branch_name
15
- end
16
- end
17
- end
18
- end