From 5323b655c78f7dae54c62fd92540269208ab6393 Mon Sep 17 00:00:00 2001 From: Evgenii Tereshkov Date: Sat, 18 Jul 2026 15:32:28 +0700 Subject: [PATCH 1/2] fix: update ameba to commit 4057e0c5 for Crystal 1.21 compatibility Ameba v1.6.4 uses next_string_array_token which was removed in Crystal 1.21.0. The fix in ameba@4057e0c5 uses responds_to? to gracefully handle both old and new Crystal versions. --- shard.lock | 2 +- shard.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shard.lock b/shard.lock index ed593ab..868283a 100644 --- a/shard.lock +++ b/shard.lock @@ -2,4 +2,4 @@ version: 2.0 shards: ameba: git: https://github.com/crystal-ameba/ameba.git - version: 1.6.4+git.commit.a21dea0b44642f4fc87429283f8b0dd9f1e47a9f + version: 1.7.0-dev+git.commit.4057e0c5ed98587282587afb9cc44395c41de3f0 diff --git a/shard.yml b/shard.yml index 4971499..943bad2 100644 --- a/shard.yml +++ b/shard.yml @@ -18,4 +18,4 @@ executables: development_dependencies: ameba: github: crystal-ameba/ameba - tag: v1.6.4 + commit: 4057e0c5 From a2ccde3166d2be2ee27d6fd19e82e621358404e1 Mon Sep 17 00:00:00 2001 From: Evgenii Tereshkov Date: Sat, 18 Jul 2026 15:41:37 +0700 Subject: [PATCH 2/2] fix: apply ameba auto-fixes for new rules in v1.7.0-dev --- .ameba.yml | 15 +--- spec/main_spec.cr | 28 ++++---- spec/reqs-up_spec.cr | 160 +++++++++++++++++++++---------------------- src/reqs-up.cr | 28 ++++---- 4 files changed, 111 insertions(+), 120 deletions(-) diff --git a/.ameba.yml b/.ameba.yml index a22ff70..0bb40b5 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -1,15 +1,2 @@ -# This configuration file was generated by `ameba --gen-config` -# on 2025-02-22 11:49:05 UTC using Ameba version 1.5.0. -# The point is for the user to remove these configuration records -# one by one as the reported problems are removed from the code base. - -# Problems found: 1 -# Run `ameba --only Lint/NotNil` for details -Lint/NotNil: - Description: Identifies usage of `not_nil!` calls - Excluded: - - src/reqs-up.cr - Enabled: true - Severity: Warning -Documentation/DocumentationAdmonition: +Style/HeredocIndent: Enabled: false diff --git a/spec/main_spec.cr b/spec/main_spec.cr index 1ff77cc..466a929 100644 --- a/spec/main_spec.cr +++ b/spec/main_spec.cr @@ -24,12 +24,14 @@ describe "main.cr CLI" do describe "опция --dry-run" do it "выводит результат в stdout вместо записи в файл" do test_file = "spec/fixtures/requirements_dryrun.yml" - File.write(test_file, "--- -- name: test - src: https://github.com/evgkrsk/reqs-up.git - version: 1.0.0 - scm: git -") + yaml = <<-YAML + --- + - name: test + src: https://github.com/evgkrsk/reqs-up.git + version: 1.0.0 + scm: git + YAML + File.write(test_file, yaml) output = `crystal run src/main.cr -- --dry-run --file #{test_file} 2>&1` $?.success?.should be_true output.should contain("---") @@ -41,12 +43,14 @@ describe "main.cr CLI" do describe "опция --file" do it "использует указанный файл вместо requirements.yml" do test_file = "spec/fixtures/requirements_custom.yml" - File.write(test_file, "--- -- name: custom - src: https://github.com/evgkrsk/reqs-up.git - version: 1.0.0 - scm: git -") + yaml = <<-YAML + --- + - name: custom + src: https://github.com/evgkrsk/reqs-up.git + version: 1.0.0 + scm: git + YAML + File.write(test_file, yaml) output = `crystal run src/main.cr -- --dry-run --file #{test_file} 2>&1` $?.success?.should be_true output.should contain("custom") diff --git a/spec/reqs-up_spec.cr b/spec/reqs-up_spec.cr index c97d182..b90721c 100644 --- a/spec/reqs-up_spec.cr +++ b/spec/reqs-up_spec.cr @@ -309,11 +309,11 @@ describe ReqsUp do describe "парсинг полей из YAML" do it "извлекает src, name, version, scm" do yaml_str = <<-YAML - - name: test-role - src: https://github.com/evgkrsk/reqs-up.git - version: 1.2.3 - scm: git - YAML + - name: test-role + src: https://github.com/evgkrsk/reqs-up.git + version: 1.2.3 + scm: git + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) git_req.name.should eq("test-role") @@ -324,9 +324,9 @@ describe ReqsUp do it "корректно обрабатывает отсутствие name" do yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.0.0 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.0.0 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) git_req.name.should be_nil @@ -336,9 +336,9 @@ describe ReqsUp do describe "#versions" do it "возвращает пустой массив при отсутствии git" do yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.0.0 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.0.0 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) # Тест предполагает что git есть в системе, но для мокирования @@ -350,9 +350,9 @@ describe ReqsUp do describe "#update" do it "возвращает nil для не-semver версии" do yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: not-a-version - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: not-a-version + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) result = git_req.update @@ -361,8 +361,8 @@ describe ReqsUp do it "возвращает nil при отсутствии версии" do yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - YAML + - src: https://github.com/evgkrsk/reqs-up.git + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) result = git_req.update @@ -371,9 +371,9 @@ describe ReqsUp do it "возвращает текущую версию если нет новых версий" do yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.0.0 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.0.0 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) # Метод versions будет вызван, но так как мы не мокаем git, @@ -388,11 +388,11 @@ describe ReqsUp do describe "#to_s" do it "возвращает строковое представление объекта" do yaml_str = <<-YAML - - name: test-role - src: https://github.com/evgkrsk/reqs-up.git - version: 1.2.3 - scm: git - YAML + - name: test-role + src: https://github.com/evgkrsk/reqs-up.git + version: 1.2.3 + scm: git + YAML yaml = YAML.parse(yaml_str) req = ReqsUp::GitReq.new(yaml[0]) req.to_s.should contain("GitReq") @@ -408,20 +408,20 @@ describe ReqsUp do it "обновляет версию когда есть более новая" do git_script = "spec/fixtures/git" script_str = <<-SCRIPT - #!/bin/bash - echo "abc123 refs/tags/v0.9.0" - echo "def456 refs/tags/v1.0.0" - echo "ghi789 refs/tags/v1.1.0" - echo "jkl012 refs/tags/v1.2.0" - echo "mno345 refs/tags/v2.0.0" - SCRIPT + #!/bin/bash + echo "abc123 refs/tags/v0.9.0" + echo "def456 refs/tags/v1.0.0" + echo "ghi789 refs/tags/v1.1.0" + echo "jkl012 refs/tags/v1.2.0" + echo "mno345 refs/tags/v2.0.0" + SCRIPT File.write(git_script, script_str) File.chmod(git_script, 0o755) yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.0.0 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.0.0 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) @@ -441,9 +441,9 @@ describe ReqsUp do describe "обработка ошибок git" do it "возвращает пустой массив когда git не найден" do yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.0.0 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.0.0 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) @@ -464,20 +464,20 @@ describe ReqsUp do it "обновляет до максимальной minor версии" do git_script = "spec/fixtures/git" script_str = <<-SCRIPT - #!/bin/bash - echo "abc123 refs/tags/v1.0.0" - echo "def456 refs/tags/v1.5.0" - echo "ghi789 refs/tags/v1.9.0" - echo "jkl012 refs/tags/v2.0.0" - echo "mno345 refs/tags/v2.1.0" - SCRIPT + #!/bin/bash + echo "abc123 refs/tags/v1.0.0" + echo "def456 refs/tags/v1.5.0" + echo "ghi789 refs/tags/v1.9.0" + echo "jkl012 refs/tags/v2.0.0" + echo "mno345 refs/tags/v2.1.0" + SCRIPT File.write(git_script, script_str) File.chmod(git_script, 0o755) yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.2.3 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.2.3 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) @@ -496,17 +496,17 @@ describe ReqsUp do it "не обновляет если нет подходящих minor версий" do git_script = "spec/fixtures/git" script_str = <<-SCRIPT - #!/bin/bash - echo "abc123 refs/tags/v2.0.0" - echo "def456 refs/tags/v2.1.0" - SCRIPT + #!/bin/bash + echo "abc123 refs/tags/v2.0.0" + echo "def456 refs/tags/v2.1.0" + SCRIPT File.write(git_script, script_str) File.chmod(git_script, 0o755) yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.2.3 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.2.3 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) @@ -527,20 +527,20 @@ describe ReqsUp do it "обновляет до максимальной patch версии" do git_script = "spec/fixtures/git" script_str = <<-SCRIPT - #!/bin/bash - echo "abc123 refs/tags/v1.2.0" - echo "def456 refs/tags/v1.2.5" - echo "ghi789 refs/tags/v1.2.8" - echo "jkl012 refs/tags/v1.2.9" - echo "mno345 refs/tags/v1.3.0" - SCRIPT + #!/bin/bash + echo "abc123 refs/tags/v1.2.0" + echo "def456 refs/tags/v1.2.5" + echo "ghi789 refs/tags/v1.2.8" + echo "jkl012 refs/tags/v1.2.9" + echo "mno345 refs/tags/v1.3.0" + SCRIPT File.write(git_script, script_str) File.chmod(git_script, 0o755) yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.2.3 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.2.3 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) @@ -559,17 +559,17 @@ describe ReqsUp do it "не обновляет если нет подходящих patch версий" do git_script = "spec/fixtures/git" script_str = <<-SCRIPT - #!/bin/bash - echo "abc123 refs/tags/v1.3.0" - echo "def456 refs/tags/v1.4.0" - SCRIPT + #!/bin/bash + echo "abc123 refs/tags/v1.3.0" + echo "def456 refs/tags/v1.4.0" + SCRIPT File.write(git_script, script_str) File.chmod(git_script, 0o755) yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.2.3 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.2.3 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) @@ -590,19 +590,19 @@ describe ReqsUp do it "игнорирует pre-release версии" do git_script = "spec/fixtures/git" script_str = <<-SCRIPT - #!/bin/bash - echo "abc123 refs/tags/v1.0.0" - echo "def456 refs/tags/v1.0.0-alpha" - echo "ghi789 refs/tags/v1.0.0-beta.1" - echo "jkl012 refs/tags/v1.0.1" - SCRIPT + #!/bin/bash + echo "abc123 refs/tags/v1.0.0" + echo "def456 refs/tags/v1.0.0-alpha" + echo "ghi789 refs/tags/v1.0.0-beta.1" + echo "jkl012 refs/tags/v1.0.1" + SCRIPT File.write(git_script, script_str) File.chmod(git_script, 0o755) yaml_str = <<-YAML - - src: https://github.com/evgkrsk/reqs-up.git - version: 1.0.0 - YAML + - src: https://github.com/evgkrsk/reqs-up.git + version: 1.0.0 + YAML yaml = YAML.parse(yaml_str) git_req = ReqsUp::GitReq.new(yaml[0]) diff --git a/src/reqs-up.cr b/src/reqs-up.cr index 2ad3a9f..bc922b5 100755 --- a/src/reqs-up.cr +++ b/src/reqs-up.cr @@ -129,9 +129,9 @@ module ReqsUp abstract class Req include YAML::Serializable property src : String - property name : String | Nil - property version : String | Nil - getter scm : String | Nil + property name : String? + property version : String? + getter scm : String? Log = ::Log.for(self) # Initialize one requirements from YAML element @@ -161,7 +161,7 @@ module ReqsUp end # Update requirement version, returns final version and explanation - def update(ver : Versions = Versions::Latest) : String | Nil + def update(ver : Versions = Versions::Latest) : String? Log.debug { "Updating req #{self}" } current = parse_current_version return unless current @@ -180,16 +180,16 @@ module ReqsUp end end - private def parse_current_version : SemanticVersion | Nil + private def parse_current_version : SemanticVersion? ver = @version - return nil unless ver + return unless ver SemanticVersion.parse(ver) rescue ArgumentError Log.debug { "#{@version} is not semver, skipping" } nil end - private def handle_no_update(ver : Versions, current : SemanticVersion) : String | Nil + private def handle_no_update(ver : Versions, current : SemanticVersion) : String? case ver when Versions::Patch Log.warn { "no suitable versions found for '#{@name || @src}' within patch version (current: #{current})" } @@ -201,9 +201,9 @@ module ReqsUp nil end - private def select_version(tags : Array(String), current : SemanticVersion, ver : Versions) : Selection | Nil + private def select_version(tags : Array(String), current : SemanticVersion, ver : Versions) : Selection? stable_tags = parse_and_filter_tags(tags) - return nil if stable_tags.empty? + return if stable_tags.empty? case ver when Versions::Latest @@ -227,23 +227,23 @@ module ReqsUp end end - private def select_latest(stable_tags : Array(Selection), current : SemanticVersion) : Selection | Nil + private def select_latest(stable_tags : Array(Selection), current : SemanticVersion) : Selection? max = stable_tags.max_by(&.version) max if max.version > current end - private def select_within_major(stable_tags : Array(Selection), current : SemanticVersion) : Selection | Nil + private def select_within_major(stable_tags : Array(Selection), current : SemanticVersion) : Selection? candidates = stable_tags.select { |candidate| candidate.version.major == current.major } - return nil if candidates.empty? + return if candidates.empty? max = candidates.max_by(&.version) max if max.version > current end - private def select_within_major_minor(stable_tags : Array(Selection), current : SemanticVersion) : Selection | Nil + private def select_within_major_minor(stable_tags : Array(Selection), current : SemanticVersion) : Selection? candidates = stable_tags.select do |candidate| candidate.version.major == current.major && candidate.version.minor == current.minor end - return nil if candidates.empty? + return if candidates.empty? max = candidates.max_by(&.version) max if max.version > current end