gfsm 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70aaff4098b16dd514bf52ca1ae4991702935d45dbc32d8049d3eb73f6268aab
4
- data.tar.gz: e72643fcbcac5675f2ad65b0a2af8b9034c289fa923c1da1ce24fcb09629a2d5
3
+ metadata.gz: bcc64afb8b73256994f18c36d2a639a046e0590ec702860b6cc60346cb764752
4
+ data.tar.gz: '048ff158cca74ebd96952424b7c8246bcae31f99d75a94d679e713411bf7aa51'
5
5
  SHA512:
6
- metadata.gz: 1aed0209eb39ccda368a53e7660d5a722e40753fddadfd046e10ecbdf5bd5695de4e54af07fc77c24945090ed978a6c400870b291579c59152854e6cdc6c4d1a
7
- data.tar.gz: f2953fecd33c22b9cfafaff19ec94cd56b9c8d77fe7f26058979410dd3e30c8ce396330f8d6657d564682dcfe1448a04b0a3627e23b9950db5ab542575304a5c
6
+ metadata.gz: 0b3283af8114728bc505d00af6e12fe6b7ebc0011e9f3fdddf0fb254752a78e98dc67283ae294c4acf3660ba2a5856c673f53786c6fb1899252df8db52058d42
7
+ data.tar.gz: 0d739d31c958f5802b595521ec7ed0ad573220a7930d5c79272628fc0172cbf71fc0129ea29ed7fd8a74036ce1f869824eb6af16e251fc6116631ab6421cf9c2
data/.version CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/Dockerfile CHANGED
@@ -1,5 +1,6 @@
1
1
  FROM ruby:3.2.4-alpine3.20
2
2
 
3
+ RUN apk add git
3
4
  RUN gem install gfsm
4
5
 
5
6
  COPY ./gfsmrc.yml ./gfsmrc.yml
data/bin/gfsm CHANGED
File without changes
@@ -11,22 +11,27 @@ module GFSM
11
11
 
12
12
  <<~HELP
13
13
  Usage:
14
- gfsm changelog [help|generate] [--output-file <path>] [--no-incremental] #{cli_info[:usage]}
14
+ gfsm changelog [help|generate|extract] [--output-file <path>] [--input-file <path>] [--no-incremental] [--only-new-entries] [--extract-version <version>] #{cli_info[:usage]}
15
15
 
16
16
  Commands:
17
17
  help # Prints this help
18
18
  generate # Generate the changelog for the current version
19
+ extract # Extract the changelog for the latest or specified version
19
20
 
20
21
  Options:
21
22
  --output-file <path> # Path to the output changelog file. Defaults to 'CHANGELOG.md'. If not specified, the generate changelog content will be written to stdout
22
23
  --no-incremental # When provided, the generated changelog won't look for an existing changelog file. When outputting to stdout the changelog will never be incremental
23
24
  --only-new-entries # When provided, the generated changelog won't look for an existing changelog file and will contain only the new entries for the current version, without the Changelog or version headings
25
+ --input-file <path> # Path to the input changelog file. Defaults to 'CHANGELOG.md'
26
+ --extract-version <version> # Version from which to extract the changelog. Defaults to the latest one on the changelog file
24
27
  #{cli_info[:options]}
25
28
 
26
29
  Environment variables:
27
30
  OUTPUT_FILE # Equivalent to --output-file
28
31
  NO_INCREMENTAL # Equivalent to --no-incremental
29
- ONLY_ENTRIES # Equivalent to --only-new-entries
32
+ ONLY_NEW_ENTRIES # Equivalent to --only-new-entries
33
+ INPUT_FILE # Equivalent to --input-file
34
+ EXTRACT_VERSION # Equivalent to --extract-version
30
35
  #{cli_info[:environment_variables]}
31
36
  HELP
32
37
  end
@@ -64,8 +69,23 @@ module GFSM
64
69
  end
65
70
  end
66
71
  end
72
+ when 'extract'
73
+ input_file_path = get_input_file_path(args)
74
+ version_to_extract = get_version_to_extract(args)
75
+
76
+ unless File.file?(input_file_path)
77
+ GFSM::Output.error "No changelog file found at #{input_file_path}"
78
+ else
79
+ section = extract_version_section(input_file_path, version_to_extract)
80
+
81
+ if section.nil?
82
+ GFSM::Output.error "No changelog section found for version #{version_to_extract}"
83
+ else
84
+ GFSM::Output.puts section
85
+ end
86
+ end
67
87
  else
68
- GFSM::Output.warn(GFSM::Commands::Version.help)
88
+ GFSM::Output.warn GFSM::Commands::Version.help
69
89
  end
70
90
 
71
91
  true
@@ -106,6 +126,44 @@ module GFSM
106
126
  "#{section}\n\n#{changelog_entries}"
107
127
  end
108
128
 
129
+ def extract_version_section(input_file_path, version_to_extract)
130
+ file_content = File.read(input_file_path)
131
+
132
+ # Parse the file contect to subdivide the changelog sections based on the version
133
+ version_sections = file_content.split(/^## /)
134
+
135
+ # Remove the initial empty section
136
+ version_sections.shift
137
+
138
+ version_to_extract_index = if version_to_extract.nil? || version_to_extract == "latest"
139
+ 0
140
+ else
141
+ version_sections.find_index { |section| section.start_with?("#{version_to_extract}\n") }
142
+ end
143
+ return nil if version_to_extract_index.nil? || version_to_extract_index > version_sections.length
144
+
145
+ version_section = version_sections[version_to_extract_index]
146
+
147
+ # Remove the first line that contains version heading
148
+ version_section = version_section[version_section.index("\n")..-1]
149
+
150
+ # Remove the empty lines at the start and at the end of version_section
151
+ version_section = version_section.strip
152
+
153
+ return version_section
154
+ end
155
+
156
+ def extract_switch_value(args, switch, default_value, env_name = nil)
157
+ return ENV.fetch(env_name) if ENV.has_key?(env_name)
158
+
159
+ switch_index = args.find_index(switch)
160
+
161
+ return default_value unless switch_index &&
162
+ (switch_index + 1) < args.length
163
+
164
+ args[switch_index + 1]
165
+ end
166
+
109
167
  def extract_switch_value_if_present(args, switch, default_value, env_name)
110
168
  return ENV.fetch(env_name) if ENV.has_key?(env_name)
111
169
 
@@ -120,6 +178,14 @@ module GFSM
120
178
  def get_output_file_path(args)
121
179
  extract_switch_value_if_present(args, "--output-file", "./CHANGELOG.md", "OUTPUT_FILE")
122
180
  end
181
+
182
+ def get_input_file_path(args)
183
+ extract_switch_value(args, "--input-file", "./CHANGELOG.md", "INPUT_FILE")
184
+ end
185
+
186
+ def get_version_to_extract(args)
187
+ extract_switch_value(args, "--extract-version", nil, "EXTRACT_VERSION")
188
+ end
123
189
  end
124
190
  end
125
191
  end
@@ -15,14 +15,13 @@ module GFSM
15
15
  begin
16
16
  repo.fetch(nil, {tags: true})
17
17
  repo.describe(nil, {tags: true, abbrev: 0})
18
- rescue => error
19
- GFSM::Output.error(error.message)
18
+ rescue
20
19
  end
21
20
  end
22
21
 
23
22
  def self.extract_commits_with_changelog_trailer(repo, from, to = "HEAD")
24
23
  begin
25
- commits = repo.log.between(from, to)
24
+ commits = from.nil? ? repo.log : repo.log.between(from, to)
26
25
  commits.each_with_object([]) do |commit, memo|
27
26
  trailer = commit.message.match(CHANGELOG_TRAILER_REGEX)
28
27
  memo << GFSM::Data::Commit.new(commit, trailer[:name], trailer[:category]) if trailer
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gfsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zille Marco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml