apress-changelogger 0.0.1

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: b8575c7c1ee53ca47428355660ac1a0b47b76a33
4
+ data.tar.gz: 6acf93b919fd20c8381a19f112216e8da0198a06
5
+ SHA512:
6
+ metadata.gz: bb96acb125667af6efd278c6cf8a770ae21492fe47221adb8773a2126bb43edf5eed846889bda5f45926694d8a71e0073b91373c63c9c6caaa9a4f200a2ee5e6
7
+ data.tar.gz: 04df6e30ff02c624b968352f4aab4e859973c320389a62824e4192fcc387bf5d0b5bb4e5697deee42daa075708bd1a50ef4084c1440d518066e326dca543fa40
@@ -0,0 +1,14 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in apress-changelogger.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 bibendi
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,33 @@
1
+ # Apress::Changelogger
2
+
3
+ Changelogger
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apress-changelogger'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install apress-changelogger
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ Apress::ChangeLogger.new.log_changes
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/abak-press/apress-changelogger/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apress/changelogger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "apress-changelogger"
8
+ spec.version = Apress::Changelogger::VERSION
9
+ spec.authors = ["Merkushin"]
10
+ spec.email = ["merkushin.m.s@gmail.com"]
11
+ spec.summary = 'Changelogger'
12
+ spec.homepage = "https://github.com/abak-press/apress-changelogger"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,121 @@
1
+ require "apress/changelogger/version"
2
+
3
+ module Apress
4
+ class ChangeLogger
5
+ COMMIT_URL = '../../commit/'.freeze
6
+ ISSUE_URL = '../../issues/'.freeze
7
+ JIRA_URL = 'https://jira.railsc.ru/browse/'.freeze
8
+
9
+ ISSUE_REGEXP = /[A-Z]+\-[0-9]+/
10
+ JIRA_REGEXP = /(?:\s|^)([A-Z]+-[0-9]+)(?=\s|$)/
11
+
12
+ GIT_LOG_CMD = %{git log --date=short --pretty=format:" * %ad [%h](#{COMMIT_URL}%h) - __(%an)__ %s"}.freeze
13
+ EXCLUDE_MERGE = %{grep -v -E "Merge (branch|pull)"}.freeze
14
+
15
+ # initialize
16
+ #
17
+ # @param [String] file_name with path
18
+ def initialize(file_name = 'CHANGELOG.md', from = nil, to = nil)
19
+ @file_name = file_name
20
+ @tag_from = from
21
+ @tag_to = to
22
+ end
23
+
24
+ def log_changes
25
+ return unless git_repository?
26
+
27
+ output = parse_change_log
28
+ write_file output unless output.empty?
29
+ end
30
+
31
+ private
32
+
33
+ def git_repository?
34
+ initialized = `git rev-parse --is-inside-work-tree`.chomp
35
+
36
+ if initialized != 'true'
37
+ initialized = false
38
+ puts 'Exiting. Nothing to create log file.'
39
+ end
40
+ initialized
41
+ end
42
+
43
+ def write_file(output)
44
+ File.open(@file_name, 'w') do |file|
45
+ file.puts(output)
46
+ end
47
+ end
48
+
49
+ def parse_change_log
50
+ output = []
51
+
52
+ tags = `git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags | grep -v '^$'#`
53
+
54
+ tags = tags.split
55
+ prev_begin = nil
56
+
57
+ if (!@tag_from.nil? && !tags.include?(@tag_from)) || (!@tag_to.nil? && !tags.include?(@tag_to))
58
+ show_not_found_message(tags)
59
+ return output
60
+ end
61
+
62
+ if !@tag_from.nil? && !@tag_to.nil?
63
+ from = tags.index(@tag_from)
64
+ to = tags.index(@tag_to)
65
+ tags = tags[from..to]
66
+ elsif !@tag_from.nil?
67
+ from = tags.index @tag_from
68
+ prev_begin = tags[from - 1]
69
+ tags = tags[from..-1]
70
+ elsif !@tag_to.nil?
71
+ to = tags.index @tag_to
72
+ tags = tags[0..to]
73
+ end
74
+
75
+ tags.reverse!
76
+
77
+ output << "\n#### [Current]" if @tag_to.nil?
78
+
79
+ previous_tag = ''
80
+ tags.each do |tag|
81
+ current_tag = tag
82
+
83
+ output << "\n#### #{previous_tag}" unless previous_tag.empty?
84
+
85
+ if !previous_tag.empty? || @tag_to.nil?
86
+ output << `#{GIT_LOG_CMD} "#{current_tag}".."#{previous_tag}" | #{EXCLUDE_MERGE}`
87
+ end
88
+
89
+ previous_tag = current_tag
90
+ end
91
+
92
+ output << "\n#### #{previous_tag}"
93
+
94
+ if prev_begin.nil?
95
+ output << `#{GIT_LOG_CMD} #{previous_tag} | #{EXCLUDE_MERGE}`
96
+ else
97
+ output << `#{GIT_LOG_CMD} "#{prev_begin}".."#{previous_tag}" | #{EXCLUDE_MERGE}`
98
+ end
99
+
100
+ output.each do |line|
101
+ line.encode!('utf-8', 'utf-8', invalid: :replace, undef: :replace, replace: '')
102
+
103
+ if line.index(ISSUE_REGEXP)
104
+ line.gsub!(ISSUE_REGEXP) { |s| "[#{s}](#{ISSUE_URL}#{s[-(s.length - 1)..-1]})" }
105
+ end
106
+
107
+ if line.index(JIRA_REGEXP)
108
+ line.gsub!(JIRA_REGEXP) { |s| "[#{s}](#{JIRA_URL}#{s[-(s.length - 1)..-1]})" }
109
+ end
110
+ end
111
+
112
+ output
113
+ end
114
+
115
+ def show_not_found_message(tags)
116
+ puts 'Could not find the given tags. Make sure that given tags exist.'
117
+ puts 'Listing found tags:'
118
+ puts tags
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,5 @@
1
+ module Apress
2
+ module Changelogger
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apress-changelogger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Merkushin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ prerelease: false
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.7'
25
+ type: :development
26
+ name: bundler
27
+ - !ruby/object:Gem::Dependency
28
+ prerelease: false
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '10.0'
39
+ type: :development
40
+ name: rake
41
+ description:
42
+ email:
43
+ - merkushin.m.s@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - apress-changelogger.gemspec
54
+ - lib/apress/changelogger.rb
55
+ - lib/apress/changelogger/version.rb
56
+ homepage: https://github.com/abak-press/apress-changelogger
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Changelogger
80
+ test_files: []