gem_hadar 2.10.0 → 2.12.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 +4 -4
- data/.all_images.yml +1 -1
- data/Rakefile +2 -1
- data/gem_hadar.gemspec +6 -5
- data/lib/gem_hadar/changelog_generator.rb +292 -0
- data/lib/gem_hadar/github.rb +1 -2
- data/lib/gem_hadar/ollama_support.rb +72 -0
- data/lib/gem_hadar/prompt_template.rb +46 -0
- data/lib/gem_hadar/rvm_config.rb +0 -3
- data/lib/gem_hadar/utils.rb +81 -41
- data/lib/gem_hadar/version.rb +1 -1
- data/lib/gem_hadar/version_spec.rb +195 -0
- data/lib/gem_hadar/warn.rb +0 -2
- data/lib/gem_hadar.rb +191 -144
- metadata +23 -3
data/lib/gem_hadar.rb
CHANGED
|
@@ -13,7 +13,6 @@ require 'rake/clean'
|
|
|
13
13
|
require 'rake/testtask'
|
|
14
14
|
require 'set'
|
|
15
15
|
require 'pathname'
|
|
16
|
-
require 'ollama'
|
|
17
16
|
require 'term/ansicolor'
|
|
18
17
|
require_maybe 'yard'
|
|
19
18
|
require_maybe 'simplecov'
|
|
@@ -21,8 +20,6 @@ require_maybe 'rubygems/package_task'
|
|
|
21
20
|
require_maybe 'rcov/rcovtask'
|
|
22
21
|
require_maybe 'rspec/core/rake_task'
|
|
23
22
|
|
|
24
|
-
# A brief description of the GemHadar class.
|
|
25
|
-
#
|
|
26
23
|
# The GemHadar class serves as the primary configuration and task management
|
|
27
24
|
# framework for Ruby gem projects. It provides a DSL for defining gem metadata,
|
|
28
25
|
# dependencies, and Rake tasks, while also offering integration with various
|
|
@@ -61,8 +58,11 @@ require 'gem_hadar/utils'
|
|
|
61
58
|
require 'gem_hadar/warn'
|
|
62
59
|
require 'gem_hadar/setup'
|
|
63
60
|
require 'gem_hadar/template_compiler'
|
|
61
|
+
require 'gem_hadar/ollama_support'
|
|
64
62
|
require 'gem_hadar/github'
|
|
63
|
+
require 'gem_hadar/version_spec'
|
|
65
64
|
require 'gem_hadar/prompt_template'
|
|
65
|
+
require 'gem_hadar/changelog_generator'
|
|
66
66
|
require 'gem_hadar/rvm_config'
|
|
67
67
|
|
|
68
68
|
class GemHadar
|
|
@@ -70,6 +70,7 @@ class GemHadar
|
|
|
70
70
|
include GemHadar::Utils
|
|
71
71
|
include GemHadar::PromptTemplate
|
|
72
72
|
include GemHadar::Warn
|
|
73
|
+
include GemHadar::OllamaSupport
|
|
73
74
|
|
|
74
75
|
if defined?(::RbConfig)
|
|
75
76
|
include ::RbConfig
|
|
@@ -80,12 +81,16 @@ class GemHadar
|
|
|
80
81
|
extend DSLKit::DSLAccessor
|
|
81
82
|
include Tins::SecureWrite
|
|
82
83
|
|
|
83
|
-
# The initialize method sets up
|
|
84
|
-
#
|
|
84
|
+
# The initialize method sets up a new GemHadar instance and configures it
|
|
85
|
+
# using the provided block.
|
|
85
86
|
#
|
|
86
|
-
#
|
|
87
|
+
# This method creates a new instance of the GemHadar class, initializes
|
|
88
|
+
# internal arrays for dependencies and development dependencies, and then
|
|
89
|
+
# evaluates the provided block in the context of the new instance to
|
|
90
|
+
# configure the gem settings.
|
|
87
91
|
#
|
|
88
|
-
# @
|
|
92
|
+
# @yield [gem_hadar] yields the GemHadar instance to the configuration block
|
|
93
|
+
# @yieldparam gem_hadar [GemHadar] the GemHadar instance being configured
|
|
89
94
|
def initialize(&block)
|
|
90
95
|
@dependencies = []
|
|
91
96
|
@development_dependencies = []
|
|
@@ -833,7 +838,9 @@ class GemHadar
|
|
|
833
838
|
#
|
|
834
839
|
# @return [ String ] the git log output in patch format showing changes between the two versions
|
|
835
840
|
def version_log_diff(to_version: 'HEAD', from_version: nil)
|
|
836
|
-
|
|
841
|
+
to_version = GemHadar::VersionSpec[to_version]
|
|
842
|
+
from_version = from_version.full? { GemHadar::VersionSpec[from_version] }
|
|
843
|
+
if to_version.head?
|
|
837
844
|
if from_version.blank?
|
|
838
845
|
from_version = versions.last
|
|
839
846
|
else
|
|
@@ -841,7 +848,7 @@ class GemHadar
|
|
|
841
848
|
fail "Could not find #{from_version.inspect}."
|
|
842
849
|
end
|
|
843
850
|
end
|
|
844
|
-
`git log -p #{
|
|
851
|
+
`git log -p #{from_version.tag}..HEAD`
|
|
845
852
|
else
|
|
846
853
|
unless versions.find { |v| v == to_version }
|
|
847
854
|
fail "Could not find #{to_version.inspect}."
|
|
@@ -853,14 +860,14 @@ class GemHadar
|
|
|
853
860
|
end
|
|
854
861
|
end
|
|
855
862
|
unless from_version
|
|
856
|
-
return `git log -p #{
|
|
863
|
+
return `git log -p #{to_version.tag}`
|
|
857
864
|
end
|
|
858
865
|
else
|
|
859
866
|
unless versions.find { |v| v == from_version }
|
|
860
867
|
fail "Could not find #{from_version.inspect}."
|
|
861
868
|
end
|
|
862
869
|
end
|
|
863
|
-
`git log -p #{
|
|
870
|
+
`git log -p #{from_version.tag}..#{to_version.tag}`
|
|
864
871
|
end
|
|
865
872
|
end
|
|
866
873
|
|
|
@@ -1070,8 +1077,8 @@ class GemHadar
|
|
|
1070
1077
|
desc 'Bump version with AI suggestion'
|
|
1071
1078
|
task :bump do
|
|
1072
1079
|
log_diff = version_log_diff(from_version: nil, to_version: 'HEAD')
|
|
1073
|
-
system = xdg_config('version_bump_system_prompt.txt', default_version_bump_system_prompt)
|
|
1074
|
-
prompt = xdg_config('version_bump_prompt.txt', default_version_bump_prompt) % { version:, log_diff: }
|
|
1080
|
+
system = xdg_config('gem_hadar', 'version_bump_system_prompt.txt', default_version_bump_system_prompt)
|
|
1081
|
+
prompt = xdg_config('gem_hadar', 'version_bump_prompt.txt', default_version_bump_prompt) % { version:, log_diff: }
|
|
1075
1082
|
response = ollama_generate(system:, prompt:)
|
|
1076
1083
|
puts response
|
|
1077
1084
|
default = nil
|
|
@@ -1107,7 +1114,7 @@ class GemHadar
|
|
|
1107
1114
|
task :tag do
|
|
1108
1115
|
force = ENV['FORCE'].to_i == 1
|
|
1109
1116
|
begin
|
|
1110
|
-
sh "git tag -a -m 'Version #{version}' #{'-f' if force} #{
|
|
1117
|
+
sh "git tag -a -m 'Version #{version}' #{'-f' if force} #{GemHadar::VersionSpec[version].tag}"
|
|
1111
1118
|
rescue RuntimeError
|
|
1112
1119
|
if `git diff v#{version}..HEAD`.empty?
|
|
1113
1120
|
puts "Version #{version} is already tagged, but it's no different"
|
|
@@ -1287,8 +1294,8 @@ class GemHadar
|
|
|
1287
1294
|
# @return [ String ] the generated changelog content for the release body
|
|
1288
1295
|
def create_git_release_body
|
|
1289
1296
|
log_diff = version_log_diff(to_version: version)
|
|
1290
|
-
system = xdg_config('release_system_prompt.txt', default_git_release_system_prompt)
|
|
1291
|
-
prompt = xdg_config('release_prompt.txt', default_git_release_prompt) % { name:, version:, log_diff: }
|
|
1297
|
+
system = xdg_config('gem_hadar', 'release_system_prompt.txt', default_git_release_system_prompt)
|
|
1298
|
+
prompt = xdg_config('gem_hadar', 'release_prompt.txt', default_git_release_prompt) % { name:, version:, log_diff: }
|
|
1292
1299
|
ollama_generate(system:, prompt:)
|
|
1293
1300
|
end
|
|
1294
1301
|
|
|
@@ -1319,7 +1326,7 @@ class GemHadar
|
|
|
1319
1326
|
end
|
|
1320
1327
|
if %r(\A/*(?<owner>[^/]+)/(?<repo>[^/.]+)) =~ github_remote_url&.path
|
|
1321
1328
|
rc = GitHub::ReleaseCreator.new(owner:, repo:, token: github_api_token)
|
|
1322
|
-
tag_name =
|
|
1329
|
+
tag_name = GemHadar::VersionSpec[version].tag
|
|
1323
1330
|
target_commitish = `git show -s --format=%H #{tag_name.inspect}^{commit}`.chomp
|
|
1324
1331
|
body = edit_temp_file(create_git_release_body)
|
|
1325
1332
|
if body.present?
|
|
@@ -1442,9 +1449,6 @@ class GemHadar
|
|
|
1442
1449
|
# protected methods. It configures the output directory, handles README
|
|
1443
1450
|
# files, includes additional documentation files, and sets up a pre-execution
|
|
1444
1451
|
# cleanup routine.
|
|
1445
|
-
#
|
|
1446
|
-
# @return [ void ] This method does not return a value but defines a Rake task
|
|
1447
|
-
# named :yard_doc with specific configuration options.
|
|
1448
1452
|
def yard_doc_task
|
|
1449
1453
|
YARD::Rake::YardocTask.new(:yard_doc) do |t|
|
|
1450
1454
|
t.files = doc_code_files.grep(%r(\.rb\z))
|
|
@@ -1548,7 +1552,7 @@ class GemHadar
|
|
|
1548
1552
|
# Ollama
|
|
1549
1553
|
puts "Ollama Model: #{ollama_model} (default is #{ollama_model_default})"
|
|
1550
1554
|
|
|
1551
|
-
if url =
|
|
1555
|
+
if url = (ollama.base_url rescue nil)&.to_s
|
|
1552
1556
|
puts "Ollama Base URL: #{url.inspect}"
|
|
1553
1557
|
else
|
|
1554
1558
|
puts "Ollama Base URL: Not set"
|
|
@@ -1560,8 +1564,8 @@ class GemHadar
|
|
|
1560
1564
|
puts "Ollama Model Options: Not set (using defaults)"
|
|
1561
1565
|
end
|
|
1562
1566
|
|
|
1563
|
-
# XDG config
|
|
1564
|
-
puts "XDG config
|
|
1567
|
+
# XDG config app dir
|
|
1568
|
+
puts "XDG config app dir: #{xdg_config_dir('gem_hadar').to_s.inspect}"
|
|
1565
1569
|
|
|
1566
1570
|
# General
|
|
1567
1571
|
puts "Gem Name: #{name}"
|
|
@@ -1583,14 +1587,116 @@ class GemHadar
|
|
|
1583
1587
|
arrow = ?⤵
|
|
1584
1588
|
puts bold{"version_bump_system_prompt.txt"} + "#{arrow}\n" + italic{default_version_bump_system_prompt}
|
|
1585
1589
|
puts bold{"version_bump_prompt.txt"} + "#{arrow}\n#{default_version_bump_prompt}"
|
|
1586
|
-
puts bold{"
|
|
1587
|
-
puts bold{"
|
|
1590
|
+
puts bold{"git_release_system_prompt.txt"} + "#{arrow}\n" + italic{default_git_release_system_prompt}
|
|
1591
|
+
puts bold{"git_release_prompt.txt"} + "#{arrow}\n" + italic{default_git_release_prompt}
|
|
1592
|
+
puts bold{"changelog_system_prompt.txt"} + "#{arrow}\n" + italic{default_changelog_system_prompt}
|
|
1593
|
+
puts bold{"changelog_prompt.txt"} + "#{arrow}\n" + italic{default_changelog_prompt}
|
|
1588
1594
|
|
|
1589
1595
|
puts "=== End Configuration ==="
|
|
1590
1596
|
end
|
|
1591
1597
|
end
|
|
1592
1598
|
end
|
|
1593
1599
|
|
|
1600
|
+
# The changes_task method defines namespaced Rake tasks for generating changelogs.
|
|
1601
|
+
#
|
|
1602
|
+
# This method sets up a hierarchical task structure under the :changes namespace that:
|
|
1603
|
+
# - :changes - Show help for all changes tasks
|
|
1604
|
+
# - :changes:pending - Show changes since last version tag
|
|
1605
|
+
# - :changes:current - Show changes between two latest version tags
|
|
1606
|
+
# - :changes:range - Show changes for a specific Git range
|
|
1607
|
+
# - :changes:full - Generate complete changelog from first tag
|
|
1608
|
+
# - :changes:add - Append to existing changelog file
|
|
1609
|
+
def changes_task
|
|
1610
|
+
namespace :changes do
|
|
1611
|
+
desc 'Show changes since last version tag'
|
|
1612
|
+
task :pending do
|
|
1613
|
+
unless version_tag_list.any?
|
|
1614
|
+
raise 'Need at least one version tag to work'
|
|
1615
|
+
end
|
|
1616
|
+
last_version = version_tag_list.last
|
|
1617
|
+
if last_version
|
|
1618
|
+
puts GemHadar::ChangelogGenerator.new(self).generate(last_version, 'HEAD')
|
|
1619
|
+
else
|
|
1620
|
+
raise 'Need at least one version tag to work'
|
|
1621
|
+
end
|
|
1622
|
+
end
|
|
1623
|
+
|
|
1624
|
+
desc 'Show changes between two latest version tags'
|
|
1625
|
+
task :current do
|
|
1626
|
+
unless version_tag_list.length >= 2
|
|
1627
|
+
raise 'Need at least two version tags to work'
|
|
1628
|
+
end
|
|
1629
|
+
|
|
1630
|
+
version1, version2 = version_tag_list.last(2)
|
|
1631
|
+
if version1 && version2
|
|
1632
|
+
puts GemHadar::ChangelogGenerator.new(self).generate(version1, version2)
|
|
1633
|
+
else
|
|
1634
|
+
raise 'Need at least two version tags to work'
|
|
1635
|
+
end
|
|
1636
|
+
end
|
|
1637
|
+
|
|
1638
|
+
desc 'Show changes for a specific Git range (e.g., v1.0.0..v1.2.0)'
|
|
1639
|
+
task :range do
|
|
1640
|
+
if ARGV.size == 2 and range = ARGV.pop and range =~ /\A(.+)\.\.(.+)\z/
|
|
1641
|
+
range_from, range_to = $1, $2
|
|
1642
|
+
|
|
1643
|
+
from_spec = GemHadar::VersionSpec[range_from]
|
|
1644
|
+
to_spec = GemHadar::VersionSpec[range_to]
|
|
1645
|
+
|
|
1646
|
+
unless from_spec.version? && to_spec.version?
|
|
1647
|
+
raise "Invalid version format: #{range_from} or #{range_to}"
|
|
1648
|
+
end
|
|
1649
|
+
|
|
1650
|
+
GemHadar::ChangelogGenerator.new(self).
|
|
1651
|
+
generate_range(STDOUT, from_spec, to_spec)
|
|
1652
|
+
exit
|
|
1653
|
+
else
|
|
1654
|
+
raise "Need range of the form v1.2.3..v1.2.4"
|
|
1655
|
+
end
|
|
1656
|
+
end
|
|
1657
|
+
|
|
1658
|
+
desc 'Generate complete changelog from first tag and output to file'
|
|
1659
|
+
task :full do
|
|
1660
|
+
if ARGV.size == 1
|
|
1661
|
+
GemHadar::ChangelogGenerator.new(self).generate_full(STDOUT)
|
|
1662
|
+
elsif ARGV.size == 2
|
|
1663
|
+
File.open(ARGV[1], ?w) do |file|
|
|
1664
|
+
GemHadar::ChangelogGenerator.new(self).generate_full(file)
|
|
1665
|
+
end
|
|
1666
|
+
else
|
|
1667
|
+
raise "Need a filename to write to"
|
|
1668
|
+
end
|
|
1669
|
+
end
|
|
1670
|
+
|
|
1671
|
+
desc 'Append new entries to existing changelog file'
|
|
1672
|
+
task :add do
|
|
1673
|
+
filename = ARGV[1] or raise 'Need file to add to'
|
|
1674
|
+
GemHadar::ChangelogGenerator.new(self).add_to_file(filename)
|
|
1675
|
+
end
|
|
1676
|
+
end
|
|
1677
|
+
|
|
1678
|
+
# Main changes task that shows help when called directly
|
|
1679
|
+
desc 'Generate changelogs using Git history and AI'
|
|
1680
|
+
task :changes do
|
|
1681
|
+
puts <<~EOT
|
|
1682
|
+
Changes Tasks:
|
|
1683
|
+
rake changes:pending Show changes since last version tag
|
|
1684
|
+
rake changes:current Show changes between two latest version tags
|
|
1685
|
+
rake changes:range <range> Show changes for a specific Git range (e.g., v1.0.0..v1.2.0)
|
|
1686
|
+
rake changes:full [file] Generate complete changelog from first tag
|
|
1687
|
+
rake changes:add <file> Append new entries to existing changelog file
|
|
1688
|
+
|
|
1689
|
+
Examples:
|
|
1690
|
+
rake changes:pending
|
|
1691
|
+
rake changes:current
|
|
1692
|
+
rake changes:range v1.0.0..v1.2.0
|
|
1693
|
+
rake changes:full
|
|
1694
|
+
rake changes:full CHANGES.md
|
|
1695
|
+
rake changes:add CHANGES.md
|
|
1696
|
+
EOT
|
|
1697
|
+
end
|
|
1698
|
+
end
|
|
1699
|
+
|
|
1594
1700
|
# The create_all_tasks method sets up and registers all the Rake tasks for
|
|
1595
1701
|
# the gem project.
|
|
1596
1702
|
#
|
|
@@ -1598,6 +1704,7 @@ class GemHadar
|
|
|
1598
1704
|
def create_all_tasks
|
|
1599
1705
|
default_task
|
|
1600
1706
|
config_task
|
|
1707
|
+
changes_task
|
|
1601
1708
|
build_task
|
|
1602
1709
|
rvm_task
|
|
1603
1710
|
version_task
|
|
@@ -1673,56 +1780,6 @@ class GemHadar
|
|
|
1673
1780
|
# @return [ String ] the default Ollama AI model name, which is 'llama3.1'
|
|
1674
1781
|
dsl_accessor :ollama_model_default, 'llama3.1'.freeze
|
|
1675
1782
|
|
|
1676
|
-
# The ollama_model method retrieves the name of the Ollama AI model to be
|
|
1677
|
-
# used for generating responses.
|
|
1678
|
-
#
|
|
1679
|
-
# It first checks the OLLAMA_MODEL environment variable for a custom model
|
|
1680
|
-
# specification. If the environment variable is not set, it falls back to
|
|
1681
|
-
# using the default model name, which is determined by the
|
|
1682
|
-
# ollama_model_default dsl method.
|
|
1683
|
-
#
|
|
1684
|
-
# @return [ String ] the name of the Ollama AI model to be used
|
|
1685
|
-
def ollama_model
|
|
1686
|
-
ENV.fetch('OLLAMA_MODEL', ollama_model_default)
|
|
1687
|
-
end
|
|
1688
|
-
|
|
1689
|
-
# The ollama_client method creates and returns an Ollama::Client instance
|
|
1690
|
-
# configured with a base URL derived from environment variables.
|
|
1691
|
-
#
|
|
1692
|
-
# It first checks for the OLLAMA_URL environment variable to determine the
|
|
1693
|
-
# base URL. If that is not set, it falls back to using the OLLAMA_HOST
|
|
1694
|
-
# environment variable, defaulting to 'localhost:11434' if that is also not
|
|
1695
|
-
# set. The method then constructs the full base URL and initializes an
|
|
1696
|
-
# Ollama::Client with appropriate timeouts for read and connect operations.
|
|
1697
|
-
#
|
|
1698
|
-
# @return [Ollama::Client, nil] An initialized Ollama::Client instance if a
|
|
1699
|
-
# valid base URL is present, otherwise nil.
|
|
1700
|
-
def ollama_client
|
|
1701
|
-
base_url = ENV['OLLAMA_URL']
|
|
1702
|
-
if base_url.blank?
|
|
1703
|
-
host = ENV.fetch('OLLAMA_HOST', 'localhost:11434')
|
|
1704
|
-
base_url = 'http://%s' % host
|
|
1705
|
-
end
|
|
1706
|
-
base_url.present? or return
|
|
1707
|
-
Ollama::Client.new(base_url:, read_timeout: 600, connect_timeout: 60)
|
|
1708
|
-
end
|
|
1709
|
-
|
|
1710
|
-
# Generates a response from an AI model using the Ollama::Client.
|
|
1711
|
-
#
|
|
1712
|
-
# @param [String] system The system prompt for the AI model.
|
|
1713
|
-
# @param [String] prompt The user prompt to generate a response to.
|
|
1714
|
-
# @return [String, nil] The generated response or nil if generation fails.
|
|
1715
|
-
def ollama_generate(system:, prompt:)
|
|
1716
|
-
unless ollama = ollama_client
|
|
1717
|
-
warn "Ollama is not configured. => Returning."
|
|
1718
|
-
return
|
|
1719
|
-
end
|
|
1720
|
-
model = ollama_model
|
|
1721
|
-
options = ENV['OLLAMA_MODEL_OPTIONS'].full? { |o| JSON.parse(o) } || {}
|
|
1722
|
-
options |= { "temperature" => 0, "top_p" => 1, "min_p" => 0.1 }
|
|
1723
|
-
ollama.generate(model:, system:, prompt:, options:, stream: false, think: false).response
|
|
1724
|
-
end
|
|
1725
|
-
|
|
1726
1783
|
# Increases the specified part of the version number and writes it back to
|
|
1727
1784
|
# the VERSION file.
|
|
1728
1785
|
#
|
|
@@ -1744,9 +1801,9 @@ class GemHadar
|
|
|
1744
1801
|
# - The start version (e.g., '1.2.3') from which changes are compared.
|
|
1745
1802
|
# - The end version (e.g., '1.2.4' or 'HEAD') up to which changes are compared.
|
|
1746
1803
|
def determine_version_range
|
|
1747
|
-
version_tags
|
|
1748
|
-
found_version_tag = version_tags.index(
|
|
1749
|
-
found_version_tag.nil? and fail "cannot find version tag #{
|
|
1804
|
+
version_tags = versions.map { GemHadar::VersionSpec[_1].tag } + %w[ HEAD ]
|
|
1805
|
+
found_version_tag = version_tags.index(GemHadar::VersionSpec[version].tag)
|
|
1806
|
+
found_version_tag.nil? and fail "cannot find version tag #{GemHadar::VersionSpec[version].tag}"
|
|
1750
1807
|
start_version, end_version = version_tags[found_version_tag, 2]
|
|
1751
1808
|
return start_version, end_version
|
|
1752
1809
|
end
|
|
@@ -1759,6 +1816,25 @@ class GemHadar
|
|
|
1759
1816
|
end
|
|
1760
1817
|
end
|
|
1761
1818
|
|
|
1819
|
+
# The version_tag_list method retrieves and processes semantic version tags
|
|
1820
|
+
# from the Git repository.
|
|
1821
|
+
#
|
|
1822
|
+
# This method fetches all Git tags from the repository, filters them to
|
|
1823
|
+
# include only those that match semantic versioning patterns (containing
|
|
1824
|
+
# three numeric components separated by dots), removes any 'v' prefix from
|
|
1825
|
+
# the tags, and sorts the resulting version specifications in ascending order
|
|
1826
|
+
# according to semantic versioning rules.
|
|
1827
|
+
#
|
|
1828
|
+
# @return [ Array<GemHadar::VersionSpec> ] an array of VersionSpec objects
|
|
1829
|
+
# representing the semantic versions found in the repository, sorted in
|
|
1830
|
+
# ascending order
|
|
1831
|
+
def version_tag_list
|
|
1832
|
+
`git tag`.lines.grep(/^v?\d+\.\d+\.\d+$/).
|
|
1833
|
+
map { |tag| GemHadar::VersionSpec[tag.chomp] }.
|
|
1834
|
+
sort_by(&:version)
|
|
1835
|
+
end
|
|
1836
|
+
memoize method: :version_tag_list, freeze: true
|
|
1837
|
+
|
|
1762
1838
|
# The write_gemfile method creates and writes the default Gemfile content if
|
|
1763
1839
|
# it doesn't exist. If a custom Gemfile exists, it only displays a warning.
|
|
1764
1840
|
def write_gemfile
|
|
@@ -1812,7 +1888,7 @@ class GemHadar
|
|
|
1812
1888
|
def gemspec
|
|
1813
1889
|
Gem::Specification.new do |s|
|
|
1814
1890
|
s.name = name
|
|
1815
|
-
s.version = ::Gem::Version.new(version)
|
|
1891
|
+
s.version = ::Gem::Version.new(GemHadar::VersionSpec[version].untag)
|
|
1816
1892
|
s.author = author
|
|
1817
1893
|
s.email = email
|
|
1818
1894
|
s.homepage = assert_valid_link(:homepage, homepage)
|
|
@@ -1873,29 +1949,6 @@ class GemHadar
|
|
|
1873
1949
|
remotes
|
|
1874
1950
|
end
|
|
1875
1951
|
|
|
1876
|
-
# The ask? method prompts the user with a message and reads their input It
|
|
1877
|
-
# returns a MatchData object if the input matches the provided pattern.
|
|
1878
|
-
#
|
|
1879
|
-
# @param prompt [ String ] the message to display to the user
|
|
1880
|
-
# @param pattern [ Regexp ] the regular expression to match against the input
|
|
1881
|
-
#
|
|
1882
|
-
# @return [ MatchData, nil ] the result of the pattern match or nil if no match
|
|
1883
|
-
def ask?(prompt, pattern, default: nil)
|
|
1884
|
-
if prompt.include?('%{default}')
|
|
1885
|
-
if default.present?
|
|
1886
|
-
prompt = prompt % { default: ", default is #{default.inspect}" }
|
|
1887
|
-
else
|
|
1888
|
-
prompt = prompt % { default: '' }
|
|
1889
|
-
end
|
|
1890
|
-
end
|
|
1891
|
-
STDOUT.print prompt
|
|
1892
|
-
answer = STDIN.gets.chomp
|
|
1893
|
-
default.present? && answer.blank? and answer = default
|
|
1894
|
-
if answer =~ pattern
|
|
1895
|
-
$~
|
|
1896
|
-
end
|
|
1897
|
-
end
|
|
1898
|
-
|
|
1899
1952
|
# The gem_files method returns an array of files that are included in the gem
|
|
1900
1953
|
# package.
|
|
1901
1954
|
#
|
|
@@ -1919,33 +1972,11 @@ class GemHadar
|
|
|
1919
1972
|
# order according to semantic versioning rules.
|
|
1920
1973
|
memoize method:
|
|
1921
1974
|
def versions
|
|
1922
|
-
`git tag`.lines.grep(/^v?\d+\.\d+\.\d+$/).map(&:chomp).map {
|
|
1923
|
-
|
|
1975
|
+
`git tag`.lines.grep(/^v?\d+\.\d+\.\d+$/).map(&:chomp).map { |tag|
|
|
1976
|
+
GemHadar::VersionSpec[tag, without_prefix: true]
|
|
1924
1977
|
}.sort_by(&:version)
|
|
1925
1978
|
end
|
|
1926
1979
|
|
|
1927
|
-
# The version_tag method prepends a 'v' prefix to the given version
|
|
1928
|
-
# string, unless it's HEAD.
|
|
1929
|
-
#
|
|
1930
|
-
# @param version [String] the version string to modify
|
|
1931
|
-
# @return [String] the modified version string with a 'v' prefix
|
|
1932
|
-
def version_tag(version)
|
|
1933
|
-
if version != 'HEAD'
|
|
1934
|
-
version.dup.prepend ?v
|
|
1935
|
-
else
|
|
1936
|
-
version.dup
|
|
1937
|
-
end
|
|
1938
|
-
end
|
|
1939
|
-
|
|
1940
|
-
# The version_untag method removes the 'v' prefix from a version tag string.
|
|
1941
|
-
#
|
|
1942
|
-
# @param version_tag [ String ] the version tag string that may start with 'v'
|
|
1943
|
-
#
|
|
1944
|
-
# @return [ String ] the version string with the 'v' prefix removed
|
|
1945
|
-
def version_untag(version_tag)
|
|
1946
|
-
version.sub(/\Av/, '')
|
|
1947
|
-
end
|
|
1948
|
-
|
|
1949
1980
|
# The github_remote_url method retrieves and parses the GitHub remote URL
|
|
1950
1981
|
# from the local Git configuration.
|
|
1951
1982
|
#
|
|
@@ -1995,36 +2026,52 @@ class GemHadar
|
|
|
1995
2026
|
@github_workflows_variables || {}
|
|
1996
2027
|
end
|
|
1997
2028
|
|
|
2029
|
+
# The create_github_workflow_templates method compiles GitHub Actions
|
|
2030
|
+
# workflow templates from ERB files into actual YAML workflow files in the
|
|
2031
|
+
# project's .github/workflows directory
|
|
2032
|
+
#
|
|
2033
|
+
# This method iterates through the configured GitHub workflows, processes
|
|
2034
|
+
# each ERB template file using the template compilation system, and generates
|
|
2035
|
+
# the corresponding workflow files in the standard GitHub Actions directory
|
|
2036
|
+
# structure
|
|
2037
|
+
def create_github_workflow_templates
|
|
2038
|
+
src_dir = Pathname.new(__dir__).join('gem_hadar', 'github_workflows')
|
|
2039
|
+
dst_dir = Pathname.pwd.join('.github', 'workflows')
|
|
2040
|
+
templates = Set[]
|
|
2041
|
+
github_workflows.each do |workflow, variables|
|
|
2042
|
+
@github_workflows_variables = variables
|
|
2043
|
+
src = src_dir.join(workflow + '.erb')
|
|
2044
|
+
unless src.exist?
|
|
2045
|
+
warn "Workflow template #{src.to_s.inspect} doesn't exist! => Skipping."
|
|
2046
|
+
end
|
|
2047
|
+
mkdir_p dst_dir, verbose: false
|
|
2048
|
+
dst = dst_dir.join(workflow)
|
|
2049
|
+
templates << template(src, dst) {}
|
|
2050
|
+
end
|
|
2051
|
+
templates.to_a
|
|
2052
|
+
end
|
|
2053
|
+
|
|
1998
2054
|
# The github_workflows_task method sets up Rake tasks for generating GitHub
|
|
1999
2055
|
# Actions workflow files from ERB templates.
|
|
2000
2056
|
#
|
|
2001
|
-
# This method configures a hierarchical task structure under the :github
|
|
2002
|
-
#
|
|
2057
|
+
# This method configures a hierarchical task structure under the :github
|
|
2058
|
+
# namespace that:
|
|
2059
|
+
#
|
|
2060
|
+
# - Compiles configured workflow templates from ERB files into actual
|
|
2061
|
+
# workflow YAML files
|
|
2003
2062
|
# - Creates a :workflows task that depends on all compiled template files
|
|
2004
2063
|
# - Sets up a :workflows:clean task to remove generated workflow files
|
|
2005
|
-
# - Uses the github_workflows configuration to determine which workflows to
|
|
2064
|
+
# - Uses the github_workflows configuration to determine which workflows to
|
|
2065
|
+
# generate
|
|
2006
2066
|
# - Applies template variables to customize the generated workflows
|
|
2007
2067
|
def github_workflows_task
|
|
2008
2068
|
namespace :github do
|
|
2009
|
-
templates = []
|
|
2010
|
-
src_dir = Pathname.new(__dir__).join('gem_hadar', 'github_workflows')
|
|
2011
|
-
dst_dir = Pathname.pwd.join('.github', 'workflows')
|
|
2012
|
-
github_workflows.each do |workflow, variables|
|
|
2013
|
-
@github_workflows_variables = variables
|
|
2014
|
-
src = src_dir.join(workflow + '.erb')
|
|
2015
|
-
puts "Compiling #{src.to_s.inspect} to #{dst_dir.to_s.inspect} now."
|
|
2016
|
-
unless src.exist?
|
|
2017
|
-
warn "Workflow template #{src.to_s.inspect} doesn't exist! => Skipping."
|
|
2018
|
-
end
|
|
2019
|
-
mkdir_p dst_dir
|
|
2020
|
-
dst = dst_dir.join(workflow)
|
|
2021
|
-
templates << (template(src, dst) {}).to_s
|
|
2022
|
-
end
|
|
2023
2069
|
desc "Create all configured github workflow tasks"
|
|
2024
|
-
task :workflows =>
|
|
2070
|
+
task :workflows => create_github_workflow_templates
|
|
2025
2071
|
namespace :workflows do
|
|
2026
2072
|
desc "Delete all created github workflows"
|
|
2027
2073
|
task :clean do
|
|
2074
|
+
dst_dir = Pathname.pwd.join('.github', 'workflows')
|
|
2028
2075
|
github_workflows.each_key do |workflow|
|
|
2029
2076
|
rm_f dst_dir.join(workflow), verbose: true
|
|
2030
2077
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gem_hadar
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.12.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '2.
|
|
18
|
+
version: '2.12'
|
|
19
19
|
type: :development
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '2.
|
|
25
|
+
version: '2.12'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: all_images
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -107,6 +107,20 @@ dependencies:
|
|
|
107
107
|
- - "~>"
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
109
|
version: '1.17'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: infobar
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0.11'
|
|
117
|
+
type: :runtime
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0.11'
|
|
110
124
|
- !ruby/object:Gem::Dependency
|
|
111
125
|
name: mize
|
|
112
126
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -242,7 +256,9 @@ extensions: []
|
|
|
242
256
|
extra_rdoc_files:
|
|
243
257
|
- README.md
|
|
244
258
|
- lib/gem_hadar.rb
|
|
259
|
+
- lib/gem_hadar/changelog_generator.rb
|
|
245
260
|
- lib/gem_hadar/github.rb
|
|
261
|
+
- lib/gem_hadar/ollama_support.rb
|
|
246
262
|
- lib/gem_hadar/prompt_template.rb
|
|
247
263
|
- lib/gem_hadar/rvm_config.rb
|
|
248
264
|
- lib/gem_hadar/setup.rb
|
|
@@ -250,6 +266,7 @@ extra_rdoc_files:
|
|
|
250
266
|
- lib/gem_hadar/template_compiler.rb
|
|
251
267
|
- lib/gem_hadar/utils.rb
|
|
252
268
|
- lib/gem_hadar/version.rb
|
|
269
|
+
- lib/gem_hadar/version_spec.rb
|
|
253
270
|
- lib/gem_hadar/warn.rb
|
|
254
271
|
files:
|
|
255
272
|
- ".all_images.yml"
|
|
@@ -261,8 +278,10 @@ files:
|
|
|
261
278
|
- bin/gem_hadar
|
|
262
279
|
- gem_hadar.gemspec
|
|
263
280
|
- lib/gem_hadar.rb
|
|
281
|
+
- lib/gem_hadar/changelog_generator.rb
|
|
264
282
|
- lib/gem_hadar/github.rb
|
|
265
283
|
- lib/gem_hadar/github_workflows/static.yml.erb
|
|
284
|
+
- lib/gem_hadar/ollama_support.rb
|
|
266
285
|
- lib/gem_hadar/prompt_template.rb
|
|
267
286
|
- lib/gem_hadar/rvm_config.rb
|
|
268
287
|
- lib/gem_hadar/setup.rb
|
|
@@ -270,6 +289,7 @@ files:
|
|
|
270
289
|
- lib/gem_hadar/template_compiler.rb
|
|
271
290
|
- lib/gem_hadar/utils.rb
|
|
272
291
|
- lib/gem_hadar/version.rb
|
|
292
|
+
- lib/gem_hadar/version_spec.rb
|
|
273
293
|
- lib/gem_hadar/warn.rb
|
|
274
294
|
- spec/gem_hadar_spec.rb
|
|
275
295
|
- spec/spec_helper.rb
|