pr_changelog 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '02288b5d68d67aba8bfeab47b86537f777f650c2'
4
+ data.tar.gz: a3ac3dc43ce78f8c336c17c9ffaab36d19cc2d0a
5
+ SHA512:
6
+ metadata.gz: fdb606a52d240f3c1ae8f20a2794ef1b5f01ed996133cccf38e6f7824574e2fa25e6ec05638cdef4274ce1c005790daf4a70d2d9b861f4b76d3eefd8cc20c022
7
+ data.tar.gz: f96c549aed74907e06404ace2e8e525136da7f3c56d5a86d1963cd2ef9f64316cacf0fde0c81a02df95344c17e9cfafe2c58cd3e4dbd9634c34fb91025798ec5
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at fespinozacast@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pr_changelog (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ method_source (0.9.2)
11
+ minitest (5.11.3)
12
+ pry (0.12.2)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ rake (10.5.0)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler (~> 2.0.1)
22
+ minitest (~> 5.0)
23
+ pr_changelog!
24
+ pry (~> 0.12.2)
25
+ rake (~> 10.0)
26
+
27
+ BUNDLED WITH
28
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Felipe Espinoza
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # PR Changelog
2
+
3
+ A script to generate a nice list of changes given two git references.
4
+
5
+ It takes in account all the merged pull request to master between the two given references, then it formats it in a nice consumable way.
6
+
7
+ To be effective, this script requires that you follow simple conventions:
8
+
9
+ 1. Your pull request titles must be written as changelog entries
10
+ 2. (Optional) Your project has git tags for each version you release (example: `0.3.0`)
11
+ 3. (Optional) Your pull request titles begin with some sort of tag (`Feature`, `Improvement`, `Fix`, `Internal`)
12
+
13
+ Then a sample pull request title would be:
14
+
15
+ > Feature: shake the phone to send feedback email
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'pr_changelog'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ ```shell
28
+ $ bundle
29
+ ```
30
+
31
+ Or install it yourself as:
32
+
33
+ ```shell
34
+ $ gem install pr_changelog
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ To get the changes between to git tags `0.3.0` and `0.5.0`, execute:
40
+
41
+ ```
42
+ $ pr_changelog 0.3.0 0.5.0
43
+ ```
44
+
45
+ Will produce:
46
+
47
+ ```markdown
48
+ ## Changes since 0.3.0 to 0.5.0
49
+
50
+ [New features]
51
+ - #61: ⭐️ Shake the phone to send feedback email
52
+
53
+ [Improvements]
54
+ - #64: 💎 Visual refinements for canvas 2.0
55
+ - #57: 💎 Memory performance tweaks
56
+ - #62: 💎 Visual polishing for top stories
57
+
58
+ [Internal]
59
+ - #65: 👨‍💻 Add formatting rules for xml files
60
+ - #60: 👨‍💻 Setup hockeyapp for crash reporting
61
+ ```
62
+
63
+ or
64
+
65
+ ```
66
+ $ pr_changelog --format plain 0.3.0 0.5.0
67
+ ```
68
+
69
+ Will produce something like:
70
+
71
+ ```markdown
72
+ ## Changes from 0.3.0 to 0.5.0
73
+
74
+ - #64: Improvement: visual refinements for canvas 2.0
75
+ - #65: Internal: add formatting rules for xml files
76
+ - #63: Feature: Add Footer story
77
+ - #57: Improvement: Memory performance tweaks
78
+ - #61: Feature: shake the phone to send feedback email
79
+ - #62: Improvement: visual polishing for top stories
80
+ - #60: Internal: setup hockeyapp for crash reporting
81
+ ```
82
+
83
+ ## Contributing
84
+
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/schibsted/pr_changelog. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
90
+
91
+ ## Code of Conduct
92
+
93
+ Everyone interacting in the `pr_changelog` project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/schibsted/pr_changelog/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'pr_changelog'
6
+
7
+ require 'pry'
8
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/exe/pr_changelog ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'pr_changelog'
5
+
6
+ begin
7
+ PrChangelog::CLI.new(ARGV).run
8
+ rescue StandardError
9
+ puts PrChangelog::CLI::HELP_TEXT
10
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrChangelog
4
+ # Used for the implementation of the exposed executable for this gem
5
+ class CLI
6
+ HELP_TEXT = <<~HELP
7
+ Usage: pr_changelog [options] from_reference to_reference
8
+
9
+ [Options]
10
+
11
+ -h, --help\tShow this help
12
+ --format FORMAT_NAME\t(default "pretty"), options ("pretty", "plain")
13
+
14
+ [Examples]
15
+
16
+ Listing the changes for the last release (since the previous to the last one)
17
+
18
+ $ pr_changelog
19
+ HELP
20
+
21
+ attr_reader :format, :from_reference, :to_reference
22
+
23
+ def initialize(args)
24
+ @format = 'pretty'
25
+ if args.include?('--format')
26
+ next_index = args.index('--format') + 1
27
+ @format = args.fetch(next_index)
28
+ end
29
+ @from_reference, @to_reference = args.last(2)
30
+ end
31
+
32
+ def run
33
+ changes = NotReleasedChanges.new(from_reference, to_reference)
34
+ if format == 'plain'
35
+ puts changes.formatted_changelog
36
+ else
37
+ puts changes.grouped_formatted_changelog
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrChangelog
4
+ # Calculates a list of not released changes from `base_ref` to `current_ref`
5
+ # those changes consist of the merged pull-request title
6
+ class NotReleasedChanges
7
+ LOG_FORMAT = '- %cn: %s%n%w(80, 2, 2)%b'
8
+ GITHUB_MERGE_COMMIT_FORMAT = /Merge pull request (?<pr_number>#\d+) .*/.freeze
9
+ MERGE_BRANCH_COMMIT_FORMAT = /(Merge branch '.*'\s?(into|of)? .*)|(Merge .* branch .*)/.freeze
10
+ PARSED_MERGE_COMMIT_FORMAT = /^- #(?<pr_number>\d+):\s+(?<tag>[^\s]+):\s*(?<title>.*)$/.freeze
11
+
12
+ attr_reader :base_ref, :current_ref
13
+
14
+ def initialize(base_ref, current_ref)
15
+ @base_ref = base_ref
16
+ @current_ref = current_ref
17
+ end
18
+
19
+ Tag = Struct.new(:emoji, :title, :sort)
20
+
21
+ EMOJI_TAGS = {
22
+ 'feature' => Tag.new('⭐️', 'New features', 0),
23
+ 'fix' => Tag.new('🐛', 'Fixes', 1),
24
+ 'improvement' => Tag.new('💎', 'Improvements', 2),
25
+ 'internal' => Tag.new('👨‍💻', 'Internal', 4),
26
+ 'unclassified' => Tag.new('❓', 'Unclassified', 5)
27
+ }.freeze
28
+
29
+ def formatted_changelog
30
+ if formatted_change_list.positive?
31
+ formatted_change_list.join("\n")
32
+ else
33
+ "There are no changes since #{base_ref} to #{current_ref}"
34
+ end
35
+ end
36
+
37
+ def grouped_formatted_changelog
38
+ changes = formatted_change_list
39
+ if changes.count.positive?
40
+
41
+ grouped_changes = changes.group_by do |change_line|
42
+ EMOJI_TAGS[tag_from(change_line)] || EMOJI_TAGS['unclassified']
43
+ end
44
+
45
+ sorted_hash = grouped_changes.sort do |first_pair, second_pair|
46
+ first_pair[0].sort <=> second_pair[0].sort
47
+ end
48
+
49
+ new_hash = {}
50
+ sorted_hash.each do |tag, change_lines|
51
+ new_key = "[#{tag.title}]"
52
+ new_hash[new_key] = change_lines.map do |change_line|
53
+ emojify_tag_for(change_line)
54
+ end
55
+ end
56
+
57
+ new_hash.reduce('') do |string, pair|
58
+ tag = pair[0]
59
+ lines = pair[1].map { |l| " #{l}" }.join("\n")
60
+ string + "#{tag}\n#{lines}\n\n"
61
+ end.chomp
62
+ else
63
+ "There are no changes since #{base_ref} to #{current_ref}"
64
+ end
65
+ end
66
+
67
+ def formatted_change_list
68
+ parsed_merge_commits.map do |pair|
69
+ format_merge_commit(pair.first, pair.last)
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def first_uppercase(line)
76
+ return line unless line.length > 2
77
+
78
+ "#{line[0].upcase}#{line[1, line.length]}"
79
+ end
80
+
81
+ def emojify_tag_for(change_line)
82
+ match = change_line.match(PARSED_MERGE_COMMIT_FORMAT)
83
+ return change_line unless match
84
+
85
+ emoji_tag = EMOJI_TAGS[match[:tag].downcase].emoji || '❓'
86
+ "- ##{match[:pr_number]}: #{emoji_tag} #{first_uppercase(match[:title])}"
87
+ end
88
+
89
+ def tag_from(merge_commit)
90
+ match = merge_commit.match(PARSED_MERGE_COMMIT_FORMAT)
91
+ return nil unless match
92
+
93
+ match[:tag].downcase
94
+ end
95
+
96
+ def parsed_merge_commits
97
+ merge_commits_not_merged_into_base_ref
98
+ .split('- ')
99
+ .reject(&:empty?)
100
+ .reject { |line| line.match(MERGE_BRANCH_COMMIT_FORMAT) }
101
+ .map { |e| e.split("\n") }
102
+ end
103
+
104
+ def format_merge_commit(github_commit_title, commit_title)
105
+ pr_number = pull_request_number_for(github_commit_title)
106
+
107
+ "- #{pr_number}: #{commit_title.strip}"
108
+ end
109
+
110
+ def merge_commits_not_merged_into_base_ref
111
+ `git log --merges #{base_ref}..#{current_ref} --format='#{LOG_FORMAT}'`
112
+ end
113
+
114
+ def pull_request_number_for(github_commit_title)
115
+ md = github_commit_title.match(GITHUB_MERGE_COMMIT_FORMAT)
116
+ md[:pr_number] if md
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrChangelog
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pr_changelog/version'
4
+ require 'pr_changelog/cli'
5
+ require 'pr_changelog/not_released_changes'
6
+
7
+ # Main module
8
+ module PrChangelog
9
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'pr_changelog/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'pr_changelog'
9
+ spec.version = PrChangelog::VERSION
10
+ spec.authors = ['Felipe Espinoza']
11
+ spec.email = ['felipe.espinoza@schibsted.com']
12
+
13
+ spec.summary = 'A script to generate nice changelogs from your merged PRs'
14
+ spec.homepage = 'https://github.com/schibsted/pr_changelog'
15
+ spec.license = 'MIT'
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
19
+ # into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 2.0.1'
30
+ spec.add_development_dependency 'minitest', '~> 5.0'
31
+ spec.add_development_dependency 'pry', '~> 0.12.2'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pr_changelog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Felipe Espinoza
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-18 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: 2.0.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.12.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.12.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - felipe.espinoza@schibsted.com
72
+ executables:
73
+ - pr_changelog
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - exe/pr_changelog
88
+ - lib/pr_changelog.rb
89
+ - lib/pr_changelog/cli.rb
90
+ - lib/pr_changelog/not_released_changes.rb
91
+ - lib/pr_changelog/version.rb
92
+ - pr_changelog.gemspec
93
+ homepage: https://github.com/schibsted/pr_changelog
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.2.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A script to generate nice changelogs from your merged PRs
117
+ test_files: []