gem_hadar 2.13.0 → 2.14.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/README.md +103 -12
- data/gem_hadar.gemspec +4 -4
- data/lib/gem_hadar/changelog_config.rb +52 -0
- data/lib/gem_hadar/changelog_generator.rb +13 -8
- data/lib/gem_hadar/editor.rb +85 -0
- data/lib/gem_hadar/template_compiler.rb +15 -3
- data/lib/gem_hadar/version.rb +1 -1
- data/lib/gem_hadar.rb +64 -55
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c1526fc633cc4869edfeebe3b9b80abc73737c70484fef234517076870b8a809
|
|
4
|
+
data.tar.gz: 5cc2ad8d79884970d57130c2f7bb43a9d9d681834ff7bec707effb74a03f73b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1fce02764c683dab0b0a96294d9050868f20edcdb0c5843aa91b500f2d09e9866c4f4c945bbacbee59eb8502a67092e578f3eb118f346b938ad1a0bbfa9c062a
|
|
7
|
+
data.tar.gz: 1398928830339c43d4005e53d2629cb7ed90ca46b34ee3e2dede5e06be41a54b215e14919de22d2772c7266ec7a3692223817a50acfb1b37b70902390b2bcc59
|
data/README.md
CHANGED
|
@@ -107,7 +107,6 @@ The following environment variables can be used to configure `gem_hadar`:
|
|
|
107
107
|
| `XDG_CONFIG_HOME` | XDG configuration directory override | System default |
|
|
108
108
|
| `MAKE` | Make program to use for building extensions | `gmake` or `make` |
|
|
109
109
|
| `VERSION` | Override the version string for some tasks | Not set |
|
|
110
|
-
| `FORCE` | Force certain operations (1 to enable) | 0 |
|
|
111
110
|
| `GIT_REMOTE` | Git remote name(s) for operations, space separated | `origin` |
|
|
112
111
|
| `GITHUB_RELEASE_ENABLED` | Enable GitHub releases (yes/no) | Auto-detected |
|
|
113
112
|
| `EDITOR` | Editor to use for interactive tasks | `vi` |
|
|
@@ -230,7 +229,7 @@ This task displays all current configuration values including:
|
|
|
230
229
|
- Repository information (gem name, version)
|
|
231
230
|
- Build parameters (MAKE, EDITOR)
|
|
232
231
|
- Git configuration (remote)
|
|
233
|
-
- Other flags (
|
|
232
|
+
- Other flags (VERSION, GITHUB_RELEASE_ENABLED)
|
|
234
233
|
- XDG/HOME directories
|
|
235
234
|
- AI prompt defaults
|
|
236
235
|
|
|
@@ -359,6 +358,17 @@ rvm do
|
|
|
359
358
|
end
|
|
360
359
|
```
|
|
361
360
|
|
|
361
|
+
#### GitHub Workflows Configuration
|
|
362
|
+
|
|
363
|
+
```ruby
|
|
364
|
+
github_workflows do
|
|
365
|
+
'ci.yml' => {
|
|
366
|
+
name: 'Continuous Integration',
|
|
367
|
+
ruby_versions: ['3.0', '3.1', '3.2']
|
|
368
|
+
}
|
|
369
|
+
end
|
|
370
|
+
```
|
|
371
|
+
|
|
362
372
|
#### Task Dependencies
|
|
363
373
|
|
|
364
374
|
- **`default_task_dependencies`** - Default: `[:gemspec, :test]`
|
|
@@ -418,7 +428,7 @@ based on your specific requirements. They are automatically derived from other
|
|
|
418
428
|
DSL accessors and provide powerful convenience features that enable `GemHadar`
|
|
419
429
|
to generate consistent, well-structured Ruby code automatically.
|
|
420
430
|
|
|
421
|
-
|
|
431
|
+
## Available Tasks
|
|
422
432
|
|
|
423
433
|
You can list all available tasks with:
|
|
424
434
|
|
|
@@ -426,12 +436,12 @@ You can list all available tasks with:
|
|
|
426
436
|
$ rake -T
|
|
427
437
|
```
|
|
428
438
|
|
|
429
|
-
|
|
439
|
+
### Core Tasks
|
|
430
440
|
|
|
431
441
|
- `rake build` - Build task (builds all packages for a release)
|
|
432
442
|
- `rake release` - Release the new version 1.2.3 for the gem foo
|
|
433
443
|
|
|
434
|
-
|
|
444
|
+
### Build Tasks
|
|
435
445
|
|
|
436
446
|
- `rake gemspec` - Create a gemspec file
|
|
437
447
|
- `rake package` - Build all the packages
|
|
@@ -440,7 +450,7 @@ $ rake -T
|
|
|
440
450
|
- `rake clobber_package` - Remove package products
|
|
441
451
|
- `rake repackage` - Force a rebuild of the package files
|
|
442
452
|
|
|
443
|
-
|
|
453
|
+
### Version Management
|
|
444
454
|
|
|
445
455
|
- `rake version` - Writing version information for foo
|
|
446
456
|
- `rake version:show` - Displaying the current version
|
|
@@ -454,7 +464,19 @@ $ rake -T
|
|
|
454
464
|
- `rake version:push` - Push version 1.2.3 to all git remotes: origin
|
|
455
465
|
- `rake version:origin:push` - Push version 1.2.3 to git remote origin
|
|
456
466
|
|
|
457
|
-
|
|
467
|
+
### Changelog Generation
|
|
468
|
+
|
|
469
|
+
- `rake changes:pending` - Show changes since last version tag
|
|
470
|
+
- `rake changes:current` - Show changes between two latest version tags
|
|
471
|
+
- `rake changes:range` - Show changes for a specific Git range (e.g., v1.0.0..v1.2.0)
|
|
472
|
+
- `rake changes:full` - Generate complete changelog from first tag
|
|
473
|
+
- `rake changes:add` - Append to changelog file
|
|
474
|
+
- `rake changes:edit` - Edit changelog file
|
|
475
|
+
- `rake changes:added` - Check if current version was added to changelog
|
|
476
|
+
- `rake changes:commit` - Commit changes to changelog file
|
|
477
|
+
- `rake changes:update` - Add and commit changes to changelog file
|
|
478
|
+
|
|
479
|
+
### Documentation
|
|
458
480
|
|
|
459
481
|
- `rake doc` - Create yard documentation (including private)
|
|
460
482
|
- `rake yard_doc` - Generate YARD Documentation
|
|
@@ -465,7 +487,7 @@ $ rake -T
|
|
|
465
487
|
- `rake yard:view` - View the yard documentation
|
|
466
488
|
- `rake yard:list-undoc` - List all undocumented classes/modules/methods
|
|
467
489
|
|
|
468
|
-
|
|
490
|
+
### Testing & Development
|
|
469
491
|
|
|
470
492
|
- `rake run_specs` - Run RSpec code examples
|
|
471
493
|
- `rake clean` - Remove any temporary products
|
|
@@ -475,12 +497,12 @@ $ rake -T
|
|
|
475
497
|
- `rake default` - Default task
|
|
476
498
|
- `rake compile` - Compile project extensions (if configured)
|
|
477
499
|
|
|
478
|
-
|
|
500
|
+
### Publishing Tasks
|
|
479
501
|
- `rake push` - Push all changes for version 1.2.3 into the internets
|
|
480
502
|
- `rake github:release` - Create a new GitHub release for the current version
|
|
481
503
|
with AI-generated changelog
|
|
482
504
|
|
|
483
|
-
|
|
505
|
+
## Code Coverage with SimpleCov
|
|
484
506
|
|
|
485
507
|
To enable detailed code coverage reporting in your project using `GemHadar`,
|
|
486
508
|
follow these steps:
|
|
@@ -524,7 +546,7 @@ follow these steps:
|
|
|
524
546
|
> branch coverage statistics per file, making it ideal for integration with CI
|
|
525
547
|
> tools or custom dashboards.
|
|
526
548
|
|
|
527
|
-
|
|
549
|
+
## Update Gem Version
|
|
528
550
|
|
|
529
551
|
Use one of the following rake tasks to bump the version:
|
|
530
552
|
|
|
@@ -535,7 +557,7 @@ Use one of the following rake tasks to bump the version:
|
|
|
535
557
|
|
|
536
558
|
Or bump your [VERSION](./VERSION) file by hand.
|
|
537
559
|
|
|
538
|
-
|
|
560
|
+
## Release
|
|
539
561
|
|
|
540
562
|
```bash
|
|
541
563
|
$ rake build
|
|
@@ -556,6 +578,75 @@ The `rake release` command performs the final publishing steps: pushing the
|
|
|
556
578
|
master branch and version tag to all git remotes, pushing the gem package to
|
|
557
579
|
RubyGems.org, and creating a GitHub release with AI-generated changelog.
|
|
558
580
|
|
|
581
|
+
## Template System
|
|
582
|
+
|
|
583
|
+
GemHadar includes a template compilation system for generating project files:
|
|
584
|
+
|
|
585
|
+
```ruby
|
|
586
|
+
# In your Rakefile
|
|
587
|
+
template 'templates/Dockerfile.erb', 'Dockerfile' do |t|
|
|
588
|
+
t.version = version
|
|
589
|
+
t.name = name
|
|
590
|
+
end
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
This system uses ERB templates and provides a clean way to generate files
|
|
594
|
+
during your build process.
|
|
595
|
+
|
|
596
|
+
## GitHub Workflows
|
|
597
|
+
|
|
598
|
+
Configure automated workflows with ERB templates:
|
|
599
|
+
|
|
600
|
+
```ruby
|
|
601
|
+
GemHadar do
|
|
602
|
+
github_workflows do
|
|
603
|
+
'ci.yml' => {
|
|
604
|
+
name: 'Continuous Integration',
|
|
605
|
+
ruby_versions: ['3.0', '3.1', '3.2']
|
|
606
|
+
}
|
|
607
|
+
end
|
|
608
|
+
end
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
This creates workflow files in `.github/workflows/` using templates from the
|
|
612
|
+
gem's internal templates directory.
|
|
613
|
+
|
|
614
|
+
## Advanced Usage Patterns
|
|
615
|
+
|
|
616
|
+
### Custom Prompt Templates
|
|
617
|
+
|
|
618
|
+
Override AI behavior by creating custom prompt files in your XDG config:
|
|
619
|
+
|
|
620
|
+
```bash
|
|
621
|
+
# Create custom prompt files
|
|
622
|
+
mkdir -p ~/.config/gem_hadar
|
|
623
|
+
cp /path/to/gem_hadar/lib/gem_hadar/default_changelog_prompt.txt ~/.config/gem_hadar/changelog_prompt.txt
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
### CI/CD Integration
|
|
627
|
+
|
|
628
|
+
Use the following workflow for automated releases:
|
|
629
|
+
|
|
630
|
+
```bash
|
|
631
|
+
# Build and test
|
|
632
|
+
$ rake build
|
|
633
|
+
$ rake test
|
|
634
|
+
|
|
635
|
+
# Bump version and create release
|
|
636
|
+
$ rake version:bump
|
|
637
|
+
$ rake build
|
|
638
|
+
$ rake release
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
### Troubleshooting
|
|
642
|
+
|
|
643
|
+
If you encounter issues with AI prompts:
|
|
644
|
+
|
|
645
|
+
1. Check that Ollama is running
|
|
646
|
+
2. Verify your model is pulled: `ollama list`
|
|
647
|
+
3. Check configuration with: `rake gem_hadar:config`
|
|
648
|
+
4. Review error messages in the console output
|
|
649
|
+
|
|
559
650
|
## Author
|
|
560
651
|
|
|
561
652
|
**GemHadar** was written by [Florian Frank](mailto:flori@ping.de).
|
data/gem_hadar.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: gem_hadar 2.
|
|
2
|
+
# stub: gem_hadar 2.14.0 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "gem_hadar".freeze
|
|
6
|
-
s.version = "2.
|
|
6
|
+
s.version = "2.14.0".freeze
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib".freeze]
|
|
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
s.description = "This library contains some useful functionality to support the development of Ruby Gems".freeze
|
|
13
13
|
s.email = "flori@ping.de".freeze
|
|
14
14
|
s.executables = ["gem_hadar".freeze]
|
|
15
|
-
s.extra_rdoc_files = ["README.md".freeze, "lib/gem_hadar.rb".freeze, "lib/gem_hadar/changelog_generator.rb".freeze, "lib/gem_hadar/github.rb".freeze, "lib/gem_hadar/ollama_support.rb".freeze, "lib/gem_hadar/prompt_template.rb".freeze, "lib/gem_hadar/rvm_config.rb".freeze, "lib/gem_hadar/setup.rb".freeze, "lib/gem_hadar/simplecov.rb".freeze, "lib/gem_hadar/template_compiler.rb".freeze, "lib/gem_hadar/utils.rb".freeze, "lib/gem_hadar/version.rb".freeze, "lib/gem_hadar/version_spec.rb".freeze, "lib/gem_hadar/warn.rb".freeze]
|
|
16
|
-
s.files = [".all_images.yml".freeze, ".github/workflows/static.yml".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/gem_hadar".freeze, "gem_hadar.gemspec".freeze, "lib/gem_hadar.rb".freeze, "lib/gem_hadar/changelog_generator.rb".freeze, "lib/gem_hadar/github.rb".freeze, "lib/gem_hadar/github_workflows/static.yml.erb".freeze, "lib/gem_hadar/ollama_support.rb".freeze, "lib/gem_hadar/prompt_template.rb".freeze, "lib/gem_hadar/rvm_config.rb".freeze, "lib/gem_hadar/setup.rb".freeze, "lib/gem_hadar/simplecov.rb".freeze, "lib/gem_hadar/template_compiler.rb".freeze, "lib/gem_hadar/utils.rb".freeze, "lib/gem_hadar/version.rb".freeze, "lib/gem_hadar/version_spec.rb".freeze, "lib/gem_hadar/warn.rb".freeze, "spec/gem_hadar_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
|
15
|
+
s.extra_rdoc_files = ["README.md".freeze, "lib/gem_hadar.rb".freeze, "lib/gem_hadar/changelog_config.rb".freeze, "lib/gem_hadar/changelog_generator.rb".freeze, "lib/gem_hadar/editor.rb".freeze, "lib/gem_hadar/github.rb".freeze, "lib/gem_hadar/ollama_support.rb".freeze, "lib/gem_hadar/prompt_template.rb".freeze, "lib/gem_hadar/rvm_config.rb".freeze, "lib/gem_hadar/setup.rb".freeze, "lib/gem_hadar/simplecov.rb".freeze, "lib/gem_hadar/template_compiler.rb".freeze, "lib/gem_hadar/utils.rb".freeze, "lib/gem_hadar/version.rb".freeze, "lib/gem_hadar/version_spec.rb".freeze, "lib/gem_hadar/warn.rb".freeze]
|
|
16
|
+
s.files = [".all_images.yml".freeze, ".github/workflows/static.yml".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/gem_hadar".freeze, "gem_hadar.gemspec".freeze, "lib/gem_hadar.rb".freeze, "lib/gem_hadar/changelog_config.rb".freeze, "lib/gem_hadar/changelog_generator.rb".freeze, "lib/gem_hadar/editor.rb".freeze, "lib/gem_hadar/github.rb".freeze, "lib/gem_hadar/github_workflows/static.yml.erb".freeze, "lib/gem_hadar/ollama_support.rb".freeze, "lib/gem_hadar/prompt_template.rb".freeze, "lib/gem_hadar/rvm_config.rb".freeze, "lib/gem_hadar/setup.rb".freeze, "lib/gem_hadar/simplecov.rb".freeze, "lib/gem_hadar/template_compiler.rb".freeze, "lib/gem_hadar/utils.rb".freeze, "lib/gem_hadar/version.rb".freeze, "lib/gem_hadar/version_spec.rb".freeze, "lib/gem_hadar/warn.rb".freeze, "spec/gem_hadar_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
|
17
17
|
s.homepage = "https://github.com/flori/gem_hadar".freeze
|
|
18
18
|
s.licenses = ["MIT".freeze]
|
|
19
19
|
s.rdoc_options = ["--title".freeze, "GemHadar - Library for the development of Ruby Gems".freeze, "--main".freeze, "README.md".freeze]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# A class that encapsulates changelog configuration settings for a gem project.
|
|
2
|
+
#
|
|
3
|
+
# This class provides a structured way to define and manage settings related to
|
|
4
|
+
# changelog generation within the GemHadar framework. It allows configuration
|
|
5
|
+
# of the changelog filename and the commit message used when adding entries.
|
|
6
|
+
#
|
|
7
|
+
# @example Configuring changelog settings
|
|
8
|
+
# GemHadar do
|
|
9
|
+
# changelog do
|
|
10
|
+
# filename 'CHANGELOG.md'
|
|
11
|
+
# commit_message 'Update changelog'
|
|
12
|
+
# end
|
|
13
|
+
# end
|
|
14
|
+
class GemHadar::ChangelogConfig
|
|
15
|
+
extend DSLKit::DSLAccessor
|
|
16
|
+
|
|
17
|
+
# This method creates a new instance of the ChangelogConfig class and then
|
|
18
|
+
# evaluates the provided block in the context of the new instance to
|
|
19
|
+
# configure the changelog settings.
|
|
20
|
+
#
|
|
21
|
+
# @param block [Proc] the block to be evaluated for configuring the changelog
|
|
22
|
+
# settings
|
|
23
|
+
#
|
|
24
|
+
# @return [GemHadar::ChangelogConfig] the initialized ChangelogConfig
|
|
25
|
+
# instance
|
|
26
|
+
def initialize(&block)
|
|
27
|
+
instance_eval(&block)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The filename attribute accessor for configuring the changelog filename.
|
|
31
|
+
#
|
|
32
|
+
# This method sets up a DSL accessor for the filename attribute, which specifies
|
|
33
|
+
# the name of the changelog file to be used when generating or modifying
|
|
34
|
+
# changelog entries. It provides a way to define the location of the changelog
|
|
35
|
+
# file that will be processed during various changelog operations within the
|
|
36
|
+
# gem project.
|
|
37
|
+
#
|
|
38
|
+
# @return [ String, nil ] the name of the changelog file or nil if not set
|
|
39
|
+
dsl_accessor :filename
|
|
40
|
+
|
|
41
|
+
# The commit_message method retrieves or sets the Git commit message used
|
|
42
|
+
# when adding changelog entries.
|
|
43
|
+
#
|
|
44
|
+
# This method serves as an accessor for the commit_message attribute within
|
|
45
|
+
# the ChangelogConfig class. When called without arguments, it returns the
|
|
46
|
+
# configured commit message, which defaults to 'Add to changes'. When called
|
|
47
|
+
# with an argument, it sets the commit message to be used for Git operations
|
|
48
|
+
# related to changelog management.
|
|
49
|
+
#
|
|
50
|
+
# @return [ String ] the default commit message 'Add to changes' when no custom message is set
|
|
51
|
+
dsl_accessor :commit_message, 'Add to changes'
|
|
52
|
+
end
|
|
@@ -146,10 +146,15 @@ class GemHadar
|
|
|
146
146
|
# changelog file, retrieves all subsequent version tags from the Git
|
|
147
147
|
# repository, and generates changelog entries for each consecutive pair of
|
|
148
148
|
# versions. It then inserts these entries into the file after the existing
|
|
149
|
-
# content, maintaining the
|
|
149
|
+
# content, maintaining the
|
|
150
|
+
# chronological order of changes.
|
|
150
151
|
#
|
|
151
|
-
# @param filename [ String ] the path to the changelog file to which
|
|
152
|
-
#
|
|
152
|
+
# @param filename [ String ] the path to the changelog file to which entries will be added
|
|
153
|
+
#
|
|
154
|
+
# @return [ Integer ] the count of changelog entries inserted into the file
|
|
155
|
+
# @return [ nil ] if no entries were added or if the file was empty
|
|
156
|
+
#
|
|
157
|
+
# @raise [ ArgumentError ] if the changelog file does not exist or if no highest version is found
|
|
153
158
|
def add_to_file(filename)
|
|
154
159
|
highest_version = find_highest_version(filename)
|
|
155
160
|
|
|
@@ -269,6 +274,7 @@ class GemHadar
|
|
|
269
274
|
changelog << generate(range_from, range_to)
|
|
270
275
|
+infobar
|
|
271
276
|
end
|
|
277
|
+
infobar.newline
|
|
272
278
|
changelog.reverse
|
|
273
279
|
end
|
|
274
280
|
|
|
@@ -280,12 +286,10 @@ class GemHadar
|
|
|
280
286
|
# the provided changelog entries immediately after the header
|
|
281
287
|
# and before the next empty line.
|
|
282
288
|
#
|
|
283
|
-
# @param filename [ String ] the path to the file into which changelog
|
|
284
|
-
#
|
|
285
|
-
# @param changelog [ Array<String> ] an array of changelog entry strings to
|
|
286
|
-
# be inserted into the file
|
|
289
|
+
# @param filename [ String ] the path to the file into which changelog entries will be injected
|
|
290
|
+
# @param changelog [ Array<String> ] an array of changelog entry strings to be inserted into the file
|
|
287
291
|
#
|
|
288
|
-
# @
|
|
292
|
+
# @return [ Integer ] the count of changelog entries inserted into the file
|
|
289
293
|
def inject_into_filename(filename, changelog)
|
|
290
294
|
File.open(filename) do |input|
|
|
291
295
|
File.secure_write(filename) do |output|
|
|
@@ -308,6 +312,7 @@ class GemHadar
|
|
|
308
312
|
end
|
|
309
313
|
end
|
|
310
314
|
end
|
|
315
|
+
changelog.size
|
|
311
316
|
end
|
|
312
317
|
|
|
313
318
|
# The find_highest_version method extracts version specifications from
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# A module that provides editor integration functionality for GemHadar.
|
|
2
|
+
#
|
|
3
|
+
# This module contains methods for determining the appropriate editor to use
|
|
4
|
+
# for interactive tasks, opening temporary files in editors for user modification,
|
|
5
|
+
# and editing specified files in an editor. It serves as a utility for
|
|
6
|
+
# automating text editing operations within the GemHadar framework.
|
|
7
|
+
#
|
|
8
|
+
# @example Finding and using an editor
|
|
9
|
+
# editor = GemHadar::Editor.find_editor
|
|
10
|
+
#
|
|
11
|
+
# @example Editing a temporary file returning the changed content
|
|
12
|
+
# content = "Initial content"
|
|
13
|
+
# edited_content = GemHadar::Editor.edit_temp_file(content)
|
|
14
|
+
#
|
|
15
|
+
# @example Editing a specific file
|
|
16
|
+
# GemHadar::Editor.edit_file('CHANGELOG.md')
|
|
17
|
+
module GemHadar::Editor
|
|
18
|
+
# The find_editor method determines the appropriate editor to use for
|
|
19
|
+
# interactive tasks.
|
|
20
|
+
#
|
|
21
|
+
# This method first checks the EDITOR environment variable for a custom
|
|
22
|
+
# editor specification. If the environment variable is not set, it falls back
|
|
23
|
+
# to using the vi editor by default. It then verifies that the identified
|
|
24
|
+
# editor exists in the file system before returning it.
|
|
25
|
+
#
|
|
26
|
+
# @return [ String, nil ] the path to the editor command if found, or nil if
|
|
27
|
+
# the editor cannot be located
|
|
28
|
+
# @return [ nil ] if the editor cannot be found in the file system
|
|
29
|
+
def find_editor
|
|
30
|
+
editor = ENV.fetch('EDITOR', `which vi`.chomp)
|
|
31
|
+
unless File.exist?(editor)
|
|
32
|
+
warn "Can't find EDITOR. => Returning."
|
|
33
|
+
return
|
|
34
|
+
end
|
|
35
|
+
editor
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The edit_temp_file method opens a temporary file in an editor for user
|
|
39
|
+
# modification.
|
|
40
|
+
#
|
|
41
|
+
# This method creates a temporary markdown file with the provided content,
|
|
42
|
+
# opens it in the configured editor, waits for the user to finish editing,
|
|
43
|
+
# and then reads the modified content back from the file.
|
|
44
|
+
#
|
|
45
|
+
# @param content [ String ] the initial content to write to the temporary file
|
|
46
|
+
#
|
|
47
|
+
# @return [ String ] the content of the file after editing, or nil if the editor
|
|
48
|
+
# could not be invoked or the file could not be read
|
|
49
|
+
# @return [ nil ] if the editor could not be found or the operation was aborted
|
|
50
|
+
def edit_temp_file(content)
|
|
51
|
+
temp_file = Tempfile.new(%w[ changelog .md ])
|
|
52
|
+
temp_file.write(content)
|
|
53
|
+
temp_file.close
|
|
54
|
+
|
|
55
|
+
edit_file(temp_file.path) or return
|
|
56
|
+
|
|
57
|
+
File.read(temp_file.path)
|
|
58
|
+
ensure
|
|
59
|
+
temp_file&.close&.unlink
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# The edit_file method opens a specified file in an editor for user
|
|
63
|
+
# modification.
|
|
64
|
+
#
|
|
65
|
+
# This method retrieves the configured editor using find_editor, then invokes
|
|
66
|
+
# the editor command with the provided filename as an argument. It waits for
|
|
67
|
+
# the editor process to complete and returns true if successful, or false if
|
|
68
|
+
# the editor command fails.
|
|
69
|
+
#
|
|
70
|
+
# @param filename [ String ] the path to the file to be opened in the editor
|
|
71
|
+
#
|
|
72
|
+
# @return [ true ] if the editor command executes successfully
|
|
73
|
+
# @return [ false ] if the editor command fails or returns a non-zero exit status
|
|
74
|
+
# @return [ nil ] if the editor cannot be found or the operation is aborted
|
|
75
|
+
def edit_file(filename)
|
|
76
|
+
editor = find_editor or return
|
|
77
|
+
|
|
78
|
+
unless system("#{editor} #{filename}")
|
|
79
|
+
warn "#{editor} returned #{$?.exitstatus} => Returning."
|
|
80
|
+
return false
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
true
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -9,11 +9,23 @@ require 'erb'
|
|
|
9
9
|
# context, and writing the resulting content to specified destination files.
|
|
10
10
|
#
|
|
11
11
|
# @example Compiling a template file
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
12
|
+
# # Set up template compiler
|
|
13
|
+
# compiler = GemHadar::TemplateCompiler.new do
|
|
14
|
+
# name 'my_template'
|
|
15
|
+
# version '1.0.0'
|
|
15
16
|
# end
|
|
17
|
+
# # Template (template.erb): Contains ERB placeholders for name and version.
|
|
18
|
+
# # Name: <%= name %>
|
|
19
|
+
# # Version: <%= version %>
|
|
20
|
+
# # Description: This is a template for <%= name %> v<%= version %>
|
|
21
|
+
#
|
|
22
|
+
# # Compile the template.
|
|
16
23
|
# compiler.compile('template.erb', 'output.txt')
|
|
24
|
+
#
|
|
25
|
+
# # Result (output.txt): The rendered output with interpolated values.
|
|
26
|
+
# # Name: my_template
|
|
27
|
+
# # Version: 1.0.0
|
|
28
|
+
# # Description: This is a template for my_template v1.0.0
|
|
17
29
|
class GemHadar::TemplateCompiler
|
|
18
30
|
include Tins::BlockSelf
|
|
19
31
|
include Tins::MethodMissingDelegator::DelegatorModule
|
data/lib/gem_hadar/version.rb
CHANGED
data/lib/gem_hadar.rb
CHANGED
|
@@ -64,6 +64,8 @@ require 'gem_hadar/version_spec'
|
|
|
64
64
|
require 'gem_hadar/prompt_template'
|
|
65
65
|
require 'gem_hadar/changelog_generator'
|
|
66
66
|
require 'gem_hadar/rvm_config'
|
|
67
|
+
require 'gem_hadar/changelog_config'
|
|
68
|
+
require 'gem_hadar/editor'
|
|
67
69
|
|
|
68
70
|
class GemHadar
|
|
69
71
|
include Term::ANSIColor
|
|
@@ -71,6 +73,7 @@ class GemHadar
|
|
|
71
73
|
include GemHadar::PromptTemplate
|
|
72
74
|
include GemHadar::Warn
|
|
73
75
|
include GemHadar::OllamaSupport
|
|
76
|
+
include GemHadar::Editor
|
|
74
77
|
|
|
75
78
|
if defined?(::RbConfig)
|
|
76
79
|
include ::RbConfig
|
|
@@ -598,16 +601,27 @@ class GemHadar
|
|
|
598
601
|
@rvm
|
|
599
602
|
end
|
|
600
603
|
|
|
601
|
-
# The
|
|
602
|
-
#
|
|
604
|
+
# The changelog method configures or retrieves the changelog settings for the
|
|
605
|
+
# gem project.
|
|
603
606
|
#
|
|
604
|
-
# This method
|
|
605
|
-
#
|
|
606
|
-
#
|
|
607
|
-
#
|
|
607
|
+
# This method serves as an accessor for the changelog configuration, allowing
|
|
608
|
+
# the gem project to define settings related to changelog generation and
|
|
609
|
+
# management. When a block is provided, it initializes a new ChangelogConfig
|
|
610
|
+
# instance with the block's configuration. If no block is provided and no
|
|
611
|
+
# existing changelog configuration exists, it creates a new default
|
|
612
|
+
# ChangelogConfig instance.
|
|
608
613
|
#
|
|
609
|
-
# @
|
|
610
|
-
|
|
614
|
+
# @param block [ Proc ] optional block to configure the changelog settings
|
|
615
|
+
#
|
|
616
|
+
# @return [ GemHadar::ChangelogConfig ] the changelog configuration instance
|
|
617
|
+
def changelog(&block)
|
|
618
|
+
if block
|
|
619
|
+
@changelog = ChangelogConfig.new(&block)
|
|
620
|
+
elsif !@changelog
|
|
621
|
+
@changelog = ChangelogConfig.new {}
|
|
622
|
+
end
|
|
623
|
+
@changelog
|
|
624
|
+
end
|
|
611
625
|
|
|
612
626
|
# The default_task_dependencies method manages the list of dependencies for
|
|
613
627
|
# the default Rake task.
|
|
@@ -1635,7 +1649,6 @@ class GemHadar
|
|
|
1635
1649
|
puts "Git Remote(s): #{ENV['GIT_REMOTE'] || 'origin'}"
|
|
1636
1650
|
|
|
1637
1651
|
# Other
|
|
1638
|
-
puts "Force Operations: #{ENV['FORCE'] || '0'}"
|
|
1639
1652
|
puts "Version Override: #{ENV['VERSION'] || 'Not set'}"
|
|
1640
1653
|
puts "GitHub Release Enabled: #{ENV['GITHUB_RELEASE_ENABLED'] || 'Not set'}"
|
|
1641
1654
|
|
|
@@ -1727,18 +1740,47 @@ class GemHadar
|
|
|
1727
1740
|
|
|
1728
1741
|
desc 'Append new entries to existing changelog file'
|
|
1729
1742
|
task :add do
|
|
1730
|
-
filename = ARGV[1] ||
|
|
1731
|
-
filename or
|
|
1732
|
-
GemHadar::ChangelogGenerator.new(self).add_to_file(filename)
|
|
1743
|
+
filename = ARGV[1] || changelog.filename
|
|
1744
|
+
filename or next
|
|
1745
|
+
if count = GemHadar::ChangelogGenerator.new(self).add_to_file(filename)
|
|
1746
|
+
edit_file filename
|
|
1747
|
+
puts "#{count} changes were added to #{filename.inspect}."
|
|
1748
|
+
else
|
|
1749
|
+
puts "No new changes added to #{filename.inspect}."
|
|
1750
|
+
end
|
|
1751
|
+
end
|
|
1752
|
+
|
|
1753
|
+
desc 'Edit the existing changelog file'
|
|
1754
|
+
task :edit do
|
|
1755
|
+
filename = ARGV[1] || changelog.filename
|
|
1756
|
+
filename or raise 'Need changelog file to edit'
|
|
1757
|
+
edit_file filename
|
|
1733
1758
|
end
|
|
1734
1759
|
|
|
1735
1760
|
desc 'Check if current version was added to the changelog'
|
|
1736
1761
|
task :added do
|
|
1737
|
-
|
|
1762
|
+
changelog.filename or next
|
|
1738
1763
|
GemHadar::ChangelogGenerator.new(self).changelog_version_added?(version) and next
|
|
1739
1764
|
abort "Version #{GemHadar::VersionSpec[version].untag} has not been "\
|
|
1740
|
-
"documented in changelog #{
|
|
1765
|
+
"documented in changelog #{changelog.filename.inspect} file."
|
|
1766
|
+
end
|
|
1767
|
+
|
|
1768
|
+
desc 'Commit changes in changelog filename'
|
|
1769
|
+
task :commit do
|
|
1770
|
+
changelog.filename or next
|
|
1771
|
+
`git status --porcelain #{changelog.filename.inspect}`.empty? and next
|
|
1772
|
+
system "git add #{changelog.filename.inspect}"
|
|
1773
|
+
msg = changelog.commit_message || "n/a"
|
|
1774
|
+
system "git commit -m #{msg.inspect} #{changelog.filename.inspect}"
|
|
1775
|
+
if $?.success?
|
|
1776
|
+
puts "Successfully commited changes in changelog filename."
|
|
1777
|
+
else
|
|
1778
|
+
warn "Committing changes in changelog filename has failed!"
|
|
1779
|
+
end
|
|
1741
1780
|
end
|
|
1781
|
+
|
|
1782
|
+
desc 'Update changelog file if necessary'
|
|
1783
|
+
task :update => %i[ add commit ]
|
|
1742
1784
|
end
|
|
1743
1785
|
|
|
1744
1786
|
# Main changes task that shows help when called directly
|
|
@@ -1750,17 +1792,20 @@ class GemHadar
|
|
|
1750
1792
|
rake changes:current Show changes between two latest version tags
|
|
1751
1793
|
rake changes:range <range> Show changes for a specific Git range (e.g., v1.0.0..v1.2.0)
|
|
1752
1794
|
rake changes:full [file] Generate complete changelog from first tag
|
|
1753
|
-
rake changes:add
|
|
1795
|
+
rake changes:add [file] Append new entries to changelog file
|
|
1754
1796
|
rake changes:added Check if current version was added to changelog
|
|
1797
|
+
rake changes:edit [file] Edit changelog file
|
|
1798
|
+
rake changes:commit Commit changes in changelog if any
|
|
1799
|
+
rake changes:update Add and commit changes to changelog
|
|
1755
1800
|
|
|
1756
1801
|
Examples:
|
|
1757
|
-
rake changes:pending
|
|
1758
|
-
rake changes:current
|
|
1759
1802
|
rake changes:range v1.0.0..v1.2.0
|
|
1760
|
-
rake changes:full
|
|
1803
|
+
rake changes:full # or
|
|
1761
1804
|
rake changes:full CHANGES.md
|
|
1805
|
+
rake changes:add # or
|
|
1762
1806
|
rake changes:add CHANGES.md
|
|
1763
|
-
rake changes:
|
|
1807
|
+
rake changes:edit # or
|
|
1808
|
+
rake changes:edit CHANGES.md
|
|
1764
1809
|
EOT
|
|
1765
1810
|
end
|
|
1766
1811
|
end
|
|
@@ -1805,42 +1850,6 @@ class GemHadar
|
|
|
1805
1850
|
self
|
|
1806
1851
|
end
|
|
1807
1852
|
|
|
1808
|
-
# The edit_temp_file method creates a temporary file with the provided
|
|
1809
|
-
# content, opens it in an editor for user modification, and returns the
|
|
1810
|
-
# updated content.
|
|
1811
|
-
#
|
|
1812
|
-
# This method first determines the editor to use from the EDITOR environment
|
|
1813
|
-
# variable or defaults to vi. If the editor cannot be found, it issues a
|
|
1814
|
-
# warning and returns nil. It then creates a temporary file, writes the
|
|
1815
|
-
# initial content to it, and opens the file in the editor. After the user
|
|
1816
|
-
# saves and closes the editor, it reads the modified content from the
|
|
1817
|
-
# temporary file. The temporary file is automatically cleaned up after use.
|
|
1818
|
-
#
|
|
1819
|
-
# @param content [ String ] the initial content to write to the temporary
|
|
1820
|
-
# file
|
|
1821
|
-
#
|
|
1822
|
-
# @return [ String, nil ] the content of the temporary file after editing, or
|
|
1823
|
-
# nil if the editor could not be found or failed
|
|
1824
|
-
def edit_temp_file(content)
|
|
1825
|
-
editor = ENV.fetch('EDITOR', `which vi`.chomp)
|
|
1826
|
-
unless File.exist?(editor)
|
|
1827
|
-
warn "Can't find EDITOR. => Returning."
|
|
1828
|
-
return
|
|
1829
|
-
end
|
|
1830
|
-
temp_file = Tempfile.new(%w[ changelog .md ])
|
|
1831
|
-
temp_file.write(content)
|
|
1832
|
-
temp_file.close
|
|
1833
|
-
|
|
1834
|
-
unless system("#{editor} #{temp_file.path}")
|
|
1835
|
-
warn "#{editor} returned #{$?.exitstatus} => Returning."
|
|
1836
|
-
return
|
|
1837
|
-
end
|
|
1838
|
-
|
|
1839
|
-
File.read(temp_file.path)
|
|
1840
|
-
ensure
|
|
1841
|
-
temp_file&.close&.unlink
|
|
1842
|
-
end
|
|
1843
|
-
|
|
1844
1853
|
# The ollama_model_default method returns the default name of the Ollama AI
|
|
1845
1854
|
# model to be used for generating responses when no custom model is
|
|
1846
1855
|
# specified.
|
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.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
@@ -256,7 +256,9 @@ extensions: []
|
|
|
256
256
|
extra_rdoc_files:
|
|
257
257
|
- README.md
|
|
258
258
|
- lib/gem_hadar.rb
|
|
259
|
+
- lib/gem_hadar/changelog_config.rb
|
|
259
260
|
- lib/gem_hadar/changelog_generator.rb
|
|
261
|
+
- lib/gem_hadar/editor.rb
|
|
260
262
|
- lib/gem_hadar/github.rb
|
|
261
263
|
- lib/gem_hadar/ollama_support.rb
|
|
262
264
|
- lib/gem_hadar/prompt_template.rb
|
|
@@ -278,7 +280,9 @@ files:
|
|
|
278
280
|
- bin/gem_hadar
|
|
279
281
|
- gem_hadar.gemspec
|
|
280
282
|
- lib/gem_hadar.rb
|
|
283
|
+
- lib/gem_hadar/changelog_config.rb
|
|
281
284
|
- lib/gem_hadar/changelog_generator.rb
|
|
285
|
+
- lib/gem_hadar/editor.rb
|
|
282
286
|
- lib/gem_hadar/github.rb
|
|
283
287
|
- lib/gem_hadar/github_workflows/static.yml.erb
|
|
284
288
|
- lib/gem_hadar/ollama_support.rb
|