pr_changelog 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d8b03e0c652b5e8c54545bda41fc8db5892f5c4
4
- data.tar.gz: 7d03c9f0832e52c65fe6cf40da38f5cf1a234622
3
+ metadata.gz: dab0c2b8a1d8fbd0d20075ac1bf8068b472f5abd
4
+ data.tar.gz: 89eb296b69a3acbc79682445a411dac2c6b9dbd8
5
5
  SHA512:
6
- metadata.gz: 16911cf9a8c6e3a29d85fd0b7534f082fc1b4a229ae5ee244846466fb57aa0d8186ac925d3208eb1e03a53e368ef1ed447c28d266d7ad60a3f6aa9dddc2f66f5
7
- data.tar.gz: 2abab755538b3cb4baef5d34945f84550fafdb0c4ac737ab4252a1e890bb2de09cafd5f48cfedadb12baa5b19f2022a181d55306bd5758d4f14d8736685d500d
6
+ metadata.gz: 11f056d478fa379d7c20e177519a9ffdf29b4d01a7aab3d9e374eff223310759217b8fafb18d4ecf247a01d5f6ed2947a329c8a51ab7430c65a7b7bca926f7b7
7
+ data.tar.gz: 42057d5c68c710b313f22e9d7fe8a5edaf7953e9956ea4f4da81131160017bf167504cccd6d50af05c91858f817eaf0de52c4953b067c26df3726707e0a6549d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pr_changelog (0.1.1)
4
+ pr_changelog (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # PR Changelog
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/pr_changelog.svg)](https://badge.fury.io/rb/pr_changelog)
4
+
3
5
  A script to generate a nice list of changes given two git references, like so:
4
6
 
5
7
  ```markdown
@@ -30,6 +32,8 @@ Then a sample pull request title would be:
30
32
 
31
33
  > Feature: shake the phone to send feedback email
32
34
 
35
+ This project itself is using this PR convention and the changelog generated with it can be found in https://github.com/schibsted/pr_changelog/releases
36
+
33
37
  ## Installation
34
38
 
35
39
  Add this line to your application's Gemfile:
@@ -96,6 +100,32 @@ Will produce:
96
100
  - #60: 👨‍💻 Setup hockeyapp for crash reporting
97
101
  ```
98
102
 
103
+ ## Configuration
104
+
105
+ Change the emojis or add your own in a `.pr_changelog.json` file:
106
+
107
+ ```json
108
+ {
109
+ "tags": [
110
+ {
111
+ "prefix": "feature",
112
+ "emoji": "⭐️",
113
+ "title": "New features"
114
+ },
115
+ {
116
+ "prefix": "improvement",
117
+ "emoji": "💎",
118
+ "title": "Improvements"
119
+ },
120
+ {
121
+ "prefix": "unclassified",
122
+ "emoji": "❓",
123
+ "title": "Unclassified"
124
+ }
125
+ ]
126
+ }
127
+ ```
128
+
99
129
  ## Contributing
100
130
 
101
131
  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.
@@ -18,19 +18,36 @@ module PrChangelog
18
18
  $ pr_changelog
19
19
  HELP
20
20
 
21
+ class InvalidInputs < StandardError
22
+ end
23
+
24
+ class HelpWanted < StandardError
25
+ end
26
+
21
27
  attr_reader :format, :from_reference, :to_reference
22
28
 
23
29
  def initialize(args)
24
- @format = 'pretty'
30
+ throw HelpWanted if args.include?('--help') || args.include?('-h')
31
+
32
+ @format = PrChangelog.config.default_format
25
33
  if args.include?('--format')
26
34
  next_index = args.index('--format') + 1
27
- @format = args.fetch(next_index)
35
+ @format = args.delete_at(next_index)
36
+ args.delete('--format')
28
37
  end
38
+
29
39
  @from_reference, @to_reference = args.last(2)
40
+ @to_reference ||= 'master'
41
+
42
+ return if @from_reference && @to_reference
43
+
44
+ throw InvalidInputs.new
30
45
  end
31
46
 
32
47
  def run
33
48
  changes = NotReleasedChanges.new(from_reference, to_reference)
49
+ puts "## Changes since #{from_reference} to #{to_reference}\n\n"
50
+
34
51
  if format == 'pretty'
35
52
  puts changes.grouped_formatted_changelog
36
53
  else
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module PrChangelog
6
+ # Loads the configuration
7
+ class Config
8
+ DEFAULTS = {
9
+ format: 'plain',
10
+ tags: [
11
+ {
12
+ prefix: 'feature',
13
+ emoji: '⭐️',
14
+ title: 'New features'
15
+ },
16
+ {
17
+ prefix: 'fix',
18
+ emoji: '🐛',
19
+ title: 'Fixes'
20
+ },
21
+ {
22
+ prefix: 'improvement',
23
+ emoji: '💎',
24
+ title: 'Improvements'
25
+ },
26
+ {
27
+ prefix: 'internal',
28
+ emoji: '👨‍💻',
29
+ title: 'Internal'
30
+ },
31
+ {
32
+ prefix: 'unclassified',
33
+ emoji: '❓',
34
+ title: 'Unclassified'
35
+ }
36
+ ]
37
+ }.freeze
38
+
39
+ def initialize(file = nil)
40
+ @file = file || '.pr_changelog.json'
41
+ @loaded_data = {}
42
+
43
+ return unless File.exist?(@file)
44
+
45
+ @loaded_data = JSON.parse(File.read(@file), symbolize_names: true)
46
+ end
47
+
48
+ def default_format
49
+ loaded_data[:format] || DEFAULTS[:format]
50
+ end
51
+
52
+ def tags
53
+ loaded_data[:tags] || DEFAULTS[:tags]
54
+ end
55
+
56
+ private
57
+
58
+ attr_reader :loaded_data
59
+ end
60
+ end
@@ -6,13 +6,6 @@ module PrChangelog
6
6
  class NotReleasedChanges
7
7
  MERGE_COMMIT_FORMAT = /Merge pull request (?<pr_number>#\d+) .*/.freeze
8
8
  TAGGED_TITLE = /^(?<tag>.+):\s*(?<title>.+)$/.freeze
9
- EMOJI_TAGS = {
10
- 'feature' => Tag.new('⭐️', 'New features', 0),
11
- 'fix' => Tag.new('🐛', 'Fixes', 1),
12
- 'improvement' => Tag.new('💎', 'Improvements', 2),
13
- 'internal' => Tag.new('👨‍💻', 'Internal', 4),
14
- 'unclassified' => Tag.new('❓', 'Unclassified', 5)
15
- }.freeze
16
9
 
17
10
  attr_reader :base_ref, :current_ref, :git_proxy
18
11
 
@@ -22,24 +15,38 @@ module PrChangelog
22
15
  @git_proxy = git_proxy
23
16
  end
24
17
 
18
+ def emoji_tags
19
+ tags = {}
20
+
21
+ PrChangelog.config.tags.each_with_index do |item, index|
22
+ tags[item[:prefix]] = Tag.new(item[:emoji], item[:title], index)
23
+ end
24
+
25
+ tags
26
+ end
27
+
25
28
  def formatted_changelog
26
29
  if parsed_change_list.count.positive?
27
30
  parsed_change_list.map(&:to_s).join("\n")
28
31
  else
29
- "There are no changes since #{base_ref} to #{current_ref}"
32
+ no_changes_found
30
33
  end
31
34
  end
32
35
 
33
36
  def grouped_formatted_changelog
34
37
  if parsed_change_list.count.positive?
35
- GroupedChanges.new(parsed_change_list, EMOJI_TAGS).to_s
38
+ GroupedChanges.new(parsed_change_list, emoji_tags).to_s
36
39
  else
37
- "There are no changes since #{base_ref} to #{current_ref}"
40
+ no_changes_found
38
41
  end
39
42
  end
40
43
 
41
44
  private
42
45
 
46
+ def no_changes_found
47
+ 'No changes found'
48
+ end
49
+
43
50
  def parsed_change_list
44
51
  @parsed_change_list ||= parsed_merge_commits.map do |pair|
45
52
  format_merge_commit(pair.first, pair.last)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrChangelog
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/pr_changelog.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pr_changelog/version'
4
+ require 'pr_changelog/config'
4
5
  require 'pr_changelog/extensions/string'
5
6
  require 'pr_changelog/cli'
6
7
  require 'pr_changelog/git_proxy'
@@ -11,4 +12,7 @@ require 'pr_changelog/not_released_changes'
11
12
 
12
13
  # Main module
13
14
  module PrChangelog
15
+ def self.config
16
+ @config ||= Config.new
17
+ end
14
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pr_changelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Espinoza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-18 00:00:00.000000000 Z
11
+ date: 2019-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,6 +88,7 @@ files:
88
88
  - lib/pr_changelog.rb
89
89
  - lib/pr_changelog/change_line.rb
90
90
  - lib/pr_changelog/cli.rb
91
+ - lib/pr_changelog/config.rb
91
92
  - lib/pr_changelog/extensions/string.rb
92
93
  - lib/pr_changelog/git_proxy.rb
93
94
  - lib/pr_changelog/grouped_changes.rb