git_tagger 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b5b103ee8cfd2f51ec3ce8dbee324998307f6e8
4
+ data.tar.gz: 9028c14e635eecc8ea1ec474ac1934881f7a02ed
5
+ SHA512:
6
+ metadata.gz: 5a8f7ada6b436722cac63dab568d5b7fa36a73222d858b46a3cc6b93fccc43587b8dc146b4f1326816ab4802f042274c2c374892dd2f9902440e58deb8b89bbb
7
+ data.tar.gz: 93e06b584eb311ef70426b8837a2fea2766e8dbd2585c1077337b8b415ecfd1acf2777f2f77b80f8556f916617762818ac5cbb93ae7c17d9bd765a1e8f9db100
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --order rand
2
+ --require spec_helper
@@ -0,0 +1,52 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/**/*
4
+ - config/**/*
5
+ - db/**/*
6
+ - spec/dummy/**/*
7
+ - Rakefile
8
+ - git_tagger.gemspec
9
+
10
+ AbcSize:
11
+ Enabled: false
12
+
13
+ ClassLength:
14
+ Enabled: false
15
+
16
+ Documentation:
17
+ Exclude:
18
+ - spec/**/*
19
+
20
+ DotPosition:
21
+ Enabled: false
22
+
23
+ TrailingBlankLines:
24
+ Enabled: false
25
+
26
+ HandleExceptions:
27
+ Enabled: false
28
+
29
+ IfUnlessModifier:
30
+ Enabled: false
31
+
32
+ LineLength:
33
+ Exclude:
34
+ - spec/**/*
35
+
36
+ MethodLength:
37
+ Max: 40
38
+
39
+ PredicateName:
40
+ Enabled: false
41
+
42
+ RegexpLiteral:
43
+ Enabled: false
44
+
45
+ StringLiterals:
46
+ EnforcedStyle: double_quotes
47
+
48
+ Style/GuardClause:
49
+ Enabled: false
50
+
51
+ WordArray:
52
+ Enabled: false
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,99 @@
1
+ ## 1.1.8 - 2015-03-10
2
+ * Updated time logic to be more robust and accurate.
3
+
4
+ ## 1.1.7 - 2015-03-09
5
+ * Final updates to auto generated changelog messages.
6
+ * Further updates to auto changelog output.
7
+ * Added logic to autocreate changelogs based on commit summaries since last tag.
8
+ * More time manipulation.
9
+ * More time manipulation.
10
+ * More of the same.
11
+ * More of the same.
12
+ * More of the same.
13
+ * Updated date math.
14
+ * Adding a second to the last tag date to remove last tag commit message.
15
+
16
+ ## 1.1.6 - 2015-03-06
17
+ * removed choice to update changelog, now it is required
18
+
19
+ ## 1.1.5 - 2015-03-06
20
+ * fixed text issue in commit message
21
+
22
+ ## 1.1.4 - 2015-03-06
23
+ * merged commit messages
24
+
25
+ ## 1.1.3 - 2015-03-06
26
+ * fixed various syntax issues.
27
+
28
+ ## 1.1.2 - 2015-03-06
29
+ * same as before
30
+
31
+ ## 1.1.1 - 2015-03-06
32
+ * modding tag push
33
+
34
+ ## 1.1.0 - 2015-03-06
35
+ * attempting fix for tag pushing problem
36
+
37
+ ## 1.0.12 - 2015-03-05
38
+ * added semantic version numbers to commit messages
39
+
40
+ ## 1.0.11 - 2015-03-05
41
+ * creates missing files, only requires one push, updated visual output
42
+
43
+ ## 1.0.10 - 2015-03-05
44
+ * added logic to create CHANGLELOG and version.rb files if they don't initially exist
45
+
46
+ ## 1.0.9 - 2015-01-22
47
+ * removed unnecessary confirmation from changelog creation, merged git command calls to reduce prompts for creds.
48
+
49
+ ## 1.0.8 - 2015-01-22
50
+ * fixed version file path issues for rails apps
51
+
52
+ ## 1.0.7 - 2015-01-16
53
+ * last update for engines
54
+
55
+ ## 1.0.6 - 2015-01-16
56
+ * fixed another issue with Gemfile.lock pushing in engines
57
+
58
+ ## 1.0.5 - 2015-01-16
59
+ * fixed issue with gemfile.lock commit on Rails engine tag updates
60
+
61
+ ## 1.0.4 - 2015-01-16
62
+ * fixed Rails app version pathing issue
63
+
64
+ ## 1.0.3 - 2015-01-16
65
+ * fixed readme styles, fixed bug with version updates of full Rails applications
66
+
67
+ ## 1.0.2 - 2015-01-16
68
+ * minor style update to output information
69
+
70
+ ## 1.0.1 - 2015-01-16
71
+ * bug fix in pushing updated version files, increased accuracy and modified styles in readme
72
+
73
+ ## 1.0.0 - 2015-01-16
74
+ * Version update 1, major overhaul of code style and organization, added version file update functionality
75
+
76
+ ## 0.1.1 - 2015-01-14
77
+ * changelog update is now pushed mid-process, process now checks that all local changes are committed and pushed before continuing the tagging process
78
+
79
+ ## 0.1.0 - 2015-01-14
80
+ * now allows rails gems to update changelog without error
81
+
82
+ ## 0.0.7 - 2015-01-13
83
+ * additional updating of changelog search logic
84
+
85
+ ## 0.0.6 - 2015-01-13
86
+ * updated readme
87
+
88
+ ## 0.0.5 - 2015-01-13
89
+ * updated changelog logic
90
+
91
+ ## 0.0.4 - 2015-01-13
92
+ * updated gemspec to have a valid summary
93
+
94
+ ## 0.0.3 - 2015-01-13
95
+ * updated spacing and style of instructions
96
+
97
+ ## 0.0.2 - 2015-01-13
98
+ * updated issues with determining if tagged project is Rails or a Gem
99
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in git_tagger.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Eric Schlange
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Eric Schlange
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # git_tagger
2
+
3
+ A Ruby Gem designed to expedite: the git tagging procedure and updating a changelog
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "git_tagger",
11
+ tag: "1.1.8",
12
+ git: "https://github.com/cbitstech/git_tagger.git"
13
+ ```
14
+
15
+ Add the following code to the project's Rakefile:
16
+
17
+ ```ruby
18
+ git_tagger = Gem::Specification.find_by_name "git_tagger"
19
+ load "#{ git_tagger.gem_dir }/lib/tasks/deploy.rake"
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```
25
+ $ bundle
26
+ ...
27
+ Bundle complete! ...
28
+ Use `bundle show [gemname]` to see where a bundled gem is installed.
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ Within the root directory of your application
34
+
35
+ - For full Rails applications:
36
+
37
+ `rake deploy:tag`
38
+
39
+ - For Ruby Gems:
40
+
41
+ `bundle exec rake deploy:tag`
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it [https://github.com/cbitstech/git_tagger/fork](https://github.com/cbitstech/git_tagger/fork)
46
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 1. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 1. Push to the branch (`git push origin my-new-feature`)
49
+ 1. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ import "./lib/tasks/deploy.rake"
4
+
5
+ require "rspec/core/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
@@ -0,0 +1,60 @@
1
+ module GitTagger
2
+ # Represents a changelog for a project.
3
+ class Changelog
4
+ attr_reader :update_text
5
+
6
+ # Sets the updated changelog text based on a semantic version and message
7
+ def initialize(version, message, autocreate)
8
+ if autocreate
9
+ @update_text = "## #{ version } - " \
10
+ "#{ DateTime.now.strftime('%F') }\n#{ message }\n\n"
11
+ else
12
+ @update_text = "## #{ version } - " \
13
+ "#{ DateTime.now.strftime('%F') }\n * #{ message }\n\n"
14
+ end
15
+
16
+ end
17
+
18
+ # Updated the changelog file with the new update text
19
+ def update(project_type)
20
+ @changelog_path = locate_changelog project_type
21
+ new_changelog = "#{ @changelog_path }.new"
22
+
23
+ if !File.exist?(@changelog_path)
24
+ File.open(@changelog_path, "w") {}
25
+ end
26
+
27
+ File.open(new_changelog, "w") do |fo|
28
+ fo.puts @update_text
29
+ File.foreach(@changelog_path) do |li|
30
+ fo.puts li
31
+ end
32
+ end
33
+
34
+ File.rename(new_changelog, @changelog_path)
35
+ end
36
+
37
+ # utilizes system commands to commit the changelog locally
38
+ def add_to_git
39
+ `git add "#{ @changelog_path }"`
40
+ end
41
+
42
+ private
43
+
44
+ # locates and returns a changelog filepath based on project type
45
+ def locate_changelog(project_type)
46
+ case project_type
47
+ when :rails_application
48
+ File.expand_path(Rails.root.join "CHANGELOG.md")
49
+ when :rails_gem
50
+ File.expand_path(Rails.root.join "../../CHANGELOG.md")
51
+ when :non_rails_gem
52
+ File.join(File.dirname(File.expand_path(__FILE__)),
53
+ "../../CHANGELOG.md")
54
+ else
55
+ puts "no changelog file could be found to update"
56
+ abort("aborting tagging process")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,55 @@
1
+ module GitTagger
2
+ # Tag holds all relevant information used to updated git tags of
3
+ # semantic versioning 2.0.0 - http://semver.org/
4
+ class GitTag
5
+ SEMANTIC_VERSION_UPDATE_TYPE_MAJOR = "major"
6
+ SEMANTIC_VERSION_UPDATE_TYPE_MINOR = "minor"
7
+ SEMANTIC_VERSION_UPDATE_TYPE_PATCH = "patch"
8
+
9
+ attr_reader :semantic_version
10
+ attr_reader :last_tag_date
11
+
12
+ # Sets the current semantic version and the creation date of the last tag
13
+ def initialize
14
+ tag_list = `git tag | gsort -V`
15
+ if tag_list && tag_list != ""
16
+ @semantic_version = tag_list.split("\n").last
17
+ # disabling cop, unable to break up system commands
18
+ # rubocop:disable Metrics/LineLength, Style/StringLiterals
19
+ @last_tag_date = `git log --tags --simplify-by-decoration --pretty="format:%ai" -n 1`
20
+ @last_tag_date = Time.parse(@last_tag_date) + 1
21
+ # rubocop:enable Metrics/LineLength, Style/StringLiterals
22
+ else
23
+ @semantic_version = "0.0.0"
24
+ @last_tag_date = Date.today
25
+ end
26
+ end
27
+
28
+ # Updates the tag semantic version based on the given update type
29
+ def update(update_type)
30
+ major = @semantic_version.split(".")[0].to_i
31
+ minor = @semantic_version.split(".")[1].to_i
32
+ patch = @semantic_version.split(".")[2].to_i
33
+
34
+ case update_type
35
+ when SEMANTIC_VERSION_UPDATE_TYPE_MAJOR
36
+ major += 1
37
+ minor = 0
38
+ patch = 0
39
+ when SEMANTIC_VERSION_UPDATE_TYPE_MINOR
40
+ minor += 1
41
+ patch = 0
42
+ when SEMANTIC_VERSION_UPDATE_TYPE_PATCH
43
+ patch += 1
44
+ end
45
+ @semantic_version = "#{ major }.#{ minor }.#{ patch }"
46
+ end
47
+
48
+ def create_and_push
49
+ `git commit -m "Tag new release. (#{@semantic_version})\n* Updating changelog for latest tag.\n* Updating version to match latest tag."`
50
+ `git push`
51
+ `git tag #{ @semantic_version }`
52
+ `git push --tags --follow-tags`
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,81 @@
1
+ require 'fileutils'
2
+
3
+ module GitTagger
4
+ # Represents a version file within a project.
5
+ class Version
6
+ # Sets the project name and filepath based on a project type
7
+ def initialize(project_type)
8
+ @project_name = find_project_name project_type
9
+ @version_file_path = version_file_location project_type, @project_name
10
+ @project_type = project_type
11
+ end
12
+
13
+ # locates and returns a project's name based on the project type
14
+ def find_project_name(project_type)
15
+ case project_type
16
+ when :rails_application
17
+ Rails.application.class.parent_name.underscore
18
+ when :rails_gem
19
+ engine_path = ""
20
+ Find.find(File.expand_path(Rails.root.join("../../lib"))) do |path|
21
+ engine_path = path if path =~ /.*\/engine\.rb$/
22
+ end
23
+ engine_text = File.read(engine_path)
24
+ (engine_text.match(/^module \w*$/))[0].split(" ")[1].underscore
25
+ when :non_rails_gem
26
+ # TODO: Add logic to find gem name and apply to version_file path
27
+ "git_tagger"
28
+ else
29
+ puts "FATAL: Unknown project type, unable to determine project name!"
30
+ abort("aborting tagging process")
31
+ end
32
+ end
33
+
34
+ # Update version file to match updated tag
35
+ def update_version_file(semantic_version)
36
+ create_version_file(@version_file_path)
37
+
38
+ version_text = File.read(@version_file_path)
39
+ version_contents = version_text
40
+ .gsub(/ VERSION = "[0-9]+\.[0-9]+\.[0-9]+"/,
41
+ " VERSION = \"#{ semantic_version }\"")
42
+ File.open(@version_file_path, "w") { |file| file.puts version_contents }
43
+
44
+ `git add "#{ @version_file_path }"`
45
+
46
+ if :rails_gem == @project_type
47
+ `(cd #{ File.expand_path(Rails.root) }; bundle install)`
48
+ `git add "#{ File.expand_path(Rails.root.join("../../Gemfile.lock")) }"`
49
+ end
50
+ end
51
+
52
+ # Locates the version file and returns its path
53
+ def version_file_location(project_type, project_name)
54
+ case project_type
55
+ when :rails_application
56
+ File.expand_path(Rails.root.join "lib/" \
57
+ "#{ project_name }/version.rb")
58
+ when :rails_gem
59
+ File.expand_path(Rails.root.join "../../lib/" \
60
+ "#{ project_name }/version.rb")
61
+ when :non_rails_gem
62
+ # TODO: add logic to find version path for non rails gems
63
+ File.expand_path("../../../lib/git_tagger/version.rb", __FILE__)
64
+ else
65
+ puts "FATAL: Unknown project type, unable to update gem version!"
66
+ abort("aborting tagging process")
67
+ end
68
+ end
69
+
70
+ def create_version_file(path)
71
+ if !File.exist?(path)
72
+ dirname = File.dirname(path)
73
+ unless File.directory?(dirname)
74
+ FileUtils.mkdir_p(dirname)
75
+ end
76
+ File.open(path, "w") {}
77
+ `git add "#{ path }"`
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git_tagger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git_tagger"
8
+ spec.version = GitTagger::VERSION
9
+ spec.authors = ["Eric Schlange"]
10
+ spec.email = ["eric.schlange@gmail.com"]
11
+ spec.summary = %q{expedites the git tagging procedure and updating a changelog for Rails projects and Gems}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/cbitstech/git_tagger"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.3"
24
+ spec.add_development_dependency "timecop", "~> 0.7.4"
25
+ spec.add_development_dependency "simplecov", "~> 0.10.0"
26
+ end
@@ -0,0 +1,5 @@
1
+ require "git_tagger/version"
2
+
3
+ # nodoc
4
+ module GitTagger
5
+ end
@@ -0,0 +1,4 @@
1
+ # nodoc
2
+ module GitTagger
3
+ VERSION = "1.1.8"
4
+ end
@@ -0,0 +1,198 @@
1
+ require "find"
2
+ require "io/console"
3
+ require_relative "../../app/models/changelog"
4
+ require_relative "../../app/models/git_tag"
5
+ require_relative "../../app/models/version"
6
+
7
+ namespace :deploy do
8
+ # Constants
9
+ PURPLE = "\e[0;35m"
10
+ WHITE = "\e[1;37m"
11
+ YELLOW = "\e[0;33m"
12
+ BLUE = "\e[0;34m"
13
+ RED = "\e[0;31m"
14
+ DEFAULT_COLOR = "\e[0m"
15
+
16
+ # Common textual components
17
+ DIVIDER_PURPLE = "\n#{ PURPLE } ======================================" \
18
+ "==========================\e[0m\n"
19
+ DIVIDER_BLUE = "\n#{ BLUE } =================================" \
20
+ "===============================\e[0m\n"
21
+ LINE_BUFFER = ""
22
+
23
+ desc "Master tagging task, run this for the full tagging process."
24
+ task :tag do
25
+ puts DIVIDER_PURPLE
26
+ print "#{ PURPLE } *** #{ WHITE }Welcome to git_tagger"\
27
+ "!#{ DEFAULT_COLOR } #{ PURPLE } ***#{ DEFAULT_COLOR }"
28
+ puts DIVIDER_PURPLE
29
+
30
+ clean_working_directory_check
31
+
32
+ # Get the latest tag or create a new tag if no tag exists.
33
+ git_tag = GitTagger::GitTag.new
34
+ project_type = find_project_type_by_gemfile_location
35
+
36
+ retrieve_tag_type(git_tag)
37
+ create_changelog(git_tag, project_type)
38
+ update_version(git_tag, project_type)
39
+
40
+ print DIVIDER_PURPLE
41
+ puts "#{ WHITE } Pushing updates to changelog and version files (if applicable) ... #{DEFAULT_COLOR}"
42
+ puts "#{ WHITE } Final step: Pushing changelog, version file, and new tag ...#{ DEFAULT_COLOR }"
43
+ git_tag.create_and_push
44
+ puts "#{ WHITE } *** Tag creation complete! *** #{ DEFAULT_COLOR }"
45
+ print DIVIDER_PURPLE
46
+ end
47
+
48
+ def retrieve_tag_type(tag)
49
+ puts LINE_BUFFER
50
+ puts "#{ YELLOW } - MAJOR#{ DEFAULT_COLOR } version when you make"\
51
+ " incompatible API changes."
52
+ puts "#{ YELLOW } - MINOR#{ DEFAULT_COLOR } version when you add "\
53
+ "functionality in a backwards-compatible manner"
54
+ puts "#{ YELLOW } - PATCH#{ DEFAULT_COLOR } version when you make"\
55
+ " backwards-compatible bug fixes."
56
+ puts LINE_BUFFER
57
+
58
+ puts "#{ RED } Type the letter indicating the tag update type "
59
+ print " #{ DEFAULT_COLOR }#{ YELLOW }MAJOR(#{ DEFAULT_COLOR }#{ WHITE }"\
60
+ "M#{ YELLOW }), #{ YELLOW }MINOR(#{ DEFAULT_COLOR }#{ WHITE }m#{ YELLOW }"\
61
+ "), #{ YELLOW }PATCH(#{ DEFAULT_COLOR }#{ WHITE }p#{ YELLOW }), "\
62
+ "#{ YELLOW }QUIT(#{ DEFAULT_COLOR }#{ WHITE }q#{ YELLOW }) (#{ WHITE }"\
63
+ "M#{ YELLOW }/#{ WHITE }m#{ YELLOW }/#{ WHITE }p#{ YELLOW }/#{ WHITE }q"\
64
+ "#{ YELLOW }): #{ DEFAULT_COLOR }"
65
+
66
+ input = ""
67
+ Kernel.loop do
68
+ input = STDIN.getch
69
+ break if !input || %(m p q M).include?(input)
70
+ end
71
+ puts input
72
+
73
+ old_semantic_version = tag.semantic_version
74
+ case input
75
+ when "p"
76
+ tag.update(GitTagger::GitTag::SEMANTIC_VERSION_UPDATE_TYPE_PATCH)
77
+ when "m"
78
+ tag.update(GitTagger::GitTag::SEMANTIC_VERSION_UPDATE_TYPE_MINOR)
79
+ when "M"
80
+ tag.update(GitTagger::GitTag::SEMANTIC_VERSION_UPDATE_TYPE_MAJOR)
81
+ when "q"
82
+ abort("Aborting tag procedure")
83
+ end
84
+
85
+ puts LINE_BUFFER
86
+ puts " The current tag is: [#{ old_semantic_version }]"
87
+ puts " Updating tag to be: [#{ tag.semantic_version }]"
88
+ puts LINE_BUFFER
89
+
90
+ if !(confirm " #{ YELLOW }Is this correct? (#{WHITE}y#{YELLOW}/#{WHITE}n"\
91
+ "#{YELLOW}) ")
92
+ abort("Aborting tag procedure")
93
+ end
94
+ end
95
+
96
+ # Create a changelog entry, update version file and commit to master
97
+ def create_changelog(tag, project_type)
98
+ # disabling cop, unable to break up system commands
99
+ # rubocop:disable Metrics/LineLength, Style/StringLiterals
100
+ commit_summaries_since_last_tag_pretty =
101
+ `git log --since="#{ tag.last_tag_date }" --pretty=format:'%Cblue %ci %Creset-%Cred %an%Creset - %s'`
102
+ commit_summaries_since_last_tag_raw =
103
+ `git log --since="#{ tag.last_tag_date }" --pretty=format:' * %s'`
104
+ # rubocop:enable Metrics/LineLength, Style/StringLiterals
105
+
106
+ puts " The following commits were made since the last tag was created"
107
+ puts DIVIDER_BLUE
108
+ print commit_summaries_since_last_tag_pretty
109
+ puts DIVIDER_BLUE
110
+
111
+ if confirm "#{ YELLOW } The above will be added to the changelog by typing 'y'" \
112
+ ", type 'n' if you wish to write a custom changelog message.(#{WHITE}y" \
113
+ "#{YELLOW}/#{WHITE}n#{YELLOW})#{DEFAULT_COLOR} "
114
+ changelog = GitTagger::Changelog
115
+ .new(tag.semantic_version, commit_summaries_since_last_tag_raw, true)
116
+ puts changelog.update_text
117
+ else
118
+ puts " #{ YELLOW }Enter a brief changelog message to describe the " \
119
+ "updates since the last tag was created, then press [#{WHITE}ENTER" \
120
+ "#{YELLOW}]#{DEFAULT_COLOR}"
121
+ print " * "
122
+ changelog_message = STDIN.gets.strip
123
+ puts LINE_BUFFER
124
+ changelog = GitTagger::Changelog
125
+ .new(tag.semantic_version, changelog_message, false)
126
+ puts "#{ YELLOW } The following will be prefixed to the CHANGELOG.md " \
127
+ "file #{DEFAULT_COLOR}"
128
+ puts LINE_BUFFER
129
+ puts changelog.update_text
130
+ end
131
+
132
+ if confirm "#{ YELLOW } Are you sure that you would like to commit " \
133
+ "this change to origin/master before creating the new tag? (#{WHITE}y" \
134
+ "#{YELLOW}/#{WHITE}n#{YELLOW})#{DEFAULT_COLOR} "
135
+ changelog.update(project_type)
136
+ changelog.add_to_git
137
+ else
138
+ abort("Aborting tagging process.")
139
+ end
140
+
141
+ end
142
+
143
+ def confirm(question)
144
+ print question
145
+ confirmation = ""
146
+ Kernel.loop do
147
+ confirmation = STDIN.getch
148
+ break if !confirmation || %(y n).include?(confirmation)
149
+ end
150
+
151
+ puts confirmation
152
+ puts DIVIDER_PURPLE
153
+ "y" == confirmation
154
+ end
155
+
156
+ # Determine location of gemfile and return project type
157
+ def find_project_type_by_gemfile_location
158
+ # If tagging an application or Gem that uses Rails
159
+ if defined? Rails
160
+ if File.file?(File.expand_path(Rails.root.join "Gemfile"))
161
+ puts "-- determined that project type is a Rails application --"
162
+ return :rails_application
163
+ end
164
+ if File.file?(File.expand_path(Rails.root.join "../../Gemfile"))
165
+ puts "-- determined that project type is a Rails Gem --"
166
+ return :rails_gem
167
+ end
168
+ else
169
+ if File.file?(File.join(File.dirname(File.expand_path(__FILE__)),
170
+ "../../Gemfile"))
171
+ puts "-- determined that project type is a Gem without Rails --"
172
+ return :non_rails_gem
173
+ end
174
+ end
175
+ puts "FATAL: unable to determine project type based on Gemfile location!"
176
+ abort("aborting tagging process")
177
+ end
178
+
179
+ def update_version(tag, project_type)
180
+ version = GitTagger::Version.new(project_type)
181
+ version.update_version_file(tag.semantic_version)
182
+ end
183
+
184
+ # Abort tagging process if there are uncommitted changes or commits that
185
+ # have not been pushed to the master branch in the repository.
186
+ # disabling cop, unable to break up system commands
187
+ # rubocop:disable Metrics/LineLength, Style/StringLiterals
188
+ def clean_working_directory_check
189
+ commit_count_check = `git status`
190
+ if (!(commit_count_check.include? "Your branch is up-to-date with 'origin/master'.") &&
191
+ !(commit_count_check.include? "nothing to commit, working directory clean")) ||
192
+ (commit_count_check.include? "Changes not staged for commit:")
193
+ abort("ABORTING... please commit and push any local changes before atte"\
194
+ "mpting to create a new tag")
195
+ end
196
+ end
197
+ # rubocop:enable Metrics/LineLength, Style/StringLiterals
198
+ end
@@ -0,0 +1,68 @@
1
+ require "timecop"
2
+ require_relative "../../../app/models/changelog"
3
+
4
+ class Rails
5
+ def self.root
6
+ ["/rails/", ""]
7
+ end
8
+ end
9
+
10
+ module GitTagger
11
+ RSpec.describe Changelog do
12
+ let(:fixed_date) { Time.local(2012, 2, 9) }
13
+
14
+ describe "initialization" do
15
+ context "when autocreate is true" do
16
+ it "sets the update text accordingly" do
17
+ Timecop.travel(fixed_date) do
18
+ changelog = Changelog.new(nil, "* teh message", true)
19
+
20
+ expect(changelog.update_text).to eq "## - 2012-02-09\n* teh message\n\n"
21
+ end
22
+ end
23
+ end
24
+
25
+ context "when autocreate is false" do
26
+ it "sets the update text accordingly" do
27
+ Timecop.travel(fixed_date) do
28
+ changelog = Changelog.new(nil, "teh message", false)
29
+
30
+ expect(changelog.update_text).to eq "## - 2012-02-09\n * teh message\n\n"
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#update" do
37
+ let(:mock_file) { double("file") }
38
+
39
+ before do
40
+ expect(mock_file).to receive(:puts).with("## - 2012-02-09\n * \n\n")
41
+ allow(File).to receive(:foreach).with("/rails/CHANGELOG.md")
42
+ allow(File).to receive(:open).with("/rails/CHANGELOG.md.new", "w")
43
+ .and_yield(mock_file)
44
+ expect(File).to receive(:rename).with("/rails/CHANGELOG.md.new", "/rails/CHANGELOG.md")
45
+ end
46
+
47
+ context "when the file doesn't exist" do
48
+ it "creates a new file with the update_text" do
49
+ expect(File).to receive(:open).with("/rails/CHANGELOG.md", "w")
50
+
51
+ Timecop.travel(fixed_date) do
52
+ Changelog.new(nil, nil, false).update(:rails_application)
53
+ end
54
+ end
55
+ end
56
+
57
+ context "when the file exists" do
58
+ it "prepends the update_text" do
59
+ allow(File).to receive(:exist?).with("/rails/CHANGELOG.md") { true }
60
+
61
+ Timecop.travel(fixed_date) do
62
+ Changelog.new(nil, nil, false).update(:rails_application)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+ require_relative "../../../app/models/git_tag"
3
+
4
+ module GitTagger
5
+ RSpec.describe GitTag do
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+ require_relative "../../../app/models/version"
3
+
4
+ module GitTagger
5
+ RSpec.describe Version do
6
+ end
7
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+ require "rake"
3
+
4
+ RSpec.describe "deploy:tag" do
5
+ let(:rake) { Rake::Application.new }
6
+ let(:root_path) do
7
+ File.expand_path(File.join(File.dirname(__FILE__), "..", "..", ".."))
8
+ end
9
+ let(:task_path) { "lib/tasks/deploy" }
10
+ subject { Rake::Task["deploy:tag"] }
11
+
12
+ def loaded_files_excluding_current_rake_file
13
+ $LOADED_FEATURES.reject do |file|
14
+ file == File.join(root_path, "#{task_path}.rake")
15
+ end
16
+ end
17
+
18
+ before :each do
19
+ Rake.application = rake
20
+ Rake.application.rake_require(task_path,
21
+ [root_path],
22
+ loaded_files_excluding_current_rake_file)
23
+ Rake::Task.define_task(:environment)
24
+ allow($stdout).to receive(:write) # Hiding puts output
25
+ subject.reenable
26
+ end
27
+
28
+ context "when there are changes not committed" do
29
+ it "aborts" do
30
+ tmp_file = ""
31
+ File.open(File.join(root_path, "README.md"), "r+") do |f|
32
+ tmp_file = f.read
33
+ f.write " "
34
+ end
35
+
36
+ expect { subject.invoke }.to raise_error SystemExit
37
+
38
+ File.open(File.join(root_path, "README.md"), "w") do |f|
39
+ f.write tmp_file
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,2 @@
1
+ require "simplecov"
2
+ SimpleCov.start
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_tagger
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.8
5
+ platform: ruby
6
+ authors:
7
+ - Eric Schlange
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ description: ''
84
+ email:
85
+ - eric.schlange@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .rubocop.yml
93
+ - .travis.yml
94
+ - CHANGELOG.md
95
+ - Gemfile
96
+ - LICENSE
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - app/models/changelog.rb
101
+ - app/models/git_tag.rb
102
+ - app/models/version.rb
103
+ - git_tagger.gemspec
104
+ - lib/git_tagger.rb
105
+ - lib/git_tagger/version.rb
106
+ - lib/tasks/deploy.rake
107
+ - spec/app/models/changelog_spec.rb
108
+ - spec/app/models/git_tag_spec.rb
109
+ - spec/app/models/version_spec.rb
110
+ - spec/lib/tasks/deploy.rake_spec.rb
111
+ - spec/spec_helper.rb
112
+ homepage: https://github.com/cbitstech/git_tagger
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.0.14.1
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: expedites the git tagging procedure and updating a changelog for Rails projects
136
+ and Gems
137
+ test_files:
138
+ - spec/app/models/changelog_spec.rb
139
+ - spec/app/models/git_tag_spec.rb
140
+ - spec/app/models/version_spec.rb
141
+ - spec/lib/tasks/deploy.rake_spec.rb
142
+ - spec/spec_helper.rb