-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove katip, make own awesome changelogger
- Loading branch information
Showing
5 changed files
with
138 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
|
||
#### [Current] | ||
* [0765294](../../commit/0765294) - __(Меркушин Михаил)__ Merge pull request [#1](../../issues/1) from bibendi/master | ||
* 2014-12-04 [101dad1](../../commit/101dad1) - __(bibendi)__ remove katip, make own awesome changelogger | ||
|
||
add new changelogger - katip | ||
* [15c21ad](../../commit/15c21ad) - __(bibendi)__ add new changelogger - katip | ||
#### v0.1.0 | ||
* 2014-12-04 [2549209](../../commit/2549209) - __(bibendi)__ Release 0.1.0 | ||
* 2014-12-03 [15c21ad](../../commit/15c21ad) - __(bibendi)__ add new changelogger - katip | ||
|
||
#### v0.0.4 | ||
* [861228d](../../commit/861228d) - __(bibendi)__ Release 0.0.4 | ||
* [1d8ec9b](../../commit/1d8ec9b) - __(bibendi)__ downgrade changelogger to 0.0.2 | ||
* 2014-10-14 [861228d](../../commit/861228d) - __(bibendi)__ Release 0.0.4 | ||
* 2014-10-14 [1d8ec9b](../../commit/1d8ec9b) - __(bibendi)__ downgrade changelogger to 0.0.2 | ||
|
||
#### v0.0.3 | ||
* [ec54bda](../../commit/ec54bda) - __(bibendi)__ Release 0.0.3 | ||
* [5d4efb5](../../commit/5d4efb5) - __(bibendi)__ add railsc gem source | ||
* 2014-10-14 [ec54bda](../../commit/ec54bda) - __(bibendi)__ Release 0.0.3 | ||
* 2014-10-14 [5d4efb5](../../commit/5d4efb5) - __(bibendi)__ add railsc gem source | ||
|
||
#### v0.0.2 | ||
* [af1fe22](../../commit/af1fe22) - __(bibendi)__ Release 0.0.2 | ||
* [5903a08](../../commit/5903a08) - __(bibendi)__ fix check git | ||
* [9e46c68](../../commit/9e46c68) - __(bibendi)__ first | ||
* 2014-10-14 [af1fe22](../../commit/af1fe22) - __(bibendi)__ Release 0.0.2 | ||
* 2014-10-14 [5903a08](../../commit/5903a08) - __(bibendi)__ fix check git | ||
* 2014-10-14 [9e46c68](../../commit/9e46c68) - __(bibendi)__ first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
require "apress/gems/version" | ||
require 'apress/gems/version' | ||
|
||
module Apress | ||
module Gems | ||
# Your code goes here... | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# coding: utf-8 | ||
# https://github.com/lab2023/katip/blob/develop/lib/katip/change_logger.rb | ||
module Apress | ||
module Gems | ||
class ChangeLogger | ||
COMMIT_URL = '../../commit/'.freeze | ||
ISSUE_URL = '../../issues/'.freeze | ||
JIRA_URL = 'https://jira.railsc.ru/browse/'.freeze | ||
|
||
ISSUE_REGEXP = /[A-Z]+\-[0-9]+/ | ||
JIRA_REGEXP = /(?:\s|^)([A-Z]+-[0-9]+)(?=\s|$)/ | ||
|
||
GIT_LOG_CMD = %{git log --date=short --pretty=format:" * %ad [%h](#{COMMIT_URL}%h) - __(%an)__ %s"}.freeze | ||
EXCLUDE_MERGE = %{grep -v -E "Merge (branch|pull)"}.freeze | ||
|
||
# initialize | ||
# | ||
# @param [String] file_name with path | ||
def initialize(file_name = 'CHANGELOG.md', from = nil, to = nil) | ||
@file_name = file_name | ||
@tag_from = from | ||
@tag_to = to | ||
end | ||
|
||
def log_changes | ||
return unless git_repository? | ||
|
||
output = parse_change_log | ||
write_file output unless output.empty? | ||
end | ||
|
||
private | ||
|
||
def git_repository? | ||
initialized = `git rev-parse --is-inside-work-tree`.chomp | ||
|
||
if initialized != 'true' | ||
initialized = false | ||
puts 'Exiting. Nothing to create log file.' | ||
end | ||
initialized | ||
end | ||
|
||
def write_file(output) | ||
File.open(@file_name, 'w') do |file| | ||
file.puts(output) | ||
end | ||
end | ||
|
||
def parse_change_log | ||
output = [] | ||
|
||
tags = `git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags | grep -v '^$'#` | ||
|
||
tags = tags.split | ||
prev_begin = nil | ||
|
||
if (!@tag_from.nil? && !tags.include?(@tag_from)) || (!@tag_to.nil? && !tags.include?(@tag_to)) | ||
show_not_found_message(tags) | ||
return output | ||
end | ||
|
||
if !@tag_from.nil? && !@tag_to.nil? | ||
from = tags.index(@tag_from) | ||
to = tags.index(@tag_to) | ||
tags = tags[from..to] | ||
elsif !@tag_from.nil? | ||
from = tags.index @tag_from | ||
prev_begin = tags[from - 1] | ||
tags = tags[from..-1] | ||
elsif !@tag_to.nil? | ||
to = tags.index @tag_to | ||
tags = tags[0..to] | ||
end | ||
|
||
tags.reverse! | ||
|
||
output << "\n#### [Current]" if @tag_to.nil? | ||
|
||
previous_tag = '' | ||
tags.each do |tag| | ||
current_tag = tag | ||
|
||
output << "\n#### #{previous_tag}" unless previous_tag.empty? | ||
|
||
if !previous_tag.empty? || @tag_to.nil? | ||
output << `#{GIT_LOG_CMD} "#{current_tag}".."#{previous_tag}" | #{EXCLUDE_MERGE}` | ||
end | ||
|
||
previous_tag = current_tag | ||
end | ||
|
||
output << "\n#### #{previous_tag}" | ||
|
||
if prev_begin.nil? | ||
output << `#{GIT_LOG_CMD} #{previous_tag} | #{EXCLUDE_MERGE}` | ||
else | ||
output << `#{GIT_LOG_CMD} "#{prev_begin}".."#{previous_tag}" | #{EXCLUDE_MERGE}` | ||
end | ||
|
||
output.each do |line| | ||
line.encode!('utf-8', 'utf-8', invalid: :replace, undef: :replace, replace: '') | ||
|
||
if line.index(ISSUE_REGEXP) | ||
line.gsub!(ISSUE_REGEXP) { |s| "[#{s}](#{ISSUE_URL}#{s[-(s.length - 1)..-1]})" } | ||
end | ||
|
||
if line.index(JIRA_REGEXP) | ||
line.gsub!(JIRA_REGEXP) { |s| "[#{s}](#{JIRA_URL}#{s[-(s.length - 1)..-1]})" } | ||
end | ||
end | ||
|
||
output | ||
end | ||
|
||
def show_not_found_message(tags) | ||
puts 'Could not find the given tags. Make sure that given tags exist.' | ||
puts 'Listing found tags:' | ||
puts tags | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters