Module: Kettle::Jem
- Defined in:
- lib/kettle/jem.rb,
lib/kettle/jem/cli.rb,
lib/kettle/jem/version.rb,
lib/kettle/jem/tasks/install_task.rb,
lib/kettle/jem/tasks/prepare_task.rb,
lib/kettle/jem/tasks/template_task.rb,
lib/kettle/jem/license_txt_migrator.rb,
lib/kettle/jem/tasks/self_test_task.rb,
lib/kettle/jem/maintenance_changelog.rb,
sig/kettle/jem.rbs
Defined Under Namespace
Modules: CLI, MaintenanceChangelog, PluginLoader, ReadmePostProcessor, SelfTest, Tasks, TemplateChecksums, TemplateLock, TemplatingReport, Version Classes: ChecksumMode, DecisionEvaluation, DecisionPolicy, Error, FileWorkUnit, GemSpecReader, LicenseTxtMigrator, PluginContext, PluginHelpers, PluginOutput, PluginRegistrar, PluginRegistry, RubyGemsResolver, TransferChangelogFilterParser, TransferChangelogLineParser, WriteIntent
Constant Summary collapse
- PACKAGE_NAME =
"kettle-jem"- CONTENT_RECIPE_TRANSPORT_VERSION =
Ast::Merge::STRUCTURED_EDIT_TRANSPORT_VERSION
- TEMPLATE_SOURCE_APPLICATION_FINGERPRINT_VERSION =
1- APPRAISALS_TEMPLATE_POLICY_FINGERPRINT_VERSION =
2- GEMSPEC_TEMPLATE_POLICY_FINGERPRINT_VERSION =
2- SPEC_HELPER_TEMPLATE_POLICY_FINGERPRINT_VERSION =
1- VERSION_NAMESPACE_TEMPLATE_POLICY_FINGERPRINT_VERSION =
2- KETTLE_CONFIG_PATH =
".structuredmerge/kettle-jem.yml"- LEGACY_KETTLE_CONFIG_PATH =
".kettle-jem.yml"- KETTLE_LOCK_PATH =
".structuredmerge/kettle-jem.lock"- LEGACY_KETTLE_LOCK_PATH =
".kettle-jem.lock"- MANAGED_BLOCK_OPEN =
"# <<kettle-jem:generated>> do not edit below this line"- MANAGED_BLOCK_CLOSE =
"# <</kettle-jem:generated>>"- GEMSPEC_DEPENDENCY_MINIMUM_REQUIREMENTS =
{ "rspec-stubbed_env" => ">= 1.0.6" }.freeze
- DEFAULT_GEMSPEC_METADATA_VALUES =
{ "allowed_push_host" => "TODO: Set to your gem server 'https://example.com'" }.freeze
- OBSOLETE_GITHUB_WORKFLOWS =
%w[ ancient.yml legacy.yml supported.yml unsupported.yml main.yml deps_locked.yml deps_unlocked.yml hoary.yml codeql-analysis.yml tests.yml ].freeze
- OPENCOLLECTIVE_DISABLED_FILES =
%w[.opencollective.yml .github/workflows/opencollective.yml].freeze
- OPT_IN_GITHUB_WORKFLOWS =
%w[.github/workflows/discord-notifier.yml].freeze
- OBSOLETE_APPRAISAL_SPEC_EXEC_CMDS =
[ "env KETTLE_TEST_RUNNER=rspec kettle-test -I ../spec --options ../.rspec ../spec", "KETTLE_TEST_RUNNER=rspec kettle-test -I ../spec --options ../.rspec ../spec", "kettle-test -I ../spec --options ../.rspec ../spec" ].freeze
- DEFAULT_ENGINES =
%w[ruby jruby truffleruby].freeze
- DEFAULT_OPENCOLLECTIVE_ORG =
"galtzo-floss"- RETIRED_GEMSPEC_DEVELOPMENT_DEPENDENCIES =
%w[kettle-drift kettle-soup-cover rubocop-rspec yard-junk].freeze
- FILE_DELETION_PRIMITIVES =
%w[ supplied_obsolete_file_deletion supplied_opt_in_workflow_deletion supplied_inactive_packaged_workflow_deletion supplied_inactive_packaged_template_deletion supplied_disabled_opencollective_file_deletion supplied_legacy_destination_file_deletion supplied_obsolete_license_file_deletion supplied_shim_profile_file_deletion ].freeze
- PHASE_ORDER =
%i[ config_sync dev_container github_workflows quality_config modular_gemfiles spec_helper environment_templates remaining_files git_hooks license_files duplicate_check ].freeze
- PACKAGED_TEMPLATE_ROOT =
File.("jem/templates", __dir__)
- TRANSFER_CHANGELOG_TEMPLATE_PATH =
"CHANGELOG.transfer.md"- TRANSFER_CHANGELOG_FILTER_FIELD_TYPES =
{ "profile" => :enum, "topology" => :enum, "ruby.min" => :version, "engine.jruby" => :boolean, "engine.truffleruby" => :boolean, "engine.alternates" => :boolean, "feature.appraisals" => :boolean, "feature.rubyforum" => :boolean, "feature.rubyforum_project_tag" => :boolean, "feature.corporate_sponsors" => :boolean, "feature.organization_logo" => :boolean, "feature.structuredmerge_driver" => :boolean, "feature.dedicated_version_gem" => :boolean, "workflow.dep_heads" => :boolean, "workflow.jruby_94" => :boolean, "version_gem.mode" => :enum }.freeze
- COPY_ONLY_WHEN_MISSING_TEMPLATE_PATHS =
%w[REEK bin/setup].freeze
- MONOREPO_ROOT_TEMPLATE_PROFILE =
"monorepo-root"- MONOREPO_SUBGEM_PACKAGE_TEMPLATE_PROFILE =
"monorepo-subgem-package"- MONOREPO_SUBGEM_RELEASE_TEMPLATE_PROFILE =
"monorepo-subgem-release"- MONOREPO_SUBGEM_FULL_TEMPLATE_PROFILE =
"monorepo-subgem-full"- MONOREPO_SUBGEM_TEMPLATE_PROFILE =
MONOREPO_SUBGEM_PACKAGE_TEMPLATE_PROFILE- SHIM_TEMPLATE_PROFILE =
"shim"- FULL_TEMPLATE_PROFILE =
"full"- REPOSITORY_TOPOLOGY_STANDALONE =
"standalone"- REPOSITORY_TOPOLOGY_MONOREPO_SUBPROJECT =
"monorepo-subproject"- MONOREPO_ROOT_TEMPLATE_ENTRIES =
[ "CHANGELOG.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "FUNDING.md", "Gemfile", "IRP.md", "LICENSE.md", "AGPL-3.0-only.md", "PolyForm-Small-Business-1.0.0.md", "RUBOCOP.md", "Rakefile", "SECURITY.md", ".github/FUNDING.yml", ".gitignore", ".structuredmerge/git-drivers.toml" ].freeze
- MONOREPO_SUBGEM_TEMPLATE_ENTRIES =
[ "README.md", "Rakefile", "LICENSE.md", "MIT.md", "AGPL-3.0-only.md", "PolyForm-Noncommercial-1.0.0.md", "PolyForm-Small-Business-1.0.0.md", "Big-Time-Public-License.md", "mise.toml", "Gemfile", "certs/pboling.pem", "tmp/.gitignore" ].freeze
- PACKAGED_MODULAR_GEMFILE_TEMPLATE_ENTRIES =
Dir.glob(File.join(PACKAGED_TEMPLATE_ROOT, "gemfiles", "modular", "**", "*.example")) .map { |path| path.delete_prefix("#{PACKAGED_TEMPLATE_ROOT}/").sub(/\.example\z/, "") } .reject { |path| path == "gemfiles/modular/shunted.gemfile" } .sort .freeze
- MONOREPO_SUBGEM_RELEASE_TEMPLATE_ENTRIES =
( MONOREPO_SUBGEM_TEMPLATE_ENTRIES + [ "Gemfile", "Rakefile", ".rspec", ".simplecov", ".yard-lint.yml", ".yardignore", ".yardopts", "bin/setup", "spec/README.md", "spec/spec_helper.rb" ] + PACKAGED_MODULAR_GEMFILE_TEMPLATE_ENTRIES ).freeze
- SIMPLECOV_BOOTSTRAP_TEMPLATE_PATHS =
%w[ .simplecov spec/spec_helper.rb ].freeze
- SHIM_TEMPLATE_STATIC_ENTRIES =
[ "README.md", "CHANGELOG.md", "Gemfile", "Rakefile", ".gitignore", ".rspec", "gemfiles/modular/templating.gemfile", "gemfiles/modular/templating_local.gemfile", "spec/spec_helper.rb", "spec/shim_spec.rb", ".github/workflows/current.yml", ".structuredmerge/kettle-jem.yml" ].freeze
- SHIM_TEMPLATE_SOURCE_TARGETS =
{ "README.md" => "shim/README.md", "CHANGELOG.md" => "shim/CHANGELOG.md", "Gemfile" => "shim/Gemfile", "Rakefile" => "shim/Rakefile", ".rspec" => "shim/.rspec", "spec/spec_helper.rb" => "shim/spec/spec_helper.rb", "spec/shim_spec.rb" => "shim/spec/shim_spec.rb", ".github/workflows/current.yml" => "shim/.github/workflows/current.yml", ".structuredmerge/kettle-jem.yml" => "shim/.structuredmerge/kettle-jem.yml" }.freeze
- SHIM_PROFILE_CLEANUP_GLOBS =
[ "Appraisal.root.gemfile", "Appraisals", "Guardfile", ".simplecov", ".yard-lint.yml", ".yardignore", ".yardopts", ".github/FUNDING.yml", ".gitattributes", "bin/*", "gemfiles/**/*.gemfile", "sig/**/*.rbs", "spec/**/*_spec.rb", "spec/support/**/*", ".github/workflows/*.yml", "lib/**/*.rb", "*.gemspec" ].freeze
- EXECUTABLE_GIT_HOOK_PATHS =
%w[ .git-hooks/commit-msg .git-hooks/prepare-commit-msg ].freeze
- VERSION_GEM_TEMPLATE_SOURCES =
[ "lib/gem/version.rb", "lib/gem/version_gem.rb", "sig/gem.rbs" ].freeze
- KETTLE_CONFIG_ENV_SYNC_PATHS =
Ractor.make_shareable({ %w[project_emoji] => "KJ_PROJECT_EMOJI", %w[repository topology] => "KJ_REPOSITORY_TOPOLOGY", %w[min_divergence_threshold] => "KJ_MIN_DIVERGENCE_THRESHOLD", %w[yard_host] => "KJ_YARD_HOST", %w[homepage_uri] => "KJ_HOMEPAGE_URI", %w[rubyforum family_tag] => "KJ_RUBYFORUM_FAMILY_TAG", %w[rubyforum project_tag] => "KJ_RUBYFORUM_PROJECT_TAG", %w[rubygems min_ruby] => "KJ_MIN_RUBY", %w[rubygems version_gem_entrypoint] => "KJ_VERSION_GEM_ENTRYPOINT", %w[templates profile] => "KETTLE_JEM_TEMPLATE_PROFILE", %w[shim replacement_gem] => "KETTLE_JEM_SHIMMED_GEM", %w[shim replacement_require] => "KETTLE_JEM_SHIMMED_REQUIRE", %w[workflows exec_cmd] => "KJ_EXEC_CMD", %w[tokens forge gh_user] => "KJ_GH_USER", %w[tokens forge gl_user] => "KJ_GL_USER", %w[tokens forge cb_user] => "KJ_CB_USER", %w[tokens forge sh_user] => "KJ_SH_USER", %w[tokens author name] => "KJ_AUTHOR_NAME", %w[tokens author given_names] => "KJ_AUTHOR_GIVEN_NAMES", %w[tokens author family_names] => "KJ_AUTHOR_FAMILY_NAMES", %w[tokens author email] => "KJ_AUTHOR_EMAIL", %w[tokens author domain] => "KJ_AUTHOR_DOMAIN", %w[tokens author orcid] => "KJ_AUTHOR_ORCID", %w[tokens funding kofi] => "KJ_FUNDING_KOFI", %w[tokens funding open_collective] => %w[OPENCOLLECTIVE_HANDLE FUNDING_ORG], %w[tokens funding paypal] => "KJ_FUNDING_PAYPAL", %w[tokens funding buymeacoffee] => "KJ_FUNDING_BUYMEACOFFEE", %w[tokens funding liberapay] => "KJ_FUNDING_LIBERAPAY", %w[tokens social mastodon] => "KJ_SOCIAL_MASTODON", %w[tokens social bluesky] => "KJ_SOCIAL_BLUESKY", %w[tokens social linktree] => "KJ_SOCIAL_LINKTREE", %w[tokens social devto] => "KJ_SOCIAL_DEVTO" })
- KETTLE_CONFIG_INTERNAL_SYNC_PATHS =
Ractor.make_shareable({ %w[kettle-jem version] => :version })
- NON_LICENSE_MD_BASENAMES =
%w[ AGENTS CHANGELOG CODE_OF_CONDUCT CONTRIBUTING FUNDING IRP LICENSE README RUBOCOP SECURITY ].freeze
- KNOWN_LICENSE_TEMPLATE_BASENAMES =
Dir.glob(File.join(PACKAGED_TEMPLATE_ROOT, "*.md.example")) .map { |path| File.basename(path, ".md.example") } .reject { |basename| NON_LICENSE_MD_BASENAMES.include?(basename) } .to_set .freeze
- MONOREPO_SUBGEM_README_BLOB_PATHS =
%w[ CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md IRP.md RUBOCOP.md SECURITY.md ].freeze
- README_DEV_TEST_STACK_GEMS =
Ractor.make_shareable([ { name: "appraisal2", repo: "https://github.com/appraisal-rb/appraisal2", role: "multi-dependency Appraisal matrix generation" }, { name: "appraisal2-rubocop", repo: "https://github.com/appraisal-rb/appraisal2-rubocop", role: "RuboCop Appraisal generator integration" }, { name: "kettle-dev", repo: "https://github.com/kettle-dev/kettle-dev", role: "development, release, and CI workflow tooling" }, { name: "kettle-jem", repo: "https://github.com/kettle-dev/kettle-jem", role: "Appraisals & CI workflow templates" }, { name: "kettle-soup-cover", repo: "https://github.com/kettle-dev/kettle-soup-cover", role: "SimpleCov coverage policy and reporting" }, { name: "kettle-test", repo: "https://github.com/kettle-dev/kettle-test", role: "standard test runner and coverage harness" }, { name: "rubocop-lts", repo: "https://github.com/rubocop-lts/rubocop-lts", role: "Ruby-version-aware linting" }, { name: "turbo_tests2", repo: "https://github.com/galtzo-floss/turbo_tests2", role: "parallel test execution" } ])
- MONOREPO_SUBGEM_THIN_README_KEEP_HEADINGS =
[ "synopsis", "info you can shake a stick at", "compatibility", "installation", "configuration", "basic usage", "security", "contributing", "versioning", "license" ].freeze
- LEGACY_DESTINATION_PATHS =
{ ".github/copilot_instructions.md" => ".github/COPILOT_INSTRUCTIONS.md" }.freeze
- SUPPORTED_TEMPLATE_STRATEGIES =
%i[merge accept_template keep_destination raw_copy].freeze
- SUPPORTED_TEMPLATE_FILE_TYPES =
%i[ruby gemfile appraisals gemspec rakefile yaml toml markdown json jsonc json5 dotenv rbs bash text].freeze
- SUPPORTED_RUBY_METHOD_MOVE_POLICIES =
%w[destination_order].freeze
- DEFAULT_RUBY_METHOD_MOVE_POLICY =
"destination_order"- SUPPORTED_YAML_COMMENT_MERGE_POLICIES =
%w[preserve_destination template_fallback_when_missing template_documentation].freeze
- DEFAULT_TEMPLATE_YAML_COMMENT_MERGE_POLICY =
"template_fallback_when_missing"- EVENT_TYPES =
%w[ run_start phase_start phase_finish recipe post_apply_step command_step diagnostic summary ].freeze
- DEFAULT_EVENT_TYPES =
EVENT_TYPES.freeze
- EVENT_TYPE_ALIASES =
{ "all" => EVENT_TYPES, "default" => DEFAULT_EVENT_TYPES, "progress" => %w[run_start phase_start phase_finish recipe post_apply_step command_step summary] }.freeze
- RECIPE_PLANNING_STRATEGIES =
%w[sequential classified].freeze
- DISABLED_RECIPE_PLANNING_STRATEGY_VALUES =
%w[0 false no off none sequential].freeze
- ENABLED_RECIPE_PLANNING_STRATEGY_VALUES =
%w[1 true yes on classified classify].freeze
- WORKER_SAFE_RECIPE_NAME_PATTERNS =
Ractor.make_shareable([ /\Agithub_actions_framework_gemfile_/, /\Agithub_actions_obsolete_workflow_cleanup_/, /\Agithub_actions_opt_in_workflow_cleanup_/, /\Agithub_actions_inactive_packaged_workflow_cleanup_/, /\Aopencollective_disabled_file_cleanup_/, /\Atemplate_legacy_destination_cleanup_/, /\Atemplate_obsolete_license_cleanup_/, /\Atemplate_shim_profile_cleanup_/ ])
- GITHUB_ACTIONS_FRAMEWORK_GEMFILE_RECIPE =
/\Agithub_actions_framework_gemfile_/- GITHUB_ACTIONS_OBSOLETE_WORKFLOW_CLEANUP_RECIPE =
/\Agithub_actions_obsolete_workflow_cleanup_/- GITHUB_ACTIONS_OPT_IN_WORKFLOW_CLEANUP_RECIPE =
/\Agithub_actions_opt_in_workflow_cleanup_/- OPENCOLLECTIVE_DISABLED_FILE_CLEANUP_RECIPE =
/\Aopencollective_disabled_file_cleanup_/- TEMPLATE_LEGACY_DESTINATION_CLEANUP_RECIPE =
/\Atemplate_legacy_destination_cleanup_/- TEMPLATE_OBSOLETE_LICENSE_CLEANUP_RECIPE =
/\Atemplate_obsolete_license_cleanup_/- TEMPLATE_SHIM_PROFILE_CLEANUP_RECIPE =
/\Atemplate_shim_profile_cleanup_/- GITHUB_ACTIONS_WORKFLOW_SNIPPETS_RECIPE =
/\Agithub_actions_workflow_snippets_/- TEMPLATE_SOURCE_PREFERENCE_RECIPE =
/\Atemplate_source_preference_/- TEMPLATE_SOURCE_APPLICATION_RECIPE =
/\Atemplate_source_application_/- DECISION_NO_WRITE_ACTIONS =
%w[keep skip].freeze
- RUBY_TEMPLATE_POLICY_FILE_TYPES =
%i[gemfile gemspec appraisals].freeze
- GEMFILE_POLICY_SELF_DEPENDENCIES =
%w[appraisal].freeze
- TEMPLATE_CONTENT_PRIMITIVES =
%w[ supplied_kettle_config_bootstrap supplied_template_source_preference supplied_template_source_application ].freeze
- PROJECT_ROOT_SENSITIVE_TEMPLATE_PATHS =
%w[ README.md mise.toml ].freeze
- RACTOR_SAFE_ACCEPT_TEMPLATE_FILE_TYPES =
%i[ rbs ruby ].freeze
- RAKEFILE_GUARDED_REQUIRE_NAMES =
%w[kettle/dev kettle/jem stone_checksums].freeze
- COVERAGE_THRESHOLD_KEYS =
%w[K_SOUP_COV_MIN_BRANCH K_SOUP_COV_MIN_LINE].freeze
- GITHUB_WORKFLOW_ENGINE_JOB_KEYS =
{ "jruby" => "jruby", "truffleruby" => "truffleruby" }.freeze
- CHANGELOG_TRANSFER_KEY_SEPARATOR =
/\s+-\s+/- CHANGELOG_TRANSFER_KEY_PATTERN =
/\Akettle-jem-template-\d{8}-\d{3}\z/- CHANGELOG_TRANSFER_KEY_SCAN_PATTERN =
/\bkettle-jem-template-\d{8}-\d{3}\b/- CHANGELOG_INITIAL_TEMPLATE_KEY =
"kettle-jem-template-initial"- CHANGELOG_INITIAL_TEMPLATE_ENTRY =
{ key: CHANGELOG_INITIAL_TEMPLATE_KEY, section: "### Added", lines: ["- #{CHANGELOG_INITIAL_TEMPLATE_KEY} - Initial templating by kettle-jem."] }.freeze
- README_KLOC_BADGE_PATTERN =
/(\[🧮kloc-img\]:\s*https?:\/\/img\.shields\.io\/badge\/KLOC-)(\d+(?:\.\d+)?)(-[^\s]*)/- CHANGELOG_COVERAGE_KLOC_PATTERN =
/-\s*COVERAGE:\s*.+--\s*\d+\/(\d+)\s+lines/i- RUBY_TEMPLATE_BASENAMES =
%w[Gemfile Rakefile Appraisals Appraisal.root.gemfile .simplecov].freeze
- RUBY_TEMPLATE_SUFFIXES =
%w[.gemspec .gemfile].freeze
- RUBY_TEMPLATE_EXTENSIONS =
%w[.rb .rake].freeze
- TEMPLATE_TOKEN_CONFIG =
Token::Resolver::Config.new(separators: ["|", ":"]).freeze
- EMPTY_TEMPLATE_TOKENS =
%w[ KJ|CB:USER KJ|COPYRIGHT_PREFIX KJ|AUTHOR:DOMAIN KJ|AUTHOR:NAME KJ|AUTHOR:ORCID KJ|FUNDING:BUYMEACOFFEE KJ|FUNDING:KOFI KJ|FUNDING:LIBERAPAY KJ|FUNDING:PAYPAL KJ|GEMSPEC:PACKAGE_FILE_INCLUDES KJ|GH:USER KJ|GH_ORG KJ|GL:USER KJ|LICENSE_EYE:FLAGS KJ|LICENSE_EYE:DEPENDENCY_LICENSES KJ|LICENSE_EYE:MODE KJ|LICENSE_EYE:PRIMARY_SPDX KJ|LOCAL_GEMFILE_NOMONO_BOOTSTRAP KJ|MAIN_GEMFILE_KETTLE_FAMILY_GEM KJ|MAIN_GEMFILE_DIRECT_SIBLING_BLOCK KJ|MAIN_GEMFILE_NOMONO_BOOTSTRAP KJ|MIN_DIVERGENCE_THRESHOLD KJ|MIN_RUBY KJ|KETTLE_CHANGELOG_GEMFILE_DEPENDENCY KJ|OPENCOLLECTIVE_ORG KJ|README:COPYRIGHT_NOTICE KJ|README:CORPORATE_SPONSORS KJ|README:FAMILY_INTRO_BACKEND_MATRIX KJ|README:LICENSE_BADGE KJ|README:LICENSE_COMPAT_BADGE KJ|README:LICENSE_EYE_WORKFLOW_BADGE KJ|README:DEV_TEST_STACK_TABLE KJ|README:FOSSA_BADGE KJ|README:FOSSA_REFS KJ|README:H2_SYNOPSIS_LOGO_ROW KJ|README:LICENSE_INTRO KJ|README:LICENSE_REFS KJ|README:TOP_LOGO_REFS KJ|README:TOP_LOGO_ROW KJ|RUBYFORUM:FAMILY_TAG KJ|RUBYFORUM:PROJECT_TAG KJ|RUBY_STYLE:TRAILING_ARRAY_COMMA KJ|SH:USER KJ|SHIMMED_GEM_NAME KJ|SHIMMED_REQUIRE KJ|SHIM_COMPAT_REQUIRES KJ|SHIMMED_GEMFILE_OVERRIDE KJ|SOCIAL:BLUESKY KJ|SOCIAL:DEVTO KJ|SOCIAL:LINKTREE KJ|SOCIAL:MASTODON ].freeze
- COPYRIGHT_NAME_RE =
/\ACopyright \(c\) [\d,\s-]+ (.+)\z/- BOT_IDENTITY_PATTERN =
/\[bot\]/i- DEFAULT_MACHINE_USERS =
["autobolt", "StepSecurity Bot", "dependabot[bot]", "depfu[bot]"].freeze
- NOT_COMMITTED_EMAIL =
"not.committed.yet"- LOGOS_GALTZO_BASE_URL =
"https://logos.galtzo.com/assets/images"- README_TOP_LOGO_DEFAULTS =
%w[org project].freeze
- README_H2_SYNOPSIS_LOGO_DEFAULTS =
%w[related_org ruby].freeze
- README_TOP_LOGO_OPTIONS =
%w[related_org ruby org project].freeze
- README_TOP_LOGO_LEGACY_MODE_MAP =
Ractor.make_shareable({ "org" => %w[related_org ruby org], "project" => %w[related_org ruby project], "org_and_project" => %w[related_org ruby org project] })
- KETTLE_CONFIG_LEGACY_KEY_PATHS =
Ractor.make_shareable([ { path: %w[readme top_logo_mode], replacement_path: %w[readme top_logos], added_in: "7.0.0", prune_after: "8.0.0" } ])
- README_TOP_LOGO_TYPES =
%w[related_org ruby language org project affiliated_project].freeze
- APPRAISAL_NAME_PREFIX =
"kja"- APPRAISAL_GEM_ABBREVIATIONS =
{ "activerecord" => "ar", "actionmailer" => "am", "actionpack" => "ap", "activesupport" => "as", "activejob" => "aj", "actioncable" => "ac", "actionview" => "av", "activestorage" => "ast", "actionmailbox" => "amb", "actiontext" => "at", "omniauth" => "oa", "mongoid" => "mo", "sequel" => "sq", "couch_potato" => "cp", "rom" => "rom", "rom-sql" => "rsql" }.freeze
- APPRAISAL_WORKFLOW_LIFECYCLE_RANGES =
Ractor.make_shareable({ "current" => {min: Gem::Version.new("3.4"), max: Gem::Version.new("3.99")}, "supported" => {min: Gem::Version.new("3.2"), max: Gem::Version.new("3.3")}, "legacy" => {min: Gem::Version.new("3.0"), max: Gem::Version.new("3.1")}, "unsupported" => {min: Gem::Version.new("2.6"), max: Gem::Version.new("2.7")}, "ancient" => {min: Gem::Version.new("2.3"), max: Gem::Version.new("2.5")} })
- APPRAISAL_ALWAYS_EXCLUDED_GEMS =
%w[version_gem].freeze
- APPRAISAL_VERSION_SELECTION_MODES =
%w[major minor patch minor-minmax semver].freeze
- DEFAULT_TEST_MINIMUM_RUBY =
Gem::Version.new("2.4")
- REQUIRE_RELATIVE_MIN_RUBY =
Gem::Version.new("2.2").freeze
- ANONYMOUS_VERSION_LOADER_MIN_RUBY =
Gem::Version.new("2.2").freeze
- MODERN_GEMSPEC_VERSION_LOADER_MIN_RUBY =
Gem::Version.new("3.1").freeze
- APPRAISAL_DEFAULT_FRESHNESS_TTL =
604_800- DECISION_ACTIONS =
%w[create merge replace keep delete skip].freeze
- DECISION_SEVERITIES =
%w[advisory warning fatal].freeze
- README_DEFAULT_PRESERVE_SECTIONS =
["synopsis", "configuration", "basic usage"].freeze
- README_DEFAULT_PRESERVE_PATTERNS =
["note:*"].freeze
- README_CODETRIAGE_BADGE =
"[![Open Source Helpers][👽oss-helpi]][👽oss-help]"- README_CODETRIAGE_LINK_LABELS =
["👽oss-help", "👽oss-helpi"].freeze
- README_LICENSE_EYE_WORKFLOW_BADGE =
"[![Apache SkyWalking Eyes License Compatibility Check][🚎15-🪪-wfi]][🚎15-🪪-wf]"- README_LICENSE_EYE_WORKFLOW_LINK_LABELS =
["🚎15-🪪-wf", "🚎15-🪪-wfi"].freeze
- README_FOSSA_BADGE =
"[![FOSSA Status][🧪fossa-img]][🧪fossa]"- README_FOSSA_LINK_LABELS =
["🧪fossa", "🧪fossa-img"].freeze
- LICENSE_EYE_COMPATIBILITY_LICENSES =
%w[MIT].freeze
- SKYWALKING_EYES_INTEGRATION =
"skywalking-eyes"- README_OPEN_COLLECTIVE_FUNDING_BADGES =
"[![OpenCollective Backers][🖇osc-backers-i]][🖇osc-backers] [![OpenCollective Sponsors][🖇osc-sponsors-i]][🖇osc-sponsors]"- README_OPEN_COLLECTIVE_LINK_LABELS =
[ "🖇osc", "🖇osc-all-bottom-img", "🖇osc-backers", "🖇osc-backers-i", "🖇osc-backers-img", "🖇osc-backers-bottom-img", "🖇osc-sponsors", "🖇osc-sponsors-i", "🖇osc-sponsors-img", "🖇osc-sponsors-bottom-img" ].freeze
- FUNDING_YML_PLATFORMS =
%w[ buy_me_a_coffee community_bridge github issuehunt ko_fi liberapay open_collective patreon polar thanks_dev tidelift ].freeze
- FUNDING_README_PLATFORMS =
(FUNDING_YML_PLATFORMS + ["paypal"]).freeze
- FUNDING_DEFAULT_DISABLED_PLATFORMS =
%w[issuehunt patreon polar].freeze
- README_FUNDING_BADGE_POLICIES =
{ "github" => { badges: [ "[![Sponsor Me on Github][🖇sponsor-img]][🖇sponsor]", "[![Sponsor me on GitHub Sponsors][🖇sponsor-bottom-img]][🖇sponsor]" ], labels: ["🖇sponsor", "🖇sponsor-img", "🖇sponsor-bottom-img"] }, "liberapay" => { badges: [ "[![Liberapay Goal Progress][⛳liberapay-img]][⛳liberapay]", "[![Sponsor me on Liberapay][⛳liberapay-bottom-img]][⛳liberapay]" ], labels: ["⛳liberapay", "⛳liberapay-img", "⛳liberapay-bottom-img"] }, "paypal" => { badges: [ "[![Donate on PayPal][🖇paypal-img]][🖇paypal]", "[![Donate on PayPal][🖇paypal-bottom-img]][🖇paypal]" ], labels: ["🖇paypal", "🖇paypal-img", "🖇paypal-bottom-img"] }, "buy_me_a_coffee" => { badges: [ "[![Buy me a coffee][🖇buyme-small-img]][🖇buyme]" ], labels: ["🖇buyme", "🖇buyme-small-img", "🖇buyme-img"] }, "ko_fi" => { badges: [ "[![Donate at ko-fi.com][🖇kofi-img]][🖇kofi]", "[![Donate to my FLOSS efforts at ko-fi.com][🖇kofi-img]][🖇kofi]" ], labels: ["🖇kofi", "🖇kofi-img"] }, "tidelift" => { badges: [ "[![Get help from me on Tidelift][🏙️entsup-tidelift-img]][🏙️entsup-tidelift]" ], labels: ["🏙️entsup-tidelift", "🏙️entsup-tidelift-img"] } }.freeze
- README_INTEGRATIONS =
%w[codecov coveralls qlty codeql skywalking-eyes].freeze
- README_STAR_HISTORY_MIN_STARS =
150- README_DISCOVERED_INTEGRATIONS =
(README_INTEGRATIONS - [SKYWALKING_EYES_INTEGRATION]).freeze
- COVERAGE_INTEGRATIONS =
%w[codecov coveralls qlty].freeze
- MANAGED_INTEGRATIONS =
(COVERAGE_INTEGRATIONS + [SKYWALKING_EYES_INTEGRATION]).freeze
- COVERAGE_INTEGRATION_CONFIG_PATHS =
Ractor.make_shareable({ "codecov" => %w[.github/.codecov.yml codecov.yml .codecov.yml], "coveralls" => %w[.coveralls.yml], "qlty" => %w[.qlty/qlty.toml .qlty.yml] })
- INTEGRATION_TEMPLATE_PATHS =
COVERAGE_INTEGRATION_CONFIG_PATHS.merge( SKYWALKING_EYES_INTEGRATION => %w[.licenserc.yaml .github/workflows/license-eye.yml .github/workflows/license-eye.yaml] ).freeze
- README_INTEGRATION_BADGE_PATTERNS =
Ractor.make_shareable({ "codecov" => [ /\s*\[!\[CodeCov Test Coverage\]\[[^\]]+\]\]\[[^\]]+\]/, /\n\[!\[Coverage Graph\]\[[^\]]+\]\]\[[^\]]+\]\n/ ], "coveralls" => [ /\s*\[!\[Coveralls Test Coverage\]\[[^\]]+\]\]\[[^\]]+\]/ ], "qlty" => [ /\s*\[!\[QLTY Test Coverage\]\[[^\]]+\]\]\[[^\]]+\]/, /\s*\[!\[QLTY Maintainability\]\[[^\]]+\]\]\[[^\]]+\]/ ], "codeql" => [ /\s*\[!\[CodeQL\]\[[^\]]+\]\]\[[^\]]+\]/ ], "skywalking-eyes" => [ /\s*\[!\[Apache SkyWalking Eyes License Compatibility Check\]\[[^\]]+\]\]\[[^\]]+\]/ ] })
- README_INTEGRATION_LINK_LABELS =
{ "codecov" => %w[🏀codecov 🏀codecovi 🏀codecov-g], "coveralls" => %w[🏀coveralls 🏀coveralls-img], "qlty" => %w[🏀qlty-mnt 🏀qlty-mnti 🏀qlty-cov 🏀qlty-covi], "codeql" => %w[🖐codeQL 🖐codeQL-img], "skywalking-eyes" => README_LICENSE_EYE_WORKFLOW_LINK_LABELS }.freeze
- README_SECTION_ALIASES =
{ "summary" => "synopsis", "usage" => "basic usage", "configuration options" => "configuration", "setup" => "basic usage" }.freeze
- VAR_HOME_PREFIX =
%r{\A/var/home(?=/|\z)}- VAR_HOME_TEXT =
%r{/var/home(?=/|\z)}- FORGE_USER_ENV_KEYS =
{ gh_user: "KJ_GH_USER", gl_user: "KJ_GL_USER", cb_user: "KJ_CB_USER", sh_user: "KJ_SH_USER" }.freeze
- FUNDING_TOKEN_ENV_KEYS =
{ kofi: "KJ_FUNDING_KOFI", paypal: "KJ_FUNDING_PAYPAL", buymeacoffee: "KJ_FUNDING_BUYMEACOFFEE", liberapay: "KJ_FUNDING_LIBERAPAY" }.freeze
- SOCIAL_TOKEN_ENV_KEYS =
{ mastodon: "KJ_SOCIAL_MASTODON", bluesky: "KJ_SOCIAL_BLUESKY", linktree: "KJ_SOCIAL_LINKTREE", devto: "KJ_SOCIAL_DEVTO" }.freeze
- APACHE_LICENSE_COMPAT_CATEGORIES =
{ "Apache-2.0" => :a, "MIT" => :a, "AGPL-3.0-only" => :x, "PolyForm-Noncommercial-1.0.0" => :x, "PolyForm-Small-Business-1.0.0" => :x, "LicenseRef-Big-Time-Public-License" => :x }.freeze
- APACHE_LICENSE_COMPAT_BADGE_DATA =
Ractor.make_shareable({ a: { alt: "Apache license compatibility: Category A", label: "Apache_Compatible:_Category_A", message: "\u2713", color: "259D6C", ref: "https://www.apache.org/legal/resolved.html#category-a" }, b: { alt: "Apache license compatibility: Category B", label: "Apache_Maybe_Compatible:_Category_B", message: "?", color: "D9A407", ref: "https://www.apache.org/legal/resolved.html#category-b" }, x: { alt: "Apache license compatibility: Category X", label: "Apache_Incompatible:_Category_X", message: "\u2717", color: "C0392B", ref: "https://www.apache.org/legal/resolved.html#category-x" }, unknown: { alt: "Apache license compatibility: Unknown", label: "Apache_Compatibility", message: "Unknown", color: "6C757D", ref: "https://www.apache.org/legal/resolved.html" } })
- CHANGELOG_STANDARD_HEADINGS =
[ "### Added", "### Changed", "### Deprecated", "### Removed", "### Fixed", "### Security" ].freeze
- MANAGED_APPRAISAL_STDLIB_GEMS =
The x_std_libs aggregate owns these extracted standard libraries. Keeping legacy gem declarations in an appraisal block that evaluates the aggregate makes Bundler reject the same gem with two requirement declarations.
%w[benchmark cgi erb mutex_m stringio webrick].freeze
- VERSION =
Current gem version exposed at the traditional constant location.
Version::VERSION
Class Method Summary collapse
- .active_license_basenames(config) ⇒ Object
- .actual_changed_files_after_apply(project_root, changed_files, before_apply_files) ⇒ Object
- .adapter_failure_template_source_error(file_type, recipe) ⇒ Object
- .add_dependency_conflict_review_list(content, conflicts) ⇒ Object
- .add_framework_matrix_job_env(content, keys) ⇒ Object
- .add_monorepo_root_file_overrides(content) ⇒ Object
- .add_monorepo_subgem_file_overrides(content, gemspec_path, profile = MONOREPO_SUBGEM_TEMPLATE_PROFILE) ⇒ Object
- .add_shim_bootstrap_config(content, shim) ⇒ Object
- .add_shim_file_overrides(content, gemspec_path) ⇒ Object
- .aliased_readme_destination_section(template_base, destination_lookup, preserve_config) ⇒ Object
- .append_gemfile_comment_block(lines, block) ⇒ Object
- .append_github_actions_coverage_steps(content, disabled_integrations: []) ⇒ Object
- .append_missing_gemspec_dependency_lines(content, destination_dependencies, receiver:) ⇒ Object
- .append_missing_markdown_link_definitions(content, definitions) ⇒ Object
- .append_used_markdown_link_definitions(content, definition_source) ⇒ Object
- .apply_changelog_transfer_entries(content, entries, excluded_keys: []) ⇒ Object
- .apply_checksum_skips(project_root, recipe_reports, checksum_mode:, template_lock:) ⇒ Object
- .apply_commented_gem_dependency_policy(template_content, content) ⇒ Object
- .apply_configured_gemspec_licenses(content, facts, receiver:) ⇒ Object
- .apply_configured_gemspec_metadata(content, facts, receiver:) ⇒ Object
- .apply_configured_gemspec_required_ruby_version(content, facts, receiver:) ⇒ Object
- .apply_github_actions_engine_exec_cmd_overrides(content, facts) ⇒ Object
- .apply_kettle_config_bootstrap(project_root, recipe, env: ENV, template_contents: nil) ⇒ Object
- .apply_kettle_config_bootstrap_profile(content, profile, gemspec_path) ⇒ Object
- .apply_markdown_conditional_block(content, name, keep:) ⇒ Object
- .apply_modular_dependency_conflict_resolutions(project_root, decisions) ⇒ Object
- .apply_monorepo_root_template_profile(content) ⇒ Object
- .apply_monorepo_subgem_readme_recipe(content, facts) ⇒ Object
- .apply_monorepo_subgem_template_profile(content, gemspec_path, profile = MONOREPO_SUBGEM_TEMPLATE_PROFILE) ⇒ Object
- .apply_monorepo_subgem_thin_readme_projection(content, facts) ⇒ Object
- .apply_project(project_root, env: ENV, run_options: {}) ⇒ Object
- .apply_readme_badge_policy(content, facts) ⇒ Object
- .apply_readme_conditional_blocks(content, facts) ⇒ Object
- .apply_readme_kloc_badge(content, facts, project_root, destination_content: nil) ⇒ Object
- .apply_readme_style(project_root, env: ENV) ⇒ Object
- .apply_recipe_report(project_root, recipe_report) ⇒ Object
- .apply_shim_template_profile(content, gemspec_path) ⇒ Object
- .apply_template_source(project_root, recipe, original, facts: nil, env: ENV, template_contents: nil) ⇒ Object
- .appraisal_all_versions_for(resolver:, gem_name:, mode:, requirements: nil, include_versions: nil, exclude_versions: nil) ⇒ Object
- .appraisal_assign_version_buckets(selected_versions:, seams:, buckets:, bucket_ranges:, all_versions:) ⇒ Object
- .appraisal_block_has_matrix_dependency_gemfile?(block, matrix_dependency_gemfiles) ⇒ Boolean
- .appraisal_blocks(content) ⇒ Object
- .appraisal_bucket_below(ruby_floor, buckets, bucket_ranges) ⇒ Object
- .appraisal_bucket_sort_key(bucket) ⇒ Object
- .appraisal_call_records(content) ⇒ Object
- .appraisal_compatible_version_for_bucket?(resolver:, gem_name:, version:, ruby_series:, bucket_ranges:) ⇒ Boolean
- .appraisal_eval_gemfile_path(path) ⇒ Object
- .appraisal_extract_runtime_dependencies(gemspec_content) ⇒ Object
- .appraisal_file_content(matrix_entries) ⇒ Object
- .appraisal_fill_bucket_gaps(assignments, buckets, bucket_ranges, version_min_rubies, all_versions) ⇒ Object
- .appraisal_filtered_versions(version_metadata, requirements:) ⇒ Object
- .appraisal_finalize_versions(base_versions, include_versions: nil, exclude_versions: nil) ⇒ Object
- .appraisal_find_ruby_seams(version_metadata) ⇒ Object
- .appraisal_format_version(version) ⇒ Object
- .appraisal_gem_abbreviation(gem_name) ⇒ Object
- .appraisal_latest_minor_patch(resolver:, gem_name:, version:) ⇒ Object
- .appraisal_latest_patch_by_minor(version_metadata) ⇒ Object
- .appraisal_latest_version_matching(version_metadata, requested_version) ⇒ Object
- .appraisal_matrix_entries(tier1_gems:, tier2_gems: []) ⇒ Object
- .appraisal_matrix_entry(tier1_name:, tier1_version:, ruby_series:, tier2_name: nil, tier2_version: nil) ⇒ Object
- .appraisal_matrix_fresh?(matrix, now: Time.now.to_i) ⇒ Boolean
- .appraisal_matrix_has_versions?(matrix) ⇒ Boolean
- .appraisal_minor_key(version) ⇒ Object
- .appraisal_minor_versions_by_major(versions) ⇒ Object
- .appraisal_minor_versions_to_buckets(minor_versions) ⇒ Object
- .appraisal_modular_gemfile_content(gem_name:, version:, sub_dependencies: {}) ⇒ Object
- .appraisal_modular_gemfile_path(gem_name:, version:, ruby_series:) ⇒ Object
- .appraisal_name(tier1_gem:, tier1_version:, ruby_series:, tier2_gem: nil, tier2_version: nil) ⇒ Object
- .appraisal_names(content) ⇒ Object
- .appraisal_next_seam_ruby(version, min_ruby, all_versions, version_min_rubies) ⇒ Object
- .appraisal_normalized_bucket_ranges(bucket_ranges) ⇒ Object
- .appraisal_recording_enabled?(config) ⇒ Boolean
- .appraisal_resolve_sub_dependencies(parent_gem:, parent_version:, parent_versions:, dependency_versions:, ruby_min: nil, excluded_gems: []) ⇒ Object
- .appraisal_ruby_series(version_metadata, project_min_ruby: nil) ⇒ Object
- .appraisal_ruby_version(value) ⇒ Object
- .appraisal_scaffold_config(gemspec_content:, existing_config: {}, exclusions: [], default_mode: "semver", freshness_ttl: APPRAISAL_DEFAULT_FRESHNESS_TTL) ⇒ Object
- .appraisal_select_dependency_version(version_metadata, requirement:, ruby_min:) ⇒ Object
- .appraisal_select_versions(version_metadata, mode:, requirements: nil) ⇒ Object
- .appraisal_sort_versions(values) ⇒ Object
- .appraisal_stale_gemfile_paths(existing_paths:, current_entries:) ⇒ Object
- .appraisal_time_ago(timestamp, now: Time.now.to_i) ⇒ Object
- .appraisal_version_min_ruby_map(all_versions, seams) ⇒ Object
- .appraisal_version_requirement(version) ⇒ Object
- .appraisal_workflow_groups(matrix_entries, bucket_ranges:, exec_cmd: "kettle-test") ⇒ Object
- .appraisal_workflow_lifecycle(ruby_floor) ⇒ Object
- .appraisal_workflow_ruby(ruby_floor, lifecycle) ⇒ Object
- .appraisal_workflow_yaml_snippets(matrix_entries, bucket_ranges:, exec_cmd: "kettle-test") ⇒ Object
- .appraisal_x_stdlib_eval_gemfile_call(block) ⇒ Object
- .appraisal_x_stdlib_exclusions(template_content) ⇒ Object
- .appraisals_policy_operations(template_content, original, final, request) ⇒ Object
- .assert_no_unresolved_template_tokens_in_yaml_values(content, label) ⇒ Object
- .author_aliases(config) ⇒ Object
- .author_facts(config, env, gemspec_metadata: {}, copyright: {}) ⇒ Object
- .author_family_names(name) ⇒ Object
- .author_given_names(name) ⇒ Object
- .author_names(gemspec_metadata, copyright, primary_name, author_aliases: {}) ⇒ Object
- .author_template_tokens(author) ⇒ Object
- .bash_merge_options(recipe) ⇒ Object
- .build_changelog_section(heading, preamble, items) ⇒ Object
- .build_changelog_unreleased_section(heading, items) ⇒ Object
- .canonical_author_name(value, aliases) ⇒ Object
- .canonical_author_name_for_entry(entry, aliases) ⇒ Object
- .canonical_changelog_release_heading(heading_text) ⇒ Object
- .changed_files_from_recipe_reports(recipe_reports) ⇒ Object
- .changelog_bullet_line?(line) ⇒ Boolean
- .changelog_coverage_kloc(section) ⇒ Object
- .changelog_existing_transfer_occurrences(content) ⇒ Object
- .changelog_heading_line?(line) ⇒ Boolean
- .changelog_release_section_for_item(release_sections, item) ⇒ Object
- .changelog_section_preamble(body_lines) ⇒ Object
- .changelog_template_header(lines, unreleased_index) ⇒ Object
- .changelog_transfer_applied_keys(project_root) ⇒ Object
- .changelog_transfer_entries(template_root) ⇒ Object
- .changelog_transfer_entries_after(entries, key) ⇒ Object
- .changelog_transfer_facts(project_root, entries) ⇒ Object
- .changelog_transfer_filter_parser ⇒ Object
- .changelog_transfer_key(line) ⇒ Object
- .changelog_transfer_key_date(key) ⇒ Object
- .changelog_transfer_keys(content) ⇒ Object
- .changelog_transfer_line_parser ⇒ Object
- .changelog_transfer_list_item_line(source, rendered_payload) ⇒ Object
- .changelog_transfer_list_item_payload(source) ⇒ Object
- .changelog_transfer_section_map ⇒ Object
- .changelog_unreleased_end_index(lines, unreleased_index) ⇒ Object
- .changelog_unreleased_heading?(heading_text) ⇒ Boolean
- .changelog_unreleased_heading_line?(line) ⇒ Boolean
- .changelog_unreleased_items(body_lines) ⇒ Object
- .changelog_unreleased_line_index(lines) ⇒ Object
- .changelog_unreleased_transfer_keys(project_root) ⇒ Object
- .changelog_version_heading_line?(line, version) ⇒ Boolean
- .checksum_cache_safe_report?(report) ⇒ Boolean
- .checksum_exact_match?(report) ⇒ Boolean
- .checksum_file_records(project_root, report, existing_state) ⇒ Object
- .checksum_match_details(project_root, report, checksum_mode:, template_lock:) ⇒ Object
- .checksum_mode_for(env, run_options) ⇒ Object
- .checksum_skip_report?(project_root, report, checksum_mode:, template_lock:) ⇒ Boolean
- .classify_namespace(name) ⇒ Object
- .cleanup_version_gem_entrypoint(project_root, entrypoint_path) ⇒ Object
- .cleanup_version_gem_version_spec(project_root, version_spec_path) ⇒ Object
- .codeberg_repo_url(repository, repo_slug, suffix) ⇒ Object
- .collapse_excess_blank_lines(content) ⇒ Object
- .collapse_nested_templating_guards(content) ⇒ Object
- .collect_changelog_list_item(lines, start_index) ⇒ Object
- .collect_yaml_mapping_path_entries(node, path, entries) ⇒ Object
- .collect_yaml_scalar_path_entries(node, path, entries) ⇒ Object
- .comment_only_lines?(lines) ⇒ Boolean
- .comment_or_blank_line?(line) ⇒ Boolean
- .commented_gem_call(comment_source) ⇒ Object
- .commented_gem_dependency_block_records(content) ⇒ Object
- .commented_gem_dependency_blocks(content) ⇒ Object
- .commented_gem_dependency_records(content) ⇒ Object
- .commit_file_outcome(file_outcome) ⇒ Object
- .commit_file_work_unit(file_work_unit) ⇒ Object
- .commit_file_work_unit_payload(payload) ⇒ Object
- .commit_file_work_units(file_work_units, workers: 0, thread_workers: 0, stats: nil) ⇒ Object
- .commit_file_work_units_ractor(file_work_units, workers:) ⇒ Object
- .commit_file_work_units_thread(file_work_units, workers:) ⇒ Object
- .commit_filesystem_outcome(file_outcome) ⇒ Object
- .commit_filesystem_outcome_payload(payload) ⇒ Object
- .commit_write_intent(write_intent) ⇒ Object
- .compact_hash(hash) ⇒ Object
- .compatible_dependency_requirements?(direct_requirements, modular_requirements) ⇒ Boolean
- .concrete_github_url(url) ⇒ Object
- .config_min_ruby(config) ⇒ Object
- .config_test_min_ruby(config, gem_min_ruby = nil) ⇒ Object
- .configured_disabled_integrations(config) ⇒ Object
- .configured_readme_top_logo_entries(config, org:, gem_name:, repository: {}) ⇒ Object
- .content_recipe_execution_report(request:, final_content:, changed:, step_reports:, diagnostics:, metadata: nil) ⇒ Object
- .content_recipe_execution_report_envelope(report) ⇒ Object
- .content_recipe_execution_request(recipe_name:, recipe_version:, relative_path:, provider_family:, template_content:, destination_content:, steps:, provider_backend: nil, runtime_context: nil, metadata: nil) ⇒ Object
- .content_recipe_execution_request_envelope(request) ⇒ Object
- .content_recipe_step(recipe) ⇒ Object
- .content_recipe_step_report(recipe:, request:, original:, final:, changed:, deletion: nil) ⇒ Object
- .copy_only_when_missing_template_path?(relative_path) ⇒ Boolean
- .copyright_author_names(copyright) ⇒ Object
- .copyright_bot_entry?(entry) ⇒ Boolean
- .copyright_facts(project_root, config) ⇒ Object
- .copyright_machine_user_entry?(entry, machine_users, author_aliases: {}) ⇒ Boolean
- .copyright_machine_users(config) ⇒ Object
- .copyright_name_from_line(line) ⇒ Object
- .copyright_notice_lines(copyright_lines, copyright_prefix, author) ⇒ Object
- .copyright_year_token?(token) ⇒ Boolean
- .coverage_thresholds_from_mise(content) ⇒ Object
- .coverage_thresholds_from_project_mise(project_root) ⇒ Object
- .coverage_thresholds_from_workflow(project_root) ⇒ Object
- .coverage_thresholds_from_yaml_workflow(content) ⇒ Object
- .current_changelog_version_section(content, version) ⇒ Object
- .decision_policy_for(env, run_options) ⇒ Object
- .decorative_grapheme?(grapheme) ⇒ Boolean
- .deduplicate_main_gemfile_direct_sibling_blocks(content) ⇒ Object
- .deduplicate_main_gemfile_eval_gemfiles(content) ⇒ Object
- .deduplicate_readme_corporate_sponsors(sponsors) ⇒ Object
- .deduplicate_readme_top_logo_entries(entries) ⇒ Object
- .deep_dup(value) ⇒ Object
- .deep_string_key_hash(value) ⇒ Object
- .default_framework_matrix_requirement(version) ⇒ Object
- .default_gemspec_metadata_assignment?(record) ⇒ Boolean
- .default_readme_top_logo_credit(type) ⇒ Object
- .default_readme_top_logo_href(type, slug:, org:, gem_name:, repository: {}) ⇒ Object
- .default_readme_top_logo_slug(type, org:, gem_name:, repository: {}) ⇒ Object
- .default_template_config ⇒ Object
- .default_template_strategy_config(template_root, target_path) ⇒ Object
-
.default_test_bundle_config(config, framework_matrix) ⇒ Object
Configures the dependencies used by
bundle exec kettle-testwithout a BUNDLE_GEMFILE override. - .default_test_bundle_gem_entry(raw) ⇒ Object
- .default_test_bundle_gem_source(gem) ⇒ Object
- .default_test_bundle_gemfile_entry(raw) ⇒ Object
- .delete_file_recipe?(recipe) ⇒ Boolean
- .delete_line_ranges(content, selectors) ⇒ Object
- .delete_markdown_with_ast_crispr(content, target) ⇒ Object
- .delete_markdown_with_ast_crispr_batch(content, *targets) ⇒ Object
- .delete_project_file(project_root, relative_path) ⇒ Object
- .delete_rakefile_scaffold(content) ⇒ Object
- .delete_yaml_top_level_mapping_entries(content, parent_key:, child_keys:) ⇒ Object
- .dependency_file_contents(project_root, recipe_reports, paths) ⇒ Object
- .dependency_records_for(path, content) ⇒ Object
- .destination_file_sha256(project_root, relative_path) ⇒ Object
- .detected_license_ids(project_root) ⇒ Object
- .direct_sibling_directory_defines_gem?(sibling_path, gem_name) ⇒ Boolean
- .direct_sibling_nomono_root_parts(workspace_slug, repository) ⇒ Object
- .direct_sibling_runtime_gems(project_root, gemspec_metadata, package_name:, local_modular_eval_paths: {}) ⇒ Object
- .direct_sibling_workspace_slug(source_url, project_root) ⇒ Object
- .disabled_coverage_integrations(config) ⇒ Object
- .disabled_integration_config_cleanups(project_root, config) ⇒ Object
- .disabled_integration_template_path?(target_path, config) ⇒ Boolean
- .disabled_integrations(config, license: nil) ⇒ Object
- .discover_facts(project_root, env: ENV, run_options: {}) ⇒ Object
- .discover_monorepo_root_facts(project_root, kettle_config, env, template_selection) ⇒ Object
-
.display_path(path) ⇒ Object
rubocop:enable ThreadSafety/ClassInstanceVariable.
- .display_text(text) ⇒ Object
- .distribute_file_work_units(file_work_units, workers) ⇒ Object
- .dotenv_merge_options(recipe) ⇒ Object
- .duplicate_drift_report(project_root:, template_root:, run_options: {}) ⇒ Object
- .duration_ms_since(started_at) ⇒ Object
- .emit_diagnostic_events(events, diagnostics) ⇒ Object
- .emit_event(events, type, payload = {}) ⇒ Object
- .emit_phase_event(events, phase, status:, **payload) ⇒ Object
- .emit_recipe_event(events, report, index:, total:) ⇒ Object
- .emit_step_event(events, event_type, step, phase:, index: nil, total: nil) ⇒ Object
- .emit_step_events(events, event_type, steps, phase:) ⇒ Object
- .emit_summary_event(events, report) ⇒ Object
- .empty_gemspec_development_dependency_section_matches(lines, heading_line_indexes:, dependency_line_indexes:) ⇒ Object
- .empty_gemspec_development_dependency_sections_target(receiver:) ⇒ Object
- .enabled_ruby_engines(config) ⇒ Object
- .enforce_gemspec_dependency_minimum_requirements(source, receiver:) ⇒ Object
- .enforce_git_preflight!(git_preflight, decision_policy:, template_selection:) ⇒ Object
- .ensure_entrypoint_namespace_superclass_declarations(content, namespace:, namespace_superclasses: {}) ⇒ Object
- .ensure_gemspec_legacy_version_loader_preamble(content, entrypoint_require:, namespace:, min_ruby:, superclass_sensitive: false, fallback_version: nil) ⇒ Object
- .ensure_gemspec_metadata_assignment(content, receiver:, key:, value:) ⇒ Object
- .ensure_main_gemfile_nomono_bootstrap(content, template_content) ⇒ Object
- .ensure_monorepo_root_gemfile_dependencies(content) ⇒ Object
-
.ensure_runtime_dependencies! ⇒ Object
rubocop:disable ThreadSafety/ClassInstanceVariable.
- .ensure_spec_helper_simplecov_config_require(content) ⇒ Object
- .ensure_spec_helper_simplecov_do_cov_bootstrap(content) ⇒ Object
- .ensure_spec_helper_simplecov_start(content) ⇒ Object
- .ensure_trailing_newline(text) ⇒ Object
- .ensure_workflow_top_level_section(content, key, section, before:) ⇒ Object
- .ensure_yaml_top_level_sequence_items(content, key, items) ⇒ Object
- .entrypoint_loads_version_file?(content, project_root:, entrypoint_path:, version_path:) ⇒ Boolean
- .entrypoint_namespace_superclasses_from_facts(facts) ⇒ Object
- .env_overridden_gemspec_fields(env) ⇒ Object
- .env_sync_value(env, env_key) ⇒ Object
- .error_class_namespace?(content, namespace) ⇒ Boolean
- .event_payload_value(payload, key) ⇒ Object
- .event_stream(io, types: nil) ⇒ Object
- .event_stream_from_options(run_options) ⇒ Object
- .executable_version_constant_nodes(node, namespaces) ⇒ Object
-
.executable_version_entrypoint_sync_step(project_root, report) ⇒ Object
Older generated executable headers used the package name for both the version file and namespace.
- .execute_indexed_recipe_reports(project_root:, indexed_recipes:, facts:, files:, template_contents:, decision_policy:, env:) ⇒ Object
- .execute_indexed_recipe_reports_thread(project_root:, indexed_recipes:, facts:, files:, template_contents:, decision_policy:, env:, workers:) ⇒ Object
- .execute_recipe(project_root:, recipe:, facts:, files:, decision_policy:, env: ENV, template_contents: nil) ⇒ Object
- .execute_recipe_reports(project_root:, recipes:, facts:, files:, template_contents:, decision_policy:, env:, events:, strategy:, workers: 0, thread_workers: 0, stats: nil) ⇒ Object
- .execute_recipe_reports_classified(project_root:, recipes:, facts:, files:, template_contents:, decision_policy:, env:, events:, workers: 0, thread_workers: 0, stats: nil) ⇒ Object
- .execute_recipe_reports_sequential(project_root:, recipes:, facts:, files:, template_contents:, decision_policy:, env:, events:) ⇒ Object
- .execute_timed_recipe(project_root:, recipe:, facts:, files:, template_contents:, decision_policy:, env:) ⇒ Object
- .execute_worker_safe_recipe_reports_ractor(project_root:, indexed_recipes:, facts:, files:, template_contents:, decision_policy:, env:, workers:) ⇒ Object
- .existing_entrypoint_version_namespace(project_root, relative_path, expected_depth: nil) ⇒ Object
- .existing_namespace_superclass_details(project_root, namespace, preferred_path: nil) ⇒ Object
- .existing_simplecov_bootstrap_template_preferences(project_root, config, preferences) ⇒ Object
- .existing_version_file_includes_version_module?(project_root, relative_path) ⇒ Boolean
- .existing_version_file_value(project_root, relative_path) ⇒ Object
- .existing_version_namespace(project_root, relative_path) ⇒ Object
- .existing_version_namespace_kinds(project_root, relative_path, namespace, entrypoint_path: nil) ⇒ Object
- .existing_version_namespace_superclasses(project_root, relative_path, namespace, entrypoint_path: nil) ⇒ Object
- .expand_framework_gemfile_pattern(pattern, version) ⇒ Object
- .expand_line_range_through_following_blanks(content, end_line) ⇒ Object
- .explicit_integration_enabled?(config, integration) ⇒ Boolean
- .explicit_zero_runtime_floor?(facts) ⇒ Boolean
- .extract_gemspec_development_dependencies(gemspec) ⇒ Object
- .fallback_opencollective_org ⇒ Object
- .falsey_config?(value) ⇒ Boolean
- .file_outcome_payload(file_outcome) ⇒ Object
- .file_work_execution_stats(file_workers, file_thread_workers = 0) ⇒ Object
- .file_work_thread_workers_for(env, run_options) ⇒ Object
- .file_work_unit_payload(file_work_unit) ⇒ Object
- .file_work_units_for_phase(project_root, recipe_reports) ⇒ Object
- .file_work_units_from_write_intents(write_intents) ⇒ Object
- .file_work_workers_for(env, run_options) ⇒ Object
- .filter_recipe_pack(pack, template_selection) ⇒ Object
- .finalize_accepted_template_source(recipe, content, destination_content, facts:, project_root: nil) ⇒ Object
- .finalize_gemfile_template_source(recipe, content, destination_content, facts:, template_content:) ⇒ Object
- .finalize_github_workflow_template(content, facts = nil) ⇒ Object
- .finalize_kettle_config_template_source(recipe, content) ⇒ Object
- .finalize_rubocop_config(content) ⇒ Object
- .finalize_template_source_content(recipe, content) ⇒ Object
- .first_grapheme(text) ⇒ Object
- .forge_facts(config, env, derived_github_user: nil) ⇒ Object
- .forge_template_tokens(forge) ⇒ Object
- .forge_user_value(forge_config, env, key, derived_value: nil) ⇒ Object
- .format_copyright_years(years) ⇒ Object
- .framework_gemfile_path(gemfile) ⇒ Object
- .framework_matrix_appraisal_block(entry) ⇒ Object
- .framework_matrix_appraisal_dependency_gemfiles(facts) ⇒ Object
- .framework_matrix_appraisal_env_by_name(facts) ⇒ Object
- .framework_matrix_appraisal_gemfile_path(path) ⇒ Object
- .framework_matrix_appraisal_gemfiles(raw) ⇒ Object
- .framework_matrix_appraisal_name(dimension, slug) ⇒ Object
- .framework_matrix_env(raw) ⇒ Object
- .framework_matrix_replaced_appraisal_names(dimension, entry, name) ⇒ Object
- .framework_matrix_version_entry(raw) ⇒ Object
- .framework_matrix_workflow_enabled?(raw) ⇒ Boolean
- .freeze_marker_blocks(content, freeze_token: nil) ⇒ Object
- .funding_platform_enabled?(enabled_platforms, platform) ⇒ Boolean
- .funding_platform_policies(config, env) ⇒ Object
- .funding_platform_token_facts(config, env) ⇒ Object
- .funding_platform_token_value(funding_config, env, key) ⇒ Object
- .funding_template_tokens(funding) ⇒ Object
- .funding_urls(project_root, package_name, funding_uri: nil, opencollective_disabled: false, open_collective_org: nil, enabled_platforms: nil) ⇒ Object
- .gem_major_token(version) ⇒ Object
- .gemfile_comment_line?(line) ⇒ Boolean
- .gemfile_conditional_node?(node) ⇒ Boolean
- .gemfile_declares_direct_gem?(content, gem_name) ⇒ Boolean
- .gemfile_declares_gem?(content, gem_name) ⇒ Boolean
- .gemfile_dependency_insertion_line(content) ⇒ Object
- .gemfile_dependency_names(content) ⇒ Object
- .gemfile_dependency_statement?(node) ⇒ Boolean
- .gemfile_eval_bucket_entries(content) ⇒ Object
- .gemfile_eval_comment_start_line(lines, start_line) ⇒ Object
- .gemfile_eval_paths(content) ⇒ Object
- .gemfile_gem_call_records(content) ⇒ Object
- .gemfile_nomono_dependency_names(content) ⇒ Object
- .gemfile_paragraphs(content) ⇒ Object
- .gemfile_percent_w_names(content) ⇒ Object
- .gemfile_policy_operations(template_content, original, final, request) ⇒ Object
- .gemfile_workspace_override_node?(node) ⇒ Boolean
- .gemspec_assignment_field(call) ⇒ Object
- .gemspec_assignment_records(source, receiver: nil) ⇒ Object
- .gemspec_assignment_value(call) ⇒ Object
- .gemspec_block_param(source) ⇒ Object
- .gemspec_dependency_call_kind(call) ⇒ Object
- .gemspec_dependency_from_record(record) ⇒ Object
- .gemspec_dependency_line_index(source, receiver:) ⇒ Object
- .gemspec_dependency_line_key(line, receiver:) ⇒ Object
- .gemspec_dependency_minimum_requirement_replacement(call, requirement) ⇒ Object
- .gemspec_dependency_names(source) ⇒ Object
- .gemspec_dependency_record_key(record) ⇒ Object
- .gemspec_dependency_record_version(record) ⇒ Object
- .gemspec_dependency_records(source, receiver: nil) ⇒ Object
- .gemspec_dependency_requirements_satisfy_floor?(requirements, floor_requirement) ⇒ Boolean
-
.gemspec_dependency_section_heading_comment?(stripped_line) ⇒ Boolean
Prism does not expose comments as normal AST statements, so dependency-section headings are bounded to single-line comments after the gemspec development note.
- .gemspec_dependency_sort_key(name) ⇒ Object
- .gemspec_dependency_source_newer?(candidate_source, current_source, receiver:) ⇒ Boolean
- .gemspec_end_line(source) ⇒ Object
- .gemspec_enumerate_package_glob_body(min_ruby) ⇒ Object
- .gemspec_field_receiver_and_name(field) ⇒ Object
- .gemspec_files_array_collection_source(target_parts, groups) ⇒ Object
- .gemspec_files_child_collection_record(record, value_node) ⇒ Object
- .gemspec_files_collection_body_source(groups) ⇒ Object
- .gemspec_files_collection_element_nodes(value_node) ⇒ Object
- .gemspec_files_collection_entry_key(node) ⇒ Object
- .gemspec_files_collection_entry_node?(node) ⇒ Boolean
- .gemspec_files_collection_group_source(group, trailing_comma:) ⇒ Object
- .gemspec_files_collection_groups(record:, element_nodes:, lines:) ⇒ Object
- .gemspec_files_collection_has_nonliteral_entries?(parts) ⇒ Boolean
- .gemspec_files_collection_has_package_metadata_splat?(parts) ⇒ Boolean
- .gemspec_files_collection_kind(value_node) ⇒ Object
- .gemspec_files_collection_needs_concat?(target_parts, groups) ⇒ Boolean
- .gemspec_files_collection_parts(record) ⇒ Object
- .gemspec_files_concat_call_node?(node) ⇒ Boolean
- .gemspec_files_concat_collection_parts(record, value_node) ⇒ Object
- .gemspec_files_concat_collection_source(target_parts, groups) ⇒ Object
- .gemspec_files_dir_call_node?(node) ⇒ Boolean
- .gemspec_files_dir_collection_source(target_parts, groups, closing: nil) ⇒ Object
- .gemspec_files_group_collection_kind(group, parts) ⇒ Object
- .gemspec_files_normalize_dir_globs_for_array(groups, target_parts) ⇒ Object
- .gemspec_files_single_collection_parts(record, value_node) ⇒ Object
- .gemspec_files_splat_expression_key(node) ⇒ Object
- .gemspec_freeze_block_structurally_managed?(block, receiver:) ⇒ Boolean
- .gemspec_legacy_version_loader_block(entrypoint_require:, namespace:, min_ruby:, superclass_sensitive: false, fallback_version: nil) ⇒ Object
- .gemspec_legacy_version_loader_preamble_line_range(content) ⇒ Object
- .gemspec_metadata_assignment_records(content, receiver:) ⇒ Object
- .gemspec_modern_package_helper?(min_ruby) ⇒ Boolean
- .gemspec_modern_version_loader_expression(entrypoint_require:, namespace:) ⇒ Object
- .gemspec_new_call(source) ⇒ Object
- .gemspec_package_file_includes_token(gemspec) ⇒ Object
- .gemspec_package_helper_assignment_records(content) ⇒ Object
- .gemspec_path_declares_gem?(path, gem_name) ⇒ Boolean
- .gemspec_policy_operations(template_content, original, final, request) ⇒ Object
- .gemspec_preserved_assignment_fields ⇒ Object
- .gemspec_preserved_assignments(source, receiver:) ⇒ Object
- .gemspec_project_emoji(gemspec_metadata) ⇒ Object
- .gemspec_relative_package_path_body(min_ruby) ⇒ Object
- .gemspec_root_license_files_token(_license) ⇒ Object
- .gemspec_root_reference_node?(node) ⇒ Boolean
- .gemspec_runtime_dependency_names(gemspec_metadata) ⇒ Object
- .gemspec_runtime_floor_token(facts) ⇒ Object
- .gemspec_self_dependency_names(request, package_name) ⇒ Object
- .gemspec_standard_legacy_version_loader_block(entrypoint_require:, namespace:, min_ruby:) ⇒ Object
- .gemspec_template_facts(config) ⇒ Object
- .gemspec_template_tokens(gemspec, min_ruby: nil) ⇒ Object
- .gemspec_top_level_gem_version_node(content) ⇒ Object
- .gemspec_version_loader_policy_operation(original, final, request) ⇒ Object
- .gemspec_version_loader_superclass_sensitive?(facts) ⇒ Boolean
- .generated_blocks_facts(gemspec, facts, run_options) ⇒ Object
- .generated_gemspec_metadata_file_group?(group, target_parts) ⇒ Boolean
- .generated_gemspec_package_glob_call?(node) ⇒ Boolean
- .generated_kettle_config_without_templates?(config) ⇒ Boolean
- .generated_or_obsolete_github_workflow?(relative_path) ⇒ Boolean
- .generated_version_tree_source_url?(source_url, version) ⇒ Boolean
- .generic_bundler_gemspec_files_assignment?(record) ⇒ Boolean
- .generic_bundler_gemspec_files_command?(node) ⇒ Boolean
- .git_capture(project_root, *args) ⇒ Object
- .git_copyright_lines(project_root, machine_users, author_aliases: {}) ⇒ Object
- .git_hooks_executable_step(project_root) ⇒ Object
- .git_operation_lock_path(env) ⇒ Object
- .git_output(project_root, *args) ⇒ Object
- .git_preflight_report(project_root, template_selection:, env: ENV) ⇒ Object
- .git_remote_source_url(project_root) ⇒ Object
- .git_success?(project_root, *args) ⇒ Boolean
- .git_version_file_value(project_root, relative_path) ⇒ Object
- .git_worktree_prefix(project_root) ⇒ Object
- .git_worktree_root(project_root) ⇒ Object
- .github_actions_coverage_config(config, env = ENV) ⇒ Object
- .github_actions_coverage_enabled?(content) ⇒ Boolean
- .github_actions_coverage_steps(disabled_integrations: []) ⇒ Object
- .github_actions_custom_workflows(project_root, config = {}, opencollective_disabled: false) ⇒ Object
-
.github_actions_engine_exec_cmds(config) ⇒ Object
A generated workflow normally uses one command for every matrix entry.
- .github_actions_exec_cmd(config, env) ⇒ Object
- .github_actions_framework_matrix(config) ⇒ Object
- .github_actions_obsolete_workflows(project_root) ⇒ Object
- .github_actions_pin_sync_step(project_root) ⇒ Object
- .github_actions_push_branches(content, default_branch:) ⇒ Object
- .github_actions_push_branches_yaml(content, default_branch:, indent: " ") ⇒ Object
- .github_actions_rspec_status_cache_step(cache_scope:, key_parts:, indent:, if_condition: "${{!env.ACT}}") ⇒ Object
- .github_actions_ruby_versions(min_ruby) ⇒ Object
- .github_actions_setup_ruby_steps(indent:) ⇒ Object
- .github_actions_standard_appraisal_gemfiles(config) ⇒ Object
- .github_actions_step_pins ⇒ Object
- .github_funding_platform_urls(platform, values) ⇒ Object
- .github_funding_urls(path, opencollective_disabled: false, enabled_platforms: nil) ⇒ Object
- .github_org_from_url(url) ⇒ Object
- .github_repository_slug(url) ⇒ Object
- .github_repository_star_count(project_root, repository_slug) ⇒ Object
- .github_workflow_action_pin_key(record) ⇒ Object
- .github_workflow_action_pin_line_record(line, line_index) ⇒ Object
- .github_workflow_action_pin_records(content) ⇒ Object
- .github_workflow_engine_exec_cmds_for_template(source_path, overrides) ⇒ Object
- .github_workflow_template_pin_warnings(recipe_reports) ⇒ Object
- .github_workflow_template_recipe?(recipe) ⇒ Boolean
- .github_workflows_include?(project_root, needle) ⇒ Boolean
- .gitlab_repo_url(repository, repo_slug, suffix) ⇒ Object
- .guard_main_gemfile_runtime_workspace_overrides(content) ⇒ Object
- .guarded_debug_require ⇒ Object
- .html_attribute_escape(value) ⇒ Object
- .http_url?(value) ⇒ Boolean
- .inactive_packaged_template_cleanup_files(project_root, config = {}) ⇒ Object
- .inactive_packaged_workflow?(relative_path, config = {}, include_patterns: nil) ⇒ Boolean
- .inactive_packaged_workflow_cleanup_files(project_root, config = {}, include_patterns: nil) ⇒ Object
- .indent_source(source, spaces) ⇒ Object
- .inject_appraisal_gemfiles(block, gemfiles) ⇒ Object
- .inject_framework_matrix_workflow_env(content, facts) ⇒ Object
-
.inject_main_gemfile_default_test_bundle(content, facts) ⇒ Object
The root Gemfile is the local-development bundle.
- .inject_main_gemfile_recording_eval(content, facts) ⇒ Object
- .inject_standard_appraisal_gemfiles(content, facts) ⇒ Object
- .insert_after_line_sequence(content, sequence, insertion, error_message) ⇒ Object
- .insert_changelog_transfer_entries_in_release(lines, heading, entries) ⇒ Object
- .insert_gemfile_dependency_blocks(content, blocks) ⇒ Object
- .insert_lines_after(content, line_number, insertion) ⇒ Object
- .insert_lines_before(content, line_number, insertion) ⇒ Object
- .insert_missing_development_gemspec_dependency_lines(content, missing_lines) ⇒ Object
- .insert_missing_gemspec_assignment_sources(content, replacements, receiver:) ⇒ Object
- .insert_missing_gemspec_files_assignment(content, template_content:, template_receiver:) ⇒ Object
- .insert_missing_runtime_gemspec_dependency_lines(content, missing_lines, receiver:) ⇒ Object
- .insert_yaml_scalar_after_path(content, path, key, value) ⇒ Object
- .install_tasks ⇒ Object
- .integration_license_spdx(config, license) ⇒ Object
- .io_popen_gemspec_files_assignment?(node) ⇒ Boolean
- .json_merge_options(recipe) ⇒ Object
- .kettle_changelog_gemfile_dependency_token(package_name) ⇒ Object
- .kettle_config_bootstrap_facts(project_root, env, template_selection: {}) ⇒ Object
- .kettle_config_bootstrap_recipe(bootstrap) ⇒ Object
- .kettle_config_file_override_block_end(lines, start_index) ⇒ Object
- .kettle_config_file_override_lines(path, strategy) ⇒ Object
- .kettle_config_gemspec_override_insertion_index(lines, files_index) ⇒ Object
- .kettle_config_internal_value(value_provider) ⇒ Object
- .kettle_config_template_entries_lines(entries) ⇒ Object
- .kettle_dev_local_gems(config) ⇒ Object
- .kettle_jem_config(project_root) ⇒ Object
- .kettle_jem_config_path(project_root) ⇒ Object
- .kettle_jem_config_relative_path(project_root) ⇒ Object
- .kettle_jem_state_sync_step(project_root, report) ⇒ Object
- .known_license_template_basenames ⇒ Object
- .large_business_license_cell(author_email, license_source_url: nil) ⇒ Object
- .latest_changelog_transfer_entry(entries) ⇒ Object
- .leading_space_count(line) ⇒ Object
- .leading_whitespace(source) ⇒ Object
-
.legacy_git_ls_files_assignment?(node) ⇒ Boolean
Legacy gemspecs commonly shell out with backticks, then apply split and optional filtering calls.
-
.legacy_git_ls_files_chdir_assignment?(node) ⇒ Boolean
Older Bundler gemspecs commonly scope a git-ls-files pipeline with Dir.chdir(File.expand_path(dir)).
- .legacy_rbs_consolidation_step(project_root, facts, entrypoint_require:) ⇒ Object
- .legacy_rbs_signature_paths(project_root, entrypoint_require) ⇒ Object
- .legacy_readme_top_logo_mode_options(value) ⇒ Object
- .license_badge(spdx_id, ref: :license_ref) ⇒ Object
- .license_badge_img(spdx_id) ⇒ Object
- .license_badge_ref(spdx_id, license_source_url: nil) ⇒ Object
- .license_compat_badge(category) ⇒ Object
- .license_compat_category(licenses) ⇒ Object
- .license_compat_img(category) ⇒ Object
- .license_compat_ref(category) ⇒ Object
- .license_contact_line(author_email, context:) ⇒ Object
- .license_copyright_notice(copyright_lines, copyright_prefix, author) ⇒ Object
- .license_detail_ref(base, license_source_url: nil) ⇒ Object
- .license_eye_compatible_licenses?(licenses) ⇒ Boolean
- .license_eye_dependency_license_entry(entry) ⇒ Object
- .license_eye_dependency_licenses(config) ⇒ Object
- .license_eye_flags(licenses) ⇒ Object
- .license_eye_mode(licenses) ⇒ Object
- .license_eye_primary_spdx(licenses, fallback) ⇒ Object
- .license_eye_workflow_badge(licenses, config = {}) ⇒ Object
- .license_facts(config, gemspec_licenses, author: {}, author_email: nil, copyright: {}, source_url: nil, license_txt: {}) ⇒ Object
- .license_link(spdx_id, license_source_url: nil) ⇒ Object
- .license_md_content(licenses, author_email: nil, license_source_url: nil, custom_license: false) ⇒ Object
- .license_source_blob_url(source_url) ⇒ Object
- .license_template_tokens(license) ⇒ Object
- .license_txt_facts(project_root) ⇒ Object
- .license_use_case_guide_table(licenses, author_email: nil, license_source_url: nil) ⇒ Object
- .license_use_case_rows(licenses, author_email: nil, license_source_url: nil) ⇒ Object
- .load_project_gemspec(gemspec_path) ⇒ Object
- .local_gemfile_nomono_bootstrap(_package_name) ⇒ Object
- .local_gemfile_nomono_kernel_activation_call?(node) ⇒ Boolean
- .local_gemfile_template_recipe?(recipe) ⇒ Boolean
- .local_gems_assignment(content) ⇒ Object
- .local_gems_assignment_record(content) ⇒ Object
- .local_modular_eval_paths_for_gem(project_root, gem_name) ⇒ Object
- .local_modular_runtime_eval_paths(project_root, gemspec_metadata, package_name:) ⇒ Object
- .main_gemfile_after_gemspec_line(content) ⇒ Object
- .main_gemfile_default_test_bundle_insertion_index(content) ⇒ Object
- .main_gemfile_direct_gem_records(content, gem_name) ⇒ Object
- .main_gemfile_direct_sibling_block(gems, package_name:, source_url:, project_root:, repository: {}, local_modular_eval_paths: []) ⇒ Object
- .main_gemfile_direct_sibling_records(content) ⇒ Object
- .main_gemfile_first_eval_gemfile_line(content) ⇒ Object
- .main_gemfile_kettle_family_gem(package_name) ⇒ Object
- .main_gemfile_nomono_bootstrap(package_name) ⇒ Object
- .main_gemfile_nomono_bootstrap_source(template_content) ⇒ Object
- .main_gemfile_nomono_requirement_records(content) ⇒ Object
- .main_gemfile_recording_eval_path ⇒ Object
- .main_gemfile_recording_insertion_index(content) ⇒ Object
- .main_gemfile_templating_eval_line(content) ⇒ Object
- .managed_license_template_basename(target_path) ⇒ Object
- .managed_version_gem_version_spec?(content) ⇒ Boolean
- .markdown_heading_has_preserved_readme_ancestor?(heading_sections, index) ⇒ Boolean
- .markdown_heading_owners(content, source_label: "README.md") ⇒ Object
- .markdown_link_definition_source(owner, url) ⇒ Object
- .markdown_link_reference_definition_line?(line) ⇒ Boolean
- .markdown_managed_block(content, marker) ⇒ Object
- .markdown_sections(content) ⇒ Object
- .markdown_source_lines(content) ⇒ Object
- .merge_appraisal_blocks_with_prism(template_block, destination_block) ⇒ Object
- .merge_appraisals_template_policy(content, facts:) ⇒ Object
- .merge_bash_template_source(template_content, destination_content, recipe) ⇒ Object
- .merge_changelog_template_source(template_content, destination_content, facts: nil) ⇒ Object
- .merge_config_template_source(recipe, template_content, destination_content, facts: nil, env: ENV) ⇒ Object
- .merge_dotenv_template_source(template_content, destination_content, recipe) ⇒ Object
- .merge_framework_matrix_appraisals(content, facts) ⇒ Object
- .merge_gemfile_eval_bucket_entries(template_content, merged_content, destination_content: nil) ⇒ Object
- .merge_gemfile_template_policy(content, facts:, template_content: nil, preserve_self_word_entries: false) ⇒ Object
- .merge_gemspec_files_assignment(content, template_content:, destination_content:, template_receiver:, destination_receiver:) ⇒ Object
- .merge_gemspec_files_assignment_source(merged_record:, template_record:, destination_record:) ⇒ Object
- .merge_gemspec_files_assignment_with_destination_splats(merged_parts:, destination_parts:) ⇒ Object
- .merge_gemspec_template_source(template_content, destination_content, facts: nil, env: ENV) ⇒ Object
- .merge_gitignore_template_source(template_content, destination_content) ⇒ Object
- .merge_json_template_source(template_content, destination_content, recipe, file_type) ⇒ Object
- .merge_local_gem_overrides(content, destination_content, facts:, template_content: nil) ⇒ Object
- .merge_prism_gemfile_template_source(template_content, destination_content) ⇒ Object
- .merge_rbs_signature_sources(template_content, destination_content) ⇒ Object
- .merge_rbs_template_source(template_content, destination_content, recipe) ⇒ Object
- .merge_readme_template(template_content:, destination_content:, preserve_config: {}) ⇒ Object
- .merge_ruby_template_source(file_type, recipe, template_content, destination_content, facts: nil) ⇒ Object
- .merge_template_gemfile_dependency_blocks(template_content, content, removable_gems, preserve_self_word_entries: false) ⇒ Object
- .metadata_value(metadata, key) ⇒ Object
-
.migrate_legacy_byebug_appraisal_dependencies(content) ⇒ Object
Each appraisal has an independent dependency set.
- .migrate_legacy_byebug_pair(content) ⇒ Object
-
.migrate_legacy_byebug_requires(content) ⇒ Object
The Gemfile migration replaces every byebug-family dependency with debug.
- .migrate_readme_logo_config(content) ⇒ Object
-
.migrate_simplecov_start_configuration(content) ⇒ Object
SimpleCov.start was historically used as both configuration and startup.
- .min_ruby_version(requirement) ⇒ Object
- .minimum_ruby_token(requirement) ⇒ Object
- .mit_readme_license_intro(license_source_url: nil) ⇒ Object
- .mkdir_p_core(path) ⇒ Object
- .modular_dependency_conflict_decided?(decisions, conflict) ⇒ Boolean
- .modular_dependency_conflict_decisions(config) ⇒ Object
- .modular_dependency_conflict_resolution_step(project_root) ⇒ Object
- .modular_dependency_conflicts(project_root, recipe_reports) ⇒ Object
- .modular_dependency_conflicts_reviewed?(config) ⇒ Boolean
- .modular_gemfile_template_recipe?(recipe) ⇒ Boolean
- .monorepo_root_file_strategy(entry) ⇒ Object
- .monorepo_root_gemfile_dependency_lines ⇒ Object
- .monorepo_root_gemfile_dependency_sync_step(project_root, report) ⇒ Object
- .monorepo_root_template_profile?(facts) ⇒ Boolean
- .monorepo_subgem_kettle_config_profile_sync_step(project_root, report) ⇒ Object
- .monorepo_subgem_template_entries(gemspec_path, profile = MONOREPO_SUBGEM_TEMPLATE_PROFILE) ⇒ Object
- .monorepo_subgem_template_entries_for_profile(gemspec_path, profile) ⇒ Object
- .monorepo_subgem_template_profile?(facts) ⇒ Boolean
- .monorepo_subgem_template_profile_value?(profile) ⇒ Boolean
- .monorepo_template_profile?(facts) ⇒ Boolean
- .monotonic_time ⇒ Object
- .namespace_descendant?(namespace, parent) ⇒ Boolean
- .nested_templating_guard_records(content) ⇒ Object
- .node_enclosed_by_ranges?(node, ranges) ⇒ Boolean
- .nomono_gemfile_declaration ⇒ Object
- .non_default_version_gem_entrypoint?(project_root, entrypoint_require) ⇒ Boolean
- .non_mit_licenses?(licenses) ⇒ Boolean
- .nonempty_string(value) ⇒ Object
- .normalize_changelog(content, facts) ⇒ Object
- .normalize_conditional_body_indentation(source) ⇒ Object
- .normalize_debug_require_records(content, records) ⇒ Object
- .normalize_entrypoint_version_require(content, entrypoint_require:, version_require_path: nil, after_declarations: false) ⇒ Object
- .normalize_eval_gemfile_ruby_bucket(path) ⇒ Object
- .normalize_executable_version_entrypoint(content, legacy_version_path:, canonical_version_path:, legacy_namespace:, namespace:) ⇒ Object
- .normalize_gemspec_dependency_version_requirements(source, receiver:, namespace:) ⇒ Object
- .normalize_gemspec_package_helper_assignments(content, template_content) ⇒ Object
- .normalize_gemspec_project_emoji(line, facts, field:) ⇒ Object
- .normalize_gemspec_receiver(line, from:, to:) ⇒ Object
- .normalize_generated_image_url(url) ⇒ Object
- .normalize_generated_rakefile(content) ⇒ Object
- .normalize_git_source_url(url) ⇒ Object
- .normalize_github_actions_exec_cmd(command) ⇒ Object
- .normalize_integration_name(name) ⇒ Object
- .normalize_kettle_config_optional_scalars(content) ⇒ Object
- .normalize_kettle_jem_config(config) ⇒ Object
- .normalize_legacy_changelog_release_headings(content) ⇒ Object
- .normalize_list_option(value) ⇒ Object
- .normalize_local_gemfile_nomono_bootstrap(content) ⇒ Object
- .normalize_main_gemfile_nomono_declaration(content) ⇒ Object
- .normalize_project_homepage_uri(value) ⇒ Object
- .normalize_project_hostname(value) ⇒ Object
- .normalize_rakefile_section_spacing(content) ⇒ Object
- .normalize_readme_blank_line_runs(content) ⇒ Object
- .normalize_readme_compatibility_summary(content, engines, min_ruby = "") ⇒ Object
- .normalize_readme_corporate_sponsors(value) ⇒ Object
- .normalize_readme_corporate_sponsors_json(value) ⇒ Object
- .normalize_readme_heading(text) ⇒ Object
- .normalize_readme_project_heading(content, facts) ⇒ Object
- .normalize_readme_rubygems_download_badges(content) ⇒ Object
- .normalize_readme_section_key(section) ⇒ Object
- .normalize_readme_synopsis_heading(content, facts) ⇒ Object
- .normalize_repository_topology(value) ⇒ Object
- .normalize_rubyforum_tag(value) ⇒ Object
-
.normalize_simplecov_cover_predicates(content) ⇒ Object
SimpleCov's compatibility probe changed spelling between template generations.
- .normalize_simplecov_template_source(content) ⇒ Object
-
.normalize_simplecov_usage_guidance(content) ⇒ Object
Older template merges appended a second generated usage-comment block.
- .normalize_spec_helper_block_bindings(content, template_content) ⇒ Object
- .normalize_spec_helper_simplecov_template_source(content) ⇒ Object
-
.normalize_structuredmerge_local_gems(content, template_content) ⇒ Object
This list is resolved exclusively through STRUCTUREDMERGE_DEV.
- .normalize_template_profile(value) ⇒ Object
- .normalize_templating_guard_indentation(content) ⇒ Object
- .normalize_version_gem_entrypoint_mode(value) ⇒ Object
- .normalize_version_gem_version_spec(project_root, version_spec_path, entrypoint_require, namespace, ensure_version_gem_require:, package_name: nil, include_version_gem_path: true, ensure_package_entrypoint_require: false) ⇒ Object
- .normalize_version_spec_anonymous_loader_example(content, version_spec_path:, entrypoint_require:, namespace:, include_version_gem_path: true) ⇒ Object
- .normalized_readme_logo_specs(value) ⇒ Object
- .normalized_readme_logo_width(value) ⇒ Object
- .normalized_readme_top_logo_options(value) ⇒ Object
- .obsolete_local_gemfile_nomono_activation_records(content) ⇒ Object
- .obsolete_simplecov_rescue_bootstrap_node?(node, complete_bootstrap_present:) ⇒ Boolean
- .obsolete_simplecov_rescue_bootstrap_records(content) ⇒ Object
- .old_ruby_version_bootstrap_step(project_root, report, entrypoint_require:, preserve_version_module_include: nil) ⇒ Object
- .opencollective_disabled?(config, env: ENV) ⇒ Boolean
- .opencollective_disabled_file?(relative_path) ⇒ Boolean
- .opencollective_disabled_files(project_root) ⇒ Object
- .opencollective_fallback_warnings(funding, github_org) ⇒ Object
- .opencollective_falsey_env(env) ⇒ Object
- .opencollective_org(project_root, config, env, opencollective_disabled: false) ⇒ Object
- .opencollective_org_config(config) ⇒ Object
- .opencollective_org_env(env) ⇒ Object
- .opencollective_org_file(project_root) ⇒ Object
- .opencollective_org_github_funding_file(project_root) ⇒ Object
- .opencollective_policy(config, env) ⇒ Object
- .opt_in_workflow_cleanup_files(project_root, template_selection) ⇒ Object
- .outdent_line(line, spaces) ⇒ Object
- .outdent_source(source, spaces) ⇒ Object
- .package_runtime_dependency_names(facts) ⇒ Object
- .packaged_gemfile_referenced_by_x_std_libs?(target_path, project_root:, template_root_path:) ⇒ Boolean
- .packaged_gemfile_template_ruby_floor(target_path) ⇒ Object
- .packaged_template_root ⇒ Object
- .paired_modular_gemfile_path(local_relative_path) ⇒ Object
- .paperclip_ref(name) ⇒ Object
- .parse_blame_porcelain(output, author_map) ⇒ Object
- .parse_changelog_transfer_filter(payload) ⇒ Object
- .parse_changelog_transfer_key(key) ⇒ Object
- .parse_changelog_transfer_line(payload) ⇒ Object
- .parse_event_types(types) ⇒ Object
- .phase_for_recipe(recipe_name, relative_path) ⇒ Object
- .phase_reports_for(recipe_reports) ⇒ Object
- .plan_project(project_root, env: ENV, run_options: {}) ⇒ Object
- .plan_readme_style(project_root, env: ENV) ⇒ Object
- .plugin_lifecycle_diagnostic(plugin_registry, callbacks_run:, active_runner_phases:) ⇒ Object
- .plugin_names_from_config(config) ⇒ Object
- .plugin_registry_for_project(project_root) ⇒ Object
- .polyform_licenses?(licenses) ⇒ Boolean
- .post_apply_steps(project_root, report) ⇒ Object
- .postprocess_funding_markdown_content(content, facts) ⇒ Object
- .postprocess_readme_content(content, facts, project_root: nil, destination_content: nil) ⇒ Object
- .preceding_comment_block_start_line(lines, line_number) ⇒ Object
- .preferred_template_source(template_root, configured_source, opencollective_disabled: false) ⇒ Object
- .preferred_template_token_value(derived_value, config_value, env, env_key) ⇒ Object
- .preflight_project!(project_root) ⇒ Object
- .preflight_ruby_syntax!(project_root, path) ⇒ Object
- .prepare_github_workflow_template(content, recipe, facts) ⇒ Object
- .prepare_readme_template(content, readme_style) ⇒ Object
- .present_template_token_value?(value) ⇒ Boolean
- .preserve_destination_gemfile_source(content, destination_content) ⇒ Object
- .preserve_destination_only_gemspec_metadata(content, template_content:, destination_content:, template_receiver:, destination_receiver:) ⇒ Object
- .preserve_destination_readme_kloc_badge(content, destination_content) ⇒ Object
- .preserve_gemspec_dependency_lines(template_content, destination_content, template_receiver:, destination_receiver:, facts: nil) ⇒ Object
- .preserve_gemspec_freeze_blocks(content, destination_content, facts:, receiver:) ⇒ Object
- .preserve_github_workflow_project_settings(recipe, content, destination_content, project_root:) ⇒ Object
- .preserve_mise_project_settings(recipe, content, destination_content, project_root:, facts:) ⇒ Object
- .preserve_newer_github_workflow_action_pins(content, destination_content) ⇒ Object
- .preserve_readme_front_sections(template_content, destination_content) ⇒ Object
- .preserve_readme_h1(merged_content, destination_content, preserve_config) ⇒ Object
- .preserve_readme_managed_block(merged_content, destination_content, marker) ⇒ Object
- .preserve_readme_sections(template_content, destination_content, preserve_config) ⇒ Object
- .previous_nonblank_line_number(content, line_number) ⇒ Object
- .prism_call_nodes(node) ⇒ Object
- .prism_parse_success(content) ⇒ Object
- .prism_ruby_merge_options(recipe) ⇒ Object
- .prism_subtree_contains_call?(node, call_name) ⇒ Boolean
- .prism_subtree_contains_simplecov_require?(node) ⇒ Boolean
- .prism_subtree_contains_string?(node, string) ⇒ Boolean
- .process_result_adapter_failure?(merge_result) ⇒ Boolean
- .project_appraisals_recording_enabled?(project_root) ⇒ Boolean
- .project_entrypoint_require(project_root, package_name, config: nil) ⇒ Object
- .project_gemspec_declares_version_gem?(project_root) ⇒ Boolean
- .project_gemspec_metadata(project_root, gemspec_path, spec: nil) ⇒ Object
- .project_gemspec_version(project_root) ⇒ Object
- .project_homepage_uri(config, env, yard_host:, gemspec_homepage_uri: nil) ⇒ Object
- .project_namespace(entrypoint_namespace:, version_namespace:, metadata_namespace:, default_namespace:) ⇒ Object
- .project_recording_enabled?(project_root, config) ⇒ Boolean
- .project_relative_path(path, project_root) ⇒ Object
- .project_runtime_config_value(config, key) ⇒ Object
- .project_runtime_facts(config, env, package_name:, source_url:, author_domain:, min_ruby:, test_min_ruby:, version:, project_root: nil, gemspec_metadata: {}, repository: {}) ⇒ Object
- .project_runtime_template_tokens(project_runtime) ⇒ Object
- .project_uses_version_gem?(project_root, _entrypoint_require, facts = nil) ⇒ Boolean
- .project_yard_host(config, env, package_name:, author_domain:) ⇒ Object
- .prune_appraisals_below_min_ruby(content, min_ruby) ⇒ Object
- .prune_appraisals_recording_entries(content, facts) ⇒ Object
- .prune_disabled_github_workflow_engine_jobs(content, facts) ⇒ Object
- .prune_empty_parent_directories(project_root, relative_path) ⇒ Object
- .prune_github_workflow_matrix_by_min_ruby(content, facts) ⇒ Object
- .prune_legacy_kettle_config_keys(content) ⇒ Object
- .prune_missing_workflow_link_definitions(content, workflow_paths) ⇒ Object
- .prune_readme_integration_badges(content, readme_style) ⇒ Object
- .prune_unused_readme_logo_link_definitions(content) ⇒ Object
- .prune_workflow_matrix_item?(mapping, minimum) ⇒ Boolean
- .quality_config_path?(path) ⇒ Boolean
- .rakefile_default_task_call?(call) ⇒ Boolean
- .rakefile_default_task_records(content) ⇒ Object
- .rakefile_require_records(content) ⇒ Object
- .rakefile_scaffold_cleanup(content, facts) ⇒ Object
- .rakefile_scaffold_cleanup_recipe?(recipe) ⇒ Boolean
- .rakefile_scaffold_delete_selectors(content) ⇒ Object
- .rakefile_selector(selector_id, start_line, end_line, reason) ⇒ Object
- .rakefile_task_block_selectors(content) ⇒ Object
- .rakefile_task_class_records(content) ⇒ Object
- .rakefile_template_default_task?(content, record) ⇒ Boolean
- .rbs_merge_options(recipe) ⇒ Object
- .read_project_file(project_root, relative_path) ⇒ Object
- .read_project_files(project_root, pack) ⇒ Object
- .read_template_source_files(project_root, pack) ⇒ Object
- .readme_config_hash(config) ⇒ Object
- .readme_copyright_notice(copyright_lines, copyright_prefix, author) ⇒ Object
- .readme_corporate_sponsor_template_tokens(readme_sponsors) ⇒ Object
- .readme_corporate_sponsors(config, env) ⇒ Object
- .readme_corporate_sponsors_facts(config, env) ⇒ Object
- .readme_corporate_sponsors_row(sponsors) ⇒ Object
- .readme_default_logo_width(entries, one:, two:) ⇒ Object
- .readme_destination_front_sections(destination_content) ⇒ Object
- .readme_dev_test_stack_table(package_name) ⇒ Object
- .readme_disabled_integrations(readme, integration_disabled: []) ⇒ Object
- .readme_extra_preserved_sections_by_anchor(destination_sections, template_bases, preserve_targets) ⇒ Object
- .readme_family_intro_and_backend_matrix(readme_style = {}) ⇒ Object
- .readme_floss_funding_enabled?(license, config_value) ⇒ Boolean
- .readme_fossa_project(readme, repository) ⇒ Object
- .readme_fossa_template_tokens(readme_style) ⇒ Object
- .readme_front_section_preserved?(section) ⇒ Boolean
- .readme_h2_synopsis_logo_entries(config, org:, gem_name:, repository: {}) ⇒ Object
- .readme_h2_synopsis_logo_options(config) ⇒ Object
- .readme_h2_synopsis_logo_row(entries) ⇒ Object
- .readme_h2_synopsis_logo_specs(config) ⇒ Object
- .readme_integration_configured?(project_root, integration) ⇒ Boolean
- .readme_integration_project_root(project_root, template_profile, repository) ⇒ Object
- .readme_kloc_from_changelog(project_root, version) ⇒ Object
- .readme_license_intro(licenses, author_email: nil, license_source_url: nil, custom_license: false) ⇒ Object
- .readme_license_refs(expression, compat_category, license_source_url: nil) ⇒ Object
- .readme_logo_config_value(spec) ⇒ Object
- .readme_logo_facts(config, package_name:, github_org:, repository: {}) ⇒ Object
- .readme_logo_html(entry, align:, width: nil) ⇒ Object
- .readme_logo_options_from_config(config, primary_key, secondary_key, defaults) ⇒ Object
- .readme_logo_specs_from_config(config, primary_key, secondary_key, defaults) ⇒ Object
- .readme_logo_template_tokens(readme_logo) ⇒ Object
- .readme_metadata_block(facts) ⇒ Object
- .readme_metadata_license_expression(facts) ⇒ Object
- .readme_metadata_table_cell(value) ⇒ Object
- .readme_preserve_config(config) ⇒ Object
- .readme_preserve_config_without_partial_sections(preserve_config, partial_sections) ⇒ Object
- .readme_preserve_targets(template_sections, destination_lookup, preserve_config) ⇒ Object
- .readme_project_emoji(project_root) ⇒ Object
- .readme_section_contains_badge_cloud?(section) ⇒ Boolean
- .readme_section_has_preserved_ancestor?(sections, index, preserve_targets) ⇒ Boolean
- .readme_section_partials(project_root, config, readme) ⇒ Object
- .readme_section_partials_for_render(readme_style, facts) ⇒ Object
- .readme_star_history_facts(project_root, git_source_url) ⇒ Object
- .readme_style_facts(project_root, config, license, template_profile: nil, repository: nil) ⇒ Object
- .readme_template_tokens(facts) ⇒ Object
- .readme_title_token(package, rubygems) ⇒ Object
- .readme_top_logo_credit_separator(type) ⇒ Object
- .readme_top_logo_default_alt(type, slug) ⇒ Object
- .readme_top_logo_entries(config, org:, gem_name:, repository: {}) ⇒ Object
- .readme_top_logo_entries_with_asset_size(entries) ⇒ Object
- .readme_top_logo_entry_from_config(logo, org:, gem_name:, repository: {}) ⇒ Object
- .readme_top_logo_entry_from_option(option, org:, gem_name:, repository: {}) ⇒ Object
- .readme_top_logo_image_url(type, slug) ⇒ Object
- .readme_top_logo_options(config) ⇒ Object
- .readme_top_logo_refs(entries) ⇒ Object
- .readme_top_logo_row(entries) ⇒ Object
- .readme_url_template_tokens(repository, package_name, github_org) ⇒ Object
- .readme_workflow_path_from_url(url) ⇒ Object
- .readme_workflow_paths(project_root) ⇒ Object
- .recipe_decision_category(recipe) ⇒ Object
- .recipe_decision_diagnostics(recipe) ⇒ Object
- .recipe_decision_evaluation(decision_policy:, recipe:, changed:, destination_existed:) ⇒ Object
- .recipe_default_action(recipe, changed:, destination_existed:) ⇒ Object
- .recipe_entry(name, target_path, provider_family, primitive, facts:, provider_backend: nil, selectors: []) ⇒ Object
- .recipe_filter_patterns(template_selection) ⇒ Object
- .recipe_pack(facts) ⇒ Object
- .recipe_planning_strategy_for(env, run_options) ⇒ Object
- .recipe_planning_thread_workers_for(env, run_options) ⇒ Object
- .recipe_planning_workers_for(env, run_options) ⇒ Object
- .recipe_report_metadata(recipe) ⇒ Object
- .recipe_report_phase(recipe_report) ⇒ Object
- .recipe_run_stats(recipe_reports, diagnostics: []) ⇒ Object
- .recipe_run_stats_summary(stats) ⇒ Object
- .recipe_runtime_context(recipe, facts, deletion) ⇒ Object
- .recipe_template_content(project_root, recipe, template_contents: nil) ⇒ Object
- .recipe_template_content_path(project_root, recipe) ⇒ Object
- .reconcile_existing_version_namespace(project_root, entrypoint_path, version_path, namespace) ⇒ Object
- .record_file_work_execution_stats(stats, units:, workers:, thread_workers:) ⇒ Object
- .record_phase_timing(events, phase, status:, duration_ms:, payload:) ⇒ Object
- .record_recipe_planning_execution_stats(stats, worker_safe:, main_only:, worker_count:, spawned:, ractor_recipes:, thread_worker_count:, thread_spawns:, thread_recipes:, main_recipes:) ⇒ Object
- .redundant_templating_guard_wrapper_node?(node) ⇒ Boolean
- .remove_duplicate_comment_span_before_marker(content, start_marker:, end_marker:) ⇒ Object
-
.remove_duplicate_framework_matrix_documentation(content) ⇒ Object
YAML parsers do not retain comments.
- .remove_duplicate_gemspec_assignments(content, receiver:, fields:) ⇒ Object
-
.remove_duplicate_gemspec_dependency_lines(content, receiver:) ⇒ Object
Template dependencies precede preserved destination dependencies.
- .remove_duplicate_readme_preservation_documentation(content) ⇒ Object
- .remove_duplicate_simplecov_do_cov_bootstrap_blocks(content) ⇒ Object
- .remove_duplicate_simplecov_requires(content) ⇒ Object
- .remove_empty_gemspec_development_dependency_section_headings(content, receiver:) ⇒ Object
- .remove_entrypoint_version_requires(content, relative_path:, absolute_path:) ⇒ Object
- .remove_excluded_changelog_transfer_entries(content, excluded_keys) ⇒ Object
- .remove_gemfile_dependency_blocks(content, gem_names) ⇒ Object
- .remove_gemfile_dependency_lines(content, gem_names) ⇒ Object
- .remove_gemfile_percent_w_entries(content, gem_names) ⇒ Object
- .remove_gemspec_assignment(content, receiver:, field:) ⇒ Object
- .remove_gemspec_dependency_lines(content, receiver:, names:, runtime_only: false, development_only: false) ⇒ Object
- .remove_gemspec_development_dependencies_already_runtime(content, receiver:) ⇒ Object
- .remove_gemspec_legacy_version_loader_preamble(content) ⇒ Object
- .remove_gemspec_self_dependency_lines(content, package_name, receiver:) ⇒ Object
- .remove_gemspec_version_gem_dependency_when_disabled(content, facts, receiver:, template_declares_version_gem: false) ⇒ Object
- .remove_gemspec_version_gem_dependency_when_non_default_entrypoint(content, facts, receiver:) ⇒ Object
- .remove_line_ranges(content, ranges) ⇒ Object
- .remove_managed_stdlib_appraisal_gems(content) ⇒ Object
- .remove_managed_stdlib_gems_from_appraisal_block(block) ⇒ Object
- .remove_obsolete_local_gemfile_nomono_activation(content) ⇒ Object
- .remove_obsolete_simplecov_keep_destination_config(content) ⇒ Object
- .remove_obsolete_simplecov_rescue_bootstrap_blocks(content) ⇒ Object
- .remove_readme_badge_and_refs(content, badge_source, link_labels) ⇒ Object
- .remove_readme_sections(content, section_bases) ⇒ Object
- .remove_ruby_comment_lines_containing(content, text) ⇒ Object
- .remove_stale_executable_startup_header(content, header) ⇒ Object
- .remove_stale_gemspec_file_override_blocks!(lines, files_index, gemspec) ⇒ Object
- .remove_stale_generated_gemspec_homepage_replacement(replacements, destination_content, facts, receiver:) ⇒ Object
- .remove_stale_main_gemfile_direct_sibling_block(content, template_content) ⇒ Object
- .remove_stale_main_gemfile_tree_sitter_language_pack(content, template_content) ⇒ Object
- .remove_top_level_ruby_require(content, argument) ⇒ Object
- .remove_top_level_yaml_key_lines(content, key) ⇒ Object
- .remove_version_gem_class_eval_references(content) ⇒ Object
- .remove_version_gem_entrypoint_references(content) ⇒ Object
- .remove_version_gem_shared_example(content) ⇒ Object
- .remove_x_std_lib_eval_for_gem(content, gem_name) ⇒ Object
- .remove_yaml_mapping_path(content, path) ⇒ Object
- .remove_yaml_scalar_path(content, path) ⇒ Object
- .render_thin_readme(facts, readme_style, original, preserve_config) ⇒ Object
- .replace_existing_markdown_managed_block(content, marker, replacement) ⇒ Object
- .replace_gemspec_assignment_sources(content, replacements, receiver:) ⇒ Object
- .replace_gemspec_version_assignment(content, receiver:, rhs:) ⇒ Object
- .replace_github_workflow_action_pin_sha(line, sha) ⇒ Object
- .replace_kettle_config_bootstrap_licenses(content, licenses) ⇒ Object
- .replace_kettle_config_bootstrap_project_emoji(content, emoji) ⇒ Object
- .replace_kettle_config_bootstrap_rubyforum(content, rubyforum) ⇒ Object
- .replace_local_gems_assignment(content, gems) ⇒ Object
- .replace_markdown_managed_block(content, marker, replacement) ⇒ Object
- .replace_markdown_managed_block_with_crispr(content, open_marker, close_marker, replacement) ⇒ Object
- .replace_markdown_with_ast_crispr(content, target, replacement) ⇒ Object
- .replace_matching_gemspec_dependency_lines(content, destination_dependencies, receiver:) ⇒ Object
- .replace_record_ranges(content, records_by_line) ⇒ Object
- .replace_ruby_managed_block(content, replacement) ⇒ Object
- .replace_ruby_managed_block_with_crispr(content, open_marker, close_marker, replacement) ⇒ Object
- .replace_source_byte_range(content, start_offset, end_offset, replacement) ⇒ Object
- .replace_source_offsets(content, replacements) ⇒ Object
- .replace_source_range_lines(content, start_line, end_line, replacement) ⇒ Object
- .replace_text_managed_block(content, replacement) ⇒ Object
- .replace_text_managed_block_with_crispr(content, open_marker, close_marker, replacement) ⇒ Object
- .replace_toml_string_scalar_line(content, key, value) ⇒ Object
- .replace_word_array_assignment(content, name, gems) ⇒ Object
- .replace_yaml_node_lines(content, key, replacement) ⇒ Object
- .replace_yaml_scalar_line(content, key, value) ⇒ Object
- .replace_yaml_scalar_path(content, path, value) ⇒ Object
- .replacement_for_supported_gemspec_files_assignment(template_record:, destination_record:, template_receiver:) ⇒ Object
- .report_with_duration(report, duration_ms) ⇒ Object
- .reported_post_apply_changed_files(step) ⇒ Object
- .repository_facts(project_root, source_url, package_name:, repository_topology:) ⇒ Object
- .repository_monorepo_subproject?(repository) ⇒ Boolean
- .repository_name_from_source_url(source_url) ⇒ Object
- .repository_project_logo_href(repository, slug:, org:, gem_name:) ⇒ Object
- .repository_project_logo_slug(repository, org:, gem_name:) ⇒ Object
- .repository_resource_urls(repository) ⇒ Object
- .repository_root_url(source_url) ⇒ Object
- .repository_topology_for(config, env, template_selection) ⇒ Object
- .required_ruby_version_rubocop_disable(min_ruby) ⇒ Object
- .resolve_template_tokens(content, tokens, scan_unresolved: true) ⇒ Object
- .resolve_uncommitted_author!(project_root, author_map) ⇒ Object
- .resolved_licenses(config, gemspec_licenses) ⇒ Object
- .retired_gemspec_development_dependency_key?(key) ⇒ Boolean
- .rewrite_gemspec_version_loader(content, facts:) ⇒ Object
- .rewrite_markdown_reference_links(content, links) ⇒ Object
- .rubocop_target_ruby_token(min_ruby) ⇒ Object
- .rubocop_template_tokens(min_ruby, ruby_style: {}) ⇒ Object
- .rubocop_tokens_for(min_ruby) ⇒ Object
- .ruby_appraisal_name_version(name) ⇒ Object
- .ruby_appraisal_names_below(content, min_ruby) ⇒ Object
- .ruby_array_literal(values) ⇒ Object
- .ruby_bucket_path_segment?(segment) ⇒ Boolean
- .ruby_call_records(content, call_name) ⇒ Object
- .ruby_constant_path_segments(node) ⇒ Object
- .ruby_double_quoted_string_body(value) ⇒ Object
- .ruby_engines_config(config) ⇒ Object
- .ruby_entrypoint_module_namespace(content, expected_depth: nil) ⇒ Object
- .ruby_entrypoint_module_namespace_for(node, namespace, expected_depth: nil) ⇒ Object
- .ruby_entrypoint_outer_namespace_kind(content, namespace) ⇒ Object
- .ruby_first_simple_quoted_string_node(node) ⇒ Object
- .ruby_first_string_argument(owner) ⇒ Object
- .ruby_keyword_argument_node(call, key) ⇒ Object
- .ruby_keyword_string_argument(call, key) ⇒ Object
- .ruby_library_source_paths(project_root) ⇒ Object
- .ruby_local_word_array_assignments(root) ⇒ Object
- .ruby_merge_options(recipe, merge_template_requires:) ⇒ Object
- .ruby_method_move_policy(recipe) ⇒ Object
- .ruby_multiline_word_array_source(names, indent:) ⇒ Object
- .ruby_namespace_declaration_kind(content, namespace) ⇒ Object
- .ruby_namespace_declaration_kind_for(node, namespace, target) ⇒ Object
- .ruby_namespace_declaration_node(content, namespace) ⇒ Object
- .ruby_namespace_declaration_node_for(node, namespace, target) ⇒ Object
- .ruby_node_source_end_line(node) ⇒ Object
- .ruby_parse_comments(analysis) ⇒ Object
- .ruby_project_version_constant_path?(node, namespace:) ⇒ Boolean
- .ruby_project_version_embedded_statements?(node, namespace:) ⇒ Boolean
- .ruby_project_version_interpolated_string_source(node, receiver:, namespace:) ⇒ Object
- .ruby_require_aliases(recipe, facts = nil) ⇒ Object
- .ruby_require_call?(owner, method_name, argument) ⇒ Boolean
- .ruby_simple_quoted_string_node?(node) ⇒ Boolean
- .ruby_static_interpolated_string_value(node) ⇒ Object
- .ruby_static_string_array_value(node, local_word_arrays = {}) ⇒ Object
- .ruby_static_string_call_value(node) ⇒ Object
- .ruby_static_string_value(node) ⇒ Object
- .ruby_string_argument(call) ⇒ Object
- .ruby_string_argument_at(call, index) ⇒ Object
- .ruby_string_arguments(call) ⇒ Object
- .ruby_style_facts(project_root) ⇒ Object
- .ruby_style_template_tokens(ruby_style) ⇒ Object
- .ruby_template_policy_report(recipe:, request:, original:, final:) ⇒ Object
- .ruby_top_level_require?(content, method_name, argument) ⇒ Boolean
- .ruby_top_level_require_records(content) ⇒ Object
- .ruby_version_class_eval_namespaces(content) ⇒ Object
- .ruby_version_constant_value(content) ⇒ Object
- .ruby_version_module_namespace(content) ⇒ Object
- .ruby_version_module_namespace_for(node, namespace) ⇒ Object
- .ruby_word_array_names(node) ⇒ Object
- .ruby_word_array_node?(node) ⇒ Boolean
- .ruby_word_array_nodes(content) ⇒ Object
- .ruby_word_array_records(content) ⇒ Object
- .rubyforum_badge_image_url(style: "flat") ⇒ Object
- .rubyforum_facts(config, env, package_name:) ⇒ Object
- .rubyforum_tag_url(tag) ⇒ Object
- .rubyforum_template_tokens(rubyforum) ⇒ Object
- .rubygems_version_gem_entrypoint_mode(rubygems_config) ⇒ Object
- .run_apply_phases(project_root, report, file_workers: 0, file_thread_workers: 0, file_stats: nil) ⇒ Object
- .runtime_context_value(request, *path) ⇒ Object
- .runtime_gemspec_dependency_insertion_index(lines, receiver:) ⇒ Object
- .runtime_workspace_override_records(content) ⇒ Object
- .security_supported_version_token(version) ⇒ Object
- .selected_template_path?(relative_path, patterns) ⇒ Boolean
- .semantic_readme_heading(text) ⇒ Object
- .set_template_file_strategy!(config, target_path, strategy) ⇒ Object
- .setup_execution_context(env, run_options) ⇒ Object
- .setup_guidance_diagnostic(config_existed:) ⇒ Object
- .setup_project(project_root, env: ENV, run_options: {}, command_runner: nil) ⇒ Object
- .shield_token(value) ⇒ Object
- .shim_facts(config, env, run_options, package_name:, entrypoint_require:, template_profile:) ⇒ Object
- .shim_profile_cleanups(project_root, facts, preferences, template_selection: {}) ⇒ Object
- .shim_replacement_namespace(replacement_require) ⇒ Object
- .shim_template_entries(facts, config) ⇒ Object
- .shim_template_entries_for_config(gemspec_path, config) ⇒ Object
- .shim_template_profile?(facts) ⇒ Boolean
- .shim_template_tokens(shim) ⇒ Object
- .shim_version_file_content(namespace:, replacement_namespace:, replacement_require:) ⇒ Object
- .shunted_dependency_has_floor_compatible_version?(resolver, dependency, versions, floor) ⇒ Boolean
- .shunted_dependency_has_modular_override?(project_root, dependency) ⇒ Boolean
- .shunted_effective_floor(min_ruby) ⇒ Object
- .shunted_gemfile_block(gemspec, facts, run_options) ⇒ Object
- .shunted_gemfile_managed_block(dependencies) ⇒ Object
- .sibling_gemspec_metadata(sibling_path, gem_name) ⇒ Object
- .simplecov_bootstrap_call_node?(node) ⇒ Boolean
- .simplecov_config_require_call_node?(node) ⇒ Boolean
- .simplecov_config_require_call_nodes(content) ⇒ Object
- .simplecov_config_require_call_records(content) ⇒ Object
- .simplecov_do_cov_bootstrap_complete_node?(node) ⇒ Boolean
- .simplecov_do_cov_bootstrap_only_node?(node) ⇒ Boolean
- .simplecov_do_cov_bootstrap_records(content) ⇒ Object
- .simplecov_do_cov_predicate_node?(node) ⇒ Boolean
- .simplecov_kettle_soup_cover_require_call_node?(node) ⇒ Boolean
- .simplecov_load_error_guard_call_node?(node) ⇒ Boolean
- .simplecov_obsolete_call_nodes(content) ⇒ Object
- .simplecov_require_call_node?(node) ⇒ Boolean
- .simplecov_require_call_records(content) ⇒ Object
- .simplecov_start_call_node?(node) ⇒ Boolean
- .simplecov_start_call_nodes(content) ⇒ Object
- .skip_disabled_integration_template?(target_path, config) ⇒ Boolean
- .skip_packaged_gemfile_template?(target_path, config, project_root: nil, template_root_path: PACKAGED_TEMPLATE_ROOT) ⇒ Boolean
- .skip_packaged_license_template?(target_path, config) ⇒ Boolean
- .skip_packaged_version_gem_entrypoint_template?(project_root, source_path, target_path, config) ⇒ Boolean
- .skip_packaged_workflow_template?(target_path, config, include_patterns: nil) ⇒ Boolean
- .skywalking_eyes_disabled_by_default?(config, license, disabled) ⇒ Boolean
- .snapshot_changed_files(project_root, changed_files) ⇒ Object
- .social_facts(config, env) ⇒ Object
- .social_template_tokens(social) ⇒ Object
- .social_token_value(social_config, env, key) ⇒ Object
- .sort_runtime_gemspec_dependency_lines(content, receiver:) ⇒ Object
- .source_blob_url(source_url, path) ⇒ Object
- .source_tree_url(source_url, path) ⇒ Object
- .spdx_basename(spdx_id) ⇒ Object
- .spdx_from_basename(basename) ⇒ Object
- .spec_helper_simplecov_do_cov_bootstrap_source(indent) ⇒ Object
- .stale_executable_startup_header(ast, require_call:, namespaces:) ⇒ Object
- .stale_generated_gemspec_files_group?(group) ⇒ Boolean
- .stale_generated_gemspec_package_glob?(path) ⇒ Boolean
- .stale_generated_gemspec_splat_key?(key) ⇒ Boolean
- .stale_github_workflow_template_pin_records(relative_path, final_content, destination_content) ⇒ Object
- .stale_main_gemfile_gem_comment?(line, gem_name) ⇒ Boolean
- .stale_main_gemfile_gem_comment_start_line(lines, start_line, gem_name) ⇒ Object
- .stale_versioned_engine_workflow?(relative_path) ⇒ Boolean
- .standard_test_appraisal_names(content) ⇒ Object
- .static_gemspec_metadata_assignment(content, key) ⇒ Object
- .static_gemspec_metadata_key_assigned?(content, key) ⇒ Boolean
- .static_project_gemspec_metadata(gemspec_path) ⇒ Object
- .step_event_mark(step) ⇒ Object
- .step_report_metadata(recipe, deletion) ⇒ Object
- .stringify_keys_for_json(value) ⇒ Object
- .stringify_template_tokens(tokens) ⇒ Object
- .strip_leading_decorative_graphemes(text) ⇒ Object
- .strip_orphaned_rake_task_requires(content) ⇒ Object
- .strip_readme_heading_adornment(text) ⇒ Object
-
.supported_gemspec_files_nonliteral_group?(group) ⇒ Boolean
Accept only the generated package helpers that can safely survive a template revision.
- .sync_author_names_documentation_comment(content) ⇒ Object
- .sync_kettle_config_documentation_comments(content) ⇒ Object
- .sync_kettle_config_env_overrides(content, env) ⇒ Object
- .sync_kettle_config_gemspec_strategy_lines!(lines, gemspec_path) ⇒ Object
- .sync_kettle_config_internal_values(content) ⇒ Object
- .sync_kettle_config_monorepo_subgem_profile(content, gemspec_path, profile) ⇒ Object
- .sync_kettle_config_project_hostnames(content) ⇒ Object
- .sync_kettle_config_rakefile_strategy_lines!(lines) ⇒ Object
- .sync_readme_top_logos_documentation_comment(content) ⇒ Object
- .synchronize_github_actions_ci(content, facts) ⇒ Object
- .synchronize_github_actions_coverage_ci(content, facts) ⇒ Object
- .synchronize_github_actions_framework_ci(content, facts) ⇒ Object
- .synchronize_github_actions_framework_gemfile(target_path, facts) ⇒ Object
- .synchronize_github_actions_workflow_snippets(content, facts: {}) ⇒ Object
- .synchronize_github_funding_yml(content, facts) ⇒ Object
- .synchronize_managed_block(content, facts) ⇒ Object
- .synchronize_readme(content, facts, project_root: nil) ⇒ Object
- .template_activation_config(config) ⇒ Object
- .template_entries(project_root, root, templates) ⇒ Object
- .template_entry_apply?(entry, apply_templates) ⇒ Boolean
- .template_entry_paths(entry) ⇒ Object
-
.template_file_outcomes(recipe_reports) ⇒ Object
Reduce overlays by path so post-planning outcome counts describe destination files, not individual recipes.
- .template_file_strategy_config(config, target_path) ⇒ Object
- .template_file_type(recipe) ⇒ Object
- .template_file_type_for_relative_path(relative_path) ⇒ Object
- .template_input_fingerprint(project_root, report) ⇒ Object
- .template_input_fingerprint_payload(project_root, report) ⇒ Object
- .template_inventory_entries(project_root, template_root_path, templates: {}) ⇒ Object
- .template_inventory_target_path(project_root, logical_path) ⇒ Object
- .template_keep_destination_path?(config, target_path) ⇒ Boolean
- .template_legacy_destination_cleanups(project_root, preferences) ⇒ Object
- .template_lock_state(project_root) ⇒ Object
- .template_manifest(project_root: Dir.pwd, template_root: nil, config: nil) ⇒ Object
- .template_obsolete_license_cleanups(project_root, config, preferences, license_txt: {}) ⇒ Object
- .template_pattern_strategy_config(config, target_path) ⇒ Object
- .template_root(project_root, templates) ⇒ Object
- .template_root_path(project_root = Dir.pwd, config: nil) ⇒ Object
- .template_runtime_config(config, facts, license: {}) ⇒ Object
- .template_selection_for(env, run_options) ⇒ Object
- .template_source_absolute_path(project_root, preference) ⇒ Object
- .template_source_application_worker_safe?(recipe) ⇒ Boolean
- .template_source_display_path(template_root, selected_source) ⇒ Object
- .template_source_lock_path(preference) ⇒ Object
- .template_source_preference(project_root, template_root, entry, config, opencollective_disabled: false, include_patterns: nil, apply_templates: false) ⇒ Object
- .template_source_preferences(project_root, config, opencollective_disabled: false, include_patterns: nil) ⇒ Object
- .template_source_selection_reason(configured_source, selected_source) ⇒ Object
- .template_strategy_config(config, target_path) ⇒ Object
- .template_strategy_entry(config, path, entry) ⇒ Object
- .template_tokens(facts, funding) ⇒ Object
- .template_version_gem_bootstrap_step(project_root, report) ⇒ Object
- .templating_guard_records(content) ⇒ Object
- .timed_recipe_report ⇒ Object
- .token_config_values(config) ⇒ Object
- .token_placeholder?(value) ⇒ Boolean
- .toml_string_scalar_line_value(content, key) ⇒ Object
- .top_level_ruby_call_records(content, call_name) ⇒ Object
- .top_level_yaml_key_line?(line) ⇒ Boolean
- .transfer_changelog_context(project_root, env: ENV) ⇒ Object
- .transfer_changelog_entries ⇒ Object
- .transfer_changelog_entry_applies?(entry, context) ⇒ Boolean
- .transfer_changelog_entrypoint_require(project_root, rubygems) ⇒ Object
- .transfer_changelog_filter_applies?(filter, context) ⇒ Boolean
- .transfer_changelog_filter_field_types ⇒ Object
- .transfer_changelog_filter_predicate_applies?(type, actual, operator, expected) ⇒ Boolean
- .transfer_changelog_gemspec_assignment(project_root, field) ⇒ Object
-
.transfer_changelog_lag(last_entry_key = nil, verbose: false) ⇒ Object
Compatibility API for callers released before filter-aware replay.
-
.transfer_changelog_min_ruby(project_root, rubygems) ⇒ Object
Do not call discover_facts here.
- .transfer_changelog_package_name(project_root) ⇒ Object
- .transfer_changelog_status(project_root, env: ENV, verbose: false) ⇒ Object
- .trim_trailing_blank_lines(content) ⇒ Object
- .truthy_config?(value) ⇒ Boolean
- .uncomment_ruby_comment_line(comment_source) ⇒ Object
- .unresolved_template_scan?(recipe) ⇒ Boolean
- .update_github_actions_pins(content) ⇒ Object
- .valid_gem_version?(version) ⇒ Boolean
- .validate_changelog_transfer_entries!(entries, path) ⇒ Object
- .validate_kettle_jem_config!(config) ⇒ Object
-
.validate_modular_dependency_conflicts!(project_root, recipe_reports) ⇒ Object
A dependency owned directly by the project must not also be introduced by a generated modular Gemfile.
- .version_bootstrap_source_state(report, before_apply_files) ⇒ Object
- .version_file_includes_version_module?(content) ⇒ Boolean
- .version_gem_bootstrap_entrypoint_content(content, namespace:, entrypoint_require:, namespace_superclasses: {}, version_require_path: nil) ⇒ Object
- .version_gem_bootstrap_entrypoint_path(project_root, package_name, entrypoint_require, package_entrypoint_preexisting: true) ⇒ Object
- .version_gem_bootstrap_step(project_root, facts) ⇒ Object
- .version_gem_bootstrap_step_for_paths(project_root, facts, manage_version_file: true, manage_signature_file: true, package_entrypoint_preexisting: true, preserve_version_module_include: nil, namespace_kinds_override: {}) ⇒ Object
- .version_gem_class_eval_block(namespace) ⇒ Object
- .version_gem_class_eval_call?(call) ⇒ Boolean
- .version_gem_class_eval_selectors(content) ⇒ Object
- .version_gem_cleanup_step(project_root, facts, cleanup_entrypoint: true, after_declarations: false, entrypoint_path: nil) ⇒ Object
- .version_gem_default_enabled_for_project?(rubygems_config, gemspec_metadata) ⇒ Boolean
- .version_gem_enabled?(facts) ⇒ Boolean
- .version_gem_entrypoint_file_content(namespace:, entrypoint_require:, dedicated: false) ⇒ Object
- .version_gem_explicitly_disabled?(facts) ⇒ Boolean
- .version_gem_facts_for_project(project_root, entrypoint_require, mode: "") ⇒ Object
- .version_gem_free_entrypoint_content(content, entrypoint_require:, ensure_version_require: true, after_declarations: false, version_require_path: nil) ⇒ Object
- .version_gem_post_apply_selected?(report, entrypoint_require) ⇒ Boolean
- .version_gem_require_insertion_index(content, before_relative_path: nil) ⇒ Object
- .version_gem_runtime_compatible?(facts) ⇒ Boolean
- .version_gem_signature_file_content(namespace:, outer_namespace_kind: :module, namespace_kinds: {}) ⇒ Object
- .version_gem_template_entries(gemspec_path) ⇒ Object
- .version_gem_template_target_path(gemspec_path, source) ⇒ Object
- .version_gem_template_target_path?(target_path) ⇒ Boolean
- .version_gem_template_target_path_for_project(project_root, gemspec_path, source) ⇒ Object
- .version_gem_template_tokens(facts) ⇒ Object
- .version_gem_version_file_content(existing_version:, namespace:, version:, outer_namespace_kind: :module, namespace_kinds: {}, preserve_version_module_include: false) ⇒ Object
- .version_gem_version_spec_content(namespace:) ⇒ Object
- .version_namespace_kinds_from_facts(facts) ⇒ Object
- .version_namespace_outer_kind(project_root, entrypoint_path, namespace) ⇒ Object
- .version_namespace_outer_kind_for_template(project_root, facts, entrypoint_path, version_path, namespace) ⇒ Object
- .version_namespace_superclasses_from_facts(facts) ⇒ Object
- .version_namespace_template_file?(relative_path) ⇒ Boolean
- .version_require_path_for_entrypoint(entrypoint_path, version_path) ⇒ Object
- .version_spec_anonymous_loader_call?(content) ⇒ Boolean
- .version_spec_package_entrypoint_require(project_root, package_name, entrypoint_require) ⇒ Object
- .version_spec_relative_version_gem_path(version_spec_path, entrypoint_require) ⇒ Object
- .version_spec_relative_version_path(version_spec_path, entrypoint_require) ⇒ Object
- .version_spec_require_insertion_index(content) ⇒ Object
- .version_spec_rspec_describe_call(content) ⇒ Object
- .versioned_gem_name_parts(name) ⇒ Object
- .versioned_gem_name_update_candidate?(destination_name, template_name) ⇒ Boolean
- .with_event_phase(events, phase, payload = {}) ⇒ Object
- .with_git_operation_lock(env) ⇒ Object
- .with_readme_timing(name) ⇒ Object
- .with_readme_timing_context(relative_path, timings) ⇒ Object
- .word_array_assignment(content, name) ⇒ Object
- .word_array_assignment_record(content, name) ⇒ Object
- .worker_safe_recipe?(recipe) ⇒ Boolean
- .worker_safe_recipe_payload(recipe, project_root:, template_contents:) ⇒ Object
- .workflow_job_env_existing_keys(lines, bundle_index, indent_length) ⇒ Object
- .workflow_matrix_env_indent(lines, mapping) ⇒ Object
- .workflow_matrix_env_insert_index(lines, mapping) ⇒ Object
- .workflow_recipe_slug(workflow_path) ⇒ Object
- .wrap_ruby_namespace(namespace, body_lines, outer_namespace_kind: :module, namespace_kinds: {}, namespace_superclasses: {}) ⇒ Object
- .write_consolidated_version_signature(project_root, signature_path, legacy_signature_paths, namespace:, outer_namespace_kind: :module, namespace_kinds: {}) ⇒ Object
- .write_if_changed(project_root, relative_path, content) ⇒ Object
- .write_intent_from_recipe_report(project_root, recipe_report) ⇒ Object
- .write_intents_for_phase(project_root, recipe_reports) ⇒ Object
- .yaml_config_scalar_literal(value, path:) ⇒ Object
- .yaml_contains_key_value?(node, key, value) ⇒ Boolean
- .yaml_double_quoted_scalar(value) ⇒ Object
- .yaml_line_comment_suffix(line, key_index) ⇒ Object
- .yaml_mapping_nodes(content) ⇒ Object
- .yaml_mapping_path_entries(content) ⇒ Object
- .yaml_mapping_scalar_node(mapping, key) ⇒ Object
- .yaml_mapping_scalar_value(mapping, key) ⇒ Object
- .yaml_mapping_value(mapping, key) ⇒ Object
- .yaml_mapping_value_node(content, key, node_class) ⇒ Object
- .yaml_merge_options(recipe) ⇒ Object
- .yaml_process_result_adapter_failure?(merge_result) ⇒ Boolean
- .yaml_scalar_line_value(content, key) ⇒ Object
- .yaml_scalar_pairs(content) ⇒ Object
- .yaml_scalar_path_entries(content) ⇒ Object
- .yaml_scalar_sequence_at_path(content, path) ⇒ Object
- .yaml_scalar_value_template_tokens(content) ⇒ Object
- .yaml_top_level_key_lines(content) ⇒ Object
Class Method Details
.active_license_basenames(config) ⇒ Object
18724 18725 18726 18727 18728 18729 |
# File 'lib/kettle/jem.rb', line 18724 def active_license_basenames(config) Array(config["resolved_licenses"]) .map { |license| spdx_basename(license) } .reject(&:empty?) .to_set end |
.actual_changed_files_after_apply(project_root, changed_files, before_apply_files) ⇒ Object
4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 |
# File 'lib/kettle/jem.rb', line 4912 def actual_changed_files_after_apply(project_root, changed_files, before_apply_files) changed_files.filter_map do |relative_path| path = File.join(project_root, relative_path) original = before_apply_files.fetch(relative_path, nil) if File.exist?(path) (File.read(path) == original) ? nil : relative_path else original.nil? ? nil : relative_path end end.uniq.sort end |
.adapter_failure_template_source_error(file_type, recipe) ⇒ Object
9283 9284 9285 |
# File 'lib/kettle/jem.rb', line 9283 def adapter_failure_template_source_error(file_type, recipe) ArgumentError.new("failed to merge #{file_type} template #{recipe.fetch(:target_path)}: provider adapter failure") end |
.add_dependency_conflict_review_list(content, conflicts) ⇒ Object
9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 |
# File 'lib/kettle/jem.rb', line 9745 def add_dependency_conflict_review_list(content, conflicts) lines = content.to_s.lines index = lines.index { |line| line.match?(/\Adependency_conflicts:\s*\z/) } unless index lines << "\n" unless lines.empty? || lines.last.strip.empty? lines.concat(["dependency_conflicts:\n", " # Review each entry and choose a supported action.\n", " resolve:\n"]) index = lines.length - 3 end block_end = (index + 1...lines.length).find { |line_index| lines[line_index].match?(/\A\S/) } || lines.length replacement = [ "dependency_conflicts:\n", " # Review each entry and choose a supported action.\n", " # keep_both is for a broad direct requirement plus a compatible modular narrowing.\n", " reviewed: false\n", " resolve:\n" ] conflicts.sort_by { |conflict| conflict.values_at(:name, :direct, :modular) }.each do |conflict| replacement.concat([ " - gem: #{conflict.fetch(:name)}\n", " direct: #{conflict.fetch(:direct)}\n", " modular: #{conflict.fetch(:modular)}\n", " action: review\n", " reason: \"\"\n" ]) end ensure_trailing_newline([*lines[0...index], *replacement, *lines[block_end..].to_a].join) end |
.add_framework_matrix_job_env(content, keys) ⇒ Object
9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 |
# File 'lib/kettle/jem.rb', line 9182 def add_framework_matrix_job_env(content, keys) lines = content.lines bundle_index = lines.index { |line| line.match?(/\A\s+BUNDLE_GEMFILE:/) } return content unless bundle_index indent = lines.fetch(bundle_index).match(/\A(\s*)/)[1] existing = workflow_job_env_existing_keys(lines, bundle_index, indent.length) additions = keys.map(&:to_s).sort.reject { |key| existing.include?(key) } return content if additions.empty? lines.insert( bundle_index + 1, *additions.map { |key| %(#{indent}#{key}: ${{ matrix.#{key} || '' }}\n) } ) lines.join end |
.add_monorepo_root_file_overrides(content) ⇒ Object
12942 12943 12944 12945 12946 12947 12948 12949 12950 12951 12952 |
# File 'lib/kettle/jem.rb', line 12942 def add_monorepo_root_file_overrides(content) override_lines = MONOREPO_ROOT_TEMPLATE_ENTRIES.reject { |entry| entry.to_s.include?("/") }.flat_map do |entry| kettle_config_file_override_lines(entry, monorepo_root_file_strategy(entry)) end insert_after_line_sequence( content, ["files:"], override_lines.join("\n"), "Could not apply monorepo-root file overrides to .kettle-jem.yml bootstrap template" ) end |
.add_monorepo_subgem_file_overrides(content, gemspec_path, profile = MONOREPO_SUBGEM_TEMPLATE_PROFILE) ⇒ Object
13049 13050 13051 13052 13053 13054 13055 13056 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 |
# File 'lib/kettle/jem.rb', line 13049 def add_monorepo_subgem_file_overrides(content, gemspec_path, profile = MONOREPO_SUBGEM_TEMPLATE_PROFILE) override_lines = [ " README.md:", " strategy: merge", " Rakefile:", " strategy: accept_template" ] gemspec = gemspec_path.to_s.strip unless gemspec.empty? override_lines.concat([ " #{gemspec}:", " strategy: merge" ]) end insert_after_line_sequence( content, ["files:"], override_lines.join("\n"), "Could not apply monorepo-subgem file overrides to .kettle-jem.yml bootstrap template" ) end |
.add_shim_bootstrap_config(content, shim) ⇒ Object
12857 12858 12859 12860 12861 12862 12863 12864 12865 12866 12867 12868 12869 12870 12871 12872 12873 12874 12875 12876 12877 12878 |
# File 'lib/kettle/jem.rb', line 12857 def add_shim_bootstrap_config(content, shim) replacement_gem = shim[:replacement_gem].to_s replacement_require = shim[:replacement_require].to_s legacy_requires = Array(shim[:legacy_requires]).map(&:to_s).reject(&:empty?) block = [ "shim:", " replacement_gem: #{replacement_gem}", " replacement_require: #{replacement_require}" ] unless legacy_requires.empty? block << " legacy_requires:" block.concat(legacy_requires.map { |path| " - #{path}" }) end block << " version:" block << " strategy: shim" insert_after_line_sequence( content, ["homepage_uri: \"{KJ|HOMEPAGE_URI}\""], ["", *block].join("\n"), "Could not add shim config to .kettle-jem.yml bootstrap template" ) end |
.add_shim_file_overrides(content, gemspec_path) ⇒ Object
13089 13090 13091 13092 13093 13094 13095 13096 13097 13098 13099 13100 13101 13102 |
# File 'lib/kettle/jem.rb', line 13089 def add_shim_file_overrides(content, gemspec_path) override_lines = shim_template_entries_for_config(gemspec_path, {}).flat_map do |entry| target = entry.fetch("target") next [] if target == KETTLE_CONFIG_PATH kettle_config_file_override_lines(target, "accept_template") end insert_after_line_sequence( content, ["files:"], override_lines.join("\n"), "Could not apply shim file overrides to .kettle-jem.yml bootstrap template" ) end |
.aliased_readme_destination_section(template_base, destination_lookup, preserve_config) ⇒ Object
18207 18208 18209 18210 18211 18212 18213 |
# File 'lib/kettle/jem.rb', line 18207 def aliased_readme_destination_section(template_base, destination_lookup, preserve_config) aliases = preserve_config[:aliases] || README_SECTION_ALIASES aliases.each do |from, to| return destination_lookup[from] if to == template_base && destination_lookup.key?(from) end nil end |
.append_gemfile_comment_block(lines, block) ⇒ Object
9531 9532 9533 9534 9535 |
# File 'lib/kettle/jem.rb', line 9531 def append_gemfile_comment_block(lines, block) first_line = block.first lines.pop while first_line && lines.last == first_line lines.concat(block) end |
.append_github_actions_coverage_steps(content, disabled_integrations: []) ⇒ Object
19796 19797 19798 19799 19800 19801 19802 19803 19804 19805 19806 19807 19808 19809 |
# File 'lib/kettle/jem.rb', line 19796 def append_github_actions_coverage_steps(content, disabled_integrations: []) return content if content.include?("Upload coverage to Coveralls") || content.include?("Upload coverage to QLTY") || content.include?("Upload coverage to CodeCov") || content.include?("Code Coverage Summary Report") lines = content.lines steps_sequence = yaml_mapping_value_node(content, "steps", Psych::Nodes::Sequence) return content unless steps_sequence insert_index = steps_sequence.end_line lines.insert(insert_index, "#{github_actions_coverage_steps(disabled_integrations: disabled_integrations)}\n") lines.join end |
.append_missing_gemspec_dependency_lines(content, destination_dependencies, receiver:) ⇒ Object
12047 12048 12049 12050 12051 12052 12053 12054 12055 12056 12057 12058 12059 12060 |
# File 'lib/kettle/jem.rb', line 12047 def append_missing_gemspec_dependency_lines(content, destination_dependencies, receiver:) existing_keys = gemspec_dependency_line_index(content, receiver: receiver).keys missing_lines = destination_dependencies.except(*existing_keys).values return content if missing_lines.empty? runtime_lines, development_lines = missing_lines.partition do |line| key = gemspec_dependency_line_key(line, receiver: receiver) key && key.first != "add_development_dependency" end merged = content.to_s merged = insert_missing_runtime_gemspec_dependency_lines(merged, runtime_lines, receiver: receiver) insert_missing_development_gemspec_dependency_lines(merged, development_lines) end |
.append_missing_markdown_link_definitions(content, definitions) ⇒ Object
7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 |
# File 'lib/kettle/jem.rb', line 7712 def append_missing_markdown_link_definitions(content, definitions) ensure_runtime_dependencies! existing = Ast::Crispr::Markdown::Markly.document_context( content: content, source_label: "README.md" ).structural_owners(owner_scope: :link_definitions).map { |owner| owner.label.to_s } missing_sources = definitions.reject { |owner| existing.include?(owner.label.to_s) }.map do |owner| owner.source.to_s.end_with?("\n") ? owner.source.to_s : "#{owner.source}\n" end return content if missing_sources.empty? [content.to_s.rstrip, "", missing_sources.join.rstrip, ""].join("\n") end |
.append_used_markdown_link_definitions(content, definition_source) ⇒ Object
7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 |
# File 'lib/kettle/jem.rb', line 7726 def append_used_markdown_link_definitions(content, definition_source) owners = ReadmePostProcessor.markdown_structural_owners(content, :link_definitions, :inline_references) existing = owners.fetch(:link_definitions).map { |owner| owner.label.to_s }.to_set referenced = owners.fetch(:inline_references).flat_map(&:labels).map(&:to_s).to_set available = ReadmePostProcessor.markdown_link_definition_owners(definition_source).to_h do |owner| [owner.label.to_s, owner] end missing = referenced.filter_map do |label| next if existing.include?(label) available[label] end append_missing_markdown_link_definitions(content, missing) end |
.apply_changelog_transfer_entries(content, entries, excluded_keys: []) ⇒ Object
6536 6537 6538 6539 6540 6541 6542 |
# File 'lib/kettle/jem.rb', line 6536 def apply_changelog_transfer_entries(content, entries, excluded_keys: []) Kettle::Changelog::TransferMerger.apply( content: normalize_changelog(content, {}), entries: entries, excluded_keys: excluded_keys ) end |
.apply_checksum_skips(project_root, recipe_reports, checksum_mode:, template_lock:) ⇒ Object
4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 |
# File 'lib/kettle/jem.rb', line 4088 def apply_checksum_skips(project_root, recipe_reports, checksum_mode:, template_lock:) return recipe_reports if checksum_mode.off? recipe_reports.map do |report| checksum_match = checksum_match_details(project_root, report, checksum_mode: checksum_mode, template_lock: template_lock) next report unless checksum_match matched = deep_dup(report) matched[:metadata] = deep_dup(matched.fetch(:metadata, {})).merge(checksum_match: checksum_match) next matched unless report[:changed] matched[:changed] = false matched[:checksum_skipped] = true matched[:metadata][:checksum_skip] = { mode: checksum_mode.to_s, reason: "lock_match" } matched end end |
.apply_commented_gem_dependency_policy(template_content, content) ⇒ Object
9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 |
# File 'lib/kettle/jem.rb', line 9493 def apply_commented_gem_dependency_policy(template_content, content) commented_blocks = commented_gem_dependency_blocks(template_content) return content if commented_blocks.empty? active_records_by_line = gemfile_gem_call_records(content) .select { |record| commented_blocks.key?(record.fetch(:name)) } .to_h { |record| [record.fetch(:start_line), record] } comment_blocks_by_line = commented_gem_dependency_block_records(content) .select { |record| commented_blocks.key?(record.fetch(:name)) } .to_h { |record| [record.fetch(:block_start_line), record] } inserted = Set.new skip_until = 0 lines = [] content.to_s.lines.each_with_index do |line, index| line_number = index + 1 next if line_number < skip_until if (record = comment_blocks_by_line[line_number]) gem_name = record.fetch(:name) append_gemfile_comment_block(lines, commented_blocks.fetch(gem_name)) unless inserted.include?(gem_name) inserted << gem_name skip_until = record.fetch(:block_end_line) + 1 next end if (record = active_records_by_line[line_number]) gem_name = record.fetch(:name) append_gemfile_comment_block(lines, commented_blocks.fetch(gem_name)) unless inserted.include?(gem_name) inserted << gem_name skip_until = record.fetch(:end_line) + 1 next end lines << line end ensure_trailing_newline(lines.join.gsub(/\n{3,}/, "\n\n")) end |
.apply_configured_gemspec_licenses(content, facts, receiver:) ⇒ Object
10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 |
# File 'lib/kettle/jem.rb', line 10846 def apply_configured_gemspec_licenses(content, facts, receiver:) licenses = Array(facts&.dig(:license, :spdx)).map { |license| license.to_s.strip }.reject(&:empty?) return content if licenses.empty? replacement = "#{receiver}.licenses = #{licenses.inspect}" existing = gemspec_assignment_records(content, receiver: receiver).find { |record| record.fetch(:field) == "licenses" } return replace_source_range_lines(content, existing.fetch(:start_line), existing.fetch(:end_line), "#{leading_whitespace(existing.fetch(:source))}#{replacement}\n") if existing homepage = gemspec_assignment_records(content, receiver: receiver).find { |record| record.fetch(:field) == "homepage" } return insert_lines_after(content, homepage.fetch(:end_line), " #{replacement}\n") if homepage content end |
.apply_configured_gemspec_metadata(content, facts, receiver:) ⇒ Object
10889 10890 10891 10892 10893 10894 |
# File 'lib/kettle/jem.rb', line 10889 def (content, facts, receiver:) mailing_list_uri = facts.to_h.dig(:rubyforum, :url).to_s return content if mailing_list_uri.empty? (content, receiver: receiver, key: "mailing_list_uri", value: mailing_list_uri) end |
.apply_configured_gemspec_required_ruby_version(content, facts, receiver:) ⇒ Object
10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 |
# File 'lib/kettle/jem.rb', line 10860 def apply_configured_gemspec_required_ruby_version(content, facts, receiver:) return remove_gemspec_assignment(content, receiver: receiver, field: "required_ruby_version") if explicit_zero_runtime_floor?(facts) min_ruby = minimum_ruby_token(facts.to_h.dig(:rubygems, :min_ruby)) if min_ruby.to_s.empty? return content end replacement = %(#{receiver}.required_ruby_version = ">= #{min_ruby}"#{required_ruby_version_rubocop_disable(min_ruby)}) existing = gemspec_assignment_records(content, receiver: receiver).find { |record| record.fetch(:field) == "required_ruby_version" } return replace_source_range_lines(content, existing.fetch(:start_line), existing.fetch(:end_line), "#{leading_whitespace(existing.fetch(:source))}#{replacement}\n") if existing licenses = gemspec_assignment_records(content, receiver: receiver).find { |record| record.fetch(:field) == "licenses" } return insert_lines_after(content, licenses.fetch(:end_line), " #{replacement}\n") if licenses homepage = gemspec_assignment_records(content, receiver: receiver).find { |record| record.fetch(:field) == "homepage" } return insert_lines_after(content, homepage.fetch(:end_line), " #{replacement}\n") if homepage content end |
.apply_github_actions_engine_exec_cmd_overrides(content, facts) ⇒ Object
9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 |
# File 'lib/kettle/jem.rb', line 9101 def apply_github_actions_engine_exec_cmd_overrides(content, facts) overrides = facts.to_h.dig(:ci, :engine_exec_cmds).to_h return content if overrides.empty? lines = content.to_s.lines yaml_mapping_nodes(content).sort_by { |mapping| -mapping.start_line }.each do |mapping| engine = yaml_mapping_scalar_value(mapping, "ruby") command = overrides[engine] next if command.to_s.empty? exec_cmd_node = yaml_mapping_scalar_node(mapping, "exec_cmd") next unless exec_cmd_node line_index = exec_cmd_node.start_line indent = lines.fetch(line_index).to_s.match(/\A(\s*)/)[1] lines[line_index] = "#{indent}exec_cmd: #{yaml_double_quoted_scalar(command)}\n" end lines.join rescue Psych::Exception content end |
.apply_kettle_config_bootstrap(project_root, recipe, env: ENV, template_contents: nil) ⇒ Object
12358 12359 12360 12361 12362 12363 12364 12365 12366 12367 12368 12369 |
# File 'lib/kettle/jem.rb', line 12358 def apply_kettle_config_bootstrap(project_root, recipe, env: ENV, template_contents: nil) content = recipe_template_content(project_root, recipe, template_contents: template_contents) tokens = stringify_template_tokens(recipe.fetch(:template_tokens, {})) content = resolve_template_tokens(content, tokens, scan_unresolved: false) bootstrap_licenses = Array(recipe[:bootstrap_licenses]).map(&:to_s).reject(&:empty?) content = replace_kettle_config_bootstrap_licenses(content, bootstrap_licenses) unless bootstrap_licenses.empty? content = replace_kettle_config_bootstrap_project_emoji(content, recipe[:bootstrap_project_emoji]) unless recipe[:bootstrap_project_emoji].to_s.empty? content = replace_kettle_config_bootstrap_rubyforum(content, recipe[:bootstrap_rubyforum]) if recipe[:bootstrap_rubyforum].is_a?(Hash) content = apply_kettle_config_bootstrap_profile(content, recipe[:bootstrap_template_profile], recipe[:bootstrap_gemspec_path]) content = add_shim_bootstrap_config(content, recipe[:bootstrap_shim]) if recipe[:bootstrap_shim].is_a?(Hash) assert_no_unresolved_template_tokens_in_yaml_values(sync_kettle_config_env_overrides(content, env), KETTLE_CONFIG_PATH) end |
.apply_kettle_config_bootstrap_profile(content, profile, gemspec_path) ⇒ Object
12819 12820 12821 12822 12823 12824 12825 12826 12827 |
# File 'lib/kettle/jem.rb', line 12819 def apply_kettle_config_bootstrap_profile(content, profile, gemspec_path) return content if profile.to_s.empty? return replace_yaml_scalar_path(content, %w[templates profile], FULL_TEMPLATE_PROFILE) if profile.to_s == FULL_TEMPLATE_PROFILE return apply_monorepo_root_template_profile(content) if profile.to_s == MONOREPO_ROOT_TEMPLATE_PROFILE return apply_monorepo_subgem_template_profile(content, gemspec_path, profile) if monorepo_subgem_template_profile_value?(profile) return apply_shim_template_profile(content, gemspec_path) if profile.to_s == SHIM_TEMPLATE_PROFILE raise Error, "Unknown kettle-jem template profile: #{profile}" end |
.apply_markdown_conditional_block(content, name, keep:) ⇒ Object
7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 |
# File 'lib/kettle/jem.rb', line 7625 def apply_markdown_conditional_block(content, name, keep:) ensure_runtime_dependencies! start_text = "KJ:#{name}:START" end_text = "KJ:#{name}:END" if keep delete_markdown_with_ast_crispr_batch( content, Ast::Crispr::Markdown::Markly::Selectors.html_comment(text: start_text, limit: {at_least: 0}), Ast::Crispr::Markdown::Markly::Selectors.html_comment(text: end_text, limit: {at_least: 0}) ) else delete_markdown_with_ast_crispr( content, Ast::Crispr::Markdown::Markly::Selectors.html_comment_block( start_text: start_text, end_text: end_text, limit: {at_least: 0} ) ) end end |
.apply_modular_dependency_conflict_resolutions(project_root, decisions) ⇒ Object
9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 |
# File 'lib/kettle/jem.rb', line 9774 def apply_modular_dependency_conflict_resolutions(project_root, decisions) decisions.each_with_object([]) do |decision, changed_files| path = File.join(project_root.to_s, decision.fetch("modular")) next unless File.file?(path) before = File.read(path) after = case decision.fetch("action") when "remove_modular_gem" remove_gemfile_dependency_blocks(before, [decision.fetch("gem")]) when "remove_x_std_lib_eval" remove_x_std_lib_eval_for_gem(before, decision.fetch("gem")) when "keep_both" before end next if after == before File.write(path, after) changed_files << decision.fetch("modular") end end |
.apply_monorepo_root_template_profile(content) ⇒ Object
12880 12881 12882 12883 12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 12897 12898 12899 12900 12901 12902 12903 |
# File 'lib/kettle/jem.rb', line 12880 def apply_monorepo_root_template_profile(content) entry_lines = MONOREPO_ROOT_TEMPLATE_ENTRIES.map { |entry| " - #{entry}" } profiled_content = replace_yaml_scalar_path(content, %w[templates profile], MONOREPO_ROOT_TEMPLATE_PROFILE) entries_block = [" entries:", *entry_lines].join("\n") updated = insert_after_line_sequence( profiled_content, ["templates:", " root: packaged", " apply: true", " profile: #{MONOREPO_ROOT_TEMPLATE_PROFILE}"], entries_block, nil ) if updated == profiled_content updated = insert_after_line_sequence( profiled_content, ["templates:", " root: packaged", " apply: true"], entries_block, "Could not apply monorepo-root template profile to .kettle-jem.yml bootstrap template" ) end if updated == profiled_content raise Error, "Could not apply monorepo-root template profile to .kettle-jem.yml bootstrap template" end add_monorepo_root_file_overrides(updated) end |
.apply_monorepo_subgem_readme_recipe(content, facts) ⇒ Object
7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 |
# File 'lib/kettle/jem.rb', line 7647 def apply_monorepo_subgem_readme_recipe(content, facts) return content unless monorepo_subgem_template_profile?(facts) source_url = facts.dig(:package, :source_url).to_s return content if source_url.empty? root_doc_links = MONOREPO_SUBGEM_README_BLOB_PATHS.to_h do |path| [path, source_blob_url(source_url, path)] end rewrite_markdown_reference_links(content, root_doc_links) end |
.apply_monorepo_subgem_template_profile(content, gemspec_path, profile = MONOREPO_SUBGEM_TEMPLATE_PROFILE) ⇒ Object
12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931 12932 12933 12934 12935 12936 12937 12938 12939 12940 |
# File 'lib/kettle/jem.rb', line 12905 def apply_monorepo_subgem_template_profile(content, gemspec_path, profile = MONOREPO_SUBGEM_TEMPLATE_PROFILE) entries = monorepo_subgem_template_entries(gemspec_path, profile) entry_lines = entries.flat_map do |entry| if entry.is_a?(Hash) [ " - source: #{entry.fetch("source")}", " target: #{entry.fetch("target")}" ] else [" - #{entry}"] end end normalized_profile = normalize_template_profile(profile) profiled_content = replace_yaml_scalar_path(content, %w[templates profile], normalized_profile) entries_block = [" entries:", *entry_lines].join("\n") updated = insert_after_line_sequence( profiled_content, ["templates:", " root: packaged", " apply: true", " profile: #{normalized_profile}"], entries_block, nil ) if updated == profiled_content updated = insert_after_line_sequence( profiled_content, ["templates:", " root: packaged", " apply: true"], entries_block, "Could not apply monorepo-subgem template profile to .kettle-jem.yml bootstrap template" ) end if updated == profiled_content raise Error, "Could not apply #{normalized_profile} template profile to .kettle-jem.yml bootstrap template" end add_monorepo_subgem_file_overrides(updated, gemspec_path, normalized_profile) end |
.apply_monorepo_subgem_thin_readme_projection(content, facts) ⇒ Object
7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 |
# File 'lib/kettle/jem.rb', line 7659 def apply_monorepo_subgem_thin_readme_projection(content, facts) ensure_runtime_dependencies! return content unless monorepo_subgem_template_profile?(facts) context = Ast::Crispr::Markdown::Markly.document_context(content: content, source_label: "README.md") link_definitions = context.structural_owners(owner_scope: :link_definitions) heading_sections = context.structural_owners(owner_scope: :heading_sections) removable = heading_sections.each_with_index.select do |owner, index| owner.level.to_i > 1 && !MONOREPO_SUBGEM_THIN_README_KEEP_HEADINGS.include?(owner.base.to_s) end.reject do |owner, index| markdown_heading_has_preserved_readme_ancestor?(heading_sections, index) end.map(&:first) projected = removable.reverse.reduce(content.to_s) do |processed, owner| delete_markdown_with_ast_crispr( processed, Ast::Crispr::Markdown::Markly::Selectors.heading_section( heading_text: owner.heading_text, level: owner.level, limit: {at_least: 0} ) ) end append_missing_markdown_link_definitions(projected, link_definitions) end |
.apply_project(project_root, env: ENV, run_options: {}) ⇒ Object
4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 |
# File 'lib/kettle/jem.rb', line 4641 def apply_project(project_root, env: ENV, run_options: {}) events = () report = plan_project(project_root, env: env, run_options: ).merge(mode: "apply") file_work_workers = with_event_phase(events, "file_work_workers") { file_work_workers_for(env, ) } file_work_thread_workers = with_event_phase(events, "file_work_thread_workers") { file_work_thread_workers_for(env, ) } report[:file_work_workers] = file_work_workers report[:file_work_thread_workers] = file_work_thread_workers report[:file_work_execution] = file_work_execution_stats(file_work_workers, file_work_thread_workers) with_event_phase(events, "apply") do before_apply_files = with_event_phase(events, "snapshot_changed_files") do snapshot_changed_files( project_root, report.fetch(:recipe_reports).filter_map { |entry| entry[:relative_path] } ) end report[:version_bootstrap_source] = version_bootstrap_source_state(report, before_apply_files) with_event_phase(events, "write_template_files") do run_apply_phases( project_root, report, file_workers: file_work_workers, file_thread_workers: file_work_thread_workers, file_stats: report.fetch(:file_work_execution) ) end report[:changed_files] = with_event_phase(events, "actual_changed_files") do actual_changed_files_after_apply(project_root, report.fetch(:changed_files), before_apply_files) end report[:post_apply_steps] = with_event_phase(events, "post_apply_steps") { post_apply_steps(project_root, report) } emit_step_events(events, "post_apply_step", report.fetch(:post_apply_steps), phase: "post_apply") end report[:changed_files] = (report.fetch(:changed_files, []) + report.fetch(:post_apply_steps).flat_map do |step| reported_post_apply_changed_files(step) end).uniq.sort report[:duplicate_drift] = with_event_phase(events, "duplicate_drift") do if DecisionPolicy.value_to_boolean(( || {})[:skip_drift_check]) { available: false, skipped: true, reason: "skip_drift_check" } else duplicate_drift_report( project_root: project_root, template_root: template_root_path(project_root, config: kettle_jem_config(project_root)), run_options: ) end end report[:phase_timings] = events.phase_timings if events.respond_to?(:phase_timings) emit_summary_event(events, report) report end |
.apply_readme_badge_policy(content, facts) ⇒ Object
7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 |
# File 'lib/kettle/jem.rb', line 7556 def apply_readme_badge_policy(content, facts) processed = with_readme_timing("badge_policy.codetriage") do remove_readme_badge_and_refs(content, README_CODETRIAGE_BADGE, README_CODETRIAGE_LINK_LABELS) end if facts.dig(:readme_style, :fossa_project).to_s.empty? processed = with_readme_timing("badge_policy.fossa") do remove_readme_badge_and_refs(processed, README_FOSSA_BADGE, README_FOSSA_LINK_LABELS) end end if Array(facts.dig(:readme_style, :disabled_integrations)).map(&:to_s).include?(SKYWALKING_EYES_INTEGRATION) processed = with_readme_timing("badge_policy.license_eye") do remove_readme_badge_and_refs( processed, README_LICENSE_EYE_WORKFLOW_BADGE, README_LICENSE_EYE_WORKFLOW_LINK_LABELS ) end end if facts.dig(:funding, :open_collective_disabled) processed = with_readme_timing("badge_policy.open_collective") do remove_readme_badge_and_refs( processed, README_OPEN_COLLECTIVE_FUNDING_BADGES, README_OPEN_COLLECTIVE_LINK_LABELS ) end end funding_platforms = facts.dig(:funding, :platforms) README_FUNDING_BADGE_POLICIES.each do |platform, policy| next if funding_platform_enabled?(funding_platforms, platform) processed = with_readme_timing("badge_policy.#{platform}") do policy.fetch(:badges).reduce(processed) do |badge_content, badge| remove_readme_badge_and_refs(badge_content, badge, policy.fetch(:labels)) end end end Array(facts.dig(:readme_style, :disabled_integrations)).each do |integration| patterns = README_INTEGRATION_BADGE_PATTERNS.fetch(integration.to_s, []) labels = README_INTEGRATION_LINK_LABELS.fetch(integration.to_s, []) processed = patterns.reduce(processed) { |content, pattern| content.gsub(pattern, "") } processed = ReadmePostProcessor.delete_markdown_link_definitions(processed, labels) end processed end |
.apply_readme_conditional_blocks(content, facts) ⇒ Object
7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 |
# File 'lib/kettle/jem.rb', line 7513 def apply_readme_conditional_blocks(content, facts) open_collective_enabled = !facts.dig(:funding, :open_collective_disabled) processed = apply_markdown_conditional_block(content, "OPEN_COLLECTIVE", keep: open_collective_enabled) processed = apply_markdown_conditional_block(processed, "NO_OPEN_COLLECTIVE", keep: !open_collective_enabled) processed = apply_markdown_conditional_block( processed, "FUNDING_TIDELIFT", keep: funding_platform_enabled?(facts.dig(:funding, :platforms), "tidelift") ) star_history_enabled = facts.dig(:repository, :star_history, :enabled) == true return processed if star_history_enabled delete_markdown_with_ast_crispr( processed, Ast::Crispr::Markdown::Markly::Selectors.html_details( summary_text: "⭐️ Star History", limit: {at_least: 0} ) ) end |
.apply_readme_kloc_badge(content, facts, project_root, destination_content: nil) ⇒ Object
7455 7456 7457 7458 7459 7460 7461 7462 7463 |
# File 'lib/kettle/jem.rb', line 7455 def apply_readme_kloc_badge(content, facts, project_root, destination_content: nil) kloc = readme_kloc_from_changelog(project_root, facts.dig(:project_runtime, :version)) return preserve_destination_readme_kloc_badge(content, destination_content) if kloc.to_s.empty? content.to_s.gsub( README_KLOC_BADGE_PATTERN, "\\1#{kloc}\\3" ) end |
.apply_readme_style(project_root, env: ENV) ⇒ Object
5844 5845 5846 5847 5848 5849 5850 5851 5852 |
# File 'lib/kettle/jem.rb', line 5844 def apply_readme_style(project_root, env: ENV) report = plan_readme_style(project_root, env: env).merge(mode: "apply") return report unless report.fetch(:changed) path = File.join(project_root, report.fetch(:readme_path)) FileUtils.mkdir_p(File.dirname(path)) File.write(path, report.fetch(:final_content)) report end |
.apply_recipe_report(project_root, recipe_report) ⇒ Object
13863 13864 13865 13866 |
# File 'lib/kettle/jem.rb', line 13863 def apply_recipe_report(project_root, recipe_report) intent = write_intent_from_recipe_report(project_root, recipe_report) commit_file_outcome(intent) if intent end |
.apply_shim_template_profile(content, gemspec_path) ⇒ Object
12829 12830 12831 12832 12833 12834 12835 12836 12837 12838 12839 12840 12841 12842 12843 12844 12845 12846 12847 12848 12849 12850 12851 12852 12853 12854 12855 |
# File 'lib/kettle/jem.rb', line 12829 def apply_shim_template_profile(content, gemspec_path) entry_lines = shim_template_entries_for_config(gemspec_path, {}).flat_map do |entry| [ " - source: #{entry.fetch("source")}", " target: #{entry.fetch("target")}" ] end profiled_content = replace_yaml_scalar_path(content, %w[templates profile], SHIM_TEMPLATE_PROFILE) entries_block = [" entries:", *entry_lines].join("\n") updated = insert_after_line_sequence( profiled_content, ["templates:", " root: packaged", " apply: true", " profile: #{SHIM_TEMPLATE_PROFILE}"], entries_block, nil ) if updated == profiled_content updated = insert_after_line_sequence( profiled_content, ["templates:", " root: packaged", " apply: true"], entries_block, "Could not apply shim template profile to .kettle-jem.yml bootstrap template" ) end raise Error, "Could not apply shim template profile to .kettle-jem.yml bootstrap template" if updated == profiled_content add_shim_file_overrides(updated, gemspec_path) end |
.apply_template_source(project_root, recipe, original, facts: nil, env: ENV, template_contents: nil) ⇒ Object
7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 |
# File 'lib/kettle/jem.rb', line 7116 def apply_template_source(project_root, recipe, original, facts: nil, env: ENV, template_contents: nil) strategy = recipe.dig(:template_preference, :strategy).to_s return original if strategy == "keep_destination" content = recipe_template_content(project_root, recipe, template_contents: template_contents) return finalize_github_workflow_template(content, facts) if strategy == "raw_copy" && github_workflow_template_recipe?(recipe) return finalize_template_source_content(recipe, content) if strategy == "raw_copy" resolved = recipe.fetch(:resolved_template_content) do resolve_template_tokens( content, recipe.fetch(:template_tokens, {}), scan_unresolved: unresolved_template_scan?(recipe) ) end rescue ArgumentError => e raise ArgumentError, "#{recipe.fetch(:target_path)}: #{e.}" else resolved = prepare_readme_template(resolved, recipe[:readme_style]) if recipe.fetch(:target_path) == "README.md" resolved = prepare_github_workflow_template(resolved, recipe, facts) if recipe.fetch(:target_path) == "README.md" && (strategy.empty? || strategy == "merge") merged_readme = with_readme_timing("readme.merge_template") do merge_readme_template( template_content: resolved, destination_content: original, preserve_config: recipe.dig(:template_preference, :readme_preserve_config) || {} ) end processed = postprocess_readme_content( merged_readme, facts, project_root: project_root, destination_content: original ) return with_readme_timing("readme.append_used_link_definitions") do appended = append_used_markdown_link_definitions(processed, resolved) postprocess_readme_content( appended, facts, project_root: project_root, destination_content: original ) end end if strategy.empty? || strategy == "merge" merged = merge_config_template_source(recipe, resolved, original, facts: facts, env: env) merged = preserve_mise_project_settings(recipe, merged, original, project_root: project_root, facts: facts) if template_file_type(recipe) == :toml return finalize_template_source_content(recipe, sync_kettle_config_env_overrides(merged, env)) if recipe.fetch(:target_path) == KETTLE_CONFIG_PATH merged = postprocess_funding_markdown_content(merged, facts) if recipe.fetch(:target_path) == "FUNDING.md" if github_workflow_template_recipe?(recipe) merged = preserve_github_workflow_project_settings(recipe, merged, original, project_root: project_root) merged = finalize_github_workflow_template(merged, facts) return preserve_newer_github_workflow_action_pins(merged, original) end return finalize_template_source_content(recipe, merged) end if strategy == "accept_template" accepted = finalize_accepted_template_source(recipe, resolved, original, facts: facts, project_root: project_root) accepted = preserve_github_workflow_project_settings(recipe, accepted, original, project_root: project_root) if github_workflow_template_recipe?(recipe) accepted = sync_kettle_config_env_overrides(accepted, env) if recipe.fetch(:target_path) == KETTLE_CONFIG_PATH accepted = postprocess_funding_markdown_content(accepted, facts) if recipe.fetch(:target_path) == "FUNDING.md" if github_workflow_template_recipe?(recipe) accepted = finalize_github_workflow_template(accepted, facts) accepted = preserve_newer_github_workflow_action_pins(accepted, original) end if recipe.fetch(:target_path) == "README.md" return postprocess_readme_content( accepted, facts, project_root: project_root, destination_content: original ) end return finalize_template_source_content(recipe, accepted) end resolved = finalize_github_workflow_template(resolved, facts) if github_workflow_template_recipe?(recipe) resolved = postprocess_funding_markdown_content(resolved, facts) if recipe.fetch(:target_path) == "FUNDING.md" if recipe.fetch(:target_path) == "README.md" return postprocess_readme_content( resolved, facts, project_root: project_root, destination_content: original ) end finalize_template_source_content(recipe, resolved) end |
.appraisal_all_versions_for(resolver:, gem_name:, mode:, requirements: nil, include_versions: nil, exclude_versions: nil) ⇒ Object
3098 3099 3100 3101 3102 3103 3104 3105 |
# File 'lib/kettle/jem.rb', line 3098 def appraisal_all_versions_for(resolver:, gem_name:, mode:, requirements: nil, include_versions: nil, exclude_versions: nil) base_versions = if mode.to_s == "patch" resolver.versions(gem_name, requirements: requirements).map { |entry| entry[:number] || entry["number"] } else resolver.minor_versions_by_major(gem_name, requirements: requirements).flat_map { |entry| entry[:minors] || entry["minors"] } end appraisal_finalize_versions(base_versions, include_versions: include_versions, exclude_versions: exclude_versions) end |
.appraisal_assign_version_buckets(selected_versions:, seams:, buckets:, bucket_ranges:, all_versions:) ⇒ Object
2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 |
# File 'lib/kettle/jem.rb', line 2867 def appraisal_assign_version_buckets(selected_versions:, seams:, buckets:, bucket_ranges:, all_versions:) return [] if selected_versions.empty? || buckets.empty? normalized_ranges = appraisal_normalized_bucket_ranges(bucket_ranges) version_min_rubies = appraisal_version_min_ruby_map(all_versions, seams) assignments = selected_versions.sort_by { |version| Gem::Version.new(version) }.filter_map do |version| min_ruby = version_min_rubies[version] next unless min_ruby next_seam = appraisal_next_seam_ruby(version, min_ruby, all_versions, version_min_rubies) bucket = next_seam ? appraisal_bucket_below(next_seam, buckets, normalized_ranges) : buckets.last {version: version, bucket: bucket} if bucket end appraisal_fill_bucket_gaps(assignments, buckets, normalized_ranges, version_min_rubies, all_versions) end |
.appraisal_block_has_matrix_dependency_gemfile?(block, matrix_dependency_gemfiles) ⇒ Boolean
10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 |
# File 'lib/kettle/jem.rb', line 10219 def appraisal_block_has_matrix_dependency_gemfile?(block, matrix_dependency_gemfiles) ruby_call_records(block, :eval_gemfile).any? do |call| path = ruby_string_argument(call).to_s next true if matrix_dependency_gemfiles.include?(path) path.start_with?("modular/") && path.delete_prefix("modular/").include?("/") && !path.start_with?("modular/x_std_libs/") end end |
.appraisal_blocks(content) ⇒ Object
10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 |
# File 'lib/kettle/jem.rb', line 10474 def appraisal_blocks(content) lines = content.to_s.lines blocks = {} order = [] records = appraisal_call_records(content) records.each do |record| name = record.fetch(:name) unless blocks.key?(name) blocks[name] = record.fetch(:source) order << name end end prelude_end = records.empty? ? lines.length : records.first.fetch(:start_line) - 1 prelude = lines[0...prelude_end].join {prelude: prelude, blocks: blocks, order: order} end |
.appraisal_bucket_below(ruby_floor, buckets, bucket_ranges) ⇒ Object
2962 2963 2964 2965 2966 2967 2968 2969 |
# File 'lib/kettle/jem.rb', line 2962 def appraisal_bucket_below(ruby_floor, buckets, bucket_ranges) buckets.filter_map do |bucket| range = bucket_ranges[bucket] next unless range && range.fetch(:ceiling) < ruby_floor [bucket, range.fetch(:ceiling)] end.max_by(&:last)&.first end |
.appraisal_bucket_sort_key(bucket) ⇒ Object
2922 2923 2924 2925 |
# File 'lib/kettle/jem.rb', line 2922 def appraisal_bucket_sort_key(bucket) match = bucket.to_s.match(/\Ar(\d+)(?:\.(\d+))?\z/) [match[1].to_i, match[2] ? match[2].to_i : 999] end |
.appraisal_call_records(content) ⇒ Object
10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 |
# File 'lib/kettle/jem.rb', line 10508 def appraisal_call_records(content) lines = content.to_s.lines ruby_call_records(content, :appraise).filter_map do |call| name = ruby_string_argument(call) next unless name { name: name, start_line: call.location.start_line, end_line: ruby_node_source_end_line(call), source: (lines[(call.location.start_line - 1)..(ruby_node_source_end_line(call) - 1)] || []).join } end end |
.appraisal_compatible_version_for_bucket?(resolver:, gem_name:, version:, ruby_series:, bucket_ranges:) ⇒ Boolean
3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 |
# File 'lib/kettle/jem.rb', line 3115 def appraisal_compatible_version_for_bucket?(resolver:, gem_name:, version:, ruby_series:, bucket_ranges:) range = bucket_ranges[ruby_series] || bucket_ranges[ruby_series.to_s] return true unless range ceiling = Gem::Version.new((range[:ceiling] || range["ceiling"]).to_s) exact_version = appraisal_latest_minor_patch(resolver: resolver, gem_name: gem_name, version: version) min_ruby = resolver.min_ruby_version(gem_name, exact_version) min_ruby.nil? || Gem::Version.new(min_ruby.to_s) <= ceiling rescue true end |
.appraisal_eval_gemfile_path(path) ⇒ Object
2669 2670 2671 |
# File 'lib/kettle/jem.rb', line 2669 def appraisal_eval_gemfile_path(path) path.to_s.delete_prefix("gemfiles/") end |
.appraisal_extract_runtime_dependencies(gemspec_content) ⇒ Object
3049 3050 3051 3052 3053 3054 |
# File 'lib/kettle/jem.rb', line 3049 def appraisal_extract_runtime_dependencies(gemspec_content) gemspec_dependency_records(gemspec_content) .reject { |record| record.fetch(:kind) == "add_development_dependency" } .map { |record| record.fetch(:name) } .uniq end |
.appraisal_file_content(matrix_entries) ⇒ Object
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 |
# File 'lib/kettle/jem.rb', line 2649 def appraisal_file_content(matrix_entries) lines = [ "# frozen_string_literal: true", "", "# Generated by kettle-jem", "# Do not edit directly; regenerate from Kettle/Jem appraisal matrix metadata.", "" ] matrix_entries.each do |entry| lines << %(appraise "#{entry.fetch(:name)}" do) lines << %( eval_gemfile "#{appraisal_eval_gemfile_path(entry.fetch(:tier1_gemfile))}") if entry[:tier1_gemfile] lines << %( eval_gemfile "#{appraisal_eval_gemfile_path(entry.fetch(:tier2_gemfile))}") if entry[:tier2_gemfile] lines << %( eval_gemfile "#{appraisal_eval_gemfile_path(entry.fetch(:x_std_libs_gemfile))}") if entry[:x_std_libs_gemfile] lines << "end" lines << "" end lines.pop while lines.last == "" ensure_trailing_newline(lines.join("\n")) end |
.appraisal_fill_bucket_gaps(assignments, buckets, bucket_ranges, version_min_rubies, all_versions) ⇒ Object
2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 |
# File 'lib/kettle/jem.rb', line 2971 def appraisal_fill_bucket_gaps(assignments, buckets, bucket_ranges, version_min_rubies, all_versions) covered = assignments.map { |assignment| assignment.fetch(:bucket) } (buckets - covered).each do |bucket| range = bucket_ranges[bucket] next unless range filler = all_versions.sort_by { |version| Gem::Version.new(version) }.reverse.find do |version| ruby = version_min_rubies[version] ruby&.between?(range.fetch(:floor), range.fetch(:ceiling)) end filler ||= all_versions.sort_by { |version| Gem::Version.new(version) }.reverse.find do |version| ruby = version_min_rubies[version] ruby && ruby <= range.fetch(:ceiling) end assignments << {version: filler, bucket: bucket, filler: true} if filler end assignments.sort_by { |assignment| bucket_ranges.fetch(assignment.fetch(:bucket)).fetch(:floor) } end |
.appraisal_filtered_versions(version_metadata, requirements:) ⇒ Object
2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 |
# File 'lib/kettle/jem.rb', line 2813 def appraisal_filtered_versions(, requirements:) requirement = requirements ? Gem::Requirement.new(Array(requirements)) : nil .filter_map do |entry| number = entry[:number] || entry["number"] next if number.to_s.empty? next if entry[:prerelease] || entry["prerelease"] next if requirement && !requirement.satisfied_by?(Gem::Version.new(number)) number.to_s end.sort_by { |version| Gem::Version.new(version) } end |
.appraisal_finalize_versions(base_versions, include_versions: nil, exclude_versions: nil) ⇒ Object
3107 3108 3109 3110 3111 3112 3113 |
# File 'lib/kettle/jem.rb', line 3107 def appraisal_finalize_versions(base_versions, include_versions: nil, exclude_versions: nil) merged = appraisal_sort_versions(Array(base_versions) + Array(include_versions)) excluded = Array(exclude_versions).map(&:to_s).to_set return merged if excluded.empty? appraisal_sort_versions(merged.reject { |version| excluded.include?(version) }) end |
.appraisal_find_ruby_seams(version_metadata) ⇒ Object
2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 |
# File 'lib/kettle/jem.rb', line 2841 def appraisal_find_ruby_seams() minors = appraisal_latest_patch_by_minor() seams = [] previous = nil minors.sort_by { |minor, _entry| Gem::Version.new(minor) }.each do |minor, entry| min_ruby = Gem::Version.new((entry[:min_ruby] || entry["min_ruby"]).to_s) min_ruby = [min_ruby, DEFAULT_TEST_MINIMUM_RUBY].max if previous.nil? || min_ruby > previous seams << {version: minor, min_ruby: min_ruby} end previous = min_ruby end seams end |
.appraisal_format_version(version) ⇒ Object
2608 2609 2610 |
# File 'lib/kettle/jem.rb', line 2608 def appraisal_format_version(version) version.to_s.tr(".", "-") end |
.appraisal_gem_abbreviation(gem_name) ⇒ Object
2604 2605 2606 |
# File 'lib/kettle/jem.rb', line 2604 def appraisal_gem_abbreviation(gem_name) APPRAISAL_GEM_ABBREVIATIONS.fetch(gem_name.to_s, gem_name.to_s) end |
.appraisal_latest_minor_patch(resolver:, gem_name:, version:) ⇒ Object
3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 |
# File 'lib/kettle/jem.rb', line 3127 def appraisal_latest_minor_patch(resolver:, gem_name:, version:) all_versions = resolver.versions(gem_name) prefix = "#{version}." matching = all_versions.select do |entry| number = (entry[:number] || entry["number"]).to_s number == version.to_s || number.start_with?(prefix) end return version.to_s if matching.empty? latest = matching.max_by { |entry| Gem::Version.new((entry[:number] || entry["number"]).to_s) } (latest[:number] || latest["number"]).to_s end |
.appraisal_latest_patch_by_minor(version_metadata) ⇒ Object
2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 |
# File 'lib/kettle/jem.rb', line 2883 def appraisal_latest_patch_by_minor() .each_with_object({}) do |entry, latest| number = (entry[:number] || entry["number"]).to_s next if number.empty? version = Gem::Version.new(number) minor = "#{version.segments[0]}.#{version.segments[1] || 0}" current = latest[minor] latest[minor] = entry if current.nil? || version > Gem::Version.new((current[:number] || current["number"]).to_s) end end |
.appraisal_latest_version_matching(version_metadata, requested_version) ⇒ Object
3014 3015 3016 3017 3018 3019 3020 |
# File 'lib/kettle/jem.rb', line 3014 def appraisal_latest_version_matching(, requested_version) prefix = "#{requested_version}." .select do |entry| number = (entry[:number] || entry["number"]).to_s number == requested_version.to_s || number.start_with?(prefix) end.max_by { |entry| Gem::Version.new((entry[:number] || entry["number"]).to_s) } end |
.appraisal_matrix_entries(tier1_gems:, tier2_gems: []) ⇒ Object
2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 |
# File 'lib/kettle/jem.rb', line 2764 def appraisal_matrix_entries(tier1_gems:, tier2_gems: []) entries = [] tier1_gems.each do |tier1| tier1_name = tier1[:name] || tier1["name"] assignments = tier1[:assignments] || tier1["assignments"] || [] assignments.each do |assignment| tier1_version = assignment[:version] || assignment["version"] ruby_series = assignment[:bucket] || assignment["bucket"] || assignment[:ruby_series] || assignment["ruby_series"] if tier2_gems.empty? entries << appraisal_matrix_entry( tier1_name: tier1_name, tier1_version: tier1_version, ruby_series: ruby_series ) else tier2_gems.each do |tier2| tier2_name = tier2[:name] || tier2["name"] Array(tier2[:versions] || tier2["versions"]).each do |tier2_version| entries << appraisal_matrix_entry( tier1_name: tier1_name, tier1_version: tier1_version, ruby_series: ruby_series, tier2_name: tier2_name, tier2_version: tier2_version ) end end end end end entries end |
.appraisal_matrix_entry(tier1_name:, tier1_version:, ruby_series:, tier2_name: nil, tier2_version: nil) ⇒ Object
2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 |
# File 'lib/kettle/jem.rb', line 2797 def appraisal_matrix_entry(tier1_name:, tier1_version:, ruby_series:, tier2_name: nil, tier2_version: nil) { name: appraisal_name( tier1_gem: tier1_name, tier1_version: tier1_version, tier2_gem: tier2_name, tier2_version: tier2_version, ruby_series: ruby_series ), tier1_gemfile: appraisal_modular_gemfile_path(gem_name: tier1_name, version: tier1_version, ruby_series: ruby_series), tier2_gemfile: tier2_name ? appraisal_modular_gemfile_path(gem_name: tier2_name, version: tier2_version, ruby_series: ruby_series) : nil, x_std_libs_gemfile: File.join("gemfiles", "modular", "x_std_libs", ruby_series.to_s, "libs.gemfile"), ruby_series: ruby_series.to_s } end |
.appraisal_matrix_fresh?(matrix, now: Time.now.to_i) ⇒ Boolean
3080 3081 3082 3083 3084 3085 3086 |
# File 'lib/kettle/jem.rb', line 3080 def appraisal_matrix_fresh?(matrix, now: Time.now.to_i) resolved_at = (matrix || {})[:resolved_at] || (matrix || {})["resolved_at"] return false unless resolved_at ttl = (matrix || {})[:freshness_ttl] || (matrix || {})["freshness_ttl"] || APPRAISAL_DEFAULT_FRESHNESS_TTL (now.to_i - resolved_at.to_i) < ttl.to_i end |
.appraisal_matrix_has_versions?(matrix) ⇒ Boolean
3073 3074 3075 3076 3077 3078 |
# File 'lib/kettle/jem.rb', line 3073 def appraisal_matrix_has_versions?(matrix) gems = deep_string_key_hash(matrix || {}).fetch("gems", {}) %w[tier1 tier2].any? do |tier| Array(gems[tier]).any? { |gem_config| Array(gem_config["versions"]).any? } end end |
.appraisal_minor_key(version) ⇒ Object
2917 2918 2919 2920 |
# File 'lib/kettle/jem.rb', line 2917 def appraisal_minor_key(version) segments = Gem::Version.new(version.to_s).segments "#{segments[0]}.#{segments[1] || 0}" end |
.appraisal_minor_versions_by_major(versions) ⇒ Object
2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 |
# File 'lib/kettle/jem.rb', line 2825 def appraisal_minor_versions_by_major(versions) versions.map do |version| gem_version = Gem::Version.new(version) segments = gem_version.segments { major: segments[0], minor: "#{segments[0]}.#{segments[1] || 0}" } end.uniq.group_by { |entry| entry.fetch(:major) }.map do |major, entries| { major: major, minors: entries.map { |entry| entry.fetch(:minor) }.sort_by { |minor| Gem::Version.new(minor) } } end.sort_by { |entry| entry.fetch(:major) } end |
.appraisal_minor_versions_to_buckets(minor_versions) ⇒ Object
2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 |
# File 'lib/kettle/jem.rb', line 2895 def appraisal_minor_versions_to_buckets(minor_versions) by_major = minor_versions.group_by { |minor| minor.split(".").first.to_i } buckets = [] ranges = {} by_major.each do |major, minors| sorted = minors.sort_by { |minor| Gem::Version.new(minor) } sorted.each_with_index do |minor, index| bucket = (index == sorted.length - 1) ? "r#{major}" : "r#{major}.#{[sorted[index + 1].split(".").last.to_i - 1, minor.split(".").last.to_i].max}" next if ranges.key?(bucket) buckets << bucket ceiling = if index == sorted.length - 1 "#{major}.99" else bucket.split(".").last ? "#{major}.#{bucket.split(".").last}" : "#{major}.99" end ranges[bucket] = {floor: Gem::Version.new(minor), ceiling: Gem::Version.new(ceiling)} end end {buckets: buckets.sort_by { |bucket| appraisal_bucket_sort_key(bucket) }, bucket_ranges: ranges} end |
.appraisal_modular_gemfile_content(gem_name:, version:, sub_dependencies: {}) ⇒ Object
2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 |
# File 'lib/kettle/jem.rb', line 2630 def appraisal_modular_gemfile_content(gem_name:, version:, sub_dependencies: {}) lines = [ "# frozen_string_literal: true", "", "# Generated by kettle-jem", "", %(gem "#{gem_name}", "#{appraisal_version_requirement(version)}") ] sub_dependencies.each do |name, requirement| lines << %(gem "#{name}", "~> #{requirement}") end ensure_trailing_newline(lines.join("\n")) end |
.appraisal_modular_gemfile_path(gem_name:, version:, ruby_series:) ⇒ Object
2626 2627 2628 |
# File 'lib/kettle/jem.rb', line 2626 def appraisal_modular_gemfile_path(gem_name:, version:, ruby_series:) File.join("gemfiles", "modular", gem_name.to_s, ruby_series.to_s, "v#{version}.gemfile") end |
.appraisal_name(tier1_gem:, tier1_version:, ruby_series:, tier2_gem: nil, tier2_version: nil) ⇒ Object
2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 |
# File 'lib/kettle/jem.rb', line 2612 def appraisal_name(tier1_gem:, tier1_version:, ruby_series:, tier2_gem: nil, tier2_version: nil) parts = [ APPRAISAL_NAME_PREFIX, appraisal_gem_abbreviation(tier1_gem), appraisal_format_version(tier1_version) ] unless tier2_gem.to_s.empty? parts << appraisal_gem_abbreviation(tier2_gem) parts << appraisal_format_version(tier2_version) end parts << ruby_series.to_s parts.join("-") end |
.appraisal_names(content) ⇒ Object
7041 7042 7043 |
# File 'lib/kettle/jem.rb', line 7041 def appraisal_names(content) appraisal_call_records(content).map { |record| record.fetch(:name) } end |
.appraisal_next_seam_ruby(version, min_ruby, all_versions, version_min_rubies) ⇒ Object
2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 |
# File 'lib/kettle/jem.rb', line 2950 def appraisal_next_seam_ruby(version, min_ruby, all_versions, version_min_rubies) found = false all_versions.sort_by { |candidate| Gem::Version.new(candidate) }.each do |candidate| found ||= Gem::Version.new(candidate) >= Gem::Version.new(version) next unless found candidate_ruby = version_min_rubies[candidate] return candidate_ruby if candidate_ruby && candidate_ruby > min_ruby end nil end |
.appraisal_normalized_bucket_ranges(bucket_ranges) ⇒ Object
2927 2928 2929 2930 2931 2932 2933 2934 |
# File 'lib/kettle/jem.rb', line 2927 def appraisal_normalized_bucket_ranges(bucket_ranges) bucket_ranges.transform_values do |range| { floor: Gem::Version.new((range[:floor] || range["floor"]).to_s), ceiling: Gem::Version.new((range[:ceiling] || range["ceiling"]).to_s) } end end |
.appraisal_recording_enabled?(config) ⇒ Boolean
19152 19153 19154 19155 19156 19157 |
# File 'lib/kettle/jem.rb', line 19152 def appraisal_recording_enabled?(config) workflows = config["workflows"] workflows = {} unless workflows.is_a?(Hash) DecisionPolicy.value_to_boolean(workflows["recording"]) == true end |
.appraisal_resolve_sub_dependencies(parent_gem:, parent_version:, parent_versions:, dependency_versions:, ruby_min: nil, excluded_gems: []) ⇒ Object
2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 |
# File 'lib/kettle/jem.rb', line 2990 def appraisal_resolve_sub_dependencies(parent_gem:, parent_version:, parent_versions:, dependency_versions:, ruby_min: nil, excluded_gems: []) parent = appraisal_latest_version_matching(parent_versions, parent_version) return {} unless parent ruby_floor = Gem::Version.new(ruby_min.to_s) unless ruby_min.to_s.empty? excluded = excluded_gems.map(&:to_s) Array(parent[:runtime_dependencies] || parent["runtime_dependencies"]).each_with_object({}) do |dependency, resolved| name = (dependency[:name] || dependency["name"]).to_s next if name.empty? || excluded.include?(name) requirement = begin Gem::Requirement.new(dependency[:requirements] || dependency["requirements"] || ">= 0") rescue ArgumentError Gem::Requirement.default end selected = appraisal_select_dependency_version( Array(dependency_versions[name] || dependency_versions[name.to_sym]), requirement: requirement, ruby_min: ruby_floor ) resolved[name] = selected if selected end end |
.appraisal_ruby_series(version_metadata, project_min_ruby: nil) ⇒ Object
2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 |
# File 'lib/kettle/jem.rb', line 2856 def appraisal_ruby_series(, project_min_ruby: nil) floors = appraisal_find_ruby_seams().map { |seam| seam.fetch(:min_ruby) } if project_min_ruby floor = Gem::Version.new(project_min_ruby.to_s) floors.reject! { |version| version < floor } floors << floor unless floors.include?(floor) end floors = [Gem::Version.new("3.2")] if floors.empty? appraisal_minor_versions_to_buckets(floors.map { |version| appraisal_minor_key(version) }.uniq.sort) end |
.appraisal_ruby_version(value) ⇒ Object
9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 |
# File 'lib/kettle/jem.rb', line 9251 def appraisal_ruby_version(value) parts = value.to_s.split("-") return unless parts.length == 3 && parts.first == "ruby" major = Integer(parts[1], exception: false) minor = Integer(parts[2], exception: false) return unless major && minor "#{major}.#{minor}" end |
.appraisal_scaffold_config(gemspec_content:, existing_config: {}, exclusions: [], default_mode: "semver", freshness_ttl: APPRAISAL_DEFAULT_FRESHNESS_TTL) ⇒ Object
3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 |
# File 'lib/kettle/jem.rb', line 3056 def appraisal_scaffold_config(gemspec_content:, existing_config: {}, exclusions: [], default_mode: "semver", freshness_ttl: APPRAISAL_DEFAULT_FRESHNESS_TTL) excluded = exclusions.map(&:to_s).to_set runtime_dependencies = appraisal_extract_runtime_dependencies(gemspec_content) tier1 = runtime_dependencies.reject { |name| excluded.include?(name) }.map { |name| {"name" => name} } config = deep_string_key_hash(existing_config) matrix = config["appraisal_matrix"] || {} gems = matrix["gems"] || {} matrix["mode"] ||= default_mode matrix["freshness_ttl"] ||= freshness_ttl gems["tier1"] = tier1 gems["tier2"] ||= [] matrix["gems"] = gems config["appraisal_matrix"] = matrix config end |
.appraisal_select_dependency_version(version_metadata, requirement:, ruby_min:) ⇒ Object
3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 |
# File 'lib/kettle/jem.rb', line 3022 def appraisal_select_dependency_version(, requirement:, ruby_min:) compatible = .select do |entry| number = (entry[:number] || entry["number"]).to_s !number.empty? && requirement.satisfied_by?(Gem::Version.new(number)) end.sort_by { |entry| Gem::Version.new((entry[:number] || entry["number"]).to_s) } return if compatible.empty? if ruby_min selected = compatible.reverse.find do |entry| min_ruby = entry[:min_ruby] || entry["min_ruby"] min_ruby.to_s.empty? || Gem::Version.new(min_ruby.to_s) <= ruby_min end return (selected || compatible.first).then { |entry| entry[:number] || entry["number"] } end compatible.last.then { |entry| entry[:number] || entry["number"] } end |
.appraisal_select_versions(version_metadata, mode:, requirements: nil) ⇒ Object
2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 |
# File 'lib/kettle/jem.rb', line 2736 def appraisal_select_versions(, mode:, requirements: nil) mode = mode.to_s raise ArgumentError, "invalid appraisal version selection mode: #{mode}" unless APPRAISAL_VERSION_SELECTION_MODES.include?(mode) versions = appraisal_filtered_versions(, requirements: requirements) return versions if mode == "patch" by_major = appraisal_minor_versions_by_major(versions) return [] if by_major.empty? current_major = by_major.last.fetch(:major) case mode when "major" by_major.map { |entry| entry.fetch(:minors).last } when "minor" by_major.flat_map { |entry| entry.fetch(:minors) } when "minor-minmax" by_major.flat_map do |entry| minors = entry.fetch(:minors) (entry.fetch(:major) < current_major) ? [minors.first, minors.last].uniq : minors end when "semver" by_major.flat_map do |entry| (entry.fetch(:major) < current_major) ? [entry.fetch(:minors).last] : entry.fetch(:minors) end end end |
.appraisal_sort_versions(values) ⇒ Object
3140 3141 3142 |
# File 'lib/kettle/jem.rb', line 3140 def appraisal_sort_versions(values) values.compact.map(&:to_s).reject(&:empty?).uniq.sort_by { |version| Gem::Version.new(version) } end |
.appraisal_stale_gemfile_paths(existing_paths:, current_entries:) ⇒ Object
3039 3040 3041 3042 3043 3044 3045 3046 3047 |
# File 'lib/kettle/jem.rb', line 3039 def appraisal_stale_gemfile_paths(existing_paths:, current_entries:) current_names = current_entries.map { |entry| (entry[:name] || entry["name"]).to_s }.to_set existing_paths.map(&:to_s).select do |path| basename = File.basename(path, ".gemfile") path.start_with?("gemfiles/#{APPRAISAL_NAME_PREFIX}-") && path.end_with?(".gemfile") && !current_names.include?(basename) end.sort end |
.appraisal_time_ago(timestamp, now: Time.now.to_i) ⇒ Object
3088 3089 3090 3091 3092 3093 3094 3095 3096 |
# File 'lib/kettle/jem.rb', line 3088 def appraisal_time_ago(, now: Time.now.to_i) return "unknown" unless seconds = now.to_i - .to_i return "#{seconds / 60}m" if seconds < 3600 return "#{seconds / 3600}h" if seconds < 86_400 "#{seconds / 86_400}d" end |
.appraisal_version_min_ruby_map(all_versions, seams) ⇒ Object
2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 |
# File 'lib/kettle/jem.rb', line 2936 def appraisal_version_min_ruby_map(all_versions, seams) sorted_seams = seams.sort_by { |seam| Gem::Version.new(seam[:version] || seam["version"]) } seam_index = 0 current = nil all_versions.sort_by { |version| Gem::Version.new(version) }.each_with_object({}) do |version, map| while seam_index < sorted_seams.length && Gem::Version.new(sorted_seams[seam_index][:version] || sorted_seams[seam_index]["version"]) <= Gem::Version.new(version) current = Gem::Version.new((sorted_seams[seam_index][:min_ruby] || sorted_seams[seam_index]["min_ruby"]).to_s) current = [current, DEFAULT_TEST_MINIMUM_RUBY].max seam_index += 1 end map[version] = current if current end end |
.appraisal_version_requirement(version) ⇒ Object
2644 2645 2646 2647 |
# File 'lib/kettle/jem.rb', line 2644 def appraisal_version_requirement(version) segments = version.to_s.split(".") (segments.length >= 3) ? "~> #{version}" : "~> #{version}.0" end |
.appraisal_workflow_groups(matrix_entries, bucket_ranges:, exec_cmd: "kettle-test") ⇒ Object
2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 |
# File 'lib/kettle/jem.rb', line 2673 def appraisal_workflow_groups(matrix_entries, bucket_ranges:, exec_cmd: "kettle-test") grouped = Hash.new { |hash, key| hash[key] = [] } normalized_ranges = bucket_ranges.transform_values do |range| { floor: Gem::Version.new((range[:floor] || range["floor"]).to_s), ceiling: Gem::Version.new((range[:ceiling] || range["ceiling"]).to_s) } end matrix_entries.each do |entry| ruby_series = entry[:ruby_series] || entry["ruby_series"] range = normalized_ranges[ruby_series] next unless range lifecycle = appraisal_workflow_lifecycle(range.fetch(:floor)) grouped[lifecycle] << { ruby: appraisal_workflow_ruby(range.fetch(:floor), lifecycle), appraisal: entry[:name] || entry["name"], exec_cmd: exec_cmd, rubygems: "latest", bundler: "latest" } end grouped.transform_values { |entries| entries.sort_by { |entry| entry.fetch(:appraisal).to_s } } end |
.appraisal_workflow_lifecycle(ruby_floor) ⇒ Object
2712 2713 2714 2715 2716 2717 |
# File 'lib/kettle/jem.rb', line 2712 def appraisal_workflow_lifecycle(ruby_floor) APPRAISAL_WORKFLOW_LIFECYCLE_RANGES.each do |name, range| return name if ruby_floor.between?(range.fetch(:min), range.fetch(:max)) end (ruby_floor < APPRAISAL_WORKFLOW_LIFECYCLE_RANGES.fetch("ancient").fetch(:min)) ? "ancient" : "current" end |
.appraisal_workflow_ruby(ruby_floor, lifecycle) ⇒ Object
2719 2720 2721 2722 2723 2724 |
# File 'lib/kettle/jem.rb', line 2719 def appraisal_workflow_ruby(ruby_floor, lifecycle) return "ruby" if lifecycle == "current" segments = ruby_floor.segments "#{segments[0]}.#{segments[1] || 0}" end |
.appraisal_workflow_yaml_snippets(matrix_entries, bucket_ranges:, exec_cmd: "kettle-test") ⇒ Object
2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 |
# File 'lib/kettle/jem.rb', line 2698 def appraisal_workflow_yaml_snippets(matrix_entries, bucket_ranges:, exec_cmd: "kettle-test") appraisal_workflow_groups(matrix_entries, bucket_ranges: bucket_ranges, exec_cmd: exec_cmd).transform_values do |entries| lines = ["strategy:", " matrix:", " include:"] entries.each do |entry| lines << %( - ruby: "#{entry.fetch(:ruby)}") lines << %( appraisal: "#{entry.fetch(:appraisal)}") lines << %( exec_cmd: "#{entry.fetch(:exec_cmd)}") lines << %( rubygems: "#{entry.fetch(:rubygems)}") lines << %( bundler: "#{entry.fetch(:bundler)}") end lines.join("\n") end end |
.appraisal_x_stdlib_eval_gemfile_call(block) ⇒ Object
10249 10250 10251 10252 10253 |
# File 'lib/kettle/jem.rb', line 10249 def appraisal_x_stdlib_eval_gemfile_call(block) ruby_call_records(block, :eval_gemfile).find do |call| ruby_string_argument(call).to_s.start_with?("modular/x_std_libs") end end |
.appraisal_x_stdlib_exclusions(template_content) ⇒ Object
2726 2727 2728 2729 2730 2731 2732 2733 2734 |
# File 'lib/kettle/jem.rb', line 2726 def appraisal_x_stdlib_exclusions(template_content) gems = ruby_call_records(template_content, :eval_gemfile).filter_map do |call| path = ruby_string_argument(call).to_s next unless path.start_with?("../") path.delete_prefix("../").split("/").first end (gems + APPRAISAL_ALWAYS_EXCLUDED_GEMS).uniq.sort end |
.appraisals_policy_operations(template_content, original, final, request) ⇒ Object
6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 |
# File 'lib/kettle/jem.rb', line 6908 def appraisals_policy_operations(template_content, original, final, request) package_name = runtime_context_value(request, :package, :name).to_s min_ruby = minimum_ruby_token(runtime_context_value(request, :ci, :test_min_ruby) || runtime_context_value(request, :rubygems, :min_ruby)) source = "#{template_content}\n#{original}" [ { operation: "merge_appraisal_blocks", inserted_appraisals: (appraisal_names(template_content) - appraisal_names(original)).sort, preserved_destination_appraisals: (appraisal_names(original) - appraisal_names(template_content) & appraisal_names(final)).sort }, { operation: "delete_self_dependency_declarations", deleted_dependency_count: [gemfile_dependency_names(source).count(package_name) - gemfile_dependency_names(final).count(package_name), 0].max }, { operation: "prune_minimum_ruby_appraisals", min_ruby: min_ruby, deleted_appraisals: (ruby_appraisal_names_below(original, min_ruby) - appraisal_names(final)).sort } ] end |
.assert_no_unresolved_template_tokens_in_yaml_values(content, label) ⇒ Object
17769 17770 17771 17772 17773 17774 17775 |
# File 'lib/kettle/jem.rb', line 17769 def assert_no_unresolved_template_tokens_in_yaml_values(content, label) unresolved = yaml_scalar_value_template_tokens(content) return content if unresolved.empty? tokens = unresolved.map { |token| "{#{token}}" }.sort.join(", ") raise ArgumentError, "#{label}: unresolved kettle-jem template tokens: #{tokens}" end |
.author_aliases(config) ⇒ Object
14718 14719 14720 14721 14722 14723 14724 14725 14726 14727 14728 14729 14730 14731 14732 |
# File 'lib/kettle/jem.rb', line 14718 def (config) return {} unless config.is_a?(Hash) configured = config["author_aliases"] configured = config.dig("copyright", "author_aliases") if configured.nil? && config["copyright"].is_a?(Hash) return {} unless configured.is_a?(Hash) configured.each_with_object({}) do |(alias_name, canonical_name), aliases| alias_key = alias_name.to_s.strip.downcase canonical = canonical_name.to_s.strip next if alias_key.empty? || canonical.empty? aliases[alias_key] = canonical end end |
.author_facts(config, env, gemspec_metadata: {}, copyright: {}) ⇒ Object
14668 14669 14670 14671 14672 14673 14674 14675 14676 14677 14678 14679 14680 14681 14682 14683 14684 14685 14686 14687 14688 14689 14690 14691 |
# File 'lib/kettle/jem.rb', line 14668 def (config, env, gemspec_metadata: {}, copyright: {}) token_config = token_config_values(config) = token_config["author"].is_a?(Hash) ? token_config["author"] : {} aliases = (config) derived_name = Array([:authors]).map { |value| (value, aliases) }.find do |value| present_template_token_value?(value) end derived_email = Array([:email]).map(&:to_s).find { |value| present_template_token_value?(value) } name = preferred_template_token_value(derived_name, ["name"], env, "KJ_AUTHOR_NAME").to_s email = preferred_template_token_value(derived_email, ["email"], env, "KJ_AUTHOR_EMAIL").to_s given_names = preferred_template_token_value((name), ["given_names"], env, "KJ_AUTHOR_GIVEN_NAMES") family_names = preferred_template_token_value((name), ["family_names"], env, "KJ_AUTHOR_FAMILY_NAMES") domain = preferred_template_token_value(email.split("@", 2)[1], ["domain"], env, "KJ_AUTHOR_DOMAIN") orcid = preferred_template_token_value(nil, ["orcid"], env, "KJ_AUTHOR_ORCID") compact_hash( name: name, names: (, copyright, name, author_aliases: aliases), given_names: given_names.to_s, family_names: family_names.to_s, email: email, domain: domain.to_s, orcid: orcid.to_s ) end |
.author_family_names(name) ⇒ Object
17750 17751 17752 17753 17754 17755 |
# File 'lib/kettle/jem.rb', line 17750 def (name) parts = name.to_s.strip.split(/\s+/) return "" if parts.size < 2 parts[-1] end |
.author_given_names(name) ⇒ Object
17743 17744 17745 17746 17747 17748 |
# File 'lib/kettle/jem.rb', line 17743 def (name) parts = name.to_s.strip.split(/\s+/) return "" if parts.size < 2 parts[0...-1].join(" ") end |
.author_names(gemspec_metadata, copyright, primary_name, author_aliases: {}) ⇒ Object
14772 14773 14774 14775 14776 14777 14778 14779 14780 |
# File 'lib/kettle/jem.rb', line 14772 def (, copyright, primary_name, author_aliases: {}) names = Array([:authors]).map(&:to_s) names += (copyright) names = names .map { |name| (name, ) } .select { |name| present_template_token_value?(name) } names = [(primary_name, )] if names.empty? names.map(&:strip).reject(&:empty?).uniq end |
.author_template_tokens(author) ⇒ Object
14758 14759 14760 14761 14762 14763 14764 14765 14766 14767 14768 14769 14770 |
# File 'lib/kettle/jem.rb', line 14758 def () names = Array([:names]).map(&:to_s).reject(&:empty?) names = [[:name].to_s] if names.empty? { "KJ|AUTHOR:NAME" => [:name].to_s, "KJ|AUTHOR:NAMES" => ruby_array_literal(names), "KJ|AUTHOR:GIVEN_NAMES" => [:given_names].to_s, "KJ|AUTHOR:FAMILY_NAMES" => [:family_names].to_s, "KJ|AUTHOR:EMAIL" => [:email].to_s, "KJ|AUTHOR:DOMAIN" => [:domain].to_s, "KJ|AUTHOR:ORCID" => [:orcid].to_s } end |
.bash_merge_options(recipe) ⇒ Object
10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 |
# File 'lib/kettle/jem.rb', line 10422 def (recipe) = { preference: (recipe.dig(:template_preference, :preference) || "destination").to_sym, add_template_only_nodes: true, freeze_token: recipe.dig(:template_preference, :freeze_token) || "kettle-jem" } if !recipe.dig(:template_preference, :add_template_only_nodes).nil? configured = DecisionPolicy.value_to_boolean(recipe.dig(:template_preference, :add_template_only_nodes)) [:add_template_only_nodes] = configured unless configured.nil? end end |
.build_changelog_section(heading, preamble, items) ⇒ Object
6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 |
# File 'lib/kettle/jem.rb', line 6624 def build_changelog_section(heading, preamble, items) lines = [heading.rstrip, ""] preamble_lines = Array(preamble).map(&:rstrip) preamble_lines.pop while preamble_lines.any? && preamble_lines.last.to_s.strip.empty? if preamble_lines.any? lines.concat(preamble_lines) lines << "" end section_lines = build_changelog_unreleased_section(heading, items) lines.concat(section_lines.drop(2)) end |
.build_changelog_unreleased_section(heading, items) ⇒ Object
6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 |
# File 'lib/kettle/jem.rb', line 6189 def build_changelog_unreleased_section(heading, items) lines = [heading] CHANGELOG_STANDARD_HEADINGS.each do |standard_heading| lines << "" lines << standard_heading lines << "" section_items = items[standard_heading].to_a.dup section_items.pop while section_items.any? && section_items.last.to_s.strip.empty? lines.concat(section_items) if section_items.any? end lines << "" lines end |
.canonical_author_name(value, aliases) ⇒ Object
14734 14735 14736 14737 14738 14739 14740 14741 14742 14743 14744 14745 14746 14747 14748 |
# File 'lib/kettle/jem.rb', line 14734 def (value, aliases) current = value.to_s.strip seen = {} loop do key = current.downcase break if current.empty? || seen[key] seen[key] = true replacement = aliases[key] break if replacement.nil? || replacement.to_s.strip.empty? current = replacement.to_s.strip end current end |
.canonical_author_name_for_entry(entry, aliases) ⇒ Object
14750 14751 14752 14753 14754 14755 14756 |
# File 'lib/kettle/jem.rb', line 14750 def (entry, aliases) name = entry[:name].to_s.strip email = entry[:email].to_s.strip configured_name = aliases[name.downcase] configured_email = aliases[email.downcase] (configured_name || configured_email || name, aliases) end |
.canonical_changelog_release_heading(heading_text) ⇒ Object
6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 |
# File 'lib/kettle/jem.rb', line 6054 def canonical_changelog_release_heading(heading_text) text = heading_text.to_s.strip return if changelog_unreleased_heading?(text) || text.start_with?("[") version, date = text.split(" - ", 2) version = version.to_s.delete_prefix("v") # Markly owns heading discovery; Gem::Version is the bounded semantic # version parser because Markdown has no release-version node type. return unless Gem::Version.correct?(version) suffix = date ? " - #{date}" : "" "## [#{version}]#{suffix}" end |
.changed_files_from_recipe_reports(recipe_reports) ⇒ Object
4025 4026 4027 4028 4029 4030 4031 4032 |
# File 'lib/kettle/jem.rb', line 4025 def changed_files_from_recipe_reports(recipe_reports) latest_by_path = {} recipe_reports.each do |report| path = report[:relative_path] latest_by_path[path] = report if path end latest_by_path.values.filter_map { |report| report[:relative_path] if report[:changed] }.uniq.sort end |
.changelog_bullet_line?(line) ⇒ Boolean
6640 6641 6642 6643 |
# File 'lib/kettle/jem.rb', line 6640 def changelog_bullet_line?(line) stripped = line.to_s.lstrip stripped.start_with?("- ", "* ") end |
.changelog_coverage_kloc(section) ⇒ Object
7504 7505 7506 7507 7508 7509 7510 7511 |
# File 'lib/kettle/jem.rb', line 7504 def changelog_coverage_kloc(section) return if section.to_s.empty? match = section.to_s.match(CHANGELOG_COVERAGE_KLOC_PATTERN) return unless match format("%.3f", match[1].to_i.to_f / 1000.0) end |
.changelog_existing_transfer_occurrences(content) ⇒ Object
6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 |
# File 'lib/kettle/jem.rb', line 6563 def changelog_existing_transfer_occurrences(content) context = Ast::Crispr::Markdown::Markly.document_context(content: content, source_label: "CHANGELOG.md") release_sections = context.structural_owners(owner_scope: :heading_sections) .select { |owner| owner.level == 2 } .sort_by { |owner| owner.location.start_line } list_items = context.structural_owners(owner_scope: :list_items) list_items.filter_map do |item| next unless item.depth == 1 key = changelog_transfer_key(item.source) next unless key release = changelog_release_section_for_item(release_sections, item) next unless release { key: key, release_heading: "## #{release.heading_text}", start_line: item.location.start_line, end_line: item.location.end_line } end end |
.changelog_heading_line?(line) ⇒ Boolean
6672 6673 6674 6675 6676 |
# File 'lib/kettle/jem.rb', line 6672 def changelog_heading_line?(line) stripped = line.to_s.lstrip marker, text = stripped.split(" ", 2) !text.to_s.empty? && marker.to_s.each_char.all? { |char| char == "#" } end |
.changelog_release_section_for_item(release_sections, item) ⇒ Object
6587 6588 6589 6590 6591 6592 6593 6594 |
# File 'lib/kettle/jem.rb', line 6587 def changelog_release_section_for_item(release_sections, item) release_sections.each_with_index.find do |section, index| next_section = release_sections[index + 1] section_end_line = next_section ? next_section.location.start_line - 1 : section.location.end_line item.location.start_line > section.location.start_line && item.location.end_line <= section_end_line end&.first end |
.changelog_section_preamble(body_lines) ⇒ Object
6620 6621 6622 |
# File 'lib/kettle/jem.rb', line 6620 def changelog_section_preamble(body_lines) body_lines.take_while { |line| !line.to_s.start_with?("### ") }.map(&:rstrip) end |
.changelog_template_header(lines, unreleased_index) ⇒ Object
6130 6131 6132 6133 6134 |
# File 'lib/kettle/jem.rb', line 6130 def changelog_template_header(lines, unreleased_index) header = lines[0...unreleased_index].to_a header.pop while header.any? && header.last.to_s.strip.empty? header end |
.changelog_transfer_applied_keys(project_root) ⇒ Object
6274 6275 6276 6277 6278 6279 |
# File 'lib/kettle/jem.rb', line 6274 def changelog_transfer_applied_keys(project_root) path = File.join(project_root.to_s, "CHANGELOG.md") return Set.new unless File.file?(path) changelog_transfer_keys(File.read(path)) end |
.changelog_transfer_entries(template_root) ⇒ Object
6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 |
# File 'lib/kettle/jem.rb', line 6419 def changelog_transfer_entries(template_root) path = File.join(template_root, TRANSFER_CHANGELOG_TEMPLATE_PATH) return [] unless File.file?(path) content = File.read(path) context = Ast::Crispr::Markdown::Markly.document_context(content: content, source_label: path) sections = context.structural_owners(owner_scope: :heading_sections).select do |owner| owner.level == 2 && changelog_transfer_section_map.key?(owner.heading_text.to_s.strip) end list_items = context.structural_owners(owner_scope: :list_items) ordered_sections = sections.sort_by { |section| section.location.start_line } entries = ordered_sections.each_with_index.flat_map do |section, index| heading = changelog_transfer_section_map.fetch(section.heading_text.to_s.strip) next_section = ordered_sections[index + 1] section_end_line = next_section ? next_section.location.start_line - 1 : section.location.end_line list_items.filter_map do |item| next unless item.depth == 1 next unless item.location.start_line > section.location.start_line next unless item.location.end_line <= section_end_line payload = changelog_transfer_list_item_payload(item.source) parsed = parse_changelog_transfer_line(payload) lines = item.source.lines.map { |line| line.chomp.rstrip } lines[0] = changelog_transfer_list_item_line(item.source, parsed.fetch(:rendered_payload)) { key: parsed.fetch(:key), section: heading, lines: lines, filter: parsed[:filter] } end end validate_changelog_transfer_entries!(entries, path) entries.sort_by { |entry| entry.fetch(:key).to_s } end |
.changelog_transfer_entries_after(entries, key) ⇒ Object
6403 6404 6405 6406 6407 6408 6409 |
# File 'lib/kettle/jem.rb', line 6403 def changelog_transfer_entries_after(entries, key) all_entries = Array(entries) index = all_entries.index { |entry| entry.fetch(:key).to_s == key.to_s } return all_entries if index.nil? all_entries[(index + 1)..].to_a end |
.changelog_transfer_facts(project_root, entries) ⇒ Object
6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 |
# File 'lib/kettle/jem.rb', line 6203 def changelog_transfer_facts(project_root, entries) all_entries = Array(entries) latest = latest_changelog_transfer_entry(all_entries) lock = TemplateLock.load(project_root: project_root, config_path: kettle_jem_config_path(project_root)) state = lock[TemplateLock::TEMPLATE_STATE_KEY] state = state.is_a?(Hash) ? state : {} context = transfer_changelog_context(project_root) applicable_entries = all_entries.select { |entry| transfer_changelog_entry_applies?(entry, context) } excluded_keys = all_entries.reject { |entry| transfer_changelog_entry_applies?(entry, context) }.map { |entry| entry.fetch(:key).to_s } applied_keys = changelog_transfer_applied_keys(project_root) selected_entries = if state.empty? [CHANGELOG_INITIAL_TEMPLATE_ENTRY] else applicable_entries.reject { |entry| applied_keys.include?(entry.fetch(:key).to_s) } end { transfer_entries: selected_entries, excluded_transfer_keys: excluded_keys, latest_transfer_entry: latest, first_template: state.empty? }.compact end |
.changelog_transfer_filter_parser ⇒ Object
6466 6467 6468 6469 |
# File 'lib/kettle/jem.rb', line 6466 def changelog_transfer_filter_parser Thread.current.thread_variable_get(:kettle_jem_transfer_changelog_filter_parser) || Thread.current.thread_variable_set(:kettle_jem_transfer_changelog_filter_parser, TransferChangelogFilterParser.new) end |
.changelog_transfer_key(line) ⇒ Object
6529 6530 6531 6532 6533 6534 |
# File 'lib/kettle/jem.rb', line 6529 def changelog_transfer_key(line) payload = changelog_transfer_list_item_payload(line) parse_changelog_transfer_line(payload)&.fetch(:key) rescue Parslet::ParseFailed nil end |
.changelog_transfer_key_date(key) ⇒ Object
6411 6412 6413 6414 6415 6416 6417 |
# File 'lib/kettle/jem.rb', line 6411 def changelog_transfer_key_date(key) parsed = parse_changelog_transfer_key(key) return nil unless parsed date = parsed.fetch(:date) "#{date[0, 4]}-#{date[4, 2]}-#{date[6, 2]}" end |
.changelog_transfer_keys(content) ⇒ Object
6636 6637 6638 |
# File 'lib/kettle/jem.rb', line 6636 def changelog_transfer_keys(content) content.to_s.scan(CHANGELOG_TRANSFER_KEY_SCAN_PATTERN).to_set end |
.changelog_transfer_line_parser ⇒ Object
6461 6462 6463 6464 |
# File 'lib/kettle/jem.rb', line 6461 def changelog_transfer_line_parser Thread.current.thread_variable_get(:kettle_jem_transfer_changelog_line_parser) || Thread.current.thread_variable_set(:kettle_jem_transfer_changelog_line_parser, TransferChangelogLineParser.new) end |
.changelog_transfer_list_item_line(source, rendered_payload) ⇒ Object
6510 6511 6512 6513 6514 6515 |
# File 'lib/kettle/jem.rb', line 6510 def changelog_transfer_list_item_line(source, rendered_payload) first_line = source.to_s.lines.first.to_s indentation = first_line.each_char.take_while { |character| character.match?(" ") || character.match?("\t") }.join marker = first_line.lstrip.start_with?("* ") ? "*" : "-" "#{indentation}#{marker} #{rendered_payload}" end |
.changelog_transfer_list_item_payload(source) ⇒ Object
6471 6472 6473 6474 6475 6476 6477 6478 6479 |
# File 'lib/kettle/jem.rb', line 6471 def changelog_transfer_list_item_payload(source) stripped = source.to_s.lines.first.to_s.lstrip.chomp %w[- *].each do |marker| prefix = "#{marker} " return stripped.delete_prefix(prefix) if stripped.start_with?(prefix) end stripped end |
.changelog_transfer_section_map ⇒ Object
6455 6456 6457 6458 6459 |
# File 'lib/kettle/jem.rb', line 6455 def changelog_transfer_section_map CHANGELOG_STANDARD_HEADINGS.to_h do |heading| [heading.delete_prefix("### ").strip, heading] end end |
.changelog_unreleased_end_index(lines, unreleased_index) ⇒ Object
6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 |
# File 'lib/kettle/jem.rb', line 6147 def changelog_unreleased_end_index(lines, unreleased_index) index = unreleased_index + 1 while index < lines.length line = lines.fetch(index) # Markdown link-reference definitions are footer content, not Unreleased section body. return index if markdown_link_reference_definition_line?(line) return index if line.start_with?("# ") || (line.start_with?("## ") && !changelog_unreleased_heading_line?(line)) index += 1 end lines.length end |
.changelog_unreleased_heading?(heading_text) ⇒ Boolean
6678 6679 6680 6681 6682 |
# File 'lib/kettle/jem.rb', line 6678 def changelog_unreleased_heading?(heading_text) text = heading_text.to_s.strip text = text[1...-1] if text.start_with?("[") && text.end_with?("]") text.casecmp("Unreleased").zero? end |
.changelog_unreleased_heading_line?(line) ⇒ Boolean
6140 6141 6142 6143 6144 6145 |
# File 'lib/kettle/jem.rb', line 6140 def changelog_unreleased_heading_line?(line) text = line.to_s.strip return false unless text.start_with?("## ") changelog_unreleased_heading?(text.delete_prefix("## ").strip) end |
.changelog_unreleased_items(body_lines) ⇒ Object
6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 |
# File 'lib/kettle/jem.rb', line 6164 def changelog_unreleased_items(body_lines) items = {} heading = nil index = 0 while index < body_lines.length line = body_lines.fetch(index) if line.start_with?("### ") heading = line.strip items[heading] ||= [] index += 1 next end if changelog_bullet_line?(line) lines, index = collect_changelog_list_item(body_lines, index) items[heading] ||= [] items[heading].concat(lines) next end index += 1 end items end |
.changelog_unreleased_line_index(lines) ⇒ Object
6136 6137 6138 |
# File 'lib/kettle/jem.rb', line 6136 def changelog_unreleased_line_index(lines) lines.index { |line| changelog_unreleased_heading_line?(line) } end |
.changelog_unreleased_transfer_keys(project_root) ⇒ Object
6281 6282 6283 6284 6285 6286 6287 6288 6289 |
# File 'lib/kettle/jem.rb', line 6281 def changelog_unreleased_transfer_keys(project_root) path = File.join(project_root.to_s, "CHANGELOG.md") return Set.new unless File.file?(path) changelog_existing_transfer_occurrences(File.read(path)) .select { |occurrence| occurrence.fetch(:release_heading) == "## [Unreleased]" } .map { |occurrence| occurrence.fetch(:key).to_s } .to_set end |
.changelog_version_heading_line?(line, version) ⇒ Boolean
7495 7496 7497 7498 7499 7500 7501 7502 |
# File 'lib/kettle/jem.rb', line 7495 def changelog_version_heading_line?(line, version) text = line.to_s.strip return false unless text.start_with?("## ") heading = text.delete_prefix("## ").strip heading = heading[1...heading.index("]")] if heading.start_with?("[") && heading.include?("]") heading == version || heading.start_with?("#{version} ") end |
.checksum_cache_safe_report?(report) ⇒ Boolean
4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 |
# File 'lib/kettle/jem.rb', line 4140 def checksum_cache_safe_report?(report) = report.fetch(:metadata, {}) preference = [:template_source_preference] || ["template_source_preference"] return false unless preference.is_a?(Hash) return false if report.dig(:metadata, :delete_file) || report.dig(:metadata, "delete_file") # Config migrations are implemented during template application. They must # run even when the template source and destination checksums still match. return false if report.fetch(:relative_path, "").to_s == KETTLE_CONFIG_PATH primitive = report.dig(:request_envelope, :request, :recipe_name).to_s primitive == "supplied_template_source_application" end |
.checksum_exact_match?(report) ⇒ Boolean
4071 4072 4073 4074 4075 |
# File 'lib/kettle/jem.rb', line 4071 def checksum_exact_match?(report) checksum_match = report.dig(:metadata, :checksum_match) || report.dig(:metadata, "checksum_match") || {} (checksum_match[:input_match] == true && checksum_match[:destination_match] == true) || (checksum_match["input_match"] == true && checksum_match["destination_match"] == true) end |
.checksum_file_records(project_root, report, existing_state) ⇒ Object
5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 |
# File 'lib/kettle/jem.rb', line 5232 def checksum_file_records(project_root, report, existing_state) existing_records = TemplateLock.files(existing_state).each_with_object({}) do |(relative_path, record), retained| action = record.is_a?(Hash) ? record["action"].to_s : "" next if action != "delete" && !File.exist?(File.join(project_root, relative_path.to_s)) retained[relative_path] = record end report.fetch(:recipe_reports, []).each_with_object(existing_records.dup) do |recipe_report, records| next unless checksum_cache_safe_report?(recipe_report) relative_path = recipe_report.fetch(:relative_path).to_s existing = records[relative_path].is_a?(Hash) ? records[relative_path].dup : {} if recipe_report[:checksum_skipped] records[relative_path] = existing.merge( "recipe" => recipe_report[:recipe_name].to_s, "input_fingerprint" => template_input_fingerprint(project_root, recipe_report), "template_sources" => [template_source_lock_path( recipe_report.dig(:metadata, :template_source_preference) || recipe_report.dig(:metadata, "template_source_preference") || {} )].reject(&:empty?) ) next end records[relative_path] = { "recipe" => recipe_report[:recipe_name].to_s, "action" => recipe_report.dig(:metadata, :delete_file) ? "delete" : "write", "dest_sha256" => destination_file_sha256(project_root, relative_path), "input_fingerprint" => template_input_fingerprint(project_root, recipe_report), "template_sources" => [template_source_lock_path( recipe_report.dig(:metadata, :template_source_preference) || recipe_report.dig(:metadata, "template_source_preference") || {} )].reject(&:empty?) }.compact end end |
.checksum_match_details(project_root, report, checksum_mode:, template_lock:) ⇒ Object
4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 |
# File 'lib/kettle/jem.rb', line 4115 def checksum_match_details(project_root, report, checksum_mode:, template_lock:) return unless checksum_cache_safe_report?(report) relative_path = report.fetch(:relative_path).to_s # `template,ignore-dest` preserves a user edit to an existing managed # file, but it must never turn a missing managed file into a cache hit. # Otherwise a prior partial template run can retain an empty SHA record # and leave an aggregate Gemfile referring to a leaf it never creates. return unless File.file?(File.join(project_root.to_s, relative_path)) record = TemplateLock.file_record(template_lock, relative_path) return if record.empty? input_match = record["input_fingerprint"].to_s == template_input_fingerprint(project_root, report) destination_match = record["dest_sha256"].to_s == destination_file_sha256(project_root, relative_path).to_s if checksum_mode.check_template? return if record["input_fingerprint"].to_s.empty? || !input_match end if checksum_mode.check_destination? return if record["dest_sha256"].to_s.empty? || !destination_match end {input_match: input_match, destination_match: destination_match} end |
.checksum_mode_for(env, run_options) ⇒ Object
4077 4078 4079 4080 4081 4082 |
# File 'lib/kettle/jem.rb', line 4077 def checksum_mode_for(env, ) raw = ( || {})[:checksums] || ( || {})["checksums"] || (env || {})["KETTLE_JEM_CHECKSUMS"] ChecksumMode.parse(raw) end |
.checksum_skip_report?(project_root, report, checksum_mode:, template_lock:) ⇒ Boolean
4109 4110 4111 4112 4113 |
# File 'lib/kettle/jem.rb', line 4109 def checksum_skip_report?(project_root, report, checksum_mode:, template_lock:) return false unless report[:changed] !checksum_match_details(project_root, report, checksum_mode: checksum_mode, template_lock: template_lock).nil? end |
.classify_namespace(name) ⇒ Object
19202 19203 19204 |
# File 'lib/kettle/jem.rb', line 19202 def classify_namespace(name) name.to_s.split(/[-_]/).map { |part| part[0].to_s.upcase + part[1..].to_s }.join("::") end |
.cleanup_version_gem_entrypoint(project_root, entrypoint_path) ⇒ Object
15819 15820 15821 15822 15823 15824 15825 |
# File 'lib/kettle/jem.rb', line 15819 def cleanup_version_gem_entrypoint(project_root, entrypoint_path) current = read_project_file(project_root, entrypoint_path) return if current.empty? return unless current.include?('require "version_gem"') && current.include?("VersionGem::Basic") delete_project_file(project_root, entrypoint_path) end |
.cleanup_version_gem_version_spec(project_root, version_spec_path) ⇒ Object
15812 15813 15814 15815 15816 15817 |
# File 'lib/kettle/jem.rb', line 15812 def cleanup_version_gem_version_spec(project_root, version_spec_path) current = read_project_file(project_root, version_spec_path) return if current.empty? || !managed_version_gem_version_spec?(current) delete_project_file(project_root, version_spec_path) end |
.codeberg_repo_url(repository, repo_slug, suffix) ⇒ Object
16782 16783 16784 16785 16786 16787 16788 16789 16790 |
# File 'lib/kettle/jem.rb', line 16782 def codeberg_repo_url(repository, repo_slug, suffix) resources = repository[:resource_urls] || {} return resources[:codeberg_issues_url] if suffix == "issues" && resources[:codeberg_issues_url] return resources[:codeberg_pulls_url] if suffix == "pulls" && resources[:codeberg_pulls_url] base = repository[:codeberg_url].to_s base = "https://codeberg.org/#{repo_slug}" if base.empty? "#{base}/#{suffix}" end |
.collapse_excess_blank_lines(content) ⇒ Object
16231 16232 16233 16234 16235 16236 16237 16238 16239 16240 16241 16242 |
# File 'lib/kettle/jem.rb', line 16231 def collapse_excess_blank_lines(content) blank_count = 0 content.to_s.lines.filter_map do |line| if line.strip.empty? blank_count += 1 next if blank_count > 1 else blank_count = 0 end line end.join end |
.collapse_nested_templating_guards(content) ⇒ Object
8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 |
# File 'lib/kettle/jem.rb', line 8322 def collapse_nested_templating_guards(content) records = nested_templating_guard_records(content) return content if records.empty? output = content.to_s records.sort_by { |record| -record.fetch(:outer_start_line) }.each do |record| inner_source = output.lines[(record.fetch(:inner_start_line) - 1)..(record.fetch(:inner_end_line) - 1)].join inner_source = outdent_source(inner_source, 2) output = replace_source_range_lines(output, record.fetch(:outer_start_line), record.fetch(:outer_end_line), inner_source) end output end |
.collect_changelog_list_item(lines, start_index) ⇒ Object
6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 |
# File 'lib/kettle/jem.rb', line 6645 def collect_changelog_list_item(lines, start_index) line = lines.fetch(start_index).to_s base_indent = line.length - line.lstrip.length item_lines = [line.rstrip] index = start_index + 1 in_fence = false while index < lines.length current = lines.fetch(index).to_s current_indent = current.length - current.lstrip.length break if !in_fence && changelog_heading_line?(current) break if !in_fence && changelog_bullet_line?(current) && current_indent <= base_indent if current.lstrip.start_with?("```") in_fence = !in_fence item_lines << current.rstrip index += 1 next end break unless in_fence || current.strip.empty? || current_indent > base_indent item_lines << current.rstrip index += 1 end [item_lines, index] end |
.collect_yaml_mapping_path_entries(node, path, entries) ⇒ Object
20084 20085 20086 20087 20088 20089 20090 20091 20092 20093 20094 20095 20096 20097 20098 20099 20100 20101 20102 20103 20104 20105 20106 20107 20108 20109 |
# File 'lib/kettle/jem.rb', line 20084 def collect_yaml_mapping_path_entries(node, path, entries) unless node.is_a?(Psych::Nodes::Mapping) Array(node.respond_to?(:children) ? node.children : nil).each do |child| collect_yaml_mapping_path_entries(child, path, entries) end return end node.children.each_slice(2) do |key_node, value_node| next unless key_node.is_a?(Psych::Nodes::Scalar) child_path = path + [key_node.value.to_s] if value_node.is_a?(Psych::Nodes::Mapping) entries << { path: child_path, start_line: key_node.start_line, end_line: value_node.end_line } collect_yaml_mapping_path_entries(value_node, child_path, entries) else Array(value_node.respond_to?(:children) ? value_node.children : nil).each do |child| collect_yaml_mapping_path_entries(child, child_path, entries) end end end end |
.collect_yaml_scalar_path_entries(node, path, entries) ⇒ Object
20066 20067 20068 20069 20070 20071 20072 20073 20074 20075 20076 20077 20078 20079 20080 20081 20082 |
# File 'lib/kettle/jem.rb', line 20066 def collect_yaml_scalar_path_entries(node, path, entries) unless node.is_a?(Psych::Nodes::Mapping) node.children.each { |child| collect_yaml_scalar_path_entries(child, path, entries) } if node.respond_to?(:children) return end node.children.each_slice(2) do |key_node, value_node| next unless key_node.is_a?(Psych::Nodes::Scalar) child_path = path + [key_node.value.to_s] if value_node.is_a?(Psych::Nodes::Scalar) entries << {path: child_path, line: key_node.start_line} elsif value_node.is_a?(Psych::Nodes::Mapping) collect_yaml_scalar_path_entries(value_node, child_path, entries) end end end |
.comment_only_lines?(lines) ⇒ Boolean
12634 12635 12636 |
# File 'lib/kettle/jem.rb', line 12634 def comment_only_lines?(lines) Array(lines).all? { |line| comment_or_blank_line?(line) } end |
.comment_or_blank_line?(line) ⇒ Boolean
12629 12630 12631 12632 |
# File 'lib/kettle/jem.rb', line 12629 def comment_or_blank_line?(line) stripped = line.to_s.strip stripped.empty? || stripped.start_with?("#") end |
.commented_gem_call(comment_source) ⇒ Object
9858 9859 9860 9861 9862 9863 9864 9865 9866 |
# File 'lib/kettle/jem.rb', line 9858 def commented_gem_call(comment_source) source = uncomment_ruby_comment_line(comment_source) return unless source result = prism_parse_success(source) body = result&.value&.statements&.body call = body&.one? ? body.first : nil call if call.is_a?(::Prism::CallNode) && call.name == :gem end |
.commented_gem_dependency_block_records(content) ⇒ Object
9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 |
# File 'lib/kettle/jem.rb', line 9543 def commented_gem_dependency_block_records(content) lines = content.to_s.lines commented_gem_dependency_records(content).map do |record| start_index = record.fetch(:start_line) - 1 while start_index.positive? && gemfile_comment_line?(lines[start_index - 1]) start_index -= 1 end record.merge( block_start_line: start_index + 1, block_end_line: record.fetch(:end_line), source_lines: lines[start_index..(record.fetch(:end_line) - 1)] || [] ) end end |
.commented_gem_dependency_blocks(content) ⇒ Object
9537 9538 9539 9540 9541 |
# File 'lib/kettle/jem.rb', line 9537 def commented_gem_dependency_blocks(content) commented_gem_dependency_block_records(content).to_h do |record| [record.fetch(:name), record.fetch(:source_lines)] end end |
.commented_gem_dependency_records(content) ⇒ Object
9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 |
# File 'lib/kettle/jem.rb', line 9841 def commented_gem_dependency_records(content) result = prism_parse_success(content) return [] unless result result.comments.filter_map do |comment| call = commented_gem_call(comment.location.slice) name = ruby_string_argument(call) next unless name { name: name, start_line: comment.location.start_line, end_line: comment.location.end_line } end end |
.commit_file_outcome(file_outcome) ⇒ Object
13983 13984 13985 |
# File 'lib/kettle/jem.rb', line 13983 def commit_file_outcome(file_outcome) commit_filesystem_outcome(file_outcome) end |
.commit_file_work_unit(file_work_unit) ⇒ Object
13924 13925 13926 |
# File 'lib/kettle/jem.rb', line 13924 def commit_file_work_unit(file_work_unit) file_work_unit.operations.each { |operation| commit_file_outcome(operation) } end |
.commit_file_work_unit_payload(payload) ⇒ Object
13991 13992 13993 13994 |
# File 'lib/kettle/jem.rb', line 13991 def commit_file_work_unit_payload(payload) Array(payload.fetch(:operations)).each { |operation| commit_filesystem_outcome_payload(operation) } payload.fetch(:relative_path) end |
.commit_file_work_units(file_work_units, workers: 0, thread_workers: 0, stats: nil) ⇒ Object
13868 13869 13870 13871 13872 13873 13874 13875 13876 13877 13878 13879 |
# File 'lib/kettle/jem.rb', line 13868 def commit_file_work_units(file_work_units, workers: 0, thread_workers: 0, stats: nil) units = Array(file_work_units) return if units.empty? raise ArgumentError, "Use either KETTLE_JEM_RACTOR_FILE_WORKERS or KETTLE_JEM_THREAD_FILE_WORKERS, not both" if workers.to_i.positive? && thread_workers.to_i.positive? record_file_work_execution_stats(stats, units: units, workers: workers.to_i, thread_workers: thread_workers.to_i) return commit_file_work_units_thread(units, workers: thread_workers.to_i) if thread_workers.to_i.positive? return commit_file_work_units_ractor(units, workers: workers.to_i) if workers.to_i.positive? units.each { |file_work_unit| commit_file_work_unit(file_work_unit) } end |
.commit_file_work_units_ractor(file_work_units, workers:) ⇒ Object
13905 13906 13907 13908 13909 13910 13911 13912 13913 13914 |
# File 'lib/kettle/jem.rb', line 13905 def commit_file_work_units_ractor(file_work_units, workers:) distribute_file_work_units(file_work_units, workers).map do |chunk| payloads = Ractor.make_shareable(chunk.map { |file_work_unit| file_work_unit_payload(file_work_unit) }) Ractor.new(payloads) do |worker_payloads| worker_payloads.map do |worker_payload| Kettle::Jem.commit_file_work_unit_payload(worker_payload) end end end.each(&:value) end |
.commit_file_work_units_thread(file_work_units, workers:) ⇒ Object
13897 13898 13899 13900 13901 13902 13903 |
# File 'lib/kettle/jem.rb', line 13897 def commit_file_work_units_thread(file_work_units, workers:) distribute_file_work_units(file_work_units, workers).map do |chunk| # rubocop:disable ThreadSafety/NewThread -- Independent file units are joined before this method returns. Thread.new { chunk.each { |file_work_unit| commit_file_work_unit(file_work_unit) } } # rubocop:enable ThreadSafety/NewThread end.each(&:join) end |
.commit_filesystem_outcome(file_outcome) ⇒ Object
13987 13988 13989 |
# File 'lib/kettle/jem.rb', line 13987 def commit_filesystem_outcome(file_outcome) commit_filesystem_outcome_payload(file_outcome_payload(file_outcome)) end |
.commit_filesystem_outcome_payload(payload) ⇒ Object
13996 13997 13998 13999 14000 14001 14002 14003 14004 14005 14006 14007 |
# File 'lib/kettle/jem.rb', line 13996 def commit_filesystem_outcome_payload(payload) path = payload.fetch(:absolute_path) action = payload.fetch(:action).to_s if action == "delete" File.delete(path) if File.exist?(path) || File.symlink?(path) elsif action == "write" mkdir_p_core(File.dirname(path)) File.write(path, payload.fetch(:content)) else raise ArgumentError, "Unsupported file outcome action #{action.inspect}" end end |
.commit_write_intent(write_intent) ⇒ Object
13979 13980 13981 |
# File 'lib/kettle/jem.rb', line 13979 def commit_write_intent(write_intent) commit_file_outcome(write_intent) end |
.compact_hash(hash) ⇒ Object
20238 20239 20240 |
# File 'lib/kettle/jem.rb', line 20238 def compact_hash(hash) hash.reject { |_key, value| value.nil? || (value.respond_to?(:empty?) && value.empty?) } end |
.compatible_dependency_requirements?(direct_requirements, modular_requirements) ⇒ Boolean
9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 |
# File 'lib/kettle/jem.rb', line 9725 def compatible_dependency_requirements?(direct_requirements, modular_requirements) direct = Gem::Requirement.new(*Array(direct_requirements).map(&:to_s)) modular = Gem::Requirement.new(*Array(modular_requirements).map(&:to_s)) candidates = ["0.0.0", "1.0.0", "2.0.0", "3.0.0", "4.0.0", "5.0.0", "6.0.0", "10.0.0"] [direct, modular].each do |requirement| requirement.requirements.each do |operator, version| base = version.to_s.split(".").map(&:to_i) base << 0 while base.length < 3 candidates << base.join(".") candidates << [base[0], base[1] + 1, 0].join(".") if operator == "~>" end end candidates.uniq.any? do |version| version = Gem::Version.new(version) direct.satisfied_by?(version) && modular.satisfied_by?(version) end rescue ArgumentError false end |
.concrete_github_url(url) ⇒ Object
16620 16621 16622 |
# File 'lib/kettle/jem.rb', line 16620 def concrete_github_url(url) github_org_from_url(url) ? url.to_s : nil end |
.config_min_ruby(config) ⇒ Object
18821 18822 18823 18824 18825 |
# File 'lib/kettle/jem.rb', line 18821 def config_min_ruby(config) value = config.dig("rubygems", "min_ruby") || config["min_ruby"] version = value.to_s[/\d+\.\d+(?:\.\d+)?/] version && Gem::Version.new(version) end |
.config_test_min_ruby(config, gem_min_ruby = nil) ⇒ Object
18827 18828 18829 18830 18831 18832 18833 18834 18835 18836 18837 18838 18839 18840 18841 18842 |
# File 'lib/kettle/jem.rb', line 18827 def config_test_min_ruby(config, gem_min_ruby = nil) config ||= {} configured = config.dig("ruby", "test_minimum") configured_version = configured.to_s[/\d+\.\d+(?:\.\d+)?/] test_minimum = configured_version ? Gem::Version.new(configured_version) : DEFAULT_TEST_MINIMUM_RUBY test_minimum = [test_minimum, DEFAULT_TEST_MINIMUM_RUBY].max gem_minimum = if gem_min_ruby token = minimum_ruby_token(gem_min_ruby) Gem::Version.new(token) unless token.empty? else config_min_ruby(config) end gem_minimum ? [test_minimum, gem_minimum].max : test_minimum rescue ArgumentError DEFAULT_TEST_MINIMUM_RUBY end |
.configured_disabled_integrations(config) ⇒ Object
17915 17916 17917 17918 17919 17920 17921 17922 17923 17924 17925 17926 17927 17928 17929 |
# File 'lib/kettle/jem.rb', line 17915 def configured_disabled_integrations(config) integrations = if config.is_a?(Hash) && config["integrations"].is_a?(Hash) config["integrations"] else {} end disabled = Array(integrations["disabled"]).map(&:to_s) integrations.each do |name, value| normalized = normalize_integration_name(name) next if normalized.empty? || normalized == "disabled" disabled << normalized if falsey_config?(value) end disabled.map { |name| normalize_integration_name(name) }.uniq & MANAGED_INTEGRATIONS end |
.configured_readme_top_logo_entries(config, org:, gem_name:, repository: {}) ⇒ Object
17075 17076 17077 17078 17079 17080 17081 17082 17083 17084 17085 17086 17087 |
# File 'lib/kettle/jem.rb', line 17075 def configured_readme_top_logo_entries(config, org:, gem_name:, repository: {}) readme_config = (config.is_a?(Hash) && config["readme"].is_a?(Hash)) ? config["readme"] : {} logo_row = readme_config["logo_row"] return unless logo_row.is_a?(Hash) return [] if falsey_config?(logo_row["enabled"]) logos = Array(logo_row["logos"]).first(4) return [] if logos.empty? logos.filter_map do |logo| readme_top_logo_entry_from_config(logo, org: org, gem_name: gem_name, repository: repository) end.then { |entries| deduplicate_readme_top_logo_entries(entries) } end |
.content_recipe_execution_report(request:, final_content:, changed:, step_reports:, diagnostics:, metadata: nil) ⇒ Object
5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 |
# File 'lib/kettle/jem.rb', line 5975 def content_recipe_execution_report(request:, final_content:, changed:, step_reports:, diagnostics:, metadata: nil) compact_hash( request: deep_dup(request), final_content: final_content.to_s, changed: changed ? true : false, step_reports: deep_dup(step_reports), diagnostics: deep_dup(diagnostics), metadata: deep_dup( || {}) ) end |
.content_recipe_execution_report_envelope(report) ⇒ Object
5986 5987 5988 5989 5990 5991 5992 |
# File 'lib/kettle/jem.rb', line 5986 def content_recipe_execution_report_envelope(report) { kind: "content_recipe_execution_report", version: CONTENT_RECIPE_TRANSPORT_VERSION, report: deep_dup(report) } end |
.content_recipe_execution_request(recipe_name:, recipe_version:, relative_path:, provider_family:, template_content:, destination_content:, steps:, provider_backend: nil, runtime_context: nil, metadata: nil) ⇒ Object
5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 |
# File 'lib/kettle/jem.rb', line 5951 def content_recipe_execution_request(recipe_name:, recipe_version:, relative_path:, provider_family:, template_content:, destination_content:, steps:, provider_backend: nil, runtime_context: nil, metadata: nil) compact_hash( recipe_name: recipe_name.to_s, recipe_version: recipe_version.to_s, relative_path: relative_path.to_s, provider_family: provider_family.to_s, provider_backend: provider_backend&.to_s, template_content: template_content.to_s, destination_content: destination_content.to_s, steps: deep_dup(steps), runtime_context: deep_dup(runtime_context || {}), metadata: deep_dup( || {}) ) end |
.content_recipe_execution_request_envelope(request) ⇒ Object
5967 5968 5969 5970 5971 5972 5973 |
# File 'lib/kettle/jem.rb', line 5967 def content_recipe_execution_request_envelope(request) { kind: "content_recipe_execution_request", version: CONTENT_RECIPE_TRANSPORT_VERSION, request: deep_dup(request) } end |
.content_recipe_step(recipe) ⇒ Object
6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 |
# File 'lib/kettle/jem.rb', line 6817 def content_recipe_step(recipe) step = { step_id: recipe.fetch(:name), step_kind: recipe.fetch(:primitive), name: recipe.fetch(:name), provider_family: recipe.fetch(:provider_family), metadata: {target_path: recipe.fetch(:target_path)} } step[:provider_backend] = recipe[:provider_backend] if recipe[:provider_backend] if recipe.fetch(:primitive) == "supplied_source_selector_deletion" step[:step_kind] = "native_policy" step[:policy] = { policy_kind: "delete_supplied_structural_owners", required_context: "delete_selectors", operation: "delete", selector_family: "structural_owner_range", normalize_blank_lines: true } end step end |
.content_recipe_step_report(recipe:, request:, original:, final:, changed:, deletion: nil) ⇒ Object
6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 |
# File 'lib/kettle/jem.rb', line 6839 def content_recipe_step_report(recipe:, request:, original:, final:, changed:, deletion: nil) operation_profile = Ast::Merge.structured_edit_operation_profile( operation_kind: recipe.fetch(:primitive), known_operation_kind: true, source_requirement: "destination_content", destination_requirement: "relative_path", replacement_source: "runtime_context", captures_source_text: false, supports_if_missing: true, operation_family: "kettle-jem" ) result = Ast::Merge.structured_edit_result( operation_kind: recipe.fetch(:primitive), updated_content: final, changed: changed, operation_profile: operation_profile ) application = Ast::Merge.structured_edit_application(request: request, result: result) { step_id: recipe.fetch(:name), step_kind: recipe.fetch(:primitive), status: changed ? "applied" : "unchanged", changed: changed, input_content: original, output_content: final, application: application, diagnostics: [], metadata: (recipe, deletion).merge( ruby_template_policy_report(recipe: recipe, request: request, original: original, final: final) ) } end |
.copy_only_when_missing_template_path?(relative_path) ⇒ Boolean
18409 18410 18411 |
# File 'lib/kettle/jem.rb', line 18409 def copy_only_when_missing_template_path?(relative_path) COPY_ONLY_WHEN_MISSING_TEMPLATE_PATHS.include?(relative_path.to_s) end |
.copyright_author_names(copyright) ⇒ Object
14782 14783 14784 14785 14786 |
# File 'lib/kettle/jem.rb', line 14782 def (copyright) Array(copyright[:lines]).filter_map do |line| copyright_name_from_line(line.to_s) end end |
.copyright_bot_entry?(entry) ⇒ Boolean
14905 14906 14907 |
# File 'lib/kettle/jem.rb', line 14905 def copyright_bot_entry?(entry) entry[:name].to_s.match?(BOT_IDENTITY_PATTERN) || entry[:email].to_s.match?(BOT_IDENTITY_PATTERN) end |
.copyright_facts(project_root, config) ⇒ Object
14805 14806 14807 14808 14809 14810 14811 14812 |
# File 'lib/kettle/jem.rb', line 14805 def copyright_facts(project_root, config) lines = git_copyright_lines( project_root, copyright_machine_users(config), author_aliases: (config) ) compact_hash(lines: lines) end |
.copyright_machine_user_entry?(entry, machine_users, author_aliases: {}) ⇒ Boolean
14909 14910 14911 14912 14913 14914 14915 14916 14917 14918 |
# File 'lib/kettle/jem.rb', line 14909 def copyright_machine_user_entry?(entry, machine_users, author_aliases: {}) return false if machine_users.empty? identities = [ entry[:name], entry[:email], (entry, ) ].map { |identity| identity.to_s.downcase.strip } identities.any? { |identity| machine_users.include?(identity) } end |
.copyright_machine_users(config) ⇒ Object
14814 14815 14816 14817 14818 |
# File 'lib/kettle/jem.rb', line 14814 def copyright_machine_users(config) copyright = config["copyright"].is_a?(Hash) ? config["copyright"] : {} configured = DEFAULT_MACHINE_USERS + Array(config["machine_users"]) + Array(copyright["machine_users"]) configured.map { |user| user.to_s.downcase.strip }.reject(&:empty?).uniq end |
.copyright_name_from_line(line) ⇒ Object
14788 14789 14790 14791 14792 14793 14794 14795 |
# File 'lib/kettle/jem.rb', line 14788 def copyright_name_from_line(line) prefix = "Copyright (c) " return unless line.start_with?(prefix) tokens = line[prefix.length..].to_s.split tokens.shift while tokens.first && copyright_year_token?(tokens.first) tokens.join(" ").strip.then { |name| name unless name.empty? } end |
.copyright_notice_lines(copyright_lines, copyright_prefix, author) ⇒ Object
17523 17524 17525 17526 17527 |
# File 'lib/kettle/jem.rb', line 17523 def copyright_notice_lines(copyright_lines, copyright_prefix, ) lines = Array(copyright_lines) lines = ["Copyright (c) #{Time.now.utc.year} #{[[:given_names], [:family_names]].compact.join(" ").strip}"] if lines.empty? lines.map { |line| "#{copyright_prefix}#{line}" } end |
.copyright_year_token?(token) ⇒ Boolean
14797 14798 14799 |
# File 'lib/kettle/jem.rb', line 14797 def copyright_year_token?(token) token.delete(",-").chars.all? { |char| char.between?("0", "9") } end |
.coverage_thresholds_from_mise(content) ⇒ Object
7263 7264 7265 7266 7267 7268 |
# File 'lib/kettle/jem.rb', line 7263 def coverage_thresholds_from_mise(content) COVERAGE_THRESHOLD_KEYS.each_with_object({}) do |key, thresholds| value = toml_string_scalar_line_value(content, key) thresholds[key] = value if value end end |
.coverage_thresholds_from_project_mise(project_root) ⇒ Object
7381 7382 7383 7384 7385 7386 7387 7388 |
# File 'lib/kettle/jem.rb', line 7381 def coverage_thresholds_from_project_mise(project_root) return {} if project_root.to_s.empty? path = File.join(project_root.to_s, "mise.toml") return {} unless File.file?(path) coverage_thresholds_from_mise(File.read(path)) end |
.coverage_thresholds_from_workflow(project_root) ⇒ Object
7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 |
# File 'lib/kettle/jem.rb', line 7270 def coverage_thresholds_from_workflow(project_root) return {} if project_root.to_s.empty? path = File.join(project_root.to_s, ".github", "workflows", "coverage.yml") return {} unless File.file?(path) content = File.read(path) COVERAGE_THRESHOLD_KEYS.each_with_object({}) do |key, thresholds| value = yaml_scalar_line_value(content, key) thresholds[key] = value.to_s.delete_prefix("\"").delete_suffix("\"") if value end end |
.coverage_thresholds_from_yaml_workflow(content) ⇒ Object
7390 7391 7392 7393 7394 7395 |
# File 'lib/kettle/jem.rb', line 7390 def coverage_thresholds_from_yaml_workflow(content) COVERAGE_THRESHOLD_KEYS.each_with_object({}) do |key, thresholds| value = yaml_scalar_line_value(content, key) thresholds[key] = value if value end end |
.current_changelog_version_section(content, version) ⇒ Object
7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 |
# File 'lib/kettle/jem.rb', line 7483 def current_changelog_version_section(content, version) version_text = version.to_s.strip return if version_text.empty? lines = content.to_s.lines start_index = lines.index { |line| changelog_version_heading_line?(line, version_text) } return unless start_index end_index = lines[(start_index + 1)..].to_a.index { |line| line.start_with?("## ") } lines[start_index...(end_index ? start_index + 1 + end_index : lines.length)].join end |
.decision_policy_for(env, run_options) ⇒ Object
13199 13200 13201 |
# File 'lib/kettle/jem.rb', line 13199 def decision_policy_for(env, ) DecisionPolicy.from_env(env || {}, **( || {})) end |
.decorative_grapheme?(grapheme) ⇒ Boolean
13166 13167 13168 13169 13170 13171 13172 |
# File 'lib/kettle/jem.rb', line 13166 def decorative_grapheme?(grapheme) value = grapheme.to_s return false if value.empty? return false if value.ascii_only? !value.match?(/\A[[:alnum:][:space:]]\z/u) end |
.deduplicate_main_gemfile_direct_sibling_blocks(content) ⇒ Object
8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 |
# File 'lib/kettle/jem.rb', line 8144 def deduplicate_main_gemfile_direct_sibling_blocks(content) records = main_gemfile_direct_sibling_records(content) return content if records.length <= 1 records[1..].sort_by { |record| -record.fetch(:start_line) }.reduce(content.to_s) do |output, record| replace_source_range_lines( output, record.fetch(:start_line), (output, record.fetch(:end_line)), "" ) end end |
.deduplicate_main_gemfile_eval_gemfiles(content) ⇒ Object
8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 |
# File 'lib/kettle/jem.rb', line 8247 def deduplicate_main_gemfile_eval_gemfiles(content) records = ruby_call_records(content, :eval_gemfile).filter_map do |call| path = ruby_string_argument(call) next unless path { path: path, start_line: gemfile_eval_comment_start_line(content.to_s.lines, call.location.start_line), end_line: ruby_node_source_end_line(call) } end return content if records.length <= 1 seen = Set.new duplicate_records = [] records.reverse_each do |record| path = record.fetch(:path) if seen.include?(path) duplicate_records << record else seen.add(path) end end return content if duplicate_records.empty? duplicate_records.sort_by { |record| -record.fetch(:start_line) }.reduce(content.to_s) do |output, record| replace_source_range_lines( output, record.fetch(:start_line), (output, record.fetch(:end_line)), "" ) end end |
.deduplicate_readme_corporate_sponsors(sponsors) ⇒ Object
16942 16943 16944 16945 16946 16947 |
# File 'lib/kettle/jem.rb', line 16942 def deduplicate_readme_corporate_sponsors(sponsors) sponsors .group_by { |sponsor| [sponsor[:name], sponsor[:url], sponsor[:img_src]] } .values .map(&:first) end |
.deduplicate_readme_top_logo_entries(entries) ⇒ Object
17089 17090 17091 17092 17093 |
# File 'lib/kettle/jem.rb', line 17089 def deduplicate_readme_top_logo_entries(entries) entries.group_by { |entry| entry[:image_url].to_s }.values.map do |group| group.find { |entry| entry[:type] == "related_org" } || group.first end end |
.deep_dup(value) ⇒ Object
20242 20243 20244 |
# File 'lib/kettle/jem.rb', line 20242 def deep_dup(value) Marshal.load(Marshal.dump(value)) end |
.deep_string_key_hash(value) ⇒ Object
3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 |
# File 'lib/kettle/jem.rb', line 3144 def deep_string_key_hash(value) case value when Hash value.each_with_object({}) do |(key, child), converted| converted[key.to_s] = deep_string_key_hash(child) end when Array value.map { |child| deep_string_key_hash(child) } else value end end |
.default_framework_matrix_requirement(version) ⇒ Object
19097 19098 19099 19100 19101 |
# File 'lib/kettle/jem.rb', line 19097 def default_framework_matrix_requirement(version) normalized = version.to_s normalized = "#{normalized}.0" if normalized.match?(/\A\d+\.\d+\z/) "~> #{normalized}" end |
.default_gemspec_metadata_assignment?(record) ⇒ Boolean
10965 10966 10967 |
# File 'lib/kettle/jem.rb', line 10965 def (record) DEFAULT_GEMSPEC_METADATA_VALUES[record.fetch(:key)] == record[:value] end |
.default_readme_top_logo_credit(type) ⇒ Object
17177 17178 17179 17180 17181 17182 17183 17184 17185 17186 |
# File 'lib/kettle/jem.rb', line 17177 def default_readme_top_logo_credit(type) case type when "ruby" "Yukihiro Matsumoto, Ruby Visual Identity Team, CC BY-SA 2.5" when "org" "GitHub" else "Aboling0, CC BY-SA 4.0" end end |
.default_readme_top_logo_href(type, slug:, org:, gem_name:, repository: {}) ⇒ Object
17162 17163 17164 17165 17166 17167 17168 17169 17170 17171 17172 17173 17174 17175 |
# File 'lib/kettle/jem.rb', line 17162 def default_readme_top_logo_href(type, slug:, org:, gem_name:, repository: {}) case type when "related_org" "https://discord.gg/3qme4XHNKN" when "ruby" "https://ruby-toolbox.com" when "org" org.to_s.empty? ? "#{LOGOS_GALTZO_BASE_URL}/#{slug}/" : "https://github.com/#{org}" when "project" repository_project_logo_href(repository, slug: slug, org: org, gem_name: gem_name) else "#{LOGOS_GALTZO_BASE_URL}/#{slug}/" end end |
.default_readme_top_logo_slug(type, org:, gem_name:, repository: {}) ⇒ Object
17131 17132 17133 17134 17135 17136 17137 17138 17139 17140 17141 17142 17143 17144 |
# File 'lib/kettle/jem.rb', line 17131 def default_readme_top_logo_slug(type, org:, gem_name:, repository: {}) case type when "related_org" "galtzo-floss" when "ruby" "ruby-lang" when "org" org.to_s when "project" repository_project_logo_slug(repository, org: org, gem_name: gem_name) else "" end end |
.default_template_config ⇒ Object
18693 18694 18695 18696 18697 18698 |
# File 'lib/kettle/jem.rb', line 18693 def default_template_config { "root" => "packaged", "apply" => true } end |
.default_template_strategy_config(template_root, target_path) ⇒ Object
18413 18414 18415 18416 18417 18418 18419 18420 18421 18422 18423 18424 |
# File 'lib/kettle/jem.rb', line 18413 def default_template_strategy_config(template_root, target_path) return unless template_root.fetch(:kind) == "packaged" return {strategy: :merge, preference: :destination, add_template_only_nodes: true} if target_path.to_s == KETTLE_CONFIG_PATH return {strategy: :merge, preference: :destination, add_template_only_nodes: true} if target_path.to_s == ".gitignore" return {strategy: :accept_template} if target_path.to_s == "CITATION.cff" return {strategy: :merge, preference: :destination, add_template_only_nodes: true} if target_path.to_s == "Rakefile" return {strategy: :accept_template} if version_gem_template_target_path?(target_path) return {strategy: :accept_template} if target_path.to_s.start_with?(".github/workflows/") return {strategy: :accept_template} if target_path.to_s.start_with?("gemfiles/modular/") nil end |
.default_test_bundle_config(config, framework_matrix) ⇒ Object
Configures the dependencies used by bundle exec kettle-test without a
BUNDLE_GEMFILE override. This intentionally does not alter Appraisals or
CI matrices: those are owned by appraisal_matrix/framework_matrix.
19020 19021 19022 19023 19024 19025 19026 19027 19028 19029 19030 19031 19032 19033 19034 19035 19036 19037 19038 19039 19040 19041 19042 19043 19044 19045 |
# File 'lib/kettle/jem.rb', line 19020 def default_test_bundle_config(config, framework_matrix) raw = config["test_bundle"] raw = {} unless raw.is_a?(Hash) gemfiles = Array(raw["gemfiles"]).filter_map { |entry| default_test_bundle_gemfile_entry(entry) } gems = Array(raw["gems"]).filter_map { |entry| default_test_bundle_gem_entry(entry) } framework_defaults = framework_matrix.to_h.fetch(:default_gemfiles, []).select { |entry| entry[:default] } if framework_defaults.length > 1 paths = framework_defaults.map { |entry| entry.fetch(:path) }.join(", ") raise ArgumentError, "workflows.framework_matrix has multiple default versions: #{paths}" end if (framework_default = framework_defaults.first) gemfiles << { path: framework_default.fetch(:path), replaces: framework_default.fetch(:replaces, []) } end return {} if gemfiles.empty? && gems.empty? { gemfiles: gemfiles.map { |entry| entry.fetch(:path) }.uniq, gems: gems, managed_gems: (gems.map { |entry| entry.fetch(:name) } + gemfiles.flat_map { |entry| entry.fetch(:replaces, []) }).uniq } end |
.default_test_bundle_gem_entry(raw) ⇒ Object
19060 19061 19062 19063 19064 19065 19066 19067 19068 19069 19070 19071 19072 19073 19074 |
# File 'lib/kettle/jem.rb', line 19060 def default_test_bundle_gem_entry(raw) return unless raw.is_a?(Hash) name = (raw["name"] || raw["gem"]).to_s.strip return if name.empty? requirements = raw.key?("requirements") ? Array(raw["requirements"]) : [raw["requirement"]] entry = { name: name, requirements: requirements.filter_map { |requirement| nonempty_string(requirement) } } require_value = DecisionPolicy.value_to_boolean(raw["require"]) entry[:require] = false if require_value == false entry end |
.default_test_bundle_gem_source(gem) ⇒ Object
9407 9408 9409 9410 9411 |
# File 'lib/kettle/jem.rb', line 9407 def default_test_bundle_gem_source(gem) arguments = [gem.fetch(:name).inspect, *gem.fetch(:requirements, []).map(&:inspect)] arguments << "require: false" if gem[:require] == false "gem #{arguments.join(", ")}" end |
.default_test_bundle_gemfile_entry(raw) ⇒ Object
19047 19048 19049 19050 19051 19052 19053 19054 19055 19056 19057 19058 |
# File 'lib/kettle/jem.rb', line 19047 def default_test_bundle_gemfile_entry(raw) if raw.is_a?(Hash) path = raw["path"].to_s.strip replaces = Array(raw["replaces"]).filter_map { |name| nonempty_string(name) } else path = raw.to_s.strip replaces = [] end return if path.empty? {path: path.start_with?("gemfiles/") ? path : "gemfiles/#{path}", replaces: replaces} end |
.delete_file_recipe?(recipe) ⇒ Boolean
13688 13689 13690 |
# File 'lib/kettle/jem.rb', line 13688 def delete_file_recipe?(recipe) FILE_DELETION_PRIMITIVES.include?(recipe.fetch(:primitive)) end |
.delete_line_ranges(content, selectors) ⇒ Object
19422 19423 19424 19425 19426 19427 19428 19429 19430 |
# File 'lib/kettle/jem.rb', line 19422 def delete_line_ranges(content, selectors) lines = content.lines selectors.sort_by { |selector| -selector.fetch(:start_line) }.each do |selector| start_index = selector.fetch(:start_line) - 1 end_index = selector.fetch(:end_line) - 1 lines.slice!(start_index..end_index) end lines.join.gsub(/\n{3,}/, "\n\n") end |
.delete_markdown_with_ast_crispr(content, target) ⇒ Object
7741 7742 7743 7744 |
# File 'lib/kettle/jem.rb', line 7741 def delete_markdown_with_ast_crispr(content, target) ensure_runtime_dependencies! Ast::Crispr::Delete.call(content: content.to_s, target: target, source_label: "README.md").updated_content end |
.delete_markdown_with_ast_crispr_batch(content, *targets) ⇒ Object
7746 7747 7748 7749 7750 7751 7752 |
# File 'lib/kettle/jem.rb', line 7746 def delete_markdown_with_ast_crispr_batch(content, *targets) ensure_runtime_dependencies! target_list = targets.flatten.compact return content if target_list.empty? Ast::Crispr::DeleteBatch.call(content: content.to_s, targets: target_list, source_label: "README.md").updated_content end |
.delete_project_file(project_root, relative_path) ⇒ Object
15938 15939 15940 15941 15942 15943 15944 15945 |
# File 'lib/kettle/jem.rb', line 15938 def delete_project_file(project_root, relative_path) path = File.join(project_root, relative_path) return unless File.file?(path) File.delete(path) prune_empty_parent_directories(project_root, File.dirname(relative_path)) relative_path end |
.delete_rakefile_scaffold(content) ⇒ Object
19284 19285 19286 19287 19288 19289 19290 19291 19292 |
# File 'lib/kettle/jem.rb', line 19284 def delete_rakefile_scaffold(content) selectors = rakefile_scaffold_delete_selectors(content) return {content: content.to_s, delete_selectors: selectors} if selectors.empty? { content: delete_line_ranges(content.to_s, selectors), delete_selectors: selectors } end |
.delete_yaml_top_level_mapping_entries(content, parent_key:, child_keys:) ⇒ Object
7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 |
# File 'lib/kettle/jem.rb', line 7335 def delete_yaml_top_level_mapping_entries(content, parent_key:, child_keys:) document = Psych.parse(content.to_s) # Psych returns `false` for a comment-only document under some versions. # Such content has no mapping to prune and must pass through unchanged. root = document.root if document.respond_to?(:root) return content unless root.is_a?(Psych::Nodes::Mapping) parent = yaml_mapping_value(root, parent_key) return content unless parent.is_a?(Psych::Nodes::Mapping) child_key_set = Array(child_keys).map(&:to_s).to_set ranges = parent.children.each_slice(2).filter_map do |key_node, value_node| next unless child_key_set.include?(key_node.value.to_s) key_node.start_line...value_node.end_line end return content if ranges.empty? remove_line_ranges(content, ranges) end |
.dependency_file_contents(project_root, recipe_reports, paths) ⇒ Object
9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 |
# File 'lib/kettle/jem.rb', line 9682 def dependency_file_contents(project_root, recipe_reports, paths) reports = recipe_reports.to_h { |report| [report.fetch(:relative_path, "").to_s, report] } paths.uniq.filter_map do |path| file_path = File.join(project_root.to_s, path) next unless reports.key?(path) || File.file?(file_path) content = reports.key?(path) ? reports.fetch(path).fetch(:final_content, "") : File.read(file_path) [path, content] end.to_h end |
.dependency_records_for(path, content) ⇒ Object
9674 9675 9676 9677 9678 9679 9680 |
# File 'lib/kettle/jem.rb', line 9674 def dependency_records_for(path, content) if path == "Gemfile" || path.end_with?(".gemfile") gemfile_gem_call_records(content) else gemspec_dependency_records(content) end end |
.destination_file_sha256(project_root, relative_path) ⇒ Object
4246 4247 4248 4249 4250 4251 |
# File 'lib/kettle/jem.rb', line 4246 def destination_file_sha256(project_root, relative_path) path = File.join(project_root.to_s, relative_path.to_s) return unless File.file?(path) Digest::SHA256.file(path).hexdigest end |
.detected_license_ids(project_root) ⇒ Object
5477 5478 5479 5480 5481 5482 |
# File 'lib/kettle/jem.rb', line 5477 def detected_license_ids(project_root) known_license_template_basenames.filter_map do |basename| path = File.join(project_root.to_s, "#{basename}.md") File.exist?(path) ? spdx_from_basename(basename) : nil end.sort end |
.direct_sibling_directory_defines_gem?(sibling_path, gem_name) ⇒ Boolean
15141 15142 15143 15144 15145 15146 15147 |
# File 'lib/kettle/jem.rb', line 15141 def direct_sibling_directory_defines_gem?(sibling_path, gem_name) return false unless File.directory?(sibling_path) Dir.glob(File.join(sibling_path, "*.gemspec")).any? do |gemspec_path| ((gemspec_path), :gem_name).to_s == gem_name.to_s end end |
.direct_sibling_nomono_root_parts(workspace_slug, repository) ⇒ Object
15230 15231 15232 15233 15234 15235 15236 15237 15238 15239 15240 15241 15242 |
# File 'lib/kettle/jem.rb', line 15230 def direct_sibling_nomono_root_parts(workspace_slug, repository) parts = ["src", "my", workspace_slug].reject(&:empty?) return parts unless repository_monorepo_subproject?(repository) repo_name = repository.is_a?(Hash) ? repository[:name].to_s : "" if !repo_name.empty? && repo_name != workspace_slug.to_s suffix = repo_name.delete_prefix("#{workspace_slug}-") parts.concat(suffix.split("-").reject(&:empty?)) unless suffix.empty? || suffix == repo_name end package_parent = File.dirname((repository[:package_path] if repository.is_a?(Hash)).to_s) parts.concat(package_parent.split("/").reject { |segment| segment.empty? || segment == "." }) parts end |
.direct_sibling_runtime_gems(project_root, gemspec_metadata, package_name:, local_modular_eval_paths: {}) ⇒ Object
15065 15066 15067 15068 15069 15070 15071 15072 15073 15074 15075 15076 15077 15078 15079 15080 15081 15082 15083 15084 15085 15086 |
# File 'lib/kettle/jem.rb', line 15065 def direct_sibling_runtime_gems(project_root, , package_name:, local_modular_eval_paths: {}) return [] unless project_root && .is_a?(Hash) sibling_root = File.("..", project_root.to_s) excluded = [package_name.to_s, *local_modular_eval_paths.keys.map(&:to_s)] pending = gemspec_runtime_dependency_names() discovered = [] until pending.empty? name = pending.shift.to_s next if name.empty? || discovered.include?(name) sibling_path = File.join(sibling_root, name) next unless direct_sibling_directory_defines_gem?(sibling_path, name) discovered << name = (sibling_path, name) pending.concat(gemspec_runtime_dependency_names()) end discovered.reject { |name| excluded.include?(name) } end |
.direct_sibling_workspace_slug(source_url, project_root) ⇒ Object
15222 15223 15224 15225 15226 15227 15228 |
# File 'lib/kettle/jem.rb', line 15222 def direct_sibling_workspace_slug(source_url, project_root) slug = github_org_from_url(source_url).to_s return slug unless slug.empty? return "" unless project_root File.basename(File.("..", project_root.to_s)).to_s end |
.disabled_coverage_integrations(config) ⇒ Object
17911 17912 17913 |
# File 'lib/kettle/jem.rb', line 17911 def disabled_coverage_integrations(config) configured_disabled_integrations(config) & COVERAGE_INTEGRATIONS end |
.disabled_integration_config_cleanups(project_root, config) ⇒ Object
18788 18789 18790 18791 18792 18793 18794 18795 18796 18797 |
# File 'lib/kettle/jem.rb', line 18788 def disabled_integration_config_cleanups(project_root, config) disabled_integrations(config).flat_map do |integration| INTEGRATION_TEMPLATE_PATHS.fetch(integration, []).filter_map do |relative_path| next if relative_path.start_with?(".github/workflows/") next unless File.exist?(File.join(project_root, relative_path)) {target_path: relative_path} end end end |
.disabled_integration_template_path?(target_path, config) ⇒ Boolean
18799 18800 18801 18802 18803 18804 18805 |
# File 'lib/kettle/jem.rb', line 18799 def disabled_integration_template_path?(target_path, config) disabled = disabled_integrations(config) return false if disabled.empty? path = target_path.to_s disabled.any? { |integration| INTEGRATION_TEMPLATE_PATHS.fetch(integration, []).include?(path) } end |
.disabled_integrations(config, license: nil) ⇒ Object
17905 17906 17907 17908 17909 |
# File 'lib/kettle/jem.rb', line 17905 def disabled_integrations(config, license: nil) disabled = configured_disabled_integrations(config) disabled << SKYWALKING_EYES_INTEGRATION if skywalking_eyes_disabled_by_default?(config, license, disabled) disabled.map { |name| normalize_integration_name(name) }.uniq & MANAGED_INTEGRATIONS end |
.discover_facts(project_root, env: ENV, run_options: {}) ⇒ Object
3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 |
# File 'lib/kettle/jem.rb', line 3301 def discover_facts(project_root, env: ENV, run_options: {}) kettle_config = kettle_jem_config(project_root) template_selection = template_selection_for(env, ) configured_template_profile = normalize_template_profile(kettle_config.dig("templates", "profile")) if template_selection[:template_profile].to_s.empty? && !configured_template_profile.empty? template_selection[:template_profile] = configured_template_profile end gemspec_path = Dir.glob(File.join(project_root, "*.gemspec")).min if !gemspec_path && template_selection[:template_profile].to_s == MONOREPO_ROOT_TEMPLATE_PROFILE return discover_monorepo_root_facts(project_root, kettle_config, env, template_selection) end raise ArgumentError, "no gemspec found in #{project_root}" unless gemspec_path gemspec_spec = load_project_gemspec(gemspec_path) = (project_root, gemspec_path, spec: gemspec_spec) rubygems_config = kettle_config["rubygems"].is_a?(Hash) ? kettle_config["rubygems"] : {} configured_name = rubygems_config["name"].to_s.strip name = (configured_name.empty? ? nil : configured_name) || (, :gem_name) || File.basename(gemspec_path, ".gemspec") homepage_url = (, :homepage) = (, :source_code_uri) = nil if generated_version_tree_source_url?(, (, :version)) = concrete_github_url() homepage_github_url = concrete_github_url(homepage_url) git_source_url = git_remote_source_url(project_root) git_github_url = concrete_github_url(git_source_url) source_url = if template_selection[:template_profile].to_s == SHIM_TEMPLATE_PROFILE git_github_url || git_source_url || || homepage_github_url || || homepage_url else || git_github_url || homepage_github_url || || git_source_url || homepage_url end if homepage_github_url && git_github_url && homepage_github_url != git_github_url && source_url == git_github_url homepage_url = git_github_url end derived_github_user = (git_github_url && source_url == git_github_url) ? github_org_from_url(git_github_url) : nil entrypoint_require = rubygems_config["entrypoint_require"].to_s.strip entrypoint_require = (, :entrypoint_require) if entrypoint_require.empty? entrypoint_require = name.tr("-", "/") if entrypoint_require.to_s.empty? version_path = File.join("lib", entrypoint_require, "version.rb") entrypoint_path = File.join("lib", "#{entrypoint_require}.rb") configured_namespace = rubygems_config["namespace"].to_s.strip version_namespace = existing_version_namespace(project_root, version_path) version_namespace = reconcile_existing_version_namespace( project_root, entrypoint_path, version_path, version_namespace ) = (, :namespace) default_namespace = classify_namespace(name) namespace_hint = configured_namespace.empty? ? default_namespace : configured_namespace entrypoint_namespace = existing_entrypoint_version_namespace( project_root, entrypoint_path, expected_depth: namespace_hint.split("::").count { |segment| !segment.empty? } ) namespace = configured_namespace.empty? ? nil : configured_namespace namespace ||= project_namespace( entrypoint_namespace: entrypoint_namespace, version_namespace: version_namespace, metadata_namespace: , default_namespace: default_namespace ) version_namespace_kinds = existing_version_namespace_kinds( project_root, version_path, namespace, entrypoint_path: entrypoint_path ) version_namespace_superclasses = existing_version_namespace_superclasses( project_root, version_path, namespace ) namespace_superclass_details = existing_namespace_superclass_details( project_root, namespace, preferred_path: entrypoint_path ) entrypoint_namespace_superclasses = namespace_superclass_details.fetch(:superclasses) project_version = (, :version) project_version = existing_version_file_value(project_root, version_path) unless valid_gem_version?(project_version) project_version = git_version_file_value(project_root, version_path) unless valid_gem_version?(project_version) configured_min_ruby = preferred_template_token_value(nil, rubygems_config["min_ruby"], env, "KJ_MIN_RUBY").to_s.strip min_ruby = (configured_min_ruby.empty? ? nil : configured_min_ruby) || (, :required_ruby_version) || (, :min_ruby) gemspec_licenses = Array([:licenses]) copyright = copyright_facts(project_root, kettle_config) license_txt = license_txt_facts(project_root) = (kettle_config, env, gemspec_metadata: , copyright: copyright) license = license_facts( kettle_config, gemspec_licenses, author: , author_email: [:email], copyright: copyright, source_url: source_url, license_txt: license_txt ) gemspec_license_spdx = gemspec_licenses .map { |license_id| license_id.to_s.strip } .reject(&:empty?) repository_topology = repository_topology_for(kettle_config, env, template_selection) repository = repository_facts( project_root, source_url, package_name: name, repository_topology: repository_topology ) project_runtime = project_runtime_facts( kettle_config, env, package_name: name, source_url: source_url, author_domain: [:domain], min_ruby: min_ruby, test_min_ruby: config_test_min_ruby(kettle_config, min_ruby), version: project_version, project_root: project_root, gemspec_metadata: , repository: repository ) rubyforum = rubyforum_facts(kettle_config, env, package_name: name) shim = shim_facts( kettle_config, env, , package_name: name, entrypoint_require: entrypoint_require, template_profile: template_selection[:template_profile] ) facts = { package: compact_hash( ecosystem: "rubygems", name: name, slug: name, summary: (, :summary), description: (, :description) || (, :summary), homepage_url: homepage_url, source_url: source_url, license_expression: license[:expression], runtime_dependencies: gemspec_runtime_dependency_names() ), rubygems: compact_hash( gemspec_path: File.basename(gemspec_path), entrypoint_require: entrypoint_require, namespace: namespace, min_ruby: min_ruby, version_namespace_kinds: version_namespace_kinds, version_namespace_superclasses: version_namespace_superclasses, entrypoint_namespace_superclasses: entrypoint_namespace_superclasses, entrypoint_namespace_superclass_path: namespace_superclass_details[:path], version_gem_default_enabled: version_gem_default_enabled_for_project?(rubygems_config, ), engines: ruby_engines_config(kettle_config) ) } facts[:rubyforum] = rubyforum unless rubyforum.empty? version_gem_facts = version_gem_facts_for_project( project_root, entrypoint_require, mode: rubygems_version_gem_entrypoint_mode(rubygems_config) ) facts[:version_gem] = version_gem_facts unless version_gem_facts.empty? facts[:shim] = shim unless shim.empty? facts[:repository] = repository unless repository.empty? generated_blocks = generated_blocks_facts(, facts.merge(project_root: File.(project_root)), ) facts[:generated_blocks] = generated_blocks unless generated_blocks.empty? bootstrap = kettle_config_bootstrap_facts(project_root, env, template_selection: template_selection) if bootstrap min_ruby_token = minimum_ruby_token(min_ruby) bootstrap[:licenses] = gemspec_license_spdx unless gemspec_license_spdx.empty? bootstrap[:gemspec_path] = File.basename(gemspec_path) if gemspec_path bootstrap[:min_ruby] = min_ruby_token unless min_ruby_token.empty? bootstrap[:test_min_ruby] = config_test_min_ruby(kettle_config, min_ruby).to_s bootstrap[:yard_host] = project_runtime[:yard_host].to_s bootstrap[:homepage_uri] = project_runtime[:homepage_uri].to_s bootstrap[:rubyforum] = rubyforum if rubyforum && !rubyforum.empty? project_emoji = preferred_template_token_value(nil, nil, env, "KJ_PROJECT_EMOJI") project_emoji ||= readme_project_emoji(project_root) project_emoji ||= gemspec_project_emoji() project_emoji ||= "💎" if monorepo_subgem_template_profile_value?(template_selection[:template_profile]) project_emoji ||= "🪞" if template_selection[:template_profile].to_s == SHIM_TEMPLATE_PROFILE bootstrap[:project_emoji] = project_emoji bootstrap[:shim] = shim if shim && !shim.empty? end facts[:kettle_config_bootstrap] = bootstrap if bootstrap facts[:author] = unless .empty? facts[:copyright] = copyright unless copyright.empty? forge = forge_facts(kettle_config, env, derived_github_user: derived_github_user) facts[:forge] = forge unless forge.empty? = (kettle_config, env) facts[:social] = unless .empty? opencollective_policy = opencollective_policy(kettle_config, env) opencollective_disabled = opencollective_policy.fetch(:disabled) funding_platforms = funding_platform_policies(kettle_config, env) open_collective_org = opencollective_org(project_root, kettle_config, env, opencollective_disabled: opencollective_disabled) open_collective_org ||= fallback_opencollective_org unless opencollective_disabled funding = compact_hash( urls: funding_urls( project_root, name, funding_uri: (, :funding_uri), opencollective_disabled: opencollective_disabled, open_collective_org: open_collective_org && open_collective_org.fetch(:org), enabled_platforms: funding_platforms ), platforms: funding_platforms ) funding_tokens = funding_platform_token_facts(kettle_config, env) funding[:platform_tokens] = funding_tokens unless funding_tokens.empty? funding[:open_collective_disabled] = true if opencollective_disabled funding[:open_collective_disabled_source] = opencollective_policy[:source] if opencollective_disabled if open_collective_org funding[:open_collective_org] = open_collective_org.fetch(:org) funding[:open_collective_org_source] = open_collective_org.fetch(:source) end open_collective_files = opencollective_disabled ? opencollective_disabled_files(project_root) : [] funding[:open_collective_files] = open_collective_files unless open_collective_files.empty? facts[:funding] = funding unless funding.empty? warnings = opencollective_fallback_warnings(funding, project_runtime[:github_org].to_s) facts[:warnings] = warnings unless warnings.empty? disabled_integrations = disabled_integrations(kettle_config, license: license) facts[:integrations] = {disabled: disabled_integrations} unless disabled_integrations.empty? opt_in_workflows = opt_in_workflow_cleanup_files(project_root, template_selection) facts[:template_profile] = template_selection[:template_profile] unless template_selection[:template_profile].to_s.empty? template_config = template_runtime_config(kettle_config, facts, license: license) inactive_workflows = inactive_packaged_workflow_cleanup_files( project_root, template_config, include_patterns: template_selection[:include] ) inactive_templates = inactive_packaged_template_cleanup_files(project_root, template_config) facts[:ci] = { provider: "github_actions", default_branch: "main", exec_cmd: github_actions_exec_cmd(kettle_config, env), engine_exec_cmds: github_actions_engine_exec_cmds(kettle_config), recording: project_recording_enabled?(project_root, kettle_config), ruby_versions: github_actions_ruby_versions(project_runtime.fetch(:test_min_ruby)), test_min_ruby: project_runtime.fetch(:test_min_ruby).to_s, obsolete_workflows: github_actions_obsolete_workflows(project_root), custom_workflows: github_actions_custom_workflows(project_root, template_config, opencollective_disabled: opencollective_disabled) } standard_appraisal_gemfiles = github_actions_standard_appraisal_gemfiles(kettle_config) facts[:ci][:standard_appraisal_gemfiles] = standard_appraisal_gemfiles unless standard_appraisal_gemfiles.empty? facts[:ci][:opt_in_workflow_cleanups] = opt_in_workflows unless opt_in_workflows.empty? facts[:ci][:inactive_packaged_workflow_cleanups] = inactive_workflows unless inactive_workflows.empty? coverage_config = github_actions_coverage_config(kettle_config, env) facts[:ci][:coverage] = coverage_config unless coverage_config.empty? framework_matrix = github_actions_framework_matrix(kettle_config) facts[:ci][:framework_matrix] = framework_matrix unless framework_matrix.empty? default_test_bundle = default_test_bundle_config(kettle_config, framework_matrix) facts[:ci][:default_test_bundle] = default_test_bundle unless default_test_bundle.empty? template_facts = {} template_preferences = template_source_preferences( project_root, template_config, opencollective_disabled: opencollective_disabled, include_patterns: template_selection[:include] ) template_preferences += existing_simplecov_bootstrap_template_preferences( project_root, template_config, template_preferences ) template_facts[:source_preferences] = template_preferences unless template_preferences.empty? template_facts[:inactive_packaged_template_cleanups] = inactive_templates unless inactive_templates.empty? shim_cleanups = shim_profile_cleanups(project_root, facts, template_preferences, template_selection: template_selection) template_facts[:shim_profile_cleanups] = shim_cleanups unless shim_cleanups.empty? legacy_cleanups = template_legacy_destination_cleanups(project_root, template_preferences) template_facts[:legacy_destination_cleanups] = legacy_cleanups unless legacy_cleanups.empty? license_cleanups = template_obsolete_license_cleanups(project_root, template_config, template_preferences, license_txt: license_txt) template_facts[:obsolete_license_cleanups] = license_cleanups unless license_cleanups.empty? unless template_preferences.empty? facts[:license] = license unless license.empty? facts[:project_runtime] = project_runtime unless project_runtime.empty? readme_github_org = project_runtime[:github_org].to_s readme_github_org = forge[:gh_user].to_s if readme_github_org.empty? readme_github_org = facts.fetch(:repository, {})[:slug].to_s.split("/", 2).first.to_s if readme_github_org.empty? readme_logo = readme_logo_facts( kettle_config, package_name: name, github_org: readme_github_org, repository: facts[:repository] ) facts[:readme_logo] = readme_logo unless readme_logo.empty? readme_sponsors = readme_corporate_sponsors_facts(kettle_config, env) facts[:readme_sponsors] = readme_sponsors unless readme_sponsors.empty? readme_style = readme_style_facts( project_root, kettle_config, license, template_profile: template_selection[:template_profile], repository: facts[:repository] ) facts[:readme_style] = readme_style unless readme_style.empty? facts[:ruby_style] = ruby_style_facts(project_root) changelog = changelog_transfer_facts(project_root, changelog_transfer_entries(PACKAGED_TEMPLATE_ROOT)) facts[:changelog] = changelog unless changelog.empty? gemspec_facts = gemspec_template_facts(kettle_config) facts[:gemspec] = gemspec_facts unless gemspec_facts.empty? template_tokens = template_tokens(facts, funding) template_facts[:tokens] = template_tokens unless template_tokens.empty? end if template_facts[:tokens].to_h.empty? && funding[:open_collective_org].to_s != "" template_facts[:tokens] = {"KJ|OPENCOLLECTIVE_ORG" => funding.fetch(:open_collective_org).to_s} end facts[:templates] = template_facts unless template_facts.empty? facts end |
.discover_monorepo_root_facts(project_root, kettle_config, env, template_selection) ⇒ Object
3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 |
# File 'lib/kettle/jem.rb', line 3180 def discover_monorepo_root_facts(project_root, kettle_config, env, template_selection) source_url = git_remote_source_url(project_root) package_name = repository_name_from_source_url(source_url) package_name = File.basename(project_root.to_s) if package_name.empty? configured_or_detected_licenses = detected_license_ids(project_root) configured_or_detected_licenses = Array(kettle_config["licenses"]) if configured_or_detected_licenses.empty? copyright = copyright_facts(project_root, kettle_config) = (kettle_config, env, copyright: copyright) license = license_facts( kettle_config.merge("licenses" => configured_or_detected_licenses), configured_or_detected_licenses, author: , author_email: [:email], copyright: copyright, source_url: source_url, license_txt: license_txt_facts(project_root) ) test_min_ruby = config_test_min_ruby(kettle_config, nil) project_runtime = project_runtime_facts( kettle_config, env, package_name: package_name, source_url: source_url, author_domain: [:domain], min_ruby: nil, test_min_ruby: test_min_ruby, version: nil, project_root: project_root ) facts = { package: compact_hash( ecosystem: "monorepo", name: package_name, slug: package_name, description: "#{package_name} monorepo", homepage_url: source_url, source_url: source_url, license_expression: license[:expression] ), rubygems: compact_hash( namespace: classify_namespace(package_name), min_ruby: nil, engines: ruby_engines_config(kettle_config) ), template_profile: MONOREPO_ROOT_TEMPLATE_PROFILE } bootstrap = kettle_config_bootstrap_facts(project_root, env, template_selection: template_selection) bootstrap[:licenses] = configured_or_detected_licenses if bootstrap && !configured_or_detected_licenses.empty? facts[:kettle_config_bootstrap] = bootstrap if bootstrap facts[:author] = unless .empty? facts[:copyright] = copyright unless copyright.empty? forge = forge_facts(kettle_config, env, derived_github_user: nil) = (kettle_config, env) facts[:forge] = forge unless forge.empty? facts[:social] = unless .empty? facts[:license] = license unless license.empty? facts[:project_runtime] = project_runtime unless project_runtime.empty? facts[:ruby_style] = ruby_style_facts(project_root) opencollective_policy = opencollective_policy(kettle_config, env) opencollective_disabled = opencollective_policy.fetch(:disabled) funding_platforms = funding_platform_policies(kettle_config, env) detected_open_collective_org = opencollective_org(project_root, kettle_config, env, opencollective_disabled: opencollective_disabled) detected_open_collective_org ||= fallback_opencollective_org unless opencollective_disabled funding = compact_hash( urls: funding_urls( project_root, package_name, opencollective_disabled: opencollective_disabled, open_collective_org: detected_open_collective_org && detected_open_collective_org.fetch(:org), enabled_platforms: funding_platforms ), platform_tokens: funding_platform_token_facts(kettle_config, env), platforms: funding_platforms ) funding[:open_collective_disabled] = true if opencollective_disabled funding[:open_collective_disabled_source] = opencollective_policy[:source] if opencollective_disabled if detected_open_collective_org funding[:open_collective_org] = detected_open_collective_org.fetch(:org) funding[:open_collective_org_source] = detected_open_collective_org.fetch(:source) end facts[:funding] = funding unless funding.empty? repository = repository_facts( project_root, source_url, package_name: package_name, repository_topology: REPOSITORY_TOPOLOGY_STANDALONE ) facts[:repository] = repository unless repository.empty? warnings = opencollective_fallback_warnings(funding, github_org_from_url(source_url).to_s) facts[:warnings] = warnings unless warnings.empty? readme_logo = readme_logo_facts( kettle_config, package_name: package_name, github_org: project_runtime[:github_org], repository: facts[:repository] ) facts[:readme_logo] = readme_logo unless readme_logo.empty? readme_sponsors = readme_corporate_sponsors_facts(kettle_config, env) facts[:readme_sponsors] = readme_sponsors unless readme_sponsors.empty? disabled_integrations = disabled_integrations(kettle_config, license: license) facts[:integrations] = {disabled: disabled_integrations} unless disabled_integrations.empty? template_facts = {} template_config = template_runtime_config(kettle_config, facts, license: license) template_preferences = template_source_preferences( project_root, template_config, opencollective_disabled: opencollective_disabled, include_patterns: template_selection[:include] ) template_preferences += existing_simplecov_bootstrap_template_preferences( project_root, template_config, template_preferences ) template_facts[:source_preferences] = template_preferences unless template_preferences.empty? template_tokens = template_tokens(facts, funding) template_facts[:tokens] = template_tokens unless template_tokens.empty? facts[:templates] = template_facts unless template_facts.empty? facts end |
.display_path(path) ⇒ Object
rubocop:enable ThreadSafety/ClassInstanceVariable
2565 2566 2567 2568 2569 |
# File 'lib/kettle/jem.rb', line 2565 def display_path(path) return path if path.nil? path.to_s.sub(VAR_HOME_PREFIX, "/home") end |
.display_text(text) ⇒ Object
2571 2572 2573 2574 2575 |
# File 'lib/kettle/jem.rb', line 2571 def display_text(text) return text if text.nil? text.to_s.gsub(VAR_HOME_TEXT, "/home") end |
.distribute_file_work_units(file_work_units, workers) ⇒ Object
13916 13917 13918 13919 13920 13921 13922 |
# File 'lib/kettle/jem.rb', line 13916 def distribute_file_work_units(file_work_units, workers) chunks = Array.new([workers, file_work_units.length].min) { [] } file_work_units.each_with_index do |file_work_unit, offset| chunks.fetch(offset % chunks.length) << file_work_unit end chunks end |
.dotenv_merge_options(recipe) ⇒ Object
10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 |
# File 'lib/kettle/jem.rb', line 10374 def (recipe) = { preference: (recipe.dig(:template_preference, :preference) || "destination").to_sym, add_template_only_nodes: true, freeze_token: recipe.dig(:template_preference, :freeze_token) || "kettle-jem" } if !recipe.dig(:template_preference, :add_template_only_nodes).nil? configured = DecisionPolicy.value_to_boolean(recipe.dig(:template_preference, :add_template_only_nodes)) [:add_template_only_nodes] = configured unless configured.nil? end end |
.duplicate_drift_report(project_root:, template_root:, run_options: {}) ⇒ Object
5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 |
# File 'lib/kettle/jem.rb', line 5749 def duplicate_drift_report(project_root:, template_root:, run_options: {}) runner = [:duplicate_drift_runner] || ["duplicate_drift_runner"] unless runner if defined?(Kettle::Drift) runner = Kettle::Drift else return { available: false, reason: "kettle-drift is not available" } end end outcome = if runner.respond_to?(:call) runner.call(project_root: project_root, template_dir: template_root) else runner.run( project_root: project_root, template_dir: template_root, lock_path: File.join(project_root.to_s, ".kettle-drift.lock"), mode: :force_update, printer_class: nil ) end { available: true, warning_count: outcome.respond_to?(:warning_count) ? outcome.warning_count : outcome.fetch(:warning_count), json_path: outcome.respond_to?(:json_path) ? outcome.json_path : outcome[:json_path], lock_path: outcome.respond_to?(:lock_path) ? outcome.lock_path : outcome[:lock_path], exit_code: outcome.respond_to?(:exit_code) ? outcome.exit_code : outcome[:exit_code] }.compact rescue => error { available: false, reason: "#{error.class}: #{error.}" } end |
.duration_ms_since(started_at) ⇒ Object
4783 4784 4785 |
# File 'lib/kettle/jem.rb', line 4783 def duration_ms_since(started_at) ((monotonic_time - started_at) * 1000).round(3) end |
.emit_diagnostic_events(events, diagnostics) ⇒ Object
4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 |
# File 'lib/kettle/jem.rb', line 4855 def emit_diagnostic_events(events, diagnostics) Array(diagnostics).each_with_index do |diagnostic, index| payload = diagnostic.respond_to?(:to_h) ? diagnostic.to_h : {message: diagnostic.to_s} emit_event( events, "diagnostic", index: index + 1, total: Array(diagnostics).length, kind: payload[:kind] || payload["kind"] || payload[:key] || payload["key"], severity: payload[:severity] || payload["severity"], path: payload[:path] || payload["path"], message: payload[:message] || payload["message"] || diagnostic.to_s, blocking: payload[:blocking] || payload["blocking"] ) end end |
.emit_event(events, type, payload = {}) ⇒ Object
4901 4902 4903 |
# File 'lib/kettle/jem.rb', line 4901 def emit_event(events, type, payload = {}) Kettle::Ndjson.emit_event(events, type, payload) end |
.emit_phase_event(events, phase, status:, **payload) ⇒ Object
4753 4754 4755 |
# File 'lib/kettle/jem.rb', line 4753 def emit_phase_event(events, phase, status:, **payload) Kettle::Ndjson.emit_phase_event(events, phase, status: status, **payload) end |
.emit_recipe_event(events, report, index:, total:) ⇒ Object
4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 |
# File 'lib/kettle/jem.rb', line 4757 def emit_recipe_event(events, report, index:, total:) payload = { phase: "template", index: index + 1, total: total, path: report.fetch(:relative_path, nil), recipe: report.fetch(:recipe_name, nil), changed: report.fetch(:changed, false), status: "ok", mark: report.fetch(:changed, false) ? "*" : "." } duration_ms = report.dig(:metadata, :duration_ms) payload[:duration_ms] = duration_ms if duration_ms emit_event(events, "recipe", payload) end |
.emit_step_event(events, event_type, step, phase:, index: nil, total: nil) ⇒ Object
4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 |
# File 'lib/kettle/jem.rb', line 4830 def emit_step_event(events, event_type, step, phase:, index: nil, total: nil) emit_event( events, event_type, phase: phase.to_s, index: index, total: total, name: event_payload_value(step, :name), status: event_payload_value(step, :status), reason: event_payload_value(step, :reason), command: event_payload_value(step, :command), path: event_payload_value(step, :path), changed_files: Array(event_payload_value(step, :changed_files) || []), changed_count: Array(event_payload_value(step, :changed_files) || []).length, mark: step_event_mark(step) ) end |
.emit_step_events(events, event_type, steps, phase:) ⇒ Object
4824 4825 4826 4827 4828 |
# File 'lib/kettle/jem.rb', line 4824 def emit_step_events(events, event_type, steps, phase:) Array(steps).each_with_index do |step, index| emit_step_event(events, event_type, step, phase: phase, index: index + 1, total: Array(steps).length) end end |
.emit_summary_event(events, report) ⇒ Object
4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 |
# File 'lib/kettle/jem.rb', line 4882 def emit_summary_event(events, report) file_outcomes = report.fetch(:file_outcomes, {}) emit_event( events, "summary", mode: report.fetch(:mode, nil), changed_files: Array(report.fetch(:changed_files, [])), changed_count: Array(report.fetch(:changed_files, [])).length, planned_count: file_outcomes.fetch(:planned, 0), checksum_hit_count: file_outcomes.fetch(:checksum_hits, 0), checksum_protected_count: file_outcomes.fetch(:checksum_protected, 0), unchanged_count: file_outcomes.fetch(:unchanged, 0), unscoped_recipe_count: file_outcomes.fetch(:unscoped_recipes, 0), diagnostics_count: Array(report.fetch(:diagnostics, [])).length, status: "ok", mark: "." ) end |
.empty_gemspec_development_dependency_section_matches(lines, heading_line_indexes:, dependency_line_indexes:) ⇒ Object
12014 12015 12016 12017 12018 12019 12020 12021 12022 12023 12024 12025 12026 12027 12028 12029 12030 12031 12032 12033 12034 12035 12036 12037 12038 12039 12040 12041 12042 12043 12044 12045 |
# File 'lib/kettle/jem.rb', line 12014 def empty_gemspec_development_dependency_section_matches(lines, heading_line_indexes:, dependency_line_indexes:) matches = [] sorted_headings = heading_line_indexes.to_a.sort visited = Set.new sorted_headings.each do |heading_start| next if visited.include?(heading_start) heading_end = heading_start while heading_line_indexes.include?(heading_end) visited << heading_end heading_end += 1 end cursor = heading_end cursor += 1 while cursor < lines.length && lines[cursor].strip != "end" && !heading_line_indexes.include?(cursor) next if (heading_end...cursor).any? { |line_index| dependency_line_indexes.include?(line_index) } start_line_index = heading_start start_line_index -= 1 if lines[heading_start - 1]&.strip == "" end_line_index = heading_end - 1 matches << Ast::Crispr::Match.new( start_line: start_line_index + 1, end_line: end_line_index + 1, metadata: { start_boundary: :comment_region_start, end_boundary: :owner_end_plus_trailing_gap, payload_kind: :section_branch } ) end matches end |
.empty_gemspec_development_dependency_sections_target(receiver:) ⇒ Object
11975 11976 11977 11978 11979 11980 11981 11982 11983 11984 11985 11986 11987 11988 11989 11990 11991 11992 11993 11994 11995 11996 11997 11998 11999 12000 12001 12002 12003 12004 12005 12006 12007 12008 12009 12010 12011 12012 |
# File 'lib/kettle/jem.rb', line 11975 def empty_gemspec_development_dependency_sections_target(receiver:) Ast::Crispr::OwnerSelector.new( id: "empty_gemspec_development_dependency_sections", limit: {at_least: 0}, metadata: { adapter: Ast::Crispr::Ruby::Prism.adapter, owner_scope: :ruby_comments, selector_kind: :owner_filter, selection_intent: :section_branch, include_trailing_gap: true }, locate: lambda do |context| lines = context.lines note_index = lines.find_index do |line| line.lstrip.start_with?("# NOTE: It is preferable to list development dependencies") end next [] unless note_index dependency_line_indexes = gemspec_dependency_records(context.content, receiver: receiver) .map { |record| record.fetch(:start_line) - 1 } .to_set comments = context.structural_owners(owner_scope: :ruby_comments) heading_line_indexes = comments.filter_map do |comment| line_index = comment.location.start_line - 1 next if line_index <= note_index next unless gemspec_dependency_section_heading_comment?(lines.fetch(line_index).lstrip) line_index end.to_set empty_gemspec_development_dependency_section_matches( lines, heading_line_indexes: heading_line_indexes, dependency_line_indexes: dependency_line_indexes ) end ) end |
.enabled_ruby_engines(config) ⇒ Object
18816 18817 18818 18819 |
# File 'lib/kettle/jem.rb', line 18816 def enabled_ruby_engines(config) engines = ruby_engines_config(config) (engines.nil? || engines.empty?) ? DEFAULT_ENGINES : engines end |
.enforce_gemspec_dependency_minimum_requirements(source, receiver:) ⇒ Object
11816 11817 11818 11819 11820 11821 11822 11823 11824 11825 11826 11827 11828 11829 11830 11831 |
# File 'lib/kettle/jem.rb', line 11816 def enforce_gemspec_dependency_minimum_requirements(source, receiver:) replacements = ruby_call_records(source, nil).filter_map do |call| next unless gemspec_dependency_call_kind(call) next if receiver && call.receiver&.slice != receiver.to_s name = ruby_string_argument(call) requirement = GEMSPEC_DEPENDENCY_MINIMUM_REQUIREMENTS[name] next unless requirement next if gemspec_dependency_requirements_satisfy_floor?(ruby_string_arguments(call).drop(1), requirement) gemspec_dependency_minimum_requirement_replacement(call, requirement) end return source if replacements.empty? replace_source_offsets(source, replacements) end |
.enforce_git_preflight!(git_preflight, decision_policy:, template_selection:) ⇒ Object
13638 13639 13640 13641 13642 13643 |
# File 'lib/kettle/jem.rb', line 13638 def enforce_git_preflight!(git_preflight, decision_policy:, template_selection:) return unless decision_policy.require_clean return if template_selection.fetch(:skip_commit, false) raise Error, "Git preflight failed: project is not a git repository" unless git_preflight.fetch(:git_repository) raise Error, "Git preflight failed: worktree is not clean" unless git_preflight.fetch(:clean_worktree) end |
.ensure_entrypoint_namespace_superclass_declarations(content, namespace:, namespace_superclasses: {}) ⇒ Object
16057 16058 16059 16060 16061 16062 16063 16064 16065 16066 16067 16068 16069 16070 16071 16072 16073 16074 16075 16076 16077 16078 16079 16080 16081 16082 16083 |
# File 'lib/kettle/jem.rb', line 16057 def ensure_entrypoint_namespace_superclass_declarations(content, namespace:, namespace_superclasses: {}) # A version file must only reopen a namesake class. When legacy source # declared that class and its superclass in version.rb, establish the # class in the entrypoint before requiring version.rb, then render the # version file without a superclass. segments = namespace.to_s.split("::").reject(&:empty?) return content.to_s if segments.empty? || namespace_superclasses.empty? missing_superclass_declaration = namespace_superclasses.any? do |index, _superclass| ruby_namespace_declaration_node(content, segments.first(index + 1).join("::")).nil? end return content.to_s unless missing_superclass_declaration namespace_kinds = segments.each_index.each_with_object({}) do |index, kinds| prefix = segments.first(index + 1).join("::") kinds[index] = ruby_namespace_declaration_kind(content, prefix) || :module kinds[index] = :class if namespace_superclasses.key?(index) end declaration = wrap_ruby_namespace( namespace, [], namespace_kinds: namespace_kinds, namespace_superclasses: namespace_superclasses ).join("\n") current = trim_trailing_blank_lines(content) current.empty? ? "#{declaration}\n" : "#{current}\n\n#{declaration}\n" end |
.ensure_gemspec_legacy_version_loader_preamble(content, entrypoint_require:, namespace:, min_ruby:, superclass_sensitive: false, fallback_version: nil) ⇒ Object
10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 |
# File 'lib/kettle/jem.rb', line 10815 def ensure_gemspec_legacy_version_loader_preamble(content, entrypoint_require:, namespace:, min_ruby:, superclass_sensitive: false, fallback_version: nil) block = "#{gemspec_legacy_version_loader_block(entrypoint_require: entrypoint_require, namespace: namespace, min_ruby: min_ruby, superclass_sensitive: superclass_sensitive, fallback_version: fallback_version)}\n" node = gemspec_top_level_gem_version_node(content) return replace_source_range_lines(content, node.location.start_line, (content, node.location.end_line), block) if node gemspec_call = gemspec_new_call(content) return content unless gemspec_call insert_lines_before(content, gemspec_call.location.start_line, block) end |
.ensure_gemspec_metadata_assignment(content, receiver:, key:, value:) ⇒ Object
10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 |
# File 'lib/kettle/jem.rb', line 10896 def (content, receiver:, key:, value:) replacement = %(#{receiver}.metadata[#{key.to_s.dump}] = #{value.to_s.dump}) record = (content, receiver: receiver).find { |candidate| candidate.fetch(:key) == key.to_s } return replace_source_range_lines(content, record.fetch(:start_line), record.fetch(:end_line), "#{leading_whitespace(record.fetch(:source))}#{replacement}\n") if record anchor = %w[discord_uri news_uri wiki_uri funding_uri documentation_uri].filter_map do || (content, receiver: receiver).find { |candidate| candidate.fetch(:key) == } end.first return insert_lines_after(content, anchor.fetch(:end_line), " #{replacement}\n") if anchor homepage = gemspec_assignment_records(content, receiver: receiver).find { |candidate| candidate.fetch(:field) == "homepage" } return insert_lines_after(content, homepage.fetch(:end_line), " #{replacement}\n") if homepage content end |
.ensure_main_gemfile_nomono_bootstrap(content, template_content) ⇒ Object
8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 |
# File 'lib/kettle/jem.rb', line 8204 def ensure_main_gemfile_nomono_bootstrap(content, template_content) return content if gemfile_declares_gem?(content, "nomono") bootstrap_source = main_gemfile_nomono_bootstrap_source(template_content) return content if bootstrap_source.empty? lines = content.to_s.lines insert_line = main_gemfile_templating_eval_line(content) || main_gemfile_first_eval_gemfile_line(content) || main_gemfile_after_gemspec_line(content) || (lines.length + 1) lines.insert(insert_line - 1, bootstrap_source) ensure_trailing_newline(lines.join.gsub(/\n{3,}/, "\n\n")) end |
.ensure_monorepo_root_gemfile_dependencies(content) ⇒ Object
5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 |
# File 'lib/kettle/jem.rb', line 5430 def ensure_monorepo_root_gemfile_dependencies(content) updated = ensure_trailing_newline(content.to_s.empty? ? %(source "https://gem.coop"\n) : content.to_s).dup monorepo_root_gemfile_dependency_lines.each do |line| next if gemfile_declares_gem?(updated, line.fetch(:name)) updated << "\n" unless updated.end_with?("\n\n") updated << line.fetch(:source) end ensure_trailing_newline(updated) end |
.ensure_runtime_dependencies! ⇒ Object
rubocop:disable ThreadSafety/ClassInstanceVariable
2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 |
# File 'lib/kettle/jem.rb', line 2548 def ensure_runtime_dependencies! return if defined?(@runtime_dependencies_loaded) && @runtime_dependencies_loaded require "ruby/merge" require "prism/merge" require "bash/merge" require "json/merge" require "dotenv/merge" require "rbs/merge" require "citrus-toml-merge" require "psych-merge" require "ast/crispr/markdown/markly" require "ast/crispr/ruby/prism" @runtime_dependencies_loaded = true end |
.ensure_spec_helper_simplecov_config_require(content) ⇒ Object
8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 |
# File 'lib/kettle/jem.rb', line 8724 def ensure_spec_helper_simplecov_config_require(content) return content if simplecov_config_require_call_nodes(content).any? simplecov_require = simplecov_require_call_records(content).first return content unless simplecov_require insert_lines_after( content, simplecov_require.fetch(:end_line), "#{leading_whitespace(simplecov_require.fetch(:source))}require \"kettle/soup/cover/config\"\n" ) end |
.ensure_spec_helper_simplecov_do_cov_bootstrap(content) ⇒ Object
8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 |
# File 'lib/kettle/jem.rb', line 8629 def ensure_spec_helper_simplecov_do_cov_bootstrap(content) record = simplecov_do_cov_bootstrap_records(content).first return content unless record return content if record.fetch(:complete) replace_source_range_lines( content, record.fetch(:start_line), record.fetch(:end_line), spec_helper_simplecov_do_cov_bootstrap_source(leading_whitespace(record.fetch(:source))) ) end |
.ensure_spec_helper_simplecov_start(content) ⇒ Object
8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 |
# File 'lib/kettle/jem.rb', line 8737 def ensure_spec_helper_simplecov_start(content) return content if simplecov_start_call_nodes(content).any? config_require = simplecov_config_require_call_records(content).first return content unless config_require insert_lines_after( content, config_require.fetch(:end_line), "#{leading_whitespace(config_require.fetch(:source))}SimpleCov.start\n" ) end |
.ensure_trailing_newline(text) ⇒ Object
20232 20233 20234 20235 20236 |
# File 'lib/kettle/jem.rb', line 20232 def ensure_trailing_newline(text) return "" if text.to_s.empty? text.end_with?("\n") ? text : "#{text}\n" end |
.ensure_workflow_top_level_section(content, key, section, before:) ⇒ Object
19884 19885 19886 19887 19888 19889 19890 19891 19892 19893 19894 19895 19896 19897 19898 |
# File 'lib/kettle/jem.rb', line 19884 def ensure_workflow_top_level_section(content, key, section, before:) top_level_keys = yaml_top_level_key_lines(content) return content if top_level_keys.key?(key.to_s) lines = content.lines index = top_level_keys[before.to_s] if index prepared_section = (index.zero? || lines[index - 1].strip.empty?) ? section : "\n#{section}" lines.insert(index, prepared_section) else lines << "\n" unless lines.empty? || lines.last == "\n" lines << section end lines.join end |
.ensure_yaml_top_level_sequence_items(content, key, items) ⇒ Object
12713 12714 12715 12716 12717 12718 12719 12720 12721 12722 12723 12724 12725 12726 12727 12728 12729 12730 12731 12732 12733 12734 12735 12736 12737 12738 12739 12740 12741 12742 12743 12744 |
# File 'lib/kettle/jem.rb', line 12713 def ensure_yaml_top_level_sequence_items(content, key, items) document = Psych.parse_stream(content.to_s).children.first root = document&.root return content unless root.is_a?(Psych::Nodes::Mapping) key_node, value_node = root.children.each_slice(2).find do |candidate_key, _candidate_value| candidate_key.is_a?(Psych::Nodes::Scalar) && candidate_key.value.to_s == key.to_s end lines = content.to_s.lines unless key_node lines << "\n" unless lines.empty? || lines.last.strip.empty? lines << "#{key}:\n" items.each { |item| lines << " - #{item}\n" } return lines.join end return content unless value_node.is_a?(Psych::Nodes::Sequence) existing = value_node.children.filter_map do |child| child.value.to_s if child.is_a?(Psych::Nodes::Scalar) end missing = items.map(&:to_s) - existing return content if missing.empty? reference_line = value_node.children.last&.start_line || key_node.start_line reference = lines[reference_line].to_s indent = reference.start_with?("-") ? "" : reference[/\A\s*/].to_s insertion_index = value_node.children.last ? value_node.children.last.end_line + 1 : key_node.end_line + 1 lines.insert(insertion_index, *missing.map { |item| "#{indent}- #{item}\n" }) lines.join rescue Psych::Exception content end |
.entrypoint_loads_version_file?(content, project_root:, entrypoint_path:, version_path:) ⇒ Boolean
15645 15646 15647 15648 15649 15650 15651 15652 15653 15654 15655 15656 15657 15658 15659 15660 15661 15662 |
# File 'lib/kettle/jem.rb', line 15645 def entrypoint_loads_version_file?(content, project_root:, entrypoint_path:, version_path:) return false if content.to_s.empty? version_absolute_path = File.(File.join(project_root, version_path)) version_require_path = version_path.delete_prefix("lib/").delete_suffix(".rb") top_level_ruby_call_records(content, :require).concat( top_level_ruby_call_records(content, :require_relative) ).any? do |call| argument = ruby_string_argument(call) next false if argument.to_s.empty? if call.name == :require_relative File.(File.join(project_root, File.dirname(entrypoint_path), "#{argument}.rb")) == version_absolute_path else argument == version_require_path end end end |
.entrypoint_namespace_superclasses_from_facts(facts) ⇒ Object
16315 16316 16317 16318 16319 16320 16321 16322 16323 |
# File 'lib/kettle/jem.rb', line 16315 def entrypoint_namespace_superclasses_from_facts(facts) raw = facts.dig(:rubygems, :entrypoint_namespace_superclasses) return {} unless raw.is_a?(Hash) raw.each_with_object({}) do |(index, superclass), superclasses| value = superclass.to_s.strip superclasses[index.to_i] = value unless value.empty? end end |
.env_overridden_gemspec_fields(env) ⇒ Object
11685 11686 11687 11688 11689 11690 |
# File 'lib/kettle/jem.rb', line 11685 def env_overridden_gemspec_fields(env) fields = [] fields << "authors" if present_template_token_value?(env["KJ_AUTHOR_NAME"].to_s) fields << "email" if present_template_token_value?(env["KJ_AUTHOR_EMAIL"].to_s) fields end |
.env_sync_value(env, env_key) ⇒ Object
12469 12470 12471 12472 12473 12474 12475 |
# File 'lib/kettle/jem.rb', line 12469 def env_sync_value(env, env_key) Array(env_key).each do |candidate| value = env[candidate].to_s.strip return value if present_template_token_value?(value) end "" end |
.error_class_namespace?(content, namespace) ⇒ Boolean
16382 16383 16384 16385 16386 16387 16388 16389 16390 |
# File 'lib/kettle/jem.rb', line 16382 def error_class_namespace?(content, namespace) return false unless namespace.to_s.split("::").last == "Error" node = ruby_namespace_declaration_node(content, namespace) return false unless node.is_a?(::Prism::ClassNode) superclass = node.superclass&.slice.to_s %w[Exception StandardError].include?(superclass) end |
.event_payload_value(payload, key) ⇒ Object
4872 4873 4874 |
# File 'lib/kettle/jem.rb', line 4872 def event_payload_value(payload, key) payload.fetch(key, payload.fetch(key.to_s, nil)) end |
.event_stream(io, types: nil) ⇒ Object
4695 4696 4697 4698 4699 4700 4701 4702 |
# File 'lib/kettle/jem.rb', line 4695 def event_stream(io, types: nil) Kettle::Ndjson.event_stream( io, types: types, event_types: EVENT_TYPES, aliases: EVENT_TYPE_ALIASES ) end |
.event_stream_from_options(run_options) ⇒ Object
4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 |
# File 'lib/kettle/jem.rb', line 4714 def () = || {} recorder = [:event_recorder] || ["event_recorder"] return recorder if recorder.respond_to?(:emit) stream = [:event_stream] || ["event_stream"] phase_timings = [:phase_timings] ||= [] recorder = Kettle::Ndjson.event_recorder(stream.respond_to?(:emit) ? stream : nil, phase_timings: phase_timings) [:event_recorder] = recorder if .respond_to?(:[]=) recorder end |
.executable_version_constant_nodes(node, namespaces) ⇒ Object
5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 |
# File 'lib/kettle/jem.rb', line 5089 def executable_version_constant_nodes(node, namespaces) constants = [] node.breadth_first_search_all do |candidate| next unless candidate.is_a?(::Prism::ConstantPathNode) segments = ruby_constant_path_segments(candidate) constants << candidate if namespaces.any? do |namespace| segments == namespace + ["Version", "VERSION"] || segments == namespace + ["VERSION"] end end constants end |
.executable_version_entrypoint_sync_step(project_root, report) ⇒ Object
Older generated executable headers used the package name for both the version file and namespace. Projects such as appraisal2 intentionally expose a different historical entrypoint, so repair that exact stale header shape from the configured entrypoint facts.
4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 |
# File 'lib/kettle/jem.rb', line 4972 def executable_version_entrypoint_sync_step(project_root, report) facts = report.fetch(:facts) package_name = facts.dig(:package, :name).to_s entrypoint_require = facts.dig(:rubygems, :entrypoint_require).to_s return if package_name.empty? || entrypoint_require.empty? package_entrypoint = package_name.tr("-", "/") return if package_entrypoint == entrypoint_require namespace = facts.dig(:rubygems, :namespace).to_s version_path = File.join("lib", entrypoint_require, "version.rb") namespace = existing_version_namespace(project_root, version_path) if namespace.empty? return if namespace.empty? legacy_namespace = package_name.split(/[-_]/).map { |part| part[0].to_s.upcase + part[1..].to_s }.join("::") legacy_version_path = "../lib/#{package_entrypoint}/version" canonical_version_path = "../lib/#{entrypoint_require}/version" changed_files = Dir.glob(File.join(project_root, "exe", "*")).sort.filter_map do |path| next unless File.file?(path) before = File.read(path) after = normalize_executable_version_entrypoint( before, legacy_version_path: legacy_version_path, canonical_version_path: canonical_version_path, legacy_namespace: legacy_namespace, namespace: namespace ) next if after == before File.write(path, after) path.delete_prefix("#{project_root}/") end { name: "executable_version_entrypoint_sync", status: changed_files.empty? ? "already_current" : "applied", changed_files: changed_files } end |
.execute_indexed_recipe_reports(project_root:, indexed_recipes:, facts:, files:, template_contents:, decision_policy:, env:) ⇒ Object
4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 |
# File 'lib/kettle/jem.rb', line 4484 def execute_indexed_recipe_reports(project_root:, indexed_recipes:, facts:, files:, template_contents:, decision_policy:, env:) indexed_recipes.to_h do |recipe, index| [ index, execute_timed_recipe( project_root: project_root, recipe: recipe, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env ) ] end end |
.execute_indexed_recipe_reports_thread(project_root:, indexed_recipes:, facts:, files:, template_contents:, decision_policy:, env:, workers:) ⇒ Object
4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 |
# File 'lib/kettle/jem.rb', line 4515 def execute_indexed_recipe_reports_thread(project_root:, indexed_recipes:, facts:, files:, template_contents:, decision_policy:, env:, workers:) chunks = Array.new(workers) { [] } indexed_recipes.each_with_index do |job, offset| chunks.fetch(offset % chunks.length) << job end chunks.reject(&:empty?).flat_map do |chunk| # rubocop:disable ThreadSafety/NewThread -- Bounded workers only read shared inputs and are joined below. Thread.new do thread_id = Thread.current.object_id chunk.map do |recipe, index| report = execute_timed_recipe( project_root: project_root, recipe: recipe, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env ) report[:metadata][:executor] = "thread" report[:metadata][:thread_id] = thread_id report.dig(:report_envelope, :report, :metadata)[:executor] = "thread" report.dig(:report_envelope, :report, :metadata)[:thread_id] = thread_id [index, report] end end # rubocop:enable ThreadSafety/NewThread end.flat_map(&:value).to_h end |
.execute_recipe(project_root:, recipe:, facts:, files:, decision_policy:, env: ENV, template_contents: nil) ⇒ Object
6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 |
# File 'lib/kettle/jem.rb', line 6695 def execute_recipe(project_root:, recipe:, facts:, files:, decision_policy:, env: ENV, template_contents: nil) relative_path = recipe.fetch(:target_path) destination_existed = File.exist?(File.join(project_root, relative_path)) original = files.fetch(relative_path, "") deletion = rakefile_scaffold_cleanup_recipe?(recipe) ? rakefile_scaffold_cleanup(original, facts) : nil readme_timings = [] final = with_readme_timing_context(relative_path, readme_timings) do case recipe.fetch(:name) when "readme_metadata" synchronize_readme(original, facts, project_root: project_root) when "changelog_unreleased" apply_changelog_transfer_entries( normalize_changelog(original, facts), facts.to_h.dig(:changelog, :transfer_entries), excluded_keys: facts.to_h.dig(:changelog, :excluded_transfer_keys) ) when "generated_block_sync" synchronize_managed_block(original, facts) when "github_funding_yml" synchronize_github_funding_yml(original, facts) when "github_actions_ci" synchronize_github_actions_ci(original, facts) when "github_actions_framework_ci" synchronize_github_actions_framework_ci(original, facts) when GITHUB_ACTIONS_FRAMEWORK_GEMFILE_RECIPE synchronize_github_actions_framework_gemfile(recipe.fetch(:target_path), facts) when "github_actions_coverage_ci" synchronize_github_actions_coverage_ci(original, facts) when GITHUB_ACTIONS_OBSOLETE_WORKFLOW_CLEANUP_RECIPE "" when GITHUB_ACTIONS_OPT_IN_WORKFLOW_CLEANUP_RECIPE "" when OPENCOLLECTIVE_DISABLED_FILE_CLEANUP_RECIPE "" when TEMPLATE_LEGACY_DESTINATION_CLEANUP_RECIPE "" when TEMPLATE_OBSOLETE_LICENSE_CLEANUP_RECIPE "" when TEMPLATE_SHIM_PROFILE_CLEANUP_RECIPE "" when GITHUB_ACTIONS_WORKFLOW_SNIPPETS_RECIPE synchronize_github_actions_workflow_snippets(original, facts: facts) when "kettle_config_bootstrap" apply_kettle_config_bootstrap(project_root, recipe, env: env, template_contents: template_contents) when TEMPLATE_SOURCE_PREFERENCE_RECIPE original when TEMPLATE_SOURCE_APPLICATION_RECIPE apply_template_source(project_root, recipe, original, facts: facts, env: env, template_contents: template_contents) when "rakefile_scaffold_cleanup" deletion.fetch(:content) else original end end final = normalize_generated_rakefile(final) if relative_path == "Rakefile" final = ensure_trailing_newline(final) unless delete_file_recipe?(recipe) template_content = recipe_template_content(project_root, recipe, template_contents: template_contents) request = content_recipe_execution_request( recipe_name: recipe.fetch(:primitive), recipe_version: "1", relative_path: relative_path, provider_family: recipe.fetch(:provider_family), provider_backend: recipe[:provider_backend], template_content: template_content, destination_content: original, steps: [content_recipe_step(recipe)], runtime_context: recipe_runtime_context(recipe, facts, deletion), metadata: {packaging_recipe: recipe.fetch(:name), project_root: project_root.to_s} ) changed = delete_file_recipe?(recipe) || final != original = (recipe).merge(destination_existed: destination_existed) decision_evaluation = recipe_decision_evaluation( decision_policy: decision_policy, recipe: recipe, changed: changed, destination_existed: destination_existed ) if DECISION_NO_WRITE_ACTIONS.include?(decision_evaluation.fetch(:selected_action)) final = original changed = false deletion = nil end if github_workflow_template_recipe?(recipe) stale_pins = stale_github_workflow_template_pin_records(relative_path, final, original) [:stale_github_workflow_template_pins] = stale_pins unless stale_pins.empty? end step_report = content_recipe_step_report(recipe: recipe, request: request, original: original, final: final, changed: changed, deletion: deletion) [:decision_evaluation] = decision_evaluation [:readme_timings] = readme_timings unless readme_timings.empty? report = content_recipe_execution_report( request: request, final_content: final, changed: changed, step_reports: [step_report], diagnostics: [], metadata: ) { recipe_name: recipe.fetch(:name), relative_path: relative_path, changed: changed, request_envelope: content_recipe_execution_request_envelope(request), report_envelope: content_recipe_execution_report_envelope(report), final_content: final, metadata: , decision_evaluation: decision_evaluation, diagnostics: [] } end |
.execute_recipe_reports(project_root:, recipes:, facts:, files:, template_contents:, decision_policy:, env:, events:, strategy:, workers: 0, thread_workers: 0, stats: nil) ⇒ Object
4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 |
# File 'lib/kettle/jem.rb', line 4345 def execute_recipe_reports(project_root:, recipes:, facts:, files:, template_contents:, decision_policy:, env:, events:, strategy:, workers: 0, thread_workers: 0, stats: nil) case strategy.to_s when "sequential" record_recipe_planning_execution_stats( stats, worker_safe: 0, main_only: recipes.length, worker_count: 0, spawned: 0, ractor_recipes: 0, thread_worker_count: 0, thread_spawns: 0, thread_recipes: 0, main_recipes: recipes.length ) execute_recipe_reports_sequential( project_root: project_root, recipes: recipes, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env, events: events ) when "classified" execute_recipe_reports_classified( project_root: project_root, recipes: recipes, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env, events: events, workers: workers, thread_workers: thread_workers, stats: stats ) else raise ArgumentError, "Unsupported kettle-jem recipe planning strategy #{strategy.inspect}" end end |
.execute_recipe_reports_classified(project_root:, recipes:, facts:, files:, template_contents:, decision_policy:, env:, events:, workers: 0, thread_workers: 0, stats: nil) ⇒ Object
4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 |
# File 'lib/kettle/jem.rb', line 4405 def execute_recipe_reports_classified(project_root:, recipes:, facts:, files:, template_contents:, decision_policy:, env:, events:, workers: 0, thread_workers: 0, stats: nil) indexed_recipes = recipes.each_with_index.to_a reports_by_index = {} worker_safe, main_only = indexed_recipes.partition { |recipe, _index| worker_safe_recipe?(recipe) } use_threads = thread_workers.to_i.positive? use_ractors = workers.to_i.positive? && worker_safe.any? raise ArgumentError, "Use either KETTLE_JEM_RACTOR_WORKERS or KETTLE_JEM_THREAD_WORKERS, not both" if use_threads && workers.to_i.positive? worker_count = use_ractors ? [workers.to_i, worker_safe.length].min : 0 thread_worker_count = use_threads ? [thread_workers.to_i, worker_safe.length].min : 0 record_recipe_planning_execution_stats( stats, worker_safe: worker_safe.length, main_only: main_only.length, worker_count: worker_count, spawned: worker_count, ractor_recipes: use_ractors ? worker_safe.length : 0, thread_worker_count: thread_worker_count, thread_spawns: thread_worker_count, thread_recipes: use_threads ? worker_safe.length : 0, main_recipes: main_only.length + ((use_threads || use_ractors) ? 0 : worker_safe.length) ) if use_threads reports_by_index.merge!( execute_indexed_recipe_reports_thread( project_root: project_root, indexed_recipes: worker_safe, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env, workers: thread_worker_count ) ) else reports_by_index.merge!( if use_ractors execute_worker_safe_recipe_reports_ractor( project_root: project_root, indexed_recipes: worker_safe, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env, workers: worker_count ) else execute_indexed_recipe_reports( project_root: project_root, indexed_recipes: worker_safe, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env ) end ) end reports_by_index.merge!( execute_indexed_recipe_reports( project_root: project_root, indexed_recipes: main_only, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env ) ) recipes.each_index.map do |index| report = reports_by_index.fetch(index) emit_recipe_event(events, report, index: index, total: recipes.length) report end end |
.execute_recipe_reports_sequential(project_root:, recipes:, facts:, files:, template_contents:, decision_policy:, env:, events:) ⇒ Object
4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 |
# File 'lib/kettle/jem.rb', line 4389 def execute_recipe_reports_sequential(project_root:, recipes:, facts:, files:, template_contents:, decision_policy:, env:, events:) recipes.each_with_index.map do |recipe, index| report = execute_timed_recipe( project_root: project_root, recipe: recipe, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env ) emit_recipe_event(events, report, index: index, total: recipes.length) report end end |
.execute_timed_recipe(project_root:, recipe:, facts:, files:, template_contents:, decision_policy:, env:) ⇒ Object
4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 |
# File 'lib/kettle/jem.rb', line 4607 def execute_timed_recipe(project_root:, recipe:, facts:, files:, template_contents:, decision_policy:, env:) timed_recipe_report do execute_recipe( project_root: project_root, recipe: recipe, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env ) end end |
.execute_worker_safe_recipe_reports_ractor(project_root:, indexed_recipes:, facts:, files:, template_contents:, decision_policy:, env:, workers:) ⇒ Object
4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 |
# File 'lib/kettle/jem.rb', line 4545 def execute_worker_safe_recipe_reports_ractor(project_root:, indexed_recipes:, facts:, files:, template_contents:, decision_policy:, env:, workers:) context = Ractor.make_shareable({ project_root: project_root, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env }) chunks = Array.new(workers) { [] } indexed_recipes.each_with_index do |job, offset| chunks.fetch(offset % chunks.length) << job end pool = chunks.reject(&:empty?).map do |chunk| jobs = Ractor.make_shareable(chunk.map do |recipe, index| { index: index, recipe: worker_safe_recipe_payload(recipe, project_root: project_root, template_contents: template_contents) } end) started_at = monotonic_time [ started_at, Ractor.new(context, jobs) do |worker_context, worker_jobs| ractor_id = Ractor.current.object_id worker_jobs.map do |job| report = Kettle::Jem.execute_recipe(**worker_context.merge(recipe: job.fetch(:recipe))) [job.fetch(:index), report, ractor_id] end end ] end reports = {} pool.each do |started_at, worker| worker_results = worker.value duration_ms = duration_ms_since(started_at) worker_results.each do |index, report, ractor_id| report = report_with_duration(report, duration_ms) report[:metadata][:executor] = "ractor" report[:metadata][:ractor_id] = ractor_id report.dig(:report_envelope, :report, :metadata)[:executor] = "ractor" report.dig(:report_envelope, :report, :metadata)[:ractor_id] = ractor_id reports[index] = report end end reports end |
.existing_entrypoint_version_namespace(project_root, relative_path, expected_depth: nil) ⇒ Object
16549 16550 16551 16552 16553 16554 16555 16556 16557 |
# File 'lib/kettle/jem.rb', line 16549 def existing_entrypoint_version_namespace(project_root, relative_path, expected_depth: nil) content = read_project_file(project_root, relative_path) if expected_depth return ruby_entrypoint_module_namespace(content, expected_depth: expected_depth) || ruby_version_class_eval_namespaces(content).first end ruby_version_class_eval_namespaces(content).first || ruby_entrypoint_module_namespace(content) end |
.existing_namespace_superclass_details(project_root, namespace, preferred_path: nil) ⇒ Object
16438 16439 16440 16441 16442 16443 16444 16445 16446 16447 16448 |
# File 'lib/kettle/jem.rb', line 16438 def existing_namespace_superclass_details(project_root, namespace, preferred_path: nil) library_paths = [preferred_path, *ruby_library_source_paths(project_root)].compact.uniq library_paths.each do |relative_path| superclasses = existing_version_namespace_superclasses(project_root, relative_path, namespace) next if superclasses.empty? return {path: relative_path, superclasses: superclasses} end {path: nil, superclasses: {}} end |
.existing_simplecov_bootstrap_template_preferences(project_root, config, preferences) ⇒ Object
18265 18266 18267 18268 18269 18270 18271 18272 18273 18274 18275 18276 18277 18278 18279 18280 18281 18282 18283 18284 18285 18286 18287 18288 18289 18290 18291 18292 18293 18294 18295 18296 |
# File 'lib/kettle/jem.rb', line 18265 def existing_simplecov_bootstrap_template_preferences(project_root, config, preferences) templates = template_activation_config(config) return [] unless templates.is_a?(Hash) root = template_root(project_root, templates) return [] unless root.fetch(:kind) == "packaged" configured_paths = preferences.map { |preference| preference.fetch(:target_path).to_s }.to_set SIMPLECOV_BOOTSTRAP_TEMPLATE_PATHS.filter_map do |target_path| next if configured_paths.include?(target_path) next unless File.exist?(File.join(project_root, target_path)) selected_source = preferred_template_source(root.fetch(:path), target_path) next unless selected_source { target_path: target_path, configured_source: target_path, selected_source: template_source_display_path(root, selected_source), selection_reason: template_source_selection_reason(target_path, template_source_display_path(root, selected_source)), apply: templates["apply"] == true, strategy: "merge", preference: "template", add_template_only_nodes: true, freeze_token: config.dig("defaults", "freeze_token").to_s.empty? ? "kettle-jem" : config.dig("defaults", "freeze_token").to_s, source_relative_path: selected_source, source_root: root.fetch(:kind), source_root_path: root.fetch(:path), migration: "simplecov_bootstrap" } end end |
.existing_version_file_includes_version_module?(project_root, relative_path) ⇒ Boolean
16392 16393 16394 |
# File 'lib/kettle/jem.rb', line 16392 def existing_version_file_includes_version_module?(project_root, relative_path) version_file_includes_version_module?(read_project_file(project_root, relative_path)) end |
.existing_version_file_value(project_root, relative_path) ⇒ Object
16337 16338 16339 |
# File 'lib/kettle/jem.rb', line 16337 def existing_version_file_value(project_root, relative_path) ruby_version_constant_value(read_project_file(project_root, relative_path)).to_s end |
.existing_version_namespace(project_root, relative_path) ⇒ Object
16353 16354 16355 |
# File 'lib/kettle/jem.rb', line 16353 def existing_version_namespace(project_root, relative_path) ruby_version_module_namespace(read_project_file(project_root, relative_path)) end |
.existing_version_namespace_kinds(project_root, relative_path, namespace, entrypoint_path: nil) ⇒ Object
16405 16406 16407 16408 16409 16410 16411 16412 16413 16414 16415 16416 16417 16418 |
# File 'lib/kettle/jem.rb', line 16405 def existing_version_namespace_kinds(project_root, relative_path, namespace, entrypoint_path: nil) contents = [read_project_file(project_root, relative_path)] contents << read_project_file(project_root, entrypoint_path) if entrypoint_path segments = namespace.to_s.split("::").reject(&:empty?) return {} if segments.empty? contents.each_with_object({}) do |content, kinds| segments.each_index do |index| prefix = segments.first(index + 1).join("::") kind = ruby_namespace_declaration_kind(content, prefix) kinds[index] = kind if kind end end end |
.existing_version_namespace_superclasses(project_root, relative_path, namespace, entrypoint_path: nil) ⇒ Object
16420 16421 16422 16423 16424 16425 16426 16427 16428 16429 16430 16431 16432 16433 16434 16435 16436 |
# File 'lib/kettle/jem.rb', line 16420 def existing_version_namespace_superclasses(project_root, relative_path, namespace, entrypoint_path: nil) contents = [read_project_file(project_root, relative_path)] contents << read_project_file(project_root, entrypoint_path) if entrypoint_path segments = namespace.to_s.split("::").reject(&:empty?) return {} if segments.empty? contents.each_with_object({}) do |content, superclasses| segments.each_index do |index| prefix = segments.first(index + 1).join("::") node = ruby_namespace_declaration_node(content, prefix) next unless node.is_a?(::Prism::ClassNode) superclass = node.superclass&.slice.to_s.strip superclasses[index] = superclass unless superclass.empty? end end end |
.expand_framework_gemfile_pattern(pattern, version) ⇒ Object
19189 19190 19191 19192 19193 19194 19195 19196 |
# File 'lib/kettle/jem.rb', line 19189 def (pattern, version) replacement = if pattern.include?("_{version}") || pattern.include?("{version}_") version.tr(".", "_") else version end pattern.gsub("{version}", replacement) end |
.expand_line_range_through_following_blanks(content, end_line) ⇒ Object
10839 10840 10841 10842 10843 10844 |
# File 'lib/kettle/jem.rb', line 10839 def (content, end_line) lines = content.to_s.lines line = end_line line += 1 while lines[line]&.strip == "" line end |
.explicit_integration_enabled?(config, integration) ⇒ Boolean
17953 17954 17955 17956 17957 17958 17959 |
# File 'lib/kettle/jem.rb', line 17953 def explicit_integration_enabled?(config, integration) return false unless config.is_a?(Hash) && config["integrations"].is_a?(Hash) config["integrations"].any? do |name, value| normalize_integration_name(name) == integration && truthy_config?(value) end end |
.explicit_zero_runtime_floor?(facts) ⇒ Boolean
11049 11050 11051 |
# File 'lib/kettle/jem.rb', line 11049 def explicit_zero_runtime_floor?(facts) facts.to_h.dig(:rubygems, :min_ruby).to_s.strip == "0" end |
.extract_gemspec_development_dependencies(gemspec) ⇒ Object
3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 |
# File 'lib/kettle/jem.rb', line 3885 def extract_gemspec_development_dependencies(gemspec) if gemspec.is_a?(Hash) return Array(gemspec[:development_dependencies] || gemspec["development_dependencies"]).map do |dependency| { name: dependency.name.to_s, requirement: dependency.requirement.to_s } end.reject { |dependency| dependency.fetch(:name).empty? }.uniq { |dependency| dependency.fetch(:name) } end Array(gemspec&.development_dependencies).map do |dependency| { name: dependency.name.to_s, requirement: dependency.requirement.to_s } end.reject { |dependency| dependency.fetch(:name).empty? }.uniq { |dependency| dependency.fetch(:name) } end |
.fallback_opencollective_org ⇒ Object
14194 14195 14196 |
# File 'lib/kettle/jem.rb', line 14194 def fallback_opencollective_org {org: DEFAULT_OPENCOLLECTIVE_ORG, source: "fallback.default"} end |
.falsey_config?(value) ⇒ Boolean
18015 18016 18017 |
# File 'lib/kettle/jem.rb', line 18015 def falsey_config?(value) %w[false no 0].include?(value.to_s.strip.downcase) end |
.file_outcome_payload(file_outcome) ⇒ Object
13954 13955 13956 13957 13958 13959 13960 13961 |
# File 'lib/kettle/jem.rb', line 13954 def file_outcome_payload(file_outcome) { relative_path: file_outcome.relative_path, absolute_path: file_outcome.absolute_path, action: file_outcome.action.to_s, content: file_outcome.content } end |
.file_work_execution_stats(file_workers, file_thread_workers = 0) ⇒ Object
13849 13850 13851 13852 13853 13854 13855 13856 13857 13858 13859 13860 13861 |
# File 'lib/kettle/jem.rb', line 13849 def file_work_execution_stats(file_workers, file_thread_workers = 0) { file_worker_count: file_workers.to_i, file_thread_worker_count: file_thread_workers.to_i, file_work_units: 0, file_operations: 0, file_ractor_units: 0, file_ractor_spawn_count: 0, file_thread_units: 0, file_thread_spawn_count: 0, main_file_units: 0 } end |
.file_work_thread_workers_for(env, run_options) ⇒ Object
4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 |
# File 'lib/kettle/jem.rb', line 4329 def file_work_thread_workers_for(env, ) value = ( || {})[:thread_file_workers] || ( || {})["thread_file_workers"] || ( || {})[:file_work_thread_workers] || ( || {})["file_work_thread_workers"] || (env || {})["KETTLE_JEM_THREAD_FILE_WORKERS"] return 0 if value.nil? || value.to_s.strip.empty? workers = Integer(value) raise ArgumentError, "KETTLE_JEM_THREAD_FILE_WORKERS must be >= 0" if workers.negative? workers rescue ArgumentError raise ArgumentError, "KETTLE_JEM_THREAD_FILE_WORKERS must be a non-negative integer" end |
.file_work_unit_payload(file_work_unit) ⇒ Object
13947 13948 13949 13950 13951 13952 |
# File 'lib/kettle/jem.rb', line 13947 def file_work_unit_payload(file_work_unit) { relative_path: file_work_unit.relative_path, operations: file_work_unit.operations.map { |operation| file_outcome_payload(operation) } } end |
.file_work_units_for_phase(project_root, recipe_reports) ⇒ Object
13928 13929 13930 |
# File 'lib/kettle/jem.rb', line 13928 def file_work_units_for_phase(project_root, recipe_reports) file_work_units_from_write_intents(write_intents_for_phase(project_root, recipe_reports)) end |
.file_work_units_from_write_intents(write_intents) ⇒ Object
13936 13937 13938 13939 13940 13941 13942 13943 13944 13945 |
# File 'lib/kettle/jem.rb', line 13936 def file_work_units_from_write_intents(write_intents) grouped_operations = {} Array(write_intents).each do |write_intent| grouped_operations[write_intent.relative_path] ||= [] grouped_operations[write_intent.relative_path] << write_intent end grouped_operations.map do |relative_path, operations| FileWorkUnit.new(relative_path: relative_path, operations: operations) end end |
.file_work_workers_for(env, run_options) ⇒ Object
4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 |
# File 'lib/kettle/jem.rb', line 4313 def file_work_workers_for(env, ) value = ( || {})[:ractor_file_workers] || ( || {})["ractor_file_workers"] || ( || {})[:file_work_workers] || ( || {})["file_work_workers"] || (env || {})["KETTLE_JEM_RACTOR_FILE_WORKERS"] return 0 if value.nil? || value.to_s.strip.empty? workers = Integer(value) raise ArgumentError, "KETTLE_JEM_RACTOR_FILE_WORKERS must be >= 0" if workers.negative? workers rescue ArgumentError raise ArgumentError, "KETTLE_JEM_RACTOR_FILE_WORKERS must be a non-negative integer" end |
.filter_recipe_pack(pack, template_selection) ⇒ Object
13263 13264 13265 13266 13267 13268 13269 13270 |
# File 'lib/kettle/jem.rb', line 13263 def filter_recipe_pack(pack, template_selection) patterns = recipe_filter_patterns(template_selection) return pack if patterns.empty? pack.merge( recipes: pack.fetch(:recipes).select { |recipe| selected_template_path?(recipe.fetch(:target_path), patterns) } ) end |
.finalize_accepted_template_source(recipe, content, destination_content, facts:, project_root: nil) ⇒ Object
7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 |
# File 'lib/kettle/jem.rb', line 7230 def finalize_accepted_template_source(recipe, content, destination_content, facts:, project_root: nil) case template_file_type(recipe) when :gemfile finalize_gemfile_template_source(recipe, content, destination_content, facts: facts, template_content: content) when :appraisals merge_appraisals_template_policy(content, facts: facts) when :gemspec package_name = facts.dig(:package, :name).to_s if facts receiver = gemspec_block_param(content) || "spec" pruned = remove_gemspec_self_dependency_lines(content, package_name, receiver: receiver) rewrite_gemspec_version_loader(pruned, facts: facts) when :toml preserve_mise_project_settings(recipe, content, destination_content, project_root: project_root) else content end end |
.finalize_gemfile_template_source(recipe, content, destination_content, facts:, template_content:) ⇒ Object
7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 |
# File 'lib/kettle/jem.rb', line 7980 def finalize_gemfile_template_source(recipe, content, destination_content, facts:, template_content:) modular_gemfile = modular_gemfile_template_recipe?(recipe) output = if modular_gemfile # Modular Gemfiles are dependency fragments, not aggregate project # Gemfiles. Preserve a dependency when a released fragment is # specifically named for that dependency (for example # mutex_m/r4/v0.3.gemfile). Local override fragments intentionally # retain their existing dependency-pruning behavior. target = recipe.fetch(:target_path).to_s package_name = facts.to_h.dig(:package, :name).to_s runtime_dependencies = package_runtime_dependency_names(facts) if local_gemfile_template_recipe?(recipe) output = remove_gemfile_dependency_blocks(content, ["rdoc"]) else named_fragment_dependencies = runtime_dependencies.select do |dependency| target.include?(dependency.tr("-", "_")) end removable = [package_name, *(runtime_dependencies - named_fragment_dependencies)] output = remove_gemfile_dependency_blocks(content, removable) output = remove_gemfile_percent_w_entries(output, removable) end # The returned content contains the policy-preserving rewrite. # rubocop:disable Lint/UselessAssignment output = apply_commented_gem_dependency_policy(template_content, output) # rubocop:enable Lint/UselessAssignment else merge_gemfile_template_policy( content, facts: facts, template_content: template_content, preserve_self_word_entries: local_gemfile_template_recipe?(recipe) ) end if recipe.fetch(:target_path).to_s == "Gemfile" # A merged Gemfile retains its project-specific source; an accepted # template owns the complete source declaration. unless recipe.dig(:template_preference, :strategy).to_s == "accept_template" output = preserve_destination_gemfile_source(output, destination_content) end output = inject_main_gemfile_recording_eval(output, facts) output = inject_main_gemfile_default_test_bundle(output, facts) output = remove_stale_main_gemfile_tree_sitter_language_pack(output, template_content) output = remove_stale_main_gemfile_direct_sibling_block(output, template_content) output = deduplicate_main_gemfile_direct_sibling_blocks(output) output = ensure_main_gemfile_nomono_bootstrap(output, template_content) output = normalize_main_gemfile_nomono_declaration(output) output = deduplicate_main_gemfile_eval_gemfiles(output) output = guard_main_gemfile_runtime_workspace_overrides(output) output = migrate_legacy_byebug_pair(output) end output = normalize_local_gemfile_nomono_bootstrap(output) if local_gemfile_template_recipe?(recipe) output = remove_gemfile_percent_w_entries(output, [facts.to_h.dig(:package, :name)]) if local_gemfile_template_recipe?(recipe) return output if recipe.dig(:template_preference, :strategy).to_s == "accept_template" return output unless local_gemfile_template_recipe?(recipe) output = normalize_structuredmerge_local_gems(output, template_content) merge_local_gem_overrides(output, destination_content, facts: facts, template_content: template_content) end |
.finalize_github_workflow_template(content, facts = nil) ⇒ Object
9096 9097 9098 9099 |
# File 'lib/kettle/jem.rb', line 9096 def finalize_github_workflow_template(content, facts = nil) output = apply_github_actions_engine_exec_cmd_overrides(content, facts) inject_framework_matrix_workflow_env(update_github_actions_pins(output), facts) end |
.finalize_kettle_config_template_source(recipe, content) ⇒ Object
7219 7220 7221 7222 7223 |
# File 'lib/kettle/jem.rb', line 7219 def finalize_kettle_config_template_source(recipe, content) tokens = stringify_template_tokens(recipe.fetch(:template_tokens, {})) resolved = resolve_template_tokens(content, tokens, scan_unresolved: false) assert_no_unresolved_template_tokens_in_yaml_values(resolved, KETTLE_CONFIG_PATH) end |
.finalize_rubocop_config(content) ⇒ Object
7225 7226 7227 7228 |
# File 'lib/kettle/jem.rb', line 7225 def finalize_rubocop_config(content) finalized = remove_yaml_scalar_path(content, %w[AllCops TargetRubyVersion]) ensure_yaml_top_level_sequence_items(finalized, "plugins", ["rubocop-rspec"]) end |
.finalize_template_source_content(recipe, content) ⇒ Object
7210 7211 7212 7213 7214 7215 7216 7217 |
# File 'lib/kettle/jem.rb', line 7210 def finalize_template_source_content(recipe, content) return finalize_rubocop_config(content) if recipe.fetch(:target_path).to_s == ".rubocop.yml" return finalize_kettle_config_template_source(recipe, content) if recipe.fetch(:target_path).to_s == KETTLE_CONFIG_PATH return normalize_simplecov_template_source(content) if recipe.fetch(:target_path).to_s == ".simplecov" return normalize_spec_helper_simplecov_template_source(content) if recipe.fetch(:target_path).to_s == "spec/spec_helper.rb" content end |
.first_grapheme(text) ⇒ Object
13162 13163 13164 |
# File 'lib/kettle/jem.rb', line 13162 def first_grapheme(text) text.to_s.strip[/\A\X/u].to_s end |
.forge_facts(config, env, derived_github_user: nil) ⇒ Object
14939 14940 14941 14942 14943 14944 14945 14946 14947 14948 |
# File 'lib/kettle/jem.rb', line 14939 def forge_facts(config, env, derived_github_user: nil) token_config = token_config_values(config) forge_config = token_config["forge"].is_a?(Hash) ? token_config["forge"] : {} compact_hash( gh_user: forge_user_value(forge_config, env, :gh_user, derived_value: derived_github_user).to_s, gl_user: forge_user_value(forge_config, env, :gl_user).to_s, cb_user: forge_user_value(forge_config, env, :cb_user).to_s, sh_user: forge_user_value(forge_config, env, :sh_user).to_s ) end |
.forge_template_tokens(forge) ⇒ Object
14954 14955 14956 14957 14958 14959 14960 14961 |
# File 'lib/kettle/jem.rb', line 14954 def forge_template_tokens(forge) { "KJ|GH:USER" => forge[:gh_user].to_s, "KJ|GL:USER" => forge[:gl_user].to_s, "KJ|CB:USER" => forge[:cb_user].to_s, "KJ|SH:USER" => forge[:sh_user].to_s } end |
.forge_user_value(forge_config, env, key, derived_value: nil) ⇒ Object
14950 14951 14952 |
# File 'lib/kettle/jem.rb', line 14950 def forge_user_value(forge_config, env, key, derived_value: nil) preferred_template_token_value(derived_value, forge_config[key.to_s], env, FORGE_USER_ENV_KEYS.fetch(key)) end |
.format_copyright_years(years) ⇒ Object
14920 14921 14922 14923 14924 14925 14926 14927 14928 14929 14930 14931 14932 14933 14934 14935 14936 14937 |
# File 'lib/kettle/jem.rb', line 14920 def format_copyright_years(years) sorted = Array(years).map(&:to_i).reject(&:zero?).sort.uniq return Time.now.utc.year.to_s if sorted.empty? return sorted.first.to_s if sorted.one? runs = [] run = [sorted.first] sorted[1..].to_a.each do |year| if year == run.last + 1 run << year else runs << run run = [year] end end runs << run runs.map { |span| span.one? ? span.first.to_s : "#{span.first}-#{span.last}" }.join(", ") end |
.framework_gemfile_path(gemfile) ⇒ Object
19198 19199 19200 |
# File 'lib/kettle/jem.rb', line 19198 def framework_gemfile_path(gemfile) gemfile.include?("/") ? gemfile : "gemfiles/#{gemfile}" end |
.framework_matrix_appraisal_block(entry) ⇒ Object
10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 |
# File 'lib/kettle/jem.rb', line 10321 def framework_matrix_appraisal_block(entry) lines = [ %(appraise "#{entry.fetch(:name)}" do) ] entry.fetch(:eval_gemfiles).each do |gemfile| lines << %( eval_gemfile "#{gemfile}") end lines << "end" lines.join("\n") end |
.framework_matrix_appraisal_dependency_gemfiles(facts) ⇒ Object
10211 10212 10213 10214 10215 10216 10217 |
# File 'lib/kettle/jem.rb', line 10211 def framework_matrix_appraisal_dependency_gemfiles(facts) framework_matrix = facts.to_h.dig(:ci, :framework_matrix).to_h [ *framework_matrix.fetch(:appraisals, []).flat_map { |entry| entry.fetch(:eval_gemfiles, []) }, *framework_matrix.fetch(:gemfiles, []).map { |entry| entry.fetch(:path).to_s.delete_prefix("gemfiles/") } ].map(&:to_s).to_set end |
.framework_matrix_appraisal_env_by_name(facts) ⇒ Object
9154 9155 9156 9157 9158 9159 9160 |
# File 'lib/kettle/jem.rb', line 9154 def framework_matrix_appraisal_env_by_name(facts) entries = facts.to_h.dig(:ci, :framework_matrix, :appraisals).to_a entries.to_h do |entry| env = {"KJ_FRAMEWORK_MATRIX_GEM" => entry.fetch(:gem).to_s}.merge(entry.fetch(:env, {}).transform_keys(&:to_s)) [entry.fetch(:name).to_s, env.reject { |_key, value| value.to_s.empty? }] end.reject { |_name, env| env.empty? } end |
.framework_matrix_appraisal_gemfile_path(path) ⇒ Object
18976 18977 18978 |
# File 'lib/kettle/jem.rb', line 18976 def framework_matrix_appraisal_gemfile_path(path) path.to_s.sub(%r{\Agemfiles/}, "") end |
.framework_matrix_appraisal_gemfiles(raw) ⇒ Object
18969 18970 18971 18972 18973 18974 |
# File 'lib/kettle/jem.rb', line 18969 def framework_matrix_appraisal_gemfiles(raw) Array(raw["appraisal_gemfiles"] || raw["appraisal_eval_gemfiles"]).filter_map do |path| normalized = framework_matrix_appraisal_gemfile_path(path.to_s.strip) normalized unless normalized.empty? end end |
.framework_matrix_appraisal_name(dimension, slug) ⇒ Object
18980 18981 18982 |
# File 'lib/kettle/jem.rb', line 18980 def framework_matrix_appraisal_name(dimension, slug) [dimension, slug].join("-").downcase.gsub(/[^a-z0-9]+/, "-").gsub(/\A-|-+\z/, "") end |
.framework_matrix_env(raw) ⇒ Object
19081 19082 19083 19084 19085 19086 19087 19088 19089 19090 |
# File 'lib/kettle/jem.rb', line 19081 def framework_matrix_env(raw) return {} unless raw.is_a?(Hash) raw.each_with_object({}) do |(key, value), result| name = key.to_s.strip next if name.empty? result[name] = value.to_s end end |
.framework_matrix_replaced_appraisal_names(dimension, entry, name) ⇒ Object
18953 18954 18955 18956 18957 18958 |
# File 'lib/kettle/jem.rb', line 18953 def framework_matrix_replaced_appraisal_names(dimension, entry, name) default_name = framework_matrix_appraisal_name(dimension, entry.fetch(:slug)) return [] if default_name == name [default_name] end |
.framework_matrix_version_entry(raw) ⇒ Object
18984 18985 18986 18987 18988 18989 18990 18991 18992 18993 18994 18995 18996 18997 18998 18999 19000 19001 19002 19003 19004 19005 19006 19007 19008 19009 19010 19011 19012 19013 19014 19015 |
# File 'lib/kettle/jem.rb', line 18984 def framework_matrix_version_entry(raw) if raw.is_a?(Hash) label = raw.fetch("label", raw["version"]).to_s.strip slug = raw.fetch("slug", label).to_s.strip requirement = raw.fetch("requirement", default_framework_matrix_requirement(label)).to_s.strip appraisal_name = (raw["appraisal"] || raw["appraisal_name"] || raw["standard_appraisal"]).to_s.strip env = framework_matrix_env(raw["env"]) default = DecisionPolicy.value_to_boolean(raw["default"]) == true replaces = Array(raw["replaces"]).filter_map { |name| nonempty_string(name) } else label = raw.to_s.strip slug = label requirement = default_framework_matrix_requirement(label) appraisal_name = "" env = {} default = false replaces = [] end return if label.empty? || slug.empty? || requirement.empty? entry = { label: label, slug: slug, requirement: requirement } entry[:appraisal_name] = appraisal_name unless appraisal_name.empty? entry[:standard_appraisal] = true if raw.is_a?(Hash) && raw["standard_appraisal"] entry[:env] = env unless env.empty? entry[:default] = true if default entry[:replaces] = replaces unless replaces.empty? entry end |
.framework_matrix_workflow_enabled?(raw) ⇒ Boolean
18960 18961 18962 18963 18964 18965 18966 18967 |
# File 'lib/kettle/jem.rb', line 18960 def framework_matrix_workflow_enabled?(raw) configured = raw["workflow"] configured = raw["generate_workflow"] if configured.nil? configured = raw["ci"] if configured.nil? return true if configured.nil? DecisionPolicy.value_to_boolean(configured) != false end |
.freeze_marker_blocks(content, freeze_token: nil) ⇒ Object
11769 11770 11771 11772 11773 11774 11775 11776 11777 11778 11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 |
# File 'lib/kettle/jem.rb', line 11769 def freeze_marker_blocks(content, freeze_token: nil) marker = freeze_token.to_s.empty? ? "kettle-jem" : freeze_token.to_s lines = content.to_s.lines blocks = [] index = 0 while index < lines.length unless lines[index].include?("# #{marker}:freeze") index += 1 next end start_index = index while index < lines.length index += 1 break if lines[index - 1].include?("# #{marker}:unfreeze") end blocks << lines[start_index...index] end blocks end |
.funding_platform_enabled?(enabled_platforms, platform) ⇒ Boolean
14143 14144 14145 14146 14147 |
# File 'lib/kettle/jem.rb', line 14143 def funding_platform_enabled?(enabled_platforms, platform) return true unless enabled_platforms.is_a?(Hash) enabled_platforms.fetch(platform.to_s, true) == true end |
.funding_platform_policies(config, env) ⇒ Object
14128 14129 14130 14131 14132 14133 14134 14135 14136 14137 14138 14139 14140 14141 |
# File 'lib/kettle/jem.rb', line 14128 def funding_platform_policies(config, env) funding = config["funding"] configured = funding.is_a?(Hash) ? funding : {} FUNDING_README_PLATFORMS.to_h do |platform| value = if platform == "open_collective" !opencollective_policy(config, env).fetch(:disabled) elsif configured.key?(platform) !falsey_config?(configured.fetch(platform)) else !FUNDING_DEFAULT_DISABLED_PLATFORMS.include?(platform) end [platform, value] end end |
.funding_platform_token_facts(config, env) ⇒ Object
14963 14964 14965 14966 14967 14968 14969 14970 14971 14972 |
# File 'lib/kettle/jem.rb', line 14963 def funding_platform_token_facts(config, env) token_config = token_config_values(config) funding_config = token_config["funding"].is_a?(Hash) ? token_config["funding"] : {} compact_hash( kofi: funding_platform_token_value(funding_config, env, :kofi).to_s, paypal: funding_platform_token_value(funding_config, env, :paypal).to_s, buymeacoffee: funding_platform_token_value(funding_config, env, :buymeacoffee).to_s, liberapay: funding_platform_token_value(funding_config, env, :liberapay).to_s ) end |
.funding_platform_token_value(funding_config, env, key) ⇒ Object
14974 14975 14976 |
# File 'lib/kettle/jem.rb', line 14974 def funding_platform_token_value(funding_config, env, key) preferred_template_token_value(nil, funding_config[key.to_s], env, FUNDING_TOKEN_ENV_KEYS.fetch(key)) end |
.funding_template_tokens(funding) ⇒ Object
14978 14979 14980 14981 14982 14983 14984 14985 14986 |
# File 'lib/kettle/jem.rb', line 14978 def funding_template_tokens(funding) platform_tokens = funding.fetch(:platform_tokens, {}) { "KJ|FUNDING:KOFI" => platform_tokens[:kofi].to_s, "KJ|FUNDING:PAYPAL" => platform_tokens[:paypal].to_s, "KJ|FUNDING:BUYMEACOFFEE" => platform_tokens[:buymeacoffee].to_s, "KJ|FUNDING:LIBERAPAY" => platform_tokens[:liberapay].to_s } end |
.funding_urls(project_root, package_name, funding_uri: nil, opencollective_disabled: false, open_collective_org: nil, enabled_platforms: nil) ⇒ Object
13470 13471 13472 13473 13474 13475 13476 13477 13478 13479 13480 13481 13482 13483 13484 13485 13486 13487 13488 13489 13490 |
# File 'lib/kettle/jem.rb', line 13470 def funding_urls(project_root, package_name, funding_uri: nil, opencollective_disabled: false, open_collective_org: nil, enabled_platforms: nil) urls = [funding_uri] path = File.join(project_root, ".github", "FUNDING.yml") if File.exist?(path) urls.concat( github_funding_urls( path, opencollective_disabled: opencollective_disabled, enabled_platforms: enabled_platforms ) ) end if !opencollective_disabled && funding_platform_enabled?(enabled_platforms, "open_collective") urls << github_funding_platform_urls("open_collective", [open_collective_org]).first end if funding_platform_enabled?(enabled_platforms, "tidelift") urls << github_funding_platform_urls("tidelift", ["rubygems/#{package_name}"]).first end urls.compact.uniq.sort end |
.gem_major_token(version) ⇒ Object
14641 14642 14643 14644 14645 |
# File 'lib/kettle/jem.rb', line 14641 def gem_major_token(version) Gem::Version.new(version.to_s).segments.first.to_s rescue ArgumentError "0" end |
.gemfile_comment_line?(line) ⇒ Boolean
9947 9948 9949 |
# File 'lib/kettle/jem.rb', line 9947 def gemfile_comment_line?(line) line.to_s.lstrip.start_with?("#") end |
.gemfile_conditional_node?(node) ⇒ Boolean
8869 8870 8871 |
# File 'lib/kettle/jem.rb', line 8869 def gemfile_conditional_node?(node) node.is_a?(::Prism::IfNode) || node.is_a?(::Prism::UnlessNode) end |
.gemfile_declares_direct_gem?(content, gem_name) ⇒ Boolean
8107 8108 8109 8110 8111 |
# File 'lib/kettle/jem.rb', line 8107 def gemfile_declares_direct_gem?(content, gem_name) ruby_call_records(content, :gem).any? do |call| call.receiver.nil? && ruby_string_argument(call) == gem_name.to_s end end |
.gemfile_declares_gem?(content, gem_name) ⇒ Boolean
5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 |
# File 'lib/kettle/jem.rb', line 5457 def gemfile_declares_gem?(content, gem_name) ruby_call_records(content, nil).any? do |call| next false unless call.receiver.nil? case call.name when :gem ruby_string_argument(call) == gem_name.to_s when :gemspec gemspec_path_declares_gem?(ruby_keyword_string_argument(call, :path), gem_name) else false end end end |
.gemfile_dependency_insertion_line(content) ⇒ Object
9472 9473 9474 9475 9476 9477 9478 9479 9480 |
# File 'lib/kettle/jem.rb', line 9472 def gemfile_dependency_insertion_line(content) body = prism_parse_success(content)&.value&.statements&.body || [] node = body.find do |statement| gemfile_dependency_statement?(statement) end return content.to_s.lines.length unless node node.location.start_line - 1 end |
.gemfile_dependency_names(content) ⇒ Object
6998 6999 7000 |
# File 'lib/kettle/jem.rb', line 6998 def gemfile_dependency_names(content) gemfile_gem_call_records(content).map { |record| record.fetch(:name) } + gemfile_nomono_dependency_names(content) end |
.gemfile_dependency_statement?(node) ⇒ Boolean
9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 |
# File 'lib/kettle/jem.rb', line 9482 def gemfile_dependency_statement?(node) case node when ::Prism::CallNode %i[gem group platforms].include?(node.name) when ::Prism::IfNode, ::Prism::UnlessNode true else false end end |
.gemfile_eval_bucket_entries(content) ⇒ Object
10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 |
# File 'lib/kettle/jem.rb', line 10078 def gemfile_eval_bucket_entries(content) lines = content.to_s.lines ruby_call_records(content, :eval_gemfile).filter_map do |call| path = ruby_string_argument(call) next unless path key = normalize_eval_gemfile_ruby_bucket(path) next unless key start_line = call.location.start_line end_line = ruby_node_source_end_line(call) section_start_line = gemfile_eval_comment_start_line(lines, start_line) { path: path, key: key, line: (lines[(start_line - 1)..(end_line - 1)] || []).join, section_line: (lines[(section_start_line - 1)..(end_line - 1)] || []).join, start_line: start_line, end_line: end_line } end end |
.gemfile_eval_comment_start_line(lines, start_line) ⇒ Object
10101 10102 10103 10104 10105 10106 10107 |
# File 'lib/kettle/jem.rb', line 10101 def gemfile_eval_comment_start_line(lines, start_line) index = start_line.to_i - 2 return start_line if index.negative? index -= 1 while index >= 0 && lines.fetch(index).lstrip.start_with?("#") index + 2 end |
.gemfile_eval_paths(content) ⇒ Object
9433 9434 9435 |
# File 'lib/kettle/jem.rb', line 9433 def gemfile_eval_paths(content) ruby_call_records(content, :eval_gemfile).filter_map { |call| ruby_string_argument(call) } end |
.gemfile_gem_call_records(content) ⇒ Object
9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 |
# File 'lib/kettle/jem.rb', line 9590 def gemfile_gem_call_records(content) ruby_call_records(content, :gem).filter_map do |call| name = ruby_string_argument(call) next unless name { name: name, requirements: ruby_string_arguments(call).drop(1), start_line: call.location.start_line, end_line: ruby_node_source_end_line(call) } end end |
.gemfile_nomono_dependency_names(content) ⇒ Object
7002 7003 7004 7005 7006 7007 7008 7009 7010 |
# File 'lib/kettle/jem.rb', line 7002 def gemfile_nomono_dependency_names(content) result = prism_parse_success(content) return [] unless result word_arrays_by_local = ruby_local_word_array_assignments(result.value) ruby_call_records(content, :eval_nomono_gems).flat_map do |call| ruby_static_string_array_value(ruby_keyword_argument_node(call, :gems), word_arrays_by_local) end.uniq end |
.gemfile_paragraphs(content) ⇒ Object
9453 9454 9455 |
# File 'lib/kettle/jem.rb', line 9453 def gemfile_paragraphs(content) content.to_s.split(/\n{2,}/).map { |paragraph| ensure_trailing_newline(paragraph.strip) }.reject { |paragraph| paragraph.strip.empty? } end |
.gemfile_percent_w_names(content) ⇒ Object
9457 9458 9459 |
# File 'lib/kettle/jem.rb', line 9457 def gemfile_percent_w_names(content) ruby_word_array_records(content).flat_map { |record| record.fetch(:names) }.reject(&:empty?) end |
.gemfile_policy_operations(template_content, original, final, request) ⇒ Object
6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 |
# File 'lib/kettle/jem.rb', line 6895 def gemfile_policy_operations(template_content, original, final, request) package_name = runtime_context_value(request, :package, :name).to_s deleted = gemfile_dependency_names("#{template_content}\n#{original}") - gemfile_dependency_names(final) expected = GEMFILE_POLICY_SELF_DEPENDENCIES.dup expected << package_name unless package_name.empty? [ { operation: "delete_dependency_declarations", deleted_gems: (deleted & expected).sort } ] end |
.gemfile_workspace_override_node?(node) ⇒ Boolean
8862 8863 8864 8865 8866 8867 |
# File 'lib/kettle/jem.rb', line 8862 def gemfile_workspace_override_node?(node) return false unless gemfile_conditional_node?(node) return false if prism_subtree_contains_string?(node, "K_JEM_TEMPLATING") prism_subtree_contains_call?(node, :eval_nomono_gems) end |
.gemspec_assignment_field(call) ⇒ Object
12172 12173 12174 12175 12176 12177 12178 |
# File 'lib/kettle/jem.rb', line 12172 def gemspec_assignment_field(call) name = call.name.to_s return unless name.end_with?("=") return if name == "[]=" name.delete_suffix("=") end |
.gemspec_assignment_records(source, receiver: nil) ⇒ Object
12152 12153 12154 12155 12156 12157 12158 12159 12160 12161 12162 12163 12164 12165 12166 12167 12168 12169 12170 |
# File 'lib/kettle/jem.rb', line 12152 def gemspec_assignment_records(source, receiver: nil) lines = source.to_s.lines ruby_call_records(source, nil).filter_map do |call| field = gemspec_assignment_field(call) next unless field next if receiver && call.receiver&.slice != receiver.to_s end_line = ruby_node_source_end_line(call) { field: field, value: gemspec_assignment_value(call), value_node: call.arguments&.arguments&.first, receiver: call.receiver&.slice, start_line: call.location.start_line, end_line: end_line, source: (lines[(call.location.start_line - 1)..(end_line - 1)] || []).join } end end |
.gemspec_assignment_value(call) ⇒ Object
12180 12181 12182 12183 12184 12185 12186 12187 12188 12189 12190 |
# File 'lib/kettle/jem.rb', line 12180 def gemspec_assignment_value(call) argument = call.arguments&.arguments&.first case argument when ::Prism::StringNode, ::Prism::InterpolatedStringNode, ::Prism::CallNode ruby_static_string_value(argument) || argument&.slice when ::Prism::ArrayNode argument.elements.filter_map { |element| ruby_static_string_value(element) } else argument&.slice end end |
.gemspec_block_param(source) ⇒ Object
11077 11078 11079 11080 11081 |
# File 'lib/kettle/jem.rb', line 11077 def gemspec_block_param(source) call = gemspec_new_call(source) required = call&.block&.parameters&.parameters&.requireds&.first required&.name&.to_s end |
.gemspec_dependency_call_kind(call) ⇒ Object
12281 12282 12283 12284 12285 12286 |
# File 'lib/kettle/jem.rb', line 12281 def gemspec_dependency_call_kind(call) case call.name when :add_dependency, :add_runtime_dependency, :add_development_dependency call.name.to_s end end |
.gemspec_dependency_from_record(record) ⇒ Object
15305 15306 15307 |
# File 'lib/kettle/jem.rb', line 15305 def gemspec_dependency_from_record(record) Gem::Dependency.new(record.fetch(:name), *record.fetch(:requirements), (record.fetch(:kind) == "add_development_dependency") ? :development : :runtime) end |
.gemspec_dependency_line_index(source, receiver:) ⇒ Object
12089 12090 12091 12092 12093 12094 |
# File 'lib/kettle/jem.rb', line 12089 def gemspec_dependency_line_index(source, receiver:) gemspec_dependency_records(source, receiver: receiver).each_with_object({}) do |record, dependencies| key = gemspec_dependency_record_key(record) dependencies[key] ||= record.fetch(:source) end end |
.gemspec_dependency_line_key(line, receiver:) ⇒ Object
12121 12122 12123 12124 |
# File 'lib/kettle/jem.rb', line 12121 def gemspec_dependency_line_key(line, receiver:) record = gemspec_dependency_records(line, receiver: receiver).first gemspec_dependency_record_key(record) if record end |
.gemspec_dependency_minimum_requirement_replacement(call, requirement) ⇒ Object
11845 11846 11847 11848 11849 11850 11851 11852 11853 11854 11855 11856 11857 11858 11859 11860 11861 11862 11863 11864 11865 11866 11867 11868 11869 11870 11871 |
# File 'lib/kettle/jem.rb', line 11845 def gemspec_dependency_minimum_requirement_replacement(call, requirement) arguments = Array(call.arguments&.arguments) floor = Gem::Requirement.new(requirement).requirements.first.last existing_floor = arguments.drop(1).find do |argument| value = ruby_static_string_value(argument) next false unless value parsed = Gem::Requirement.new(value).requirements parsed.any? { |operator, version| %w[>= > =].include?(operator.to_s) && version < floor } rescue ArgumentError false end if existing_floor { start_offset: existing_floor.location.start_offset, end_offset: existing_floor.location.end_offset, replacement: JSON.generate(requirement) } else insertion_offset = arguments.last.location.end_offset { start_offset: insertion_offset, end_offset: insertion_offset, replacement: ", #{JSON.generate(requirement)}" } end end |
.gemspec_dependency_names(source) ⇒ Object
12096 12097 12098 |
# File 'lib/kettle/jem.rb', line 12096 def gemspec_dependency_names(source) gemspec_dependency_records(source).map { |record| record.fetch(:name) } end |
.gemspec_dependency_record_key(record) ⇒ Object
12126 12127 12128 |
# File 'lib/kettle/jem.rb', line 12126 def gemspec_dependency_record_key(record) [record.fetch(:kind), record.fetch(:name)] end |
.gemspec_dependency_record_version(record) ⇒ Object
12143 12144 12145 12146 12147 12148 12149 12150 |
# File 'lib/kettle/jem.rb', line 12143 def gemspec_dependency_record_version(record) versions = record.fetch(:requirements, []).filter_map do |requirement| Gem::Requirement.new(requirement.to_s).requirements.map(&:last) rescue ArgumentError nil end.flatten versions.max || Gem::Version.new("0") end |
.gemspec_dependency_records(source, receiver: nil) ⇒ Object
12258 12259 12260 12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271 12272 12273 12274 12275 12276 12277 12278 12279 |
# File 'lib/kettle/jem.rb', line 12258 def gemspec_dependency_records(source, receiver: nil) lines = source.to_s.lines ruby_call_records(source, nil).filter_map do |call| kind = gemspec_dependency_call_kind(call) next unless kind next if receiver && call.receiver&.slice != receiver.to_s name = ruby_string_argument(call) next unless name { kind: kind, name: name, requirement: ruby_string_argument_at(call, 1), requirements: ruby_string_arguments(call).drop(1), receiver: call.receiver&.slice, start_line: call.location.start_line, end_line: ruby_node_source_end_line(call), source: (lines[(call.location.start_line - 1)..(ruby_node_source_end_line(call) - 1)] || []).join } end end |
.gemspec_dependency_requirements_satisfy_floor?(requirements, floor_requirement) ⇒ Boolean
11833 11834 11835 11836 11837 11838 11839 11840 11841 11842 11843 |
# File 'lib/kettle/jem.rb', line 11833 def gemspec_dependency_requirements_satisfy_floor?(requirements, floor_requirement) floor = Gem::Requirement.new(floor_requirement).requirements.first.last requirements.any? do |requirement| parsed = Gem::Requirement.new(requirement.to_s).requirements parsed.any? do |operator, version| %w[>= > =].include?(operator.to_s) && version >= floor end rescue ArgumentError false end end |
.gemspec_dependency_section_heading_comment?(stripped_line) ⇒ Boolean
Prism does not expose comments as normal AST statements, so dependency-section headings are bounded to single-line comments after the gemspec development note.
11969 11970 11971 11972 11973 |
# File 'lib/kettle/jem.rb', line 11969 def gemspec_dependency_section_heading_comment?(stripped_line) stripped_line.start_with?("# ") && !stripped_line.start_with?("# NOTE:") && !stripped_line.start_with?("# ") end |
.gemspec_dependency_sort_key(name) ⇒ Object
11920 11921 11922 |
# File 'lib/kettle/jem.rb', line 11920 def gemspec_dependency_sort_key(name) name.to_s.tr("_", "-") end |
.gemspec_dependency_source_newer?(candidate_source, current_source, receiver:) ⇒ Boolean
12135 12136 12137 12138 12139 12140 12141 |
# File 'lib/kettle/jem.rb', line 12135 def gemspec_dependency_source_newer?(candidate_source, current_source, receiver:) candidate = gemspec_dependency_records(candidate_source, receiver: receiver).first current = gemspec_dependency_records(current_source, receiver: receiver).first return false unless candidate && current gemspec_dependency_record_version(candidate) > gemspec_dependency_record_version(current) end |
.gemspec_end_line(source) ⇒ Object
12292 12293 12294 |
# File 'lib/kettle/jem.rb', line 12292 def gemspec_end_line(source) gemspec_new_call(source)&.location&.end_line || source.to_s.lines.length + 1 end |
.gemspec_enumerate_package_glob_body(min_ruby) ⇒ Object
17333 17334 17335 17336 17337 17338 17339 17340 17341 17342 17343 17344 17345 17346 17347 17348 17349 17350 17351 17352 17353 |
# File 'lib/kettle/jem.rb', line 17333 def gemspec_enumerate_package_glob_body(min_ruby) if gemspec_modern_package_helper?(min_ruby) [ " Dir.glob(glob, File::FNM_DOTMATCH).filter_map do |path|", %( next unless File.file?(path) && ![".", ".."].include?(File.basename(path))), "", " relative_package_path.call(path)", " end" ].join("\n") else [ " files = []", " Dir.glob(glob, File::FNM_DOTMATCH).each do |path|", %( next unless File.file?(path) && ![".", ".."].include?(File.basename(path))), "", " files << relative_package_path.call(path)", " end", " files" ].join("\n") end end |
.gemspec_field_receiver_and_name(field) ⇒ Object
12212 12213 12214 12215 12216 12217 |
# File 'lib/kettle/jem.rb', line 12212 def gemspec_field_receiver_and_name(field) parts = field.to_s.split(".") return [nil, field.to_s] if parts.length == 1 [parts[0...-1].join("."), parts.last] end |
.gemspec_files_array_collection_source(target_parts, groups) ⇒ Object
11250 11251 11252 11253 11254 11255 11256 |
# File 'lib/kettle/jem.rb', line 11250 def gemspec_files_array_collection_source(target_parts, groups) [ target_parts.fetch(:opening), gemspec_files_collection_body_source(groups), target_parts.fetch(:closing) ].join end |
.gemspec_files_child_collection_record(record, value_node) ⇒ Object
11412 11413 11414 11415 11416 11417 11418 11419 11420 11421 11422 11423 11424 11425 11426 |
# File 'lib/kettle/jem.rb', line 11412 def gemspec_files_child_collection_record(record, value_node) source_start_line = record.fetch(:start_line) lines = record.fetch(:source).lines start_index = value_node.location.start_line - source_start_line end_index = value_node.location.end_line - source_start_line child_lines = lines[start_index..end_index] return unless child_lines record.merge( value_node: value_node, start_line: value_node.location.start_line, end_line: value_node.location.end_line, source: child_lines.join ) end |
.gemspec_files_collection_body_source(groups) ⇒ Object
11258 11259 11260 11261 11262 |
# File 'lib/kettle/jem.rb', line 11258 def gemspec_files_collection_body_source(groups) groups.each_with_index.map do |group, index| gemspec_files_collection_group_source(group, trailing_comma: index < groups.length - 1) end.join end |
.gemspec_files_collection_element_nodes(value_node) ⇒ Object
11435 11436 11437 11438 11439 11440 11441 11442 |
# File 'lib/kettle/jem.rb', line 11435 def gemspec_files_collection_element_nodes(value_node) if gemspec_files_dir_call_node?(value_node) return Array(value_node.arguments&.arguments) end return value_node.elements if value_node.is_a?(::Prism::ArrayNode) nil end |
.gemspec_files_collection_entry_key(node) ⇒ Object
11505 11506 11507 11508 11509 11510 |
# File 'lib/kettle/jem.rb', line 11505 def gemspec_files_collection_entry_key(node) return [:string, node.unescaped] if node.is_a?(::Prism::StringNode) return [:splat, gemspec_files_splat_expression_key(node.expression)] if node.is_a?(::Prism::SplatNode) [:source, node.slice] end |
.gemspec_files_collection_entry_node?(node) ⇒ Boolean
11500 11501 11502 11503 |
# File 'lib/kettle/jem.rb', line 11500 def gemspec_files_collection_entry_node?(node) node.location.start_line == node.location.end_line && (node.is_a?(::Prism::StringNode) || node.is_a?(::Prism::SplatNode)) end |
.gemspec_files_collection_group_source(group, trailing_comma:) ⇒ Object
11264 11265 11266 11267 11268 11269 11270 11271 11272 11273 11274 11275 11276 11277 |
# File 'lib/kettle/jem.rb', line 11264 def gemspec_files_collection_group_source(group, trailing_comma:) lines = group.fetch(:lines).dup return lines.join unless trailing_comma entry_index = lines.rindex { |line| !line.strip.empty? && !line.lstrip.start_with?("#") } return lines.join unless entry_index line = lines.fetch(entry_index) return lines.join if line.rstrip.end_with?(",") newline = line.end_with?("\n") ? "\n" : "" lines[entry_index] = "#{line.delete_suffix("\n").rstrip},#{newline}" lines.join end |
.gemspec_files_collection_groups(record:, element_nodes:, lines:) ⇒ Object
11463 11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 11477 11478 11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493 11494 11495 11496 11497 11498 |
# File 'lib/kettle/jem.rb', line 11463 def gemspec_files_collection_groups(record:, element_nodes:, lines:) pending = [] groups = [] body_lines = lines[1...-1] nodes = element_nodes.dup body_lines.each_with_index do |line, body_index| current_entry = nodes.first if current_entry && current_entry.location.start_line == record.fetch(:start_line) + body_index + 1 unless gemspec_files_collection_entry_node?(current_entry) groups = nil break end groups << { key: gemspec_files_collection_entry_key(current_entry), node: current_entry, lines: pending + [line] } pending = [] nodes.shift next end if line.strip.empty? || line.lstrip.start_with?("#") pending << line next end end return unless groups return if nodes.any? groups end |
.gemspec_files_collection_has_nonliteral_entries?(parts) ⇒ Boolean
11636 11637 11638 11639 11640 11641 |
# File 'lib/kettle/jem.rb', line 11636 def gemspec_files_collection_has_nonliteral_entries?(parts) parts.fetch(:groups).any? do |group| node = group.fetch(:node) !node.is_a?(::Prism::StringNode) end end |
.gemspec_files_collection_has_package_metadata_splat?(parts) ⇒ Boolean
11627 11628 11629 11630 11631 11632 11633 11634 |
# File 'lib/kettle/jem.rb', line 11627 def (parts) parts.fetch(:groups).any? do |group| key = group.fetch(:key) key.is_a?(Array) && key.first == :splat && (key[1] == "package_metadata_files" || key[1] == [:call, nil, :package_metadata_files, []]) end end |
.gemspec_files_collection_kind(value_node) ⇒ Object
11428 11429 11430 11431 11432 11433 |
# File 'lib/kettle/jem.rb', line 11428 def gemspec_files_collection_kind(value_node) return :dir if gemspec_files_dir_call_node?(value_node) return :array if value_node.is_a?(::Prism::ArrayNode) nil end |
.gemspec_files_collection_needs_concat?(target_parts, groups) ⇒ Boolean
11218 11219 11220 11221 11222 11223 11224 |
# File 'lib/kettle/jem.rb', line 11218 def gemspec_files_collection_needs_concat?(target_parts, groups) target_parts.fetch(:collection_kind) == :array && groups.any? do |group| group.fetch(:source_collection_kind) == :dir && group.fetch(:node).is_a?(::Prism::StringNode) end end |
.gemspec_files_collection_parts(record) ⇒ Object
11352 11353 11354 11355 11356 11357 11358 11359 |
# File 'lib/kettle/jem.rb', line 11352 def gemspec_files_collection_parts(record) value_node = record.fetch(:value_node) if gemspec_files_concat_call_node?(value_node) return gemspec_files_concat_collection_parts(record, value_node) end gemspec_files_single_collection_parts(record, value_node) end |
.gemspec_files_concat_call_node?(node) ⇒ Boolean
11448 11449 11450 11451 11452 11453 11454 |
# File 'lib/kettle/jem.rb', line 11448 def gemspec_files_concat_call_node?(node) node.is_a?(::Prism::CallNode) && node.name == :+ && node.block.nil? && node.receiver && Array(node.arguments&.arguments).length == 1 end |
.gemspec_files_concat_collection_parts(record, value_node) ⇒ Object
11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 |
# File 'lib/kettle/jem.rb', line 11379 def gemspec_files_concat_collection_parts(record, value_node) arguments = Array(value_node.arguments&.arguments) left_record = gemspec_files_child_collection_record(record, value_node.receiver) right_record = gemspec_files_child_collection_record(record, arguments.first) return unless left_record && right_record left_parts = gemspec_files_single_collection_parts( left_record, value_node.receiver ) right_parts = gemspec_files_single_collection_parts( right_record, arguments.first ) return unless left_parts && right_parts groups = left_parts.fetch(:groups).map do |group| group.merge(source_collection_kind: left_parts.fetch(:collection_kind)) end groups.concat( right_parts.fetch(:groups).map do |group| group.merge(source_collection_kind: right_parts.fetch(:collection_kind)) end ) { collection_kind: :concat, opening: left_parts.fetch(:opening), closing: right_parts.fetch(:closing), groups: groups } end |
.gemspec_files_concat_collection_source(target_parts, groups) ⇒ Object
11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 |
# File 'lib/kettle/jem.rb', line 11226 def gemspec_files_concat_collection_source(target_parts, groups) dir_groups, array_groups = groups.partition do |group| group.fetch(:source_collection_kind) == :dir && group.fetch(:node).is_a?(::Prism::StringNode) end return gemspec_files_array_collection_source(target_parts, array_groups) if dir_groups.empty? return gemspec_files_dir_collection_source(target_parts, dir_groups) if array_groups.empty? [ gemspec_files_dir_collection_source(target_parts, dir_groups, closing: "] + [\n"), gemspec_files_collection_body_source(array_groups), target_parts.fetch(:closing) ].join end |
.gemspec_files_dir_call_node?(node) ⇒ Boolean
11456 11457 11458 11459 11460 11461 |
# File 'lib/kettle/jem.rb', line 11456 def gemspec_files_dir_call_node?(node) node.is_a?(::Prism::CallNode) && node.name == :[] && node.block.nil? && node.receiver&.slice == "Dir" end |
.gemspec_files_dir_collection_source(target_parts, groups, closing: nil) ⇒ Object
11241 11242 11243 11244 11245 11246 11247 11248 |
# File 'lib/kettle/jem.rb', line 11241 def gemspec_files_dir_collection_source(target_parts, groups, closing: nil) opening = target_parts.fetch(:opening).sub("= [", "= Dir[") [ opening, gemspec_files_collection_body_source(groups), closing || target_parts.fetch(:closing) ].join end |
.gemspec_files_group_collection_kind(group, parts) ⇒ Object
11444 11445 11446 |
# File 'lib/kettle/jem.rb', line 11444 def gemspec_files_group_collection_kind(group, parts) group.fetch(:source_collection_kind, parts.fetch(:collection_kind)) end |
.gemspec_files_normalize_dir_globs_for_array(groups, target_parts) ⇒ Object
11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 11349 11350 |
# File 'lib/kettle/jem.rb', line 11330 def gemspec_files_normalize_dir_globs_for_array(groups, target_parts) return groups unless target_parts.fetch(:collection_kind) == :array groups.map do |group| next group unless group.fetch(:source_collection_kind, nil) == :dir node = group.fetch(:node) next group unless node.is_a?(::Prism::StringNode) pattern = node.unescaped.to_s lines = group.fetch(:lines) entry_line = lines.reverse.find { |line| !line.strip.empty? && !line.lstrip.start_with?("#") }.to_s indent = entry_line[/\A\s*/].to_s comments = lines.take_while { |line| line.strip.empty? || line.lstrip.start_with?("#") } group.merge( key: [:package_glob, pattern], source_collection_kind: :array, lines: comments + [%(#{indent}*enumerate_package_glob.call(File.join(gemspec_root, #{pattern.dump}))\n)] ) end end |
.gemspec_files_single_collection_parts(record, value_node) ⇒ Object
11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 |
# File 'lib/kettle/jem.rb', line 11361 def gemspec_files_single_collection_parts(record, value_node) element_nodes = gemspec_files_collection_element_nodes(value_node) return unless element_nodes lines = record.fetch(:source).lines return if lines.length < 3 groups = gemspec_files_collection_groups(record: record, element_nodes: element_nodes, lines: lines) return unless groups { collection_kind: gemspec_files_collection_kind(value_node), opening: lines.first, closing: lines.last, groups: groups } end |
.gemspec_files_splat_expression_key(node) ⇒ Object
11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 |
# File 'lib/kettle/jem.rb', line 11512 def gemspec_files_splat_expression_key(node) if node.is_a?(::Prism::CallNode) return [ :call, node.receiver&.slice, node.name, Array(node.arguments&.arguments).map { |argument| ruby_static_string_value(argument) || argument.slice } ] end node&.slice end |
.gemspec_freeze_block_structurally_managed?(block, receiver:) ⇒ Boolean
11763 11764 11765 11766 11767 |
# File 'lib/kettle/jem.rb', line 11763 def gemspec_freeze_block_structurally_managed?(block, receiver:) gemspec_assignment_records(block.join, receiver: receiver).any? { |record| record.fetch(:field) == "files" } rescue Ast::Crispr::Error, Prism::ParseError false end |
.gemspec_legacy_version_loader_block(entrypoint_require:, namespace:, min_ruby:, superclass_sensitive: false, fallback_version: nil) ⇒ Object
10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 |
# File 'lib/kettle/jem.rb', line 10706 def gemspec_legacy_version_loader_block(entrypoint_require:, namespace:, min_ruby:, superclass_sensitive: false, fallback_version: nil) unless superclass_sensitive return gemspec_standard_legacy_version_loader_block( entrypoint_require: entrypoint_require, namespace: namespace, min_ruby: min_ruby ) end anonymous_loader = <<~RUBY.chomp require "anonymous_loader" path = File.expand_path("lib/#{entrypoint_require}/version.rb", __dir__) anonymous_namespace = AnonymousLoader.load(files: path) anonymous_namespace::#{namespace}::Version::VERSION RUBY anonymous_loader_lines = anonymous_loader.lines.map { |line| " #{line.chomp}" } fallback = fallback_version.to_s fallback = "0.0.0" if fallback.empty? lines = [ "gem_version =", " if Gem.ruby_version >= Gem::Version.new(\"3.1\")", " # Loading Version into an anonymous module allows version.rb to get code coverage from SimpleCov!", " # See: https://github.com/simplecov-ruby/simplecov/issues/557#issuecomment-2630782358", " # See: https://github.com/panorama-ed/memo_wise/pull/397", " #{gemspec_modern_version_loader_expression(entrypoint_require: entrypoint_require, namespace: namespace)}" ] lines << " # The namesake namespace has a superclass. Directly requiring version.rb" lines << " # on legacy Ruby could define that namespace with the wrong superclass." if min_ruby < ANONYMOUS_VERSION_LOADER_MIN_RUBY lines << " elsif Gem.ruby_version >= Gem::Version.new(\"2.2\")" lines.concat(anonymous_loader_lines) lines << " else" lines << " #{fallback.dump}" else lines << " else" lines.concat(anonymous_loader_lines) end lines << " end" "#{lines.join("\n")}\n" end |
.gemspec_legacy_version_loader_preamble_line_range(content) ⇒ Object
10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 |
# File 'lib/kettle/jem.rb', line 10795 def gemspec_legacy_version_loader_preamble_line_range(content) lines = content.to_s.lines start_index = lines.index do |line| # Prism has represented this legacy multiline assignment inconsistently across # parser versions; this fallback is limited to the exact top-level preamble # shape immediately preceding Gem::Specification.new. line.match?(/\Agem_version\s*=/) end return unless start_index gemspec_index = lines.each_with_index.find do |line, index| index > start_index && line.include?("Gem::Specification.new") end&.last return unless gemspec_index end_line = gemspec_index end_line -= 1 while end_line > start_index && lines[end_line - 1].strip.empty? {start_line: start_index + 1, end_line: end_line} end |
.gemspec_metadata_assignment_records(content, receiver:) ⇒ Object
10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 |
# File 'lib/kettle/jem.rb', line 10942 def (content, receiver:) lines = content.to_s.lines ruby_call_records(content, :[]=).filter_map do |call| next unless call.receiver&.slice.to_s == "#{receiver}.metadata" args = call.arguments&.arguments.to_a key = ruby_static_string_value(args.first) next if key.to_s.empty? start_line = call.location.start_line end_line = ruby_node_source_end_line(call) { key: key, value: ruby_static_string_value(args[1]), start_line: start_line, end_line: end_line, source: lines[(start_line - 1)..(end_line - 1)].to_a.join } end rescue Ast::Crispr::Error [] end |
.gemspec_modern_package_helper?(min_ruby) ⇒ Boolean
17355 17356 17357 17358 17359 17360 17361 17362 |
# File 'lib/kettle/jem.rb', line 17355 def gemspec_modern_package_helper?(min_ruby) token = minimum_ruby_token(min_ruby) return false if token.to_s.empty? || token == "0" Gem::Version.new(token) >= Gem::Version.new("2.7") rescue ArgumentError false end |
.gemspec_modern_version_loader_expression(entrypoint_require:, namespace:) ⇒ Object
10702 10703 10704 |
# File 'lib/kettle/jem.rb', line 10702 def gemspec_modern_version_loader_expression(entrypoint_require:, namespace:) %(Module.new.tap { |mod| Kernel.load("\#{__dir__}/lib/#{entrypoint_require}/version.rb", mod) }::#{namespace}::Version::VERSION) end |
.gemspec_new_call(source) ⇒ Object
12288 12289 12290 |
# File 'lib/kettle/jem.rb', line 12288 def gemspec_new_call(source) ruby_call_records(source, :new).find { |call| call.receiver&.slice == "Gem::Specification" } end |
.gemspec_package_file_includes_token(gemspec) ⇒ Object
17364 17365 17366 17367 17368 17369 17370 17371 17372 17373 17374 17375 17376 17377 17378 17379 17380 17381 |
# File 'lib/kettle/jem.rb', line 17364 def gemspec_package_file_includes_token(gemspec) includes = Array(gemspec[:package_file_includes] || gemspec["package_file_includes"]) .map { |path| path.to_s.strip } .reject(&:empty?) .uniq return "" if includes.empty? lines = [ "", " # Extra package files configured by .structuredmerge/kettle-jem.yml" ] includes.each_with_index do |pattern, index| comma = (index < includes.length - 1) ? "," : "" glob = %(File.join(gemspec_root, #{pattern.dump})) lines << %( *enumerate_package_glob.call(#{glob})#{comma}) end ",#{lines.join("\n")}" end |
.gemspec_package_helper_assignment_records(content) ⇒ Object
10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 |
# File 'lib/kettle/jem.rb', line 10621 def gemspec_package_helper_assignment_records(content) result = prism_parse_success(content) return [] unless result lines = content.to_s.lines helper_names = %w[ gemspec_root relative_package_path enumerate_package_glob enumerate_package_files package_metadata_files ].to_set result.value.breadth_first_search_all do |node| node.is_a?(::Prism::LocalVariableWriteNode) && helper_names.include?(node.name.to_s) end.map do |node| end_line = ruby_node_source_end_line(node) { name: node.name.to_s, start_line: node.location.start_line, end_line: end_line, source: lines[(node.location.start_line - 1)..(end_line - 1)].join } end end |
.gemspec_path_declares_gem?(path, gem_name) ⇒ Boolean
5472 5473 5474 5475 |
# File 'lib/kettle/jem.rb', line 5472 def gemspec_path_declares_gem?(path, gem_name) normalized_path = path.to_s.delete_suffix("/") normalized_path == "gems/#{gem_name}" end |
.gemspec_policy_operations(template_content, original, final, request) ⇒ Object
6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 |
# File 'lib/kettle/jem.rb', line 6930 def gemspec_policy_operations(template_content, original, final, request) template_receiver = gemspec_block_param(template_content) || "spec" destination_receiver = gemspec_block_param(original) || "spec" package_name = runtime_context_value(request, :package, :name).to_s self_dependency_names = gemspec_self_dependency_names(request, package_name) operations = [ { operation: "preserve_project_fields", preserved_fields: gemspec_preserved_assignments(original, receiver: destination_receiver).keys.select do |field| final.include?("#{template_receiver}.#{field} =") end.sort }, { operation: "preserve_dependency_declarations", preserved_dependencies: gemspec_dependency_line_index(original, receiver: destination_receiver).keys.map(&:last).select do |gem_name| final.include?(%("#{gem_name}")) end.sort }, { operation: "delete_self_dependency_declarations", deleted_dependency_count: [ gemspec_dependency_names("#{template_content}\n#{original}").count { |name| self_dependency_names.include?(name) } - gemspec_dependency_names(final).count { |name| self_dependency_names.include?(name) }, 0 ].max } ] version_loader_operation = gemspec_version_loader_policy_operation(original, final, request) operations << version_loader_operation if version_loader_operation if template_receiver != destination_receiver operations << { operation: "normalize_gemspec_receiver", from: destination_receiver, to: template_receiver } end operations end |
.gemspec_preserved_assignment_fields ⇒ Object
11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 |
# File 'lib/kettle/jem.rb', line 11117 def gemspec_preserved_assignment_fields %w[ name authors email summary description homepage licenses required_ruby_version executables ] end |
.gemspec_preserved_assignments(source, receiver:) ⇒ Object
11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 |
# File 'lib/kettle/jem.rb', line 11106 def gemspec_preserved_assignments(source, receiver:) gemspec_assignment_records(source, receiver: receiver).each_with_object({}) do |record, assignments| field = record.fetch(:field) next unless gemspec_preserved_assignment_fields.include?(field) next if assignments.key?(field) next if record.fetch(:source).include?("TODO:") assignments[field] = record.fetch(:source) end end |
.gemspec_project_emoji(gemspec_metadata) ⇒ Object
13151 13152 13153 13154 13155 13156 13157 13158 13159 13160 |
# File 'lib/kettle/jem.rb', line 13151 def gemspec_project_emoji() [ (, :summary), (, :description) ].each do |value| candidate = first_grapheme(value) return candidate if decorative_grapheme?(candidate) end nil end |
.gemspec_relative_package_path_body(min_ruby) ⇒ Object
17322 17323 17324 17325 17326 17327 17328 17329 17330 17331 |
# File 'lib/kettle/jem.rb', line 17322 def gemspec_relative_package_path_body(min_ruby) if gemspec_modern_package_helper?(min_ruby) %( path.delete_prefix("\#{gemspec_root}/")) else [ %( prefix = "\#{gemspec_root}/"), " path[0, prefix.length] == prefix ? path[prefix.length..-1] : path" ].join("\n") end end |
.gemspec_root_license_files_token(_license) ⇒ Object
17500 17501 17502 |
# File 'lib/kettle/jem.rb', line 17500 def gemspec_root_license_files_token(_license) " \"LICENSE.md\",\n" end |
.gemspec_root_reference_node?(node) ⇒ Boolean
11561 11562 11563 11564 11565 11566 11567 11568 11569 |
# File 'lib/kettle/jem.rb', line 11561 def gemspec_root_reference_node?(node) return node.name == :gemspec_root if node.is_a?(::Prism::LocalVariableReadNode) node.is_a?(::Prism::CallNode) && node.receiver.nil? && node.name == :gemspec_root && Array(node.arguments&.arguments).empty? && node.block.nil? end |
.gemspec_runtime_dependency_names(gemspec_metadata) ⇒ Object
15149 15150 15151 15152 15153 15154 15155 15156 15157 15158 15159 |
# File 'lib/kettle/jem.rb', line 15149 def gemspec_runtime_dependency_names() dependencies = Array( [:runtime_dependencies] || ["runtime_dependencies"] ) dependencies.each_with_object([]) do |dependency, names| name = dependency.respond_to?(:name) ? dependency.name.to_s : dependency.to_s next if name.empty? || names.include?(name) names << name end end |
.gemspec_runtime_floor_token(facts) ⇒ Object
11041 11042 11043 11044 11045 11046 11047 |
# File 'lib/kettle/jem.rb', line 11041 def gemspec_runtime_floor_token(facts) raw = facts.to_h.dig(:rubygems, :min_ruby).to_s.strip token = minimum_ruby_token(raw) return "0" if token.empty? && raw == "0" token end |
.gemspec_self_dependency_names(request, package_name) ⇒ Object
12100 12101 12102 12103 12104 12105 |
# File 'lib/kettle/jem.rb', line 12100 def gemspec_self_dependency_names(request, package_name) names = [package_name.to_s] token_value = runtime_context_value(request, :template_tokens, "KJ|GEM_NAME") names << "{KJ|GEM_NAME}" if token_value.to_s == package_name.to_s names.reject(&:empty?).uniq end |
.gemspec_standard_legacy_version_loader_block(entrypoint_require:, namespace:, min_ruby:) ⇒ Object
10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 |
# File 'lib/kettle/jem.rb', line 10747 def gemspec_standard_legacy_version_loader_block(entrypoint_require:, namespace:, min_ruby:) legacy_require = if min_ruby >= REQUIRE_RELATIVE_MIN_RUBY %(require_relative "lib/#{entrypoint_require}/version") else <<~RUBY.chomp # NOTE: Use __FILE__ or __dir__ until removal of Ruby 1.x support # __dir__ introduced in Ruby 1.9.1 lib = File.expand_path("lib", File.dirname(__FILE__)) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "#{entrypoint_require}/version" RUBY end <<~RUBY gem_version = if Gem.ruby_version >= Gem::Version.new("3.1") # Loading Version into an anonymous module allows version.rb to get code coverage from SimpleCov! # See: https://github.com/simplecov-ruby/simplecov/issues/557#issuecomment-2630782358 # See: https://github.com/panorama-ed/memo_wise/pull/397 #{gemspec_modern_version_loader_expression(entrypoint_require: entrypoint_require, namespace: namespace)} else #{legacy_require.gsub("\n", "\n ")} #{namespace}::Version::VERSION end RUBY end |
.gemspec_template_facts(config) ⇒ Object
17306 17307 17308 17309 17310 17311 17312 |
# File 'lib/kettle/jem.rb', line 17306 def gemspec_template_facts(config) includes = Array(config.dig("gemspec", "package_files", "include")) .map { |path| path.to_s.strip } .reject(&:empty?) .uniq includes.empty? ? {} : {package_file_includes: includes} end |
.gemspec_template_tokens(gemspec, min_ruby: nil) ⇒ Object
17314 17315 17316 17317 17318 17319 17320 |
# File 'lib/kettle/jem.rb', line 17314 def gemspec_template_tokens(gemspec, min_ruby: nil) { "KJ|GEMSPEC:ENUMERATE_PACKAGE_GLOB_BODY" => gemspec_enumerate_package_glob_body(min_ruby), "KJ|GEMSPEC:PACKAGE_FILE_INCLUDES" => gemspec_package_file_includes_token(gemspec), "KJ|GEMSPEC:RELATIVE_PACKAGE_PATH_BODY" => gemspec_relative_package_path_body(min_ruby) } end |
.gemspec_top_level_gem_version_node(content) ⇒ Object
10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 |
# File 'lib/kettle/jem.rb', line 10826 def gemspec_top_level_gem_version_node(content) ensure_runtime_dependencies! context = Ast::Crispr::Ruby::Prism.document_context(content: content.to_s, source_label: "gemspec") gemspec_call = context.structural_owners(owner_scope: :top_level_statements).find do |owner| owner.is_a?(::Prism::CallNode) && owner.name == :new && owner.receiver&.slice == "Gem::Specification" end context.structural_owners(owner_scope: :top_level_statements).find do |owner| owner.is_a?(::Prism::LocalVariableWriteNode) && owner.name == :gem_version && (!gemspec_call || owner.location.start_offset < gemspec_call.location.start_offset) end end |
.gemspec_version_loader_policy_operation(original, final, request) ⇒ Object
6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 |
# File 'lib/kettle/jem.rb', line 6969 def gemspec_version_loader_policy_operation(original, final, request) min_ruby = minimum_ruby_token(runtime_context_value(request, :rubygems, :min_ruby)) return if min_ruby.to_s.empty? modern = Gem::Version.new(min_ruby) >= MODERN_GEMSPEC_VERSION_LOADER_MIN_RUBY before_legacy = !gemspec_top_level_gem_version_node(original).nil? after_legacy = !gemspec_top_level_gem_version_node(final).nil? superclass_sensitive = gemspec_version_loader_superclass_sensitive?(request[:runtime_context] || request["runtime_context"] || {}) { operation: "rewrite_version_loader", min_ruby: min_ruby, mode: modern ? "modern" : "legacy", superclass_sensitive: superclass_sensitive, legacy_preamble_removed: before_legacy && !after_legacy, legacy_preamble_present: after_legacy } rescue ArgumentError, Ast::Crispr::Error nil end |
.gemspec_version_loader_superclass_sensitive?(facts) ⇒ Boolean
10775 10776 10777 10778 10779 10780 10781 |
# File 'lib/kettle/jem.rb', line 10775 def gemspec_version_loader_superclass_sensitive?(facts) rubygems = facts.to_h[:rubygems] return false unless rubygems.is_a?(Hash) value = rubygems[:entrypoint_namespace_superclasses] value.is_a?(Hash) && !value.empty? end |
.generated_blocks_facts(gemspec, facts, run_options) ⇒ Object
3785 3786 3787 3788 3789 3790 |
# File 'lib/kettle/jem.rb', line 3785 def generated_blocks_facts(gemspec, facts, ) return {} if shim_template_profile?(facts) shunted = shunted_gemfile_block(gemspec, facts, ) shunted ? {shunted_gemfile: shunted} : {} end |
.generated_gemspec_metadata_file_group?(group, target_parts) ⇒ Boolean
11618 11619 11620 11621 11622 11623 11624 11625 |
# File 'lib/kettle/jem.rb', line 11618 def (group, target_parts) return false unless (target_parts) node = group.fetch(:node) return false unless node.is_a?(::Prism::StringNode) %w[CHANGELOG.md LICENSE.md README.md].include?(node.unescaped.to_s) end |
.generated_gemspec_package_glob_call?(node) ⇒ Boolean
11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 |
# File 'lib/kettle/jem.rb', line 11547 def generated_gemspec_package_glob_call?(node) arguments = Array(node.arguments&.arguments) return false unless arguments.length == 1 join = arguments.first return false unless join.is_a?(::Prism::CallNode) && join.receiver&.slice == "File" && join.name == :join join_arguments = Array(join.arguments&.arguments) root = join_arguments.shift gemspec_root_reference_node?(root) && join_arguments.any? && join_arguments.all? { |argument| argument.is_a?(::Prism::StringNode) } end |
.generated_kettle_config_without_templates?(config) ⇒ Boolean
18335 18336 18337 18338 18339 |
# File 'lib/kettle/jem.rb', line 18335 def generated_kettle_config_without_templates?(config) return false unless config.is_a?(Hash) config["tokens"].is_a?(Hash) end |
.generated_or_obsolete_github_workflow?(relative_path) ⇒ Boolean
13589 13590 13591 13592 13593 13594 13595 |
# File 'lib/kettle/jem.rb', line 13589 def generated_or_obsolete_github_workflow?(relative_path) return true if preferred_template_source(PACKAGED_TEMPLATE_ROOT, relative_path) return true if stale_versioned_engine_workflow?(relative_path) return true if relative_path == ".github/workflows/opencollective.yml" OBSOLETE_GITHUB_WORKFLOWS.include?(File.basename(relative_path)) end |
.generated_version_tree_source_url?(source_url, version) ⇒ Boolean
15333 15334 15335 15336 15337 15338 15339 15340 15341 |
# File 'lib/kettle/jem.rb', line 15333 def generated_version_tree_source_url?(source_url, version) return false unless present_template_token_value?(source_url) && present_template_token_value?(version) uri = URI.parse(source_url.to_s) segments = uri.path.to_s.split("/").reject(&:empty?) uri.host == "github.com" && segments[2] == "tree" && segments[3] == "v#{version}" rescue URI::InvalidURIError false end |
.generic_bundler_gemspec_files_assignment?(record) ⇒ Boolean
11643 11644 11645 11646 |
# File 'lib/kettle/jem.rb', line 11643 def generic_bundler_gemspec_files_assignment?(record) node = record.fetch(:value_node) io_popen_gemspec_files_assignment?(node) || legacy_git_ls_files_assignment?(node) end |
.generic_bundler_gemspec_files_command?(node) ⇒ Boolean
11680 11681 11682 11683 |
# File 'lib/kettle/jem.rb', line 11680 def generic_bundler_gemspec_files_command?(node) node.is_a?(::Prism::ArrayNode) && node.elements.map { |element| ruby_static_string_value(element) } == %w[git ls-files -z] end |
.git_capture(project_root, *args) ⇒ Object
14853 14854 14855 14856 14857 14858 |
# File 'lib/kettle/jem.rb', line 14853 def git_capture(project_root, *args) output, status = Open3.capture2("git", "-C", project_root.to_s, *args, err: File::NULL) raise ArgumentError, "git #{args.join(" ")} failed" unless status.success? output.to_s end |
.git_copyright_lines(project_root, machine_users, author_aliases: {}) ⇒ Object
14820 14821 14822 14823 14824 14825 14826 14827 14828 14829 14830 14831 14832 14833 14834 14835 14836 14837 14838 14839 14840 14841 14842 14843 14844 14845 14846 14847 14848 14849 14850 14851 |
# File 'lib/kettle/jem.rb', line 14820 def git_copyright_lines(project_root, machine_users, author_aliases: {}) files = git_capture(project_root, "ls-files", "-z") return [] if files.to_s.empty? = Hash.new { |hash, email| hash[email] = {name: nil, years: [], email: email} } files.split("\0").reject(&:empty?).each do |relative_path| next unless File.exist?(File.join(project_root, relative_path)) parse_blame_porcelain(git_capture(project_root, "blame", "--porcelain", "--", relative_path), ) rescue ArgumentError next end (project_root, ) consolidated = .values .reject { |entry| copyright_bot_entry?(entry) } .reject { |entry| copyright_machine_user_entry?(entry, machine_users, author_aliases: ) } .each_with_object({}) do |entry, | next if entry[:name].to_s.strip.empty? || entry[:years].empty? name = (entry, ) next if name.empty? = [name.downcase] ||= {name: name, years: []} [:years].concat(entry[:years]) end .values consolidated .sort_by { |entry| [entry[:years].map(&:to_i).min, entry[:name].to_s.downcase] } .map { |entry| "Copyright (c) #{format_copyright_years(entry[:years])} #{entry[:name]}" } rescue ArgumentError [] end |
.git_hooks_executable_step(project_root) ⇒ Object
5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 |
# File 'lib/kettle/jem.rb', line 5113 def git_hooks_executable_step(project_root) existing_paths = EXECUTABLE_GIT_HOOK_PATHS.select do |relative_path| File.file?(File.join(project_root.to_s, relative_path)) end return {name: "git_hooks_executable", status: "missing", changed_files: []} if existing_paths.empty? changed_files = existing_paths.filter_map do |relative_path| path = File.join(project_root.to_s, relative_path) before = File.stat(path).mode after = before | 0o111 next if before == after FileUtils.chmod(after, path) relative_path end { name: "git_hooks_executable", status: changed_files.empty? ? "already_executable" : "updated", changed_files: changed_files } end |
.git_operation_lock_path(env) ⇒ Object
13668 13669 13670 13671 13672 13673 13674 |
# File 'lib/kettle/jem.rb', line 13668 def git_operation_lock_path(env) %w[KETTLE_JEM_GIT_LOCK KETTLE_JEM_GIT_COMMIT_LOCK].each do |key| value = env.to_h[key].to_s.strip return value unless value.empty? end "" end |
.git_output(project_root, *args) ⇒ Object
13650 13651 13652 13653 |
# File 'lib/kettle/jem.rb', line 13650 def git_output(project_root, *args) stdout, _stderr, status = Open3.capture3("git", "-C", project_root.to_s, *args) status.success? ? stdout : "" end |
.git_preflight_report(project_root, template_selection:, env: ENV) ⇒ Object
13624 13625 13626 13627 13628 13629 13630 13631 13632 13633 13634 13635 13636 |
# File 'lib/kettle/jem.rb', line 13624 def git_preflight_report(project_root, template_selection:, env: ENV) with_git_operation_lock(env) do inside = git_success?(project_root, "rev-parse", "--is-inside-work-tree") status = inside ? git_output(project_root, "status", "--porcelain") : nil dirty_entries = status.to_s.lines.map(&:chomp).reject(&:empty?) { git_repository: inside, clean_worktree: inside && dirty_entries.empty?, dirty_entries: dirty_entries, skip_commit: template_selection.fetch(:skip_commit, false) } end end |
.git_remote_source_url(project_root) ⇒ Object
16792 16793 16794 16795 16796 |
# File 'lib/kettle/jem.rb', line 16792 def git_remote_source_url(project_root) normalize_git_source_url(git_capture(project_root, "config", "--get", "remote.origin.url").strip) rescue ArgumentError nil end |
.git_success?(project_root, *args) ⇒ Boolean
13645 13646 13647 13648 |
# File 'lib/kettle/jem.rb', line 13645 def git_success?(project_root, *args) _stdout, _stderr, status = Open3.capture3("git", "-C", project_root.to_s, *args) status.success? end |
.git_version_file_value(project_root, relative_path) ⇒ Object
16341 16342 16343 16344 16345 16346 16347 16348 16349 16350 16351 |
# File 'lib/kettle/jem.rb', line 16341 def git_version_file_value(project_root, relative_path) [ git_output(project_root, "show", ":#{relative_path}"), git_output(project_root, "show", "HEAD:#{relative_path}") ].each do |content| version = ruby_version_constant_value(content) return version.to_s if valid_gem_version?(version) end "" end |
.git_worktree_prefix(project_root) ⇒ Object
16764 16765 16766 16767 16768 |
# File 'lib/kettle/jem.rb', line 16764 def git_worktree_prefix(project_root) git_capture(project_root, "rev-parse", "--show-prefix").strip rescue ArgumentError "" end |
.git_worktree_root(project_root) ⇒ Object
16757 16758 16759 16760 16761 16762 |
# File 'lib/kettle/jem.rb', line 16757 def git_worktree_root(project_root) root = git_capture(project_root, "rev-parse", "--show-toplevel").strip root.empty? ? project_root.to_s : root rescue ArgumentError project_root.to_s end |
.github_actions_coverage_config(config, env = ENV) ⇒ Object
19103 19104 19105 19106 19107 19108 19109 19110 19111 19112 19113 19114 19115 19116 19117 |
# File 'lib/kettle/jem.rb', line 19103 def github_actions_coverage_config(config, env = ENV) workflows = config["workflows"] return {} unless workflows.is_a?(Hash) raw = workflows["coverage"] enabled = raw == true || (raw.is_a?(Hash) && raw.fetch("enabled", false) == true) return {} unless enabled raw = {} unless raw.is_a?(Hash) { enabled: true, command: raw.fetch("command", github_actions_exec_cmd(config, env)).to_s, appraisal: raw.fetch("appraisal", "coverage").to_s } end |
.github_actions_coverage_enabled?(content) ⇒ Boolean
19769 19770 19771 19772 19773 |
# File 'lib/kettle/jem.rb', line 19769 def github_actions_coverage_enabled?(content) yaml_contains_key_value?(YAML.safe_load(content.to_s, aliases: true), "K_SOUP_COV_DO", "true") rescue Psych::Exception false end |
.github_actions_coverage_steps(disabled_integrations: []) ⇒ Object
19811 19812 19813 19814 19815 19816 19817 19818 19819 19820 19821 19822 19823 19824 19825 19826 19827 19828 19829 19830 19831 19832 19833 19834 19835 19836 19837 19838 19839 19840 19841 19842 19843 19844 19845 19846 19847 19848 19849 19850 19851 19852 19853 19854 19855 19856 19857 19858 19859 19860 19861 19862 19863 19864 19865 19866 19867 19868 19869 19870 19871 19872 19873 19874 19875 19876 19877 19878 19879 19880 19881 19882 |
# File 'lib/kettle/jem.rb', line 19811 def github_actions_coverage_steps(disabled_integrations: []) disabled = Array(disabled_integrations).map { |name| normalize_integration_name(name) }.to_set steps = [] unless disabled.include?("coveralls") steps << <<~YAML - name: Upload coverage to Coveralls if: ${{ !env.ACT }} uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8 with: github-token: ${{ secrets.GITHUB_TOKEN }} file: coverage/lcov.info format: lcov fail-on-error: false continue-on-error: true YAML end unless disabled.include?("qlty") steps << <<~YAML - name: Upload coverage to QLTY if: ${{ !env.ACT }} uses: qltysh/qlty-action/coverage@08a0a862c159eae9b9003081da6663d96efef637 # v2.3.0 with: oidc: true files: coverage/lcov.info format: lcov skip-errors: true continue-on-error: true YAML end unless disabled.include?("codecov") steps << <<~YAML - name: Upload coverage to CodeCov if: ${{ !env.ACT }} uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 with: use_oidc: true disable_search: true fail_ci_if_error: false files: coverage/lcov.info,coverage/coverage.xml verbose: true continue-on-error: true YAML end steps << <<~YAML - name: Code Coverage Summary Report if: ${{ !env.ACT && github.event_name == 'pull_request' }} uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0 with: filename: ./coverage/coverage.xml badge: true fail_below_min: true format: markdown hide_branch_rate: false hide_complexity: true indicators: true output: both thresholds: '${{ env.K_SOUP_COV_MIN_LINE }} ${{ env.K_SOUP_COV_MIN_BRANCH }}' continue-on-error: ${{ matrix.experimental || endsWith(matrix.ruby, 'head') }} - name: Add Coverage PR Comment uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5 if: ${{ !env.ACT && github.event_name == 'pull_request' }} with: recreate: true path: code-coverage-results.md continue-on-error: ${{ matrix.experimental || endsWith(matrix.ruby, 'head') }} YAML steps.join("\n").lines.map { |line| line.strip.empty? ? line : " #{line}" }.join.chomp end |
.github_actions_custom_workflows(project_root, config = {}, opencollective_disabled: false) ⇒ Object
13538 13539 13540 13541 13542 13543 13544 13545 13546 13547 13548 13549 13550 13551 |
# File 'lib/kettle/jem.rb', line 13538 def github_actions_custom_workflows(project_root, config = {}, opencollective_disabled: false) workflow_root = File.join(project_root, ".github", "workflows") return [] unless Dir.exist?(workflow_root) Dir.glob(File.join(workflow_root, "*.{yml,yaml}")).filter_map do |path| relative_path = path.delete_prefix("#{project_root}/") next if opencollective_disabled && opencollective_disabled_file?(relative_path) next if inactive_packaged_workflow?(relative_path, config) next if generated_or_obsolete_github_workflow?(relative_path) && !skip_packaged_workflow_template?(relative_path, config) relative_path end.sort end |
.github_actions_engine_exec_cmds(config) ⇒ Object
A generated workflow normally uses one command for every matrix entry. Legacy engines occasionally need a narrower command while retaining the rest of the generated workflow (setup, retries, cache keys, and pins).
19131 19132 19133 19134 19135 19136 19137 19138 19139 19140 19141 19142 19143 |
# File 'lib/kettle/jem.rb', line 19131 def github_actions_engine_exec_cmds(config) workflows = config["workflows"] return {} unless workflows.is_a?(Hash) raw = workflows["engine_exec_cmds"] return {} unless raw.is_a?(Hash) raw.each_with_object({}) do |(engine, command), overrides| engine_name = engine.to_s.strip command_text = command.to_s.strip overrides[engine_name] = command_text unless engine_name.empty? || command_text.empty? end end |
.github_actions_exec_cmd(config, env) ⇒ Object
19119 19120 19121 19122 19123 19124 19125 19126 |
# File 'lib/kettle/jem.rb', line 19119 def github_actions_exec_cmd(config, env) workflows = config["workflows"] workflows = {} unless workflows.is_a?(Hash) normalize_github_actions_exec_cmd( preferred_template_token_value("kettle-test", workflows["exec_cmd"], env, "KJ_EXEC_CMD").to_s ) end |
.github_actions_framework_matrix(config) ⇒ Object
18889 18890 18891 18892 18893 18894 18895 18896 18897 18898 18899 18900 18901 18902 18903 18904 18905 18906 18907 18908 18909 18910 18911 18912 18913 18914 18915 18916 18917 18918 18919 18920 18921 18922 18923 18924 18925 18926 18927 18928 18929 18930 18931 18932 18933 18934 18935 18936 18937 18938 18939 18940 18941 18942 18943 18944 18945 18946 18947 18948 18949 18950 18951 |
# File 'lib/kettle/jem.rb', line 18889 def github_actions_framework_matrix(config) workflows = config["workflows"] return {} unless workflows.is_a?(Hash) && workflows["preset"].to_s.strip.downcase == "framework" raw = workflows["framework_matrix"] return {} unless raw.is_a?(Hash) dimension = raw["dimension"].to_s.strip versions = raw["versions"] pattern = raw["gemfile_pattern"].to_s.strip return {} unless !dimension.empty? && versions.is_a?(Array) && !versions.empty? && !pattern.empty? framework_gem = raw.fetch("gem", dimension).to_s.strip return {} if framework_gem.empty? version_entries = versions.filter_map { |version| framework_matrix_version_entry(version) } return {} if version_entries.empty? appraisal_gemfiles = framework_matrix_appraisal_gemfiles(raw) gemfiles = version_entries.map do |entry| gemfile = (pattern, entry.fetch(:slug)) gemfile_entry = { path: framework_gemfile_path(gemfile), gem: framework_gem, requirement: entry.fetch(:requirement), env: entry.fetch(:env, {}) } gemfile_entry[:default] = true if entry[:default] gemfile_entry[:replaces] = entry[:replaces] unless entry.fetch(:replaces, []).empty? gemfile_entry end.uniq { |entry| entry.fetch(:path) } default_gemfiles = gemfiles.select { |entry| entry[:default] } gemfiles.reject! { |entry| template_keep_destination_path?(config, entry.fetch(:path)) } { dimension: dimension, gem: framework_gem, workflow: framework_matrix_workflow_enabled?(raw), versions: version_entries.map { |entry| entry.fetch(:label) }, gemfile_pattern: pattern, include: version_entries.map do |entry| { framework_version: entry.fetch(:label), appraisal: entry[:appraisal_name] || framework_matrix_appraisal_name(dimension, entry.fetch(:slug)) } end, gemfiles: gemfiles, appraisals: version_entries.map do |entry| gemfile = framework_gemfile_path((pattern, entry.fetch(:slug))) name = entry[:appraisal_name] || framework_matrix_appraisal_name(dimension, entry.fetch(:slug)) { name: name, framework_version: entry.fetch(:label), gem: framework_gem, env: entry.fetch(:env, {}), standard_appraisal: entry.fetch(:standard_appraisal, false), eval_gemfiles: [framework_matrix_appraisal_gemfile_path(gemfile), *appraisal_gemfiles].uniq, replaces: framework_matrix_replaced_appraisal_names(dimension, entry, name) } end }.tap do |matrix| matrix[:default_gemfiles] = default_gemfiles unless default_gemfiles.empty? end end |
.github_actions_obsolete_workflows(project_root) ⇒ Object
13572 13573 13574 13575 13576 13577 13578 13579 |
# File 'lib/kettle/jem.rb', line 13572 def github_actions_obsolete_workflows(project_root) workflow_root = File.join(project_root, ".github", "workflows") OBSOLETE_GITHUB_WORKFLOWS.filter_map do |workflow| relative_path = ".github/workflows/#{workflow}" path = File.join(workflow_root, workflow) relative_path if File.exist?(path) end.sort end |
.github_actions_pin_sync_step(project_root) ⇒ Object
5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 |
# File 'lib/kettle/jem.rb', line 5135 def github_actions_pin_sync_step(project_root) workflow_root = File.join(project_root.to_s, ".github", "workflows") return unless File.directory?(workflow_root) changed_files = Dir[File.join(workflow_root, "*.{yml,yaml}")].sort.filter_map do |path| before = File.read(path) after = update_github_actions_pins(before) next if after == before File.write(path, after) path.delete_prefix("#{project_root}/") end { name: "github_actions_pin_sync", status: changed_files.empty? ? "already_current" : "applied", changed_files: changed_files } end |
.github_actions_push_branches(content, default_branch:) ⇒ Object
19744 19745 19746 19747 19748 |
# File 'lib/kettle/jem.rb', line 19744 def github_actions_push_branches(content, default_branch:) managed = [default_branch.to_s, "*-stable"] existing = yaml_scalar_sequence_at_path(content, %w[on push branches]) (managed + existing).uniq end |
.github_actions_push_branches_yaml(content, default_branch:, indent: " ") ⇒ Object
19738 19739 19740 19741 19742 |
# File 'lib/kettle/jem.rb', line 19738 def github_actions_push_branches_yaml(content, default_branch:, indent: " ") github_actions_push_branches(content, default_branch: default_branch).map do |branch| "#{indent}- #{branch.inspect}" end.join("\n") end |
.github_actions_rspec_status_cache_step(cache_scope:, key_parts:, indent:, if_condition: "${{!env.ACT}}") ⇒ Object
19591 19592 19593 19594 19595 19596 19597 19598 19599 19600 19601 19602 19603 19604 19605 |
# File 'lib/kettle/jem.rb', line 19591 def github_actions_rspec_status_cache_step(cache_scope:, key_parts:, indent:, if_condition: "${{!env.ACT}}") cache_prefix = ["rspec-status", cache_scope, *key_parts].join("-") yaml = <<~YAML - name: Restore RSpec status log if: #{if_condition} uses: #{github_actions_step_pins.fetch("actions/cache")} with: path: .rspec_status key: #{cache_prefix}-${{hashFiles('**/Gemfile.lock','Appraisal.root.gemfile','gemfiles/**/*.gemfile')}}-${{github.run_id}}-${{github.run_attempt}} restore-keys: | #{cache_prefix}-${{hashFiles('**/Gemfile.lock','Appraisal.root.gemfile','gemfiles/**/*.gemfile')}}- #{cache_prefix}- YAML yaml.lines.map { |line| line.strip.empty? ? line : "#{indent}#{line}" }.join.rstrip end |
.github_actions_ruby_versions(min_ruby) ⇒ Object
13531 13532 13533 13534 13535 13536 |
# File 'lib/kettle/jem.rb', line 13531 def github_actions_ruby_versions(min_ruby) floor = min_ruby.to_s[/\d+\.\d+/] || "3.1" candidates = %w[3.1 3.2 3.3 3.4] selected = candidates.select { |version| Gem::Version.new(version) >= Gem::Version.new(floor) } selected.empty? ? [floor] : selected end |
.github_actions_setup_ruby_steps(indent:) ⇒ Object
19571 19572 19573 19574 19575 19576 19577 19578 19579 19580 19581 19582 19583 19584 19585 19586 19587 19588 19589 |
# File 'lib/kettle/jem.rb', line 19571 def github_actions_setup_ruby_steps(indent:) yaml = <<~YAML - name: Setup Ruby & RubyGems uses: appraisal-rb/setup-ruby-flash@925395edf973d2dc0a629919f407f3547a03d4b5 # v2.1 with: ruby-version: "${{ matrix.ruby }}" rubygems: "${{ matrix.rubygems }}" bundler: "${{ matrix.bundler }}" bundler-cache: ${{ matrix.ruby != 'ruby-2.4' && matrix.ruby != 'ruby-2.5' && matrix.ruby != 'ruby-2.6' && matrix.ruby != 'ruby-2.7' && matrix.ruby != 'truffleruby-25.0' && matrix.ruby != 'jruby-9.2' && matrix.ruby != 'jruby-9.3' && matrix.ruby != 'jruby-9.4' }} - name: Bundle install for legacy Ruby engine if: ${{ matrix.ruby == 'ruby-2.4' || matrix.ruby == 'ruby-2.5' || matrix.ruby == 'ruby-2.6' || matrix.ruby == 'ruby-2.7' || matrix.ruby == 'truffleruby-25.0' || matrix.ruby == 'jruby-9.2' || matrix.ruby == 'jruby-9.3' || matrix.ruby == 'jruby-9.4' }} run: | bundle config set --local path "${RUNNER_TEMP}/bundle" bundle config set --local mirror.https://gem.coop https://rubygems.org bundle install --jobs 1 YAML yaml.lines.map { |line| line.strip.empty? ? line : "#{indent}#{line}" }.join.rstrip end |
.github_actions_standard_appraisal_gemfiles(config) ⇒ Object
19172 19173 19174 19175 19176 19177 19178 19179 19180 19181 19182 19183 19184 19185 19186 19187 |
# File 'lib/kettle/jem.rb', line 19172 def github_actions_standard_appraisal_gemfiles(config) workflows = config["workflows"] workflows = {} unless workflows.is_a?(Hash) appraisal_matrix = config["appraisal_matrix"] appraisal_matrix = {} unless appraisal_matrix.is_a?(Hash) raw_paths = workflows["standard_appraisal_gemfiles"] || appraisal_matrix["appraisal_gemfiles"] || appraisal_matrix["appraisal_eval_gemfiles"] Array(raw_paths).filter_map do |path| normalized = path.to_s.strip.sub(%r{\Agemfiles/}, "") normalized unless normalized.empty? end.uniq end |
.github_actions_step_pins ⇒ Object
20122 20123 20124 20125 20126 20127 20128 20129 20130 20131 20132 20133 20134 20135 20136 20137 20138 20139 20140 20141 20142 20143 |
# File 'lib/kettle/jem.rb', line 20122 def github_actions_step_pins { "actions/checkout" => "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1", "actions/cache" => "actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0", "appraisal-rb/setup-ruby-flash" => "appraisal-rb/setup-ruby-flash@925395edf973d2dc0a629919f407f3547a03d4b5 # v2.1", "ruby/setup-ruby" => "ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0", "coverallsapp/github-action" => "coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8", "qltysh/qlty-action/coverage" => "qltysh/qlty-action/coverage@08a0a862c159eae9b9003081da6663d96efef637 # v2.3.0", "codecov/codecov-action" => "codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0", "irongut/CodeCoverageSummary" => "irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0", "marocchino/sticky-pull-request-comment" => "marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5", "actions/upload-artifact" => "actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1", "amancevice/setup-code-climate" => "amancevice/setup-code-climate@0daf2985a225e8ac15975b4d233010e94d65b76a # v2", "actions/dependency-review-action" => "actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0", "github/codeql-action/init" => "github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9", "github/codeql-action/autobuild" => "github/codeql-action/autobuild@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9", "github/codeql-action/analyze" => "github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9", "pozil/auto-assign-issue" => "pozil/auto-assign-issue@af6beea6bdf1e8eb373f061c5bc168681fc6d011 # v4.0.1", "apache/skywalking-eyes/dependency" => "apache/skywalking-eyes/dependency@a196742f472feaffafea537ce5a2a4c3c53a8de4 # v0.9.0", "sarisia/actions-status-discord" => "sarisia/actions-status-discord@eb045afee445dc055c18d3d90bd0f244fd062708 # v1.16.0" } end |
.github_funding_platform_urls(platform, values) ⇒ Object
13505 13506 13507 13508 13509 13510 13511 13512 13513 13514 13515 13516 13517 13518 13519 13520 13521 13522 13523 13524 13525 13526 13527 13528 13529 |
# File 'lib/kettle/jem.rb', line 13505 def github_funding_platform_urls(platform, values) values.filter_map do |value| handle = value.to_s.strip.delete_prefix("@") next if handle.empty? case platform when "buy_me_a_coffee" "https://www.buymeacoffee.com/#{handle}" when "custom" handle if http_url?(handle) when "github" "https://github.com/sponsors/#{handle}" when "ko_fi" "https://ko-fi.com/#{handle}" when "liberapay" "https://liberapay.com/#{handle}/donate" when "open_collective" "https://opencollective.com/#{handle}" when "thanks_dev" "https://thanks.dev/#{handle}" when "tidelift" "https://tidelift.com/funding/github/#{handle}" end end end |
.github_funding_urls(path, opencollective_disabled: false, enabled_platforms: nil) ⇒ Object
13492 13493 13494 13495 13496 13497 13498 13499 13500 13501 13502 13503 |
# File 'lib/kettle/jem.rb', line 13492 def github_funding_urls(path, opencollective_disabled: false, enabled_platforms: nil) funding = YAML.safe_load_file(path, permitted_classes: [], aliases: false) || {} return [] unless funding.is_a?(Hash) funding.flat_map do |platform, value| normalized_platform = platform.to_s next [] if opencollective_disabled && normalized_platform == "open_collective" next [] unless funding_platform_enabled?(enabled_platforms, normalized_platform) github_funding_platform_urls(normalized_platform, Array(value).compact) end end |
.github_org_from_url(url) ⇒ Object
16615 16616 16617 16618 |
# File 'lib/kettle/jem.rb', line 16615 def github_org_from_url(url) match = url.to_s.match(%r{\Ahttps?://github\.com/([^/]+)/}) match && match[1] end |
.github_repository_slug(url) ⇒ Object
16819 16820 16821 16822 16823 16824 16825 16826 16827 16828 |
# File 'lib/kettle/jem.rb', line 16819 def github_repository_slug(url) normalized = normalize_git_source_url(url) match = normalized.to_s.match(%r{\Ahttps?://github\.com/([^/]+)/([^/?#]+)}) return unless match repository = match[2].delete_suffix(".git") return if match[1].empty? || repository.empty? "#{match[1]}/#{repository}" end |
.github_repository_star_count(project_root, repository_slug) ⇒ Object
16830 16831 16832 16833 16834 16835 16836 16837 16838 16839 16840 16841 16842 16843 16844 |
# File 'lib/kettle/jem.rb', line 16830 def github_repository_star_count(project_root, repository_slug) stdout, _stderr, status = Open3.capture3( "gh", "api", "repos/#{repository_slug}", "--jq", ".stargazers_count", chdir: project_root.to_s ) return unless status.success? Integer(stdout.to_s.strip) rescue ArgumentError, IOError, SystemCallError nil end |
.github_workflow_action_pin_key(record) ⇒ Object
20012 20013 20014 |
# File 'lib/kettle/jem.rb', line 20012 def github_workflow_action_pin_key(record) [record.fetch(:action), record.fetch(:version)] end |
.github_workflow_action_pin_line_record(line, line_index) ⇒ Object
20016 20017 20018 20019 20020 20021 20022 20023 20024 20025 20026 20027 20028 20029 20030 20031 20032 20033 20034 |
# File 'lib/kettle/jem.rb', line 20016 def github_workflow_action_pin_line_record(line, line_index) # Psych intentionally drops comments, but the managed pin contract uses # the trailing comment as the human version label paired with the SHA. match = line.to_s.match( %r{ \A\s*(?:-\s*)?uses:\s* (?<action>[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)*) @(?<sha>[a-f0-9]{40})\s+\#\s*(?<version>v?[^#\s]+) }x ) return unless match { action: match[:action], sha: match[:sha], version: match[:version], line_index: line_index } end |
.github_workflow_action_pin_records(content) ⇒ Object
20000 20001 20002 20003 20004 20005 20006 20007 20008 20009 20010 |
# File 'lib/kettle/jem.rb', line 20000 def github_workflow_action_pin_records(content) lines = content.to_s.lines yaml_scalar_pairs(content).filter_map do |key_node, value_node| next unless key_node.value.to_s == "uses" next unless value_node.value.to_s.include?("@") github_workflow_action_pin_line_record(lines[key_node.start_line], key_node.start_line) end rescue Psych::Exception [] end |
.github_workflow_engine_exec_cmds_for_template(source_path, overrides) ⇒ Object
4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 |
# File 'lib/kettle/jem.rb', line 4202 def github_workflow_engine_exec_cmds_for_template(source_path, overrides) return {} unless source_path && File.file?(source_path) configured = stringify_keys_for_json(overrides) return {} if configured.empty? yaml_mapping_nodes(File.read(source_path)).each_with_object({}) do |mapping, matching| engine = yaml_mapping_scalar_value(mapping, "ruby") matching[engine] = configured[engine] if configured.key?(engine) end rescue Psych::Exception {} end |
.github_workflow_template_pin_warnings(recipe_reports) ⇒ Object
19983 19984 19985 19986 19987 19988 19989 19990 19991 19992 19993 19994 19995 19996 19997 19998 |
# File 'lib/kettle/jem.rb', line 19983 def github_workflow_template_pin_warnings(recipe_reports) records = recipe_reports.flat_map do |report| Array(report.dig(:metadata, :stale_github_workflow_template_pins)) end return [] if records.empty? grouped = records.group_by { |record| record.fetch(:path) } grouped.map do |path, path_records| actions = path_records.map { |record| "#{record.fetch(:action)} #{record.fetch(:version)}" }.uniq.sort.join(", ") [ "GitHub Actions template pins appear stale for #{path}:", "preserved existing project pin(s) for #{actions}.", "Update kettle-jem's workflow template pins." ].join(" ") end end |
.github_workflow_template_recipe?(recipe) ⇒ Boolean
9267 9268 9269 |
# File 'lib/kettle/jem.rb', line 9267 def github_workflow_template_recipe?(recipe) recipe.fetch(:target_path).to_s.start_with?(".github/workflows/") end |
.github_workflows_include?(project_root, needle) ⇒ Boolean
17996 17997 17998 17999 18000 18001 18002 |
# File 'lib/kettle/jem.rb', line 17996 def github_workflows_include?(project_root, needle) Dir.glob(File.join(project_root, ".github/workflows/*.{yml,yaml}")).any? do |path| File.read(path).include?(needle) rescue Errno::ENOENT false end end |
.gitlab_repo_url(repository, repo_slug, suffix) ⇒ Object
16770 16771 16772 16773 16774 16775 16776 16777 16778 16779 16780 |
# File 'lib/kettle/jem.rb', line 16770 def gitlab_repo_url(repository, repo_slug, suffix) resources = repository[:resource_urls] || {} return resources[:gitlab_issues_url] if suffix == "issues" && resources[:gitlab_issues_url] return resources[:gitlab_pulls_url] if suffix == "merge_requests" && resources[:gitlab_pulls_url] return resources[:gitlab_wiki_url] if suffix == "wikis/home" && resources[:gitlab_wiki_url] return resources[:gitlab_contributors_url] if suffix == "graphs/main" && resources[:gitlab_contributors_url] base = repository[:gitlab_url].to_s base = "https://gitlab.com/#{repo_slug}" if base.empty? "#{base}/-/#{suffix}" end |
.guard_main_gemfile_runtime_workspace_overrides(content) ⇒ Object
8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 |
# File 'lib/kettle/jem.rb', line 8184 def guard_main_gemfile_runtime_workspace_overrides(content) content = collapse_nested_templating_guards(content) content = normalize_templating_guard_indentation(content) records = runtime_workspace_override_records(content) return content if records.empty? output = content.to_s records.sort_by { |record| -record.fetch(:start_line) }.each do |record| source = output.lines[(record.fetch(:start_line) - 1)..(record.fetch(:end_line) - 1)].join guarded = [ %(unless ENV.fetch("K_JEM_TEMPLATING", "false").casecmp("true").zero?), indent_source(source, 2).rstrip, "end", "" ].join("\n") output = replace_source_range_lines(output, record.fetch(:start_line), record.fetch(:end_line), guarded) end output end |
.guarded_debug_require ⇒ Object
8544 8545 8546 |
# File 'lib/kettle/jem.rb', line 8544 def guarded_debug_require 'require "debug" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7") && ENV["CI"].nil? && ENV.fetch("DEBUG", "false").casecmp("true").zero?' end |
.html_attribute_escape(value) ⇒ Object
17250 17251 17252 |
# File 'lib/kettle/jem.rb', line 17250 def html_attribute_escape(value) value.to_s.gsub("&", "&").gsub("\"", """).gsub("<", "<").gsub(">", ">") end |
.http_url?(value) ⇒ Boolean
19789 19790 19791 19792 19793 19794 |
# File 'lib/kettle/jem.rb', line 19789 def http_url?(value) uri = URI.parse(value.to_s) %w[http https].include?(uri.scheme) rescue URI::InvalidURIError false end |
.inactive_packaged_template_cleanup_files(project_root, config = {}) ⇒ Object
18431 18432 18433 18434 18435 18436 18437 18438 18439 |
# File 'lib/kettle/jem.rb', line 18431 def inactive_packaged_template_cleanup_files(project_root, config = {}) gemfile_cleanups = Dir.glob(File.join(project_root, "gemfiles/**/*.gemfile")).filter_map do |path| relative_path = path.delete_prefix("#{project_root}/") next unless preferred_template_source(PACKAGED_TEMPLATE_ROOT, relative_path) {target_path: relative_path} if skip_packaged_gemfile_template?(relative_path, config, project_root: project_root) end (gemfile_cleanups + disabled_integration_config_cleanups(project_root, config)).sort_by { |cleanup| cleanup.fetch(:target_path) } end |
.inactive_packaged_workflow?(relative_path, config = {}, include_patterns: nil) ⇒ Boolean
13565 13566 13567 13568 13569 13570 |
# File 'lib/kettle/jem.rb', line 13565 def inactive_packaged_workflow?(relative_path, config = {}, include_patterns: nil) return true if stale_versioned_engine_workflow?(relative_path) preferred_template_source(PACKAGED_TEMPLATE_ROOT, relative_path) && skip_packaged_workflow_template?(relative_path, config, include_patterns: include_patterns) end |
.inactive_packaged_workflow_cleanup_files(project_root, config = {}, include_patterns: nil) ⇒ Object
13553 13554 13555 13556 13557 13558 13559 13560 13561 13562 13563 |
# File 'lib/kettle/jem.rb', line 13553 def inactive_packaged_workflow_cleanup_files(project_root, config = {}, include_patterns: nil) workflow_root = File.join(project_root, ".github", "workflows") return [] unless Dir.exist?(workflow_root) Dir.glob(File.join(workflow_root, "*.{yml,yaml}")).filter_map do |path| relative_path = path.delete_prefix("#{project_root}/") next if OPT_IN_GITHUB_WORKFLOWS.include?(relative_path) relative_path if inactive_packaged_workflow?(relative_path, config, include_patterns: include_patterns) end.sort end |
.indent_source(source, spaces) ⇒ Object
8893 8894 8895 8896 |
# File 'lib/kettle/jem.rb', line 8893 def indent_source(source, spaces) prefix = " " * spaces source.to_s.lines.map { |line| line.strip.empty? ? line : "#{prefix}#{line}" }.join end |
.inject_appraisal_gemfiles(block, gemfiles) ⇒ Object
10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 |
# File 'lib/kettle/jem.rb', line 10230 def inject_appraisal_gemfiles(block, gemfiles) lines = block.to_s.lines existing_paths = ruby_call_records(block, :eval_gemfile).filter_map { |call| ruby_string_argument(call) }.to_set additions = gemfiles.filter_map do |gemfile| path = gemfile.to_s.delete_prefix("gemfiles/") line = %( eval_gemfile "#{path}") + "\n" line unless existing_paths.include?(path) end return block if additions.empty? insert_line = appraisal_x_stdlib_eval_gemfile_call(block)&.location&.start_line || ruby_call_records(block, :appraise).first&.location&.end_line insert_index = insert_line ? insert_line - 1 : nil return block unless insert_index lines.insert(insert_index, *additions) ensure_trailing_newline(lines.join.gsub(/\n{3,}/, "\n\n")) end |
.inject_framework_matrix_workflow_env(content, facts) ⇒ Object
9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 |
# File 'lib/kettle/jem.rb', line 9123 def inject_framework_matrix_workflow_env(content, facts) env_by_appraisal = framework_matrix_appraisal_env_by_name(facts) return content if env_by_appraisal.empty? lines = content.to_s.lines inserted_keys = Set.new inserted_locations = Set.new yaml_mapping_nodes(content).sort_by { |mapping| -mapping.start_line }.each do |mapping| appraisal = yaml_mapping_scalar_value(mapping, "appraisal") matrix_env = env_by_appraisal[appraisal] next unless matrix_env insert_index = workflow_matrix_env_insert_index(lines, mapping) next unless insert_index indent = workflow_matrix_env_indent(lines, mapping) additions = matrix_env.reject { |key, _value| yaml_mapping_scalar_node(mapping, key) } additions.reject! { |key, _value| inserted_locations.include?([insert_index, key.to_s]) } next if additions.empty? additions.each_key { |key| inserted_keys << key } additions.each_key { |key| inserted_locations << [insert_index, key.to_s] } lines.insert(insert_index, *additions.map { |key, value| %(#{indent}#{key}: #{yaml_double_quoted_scalar(value)}\n) }) end return content if inserted_keys.empty? add_framework_matrix_job_env(lines.join, inserted_keys) rescue content end |
.inject_main_gemfile_default_test_bundle(content, facts) ⇒ Object
The root Gemfile is the local-development bundle. Appraisals and CI use their own Gemfiles, so a project that needs a framework or application harness locally must declare that dependency separately in test_bundle.
9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 |
# File 'lib/kettle/jem.rb', line 9385 def inject_main_gemfile_default_test_bundle(content, facts) bundle = facts.to_h.dig(:ci, :default_test_bundle).to_h return content if bundle.empty? managed_gems = bundle.fetch(:managed_gems, []) output = remove_gemfile_dependency_blocks(content, managed_gems) existing_paths = gemfile_eval_paths(output).to_set additions = bundle.fetch(:gemfiles, []).filter_map do |path| next if existing_paths.include?(path) %(eval_gemfile "#{path}") end additions.concat(bundle.fetch(:gems, []).map { |gem| default_test_bundle_gem_source(gem) }) return output if additions.empty? lines = output.to_s.lines insert_at = main_gemfile_default_test_bundle_insertion_index(output) || lines.length block = ["# Default local test bundle", *additions].join("\n") lines.insert(insert_at, "#{block}\n\n") ensure_trailing_newline(lines.join.gsub(/\n{3,}/, "\n\n")) end |
.inject_main_gemfile_recording_eval(content, facts) ⇒ Object
9372 9373 9374 9375 9376 9377 9378 9379 9380 |
# File 'lib/kettle/jem.rb', line 9372 def inject_main_gemfile_recording_eval(content, facts) return content unless facts.to_h.dig(:ci, :recording) return content if gemfile_eval_paths(content).any? { |path| path.to_s.include?("gemfiles/modular/recording/") } lines = content.to_s.lines insert_at = main_gemfile_recording_insertion_index(content) || lines.length lines.insert(insert_at, "# Test HTTP Interaction Recording\n", %(eval_gemfile "#{main_gemfile_recording_eval_path}"\n), "\n") ensure_trailing_newline(lines.join.gsub(/\n{3,}/, "\n\n")) end |
.inject_standard_appraisal_gemfiles(content, facts) ⇒ Object
10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 |
# File 'lib/kettle/jem.rb', line 10181 def inject_standard_appraisal_gemfiles(content, facts) gemfiles = facts.to_h.dig(:ci, :standard_appraisal_gemfiles).to_a return content if gemfiles.empty? standard_names = standard_test_appraisal_names(content) return content if standard_names.empty? matrix_dependency_gemfiles = framework_matrix_appraisal_dependency_gemfiles(facts) parsed = appraisal_blocks(content) blocks = parsed.fetch(:order).map do |name| block = parsed.fetch(:blocks).fetch(name) if standard_names.include?(name) && !appraisal_block_has_matrix_dependency_gemfile?(block, matrix_dependency_gemfiles) inject_appraisal_gemfiles(block, gemfiles) else block end end ensure_trailing_newline(([parsed.fetch(:prelude).to_s.rstrip] + blocks.map(&:rstrip)).reject(&:empty?).join("\n\n")) end |
.insert_after_line_sequence(content, sequence, insertion, error_message) ⇒ Object
13104 13105 13106 13107 13108 13109 13110 13111 13112 13113 13114 13115 13116 |
# File 'lib/kettle/jem.rb', line 13104 def insert_after_line_sequence(content, sequence, insertion, ) lines = content.to_s.lines(chomp: true) index = (0..(lines.length - sequence.length)).find do |candidate| lines[candidate, sequence.length] == sequence end return content if !index && .nil? raise Error, unless index insertion_lines = insertion.to_s.lines(chomp: true) updated = lines.dup updated.insert(index + sequence.length, *insertion_lines) "#{updated.join("\n")}\n" end |
.insert_changelog_transfer_entries_in_release(lines, heading, entries) ⇒ Object
6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 |
# File 'lib/kettle/jem.rb', line 6596 def insert_changelog_transfer_entries_in_release(lines, heading, entries) heading_index = lines.index { |line| line.to_s == heading.to_s } heading_index = changelog_unreleased_line_index(lines) if heading_index.nil? return lines if heading_index.nil? release_end = changelog_unreleased_end_index(lines, heading_index) release_body = lines[(heading_index + 1)...release_end] || [] release_preamble = changelog_section_preamble(release_body) items = changelog_unreleased_items(release_body) entries.group_by { |entry| entry.fetch(:section, "### Changed") }.each do |section, section_entries| section = CHANGELOG_STANDARD_HEADINGS.include?(section) ? section : "### Changed" items[section] ||= [] items[section].pop while items[section].any? && items[section].last.to_s.strip.empty? items[section] << "" if items[section].any? section_entries.each do |entry| items[section].concat(Array(entry.fetch(:lines)).map(&:rstrip)) end end lines[0...heading_index] + build_changelog_section(lines.fetch(heading_index), release_preamble, items) + lines[release_end..].to_a end |
.insert_gemfile_dependency_blocks(content, blocks) ⇒ Object
9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 |
# File 'lib/kettle/jem.rb', line 9461 def insert_gemfile_dependency_blocks(content, blocks) lines = content.to_s.lines insert_at = gemfile_dependency_insertion_line(content) while insert_at.positive? && lines[insert_at - 1].strip.empty? insert_at -= 1 end insertion = blocks.map { |block| block.strip }.join("\n\n") lines.insert(insert_at, "#{insertion}\n\n") ensure_trailing_newline(lines.join.gsub(/\n{3,}/, "\n\n")) end |
.insert_lines_after(content, line_number, insertion) ⇒ Object
12247 12248 12249 12250 12251 |
# File 'lib/kettle/jem.rb', line 12247 def insert_lines_after(content, line_number, insertion) lines = content.to_s.lines lines.insert(line_number, insertion) lines.join end |
.insert_lines_before(content, line_number, insertion) ⇒ Object
12241 12242 12243 12244 12245 |
# File 'lib/kettle/jem.rb', line 12241 def insert_lines_before(content, line_number, insertion) lines = content.to_s.lines lines.insert([line_number - 1, 0].max, insertion) lines.join end |
.insert_missing_development_gemspec_dependency_lines(content, missing_lines) ⇒ Object
12071 12072 12073 12074 12075 |
# File 'lib/kettle/jem.rb', line 12071 def insert_missing_development_gemspec_dependency_lines(content, missing_lines) return content if missing_lines.empty? insert_lines_before(content, gemspec_end_line(content), missing_lines.join) end |
.insert_missing_gemspec_assignment_sources(content, replacements, receiver:) ⇒ Object
11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 |
# File 'lib/kettle/jem.rb', line 11704 def insert_missing_gemspec_assignment_sources(content, replacements, receiver:) return content if replacements.empty? present_fields = gemspec_assignment_records(content, receiver: receiver).map { |record| record.fetch(:field) }.to_set missing_sources = gemspec_preserved_assignment_fields.filter_map do |field| next if present_fields.include?(field) source = replacements[field] "#{source}\n" if source end return content if missing_sources.empty? first_dependency_line = gemspec_dependency_records(content, receiver: receiver).map { |record| record.fetch(:start_line) }.min insert_lines_before(content, first_dependency_line || gemspec_end_line(content), missing_sources.join) end |
.insert_missing_gemspec_files_assignment(content, template_content:, template_receiver:) ⇒ Object
11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 |
# File 'lib/kettle/jem.rb', line 11154 def insert_missing_gemspec_files_assignment(content, template_content:, template_receiver:) return content if gemspec_assignment_records(content, receiver: template_receiver).any? { |record| record.fetch(:field) == "files" } template_record = gemspec_assignment_records(template_content, receiver: template_receiver).find { |record| record.fetch(:field) == "files" } return content unless template_record insertion = "#{normalize_gemspec_receiver(template_record.fetch(:source).rstrip, from: template_receiver, to: template_receiver)}\n" extra_rdoc = gemspec_assignment_records(content, receiver: template_receiver).find { |record| record.fetch(:field) == "extra_rdoc_files" } return insert_lines_before(content, extra_rdoc.fetch(:start_line), "\n#{insertion}") if extra_rdoc anchor = %w[required_ruby_version licenses homepage description summary name].filter_map do |field| gemspec_assignment_records(content, receiver: template_receiver).find { |record| record.fetch(:field) == field } end.first return insert_lines_after(content, anchor.fetch(:end_line), "\n#{insertion}") if anchor content end |
.insert_missing_runtime_gemspec_dependency_lines(content, missing_lines, receiver:) ⇒ Object
12062 12063 12064 12065 12066 12067 12068 12069 |
# File 'lib/kettle/jem.rb', line 12062 def insert_missing_runtime_gemspec_dependency_lines(content, missing_lines, receiver:) return content if missing_lines.empty? lines = content.to_s.lines insertion_index = runtime_gemspec_dependency_insertion_index(lines, receiver: receiver) lines.insert(insertion_index, *missing_lines) lines.join end |
.insert_yaml_scalar_after_path(content, path, key, value) ⇒ Object
12667 12668 12669 12670 12671 12672 12673 12674 12675 12676 12677 12678 12679 12680 12681 12682 12683 |
# File 'lib/kettle/jem.rb', line 12667 def insert_yaml_scalar_after_path(content, path, key, value) lines = content.to_s.lines scalar_entry = yaml_scalar_path_entries(content).find { |candidate| candidate.fetch(:path) == path } mapping_entry = yaml_mapping_path_entries(content).find { |candidate| candidate.fetch(:path) == path } entry = scalar_entry || mapping_entry return content unless entry line_index = entry.key?(:line) ? entry.fetch(:line) : entry.fetch(:start_line) indent = lines[line_index].to_s[/\A\s*/].to_s scalar_path = path[0...-1] + [key] if mapping_entry && !scalar_entry indent = "#{indent} " scalar_path = path + [key] end lines.insert(line_index + 1, "#{indent}#{key}: #{yaml_config_scalar_literal(value, path: scalar_path)}\n") lines.join end |
.install_tasks ⇒ Object
2598 2599 2600 2601 2602 |
# File 'lib/kettle/jem.rb', line 2598 def install_tasks # Rake task files must be reloaded for each active Rake.application. require "rake" load(File.("jem/tasks.rb", __dir__)) end |
.integration_license_spdx(config, license) ⇒ Object
17939 17940 17941 17942 17943 17944 17945 17946 17947 |
# File 'lib/kettle/jem.rb', line 17939 def integration_license_spdx(config, license) configured = if license.is_a?(Hash) license[:spdx] || license["spdx"] else [] end configured = config["resolved_licenses"] if Array(configured).empty? && config.is_a?(Hash) Array(configured).map(&:to_s) end |
.io_popen_gemspec_files_assignment?(node) ⇒ Boolean
11648 11649 11650 11651 11652 11653 |
# File 'lib/kettle/jem.rb', line 11648 def io_popen_gemspec_files_assignment?(node) node.is_a?(::Prism::CallNode) && node.name == :popen && node.receiver&.slice == "IO" && generic_bundler_gemspec_files_command?(node.arguments&.arguments&.first) end |
.json_merge_options(recipe) ⇒ Object
10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 |
# File 'lib/kettle/jem.rb', line 10349 def (recipe) = { preference: (recipe.dig(:template_preference, :preference) || "destination").to_sym, add_template_only_nodes: true, freeze_token: recipe.dig(:template_preference, :freeze_token) || "kettle-jem" } if !recipe.dig(:template_preference, :add_template_only_nodes).nil? configured = DecisionPolicy.value_to_boolean(recipe.dig(:template_preference, :add_template_only_nodes)) [:add_template_only_nodes] = configured unless configured.nil? end end |
.kettle_changelog_gemfile_dependency_token(package_name) ⇒ Object
14324 14325 14326 14327 14328 14329 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 |
# File 'lib/kettle/jem.rb', line 14324 def kettle_changelog_gemfile_dependency_token(package_name) return "" if package_name == "kettle-changelog" <<~RUBY.chomp # Release lockfile/build commands set this dependency-specific switch so # the development tool cannot pull unpublished family gems into resolution. kettle_changelog_skip = ENV.fetch("KETTLE_DEV_SKIP_CHANGELOG_DEPENDENCY", "false").downcase kettle_changelog_skip = %w[true 1 yes on].include?(kettle_changelog_skip) kettle_changelog_local = ENV.fetch("KETTLE_DEV_DEV", "false").downcase kettle_changelog_local = !%w[false 0 no off].include?(kettle_changelog_local) unless kettle_changelog_skip if kettle_changelog_local require "nomono/bundler" eval_nomono_gems( gems: ["kettle-changelog"], prefix: "KETTLE_DEV", path_env: "KETTLE_DEV_DEV", root: ["src", "my", "kettle-dev"] ) elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("4.0.0") gem "kettle-changelog", "~> 1.0", ">= 1.0.7" end end RUBY end |
.kettle_config_bootstrap_facts(project_root, env, template_selection: {}) ⇒ Object
18460 18461 18462 18463 18464 18465 18466 18467 18468 18469 18470 18471 18472 18473 18474 18475 18476 18477 18478 18479 18480 18481 |
# File 'lib/kettle/jem.rb', line 18460 def kettle_config_bootstrap_facts(project_root, env, template_selection: {}) return if File.exist?(File.join(project_root, KETTLE_CONFIG_PATH)) return if File.exist?(File.join(project_root, LEGACY_KETTLE_CONFIG_PATH)) selected_source = preferred_template_source(PACKAGED_TEMPLATE_ROOT, KETTLE_CONFIG_PATH) return unless selected_source { template_preference: { target_path: KETTLE_CONFIG_PATH, configured_source: KETTLE_CONFIG_PATH, selected_source: selected_source, source_relative_path: selected_source, source_root: "packaged", source_root_path: PACKAGED_TEMPLATE_ROOT, selection_reason: template_source_selection_reason(KETTLE_CONFIG_PATH, selected_source), apply: true }, min_divergence_threshold: preferred_template_token_value(nil, nil, env, "KJ_MIN_DIVERGENCE_THRESHOLD").to_s, template_profile: template_selection[:template_profile].to_s }.compact end |
.kettle_config_bootstrap_recipe(bootstrap) ⇒ Object
18483 18484 18485 18486 18487 18488 18489 18490 18491 18492 18493 18494 18495 18496 18497 18498 18499 18500 18501 18502 18503 18504 18505 18506 18507 18508 |
# File 'lib/kettle/jem.rb', line 18483 def kettle_config_bootstrap_recipe(bootstrap) recipe = recipe_entry( "kettle_config_bootstrap", KETTLE_CONFIG_PATH, "yaml", "supplied_kettle_config_bootstrap", facts: %w[kettle_config_bootstrap] ) recipe[:template_preference] = bootstrap.fetch(:template_preference) recipe[:template_tokens] = { "KJ|MIN_DIVERGENCE_THRESHOLD" => bootstrap.fetch(:min_divergence_threshold).to_s, "KJ|MIN_RUBY" => bootstrap[:min_ruby].to_s, "KJ|MIN_TEST_RUBY" => bootstrap[:test_min_ruby].to_s, "KJ|YARD_HOST" => bootstrap[:yard_host].to_s, "KJ|HOMEPAGE_URI" => bootstrap[:homepage_uri].to_s, "KJ|RUBYFORUM:FAMILY_TAG" => bootstrap.dig(:rubyforum, :family_tag).to_s, "KJ|RUBYFORUM:PROJECT_TAG" => bootstrap.dig(:rubyforum, :project_tag).to_s } recipe[:bootstrap_licenses] = Array(bootstrap[:licenses]).map(&:to_s).reject(&:empty?) recipe[:bootstrap_template_profile] = bootstrap[:template_profile].to_s unless bootstrap[:template_profile].to_s.empty? recipe[:bootstrap_gemspec_path] = bootstrap[:gemspec_path].to_s unless bootstrap[:gemspec_path].to_s.empty? recipe[:bootstrap_project_emoji] = bootstrap[:project_emoji].to_s unless bootstrap[:project_emoji].to_s.empty? recipe[:bootstrap_rubyforum] = bootstrap[:rubyforum] if bootstrap[:rubyforum].is_a?(Hash) recipe[:bootstrap_shim] = bootstrap[:shim] if bootstrap[:shim].is_a?(Hash) recipe end |
.kettle_config_file_override_block_end(lines, start_index) ⇒ Object
5389 5390 5391 5392 5393 |
# File 'lib/kettle/jem.rb', line 5389 def kettle_config_file_override_block_end(lines, start_index) index = start_index + 1 index += 1 while index < lines.length && lines.fetch(index).start_with?(" ") index end |
.kettle_config_file_override_lines(path, strategy) ⇒ Object
12962 12963 12964 12965 12966 12967 12968 12969 12970 12971 12972 |
# File 'lib/kettle/jem.rb', line 12962 def kettle_config_file_override_lines(path, strategy) parts = path.to_s.split("/") parts.each_with_index.flat_map do |part, index| indent = " " * (index + 1) if index == parts.length - 1 ["#{indent}#{part}:", "#{" " * (index + 2)}strategy: #{strategy}"] else ["#{indent}#{part}:"] end end end |
.kettle_config_gemspec_override_insertion_index(lines, files_index) ⇒ Object
5380 5381 5382 5383 5384 5385 5386 5387 |
# File 'lib/kettle/jem.rb', line 5380 def kettle_config_gemspec_override_insertion_index(lines, files_index) readme_index = lines.index(" README.md:") if readme_index && readme_index > files_index return kettle_config_file_override_block_end(lines, readme_index) end files_index + 1 end |
.kettle_config_internal_value(value_provider) ⇒ Object
12483 12484 12485 12486 12487 12488 12489 12490 |
# File 'lib/kettle/jem.rb', line 12483 def kettle_config_internal_value(value_provider) case value_provider when :version VERSION else raise ArgumentError, "Unsupported kettle-jem internal config value provider: #{value_provider.inspect}" end end |
.kettle_config_template_entries_lines(entries) ⇒ Object
5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 |
# File 'lib/kettle/jem.rb', line 5401 def kettle_config_template_entries_lines(entries) [" entries:", *entries.flat_map do |entry| if entry.is_a?(Hash) [ " - source: #{entry.fetch("source")}", " target: #{entry.fetch("target")}" ] else [" - #{entry}"] end end] end |
.kettle_dev_local_gems(config) ⇒ Object
15383 15384 15385 15386 15387 15388 |
# File 'lib/kettle/jem.rb', line 15383 def kettle_dev_local_gems(config) gems = %w[kettle-dev kettle-family kettle-test kettle-soup-cover kettle-changelog] plugin_names = PluginLoader.normalize_plugin_names(plugin_names_from_config(config)) gems.concat(plugin_names.select { |plugin_name| plugin_name.start_with?("kettle-") }) gems.uniq.join(" ") end |
.kettle_jem_config(project_root) ⇒ Object
13696 13697 13698 13699 13700 13701 13702 13703 13704 13705 13706 |
# File 'lib/kettle/jem.rb', line 13696 def kettle_jem_config(project_root) path = kettle_jem_config_path(project_root) return {} unless File.exist?(path) config = YAML.safe_load_file(path, permitted_classes: [], aliases: false) || {} config = normalize_kettle_jem_config(config) validate_kettle_jem_config!(config) config rescue Psych::SyntaxError => error raise Error, "Invalid #{kettle_jem_config_relative_path(project_root)}: #{error.}" end |
.kettle_jem_config_path(project_root) ⇒ Object
13724 13725 13726 13727 13728 13729 |
# File 'lib/kettle/jem.rb', line 13724 def kettle_jem_config_path(project_root) canonical = File.join(project_root, KETTLE_CONFIG_PATH) return canonical if File.exist?(canonical) File.join(project_root, LEGACY_KETTLE_CONFIG_PATH) end |
.kettle_jem_config_relative_path(project_root) ⇒ Object
13731 13732 13733 13734 |
# File 'lib/kettle/jem.rb', line 13731 def kettle_jem_config_relative_path(project_root) path = kettle_jem_config_path(project_root) File.(path).delete_prefix("#{File.(project_root.to_s)}/") end |
.kettle_jem_state_sync_step(project_root, report) ⇒ Object
5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 |
# File 'lib/kettle/jem.rb', line 5174 def kettle_jem_state_sync_step(project_root, report) config_path = kettle_jem_config_path(project_root) return unless File.file?(config_path) relative_config_path = config_path.delete_prefix("#{project_root}/") lock_path = TemplateLock.path(project_root) relative_lock_path = lock_path.delete_prefix("#{project_root}/") legacy_lock_path = TemplateLock.legacy_path(project_root) relative_legacy_lock_path = legacy_lock_path.delete_prefix("#{project_root}/") legacy_lock_existed = File.exist?(legacy_lock_path) before_config = File.read(config_path) before_lock = File.exist?(lock_path) ? File.read(lock_path) : nil latest_replay = report.dig(:facts, :changelog, :latest_transfer_entry) existing_state = TemplateLock.load(project_root: project_root, config_path: config_path) existing_replay = existing_state.dig(TemplateLock::TEMPLATE_STATE_KEY, TemplateChecksums::CHANGELOG_REPLAY_SUBKEY) changelog_replay = if latest_replay { TemplateChecksums::LAST_ENTRY_KEY_SUBKEY => latest_replay.fetch(:key), TemplateChecksums::LAST_ENTRY_DATE_SUBKEY => changelog_transfer_key_date(latest_replay.fetch(:key)) } elsif existing_replay.is_a?(Hash) existing_replay end template_state = { "version" => VERSION, "applied_at" => Time.now.utc.strftime("%Y-%m-%d"), TemplateChecksums::CHANGELOG_REPLAY_SUBKEY => changelog_replay, TemplateChecksums::CHECKSUMS_SUBKEY => TemplateChecksums.compute( template_root: template_root_path(project_root, config: kettle_jem_config(project_root)) ) }.compact file_records = checksum_file_records(project_root, report, existing_state) TemplateLock.write( project_root: project_root, lock: TemplateLock.build_lock(template_state: template_state, file_records: file_records) ) TemplateLock.remove_legacy(project_root) TemplateChecksums.remove_from_config(config_path: config_path) after_config = File.read(config_path) after_lock = File.read(lock_path) if after_config != before_config config_report = report.fetch(:recipe_reports, []).find { |entry| entry.fetch(:relative_path, nil) == relative_config_path } config_report[:final_content] = after_config if config_report config_report&.dig(:report_envelope, :report)&.[]=(:final_content, after_config) end changed_files = [] changed_files << relative_config_path if after_config != before_config changed_files << relative_lock_path if after_lock != before_lock changed_files << relative_legacy_lock_path if legacy_lock_existed { name: "kettle_jem_state_sync", path: relative_lock_path, status: changed_files.empty? ? "already_current" : "applied", changed_files: changed_files, metadata_only: true } end |
.known_license_template_basenames ⇒ Object
18720 18721 18722 |
# File 'lib/kettle/jem.rb', line 18720 def known_license_template_basenames KNOWN_LICENSE_TEMPLATE_BASENAMES end |
.large_business_license_cell(author_email, license_source_url: nil) ⇒ Object
17723 17724 17725 17726 17727 17728 17729 17730 |
# File 'lib/kettle/jem.rb', line 17723 def large_business_license_cell(, license_source_url: nil) cell = license_link("LicenseRef-Big-Time-Public-License", license_source_url: license_source_url) if .to_s.empty? "#{cell} or contact us for a custom license" else "#{cell} or [contact us](mailto:#{}) for a custom license" end end |
.latest_changelog_transfer_entry(entries) ⇒ Object
6270 6271 6272 |
# File 'lib/kettle/jem.rb', line 6270 def latest_changelog_transfer_entry(entries) Array(entries).last end |
.leading_space_count(line) ⇒ Object
8803 8804 8805 |
# File 'lib/kettle/jem.rb', line 8803 def leading_space_count(line) line.to_s.each_char.take_while { |char| char == " " }.count end |
.leading_whitespace(source) ⇒ Object
12253 12254 12255 12256 |
# File 'lib/kettle/jem.rb', line 12253 def leading_whitespace(source) text = source.to_s text[0...(text.length - text.lstrip.length)] end |
.legacy_git_ls_files_assignment?(node) ⇒ Boolean
Legacy gemspecs commonly shell out with backticks, then apply split and optional filtering calls. Prism lets us recognize that bounded pipeline without interpreting arbitrary Ruby.
11658 11659 11660 11661 11662 11663 11664 11665 11666 |
# File 'lib/kettle/jem.rb', line 11658 def legacy_git_ls_files_assignment?(node) return legacy_git_ls_files_chdir_assignment?(node) if node.is_a?(::Prism::CallNode) && node.name == :chdir current = node while current.is_a?(::Prism::CallNode) && %i[split reject select grep map].include?(current.name) current = current.receiver end current.is_a?(::Prism::XStringNode) && %w[git\ ls-files git\ ls-files\ -z].include?(current.unescaped.to_s) end |
.legacy_git_ls_files_chdir_assignment?(node) ⇒ Boolean
Older Bundler gemspecs commonly scope a git-ls-files pipeline with Dir.chdir(File.expand_path(dir)). This wrapper does not change the package-file semantics, so recognize it without evaluating arbitrary destination Ruby. The block must contain exactly one known pipeline.
11672 11673 11674 11675 11676 11677 11678 |
# File 'lib/kettle/jem.rb', line 11672 def legacy_git_ls_files_chdir_assignment?(node) return false unless node.receiver&.slice == "Dir" return false unless Array(node.arguments&.arguments).length == 1 body = Array(node.block&.body&.body) body.length == 1 && legacy_git_ls_files_assignment?(body.first) end |
.legacy_rbs_consolidation_step(project_root, facts, entrypoint_require:) ⇒ Object
5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 |
# File 'lib/kettle/jem.rb', line 5669 def legacy_rbs_consolidation_step(project_root, facts, entrypoint_require:) legacy_signature_paths = legacy_rbs_signature_paths(project_root, entrypoint_require) return if legacy_signature_paths.empty? namespace = facts.dig(:rubygems, :namespace).to_s signature_path = File.join("sig", "#{entrypoint_require}.rbs") changes = write_consolidated_version_signature( project_root, signature_path, legacy_signature_paths, namespace: namespace ).compact { name: "legacy_rbs_consolidation", status: changes.empty? ? "already_current" : "applied", changed_files: changes, signature_path: signature_path } end |
.legacy_rbs_signature_paths(project_root, entrypoint_require) ⇒ Object
15897 15898 15899 15900 15901 15902 15903 15904 |
# File 'lib/kettle/jem.rb', line 15897 def legacy_rbs_signature_paths(project_root, entrypoint_require) legacy_root = File.join(project_root, "sig", entrypoint_require.to_s) return [] unless Dir.exist?(legacy_root) Dir.glob(File.join(legacy_root, "**", "*.rbs")).sort.map do |path| path.delete_prefix("#{project_root}/") end end |
.legacy_readme_top_logo_mode_options(value) ⇒ Object
12544 12545 12546 12547 12548 12549 12550 12551 12552 12553 12554 12555 12556 |
# File 'lib/kettle/jem.rb', line 12544 def (value) raw = value.to_s.strip return [] if raw.empty? normalized = raw.downcase.tr("-", "_").gsub(/\s*,\s*/, ",").tr(" ", "_") mapped = README_TOP_LOGO_LEGACY_MODE_MAP[normalized] return mapped if mapped normalized.split(",").filter_map do |option| option = option.strip README_TOP_LOGO_OPTIONS.include?(option) ? option : nil end end |
.license_badge(spdx_id, ref: :license_ref) ⇒ Object
17597 17598 17599 17600 |
# File 'lib/kettle/jem.rb', line 17597 def license_badge(spdx_id, ref: :license_ref) base = spdx_basename(spdx_id) "[![License: #{base}][#{paperclip_ref(:license_img)}]][#{paperclip_ref(ref)}]" end |
.license_badge_img(spdx_id) ⇒ Object
17612 17613 17614 17615 |
# File 'lib/kettle/jem.rb', line 17612 def license_badge_img(spdx_id) base = spdx_basename(spdx_id).gsub("-", "--").gsub("_", "__").tr(" ", "_") "https://img.shields.io/badge/License-#{base}-259D6C.svg" end |
.license_badge_ref(spdx_id, license_source_url: nil) ⇒ Object
17602 17603 17604 17605 |
# File 'lib/kettle/jem.rb', line 17602 def license_badge_ref(spdx_id, license_source_url: nil) base = spdx_basename(spdx_id) base.include?(" OR ") ? "LICENSE.md" : license_detail_ref(base, license_source_url: license_source_url) end |
.license_compat_badge(category) ⇒ Object
17626 17627 17628 17629 |
# File 'lib/kettle/jem.rb', line 17626 def license_compat_badge(category) data = APACHE_LICENSE_COMPAT_BADGE_DATA.fetch(category) "[![#{data.fetch(:alt)}][#{paperclip_ref(:license_compat_img)}]][#{paperclip_ref(:license_compat)}]" end |
.license_compat_category(licenses) ⇒ Object
17617 17618 17619 17620 17621 17622 17623 17624 |
# File 'lib/kettle/jem.rb', line 17617 def license_compat_category(licenses) categories = Array(licenses).filter_map { |license| APACHE_LICENSE_COMPAT_CATEGORIES[license.to_s] }.uniq return :a if categories.include?(:a) return :b if categories.include?(:b) return :x if categories.any? && categories.all?(:x) :unknown end |
.license_compat_img(category) ⇒ Object
17679 17680 17681 17682 17683 17684 |
# File 'lib/kettle/jem.rb', line 17679 def license_compat_img(category) data = APACHE_LICENSE_COMPAT_BADGE_DATA.fetch(category) normalize_generated_image_url( "https://img.shields.io/badge/#{data.fetch(:label)}-#{data.fetch(:message)}-#{data.fetch(:color)}.svg?style=flat&logo=Apache" ) end |
.license_compat_ref(category) ⇒ Object
17675 17676 17677 |
# File 'lib/kettle/jem.rb', line 17675 def license_compat_ref(category) APACHE_LICENSE_COMPAT_BADGE_DATA.fetch(category).fetch(:ref) end |
.license_contact_line(author_email, context:) ⇒ Object
17565 17566 17567 17568 17569 17570 17571 17572 17573 17574 17575 |
# File 'lib/kettle/jem.rb', line 17565 def license_contact_line(, context:) if .to_s.empty? return "If none of the above licenses fit your use case, please contact the project maintainer to discuss a custom commercial license." if context == :license_md "If none of the available licenses suit your use case, please contact the project maintainer to discuss a custom commercial license." elsif context == :license_md "If none of the above licenses fit your use case, please [contact us](mailto:#{}) to discuss a custom commercial license." else "If none of the available licenses suit your use case, please [contact us](mailto:#{}) to discuss a custom commercial license." end end |
.license_copyright_notice(copyright_lines, copyright_prefix, author) ⇒ Object
17504 17505 17506 17507 |
# File 'lib/kettle/jem.rb', line 17504 def license_copyright_notice(copyright_lines, copyright_prefix, ) lines = copyright_notice_lines(copyright_lines, copyright_prefix, ).map { |line| "- #{line}" } "## Copyright Notice\n\n#{lines.join("\n")}" end |
.license_detail_ref(base, license_source_url: nil) ⇒ Object
17607 17608 17609 17610 |
# File 'lib/kettle/jem.rb', line 17607 def license_detail_ref(base, license_source_url: nil) file = "#{base}.md" license_source_url.to_s.empty? ? file : "#{license_source_url}/#{file}" end |
.license_eye_compatible_licenses?(licenses) ⇒ Boolean
17949 17950 17951 |
# File 'lib/kettle/jem.rb', line 17949 def license_eye_compatible_licenses?(licenses) Array(licenses).map(&:to_s).any? { |license_id| LICENSE_EYE_COMPATIBILITY_LICENSES.include?(license_id) } end |
.license_eye_dependency_license_entry(entry) ⇒ Object
17656 17657 17658 17659 17660 17661 17662 17663 17664 17665 17666 17667 17668 17669 17670 17671 17672 17673 |
# File 'lib/kettle/jem.rb', line 17656 def license_eye_dependency_license_entry(entry) data = if entry.is_a?(Hash) entry else {} end name = data["name"] || data[:name] license = data["license"] || data[:license] version = data["version"] || data[:version] return if name.to_s.strip.empty? || license.to_s.strip.empty? lines = [ " - name: #{JSON.generate(name.to_s.strip)}", " license: #{JSON.generate(license.to_s.strip)}" ] lines.insert(1, " version: #{JSON.generate(version.to_s.strip)}") unless version.to_s.strip.empty? lines end |
.license_eye_dependency_licenses(config) ⇒ Object
17647 17648 17649 17650 17651 17652 17653 17654 |
# File 'lib/kettle/jem.rb', line 17647 def license_eye_dependency_licenses(config) entries = Array(config.dig("license_eye", "dependency_licenses")).filter_map do |entry| license_eye_dependency_license_entry(entry) end return "" if entries.empty? [" licenses:", *entries].join("\n") end |
.license_eye_flags(licenses) ⇒ Object
17643 17644 17645 |
# File 'lib/kettle/jem.rb', line 17643 def license_eye_flags(licenses) (license_eye_mode(licenses) == "check") ? "--weak-compatible" : "" end |
.license_eye_mode(licenses) ⇒ Object
17639 17640 17641 |
# File 'lib/kettle/jem.rb', line 17639 def license_eye_mode(licenses) (Array(licenses).map(&:to_s).any? { |license| LICENSE_EYE_COMPATIBILITY_LICENSES.include?(license) }) ? "check" : "resolve" end |
.license_eye_primary_spdx(licenses, fallback) ⇒ Object
17635 17636 17637 |
# File 'lib/kettle/jem.rb', line 17635 def license_eye_primary_spdx(licenses, fallback) Array(licenses).map(&:to_s).find { |license| LICENSE_EYE_COMPATIBILITY_LICENSES.include?(license) } || fallback end |
.license_eye_workflow_badge(licenses, config = {}) ⇒ Object
17631 17632 17633 |
# File 'lib/kettle/jem.rb', line 17631 def license_eye_workflow_badge(licenses, config = {}) disabled_integrations(config, license: {spdx: licenses}).include?(SKYWALKING_EYES_INTEGRATION) ? "" : README_LICENSE_EYE_WORKFLOW_BADGE end |
.license_facts(config, gemspec_licenses, author: {}, author_email: nil, copyright: {}, source_url: nil, license_txt: {}) ⇒ Object
17406 17407 17408 17409 17410 17411 17412 17413 17414 17415 17416 17417 17418 17419 17420 17421 17422 17423 17424 17425 17426 17427 17428 17429 17430 17431 17432 17433 17434 17435 17436 17437 17438 17439 17440 17441 17442 17443 17444 17445 17446 |
# File 'lib/kettle/jem.rb', line 17406 def license_facts(config, gemspec_licenses, author: {}, author_email: nil, copyright: {}, source_url: nil, license_txt: {}) configured_licenses = Array(config["licenses"]).map { |license| license.to_s.strip }.reject(&:empty?) gemspec_licenses = Array(gemspec_licenses).map { |license| license.to_s.strip }.reject(&:empty?) licenses = if configured_licenses.any? configured_licenses elsif gemspec_licenses.any? gemspec_licenses elsif license_txt[:present] && !license_txt[:mit] [] else ["MIT"] end custom_license = license_txt[:custom] && configured_licenses.empty? && gemspec_licenses.empty? primary = licenses.first compat_category = license_compat_category(licenses) copyright_prefix = polyform_licenses?(licenses) ? "Required Notice: " : "" copyright_lines = Array(copyright[:lines]) # Git blame is authoritative for generated LICENSE.md notices. A legacy # MIT LICENSE.txt notice is only a fallback for projects without blame # data, such as an unpacked source tree being templated for the first time. copyright_lines = license_txt[:copyright_lines] if copyright_lines.empty? && license_txt[:mit] license_source_url = license_source_blob_url(source_url) compact_hash( spdx: licenses, expression: licenses.join(" OR "), primary_spdx: primary, license_md_content: license_md_content(licenses, author_email: , license_source_url: license_source_url, custom_license: custom_license), readme_license_intro: readme_license_intro(licenses, author_email: , license_source_url: license_source_url, custom_license: custom_license), readme_license_badge: license_badge(licenses.join(" OR "), ref: :license), readme_license_compat_badge: license_compat_badge(compat_category), readme_license_eye_workflow_badge: license_eye_workflow_badge(licenses, config), readme_license_refs: readme_license_refs(licenses.join(" OR "), compat_category, license_source_url: license_source_url), license_eye_primary_spdx: license_eye_primary_spdx(licenses, primary), license_eye_mode: license_eye_mode(licenses), license_eye_flags: license_eye_flags(licenses), license_eye_dependency_licenses: license_eye_dependency_licenses(config), license_copyright_notice: license_copyright_notice(copyright_lines, copyright_prefix, ), readme_copyright_notice: readme_copyright_notice(copyright_lines, copyright_prefix, ), copyright_prefix: copyright_prefix ) end |
.license_link(spdx_id, license_source_url: nil) ⇒ Object
17592 17593 17594 17595 |
# File 'lib/kettle/jem.rb', line 17592 def license_link(spdx_id, license_source_url: nil) base = spdx_basename(spdx_id) "[#{base}](#{license_detail_ref(base, license_source_url: license_source_url)})" end |
.license_md_content(licenses, author_email: nil, license_source_url: nil, custom_license: false) ⇒ Object
17529 17530 17531 17532 17533 17534 17535 17536 17537 17538 17539 17540 17541 17542 17543 17544 |
# File 'lib/kettle/jem.rb', line 17529 def license_md_content(licenses, author_email: nil, license_source_url: nil, custom_license: false) return "# License\n\nThe licensing terms for this project are provided in [LICENSE.txt](LICENSE.txt)." if custom_license content = <<~MARKDOWN.chomp # License This project is made available under the following license#{"s" if licenses.size > 1}. Choose the option that best fits your use case: #{licenses.map { |license| "- #{license_link(license, license_source_url: license_source_url)}" }.join("\n")} MARKDOWN guide_table = license_use_case_guide_table(licenses, author_email: , license_source_url: license_source_url) content += "\n\n## Use-case guide\n\n#{guide_table}" if guide_table content += "\n\n#{license_contact_line(, context: :license_md)}" if non_mit_licenses?(licenses) content end |
.license_source_blob_url(source_url) ⇒ Object
17463 17464 17465 17466 17467 17468 17469 |
# File 'lib/kettle/jem.rb', line 17463 def license_source_blob_url(source_url) repo_url = concrete_github_url(source_url) repo_url = source_url.to_s.sub(%r{/tree/[^/]+\z}, "") if repo_url.to_s.empty? return if repo_url.to_s.empty? "#{repo_url.to_s.sub(%r{/\z}, "")}/blob/main" end |
.license_template_tokens(license) ⇒ Object
17480 17481 17482 17483 17484 17485 17486 17487 17488 17489 17490 17491 17492 17493 17494 17495 17496 17497 17498 |
# File 'lib/kettle/jem.rb', line 17480 def license_template_tokens(license) { "KJ|LICENSE_MD_CONTENT" => license[:license_md_content].to_s, "KJ|GEMSPEC:ROOT_LICENSE_FILES" => gemspec_root_license_files_token(license), "KJ|README:LICENSE_INTRO" => license[:readme_license_intro].to_s, "KJ|LICENSE:PRIMARY_SPDX" => license[:primary_spdx].to_s, "KJ|LICENSE_EYE:PRIMARY_SPDX" => license[:license_eye_primary_spdx].to_s, "KJ|LICENSE_EYE:MODE" => license[:license_eye_mode].to_s, "KJ|LICENSE_EYE:FLAGS" => license[:license_eye_flags].to_s, "KJ|LICENSE_EYE:DEPENDENCY_LICENSES" => license[:license_eye_dependency_licenses].to_s, "KJ|README:LICENSE_BADGE" => license[:readme_license_badge].to_s, "KJ|README:LICENSE_COMPAT_BADGE" => license[:readme_license_compat_badge].to_s, "KJ|README:LICENSE_EYE_WORKFLOW_BADGE" => license[:readme_license_eye_workflow_badge].to_s, "KJ|README:LICENSE_REFS" => license[:readme_license_refs].to_s, "KJ|LICENSE_COPYRIGHT_NOTICE" => license[:license_copyright_notice].to_s, "KJ|README:COPYRIGHT_NOTICE" => license[:readme_copyright_notice].to_s, "KJ|COPYRIGHT_PREFIX" => license[:copyright_prefix].to_s } end |
.license_txt_facts(project_root) ⇒ Object
17448 17449 17450 17451 17452 17453 17454 17455 17456 17457 17458 17459 17460 17461 |
# File 'lib/kettle/jem.rb', line 17448 def license_txt_facts(project_root) path = File.join(project_root.to_s, "LICENSE.txt") return {} unless File.file?(path) migrator = LicenseTxtMigrator.new(File.read(path)) if migrator.mit_license? {present: true, mit: true, copyright_lines: migrator.copyright_lines} else {present: true, custom: true, mit: false, copyright_lines: []} end rescue => error Kettle::Dev.debug_error(error, __method__) {present: true, custom: true, mit: false, copyright_lines: []} end |
.license_use_case_guide_table(licenses, author_email: nil, license_source_url: nil) ⇒ Object
17694 17695 17696 17697 17698 17699 17700 17701 17702 17703 17704 17705 |
# File 'lib/kettle/jem.rb', line 17694 def license_use_case_guide_table(licenses, author_email: nil, license_source_url: nil) has_floss_oss = licenses.include?("MIT") || licenses.include?("AGPL-3.0-only") has_polyform = licenses.include?("PolyForm-Noncommercial-1.0.0") || licenses.include?("PolyForm-Small-Business-1.0.0") has_big_time = licenses.include?("LicenseRef-Big-Time-Public-License") return unless has_floss_oss && has_polyform && has_big_time rows = license_use_case_rows(licenses, author_email: , license_source_url: license_source_url) return if rows.empty? "| Use case | License |\n|---|---|\n" + rows.map { |use_case, license| "| #{use_case} | #{license} |" }.join("\n") end |
.license_use_case_rows(licenses, author_email: nil, license_source_url: nil) ⇒ Object
17707 17708 17709 17710 17711 17712 17713 17714 17715 17716 17717 17718 17719 17720 17721 |
# File 'lib/kettle/jem.rb', line 17707 def license_use_case_rows(licenses, author_email: nil, license_source_url: nil) rows = [] rows << ["FLOSS (free and open source)", license_link("MIT", license_source_url: license_source_url)] if licenses.include?("MIT") rows << ["Copy-left open source", license_link("AGPL-3.0-only", license_source_url: license_source_url)] if licenses.include?("AGPL-3.0-only") noncommercial_links = %w[PolyForm-Noncommercial-1.0.0 PolyForm-Small-Business-1.0.0 LicenseRef-Big-Time-Public-License] .select { |license| licenses.include?(license) } .map { |license| license_link(license, license_source_url: license_source_url) } rows << ["Non-commercial (research, education, personal use)", noncommercial_links.join(" or ")] unless noncommercial_links.empty? small_business_links = %w[PolyForm-Small-Business-1.0.0 LicenseRef-Big-Time-Public-License] .select { |license| licenses.include?(license) } .map { |license| license_link(license, license_source_url: license_source_url) } rows << ["Small business commercial", small_business_links.join(" or ")] unless small_business_links.empty? rows << ["Larger business commercial", large_business_license_cell(, license_source_url: license_source_url)] if licenses.include?("LicenseRef-Big-Time-Public-License") rows end |
.load_project_gemspec(gemspec_path) ⇒ Object
15351 15352 15353 15354 15355 |
# File 'lib/kettle/jem.rb', line 15351 def load_project_gemspec(gemspec_path) Gem::Specification.load(gemspec_path) rescue LoadError, StandardError nil end |
.local_gemfile_nomono_bootstrap(_package_name) ⇒ Object
15409 15410 15411 15412 15413 15414 15415 15416 15417 15418 15419 15420 15421 15422 15423 15424 15425 15426 15427 15428 15429 15430 15431 15432 15433 15434 15435 15436 |
# File 'lib/kettle/jem.rb', line 15409 def local_gemfile_nomono_bootstrap(_package_name) <<~RUBY.rstrip # Bootstrapping nomono here cannot rely on a plain `gem "nomono", ...` line. # Bundler records that dependency during Gemfile evaluation, but it does not # activate that exact version before the immediate `require "nomono/bundler"`. nomono_activation_requirements = ["~> 1.1", ">= 1.1.5"] nomono_requirement = Gem::Requirement.new(nomono_activation_requirements) nomono_already_activated = Gem.loaded_specs["nomono"] nomono_lockfile = File.expand_path("../../Gemfile.lock", __dir__) if !nomono_already_activated || !nomono_requirement.satisfied_by?(nomono_already_activated.version) require "bundler" if File.file?(nomono_lockfile) nomono_locked_spec = Bundler::LockfileParser .new(Bundler.read_file(nomono_lockfile)) .specs .find { |spec| spec.name == "nomono" } nomono_locked_installed = nomono_locked_spec && Gem::Specification.find_all_by_name("nomono").any? { |spec| spec.version == nomono_locked_spec.version } nomono_locked = nomono_locked_spec && nomono_locked_installed && nomono_requirement.satisfied_by?(nomono_locked_spec.version) nomono_activation_requirements = ["= \#{nomono_locked_spec.version}"] if nomono_locked end end Kernel.send(:gem, "nomono", *nomono_activation_requirements) require "nomono/bundler" RUBY end |
.local_gemfile_nomono_kernel_activation_call?(node) ⇒ Boolean
8974 8975 8976 8977 8978 8979 8980 |
# File 'lib/kettle/jem.rb', line 8974 def local_gemfile_nomono_kernel_activation_call?(node) node.is_a?(::Prism::CallNode) && node.name == :send && node.receiver&.slice == "Kernel" && node.arguments&.arguments&.[](0)&.location&.slice == ":gem" && ruby_string_argument_at(node, 1) == "nomono" end |
.local_gemfile_template_recipe?(recipe) ⇒ Boolean
8903 8904 8905 |
# File 'lib/kettle/jem.rb', line 8903 def local_gemfile_template_recipe?(recipe) recipe.fetch(:target_path).to_s.end_with?("_local.gemfile") end |
.local_gems_assignment(content) ⇒ Object
9032 9033 9034 |
# File 'lib/kettle/jem.rb', line 9032 def local_gems_assignment(content) word_array_assignment(content, :local_gems) end |
.local_gems_assignment_record(content) ⇒ Object
9040 9041 9042 |
# File 'lib/kettle/jem.rb', line 9040 def local_gems_assignment_record(content) word_array_assignment_record(content, :local_gems) end |
.local_modular_eval_paths_for_gem(project_root, gem_name) ⇒ Object
15107 15108 15109 15110 15111 15112 15113 15114 15115 15116 15117 15118 15119 15120 15121 15122 |
# File 'lib/kettle/jem.rb', line 15107 def local_modular_eval_paths_for_gem(project_root, gem_name) Dir.glob(File.join(project_root.to_s, "gemfiles", "modular", "**", "*_local.gemfile")).filter_map do |path| next unless gemfile_dependency_names(File.read(path)).include?(gem_name.to_s) local_relative = project_relative_path(path, project_root) paired_relative = paired_modular_gemfile_path(local_relative) next unless paired_relative next unless File.file?(File.join(project_root.to_s, paired_relative)) paired_relative rescue Errno::ENOENT nil end .uniq .sort end |
.local_modular_runtime_eval_paths(project_root, gemspec_metadata, package_name:) ⇒ Object
15095 15096 15097 15098 15099 15100 15101 15102 15103 15104 15105 |
# File 'lib/kettle/jem.rb', line 15095 def local_modular_runtime_eval_paths(project_root, , package_name:) return {} unless project_root && .is_a?(Hash) runtime_names = gemspec_runtime_dependency_names() - [package_name.to_s] return {} if runtime_names.empty? runtime_names.each_with_object({}) do |gem_name, paths_by_gem| paths = local_modular_eval_paths_for_gem(project_root, gem_name) paths_by_gem[gem_name] = paths if paths.any? end end |
.main_gemfile_after_gemspec_line(content) ⇒ Object
8243 8244 8245 |
# File 'lib/kettle/jem.rb', line 8243 def main_gemfile_after_gemspec_line(content) ruby_call_records(content, :gemspec).map { |call| ruby_node_source_end_line(call) + 1 }.min end |
.main_gemfile_default_test_bundle_insertion_index(content) ⇒ Object
9413 9414 9415 9416 9417 |
# File 'lib/kettle/jem.rb', line 9413 def main_gemfile_default_test_bundle_insertion_index(content) main_gemfile_templating_eval_line(content) || main_gemfile_first_eval_gemfile_line(content) || main_gemfile_after_gemspec_line(content) end |
.main_gemfile_direct_gem_records(content, gem_name) ⇒ Object
8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 |
# File 'lib/kettle/jem.rb', line 8113 def main_gemfile_direct_gem_records(content, gem_name) lines = content.to_s.lines ruby_call_records(content, :gem).filter_map do |call| next unless call.receiver.nil? && ruby_string_argument(call) == gem_name.to_s start_line = stale_main_gemfile_gem_comment_start_line(lines, call.location.start_line, gem_name) { start_line: start_line, end_line: ruby_node_source_end_line(call) } end end |
.main_gemfile_direct_sibling_block(gems, package_name:, source_url:, project_root:, repository: {}, local_modular_eval_paths: []) ⇒ Object
15161 15162 15163 15164 15165 15166 15167 15168 15169 15170 15171 15172 15173 15174 15175 15176 15177 15178 15179 15180 15181 15182 15183 15184 15185 15186 15187 15188 15189 15190 15191 15192 15193 15194 15195 15196 15197 15198 15199 15200 15201 15202 15203 15204 15205 15206 15207 15208 15209 15210 15211 15212 15213 15214 15215 15216 15217 15218 15219 15220 |
# File 'lib/kettle/jem.rb', line 15161 def main_gemfile_direct_sibling_block(gems, package_name:, source_url:, project_root:, repository: {}, local_modular_eval_paths: []) names = Array(gems).map(&:to_s).reject(&:empty?).uniq eval_paths = Array(local_modular_eval_paths).map(&:to_s).reject(&:empty?).uniq.sort return "" if names.empty? && eval_paths.empty? blocks = [] if eval_paths.any? blocks << [ "# Modular sibling dependencies (env-switched inside each modular Gemfile)", *eval_paths.map { |path| %(eval_gemfile "#{path}") } ].join("\n") end return blocks.join("\n\n") if names.empty? workspace_slug = direct_sibling_workspace_slug(source_url, project_root) prefix = workspace_slug.to_s.upcase.tr("-", "_") prefix = "LOCAL" if prefix.empty? dev_env = "#{prefix}_DEV" root_literal = ruby_array_literal(direct_sibling_nomono_root_parts(workspace_slug, repository)) word_array = names.map { |name| " #{name}" }.join("\n") nomono_loader = %(require "nomono/bundler") blocks << <<~RUBY.rstrip # Direct sibling dependencies (env-switched via #{dev_env}) direct_sibling_gems = %w[ #{word_array} ] direct_sibling_dev = ENV.fetch("#{dev_env}", "") direct_sibling_local = !direct_sibling_dev.empty? && !%w[false 0 no off].include?(direct_sibling_dev.downcase) direct_sibling_templating = ENV.fetch("K_JEM_TEMPLATING", "false").casecmp("true").zero? if direct_sibling_gems.any? && (direct_sibling_local || ENV.fetch("K_JEM_TEMPLATING", "false").casecmp("true").zero?) direct_sibling_dev_was_set = ENV.key?("#{dev_env}") direct_sibling_dev_original = ENV.fetch("#{dev_env}", nil) #{nomono_loader} begin ENV["#{dev_env}"] = File.expand_path("..", __dir__) if direct_sibling_templating && !direct_sibling_local eval_nomono_gems( gems: direct_sibling_gems, prefix: "#{prefix}", path_env: "#{dev_env}", root: #{root_literal} ) ensure if direct_sibling_templating && !direct_sibling_local if direct_sibling_dev_was_set ENV["#{dev_env}"] = direct_sibling_dev_original else ENV.delete("#{dev_env}") end end end end RUBY blocks.join("\n\n") end |
.main_gemfile_direct_sibling_records(content) ⇒ Object
8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 |
# File 'lib/kettle/jem.rb', line 8158 def main_gemfile_direct_sibling_records(content) body = prism_parse_success(content)&.value&.statements&.body || [] assignments = body.select do |node| node.is_a?(::Prism::LocalVariableWriteNode) && node.name == :direct_sibling_gems end return [] if assignments.empty? lines = content.to_s.lines assignments.each_with_object([]) do |assignment, records| block_ifs = body.select do |node| node.is_a?(::Prism::IfNode) && node.location.start_line > assignment.location.end_line && prism_subtree_contains_call?(node, :eval_nomono_gems) end next if block_ifs.empty? start_line = assignment.location.start_line previous = lines[start_line - 2].to_s start_line -= 1 if previous.strip.start_with?("# Direct sibling dependencies") records << {start_line: start_line, end_line: block_ifs.first.location.end_line} block_ifs.drop(1).each do |block_if| records << {start_line: block_if.location.start_line, end_line: block_if.location.end_line} end end end |
.main_gemfile_first_eval_gemfile_line(content) ⇒ Object
8239 8240 8241 |
# File 'lib/kettle/jem.rb', line 8239 def main_gemfile_first_eval_gemfile_line(content) ruby_call_records(content, :eval_gemfile).map { |call| call.location.start_line }.min end |
.main_gemfile_kettle_family_gem(package_name) ⇒ Object
15390 15391 15392 15393 15394 |
# File 'lib/kettle/jem.rb', line 15390 def main_gemfile_kettle_family_gem(package_name) return "" if package_name.to_s == "kettle-family" %(gem "kettle-family", "~> 1.2", ">= 1.2.80"\n) end |
.main_gemfile_nomono_bootstrap(package_name) ⇒ Object
15396 15397 15398 15399 15400 15401 15402 15403 |
# File 'lib/kettle/jem.rb', line 15396 def main_gemfile_nomono_bootstrap(package_name) return "" if package_name.to_s == "nomono" <<~RUBY.rstrip # Local workspace dependency wiring for *_local.gemfile overrides #{nomono_gemfile_declaration} RUBY end |
.main_gemfile_nomono_bootstrap_source(template_content) ⇒ Object
8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 |
# File 'lib/kettle/jem.rb', line 8219 def main_gemfile_nomono_bootstrap_source(template_content) records = main_gemfile_nomono_requirement_records(template_content) call = records.fetch(:calls).first return "" unless call lines = template_content.to_s.lines start_line = call.fetch(:start_line) previous = lines[start_line - 2].to_s start_line -= 1 if previous.strip.start_with?("# Local workspace dependency wiring") lines[(start_line - 1)..(call.fetch(:end_line) - 1)].join.rstrip + "\n\n" end |
.main_gemfile_nomono_requirement_records(content) ⇒ Object
8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 |
# File 'lib/kettle/jem.rb', line 8299 def main_gemfile_nomono_requirement_records(content) body = prism_parse_success(content)&.value&.statements&.body || [] assignments = body.filter_map do |node| next unless node.is_a?(::Prism::LocalVariableWriteNode) && node.name == :nomono_requirements { start_line: node.location.start_line, end_line: ruby_node_source_end_line(node), source: node.location.slice } end calls = ruby_call_records(content, :gem).filter_map do |call| next unless ruby_string_argument(call) == "nomono" { start_line: call.location.start_line, end_line: ruby_node_source_end_line(call), source: call.location.slice } end {assignments: assignments, calls: calls.sort_by { |record| record.fetch(:start_line) }} end |
.main_gemfile_recording_eval_path ⇒ Object
9429 9430 9431 |
# File 'lib/kettle/jem.rb', line 9429 def main_gemfile_recording_eval_path "gemfiles/modular/recording/r4/recording.gemfile" end |
.main_gemfile_recording_insertion_index(content) ⇒ Object
9419 9420 9421 9422 9423 9424 9425 9426 9427 |
# File 'lib/kettle/jem.rb', line 9419 def main_gemfile_recording_insertion_index(content) lines = content.to_s.lines call = ruby_call_records(content, :eval_gemfile).find do |candidate| ruby_string_argument(candidate).to_s == "gemfiles/modular/style.gemfile" end return unless call gemfile_eval_comment_start_line(lines, call.location.start_line) - 1 end |
.main_gemfile_templating_eval_line(content) ⇒ Object
8231 8232 8233 8234 8235 8236 8237 |
# File 'lib/kettle/jem.rb', line 8231 def main_gemfile_templating_eval_line(content) ruby_call_records(content, :eval_gemfile).filter_map do |call| next unless ruby_string_argument(call) == "gemfiles/modular/templating.gemfile" call.location.start_line end.min end |
.managed_license_template_basename(target_path) ⇒ Object
18710 18711 18712 18713 18714 18715 18716 18717 18718 |
# File 'lib/kettle/jem.rb', line 18710 def managed_license_template_basename(target_path) path = target_path.to_s return unless path.end_with?(".md") basename = File.basename(path, ".md") return if NON_LICENSE_MD_BASENAMES.include?(basename) known_license_template_basenames.include?(basename) ? basename : nil end |
.managed_version_gem_version_spec?(content) ⇒ Boolean
15827 15828 15829 15830 |
# File 'lib/kettle/jem.rb', line 15827 def managed_version_gem_version_spec?(content) content.to_s.include?('it_behaves_like "a Version module"') || version_spec_anonymous_loader_call?(content) end |
.markdown_heading_has_preserved_readme_ancestor?(heading_sections, index) ⇒ Boolean
7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 |
# File 'lib/kettle/jem.rb', line 7684 def markdown_heading_has_preserved_readme_ancestor?(heading_sections, index) owner = heading_sections.fetch(index) ancestor_level = owner.level.to_i heading_sections[0...index].reverse_each do |candidate| next unless candidate.level.to_i < ancestor_level return true if README_DEFAULT_PRESERVE_SECTIONS.include?(candidate.base.to_s) ancestor_level = candidate.level.to_i end false end |
.markdown_heading_owners(content, source_label: "README.md") ⇒ Object
7814 7815 7816 7817 7818 7819 7820 |
# File 'lib/kettle/jem.rb', line 7814 def markdown_heading_owners(content, source_label: "README.md") ensure_runtime_dependencies! context = Ast::Crispr::Markdown::Markly.document_context(content: content.to_s, source_label: source_label) context.structural_owners(owner_scope: :heading_sections) rescue Ast::Crispr::Error [] end |
.markdown_link_definition_source(owner, url) ⇒ Object
7764 7765 7766 7767 7768 |
# File 'lib/kettle/jem.rb', line 7764 def markdown_link_definition_source(owner, url) source = "[#{owner.label}]: #{url}" source = "#{source} #{owner.title.dump}" if owner.title "#{source}\n" end |
.markdown_link_reference_definition_line?(line) ⇒ Boolean
6160 6161 6162 |
# File 'lib/kettle/jem.rb', line 6160 def markdown_link_reference_definition_line?(line) line.to_s.lstrip.start_with?("[") && line.to_s.include?("]:") end |
.markdown_managed_block(content, marker) ⇒ Object
18152 18153 18154 18155 18156 18157 18158 18159 18160 18161 18162 18163 18164 |
# File 'lib/kettle/jem.rb', line 18152 def markdown_managed_block(content, marker) ensure_runtime_dependencies! open = "<!-- #{marker}:start -->" close = "<!-- #{marker}:end -->" context = Ast::Crispr::Markdown::Markly.document_context(content: content.to_s, source_label: "managed markdown block") target = Ast::Crispr::Markdown::Markly::Selectors.html_comment_block( start_text: open.delete_prefix("<!-- ").delete_suffix(" -->"), end_text: close.delete_prefix("<!-- ").delete_suffix(" -->"), span: :outermost, limit: {none_or_one: true} ) target.locate_matches(context).first&.slice_from(content.to_s) end |
.markdown_sections(content) ⇒ Object
18166 18167 18168 18169 18170 18171 18172 18173 18174 18175 18176 18177 18178 18179 18180 18181 18182 |
# File 'lib/kettle/jem.rb', line 18166 def markdown_sections(content) lines = content.to_s.split("\n", -1) markdown_heading_owners(content, source_label: "README.md").map do |owner| start = owner.location.start_line - 1 branch_end = owner.location.end_line - 1 body = (lines[(start + 1)..branch_end] || []).join("\n") { start: start, level: owner.level, heading: owner.heading_source, heading_text: owner.heading_text, base: owner.base, end: branch_end, body: body } end end |
.markdown_source_lines(content) ⇒ Object
6126 6127 6128 |
# File 'lib/kettle/jem.rb', line 6126 def markdown_source_lines(content) content.to_s.split("\n") end |
.merge_appraisal_blocks_with_prism(template_block, destination_block) ⇒ Object
10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 |
# File 'lib/kettle/jem.rb', line 10459 def merge_appraisal_blocks_with_prism(template_block, destination_block) result = Prism::Merge.merge_ruby( template_block, destination_block, "ruby", preference: :destination, add_template_only_nodes: true, signature_generator: Prism::Merge.ruby_dsl_signature_generator, method_move_policy: ruby_method_move_policy({}), merge_template_requires: true, template_only_placement: :after_anchor ) result[:ok] ? result.fetch(:output) : template_block end |
.merge_appraisals_template_policy(content, facts:) ⇒ Object
10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 |
# File 'lib/kettle/jem.rb', line 10127 def merge_appraisals_template_policy(content, facts:) package_name = facts.dig(:package, :name).to_s if facts min_ruby = minimum_ruby_token(facts.dig(:ci, :test_min_ruby) || facts.dig(:rubygems, :min_ruby)) if facts with_framework_appraisals = merge_framework_matrix_appraisals(content, facts) with_standard_appraisal_gemfiles = inject_standard_appraisal_gemfiles(with_framework_appraisals, facts) pruned = prune_appraisals_recording_entries(with_standard_appraisal_gemfiles, facts) pruned = prune_appraisals_below_min_ruby(pruned, min_ruby) pruned = remove_managed_stdlib_appraisal_gems(pruned) pruned = migrate_legacy_byebug_appraisal_dependencies(pruned) pruned = remove_gemfile_dependency_lines(pruned, [package_name]) remove_gemfile_percent_w_entries(pruned, [package_name]) end |
.merge_bash_template_source(template_content, destination_content, recipe) ⇒ Object
10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 |
# File 'lib/kettle/jem.rb', line 10435 def merge_bash_template_source(template_content, destination_content, recipe) availability = Bash::Merge.availability(source: template_content.to_s) unless availability.available? return { ok: false, output: destination_content, diagnostics: [{ kind: "bash_merge_unavailable", message: "bash structural merge is unavailable because TreeHaver node parser support for Bash is not available", details: availability.diagnostics }] } end output = Bash::Merge::SmartMerger.new( template_content, destination_content, **(recipe) ).merge {ok: true, output: output, diagnostics: []} rescue Bash::Merge::Error => e {ok: false, output: destination_content, diagnostics: [{kind: "bash_merge_failed", message: e.}]} end |
.merge_changelog_template_source(template_content, destination_content, facts: nil) ⇒ Object
6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 |
# File 'lib/kettle/jem.rb', line 6077 def merge_changelog_template_source(template_content, destination_content, facts: nil) destination = normalize_legacy_changelog_release_headings(destination_content.to_s) if destination.strip.empty? return apply_changelog_transfer_entries( ensure_trailing_newline(template_content.to_s), facts.to_h.dig(:changelog, :transfer_entries), excluded_keys: facts.to_h.dig(:changelog, :excluded_transfer_keys) ) end template_lines = markdown_source_lines(template_content) template_unreleased = changelog_unreleased_line_index(template_lines) unless template_unreleased return apply_changelog_transfer_entries( ensure_trailing_newline(template_content.to_s), facts.to_h.dig(:changelog, :transfer_entries), excluded_keys: facts.to_h.dig(:changelog, :excluded_transfer_keys) ) end destination_lines = markdown_source_lines(destination) destination_unreleased = changelog_unreleased_line_index(destination_lines) unless destination_unreleased header = changelog_template_header(template_lines, template_unreleased).join("\n") return apply_changelog_transfer_entries( ensure_trailing_newline("#{header}\n\n#{destination}"), facts.to_h.dig(:changelog, :transfer_entries), excluded_keys: facts.to_h.dig(:changelog, :excluded_transfer_keys) ) end destination_end = changelog_unreleased_end_index(destination_lines, destination_unreleased) destination_body = destination_lines[(destination_unreleased + 1)...destination_end] || [] canonical = build_changelog_unreleased_section( template_lines.fetch(template_unreleased), changelog_unreleased_items(destination_body) ) header = changelog_template_header(template_lines, template_unreleased) merged_lines = header + (header.empty? ? [] : [""]) + canonical + destination_lines[destination_end..].to_a apply_changelog_transfer_entries( ensure_trailing_newline(merged_lines.join("\n").gsub(/\n{3,}/, "\n\n")), facts.to_h.dig(:changelog, :transfer_entries), excluded_keys: facts.to_h.dig(:changelog, :excluded_transfer_keys) ) end |
.merge_config_template_source(recipe, template_content, destination_content, facts: nil, env: ENV) ⇒ Object
7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 |
# File 'lib/kettle/jem.rb', line 7901 def merge_config_template_source(recipe, template_content, destination_content, facts: nil, env: ENV) file_type = template_file_type(recipe) if destination_content.to_s.strip.empty? if file_type == :gemfile return finalize_gemfile_template_source(recipe, template_content, destination_content, facts: facts, template_content: template_content) end return merge_appraisals_template_policy(template_content, facts: facts) if file_type == :appraisals return finalize_github_workflow_template(prune_github_workflow_matrix_by_min_ruby(template_content, facts), facts) if github_workflow_template_recipe?(recipe) return template_content end if destination_content == template_content if file_type == :gemfile return finalize_gemfile_template_source(recipe, destination_content, destination_content, facts: facts, template_content: template_content) end return merge_appraisals_template_policy(destination_content, facts: facts) if file_type == :appraisals return destination_content end case file_type when :gitignore return merge_gitignore_template_source(template_content, destination_content) when :gemspec return merge_gemspec_template_source(template_content, destination_content, facts: facts, env: env) when :ruby, :gemfile, :rakefile, :appraisals merge_destination = if recipe.fetch(:target_path).to_s == ".simplecov" normalize_simplecov_template_source(destination_content) else destination_content end merge_result = merge_ruby_template_source(file_type, recipe, template_content, merge_destination, facts: facts) when :yaml merge_result = Psych::Merge.merge_yaml( template_content, destination_content, "yaml", **(recipe) ) when :toml merge_result = Citrus::Toml::Merge.merge_toml(template_content, destination_content, "toml") when :json, :jsonc, :json5 merge_result = merge_json_template_source(template_content, destination_content, recipe, file_type) when :markdown return merge_changelog_template_source(template_content, destination_content, facts: facts) if recipe.fetch(:target_path) == "CHANGELOG.md" return template_content when :dotenv merge_result = merge_dotenv_template_source(template_content, destination_content, recipe) when :rbs merge_result = merge_rbs_template_source(template_content, destination_content, recipe) when :bash merge_result = merge_bash_template_source(template_content, destination_content, recipe) else return template_content end if merge_result[:ok] output = merge_result.fetch(:output) if file_type == :gemfile output = merge_gemfile_eval_bucket_entries(template_content, output, destination_content: destination_content) return finalize_gemfile_template_source(recipe, output, destination_content, facts: facts, template_content: template_content) end return merge_appraisals_template_policy(output, facts: facts) if file_type == :appraisals output = finalize_github_workflow_template(prune_github_workflow_matrix_by_min_ruby(output, facts), facts) if github_workflow_template_recipe?(recipe) output = normalize_simplecov_template_source(output) if recipe.fetch(:target_path).to_s == ".simplecov" output = normalize_spec_helper_simplecov_template_source(output) if recipe.fetch(:target_path).to_s == "spec/spec_helper.rb" output = normalize_spec_helper_block_bindings(output, template_content) if recipe.fetch(:target_path).to_s == "spec/spec_helper.rb" return output end raise adapter_failure_template_source_error(file_type, recipe) if process_result_adapter_failure?(merge_result) return template_content if github_workflow_template_recipe?(recipe) diagnostics = merge_result.fetch(:diagnostics, []) = diagnostics.map { |diagnostic| diagnostic[:message] || diagnostic["message"] }.compact.join("; ") raise ArgumentError, "failed to merge #{file_type} template #{recipe.fetch(:target_path)}: #{}" end |
.merge_dotenv_template_source(template_content, destination_content, recipe) ⇒ Object
10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 |
# File 'lib/kettle/jem.rb', line 10387 def merge_dotenv_template_source(template_content, destination_content, recipe) output = Dotenv::Merge::SmartMerger.new( template_content, destination_content, **(recipe) ).merge {ok: true, output: output, diagnostics: []} rescue Dotenv::Merge::Error => e {ok: false, output: destination_content, diagnostics: [{kind: "dotenv_merge_failed", message: e.}]} end |
.merge_framework_matrix_appraisals(content, facts) ⇒ Object
10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 |
# File 'lib/kettle/jem.rb', line 10286 def merge_framework_matrix_appraisals(content, facts) entries = facts.to_h.dig(:ci, :framework_matrix, :appraisals).to_a return content if entries.empty? generated = entries.to_h do |entry| [entry.fetch(:name).to_s, framework_matrix_appraisal_block(entry)] end entries_by_name = entries.to_h { |entry| [entry.fetch(:name).to_s, entry] } replaced = entries.flat_map { |entry| entry.fetch(:replaces, []) }.map(&:to_s).to_set parsed = appraisal_blocks(content) emitted = Set.new blocks = parsed.fetch(:order).map do |name| next if replaced.include?(name) && !generated.key?(name) emitted << name parsed_block = parsed.fetch(:blocks).fetch(name).rstrip generated_block = generated[name] if generated_block && !entries_by_name.fetch(name).fetch(:standard_appraisal, false) generated_block elsif generated_block merge_appraisal_blocks_with_prism(generated_block, parsed_block) else parsed_block end end.compact entries.each do |entry| name = entry.fetch(:name).to_s next if emitted.include?(name) blocks << generated.fetch(name) end ensure_trailing_newline(([parsed.fetch(:prelude).to_s.rstrip] + blocks).reject(&:empty?).join("\n\n")) end |
.merge_gemfile_eval_bucket_entries(template_content, merged_content, destination_content: nil) ⇒ Object
10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 |
# File 'lib/kettle/jem.rb', line 10033 def merge_gemfile_eval_bucket_entries(template_content, merged_content, destination_content: nil) template_entries = gemfile_eval_bucket_entries(template_content) template_by_key = template_entries.to_h { |entry| [entry.fetch(:key), entry] } destination_entries = gemfile_eval_bucket_entries(destination_content) destination_only_entries = destination_entries.reject { |entry| template_by_key.key?(entry.fetch(:key)) } return merged_content if template_entries.empty? && destination_only_entries.empty? emitted_paths = Set.new insert_at = nil lines = [] merged_lines = merged_content.to_s.lines merged_entries_by_line = gemfile_eval_bucket_entries(merged_content).to_h { |entry| [entry.fetch(:start_line), entry] } skip_until = 0 merged_lines.each_with_index do |line, index| line_number = index + 1 next if line_number < skip_until entry = merged_entries_by_line[line_number] unless entry && template_by_key.key?(entry.fetch(:key)) lines << line next end template_entry = template_by_key.fetch(entry.fetch(:key)) if entry.fetch(:path) == template_entry.fetch(:path) lines << entry.fetch(:line) unless emitted_paths.include?(entry.fetch(:path)) emitted_paths << entry.fetch(:path) else insert_at ||= lines.length end skip_until = entry.fetch(:end_line) + 1 end existing_paths = gemfile_eval_bucket_entries(lines.join).map { |entry| entry.fetch(:path) }.to_set wanted_entries = template_entries + destination_only_entries missing_lines = wanted_entries .reject { |entry| emitted_paths.include?(entry.fetch(:path)) || existing_paths.include?(entry.fetch(:path)) } .map { |entry| entry.fetch(:section_line) } return ensure_trailing_newline(lines.join) if missing_lines.empty? insert_at ||= lines.length lines[insert_at, 0] = missing_lines ensure_trailing_newline(lines.join.gsub(/\n{3,}/, "\n\n")) end |
.merge_gemfile_template_policy(content, facts:, template_content: nil, preserve_self_word_entries: false) ⇒ Object
9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 |
# File 'lib/kettle/jem.rb', line 9350 def merge_gemfile_template_policy(content, facts:, template_content: nil, preserve_self_word_entries: false) package_name = facts.dig(:package, :name).to_s if facts removable_gems = ["appraisal"] removable_gems << package_name unless package_name.to_s.empty? removable_gems.concat(package_runtime_dependency_names(facts)) removable_gems << "version_gem" unless version_gem_enabled?(facts) pruned = remove_gemfile_dependency_blocks(content, removable_gems) pruned = remove_gemfile_percent_w_entries(pruned, [package_name]) unless preserve_self_word_entries pruned = merge_template_gemfile_dependency_blocks( template_content, pruned, removable_gems, preserve_self_word_entries: preserve_self_word_entries ) apply_commented_gem_dependency_policy(template_content, pruned) end |
.merge_gemspec_files_assignment(content, template_content:, destination_content:, template_receiver:, destination_receiver:) ⇒ Object
11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 |
# File 'lib/kettle/jem.rb', line 11131 def merge_gemspec_files_assignment(content, template_content:, destination_content:, template_receiver:, destination_receiver:) merged_record = gemspec_assignment_records(content, receiver: template_receiver).find { |record| record.fetch(:field) == "files" } template_record = gemspec_assignment_records(template_content, receiver: template_receiver).find { |record| record.fetch(:field) == "files" } destination_record = gemspec_assignment_records(destination_content, receiver: destination_receiver).find { |record| record.fetch(:field) == "files" } return content unless merged_record && template_record && destination_record replacement = merge_gemspec_files_assignment_source( merged_record: merged_record, template_record: template_record, destination_record: destination_record ) replacement ||= replacement_for_supported_gemspec_files_assignment( template_record: template_record, destination_record: destination_record, template_receiver: template_receiver ) unless replacement raise Error, "Unsupported gemspec spec.files assignment; kettle-jem requires an AST-mergeable Array, Dir[], or known Bundler git-ls-files assignment" end replace_source_range_lines(content, merged_record.fetch(:start_line), merged_record.fetch(:end_line), replacement) end |
.merge_gemspec_files_assignment_source(merged_record:, template_record:, destination_record:) ⇒ Object
11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 |
# File 'lib/kettle/jem.rb', line 11172 def merge_gemspec_files_assignment_source(merged_record:, template_record:, destination_record:) merged_parts = gemspec_files_collection_parts(merged_record) template_parts = gemspec_files_collection_parts(template_record) destination_parts = gemspec_files_collection_parts(destination_record) return unless merged_parts && template_parts && destination_parts if gemspec_files_collection_has_nonliteral_entries?(destination_parts) return merge_gemspec_files_assignment_with_destination_splats( merged_parts: merged_parts, destination_parts: destination_parts ) end combined_groups = [] seen = {} destination_groups = destination_parts.fetch(:groups).reject do |group| stale_generated_gemspec_files_group?(group) || (group, template_parts) end merged_groups = merged_parts.fetch(:groups).reject do |group| (group, merged_parts) end [ [destination_parts, destination_groups], [merged_parts, merged_groups], [template_parts, template_parts.fetch(:groups)] ].each do |parts, groups| groups.each do |group| next if seen[group.fetch(:key)] combined_groups << group.merge(source_collection_kind: gemspec_files_group_collection_kind(group, parts)) seen[group.fetch(:key)] = true end end combined_groups = gemspec_files_normalize_dir_globs_for_array(combined_groups, merged_parts) if gemspec_files_collection_needs_concat?(merged_parts, combined_groups) return gemspec_files_concat_collection_source(merged_parts, combined_groups) end body = combined_groups.each_with_index.map do |group, index| gemspec_files_collection_group_source(group, trailing_comma: index < combined_groups.length - 1) end.join merged_parts.fetch(:opening) + body + merged_parts.fetch(:closing) end |
.merge_gemspec_files_assignment_with_destination_splats(merged_parts:, destination_parts:) ⇒ Object
11289 11290 11291 11292 11293 11294 11295 11296 11297 11298 11299 11300 11301 11302 11303 11304 11305 11306 11307 11308 11309 11310 11311 11312 11313 11314 11315 11316 11317 11318 11319 11320 11321 11322 11323 11324 11325 11326 11327 11328 |
# File 'lib/kettle/jem.rb', line 11289 def merge_gemspec_files_assignment_with_destination_splats(merged_parts:, destination_parts:) return unless %i[array concat].include?(destination_parts.fetch(:collection_kind)) merged_keys = merged_parts.fetch(:groups).map { |group| group.fetch(:key) }.to_set destination_groups = destination_parts.fetch(:groups).reject do |group| stale_generated_gemspec_files_group?(group) || (group, merged_parts) end destination_only_nonliteral = destination_groups.any? do |group| !group.fetch(:node).is_a?(::Prism::StringNode) && !merged_keys.include?(group.fetch(:key)) && !supported_gemspec_files_nonliteral_group?(group) end return if destination_only_nonliteral destination_groups_by_key = destination_groups.to_h do |group| [group.fetch(:key), group.merge(source_collection_kind: gemspec_files_group_collection_kind(group, destination_parts))] end seen = Set.new merged_groups = merged_parts.fetch(:groups).reject do |group| (group, merged_parts) end groups = merged_groups.map do |group| key = group.fetch(:key) seen << key destination_groups_by_key.fetch(key, group.merge(source_collection_kind: gemspec_files_group_collection_kind(group, merged_parts))) end destination_groups.each do |group| next if seen.include?(group.fetch(:key)) groups << group.merge(source_collection_kind: gemspec_files_group_collection_kind(group, destination_parts)) end groups = gemspec_files_normalize_dir_globs_for_array(groups, merged_parts) if gemspec_files_collection_needs_concat?(merged_parts, groups) return gemspec_files_concat_collection_source(merged_parts, groups) end gemspec_files_array_collection_source(merged_parts, groups) end |
.merge_gemspec_template_source(template_content, destination_content, facts: nil, env: ENV) ⇒ Object
10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 |
# File 'lib/kettle/jem.rb', line 10534 def merge_gemspec_template_source(template_content, destination_content, facts: nil, env: ENV) template_receiver = gemspec_block_param(template_content) || "spec" destination_receiver = gemspec_block_param(destination_content) || "spec" package_name = facts.dig(:package, :name).to_s if facts replacements = gemspec_preserved_assignments(destination_content, receiver: destination_receiver) .except(*env_overridden_gemspec_fields(env)) replacements = remove_stale_generated_gemspec_homepage_replacement( replacements, destination_content, facts, receiver: destination_receiver ) normalized_replacements = replacements.to_h do |field, source| replacement = normalize_gemspec_receiver(source.rstrip, from: destination_receiver, to: template_receiver) [field, normalize_gemspec_project_emoji(replacement, facts, field: field)] end merged = replace_gemspec_assignment_sources(template_content, normalized_replacements, receiver: template_receiver) merged = insert_missing_gemspec_assignment_sources(merged, normalized_replacements, receiver: template_receiver) merged = normalize_gemspec_package_helper_assignments(merged, template_content) merged = merge_gemspec_files_assignment( merged, template_content: template_content, destination_content: destination_content, template_receiver: template_receiver, destination_receiver: destination_receiver ) merged = insert_missing_gemspec_files_assignment( merged, template_content: template_content, template_receiver: template_receiver ) merged = remove_gemspec_assignment(merged, receiver: template_receiver, field: "extra_rdoc_files") merged = preserve_gemspec_dependency_lines( merged, destination_content, template_receiver: template_receiver, destination_receiver: destination_receiver, facts: facts ) merged = preserve_gemspec_freeze_blocks(merged, destination_content, facts: facts, receiver: template_receiver) merged = apply_configured_gemspec_licenses(merged, facts, receiver: template_receiver) merged = apply_configured_gemspec_required_ruby_version(merged, facts, receiver: template_receiver) merged = (merged, facts, receiver: template_receiver) merged = ( merged, template_content: template_content, destination_content: destination_content, template_receiver: template_receiver, destination_receiver: destination_receiver ) merged = remove_duplicate_gemspec_assignments(merged, receiver: template_receiver, fields: %w[homepage]) merged = remove_gemspec_self_dependency_lines(merged, package_name, receiver: template_receiver) merged = remove_gemspec_version_gem_dependency_when_disabled( merged, facts, receiver: template_receiver, template_declares_version_gem: gemspec_dependency_names(template_content).include?("version_gem") ) merged = remove_gemspec_version_gem_dependency_when_non_default_entrypoint(merged, facts, receiver: template_receiver) # Yard owns the documentation dependency graph. A direct gemspec rdoc # development dependency creates an unnecessary second owner and can # conflict with the documentation modular Gemfile. merged = remove_gemspec_dependency_lines(merged, receiver: template_receiver, names: ["rdoc"], development_only: true) merged = remove_gemspec_development_dependencies_already_runtime(merged, receiver: template_receiver) merged = remove_duplicate_gemspec_dependency_lines(merged, receiver: template_receiver) merged = remove_empty_gemspec_development_dependency_section_headings(merged, receiver: template_receiver) merged = sort_runtime_gemspec_dependency_lines(merged, receiver: template_receiver) rewrite_gemspec_version_loader(merged, facts: facts) end |
.merge_gitignore_template_source(template_content, destination_content) ⇒ Object
12324 12325 12326 12327 12328 12329 12330 12331 12332 12333 12334 12335 12336 12337 12338 12339 12340 12341 12342 12343 12344 12345 12346 12347 12348 12349 12350 12351 12352 12353 12354 12355 12356 |
# File 'lib/kettle/jem.rb', line 12324 def merge_gitignore_template_source(template_content, destination_content) # Git ignore files have no parser-backed AST. Treat each non-comment line # as a rule node, retain destination order and comments, and append only # template rules that the destination does not already declare. destination_rules = destination_content.lines.map(&:strip).reject { |line| line.empty? || line.start_with?("#") }.to_set additions = [] pending_comments = [] template_content.lines.each do |line| stripped = line.strip if stripped.empty? pending_comments << line unless pending_comments.empty? next end if stripped.start_with?("#") pending_comments << line next end next if destination_rules.include?(stripped) additions.concat(pending_comments) additions << line destination_rules << stripped pending_comments = [] end return destination_content if additions.empty? output = destination_content.dup output << "\n" unless output.empty? || output.end_with?("\n\n") output << additions.join ensure_trailing_newline(output) end |
.merge_json_template_source(template_content, destination_content, recipe, file_type) ⇒ Object
10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 |
# File 'lib/kettle/jem.rb', line 10362 def merge_json_template_source(template_content, destination_content, recipe, file_type) output = Json::Merge::SmartMerger.new( template_content, destination_content, dialect: file_type, **(recipe) ).merge {ok: true, output: output, diagnostics: []} rescue Json::Merge::Error => e {ok: false, output: destination_content, diagnostics: [{kind: "#{file_type}_merge_failed", message: e.}]} end |
.merge_local_gem_overrides(content, destination_content, facts:, template_content: nil) ⇒ Object
8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 |
# File 'lib/kettle/jem.rb', line 8988 def merge_local_gem_overrides(content, destination_content, facts:, template_content: nil) template_gems = local_gems_assignment(content) template_gems = local_gems_assignment(template_content) if template_gems.empty? destination_gems = local_gems_assignment(destination_content) return content if template_gems.empty? && destination_gems.empty? destination_gems = destination_gems.reject do |destination_gem| template_gems.any? { |template_gem| versioned_gem_name_update_candidate?(destination_gem, template_gem) } end gems = (template_gems + destination_gems).map(&:to_s).reject(&:empty?).uniq replace_local_gems_assignment(content, gems) end |
.merge_prism_gemfile_template_source(template_content, destination_content) ⇒ Object
9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 |
# File 'lib/kettle/jem.rb', line 9318 def merge_prism_gemfile_template_source(template_content, destination_content) Prism::Merge.merge_ruby( template_content, destination_content, "ruby", preference: :template, add_template_only_nodes: true, signature_generator: Prism::Merge.ruby_dsl_signature_generator ) end |
.merge_rbs_signature_sources(template_content, destination_content) ⇒ Object
15927 15928 15929 15930 15931 15932 15933 15934 15935 15936 |
# File 'lib/kettle/jem.rb', line 15927 def merge_rbs_signature_sources(template_content, destination_content) return ensure_trailing_newline(template_content) if destination_content.to_s.strip.empty? result = merge_rbs_template_source( ensure_trailing_newline(template_content), ensure_trailing_newline(destination_content), {template_preference: {preference: "destination"}} ) result.fetch(:ok) ? result.fetch(:output) : ensure_trailing_newline(destination_content) end |
.merge_rbs_template_source(template_content, destination_content, recipe) ⇒ Object
10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 |
# File 'lib/kettle/jem.rb', line 10411 def merge_rbs_template_source(template_content, destination_content, recipe) output = Rbs::Merge::SmartMerger.new( template_content, destination_content, **(recipe) ).merge {ok: true, output: output, diagnostics: []} rescue Rbs::Merge::Error => e {ok: false, output: destination_content, diagnostics: [{kind: "rbs_merge_failed", message: e.}]} end |
.merge_readme_template(template_content:, destination_content:, preserve_config: {}) ⇒ Object
18023 18024 18025 18026 18027 18028 18029 18030 |
# File 'lib/kettle/jem.rb', line 18023 def merge_readme_template(template_content:, destination_content:, preserve_config: {}) return template_content if destination_content.to_s.strip.empty? with_front_sections = preserve_readme_front_sections(template_content, destination_content) preserved = preserve_readme_sections(with_front_sections, destination_content, preserve_config) with_h1 = preserve_readme_h1(preserved, destination_content, preserve_config) preserve_readme_managed_block(with_h1, destination_content, "kettle-jem:metadata") end |
.merge_ruby_template_source(file_type, recipe, template_content, destination_content, facts: nil) ⇒ Object
9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 |
# File 'lib/kettle/jem.rb', line 9296 def merge_ruby_template_source(file_type, recipe, template_content, destination_content, facts: nil) return merge_prism_gemfile_template_source(template_content, destination_content) if file_type == :gemfile template_preference = recipe.fetch(:template_preference, {}) preference = (template_preference[:preference] || "destination").to_sym add_template_only_nodes = true unless template_preference[:add_template_only_nodes].nil? configured = DecisionPolicy.value_to_boolean(template_preference[:add_template_only_nodes]) add_template_only_nodes = configured unless configured.nil? end Prism::Merge.merge_ruby( template_content, destination_content, "ruby", preference: preference, add_template_only_nodes: add_template_only_nodes, signature_generator: Prism::Merge.ruby_dsl_signature_generator(require_aliases: ruby_require_aliases(recipe, facts)), **(recipe) ) end |
.merge_template_gemfile_dependency_blocks(template_content, content, removable_gems, preserve_self_word_entries: false) ⇒ Object
9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 |
# File 'lib/kettle/jem.rb', line 9437 def merge_template_gemfile_dependency_blocks(template_content, content, removable_gems, preserve_self_word_entries: false) template = remove_gemfile_dependency_blocks(template_content, removable_gems) template = remove_gemfile_percent_w_entries(template, removable_gems) unless preserve_self_word_entries existing = gemfile_dependency_names(content) + gemfile_percent_w_names(content) additions = gemfile_paragraphs(template).filter_map do |paragraph| names = gemfile_dependency_names(paragraph) + gemfile_percent_w_names(paragraph) next if names.empty? next if (names - existing).empty? paragraph end return content if additions.empty? insert_gemfile_dependency_blocks(content, additions) end |
.metadata_value(metadata, key) ⇒ Object
15343 15344 15345 15346 15347 15348 15349 |
# File 'lib/kettle/jem.rb', line 15343 def (, key) value = [key] return if value.nil? text = value.to_s.strip text unless text.empty? end |
.migrate_legacy_byebug_appraisal_dependencies(content) ⇒ Object
Each appraisal has an independent dependency set. Reuse the AST-based Gemfile migration per block so every legacy byebug/pry-byebug pair is replaced by one debug declaration in that same appraisal.
10143 10144 10145 10146 10147 10148 10149 |
# File 'lib/kettle/jem.rb', line 10143 def migrate_legacy_byebug_appraisal_dependencies(content) parsed = appraisal_blocks(content) blocks = parsed.fetch(:order).map do |name| migrate_legacy_byebug_pair(parsed.fetch(:blocks).fetch(name)) end ensure_trailing_newline(([parsed.fetch(:prelude).to_s.rstrip] + blocks.map(&:rstrip)).reject(&:empty?).join("\n\n")) end |
.migrate_legacy_byebug_pair(content) ⇒ Object
8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 |
# File 'lib/kettle/jem.rb', line 8061 def migrate_legacy_byebug_pair(content) records = gemfile_gem_call_records(content) obsolete = records.select { |record| record.fetch(:name).include?("byebug") } return content if obsolete.empty? first = obsolete.min_by { |record| record.fetch(:start_line) } replacement = "#{content.to_s.lines.fetch(first.fetch(:start_line) - 1)[/\A\s*/]}gem \"debug\", require: false\n" replacements = obsolete.to_h do |record| source = (record == first) ? replacement : "" [record.fetch(:start_line), record.merge(replacement: source)] end replace_record_ranges(content, replacements) end |
.migrate_legacy_byebug_requires(content) ⇒ Object
The Gemfile migration replaces every byebug-family dependency with debug. Keep the runnable spec helper consistent with that dependency graph: a stale require "byebug" otherwise makes a successfully templated project fail before its examples load.
8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 |
# File 'lib/kettle/jem.rb', line 8493 def migrate_legacy_byebug_requires(content) debug_records = ruby_call_records(content, :require).filter_map do |call| next unless call.receiver.nil? && ruby_string_argument(call) == "debug" line = content.to_s.lines.fetch(call.location.start_line - 1, "") next unless line.strip == call.location.slice.strip { start_line: call.location.start_line, end_line: ruby_node_source_end_line(call), source: call.location.slice } end records = ruby_call_records(content, :require).filter_map do |call| next unless call.receiver.nil? name = ruby_string_argument(call).to_s next unless name.include?("byebug") { start_line: call.location.start_line, end_line: ruby_node_source_end_line(call), source: call.location.slice } end.sort_by { |record| record.fetch(:start_line) } return normalize_debug_require_records(content, debug_records) if records.empty? debug_already_required = !debug_records.empty? first = records.first replacements = records.to_h do |record| replacement = if record.equal?(first) && !debug_already_required indent = content.to_s.lines.fetch(record.fetch(:start_line) - 1)[/\A\s*/] %(#{indent}#{guarded_debug_require}\n) else "" end [record.fetch(:start_line), record.merge(replacement: replacement)] end normalize_debug_require_records(replace_record_ranges(content, replacements), debug_records) end |
.migrate_readme_logo_config(content) ⇒ Object
12508 12509 12510 12511 12512 12513 12514 12515 12516 12517 12518 12519 12520 12521 12522 12523 12524 12525 12526 12527 12528 12529 12530 12531 12532 12533 12534 12535 12536 12537 12538 12539 12540 12541 12542 |
# File 'lib/kettle/jem.rb', line 12508 def migrate_readme_logo_config(content) config = YAML.safe_load(content.to_s, permitted_classes: [], aliases: true) || {} readme_config = config["readme"] return content unless readme_config.is_a?(Hash) configured_specs = normalized_readme_logo_specs(readme_config["top_logos"] || readme_config["top_logo_options"]) legacy_mode_migrated = configured_specs.empty? if legacy_mode_migrated = (readme_config["top_logo_mode"]) configured_specs = .map { |option| {type: option, width: nil} } end configured = configured_specs.map { |spec| spec.fetch(:type) } return content if configured.empty? top_logo_specs = configured_specs.select { |spec| README_TOP_LOGO_DEFAULTS.include?(spec.fetch(:type)) } h2_synopsis_logo_specs = normalized_readme_logo_specs(readme_config["h2_synopsis_logos"]) h2_synopsis_logo_specs = configured_specs.select { |spec| README_H2_SYNOPSIS_LOGO_DEFAULTS.include?(spec.fetch(:type)) } if h2_synopsis_logo_specs.empty? if legacy_mode_migrated && h2_synopsis_logo_specs.empty? h2_synopsis_logo_specs = README_H2_SYNOPSIS_LOGO_DEFAULTS.map { |option| {type: option, width: nil} } end top_logos = top_logo_specs.map { |spec| readme_logo_config_value(spec) } h2_synopsis_logos = h2_synopsis_logo_specs.map { |spec| readme_logo_config_value(spec) } return content if h2_synopsis_logos.empty? && top_logos == configured migrated = if readme_config.key?("top_logos") replace_yaml_scalar_path(content, %w[readme top_logos], top_logos.join(",")) else insert_yaml_scalar_after_path(content, %w[readme], "top_logos", top_logos.join(",")) end return replace_yaml_scalar_path(migrated, %w[readme h2_synopsis_logos], h2_synopsis_logos.join(",")) if readme_config.key?("h2_synopsis_logos") insert_yaml_scalar_after_path(migrated, %w[readme top_logos], "h2_synopsis_logos", h2_synopsis_logos.join(",")) rescue Psych::Exception content end |
.migrate_simplecov_start_configuration(content) ⇒ Object
SimpleCov.start was historically used as both configuration and startup. The generated spec helper now owns startup, but a destination's block can contain project-specific filters and formatters that must survive.
8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 |
# File 'lib/kettle/jem.rb', line 8417 def migrate_simplecov_start_configuration(content) result = prism_parse_success(content) return content unless result replacements = [] result.value.breadth_first_search_all do |node| next unless simplecov_start_call_node?(node) && node.block replacements << { start_offset: node..start_offset, end_offset: node..end_offset, replacement: "configure" } end replace_source_offsets(content, replacements) end |
.min_ruby_version(requirement) ⇒ Object
17397 17398 17399 17400 17401 17402 17403 17404 |
# File 'lib/kettle/jem.rb', line 17397 def min_ruby_version(requirement) token = minimum_ruby_token(requirement) return if token.empty? Gem::Version.new(token) rescue ArgumentError nil end |
.minimum_ruby_token(requirement) ⇒ Object
14634 14635 14636 14637 14638 14639 |
# File 'lib/kettle/jem.rb', line 14634 def minimum_ruby_token(requirement) text = requirement.to_s.strip return "0" if text == "0" requirement.to_s[/\d+(?:\.\d+){1,2}/].to_s end |
.mit_readme_license_intro(license_source_url: nil) ⇒ Object
17560 17561 17562 17563 |
# File 'lib/kettle/jem.rb', line 17560 def mit_readme_license_intro(license_source_url: nil) "The gem is available as open source under the terms of\n" \ "the #{license_link("MIT", license_source_url: license_source_url)} #{license_badge("MIT")}." end |
.mkdir_p_core(path) ⇒ Object
14009 14010 14011 14012 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 14023 14024 14025 14026 |
# File 'lib/kettle/jem.rb', line 14009 def mkdir_p_core(path) dir = path.to_s return if dir.empty? || dir == "." || Dir.exist?(dir) pending = [] until dir.empty? || dir == "." || Dir.exist?(dir) pending << dir parent = File.dirname(dir) break if parent == dir dir = parent end pending.reverse_each do |entry| Dir.mkdir(entry) unless Dir.exist?(entry) rescue Errno::EEXIST nil end end |
.modular_dependency_conflict_decided?(decisions, conflict) ⇒ Boolean
9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 |
# File 'lib/kettle/jem.rb', line 9709 def modular_dependency_conflict_decided?(decisions, conflict) decisions.any? do |decision| decision.fetch("gem") == conflict.fetch(:name) && decision.fetch("direct") == conflict.fetch(:direct) && decision.fetch("modular") == conflict.fetch(:modular) && case decision.fetch("action") when "remove_modular_gem", "remove_x_std_lib_eval" true when "keep_both" compatible_dependency_requirements?(conflict.fetch(:direct_requirements), conflict.fetch(:modular_requirements)) else false end end end |
.modular_dependency_conflict_decisions(config) ⇒ Object
9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 |
# File 'lib/kettle/jem.rb', line 9693 def modular_dependency_conflict_decisions(config) Array(config.dig("dependency_conflicts", "resolve")).filter_map do |entry| case entry when Hash normalized = entry.each_with_object({}) { |(key, value), result| result[key.to_s] = value } next if %w[gem direct modular action reason].any? { |key| normalized.fetch(key, "").to_s.strip.empty? } %w[gem direct modular action reason].to_h { |key| [key, normalized.fetch(key).to_s] } end end end |
.modular_dependency_conflict_resolution_step(project_root) ⇒ Object
4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 |
# File 'lib/kettle/jem.rb', line 4955 def modular_dependency_conflict_resolution_step(project_root) decisions = modular_dependency_conflict_decisions(kettle_jem_config(project_root)) return nil if decisions.empty? changed_files = apply_modular_dependency_conflict_resolutions(project_root, decisions) { name: "modular_dependency_conflict_resolution", status: changed_files.empty? ? "already_current" : "applied", changed_files: changed_files, decisions: decisions.map { |decision| %w[gem modular action].to_h { |key| [key, decision.fetch(key)] } } } end |
.modular_dependency_conflicts(project_root, recipe_reports) ⇒ Object
9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 |
# File 'lib/kettle/jem.rb', line 9634 def modular_dependency_conflicts(project_root, recipe_reports) report_paths = recipe_reports.map { |report| report.fetch(:relative_path, "").to_s } paths = ["Gemfile", *Dir.glob(File.join(project_root.to_s, "*.gemspec")).map { |path| File.basename(path) }, *report_paths.select { |path| path.end_with?(".gemspec") }] direct = dependency_file_contents(project_root, recipe_reports, paths) modular_paths = [ *Dir.glob(File.join(project_root.to_s, "gemfiles/modular/**/*.gemfile")).map do |path| Pathname(path).relative_path_from(Pathname(project_root.to_s)).to_s end, *report_paths.select { |path| path.start_with?("gemfiles/modular/") && path.end_with?(".gemfile") } ].uniq modular_paths = modular_paths.map do |path| if path.start_with?("/") Pathname(path).relative_path_from(Pathname(project_root.to_s)).to_s else path end end.select do |path| relative = path.delete_prefix("gemfiles/modular/") !relative.include?("/") || relative.start_with?("x_std_libs/") end modular = dependency_file_contents(project_root, recipe_reports, modular_paths) direct.flat_map do |direct_path, content| direct_records = dependency_records_for(direct_path, content) modular.flat_map do |modular_path, modular_content| modular_records = dependency_records_for(modular_path, modular_content) direct_records.flat_map do |direct_record| modular_records.select { |record| record.fetch(:name) == direct_record.fetch(:name) }.map do |modular_record| { name: direct_record.fetch(:name), direct: direct_path, modular: modular_path, direct_requirements: direct_record.fetch(:requirements, []), modular_requirements: modular_record.fetch(:requirements, []) } end end end end end |
.modular_dependency_conflicts_reviewed?(config) ⇒ Boolean
9705 9706 9707 |
# File 'lib/kettle/jem.rb', line 9705 def modular_dependency_conflicts_reviewed?(config) config.dig("dependency_conflicts", "reviewed") == true end |
.modular_gemfile_template_recipe?(recipe) ⇒ Boolean
8907 8908 8909 |
# File 'lib/kettle/jem.rb', line 8907 def modular_gemfile_template_recipe?(recipe) recipe.fetch(:target_path).to_s.start_with?("gemfiles/modular/") end |
.monorepo_root_file_strategy(entry) ⇒ Object
12954 12955 12956 12957 12958 12959 12960 |
# File 'lib/kettle/jem.rb', line 12954 def monorepo_root_file_strategy(entry) if entry.to_s == "CHANGELOG.md" "keep_destination" else "accept_template" end end |
.monorepo_root_gemfile_dependency_lines ⇒ Object
5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 |
# File 'lib/kettle/jem.rb', line 5441 def monorepo_root_gemfile_dependency_lines [ {name: "appraisal2", source: %(gem "appraisal2", "~> 3.2", ">= 3.2.3"\n)}, {name: "bundler-audit", source: %(gem "bundler-audit", "~> 0.9.3"\n)}, {name: "kettle-dev", source: %(gem "kettle-dev", "~> 3.0", ">= 3.0.27"\n)}, {name: "kettle-drift", source: %(gem "kettle-drift", "~> 1.0", ">= 1.0.13"\n)}, {name: "kettle-family", source: %(gem "kettle-family", "~> 1.2", ">= 1.2.80"\n)}, {name: "kettle-jem", source: %(gem "kettle-jem", "~> 7.1", ">= 7.1.14"\n)}, {name: "kettle-test", source: %(gem "kettle-test", "~> 2.0", ">= 2.0.21"\n)}, {name: "rake", source: %(gem "rake", "~> 13.0"\n)}, {name: "rspec", source: %(gem "rspec", "~> 3.0"\n)}, {name: "stone_checksums", source: %(gem "stone_checksums", "~> 1.0", ">= 1.0.8"\n)}, {name: "turbo_tests2", source: %(gem "turbo_tests2", "~> 3.2", ">= 3.2.7"\n)} ].freeze end |
.monorepo_root_gemfile_dependency_sync_step(project_root, report) ⇒ Object
5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 |
# File 'lib/kettle/jem.rb', line 5414 def monorepo_root_gemfile_dependency_sync_step(project_root, report) facts = report.fetch(:facts) return unless monorepo_root_template_profile?(facts) path = File.join(project_root.to_s, "Gemfile") before = File.exist?(path) ? File.read(path) : %(source "https://gem.coop"\n) after = ensure_monorepo_root_gemfile_dependencies(before) File.write(path, after) if after != before { name: "monorepo_root_gemfile_dependency_sync", path: "Gemfile", status: (after == before) ? "already_current" : "applied", changed_files: (after == before) ? [] : ["Gemfile"] } end |
.monorepo_root_template_profile?(facts) ⇒ Boolean
13122 13123 13124 |
# File 'lib/kettle/jem.rb', line 13122 def monorepo_root_template_profile?(facts) facts[:template_profile].to_s == MONOREPO_ROOT_TEMPLATE_PROFILE end |
.monorepo_subgem_kettle_config_profile_sync_step(project_root, report) ⇒ Object
5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 |
# File 'lib/kettle/jem.rb', line 5154 def monorepo_subgem_kettle_config_profile_sync_step(project_root, report) facts = report.fetch(:facts) return unless monorepo_subgem_template_profile?(facts) profile = normalize_template_profile(facts[:template_profile]) path = File.join(project_root.to_s, KETTLE_CONFIG_PATH) return unless File.file?(path) gemspec = facts.dig(:rubygems, :gemspec_path).to_s before = File.read(path) after = sync_kettle_config_monorepo_subgem_profile(before, gemspec, profile) File.write(path, after) if after != before { name: "monorepo_subgem_kettle_config_profile_sync", path: KETTLE_CONFIG_PATH, status: (after == before) ? "already_current" : "applied", changed_files: (after == before) ? [] : [KETTLE_CONFIG_PATH] } end |
.monorepo_subgem_template_entries(gemspec_path, profile = MONOREPO_SUBGEM_TEMPLATE_PROFILE) ⇒ Object
12974 12975 12976 12977 12978 12979 12980 12981 12982 |
# File 'lib/kettle/jem.rb', line 12974 def monorepo_subgem_template_entries(gemspec_path, profile = MONOREPO_SUBGEM_TEMPLATE_PROFILE) entries = monorepo_subgem_template_entries_for_profile(gemspec_path, profile) gemspec = gemspec_path.to_s.strip return entries if gemspec.empty? entries.insert(1, {"source" => "gem.gemspec", "target" => gemspec}) entries.concat(version_gem_template_entries(gemspec)) entries end |
.monorepo_subgem_template_entries_for_profile(gemspec_path, profile) ⇒ Object
12984 12985 12986 12987 12988 12989 12990 12991 12992 12993 12994 |
# File 'lib/kettle/jem.rb', line 12984 def monorepo_subgem_template_entries_for_profile(gemspec_path, profile) case normalize_template_profile(profile) when MONOREPO_SUBGEM_RELEASE_TEMPLATE_PROFILE MONOREPO_SUBGEM_RELEASE_TEMPLATE_ENTRIES.dup when MONOREPO_SUBGEM_FULL_TEMPLATE_PROFILE project_root = File.dirname(File.(gemspec_path.to_s)) template_inventory_entries(project_root, PACKAGED_TEMPLATE_ROOT).dup else (MONOREPO_SUBGEM_TEMPLATE_ENTRIES + PACKAGED_MODULAR_GEMFILE_TEMPLATE_ENTRIES).uniq end end |
.monorepo_subgem_template_profile?(facts) ⇒ Boolean
13118 13119 13120 |
# File 'lib/kettle/jem.rb', line 13118 def monorepo_subgem_template_profile?(facts) monorepo_subgem_template_profile_value?(facts[:template_profile]) end |
.monorepo_subgem_template_profile_value?(profile) ⇒ Boolean
13134 13135 13136 13137 13138 13139 13140 |
# File 'lib/kettle/jem.rb', line 13134 def monorepo_subgem_template_profile_value?(profile) [ MONOREPO_SUBGEM_PACKAGE_TEMPLATE_PROFILE, MONOREPO_SUBGEM_RELEASE_TEMPLATE_PROFILE, MONOREPO_SUBGEM_FULL_TEMPLATE_PROFILE ].include?(normalize_template_profile(profile)) end |
.monorepo_template_profile?(facts) ⇒ Boolean
13126 13127 13128 |
# File 'lib/kettle/jem.rb', line 13126 def monorepo_template_profile?(facts) monorepo_root_template_profile?(facts) || monorepo_subgem_template_profile?(facts) end |
.monotonic_time ⇒ Object
4779 4780 4781 |
# File 'lib/kettle/jem.rb', line 4779 def monotonic_time Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
.namespace_descendant?(namespace, parent) ⇒ Boolean
15723 15724 15725 15726 15727 15728 15729 |
# File 'lib/kettle/jem.rb', line 15723 def namespace_descendant?(namespace, parent) namespace = namespace.to_s parent = parent.to_s return false if namespace.empty? || parent.empty? || namespace == parent namespace.start_with?("#{parent}::") end |
.nested_templating_guard_records(content) ⇒ Object
8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 |
# File 'lib/kettle/jem.rb', line 8813 def nested_templating_guard_records(content) result = prism_parse_success(content) return [] unless result result.value.breadth_first_search_all do |node| redundant_templating_guard_wrapper_node?(node) end.map do |node| inner = node.statements.body.first { outer_start_line: node.location.start_line, outer_end_line: node.location.end_line, inner_start_line: inner.location.start_line, inner_end_line: inner.location.end_line } end end |
.node_enclosed_by_ranges?(node, ranges) ⇒ Boolean
8873 8874 8875 8876 8877 8878 8879 |
# File 'lib/kettle/jem.rb', line 8873 def node_enclosed_by_ranges?(node, ranges) start_line = node.location.start_line end_line = node.location.end_line ranges.any? do |range| range.fetch(:start_line) < start_line && range.fetch(:end_line) > end_line end end |
.nomono_gemfile_declaration ⇒ Object
15405 15406 15407 |
# File 'lib/kettle/jem.rb', line 15405 def nomono_gemfile_declaration %(gem "nomono", "~> 1.1", ">= 1.1.5", require: false # ruby >= 3.2.0) end |
.non_default_version_gem_entrypoint?(project_root, entrypoint_require) ⇒ Boolean
15664 15665 15666 15667 |
# File 'lib/kettle/jem.rb', line 15664 def non_default_version_gem_entrypoint?(project_root, entrypoint_require) version_gem_path = File.join("lib", entrypoint_require.to_s, "version_gem.rb") File.file?(File.join(project_root, version_gem_path)) end |
.non_mit_licenses?(licenses) ⇒ Boolean
17690 17691 17692 |
# File 'lib/kettle/jem.rb', line 17690 def non_mit_licenses?(licenses) licenses.any? { |license| license != "MIT" } end |
.nonempty_string(value) ⇒ Object
19076 19077 19078 19079 |
# File 'lib/kettle/jem.rb', line 19076 def nonempty_string(value) normalized = value.to_s.strip normalized unless normalized.empty? end |
.normalize_changelog(content, facts) ⇒ Object
6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 |
# File 'lib/kettle/jem.rb', line 6009 def normalize_changelog(content, facts) text = normalize_legacy_changelog_release_headings(content.to_s) title = "# Changelog" headings = markdown_heading_owners(text, source_label: "CHANGELOG.md") unless headings.any? { |heading| heading.level == 1 } text = "#{title}\n\n#{text}" headings = markdown_heading_owners(text, source_label: "CHANGELOG.md") end return ensure_trailing_newline(text) if headings.any? { |heading| heading.level == 2 && changelog_unreleased_heading?(heading.heading_text) } lines = text.split("\n", -1) insert_at = headings.find { |heading| heading.level == 2 }&.location&.start_line&.-(1) || lines.length section = [ "## [Unreleased]", "", "### Added", "", "### Changed", "", "### Deprecated", "", "### Removed", "", "### Fixed", "", "### Security", "" ] lines.insert(insert_at, *section) ensure_trailing_newline(lines.join("\n").gsub(/\n{3,}/, "\n\n")) end |
.normalize_conditional_body_indentation(source) ⇒ Object
8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 |
# File 'lib/kettle/jem.rb', line 8361 def normalize_conditional_body_indentation(source) lines = source.to_s.lines return source if lines.length < 3 outer_indent = leading_space_count(lines.first) desired_body_indent = outer_indent + 2 body = lines[1...-1] min_body_indent = body.reject { |line| line.strip.empty? }.map { |line| leading_space_count(line) }.min return source unless min_body_indent && min_body_indent > desired_body_indent remove_spaces = min_body_indent - desired_body_indent ([lines.first] + body.map { |line| outdent_line(line, remove_spaces) } + [lines.last]).join end |
.normalize_debug_require_records(content, records) ⇒ Object
8534 8535 8536 8537 8538 8539 8540 8541 8542 |
# File 'lib/kettle/jem.rb', line 8534 def normalize_debug_require_records(content, records) return content if records.empty? replacements = records.to_h do |record| indent = content.to_s.lines.fetch(record.fetch(:start_line) - 1)[/\A\s*/] [record.fetch(:start_line), record.merge(replacement: %(#{indent}#{guarded_debug_require}\n))] end replace_record_ranges(content, replacements) end |
.normalize_entrypoint_version_require(content, entrypoint_require:, version_require_path: nil, after_declarations: false) ⇒ Object
16105 16106 16107 16108 16109 16110 16111 16112 16113 16114 16115 16116 16117 16118 16119 16120 |
# File 'lib/kettle/jem.rb', line 16105 def normalize_entrypoint_version_require(content, entrypoint_require:, version_require_path: nil, after_declarations: false) relative_path = version_require_path.to_s.empty? ? File.join(File.basename(entrypoint_require), "version") : version_require_path.to_s absolute_path = File.join(entrypoint_require, "version") legacy_relative_path = File.join(File.basename(entrypoint_require), "version") current = [relative_path, legacy_relative_path].uniq.reduce(content) do |value, path| remove_entrypoint_version_requires(value, relative_path: path, absolute_path: absolute_path) end if after_declarations current = trim_trailing_blank_lines(collapse_excess_blank_lines(current)) return "#{current}\n\nrequire_relative \"#{relative_path}\"\n" unless current.empty? end lines = current.lines lines.insert(version_gem_require_insertion_index(current), %(require_relative "#{relative_path}"\n), "\n") trim_trailing_blank_lines(collapse_excess_blank_lines(lines.join)) end |
.normalize_eval_gemfile_ruby_bucket(path) ⇒ Object
10109 10110 10111 10112 10113 10114 10115 10116 |
# File 'lib/kettle/jem.rb', line 10109 def normalize_eval_gemfile_ruby_bucket(path) segments = path.to_s.split("/", -1) bucket_index = segments.index { |segment| ruby_bucket_path_segment?(segment) } return unless bucket_index segments[bucket_index] = "{ruby}" segments.join("/") end |
.normalize_executable_version_entrypoint(content, legacy_version_path:, canonical_version_path:, legacy_namespace:, namespace:) ⇒ Object
5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 |
# File 'lib/kettle/jem.rb', line 5012 def normalize_executable_version_entrypoint(content, legacy_version_path:, canonical_version_path:, legacy_namespace:, namespace:) parsed = prism_parse_success(content) return content unless parsed require_call = ruby_call_records(content, :require_relative).find do |call| argument = call.arguments&.arguments&.first [legacy_version_path, canonical_version_path].include?(ruby_static_string_value(argument)) end return content unless require_call stale_header = stale_executable_startup_header( parsed.value, require_call: require_call, namespaces: [legacy_namespace, namespace] ) return remove_stale_executable_startup_header(content, stale_header) if stale_header require_argument = require_call.arguments&.arguments&.first return content unless ruby_static_string_value(require_argument) == legacy_version_path legacy_segments = legacy_namespace.to_s.split("::") namespace_segments = namespace.to_s.split("::") version_constants = [] parsed.value.breadth_first_search_all do |node| next unless node.is_a?(::Prism::ConstantPathNode) segments = ruby_constant_path_segments(node) version_constants << node if segments == legacy_segments + ["Version", "VERSION"] || segments == legacy_segments + ["VERSION"] end return content if version_constants.empty? replacements = [ { start_offset: require_argument.location.start_offset, end_offset: require_argument.location.end_offset, replacement: JSON.generate(canonical_version_path) } ] version_constants.each do |node| suffix = (ruby_constant_path_segments(node).last(2) == ["Version", "VERSION"]) ? ["Version", "VERSION"] : ["VERSION"] replacements << { start_offset: node.location.start_offset, end_offset: node.location.end_offset, replacement: (namespace_segments + suffix).join("::") } end replace_source_offsets(content, replacements) end |
.normalize_gemspec_dependency_version_requirements(source, receiver:, namespace:) ⇒ Object
11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 11808 11809 11810 11811 11812 11813 11814 |
# File 'lib/kettle/jem.rb', line 11798 def normalize_gemspec_dependency_version_requirements(source, receiver:, namespace:) return source if namespace.to_s.empty? replacements = ruby_call_records(source, nil).flat_map do |call| next [] unless gemspec_dependency_call_kind(call) Array(call.arguments&.arguments).drop(1).filter_map do |argument| replacement = ruby_project_version_interpolated_string_source(argument, receiver: receiver, namespace: namespace) next unless replacement {start_offset: argument.location.start_offset, end_offset: argument.location.end_offset, replacement: replacement} end end return source if replacements.empty? replace_source_offsets(source, replacements) end |
.normalize_gemspec_package_helper_assignments(content, template_content) ⇒ Object
10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 |
# File 'lib/kettle/jem.rb', line 10604 def normalize_gemspec_package_helper_assignments(content, template_content) template_records = gemspec_package_helper_assignment_records(template_content).to_h do |record| [record.fetch(:name), record.fetch(:source)] end return content if template_records.empty? replacements = gemspec_package_helper_assignment_records(content).filter_map do |record| source = template_records[record.fetch(:name)] next unless source [record.fetch(:start_line), record.merge(replacement: source)] end.to_h return content if replacements.empty? replace_record_ranges(content, replacements) end |
.normalize_gemspec_project_emoji(line, facts, field:) ⇒ Object
11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 |
# File 'lib/kettle/jem.rb', line 11089 def normalize_gemspec_project_emoji(line, facts, field:) return line unless %w[summary description].include?(field.to_s) return line unless facts&.dig(:project_runtime, :project_emoji_configured) project_emoji = facts&.dig(:project_runtime, :project_emoji).to_s return line if project_emoji.empty? record = gemspec_assignment_records(line).find { |candidate| candidate.fetch(:field) == field.to_s } value = record&.fetch(:value) return line unless value.is_a?(String) string_node = ruby_first_simple_quoted_string_node(record[:value_node]) return line unless string_node first_value = string_node.unescaped.to_s line.sub(first_value, "#{project_emoji} #{strip_leading_decorative_graphemes(first_value)}") end |
.normalize_gemspec_receiver(line, from:, to:) ⇒ Object
11083 11084 11085 11086 11087 |
# File 'lib/kettle/jem.rb', line 11083 def normalize_gemspec_receiver(line, from:, to:) return line if from.to_s.empty? || to.to_s.empty? || from == to Prism::Merge::BlockVarRenamer.rename(line.to_s, old_var: from.to_s, new_var: to.to_s) end |
.normalize_generated_image_url(url) ⇒ Object
16611 16612 16613 |
# File 'lib/kettle/jem.rb', line 16611 def normalize_generated_image_url(url) Addressable::URI.parse(url.to_s).normalize.to_s end |
.normalize_generated_rakefile(content) ⇒ Object
7089 7090 7091 7092 7093 7094 7095 |
# File 'lib/kettle/jem.rb', line 7089 def normalize_generated_rakefile(content) return "" if content.to_s.empty? stripped = strip_orphaned_rake_task_requires(content.to_s) spaced = normalize_rakefile_section_spacing(stripped) ensure_trailing_newline(spaced.rstrip) end |
.normalize_git_source_url(url) ⇒ Object
16846 16847 16848 16849 16850 16851 16852 16853 16854 16855 16856 16857 16858 16859 16860 16861 16862 16863 16864 16865 16866 16867 16868 16869 |
# File 'lib/kettle/jem.rb', line 16846 def normalize_git_source_url(url) value = url.to_s.strip return if value.empty? if value.start_with?("[email protected]:") slug = value.split(":", 2).last.to_s.delete_suffix(".git") return "https://github.com/#{slug}" if slug.split("/").length >= 2 end uri = URI.parse(value) if uri.scheme == "ssh" && uri.host == "github.com" slug = uri.path.to_s.delete_prefix("/").delete_suffix(".git") return "https://github.com/#{slug}" if slug.split("/").length >= 2 end if %w[http https].include?(uri.scheme) && uri.host == "github.com" slug = uri.path.to_s.delete_prefix("/").delete_suffix(".git") return "https://github.com/#{slug}" if slug.split("/").length >= 2 end value rescue URI::InvalidURIError value end |
.normalize_github_actions_exec_cmd(command) ⇒ Object
19145 19146 19147 19148 19149 19150 |
# File 'lib/kettle/jem.rb', line 19145 def normalize_github_actions_exec_cmd(command) normalized = command.to_s.strip return "kettle-test" if OBSOLETE_APPRAISAL_SPEC_EXEC_CMDS.include?(normalized) normalized end |
.normalize_integration_name(name) ⇒ Object
17961 17962 17963 17964 17965 17966 17967 17968 |
# File 'lib/kettle/jem.rb', line 17961 def normalize_integration_name(name) normalized = name.to_s.tr("_", "-").downcase return "codecov" if normalized == "code-cov" return "codeql" if normalized == "code-ql" return SKYWALKING_EYES_INTEGRATION if %w[license-eye license-eyes skywalking-eye skywalking-eyes apache-skywalking-eyes].include?(normalized) normalized end |
.normalize_kettle_config_optional_scalars(content) ⇒ Object
12440 12441 12442 12443 12444 12445 12446 12447 12448 12449 12450 12451 |
# File 'lib/kettle/jem.rb', line 12440 def normalize_kettle_config_optional_scalars(content) config = YAML.safe_load(content.to_s, permitted_classes: [], aliases: true) || {} return content unless config.key?("min_divergence_threshold") replace_yaml_scalar_path( content, %w[min_divergence_threshold], yaml_config_scalar_literal(config["min_divergence_threshold"], path: %w[min_divergence_threshold]) ) rescue Psych::Exception content end |
.normalize_kettle_jem_config(config) ⇒ Object
13708 13709 13710 13711 13712 13713 13714 13715 13716 13717 13718 13719 13720 13721 13722 |
# File 'lib/kettle/jem.rb', line 13708 def normalize_kettle_jem_config(config) return config unless config.is_a?(Hash) files = config["files"] return config unless files.is_a?(Hash) simplecov_config = files[".simplecov"] return config unless simplecov_config.is_a?(Hash) return config unless simplecov_config.keys == ["strategy"] && simplecov_config["strategy"].to_s == "keep_destination" normalized = config.dup normalized["files"] = files.dup normalized["files"].delete(".simplecov") normalized end |
.normalize_legacy_changelog_release_headings(content) ⇒ Object
6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 |
# File 'lib/kettle/jem.rb', line 6041 def normalize_legacy_changelog_release_headings(content) lines = markdown_source_lines(content) markdown_heading_owners(content, source_label: "CHANGELOG.md").each do |heading| next unless heading.level == 2 canonical = canonical_changelog_release_heading(heading.heading_text) next unless canonical lines[heading.location.start_line - 1] = canonical end lines.join("\n") end |
.normalize_list_option(value) ⇒ Object
13227 13228 13229 13230 |
# File 'lib/kettle/jem.rb', line 13227 def normalize_list_option(value) values = Array(value).flat_map { |entry| entry.to_s.split(",") }.map(&:strip).reject(&:empty?) values.empty? ? nil : values end |
.normalize_local_gemfile_nomono_bootstrap(content) ⇒ Object
8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 |
# File 'lib/kettle/jem.rb', line 8911 def normalize_local_gemfile_nomono_bootstrap(content) output = remove_obsolete_local_gemfile_nomono_activation(content) bootstrap = "#{local_gemfile_nomono_bootstrap(nil)}\n\n" require_records = ruby_call_records(output, :require).filter_map do |call| next unless ruby_string_argument(call) == "nomono/bundler" { start_line: call.location.start_line, end_line: ruby_node_source_end_line(call) } end unless require_records.empty? first = require_records.min_by { |record| record.fetch(:start_line) } without_duplicates = require_records.reject { |record| record.equal?(first) }.sort_by { |record| -record.fetch(:start_line) }.reduce(output) do |memo, record| replace_source_range_lines(memo, record.fetch(:start_line), (memo, record.fetch(:end_line)), "") end return replace_source_range_lines(without_duplicates, first.fetch(:start_line), first.fetch(:end_line), bootstrap) end if (record = local_gems_assignment_record(output)) insert_lines_before(output, record.fetch(:start_line), bootstrap) else ensure_trailing_newline([output.to_s.rstrip, bootstrap.rstrip].reject(&:empty?).join("\n\n")) end end |
.normalize_main_gemfile_nomono_declaration(content) ⇒ Object
8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 |
# File 'lib/kettle/jem.rb', line 8282 def normalize_main_gemfile_nomono_declaration(content) records = main_gemfile_nomono_requirement_records(content) return content if records.fetch(:calls).empty? output = records.fetch(:assignments).sort_by { |record| -record.fetch(:start_line) }.reduce(content.to_s) do |memo, record| replace_source_range_lines( memo, record.fetch(:start_line), (memo, record.fetch(:end_line)), "" ) end main_gemfile_nomono_requirement_records(output).fetch(:calls).sort_by { |record| -record.fetch(:start_line) }.reduce(output) do |memo, record| replace_source_range_lines(memo, record.fetch(:start_line), record.fetch(:end_line), "#{nomono_gemfile_declaration}\n") end end |
.normalize_project_homepage_uri(value) ⇒ Object
15453 15454 15455 15456 15457 15458 15459 15460 15461 |
# File 'lib/kettle/jem.rb', line 15453 def normalize_project_homepage_uri(value) uri = URI.parse(value.to_s) return value.to_s unless uri.host uri.host = normalize_project_hostname(uri.host) uri.to_s rescue URI::InvalidURIError value.to_s end |
.normalize_project_hostname(value) ⇒ Object
15449 15450 15451 |
# File 'lib/kettle/jem.rb', line 15449 def normalize_project_hostname(value) value.to_s.tr("_", "-") end |
.normalize_rakefile_section_spacing(content) ⇒ Object
7097 7098 7099 7100 7101 7102 7103 7104 |
# File 'lib/kettle/jem.rb', line 7097 def normalize_rakefile_section_spacing(content) content.to_s.lines.each_with_object([]) do |line, normalized| if line.start_with?("### ") normalized.pop while normalized.length > 1 && normalized[-1].strip.empty? && normalized[-2].strip.empty? end normalized << line end.join end |
.normalize_readme_blank_line_runs(content) ⇒ Object
7437 7438 7439 7440 7441 |
# File 'lib/kettle/jem.rb', line 7437 def normalize_readme_blank_line_runs(content) return Ast::Merge.normalize_blank_line_runs(content) if Ast::Merge.respond_to?(:normalize_blank_line_runs) collapse_excess_blank_lines(content) end |
.normalize_readme_compatibility_summary(content, engines, min_ruby = "") ⇒ Object
7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 |
# File 'lib/kettle/jem.rb', line 7602 def normalize_readme_compatibility_summary(content, engines, min_ruby = "") enabled = Array(engines).map { |engine| engine.to_s.strip.downcase }.reject(&:empty?).uniq return content if enabled.empty? runtime_floor = min_ruby.to_s.strip runtime_floor = " #{runtime_floor}+" unless runtime_floor.empty? runtime_engines = ["MRI Ruby#{runtime_floor}"] runtime_engines << "JRuby" if enabled.include?("jruby") runtime_engines << "TruffleRuby" if enabled.include?("truffleruby") || enabled.include?("truby") description = runtime_engines.one? ? runtime_engines.first : runtime_engines[0...-1].join(", ") + ", and #{runtime_engines.last}" content.to_s.sub( /Compatible with MRI Ruby [^\n]+\./, "Compatible with #{description}." ) end |
.normalize_readme_corporate_sponsors(value) ⇒ Object
16921 16922 16923 16924 16925 16926 16927 16928 16929 16930 16931 16932 16933 16934 16935 16936 16937 16938 16939 16940 |
# File 'lib/kettle/jem.rb', line 16921 def normalize_readme_corporate_sponsors(value) Array(value).filter_map do |entry| unless entry.is_a?(Hash) raise ArgumentError, "corporate sponsor entries must be mappings with name, url, and img_src" end name = entry["name"].to_s.strip url = entry["url"].to_s.strip img_src = entry["img_src"].to_s.strip if name.empty? || url.empty? || img_src.empty? raise ArgumentError, "corporate sponsor entries require name, url, and img_src" end { name: name, url: url, img_src: img_src } end end |
.normalize_readme_corporate_sponsors_json(value) ⇒ Object
16911 16912 16913 16914 16915 16916 16917 16918 16919 |
# File 'lib/kettle/jem.rb', line 16911 def normalize_readme_corporate_sponsors_json(value) clean = value.to_s.strip return [] if clean.empty? parsed = JSON.parse(clean) normalize_readme_corporate_sponsors(parsed) rescue JSON::ParserError raise ArgumentError, "invalid KETTLE_JEM_CORPORATE_SPONSORS_JSON" end |
.normalize_readme_heading(text) ⇒ Object
18231 18232 18233 |
# File 'lib/kettle/jem.rb', line 18231 def normalize_readme_heading(text) strip_readme_heading_adornment(text).strip.downcase end |
.normalize_readme_project_heading(content, facts) ⇒ Object
7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 |
# File 'lib/kettle/jem.rb', line 7783 def normalize_readme_project_heading(content, facts) package = facts.fetch(:package, {}) rubygems = facts.fetch(:rubygems, {}) title = readme_title_token(package, rubygems) emoji = facts.dig(:project_runtime, :project_emoji).to_s return content if title.empty? || emoji.empty? lines = content.to_s.split("\n", -1) h1 = markdown_heading_owners(content, source_label: "README.md").find { |owner| owner.level == 1 } return content unless h1 index = h1.location.start_line - 1 lines[index] = "# #{emoji} #{title}" lines.join("\n") end |
.normalize_readme_rubygems_download_badges(content) ⇒ Object
7433 7434 7435 |
# File 'lib/kettle/jem.rb', line 7433 def normalize_readme_rubygems_download_badges(content) content.gsub("https://img.shields.io/gem/rd/", "https://img.shields.io/gem/dt/") end |
.normalize_readme_section_key(section) ⇒ Object
17882 17883 17884 |
# File 'lib/kettle/jem.rb', line 17882 def normalize_readme_section_key(section) normalize_readme_heading(section.to_s.tr("_-", " ")) end |
.normalize_readme_synopsis_heading(content, facts) ⇒ Object
7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 |
# File 'lib/kettle/jem.rb', line 7799 def normalize_readme_synopsis_heading(content, facts) logo_row = facts.dig(:readme_logo, :h2_synopsis_logo_row).to_s return content if logo_row.empty? lines = content.to_s.split("\n", -1) h2 = markdown_heading_owners(content, source_label: "README.md").find do |owner| owner.level == 2 && owner.base.to_s == "synopsis" end return content unless h2 index = h2.location.start_line - 1 lines[index] = "## 🌻 Synopsis #{logo_row}" lines.join("\n") end |
.normalize_repository_topology(value) ⇒ Object
13254 13255 13256 13257 13258 13259 13260 13261 |
# File 'lib/kettle/jem.rb', line 13254 def normalize_repository_topology(value) topology = value.to_s.strip.downcase.tr("_", "-") return "" if topology.empty? return REPOSITORY_TOPOLOGY_MONOREPO_SUBPROJECT if %w[monorepo-subproject monorepo-subgem monorepo-package subproject subgem].include?(topology) return REPOSITORY_TOPOLOGY_STANDALONE if %w[standalone single-repo repo].include?(topology) topology end |
.normalize_rubyforum_tag(value) ⇒ Object
14430 14431 14432 |
# File 'lib/kettle/jem.rb', line 14430 def normalize_rubyforum_tag(value) value.to_s.strip.delete_prefix("#").delete_suffix("/").split("/").last.to_s end |
.normalize_simplecov_cover_predicates(content) ⇒ Object
SimpleCov's compatibility probe changed spelling between template generations. Normalize the legacy AST shape before merging so the same generated branch is matched instead of appended a second time.
8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 |
# File 'lib/kettle/jem.rb', line 8388 def normalize_simplecov_cover_predicates(content) result = prism_parse_success(content) return content unless result nodes = [] result.value.breadth_first_search_all { |node| nodes << node } replacements = nodes.filter_map do |node| next unless node.is_a?(::Prism::IfNode) predicate = node.predicate next unless predicate.is_a?(::Prism::CallNode) next unless predicate.name == :method_defined? next unless predicate.receiver&.slice.to_s == "SimpleCov::Configuration" next unless predicate.arguments&.arguments&.first&.slice.to_s == ":cover" { start_offset: predicate.location.start_offset, end_offset: predicate.location.end_offset, replacement: "SimpleCov::Configuration.instance_methods.include?(:cover)" } end return content if replacements.empty? replace_source_offsets(content, replacements) end |
.normalize_simplecov_template_source(content) ⇒ Object
8375 8376 8377 8378 8379 8380 8381 8382 8383 |
# File 'lib/kettle/jem.rb', line 8375 def normalize_simplecov_template_source(content) output = normalize_simplecov_cover_predicates(content) output = migrate_simplecov_start_configuration(output) nodes = simplecov_obsolete_call_nodes(output) output = nodes.sort_by { |node| -node.location.start_line }.reduce(output) do |memo, node| replace_source_range_lines(memo, node.location.start_line, (memo, node.location.end_line), "") end normalize_simplecov_usage_guidance(output) end |
.normalize_simplecov_usage_guidance(content) ⇒ Object
Older template merges appended a second generated usage-comment block. Keep the first block and remove only later comment-only blocks with the same generated heading, leaving any coverage code or local notes intact.
8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 |
# File 'lib/kettle/jem.rb', line 8437 def normalize_simplecov_usage_guidance(content) lines = content.to_s.lines starts = lines.each_index.select { |index| lines[index].strip == "# To get coverage" } return content if starts.length < 2 starts.drop(1).reverse_each do |start_index| end_index = start_index end_index += 1 while end_index < lines.length && comment_or_blank_line?(lines[end_index]) lines.slice!(start_index...end_index) if comment_only_lines?(lines[start_index...end_index]) end lines.join end |
.normalize_spec_helper_block_bindings(content, template_content) ⇒ Object
8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 |
# File 'lib/kettle/jem.rb', line 8548 def normalize_spec_helper_block_bindings(content, template_content) output = content [ lambda { |call| call.receiver&.slice == "RSpec" && call.name == :configure }, lambda { |call| call.name == :expect_with && call.receiver } ].each do |matcher| template_binding = Prism::Merge::BlockBinding.find(template_content, &matcher) destination_binding = Prism::Merge::BlockBinding.find(output, &matcher) next unless template_binding && destination_binding output = Prism::Merge::BlockVarRenamer.normalize( output, binding: destination_binding, canonical_name: template_binding.name ) end output end |
.normalize_spec_helper_simplecov_template_source(content) ⇒ Object
8479 8480 8481 8482 8483 8484 8485 8486 8487 |
# File 'lib/kettle/jem.rb', line 8479 def normalize_spec_helper_simplecov_template_source(content) output = remove_duplicate_simplecov_do_cov_bootstrap_blocks(content) output = ensure_spec_helper_simplecov_do_cov_bootstrap(output) output = remove_obsolete_simplecov_rescue_bootstrap_blocks(output) output = remove_duplicate_simplecov_requires(output) output = ensure_spec_helper_simplecov_config_require(output) output = ensure_spec_helper_simplecov_start(output) migrate_legacy_byebug_requires(output) end |
.normalize_structuredmerge_local_gems(content, template_content) ⇒ Object
This list is resolved exclusively through STRUCTUREDMERGE_DEV. Preserve no destination entries here: an obsolete entry can point Bundler at a sibling path that does not exist in the StructuredMerge gems directory.
9004 9005 9006 9007 9008 9009 9010 |
# File 'lib/kettle/jem.rb', line 9004 def normalize_structuredmerge_local_gems(content, template_content) template_gems = word_array_assignment(template_content, :structuredmerge_local_gems) return content if template_gems.empty? return content unless word_array_assignment_record(content, :structuredmerge_local_gems) replace_word_array_assignment(content, :structuredmerge_local_gems, template_gems) end |
.normalize_template_profile(value) ⇒ Object
13232 13233 13234 13235 13236 13237 13238 13239 13240 13241 13242 13243 |
# File 'lib/kettle/jem.rb', line 13232 def normalize_template_profile(value) profile = value.to_s.strip.downcase.tr("_", "-") return "" if profile.empty? return FULL_TEMPLATE_PROFILE if %w[full large default standalone].include?(profile) return MONOREPO_SUBGEM_PACKAGE_TEMPLATE_PROFILE if %w[monorepo-subgem monorepo-subproject monorepo-package monorepo-subgem-package small thin package].include?(profile) return MONOREPO_SUBGEM_RELEASE_TEMPLATE_PROFILE if %w[monorepo-subgem-release monorepo-release release].include?(profile) return MONOREPO_SUBGEM_FULL_TEMPLATE_PROFILE if %w[monorepo-subgem-full monorepo-full subgem-full].include?(profile) return MONOREPO_ROOT_TEMPLATE_PROFILE if profile == MONOREPO_ROOT_TEMPLATE_PROFILE return SHIM_TEMPLATE_PROFILE if %w[shim shim-gem compatibility-shim compat-shim].include?(profile) profile end |
.normalize_templating_guard_indentation(content) ⇒ Object
8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 |
# File 'lib/kettle/jem.rb', line 8335 def normalize_templating_guard_indentation(content) records = templating_guard_records(content) return content if records.empty? output = content.to_s records.sort_by { |record| -record.fetch(:start_line) }.each do |record| source = output.lines[(record.fetch(:start_line) - 1)..(record.fetch(:end_line) - 1)].join normalized = normalize_conditional_body_indentation(source) next if normalized == source output = replace_source_range_lines(output, record.fetch(:start_line), record.fetch(:end_line), normalized) end output end |
.normalize_version_gem_entrypoint_mode(value) ⇒ Object
15699 15700 15701 15702 15703 15704 15705 15706 15707 |
# File 'lib/kettle/jem.rb', line 15699 def normalize_version_gem_entrypoint_mode(value) mode = value.to_s.strip.downcase.tr("_", "-") return "" if mode.empty? || mode == "auto" return "dedicated" if %w[dedicated non-default nondefault separate split].include?(mode) return "inline" if %w[inline default].include?(mode) return "disabled" if %w[disabled disable false off no none].include?(mode) mode end |
.normalize_version_gem_version_spec(project_root, version_spec_path, entrypoint_require, namespace, ensure_version_gem_require:, package_name: nil, include_version_gem_path: true, ensure_package_entrypoint_require: false) ⇒ Object
15731 15732 15733 15734 15735 15736 15737 15738 15739 15740 15741 15742 15743 15744 15745 15746 15747 15748 15749 15750 15751 15752 15753 15754 15755 15756 15757 15758 15759 15760 15761 15762 15763 15764 15765 15766 15767 15768 15769 15770 15771 15772 15773 15774 15775 |
# File 'lib/kettle/jem.rb', line 15731 def normalize_version_gem_version_spec(project_root, version_spec_path, entrypoint_require, namespace, ensure_version_gem_require:, package_name: nil, include_version_gem_path: true, ensure_package_entrypoint_require: false) current = read_project_file(project_root, version_spec_path) package_entrypoint_require = if ensure_package_entrypoint_require version_spec_package_entrypoint_require(project_root, package_name, entrypoint_require) end require_path = File.join(entrypoint_require.to_s, "version_gem") updated = if current.empty? version_gem_version_spec_content(namespace: namespace) else current end requirements = [] requirements << %(require "anonymous_loader"\n) unless ruby_top_level_require?(updated, "require", "anonymous_loader") if ensure_version_gem_require && !ruby_top_level_require?(updated, "require", require_path) requirements << %(require "#{require_path}"\n) end if ensure_package_entrypoint_require && !entrypoint_require.to_s.empty? && !package_name.to_s.empty? && package_name.to_s != entrypoint_require.to_s updated = remove_top_level_ruby_require(updated, package_name.to_s) end if ensure_package_entrypoint_require && package_entrypoint_require.to_s != entrypoint_require.to_s updated = remove_top_level_ruby_require(updated, entrypoint_require.to_s) end if ensure_package_entrypoint_require && !entrypoint_require.to_s.empty? && !ruby_top_level_require?(updated, "require", package_entrypoint_require.to_s) requirements << %(require "#{package_entrypoint_require}"\n) end if requirements.any? lines = updated.lines lines.insert(version_spec_require_insertion_index(updated), *requirements) updated = lines.join end updated = remove_version_gem_shared_example(updated) unless include_version_gem_path updated = normalize_version_spec_anonymous_loader_example( updated, version_spec_path: version_spec_path, entrypoint_require: entrypoint_require, namespace: namespace, include_version_gem_path: include_version_gem_path ) write_if_changed(project_root, version_spec_path, collapse_excess_blank_lines(updated)) end |
.normalize_version_spec_anonymous_loader_example(content, version_spec_path:, entrypoint_require:, namespace:, include_version_gem_path: true) ⇒ Object
15832 15833 15834 15835 15836 15837 15838 15839 15840 15841 15842 15843 15844 15845 15846 15847 15848 15849 15850 15851 15852 15853 15854 15855 15856 15857 15858 15859 15860 15861 15862 15863 15864 15865 15866 15867 15868 15869 15870 15871 15872 15873 15874 15875 |
# File 'lib/kettle/jem.rb', line 15832 def normalize_version_spec_anonymous_loader_example(content, version_spec_path:, entrypoint_require:, namespace:, include_version_gem_path: true) version_path = version_spec_relative_version_path(version_spec_path, entrypoint_require) version_gem_path = version_spec_relative_version_gem_path(version_spec_path, entrypoint_require) path_loader = if include_version_gem_path <<~RUBY.chomp paths = [ File.expand_path("#{version_path}", __dir__), File.expand_path("#{version_gem_path}", __dir__) ].select { |path| File.file?(path) } anonymous_namespace = AnonymousLoader.load(files: paths) RUBY else <<~RUBY.chomp path = File.expand_path("#{version_path}", __dir__) anonymous_namespace = AnonymousLoader.load(files: path) RUBY end legacy_path_loader = <<~RUBY.chomp path = File.expand_path("#{version_path}", __dir__) anonymous_namespace = AnonymousLoader.load(files: path) RUBY indented_path_loader = path_loader.lines.map { |line| " #{line}" }.join indented_legacy_path_loader = legacy_path_loader.lines.map { |line| " #{line}" }.join return content.sub(indented_legacy_path_loader, indented_path_loader) if content.include?(indented_legacy_path_loader) return content.sub(legacy_path_loader, path_loader) if content.include?(legacy_path_loader) return content if version_spec_anonymous_loader_call?(content) describe_call = version_spec_rspec_describe_call(content) return content unless describe_call&.block clean_namespace = namespace.to_s.start_with?("::") ? namespace.to_s[2..] : namespace.to_s example = <<~RUBY it "executes the version file for coverage without redefining constants" do #{indented_path_loader} expect(anonymous_namespace::#{clean_namespace}::Version::VERSION).to eq(described_class::VERSION) end RUBY insert_lines_before(content, describe_call.block.closing_loc.start_line, example) end |
.normalized_readme_logo_specs(value) ⇒ Object
17024 17025 17026 17027 17028 17029 17030 17031 17032 17033 17034 17035 17036 17037 17038 17039 17040 |
# File 'lib/kettle/jem.rb', line 17024 def normalized_readme_logo_specs(value) raw_values = case value when String value.split(",") when Array value else [] end raw_values.filter_map do |raw_value| raw_type, raw_width = raw_value.to_s.split("|", 2) normalized = raw_type.to_s.strip.downcase.tr("-", "_") next unless README_TOP_LOGO_OPTIONS.include?(normalized) {type: normalized, width: normalized_readme_logo_width(raw_width)} end.uniq end |
.normalized_readme_logo_width(value) ⇒ Object
17042 17043 17044 17045 17046 17047 |
# File 'lib/kettle/jem.rb', line 17042 def normalized_readme_logo_width(value) clean = value.to_s.strip return nil if clean.empty? clean end |
.normalized_readme_top_logo_options(value) ⇒ Object
17020 17021 17022 |
# File 'lib/kettle/jem.rb', line 17020 def (value) normalized_readme_logo_specs(value).map { |spec| spec.fetch(:type) } end |
.obsolete_local_gemfile_nomono_activation_records(content) ⇒ Object
8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 |
# File 'lib/kettle/jem.rb', line 8951 def obsolete_local_gemfile_nomono_activation_records(content) result = prism_parse_success(content) body = result&.value&.statements&.body || [] assignments = body.select do |node| node.is_a?(::Prism::LocalVariableWriteNode) && node.name == :nomono_activation_requirements end return [] if assignments.empty? lines = content.to_s.lines assignments.filter_map do |assignment| kernel_gem_call = body.find do |node| local_gemfile_nomono_kernel_activation_call?(node) && node.location.start_line > assignment.location.start_line end next unless kernel_gem_call { start_line: preceding_comment_block_start_line(lines, assignment.location.start_line), end_line: ruby_node_source_end_line(kernel_gem_call) } end end |
.obsolete_simplecov_rescue_bootstrap_node?(node, complete_bootstrap_present:) ⇒ Boolean
8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 |
# File 'lib/kettle/jem.rb', line 8591 def obsolete_simplecov_rescue_bootstrap_node?(node, complete_bootstrap_present:) return false unless node.is_a?(::Prism::BeginNode) return false unless node.rescue_clause calls = prism_call_nodes(node) has_kettle_soup_cover_require = calls.any? { |call| simplecov_kettle_soup_cover_require_call_node?(call) } has_simplecov_require = calls.any? { |call| simplecov_require_call_node?(call) } has_config_require = calls.any? { |call| simplecov_config_require_call_node?(call) } has_kettle_soup_cover_require && !has_config_require && (has_simplecov_require || complete_bootstrap_present) && calls.all? { |call| simplecov_bootstrap_call_node?(call) || simplecov_load_error_guard_call_node?(call) } end |
.obsolete_simplecov_rescue_bootstrap_records(content) ⇒ Object
8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 |
# File 'lib/kettle/jem.rb', line 8576 def obsolete_simplecov_rescue_bootstrap_records(content) result = prism_parse_success(content) return [] unless result complete_bootstrap_present = simplecov_do_cov_bootstrap_records(content).any? { |record| record.fetch(:complete) } result.value.breadth_first_search_all do |node| obsolete_simplecov_rescue_bootstrap_node?(node, complete_bootstrap_present: complete_bootstrap_present) end.map do |node| { start_line: node.location.start_line, end_line: ruby_node_source_end_line(node) } end end |
.old_ruby_version_bootstrap_step(project_root, report, entrypoint_require:, preserve_version_module_include: nil) ⇒ Object
5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 |
# File 'lib/kettle/jem.rb', line 5580 def old_ruby_version_bootstrap_step(project_root, report, entrypoint_require:, preserve_version_module_include: nil) facts = report.fetch(:facts) package_name = facts.dig(:package, :name).to_s return {name: "version_bootstrap", status: "unavailable", reason: "missing_package_facts"} if package_name.empty? entrypoint_require = package_name.tr("-", "/") if entrypoint_require.to_s.empty? namespace = facts.dig(:rubygems, :namespace).to_s version_path = File.join("lib", entrypoint_require, "version.rb") entrypoint_path = File.join("lib", "#{entrypoint_require}.rb") if namespace.empty? namespace = existing_entrypoint_version_namespace( project_root, entrypoint_path, expected_depth: classify_namespace(package_name).split("::").count { |segment| !segment.empty? } ).to_s end namespace = existing_version_namespace(project_root, version_path).to_s if namespace.empty? namespace = classify_namespace(package_name) if namespace.empty? return {name: "version_bootstrap", status: "unavailable", reason: "missing_package_facts"} if namespace.empty? namespace_superclass_details = existing_namespace_superclass_details( project_root, namespace, preferred_path: entrypoint_path ) entrypoint_namespace_superclasses = version_namespace_superclasses_from_facts(facts).merge( namespace_superclass_details.fetch(:superclasses) ).merge( entrypoint_namespace_superclasses_from_facts(facts) ) fact_superclass_path = facts.dig(:rubygems, :entrypoint_namespace_superclass_path).to_s if entrypoint_namespace_superclasses.any? && File.file?(File.join(project_root, fact_superclass_path)) entrypoint_path = fact_superclass_path elsif namespace_superclass_details[:path] entrypoint_path = namespace_superclass_details[:path] end templated_paths = report.fetch(:recipe_reports, []).map { |recipe_report| recipe_report.fetch(:relative_path, "") } changes = [] outer_namespace_kind = version_namespace_outer_kind(project_root, entrypoint_path, namespace) namespace_kinds = existing_version_namespace_kinds( project_root, version_path, namespace, entrypoint_path: entrypoint_path ) cleanup = version_gem_cleanup_step( project_root, facts, entrypoint_path: entrypoint_path, after_declarations: !entrypoint_namespace_superclasses.empty? ) changes.concat(Array(cleanup[:changed_files])) preserve_version_module_include = existing_version_file_includes_version_module?(project_root, version_path) if preserve_version_module_include.nil? unless templated_paths.include?(version_path) && outer_namespace_kind != :class version = facts.dig(:project_runtime, :version).to_s version = project_gemspec_version(project_root) if version.empty? version = "0.0.1.pre" if version.empty? changes << write_if_changed( project_root, version_path, version_gem_version_file_content( existing_version: existing_version_file_value(project_root, version_path), namespace: namespace, version: version, outer_namespace_kind: outer_namespace_kind, namespace_kinds: namespace_kinds, preserve_version_module_include: preserve_version_module_include ) ) end changes << normalize_version_gem_version_spec( project_root, File.join("spec", entrypoint_require, "version_spec.rb"), entrypoint_require, namespace, ensure_version_gem_require: false, include_version_gem_path: false ) changes.compact! changes.uniq! { name: "version_bootstrap", status: changes.empty? ? "already_current" : "applied", changed_files: changes, cleanup_status: cleanup.fetch(:status) } end |
.opencollective_disabled?(config, env: ENV) ⇒ Boolean
14124 14125 14126 |
# File 'lib/kettle/jem.rb', line 14124 def opencollective_disabled?(config, env: ENV) opencollective_policy(config, env).fetch(:disabled) end |
.opencollective_disabled_file?(relative_path) ⇒ Boolean
13613 13614 13615 |
# File 'lib/kettle/jem.rb', line 13613 def opencollective_disabled_file?(relative_path) OPENCOLLECTIVE_DISABLED_FILES.include?(relative_path.to_s) end |
.opencollective_disabled_files(project_root) ⇒ Object
13607 13608 13609 13610 13611 |
# File 'lib/kettle/jem.rb', line 13607 def opencollective_disabled_files(project_root) OPENCOLLECTIVE_DISABLED_FILES.select do |relative_path| File.exist?(File.join(project_root, relative_path)) end end |
.opencollective_fallback_warnings(funding, github_org) ⇒ Object
14198 14199 14200 14201 14202 14203 14204 14205 14206 14207 |
# File 'lib/kettle/jem.rb', line 14198 def opencollective_fallback_warnings(funding, github_org) return [] unless funding[:open_collective_org_source].to_s == "fallback.default" clean_github_org = github_org.to_s.strip return [] if clean_github_org.empty? || clean_github_org == DEFAULT_OPENCOLLECTIVE_ORG [ "OpenCollective funding org defaulted to #{DEFAULT_OPENCOLLECTIVE_ORG.inspect}, but the GitHub org is #{clean_github_org.inspect}. Configure funding.open_collective or FUNDING_ORG if this is not intended." ] end |
.opencollective_falsey_env(env) ⇒ Object
14171 14172 14173 14174 14175 14176 14177 |
# File 'lib/kettle/jem.rb', line 14171 def opencollective_falsey_env(env) %w[OPENCOLLECTIVE_HANDLE FUNDING_ORG].each do |key| value = env[key] return {key: key, value: value} if falsey_config?(value) end nil end |
.opencollective_org(project_root, config, env, opencollective_disabled: false) ⇒ Object
14179 14180 14181 14182 14183 14184 14185 14186 14187 14188 14189 14190 14191 14192 |
# File 'lib/kettle/jem.rb', line 14179 def opencollective_org(project_root, config, env, opencollective_disabled: false) return if opencollective_disabled env_org = opencollective_org_env(env) return env_org if env_org config_org = opencollective_org_config(config) return config_org if config_org funding_org = opencollective_org_github_funding_file(project_root) return funding_org if funding_org opencollective_org_file(project_root) end |
.opencollective_org_config(config) ⇒ Object
14209 14210 14211 14212 14213 14214 14215 14216 14217 14218 14219 14220 |
# File 'lib/kettle/jem.rb', line 14209 def opencollective_org_config(config) funding = config["funding"] return unless funding.is_a?(Hash) && funding.key?("open_collective") value = funding["open_collective"] return if value == true || falsey_config?(value) org = value.to_s.strip return if org.empty? {org: org, source: "config.funding.open_collective"} end |
.opencollective_org_env(env) ⇒ Object
14222 14223 14224 14225 14226 14227 14228 14229 14230 |
# File 'lib/kettle/jem.rb', line 14222 def opencollective_org_env(env) %w[OPENCOLLECTIVE_HANDLE FUNDING_ORG].each do |key| value = env[key].to_s.strip next if value.empty? || falsey_config?(value) return {org: value, source: "env.#{key}"} end nil end |
.opencollective_org_file(project_root) ⇒ Object
14232 14233 14234 14235 14236 14237 14238 14239 14240 14241 14242 14243 |
# File 'lib/kettle/jem.rb', line 14232 def opencollective_org_file(project_root) path = File.join(project_root, ".opencollective.yml") return unless File.exist?(path) config = YAML.safe_load_file(path, permitted_classes: [], aliases: false) || {} return unless config.is_a?(Hash) org = config.fetch("collective", config["org"]).to_s.strip return if org.empty? {org: org, source: ".opencollective.yml"} end |
.opencollective_org_github_funding_file(project_root) ⇒ Object
14245 14246 14247 14248 14249 14250 14251 14252 14253 14254 14255 14256 |
# File 'lib/kettle/jem.rb', line 14245 def opencollective_org_github_funding_file(project_root) path = File.join(project_root, ".github", "FUNDING.yml") return unless File.exist?(path) funding = YAML.safe_load_file(path, permitted_classes: [], aliases: false) || {} return unless funding.is_a?(Hash) org = Array(funding["open_collective"]).map(&:to_s).map(&:strip).reject(&:empty?).first return unless org {org: org.delete_prefix("@"), source: ".github/FUNDING.yml"} end |
.opencollective_policy(config, env) ⇒ Object
14149 14150 14151 14152 14153 14154 14155 14156 14157 14158 14159 14160 14161 14162 14163 14164 14165 14166 14167 14168 14169 |
# File 'lib/kettle/jem.rb', line 14149 def opencollective_policy(config, env) funding = config["funding"] if funding.is_a?(Hash) && funding.key?("open_collective") config_value = funding["open_collective"] return { disabled: falsey_config?(config_value), source: "config.funding.open_collective", value: config_value.to_s } end env_falsey = opencollective_falsey_env(env) return {disabled: true, source: "env.#{env_falsey.fetch(:key)}", value: env_falsey.fetch(:value).to_s} if env_falsey template_profile = config.dig("templates", "profile").to_s if [MONOREPO_SUBGEM_TEMPLATE_PROFILE, "monorepo-subgem"].include?(template_profile) return {disabled: true, source: "config.templates.profile", value: template_profile} end {disabled: false} end |
.opt_in_workflow_cleanup_files(project_root, template_selection) ⇒ Object
13581 13582 13583 13584 13585 13586 13587 |
# File 'lib/kettle/jem.rb', line 13581 def opt_in_workflow_cleanup_files(project_root, template_selection) include_patterns = Array(template_selection[:include]) OPT_IN_GITHUB_WORKFLOWS.select do |relative_path| File.exist?(File.join(project_root, relative_path)) && !selected_template_path?(relative_path, include_patterns) end end |
.outdent_line(line, spaces) ⇒ Object
8807 8808 8809 8810 8811 |
# File 'lib/kettle/jem.rb', line 8807 def outdent_line(line, spaces) return line if line.strip.empty? line.delete_prefix(" " * spaces) end |
.outdent_source(source, spaces) ⇒ Object
8898 8899 8900 8901 |
# File 'lib/kettle/jem.rb', line 8898 def outdent_source(source, spaces) prefix = " " * spaces source.to_s.lines.map { |line| line.start_with?(prefix) ? line.delete_prefix(prefix) : line }.join end |
.package_runtime_dependency_names(facts) ⇒ Object
9367 9368 9369 9370 |
# File 'lib/kettle/jem.rb', line 9367 def package_runtime_dependency_names(facts) dependencies = facts.to_h.dig(:package, :runtime_dependencies) Array(dependencies).map(&:to_s).reject(&:empty?).uniq end |
.packaged_gemfile_referenced_by_x_std_libs?(target_path, project_root:, template_root_path:) ⇒ Boolean
18769 18770 18771 18772 18773 18774 18775 18776 18777 18778 18779 18780 18781 18782 |
# File 'lib/kettle/jem.rb', line 18769 def packaged_gemfile_referenced_by_x_std_libs?(target_path, project_root:, template_root_path:) relative_path = target_path.to_s.delete_prefix("gemfiles/modular/") return false unless relative_path.start_with?("x_std_libs/") aggregate_paths = [ File.join(template_root_path.to_s, "gemfiles/modular/x_std_libs.gemfile.example"), File.join(project_root.to_s, "gemfiles/modular/x_std_libs.gemfile") ].select { |path| File.file?(path) } aggregate_paths.any? do |path| gemfile_eval_paths(File.read(path)).include?(relative_path) end rescue false end |
.packaged_gemfile_template_ruby_floor(target_path) ⇒ Object
18807 18808 18809 18810 18811 18812 18813 18814 |
# File 'lib/kettle/jem.rb', line 18807 def packaged_gemfile_template_ruby_floor(target_path) path = target_path.to_s if (match = path.match(%r{\Agemfiles/ruby_(\d+)_(\d+)\.gemfile\z})) return "#{match[1]}.#{match[2]}" end path[%r{(?:\A|/)r(\d+\.\d+)(?:/|\z)}, 1] end |
.packaged_template_root ⇒ Object
2577 2578 2579 |
# File 'lib/kettle/jem.rb', line 2577 def packaged_template_root PACKAGED_TEMPLATE_ROOT end |
.paired_modular_gemfile_path(local_relative_path) ⇒ Object
15124 15125 15126 15127 15128 15129 15130 |
# File 'lib/kettle/jem.rb', line 15124 def paired_modular_gemfile_path(local_relative_path) suffix = "_local.gemfile" path = local_relative_path.to_s return unless path.end_with?(suffix) "#{path[0...-suffix.length]}.gemfile" end |
.paperclip_ref(name) ⇒ Object
17732 17733 17734 17735 17736 17737 17738 17739 17740 17741 |
# File 'lib/kettle/jem.rb', line 17732 def paperclip_ref(name) { copyright_notice_explainer: "\u{1F4C4}copyright-notice-explainer", license: "\u{1F4C4}license", license_ref: "\u{1F4C4}license-ref", license_img: "\u{1F4C4}license-img", license_compat: "\u{1F4C4}license-compat", license_compat_img: "\u{1F4C4}license-compat-img" }.fetch(name) end |
.parse_blame_porcelain(output, author_map) ⇒ Object
14860 14861 14862 14863 14864 14865 14866 14867 14868 14869 14870 14871 14872 14873 14874 14875 14876 14877 14878 14879 14880 14881 14882 14883 14884 14885 14886 14887 14888 14889 |
# File 'lib/kettle/jem.rb', line 14860 def parse_blame_porcelain(output, ) = {} current_sha = nil current_name = nil current_email = nil current_time = nil output.to_s.each_line do |raw_line| line = raw_line.chomp if line.match?(/\A[0-9a-f]{40}\s/) current_sha = line[0, 40] = [current_sha] current_name = && [:name] current_email = && [:email] current_time = && [:time] elsif line.start_with?("author ") && !.key?(current_sha.to_s) current_name = line[7..].strip elsif line.start_with?("author-mail ") && !.key?(current_sha.to_s) current_email = line[12..].strip.gsub(/[<>]/, "") elsif line.start_with?("author-time ") && !.key?(current_sha.to_s) current_time = line[12..].strip.to_i elsif line.start_with?("filename ") next unless current_sha && current_email [current_sha] ||= {name: current_name, email: current_email, time: current_time} year = current_time&.positive? ? Time.at(current_time).utc.year.to_s : Time.now.utc.year.to_s [current_email][:name] ||= current_name [current_email][:years] << year end end end |
.parse_changelog_transfer_filter(payload) ⇒ Object
6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 |
# File 'lib/kettle/jem.rb', line 6497 def parse_changelog_transfer_filter(payload) parsed = changelog_transfer_filter_parser.parse(payload.to_s) predicates = (parsed.is_a?(Array) ? parsed : [parsed]).map do |node| predicate = node.fetch(:predicate).fetch(:predicate) { field: predicate.fetch(:field).to_s, operator: predicate.fetch(:operator).to_s, value: predicate.fetch(:value).to_s } end {predicates: predicates} end |
.parse_changelog_transfer_key(key) ⇒ Object
6517 6518 6519 6520 6521 |
# File 'lib/kettle/jem.rb', line 6517 def parse_changelog_transfer_key(key) parse_changelog_transfer_line("#{key} - placeholder") rescue Parslet::ParseFailed nil end |
.parse_changelog_transfer_line(payload) ⇒ Object
6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 |
# File 'lib/kettle/jem.rb', line 6481 def parse_changelog_transfer_line(payload) parsed = changelog_transfer_line_parser.parse(payload.to_s) key_data = parsed.fetch(:key) date = key_data.fetch(:date).to_s sequence = key_data.fetch(:sequence).to_s key = "kettle-jem-template-#{date}-#{sequence}" filter = parsed[:filter] ? parse_changelog_transfer_filter(parsed.fetch(:filter).to_s) : nil { key: key, date: date, sequence: sequence, message: parsed.fetch(:message).to_s, rendered_payload: "#{key} - #{parsed.fetch(:message)}" }.tap { |entry| entry[:filter] = filter if filter } end |
.parse_event_types(types) ⇒ Object
4704 4705 4706 4707 4708 4709 4710 4711 4712 |
# File 'lib/kettle/jem.rb', line 4704 def parse_event_types(types) Kettle::Ndjson.normalize_event_types( Array(types).join(","), event_types: EVENT_TYPES, aliases: EVENT_TYPE_ALIASES ) rescue Kettle::Ndjson::UnknownEventTypeError => error raise ArgumentError, "#{error.}. Supported event types: #{EVENT_TYPES.join(", ")}" end |
.phase_for_recipe(recipe_name, relative_path) ⇒ Object
14049 14050 14051 14052 14053 14054 14055 14056 14057 14058 14059 14060 14061 14062 14063 14064 |
# File 'lib/kettle/jem.rb', line 14049 def phase_for_recipe(recipe_name, relative_path) path = relative_path.to_s name = recipe_name.to_s return :config_sync if path == KETTLE_CONFIG_PATH || path == LEGACY_KETTLE_CONFIG_PATH || name.include?("kettle_config") return :dev_container if path.start_with?(".devcontainer/") return :github_workflows if path.start_with?(".github/workflows/") || path == ".github/FUNDING.yml" return :modular_gemfiles if path.start_with?("gemfiles/modular/") return :spec_helper if path == "spec/spec_helper.rb" || path.start_with?("spec/support/") return :environment_templates if path.start_with?(".env") || path.end_with?(".env") return :git_hooks if path.start_with?(".git/hooks/", "git-hooks/") return :license_files if path.start_with?("LICENSE", "NOTICE") || managed_license_template_basename(path) return :duplicate_check if name.include?("duplicate") return :quality_config if quality_config_path?(path) :remaining_files end |
.phase_reports_for(recipe_reports) ⇒ Object
14028 14029 14030 14031 14032 14033 14034 14035 14036 14037 14038 14039 14040 14041 14042 14043 |
# File 'lib/kettle/jem.rb', line 14028 def phase_reports_for(recipe_reports) reports_by_phase = recipe_reports.group_by { |recipe_report| recipe_report_phase(recipe_report) } PHASE_ORDER.map do |phase| reports = reports_by_phase.fetch(phase, []) changed_reports = reports.select { |recipe_report| recipe_report[:changed] } { phase: phase.to_s, recipes: reports.map { |recipe_report| recipe_report[:recipe_name] }.compact, changed_files: changed_reports.map { |recipe_report| recipe_report[:relative_path] }.compact.uniq.sort, stats: { recipe_count: reports.length, changed_count: changed_reports.length } } end end |
.plan_project(project_root, env: ENV, run_options: {}) ⇒ Object
3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 |
# File 'lib/kettle/jem.rb', line 3928 def plan_project(project_root, env: ENV, run_options: {}) events = () emit_event(events, "run_start", mode: "plan", project_root: project_root.to_s) with_event_phase(events, "runtime_dependencies") { ensure_runtime_dependencies! } with_event_phase(events, "preflight") { preflight_project!(project_root) } template_selection = with_event_phase(events, "template_selection") { template_selection_for(env, ) } checksum_mode = with_event_phase(events, "checksum_mode") { checksum_mode_for(env, ) } decision_policy = with_event_phase(events, "decision_policy") { decision_policy_for(env, ) } git_preflight = with_event_phase(events, "git_preflight") do git_preflight_report(project_root, env: env, template_selection: template_selection) end with_event_phase(events, "git_preflight_enforcement") do enforce_git_preflight!(git_preflight, decision_policy: decision_policy, template_selection: template_selection) end facts = with_event_phase(events, "facts") { discover_facts(project_root, env: env, run_options: ) } pack = with_event_phase(events, "recipe_pack") { recipe_pack(facts) } pack = with_event_phase(events, "recipe_filter") { filter_recipe_pack(pack, template_selection) } files = with_event_phase(events, "read_project_files") { read_project_files(project_root, pack) } template_contents = with_event_phase(events, "read_template_files") { read_template_source_files(project_root, pack) } recipes = pack.fetch(:recipes) recipe_planning_strategy = with_event_phase(events, "recipe_planning_strategy") { recipe_planning_strategy_for(env, ) } recipe_planning_workers = with_event_phase(events, "recipe_planning_workers") { recipe_planning_workers_for(env, ) } recipe_planning_thread_workers = with_event_phase(events, "recipe_planning_thread_workers") { recipe_planning_thread_workers_for(env, ) } recipe_planning_execution = {} recipe_reports = with_event_phase(events, "recipes", total: recipes.length) do execute_recipe_reports( project_root: project_root, recipes: recipes, facts: facts, files: files, template_contents: template_contents, decision_policy: decision_policy, env: env, events: events, strategy: recipe_planning_strategy, workers: recipe_planning_workers, thread_workers: recipe_planning_thread_workers, stats: recipe_planning_execution ) end template_lock = with_event_phase(events, "template_lock") { template_lock_state(project_root) } recipe_reports = with_event_phase(events, "checksum_skip") do apply_checksum_skips(project_root, recipe_reports, checksum_mode: checksum_mode, template_lock: template_lock) end with_event_phase(events, "dependency_conflicts") do validate_modular_dependency_conflicts!(project_root, recipe_reports) end plugin_registry = with_event_phase(events, "plugins") { plugin_registry_for_project(project_root) } changed_files = changed_files_from_recipe_reports(recipe_reports) file_outcomes = template_file_outcomes(recipe_reports) diagnostics = recipe_reports.flat_map { |report| report[:diagnostics] } phase_reports = phase_reports_for(recipe_reports) decision_evaluations = recipe_reports.map { |report| report.fetch(:decision_evaluation) } prompt_requests = decision_evaluations.filter_map { |decision| decision[:prompt] if decision[:prompt_required] } unless plugin_registry.configured_plugins.empty? diagnostics << plugin_lifecycle_diagnostic( plugin_registry, callbacks_run: false, active_runner_phases: [] ) end emit_diagnostic_events(events, diagnostics) run_stats = recipe_run_stats(recipe_reports, diagnostics: diagnostics) warnings = Array(facts[:warnings]).map(&:to_s).reject(&:empty?) warnings.concat(github_workflow_template_pin_warnings(recipe_reports)) report = with_event_phase(events, "report") do { mode: "plan", ready: true, facts: facts, recipe_pack: pack, recipe_reports: recipe_reports, phase_reports: phase_reports, recipe_planning_strategy: recipe_planning_strategy, recipe_planning_workers: recipe_planning_workers, recipe_planning_thread_workers: recipe_planning_thread_workers, recipe_planning_execution: recipe_planning_execution, decision_policy: decision_policy.to_h, checksum_mode: checksum_mode.to_s, template_lock: template_lock, template_selection: template_selection, git_preflight: git_preflight, decision_evaluations: decision_evaluations, prompt_requests: prompt_requests, changed_files: changed_files, file_outcomes: file_outcomes, phase_timings: events.respond_to?(:phase_timings) ? events.phase_timings : [], warnings: warnings.uniq, diagnostics: diagnostics, run_stats: run_stats } end emit_summary_event(events, report) report end |
.plan_readme_style(project_root, env: ENV) ⇒ Object
5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 |
# File 'lib/kettle/jem.rb', line 5819 def plan_readme_style(project_root, env: ENV) facts = discover_facts(project_root, env: env) config = kettle_jem_config(project_root) readme_style = facts[:readme_style] || readme_style_facts( project_root, config, facts.fetch(:license, {}), template_profile: facts[:template_profile], repository: facts[:repository] ) original_path = File.join(project_root, "README.md") original = File.exist?(original_path) ? File.read(original_path) : "" final_content = render_thin_readme(facts, readme_style, original, readme_preserve_config(config)) { mode: "plan", readme_path: "README.md", changed: final_content != original, readme_style: readme_style, final_content: final_content, diagnostics: [] } end |
.plugin_lifecycle_diagnostic(plugin_registry, callbacks_run:, active_runner_phases:) ⇒ Object
13776 13777 13778 13779 13780 13781 13782 13783 13784 13785 13786 13787 13788 13789 13790 13791 13792 |
# File 'lib/kettle/jem.rb', line 13776 def plugin_lifecycle_diagnostic(plugin_registry, callbacks_run:, active_runner_phases:) { kind: "plugin_lifecycle", configured_plugins: plugin_registry.configured_plugins, loaded_plugins: plugin_registry.loaded_plugins, load_errors: plugin_registry.load_errors, registered_hooks: plugin_registry.hooks.map do |hook| { plugin_name: hook.plugin_name, phase: hook.phase.to_s, timing: hook.timing.to_s } end, callbacks_run: callbacks_run, active_runner_phases: active_runner_phases.map(&:to_s) } end |
.plugin_names_from_config(config) ⇒ Object
13764 13765 13766 13767 13768 13769 13770 13771 13772 13773 13774 |
# File 'lib/kettle/jem.rb', line 13764 def plugin_names_from_config(config) raw = config.is_a?(Hash) ? config["plugins"] : nil case raw when Hash raw.each_with_object([]) do |(name, enabled), names| names << name unless falsey_config?(enabled) end else raw end end |
.plugin_registry_for_project(project_root) ⇒ Object
13749 13750 13751 13752 13753 13754 13755 13756 13757 13758 13759 13760 13761 13762 |
# File 'lib/kettle/jem.rb', line 13749 def plugin_registry_for_project(project_root) plugin_names = PluginLoader.normalize_plugin_names(plugin_names_from_config(kettle_jem_config(project_root))) registry = PluginRegistry.new(configured_plugins: plugin_names) plugin_names.each do |plugin_name| PluginLoader.load_plugin!(plugin_name, registry: registry) registry.loaded_plugins << plugin_name rescue Error => e registry.load_errors << { plugin_name: plugin_name, message: e. } end registry end |
.polyform_licenses?(licenses) ⇒ Boolean
17686 17687 17688 |
# File 'lib/kettle/jem.rb', line 17686 def polyform_licenses?(licenses) licenses.any? { |license| license.to_s.start_with?("PolyForm-") } end |
.post_apply_steps(project_root, report) ⇒ Object
4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 |
# File 'lib/kettle/jem.rb', line 4924 def post_apply_steps(project_root, report) selection = report.fetch(:template_selection, {}) scoped_template = Array(selection[:only]).any? return [kettle_jem_state_sync_step(project_root, report)].compact if scoped_template [ *[template_version_gem_bootstrap_step(project_root, report)].flatten, executable_version_entrypoint_sync_step(project_root, report), monorepo_root_gemfile_dependency_sync_step(project_root, report), modular_dependency_conflict_resolution_step(project_root), git_hooks_executable_step(project_root), github_actions_pin_sync_step(project_root), monorepo_subgem_kettle_config_profile_sync_step(project_root, report), kettle_jem_state_sync_step(project_root, report) ].compact end |
.postprocess_funding_markdown_content(content, facts) ⇒ Object
7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 |
# File 'lib/kettle/jem.rb', line 7534 def postprocess_funding_markdown_content(content, facts) open_collective_enabled = !facts.dig(:funding, :open_collective_disabled) processed = apply_markdown_conditional_block(content, "OPEN_COLLECTIVE", keep: open_collective_enabled) processed = apply_markdown_conditional_block(processed, "NO_OPEN_COLLECTIVE", keep: !open_collective_enabled) funding_platforms = facts.dig(:funding, :platforms) if facts.dig(:funding, :open_collective_disabled) processed = remove_readme_badge_and_refs( processed, README_OPEN_COLLECTIVE_FUNDING_BADGES, README_OPEN_COLLECTIVE_LINK_LABELS ) end README_FUNDING_BADGE_POLICIES.each do |platform, policy| next if funding_platform_enabled?(funding_platforms, platform) processed = policy.fetch(:badges).reduce(processed) do |badge_content, badge| remove_readme_badge_and_refs(badge_content, badge, policy.fetch(:labels)) end end processed end |
.postprocess_readme_content(content, facts, project_root: nil, destination_content: nil) ⇒ Object
7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 |
# File 'lib/kettle/jem.rb', line 7397 def postprocess_readme_content(content, facts, project_root: nil, destination_content: nil) return content unless facts processed = with_readme_timing("postprocess.readme_post_processor") do ReadmePostProcessor.process( content: content, min_ruby: minimum_ruby_token(facts.dig(:rubygems, :min_ruby)), engines: facts.dig(:rubygems, :engines) ) end processed = with_readme_timing("postprocess.compatibility_summary") do normalize_readme_compatibility_summary( processed, facts.dig(:rubygems, :engines), minimum_ruby_token(facts.dig(:rubygems, :min_ruby)) ) end processed = with_readme_timing("postprocess.project_heading") { normalize_readme_project_heading(processed, facts) } processed = with_readme_timing("postprocess.synopsis_heading") { normalize_readme_synopsis_heading(processed, facts) } processed = with_readme_timing("postprocess.conditional_blocks") { apply_readme_conditional_blocks(processed, facts) } processed = with_readme_timing("postprocess.badge_policy") { apply_readme_badge_policy(processed, facts) } processed = with_readme_timing("postprocess.rubygems_download_badges") do normalize_readme_rubygems_download_badges(processed) end processed = with_readme_timing("postprocess.logo_link_prune") { prune_unused_readme_logo_link_definitions(processed) } processed = with_readme_timing("postprocess.kloc_badge") do apply_readme_kloc_badge(processed, facts, project_root, destination_content: destination_content) end processed = with_readme_timing("postprocess.monorepo_thin_projection") { apply_monorepo_subgem_thin_readme_projection(processed, facts) } processed = with_readme_timing("postprocess.monorepo_subgem_recipe") { apply_monorepo_subgem_readme_recipe(processed, facts) } processed = with_readme_timing("postprocess.metadata_block") do replace_existing_markdown_managed_block(processed, "kettle-jem:metadata", (facts)) end with_readme_timing("postprocess.blank_lines") { normalize_readme_blank_line_runs(processed) } end |
.preceding_comment_block_start_line(lines, line_number) ⇒ Object
8982 8983 8984 8985 8986 |
# File 'lib/kettle/jem.rb', line 8982 def preceding_comment_block_start_line(lines, line_number) line = line_number line -= 1 while line > 1 && lines[line - 2].to_s.strip.start_with?("#") line end |
.preferred_template_source(template_root, configured_source, opencollective_disabled: false) ⇒ Object
18868 18869 18870 18871 18872 18873 18874 18875 |
# File 'lib/kettle/jem.rb', line 18868 def preferred_template_source(template_root, configured_source, opencollective_disabled: false) base = configured_source.sub(/\.example\z/, "") candidates = [] candidates << "#{base}.no-osc.example" if opencollective_disabled && base != "README.md" candidates << "#{base}.example" candidates << configured_source candidates.find { |relative_path| File.exist?(File.join(template_root, relative_path)) } end |
.preferred_template_token_value(derived_value, config_value, env, env_key) ⇒ Object
14698 14699 14700 14701 14702 14703 14704 14705 14706 14707 |
# File 'lib/kettle/jem.rb', line 14698 def preferred_template_token_value(derived_value, config_value, env, env_key) env_clean = env[env_key].to_s.strip return env_clean if present_template_token_value?(env_clean) config_clean = config_value.to_s.strip return config_clean if present_template_token_value?(config_clean) return unless present_template_token_value?(derived_value) derived_value.to_s.strip end |
.preflight_project!(project_root) ⇒ Object
13617 13618 13619 13620 13621 13622 |
# File 'lib/kettle/jem.rb', line 13617 def preflight_project!(project_root) paths = Dir.glob(File.join(project_root, "*.gemspec")).sort gemfile_path = File.join(project_root, "Gemfile") paths << gemfile_path if File.exist?(gemfile_path) paths.each { |path| preflight_ruby_syntax!(project_root, path) } end |
.preflight_ruby_syntax!(project_root, path) ⇒ Object
13676 13677 13678 13679 13680 13681 13682 13683 13684 13685 13686 |
# File 'lib/kettle/jem.rb', line 13676 def preflight_ruby_syntax!(project_root, path) if defined?(RubyVM::InstructionSequence) RubyVM::InstructionSequence.compile_file(path) else _stdout, stderr, status = Open3.capture3(RbConfig.ruby, "-c", path) raise SyntaxError, stderr unless status.success? end rescue SyntaxError => e relative_path = path.delete_prefix("#{project_root}/") raise Error, "Preflight failed for #{relative_path}: #{e.}" end |
.prepare_github_workflow_template(content, recipe, facts) ⇒ Object
7308 7309 7310 7311 7312 7313 7314 |
# File 'lib/kettle/jem.rb', line 7308 def prepare_github_workflow_template(content, recipe, facts) processed = prune_disabled_github_workflow_engine_jobs(content, facts) return processed unless recipe.fetch(:target_path).to_s == ".github/workflows/framework-ci.yml" return processed if facts.to_h.dig(:ci, :framework_matrix).to_h.empty? synchronize_github_actions_framework_ci(processed, facts) end |
.prepare_readme_template(content, readme_style) ⇒ Object
7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 |
# File 'lib/kettle/jem.rb', line 7822 def prepare_readme_template(content, readme_style) style = readme_style || {} prepared = with_readme_timing("prepare.integration_badges") { prune_readme_integration_badges(content, style) } if style[:workflow_paths] prepared = with_readme_timing("prepare.workflow_post_processor") do ReadmePostProcessor.process( content: prepared, min_ruby: "0", workflow_paths: style[:workflow_paths] ) end end if style[:workflow_paths] prepared = with_readme_timing("prepare.workflow_link_prune") do prune_missing_workflow_link_definitions(prepared, style[:workflow_paths]) end prepared = with_readme_timing("prepare.workflow_inline_prune") do ReadmePostProcessor.prune_orphaned_workflow_inline_references(prepared) end end omitted_sections = Array(style[:omitted_sections]).map(&:to_s) omitted_sections << "security" if style.key?(:security_enabled) && !style[:security_enabled] omitted_sections << "floss_funding" if style.key?(:floss_funding_enabled) && !style[:floss_funding_enabled] with_readme_timing("prepare.remove_sections") do remove_readme_sections(prepared, omitted_sections.map { |section| section.tr("_", " ") }) end end |
.present_template_token_value?(value) ⇒ Boolean
14709 14710 14711 14712 |
# File 'lib/kettle/jem.rb', line 14709 def present_template_token_value?(value) clean = value.to_s.strip !clean.empty? && !token_placeholder?(clean) end |
.preserve_destination_gemfile_source(content, destination_content) ⇒ Object
8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 |
# File 'lib/kettle/jem.rb', line 8040 def preserve_destination_gemfile_source(content, destination_content) destination_source = ruby_call_records(destination_content, :source).find do |call| call.receiver.nil? && ruby_string_argument(call) end template_source = ruby_call_records(content, :source).find do |call| call.receiver.nil? && ruby_string_argument(call) end return content unless destination_source && template_source destination_text = destination_source.location.slice return content if destination_text == template_source.location.slice replace_record_ranges(content, { template_source.location.start_line => { start_line: template_source.location.start_line, end_line: ruby_node_source_end_line(template_source), replacement: "#{destination_text}\n" } }) end |
.preserve_destination_only_gemspec_metadata(content, template_content:, destination_content:, template_receiver:, destination_receiver:) ⇒ Object
10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 |
# File 'lib/kettle/jem.rb', line 10912 def ( content, template_content:, destination_content:, template_receiver:, destination_receiver: ) template_keys = (template_content, receiver: template_receiver).map do |record| record.fetch(:key) end merged_keys = (content, receiver: template_receiver).map do |record| record.fetch(:key) end destination_records = (destination_content, receiver: destination_receiver).select do |record| !template_keys.include?(record.fetch(:key)) && !merged_keys.include?(record.fetch(:key)) && !(record) end return content if destination_records.empty? insertion = destination_records.map do |record| normalize_gemspec_receiver(record.fetch(:source).rstrip, from: destination_receiver, to: template_receiver) end.join("\n") + "\n" anchor = (content, receiver: template_receiver).last anchor ||= gemspec_assignment_records(content, receiver: template_receiver).find { |record| record.fetch(:field) == "homepage" } return content unless anchor insert_lines_after(content, anchor.fetch(:end_line), insertion) end |
.preserve_destination_readme_kloc_badge(content, destination_content) ⇒ Object
7465 7466 7467 7468 7469 7470 7471 7472 |
# File 'lib/kettle/jem.rb', line 7465 def preserve_destination_readme_kloc_badge(content, destination_content) destination_match = destination_content.to_s.match(README_KLOC_BADGE_PATTERN) return content unless destination_match content.to_s.gsub(README_KLOC_BADGE_PATTERN) do "#{Regexp.last_match(1)}#{destination_match[2]}#{Regexp.last_match(3)}" end end |
.preserve_gemspec_dependency_lines(template_content, destination_content, template_receiver:, destination_receiver:, facts: nil) ⇒ Object
11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 |
# File 'lib/kettle/jem.rb', line 11720 def preserve_gemspec_dependency_lines(template_content, destination_content, template_receiver:, destination_receiver:, facts: nil) namespace = facts.to_h.dig(:rubygems, :namespace).to_s template_dependencies = gemspec_dependency_line_index(template_content, receiver: template_receiver) destination_dependencies = gemspec_dependency_line_index(destination_content, receiver: destination_receiver) .transform_values do |source| normalized = normalize_gemspec_receiver(source, from: destination_receiver, to: template_receiver) normalized = normalize_gemspec_dependency_version_requirements(normalized, receiver: template_receiver, namespace: namespace) enforce_gemspec_dependency_minimum_requirements(normalized, receiver: template_receiver) end destination_dependencies = destination_dependencies.reject do |key, _source| retired_gemspec_development_dependency_key?(key) end return template_content if destination_dependencies.empty? replacements, additions = destination_dependencies.partition do |key, source| template_dependencies.key?(key) && gemspec_dependency_source_newer?(source, template_dependencies.fetch(key), receiver: template_receiver) end.map(&:to_h) merged = replace_matching_gemspec_dependency_lines(template_content, replacements, receiver: template_receiver) append_missing_gemspec_dependency_lines(merged, additions, receiver: template_receiver) end |
.preserve_gemspec_freeze_blocks(content, destination_content, facts:, receiver:) ⇒ Object
11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 |
# File 'lib/kettle/jem.rb', line 11743 def preserve_gemspec_freeze_blocks(content, destination_content, facts:, receiver:) blocks = freeze_marker_blocks(destination_content, freeze_token: facts.to_h.dig(:project_runtime, :freeze_token)) return content if blocks.empty? merged = content.to_s blocks.each do |block| next if gemspec_freeze_block_structurally_managed?(block, receiver: receiver) next if merged.include?(block.join) insertion = "\n#{block.join}\n" require_paths = gemspec_assignment_records(merged, receiver: receiver).find { |record| record.fetch(:field) == "require_paths" } merged = if require_paths insert_lines_before(merged, require_paths.fetch(:start_line), insertion) else insert_lines_before(merged, gemspec_end_line(merged), insertion) end end ensure_trailing_newline(merged.gsub(/\n{3,}/, "\n\n")) end |
.preserve_github_workflow_project_settings(recipe, content, destination_content, project_root:) ⇒ Object
7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 |
# File 'lib/kettle/jem.rb', line 7369 def preserve_github_workflow_project_settings(recipe, content, destination_content, project_root:) return content unless recipe.fetch(:target_path).to_s == ".github/workflows/coverage.yml" thresholds = coverage_thresholds_from_project_mise(project_root) thresholds = coverage_thresholds_from_yaml_workflow(destination_content) if thresholds.empty? preserved = content thresholds.each do |key, value| preserved = replace_yaml_scalar_line(preserved, key, value) end preserved end |
.preserve_mise_project_settings(recipe, content, destination_content, project_root:, facts:) ⇒ Object
7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 |
# File 'lib/kettle/jem.rb', line 7248 def preserve_mise_project_settings(recipe, content, destination_content, project_root:, facts:) return content unless recipe.fetch(:target_path).to_s == "mise.toml" thresholds = coverage_thresholds_from_mise(destination_content) thresholds = coverage_thresholds_from_workflow(project_root) if thresholds.empty? preserved = thresholds.reduce(content.to_s) do |result, (key, value)| replace_toml_string_scalar_line(result, key, value) end return preserved unless monorepo_subgem_template_profile?(facts) # Subgems generate useful coverage reports, but their narrow suites cannot # satisfy the aggregate thresholds enforced by the monorepo root. replace_toml_string_scalar_line(preserved, "K_SOUP_COV_MIN_HARD", "false") end |
.preserve_newer_github_workflow_action_pins(content, destination_content) ⇒ Object
19936 19937 19938 19939 19940 19941 19942 19943 19944 19945 19946 19947 19948 19949 19950 19951 19952 19953 |
# File 'lib/kettle/jem.rb', line 19936 def preserve_newer_github_workflow_action_pins(content, destination_content) destination_records = github_workflow_action_pin_records(destination_content) return content if destination_records.empty? destination_by_key = destination_records.to_h { |record| [github_workflow_action_pin_key(record), record] } lines = content.to_s.lines github_workflow_action_pin_records(content).each do |record| destination = destination_by_key[github_workflow_action_pin_key(record)] next unless destination next if destination.fetch(:sha) == record.fetch(:sha) lines[record.fetch(:line_index)] = replace_github_workflow_action_pin_sha( lines.fetch(record.fetch(:line_index)), destination.fetch(:sha) ) end lines.join end |
.preserve_readme_front_sections(template_content, destination_content) ⇒ Object
18032 18033 18034 18035 18036 18037 18038 18039 18040 18041 18042 18043 18044 18045 18046 18047 |
# File 'lib/kettle/jem.rb', line 18032 def preserve_readme_front_sections(template_content, destination_content) front_sections = readme_destination_front_sections(destination_content) return template_content if front_sections.empty? template_sections = markdown_sections(template_content) template_h1 = template_sections.find { |section| section.fetch(:level) == 1 } insert_before = template_sections.find do |section| section.fetch(:level) == 2 && section.fetch(:start) > template_h1.to_h.fetch(:start, -1) end return template_content unless insert_before lines = template_content.split("\n", -1) inserted = front_sections.map { |section| "#{section.fetch(:heading)}\n#{section.fetch(:body).rstrip}" }.join("\n\n") lines[(template_h1.fetch(:start) + 1)...insert_before.fetch(:start)] = ["", *inserted.split("\n"), ""] lines.join("\n") end |
.preserve_readme_h1(merged_content, destination_content, preserve_config) ⇒ Object
18133 18134 18135 18136 18137 18138 18139 18140 18141 18142 18143 |
# File 'lib/kettle/jem.rb', line 18133 def preserve_readme_h1(merged_content, destination_content, preserve_config) return merged_content if preserve_config.empty? merged_h1 = markdown_sections(merged_content).find { |section| section.fetch(:level) == 1 } destination_h1 = markdown_sections(destination_content).find { |section| section.fetch(:level) == 1 } return merged_content unless merged_h1 && destination_h1 lines = merged_content.split("\n", -1) lines[merged_h1.fetch(:start)] = destination_h1.fetch(:heading) lines.join("\n") end |
.preserve_readme_managed_block(merged_content, destination_content, marker) ⇒ Object
18145 18146 18147 18148 18149 18150 |
# File 'lib/kettle/jem.rb', line 18145 def preserve_readme_managed_block(merged_content, destination_content, marker) destination_block = markdown_managed_block(destination_content, marker) return merged_content unless destination_block replace_markdown_managed_block(merged_content, marker, destination_block) end |
.preserve_readme_sections(template_content, destination_content, preserve_config) ⇒ Object
18071 18072 18073 18074 18075 18076 18077 18078 18079 18080 18081 18082 18083 18084 18085 18086 18087 18088 18089 18090 18091 18092 18093 18094 18095 18096 18097 18098 18099 18100 18101 18102 18103 |
# File 'lib/kettle/jem.rb', line 18071 def preserve_readme_sections(template_content, destination_content, preserve_config) template_sections = markdown_sections(template_content) destination_sections = markdown_sections(destination_content) destination_lookup = destination_sections.to_h { |section| [section.fetch(:base), section] } preserve_targets = readme_preserve_targets(template_sections, destination_lookup, preserve_config) return template_content if preserve_targets.empty? template_bases = template_sections.map { |section| section.fetch(:base) }.to_set extra_sections_by_anchor = readme_extra_preserved_sections_by_anchor( destination_sections, template_bases, preserve_targets ) lines = template_content.split("\n", -1) template_sections.reverse_each do |section| base = section.fetch(:base) extra_sections = extra_sections_by_anchor[base].to_a next if !preserve_targets.include?(base) && extra_sections.empty? replacement = if preserve_targets.include?(base) destination_section = destination_lookup[base] || aliased_readme_destination_section(base, destination_lookup, preserve_config) next unless destination_section "#{section.fetch(:heading)}\n#{destination_section.fetch(:body)}" else lines[section.fetch(:start)..section.fetch(:end)].join("\n") end replacement = ([replacement] + extra_sections.map { |extra| "#{extra.fetch(:heading)}\n#{extra.fetch(:body)}" }).join("\n") lines[section.fetch(:start)..section.fetch(:end)] = replacement end lines.join("\n") end |
.previous_nonblank_line_number(content, line_number) ⇒ Object
19405 19406 19407 19408 19409 19410 |
# File 'lib/kettle/jem.rb', line 19405 def previous_nonblank_line_number(content, line_number) lines = content.to_s.lines cursor = line_number - 2 cursor -= 1 while cursor >= 0 && lines[cursor].strip.empty? (cursor >= 0) ? cursor + 1 : nil end |
.prism_call_nodes(node) ⇒ Object
8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 |
# File 'lib/kettle/jem.rb', line 8702 def prism_call_nodes(node) return [] unless node nodes = [] stack = [node] until stack.empty? current = stack.pop nodes << current if current.is_a?(::Prism::CallNode) stack.concat(current.compact_child_nodes) end nodes end |
.prism_parse_success(content) ⇒ Object
9941 9942 9943 9944 9945 |
# File 'lib/kettle/jem.rb', line 9941 def prism_parse_success(content) ensure_runtime_dependencies! result = ::Prism.parse(content.to_s) result if result.success? end |
.prism_ruby_merge_options(recipe) ⇒ Object
9329 9330 9331 9332 9333 9334 9335 |
# File 'lib/kettle/jem.rb', line 9329 def (recipe) { method_move_policy: ruby_method_move_policy(recipe), merge_template_requires: true, template_only_placement: :after_anchor } end |
.prism_subtree_contains_call?(node, call_name) ⇒ Boolean
8881 8882 8883 8884 8885 |
# File 'lib/kettle/jem.rb', line 8881 def prism_subtree_contains_call?(node, call_name) node.breadth_first_search_all do |child| child.is_a?(::Prism::CallNode) && child.name == call_name end.any? end |
.prism_subtree_contains_simplecov_require?(node) ⇒ Boolean
8678 8679 8680 8681 8682 |
# File 'lib/kettle/jem.rb', line 8678 def prism_subtree_contains_simplecov_require?(node) node.compact_child_nodes.any? do |child| simplecov_require_call_node?(child) || prism_subtree_contains_simplecov_require?(child) end end |
.prism_subtree_contains_string?(node, string) ⇒ Boolean
8887 8888 8889 8890 8891 |
# File 'lib/kettle/jem.rb', line 8887 def prism_subtree_contains_string?(node, string) node.breadth_first_search_all do |child| child.is_a?(::Prism::StringNode) && child.unescaped == string end.any? end |
.process_result_adapter_failure?(merge_result) ⇒ Boolean
9275 9276 9277 9278 9279 9280 9281 |
# File 'lib/kettle/jem.rb', line 9275 def process_result_adapter_failure?(merge_result) diagnostics = merge_result.respond_to?(:fetch) ? merge_result.fetch(:diagnostics, []) : [] diagnostics.any? do |diagnostic| = diagnostic[:message] || diagnostic["message"] .to_s.include?("TreeSitterLanguagePack::ProcessResult") && .to_s.include?("undefined method") end end |
.project_appraisals_recording_enabled?(project_root) ⇒ Boolean
19165 19166 19167 19168 19169 19170 |
# File 'lib/kettle/jem.rb', line 19165 def project_appraisals_recording_enabled?(project_root) appraisals_path = File.join(project_root.to_s, "Appraisals") return false unless File.file?(appraisals_path) gemfile_eval_paths(File.read(appraisals_path)).any? { |path| path.to_s.include?("modular/recording/") } end |
.project_entrypoint_require(project_root, package_name, config: nil) ⇒ Object
13039 13040 13041 13042 13043 13044 13045 13046 13047 |
# File 'lib/kettle/jem.rb', line 13039 def project_entrypoint_require(project_root, package_name, config: nil) configured = (config || kettle_jem_config(project_root)).dig("rubygems", "entrypoint_require").to_s.strip return configured unless configured.empty? discovered = GemSpecReader.load(project_root).fetch(:entrypoint_require, "").to_s.strip return discovered unless discovered.empty? package_name.to_s.tr("-", "/") end |
.project_gemspec_declares_version_gem?(project_root) ⇒ Boolean
5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 |
# File 'lib/kettle/jem.rb', line 5730 def project_gemspec_declares_version_gem?(project_root) path = Dir.glob(File.join(project_root, "*.gemspec")).min return false unless path = (path) dependencies = Array([:runtime_dependencies] || ["runtime_dependencies"]) if dependencies.empty? spec = load_project_gemspec(path) dependencies = Array(spec&.runtime_dependencies) end dependencies.any? { |dependency| dependency.name == "version_gem" } end |
.project_gemspec_metadata(project_root, gemspec_path, spec: nil) ⇒ Object
15244 15245 15246 15247 15248 15249 15250 15251 15252 15253 15254 15255 15256 15257 15258 15259 15260 15261 15262 15263 15264 15265 15266 15267 15268 15269 15270 15271 15272 15273 15274 15275 |
# File 'lib/kettle/jem.rb', line 15244 def (project_root, gemspec_path, spec: nil) = GemSpecReader.load(project_root) spec ||= load_project_gemspec(gemspec_path) = {} unless .is_a?(Hash) = .dup if spec [:gemspec_path] ||= gemspec_path [:gem_name] = spec.name.to_s if (, :gem_name).nil? [:version] = spec.version.to_s if (, :version).nil? [:min_ruby] = min_ruby_version(spec.required_ruby_version) if [:min_ruby].nil? [:homepage] = spec.homepage.to_s if (, :homepage).nil? [:homepage_uri] = spec..fetch("homepage_uri", nil) if (, :homepage_uri).nil? [:source_code_uri] = spec..fetch("source_code_uri", nil) if (, :source_code_uri).nil? [:funding_uri] = spec..fetch("funding_uri", nil) if (, :funding_uri).nil? [:authors] = Array(spec.).compact.uniq if Array([:authors]).empty? [:email] = Array(spec.email).compact.uniq if Array([:email]).empty? [:summary] = spec.summary.to_s if (, :summary).nil? [:description] = spec.description.to_s if (, :description).nil? [:licenses] = Array(spec.licenses) if Array([:licenses]).empty? [:required_ruby_version] = spec.required_ruby_version if [:required_ruby_version].nil? [:require_paths] = Array(spec.require_paths) if Array([:require_paths]).empty? [:bindir] = spec.bindir.to_s if (, :bindir).nil? [:executables] = Array(spec.executables) if Array([:executables]).empty? end return {} unless present_template_token_value?([:gem_name]) rescue LoadError, StandardError (gemspec_path) end |
.project_gemspec_version(project_root) ⇒ Object
5723 5724 5725 5726 5727 5728 |
# File 'lib/kettle/jem.rb', line 5723 def project_gemspec_version(project_root) path = Dir.glob(File.join(project_root, "*.gemspec")).min return "" unless path load_project_gemspec(path)&.version.to_s end |
.project_homepage_uri(config, env, yard_host:, gemspec_homepage_uri: nil) ⇒ Object
15438 15439 15440 15441 15442 15443 15444 15445 15446 15447 |
# File 'lib/kettle/jem.rb', line 15438 def project_homepage_uri(config, env, yard_host:, gemspec_homepage_uri: nil) derived = if present_template_token_value?(gemspec_homepage_uri) gemspec_homepage_uri elsif present_template_token_value?(yard_host) "https://#{yard_host}" end normalize_project_homepage_uri( preferred_template_token_value(derived, project_runtime_config_value(config, "homepage_uri"), env, "KJ_HOMEPAGE_URI") ) end |
.project_namespace(entrypoint_namespace:, version_namespace:, metadata_namespace:, default_namespace:) ⇒ Object
15709 15710 15711 15712 15713 15714 15715 15716 15717 15718 15719 15720 15721 |
# File 'lib/kettle/jem.rb', line 15709 def project_namespace(entrypoint_namespace:, version_namespace:, metadata_namespace:, default_namespace:) if namespace_descendant?(entrypoint_namespace, version_namespace) return version_namespace end if namespace_descendant?(version_namespace, default_namespace) || namespace_descendant?(entrypoint_namespace, default_namespace) return default_namespace end [entrypoint_namespace, version_namespace, , default_namespace].find do |candidate| !candidate.to_s.empty? end end |
.project_recording_enabled?(project_root, config) ⇒ Boolean
19159 19160 19161 19162 19163 |
# File 'lib/kettle/jem.rb', line 19159 def project_recording_enabled?(project_root, config) return true if appraisal_recording_enabled?(config) project_appraisals_recording_enabled?(project_root) end |
.project_relative_path(path, project_root) ⇒ Object
15132 15133 15134 15135 15136 15137 15138 15139 |
# File 'lib/kettle/jem.rb', line 15132 def project_relative_path(path, project_root) = File.(project_root.to_s) = File.(path.to_s) prefix = "#{}#{File::SEPARATOR}" return unless .start_with?(prefix) [prefix.length..].to_s end |
.project_runtime_config_value(config, key) ⇒ Object
15463 15464 15465 15466 15467 15468 15469 15470 |
# File 'lib/kettle/jem.rb', line 15463 def project_runtime_config_value(config, key) token_config = token_config_values(config) runtime_config = token_config["project_runtime"].is_a?(Hash) ? token_config["project_runtime"] : {} top_level_value = config[key] return top_level_value if present_template_token_value?(top_level_value) runtime_config[key] end |
.project_runtime_facts(config, env, package_name:, source_url:, author_domain:, min_ruby:, test_min_ruby:, version:, project_root: nil, gemspec_metadata: {}, repository: {}) ⇒ Object
15012 15013 15014 15015 15016 15017 15018 15019 15020 15021 15022 15023 15024 15025 15026 15027 15028 15029 15030 15031 15032 15033 15034 15035 15036 15037 15038 15039 15040 15041 15042 15043 15044 15045 15046 15047 15048 15049 15050 15051 15052 15053 15054 15055 15056 15057 15058 15059 15060 15061 15062 15063 |
# File 'lib/kettle/jem.rb', line 15012 def project_runtime_facts( config, env, package_name:, source_url:, author_domain:, min_ruby:, test_min_ruby:, version:, project_root: nil, gemspec_metadata: {}, repository: {} ) = Time.now configured_project_emoji = preferred_template_token_value(nil, config["project_emoji"], env, "KJ_PROJECT_EMOJI") yard_host = project_yard_host(config, env, package_name: package_name, author_domain: ) local_modular_eval_paths = local_modular_runtime_eval_paths(project_root, , package_name: package_name) direct_sibling_gems = direct_sibling_runtime_gems( project_root, , package_name: package_name, local_modular_eval_paths: local_modular_eval_paths ) compact_hash( freeze_token: config.dig("defaults", "freeze_token").to_s.empty? ? "kettle-jem" : config.dig("defaults", "freeze_token").to_s, kettle_jem_version: VERSION, template_run_date: .strftime("%Y-%m-%d"), template_run_year: .year.to_s, kettle_dev_local_gems: kettle_dev_local_gems(config), local_gemfile_nomono_bootstrap: local_gemfile_nomono_bootstrap(package_name), main_gemfile_kettle_family_gem: main_gemfile_kettle_family_gem(package_name), main_gemfile_nomono_bootstrap: main_gemfile_nomono_bootstrap(package_name), package_name: package_name.to_s, yard_host: yard_host, homepage_uri: project_homepage_uri(config, env, yard_host: yard_host, gemspec_homepage_uri: (, :homepage_uri)), project_emoji: preferred_template_token_value("💎", config["project_emoji"], env, "KJ_PROJECT_EMOJI").to_s, project_emoji_configured: !configured_project_emoji.to_s.empty?, min_divergence_threshold: preferred_template_token_value(nil, config["min_divergence_threshold"], env, "KJ_MIN_DIVERGENCE_THRESHOLD").to_s, min_dev_ruby: test_min_ruby.to_s, test_min_ruby: test_min_ruby.to_s, version: version.to_s, github_org: github_org_from_url(source_url).to_s, main_gemfile_direct_sibling_block: main_gemfile_direct_sibling_block( direct_sibling_gems, package_name: package_name, source_url: source_url, project_root: project_root, repository: repository, local_modular_eval_paths: local_modular_eval_paths.values.flatten ) ) end |
.project_runtime_template_tokens(project_runtime) ⇒ Object
15357 15358 15359 15360 15361 15362 15363 15364 15365 15366 15367 15368 15369 15370 15371 15372 15373 15374 |
# File 'lib/kettle/jem.rb', line 15357 def project_runtime_template_tokens(project_runtime) { "KJ|FREEZE_TOKEN" => project_runtime[:freeze_token].to_s, "KJ|KETTLE_JEM_VERSION" => project_runtime[:kettle_jem_version].to_s, "KJ|TEMPLATE_RUN_DATE" => project_runtime[:template_run_date].to_s, "KJ|TEMPLATE_RUN_YEAR" => project_runtime[:template_run_year].to_s, "KJ|KETTLE_DEV_LOCAL_GEMS" => project_runtime[:kettle_dev_local_gems].to_s, "KJ|LOCAL_GEMFILE_NOMONO_BOOTSTRAP" => project_runtime[:local_gemfile_nomono_bootstrap].to_s, "KJ|MAIN_GEMFILE_KETTLE_FAMILY_GEM" => project_runtime[:main_gemfile_kettle_family_gem].to_s, "KJ|MAIN_GEMFILE_NOMONO_BOOTSTRAP" => project_runtime[:main_gemfile_nomono_bootstrap].to_s, "KJ|MAIN_GEMFILE_DIRECT_SIBLING_BLOCK" => project_runtime[:main_gemfile_direct_sibling_block].to_s, "KJ|PACKAGE_NAME" => project_runtime[:package_name].to_s, "KJ|YARD_HOST" => project_runtime[:yard_host].to_s, "KJ|HOMEPAGE_URI" => project_runtime[:homepage_uri].to_s, "KJ|PROJECT_EMOJI" => project_runtime[:project_emoji].to_s, "KJ|MIN_DIVERGENCE_THRESHOLD" => project_runtime[:min_divergence_threshold].to_s } end |
.project_uses_version_gem?(project_root, _entrypoint_require, facts = nil) ⇒ Boolean
5743 5744 5745 5746 5747 |
# File 'lib/kettle/jem.rb', line 5743 def project_uses_version_gem?(project_root, _entrypoint_require, facts = nil) return false if version_gem_explicitly_disabled?(facts) version_gem_enabled?(facts) || project_gemspec_declares_version_gem?(project_root) end |
.project_yard_host(config, env, package_name:, author_domain:) ⇒ Object
15376 15377 15378 15379 15380 15381 |
# File 'lib/kettle/jem.rb', line 15376 def project_yard_host(config, env, package_name:, author_domain:) derived = "#{package_name.to_s.tr("_", "-")}.#{.to_s.empty? ? "example.com" : }" normalize_project_hostname( preferred_template_token_value(derived, project_runtime_config_value(config, "yard_host"), env, "KJ_YARD_HOST") ) end |
.prune_appraisals_below_min_ruby(content, min_ruby) ⇒ Object
10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 |
# File 'lib/kettle/jem.rb', line 10491 def prune_appraisals_below_min_ruby(content, min_ruby) return content if min_ruby.to_s.empty? minimum = Gem::Version.new(min_ruby.to_s) remove_indexes = Set.new appraisal_call_records(content).each do |record| version = ruby_appraisal_name_version(record.fetch(:name)) next unless version && version < minimum (record.fetch(:start_line)..record.fetch(:end_line)).each { |line_number| remove_indexes << (line_number - 1) } end kept = content.to_s.lines.each_with_index.reject { |_line, index| remove_indexes.include?(index) }.map(&:first) ensure_trailing_newline(kept.join.gsub(/\n{3,}/, "\n\n")) rescue ArgumentError content end |
.prune_appraisals_recording_entries(content, facts) ⇒ Object
10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 |
# File 'lib/kettle/jem.rb', line 10255 def prune_appraisals_recording_entries(content, facts) remove_indexes = Set.new lines = content.to_s.lines unless facts.to_h.dig(:ci, :recording) ruby_call_records(content, :eval_gemfile).each do |call| path = ruby_string_argument(call) next unless path.to_s.include?("modular/recording/") (call.location.start_line..ruby_node_source_end_line(call)).each { |line_number| remove_indexes << (line_number - 1) } end end head_appraisal = appraisal_call_records(content).find { |record| record.fetch(:name) == "head" } if head_appraisal gemfile_gem_call_records(content).each do |record| next unless record.fetch(:name) == "cgi" next unless record.fetch(:start_line) >= head_appraisal.fetch(:start_line) next unless record.fetch(:end_line) <= head_appraisal.fetch(:end_line) start_index = record.fetch(:start_line) - 1 while start_index.positive? && gemfile_comment_line?(lines[start_index - 1]) start_index -= 1 end (start_index..(record.fetch(:end_line) - 1)).each { |index| remove_indexes << index } end end return content if remove_indexes.empty? kept = lines.each_with_index.reject { |_line, index| remove_indexes.include?(index) }.map(&:first) ensure_trailing_newline(kept.join.gsub(/\n{3,}/, "\n\n")) end |
.prune_disabled_github_workflow_engine_jobs(content, facts) ⇒ Object
7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 |
# File 'lib/kettle/jem.rb', line 7316 def prune_disabled_github_workflow_engine_jobs(content, facts) engines = facts.to_h.dig(:rubygems, :engines) return content if engines.nil? enabled = Array(engines).map { |engine| engine.to_s.strip.downcase }.reject(&:empty?).to_set return content if enabled.empty? disabled_job_keys = GITHUB_WORKFLOW_ENGINE_JOB_KEYS.except(*enabled).values return content if disabled_job_keys.empty? delete_yaml_top_level_mapping_entries( content, parent_key: "jobs", child_keys: disabled_job_keys ) rescue Psych::Exception content end |
.prune_empty_parent_directories(project_root, relative_path) ⇒ Object
15947 15948 15949 15950 15951 15952 15953 15954 15955 15956 15957 15958 |
# File 'lib/kettle/jem.rb', line 15947 def prune_empty_parent_directories(project_root, relative_path) current = relative_path.to_s while !current.empty? && current != "." path = File.join(project_root, current) begin Dir.rmdir(path) rescue SystemCallError break end current = File.dirname(current) end end |
.prune_github_workflow_matrix_by_min_ruby(content, facts) ⇒ Object
9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 |
# File 'lib/kettle/jem.rb', line 9076 def prune_github_workflow_matrix_by_min_ruby(content, facts) min_ruby = minimum_ruby_token(facts.to_h.dig(:ci, :test_min_ruby) || facts.to_h.dig(:rubygems, :min_ruby)) return content if min_ruby.to_s.empty? minimum = Gem::Version.new(min_ruby) lines = content.to_s.lines remove_indexes = Set.new yaml_mapping_nodes(content).each do |mapping| next unless prune_workflow_matrix_item?(mapping, minimum) (mapping.start_line...mapping.end_line).each { |line_index| remove_indexes << line_index } end return content if remove_indexes.empty? ensure_trailing_newline(lines.each_with_index.reject { |_line, line_index| remove_indexes.include?(line_index) }.map(&:first).join.gsub(/\n{3,}/, "\n\n")) rescue content end |
.prune_legacy_kettle_config_keys(content) ⇒ Object
12492 12493 12494 12495 12496 12497 |
# File 'lib/kettle/jem.rb', line 12492 def prune_legacy_kettle_config_keys(content) pruned = KETTLE_CONFIG_LEGACY_KEY_PATHS.reduce(content.to_s) do |updated, legacy_key| remove_yaml_scalar_path(updated, legacy_key.fetch(:path)) end remove_obsolete_simplecov_keep_destination_config(pruned) end |
.prune_missing_workflow_link_definitions(content, workflow_paths) ⇒ Object
7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 |
# File 'lib/kettle/jem.rb', line 7863 def prune_missing_workflow_link_definitions(content, workflow_paths) ensure_runtime_dependencies! existing = Array(workflow_paths).map { |path| path.to_s.delete_prefix("./") }.to_set Ast::Crispr::Markdown::Markly.document_context(content: content.to_s, source_label: "README.md") .structural_owners(owner_scope: :link_definitions) .filter_map do |owner| workflow_path = readme_workflow_path_from_url(owner.url) owner.label if !workflow_path.empty? && !existing.include?(workflow_path) end .then { |labels| ReadmePostProcessor.delete_markdown_link_definitions(content, labels) } end |
.prune_readme_integration_badges(content, readme_style) ⇒ Object
7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 |
# File 'lib/kettle/jem.rb', line 7850 def prune_readme_integration_badges(content, readme_style) ensure_runtime_dependencies! integrations = Array(readme_style[:missing_integrations]) + Array(readme_style[:disabled_integrations]) labels = [] pruned = integrations.uniq.reduce(content.to_s) do |result, integration| labels.concat(README_INTEGRATION_LINK_LABELS.fetch(integration.to_s, [])) README_INTEGRATION_BADGE_PATTERNS.fetch(integration.to_s, []).reduce(result) do |memo, pattern| memo.gsub(pattern, "") end end ReadmePostProcessor.delete_markdown_link_definitions(pruned, labels).gsub(/[ \t]{2,}/, " ") end |
.prune_unused_readme_logo_link_definitions(content) ⇒ Object
7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 |
# File 'lib/kettle/jem.rb', line 7443 def prune_unused_readme_logo_link_definitions(content) owners = ReadmePostProcessor.markdown_structural_owners(content, :inline_references, :link_definitions) referenced = owners.fetch(:inline_references).flat_map(&:labels).map(&:to_s).to_set labels = owners.fetch(:link_definitions).filter_map do |owner| label = owner.label.to_s label if label.start_with?("🖼️") && !referenced.include?(label) end return content if labels.empty? ReadmePostProcessor.delete_markdown_link_definitions(content, labels) end |
.prune_workflow_matrix_item?(mapping, minimum) ⇒ Boolean
9227 9228 9229 9230 9231 9232 9233 9234 9235 |
# File 'lib/kettle/jem.rb', line 9227 def prune_workflow_matrix_item?(mapping, minimum) ruby = yaml_mapping_scalar_value(mapping, "ruby").to_s.strip return true if !ruby.empty? && Gem::Version.new(ruby) < minimum appraisal_ruby = appraisal_ruby_version(yaml_mapping_scalar_value(mapping, "appraisal")).to_s.strip !appraisal_ruby.empty? && Gem::Version.new(appraisal_ruby) < minimum rescue ArgumentError false end |
.quality_config_path?(path) ⇒ Boolean
14066 14067 14068 14069 14070 14071 14072 14073 14074 14075 14076 |
# File 'lib/kettle/jem.rb', line 14066 def quality_config_path?(path) %w[ .rubocop.yml .reek.yml .standard.yml .simplecov .yard-lint.yml .yardopts Rakefile ].include?(path) end |
.rakefile_default_task_call?(call) ⇒ Boolean
19377 19378 19379 19380 19381 19382 19383 19384 19385 19386 19387 |
# File 'lib/kettle/jem.rb', line 19377 def rakefile_default_task_call?(call) argument = call.arguments&.arguments&.first case argument when ::Prism::SymbolNode argument.unescaped.to_s == "default" when ::Prism::KeywordHashNode argument.elements.any? { |element| element.key.is_a?(::Prism::SymbolNode) && element.key.unescaped.to_s == "default" } else false end end |
.rakefile_default_task_records(content) ⇒ Object
19366 19367 19368 19369 19370 19371 19372 19373 19374 19375 |
# File 'lib/kettle/jem.rb', line 19366 def rakefile_default_task_records(content) top_level_ruby_call_records(content, :task).filter_map do |call| next unless rakefile_default_task_call?(call) { start_line: call.location.start_line, end_line: ruby_node_source_end_line(call) } end end |
.rakefile_require_records(content) ⇒ Object
19327 19328 19329 19330 19331 19332 19333 19334 19335 19336 19337 19338 |
# File 'lib/kettle/jem.rb', line 19327 def rakefile_require_records(content) top_level_ruby_call_records(content, :require).filter_map do |call| name = ruby_string_argument(call) next unless name { name: name, start_line: call.location.start_line, end_line: ruby_node_source_end_line(call) } end end |
.rakefile_scaffold_cleanup(content, facts) ⇒ Object
6811 6812 6813 6814 6815 |
# File 'lib/kettle/jem.rb', line 6811 def rakefile_scaffold_cleanup(content, facts) return {content: content.to_s, delete_selectors: []} if facts[:template_profile].to_s == MONOREPO_ROOT_TEMPLATE_PROFILE delete_rakefile_scaffold(content) end |
.rakefile_scaffold_cleanup_recipe?(recipe) ⇒ Boolean
6807 6808 6809 |
# File 'lib/kettle/jem.rb', line 6807 def rakefile_scaffold_cleanup_recipe?(recipe) recipe.fetch(:name) == "rakefile_scaffold_cleanup" end |
.rakefile_scaffold_delete_selectors(content) ⇒ Object
19294 19295 19296 19297 19298 19299 19300 19301 19302 19303 19304 19305 19306 19307 19308 19309 19310 19311 19312 19313 19314 19315 19316 19317 19318 19319 19320 19321 19322 19323 19324 19325 |
# File 'lib/kettle/jem.rb', line 19294 def rakefile_scaffold_delete_selectors(content) selectors = [] rakefile_require_records(content).each do |record| selector_id = case record.fetch(:name) when "bundler/gem_tasks" "rakefile_scaffold_require_bundler_gem_tasks" when "rspec/core/rake_task" "rakefile_scaffold_require_rspec_core_rake_task" when "rubocop/rake_task" "rakefile_scaffold_require_rubocop_rake_task" end next unless selector_id selectors << rakefile_selector(selector_id, record.fetch(:start_line), record.fetch(:end_line), "wrapper_selected_scaffold_require") end rakefile_task_class_records(content).each do |record| selector_id = case record.fetch(:receiver) when "RSpec::Core::RakeTask" "rakefile_scaffold_rspec_task" when "RuboCop::RakeTask" "rakefile_scaffold_rubocop_task" end next unless selector_id selectors << rakefile_selector(selector_id, record.fetch(:start_line), record.fetch(:end_line), "wrapper_selected_scaffold_task") end selectors.concat(rakefile_task_block_selectors(content)) selectors.sort_by { |selector| [selector.fetch(:start_line), selector.fetch(:end_line)] } end |
.rakefile_selector(selector_id, start_line, end_line, reason) ⇒ Object
19412 19413 19414 19415 19416 19417 19418 19419 19420 |
# File 'lib/kettle/jem.rb', line 19412 def rakefile_selector(selector_id, start_line, end_line, reason) { selector_id: selector_id, selector_family: "structural_owner_range", start_line: start_line, end_line: end_line, reason: reason } end |
.rakefile_task_block_selectors(content) ⇒ Object
19353 19354 19355 19356 19357 19358 19359 19360 19361 19362 19363 19364 |
# File 'lib/kettle/jem.rb', line 19353 def rakefile_task_block_selectors(content) rakefile_default_task_records(content).filter_map do |record| next if rakefile_template_default_task?(content, record) rakefile_selector( "rakefile_scaffold_task_default", record.fetch(:start_line), record.fetch(:end_line), "wrapper_selected_scaffold_task" ) end end |
.rakefile_task_class_records(content) ⇒ Object
19340 19341 19342 19343 19344 19345 19346 19347 19348 19349 19350 19351 |
# File 'lib/kettle/jem.rb', line 19340 def rakefile_task_class_records(content) top_level_ruby_call_records(content, :new).filter_map do |call| receiver = call.receiver&.slice next unless %w[RSpec::Core::RakeTask RuboCop::RakeTask].include?(receiver) { receiver: receiver, start_line: call.location.start_line, end_line: ruby_node_source_end_line(call) } end end |
.rakefile_template_default_task?(content, record) ⇒ Boolean
19389 19390 19391 19392 19393 19394 19395 19396 |
# File 'lib/kettle/jem.rb', line 19389 def rakefile_template_default_task?(content, record) desc_lines = top_level_ruby_call_records(content, :desc).filter_map do |call| next unless ruby_string_argument(call) == "Default tasks aggregator" call.location.start_line end desc_lines.include?(previous_nonblank_line_number(content, record.fetch(:start_line))) end |
.rbs_merge_options(recipe) ⇒ Object
10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 |
# File 'lib/kettle/jem.rb', line 10398 def (recipe) = { preference: (recipe.dig(:template_preference, :preference) || "destination").to_sym, add_template_only_nodes: true, freeze_token: recipe.dig(:template_preference, :freeze_token) || "kettle-jem" } if !recipe.dig(:template_preference, :add_template_only_nodes).nil? configured = DecisionPolicy.value_to_boolean(recipe.dig(:template_preference, :add_template_only_nodes)) [:add_template_only_nodes] = configured unless configured.nil? end end |
.read_project_file(project_root, relative_path) ⇒ Object
16592 16593 16594 16595 |
# File 'lib/kettle/jem.rb', line 16592 def read_project_file(project_root, relative_path) path = File.join(project_root, relative_path) File.file?(path) ? File.read(path) : "" end |
.read_project_files(project_root, pack) ⇒ Object
7057 7058 7059 7060 7061 7062 |
# File 'lib/kettle/jem.rb', line 7057 def read_project_files(project_root, pack) pack.fetch(:recipes).map { |recipe| recipe.fetch(:target_path) }.uniq.to_h do |relative_path| path = File.join(project_root, relative_path) [relative_path, File.exist?(path) ? File.read(path) : ""] end end |
.read_template_source_files(project_root, pack) ⇒ Object
7064 7065 7066 7067 7068 |
# File 'lib/kettle/jem.rb', line 7064 def read_template_source_files(project_root, pack) pack.fetch(:recipes).filter_map { |recipe| recipe_template_content_path(project_root, recipe) }.uniq.to_h do |path| [path, File.read(path)] end end |
.readme_config_hash(config) ⇒ Object
17015 17016 17017 17018 |
# File 'lib/kettle/jem.rb', line 17015 def readme_config_hash(config) raw_config = config.is_a?(Hash) ? config["readme"] : nil raw_config.is_a?(Hash) ? raw_config : {} end |
.readme_copyright_notice(copyright_lines, copyright_prefix, author) ⇒ Object
17509 17510 17511 17512 17513 17514 17515 17516 17517 17518 17519 17520 17521 |
# File 'lib/kettle/jem.rb', line 17509 def readme_copyright_notice(copyright_lines, copyright_prefix, ) lines = copyright_notice_lines(copyright_lines, copyright_prefix, ).map { |line| "- #{line}" } <<~MARKDOWN.chomp See [LICENSE.md][#{paperclip_ref(:license)}] for the official copyright notice. <details markdown="1"> <summary>Copyright holders</summary> #{lines.join("\n")} </details> MARKDOWN end |
.readme_corporate_sponsor_template_tokens(readme_sponsors) ⇒ Object
17262 17263 17264 17265 17266 |
# File 'lib/kettle/jem.rb', line 17262 def readme_corporate_sponsor_template_tokens(readme_sponsors) { "KJ|README:CORPORATE_SPONSORS" => readme_sponsors[:row].to_s } end |
.readme_corporate_sponsors(config, env) ⇒ Object
16902 16903 16904 16905 16906 16907 16908 16909 |
# File 'lib/kettle/jem.rb', line 16902 def readme_corporate_sponsors(config, env) readme_config = readme_config_hash(config) configured = normalize_readme_corporate_sponsors( readme_config["corporate_sponsors"] || readme_config["sponsors"] ) inherited = normalize_readme_corporate_sponsors_json(env["KETTLE_JEM_CORPORATE_SPONSORS_JSON"]) deduplicate_readme_corporate_sponsors(configured + inherited) end |
.readme_corporate_sponsors_facts(config, env) ⇒ Object
16894 16895 16896 16897 16898 16899 16900 |
# File 'lib/kettle/jem.rb', line 16894 def readme_corporate_sponsors_facts(config, env) sponsors = readme_corporate_sponsors(config, env) compact_hash( entries: sponsors, row: readme_corporate_sponsors_row(sponsors) ) end |
.readme_corporate_sponsors_row(sponsors) ⇒ Object
16949 16950 16951 16952 16953 16954 16955 16956 16957 16958 16959 16960 16961 16962 |
# File 'lib/kettle/jem.rb', line 16949 def readme_corporate_sponsors_row(sponsors) return "" if sponsors.empty? label = sponsors.one? ? "Corporate sponsor:" : "Corporate sponsors:" logos = sponsors.map do |sponsor| [ %(<a href="#{html_attribute_escape(sponsor.fetch(:url))}">), %(<img alt="#{html_attribute_escape(sponsor.fetch(:name))}"), %( src="#{html_attribute_escape(sponsor.fetch(:img_src))}" height="24"/>), "</a>" ].join end.join(" ") %(<p><sub>#{label} #{logos} <a href="#-floss-funding">Become a sponsor</a></sub></p>) end |
.readme_default_logo_width(entries, one:, two:) ⇒ Object
17227 17228 17229 17230 17231 17232 17233 17234 |
# File 'lib/kettle/jem.rb', line 17227 def readme_default_logo_width(entries, one:, two:) case entries.length when 1 one when 2 two end end |
.readme_destination_front_sections(destination_content) ⇒ Object
18049 18050 18051 18052 18053 18054 18055 18056 18057 18058 18059 18060 18061 |
# File 'lib/kettle/jem.rb', line 18049 def readme_destination_front_sections(destination_content) sections = markdown_sections(destination_content) h1 = sections.find { |section| section.fetch(:level) == 1 } synopsis = sections.find { |section| section.fetch(:level) == 2 && section.fetch(:base) == "synopsis" } return [] unless h1 && synopsis sections.select do |section| section.fetch(:level) == 2 && section.fetch(:start) > h1.fetch(:start) && section.fetch(:end) < synopsis.fetch(:start) && readme_front_section_preserved?(section) end end |
.readme_dev_test_stack_table(package_name) ⇒ Object
14360 14361 14362 14363 14364 14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 14381 14382 14383 |
# File 'lib/kettle/jem.rb', line 14360 def readme_dev_test_stack_table(package_name) rows = README_DEV_TEST_STACK_GEMS.reject { |gem| gem.fetch(:name) == package_name.to_s }.map do |gem| name = gem.fetch(:name) clickgems_url = "https://clickgems.clickhouse.com/dashboard/#{name}" badge_url = "https://img.shields.io/gem/dt/#{name}.svg?style=flat-square" [ "| [#{name}](#{clickgems_url})", "[GitHub](#{gem.fetch(:repo)})", gem.fetch(:role), "[](#{clickgems_url}) |" ].join(" | ") end [ '<details markdown="1">', "<summary>How kettle-dev manages complexity in tests</summary>", "", "| Gem | Source | Role | Total downloads |", "|-----|--------|------|---------------------|", *rows, "", "</details>" ].join("\n") end |
.readme_disabled_integrations(readme, integration_disabled: []) ⇒ Object
17893 17894 17895 17896 17897 17898 17899 17900 17901 17902 17903 |
# File 'lib/kettle/jem.rb', line 17893 def readme_disabled_integrations(readme, integration_disabled: []) disabled = [] disabled.concat(Array(integration_disabled).map(&:to_s)) integrations = readme["integrations"].is_a?(Hash) ? readme["integrations"] : {} badges = readme["badges"].is_a?(Hash) ? readme["badges"] : {} integrations.each do |name, value| disabled << name.to_s if falsey_config?(value) end disabled.concat(Array(badges["disabled"]).map(&:to_s)) disabled.map { |name| normalize_integration_name(name) }.uniq & README_INTEGRATIONS end |
.readme_extra_preserved_sections_by_anchor(destination_sections, template_bases, preserve_targets) ⇒ Object
18105 18106 18107 18108 18109 18110 18111 18112 18113 18114 18115 18116 18117 18118 18119 18120 |
# File 'lib/kettle/jem.rb', line 18105 def readme_extra_preserved_sections_by_anchor(destination_sections, template_bases, preserve_targets) destination_sections.each_with_index.each_with_object({}) do |(section, index), result| base = section.fetch(:base) next if template_bases.include?(base) next unless preserve_targets.include?(base) next if readme_section_has_preserved_ancestor?(destination_sections, index, preserve_targets) anchor = destination_sections[0...index].reverse.find do |candidate| template_bases.include?(candidate.fetch(:base)) end next unless anchor result[anchor.fetch(:base)] ||= [] result[anchor.fetch(:base)] << section end end |
.readme_family_intro_and_backend_matrix(readme_style = {}) ⇒ Object
14612 14613 14614 14615 14616 14617 14618 14619 14620 14621 14622 14623 14624 14625 14626 14627 14628 14629 14630 14631 14632 |
# File 'lib/kettle/jem.rb', line 14612 def readme_family_intro_and_backend_matrix(readme_style = {}) return "" unless readme_style.is_a?(Hash) && readme_style[:package_family].to_s == "structuredmerge" [ "<details markdown=\"1\">", "<summary>StructuredMerge package family</summary>", "", "This gem is part of the StructuredMerge Ruby package family. The implementation inventory, layering model, and backend notes live in the [root package-family guide][sm-family-guide]. Shared behavior is defined by the [StructuredMerge fixtures][sm-family-fixtures] and implemented by the [Go][sm-family-go], [Ruby][sm-family-ruby], [Rust][sm-family-rust], and [TypeScript][sm-family-typescript] repositories.", "", "Merge analysis must enter parsing through `tree_haver`. Parser-specific gems register concrete TreeHaver backends; substrate gems register grammar mappings and keep shared format or language merge behavior in one place. Missing backends fail closed instead of falling back to direct parser-library calls.", "", "</details>", "", "[sm-family-guide]: https://github.com/structuredmerge/structuredmerge-ruby#package-family", "[sm-family-fixtures]: https://github.com/structuredmerge/structuredmerge-fixtures", "[sm-family-go]: https://github.com/structuredmerge/structuredmerge-go", "[sm-family-ruby]: https://github.com/structuredmerge/structuredmerge-ruby", "[sm-family-rust]: https://github.com/structuredmerge/structuredmerge-rust", "[sm-family-typescript]: https://github.com/structuredmerge/structuredmerge-typescript" ].join("\n") end |
.readme_floss_funding_enabled?(license, config_value) ⇒ Boolean
17886 17887 17888 17889 17890 17891 |
# File 'lib/kettle/jem.rb', line 17886 def readme_floss_funding_enabled?(license, config_value) return false if falsey_config?(config_value) return true if %w[true yes 1 always enabled].include?(config_value.to_s.strip.downcase) Array(license[:spdx]).map(&:to_s).include?("MIT") end |
.readme_fossa_project(readme, repository) ⇒ Object
17815 17816 17817 17818 17819 17820 17821 17822 17823 17824 17825 17826 17827 17828 17829 17830 17831 17832 17833 17834 17835 |
# File 'lib/kettle/jem.rb', line 17815 def readme_fossa_project(readme, repository) badges = readme["badges"].is_a?(Hash) ? readme["badges"] : {} return "" unless badges.key?("fossa") value = badges["fossa"] return "" if falsey_config?(value) project = case value when Hash return "" if falsey_config?(value["enabled"]) value["project"] || value["project_id"] || value["slug"] else value end normalized = project.to_s.strip return normalized unless normalized.empty? || %w[true yes 1 on enabled].include?(normalized.downcase) slug = repository.is_a?(Hash) ? repository[:slug].to_s : "" slug.empty? ? "" : "git+github.com/#{slug}" end |
.readme_fossa_template_tokens(readme_style) ⇒ Object
14395 14396 14397 14398 14399 14400 14401 14402 14403 14404 14405 14406 14407 |
# File 'lib/kettle/jem.rb', line 14395 def readme_fossa_template_tokens(readme_style) project = readme_style.fetch(:fossa_project, "").to_s return {"KJ|README:FOSSA_BADGE" => "", "KJ|README:FOSSA_REFS" => ""} if project.empty? encoded_project = URI.encode_www_form_component(project) { "KJ|README:FOSSA_BADGE" => README_FOSSA_BADGE, "KJ|README:FOSSA_REFS" => [ "[🧪fossa]: https://app.fossa.com/projects/#{encoded_project}?ref=badge_shield", "[🧪fossa-img]: https://app.fossa.com/api/projects/#{encoded_project}.svg?type=shield" ].join("\n") } end |
.readme_front_section_preserved?(section) ⇒ Boolean
18063 18064 18065 |
# File 'lib/kettle/jem.rb', line 18063 def readme_front_section_preserved?(section) section.fetch(:base) == "important" || readme_section_contains_badge_cloud?(section) end |
.readme_h2_synopsis_logo_entries(config, org:, gem_name:, repository: {}) ⇒ Object
17060 17061 17062 17063 17064 17065 17066 |
# File 'lib/kettle/jem.rb', line 17060 def readme_h2_synopsis_logo_entries(config, org:, gem_name:, repository: {}) entries = readme_h2_synopsis_logo_specs(config).filter_map do |spec| readme_top_logo_entry_from_option(spec.fetch(:type), org: org, gem_name: gem_name, repository: repository)&.merge(width: spec[:width]) end entries = deduplicate_readme_top_logo_entries(entries) readme_top_logo_entries_with_asset_size(entries) end |
.readme_h2_synopsis_logo_options(config) ⇒ Object
16968 16969 16970 |
# File 'lib/kettle/jem.rb', line 16968 def (config) readme_h2_synopsis_logo_specs(config).map { |spec| spec.fetch(:type) } end |
.readme_h2_synopsis_logo_row(entries) ⇒ Object
17220 17221 17222 17223 17224 17225 |
# File 'lib/kettle/jem.rb', line 17220 def readme_h2_synopsis_logo_row(entries) default_width = readme_default_logo_width(entries, one: "10%", two: "8%") entries.map do |entry| readme_logo_html(entry, align: "right", width: entry[:width] || default_width) end.join(" ") end |
.readme_h2_synopsis_logo_specs(config) ⇒ Object
16972 16973 16974 16975 16976 16977 16978 16979 16980 16981 16982 16983 16984 16985 16986 16987 16988 16989 16990 16991 |
# File 'lib/kettle/jem.rb', line 16972 def readme_h2_synopsis_logo_specs(config) readme_config = readme_config_hash(config) h2_synopsis_logos = readme_config["h2_synopsis_logos"] normalized = normalized_readme_logo_specs(h2_synopsis_logos) return normalized unless normalized.empty? raw_top_logos = readme_config["top_logos"] || readme_config["top_logo_options"] normalized_top_logos = normalized_readme_logo_specs(raw_top_logos) synopsis_from_top_logos = normalized_top_logos.select { |spec| README_H2_SYNOPSIS_LOGO_DEFAULTS.include?(spec.fetch(:type)) } return synopsis_from_top_logos unless synopsis_from_top_logos.empty? legacy_mode = readme_config["top_logo_mode"].to_s.strip.downcase.tr("-", "_") = README_TOP_LOGO_LEGACY_MODE_MAP[legacy_mode] synopsis_from_legacy = Array().filter_map do |option| {type: option, width: nil} if README_H2_SYNOPSIS_LOGO_DEFAULTS.include?(option) end return synopsis_from_legacy unless synopsis_from_legacy.empty? raw_top_logos ? [] : README_H2_SYNOPSIS_LOGO_DEFAULTS.map { |option| {type: option, width: nil} } end |
.readme_integration_configured?(project_root, integration) ⇒ Boolean
17970 17971 17972 17973 17974 17975 17976 17977 17978 17979 17980 17981 17982 17983 17984 17985 17986 17987 17988 17989 17990 17991 17992 17993 17994 |
# File 'lib/kettle/jem.rb', line 17970 def readme_integration_configured?(project_root, integration) case integration when "codecov" File.exist?(File.join(project_root, ".codecov.yml")) || File.exist?(File.join(project_root, "codecov.yml")) || github_workflows_include?(project_root, "codecov/codecov-action") when "coveralls" File.exist?(File.join(project_root, ".coveralls.yml")) || github_workflows_include?(project_root, "coverallsapp/github-action") when "qlty" File.exist?(File.join(project_root, ".qlty/qlty.toml")) || File.exist?(File.join(project_root, ".qlty.yml")) || github_workflows_include?(project_root, "qltysh/qlty-action") when "codeql" File.exist?(File.join(project_root, ".github/workflows/codeql.yml")) || File.exist?(File.join(project_root, ".github/workflows/codeql-analysis.yml")) || github_workflows_include?(project_root, "github/codeql-action") when "skywalking-eyes" File.exist?(File.join(project_root, ".github/workflows/license-eye.yml")) || File.exist?(File.join(project_root, ".github/workflows/license-eye.yaml")) || github_workflows_include?(project_root, "apache/skywalking-eyes/dependency") else false end end |
.readme_integration_project_root(project_root, template_profile, repository) ⇒ Object
17837 17838 17839 17840 17841 |
# File 'lib/kettle/jem.rb', line 17837 def readme_integration_project_root(project_root, template_profile, repository) return project_root unless repository_monorepo_subproject?(repository) Array(repository && repository[:local_root]).find { |path| !path.to_s.empty? } || project_root end |
.readme_kloc_from_changelog(project_root, version) ⇒ Object
7474 7475 7476 7477 7478 7479 7480 7481 |
# File 'lib/kettle/jem.rb', line 7474 def readme_kloc_from_changelog(project_root, version) return if project_root.to_s.empty? || version.to_s.empty? changelog_path = File.join(project_root, "CHANGELOG.md") return unless File.file?(changelog_path) changelog_coverage_kloc(current_changelog_version_section(File.read(changelog_path), version)) end |
.readme_license_intro(licenses, author_email: nil, license_source_url: nil, custom_license: false) ⇒ Object
17546 17547 17548 17549 17550 17551 17552 17553 17554 17555 17556 17557 17558 |
# File 'lib/kettle/jem.rb', line 17546 def readme_license_intro(licenses, author_email: nil, license_source_url: nil, custom_license: false) return "The licensing terms for this project are provided in [LICENSE.txt](LICENSE.txt). See [LICENSE.md](LICENSE.md) for details." if custom_license return mit_readme_license_intro(license_source_url: license_source_url) if licenses == ["MIT"] intro = "The gem is available under the following license#{"s" if licenses.size > 1}: " \ "#{licenses.map { |license| license_link(license, license_source_url: license_source_url) }.join(", ")}.\n" \ "See [LICENSE.md][#{paperclip_ref(:license)}] for details." intro += "\n\n#{license_contact_line(, context: :readme)}" if non_mit_licenses?(licenses) guide_table = license_use_case_guide_table(licenses, author_email: , license_source_url: license_source_url) intro += "\n\n### License use-case guide\n\n#{guide_table}" if guide_table intro end |
.readme_license_refs(expression, compat_category, license_source_url: nil) ⇒ Object
17577 17578 17579 17580 17581 17582 17583 17584 17585 17586 |
# File 'lib/kettle/jem.rb', line 17577 def readme_license_refs(expression, compat_category, license_source_url: nil) [ "[#{paperclip_ref(:copyright_notice_explainer)}]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year", "[#{paperclip_ref(:license)}]: LICENSE.md", "[#{paperclip_ref(:license_ref)}]: #{license_badge_ref(expression, license_source_url: license_source_url)}", "[#{paperclip_ref(:license_img)}]: #{license_badge_img(expression)}", "[#{paperclip_ref(:license_compat)}]: #{license_compat_ref(compat_category)}", "[#{paperclip_ref(:license_compat_img)}]: #{license_compat_img(compat_category)}" ].join("\n") end |
.readme_logo_config_value(spec) ⇒ Object
12558 12559 12560 12561 |
# File 'lib/kettle/jem.rb', line 12558 def readme_logo_config_value(spec) width = spec[:width].to_s width.empty? ? spec.fetch(:type).tr("_", "-") : "#{spec.fetch(:type).tr("_", "-")}|#{width}" end |
.readme_logo_facts(config, package_name:, github_org:, repository: {}) ⇒ Object
16871 16872 16873 16874 16875 16876 16877 16878 16879 16880 16881 16882 16883 16884 16885 16886 16887 16888 16889 16890 16891 16892 |
# File 'lib/kettle/jem.rb', line 16871 def readme_logo_facts(config, package_name:, github_org:, repository: {}) top_entries = readme_top_logo_entries( config, org: github_org.to_s, gem_name: package_name.to_s, repository: repository || {} ) h2_synopsis_entries = readme_h2_synopsis_logo_entries( config, org: github_org.to_s, gem_name: package_name.to_s, repository: repository || {} ) all_entries = deduplicate_readme_top_logo_entries(top_entries + h2_synopsis_entries) compact_hash( top_logos: (config).join(","), h2_synopsis_logos: (config).join(","), top_logo_row: readme_top_logo_row(top_entries), h2_synopsis_logo_row: readme_h2_synopsis_logo_row(h2_synopsis_entries), top_logo_refs: readme_top_logo_refs(all_entries) ) end |
.readme_logo_html(entry, align:, width: nil) ⇒ Object
17240 17241 17242 17243 17244 17245 17246 17247 17248 |
# File 'lib/kettle/jem.rb', line 17240 def readme_logo_html(entry, align:, width: nil) attributes = [ %(alt="#{html_attribute_escape("#{entry[:label]} Logo#{entry[:credit_separator]}#{entry[:credit]}")}"), %(src="#{html_attribute_escape(entry[:image_url])}") ] attributes << %(width="#{html_attribute_escape(width)}") if width attributes << %(align="#{html_attribute_escape(align)}") %(<a href="#{html_attribute_escape(entry[:href])}"><img #{attributes.join(" ")}/></a>) end |
.readme_logo_options_from_config(config, primary_key, secondary_key, defaults) ⇒ Object
16993 16994 16995 |
# File 'lib/kettle/jem.rb', line 16993 def (config, primary_key, secondary_key, defaults) readme_logo_specs_from_config(config, primary_key, secondary_key, defaults).map { |spec| spec.fetch(:type) } end |
.readme_logo_specs_from_config(config, primary_key, secondary_key, defaults) ⇒ Object
16997 16998 16999 17000 17001 17002 17003 17004 17005 17006 17007 17008 17009 17010 17011 17012 17013 |
# File 'lib/kettle/jem.rb', line 16997 def readme_logo_specs_from_config(config, primary_key, secondary_key, defaults) readme_config = readme_config_hash(config) raw_logos = readme_config[primary_key] || readme_config[secondary_key] normalized = normalized_readme_logo_specs(raw_logos) selected = normalized.select { |spec| defaults.include?(spec.fetch(:type)) } return selected unless selected.empty? return [] if raw_logos legacy_mode = readme_config["top_logo_mode"].to_s.strip.downcase.tr("-", "_") = README_TOP_LOGO_LEGACY_MODE_MAP[legacy_mode] selected_legacy = Array().filter_map do |option| {type: option, width: nil} if defaults.include?(option) end return selected_legacy unless selected_legacy.empty? defaults.map { |option| {type: option, width: nil} } end |
.readme_logo_template_tokens(readme_logo) ⇒ Object
17254 17255 17256 17257 17258 17259 17260 |
# File 'lib/kettle/jem.rb', line 17254 def readme_logo_template_tokens(readme_logo) { "KJ|README:H2_SYNOPSIS_LOGO_ROW" => readme_logo[:h2_synopsis_logo_row].to_s, "KJ|README:TOP_LOGO_ROW" => readme_logo[:top_logo_row].to_s, "KJ|README:TOP_LOGO_REFS" => readme_logo[:top_logo_refs].to_s } end |
.readme_metadata_block(facts) ⇒ Object
19206 19207 19208 19209 19210 19211 19212 19213 19214 19215 19216 19217 19218 19219 19220 19221 19222 19223 19224 19225 19226 19227 |
# File 'lib/kettle/jem.rb', line 19206 def (facts) package = facts.fetch(:package) funding_urls = facts.fetch(:funding, {}).fetch(:urls, []) rows = [ ["Package", package[:name]], ["Description", package[:description]], ["Homepage", package[:homepage_url]], ["Source", package[:source_url]], ["License", (facts)], ["Funding", funding_urls.join(", ")] ].reject { |(_, value)| value.to_s.empty? } [ "<!-- kettle-jem:metadata:start -->", "| Field | Value |", "|---|---|", *rows.map do |field, value| "| #{(field)} | #{(value)} |" end, "<!-- kettle-jem:metadata:end -->" ].join("\n") end |
.readme_metadata_license_expression(facts) ⇒ Object
19233 19234 19235 19236 19237 19238 19239 19240 19241 19242 |
# File 'lib/kettle/jem.rb', line 19233 def (facts) package = facts.fetch(:package) expression = package[:license_expression].to_s spdx_ids = Array(facts.dig(:license, :spdx)).map(&:to_s).reject(&:empty?) return expression if expression.empty? || spdx_ids.empty? spdx_ids.sort_by { |spdx_id| -spdx_id.length }.reduce(expression) do |formatted, spdx_id| formatted.gsub(/\b#{Regexp.escape(spdx_id)}\b/, "`#{spdx_id}`") end end |
.readme_metadata_table_cell(value) ⇒ Object
19229 19230 19231 |
# File 'lib/kettle/jem.rb', line 19229 def (value) value.to_s.split(/\r\n?|\n/).map(&:strip).join("<br>").gsub("|", "\\|") end |
.readme_preserve_config(config) ⇒ Object
18215 18216 18217 18218 18219 18220 18221 18222 18223 18224 18225 18226 18227 18228 18229 |
# File 'lib/kettle/jem.rb', line 18215 def readme_preserve_config(config) readme = config["readme"] return {} unless readme.is_a?(Hash) result = {} result[:sections] = Array(readme["preserve_sections"]) if readme.key?("preserve_sections") result[:patterns] = Array(readme["preserve_patterns"]) if readme.key?("preserve_patterns") if readme["section_aliases"].is_a?(Hash) result[:aliases] = README_SECTION_ALIASES.merge( readme["section_aliases"].transform_keys { |key| normalize_readme_heading(key) } .transform_values { |value| normalize_readme_heading(value) } ) end result end |
.readme_preserve_config_without_partial_sections(preserve_config, partial_sections) ⇒ Object
5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 |
# File 'lib/kettle/jem.rb', line 5906 def readme_preserve_config_without_partial_sections(preserve_config, partial_sections) normalized_partials = partial_sections.map { |section| normalize_readme_section_key(section) } return preserve_config if normalized_partials.empty? config = (preserve_config || {}).dup sections = if config.key?(:sections) Array(config[:sections]).map { |section| normalize_readme_section_key(section) } else README_DEFAULT_PRESERVE_SECTIONS.dup end config[:sections] = sections.reject { |section| normalized_partials.include?(section) } config end |
.readme_preserve_targets(template_sections, destination_lookup, preserve_config) ⇒ Object
18184 18185 18186 18187 18188 18189 18190 18191 18192 18193 18194 18195 18196 18197 18198 18199 18200 18201 18202 18203 18204 18205 |
# File 'lib/kettle/jem.rb', line 18184 def readme_preserve_targets(template_sections, destination_lookup, preserve_config) sections = if preserve_config.key?(:sections) Array(preserve_config[:sections]).map { |section| normalize_readme_heading(section) } else README_DEFAULT_PRESERVE_SECTIONS.dup end patterns = if preserve_config.key?(:patterns) Array(preserve_config[:patterns]).map { |pattern| pattern.to_s.strip.downcase } else README_DEFAULT_PRESERVE_PATTERNS.dup end aliases = preserve_config[:aliases] || README_SECTION_ALIASES targets = sections.dup template_sections.each do |section| base = section.fetch(:base) targets << base if patterns.any? { |pattern| File.fnmatch?(pattern, base, File::FNM_PATHNAME) } end aliases.each do |from, to| targets << to if destination_lookup.key?(from) && targets.include?(to) end targets.uniq end |
.readme_project_emoji(project_root) ⇒ Object
13142 13143 13144 13145 13146 13147 13148 13149 |
# File 'lib/kettle/jem.rb', line 13142 def readme_project_emoji(project_root) readme_path = File.join(project_root, "README.md") return unless File.exist?(readme_path) h1 = markdown_heading_owners(File.read(readme_path), source_label: "README.md").find { |owner| owner.level == 1 } candidate = first_grapheme(h1&.heading_text) decorative_grapheme?(candidate) ? candidate : nil end |
.readme_section_contains_badge_cloud?(section) ⇒ Boolean
18067 18068 18069 |
# File 'lib/kettle/jem.rb', line 18067 def readme_section_contains_badge_cloud?(section) section.fetch(:body).to_s.lines.any? { |line| line.include?("[![") } end |
.readme_section_has_preserved_ancestor?(sections, index, preserve_targets) ⇒ Boolean
18122 18123 18124 18125 18126 18127 18128 18129 18130 18131 |
# File 'lib/kettle/jem.rb', line 18122 def readme_section_has_preserved_ancestor?(sections, index, preserve_targets) section = sections.fetch(index) section_level = section.fetch(:level).to_i sections[0...index].reverse_each do |candidate| next unless candidate.fetch(:level).to_i < section_level return preserve_targets.include?(candidate.fetch(:base)) end false end |
.readme_section_partials(project_root, config, readme) ⇒ Object
17857 17858 17859 17860 17861 17862 17863 17864 17865 17866 17867 17868 17869 17870 17871 17872 17873 17874 17875 17876 17877 17878 17879 17880 |
# File 'lib/kettle/jem.rb', line 17857 def readme_section_partials(project_root, config, readme) configured = readme["section_partials"] return {} unless configured.is_a?(Hash) root = template_root(project_root, config["templates"].is_a?(Hash) ? config["templates"] : {}) configured.each_with_object({}) do |(section, source), result| normalized = normalize_readme_section_key(section) next if normalized.empty? source_path = source.to_s next if source_path.empty? selected = preferred_template_source(root.fetch(:path), source_path) next unless selected result[normalized] = { configured_source: source_path, selected_source: template_source_display_path(root, selected), source_relative_path: selected, source_root: root.fetch(:kind), content: File.read(File.join(root.fetch(:path), selected)) } end end |
.readme_section_partials_for_render(readme_style, facts) ⇒ Object
5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 |
# File 'lib/kettle/jem.rb', line 5893 def readme_section_partials_for_render(readme_style, facts) partials = readme_style[:section_partials] return {} unless partials.is_a?(Hash) tokens = readme_template_tokens(facts) partials.each_with_object({}) do |(section, partial), result| content = partial.is_a?(Hash) ? partial[:content].to_s : partial.to_s next if content.strip.empty? result[normalize_readme_section_key(section)] = resolve_template_tokens(content, tokens) end end |
.readme_star_history_facts(project_root, git_source_url) ⇒ Object
16798 16799 16800 16801 16802 16803 16804 16805 16806 16807 16808 16809 16810 16811 16812 16813 16814 16815 16816 16817 |
# File 'lib/kettle/jem.rb', line 16798 def readme_star_history_facts(project_root, git_source_url) repository_slug = github_repository_slug(git_source_url) return {enabled: false, reason: "no_github_remote"} if repository_slug.to_s.empty? stars = github_repository_star_count(project_root, repository_slug) unless stars return { enabled: false, repository: repository_slug, reason: "star_count_unavailable" } end { enabled: stars >= README_STAR_HISTORY_MIN_STARS, repository: repository_slug, stars: stars, minimum_stars: README_STAR_HISTORY_MIN_STARS } end |
.readme_style_facts(project_root, config, license, template_profile: nil, repository: nil) ⇒ Object
17783 17784 17785 17786 17787 17788 17789 17790 17791 17792 17793 17794 17795 17796 17797 17798 17799 17800 17801 17802 17803 17804 17805 17806 17807 17808 17809 17810 17811 17812 17813 |
# File 'lib/kettle/jem.rb', line 17783 def readme_style_facts(project_root, config, license, template_profile: nil, repository: nil) readme = config["readme"].is_a?(Hash) ? config["readme"] : {} conditional = readme["conditional_sections"].is_a?(Hash) ? readme["conditional_sections"] : {} disabled_integrations = readme_disabled_integrations(readme, integration_disabled: disabled_integrations(config, license: license)) integration_root = readme_integration_project_root(project_root, template_profile, repository) missing_integrations = README_DISCOVERED_INTEGRATIONS.reject do |integration| disabled_integrations.include?(integration) || readme_integration_configured?(integration_root, integration) end workflow_paths = readme_workflow_paths(integration_root) omitted_sections = [] security_enabled = repository_monorepo_subproject?(repository) || File.exist?(File.join(project_root, "SECURITY.md")) floss_funding_enabled = readme_floss_funding_enabled?(license, conditional["floss_funding"]) omitted_sections << "security" unless security_enabled omitted_sections << "floss_funding" unless floss_funding_enabled section_partials = readme_section_partials(project_root, config, readme) package_family = readme["package_family"].to_s.strip.downcase fossa_project = readme_fossa_project(readme, repository) compact_hash( profile: "slice-740-kettle-readme-style-profile", security_enabled: security_enabled, floss_funding_enabled: floss_funding_enabled, package_family: package_family, fossa_project: fossa_project, omitted_sections: omitted_sections, disabled_integrations: disabled_integrations, missing_integrations: missing_integrations, workflow_paths: workflow_paths, section_partials: section_partials ) end |
.readme_template_tokens(facts) ⇒ Object
5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 |
# File 'lib/kettle/jem.rb', line 5920 def readme_template_tokens(facts) { "KJ|CB:USER" => "", "KJ|FUNDING:BUYMEACOFFEE" => "", "KJ|FUNDING:KOFI" => "", "KJ|FUNDING:LIBERAPAY" => "", "KJ|FUNDING:PAYPAL" => "", "KJ|GH:USER" => "", "KJ|GH_ORG" => github_org_from_url(facts.dig(:package, :source_url)).to_s, "KJ|GL:USER" => "", "KJ|PROJECT_EMOJI" => "💎", "KJ|README:COPYRIGHT_NOTICE" => "", "KJ|README:CORPORATE_SPONSORS" => "", "KJ|README:LICENSE_BADGE" => "", "KJ|README:LICENSE_COMPAT_BADGE" => "", "KJ|README:DEV_TEST_STACK_TABLE" => "", "KJ|README:LICENSE_INTRO" => "", "KJ|README:LICENSE_REFS" => "", "KJ|README:H2_SYNOPSIS_LOGO_ROW" => "", "KJ|README:TOP_LOGO_REFS" => "", "KJ|README:TOP_LOGO_ROW" => "", "KJ|SH:USER" => "", "KJ|SOCIAL:BLUESKY" => "", "KJ|SOCIAL:DEVTO" => "", "KJ|SOCIAL:LINKTREE" => "", "KJ|SOCIAL:MASTODON" => "", "KJ|HOMEPAGE_URI" => "https://rubydoc.info", "KJ|YARD_HOST" => "rubydoc.info" }.merge(template_tokens(facts, facts.fetch(:funding, {}))) end |
.readme_title_token(package, rubygems) ⇒ Object
14350 14351 14352 14353 14354 14355 14356 14357 14358 |
# File 'lib/kettle/jem.rb', line 14350 def readme_title_token(package, rubygems) package_name = package.fetch(:name).to_s.strip default_entrypoint = package_name.tr("-", "/") entrypoint = rubygems.fetch(:entrypoint_require, default_entrypoint).to_s.strip namespace = rubygems.fetch(:namespace, package_name).to_s.strip return namespace if entrypoint.empty? || entrypoint == default_entrypoint || namespace.empty? "#{package_name} / #{namespace}" end |
.readme_top_logo_credit_separator(type) ⇒ Object
17188 17189 17190 |
# File 'lib/kettle/jem.rb', line 17188 def readme_top_logo_credit_separator(type) (type == "ruby") ? ", " : " by " end |
.readme_top_logo_default_alt(type, slug) ⇒ Object
17146 17147 17148 17149 17150 17151 17152 17153 17154 17155 17156 17157 17158 17159 17160 |
# File 'lib/kettle/jem.rb', line 17146 def readme_top_logo_default_alt(type, slug) label = slug.split("/").last.to_s case type when "related_org" "Galtzo FLOSS" when "ruby" "ruby-lang" when "org" label when "project" label else "#{label} affiliated project" end end |
.readme_top_logo_entries(config, org:, gem_name:, repository: {}) ⇒ Object
17049 17050 17051 17052 17053 17054 17055 17056 17057 17058 |
# File 'lib/kettle/jem.rb', line 17049 def readme_top_logo_entries(config, org:, gem_name:, repository: {}) configured = configured_readme_top_logo_entries(config, org: org, gem_name: gem_name, repository: repository) return readme_top_logo_entries_with_asset_size(configured) if configured entries = readme_logo_specs_from_config(config, "top_logos", "top_logo_options", README_TOP_LOGO_DEFAULTS).filter_map do |spec| readme_top_logo_entry_from_option(spec.fetch(:type), org: org, gem_name: gem_name, repository: repository)&.merge(width: spec[:width]) end entries = deduplicate_readme_top_logo_entries(entries) readme_top_logo_entries_with_asset_size(entries) end |
.readme_top_logo_entries_with_asset_size(entries) ⇒ Object
17068 17069 17070 17071 17072 17073 |
# File 'lib/kettle/jem.rb', line 17068 def readme_top_logo_entries_with_asset_size(entries) entries.map do |entry| image_url = entry.fetch(:image_url).to_s.sub(%r{/avatar-\d+px\.svg\z}, "/avatar-128px.svg") entry.merge(image_url: image_url) end end |
.readme_top_logo_entry_from_config(logo, org:, gem_name:, repository: {}) ⇒ Object
17095 17096 17097 17098 17099 17100 17101 17102 17103 17104 17105 17106 17107 17108 17109 17110 17111 17112 17113 17114 17115 17116 17117 17118 17119 17120 17121 17122 17123 |
# File 'lib/kettle/jem.rb', line 17095 def readme_top_logo_entry_from_config(logo, org:, gem_name:, repository: {}) return unless logo.is_a?(Hash) type = logo["type"].to_s.strip.downcase.tr("-", "_") return unless README_TOP_LOGO_TYPES.include?(type) type = "ruby" if type == "language" slug = logo["slug"].to_s.strip slug = default_readme_top_logo_slug(type, org: org, gem_name: gem_name, repository: repository) if slug.empty? return if slug.empty? alt = logo["alt"].to_s.strip alt = readme_top_logo_default_alt(type, slug) if alt.empty? href = logo["href"].to_s.strip href = default_readme_top_logo_href(type, slug: slug, org: org, gem_name: gem_name, repository: repository) if href.empty? credit = logo["credit"].to_s.strip credit = default_readme_top_logo_credit(type) if credit.empty? ref_slug = slug.tr("/", "-") { type: type, label: alt.sub(/\s+logo\z/i, ""), credit: credit, credit_separator: readme_top_logo_credit_separator(type), image_ref: "#{ref_slug}-i", link_ref: ref_slug, image_url: readme_top_logo_image_url(type, slug), href: href } end |
.readme_top_logo_entry_from_option(option, org:, gem_name:, repository: {}) ⇒ Object
17206 17207 17208 17209 17210 17211 |
# File 'lib/kettle/jem.rb', line 17206 def readme_top_logo_entry_from_option(option, org:, gem_name:, repository: {}) return if option == "org" && org.to_s.empty? return if option == "project" && (org.to_s.empty? || gem_name.to_s.empty?) readme_top_logo_entry_from_config({"type" => option}, org: org, gem_name: gem_name, repository: repository) end |
.readme_top_logo_image_url(type, slug) ⇒ Object
17125 17126 17127 17128 17129 |
# File 'lib/kettle/jem.rb', line 17125 def readme_top_logo_image_url(type, slug) return "https://github.com/#{slug}.png?size=192" if type == "org" "#{LOGOS_GALTZO_BASE_URL}/#{slug}/avatar-192px.svg" end |
.readme_top_logo_options(config) ⇒ Object
16964 16965 16966 |
# File 'lib/kettle/jem.rb', line 16964 def (config) (config, "top_logos", "top_logo_options", README_TOP_LOGO_DEFAULTS) end |
.readme_top_logo_refs(entries) ⇒ Object
17236 17237 17238 |
# File 'lib/kettle/jem.rb', line 17236 def readme_top_logo_refs(entries) "" end |
.readme_top_logo_row(entries) ⇒ Object
17213 17214 17215 17216 17217 17218 |
# File 'lib/kettle/jem.rb', line 17213 def readme_top_logo_row(entries) default_width = readme_default_logo_width(entries, one: "14%", two: "12%") entries.map do |entry| readme_logo_html(entry, align: "right", width: entry[:width] || default_width) end.join(" ") end |
.readme_url_template_tokens(repository, package_name, github_org) ⇒ Object
14456 14457 14458 14459 14460 14461 14462 14463 14464 14465 14466 14467 14468 14469 14470 14471 14472 14473 14474 14475 14476 14477 14478 14479 14480 14481 14482 14483 14484 14485 14486 14487 14488 14489 14490 14491 14492 14493 14494 14495 14496 14497 14498 14499 14500 14501 14502 14503 14504 14505 14506 14507 14508 14509 14510 14511 14512 14513 14514 14515 14516 14517 14518 14519 14520 14521 14522 14523 14524 14525 14526 14527 14528 14529 14530 14531 14532 14533 14534 14535 14536 |
# File 'lib/kettle/jem.rb', line 14456 def readme_url_template_tokens(repository, package_name, github_org) repo_url = repository[:url].to_s repo_name = repository[:name].to_s repo_slug = repository[:slug].to_s package_path = repository[:package_path].to_s package_source_url = repository[:package_source_url].to_s repo_url = "https://github.com/#{github_org}/#{package_name}" if repo_url.empty? repo_name = package_name if repo_name.empty? repo_slug = "#{github_org}/#{repo_name}" if repo_slug.empty? package_source_url = repo_url if package_source_url.empty? repository = repository.merge( url: repo_url, name: repo_name, slug: repo_slug, package_path: package_path, package_source_url: package_source_url ) resources = repository[:resource_urls].is_a?(Hash) ? repository[:resource_urls] : repository_resource_urls(repository) resource_url = lambda do |key, fallback| value = resources[key].to_s value.empty? ? fallback : value end gitlab_source = repository[:gitlab_package_source_url].to_s codeberg_source = repository[:codeberg_package_source_url].to_s gitlab_source = "https://gitlab.com/#{repo_slug}/" if gitlab_source.empty? codeberg_source = "https://codeberg.org/#{repo_slug}" if codeberg_source.empty? checksums_url = repository[:checksums_url].to_s checksums_url = "https://gitlab.com/#{repo_slug}/-/tree/main/checksums" if checksums_url.empty? { "KJ|README:REPO_SLUG" => repo_slug, "KJ|README:REPO_NAME" => repo_name, "KJ|README:PACKAGE_PATH" => package_path, "KJ|README:GH_REPOSITORY_URL" => resource_url.call(:github_repository_url, repo_url), "KJ|README:GH_PACKAGE_SOURCE_URL" => resource_url.call(:github_package_source_url, package_source_url), "KJ|README:GH_RELEASES_URL" => resource_url.call(:github_releases_url, "#{repo_url}/releases"), "KJ|README:GH_TAG_BADGE_REPO" => repo_slug, "KJ|README:GH_ACTIONS_URL" => resource_url.call(:github_actions_url, "#{repo_url}/actions"), "KJ|README:GH_DISCUSSIONS_URL" => resource_url.call(:github_discussions_url, "#{repo_url}/discussions"), "KJ|README:GH_ISSUES_URL" => resource_url.call(:github_issues_url, "#{repo_url}/issues"), "KJ|README:GH_PULLS_URL" => resource_url.call(:github_pulls_url, "#{repo_url}/pulls"), "KJ|README:GH_WIKI_URL" => resource_url.call(:github_wiki_url, "#{repo_url}/wiki"), "KJ|README:GH_CODEQL_URL" => resource_url.call(:github_codeql_url, "#{repo_url}/security/code-scanning"), "KJ|README:GH_CONTRIBUTORS_URL" => resource_url.call(:github_contributors_url, "#{repo_url}/graphs/contributors"), "KJ|README:GH_CONTRIBUTING_URL" => resource_url.call(:github_contributing_url, source_blob_url(repo_url, "CONTRIBUTING.md")), "KJ|README:GH_CHANGELOG_URL" => resource_url.call(:github_changelog_url, source_blob_url(repo_url, "CHANGELOG.md")), "KJ|README:GH_SECURITY_URL" => resource_url.call(:github_security_url, source_blob_url(repo_url, "SECURITY.md")), "KJ|README:GH_CODE_OF_CONDUCT_URL" => resource_url.call(:github_code_of_conduct_url, source_blob_url(repo_url, "CODE_OF_CONDUCT.md")), "KJ|README:GH_RUBOCOP_URL" => resource_url.call(:github_rubocop_url, source_blob_url(repo_url, "RUBOCOP.md")), "KJ|README:GH_IRP_URL" => resource_url.call(:github_irp_url, source_blob_url(repo_url, "IRP.md")), "KJ|README:GL_REPOSITORY_URL" => resource_url.call(:gitlab_repository_url, "https://gitlab.com/#{repo_slug}"), "KJ|README:GL_PACKAGE_SOURCE_URL" => resource_url.call(:gitlab_package_source_url, gitlab_source), "KJ|README:GL_ISSUES_URL" => resource_url.call(:gitlab_issues_url, gitlab_repo_url(repository, repo_slug, "issues")), "KJ|README:GL_PULLS_URL" => resource_url.call(:gitlab_pulls_url, gitlab_repo_url(repository, repo_slug, "merge_requests")), "KJ|README:GL_WIKI_URL" => resource_url.call(:gitlab_wiki_url, gitlab_repo_url(repository, repo_slug, "wikis/home")), "KJ|README:GL_CONTRIBUTORS_URL" => resource_url.call(:gitlab_contributors_url, gitlab_repo_url(repository, repo_slug, "graphs/main")), "KJ|README:GL_CONTRIBUTING_URL" => resource_url.call(:gitlab_contributing_url, source_blob_url("https://gitlab.com/#{repo_slug}", "CONTRIBUTING.md")), "KJ|README:GL_CHANGELOG_URL" => resource_url.call(:gitlab_changelog_url, source_blob_url("https://gitlab.com/#{repo_slug}", "CHANGELOG.md")), "KJ|README:GL_CODE_OF_CONDUCT_URL" => resource_url.call(:gitlab_code_of_conduct_url, source_blob_url("https://gitlab.com/#{repo_slug}", "CODE_OF_CONDUCT.md")), "KJ|README:CB_REPOSITORY_URL" => resource_url.call(:codeberg_repository_url, "https://codeberg.org/#{repo_slug}"), "KJ|README:CB_PACKAGE_SOURCE_URL" => resource_url.call(:codeberg_package_source_url, codeberg_source), "KJ|README:CB_ISSUES_URL" => resource_url.call(:codeberg_issues_url, codeberg_repo_url(repository, repo_slug, "issues")), "KJ|README:CB_PULLS_URL" => resource_url.call(:codeberg_pulls_url, codeberg_repo_url(repository, repo_slug, "pulls")), "KJ|README:CODECOV_URL" => resource_url.call(:codecov_url, "https://codecov.io/gh/#{repo_slug}"), "KJ|README:CODECOV_BADGE_URL" => resource_url.call(:codecov_badge_url, "https://codecov.io/gh/#{repo_slug}/graph/badge.svg"), "KJ|README:CODECOV_GRAPH_URL" => resource_url.call(:codecov_graph_url, "https://codecov.io/gh/#{repo_slug}/graph/badge.svg"), "KJ|README:COVERALLS_URL" => resource_url.call(:coveralls_url, "https://coveralls.io/github/#{repo_slug}?branch=main"), "KJ|README:COVERALLS_BADGE_URL" => resource_url.call(:coveralls_badge_url, "https://coveralls.io/repos/github/#{repo_slug}/badge.svg?branch=main"), "KJ|README:QLTY_PROJECT_URL" => resource_url.call(:qlty_project_url, "https://qlty.sh/gh/#{github_org}/projects/#{repo_name}"), "KJ|README:QLTY_MAINTAINABILITY_URL" => resource_url.call(:qlty_maintainability_url, "https://qlty.sh/gh/#{github_org}/projects/#{repo_name}/maintainability.svg"), "KJ|README:QLTY_COVERAGE_URL" => resource_url.call(:qlty_coverage_url, "https://qlty.sh/gh/#{github_org}/projects/#{repo_name}/metrics/code?sort=coverageRating"), "KJ|README:QLTY_COVERAGE_BADGE_URL" => resource_url.call(:qlty_coverage_badge_url, "https://qlty.sh/gh/#{github_org}/projects/#{repo_name}/coverage.svg"), "KJ|CHANGELOG:GL_COMPARE_URL" => resource_url.call(:gitlab_compare_url, "https://gitlab.com/#{repo_slug}/-/compare"), "KJ|CHANGELOG:GL_TAGS_URL" => resource_url.call(:gitlab_tags_url, "https://gitlab.com/#{repo_slug}/-/tags"), "KJ|README:CONTRIBUTORS_IMAGE_REPO" => repo_slug, "KJ|README:STAR_HISTORY_REPO" => repo_slug, "KJ|README:SHA_CHECKSUMS_URL" => resource_url.call(:checksums_url, checksums_url) } end |
.readme_workflow_path_from_url(url) ⇒ Object
7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 |
# File 'lib/kettle/jem.rb', line 7875 def readme_workflow_path_from_url(url) marker = "/actions/workflows/" path = URI.parse(url.to_s).path.to_s marker_index = path.index(marker) return "" unless marker_index workflow = path[(marker_index + marker.length)..].to_s.split("/").first.to_s workflow.empty? ? "" : ".github/workflows/#{workflow}" rescue URI::InvalidURIError "" end |
.readme_workflow_paths(project_root) ⇒ Object
17851 17852 17853 17854 17855 |
# File 'lib/kettle/jem.rb', line 17851 def readme_workflow_paths(project_root) Dir.glob(File.join(project_root.to_s, ".github/workflows/*.{yml,yaml}")).map do |path| ".github/workflows/#{File.basename(path)}" end.sort end |
.recipe_decision_category(recipe) ⇒ Object
13299 13300 13301 13302 13303 13304 13305 13306 |
# File 'lib/kettle/jem.rb', line 13299 def recipe_decision_category(recipe) return "delete_file" if delete_file_recipe?(recipe) return "select_template_source" if recipe.fetch(:primitive) == "supplied_template_source_preference" return "bootstrap_config" if recipe.fetch(:primitive) == "supplied_kettle_config_bootstrap" return "apply_template_source" if recipe.fetch(:primitive) == "supplied_template_source_application" "merge_valid_document" end |
.recipe_decision_diagnostics(recipe) ⇒ Object
13317 13318 13319 13320 13321 13322 13323 13324 13325 13326 |
# File 'lib/kettle/jem.rb', line 13317 def recipe_decision_diagnostics(recipe) diagnostics = [] if recipe.fetch(:primitive) == "supplied_template_source_application" diagnostics << "Non-interactive runs apply the configured template source default and report the decision." end if delete_file_recipe?(recipe) diagnostics << "Deletion is allowed only for explicit Kettle/Jem cleanup primitives." end diagnostics end |
.recipe_decision_evaluation(decision_policy:, recipe:, changed:, destination_existed:) ⇒ Object
13288 13289 13290 13291 13292 13293 13294 13295 13296 13297 |
# File 'lib/kettle/jem.rb', line 13288 def recipe_decision_evaluation(decision_policy:, recipe:, changed:, destination_existed:) decision_policy.resolve( id: "recipe:#{recipe.fetch(:name)}", category: recipe_decision_category(recipe), file: recipe.fetch(:target_path), default_action: recipe_default_action(recipe, changed: changed, destination_existed: destination_existed), severity: :advisory, diagnostics: recipe_decision_diagnostics(recipe) ).to_h end |
.recipe_default_action(recipe, changed:, destination_existed:) ⇒ Object
13308 13309 13310 13311 13312 13313 13314 13315 |
# File 'lib/kettle/jem.rb', line 13308 def recipe_default_action(recipe, changed:, destination_existed:) return "delete" if delete_file_recipe?(recipe) return "keep" unless changed return "create" unless destination_existed return "replace" if recipe.fetch(:primitive) == "supplied_template_source_application" "merge" end |
.recipe_entry(name, target_path, provider_family, primitive, facts:, provider_backend: nil, selectors: []) ⇒ Object
13350 13351 13352 13353 13354 13355 13356 13357 13358 13359 13360 |
# File 'lib/kettle/jem.rb', line 13350 def recipe_entry(name, target_path, provider_family, primitive, facts:, provider_backend: nil, selectors: []) { name: name, target_path: target_path, provider_family: provider_family, provider_backend: provider_backend, primitive: primitive, facts: facts, selectors: selectors } end |
.recipe_filter_patterns(template_selection) ⇒ Object
13272 13273 13274 13275 13276 |
# File 'lib/kettle/jem.rb', line 13272 def recipe_filter_patterns(template_selection) only = Array(template_selection[:only]).compact include = Array(template_selection[:include]).compact only.empty? ? [] : (only + include) end |
.recipe_pack(facts) ⇒ Object
3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 |
# File 'lib/kettle/jem.rb', line 3621 def recipe_pack(facts) recipes = if monorepo_template_profile?(facts) || shim_template_profile?(facts) [] else [ recipe_entry("readme_metadata", "README.md", "markdown", "supplied_readme_metadata_synchronization", facts: %w[package funding readme]), recipe_entry("changelog_unreleased", "CHANGELOG.md", "markdown", "changelog_unreleased_normalization", facts: %w[package changelog]), recipe_entry( "generated_block_sync", "gemfiles/modular/shunted.gemfile", "ruby", "supplied_managed_text_block_replacement", facts: %w[package generated_blocks], provider_backend: "ast-crispr-ruby-prism" ), recipe_entry( "github_funding_yml", ".github/FUNDING.yml", "yaml", "supplied_github_funding_yaml_synchronization", facts: %w[package funding] ) ] end if facts[:kettle_config_bootstrap] recipes.unshift(kettle_config_bootstrap_recipe(facts.fetch(:kettle_config_bootstrap))) end unless monorepo_template_profile?(facts) || shim_template_profile?(facts) facts.dig(:ci, :framework_matrix, :gemfiles).to_a.each do |gemfile| recipes << recipe_entry( "github_actions_framework_gemfile_#{workflow_recipe_slug(gemfile.fetch(:path))}", gemfile.fetch(:path), "ruby", "supplied_framework_matrix_gemfile_generation", facts: %w[ci] ) end facts.dig(:ci, :obsolete_workflows).to_a.each do |workflow_path| recipes << recipe_entry( "github_actions_obsolete_workflow_cleanup_#{workflow_recipe_slug(workflow_path)}", workflow_path, "file", "supplied_obsolete_file_deletion", facts: %w[ci] ) end facts.dig(:ci, :opt_in_workflow_cleanups).to_a.each do |workflow_path| recipes << recipe_entry( "github_actions_opt_in_workflow_cleanup_#{workflow_recipe_slug(workflow_path)}", workflow_path, "file", "supplied_opt_in_workflow_deletion", facts: %w[ci] ) end facts.dig(:ci, :inactive_packaged_workflow_cleanups).to_a.each do |workflow_path| recipes << recipe_entry( "github_actions_inactive_packaged_workflow_cleanup_#{workflow_recipe_slug(workflow_path)}", workflow_path, "file", "supplied_inactive_packaged_workflow_deletion", facts: %w[ci] ) end facts.dig(:funding, :open_collective_files).to_a.each do |relative_path| recipes << recipe_entry( "opencollective_disabled_file_cleanup_#{workflow_recipe_slug(relative_path)}", relative_path, "file", "supplied_disabled_opencollective_file_deletion", facts: %w[funding] ) end facts.dig(:ci, :custom_workflows).to_a.each do |workflow_path| recipes << recipe_entry( "github_actions_workflow_snippets_#{workflow_recipe_slug(workflow_path)}", workflow_path, "yaml", "supplied_github_actions_workflow_snippet_merge", facts: %w[ci] ) end end if monorepo_template_profile?(facts) facts.dig(:ci, :inactive_packaged_workflow_cleanups).to_a.each do |workflow_path| recipes << recipe_entry( "github_actions_inactive_packaged_workflow_cleanup_#{workflow_recipe_slug(workflow_path)}", workflow_path, "file", "supplied_inactive_packaged_workflow_deletion", facts: %w[ci] ) end end facts.dig(:templates, :source_preferences).to_a.each do |preference| apply_template = preference.fetch(:apply, false) recipe = recipe_entry( "#{apply_template ? "template_source_application" : "template_source_preference"}_#{workflow_recipe_slug(preference.fetch(:target_path))}", preference.fetch(:target_path), "file", apply_template ? "supplied_template_source_application" : "supplied_template_source_preference", facts: %w[templates funding] ) recipe[:template_preference] = preference recipe[:template_tokens] = facts.dig(:templates, :tokens) if facts.dig(:templates, :tokens) recipe[:readme_style] = facts[:readme_style] if preference.fetch(:target_path) == "README.md" && facts[:readme_style] recipes << recipe end facts.dig(:templates, :inactive_packaged_template_cleanups).to_a.each do |cleanup| recipes << recipe_entry( "template_inactive_packaged_cleanup_#{workflow_recipe_slug(cleanup.fetch(:target_path))}", cleanup.fetch(:target_path), "file", "supplied_inactive_packaged_template_deletion", facts: %w[templates] ) end facts.dig(:templates, :legacy_destination_cleanups).to_a.each do |cleanup| recipes << recipe_entry( "template_legacy_destination_cleanup_#{workflow_recipe_slug(cleanup.fetch(:legacy_path))}", cleanup.fetch(:legacy_path), "file", "supplied_legacy_destination_file_deletion", facts: %w[templates] ) end facts.dig(:templates, :obsolete_license_cleanups).to_a.each do |cleanup| recipes << recipe_entry( "template_obsolete_license_cleanup_#{workflow_recipe_slug(cleanup.fetch(:license_path))}", cleanup.fetch(:license_path), "file", "supplied_obsolete_license_file_deletion", facts: %w[templates license] ) end facts.dig(:templates, :shim_profile_cleanups).to_a.each do |cleanup| recipes << recipe_entry( "template_shim_profile_cleanup_#{workflow_recipe_slug(cleanup.fetch(:target_path))}", cleanup.fetch(:target_path), "file", "supplied_shim_profile_file_deletion", facts: %w[templates shim] ) end unless shim_template_profile?(facts) recipes << recipe_entry( "rakefile_scaffold_cleanup", "Rakefile", "generic_ast", "supplied_source_selector_deletion", provider_backend: "generic_structural_owners", facts: %w[rubygems rakefile], selectors: %w[rakefile_scaffold] ) end { name: "kettle-jem-core", version: 1, ecosystem: "rubygems", recipes: recipes } end |
.recipe_planning_strategy_for(env, run_options) ⇒ Object
4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 |
# File 'lib/kettle/jem.rb', line 4267 def recipe_planning_strategy_for(env, ) value = ( || {})[:recipe_planning_strategy] || ( || {})["recipe_planning_strategy"] || (env || {})["KETTLE_JEM_RECIPE_PLANNING_STRATEGY"] strategy = value.to_s.strip strategy = "sequential" if strategy.empty? strategy = strategy.tr("_", "-") strategy = "sequential" if DISABLED_RECIPE_PLANNING_STRATEGY_VALUES.include?(strategy) strategy = "classified" if ENABLED_RECIPE_PLANNING_STRATEGY_VALUES.include?(strategy) raise ArgumentError, "Unsupported kettle-jem recipe planning strategy #{value.inspect}" unless RECIPE_PLANNING_STRATEGIES.include?(strategy) strategy end |
.recipe_planning_thread_workers_for(env, run_options) ⇒ Object
4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 |
# File 'lib/kettle/jem.rb', line 4297 def recipe_planning_thread_workers_for(env, ) value = ( || {})[:thread_workers] || ( || {})["thread_workers"] || ( || {})[:recipe_planning_thread_workers] || ( || {})["recipe_planning_thread_workers"] || (env || {})["KETTLE_JEM_THREAD_WORKERS"] return 0 if value.nil? || value.to_s.strip.empty? workers = Integer(value) raise ArgumentError, "KETTLE_JEM_THREAD_WORKERS must be >= 0" if workers.negative? workers rescue ArgumentError raise ArgumentError, "KETTLE_JEM_THREAD_WORKERS must be a non-negative integer" end |
.recipe_planning_workers_for(env, run_options) ⇒ Object
4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 |
# File 'lib/kettle/jem.rb', line 4281 def recipe_planning_workers_for(env, ) value = ( || {})[:ractor_workers] || ( || {})["ractor_workers"] || ( || {})[:recipe_planning_workers] || ( || {})["recipe_planning_workers"] || (env || {})["KETTLE_JEM_RACTOR_WORKERS"] return 0 if value.nil? || value.to_s.strip.empty? workers = Integer(value) raise ArgumentError, "KETTLE_JEM_RACTOR_WORKERS must be >= 0" if workers.negative? workers rescue ArgumentError raise ArgumentError, "KETTLE_JEM_RACTOR_WORKERS must be a non-negative integer" end |
.recipe_report_metadata(recipe) ⇒ Object
13189 13190 13191 13192 13193 13194 13195 13196 13197 |
# File 'lib/kettle/jem.rb', line 13189 def (recipe) = {packaging_recipe: recipe.fetch(:name)} [:delete_file] = true if delete_file_recipe?(recipe) [:template_source_preference] = deep_dup(recipe[:template_preference]) if recipe[:template_preference] [:template_tokens] = deep_dup(recipe[:template_tokens]) if recipe[:template_tokens] [:readme_style] = deep_dup(recipe[:readme_style]) if recipe[:readme_style] [:bootstrap_file] = true if recipe.fetch(:primitive) == "supplied_kettle_config_bootstrap" end |
.recipe_report_phase(recipe_report) ⇒ Object
14045 14046 14047 |
# File 'lib/kettle/jem.rb', line 14045 def recipe_report_phase(recipe_report) phase_for_recipe(recipe_report[:recipe_name], recipe_report[:relative_path]) end |
.recipe_run_stats(recipe_reports, diagnostics: []) ⇒ Object
14078 14079 14080 14081 14082 14083 14084 14085 14086 14087 14088 14089 14090 14091 14092 14093 14094 14095 14096 14097 14098 14099 14100 14101 14102 14103 14104 14105 14106 14107 14108 14109 14110 |
# File 'lib/kettle/jem.rb', line 14078 def recipe_run_stats(recipe_reports, diagnostics: []) stats = { recipes: recipe_reports.length, created: 0, pre_existing: 0, identical: 0, changed: 0, deleted: 0, plugin_file_changes: diagnostics.count { |diagnostic| diagnostic[:kind] == "plugin_file_change" } } recipe_reports.each do |report| = report.fetch(:metadata, {}) if [:delete_file] stats[:deleted] += 1 if report[:changed] next end if [:destination_existed] stats[:pre_existing] += 1 if report[:changed] stats[:changed] += 1 else stats[:identical] += 1 end elsif report[:changed] stats[:created] += 1 end end stats[:summary] = recipe_run_stats_summary(stats) stats end |
.recipe_run_stats_summary(stats) ⇒ Object
14112 14113 14114 14115 14116 14117 14118 14119 14120 14121 14122 |
# File 'lib/kettle/jem.rb', line 14112 def recipe_run_stats_summary(stats) [ "recipes #{stats.fetch(:recipes)}", "created #{stats.fetch(:created)}", "pre_existing #{stats.fetch(:pre_existing)}", "identical #{stats.fetch(:identical)}", "changed #{stats.fetch(:changed)}", "deleted #{stats.fetch(:deleted)}", "plugin_file_changes #{stats.fetch(:plugin_file_changes)}" ].join(" ") end |
.recipe_runtime_context(recipe, facts, deletion) ⇒ Object
13362 13363 13364 13365 13366 13367 13368 13369 13370 13371 |
# File 'lib/kettle/jem.rb', line 13362 def recipe_runtime_context(recipe, facts, deletion) context = deep_dup(facts) if recipe.fetch(:primitive) == "supplied_source_selector_deletion" && deletion context[:delete_selectors] = deletion.fetch(:delete_selectors) end context[:template_source_preference] = deep_dup(recipe[:template_preference]) if recipe[:template_preference] context[:template_tokens] = deep_dup(recipe[:template_tokens]) if recipe[:template_tokens] context[:readme_style] = deep_dup(recipe[:readme_style]) if recipe[:readme_style] context end |
.recipe_template_content(project_root, recipe, template_contents: nil) ⇒ Object
7070 7071 7072 7073 7074 7075 7076 7077 |
# File 'lib/kettle/jem.rb', line 7070 def recipe_template_content(project_root, recipe, template_contents: nil) path = recipe_template_content_path(project_root, recipe) return "" unless path return template_contents.fetch(path) if template_contents&.key?(path) File.read(path) end |
.recipe_template_content_path(project_root, recipe) ⇒ Object
7079 7080 7081 7082 7083 7084 7085 7086 7087 |
# File 'lib/kettle/jem.rb', line 7079 def recipe_template_content_path(project_root, recipe) return unless TEMPLATE_CONTENT_PRIMITIVES.include?(recipe.fetch(:primitive)) preference = recipe.fetch(:template_preference) File.join( preference.fetch(:source_root_path, project_root), preference.fetch(:source_relative_path, preference.fetch(:selected_source)) ) end |
.reconcile_existing_version_namespace(project_root, entrypoint_path, version_path, namespace) ⇒ Object
16357 16358 16359 16360 16361 16362 16363 16364 16365 16366 16367 16368 16369 16370 16371 16372 16373 16374 16375 16376 16377 16378 16379 16380 |
# File 'lib/kettle/jem.rb', line 16357 def reconcile_existing_version_namespace(project_root, entrypoint_path, version_path, namespace) namespace = namespace.to_s return namespace if namespace.empty? entrypoint_kind = ruby_namespace_declaration_kind( read_project_file(project_root, entrypoint_path), namespace ) version_kind = ruby_namespace_declaration_kind( read_project_file(project_root, version_path), namespace ) return namespace unless entrypoint_kind && version_kind && entrypoint_kind != version_kind return namespace unless error_class_namespace?(read_project_file(project_root, entrypoint_path), namespace) parent = namespace.split("::")[0...-1].join("::") return namespace if parent.empty? return namespace unless ruby_namespace_declaration_kind( read_project_file(project_root, entrypoint_path), parent ) parent end |
.record_file_work_execution_stats(stats, units:, workers:, thread_workers:) ⇒ Object
13881 13882 13883 13884 13885 13886 13887 13888 13889 13890 13891 13892 13893 13894 13895 |
# File 'lib/kettle/jem.rb', line 13881 def record_file_work_execution_stats(stats, units:, workers:, thread_workers:) return unless stats stats[:file_work_units] += units.length stats[:file_operations] += units.sum { |unit| unit.operations.length } if workers.positive? stats[:file_ractor_units] += units.length stats[:file_ractor_spawn_count] += [workers, units.length].min elsif thread_workers.positive? stats[:file_thread_units] += units.length stats[:file_thread_spawn_count] += [thread_workers, units.length].min else stats[:main_file_units] += units.length end end |
.record_phase_timing(events, phase, status:, duration_ms:, payload:) ⇒ Object
4749 4750 4751 |
# File 'lib/kettle/jem.rb', line 4749 def record_phase_timing(events, phase, status:, duration_ms:, payload:) Kettle::Ndjson.record_phase_timing(events, phase, status: status, duration_ms: duration_ms, payload: payload) end |
.record_recipe_planning_execution_stats(stats, worker_safe:, main_only:, worker_count:, spawned:, ractor_recipes:, thread_worker_count:, thread_spawns:, thread_recipes:, main_recipes:) ⇒ Object
4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 |
# File 'lib/kettle/jem.rb', line 4501 def record_recipe_planning_execution_stats(stats, worker_safe:, main_only:, worker_count:, spawned:, ractor_recipes:, thread_worker_count:, thread_spawns:, thread_recipes:, main_recipes:) return unless stats stats[:worker_safe_recipes] = worker_safe stats[:main_only_recipes] = main_only stats[:ractor_worker_count] = worker_count stats[:ractor_spawn_count] = spawned stats[:ractor_recipe_count] = ractor_recipes stats[:thread_worker_count] = thread_worker_count stats[:thread_spawn_count] = thread_spawns stats[:thread_recipe_count] = thread_recipes stats[:main_recipe_count] = main_recipes end |
.redundant_templating_guard_wrapper_node?(node) ⇒ Boolean
8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 |
# File 'lib/kettle/jem.rb', line 8830 def redundant_templating_guard_wrapper_node?(node) return false unless gemfile_conditional_node?(node) return false unless prism_subtree_contains_string?(node.predicate, "K_JEM_TEMPLATING") body = node.statements&.body.to_a return false unless body.length == 1 inner = body.first gemfile_conditional_node?(inner) && prism_subtree_contains_string?(inner.predicate, "K_JEM_TEMPLATING") end |
.remove_duplicate_comment_span_before_marker(content, start_marker:, end_marker:) ⇒ Object
12615 12616 12617 12618 12619 12620 12621 12622 12623 12624 12625 12626 12627 |
# File 'lib/kettle/jem.rb', line 12615 def remove_duplicate_comment_span_before_marker(content, start_marker:, end_marker:) lines = content.to_s.lines starts = lines.each_index.select { |index| lines[index].chomp == start_marker } return content if starts.length < 2 starts.drop(1).reverse_each do |start_index| end_index = ((start_index + 1)...lines.length).find { |index| lines[index].chomp == end_marker } next unless end_index && comment_only_lines?(lines[start_index...end_index]) lines.slice!(start_index...end_index) end lines.join end |
.remove_duplicate_framework_matrix_documentation(content) ⇒ Object
YAML parsers do not retain comments. These migrations therefore operate on bounded comment-only spans left by older template versions; they never remove a span containing a YAML key or value.
12593 12594 12595 12596 12597 12598 12599 |
# File 'lib/kettle/jem.rb', line 12593 def remove_duplicate_framework_matrix_documentation(content) remove_duplicate_comment_span_before_marker( content, start_marker: "# Framework matrix workflows.", end_marker: "# README top logos." ) end |
.remove_duplicate_gemspec_assignments(content, receiver:, fields:) ⇒ Object
11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 |
# File 'lib/kettle/jem.rb', line 11053 def remove_duplicate_gemspec_assignments(content, receiver:, fields:) wanted = fields.map(&:to_s).to_set seen = Set.new duplicate_ranges = [] gemspec_assignment_records(content, receiver: receiver).each do |record| field = record.fetch(:field).to_s next unless wanted.include?(field) key = [record.fetch(:receiver).to_s, field, record.fetch(:value)] if seen.include?(key) duplicate_ranges << [record.fetch(:start_line), record.fetch(:end_line)] else seen << key end end return content if duplicate_ranges.empty? lines = content.to_s.lines duplicate_ranges.reverse_each do |start_line, end_line| lines.slice!(start_line - 1, end_line - start_line + 1) end ensure_trailing_newline(lines.join) end |
.remove_duplicate_gemspec_dependency_lines(content, receiver:) ⇒ Object
Template dependencies precede preserved destination dependencies. Keep the first declaration for each dependency kind/name pair so an old, weaker destination declaration cannot survive beside its managed one.
11947 11948 11949 11950 11951 11952 11953 11954 11955 11956 11957 11958 |
# File 'lib/kettle/jem.rb', line 11947 def remove_duplicate_gemspec_dependency_lines(content, receiver:) seen = Set.new duplicates = gemspec_dependency_records(content, receiver: receiver).select do |record| key = gemspec_dependency_record_key(record) already_seen = seen.include?(key) seen << key already_seen end return content if duplicates.empty? replace_record_ranges(content, duplicates.to_h { |record| [record.fetch(:start_line), record.merge(replacement: "")] }) end |
.remove_duplicate_readme_preservation_documentation(content) ⇒ Object
12601 12602 12603 12604 12605 12606 12607 12608 12609 12610 12611 12612 12613 |
# File 'lib/kettle/jem.rb', line 12601 def remove_duplicate_readme_preservation_documentation(content) lines = content.to_s.lines marker = "# Sections to preserve from the destination README during template merging." starts = lines.each_index.select { |index| lines[index].strip == marker } return content if starts.length < 2 starts.drop(1).reverse_each do |start_index| end_index = start_index end_index += 1 while end_index < lines.length && comment_or_blank_line?(lines[end_index]) lines.slice!(start_index...end_index) if comment_only_lines?(lines[start_index...end_index]) end lines.join end |
.remove_duplicate_simplecov_do_cov_bootstrap_blocks(content) ⇒ Object
8620 8621 8622 8623 8624 8625 8626 8627 |
# File 'lib/kettle/jem.rb', line 8620 def remove_duplicate_simplecov_do_cov_bootstrap_blocks(content) records = simplecov_do_cov_bootstrap_records(content) return content if records.length <= 1 records.drop(1).select { |record| record.fetch(:bootstrap_only) }.sort_by { |record| -record.fetch(:start_line) }.reduce(content.to_s) do |output, record| replace_source_range_lines(output, record.fetch(:start_line), (output, record.fetch(:end_line)), "") end end |
.remove_duplicate_simplecov_requires(content) ⇒ Object
8715 8716 8717 8718 8719 8720 8721 8722 |
# File 'lib/kettle/jem.rb', line 8715 def remove_duplicate_simplecov_requires(content) records = simplecov_require_call_records(content) return content if records.length <= 1 records.drop(1).sort_by { |record| -record.fetch(:start_line) }.reduce(content.to_s) do |output, record| replace_source_range_lines(output, record.fetch(:start_line), (output, record.fetch(:end_line)), "") end end |
.remove_empty_gemspec_development_dependency_section_headings(content, receiver:) ⇒ Object
11960 11961 11962 11963 11964 11965 |
# File 'lib/kettle/jem.rb', line 11960 def remove_empty_gemspec_development_dependency_section_headings(content, receiver:) ensure_runtime_dependencies! target = empty_gemspec_development_dependency_sections_target(receiver: receiver) actor = Ast::Crispr::Delete.call(content: content.to_s, target: target, source_label: "gemspec") actor.updated_content end |
.remove_entrypoint_version_requires(content, relative_path:, absolute_path:) ⇒ Object
16122 16123 16124 16125 16126 16127 16128 16129 16130 16131 16132 16133 16134 16135 16136 16137 |
# File 'lib/kettle/jem.rb', line 16122 def remove_entrypoint_version_requires(content, relative_path:, absolute_path:) selectors = [ *top_level_ruby_call_records(content, :require), *top_level_ruby_call_records(content, :require_relative) ].filter_map do |call| argument = ruby_string_argument(call) matches_relative = call.name == :require_relative && argument == relative_path matches_absolute = call.name == :require && argument == absolute_path next unless matches_relative || matches_absolute {start_line: call.location.start_line, end_line: ruby_node_source_end_line(call)} end return content.to_s if selectors.empty? collapse_excess_blank_lines(delete_line_ranges(content.to_s, selectors)) end |
.remove_excluded_changelog_transfer_entries(content, excluded_keys) ⇒ Object
6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 |
# File 'lib/kettle/jem.rb', line 6544 def remove_excluded_changelog_transfer_entries(content, excluded_keys) excluded = Array(excluded_keys).map(&:to_s).reject(&:empty?).to_set return content if excluded.empty? lines = markdown_source_lines(content) removals = changelog_existing_transfer_occurrences(content).filter_map do |occurrence| key = occurrence.fetch(:key).to_s next unless excluded.include?(key) (occurrence.fetch(:start_line)..occurrence.fetch(:end_line)) end return content if removals.empty? lines.each_with_index.reject do |_line, index| line_number = index + 1 removals.any? { |range| range.cover?(line_number) } end.map(&:first).join("\n").then { |text| ensure_trailing_newline(text.gsub(/\n{3,}/, "\n\n")) } end |
.remove_gemfile_dependency_blocks(content, gem_names) ⇒ Object
9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 |
# File 'lib/kettle/jem.rb', line 9572 def remove_gemfile_dependency_blocks(content, gem_names) names = gem_names.map(&:to_s).reject(&:empty?).uniq return content if names.empty? lines = content.to_s.lines remove_indexes = Set.new gemfile_gem_call_records(content).each do |record| next unless names.include?(record.fetch(:name)) start_index = record.fetch(:start_line) - 1 start_index -= 1 while start_index.positive? && gemfile_comment_line?(lines[start_index - 1]) (start_index..(record.fetch(:end_line) - 1)).each { |index| remove_indexes << index } end return content if remove_indexes.empty? ensure_trailing_newline(lines.each_with_index.reject { |_line, index| remove_indexes.include?(index) }.map(&:first).join.gsub(/\n{3,}/, "\n\n")) end |
.remove_gemfile_dependency_lines(content, gem_names) ⇒ Object
9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 |
# File 'lib/kettle/jem.rb', line 9558 def remove_gemfile_dependency_lines(content, gem_names) names = gem_names.map(&:to_s).reject(&:empty?).uniq return content if names.empty? remove_indexes = Set.new gemfile_gem_call_records(content).each do |record| next unless names.include?(record.fetch(:name)) (record.fetch(:start_line)..record.fetch(:end_line)).each { |line_number| remove_indexes << (line_number - 1) } end lines = content.to_s.lines.each_with_index.reject { |_line, index| remove_indexes.include?(index) }.map(&:first) ensure_trailing_newline(lines.join.gsub(/\n{3,}/, "\n\n")) end |
.remove_gemfile_percent_w_entries(content, gem_names) ⇒ Object
9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 |
# File 'lib/kettle/jem.rb', line 9951 def remove_gemfile_percent_w_entries(content, gem_names) names = gem_names.map(&:to_s).reject(&:empty?).uniq return content if names.empty? replacements = ruby_word_array_records(content).filter_map do |record| kept = record.fetch(:names).reject { |word| names.include?(word) } next if kept == record.fetch(:names) replacement = if record.fetch(:source).lines.one? "%w[#{kept.join(" ")}]" else ruby_multiline_word_array_source(kept, indent: record.fetch(:line_indent)) end {start_offset: record.fetch(:start_offset), end_offset: record.fetch(:end_offset), replacement: replacement} end return content if replacements.empty? replaced = replace_source_offsets(content, replacements) ensure_trailing_newline(replaced.gsub(/\n{3,}/, "\n\n")) end |
.remove_gemspec_assignment(content, receiver:, field:) ⇒ Object
10988 10989 10990 10991 10992 10993 10994 10995 |
# File 'lib/kettle/jem.rb', line 10988 def remove_gemspec_assignment(content, receiver:, field:) records_by_line = gemspec_assignment_records(content, receiver: receiver) .select { |record| record.fetch(:field) == field.to_s } .to_h { |record| [record.fetch(:start_line), record.merge(replacement: "")] } return content if records_by_line.empty? ensure_trailing_newline(replace_record_ranges(content, records_by_line).gsub(/\n{3,}/, "\n\n")) end |
.remove_gemspec_dependency_lines(content, receiver:, names:, runtime_only: false, development_only: false) ⇒ Object
10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 |
# File 'lib/kettle/jem.rb', line 10997 def remove_gemspec_dependency_lines(content, receiver:, names:, runtime_only: false, development_only: false) wanted = names.map(&:to_s).to_set records_by_line = gemspec_dependency_records(content, receiver: receiver) .select { |record| wanted.include?(record.fetch(:name)) } .select { |record| !runtime_only || record.fetch(:kind) != "add_development_dependency" } .select { |record| !development_only || record.fetch(:kind) == "add_development_dependency" } .to_h { |record| [record.fetch(:start_line), record.merge(replacement: "")] } return content if records_by_line.empty? ensure_trailing_newline(replace_record_ranges(content, records_by_line).gsub(/\n{3,}/, "\n\n")) end |
.remove_gemspec_development_dependencies_already_runtime(content, receiver:) ⇒ Object
11924 11925 11926 11927 11928 11929 11930 11931 11932 11933 11934 11935 11936 11937 11938 11939 11940 11941 11942 |
# File 'lib/kettle/jem.rb', line 11924 def remove_gemspec_development_dependencies_already_runtime(content, receiver:) records = gemspec_dependency_records(content, receiver: receiver) runtime_names = records.each_with_object(Set.new) do |record, names| next if record.fetch(:kind) == "add_development_dependency" names << record.fetch(:name) end return content if runtime_names.empty? duplicate_development_records = records.select do |record| record.fetch(:kind) == "add_development_dependency" && runtime_names.include?(record.fetch(:name)) end return content if duplicate_development_records.empty? records_by_line = duplicate_development_records.to_h do |record| [record.fetch(:start_line), record.merge(replacement: "")] end replace_record_ranges(content, records_by_line) end |
.remove_gemspec_legacy_version_loader_preamble(content) ⇒ Object
10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 |
# File 'lib/kettle/jem.rb', line 10783 def remove_gemspec_legacy_version_loader_preamble(content) node = gemspec_top_level_gem_version_node(content) unless node fallback_range = gemspec_legacy_version_loader_preamble_line_range(content) return content unless fallback_range return replace_source_range_lines(content, fallback_range.fetch(:start_line), fallback_range.fetch(:end_line), "") end replace_source_range_lines(content, node.location.start_line, (content, node.location.end_line), "") end |
.remove_gemspec_self_dependency_lines(content, package_name, receiver:) ⇒ Object
12107 12108 12109 12110 12111 12112 12113 12114 12115 12116 12117 12118 12119 |
# File 'lib/kettle/jem.rb', line 12107 def remove_gemspec_self_dependency_lines(content, package_name, receiver:) name = package_name.to_s return content if name.empty? remove_indexes = Set.new gemspec_dependency_records(content, receiver: receiver).each do |record| next unless record.fetch(:name) == name (record.fetch(:start_line)..record.fetch(:end_line)).each { |line_number| remove_indexes << (line_number - 1) } end lines = content.to_s.lines.each_with_index.reject { |_line, index| remove_indexes.include?(index) }.map(&:first) ensure_trailing_newline(lines.join.gsub(/\n{3,}/, "\n\n")) end |
.remove_gemspec_version_gem_dependency_when_disabled(content, facts, receiver:, template_declares_version_gem: false) ⇒ Object
10969 10970 10971 10972 10973 10974 10975 |
# File 'lib/kettle/jem.rb', line 10969 def remove_gemspec_version_gem_dependency_when_disabled(content, facts, receiver:, template_declares_version_gem: false) return content if version_gem_enabled?(facts) return content if template_declares_version_gem && !version_gem_explicitly_disabled?(facts) && version_gem_runtime_compatible?(facts) cleaned = remove_gemspec_dependency_lines(content, receiver: receiver, names: ["version_gem"], runtime_only: true) remove_ruby_comment_lines_containing(cleaned, "version_gem") end |
.remove_gemspec_version_gem_dependency_when_non_default_entrypoint(content, facts, receiver:) ⇒ Object
10981 10982 10983 10984 10985 10986 |
# File 'lib/kettle/jem.rb', line 10981 def remove_gemspec_version_gem_dependency_when_non_default_entrypoint(content, facts, receiver:) return content unless facts.to_h.dig(:version_gem, :non_default_entrypoint) cleaned = remove_gemspec_dependency_lines(content, receiver: receiver, names: ["version_gem"], runtime_only: true) remove_ruby_comment_lines_containing(cleaned, "version_gem") end |
.remove_line_ranges(content, ranges) ⇒ Object
7364 7365 7366 7367 |
# File 'lib/kettle/jem.rb', line 7364 def remove_line_ranges(content, ranges) delete_lines = ranges.flat_map(&:to_a).to_set content.to_s.lines.each_with_index.reject { |_line, index| delete_lines.include?(index) }.map(&:first).join end |
.remove_managed_stdlib_appraisal_gems(content) ⇒ Object
10156 10157 10158 10159 10160 10161 10162 |
# File 'lib/kettle/jem.rb', line 10156 def remove_managed_stdlib_appraisal_gems(content) parsed = appraisal_blocks(content) blocks = parsed.fetch(:order).map do |name| remove_managed_stdlib_gems_from_appraisal_block(parsed.fetch(:blocks).fetch(name)) end ensure_trailing_newline(([parsed.fetch(:prelude).to_s.rstrip] + blocks.map(&:rstrip)).reject(&:empty?).join("\n\n")) end |
.remove_managed_stdlib_gems_from_appraisal_block(block) ⇒ Object
10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 |
# File 'lib/kettle/jem.rb', line 10164 def remove_managed_stdlib_gems_from_appraisal_block(block) return block unless appraisal_x_stdlib_eval_gemfile_call(block) lines = block.to_s.lines remove_indexes = Set.new gemfile_gem_call_records(block).each do |record| next unless MANAGED_APPRAISAL_STDLIB_GEMS.include?(record.fetch(:name)) start_index = record.fetch(:start_line) - 1 start_index -= 1 while start_index.positive? && gemfile_comment_line?(lines[start_index - 1]) (start_index..(record.fetch(:end_line) - 1)).each { |index| remove_indexes << index } end return block if remove_indexes.empty? ensure_trailing_newline(lines.each_with_index.reject { |_line, index| remove_indexes.include?(index) }.map(&:first).join.gsub(/\n{3,}/, "\n\n")) end |
.remove_obsolete_local_gemfile_nomono_activation(content) ⇒ Object
8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 |
# File 'lib/kettle/jem.rb', line 8937 def remove_obsolete_local_gemfile_nomono_activation(content) records = obsolete_local_gemfile_nomono_activation_records(content) return content if records.empty? records.sort_by { |record| -record.fetch(:start_line) }.reduce(content.to_s) do |output, record| replace_source_range_lines( output, record.fetch(:start_line), (output, record.fetch(:end_line)), "" ) end end |
.remove_obsolete_simplecov_keep_destination_config(content) ⇒ Object
12499 12500 12501 12502 12503 12504 12505 12506 |
# File 'lib/kettle/jem.rb', line 12499 def remove_obsolete_simplecov_keep_destination_config(content) config = YAML.safe_load(content.to_s, permitted_classes: [], aliases: true) || {} simplecov_config = config.dig("files", ".simplecov") return content unless simplecov_config.is_a?(Hash) return content unless simplecov_config.keys == ["strategy"] && simplecov_config["strategy"].to_s == "keep_destination" remove_yaml_mapping_path(content, %w[files .simplecov]) end |
.remove_obsolete_simplecov_rescue_bootstrap_blocks(content) ⇒ Object
8567 8568 8569 8570 8571 8572 8573 8574 |
# File 'lib/kettle/jem.rb', line 8567 def remove_obsolete_simplecov_rescue_bootstrap_blocks(content) records = obsolete_simplecov_rescue_bootstrap_records(content) return content if records.empty? records.sort_by { |record| -record.fetch(:start_line) }.reduce(content.to_s) do |output, record| replace_source_range_lines(output, record.fetch(:start_line), (output, record.fetch(:end_line)), "") end end |
.remove_readme_badge_and_refs(content, badge_source, link_labels) ⇒ Object
7618 7619 7620 7621 7622 7623 |
# File 'lib/kettle/jem.rb', line 7618 def remove_readme_badge_and_refs(content, badge_source, link_labels) ensure_runtime_dependencies! processed = content.to_s.gsub(badge_source, "").lines.map(&:rstrip).join("\n") processed = "#{processed}\n" if content.to_s.end_with?("\n") ReadmePostProcessor.delete_markdown_link_definitions(processed, Array(link_labels)) end |
.remove_readme_sections(content, section_bases) ⇒ Object
7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 |
# File 'lib/kettle/jem.rb', line 7887 def remove_readme_sections(content, section_bases) bases = section_bases.map { |section| normalize_readme_heading(section) }.uniq return content if bases.empty? sections = markdown_sections(content).select { |section| bases.include?(section.fetch(:base)) } return content if sections.empty? lines = content.to_s.split("\n", -1) sections.reverse_each do |section| lines[section.fetch(:start)..section.fetch(:end)] = [] end ensure_trailing_newline(lines.join("\n").gsub(/\n{3,}/, "\n\n").strip) end |
.remove_ruby_comment_lines_containing(content, text) ⇒ Object
11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 |
# File 'lib/kettle/jem.rb', line 11009 def remove_ruby_comment_lines_containing(content, text) result = prism_parse_success(content) return content unless result selectors = result.comments.filter_map do |comment| next unless comment.location.slice.include?(text.to_s) {start_line: comment.location.start_line, end_line: comment.location.end_line} end return content if selectors.empty? ensure_trailing_newline(delete_line_ranges(content.to_s, selectors)) end |
.remove_stale_executable_startup_header(content, header) ⇒ Object
5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 |
# File 'lib/kettle/jem.rb', line 5102 def remove_stale_executable_startup_header(content, header) replacements = header.values.map do |node| { start_offset: node.location.start_offset, end_offset: node.location.end_offset, replacement: "" } end ensure_trailing_newline(collapse_excess_blank_lines(replace_source_offsets(content, replacements))) end |
.remove_stale_gemspec_file_override_blocks!(lines, files_index, gemspec) ⇒ Object
5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 |
# File 'lib/kettle/jem.rb', line 5361 def remove_stale_gemspec_file_override_blocks!(lines, files_index, gemspec) index = files_index + 1 while index < lines.length line = lines.fetch(index) break if top_level_yaml_key_line?(line) # Keep this as a bounded line match instead of dumping YAML so the # generated field-guide comments and ordering survive profile sync. match = line.match(/\A ([^ ].*\.gemspec):\z/) if match && match[1] != gemspec block_end = kettle_config_file_override_block_end(lines, index) lines.slice!(index...block_end) next end index += 1 end end |
.remove_stale_generated_gemspec_homepage_replacement(replacements, destination_content, facts, receiver:) ⇒ Object
10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 |
# File 'lib/kettle/jem.rb', line 10646 def remove_stale_generated_gemspec_homepage_replacement(replacements, destination_content, facts, receiver:) desired_homepage = facts.to_h.dig(:package, :homepage_url).to_s return replacements if desired_homepage.empty? || !github_org_from_url(desired_homepage) return replacements unless replacements.key?("homepage") existing = gemspec_assignment_records(destination_content, receiver: receiver).find { |record| record.fetch(:field) == "homepage" } existing_homepage = existing && existing.fetch(:value).to_s return replacements if existing_homepage.empty? || existing_homepage == desired_homepage return replacements unless github_org_from_url(existing_homepage) replacements.except("homepage") end |
.remove_stale_main_gemfile_direct_sibling_block(content, template_content) ⇒ Object
8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 |
# File 'lib/kettle/jem.rb', line 8091 def remove_stale_main_gemfile_direct_sibling_block(content, template_content) return content if template_content.to_s.include?("direct_sibling_gems = %w[") records = main_gemfile_direct_sibling_records(content) return content if records.empty? records.sort_by { |record| -record.fetch(:start_line) }.reduce(content.to_s) do |output, record| replace_source_range_lines( output, record.fetch(:start_line), (output, record.fetch(:end_line)), "" ) end end |
.remove_stale_main_gemfile_tree_sitter_language_pack(content, template_content) ⇒ Object
8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 |
# File 'lib/kettle/jem.rb', line 8075 def remove_stale_main_gemfile_tree_sitter_language_pack(content, template_content) return content if gemfile_declares_direct_gem?(template_content, "tree_sitter_language_pack") records = main_gemfile_direct_gem_records(content, "tree_sitter_language_pack") return content if records.empty? records.sort_by { |record| -record.fetch(:start_line) }.reduce(content.to_s) do |output, record| replace_source_range_lines( output, record.fetch(:start_line), (output, record.fetch(:end_line)), "" ) end end |
.remove_top_level_ruby_require(content, argument) ⇒ Object
16139 16140 16141 16142 16143 16144 16145 16146 16147 16148 |
# File 'lib/kettle/jem.rb', line 16139 def remove_top_level_ruby_require(content, argument) selectors = top_level_ruby_call_records(content, :require).filter_map do |call| next unless ruby_string_argument(call) == argument.to_s {start_line: call.location.start_line, end_line: ruby_node_source_end_line(call)} end return content.to_s if selectors.empty? collapse_excess_blank_lines(delete_line_ranges(content.to_s, selectors)) end |
.remove_top_level_yaml_key_lines(content, key) ⇒ Object
19263 19264 19265 19266 19267 19268 19269 19270 19271 19272 19273 19274 19275 19276 19277 19278 19279 19280 19281 19282 |
# File 'lib/kettle/jem.rb', line 19263 def remove_top_level_yaml_key_lines(content, key) lines = content.to_s.lines document = Psych.parse_stream(content.to_s).children.first root = document&.root return content unless root.is_a?(Psych::Nodes::Mapping) pairs = root.children.each_slice(2).to_a pairs.each_with_index do |(key_node, value_node), index| next unless key_node.is_a?(Psych::Nodes::Scalar) && key_node.value.to_s == key.to_s next_key = pairs[index + 1]&.first end_line = next_key&.start_line || value_node.end_line end_line += 1 if end_line <= key_node.start_line return [*lines[0...key_node.start_line], *lines[end_line..].to_a].join end content rescue Psych::Exception content end |
.remove_version_gem_class_eval_references(content) ⇒ Object
16163 16164 16165 16166 16167 16168 |
# File 'lib/kettle/jem.rb', line 16163 def remove_version_gem_class_eval_references(content) selectors = version_gem_class_eval_selectors(content) return content.to_s if selectors.empty? collapse_excess_blank_lines(delete_line_ranges(content.to_s, selectors)) end |
.remove_version_gem_entrypoint_references(content) ⇒ Object
16150 16151 16152 16153 16154 16155 16156 16157 16158 16159 16160 16161 |
# File 'lib/kettle/jem.rb', line 16150 def remove_version_gem_entrypoint_references(content) selectors = [] top_level_ruby_call_records(content, :require).each do |call| next unless ruby_string_argument(call) == "version_gem" selectors << {start_line: call.location.start_line, end_line: ruby_node_source_end_line(call)} end selectors.concat(version_gem_class_eval_selectors(content)) return content.to_s if selectors.empty? collapse_excess_blank_lines(delete_line_ranges(content.to_s, selectors)) end |
.remove_version_gem_shared_example(content) ⇒ Object
15795 15796 15797 15798 15799 |
# File 'lib/kettle/jem.rb', line 15795 def remove_version_gem_shared_example(content) content.to_s.lines.reject do |line| line.include?('it_behaves_like "a Version module"') end.join end |
.remove_x_std_lib_eval_for_gem(content, gem_name) ⇒ Object
9795 9796 9797 9798 9799 9800 9801 9802 9803 |
# File 'lib/kettle/jem.rb', line 9795 def remove_x_std_lib_eval_for_gem(content, gem_name) records = ruby_call_records(content, :eval_gemfile).filter_map do |call| path = ruby_string_argument(call).to_s next unless path.split("/").any? { |part| part == gem_name || part.tr("-", "_") == gem_name.tr("-", "_") } {start_line: call.location.start_line, end_line: ruby_node_source_end_line(call)} end replace_record_ranges(content, records.to_h { |record| [record.fetch(:start_line), record.merge(replacement: "")] }) end |
.remove_yaml_mapping_path(content, path) ⇒ Object
12746 12747 12748 12749 12750 12751 12752 12753 12754 12755 12756 |
# File 'lib/kettle/jem.rb', line 12746 def remove_yaml_mapping_path(content, path) lines = content.to_s.lines yaml_mapping_path_entries(content).each do |entry| next unless entry.fetch(:path) == path start_line = entry.fetch(:start_line) end_line = entry.fetch(:end_line) return ensure_trailing_newline([*lines[0...start_line], *lines[end_line..].to_a].join) end content end |
.remove_yaml_scalar_path(content, path) ⇒ Object
12702 12703 12704 12705 12706 12707 12708 12709 12710 12711 |
# File 'lib/kettle/jem.rb', line 12702 def remove_yaml_scalar_path(content, path) lines = content.to_s.lines yaml_scalar_path_entries(content).each do |entry| next unless entry.fetch(:path) == path line_index = entry.fetch(:line) return ensure_trailing_newline(lines.each_with_index.reject { |_line, index| index == line_index }.map(&:first).join) end content end |
.render_thin_readme(facts, readme_style, original, preserve_config) ⇒ Object
5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 |
# File 'lib/kettle/jem.rb', line 5854 def render_thin_readme(facts, readme_style, original, preserve_config) package = facts.fetch(:package) rubygems = facts.fetch(:rubygems) license_expression = package[:license_expression].to_s min_ruby = minimum_ruby_token(rubygems[:min_ruby]) title = classify_namespace(package.fetch(:name)) badges = [ package[:source_url] && "[](#{package[:source_url]})", license_expression.empty? ? nil : "}-259D6C.svg)" ].compact.join(" ") funding_enabled = readme_style.fetch(:floss_funding_enabled, false) security_enabled = readme_style.fetch(:security_enabled, false) section_partials = readme_section_partials_for_render(readme_style, facts) rendered = [ "# 💎 #{title}", badges, "## 🌻 Synopsis\n\n#{section_partials.fetch("synopsis", "")}", "## 💡 Info you can shake a stick at\n\nCompatible with MRI Ruby #{min_ruby}+.\n\n#{readme_family_intro_and_backend_matrix(readme_style)}", "## ✨ Installation\n\n```console\ngem install #{package.fetch(:name)}\n```", "## ⚙️ Configuration\n\n#{section_partials.fetch("configuration", "")}", "## 🔧 Basic Usage\n\n#{section_partials.fetch("basic usage", "")}" ] rendered << "## 🦷 FLOSS Funding\n\nThis free software project accepts funding support when configured by the package maintainer." if funding_enabled rendered << "## 🔐 Security\n\nSee [SECURITY.md](SECURITY.md)." if security_enabled rendered.concat([ "## 🤝 Contributing\n\nContributions are welcome. Missing optional service integrations are reported by the generator instead of rendered as broken badges.", "## 📌 Versioning\n\nThis project follows semantic versioning for its public API where practical.", "## 📄 License\n\nThis project is made available under the following license expression: #{license_expression.empty? ? "unspecified" : license_expression}.", "## 🤑 A request for help\n\nPlease support the project by using it, reporting issues, and contributing improvements." ]) template_content = rendered.reject(&:empty?).join("\n\n") + "\n" merge_readme_template( template_content: template_content, destination_content: original, preserve_config: readme_preserve_config_without_partial_sections(preserve_config, section_partials.keys) ) end |
.replace_existing_markdown_managed_block(content, marker, replacement) ⇒ Object
20153 20154 20155 20156 20157 20158 20159 |
# File 'lib/kettle/jem.rb', line 20153 def replace_existing_markdown_managed_block(content, marker, replacement) open = "<!-- #{marker}:start -->" close = "<!-- #{marker}:end -->" replace_markdown_managed_block_with_crispr(content, open, close, replacement) do content end end |
.replace_gemspec_assignment_sources(content, replacements, receiver:) ⇒ Object
11692 11693 11694 11695 11696 11697 11698 11699 11700 11701 11702 |
# File 'lib/kettle/jem.rb', line 11692 def replace_gemspec_assignment_sources(content, replacements, receiver:) return content if replacements.empty? records_by_line = gemspec_assignment_records(content, receiver: receiver).each_with_object({}) do |record, index| field = record.fetch(:field) next unless replacements.key?(field) index[record.fetch(:start_line)] = record.merge(replacement: "#{replacements.fetch(field)}\n") end replace_record_ranges(content, records_by_line) end |
.replace_gemspec_version_assignment(content, receiver:, rhs:) ⇒ Object
10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 |
# File 'lib/kettle/jem.rb', line 10691 def replace_gemspec_version_assignment(content, receiver:, rhs:) replacement = "#{receiver}.version = #{rhs}" record = gemspec_assignment_records(content, receiver: receiver).find { |candidate| candidate.fetch(:field) == "version" } return replace_source_range_lines(content, record.fetch(:start_line), record.fetch(:end_line), "#{leading_whitespace(record.fetch(:source))}#{replacement}\n") if record name = gemspec_assignment_records(content, receiver: receiver).find { |candidate| candidate.fetch(:field) == "name" } return insert_lines_after(content, name.fetch(:end_line), " #{replacement}\n") if name insert_lines_after(content, gemspec_new_call(content)&.location&.start_line || 1, " #{replacement}\n") end |
.replace_github_workflow_action_pin_sha(line, sha) ⇒ Object
20036 20037 20038 |
# File 'lib/kettle/jem.rb', line 20036 def replace_github_workflow_action_pin_sha(line, sha) line.to_s.sub(/@[a-f0-9]{40}/, "@#{sha}") end |
.replace_kettle_config_bootstrap_licenses(content, licenses) ⇒ Object
12378 12379 12380 12381 12382 12383 12384 |
# File 'lib/kettle/jem.rb', line 12378 def replace_kettle_config_bootstrap_licenses(content, licenses) license_block = ["licenses:", *licenses.map { |license_id| " - #{license_id}" }].join("\n") updated = replace_yaml_node_lines(content, "licenses", "#{license_block}\n") return updated unless updated == content raise Error, "Could not replace licenses block in .kettle-jem.yml bootstrap template" end |
.replace_kettle_config_bootstrap_project_emoji(content, emoji) ⇒ Object
12371 12372 12373 12374 12375 12376 |
# File 'lib/kettle/jem.rb', line 12371 def replace_kettle_config_bootstrap_project_emoji(content, emoji) updated = replace_yaml_scalar_line(content, "project_emoji", emoji.to_s) return updated unless updated == content raise Error, "Could not replace project_emoji in .kettle-jem.yml bootstrap template" end |
.replace_kettle_config_bootstrap_rubyforum(content, rubyforum) ⇒ Object
12386 12387 12388 12389 12390 12391 12392 12393 12394 12395 |
# File 'lib/kettle/jem.rb', line 12386 def replace_kettle_config_bootstrap_rubyforum(content, rubyforum) updated = content family_tag = rubyforum[:family_tag].to_s project_tag = rubyforum[:project_tag].to_s family_tag = "" if token_placeholder?(family_tag) project_tag = "" if token_placeholder?(project_tag) updated = replace_yaml_scalar_path(updated, %w[rubyforum family_tag], yaml_config_scalar_literal(family_tag, path: %w[rubyforum family_tag])) unless family_tag.empty? updated = replace_yaml_scalar_path(updated, %w[rubyforum project_tag], yaml_config_scalar_literal(project_tag, path: %w[rubyforum project_tag])) unless project_tag.empty? updated end |
.replace_local_gems_assignment(content, gems) ⇒ Object
9036 9037 9038 |
# File 'lib/kettle/jem.rb', line 9036 def replace_local_gems_assignment(content, gems) replace_word_array_assignment(content, :local_gems, gems) end |
.replace_markdown_managed_block(content, marker, replacement) ⇒ Object
20145 20146 20147 20148 20149 20150 20151 |
# File 'lib/kettle/jem.rb', line 20145 def replace_markdown_managed_block(content, marker, replacement) open = "<!-- #{marker}:start -->" close = "<!-- #{marker}:end -->" replace_markdown_managed_block_with_crispr(content, open, close, replacement) do ensure_trailing_newline([content.rstrip, "", replacement.to_s.rstrip].join("\n")) end end |
.replace_markdown_managed_block_with_crispr(content, open_marker, close_marker, replacement) ⇒ Object
20173 20174 20175 20176 20177 20178 20179 20180 20181 20182 20183 20184 20185 20186 20187 20188 20189 20190 20191 |
# File 'lib/kettle/jem.rb', line 20173 def replace_markdown_managed_block_with_crispr(content, open_marker, close_marker, replacement) ensure_runtime_dependencies! prepared_replacement = ensure_trailing_newline(replacement.to_s) actor = Ast::Crispr::Replace.call( content: content.to_s, target: Ast::Crispr::Markdown::Markly::Selectors.html_comment_block( start_text: open_marker.delete_prefix("<!-- ").delete_suffix(" -->"), end_text: close_marker.delete_prefix("<!-- ").delete_suffix(" -->"), span: :outermost, include_trailing_gap: true, limit: {none_or_one: true} ), replacement: prepared_replacement, source_label: "managed markdown block" ) return actor.updated_content if actor.match_count.positive? yield end |
.replace_markdown_with_ast_crispr(content, target, replacement) ⇒ Object
7754 7755 7756 7757 7758 7759 7760 7761 7762 |
# File 'lib/kettle/jem.rb', line 7754 def replace_markdown_with_ast_crispr(content, target, replacement) ensure_runtime_dependencies! Ast::Crispr::Replace.call( content: content.to_s, target: target, replacement: replacement, source_label: "README.md" ).updated_content end |
.replace_matching_gemspec_dependency_lines(content, destination_dependencies, receiver:) ⇒ Object
11790 11791 11792 11793 11794 11795 11796 |
# File 'lib/kettle/jem.rb', line 11790 def replace_matching_gemspec_dependency_lines(content, destination_dependencies, receiver:) records_by_line = gemspec_dependency_records(content, receiver: receiver).each_with_object({}) do |record, index| replacement = destination_dependencies[gemspec_dependency_record_key(record)] index[record.fetch(:start_line)] = record.merge(replacement: replacement) if replacement end replace_record_ranges(content, records_by_line) end |
.replace_record_ranges(content, records_by_line) ⇒ Object
12219 12220 12221 12222 12223 12224 12225 12226 12227 12228 12229 12230 12231 12232 12233 12234 12235 |
# File 'lib/kettle/jem.rb', line 12219 def replace_record_ranges(content, records_by_line) return content if records_by_line.empty? skip_until = 0 content.to_s.lines.each_with_index.flat_map do |line, index| line_number = index + 1 next [] if line_number < skip_until record = records_by_line[line_number] if record skip_until = record.fetch(:end_line) + 1 record.fetch(:replacement) else line end end.join end |
.replace_ruby_managed_block(content, replacement) ⇒ Object
20167 20168 20169 20170 20171 |
# File 'lib/kettle/jem.rb', line 20167 def replace_ruby_managed_block(content, replacement) replace_ruby_managed_block_with_crispr(content, MANAGED_BLOCK_OPEN, MANAGED_BLOCK_CLOSE, replacement) do ensure_trailing_newline([content.rstrip, replacement.to_s.rstrip].reject(&:empty?).join("\n")) end end |
.replace_ruby_managed_block_with_crispr(content, open_marker, close_marker, replacement) ⇒ Object
20212 20213 20214 20215 20216 20217 20218 20219 20220 20221 20222 20223 20224 20225 20226 20227 20228 20229 20230 |
# File 'lib/kettle/jem.rb', line 20212 def replace_ruby_managed_block_with_crispr(content, open_marker, close_marker, replacement) ensure_runtime_dependencies! prepared_replacement = ensure_trailing_newline(replacement.to_s) actor = Ast::Crispr::Replace.call( content: content.to_s, target: Ast::Crispr::Ruby::Prism::Selectors.comment_line_block( start_text: open_marker, end_text: close_marker, span: :outermost, include_trailing_gap: true, limit: {none_or_one: true} ), replacement: prepared_replacement, source_label: "managed Ruby block" ) return actor.updated_content if actor.match_count.positive? yield end |
.replace_source_byte_range(content, start_offset, end_offset, replacement) ⇒ Object
10026 10027 10028 10029 10030 10031 |
# File 'lib/kettle/jem.rb', line 10026 def replace_source_byte_range(content, start_offset, end_offset, replacement) source = content.to_s before = source.byteslice(0, start_offset) || +"" after = source.byteslice(end_offset, source.bytesize - end_offset) || +"" "#{before}#{replacement}#{after}" end |
.replace_source_offsets(content, replacements) ⇒ Object
10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 |
# File 'lib/kettle/jem.rb', line 10013 def replace_source_offsets(content, replacements) output = content.to_s.dup replacements.sort_by { |replacement| -replacement.fetch(:start_offset) }.each do |replacement| output = replace_source_byte_range( output, replacement.fetch(:start_offset), replacement.fetch(:end_offset), replacement.fetch(:replacement) ) end output end |
.replace_source_range_lines(content, start_line, end_line, replacement) ⇒ Object
12237 12238 12239 |
# File 'lib/kettle/jem.rb', line 12237 def replace_source_range_lines(content, start_line, end_line, replacement) replace_record_ranges(content, {start_line => {end_line: end_line, replacement: replacement}}) end |
.replace_text_managed_block(content, replacement) ⇒ Object
20161 20162 20163 20164 20165 |
# File 'lib/kettle/jem.rb', line 20161 def replace_text_managed_block(content, replacement) replace_text_managed_block_with_crispr(content, MANAGED_BLOCK_OPEN, MANAGED_BLOCK_CLOSE, replacement) do ensure_trailing_newline([content.rstrip, replacement.to_s.rstrip].reject(&:empty?).join("\n")) end end |
.replace_text_managed_block_with_crispr(content, open_marker, close_marker, replacement) ⇒ Object
20193 20194 20195 20196 20197 20198 20199 20200 20201 20202 20203 20204 20205 20206 20207 20208 20209 20210 |
# File 'lib/kettle/jem.rb', line 20193 def replace_text_managed_block_with_crispr(content, open_marker, close_marker, replacement) ensure_runtime_dependencies! prepared_replacement = ensure_trailing_newline(replacement.to_s) actor = Ast::Crispr::Replace.call( content: content.to_s, target: Ast::Crispr::Selectors.line_block( start_line_text: open_marker, end_line_text: close_marker, include_trailing_gap: true, limit: {none_or_one: true} ), replacement: prepared_replacement, source_label: "managed text block" ) return actor.updated_content if actor.match_count.positive? yield end |
.replace_toml_string_scalar_line(content, key, value) ⇒ Object
7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 |
# File 'lib/kettle/jem.rb', line 7296 def replace_toml_string_scalar_line(content, key, value) lines = content.to_s.lines lines.each_with_index do |line, index| next unless line.strip.start_with?("#{key} ") indent = line[/\A\s*/] lines[index] = "#{indent}#{key} = #{JSON.generate(value.to_s)}\n" return lines.join end content end |
.replace_word_array_assignment(content, name, gems) ⇒ Object
9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 |
# File 'lib/kettle/jem.rb', line 9048 def replace_word_array_assignment(content, name, gems) replacement = ["#{name} = %w["] gems.each { |gem_name| replacement << " #{gem_name}" } replacement << "]" if (record = word_array_assignment_record(content, name)) replace_source_range_lines(content, record.fetch(:start_line), record.fetch(:end_line), ensure_trailing_newline(replacement.join("\n"))) else ensure_trailing_newline([content.to_s.rstrip, replacement.join("\n")].reject(&:empty?).join("\n\n")) end end |
.replace_yaml_node_lines(content, key, replacement) ⇒ Object
12805 12806 12807 12808 12809 12810 12811 12812 12813 12814 12815 12816 12817 |
# File 'lib/kettle/jem.rb', line 12805 def replace_yaml_node_lines(content, key, replacement) lines = content.to_s.lines yaml_mapping_nodes(content).each do |mapping| mapping.children.each_slice(2) do |key_node, value_node| next unless key_node.is_a?(Psych::Nodes::Scalar) && key_node.value.to_s == key.to_s start_line = key_node.start_line end_line = value_node.end_line return [*lines[0...start_line], replacement, *lines[end_line..].to_a].join end end content end |
.replace_yaml_scalar_line(content, key, value) ⇒ Object
12397 12398 12399 12400 12401 12402 12403 12404 12405 12406 12407 12408 12409 12410 12411 |
# File 'lib/kettle/jem.rb', line 12397 def replace_yaml_scalar_line(content, key, value) lines = content.to_s.lines yaml_scalar_pairs(content).each do |key_node, value_node| next unless key_node.value.to_s == key.to_s line_index = key_node.start_line line = lines[line_index].to_s key_index = line.index("#{key}:") next unless key_index lines[line_index] = "#{line[0...key_index]}#{key}: #{value}\n" return lines.join end content end |
.replace_yaml_scalar_path(content, path, value) ⇒ Object
12685 12686 12687 12688 12689 12690 12691 12692 12693 12694 12695 12696 12697 12698 12699 12700 |
# File 'lib/kettle/jem.rb', line 12685 def replace_yaml_scalar_path(content, path, value) lines = content.to_s.lines yaml_scalar_path_entries(content).each do |entry| next unless entry.fetch(:path) == path line_index = entry.fetch(:line) line = lines[line_index].to_s key = path.last.to_s key_index = line.index("#{key}:") next unless key_index lines[line_index] = "#{line[0...key_index]}#{key}: #{value}#{yaml_line_comment_suffix(line, key_index)}\n" return lines.join end content end |
.replacement_for_supported_gemspec_files_assignment(template_record:, destination_record:, template_receiver:) ⇒ Object
11279 11280 11281 11282 11283 11284 11285 11286 11287 |
# File 'lib/kettle/jem.rb', line 11279 def replacement_for_supported_gemspec_files_assignment(template_record:, destination_record:, template_receiver:) if generic_bundler_gemspec_files_assignment?(destination_record) normalize_gemspec_receiver( template_record.fetch(:source), from: template_receiver, to: template_receiver ) end end |
.report_with_duration(report, duration_ms) ⇒ Object
4818 4819 4820 4821 4822 |
# File 'lib/kettle/jem.rb', line 4818 def report_with_duration(report, duration_ms) report[:metadata] = report.fetch(:metadata, {}).merge(duration_ms: duration_ms) report.dig(:report_envelope, :report, :metadata)&.[]=(:duration_ms, duration_ms) report end |
.reported_post_apply_changed_files(step) ⇒ Object
4876 4877 4878 4879 4880 |
# File 'lib/kettle/jem.rb', line 4876 def reported_post_apply_changed_files(step) return [] if event_payload_value(step, :metadata_only) Array(event_payload_value(step, :changed_files) || []) end |
.repository_facts(project_root, source_url, package_name:, repository_topology:) ⇒ Object
16631 16632 16633 16634 16635 16636 16637 16638 16639 16640 16641 16642 16643 16644 16645 16646 16647 16648 16649 16650 16651 16652 16653 16654 16655 16656 16657 16658 16659 16660 16661 16662 16663 16664 16665 16666 16667 |
# File 'lib/kettle/jem.rb', line 16631 def repository_facts(project_root, source_url, package_name:, repository_topology:) topology = normalize_repository_topology(repository_topology) monorepo_subproject = topology == REPOSITORY_TOPOLOGY_MONOREPO_SUBPROJECT local_root = monorepo_subproject ? git_worktree_root(project_root) : nil repository_root = local_root || project_root git_source_url = git_remote_source_url(repository_root) repo_url = if monorepo_subproject repository_root_url(git_source_url || source_url) else repository_root_url(source_url) end repo_name = repository_name_from_source_url(repo_url) org = github_org_from_url(repo_url).to_s slug = [org, repo_name].reject(&:empty?).join("/") facts = compact_hash( mode: monorepo_subproject ? "monorepo_subproject" : "standalone", topology: topology, url: repo_url, name: repo_name, slug: slug, star_history: readme_star_history_facts(repository_root, git_source_url) ) return facts unless monorepo_subproject package_path = git_worktree_prefix(project_root) package_path = package_path[0...-1] while package_path.end_with?("/") return facts.merge(local_root: local_root) if package_path.empty? facts.merge( local_root: local_root, package_path: package_path, package_source_url: source_tree_url(repo_url, package_path), gitlab_package_source_url: source_tree_url("https://gitlab.com/#{slug}", package_path), codeberg_package_source_url: source_tree_url("https://codeberg.org/#{slug}", package_path), checksums_url: source_tree_url("https://gitlab.com/#{slug}", "checksums") ) end |
.repository_monorepo_subproject?(repository) ⇒ Boolean
17843 17844 17845 17846 17847 17848 17849 |
# File 'lib/kettle/jem.rb', line 17843 def repository_monorepo_subproject?(repository) return false unless repository.is_a?(Hash) repository[:topology].to_s == REPOSITORY_TOPOLOGY_MONOREPO_SUBPROJECT || repository[:mode].to_s == "monorepo_subproject" || repository[:mode].to_s == "monorepo_subgem" end |
.repository_name_from_source_url(source_url) ⇒ Object
16624 16625 16626 16627 16628 16629 |
# File 'lib/kettle/jem.rb', line 16624 def repository_name_from_source_url(source_url) base = source_url.to_s.split("?", 2).first.to_s.split("#", 2).first.to_s base = base[0...-1] while base.end_with?("/") name = base.split("/").last.to_s name.end_with?(".git") ? name[0...-4] : name end |
.repository_project_logo_href(repository, slug:, org:, gem_name:) ⇒ Object
17199 17200 17201 17202 17203 17204 |
# File 'lib/kettle/jem.rb', line 17199 def repository_project_logo_href(repository, slug:, org:, gem_name:) package_source_url = repository.is_a?(Hash) ? repository[:package_source_url].to_s : "" return package_source_url unless package_source_url.empty? (org.to_s.empty? || gem_name.to_s.empty?) ? "#{LOGOS_GALTZO_BASE_URL}/#{slug}/" : "https://github.com/#{org}/#{gem_name}" end |
.repository_project_logo_slug(repository, org:, gem_name:) ⇒ Object
17192 17193 17194 17195 17196 17197 |
# File 'lib/kettle/jem.rb', line 17192 def repository_project_logo_slug(repository, org:, gem_name:) package_path = repository.is_a?(Hash) ? repository[:package_path].to_s : "" return [org, repository[:name].to_s, File.basename(package_path)].reject(&:empty?).join("/") if repository.is_a?(Hash) && !package_path.empty? [org.to_s, gem_name.to_s].reject(&:empty?).join("/") end |
.repository_resource_urls(repository) ⇒ Object
16669 16670 16671 16672 16673 16674 16675 16676 16677 16678 16679 16680 16681 16682 16683 16684 16685 16686 16687 16688 16689 16690 16691 16692 16693 16694 16695 16696 16697 16698 16699 16700 16701 16702 16703 16704 16705 16706 16707 16708 16709 16710 16711 16712 16713 16714 16715 16716 16717 16718 16719 16720 16721 16722 16723 16724 16725 16726 16727 16728 16729 16730 |
# File 'lib/kettle/jem.rb', line 16669 def repository_resource_urls(repository) repo_url = repository[:url].to_s repo_slug = repository[:slug].to_s github_org = repo_slug.split("/", 2).first.to_s repo_name = repository[:name].to_s gitlab_url = repository[:gitlab_url].to_s gitlab_url = "https://gitlab.com/#{repo_slug}" if gitlab_url.empty? codeberg_url = repository[:codeberg_url].to_s codeberg_url = "https://codeberg.org/#{repo_slug}" if codeberg_url.empty? package_source_url = repository[:package_source_url].to_s package_source_url = repo_url if package_source_url.empty? gitlab_package_source_url = repository[:gitlab_package_source_url].to_s gitlab_package_source_url = gitlab_url if gitlab_package_source_url.empty? codeberg_package_source_url = repository[:codeberg_package_source_url].to_s codeberg_package_source_url = codeberg_url if codeberg_package_source_url.empty? checksums_url = repository[:checksums_url].to_s checksums_url = source_tree_url(gitlab_url, "checksums") if checksums_url.empty? { github_repository_url: repo_url, github_package_source_url: package_source_url, github_releases_url: "#{repo_url}/releases", github_actions_url: "#{repo_url}/actions", github_discussions_url: "#{repo_url}/discussions", github_issues_url: "#{repo_url}/issues", github_pulls_url: "#{repo_url}/pulls", github_wiki_url: "#{repo_url}/wiki", github_codeql_url: "#{repo_url}/security/code-scanning", github_contributors_url: "#{repo_url}/graphs/contributors", github_contributing_url: source_blob_url(repo_url, "CONTRIBUTING.md"), github_changelog_url: source_blob_url(repo_url, "CHANGELOG.md"), github_security_url: source_blob_url(repo_url, "SECURITY.md"), github_code_of_conduct_url: source_blob_url(repo_url, "CODE_OF_CONDUCT.md"), github_rubocop_url: source_blob_url(repo_url, "RUBOCOP.md"), github_irp_url: source_blob_url(repo_url, "IRP.md"), gitlab_repository_url: gitlab_url, gitlab_package_source_url: gitlab_package_source_url, gitlab_issues_url: "#{gitlab_url}/-/issues", gitlab_pulls_url: "#{gitlab_url}/-/merge_requests", gitlab_wiki_url: "#{gitlab_url}/-/wikis/home", gitlab_contributors_url: "#{gitlab_url}/-/graphs/main", gitlab_contributing_url: source_blob_url(gitlab_url, "CONTRIBUTING.md"), gitlab_changelog_url: source_blob_url(gitlab_url, "CHANGELOG.md"), gitlab_code_of_conduct_url: source_blob_url(gitlab_url, "CODE_OF_CONDUCT.md"), gitlab_compare_url: "#{gitlab_url}/-/compare", gitlab_tags_url: "#{gitlab_url}/-/tags", codeberg_repository_url: codeberg_url, codeberg_package_source_url: codeberg_package_source_url, codeberg_issues_url: "#{codeberg_url}/issues", codeberg_pulls_url: "#{codeberg_url}/pulls", codecov_url: "https://codecov.io/gh/#{repo_slug}", codecov_badge_url: "https://codecov.io/gh/#{repo_slug}/graph/badge.svg", codecov_graph_url: "https://codecov.io/gh/#{repo_slug}/graph/badge.svg", coveralls_url: "https://coveralls.io/github/#{repo_slug}?branch=main", coveralls_badge_url: "https://coveralls.io/repos/github/#{repo_slug}/badge.svg?branch=main", qlty_project_url: "https://qlty.sh/gh/#{github_org}/projects/#{repo_name}", qlty_maintainability_url: "https://qlty.sh/gh/#{github_org}/projects/#{repo_name}/maintainability.svg", qlty_coverage_url: "https://qlty.sh/gh/#{github_org}/projects/#{repo_name}/metrics/code?sort=coverageRating", qlty_coverage_badge_url: "https://qlty.sh/gh/#{github_org}/projects/#{repo_name}/coverage.svg", checksums_url: checksums_url } end |
.repository_root_url(source_url) ⇒ Object
16732 16733 16734 16735 16736 16737 16738 16739 16740 16741 16742 |
# File 'lib/kettle/jem.rb', line 16732 def repository_root_url(source_url) uri = URI.parse(source_url.to_s) return source_url.to_s unless uri.host == "github.com" segments = uri.path.to_s.split("/").reject(&:empty?) return source_url.to_s if segments.length < 2 "#{uri.scheme}://#{uri.host}/#{segments[0]}/#{segments[1].delete_suffix(".git")}" rescue URI::InvalidURIError source_url.to_s end |
.repository_topology_for(config, env, template_selection) ⇒ Object
13245 13246 13247 13248 13249 13250 13251 13252 |
# File 'lib/kettle/jem.rb', line 13245 def repository_topology_for(config, env, template_selection) repository_config = config["repository"].is_a?(Hash) ? config["repository"] : {} topology = preferred_template_token_value(nil, repository_config["topology"], env, "KJ_REPOSITORY_TOPOLOGY") normalized = normalize_repository_topology(topology) return normalized unless normalized.empty? monorepo_subgem_template_profile_value?(template_selection[:template_profile]) ? REPOSITORY_TOPOLOGY_MONOREPO_SUBPROJECT : REPOSITORY_TOPOLOGY_STANDALONE end |
.required_ruby_version_rubocop_disable(min_ruby) ⇒ Object
10881 10882 10883 10884 10885 10886 10887 |
# File 'lib/kettle/jem.rb', line 10881 def required_ruby_version_rubocop_disable(min_ruby) return "" unless Gem::Version.new(min_ruby) < Gem::Version.new("2.0") " # rubocop:disable Gemspec/RequiredRubyVersion" rescue ArgumentError "" end |
.resolve_template_tokens(content, tokens, scan_unresolved: true) ⇒ Object
17757 17758 17759 17760 17761 17762 17763 17764 17765 17766 17767 |
# File 'lib/kettle/jem.rb', line 17757 def resolve_template_tokens(content, tokens, scan_unresolved: true) resolver = Token::Resolver::Resolve.new(on_missing: :keep) document = Token::Resolver::Document.new(content.to_s, config: TEMPLATE_TOKEN_CONFIG) resolved = resolver.resolve(document, stringify_template_tokens(tokens)) return resolved unless scan_unresolved unresolved = Token::Resolver::Document.new(resolved, config: TEMPLATE_TOKEN_CONFIG).token_keys.grep(/\AKJ\|/).sort return resolved if unresolved.empty? raise ArgumentError, "unresolved kettle-jem template tokens: #{unresolved.map { |token| "{#{token}}" }.join(", ")}" end |
.resolve_uncommitted_author!(project_root, author_map) ⇒ Object
14891 14892 14893 14894 14895 14896 14897 14898 14899 14900 14901 14902 14903 |
# File 'lib/kettle/jem.rb', line 14891 def (project_root, ) uncommitted = .delete(NOT_COMMITTED_EMAIL) return unless uncommitted && !uncommitted[:years].empty? name = git_capture(project_root, "config", "user.name").strip email = git_capture(project_root, "config", "user.email").strip return if email.empty? [email][:name] ||= name [email][:years].concat(uncommitted[:years]) rescue ArgumentError nil end |
.resolved_licenses(config, gemspec_licenses) ⇒ Object
17471 17472 17473 17474 17475 17476 17477 17478 |
# File 'lib/kettle/jem.rb', line 17471 def resolved_licenses(config, gemspec_licenses) config_licenses = config.is_a?(Hash) ? config["licenses"] : nil licenses = Array(config_licenses).map { |license| license.to_s.strip }.reject(&:empty?) return licenses unless licenses.empty? licenses = Array(gemspec_licenses).map { |license| license.to_s.strip }.reject(&:empty?) licenses.empty? ? ["MIT"] : licenses end |
.retired_gemspec_development_dependency_key?(key) ⇒ Boolean
12130 12131 12132 12133 |
# File 'lib/kettle/jem.rb', line 12130 def retired_gemspec_development_dependency_key?(key) key.first == "add_development_dependency" && RETIRED_GEMSPEC_DEVELOPMENT_DEPENDENCIES.include?(key.last) end |
.rewrite_gemspec_version_loader(content, facts:) ⇒ Object
10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 |
# File 'lib/kettle/jem.rb', line 10659 def rewrite_gemspec_version_loader(content, facts:) return content if shim_template_profile?(facts) min_ruby = gemspec_runtime_floor_token(facts) return content if min_ruby.to_s.empty? namespace = facts.to_h.dig(:rubygems, :namespace).to_s entrypoint_require = facts.to_h.dig(:rubygems, :entrypoint_require).to_s entrypoint_require = facts.to_h.dig(:package, :name).to_s.tr("-", "/") if entrypoint_require.empty? return content if namespace.empty? || entrypoint_require.empty? receiver = gemspec_block_param(content) || "spec" min_ruby_version = Gem::Version.new(min_ruby) modern = min_ruby_version >= MODERN_GEMSPEC_VERSION_LOADER_MIN_RUBY rhs = modern ? gemspec_modern_version_loader_expression(entrypoint_require: entrypoint_require, namespace: namespace) : "gem_version" rewritten = replace_gemspec_version_assignment(content, receiver: receiver, rhs: rhs) if modern remove_gemspec_legacy_version_loader_preamble(rewritten) else ensure_gemspec_legacy_version_loader_preamble( rewritten, entrypoint_require: entrypoint_require, namespace: namespace, min_ruby: min_ruby_version, superclass_sensitive: gemspec_version_loader_superclass_sensitive?(facts), fallback_version: facts.to_h.dig(:project_runtime, :version) ) end rescue ArgumentError, Ast::Crispr::Error content end |
.rewrite_markdown_reference_links(content, links) ⇒ Object
7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 |
# File 'lib/kettle/jem.rb', line 7697 def rewrite_markdown_reference_links(content, links) ensure_runtime_dependencies! context = Ast::Crispr::Markdown::Markly.document_context(content: content, source_label: "README.md") context.structural_owners(owner_scope: :link_definitions).reduce(content.to_s) do |processed, owner| replacement = links[owner.url.to_s] next processed unless replacement replace_markdown_with_ast_crispr( processed, Ast::Crispr::Markdown::Markly::Selectors.link_definition(label: owner.label, limit: {exactly: 1}), markdown_link_definition_source(owner, replacement) ) end end |
.rubocop_target_ruby_token(min_ruby) ⇒ Object
17383 17384 17385 17386 17387 17388 17389 17390 17391 |
# File 'lib/kettle/jem.rb', line 17383 def rubocop_target_ruby_token(min_ruby) token = minimum_ruby_token(min_ruby) return "0" if token == "0" segments = Gem::Version.new(token).segments segments.first(2).join(".") rescue ArgumentError "" end |
.rubocop_template_tokens(min_ruby, ruby_style: {}) ⇒ Object
17268 17269 17270 17271 17272 17273 17274 17275 17276 17277 17278 |
# File 'lib/kettle/jem.rb', line 17268 def rubocop_template_tokens(min_ruby, ruby_style: {}) constraint, gem_name, gem_constraint = rubocop_tokens_for(min_ruby_version(min_ruby)) { "KJ|RUBOCOP_TARGET_RUBY" => rubocop_target_ruby_token(min_ruby), "KJ|RUBOCOP_LTS_CONSTRAINT" => constraint, "KJ|RUBOCOP_RUBY_GEM" => gem_name, "KJ|RUBOCOP_RUBY_CONSTRAINT" => gem_constraint }.merge( ruby_style_template_tokens(ruby_style) ) end |
.rubocop_tokens_for(min_ruby) ⇒ Object
17393 17394 17395 |
# File 'lib/kettle/jem.rb', line 17393 def rubocop_tokens_for(min_ruby) Kettle::Rb::CompatMatrix.rubocop_template_tokens(min_ruby) end |
.ruby_appraisal_name_version(name) ⇒ Object
10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 |
# File 'lib/kettle/jem.rb', line 10523 def ruby_appraisal_name_version(name) text = name.to_s return unless text.start_with?("ruby-") major, minor, extra = text.delete_prefix("ruby-").split("-", -1) return if extra || major.to_s.empty? || minor.to_s.empty? return unless [major, minor].all? { |part| part.each_char.all? { |char| char.between?("0", "9") } } Gem::Version.new("#{major}.#{minor}") end |
.ruby_appraisal_names_below(content, min_ruby) ⇒ Object
7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 |
# File 'lib/kettle/jem.rb', line 7045 def ruby_appraisal_names_below(content, min_ruby) return [] if min_ruby.to_s.empty? minimum = Gem::Version.new(min_ruby.to_s) appraisal_names(content).select do |name| version = ruby_appraisal_name_version(name) version && version < minimum end rescue ArgumentError [] end |
.ruby_array_literal(values) ⇒ Object
14801 14802 14803 |
# File 'lib/kettle/jem.rb', line 14801 def ruby_array_literal(values) "[#{Array(values).map { |value| %("#{ruby_double_quoted_string_body(value.to_s)}") }.join(", ")}]" end |
.ruby_bucket_path_segment?(segment) ⇒ Boolean
10118 10119 10120 10121 10122 10123 10124 10125 |
# File 'lib/kettle/jem.rb', line 10118 def ruby_bucket_path_segment?(segment) return false unless segment.to_s.start_with?("r") version = segment.to_s[1..].to_s return false if version.empty? version.split(".", -1).all? { |part| !part.empty? && part.each_char.all? { |char| char.between?("0", "9") } } end |
.ruby_call_records(content, call_name) ⇒ Object
9821 9822 9823 9824 9825 9826 9827 9828 |
# File 'lib/kettle/jem.rb', line 9821 def ruby_call_records(content, call_name) result = prism_parse_success(content) return [] unless result result.value.breadth_first_search_all do |node| node.is_a?(::Prism::CallNode) && (call_name.nil? || node.name == call_name) end end |
.ruby_constant_path_segments(node) ⇒ Object
16545 16546 16547 |
# File 'lib/kettle/jem.rb', line 16545 def ruby_constant_path_segments(node) node&.slice.to_s.split("::").reject(&:empty?) end |
.ruby_double_quoted_string_body(value) ⇒ Object
13185 13186 13187 |
# File 'lib/kettle/jem.rb', line 13185 def ruby_double_quoted_string_body(value) value.to_s.gsub("\\", "\\\\\\").gsub('"', '\"') end |
.ruby_engines_config(config) ⇒ Object
13463 13464 13465 13466 13467 13468 |
# File 'lib/kettle/jem.rb', line 13463 def ruby_engines_config(config) engines = config["engines"] return unless engines.is_a?(Array) engines.map { |engine| engine.to_s.strip.downcase }.reject(&:empty?).uniq end |
.ruby_entrypoint_module_namespace(content, expected_depth: nil) ⇒ Object
16569 16570 16571 16572 16573 16574 16575 16576 |
# File 'lib/kettle/jem.rb', line 16569 def ruby_entrypoint_module_namespace(content, expected_depth: nil) body = prism_parse_success(content)&.value&.statements&.body || [] body.each do |node| namespace = ruby_entrypoint_module_namespace_for(node, [], expected_depth: expected_depth) return namespace if namespace end nil end |
.ruby_entrypoint_module_namespace_for(node, namespace, expected_depth: nil) ⇒ Object
16578 16579 16580 16581 16582 16583 16584 16585 16586 16587 16588 16589 16590 |
# File 'lib/kettle/jem.rb', line 16578 def ruby_entrypoint_module_namespace_for(node, namespace, expected_depth: nil) return unless node.is_a?(::Prism::ModuleNode) || node.is_a?(::Prism::ClassNode) current = namespace + ruby_constant_path_segments(node.constant_path) return current.join("::") if expected_depth && current.length == expected_depth return if expected_depth && current.length > expected_depth node.body&.body&.each do |child| child_namespace = ruby_entrypoint_module_namespace_for(child, current, expected_depth: expected_depth) return child_namespace if child_namespace end current.join("::") unless expected_depth || current.empty? end |
.ruby_entrypoint_outer_namespace_kind(content, namespace) ⇒ Object
16325 16326 16327 16328 16329 16330 16331 16332 16333 16334 16335 |
# File 'lib/kettle/jem.rb', line 16325 def ruby_entrypoint_outer_namespace_kind(content, namespace) first_segment = namespace.to_s.split("::").reject(&:empty?).first return :module if first_segment.to_s.empty? body = prism_parse_success(content)&.value&.statements&.body || [] declaration = body.find do |node| (node.is_a?(::Prism::ClassNode) || node.is_a?(::Prism::ModuleNode)) && ruby_constant_path_segments(node.constant_path).first == first_segment end declaration.is_a?(::Prism::ClassNode) ? :class : :module end |
.ruby_first_simple_quoted_string_node(node) ⇒ Object
12192 12193 12194 12195 12196 12197 12198 12199 12200 12201 12202 12203 12204 12205 |
# File 'lib/kettle/jem.rb', line 12192 def ruby_first_simple_quoted_string_node(node) case node when ::Prism::StringNode node if ruby_simple_quoted_string_node?(node) when ::Prism::InterpolatedStringNode node.compact_child_nodes.each do |child| string_node = ruby_first_simple_quoted_string_node(child) return string_node if string_node end nil when ::Prism::CallNode ruby_first_simple_quoted_string_node(node.receiver) end end |
.ruby_first_string_argument(owner) ⇒ Object
16226 16227 16228 16229 |
# File 'lib/kettle/jem.rb', line 16226 def ruby_first_string_argument(owner) argument = owner.arguments&.arguments&.first argument.respond_to?(:unescaped) ? argument.unescaped : nil end |
.ruby_keyword_argument_node(call, key) ⇒ Object
7033 7034 7035 7036 7037 7038 7039 |
# File 'lib/kettle/jem.rb', line 7033 def ruby_keyword_argument_node(call, key) keyword_hash = Array(call&.arguments&.arguments).find { |argument| argument.is_a?(::Prism::KeywordHashNode) } assoc = keyword_hash&.elements&.find do |element| element.respond_to?(:key) && element.key.respond_to?(:unescaped) && element.key.unescaped == key.to_s end assoc&.value end |
.ruby_keyword_string_argument(call, key) ⇒ Object
9892 9893 9894 9895 9896 9897 9898 9899 |
# File 'lib/kettle/jem.rb', line 9892 def ruby_keyword_string_argument(call, key) keyword_hash = Array(call&.arguments&.arguments).find { |argument| argument.is_a?(::Prism::KeywordHashNode) } assoc = keyword_hash&.elements&.find do |element| element.respond_to?(:key) && element.key.respond_to?(:unescaped) && element.key.unescaped == key.to_s end value = assoc&.value ruby_static_string_value(value) end |
.ruby_library_source_paths(project_root) ⇒ Object
16450 16451 16452 16453 16454 16455 16456 16457 |
# File 'lib/kettle/jem.rb', line 16450 def ruby_library_source_paths(project_root) Dir.glob(File.join(project_root, "lib", "**", "*.rb")).sort.filter_map do |path| relative_path = Pathname(path).relative_path_from(Pathname(project_root)).to_s next if relative_path.end_with?("/version.rb", "/version_gem.rb") relative_path end end |
.ruby_local_word_array_assignments(root) ⇒ Object
7012 7013 7014 7015 7016 7017 7018 |
# File 'lib/kettle/jem.rb', line 7012 def ruby_local_word_array_assignments(root) root.breadth_first_search_all do |node| node.is_a?(::Prism::LocalVariableWriteNode) && ruby_word_array_node?(node.value) end.to_h do |node| [node.name.to_s, ruby_word_array_names(node.value)] end end |
.ruby_merge_options(recipe, merge_template_requires:) ⇒ Object
9287 9288 9289 9290 9291 9292 9293 9294 |
# File 'lib/kettle/jem.rb', line 9287 def (recipe, merge_template_requires:) = {merge_template_requires: merge_template_requires} parameters = Ruby::Merge.method(:merge_ruby).parameters if parameters.include?([:key, :method_move_policy]) || parameters.any? { |kind, _name| kind == :keyrest } [:method_move_policy] = ruby_method_move_policy(recipe) end end |
.ruby_method_move_policy(recipe) ⇒ Object
9262 9263 9264 9265 |
# File 'lib/kettle/jem.rb', line 9262 def ruby_method_move_policy(recipe) recipe.dig(:template_preference, :method_move_policy) || (Ruby::Merge.const_defined?(:DEFAULT_METHOD_MOVE_POLICY) ? Ruby::Merge::DEFAULT_METHOD_MOVE_POLICY : DEFAULT_RUBY_METHOD_MOVE_POLICY) end |
.ruby_multiline_word_array_source(names, indent:) ⇒ Object
10007 10008 10009 10010 10011 |
# File 'lib/kettle/jem.rb', line 10007 def ruby_multiline_word_array_source(names, indent:) element_prefix = " " * (indent.to_i + 2) closing_prefix = " " * indent.to_i (["%w["] + names.map { |name| "#{element_prefix}#{name}" } + ["#{closing_prefix}]"]).join("\n") end |
.ruby_namespace_declaration_kind(content, namespace) ⇒ Object
16459 16460 16461 16462 16463 16464 16465 16466 16467 |
# File 'lib/kettle/jem.rb', line 16459 def ruby_namespace_declaration_kind(content, namespace) target = namespace.to_s.split("::").reject(&:empty?) body = prism_parse_success(content)&.value&.statements&.body || [] body.each do |node| kind = ruby_namespace_declaration_kind_for(node, [], target) return kind if kind end nil end |
.ruby_namespace_declaration_kind_for(node, namespace, target) ⇒ Object
16469 16470 16471 16472 16473 16474 16475 16476 16477 16478 16479 16480 |
# File 'lib/kettle/jem.rb', line 16469 def ruby_namespace_declaration_kind_for(node, namespace, target) return unless node.is_a?(::Prism::ModuleNode) || node.is_a?(::Prism::ClassNode) current = namespace + ruby_constant_path_segments(node.constant_path) return (node.is_a?(::Prism::ClassNode) ? :class : :module) if current == target node.body&.body&.each do |child| kind = ruby_namespace_declaration_kind_for(child, current, target) return kind if kind end nil end |
.ruby_namespace_declaration_node(content, namespace) ⇒ Object
16482 16483 16484 16485 16486 16487 16488 16489 16490 |
# File 'lib/kettle/jem.rb', line 16482 def ruby_namespace_declaration_node(content, namespace) target = namespace.to_s.split("::").reject(&:empty?) body = prism_parse_success(content)&.value&.statements&.body || [] body.each do |node| found = ruby_namespace_declaration_node_for(node, [], target) return found if found end nil end |
.ruby_namespace_declaration_node_for(node, namespace, target) ⇒ Object
16492 16493 16494 16495 16496 16497 16498 16499 16500 16501 16502 16503 |
# File 'lib/kettle/jem.rb', line 16492 def ruby_namespace_declaration_node_for(node, namespace, target) return unless node.is_a?(::Prism::ModuleNode) || node.is_a?(::Prism::ClassNode) current = namespace + ruby_constant_path_segments(node.constant_path) return node if current == target node.body&.body&.each do |child| found = ruby_namespace_declaration_node_for(child, current, target) return found if found end nil end |
.ruby_node_source_end_line(node) ⇒ Object
9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 |
# File 'lib/kettle/jem.rb', line 9830 def ruby_node_source_end_line(node) return 0 unless node lines = [node.location&.end_line] lines << node.closing_loc&.start_line if node.respond_to?(:closing_loc) node.compact_child_nodes.each do |child| lines << ruby_node_source_end_line(child) end lines.compact.max.to_i end |
.ruby_parse_comments(analysis) ⇒ Object
16205 16206 16207 16208 16209 16210 |
# File 'lib/kettle/jem.rb', line 16205 def ruby_parse_comments(analysis) return analysis.comments if analysis.respond_to?(:comments) return analysis.parse_result.comments if analysis.respond_to?(:parse_result) && analysis.parse_result.respond_to?(:comments) [] end |
.ruby_project_version_constant_path?(node, namespace:) ⇒ Boolean
11898 11899 11900 11901 11902 11903 11904 11905 |
# File 'lib/kettle/jem.rb', line 11898 def ruby_project_version_constant_path?(node, namespace:) return false unless node.is_a?(::Prism::ConstantPathNode) segments = ruby_constant_path_segments(node) namespace_segments = namespace.to_s.split("::").reject(&:empty?) segments == namespace_segments + ["VERSION"] || segments == namespace_segments + ["Version", "VERSION"] end |
.ruby_project_version_embedded_statements?(node, namespace:) ⇒ Boolean
11891 11892 11893 11894 11895 11896 |
# File 'lib/kettle/jem.rb', line 11891 def (node, namespace:) body = node.statements&.body.to_a return false unless body.length == 1 ruby_project_version_constant_path?(body.first, namespace: namespace) end |
.ruby_project_version_interpolated_string_source(node, receiver:, namespace:) ⇒ Object
11873 11874 11875 11876 11877 11878 11879 11880 11881 11882 11883 11884 11885 11886 11887 11888 11889 |
# File 'lib/kettle/jem.rb', line 11873 def ruby_project_version_interpolated_string_source(node, receiver:, namespace:) return unless node.is_a?(::Prism::InterpolatedStringNode) parts = node.parts.map do |part| case part when ::Prism::StringNode ruby_double_quoted_string_body(part.unescaped.to_s) when ::Prism::EmbeddedStatementsNode next unless (part, namespace: namespace) "\#{#{receiver}.version}" end end return if parts.any?(&:nil?) %("#{parts.join}") end |
.ruby_require_aliases(recipe, facts = nil) ⇒ Object
9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 |
# File 'lib/kettle/jem.rb', line 9337 def ruby_require_aliases(recipe, facts = nil) facts ||= recipe[:facts] || recipe["facts"] return [] unless facts.is_a?(Hash) package = facts[:package] || facts["package"] || {} rubygems = facts[:rubygems] || facts["rubygems"] || {} package_name = (package[:name] || package["name"]).to_s.strip entrypoint = (rubygems[:entrypoint_require] || rubygems["entrypoint_require"]).to_s.strip return [] if package_name.empty? || entrypoint.empty? || package_name == entrypoint [[package_name, entrypoint]] end |
.ruby_require_call?(owner, method_name, argument) ⇒ Boolean
16220 16221 16222 16223 16224 |
# File 'lib/kettle/jem.rb', line 16220 def ruby_require_call?(owner, method_name, argument) owner.is_a?(::Prism::CallNode) && owner.name.to_s == method_name.to_s && ruby_first_string_argument(owner).to_s == argument.to_s end |
.ruby_simple_quoted_string_node?(node) ⇒ Boolean
12207 12208 12209 12210 |
# File 'lib/kettle/jem.rb', line 12207 def ruby_simple_quoted_string_node?(node) opening = node.opening_loc&.slice opening == '"' || opening == "'" end |
.ruby_static_interpolated_string_value(node) ⇒ Object
9912 9913 9914 9915 9916 9917 |
# File 'lib/kettle/jem.rb', line 9912 def ruby_static_interpolated_string_value(node) parts = node.compact_child_nodes.map { |child| ruby_static_string_value(child) } return if parts.any?(&:nil?) parts.join end |
.ruby_static_string_array_value(node, local_word_arrays = {}) ⇒ Object
7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 |
# File 'lib/kettle/jem.rb', line 7020 def ruby_static_string_array_value(node, local_word_arrays = {}) case node when ::Prism::ArrayNode return ruby_word_array_names(node) if ruby_word_array_node?(node) node.elements.map { |element| ruby_static_string_value(element) } when ::Prism::LocalVariableReadNode local_word_arrays.fetch(node.name.to_s, []) else [] end.compact end |
.ruby_static_string_call_value(node) ⇒ Object
9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 |
# File 'lib/kettle/jem.rb', line 9919 def ruby_static_string_call_value(node) return unless node.receiver && node.arguments.nil? value = ruby_static_string_value(node.receiver) return if value.nil? case node.name when :to_s value.to_s when :strip value.strip when :lstrip value.lstrip when :rstrip value.rstrip when :chomp value.chomp when :chop value.chop end end |
.ruby_static_string_value(node) ⇒ Object
9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 |
# File 'lib/kettle/jem.rb', line 9901 def ruby_static_string_value(node) case node when ::Prism::StringNode node.unescaped when ::Prism::InterpolatedStringNode ruby_static_interpolated_string_value(node) when ::Prism::CallNode ruby_static_string_call_value(node) end end |
.ruby_string_argument(call) ⇒ Object
9877 9878 9879 |
# File 'lib/kettle/jem.rb', line 9877 def ruby_string_argument(call) ruby_string_argument_at(call, 0) end |
.ruby_string_argument_at(call, index) ⇒ Object
9881 9882 9883 9884 |
# File 'lib/kettle/jem.rb', line 9881 def ruby_string_argument_at(call, index) argument = call&.arguments&.arguments&.[](index) ruby_static_string_value(argument) end |
.ruby_string_arguments(call) ⇒ Object
9886 9887 9888 9889 9890 |
# File 'lib/kettle/jem.rb', line 9886 def ruby_string_arguments(call) Array(call&.arguments&.arguments).filter_map do |argument| ruby_static_string_value(argument) end end |
.ruby_style_facts(project_root) ⇒ Object
3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 |
# File 'lib/kettle/jem.rb', line 3157 def ruby_style_facts(project_root) config_path = File.join(project_root.to_s, ".rubocop.yml") config = if File.file?(config_path) YAML.safe_load_file(config_path, permitted_classes: [], aliases: true) || {} else {} end config = {} unless config.is_a?(Hash) dot_position = config.dig("Layout/DotPosition", "EnforcedStyle").to_s dot_position = if dot_position == "trailing" "trailing" else "leading" end { dot_position: dot_position, trailing_array_comma: config.dig("Style/TrailingCommaInArrayLiteral", "EnforcedStyleForMultiline").to_s == "comma" } rescue Psych::Exception {dot_position: "leading", trailing_array_comma: false} end |
.ruby_style_template_tokens(ruby_style) ⇒ Object
17280 17281 17282 17283 17284 17285 17286 17287 17288 17289 17290 17291 17292 17293 17294 17295 17296 17297 17298 17299 17300 17301 17302 17303 17304 |
# File 'lib/kettle/jem.rb', line 17280 def ruby_style_template_tokens(ruby_style) style = ruby_style.is_a?(Hash) ? ruby_style : {} trailing_dot = style.fetch(:dot_position, style["dot_position"]).to_s == "trailing" trailing_array_comma = style.fetch(:trailing_array_comma, style["trailing_array_comma"]) == true family_gem_dirs_enumeration = if trailing_dot <<~RUBY.chomp Dir.glob(File.join(__dir__, "gems", "*", "*.gemspec")). map { |path| File.dirname(path) }. uniq. sort_by { |path| File.basename(path) } RUBY else <<~RUBY.chomp Dir.glob(File.join(__dir__, "gems", "*", "*.gemspec")) .map { |path| File.dirname(path) } .uniq .sort_by { |path| File.basename(path) } RUBY end { "KJ|RAKE:FAMILY_GEM_DIRS_ENUMERATION" => family_gem_dirs_enumeration.lines.map { |line| " #{line}" }.join.chomp, "KJ|RUBY_STYLE:TRAILING_ARRAY_COMMA" => trailing_array_comma ? "," : "" } end |
.ruby_template_policy_report(recipe:, request:, original:, final:) ⇒ Object
6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 |
# File 'lib/kettle/jem.rb', line 6872 def ruby_template_policy_report(recipe:, request:, original:, final:) return {} unless recipe.fetch(:primitive) == "supplied_template_source_application" file_type = template_file_type(recipe) return {} unless RUBY_TEMPLATE_POLICY_FILE_TYPES.include?(file_type) template_content = request.fetch(:template_content, "") report = { policy_kind: "kettle_jem_ruby_template_policy", file_type: file_type.to_s } operations = case file_type when :gemfile gemfile_policy_operations(template_content, original, final, request) when :gemspec gemspec_policy_operations(template_content, original, final, request) when :appraisals appraisals_policy_operations(template_content, original, final, request) end report[:operations] = operations {ruby_template_policy: report} end |
.ruby_top_level_require?(content, method_name, argument) ⇒ Boolean
16212 16213 16214 16215 16216 16217 16218 |
# File 'lib/kettle/jem.rb', line 16212 def ruby_top_level_require?(content, method_name, argument) ensure_runtime_dependencies! context = Ast::Crispr::Ruby::Prism.document_context(content: content.to_s, source_label: "entrypoint.rb") context.structural_owners(owner_scope: :top_level_statements).any? do |owner| ruby_require_call?(owner, method_name, argument) end end |
.ruby_top_level_require_records(content) ⇒ Object
9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 |
# File 'lib/kettle/jem.rb', line 9805 def ruby_top_level_require_records(content) body = prism_parse_success(content)&.value&.statements&.body || [] body.filter_map do |node| next unless node.is_a?(::Prism::CallNode) && node.name == :require name = ruby_string_argument(node) next unless name { name: name, start_line: node.location.start_line, end_line: ruby_node_source_end_line(node) } end end |
.ruby_version_class_eval_namespaces(content) ⇒ Object
16559 16560 16561 16562 16563 16564 16565 16566 16567 |
# File 'lib/kettle/jem.rb', line 16559 def ruby_version_class_eval_namespaces(content) ruby_call_records(content, :class_eval).filter_map do |call| receiver = call.receiver&.slice.to_s next unless receiver.end_with?("::Version") next unless call.block receiver.delete_suffix("::Version") end end |
.ruby_version_constant_value(content) ⇒ Object
16505 16506 16507 16508 16509 16510 16511 16512 16513 16514 16515 |
# File 'lib/kettle/jem.rb', line 16505 def ruby_version_constant_value(content) result = prism_parse_success(content) return unless result node = result.value.breadth_first_search_all do |candidate| candidate.is_a?(::Prism::ConstantWriteNode) && candidate.name == :VERSION && candidate.value.is_a?(::Prism::StringNode) end.first node&.value&.unescaped end |
.ruby_version_module_namespace(content) ⇒ Object
16517 16518 16519 16520 16521 16522 16523 16524 |
# File 'lib/kettle/jem.rb', line 16517 def ruby_version_module_namespace(content) body = prism_parse_success(content)&.value&.statements&.body || [] body.each do |node| namespace = ruby_version_module_namespace_for(node, []) return namespace if namespace end nil end |
.ruby_version_module_namespace_for(node, namespace) ⇒ Object
16526 16527 16528 16529 16530 16531 16532 16533 16534 16535 16536 16537 16538 16539 16540 16541 16542 16543 |
# File 'lib/kettle/jem.rb', line 16526 def ruby_version_module_namespace_for(node, namespace) return unless node.is_a?(::Prism::ModuleNode) || node.is_a?(::Prism::ClassNode) current = namespace + ruby_constant_path_segments(node.constant_path) if current.last == "Version" && current.length > 1 return current[0...-1].join("::") end if node.body&.body&.any? { |child| child.is_a?(::Prism::ConstantWriteNode) && child.name == :VERSION } return current.join("::") end node.body&.body&.each do |child| child_namespace = ruby_version_module_namespace_for(child, current) return child_namespace if child_namespace end nil end |
.ruby_word_array_names(node) ⇒ Object
10001 10002 10003 10004 10005 |
# File 'lib/kettle/jem.rb', line 10001 def ruby_word_array_names(node) node.elements.filter_map do |element| element.unescaped if element.is_a?(::Prism::StringNode) end end |
.ruby_word_array_node?(node) ⇒ Boolean
9997 9998 9999 |
# File 'lib/kettle/jem.rb', line 9997 def ruby_word_array_node?(node) node.is_a?(::Prism::ArrayNode) && node.opening_loc&.slice.to_s.start_with?("%w[") end |
.ruby_word_array_nodes(content) ⇒ Object
9988 9989 9990 9991 9992 9993 9994 9995 |
# File 'lib/kettle/jem.rb', line 9988 def ruby_word_array_nodes(content) result = prism_parse_success(content) return [] unless result result.value.breadth_first_search_all do |node| ruby_word_array_node?(node) end end |
.ruby_word_array_records(content) ⇒ Object
9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 |
# File 'lib/kettle/jem.rb', line 9972 def ruby_word_array_records(content) lines = content.to_s.lines ruby_word_array_nodes(content).map do |node| source_line = lines.fetch(node.location.start_line - 1) { names: ruby_word_array_names(node), source: node.location.slice, start_line: node.location.start_line, end_line: node.location.end_line, line_indent: source_line.length - source_line.lstrip.length, start_offset: node.location.start_offset, end_offset: node.location.end_offset } end end |
.rubyforum_badge_image_url(style: "flat") ⇒ Object
14438 14439 14440 |
# File 'lib/kettle/jem.rb', line 14438 def rubyforum_badge_image_url(style: "flat") "https://img.shields.io/discourse/topics?server=https%3A%2F%2Fwww.rubyforum.org&style=#{style}&logo=discourse&label=Ruby%20Users%20Forum" end |
.rubyforum_facts(config, env, package_name:) ⇒ Object
14409 14410 14411 14412 14413 14414 14415 14416 14417 14418 14419 14420 14421 14422 14423 14424 14425 14426 14427 14428 |
# File 'lib/kettle/jem.rb', line 14409 def rubyforum_facts(config, env, package_name:) rubyforum_config = config["rubyforum"].is_a?(Hash) ? config["rubyforum"] : {} family_tag = preferred_template_token_value(nil, rubyforum_config["family_tag"], env, "KJ_RUBYFORUM_FAMILY_TAG").to_s project_tag = preferred_template_token_value(nil, rubyforum_config["project_tag"], env, "KJ_RUBYFORUM_PROJECT_TAG").to_s family_tag = normalize_rubyforum_tag(family_tag) project_tag = normalize_rubyforum_tag(project_tag) tag = project_tag.empty? ? family_tag : project_tag tag = normalize_rubyforum_tag(package_name) if tag.empty? return {} if tag.empty? url = rubyforum_tag_url(tag) { family_tag: family_tag, project_tag: project_tag, tag: tag, url: url, badge_img: rubyforum_badge_image_url, badge_img_ftb: rubyforum_badge_image_url(style: "for-the-badge") } end |
.rubyforum_tag_url(tag) ⇒ Object
14434 14435 14436 |
# File 'lib/kettle/jem.rb', line 14434 def rubyforum_tag_url(tag) "https://www.rubyforum.org/tag/#{URI.encode_www_form_component(tag.to_s)}" end |
.rubyforum_template_tokens(rubyforum) ⇒ Object
14442 14443 14444 14445 14446 14447 14448 14449 14450 14451 14452 14453 14454 |
# File 'lib/kettle/jem.rb', line 14442 def rubyforum_template_tokens(rubyforum) url = rubyforum[:url].to_s badge_img = rubyforum[:badge_img].to_s badge_img_ftb = rubyforum[:badge_img_ftb].to_s { "KJ|RUBYFORUM:TAG" => rubyforum[:tag].to_s, "KJ|RUBYFORUM:FAMILY_TAG" => rubyforum[:family_tag].to_s, "KJ|RUBYFORUM:PROJECT_TAG" => rubyforum[:project_tag].to_s, "KJ|RUBYFORUM:URL" => url, "KJ|RUBYFORUM:BADGE_IMG" => badge_img, "KJ|RUBYFORUM:BADGE_IMG_FTB" => badge_img_ftb } end |
.rubygems_version_gem_entrypoint_mode(rubygems_config) ⇒ Object
15692 15693 15694 15695 15696 15697 |
# File 'lib/kettle/jem.rb', line 15692 def rubygems_version_gem_entrypoint_mode(rubygems_config) raw = rubygems_config["version_gem_entrypoint"] nested = rubygems_config["version_gem"] raw = nested["entrypoint"] if raw.to_s.strip.empty? && nested.is_a?(Hash) normalize_version_gem_entrypoint_mode(raw) end |
.run_apply_phases(project_root, report, file_workers: 0, file_thread_workers: 0, file_stats: nil) ⇒ Object
13794 13795 13796 13797 13798 13799 13800 13801 13802 13803 13804 13805 13806 13807 13808 13809 13810 13811 13812 13813 13814 13815 13816 13817 13818 13819 13820 13821 13822 13823 13824 13825 13826 13827 13828 13829 13830 13831 13832 13833 13834 13835 13836 13837 13838 13839 13840 13841 13842 13843 13844 13845 13846 13847 |
# File 'lib/kettle/jem.rb', line 13794 def run_apply_phases(project_root, report, file_workers: 0, file_thread_workers: 0, file_stats: nil) plugin_registry = plugin_registry_for_project(project_root) changed_files = report.fetch(:changed_files) diagnostics = report.fetch(:diagnostics) context = PluginContext.new( project_root: project_root, mode: "apply", facts: report.fetch(:facts), recipe_pack: report.fetch(:recipe_pack), recipe_reports: report.fetch(:recipe_reports), phase_reports: report.fetch(:phase_reports), changed_files: changed_files, diagnostics: diagnostics ) reports_by_phase = report.fetch(:recipe_reports).group_by { |recipe_report| recipe_report_phase(recipe_report) } active_runner_phases = report.fetch(:phase_reports).map { |phase_report| phase_report.fetch(:phase).to_sym } active_runner_phases.each do |phase| phase_report = report.fetch(:phase_reports).find { |entry| entry.fetch(:phase).to_sym == phase } phase_stats = phase_report.fetch(:stats) unless plugin_registry.empty? plugin_registry.run( timing: :before, phase: phase, context: context, actor: self, phase_stats: phase_stats ) end commit_file_work_units( file_work_units_for_phase(project_root, reports_by_phase.fetch(phase, [])), workers: file_workers, thread_workers: file_thread_workers, stats: file_stats ) unless plugin_registry.empty? plugin_registry.run( timing: :after, phase: phase, context: context, actor: self, phase_stats: phase_stats ) end end unless plugin_registry.configured_plugins.empty? diagnostics << plugin_lifecycle_diagnostic( plugin_registry, callbacks_run: true, active_runner_phases: active_runner_phases ) end changed_files.sort! report[:run_stats] = recipe_run_stats(report.fetch(:recipe_reports), diagnostics: diagnostics) end |
.runtime_context_value(request, *path) ⇒ Object
6989 6990 6991 6992 6993 6994 6995 6996 |
# File 'lib/kettle/jem.rb', line 6989 def runtime_context_value(request, *path) context = request[:runtime_context] || request["runtime_context"] || {} path.reduce(context) do |value, key| break nil unless value.respond_to?(:[]) value[key] || value[key.to_s] end end |
.runtime_gemspec_dependency_insertion_index(lines, receiver:) ⇒ Object
12077 12078 12079 12080 12081 12082 12083 12084 12085 12086 12087 |
# File 'lib/kettle/jem.rb', line 12077 def runtime_gemspec_dependency_insertion_index(lines, receiver:) note_index = lines.find_index { |line| line.lstrip.start_with?("# NOTE: It is preferable to list development dependencies") } return note_index - 1 if note_index&.positive? && lines[note_index - 1].strip.empty? return note_index if note_index development_line = gemspec_dependency_records(lines.join, receiver: receiver).find { |record| record.fetch(:kind) == "add_development_dependency" }&.fetch(:start_line) development_index = development_line && development_line - 1 return development_index if development_index gemspec_end_line(lines.join) - 1 end |
.runtime_workspace_override_records(content) ⇒ Object
8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 |
# File 'lib/kettle/jem.rb', line 8842 def runtime_workspace_override_records(content) result = prism_parse_success(content) return [] unless result conditional_nodes = result.value.breadth_first_search_all do |node| gemfile_conditional_node?(node) end templating_guard_ranges = conditional_nodes.filter_map do |node| next unless prism_subtree_contains_string?(node, "K_JEM_TEMPLATING") {start_line: node.location.start_line, end_line: node.location.end_line} end conditional_nodes.select do |node| gemfile_workspace_override_node?(node) && !node_enclosed_by_ranges?(node, templating_guard_ranges) end.map do |node| {start_line: node.location.start_line, end_line: node.location.end_line} end end |
.security_supported_version_token(version) ⇒ Object
14647 14648 14649 14650 14651 14652 14653 14654 14655 14656 |
# File 'lib/kettle/jem.rb', line 14647 def security_supported_version_token(version) parsed = Gem::Version.new(version.to_s) major = parsed.segments.fetch(0, 0).to_i return "0.latest" if major.zero? minor = parsed.segments.fetch(1, 0).to_i "#{major}.#{minor}.latest" rescue ArgumentError "0.latest" end |
.selected_template_path?(relative_path, patterns) ⇒ Boolean
13278 13279 13280 13281 13282 13283 13284 13285 13286 |
# File 'lib/kettle/jem.rb', line 13278 def selected_template_path?(relative_path, patterns) path = relative_path.to_s.delete_prefix("./") patterns.any? do |pattern| normalized = pattern.to_s.delete_prefix("./") path == normalized || File.fnmatch?(normalized, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB) || (normalized.end_with?("/**") && path.start_with?(normalized.delete_suffix("/**") + "/")) end end |
.semantic_readme_heading(text) ⇒ Object
18235 18236 18237 |
# File 'lib/kettle/jem.rb', line 18235 def semantic_readme_heading(text) normalize_readme_heading(text) end |
.set_template_file_strategy!(config, target_path, strategy) ⇒ Object
18318 18319 18320 18321 18322 18323 18324 18325 18326 |
# File 'lib/kettle/jem.rb', line 18318 def set_template_file_strategy!(config, target_path, strategy) config["files"] = {} unless config["files"].is_a?(Hash) current = config["files"] target_path.to_s.split("/").each do |part| current[part] = {} unless current[part].is_a?(Hash) current = current[part] end current["strategy"] = strategy end |
.setup_execution_context(env, run_options) ⇒ Object
13339 13340 13341 13342 13343 13344 13345 13346 13347 13348 |
# File 'lib/kettle/jem.rb', line 13339 def setup_execution_context(env, ) return {bundled: false, source: "bootstrap_mode", bundle_gemfile: nil} if DecisionPolicy.value_to_boolean(( || {})[:bootstrap_mode]) bundle_gemfile = (env || {})["BUNDLE_GEMFILE"].to_s.strip { bundled: !bundle_gemfile.empty?, source: bundle_gemfile.empty? ? "process" : "BUNDLE_GEMFILE", bundle_gemfile: bundle_gemfile.empty? ? nil : bundle_gemfile } end |
.setup_guidance_diagnostic(config_existed:) ⇒ Object
13328 13329 13330 13331 13332 13333 13334 13335 13336 13337 |
# File 'lib/kettle/jem.rb', line 13328 def setup_guidance_diagnostic(config_existed:) { severity: "advisory", message: if config_existed "Kettle/Jem setup bootstrap mode found existing #{KETTLE_CONFIG_PATH}; run kettle-jem apply to template the project." else "Created #{KETTLE_CONFIG_PATH}. Review it, then run kettle-jem --accept-config to continue setup." end } end |
.setup_project(project_root, env: ENV, run_options: {}, command_runner: nil) ⇒ Object
5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 |
# File 'lib/kettle/jem.rb', line 5787 def setup_project(project_root, env: ENV, run_options: {}, command_runner: nil) root = File.(project_root.to_s) config_path = kettle_jem_config_path(root) config_existed = File.exist?(config_path) execution_context = setup_execution_context(env, ) plan = plan_project(root, env: env, run_options: ) selection = plan.fetch(:template_selection) bootstrap_only = selection[:bootstrap_mode] || (!config_existed && !selection[:accept_config]) if bootstrap_only bootstrap_report = plan.fetch(:recipe_reports).find { |report| report.fetch(:relative_path) == KETTLE_CONFIG_PATH } apply_recipe_report(root, bootstrap_report) if bootstrap_report&.fetch(:changed, false) changed_files = bootstrap_report&.fetch(:changed, false) ? [KETTLE_CONFIG_PATH] : [] return plan.merge( mode: "setup", setup_status: config_existed ? "bootstrap_config_already_present" : "bootstrap_config_written", setup_execution_context: execution_context, ready: config_existed, changed_files: changed_files, diagnostics: plan.fetch(:diagnostics) + [setup_guidance_diagnostic(config_existed: config_existed)] ) end install_kwargs = {project_root: root, env: env, run_options: } install_kwargs[:command_runner] = command_runner if command_runner Tasks::InstallTask.run(**install_kwargs).merge( mode: "setup", setup_execution_context: execution_context, setup_status: config_existed ? "configured_project_applied" : "accepted_config_applied" ) end |
.shield_token(value) ⇒ Object
16607 16608 16609 |
# File 'lib/kettle/jem.rb', line 16607 def shield_token(value) value.to_s.gsub("-", "--").gsub("_", "__").tr(" ", "_") end |
.shim_facts(config, env, run_options, package_name:, entrypoint_require:, template_profile:) ⇒ Object
3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 |
# File 'lib/kettle/jem.rb', line 3792 def shim_facts(config, env, , package_name:, entrypoint_require:, template_profile:) shim_config = config["shim"].is_a?(Hash) ? config["shim"] : {} selection = || {} replacement_gem = selection[:shimmed_gem].to_s.strip replacement_gem = selection["shimmed_gem"].to_s.strip if replacement_gem.empty? replacement_gem = env["KETTLE_JEM_SHIMMED_GEM"].to_s.strip if replacement_gem.empty? replacement_gem = shim_config["replacement_gem"].to_s.strip if replacement_gem.empty? replacement_require = selection[:shimmed_require].to_s.strip replacement_require = selection["shimmed_require"].to_s.strip if replacement_require.empty? replacement_require = env["KETTLE_JEM_SHIMMED_REQUIRE"].to_s.strip if replacement_require.empty? replacement_require = shim_config["replacement_require"].to_s.strip if replacement_require.empty? replacement_require = replacement_gem if replacement_require.empty? replacement_git = env["KETTLE_JEM_SHIMMED_GIT"].to_s.strip replacement_git = shim_config["replacement_git"].to_s.strip if replacement_git.empty? legacy_requires = Array(shim_config["legacy_requires"]).flat_map { |entry| entry.to_s.split(",") } env_legacy_requires = env["KETTLE_JEM_SHIM_LEGACY_REQUIRES"].to_s legacy_requires.concat(env_legacy_requires.split(",")) unless env_legacy_requires.empty? legacy_requires << entrypoint_require legacy_requires = legacy_requires.map(&:strip).reject(&:empty?).uniq return {} if replacement_gem.empty? && template_profile.to_s != SHIM_TEMPLATE_PROFILE if replacement_gem.empty? raise ArgumentError, "shim template profile requires shim.replacement_gem, KETTLE_JEM_SHIMMED_GEM, or --shimmed-gem" end { replacement_gem: replacement_gem, replacement_require: replacement_require, replacement_git: replacement_git, legacy_requires: legacy_requires, primary_require: entrypoint_require.to_s, package_name: package_name.to_s, version_strategy: shim_config.dig("version", "strategy").to_s.empty? ? "shim" : shim_config.dig("version", "strategy").to_s } end |
.shim_profile_cleanups(project_root, facts, preferences, template_selection: {}) ⇒ Object
18441 18442 18443 18444 18445 18446 18447 18448 18449 18450 18451 18452 18453 18454 18455 18456 18457 18458 |
# File 'lib/kettle/jem.rb', line 18441 def shim_profile_cleanups(project_root, facts, preferences, template_selection: {}) return [] unless facts[:template_profile].to_s == SHIM_TEMPLATE_PROFILE return [] unless Array(template_selection[:only]).empty? retained_paths = preferences.map { |preference| preference.fetch(:target_path).to_s }.to_set retained_paths << KETTLE_CONFIG_PATH SHIM_PROFILE_CLEANUP_GLOBS.flat_map do |pattern| Dir.glob(File.join(project_root, pattern), File::FNM_DOTMATCH).filter_map do |path| next unless File.file?(path) relative_path = path.delete_prefix("#{project_root}/") next if retained_paths.include?(relative_path) next if relative_path.start_with?(".git/") {target_path: relative_path} end end.uniq { |cleanup| cleanup.fetch(:target_path) }.sort_by { |cleanup| cleanup.fetch(:target_path) } end |
.shim_replacement_namespace(replacement_require) ⇒ Object
14587 14588 14589 14590 14591 14592 14593 |
# File 'lib/kettle/jem.rb', line 14587 def shim_replacement_namespace(replacement_require) replacement_require.to_s.tr("-", "/").split("/").reject(&:empty?).map do |segment| SHIM_REPLACEMENT_NAMESPACE_ACRONYMS.fetch(segment) do segment.split("_").map { |part| "#{part[0].to_s.upcase}#{part[1..]}" }.join end end.join("::") end |
.shim_template_entries(facts, config) ⇒ Object
18348 18349 18350 18351 18352 18353 18354 18355 18356 18357 18358 18359 18360 18361 18362 18363 |
# File 'lib/kettle/jem.rb', line 18348 def shim_template_entries(facts, config) package_name = facts.dig(:package, :name).to_s entrypoint_require = facts.dig(:rubygems, :entrypoint_require).to_s shim = facts.fetch(:shim) targets = SHIM_TEMPLATE_STATIC_ENTRIES.map do |target| source = SHIM_TEMPLATE_SOURCE_TARGETS.fetch(target, target) {"source" => source, "target" => target} end targets << {"source" => "shim/gem.gemspec", "target" => "#{package_name}.gemspec"} targets << {"source" => "shim/lib/version.rb", "target" => File.join("lib", entrypoint_require, "version.rb")} targets << {"source" => "shim/lib/entrypoint.rb", "target" => File.join("lib", "#{entrypoint_require}.rb")} Array(shim[:legacy_requires]).map(&:to_s).reject { |path| path == entrypoint_require }.each do |require_path| targets << {"source" => "shim/lib/compat_require.rb", "target" => File.join("lib", "#{require_path}.rb")} end targets.uniq { |entry| entry.fetch("target") } end |
.shim_template_entries_for_config(gemspec_path, config) ⇒ Object
13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 13082 13083 13084 13085 13086 13087 |
# File 'lib/kettle/jem.rb', line 13071 def shim_template_entries_for_config(gemspec_path, config) package_name = config.dig("rubygems", "name").to_s.strip package_name = File.basename(gemspec_path.to_s, ".gemspec") if package_name.empty? entrypoint_require = config.dig("rubygems", "entrypoint_require").to_s.strip entrypoint_require = package_name.tr("-", "/") if entrypoint_require.empty? legacy_requires = Array(config.dig("shim", "legacy_requires")).map(&:to_s) legacy_requires << entrypoint_require shim = {legacy_requires: legacy_requires.uniq} shim_template_entries( { package: {name: package_name}, rubygems: {entrypoint_require: entrypoint_require}, shim: shim }, config ) end |
.shim_template_profile?(facts) ⇒ Boolean
13130 13131 13132 |
# File 'lib/kettle/jem.rb', line 13130 def shim_template_profile?(facts) facts[:template_profile].to_s == SHIM_TEMPLATE_PROFILE end |
.shim_template_tokens(shim) ⇒ Object
14385 14386 14387 14388 14389 14390 14391 14392 14393 |
# File 'lib/kettle/jem.rb', line 14385 def shim_template_tokens(shim) return {} unless shim.is_a?(Hash) && !shim.empty? { "KJ|SHIMMED_GEM_NAME" => shim[:replacement_gem].to_s, "KJ|SHIMMED_REQUIRE" => shim[:replacement_require].to_s, "KJ|SHIM_COMPAT_REQUIRES" => Array(shim[:legacy_requires]).join(", ") } end |
.shim_version_file_content(namespace:, replacement_namespace:, replacement_require:) ⇒ Object
14595 14596 14597 14598 14599 14600 14601 14602 14603 14604 14605 14606 14607 14608 14609 14610 |
# File 'lib/kettle/jem.rb', line 14595 def shim_version_file_content(namespace:, replacement_namespace:, replacement_require:) body = [ "# Version namespace delegated to the replacement gem.", "Version = #{replacement_namespace}::Version unless const_defined?(:Version, false)", "# Current gem version delegated to the replacement gem.", "VERSION = #{replacement_namespace}::VERSION unless const_defined?(:VERSION, false)" ] <<~RUBY # frozen_string_literal: true require #{replacement_require.to_s.dump} #{wrap_ruby_namespace(namespace, body).join("\n")} RUBY end |
.shunted_dependency_has_floor_compatible_version?(resolver, dependency, versions, floor) ⇒ Boolean
3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 |
# File 'lib/kettle/jem.rb', line 3872 def shunted_dependency_has_floor_compatible_version?(resolver, dependency, versions, floor) versions.any? do |entry| number = (entry[:number] || entry["number"]).to_s next false if number.empty? min_ruby = resolver.min_ruby_version(dependency.fetch(:name), number) || resolver.parse_min_ruby(entry[:ruby_version] || entry["ruby_version"]) min_ruby.nil? || Gem::Version.new(min_ruby.to_s) <= floor rescue false end end |
.shunted_dependency_has_modular_override?(project_root, dependency) ⇒ Boolean
3862 3863 3864 3865 3866 3867 3868 3869 3870 |
# File 'lib/kettle/jem.rb', line 3862 def shunted_dependency_has_modular_override?(project_root, dependency) root = project_root.to_s return false if root.empty? name = dependency.fetch(:name).to_s return false if name.empty? || name.include?("/") || name.include?("\\") File.directory?(File.join(root, "gemfiles", "modular", name)) end |
.shunted_effective_floor(min_ruby) ⇒ Object
3903 3904 3905 3906 3907 3908 3909 3910 |
# File 'lib/kettle/jem.rb', line 3903 def shunted_effective_floor(min_ruby) floor = minimum_ruby_token(min_ruby) versions = [Gem::Version.new("2.3")] versions << Gem::Version.new(floor) unless floor.to_s.empty? versions.max rescue ArgumentError Gem::Version.new("2.3") end |
.shunted_gemfile_block(gemspec, facts, run_options) ⇒ Object
3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 |
# File 'lib/kettle/jem.rb', line 3831 def shunted_gemfile_block(gemspec, facts, ) resolver = [:rubygems_resolver] || ["rubygems_resolver"] || RubyGemsResolver.new dependencies = extract_gemspec_development_dependencies(gemspec) return if dependencies.empty? floor = shunted_effective_floor(facts.dig(:rubygems, :min_ruby)) project_root = facts[:project_root] || facts["project_root"] || [:project_root] || ["project_root"] shunted = dependencies.filter_map do |dependency| next if shunted_dependency_has_modular_override?(project_root, dependency) versions = resolver.versions(dependency.fetch(:name), requirements: dependency[:requirement]) version = versions.max_by { |entry| Gem::Version.new((entry[:number] || entry["number"]).to_s) } next unless version number = (version[:number] || version["number"]).to_s min_ruby = resolver.min_ruby_version(dependency.fetch(:name), number) || resolver.parse_min_ruby(version[:ruby_version] || version["ruby_version"]) next unless min_ruby && Gem::Version.new(min_ruby.to_s) > floor next if shunted_dependency_has_floor_compatible_version?(resolver, dependency, versions, floor) dependency.merge(version: number, min_ruby: min_ruby.to_s) rescue nil end return if shunted.empty? shunted_gemfile_managed_block(shunted) rescue nil end |
.shunted_gemfile_managed_block(dependencies) ⇒ Object
3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 |
# File 'lib/kettle/jem.rb', line 3912 def shunted_gemfile_managed_block(dependencies) lines = [ MANAGED_BLOCK_OPEN ] if dependencies.empty? lines << "# (no shunted dependencies)" else dependencies.sort_by { |dependency| dependency.fetch(:name) }.each do |dependency| requirement = dependency[:requirement].to_s.empty? ? "" : %(, "#{dependency.fetch(:requirement)}") lines << %(gem "#{dependency.fetch(:name)}"#{requirement} # ruby >= #{dependency.fetch(:min_ruby)}) end end lines << MANAGED_BLOCK_CLOSE ensure_trailing_newline(lines.join("\n")) end |
.sibling_gemspec_metadata(sibling_path, gem_name) ⇒ Object
15088 15089 15090 15091 15092 15093 |
# File 'lib/kettle/jem.rb', line 15088 def (sibling_path, gem_name) gemspec_path = Dir.glob(File.join(sibling_path, "*.gemspec")).find do |path| ((path), :gem_name).to_s == gem_name.to_s end gemspec_path ? (gemspec_path) : {} end |
.simplecov_bootstrap_call_node?(node) ⇒ Boolean
8605 8606 8607 8608 8609 8610 |
# File 'lib/kettle/jem.rb', line 8605 def simplecov_bootstrap_call_node?(node) simplecov_require_call_node?(node) || simplecov_config_require_call_node?(node) || simplecov_kettle_soup_cover_require_call_node?(node) || simplecov_start_call_node?(node) end |
.simplecov_config_require_call_node?(node) ⇒ Boolean
8465 8466 8467 8468 8469 8470 |
# File 'lib/kettle/jem.rb', line 8465 def simplecov_config_require_call_node?(node) node.is_a?(::Prism::CallNode) && node.name == :require && node.receiver.nil? && ruby_string_argument(node) == "kettle/soup/cover/config" end |
.simplecov_config_require_call_nodes(content) ⇒ Object
8785 8786 8787 8788 8789 8790 8791 8792 |
# File 'lib/kettle/jem.rb', line 8785 def simplecov_config_require_call_nodes(content) result = prism_parse_success(content) return [] unless result result.value.breadth_first_search_all do |node| simplecov_config_require_call_node?(node) end end |
.simplecov_config_require_call_records(content) ⇒ Object
8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 |
# File 'lib/kettle/jem.rb', line 8771 def simplecov_config_require_call_records(content) lines = content.to_s.lines ruby_call_records(content, :require).filter_map do |call| next unless simplecov_config_require_call_node?(call) end_line = ruby_node_source_end_line(call) { start_line: call.location.start_line, end_line: end_line, source: (lines[(call.location.start_line - 1)..(end_line - 1)] || []).join } end.sort_by { |record| record.fetch(:start_line) } end |
.simplecov_do_cov_bootstrap_complete_node?(node) ⇒ Boolean
8684 8685 8686 8687 8688 8689 |
# File 'lib/kettle/jem.rb', line 8684 def simplecov_do_cov_bootstrap_complete_node?(node) subtree = prism_call_nodes(node) subtree.any? { |child| simplecov_require_call_node?(child) } && subtree.any? { |child| simplecov_config_require_call_node?(child) } && subtree.any? { |child| simplecov_start_call_node?(child) } end |
.simplecov_do_cov_bootstrap_only_node?(node) ⇒ Boolean
8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 |
# File 'lib/kettle/jem.rb', line 8691 def simplecov_do_cov_bootstrap_only_node?(node) calls = prism_call_nodes(node) return false if calls.empty? calls.all? do |call| simplecov_require_call_node?(call) || simplecov_config_require_call_node?(call) || simplecov_start_call_node?(call) end end |
.simplecov_do_cov_bootstrap_records(content) ⇒ Object
8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 |
# File 'lib/kettle/jem.rb', line 8652 def simplecov_do_cov_bootstrap_records(content) result = prism_parse_success(content) return [] unless result lines = content.to_s.lines result.value.breadth_first_search_all do |node| node.is_a?(::Prism::IfNode) && simplecov_do_cov_predicate_node?(node.predicate) && prism_subtree_contains_simplecov_require?(node) end.map do |node| end_line = ruby_node_source_end_line(node) source = (lines[(node.location.start_line - 1)..(end_line - 1)] || []).join { start_line: node.location.start_line, end_line: end_line, source: source, bootstrap_only: simplecov_do_cov_bootstrap_only_node?(node), complete: simplecov_do_cov_bootstrap_complete_node?(node) } end.sort_by { |record| record.fetch(:start_line) } end |
.simplecov_do_cov_predicate_node?(node) ⇒ Boolean
8674 8675 8676 |
# File 'lib/kettle/jem.rb', line 8674 def simplecov_do_cov_predicate_node?(node) node&.location&.slice.to_s == "Kettle::Soup::Cover::DO_COV" end |
.simplecov_kettle_soup_cover_require_call_node?(node) ⇒ Boolean
8472 8473 8474 8475 8476 8477 |
# File 'lib/kettle/jem.rb', line 8472 def simplecov_kettle_soup_cover_require_call_node?(node) node.is_a?(::Prism::CallNode) && node.name == :require && node.receiver.nil? && ruby_string_argument(node) == "kettle-soup-cover" end |
.simplecov_load_error_guard_call_node?(node) ⇒ Boolean
8612 8613 8614 8615 8616 8617 8618 |
# File 'lib/kettle/jem.rb', line 8612 def simplecov_load_error_guard_call_node?(node) return true if node.name == :raise return true if node.name == :message return true if node.name == :include? && ruby_string_argument(node) == "kettle" false end |
.simplecov_obsolete_call_nodes(content) ⇒ Object
8450 8451 8452 8453 8454 8455 8456 8457 |
# File 'lib/kettle/jem.rb', line 8450 def simplecov_obsolete_call_nodes(content) result = prism_parse_success(content) return [] unless result result.value.breadth_first_search_all do |node| simplecov_start_call_node?(node) || simplecov_config_require_call_node?(node) || simplecov_kettle_soup_cover_require_call_node?(node) end end |
.simplecov_require_call_node?(node) ⇒ Boolean
8750 8751 8752 8753 8754 8755 |
# File 'lib/kettle/jem.rb', line 8750 def simplecov_require_call_node?(node) node.is_a?(::Prism::CallNode) && node.name == :require && node.receiver.nil? && ruby_string_argument(node) == "simplecov" end |
.simplecov_require_call_records(content) ⇒ Object
8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 |
# File 'lib/kettle/jem.rb', line 8757 def simplecov_require_call_records(content) lines = content.to_s.lines ruby_call_records(content, :require).filter_map do |call| next unless simplecov_require_call_node?(call) end_line = ruby_node_source_end_line(call) { start_line: call.location.start_line, end_line: end_line, source: (lines[(call.location.start_line - 1)..(end_line - 1)] || []).join } end.sort_by { |record| record.fetch(:start_line) } end |
.simplecov_start_call_node?(node) ⇒ Boolean
8459 8460 8461 8462 8463 |
# File 'lib/kettle/jem.rb', line 8459 def simplecov_start_call_node?(node) node.is_a?(::Prism::CallNode) && node.name == :start && node.receiver&.slice == "SimpleCov" end |
.simplecov_start_call_nodes(content) ⇒ Object
8794 8795 8796 8797 8798 8799 8800 8801 |
# File 'lib/kettle/jem.rb', line 8794 def simplecov_start_call_nodes(content) result = prism_parse_success(content) return [] unless result result.value.breadth_first_search_all do |node| simplecov_start_call_node?(node) end end |
.skip_disabled_integration_template?(target_path, config) ⇒ Boolean
18784 18785 18786 |
# File 'lib/kettle/jem.rb', line 18784 def skip_disabled_integration_template?(target_path, config) disabled_integration_template_path?(target_path, config) end |
.skip_packaged_gemfile_template?(target_path, config, project_root: nil, template_root_path: PACKAGED_TEMPLATE_ROOT) ⇒ Boolean
18755 18756 18757 18758 18759 18760 18761 18762 18763 18764 18765 18766 18767 |
# File 'lib/kettle/jem.rb', line 18755 def skip_packaged_gemfile_template?(target_path, config, project_root: nil, template_root_path: PACKAGED_TEMPLATE_ROOT) return true if target_path.to_s.include?("gemfiles/modular/recording/") && !appraisal_recording_enabled?(config) return false if packaged_gemfile_referenced_by_x_std_libs?(target_path, project_root: project_root, template_root_path: template_root_path) version = packaged_gemfile_template_ruby_floor(target_path) return false unless version min_ruby = config_test_min_ruby(config) return false unless min_ruby Gem::Version.new(version) < min_ruby end |
.skip_packaged_license_template?(target_path, config) ⇒ Boolean
18700 18701 18702 18703 18704 18705 18706 18707 18708 |
# File 'lib/kettle/jem.rb', line 18700 def skip_packaged_license_template?(target_path, config) basename = managed_license_template_basename(target_path) return false unless basename active_basenames = active_license_basenames(config) return false if active_basenames.empty? !active_basenames.include?(basename) end |
.skip_packaged_version_gem_entrypoint_template?(project_root, source_path, target_path, config) ⇒ Boolean
18562 18563 18564 18565 18566 18567 18568 18569 18570 18571 |
# File 'lib/kettle/jem.rb', line 18562 def skip_packaged_version_gem_entrypoint_template?(project_root, source_path, target_path, config) return false unless source_path == "lib/gem/version_gem.rb" return true unless version_gem_runtime_compatible?({rubygems: {min_ruby: config.dig("rubygems", "min_ruby")}}) mode = rubygems_version_gem_entrypoint_mode(config.fetch("rubygems", {})) return true if mode == "disabled" || mode == "inline" return false if mode == "dedicated" !File.file?(File.join(project_root, target_path)) end |
.skip_packaged_workflow_template?(target_path, config, include_patterns: nil) ⇒ Boolean
18731 18732 18733 18734 18735 18736 18737 18738 18739 18740 18741 18742 18743 18744 18745 18746 18747 18748 18749 18750 18751 18752 18753 |
# File 'lib/kettle/jem.rb', line 18731 def skip_packaged_workflow_template?(target_path, config, include_patterns: nil) path = target_path.to_s return false unless path.start_with?(".github/workflows/") return true if disabled_integration_template_path?(path, config) return true if OPT_IN_GITHUB_WORKFLOWS.include?(path) && !selected_template_path?(path, Array(include_patterns)) basename = File.basename(path, ".yml") if basename == "framework-ci" matrix = github_actions_framework_matrix(config) return matrix.empty? || !matrix.fetch(:workflow, true) end min_ruby = config_test_min_ruby(config) workflow_floor = Kettle::Rb::CompatMatrix.workflow_ruby_floor(basename) return true if workflow_floor && min_ruby && Gem::Version.new(workflow_floor) < min_ruby engine = Kettle::Rb::CompatMatrix.engine_workflow(basename) return true if engine && !enabled_ruby_engines(config).include?(engine) version = basename[/\Aruby-(\d+\.\d+)\z/, 1] return false unless version && min_ruby Gem::Version.new(version) < min_ruby end |
.skywalking_eyes_disabled_by_default?(config, license, disabled) ⇒ Boolean
17931 17932 17933 17934 17935 17936 17937 |
# File 'lib/kettle/jem.rb', line 17931 def skywalking_eyes_disabled_by_default?(config, license, disabled) return false if disabled.include?(SKYWALKING_EYES_INTEGRATION) return false if explicit_integration_enabled?(config, SKYWALKING_EYES_INTEGRATION) licenses = integration_license_spdx(config, license) !license_eye_compatible_licenses?(licenses) end |
.snapshot_changed_files(project_root, changed_files) ⇒ Object
4905 4906 4907 4908 4909 4910 |
# File 'lib/kettle/jem.rb', line 4905 def snapshot_changed_files(project_root, changed_files) changed_files.to_h do |relative_path| path = File.join(project_root, relative_path) [relative_path, File.exist?(path) ? File.read(path) : nil] end end |
.social_facts(config, env) ⇒ Object
14988 14989 14990 14991 14992 14993 14994 14995 14996 14997 |
# File 'lib/kettle/jem.rb', line 14988 def (config, env) token_config = token_config_values(config) = token_config["social"].is_a?(Hash) ? token_config["social"] : {} compact_hash( mastodon: (, env, :mastodon).to_s, bluesky: (, env, :bluesky).to_s, linktree: (, env, :linktree).to_s, devto: (, env, :devto).to_s ) end |
.social_template_tokens(social) ⇒ Object
15003 15004 15005 15006 15007 15008 15009 15010 |
# File 'lib/kettle/jem.rb', line 15003 def () { "KJ|SOCIAL:MASTODON" => [:mastodon].to_s, "KJ|SOCIAL:BLUESKY" => [:bluesky].to_s, "KJ|SOCIAL:LINKTREE" => [:linktree].to_s, "KJ|SOCIAL:DEVTO" => [:devto].to_s } end |
.social_token_value(social_config, env, key) ⇒ Object
14999 15000 15001 |
# File 'lib/kettle/jem.rb', line 14999 def (, env, key) preferred_template_token_value(nil, [key.to_s], env, SOCIAL_TOKEN_ENV_KEYS.fetch(key)) end |
.sort_runtime_gemspec_dependency_lines(content, receiver:) ⇒ Object
11907 11908 11909 11910 11911 11912 11913 11914 11915 11916 11917 11918 |
# File 'lib/kettle/jem.rb', line 11907 def sort_runtime_gemspec_dependency_lines(content, receiver:) records = gemspec_dependency_records(content, receiver: receiver).select do |record| record.fetch(:kind) != "add_development_dependency" && record.fetch(:start_line) == record.fetch(:end_line) end return content if records.length < 2 sorted_sources = records.sort_by { |record| [gemspec_dependency_sort_key(record.fetch(:name)), record.fetch(:source).to_s] }.map { |record| record.fetch(:source) } records_by_line = records.sort_by { |record| record.fetch(:start_line) }.each_with_index.to_h do |record, index| [record.fetch(:start_line), record.merge(replacement: sorted_sources.fetch(index))] end replace_record_ranges(content, records_by_line) end |
.source_blob_url(source_url, path) ⇒ Object
7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 |
# File 'lib/kettle/jem.rb', line 7770 def source_blob_url(source_url, path) base = source_url.to_s.dup base = base[0...-1] while base.end_with?("/") escaped_path = path.to_s.split("/").map { |segment| segment.split(" ").join("%20") }.join("/") if base.start_with?("https://gitlab.com/", "http://gitlab.com/") "#{base}/-/blob/main/#{escaped_path}" elsif base.start_with?("https://codeberg.org/", "http://codeberg.org/") "#{base}/src/branch/main/#{escaped_path}" else "#{base}/blob/main/#{escaped_path}" end end |
.source_tree_url(source_url, path) ⇒ Object
16744 16745 16746 16747 16748 16749 16750 16751 16752 16753 16754 16755 |
# File 'lib/kettle/jem.rb', line 16744 def source_tree_url(source_url, path) base = source_url.to_s.dup base = base[0...-1] while base.end_with?("/") escaped_path = path.to_s.split("/").map { |segment| segment.split(" ").join("%20") }.join("/") if base.start_with?("https://gitlab.com/", "http://gitlab.com/") "#{base}/-/tree/main/#{escaped_path}" elsif base.start_with?("https://codeberg.org/", "http://codeberg.org/") "#{base}/src/branch/main/#{escaped_path}" else "#{base}/tree/main/#{escaped_path}" end end |
.spdx_basename(spdx_id) ⇒ Object
17588 17589 17590 |
# File 'lib/kettle/jem.rb', line 17588 def spdx_basename(spdx_id) spdx_id.to_s.sub(/\ALicenseRef-/, "") end |
.spdx_from_basename(basename) ⇒ Object
5484 5485 5486 5487 5488 |
# File 'lib/kettle/jem.rb', line 5484 def spdx_from_basename(basename) return "LicenseRef-Big-Time-Public-License" if basename.to_s == "Big-Time-Public-License" basename.to_s end |
.spec_helper_simplecov_do_cov_bootstrap_source(indent) ⇒ Object
8642 8643 8644 8645 8646 8647 8648 8649 8650 |
# File 'lib/kettle/jem.rb', line 8642 def spec_helper_simplecov_do_cov_bootstrap_source(indent) [ "#{indent}if Kettle::Soup::Cover::DO_COV\n", "#{indent} require \"simplecov\" # Loads project-local .simplecov.\n", "#{indent} require \"kettle/soup/cover/config\"\n", "#{indent} SimpleCov.start\n", "#{indent}end\n" ].join end |
.stale_executable_startup_header(ast, require_call:, namespaces:) ⇒ Object
5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 |
# File 'lib/kettle/jem.rb', line 5061 def stale_executable_startup_header(ast, require_call:, namespaces:) owners = ast.statements&.body.to_a require_index = owners.index do |owner| owner.location.start_offset == require_call.location.start_offset && owner.location.end_offset == require_call.location.end_offset end return unless require_index && require_index >= 1 assignment = owners.fetch(require_index - 1) conditional = owners.fetch(require_index + 1, nil) header = owners.drop(require_index + 2).find do |owner| owner.is_a?(::Prism::CallNode) && owner.name == :puts && owner.slice.to_s.include?("script_basename") end return unless assignment.is_a?(::Prism::LocalVariableWriteNode) && assignment.name == :script_basename return unless conditional.is_a?(::Prism::IfNode) && header namespace_segments = namespaces.filter_map do |value| segments = value.to_s.split("::").reject(&:empty?) segments unless segments.empty? end return if namespace_segments.empty? return unless executable_version_constant_nodes(conditional, namespace_segments).any? return unless executable_version_constant_nodes(header, namespace_segments).any? return unless header.slice.to_s.include?("script_basename") {assignment: assignment, require_call: require_call, conditional: conditional, header: header} end |
.stale_generated_gemspec_files_group?(group) ⇒ Boolean
11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 |
# File 'lib/kettle/jem.rb', line 11571 def stale_generated_gemspec_files_group?(group) node = group.fetch(:node) if node.is_a?(::Prism::StringNode) path = node.unescaped.to_s basename = File.basename(path, ".md") return true if %w[ CITATION.md CITATION.cff CODE_OF_CONDUCT.md CONTRIBUTING.md FUNDING.md RUBOCOP.md SECURITY.md ].include?(path) return true if stale_generated_gemspec_package_glob?(path) return true if path.end_with?(".md") && basename != "LICENSE" && known_license_template_basenames.include?(basename) return false end key = group.fetch(:key) return false unless key.is_a?(Array) && key.first == :splat stale_generated_gemspec_splat_key?(key[1]) end |
.stale_generated_gemspec_package_glob?(path) ⇒ Boolean
11607 11608 11609 11610 11611 11612 11613 11614 11615 11616 |
# File 'lib/kettle/jem.rb', line 11607 def stale_generated_gemspec_package_glob?(path) %w[ certs/**/* exe/* exe/**/* lib/**/*.rake lib/**/*.rb sig/**/*.rbs ].include?(path.to_s) end |
.stale_generated_gemspec_splat_key?(key) ⇒ Boolean
11597 11598 11599 11600 11601 11602 11603 11604 11605 |
# File 'lib/kettle/jem.rb', line 11597 def stale_generated_gemspec_splat_key?(key) return false unless key.is_a?(Array) && key.first == :call receiver, method_name, arguments = key[1], key[2], Array(key[3]) return true if receiver == "enumerate_package_files" && method_name == :call && %w[certs sig].include?(arguments.first.to_s) return true if receiver == "Dir" && method_name == :[] && arguments.first.to_s == "sig/**/*.rbs" false end |
.stale_github_workflow_template_pin_records(relative_path, final_content, destination_content) ⇒ Object
19955 19956 19957 19958 19959 19960 19961 19962 19963 19964 19965 19966 19967 19968 19969 19970 19971 19972 19973 19974 19975 19976 19977 19978 19979 19980 19981 |
# File 'lib/kettle/jem.rb', line 19955 def stale_github_workflow_template_pin_records(relative_path, final_content, destination_content) destination_records = github_workflow_action_pin_records(destination_content) final_records = github_workflow_action_pin_records(final_content) canonical_records = github_actions_step_pins.values.flat_map do |pin| github_workflow_action_pin_records("uses: #{pin}\n") end return [] if destination_records.empty? || final_records.empty? || canonical_records.empty? destination_by_key = destination_records.to_h { |record| [github_workflow_action_pin_key(record), record] } canonical_by_key = canonical_records.to_h { |record| [github_workflow_action_pin_key(record), record] } final_records.filter_map do |record| key = github_workflow_action_pin_key(record) destination = destination_by_key[key] canonical = canonical_by_key[key] next unless destination && canonical next unless destination.fetch(:sha) == record.fetch(:sha) next if canonical.fetch(:sha) == record.fetch(:sha) { path: relative_path.to_s, action: record.fetch(:action), version: record.fetch(:version), preserved_sha: record.fetch(:sha), template_sha: canonical.fetch(:sha) } end end |
.stale_main_gemfile_gem_comment?(line, gem_name) ⇒ Boolean
8136 8137 8138 8139 8140 8141 8142 |
# File 'lib/kettle/jem.rb', line 8136 def stale_main_gemfile_gem_comment?(line, gem_name) stripped = line.to_s.strip return false unless stripped.start_with?("#") return stripped.include?("TSLP") if gem_name.to_s == "tree_sitter_language_pack" false end |
.stale_main_gemfile_gem_comment_start_line(lines, start_line, gem_name) ⇒ Object
8126 8127 8128 8129 8130 8131 8132 8133 8134 |
# File 'lib/kettle/jem.rb', line 8126 def stale_main_gemfile_gem_comment_start_line(lines, start_line, gem_name) index = start_line.to_i - 2 return start_line if index.negative? previous = lines.fetch(index).to_s return index + 1 if stale_main_gemfile_gem_comment?(previous, gem_name) start_line end |
.stale_versioned_engine_workflow?(relative_path) ⇒ Boolean
13597 13598 13599 13600 13601 13602 13603 13604 13605 |
# File 'lib/kettle/jem.rb', line 13597 def stale_versioned_engine_workflow?(relative_path) return false if preferred_template_source(PACKAGED_TEMPLATE_ROOT, relative_path) basename = File.basename(relative_path.to_s, File.extname(relative_path.to_s)) basename.match?(/\Aruby-\d+\.\d+\z/) || basename.match?(/\Aruby-\d+-\d+\z/) || basename.match?(/\Ajruby-\d+\.\d+\z/) || basename.match?(/\Atruffleruby-\d+\.\d+\z/) end |
.standard_test_appraisal_names(content) ⇒ Object
10201 10202 10203 10204 10205 10206 10207 10208 10209 |
# File 'lib/kettle/jem.rb', line 10201 def standard_test_appraisal_names(content) appraisal_call_records(content).filter_map do |record| name = record.fetch(:name) next name if %w[unlocked_deps head current dep-heads coverage].include?(name) next name if ruby_appraisal_name_version(name) nil end.to_set end |
.static_gemspec_metadata_assignment(content, key) ⇒ Object
15309 15310 15311 15312 15313 15314 15315 15316 15317 15318 15319 15320 |
# File 'lib/kettle/jem.rb', line 15309 def (content, key) ruby_call_records(content, :[]=).each do |call| next unless call.receiver&.slice.to_s.end_with?(".metadata") args = call.arguments&.arguments.to_a next unless args.first.respond_to?(:unescaped) && args.first.unescaped == key return args[1].unescaped if args[1].respond_to?(:unescaped) end nil rescue Ast::Crispr::Error nil end |
.static_gemspec_metadata_key_assigned?(content, key) ⇒ Boolean
15322 15323 15324 15325 15326 15327 15328 15329 15330 15331 |
# File 'lib/kettle/jem.rb', line 15322 def (content, key) ruby_call_records(content, :[]=).any? do |call| next false unless call.receiver&.slice.to_s.end_with?(".metadata") args = call.arguments&.arguments.to_a args.first.respond_to?(:unescaped) && args.first.unescaped == key end rescue Ast::Crispr::Error false end |
.static_project_gemspec_metadata(gemspec_path) ⇒ Object
15277 15278 15279 15280 15281 15282 15283 15284 15285 15286 15287 15288 15289 15290 15291 15292 15293 15294 15295 15296 15297 15298 15299 15300 15301 15302 15303 |
# File 'lib/kettle/jem.rb', line 15277 def (gemspec_path) return {} unless gemspec_path && File.file?(gemspec_path) content = File.read(gemspec_path) assignments = gemspec_assignment_records(content) values = assignments.to_h { |record| [record.fetch(:field).to_sym, record.fetch(:value)] } name = values[:name].to_s return {} if name.empty? = { gemspec_path: gemspec_path, gem_name: name, homepage: values[:homepage].to_s, summary: values[:summary].to_s, description: values[:description].to_s, required_ruby_version: values[:required_ruby_version], min_ruby: min_ruby_version(values[:required_ruby_version]), licenses: Array(values[:licenses]), runtime_dependencies: gemspec_dependency_records(content).select { |dependency| dependency.fetch(:kind) == "add_dependency" }.map { |dependency| gemspec_dependency_from_record(dependency) }, development_dependencies: gemspec_dependency_records(content).select { |dependency| dependency.fetch(:kind) == "add_development_dependency" }.map { |dependency| gemspec_dependency_from_record(dependency) } } static_source_code_uri = (content, "source_code_uri") [:source_code_uri] = static_source_code_uri if static_source_code_uri static_homepage_uri = (content, "homepage_uri") [:homepage_uri] = static_homepage_uri if static_homepage_uri end |
.step_event_mark(step) ⇒ Object
4848 4849 4850 4851 4852 4853 |
# File 'lib/kettle/jem.rb', line 4848 def step_event_mark(step) return ">" if event_payload_value(step, :status).to_s == "started" return "F" if %w[failed blocked].include?(event_payload_value(step, :status).to_s) Array(event_payload_value(step, :changed_files) || []).empty? ? "." : "*" end |
.step_report_metadata(recipe, deletion) ⇒ Object
13373 13374 13375 13376 13377 13378 13379 13380 13381 13382 13383 13384 13385 13386 13387 13388 13389 13390 13391 13392 13393 13394 13395 13396 13397 13398 13399 13400 13401 13402 13403 13404 13405 13406 13407 13408 13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 13423 13424 13425 13426 13427 13428 13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442 13443 13444 13445 13446 13447 13448 13449 13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 |
# File 'lib/kettle/jem.rb', line 13373 def (recipe, deletion) = { target_path: recipe.fetch(:target_path), provider_family: recipe.fetch(:provider_family) } if recipe.fetch(:primitive) == "supplied_obsolete_file_deletion" .merge!( policy_kind: "delete_obsolete_file", operation: "delete", deleted_file: recipe.fetch(:target_path) ) end if recipe.fetch(:primitive) == "supplied_disabled_opencollective_file_deletion" .merge!( policy_kind: "delete_disabled_opencollective_file", operation: "delete", deleted_file: recipe.fetch(:target_path) ) end if recipe.fetch(:primitive) == "supplied_inactive_packaged_workflow_deletion" .merge!( policy_kind: "delete_inactive_packaged_workflow", operation: "delete", deleted_file: recipe.fetch(:target_path) ) end if recipe.fetch(:primitive) == "supplied_inactive_packaged_template_deletion" .merge!( policy_kind: "delete_inactive_packaged_template", operation: "delete", deleted_file: recipe.fetch(:target_path) ) end if recipe.fetch(:primitive) == "supplied_legacy_destination_file_deletion" .merge!( policy_kind: "delete_legacy_destination_file", operation: "delete", deleted_file: recipe.fetch(:target_path) ) end if recipe.fetch(:primitive) == "supplied_obsolete_license_file_deletion" .merge!( policy_kind: "delete_obsolete_license_file", operation: "delete", deleted_file: recipe.fetch(:target_path) ) end if recipe.fetch(:primitive) == "supplied_shim_profile_file_deletion" .merge!( policy_kind: "delete_shim_profile_file", operation: "delete", deleted_file: recipe.fetch(:target_path) ) end if recipe.fetch(:primitive) == "supplied_template_source_preference" .merge!( policy_kind: "select_template_source", operation: "select", template_source_preference: deep_dup(recipe.fetch(:template_preference)) ) [:template_tokens] = deep_dup(recipe[:template_tokens]) if recipe[:template_tokens] [:readme_style] = deep_dup(recipe[:readme_style]) if recipe[:readme_style] end if recipe.fetch(:primitive) == "supplied_template_source_application" .merge!( policy_kind: "apply_template_source", operation: "replace", template_source_preference: deep_dup(recipe.fetch(:template_preference)) ) [:template_tokens] = deep_dup(recipe[:template_tokens]) if recipe[:template_tokens] end if recipe.fetch(:primitive) == "supplied_kettle_config_bootstrap" .merge!( policy_kind: "bootstrap_kettle_config", operation: "create", template_source_preference: deep_dup(recipe.fetch(:template_preference)) ) [:template_tokens] = deep_dup(recipe[:template_tokens]) if recipe[:template_tokens] end return unless deletion .merge( policy_kind: "delete_supplied_structural_owners", operation: "delete", consumed_context: "delete_selectors", deleted_ranges: deletion.fetch(:delete_selectors).length, deleted_selector_ids: deletion.fetch(:delete_selectors).map { |selector| selector.fetch(:selector_id) } ) end |
.stringify_keys_for_json(value) ⇒ Object
4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 |
# File 'lib/kettle/jem.rb', line 4253 def stringify_keys_for_json(value) case value when Hash value.keys.map(&:to_s).sort.to_h do |key| raw_value = value.key?(key) ? value[key] : value[key.to_sym] [key, stringify_keys_for_json(raw_value)] end when Array value.map { |entry| stringify_keys_for_json(entry) } else value end end |
.stringify_template_tokens(tokens) ⇒ Object
18011 18012 18013 |
# File 'lib/kettle/jem.rb', line 18011 def stringify_template_tokens(tokens) tokens.to_h.transform_keys(&:to_s).transform_values(&:to_s) end |
.strip_leading_decorative_graphemes(text) ⇒ Object
13174 13175 13176 13177 13178 13179 13180 13181 13182 13183 |
# File 'lib/kettle/jem.rb', line 13174 def strip_leading_decorative_graphemes(text) remaining = text.to_s.sub(/\A\s+/, "") loop do first = first_grapheme(remaining) break unless decorative_grapheme?(first) remaining = remaining[first.length..].to_s.sub(/\A\s+/, "") end remaining end |
.strip_orphaned_rake_task_requires(content) ⇒ Object
7106 7107 7108 7109 7110 7111 7112 7113 7114 |
# File 'lib/kettle/jem.rb', line 7106 def strip_orphaned_rake_task_requires(content) remove_indexes = Set.new ruby_top_level_require_records(content).each do |record| next unless RAKEFILE_GUARDED_REQUIRE_NAMES.include?(record.fetch(:name)) (record.fetch(:start_line)..record.fetch(:end_line)).each { |line_number| remove_indexes << (line_number - 1) } end content.to_s.lines.each_with_index.reject { |_line, index| remove_indexes.include?(index) }.map(&:first).join end |
.strip_readme_heading_adornment(text) ⇒ Object
18239 18240 18241 |
# File 'lib/kettle/jem.rb', line 18239 def strip_readme_heading_adornment(text) text.to_s.sub(/\A(?:\d\uFE0F?\u20E3|[^[:alnum:][:space:]])+[ \t]*/u, "") end |
.supported_gemspec_files_nonliteral_group?(group) ⇒ Boolean
Accept only the generated package helpers that can safely survive a template revision. Other destination splats remain unsupported rather than being silently treated as template-owned package content.
11528 11529 11530 11531 11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 11544 11545 |
# File 'lib/kettle/jem.rb', line 11528 def supported_gemspec_files_nonliteral_group?(group) node = group.fetch(:node) return false unless node.is_a?(::Prism::SplatNode) expression = node.expression return true if expression.is_a?(::Prism::LocalVariableReadNode) && expression.name == :package_metadata_files return false unless expression.is_a?(::Prism::CallNode) && expression.name == :call case expression.receiver&.slice when "enumerate_package_files" argument = Array(expression.arguments&.arguments).first %w[lib exe certs sig].include?(ruby_static_string_value(argument)) when "enumerate_package_glob" generated_gemspec_package_glob_call?(expression) else false end end |
.sync_author_names_documentation_comment(content) ⇒ Object
12570 12571 12572 12573 12574 12575 12576 12577 12578 12579 12580 12581 12582 12583 12584 12585 12586 12587 12588 |
# File 'lib/kettle/jem.rb', line 12570 def (content) legacy = "# AUTHOR:NAMES <- all authors from the gemspec, or copyright holders if no gemspec authors exist" current = [ "# AUTHOR:NAMES <- existing gemspec authors plus Git-derived copyright holders\n", "# (after author_aliases consolidation)\n" ] lines = content.to_s.lines index = lines.index { |line| line.chomp == legacy } updated = if index lines[index, 1] = current lines.join else content end legacy_token_comment = "generated gemspec authors preserve the full existing authors array via AUTHOR:NAMES." current_token_comment = "AUTHOR:NAMES preserves existing gemspec authors and appends Git-derived copyright holders." updated.lines.map { |line| line.sub(legacy_token_comment, current_token_comment) }.join end |
.sync_kettle_config_documentation_comments(content) ⇒ Object
12563 12564 12565 12566 12567 12568 |
# File 'lib/kettle/jem.rb', line 12563 def sync_kettle_config_documentation_comments(content) synced = sync_readme_top_logos_documentation_comment(content) synced = remove_duplicate_framework_matrix_documentation(synced) synced = remove_duplicate_readme_preservation_documentation(synced) (synced) end |
.sync_kettle_config_env_overrides(content, env) ⇒ Object
12425 12426 12427 12428 12429 12430 12431 12432 12433 12434 12435 12436 12437 12438 |
# File 'lib/kettle/jem.rb', line 12425 def sync_kettle_config_env_overrides(content, env) synced = KETTLE_CONFIG_ENV_SYNC_PATHS.reduce(content.to_s) do |updated, (path, env_key)| value = env_sync_value(env, env_key) next updated unless present_template_token_value?(value) replace_yaml_scalar_path(updated, path, yaml_config_scalar_literal(value, path: path)) end synced = normalize_kettle_config_optional_scalars(synced) synced = sync_kettle_config_project_hostnames(synced) synced = sync_kettle_config_internal_values(synced) synced = migrate_readme_logo_config(synced) synced = prune_legacy_kettle_config_keys(synced) sync_kettle_config_documentation_comments(synced) end |
.sync_kettle_config_gemspec_strategy_lines!(lines, gemspec_path) ⇒ Object
5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 |
# File 'lib/kettle/jem.rb', line 5307 def sync_kettle_config_gemspec_strategy_lines!(lines, gemspec_path) gemspec = gemspec_path.to_s return if gemspec.empty? files_index = lines.index("files:") return unless files_index remove_stale_gemspec_file_override_blocks!(lines, files_index, gemspec) gemspec_index = lines.index(" #{gemspec}:") unless gemspec_index insertion_index = kettle_config_gemspec_override_insertion_index(lines, files_index) lines.insert(insertion_index, " #{gemspec}:", " strategy: merge") return end block_end = kettle_config_file_override_block_end(lines, gemspec_index) strategy_index = ((gemspec_index + 1)...block_end).find do |index| line = lines.fetch(index) line.start_with?(" strategy:") end if strategy_index lines[strategy_index] = " strategy: merge" else lines.insert(gemspec_index + 1, " strategy: merge") end end |
.sync_kettle_config_internal_values(content) ⇒ Object
12477 12478 12479 12480 12481 |
# File 'lib/kettle/jem.rb', line 12477 def sync_kettle_config_internal_values(content) KETTLE_CONFIG_INTERNAL_SYNC_PATHS.reduce(content.to_s) do |updated, (path, value_provider)| replace_yaml_scalar_path(updated, path, yaml_config_scalar_literal(kettle_config_internal_value(value_provider), path: path)) end end |
.sync_kettle_config_monorepo_subgem_profile(content, gemspec_path, profile) ⇒ Object
5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 |
# File 'lib/kettle/jem.rb', line 5271 def sync_kettle_config_monorepo_subgem_profile(content, gemspec_path, profile) normalized_profile = normalize_template_profile(profile) entries = monorepo_subgem_template_entries(gemspec_path, normalized_profile) lines = content.to_s.lines(chomp: true) templates_index = lines.index("templates:") return content unless templates_index profile_index = ((templates_index + 1)...lines.length).find do |index| line = lines.fetch(index) break nil if top_level_yaml_key_line?(line) line.start_with?(" profile:") end return content unless profile_index updated = lines.dup updated[profile_index] = " profile: #{normalized_profile}" entries_lines = kettle_config_template_entries_lines(entries) entries_index = ((templates_index + 1)...updated.length).find do |index| line = updated.fetch(index) break nil if top_level_yaml_key_line?(line) line == " entries:" end if entries_index entries_end = entries_index + 1 entries_end += 1 while entries_end < updated.length && updated.fetch(entries_end).start_with?(" ") updated[entries_index...entries_end] = entries_lines else updated.insert(profile_index + 1, *entries_lines) end sync_kettle_config_gemspec_strategy_lines!(updated, gemspec_path) sync_kettle_config_rakefile_strategy_lines!(updated) ensure_trailing_newline(updated.join("\n")) end |
.sync_kettle_config_project_hostnames(content) ⇒ Object
12453 12454 12455 12456 12457 12458 12459 12460 12461 12462 12463 12464 12465 12466 12467 |
# File 'lib/kettle/jem.rb', line 12453 def sync_kettle_config_project_hostnames(content) config = YAML.safe_load(content.to_s, permitted_classes: [], aliases: true) || {} yard_host = config["yard_host"].to_s homepage_uri = config["homepage_uri"].to_s normalized_yard_host = token_placeholder?(yard_host) ? yard_host : normalize_project_hostname(yard_host) normalized_homepage_uri = token_placeholder?(homepage_uri) ? homepage_uri : normalize_project_homepage_uri(homepage_uri) synced = content.to_s if !yard_host.empty? && normalized_yard_host != yard_host synced = replace_yaml_scalar_path(synced, %w[yard_host], yaml_config_scalar_literal(normalized_yard_host, path: %w[yard_host])) end if !homepage_uri.empty? && normalized_homepage_uri != homepage_uri synced = replace_yaml_scalar_path(synced, %w[homepage_uri], yaml_config_scalar_literal(normalized_homepage_uri, path: %w[homepage_uri])) end synced end |
.sync_kettle_config_rakefile_strategy_lines!(lines) ⇒ Object
5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 |
# File 'lib/kettle/jem.rb', line 5334 def sync_kettle_config_rakefile_strategy_lines!(lines) files_index = lines.index("files:") return unless files_index rakefile_index = ((files_index + 1)...lines.length).find do |index| line = lines.fetch(index) break nil if top_level_yaml_key_line?(line) line == " Rakefile:" end unless rakefile_index insertion_index = kettle_config_gemspec_override_insertion_index(lines, files_index) lines.insert(insertion_index, " Rakefile:", " strategy: accept_template") return end block_end = kettle_config_file_override_block_end(lines, rakefile_index) strategy_index = ((rakefile_index + 1)...block_end).find do |index| lines.fetch(index).start_with?(" strategy:") end if strategy_index lines[strategy_index] = " strategy: accept_template" else lines.insert(rakefile_index + 1, " strategy: accept_template") end end |
.sync_readme_top_logos_documentation_comment(content) ⇒ Object
12638 12639 12640 12641 12642 12643 12644 12645 12646 12647 12648 12649 12650 12651 12652 12653 12654 12655 12656 12657 12658 12659 12660 12661 12662 12663 12664 12665 |
# File 'lib/kettle/jem.rb', line 12638 def sync_readme_top_logos_documentation_comment(content) lines = content.to_s.lines start_index = lines.index do |line| stripped = line.strip stripped == "# README top logo mode." || stripped == "# README top logos." end return content unless start_index return content unless lines.any? { |line| line.strip.start_with?("top_logos:") } readme_index = ((start_index + 1)...lines.length).find { |index| lines[index].strip == "readme:" } return content unless readme_index replacement = [ "# README top logos.\n", "# Comma-separated list of optional logo entries for the generated README header.\n", "# top_logos render above the title; h2_synopsis_logos render inline with the Synopsis H2.\n", "# Supported values: related-org, ruby, org, project, optionally followed by |width.\n", "# Examples: org|12%, ruby|96px\n", "# Default widths: top 1 logo => 14%, top 2 logos => 12%, Synopsis 1 logo => 10%, Synopsis 2 logos => 8%.\n", "# Default (when keys are absent): top_logos: org,project; h2_synopsis_logos: related-org,ruby\n", "# Legacy top_logo_mode values map as:\n", "# org => related-org,ruby,org\n", "# project => related-org,ruby,project\n", "# org_and_project => related-org,ruby,org,project\n" ] lines[start_index...readme_index] = replacement lines.join end |
.synchronize_github_actions_ci(content, facts) ⇒ Object
19432 19433 19434 19435 19436 19437 19438 19439 19440 19441 19442 19443 19444 19445 19446 19447 19448 19449 19450 19451 19452 19453 19454 19455 19456 19457 19458 19459 19460 19461 19462 19463 19464 19465 19466 19467 19468 19469 19470 19471 19472 19473 19474 19475 19476 19477 19478 19479 19480 19481 19482 19483 19484 19485 19486 19487 19488 19489 |
# File 'lib/kettle/jem.rb', line 19432 def synchronize_github_actions_ci(content, facts) package = facts.fetch(:package) ci = facts.fetch(:ci) ruby_versions = ci.fetch(:ruby_versions) lines = [ "name: CI", "", "permissions:", " contents: read", "", "on:", " push:", " branches:", *github_actions_push_branches_yaml(content, default_branch: ci.fetch(:default_branch), indent: " ").lines(chomp: true), " tags:", " - \"!*\" # Do not execute on tags", " pull_request:", " branches:", " - \"*\"", " workflow_dispatch:", "", "concurrency:", " group: \"${{ github.workflow }}-${{ github.ref }}\"", " cancel-in-progress: true", "", "jobs:", " test:", " if: \"!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')\"", " name: Specs ${{ matrix.ruby }}", " runs-on: ubuntu-latest", " continue-on-error: ${{ endsWith(matrix.ruby, 'head') }}", " strategy:", " fail-fast: false", " matrix:", " ruby:", *ruby_versions.map { |version| " - \"#{version}\"" }, " rubygems:", " - default", " bundler:", " - default", "", " steps:", " - name: Checkout #{package.fetch(:name)}", " uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1", "", *github_actions_setup_ruby_steps(indent: " ").lines(chomp: true), "", *github_actions_rspec_status_cache_step( cache_scope: "ci", key_parts: ["${{matrix.ruby}}"], indent: " " ).lines(chomp: true), "", " - name: Tests", " run: bundle exec #{ci.fetch(:exec_cmd)}" ] "#{lines.join("\n")}\n" end |
.synchronize_github_actions_coverage_ci(content, facts) ⇒ Object
19627 19628 19629 19630 19631 19632 19633 19634 19635 19636 19637 19638 19639 19640 19641 19642 19643 19644 19645 19646 19647 19648 19649 19650 19651 19652 19653 19654 19655 19656 19657 19658 19659 19660 19661 19662 19663 19664 19665 19666 19667 19668 19669 19670 19671 19672 19673 19674 19675 19676 19677 19678 19679 19680 19681 19682 19683 19684 19685 19686 19687 19688 19689 19690 19691 19692 19693 19694 19695 19696 19697 19698 19699 19700 19701 19702 19703 19704 19705 19706 19707 19708 19709 19710 19711 19712 19713 19714 19715 19716 19717 19718 19719 |
# File 'lib/kettle/jem.rb', line 19627 def synchronize_github_actions_coverage_ci(content, facts) ci = facts.fetch(:ci) coverage = ci.fetch(:coverage) coverage_steps = github_actions_coverage_steps(disabled_integrations: facts.dig(:integrations, :disabled)) lines = [ "name: Test Coverage", "", "permissions:", " contents: read", " pull-requests: write", " id-token: write", "", "env:", " K_SOUP_COV_MIN_BRANCH: 100", " K_SOUP_COV_MIN_LINE: 100", " K_SOUP_COV_MIN_HARD: true", " K_SOUP_COV_FORMATTERS: \"xml,rcov,lcov,tty\"", " K_SOUP_COV_DO: true", " K_SOUP_COV_MULTI_FORMATTERS: true", " K_SOUP_COV_COMMAND_NAME: \"Test Coverage\"", "", "on:", " push:", " branches:", *github_actions_push_branches_yaml(content, default_branch: ci.fetch(:default_branch), indent: " ").lines(chomp: true), " tags:", " - \"!*\" # Do not execute on tags", " pull_request:", " branches:", " - \"*\"", " workflow_dispatch:", "", "concurrency:", " group: \"${{ github.workflow }}-${{ github.ref }}\"", " cancel-in-progress: true", "", "jobs:", " coverage:", " if: \"!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')\"", " name: Code Coverage on ${{ matrix.ruby }}@current", " runs-on: ubuntu-latest", " continue-on-error: ${{ matrix.experimental || endsWith(matrix.ruby, 'head') }}", " env:", " BUNDLE_GEMFILE: ${{ github.workspace }}/Appraisal.root.gemfile", " strategy:", " fail-fast: false", " matrix:", " include:", " - ruby: \"ruby\"", " appraisal: \"#{coverage.fetch(:appraisal)}\"", " exec_cmd: \"#{coverage.fetch(:command)}\"", " rubygems: latest", " bundler: latest", "", " steps:", " - name: Checkout", " uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1", "", " - name: Setup Ruby & RubyGems", " uses: appraisal-rb/setup-ruby-flash@925395edf973d2dc0a629919f407f3547a03d4b5 # v2.1", " with:", " ruby-version: \"${{ matrix.ruby }}\"", " rubygems: \"${{ matrix.rubygems }}\"", " bundler: \"${{ matrix.bundler }}\"", " bundler-cache: true", "", " - name: \"[Attempt 1] Appraisal for ${{ matrix.ruby }}@${{ matrix.appraisal }}\"", " id: bundleAppraisalAttempt1", " run: bundle exec appraisal ${{ matrix.appraisal }} install", " continue-on-error: true", "", " - name: \"[Attempt 2] Appraisal for ${{ matrix.ruby }}@${{ matrix.appraisal }}\"", " id: bundleAppraisalAttempt2", " if: ${{ steps.bundleAppraisalAttempt1.outcome == 'failure' }}", " run: bundle exec appraisal ${{ matrix.appraisal }} install", "", *github_actions_rspec_status_cache_step( cache_scope: "coverage", key_parts: ["${{matrix.ruby}}", "${{matrix.appraisal}}"], indent: " " ).lines(chomp: true), "", " - name: Tests for ${{ matrix.ruby }}@current via ${{ matrix.exec_cmd }}", " run: bundle exec appraisal ${{ matrix.appraisal }} bundle exec ${{ matrix.exec_cmd }}", "", " - name: Verify coverage reports", " run: |", " test -s coverage/lcov.info", " test -s coverage/coverage.xml", *coverage_steps.lines(chomp: true).map { |line| line.empty? ? line : " #{line}" } ] "#{lines.join("\n")}\n" end |
.synchronize_github_actions_framework_ci(content, facts) ⇒ Object
19491 19492 19493 19494 19495 19496 19497 19498 19499 19500 19501 19502 19503 19504 19505 19506 19507 19508 19509 19510 19511 19512 19513 19514 19515 19516 19517 19518 19519 19520 19521 19522 19523 19524 19525 19526 19527 19528 19529 19530 19531 19532 19533 19534 19535 19536 19537 19538 19539 19540 19541 19542 19543 19544 19545 19546 19547 19548 19549 19550 19551 19552 19553 19554 19555 19556 19557 19558 19559 19560 19561 19562 19563 19564 19565 19566 19567 19568 19569 |
# File 'lib/kettle/jem.rb', line 19491 def synchronize_github_actions_framework_ci(content, facts) ci = facts.fetch(:ci) framework_matrix = ci.fetch(:framework_matrix) dimension = framework_matrix.fetch(:dimension) label = dimension.split(/[-_]/).map { |part| part[0].to_s.upcase + part[1..].to_s }.join(" ") framework_axis = framework_matrix.fetch(:include).flat_map do |entry| [ " - framework_version: \"#{entry.fetch(:framework_version)}\"", " appraisal: \"#{entry.fetch(:appraisal)}\"" ] end lines = [ "name: #{label} CI", "", "permissions:", " contents: read", "", "on:", " push:", " branches:", *github_actions_push_branches_yaml(content, default_branch: ci.fetch(:default_branch), indent: " ").lines(chomp: true), " tags:", " - \"!*\" # Do not execute on tags", " pull_request:", " branches:", " - \"*\"", " workflow_dispatch:", "", "concurrency:", " group: \"${{ github.workflow }}-${{ github.ref }}\"", " cancel-in-progress: true", "", "jobs:", " test:", " if: \"!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')\"", " name: Specs ${{ matrix.ruby }}@${{ matrix.framework.framework_version }}", " runs-on: ubuntu-latest", " continue-on-error: ${{ endsWith(matrix.ruby, 'head') }}", " env:", " BUNDLE_GEMFILE: ${{ github.workspace }}/Appraisal.root.gemfile", " strategy:", " fail-fast: false", " matrix:", " ruby:", *ci.fetch(:ruby_versions).map { |version| " - \"#{version}\"" }, " rubygems:", " - default", " bundler:", " - default", " framework:", *framework_axis, "", " steps:", " - name: Checkout", " uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1", "", *github_actions_setup_ruby_steps(indent: " ").lines(chomp: true), "", " - name: \"[Attempt 1] Appraisal for ${{ matrix.ruby }}@${{ matrix.framework.framework_version }}\"", " id: bundleAppraisalAttempt1", " run: bundle exec appraisal ${{ matrix.framework.appraisal }} install", " continue-on-error: true", "", " - name: \"[Attempt 2] Appraisal for ${{ matrix.ruby }}@${{ matrix.framework.framework_version }}\"", " id: bundleAppraisalAttempt2", " if: ${{ steps.bundleAppraisalAttempt1.outcome == 'failure' }}", " run: bundle exec appraisal ${{ matrix.framework.appraisal }} install", "", *github_actions_rspec_status_cache_step( cache_scope: "framework-ci", key_parts: ["${{matrix.ruby}}", "${{matrix.framework.appraisal}}"], indent: " " ).lines(chomp: true), "", " - name: Tests for ${{ matrix.ruby }}@${{ matrix.framework.framework_version }}", " run: bundle exec appraisal ${{ matrix.framework.appraisal }} bundle exec #{ci.fetch(:exec_cmd)}" ] "#{lines.join("\n")}\n" end |
.synchronize_github_actions_framework_gemfile(target_path, facts) ⇒ Object
19607 19608 19609 19610 19611 19612 19613 19614 19615 19616 19617 19618 19619 19620 19621 19622 19623 19624 19625 |
# File 'lib/kettle/jem.rb', line 19607 def synchronize_github_actions_framework_gemfile(target_path, facts) gemfile = facts.dig(:ci, :framework_matrix, :gemfiles).to_a.find do |entry| entry.fetch(:path).to_s == target_path.to_s end raise ArgumentError, "missing framework matrix gemfile config for #{target_path}" unless gemfile lines = [ "# frozen_string_literal: true", "", "# Generated by kettle-jem from workflows.framework_matrix.", %(ENV["KJ_FRAMEWORK_MATRIX_GEM"] = #{gemfile.fetch(:gem).inspect}) ] gemfile.fetch(:env, {}).each do |key, value| lines << %(ENV[#{key.inspect}] = #{value.inspect}) end lines << "" lines << %(gem #{gemfile.fetch(:gem).inspect}, #{gemfile.fetch(:requirement).inspect}) "#{lines.join("\n")}\n" end |
.synchronize_github_actions_workflow_snippets(content, facts: {}) ⇒ Object
19721 19722 19723 19724 19725 19726 19727 19728 19729 19730 19731 19732 19733 19734 19735 19736 |
# File 'lib/kettle/jem.rb', line 19721 def synchronize_github_actions_workflow_snippets(content, facts: {}) updated = ensure_workflow_top_level_section( content.to_s, "permissions", "permissions:\n contents: read\n\n", before: "on" ) updated = ensure_workflow_top_level_section( updated, "concurrency", "concurrency:\n group: \"${{ github.workflow }}-${{ github.ref }}\"\n cancel-in-progress: true\n\n", before: "jobs" ) updated = append_github_actions_coverage_steps(updated, disabled_integrations: facts.dig(:integrations, :disabled)) if github_actions_coverage_enabled?(updated) update_github_actions_pins(updated) end |
.synchronize_github_funding_yml(content, facts) ⇒ Object
19244 19245 19246 19247 19248 19249 19250 19251 19252 19253 19254 19255 19256 19257 19258 19259 19260 19261 |
# File 'lib/kettle/jem.rb', line 19244 def synchronize_github_funding_yml(content, facts) output = content.to_s enabled_platforms = facts.fetch(:funding, {}).fetch(:platforms, {}) enabled_platforms = enabled_platforms.merge("open_collective" => false) if facts.fetch(:funding, {})[:open_collective_disabled] FUNDING_YML_PLATFORMS.each do |platform| next if funding_platform_enabled?(enabled_platforms, platform) output = remove_top_level_yaml_key_lines(output, platform) end tidelift_value = "rubygems/#{facts.fetch(:package).fetch(:name)}" if funding_platform_enabled?(enabled_platforms, "tidelift") && !yaml_top_level_key_lines(output).key?("tidelift") lines = output.lines lines << "\n" unless lines.empty? || lines.last.to_s.strip.empty? lines << "tidelift: #{tidelift_value}\n" output = lines.join end ensure_trailing_newline(output) end |
.synchronize_managed_block(content, facts) ⇒ Object
6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 |
# File 'lib/kettle/jem.rb', line 6684 def synchronize_managed_block(content, facts) replacement = facts.dig(:generated_blocks, :shunted_gemfile) || [ MANAGED_BLOCK_OPEN, "# package: #{facts.fetch(:package).fetch(:name)}", "# generated by kettle-jem vNext", MANAGED_BLOCK_CLOSE, "" ].join("\n") replace_ruby_managed_block(content.to_s, replacement) end |
.synchronize_readme(content, facts, project_root: nil) ⇒ Object
5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 |
# File 'lib/kettle/jem.rb', line 5994 def synchronize_readme(content, facts, project_root: nil) package = facts.fetch(:package) lines = content.to_s.split("\n", -1) heading = "# #{package.fetch(:name)}" h1_index = lines.index { |line| line.start_with?("# ") } unless h1_index lines.unshift(heading, "") end postprocess_readme_content( replace_markdown_managed_block(lines.join("\n"), "kettle-jem:metadata", (facts)), facts, project_root: project_root ) end |
.template_activation_config(config) ⇒ Object
18328 18329 18330 18331 18332 18333 |
# File 'lib/kettle/jem.rb', line 18328 def template_activation_config(config) return config["templates"] if config["templates"].is_a?(Hash) return default_template_config if generated_kettle_config_without_templates?(config) nil end |
.template_entries(project_root, root, templates) ⇒ Object
18341 18342 18343 18344 18345 18346 |
# File 'lib/kettle/jem.rb', line 18341 def template_entries(project_root, root, templates) return templates["entries"] if templates["entries"].is_a?(Array) return [] if templates.key?("entries") template_inventory_entries(project_root, root.fetch(:path), templates: templates) end |
.template_entry_apply?(entry, apply_templates) ⇒ Boolean
18862 18863 18864 18865 18866 |
# File 'lib/kettle/jem.rb', line 18862 def template_entry_apply?(entry, apply_templates) return entry["apply"] == true if entry.is_a?(Hash) && entry.key?("apply") apply_templates end |
.template_entry_paths(entry) ⇒ Object
18851 18852 18853 18854 18855 18856 18857 18858 18859 18860 |
# File 'lib/kettle/jem.rb', line 18851 def template_entry_paths(entry) if entry.is_a?(Hash) source_path = entry.fetch("source", entry["target"]).to_s target_path = entry.fetch("target", source_path.sub(/\.example\z/, "")).to_s [source_path, target_path] else source_path = entry.to_s [source_path, source_path.sub(/\.example\z/, "")] end end |
.template_file_outcomes(recipe_reports) ⇒ Object
Reduce overlays by path so post-planning outcome counts describe destination files, not individual recipes.
4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 |
# File 'lib/kettle/jem.rb', line 4036 def template_file_outcomes(recipe_reports) latest_by_path = {} unscoped_recipes = 0 recipe_reports.each do |report| path = report[:relative_path].to_s if path.empty? unscoped_recipes += 1 else latest_by_path[path] = report end end outcomes = { planned: latest_by_path.length, checksum_hits: 0, checksum_protected: 0, unchanged: 0, changed: 0, unscoped_recipes: unscoped_recipes } latest_by_path.each_value do |report| if checksum_exact_match?(report) outcomes[:checksum_hits] += 1 elsif report[:checksum_skipped] outcomes[:checksum_protected] += 1 elsif report[:changed] outcomes[:changed] += 1 else outcomes[:unchanged] += 1 end end outcomes end |
.template_file_strategy_config(config, target_path) ⇒ Object
18611 18612 18613 18614 18615 18616 18617 18618 18619 18620 18621 18622 18623 18624 18625 18626 |
# File 'lib/kettle/jem.rb', line 18611 def template_file_strategy_config(config, target_path) files = config["files"] return unless files.is_a?(Hash) current = files parts = target_path.to_s.delete_prefix("./").split("/") until parts.empty? part = parts.shift return unless current.is_a?(Hash) && current.key?(part) current = current[part] end return unless current.is_a?(Hash) && current.key?("strategy") template_strategy_entry(config, nil, current) end |
.template_file_type(recipe) ⇒ Object
12296 12297 12298 12299 12300 12301 12302 12303 12304 12305 12306 12307 12308 12309 12310 12311 12312 12313 12314 12315 12316 12317 12318 12319 12320 12321 12322 |
# File 'lib/kettle/jem.rb', line 12296 def template_file_type(recipe) configured = recipe.dig(:template_preference, :file_type).to_s return configured.to_sym unless configured.empty? relative_path = recipe.fetch(:target_path).to_s basename = File.basename(relative_path) extension = File.extname(relative_path).downcase return :gitignore if basename == ".gitignore" return :gemfile if basename == "Gemfile" || basename.end_with?(".gemfile") return :appraisals if basename.start_with?("Appraisals") || basename == "Appraisal.root.gemfile" return :gemspec if basename.end_with?(".gemspec") return :rakefile if basename == "Rakefile" || extension == ".rake" return :ruby if RUBY_TEMPLATE_BASENAMES.include?(basename) || RUBY_TEMPLATE_SUFFIXES.any? { |suffix| basename.end_with?(suffix) } || RUBY_TEMPLATE_EXTENSIONS.include?(extension) return :yaml if extension.match?(/\A\.ya?ml\z/) || File.basename(relative_path).casecmp("citation.cff").zero? return :toml if extension == ".toml" return :jsonc if relative_path == ".devcontainer/devcontainer.json" return :jsonc if extension == ".jsonc" return :json5 if extension == ".json5" return :json if extension == ".json" return :markdown if extension.match?(/\A\.md(?:own)?\z/) return :dotenv if basename.start_with?(".env") || basename.end_with?(".env") || extension == ".env" return :rbs if extension == ".rbs" :text end |
.template_file_type_for_relative_path(relative_path) ⇒ Object
4221 4222 4223 4224 4225 4226 |
# File 'lib/kettle/jem.rb', line 4221 def template_file_type_for_relative_path(relative_path) basename = File.basename(relative_path.to_s) return :appraisals if basename.start_with?("Appraisals") || basename == "Appraisal.root.gemfile" nil end |
.template_input_fingerprint(project_root, report) ⇒ Object
4153 4154 4155 |
# File 'lib/kettle/jem.rb', line 4153 def template_input_fingerprint(project_root, report) Digest::SHA256.hexdigest(JSON.generate(template_input_fingerprint_payload(project_root, report))) end |
.template_input_fingerprint_payload(project_root, report) ⇒ Object
4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 |
# File 'lib/kettle/jem.rb', line 4157 def template_input_fingerprint_payload(project_root, report) = report.fetch(:metadata, {}) preference = [:template_source_preference] || ["template_source_preference"] || {} tokens = stringify_keys_for_json([:template_tokens] || ["template_tokens"] || {}) source_path = template_source_absolute_path(project_root, preference) # This payload is the per-destination "template checksum" used by # --checksums=template. Bump the explicit renderer version only when # source-template application semantics change; unrelated Kettle-Jem # code changes must not invalidate every destination record. payload = { template_source_application_fingerprint_version: TEMPLATE_SOURCE_APPLICATION_FINGERPRINT_VERSION, recipe_name: report[:recipe_name].to_s, request_recipe_name: report.dig(:request_envelope, :request, :recipe_name).to_s, recipe_version: report.dig(:request_envelope, :request, :recipe_version).to_s, relative_path: report.fetch(:relative_path).to_s, template_source: template_source_lock_path(preference), template_source_sha256: (source_path && File.file?(source_path)) ? Digest::SHA256.file(source_path).hexdigest : "", template_source_preference: stringify_keys_for_json(preference), template_token_keys: tokens.keys.sort, template_tokens_sha256: Digest::SHA256.hexdigest(JSON.generate(tokens)) } if template_file_type_for_relative_path(report.fetch(:relative_path).to_s) == :appraisals payload[:appraisals_template_policy_fingerprint_version] = APPRAISALS_TEMPLATE_POLICY_FINGERPRINT_VERSION end if template_file_type_for_relative_path(report.fetch(:relative_path).to_s) == :gemspec payload[:gemspec_template_policy_fingerprint_version] = GEMSPEC_TEMPLATE_POLICY_FINGERPRINT_VERSION end if version_namespace_template_file?(report.fetch(:relative_path).to_s) payload[:version_namespace_template_policy_fingerprint_version] = VERSION_NAMESPACE_TEMPLATE_POLICY_FINGERPRINT_VERSION end if report.fetch(:relative_path).to_s == "spec/spec_helper.rb" payload[:spec_helper_template_policy_fingerprint_version] = SPEC_HELPER_TEMPLATE_POLICY_FINGERPRINT_VERSION end if report.fetch(:relative_path).to_s.start_with?(".github/workflows/") engine_exec_cmds = github_workflow_engine_exec_cmds_for_template( source_path, report.dig(:request_envelope, :request, :runtime_context, :ci, :engine_exec_cmds) || report.dig(:request_envelope, :request, :runtime_context, "ci", "engine_exec_cmds") || {} ) payload[:github_workflow_engine_exec_cmds] = engine_exec_cmds unless engine_exec_cmds.empty? end payload end |
.template_inventory_entries(project_root, template_root_path, templates: {}) ⇒ Object
18365 18366 18367 18368 18369 18370 18371 18372 18373 18374 18375 18376 18377 18378 18379 18380 18381 18382 18383 18384 18385 18386 18387 18388 18389 18390 18391 |
# File 'lib/kettle/jem.rb', line 18365 def template_inventory_entries(project_root, template_root_path, templates: {}) logical_paths = [] include_shim_templates = normalize_template_profile(templates["profile"]) == SHIM_TEMPLATE_PROFILE Find.find(template_root_path) do |path| next if File.directory?(path) relative_path = path.delete_prefix("#{template_root_path}/") logical_path = relative_path .sub(/\.no-osc\.example\z/, "") .sub(/\.example\z/, "") next if logical_path.start_with?("readme/partials/") next if logical_path.start_with?("shim/") && !include_shim_templates next if logical_path == "gemfiles/modular/shunted.gemfile" next if logical_path == TRANSFER_CHANGELOG_TEMPLATE_PATH logical_paths << logical_path unless logical_path.empty? end logical_paths.uniq.sort.map do |logical_path| target_path = template_inventory_target_path(project_root, logical_path) if target_path == logical_path logical_path else {"source" => logical_path, "target" => target_path} end end end |
.template_inventory_target_path(project_root, logical_path) ⇒ Object
18393 18394 18395 18396 18397 18398 18399 18400 18401 18402 18403 18404 18405 18406 18407 |
# File 'lib/kettle/jem.rb', line 18393 def template_inventory_target_path(project_root, logical_path) return ".env.local.example" if logical_path == ".env.local" if VERSION_GEM_TEMPLATE_SOURCES.include?(logical_path) existing_gemspec = Dir.glob(File.join(project_root, "*.gemspec")).min return version_gem_template_target_path_for_project(project_root, File.basename(existing_gemspec), logical_path) if existing_gemspec end if logical_path.end_with?(".gemspec") existing_gemspec = Dir.glob(File.join(project_root, "*.gemspec")).min return File.basename(existing_gemspec) if existing_gemspec end logical_path end |
.template_keep_destination_path?(config, target_path) ⇒ Boolean
19092 19093 19094 19095 |
# File 'lib/kettle/jem.rb', line 19092 def template_keep_destination_path?(config, target_path) strategy = template_file_strategy_config(config, target_path) || template_pattern_strategy_config(config, target_path) strategy.to_h.fetch(:strategy, nil) == :keep_destination end |
.template_legacy_destination_cleanups(project_root, preferences) ⇒ Object
18573 18574 18575 18576 18577 18578 18579 18580 18581 18582 18583 18584 18585 18586 |
# File 'lib/kettle/jem.rb', line 18573 def template_legacy_destination_cleanups(project_root, preferences) preferences.filter_map do |preference| canonical_path = preference.fetch(:target_path) legacy_path = LEGACY_DESTINATION_PATHS[canonical_path] next unless legacy_path next unless File.exist?(File.join(project_root, legacy_path)) next if preference[:strategy] == "keep_destination" && !File.exist?(File.join(project_root, canonical_path)) { canonical_path: canonical_path, legacy_path: legacy_path } end end |
.template_lock_state(project_root) ⇒ Object
4084 4085 4086 |
# File 'lib/kettle/jem.rb', line 4084 def template_lock_state(project_root) TemplateLock.load(project_root: project_root, config_path: kettle_jem_config_path(project_root)) end |
.template_manifest(project_root: Dir.pwd, template_root: nil, config: nil) ⇒ Object
2588 2589 2590 2591 2592 2593 2594 2595 2596 |
# File 'lib/kettle/jem.rb', line 2588 def template_manifest(project_root: Dir.pwd, template_root: nil, config: nil) root = template_root || template_root_path(project_root, config: config) { kind: "kettle_jem_template_manifest", version: 1, template_root: root, checksums: TemplateChecksums.compute(template_root: root) } end |
.template_obsolete_license_cleanups(project_root, config, preferences, license_txt: {}) ⇒ Object
18588 18589 18590 18591 18592 18593 18594 18595 18596 18597 18598 18599 18600 18601 18602 18603 18604 18605 |
# File 'lib/kettle/jem.rb', line 18588 def template_obsolete_license_cleanups(project_root, config, preferences, license_txt: {}) active_basenames = active_license_basenames(config) return [] if active_basenames.empty? retained_paths = preferences.map { |preference| preference.fetch(:target_path) }.to_set cleanups = known_license_template_basenames.filter_map do |basename| license_path = "#{basename}.md" next if active_basenames.include?(basename) next if retained_paths.include?(license_path) next unless File.exist?(File.join(project_root, license_path)) {license_path: license_path, license_basename: basename} end if license_txt[:mit] && retained_paths.include?("LICENSE.md") && File.exist?(File.join(project_root, "LICENSE.txt")) cleanups << {license_path: "LICENSE.txt", license_basename: "LICENSE"} end cleanups end |
.template_pattern_strategy_config(config, target_path) ⇒ Object
18628 18629 18630 18631 18632 18633 18634 18635 18636 18637 18638 18639 |
# File 'lib/kettle/jem.rb', line 18628 def template_pattern_strategy_config(config, target_path) patterns = config["patterns"] return unless patterns.is_a?(Array) match = patterns.find do |entry| entry.is_a?(Hash) && File.fnmatch?(entry["path"].to_s, target_path.to_s, File::FNM_PATHNAME | File::FNM_EXTGLOB | File::FNM_DOTMATCH) end return unless match template_strategy_entry(config, match["path"].to_s, match) end |
.template_root(project_root, templates) ⇒ Object
18678 18679 18680 18681 18682 18683 18684 18685 18686 18687 18688 18689 18690 18691 |
# File 'lib/kettle/jem.rb', line 18678 def template_root(project_root, templates) configured_root = templates["root"].to_s if configured_root.empty? local_root = File.join(project_root, "template") return {kind: "project", path: local_root, display_prefix: "template"} if Dir.exist?(local_root) return {kind: "packaged", path: PACKAGED_TEMPLATE_ROOT} end return {kind: "packaged", path: PACKAGED_TEMPLATE_ROOT} if configured_root == "packaged" path = configured_root.start_with?("/") ? configured_root : File.join(project_root, configured_root) {kind: "project", path: path, display_prefix: configured_root} end |
.template_root_path(project_root = Dir.pwd, config: nil) ⇒ Object
2581 2582 2583 2584 2585 2586 |
# File 'lib/kettle/jem.rb', line 2581 def template_root_path(project_root = Dir.pwd, config: nil) root = File.(project_root.to_s) resolved_config = config || kettle_jem_config(root) templates = resolved_config["templates"].is_a?(Hash) ? resolved_config["templates"] : {} template_root(root, templates).fetch(:path) end |
.template_runtime_config(config, facts, license: {}) ⇒ Object
18298 18299 18300 18301 18302 18303 18304 18305 18306 18307 18308 18309 18310 18311 18312 18313 18314 18315 18316 |
# File 'lib/kettle/jem.rb', line 18298 def template_runtime_config(config, facts, license: {}) result = deep_dup(config) result["rubygems"] = {} unless result["rubygems"].is_a?(Hash) result["rubygems"]["min_ruby"] ||= facts.dig(:rubygems, :min_ruby) result["ruby"] = {} unless result["ruby"].is_a?(Hash) result["ruby"]["test_minimum"] = config_test_min_ruby(result, facts.dig(:rubygems, :min_ruby)).to_s result["resolved_licenses"] = license[:spdx] if facts[:template_profile].to_s == SHIM_TEMPLATE_PROFILE result["templates"] = default_template_config.merge(result["templates"].is_a?(Hash) ? result["templates"] : {}) result["templates"]["profile"] = SHIM_TEMPLATE_PROFILE result["templates"]["entries"] = shim_template_entries(facts, result) result["templates"]["entries"].each do |entry| target = entry.fetch("target").to_s set_template_file_strategy!(result, target, "accept_template") end end result end |
.template_selection_for(env, run_options) ⇒ Object
13203 13204 13205 13206 13207 13208 13209 13210 13211 13212 13213 13214 13215 13216 13217 13218 13219 13220 13221 13222 13223 13224 13225 |
# File 'lib/kettle/jem.rb', line 13203 def template_selection_for(env, ) env_hash = env || {} option_hash = || {} { allowed: option_hash.fetch(:allowed, env_hash["allowed"]), hook_templates: option_hash.fetch(:hook_templates, env_hash["hook_templates"]), git_drivers: option_hash.fetch(:git_drivers, env_hash["git_drivers"] || env_hash["KETTLE_JEM_GIT_DRIVERS"]), only: normalize_list_option(option_hash.fetch(:only, env_hash["only"])), include: normalize_list_option(option_hash.fetch(:include, env_hash["include"])), template_profile: normalize_template_profile(option_hash.fetch(:template_profile, env_hash["KETTLE_JEM_TEMPLATE_PROFILE"])), shimmed_gem: option_hash.fetch(:shimmed_gem, env_hash["KETTLE_JEM_SHIMMED_GEM"]), shimmed_require: option_hash.fetch(:shimmed_require, env_hash["KETTLE_JEM_SHIMMED_REQUIRE"]), skip_commit: DecisionPolicy.value_to_boolean(option_hash.fetch(:skip_commit, env_hash["KETTLE_JEM_SKIP_COMMIT"])), skip_drift_check: DecisionPolicy.value_to_boolean(option_hash.fetch(:skip_drift_check, env_hash["KETTLE_JEM_SKIP_DRIFT_CHECK"])), skip_rubocop_gradual: DecisionPolicy.value_to_boolean(option_hash.fetch(:skip_rubocop_gradual, env_hash["KETTLE_JEM_SKIP_RUBOCOP_GRADUAL"])), skip_binstubs: DecisionPolicy.value_to_boolean(option_hash.fetch(:skip_binstubs, env_hash["KETTLE_JEM_SKIP_BINSTUBS"])), dry_run: DecisionPolicy.value_to_boolean(option_hash.fetch(:dry_run, env_hash["KETTLE_JEM_DRY_RUN"])), accept_config: DecisionPolicy.value_to_boolean(option_hash.fetch(:accept_config, env_hash["KETTLE_JEM_ACCEPT_CONFIG"])), bootstrap_mode: DecisionPolicy.value_to_boolean(option_hash.fetch(:bootstrap_mode, env_hash["KETTLE_JEM_BOOTSTRAP_MODE"])), quiet: DecisionPolicy.value_to_boolean(option_hash.fetch(:quiet, env_hash["KETTLE_JEM_QUIET"])), verbose: DecisionPolicy.value_to_boolean(option_hash.fetch(:verbose, env_hash["KETTLE_JEM_VERBOSE"])) }.compact end |
.template_source_absolute_path(project_root, preference) ⇒ Object
4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 |
# File 'lib/kettle/jem.rb', line 4228 def template_source_absolute_path(project_root, preference) return unless preference.is_a?(Hash) root = preference[:source_root_path] || preference["source_root_path"] || project_root relative = preference[:source_relative_path] || preference["source_relative_path"] || preference[:selected_source] || preference["selected_source"] return if relative.to_s.empty? File.join(root.to_s, relative.to_s) end |
.template_source_application_worker_safe?(recipe) ⇒ Boolean
4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 |
# File 'lib/kettle/jem.rb', line 4628 def template_source_application_worker_safe?(recipe) return false unless recipe.fetch(:primitive).to_s == "supplied_template_source_application" path = recipe.fetch(:target_path).to_s return false if PROJECT_ROOT_SENSITIVE_TEMPLATE_PATHS.include?(path) return false if path == KETTLE_CONFIG_PATH return false if github_workflow_template_recipe?(recipe) return true if recipe.dig(:template_preference, :strategy).to_s == "raw_copy" recipe.dig(:template_preference, :strategy).to_s == "accept_template" && RACTOR_SAFE_ACCEPT_TEMPLATE_FILE_TYPES.include?(template_file_type(recipe)) end |
.template_source_display_path(template_root, selected_source) ⇒ Object
18844 18845 18846 18847 18848 18849 |
# File 'lib/kettle/jem.rb', line 18844 def template_source_display_path(template_root, selected_source) prefix = template_root[:display_prefix].to_s return selected_source if prefix.empty? File.join(prefix, selected_source) end |
.template_source_lock_path(preference) ⇒ Object
4239 4240 4241 4242 4243 4244 |
# File 'lib/kettle/jem.rb', line 4239 def template_source_lock_path(preference) return "" unless preference.is_a?(Hash) (preference[:source_relative_path] || preference["source_relative_path"] || preference[:selected_source] || preference["selected_source"]).to_s end |
.template_source_preference(project_root, template_root, entry, config, opencollective_disabled: false, include_patterns: nil, apply_templates: false) ⇒ Object
18510 18511 18512 18513 18514 18515 18516 18517 18518 18519 18520 18521 18522 18523 18524 18525 18526 18527 18528 18529 18530 18531 18532 18533 18534 18535 18536 18537 18538 18539 18540 18541 18542 18543 18544 18545 18546 18547 18548 18549 18550 18551 18552 18553 18554 18555 18556 18557 18558 18559 18560 |
# File 'lib/kettle/jem.rb', line 18510 def template_source_preference(project_root, template_root, entry, config, opencollective_disabled: false, include_patterns: nil, apply_templates: false) source_path, target_path = template_entry_paths(entry) if template_root.fetch(:kind) == "packaged" && VERSION_GEM_TEMPLATE_SOURCES.include?(source_path) && target_path == source_path existing_gemspec = Dir.glob(File.join(project_root, "*.gemspec")).min target_path = version_gem_template_target_path_for_project(project_root, File.basename(existing_gemspec), source_path) if existing_gemspec end return if source_path.to_s.empty? || target_path.to_s.empty? return if skip_packaged_workflow_template?(target_path, config, include_patterns: include_patterns) return if skip_disabled_integration_template?(target_path, config) return if skip_packaged_gemfile_template?(target_path, config, project_root: project_root, template_root_path: template_root.fetch(:path)) return if skip_packaged_license_template?(target_path, config) return if skip_packaged_version_gem_entrypoint_template?(project_root, source_path, target_path, config) return if template_root.fetch(:kind) == "packaged" && opencollective_disabled && opencollective_disabled_file?(target_path) selected_source = preferred_template_source(template_root.fetch(:path), source_path, opencollective_disabled: opencollective_disabled) return unless selected_source strategy_config = if template_root.fetch(:kind) == "packaged" && target_path.to_s == KETTLE_CONFIG_PATH default_template_strategy_config(template_root, target_path) else template_strategy_config(config, target_path) || default_template_strategy_config(template_root, target_path) end preference = { target_path: target_path, configured_source: source_path, selected_source: template_source_display_path(template_root, selected_source), selection_reason: template_source_selection_reason(source_path, template_source_display_path(template_root, selected_source)), apply: template_entry_apply?(entry, apply_templates) } preference[:strategy] = strategy_config.fetch(:strategy).to_s if strategy_config if strategy_config %i[file_type preference freeze_token method_move_policy max_recursion_depth comment_merge_policy].each do |key| preference[key] = strategy_config.fetch(key).to_s if strategy_config.key?(key) end preference[:add_template_only_nodes] = strategy_config.fetch(:add_template_only_nodes) if strategy_config.key?(:add_template_only_nodes) preference[:skip_unresolved_scan] = strategy_config.fetch(:skip_unresolved_scan) if strategy_config.key?(:skip_unresolved_scan) end if copy_only_when_missing_template_path?(target_path) && File.exist?(File.join(project_root, target_path)) preference[:strategy] = "keep_destination" preference[:policy] = "copy_only_when_missing" end preserve_config = readme_preserve_config(config) preference[:readme_preserve_config] = preserve_config if target_path == "README.md" && !preserve_config.empty? if template_root.fetch(:kind) == "packaged" preference[:source_relative_path] = selected_source preference[:source_root] = template_root.fetch(:kind) preference[:source_root_path] = template_root.fetch(:path) end preference end |
.template_source_preferences(project_root, config, opencollective_disabled: false, include_patterns: nil) ⇒ Object
18243 18244 18245 18246 18247 18248 18249 18250 18251 18252 18253 18254 18255 18256 18257 18258 18259 18260 18261 18262 18263 |
# File 'lib/kettle/jem.rb', line 18243 def template_source_preferences(project_root, config, opencollective_disabled: false, include_patterns: nil) templates = template_activation_config(config) return [] unless templates.is_a?(Hash) root = template_root(project_root, templates) entries = template_entries(project_root, root, templates) return [] if entries.empty? apply_templates = templates["apply"] == true entries.filter_map do |entry| template_source_preference( project_root, root, entry, config, opencollective_disabled: opencollective_disabled, include_patterns: include_patterns, apply_templates: apply_templates ) end end |
.template_source_selection_reason(configured_source, selected_source) ⇒ Object
18877 18878 18879 18880 18881 18882 18883 18884 18885 18886 18887 |
# File 'lib/kettle/jem.rb', line 18877 def template_source_selection_reason(configured_source, selected_source) if selected_source.end_with?(".no-osc.example") "opencollective_disabled_no_osc_variant" elsif selected_source.end_with?(".example") "default_example_variant" elsif selected_source == configured_source "configured_source" else "fallback_source" end end |
.template_strategy_config(config, target_path) ⇒ Object
18607 18608 18609 |
# File 'lib/kettle/jem.rb', line 18607 def template_strategy_config(config, target_path) template_file_strategy_config(config, target_path) || template_pattern_strategy_config(config, target_path) end |
.template_strategy_entry(config, path, entry) ⇒ Object
18641 18642 18643 18644 18645 18646 18647 18648 18649 18650 18651 18652 18653 18654 18655 18656 18657 18658 18659 18660 18661 18662 18663 18664 18665 18666 18667 18668 18669 18670 18671 18672 18673 18674 18675 18676 |
# File 'lib/kettle/jem.rb', line 18641 def template_strategy_entry(config, path, entry) strategy = entry["strategy"].to_s.strip.downcase.to_sym raise ArgumentError, "unknown kettle-jem template strategy: #{entry["strategy"]}" unless SUPPORTED_TEMPLATE_STRATEGIES.include?(strategy) result = {strategy: strategy} result[:path] = path if path result[:skip_unresolved_scan] = true if entry["skip_unresolved_scan"] if entry.key?("file_type") file_type = entry["file_type"].to_s.strip.downcase.tr("-", "_").to_sym raise ArgumentError, "unknown kettle-jem template file_type: #{entry["file_type"]}" unless SUPPORTED_TEMPLATE_FILE_TYPES.include?(file_type) result[:file_type] = file_type end if strategy == :merge defaults = config["defaults"].is_a?(Hash) ? config["defaults"] : {} result[:preference] = (entry.key?("preference") ? entry["preference"] : defaults["preference"]).to_s if entry.key?("preference") || defaults.key?("preference") if entry.key?("add_template_only_nodes") || defaults.key?("add_template_only_nodes") result[:add_template_only_nodes] = entry.key?("add_template_only_nodes") ? entry["add_template_only_nodes"] : defaults["add_template_only_nodes"] end result[:freeze_token] = (entry.key?("freeze_token") ? entry["freeze_token"] : defaults["freeze_token"]).to_s if entry.key?("freeze_token") || defaults.key?("freeze_token") result[:max_recursion_depth] = (entry.key?("max_recursion_depth") ? entry["max_recursion_depth"] : defaults["max_recursion_depth"]).to_s if entry.key?("max_recursion_depth") || defaults.key?("max_recursion_depth") if entry.key?("method_move_policy") || defaults.key?("method_move_policy") policy = (entry.key?("method_move_policy") ? entry["method_move_policy"] : defaults["method_move_policy"]).to_s raise ArgumentError, "unknown kettle-jem Ruby method_move_policy: #{policy}" unless SUPPORTED_RUBY_METHOD_MOVE_POLICIES.include?(policy) result[:method_move_policy] = policy end if entry.key?("comment_merge_policy") || defaults.key?("comment_merge_policy") policy = (entry.key?("comment_merge_policy") ? entry["comment_merge_policy"] : defaults["comment_merge_policy"]).to_s.strip.downcase.tr("-", "_") raise ArgumentError, "unknown kettle-jem YAML comment_merge_policy: #{policy}" unless SUPPORTED_YAML_COMMENT_MERGE_POLICIES.include?(policy) result[:comment_merge_policy] = policy end end result end |
.template_tokens(facts, funding) ⇒ Object
14258 14259 14260 14261 14262 14263 14264 14265 14266 14267 14268 14269 14270 14271 14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 14298 14299 14300 14301 14302 14303 14304 14305 14306 14307 14308 14309 14310 14311 14312 14313 14314 14315 14316 14317 14318 14319 14320 14321 14322 |
# File 'lib/kettle/jem.rb', line 14258 def template_tokens(facts, funding) package = facts.fetch(:package) rubygems = facts.fetch(:rubygems) github_org = facts.fetch(:project_runtime, {})[:github_org].to_s github_org = facts.fetch(:forge, {})[:gh_user].to_s if github_org.empty? github_org = facts.fetch(:repository, {})[:slug].to_s.split("/", 2).first.to_s if github_org.empty? tokens = { "KJ|GEM_NAME" => package.fetch(:name).to_s, "KJ|PACKAGE_SUMMARY" => package.fetch(:summary, package.fetch(:description, "")).to_s, "KJ|PACKAGE_DESCRIPTION" => package.fetch(:description, package.fetch(:summary, "")).to_s, "KJ|GEMSPEC_PACKAGE_SUMMARY" => ruby_double_quoted_string_body(strip_leading_decorative_graphemes(package.fetch(:summary, package.fetch(:description, "")).to_s)), "KJ|GEMSPEC_PACKAGE_DESCRIPTION" => ruby_double_quoted_string_body(strip_leading_decorative_graphemes(package.fetch(:description, package.fetch(:summary, "")).to_s)), "KJ|GEM_NAME_PATH" => package.fetch(:name).to_s.tr("-", "/"), "KJ|ENTRYPOINT_REQUIRE" => rubygems.fetch(:entrypoint_require, package.fetch(:name).to_s.tr("-", "/")).to_s, "KJ|GEM_SHIELD" => shield_token(package.fetch(:name).to_s), "KJ|GEM_VERSION" => facts.dig(:project_runtime, :version).to_s, "KJ|GEM_MAJOR" => gem_major_token(facts.fetch(:project_runtime, {})[:version]), "KJ|SECURITY:SUPPORTED_VERSION" => security_supported_version_token(facts.fetch(:project_runtime, {})[:version]), "KJ|GH_ORG" => github_org, "KJ|NAMESPACE" => rubygems.fetch(:namespace, package.fetch(:name).to_s).to_s, "KJ|NAMESPACE_SHIELD" => shield_token(rubygems.fetch(:namespace, package.fetch(:name).to_s).to_s), "KJ|README:TITLE" => readme_title_token(package, rubygems), "KJ|MIN_RUBY" => minimum_ruby_token(rubygems[:min_ruby]), "KJ|MIN_DEV_RUBY" => facts.dig(:project_runtime, :test_min_ruby).to_s, "KJ|MIN_TEST_RUBY" => facts.dig(:project_runtime, :test_min_ruby).to_s, "KJ|KETTLE_CHANGELOG_GEMFILE_DEPENDENCY" => kettle_changelog_gemfile_dependency_token( package.fetch(:name).to_s ), "KJ|CI:EXEC_CMD" => facts.dig(:ci, :exec_cmd).to_s, "KJ|GITHUB_ACTIONS:COVERAGE_UPLOAD_STEPS" => github_actions_coverage_steps(disabled_integrations: facts.dig(:integrations, :disabled)) }.merge( rubocop_template_tokens(rubygems[:min_ruby], ruby_style: facts.fetch(:ruby_style, {})) ).merge( (facts.fetch(:author, {})) ).merge( forge_template_tokens(facts.fetch(:forge, {})) ).merge( funding_template_tokens(funding) ).merge( (facts.fetch(:social, {})) ).merge( license_template_tokens(facts.fetch(:license, {})) ).merge( gemspec_template_tokens(facts.fetch(:gemspec, {}), min_ruby: rubygems[:min_ruby]) ).merge( project_runtime_template_tokens(facts.fetch(:project_runtime, {})) ).merge( readme_url_template_tokens(facts.fetch(:repository, {}), package.fetch(:name).to_s, github_org) ).merge( readme_logo_template_tokens(facts.fetch(:readme_logo, {})) ).merge( readme_corporate_sponsor_template_tokens(facts.fetch(:readme_sponsors, {})) ) org = funding[:open_collective_org].to_s tokens["KJ|OPENCOLLECTIVE_ORG"] = org tokens["KJ|README:FAMILY_INTRO_BACKEND_MATRIX"] = readme_family_intro_and_backend_matrix(facts.fetch(:readme_style, {})) tokens["KJ|README:DEV_TEST_STACK_TABLE"] = readme_dev_test_stack_table(package.fetch(:name).to_s) tokens.merge!(readme_fossa_template_tokens(facts.fetch(:readme_style, {}))) tokens.merge!(rubyforum_template_tokens(facts.fetch(:rubyforum, {}))) tokens.merge!(version_gem_template_tokens(facts)) tokens.merge!(shim_template_tokens(facts.fetch(:shim, {}))) tokens.reject { |key, value| value.empty? && !EMPTY_TEMPLATE_TOKENS.include?(key) } end |
.template_version_gem_bootstrap_step(project_root, report) ⇒ Object
5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 |
# File 'lib/kettle/jem.rb', line 5490 def template_version_gem_bootstrap_step(project_root, report) facts = report.fetch(:facts) entrypoint_require = facts.dig(:rubygems, :entrypoint_require).to_s entrypoint_require = facts.dig(:package, :name).to_s.tr("-", "/") if entrypoint_require.empty? return [] unless version_gem_post_apply_selected?(report, entrypoint_require) package_name = facts.dig(:package, :name).to_s package_entrypoint_path = File.join("lib", "#{package_name}.rb") package_entrypoint_report = report.fetch(:recipe_reports, []).find do |recipe_report| recipe_report.fetch(:relative_path, "").to_s == package_entrypoint_path end package_entrypoint_preexisting = if package_entrypoint_report destination_existed = package_entrypoint_report.dig(:metadata, :destination_existed) destination_existed.nil? ? File.file?(File.join(project_root, package_entrypoint_path)) : destination_existed else File.file?(File.join(project_root, package_entrypoint_path)) end package_entrypoint_preexisting = false if facts.dig(:version_gem, :mode).to_s == "inline" unless version_gem_runtime_compatible?(facts) return [ old_ruby_version_bootstrap_step( project_root, report, entrypoint_require: entrypoint_require, preserve_version_module_include: report.dig(:version_bootstrap_source, :preserve_version_module_include) ), legacy_rbs_consolidation_step(project_root, facts, entrypoint_require: entrypoint_require) ].compact end unless project_uses_version_gem?(project_root, entrypoint_require, facts) return [ version_gem_cleanup_step(project_root, facts, cleanup_entrypoint: !version_gem_enabled?(facts)), legacy_rbs_consolidation_step(project_root, facts, entrypoint_require: entrypoint_require) ].compact end templated_paths = report.fetch(:recipe_reports, []).map { |recipe_report| recipe_report.fetch(:relative_path, "") } version_path = File.join("lib", entrypoint_require, "version.rb") signature_path = File.join("sig", "#{entrypoint_require}.rbs") namespace = facts.dig(:rubygems, :namespace).to_s entrypoint_path = facts.dig(:rubygems, :entrypoint_namespace_superclass_path).to_s entrypoint_path = File.join("lib", "#{entrypoint_require}.rb") unless File.file?(File.join(project_root, entrypoint_path)) namespace_superclass_details = existing_namespace_superclass_details( project_root, namespace, preferred_path: entrypoint_path ) entrypoint_path = namespace_superclass_details[:path] if namespace_superclass_details[:path] namespace_kinds_override = existing_version_namespace_kinds( project_root, version_path, namespace, entrypoint_path: entrypoint_path ) version_gem_bootstrap_step_for_paths( project_root, facts, package_entrypoint_preexisting: package_entrypoint_preexisting, preserve_version_module_include: report.dig(:version_bootstrap_source, :preserve_version_module_include), # The generic recipe renders module namespaces. A destination entrypoint # can establish its outer namespace as a class (for example Month), which # the generated version file must reopen as that same class. manage_version_file: !templated_paths.include?(version_path) || version_namespace_outer_kind_for_template(project_root, facts, entrypoint_path, version_path, namespace) == :class, manage_signature_file: !templated_paths.include?(signature_path), namespace_kinds_override: namespace_kinds_override ) end |
.templating_guard_records(content) ⇒ Object
8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 |
# File 'lib/kettle/jem.rb', line 8350 def templating_guard_records(content) result = prism_parse_success(content) return [] unless result result.value.breadth_first_search_all do |node| gemfile_conditional_node?(node) && prism_subtree_contains_string?(node.predicate, "K_JEM_TEMPLATING") end.map do |node| {start_line: node.location.start_line, end_line: node.location.end_line} end end |
.timed_recipe_report ⇒ Object
4773 4774 4775 4776 4777 |
# File 'lib/kettle/jem.rb', line 4773 def timed_recipe_report started_at = monotonic_time report = yield report_with_duration(report, duration_ms_since(started_at)) end |
.token_config_values(config) ⇒ Object
14693 14694 14695 14696 |
# File 'lib/kettle/jem.rb', line 14693 def token_config_values(config) raw = config.is_a?(Hash) ? config["tokens"] : nil raw.is_a?(Hash) ? raw : {} end |
.token_placeholder?(value) ⇒ Boolean
14714 14715 14716 |
# File 'lib/kettle/jem.rb', line 14714 def token_placeholder?(value) value.to_s.strip.match?(%r{\A\{KJ\|[A-Z][A-Z0-9_:]*\}\z}) end |
.toml_string_scalar_line_value(content, key) ⇒ Object
7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 |
# File 'lib/kettle/jem.rb', line 7283 def toml_string_scalar_line_value(content, key) content.to_s.lines.each do |line| stripped = line.strip next if stripped.start_with?("#") next unless stripped.start_with?("#{key} ") value = stripped.split("=", 2).last.to_s.strip return value[1...-1] if value.start_with?("\"") && value.end_with?("\"") return value unless value.empty? end nil end |
.top_level_ruby_call_records(content, call_name) ⇒ Object
19398 19399 19400 19401 19402 19403 |
# File 'lib/kettle/jem.rb', line 19398 def top_level_ruby_call_records(content, call_name) result = prism_parse_success(content) return [] unless result result.value.statements&.body.to_a.select { |node| node.is_a?(::Prism::CallNode) && node.name == call_name } end |
.top_level_yaml_key_line?(line) ⇒ Boolean
5395 5396 5397 5398 5399 |
# File 'lib/kettle/jem.rb', line 5395 def top_level_yaml_key_line?(line) return false if line.to_s.empty? || line.start_with?("#") || line.start_with?(" ") line.include?(":") end |
.transfer_changelog_context(project_root, env: ENV) ⇒ Object
6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 |
# File 'lib/kettle/jem.rb', line 6291 def transfer_changelog_context(project_root, env: ENV) config = kettle_jem_config(project_root) rubygems = config["rubygems"].is_a?(Hash) ? config["rubygems"] : {} engines = Array(ruby_engines_config(config)) engines = DEFAULT_ENGINES if engines.empty? profile = normalize_template_profile(config.dig("templates", "profile")) profile = FULL_TEMPLATE_PROFILE if profile.empty? min_ruby = transfer_changelog_min_ruby(project_root, rubygems) entrypoint = transfer_changelog_entrypoint_require(project_root, rubygems) version_gem_mode = rubygems_version_gem_entrypoint_mode(rubygems) rubyforum_config = config["rubyforum"].is_a?(Hash) ? config["rubyforum"] : {} project_tag = preferred_template_token_value(nil, rubyforum_config["project_tag"], env, "KJ_RUBYFORUM_PROJECT_TAG").to_s sponsors = readme_corporate_sponsors(config, env) { "profile" => profile, "topology" => config.dig("repository", "topology").to_s.empty? ? REPOSITORY_TOPOLOGY_STANDALONE : config.dig("repository", "topology").to_s, "ruby.min" => min_ruby.empty? ? "0" : min_ruby, "engine.jruby" => engines.include?("jruby"), "engine.truffleruby" => engines.include?("truffleruby") || engines.include?("truby"), "engine.alternates" => engines.any? { |engine| %w[jruby truffleruby truby].include?(engine) }, "feature.appraisals" => File.file?(File.join(project_root, "Appraisals")), "feature.rubyforum" => !rubyforum_facts(config, env, package_name: transfer_changelog_package_name(project_root)).empty?, "feature.rubyforum_project_tag" => !normalize_rubyforum_tag(project_tag).empty?, "feature.corporate_sponsors" => sponsors.any?, "feature.organization_logo" => (config).any? || (config).any?, "feature.structuredmerge_driver" => config.fetch("git_drivers", "semantic-diff").to_s == "semantic-diff", "feature.dedicated_version_gem" => version_gem_mode == "dedicated" || File.file?(File.join(project_root, "lib", entrypoint, "version_gem.rb")), "workflow.dep_heads" => File.file?(File.join(project_root, ".github", "workflows", "dep-heads.yml")), "workflow.jruby_94" => File.file?(File.join(project_root, ".github", "workflows", "jruby-9.4.yml")), "version_gem.mode" => version_gem_mode } end |
.transfer_changelog_entries ⇒ Object
6266 6267 6268 |
# File 'lib/kettle/jem.rb', line 6266 def transfer_changelog_entries changelog_transfer_entries(PACKAGED_TEMPLATE_ROOT) end |
.transfer_changelog_entry_applies?(entry, context) ⇒ Boolean
6355 6356 6357 6358 6359 6360 |
# File 'lib/kettle/jem.rb', line 6355 def transfer_changelog_entry_applies?(entry, context) filter = entry[:filter] return true unless filter transfer_changelog_filter_applies?(filter, context) end |
.transfer_changelog_entrypoint_require(project_root, rubygems) ⇒ Object
6333 6334 6335 6336 6337 6338 |
# File 'lib/kettle/jem.rb', line 6333 def transfer_changelog_entrypoint_require(project_root, rubygems) configured = rubygems["entrypoint_require"].to_s.strip return configured unless configured.empty? transfer_changelog_package_name(project_root).tr("-", "/") end |
.transfer_changelog_filter_applies?(filter, context) ⇒ Boolean
6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 |
# File 'lib/kettle/jem.rb', line 6362 def transfer_changelog_filter_applies?(filter, context) Array(filter.fetch(:predicates)).all? do |predicate| field = predicate.fetch(:field) type = transfer_changelog_filter_field_types.fetch(field) do raise Error, "Unknown transfer changelog filter field #{field.inspect}" end actual = context.fetch(field) do raise Error, "Transfer changelog context omitted #{field.inspect}" end transfer_changelog_filter_predicate_applies?(type, actual, predicate.fetch(:operator), predicate.fetch(:value)) end end |
.transfer_changelog_filter_field_types ⇒ Object
6375 6376 6377 |
# File 'lib/kettle/jem.rb', line 6375 def transfer_changelog_filter_field_types TRANSFER_CHANGELOG_FILTER_FIELD_TYPES end |
.transfer_changelog_filter_predicate_applies?(type, actual, operator, expected) ⇒ Boolean
6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 |
# File 'lib/kettle/jem.rb', line 6379 def transfer_changelog_filter_predicate_applies?(type, actual, operator, expected) case type when :boolean raise Error, "Invalid boolean transfer changelog filter value #{expected.inspect}" unless %w[true false].include?(expected) raise Error, "Invalid boolean transfer changelog filter operator #{operator.inspect}" unless %w[= !=].include?(operator) (operator == "=") ? actual == (expected == "true") : actual != (expected == "true") when :version actual_version = Gem::Version.new(actual.to_s) expected_version = Gem::Version.new(expected.to_s) {"=" => actual_version == expected_version, "!=" => actual_version != expected_version, ">" => actual_version > expected_version, ">=" => actual_version >= expected_version, "<" => actual_version < expected_version, "<=" => actual_version <= expected_version}.fetch(operator) do raise Error, "Invalid version transfer changelog filter operator #{operator.inspect}" end when :enum raise Error, "Invalid enum transfer changelog filter operator #{operator.inspect}" unless %w[= !=].include?(operator) (operator == "=") ? actual.to_s == expected : actual.to_s != expected else raise Error, "Unknown transfer changelog filter type #{type.inspect}" end rescue ArgumentError raise Error, "Invalid version transfer changelog filter value #{expected.inspect}" end |
.transfer_changelog_gemspec_assignment(project_root, field) ⇒ Object
6346 6347 6348 6349 6350 6351 6352 6353 |
# File 'lib/kettle/jem.rb', line 6346 def transfer_changelog_gemspec_assignment(project_root, field) path = Dir.glob(File.join(project_root, "*.gemspec")).min return nil unless path gemspec_assignment_records(File.read(path)).find { |record| record.fetch(:field) == field }&.fetch(:value) rescue SystemCallError, Error nil end |
.transfer_changelog_lag(last_entry_key = nil, verbose: false) ⇒ Object
Compatibility API for callers released before filter-aware replay. New callers must use transfer_changelog_status(project_root:).
6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 |
# File 'lib/kettle/jem.rb', line 6249 def transfer_changelog_lag(last_entry_key = nil, verbose: false) all_entries = changelog_transfer_entries(PACKAGED_TEMPLATE_ROOT) latest = latest_changelog_transfer_entry(all_entries) missing = if last_entry_key.to_s.empty? all_entries else changelog_transfer_entries_after(all_entries, last_entry_key) end result = { last_entry_key: last_entry_key.to_s.empty? ? nil : last_entry_key.to_s, latest_entry_key: latest&.fetch(:key), missing_count: missing.size }.compact result[:missing_entries] = missing if verbose result end |
.transfer_changelog_min_ruby(project_root, rubygems) ⇒ Object
Do not call discover_facts here. discover_facts itself computes changelog facts, so doing so would recurse during every prepare/template operation.
6326 6327 6328 6329 6330 6331 |
# File 'lib/kettle/jem.rb', line 6326 def transfer_changelog_min_ruby(project_root, rubygems) configured = minimum_ruby_token(rubygems["min_ruby"]) return configured unless configured.empty? minimum_ruby_token(transfer_changelog_gemspec_assignment(project_root, "required_ruby_version")) end |
.transfer_changelog_package_name(project_root) ⇒ Object
6340 6341 6342 6343 6344 |
# File 'lib/kettle/jem.rb', line 6340 def transfer_changelog_package_name(project_root) transfer_changelog_gemspec_assignment(project_root, "name").to_s.strip.then do |name| name.empty? ? File.basename(project_root.to_s) : name end end |
.transfer_changelog_status(project_root, env: ENV, verbose: false) ⇒ Object
6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 |
# File 'lib/kettle/jem.rb', line 6227 def transfer_changelog_status(project_root, env: ENV, verbose: false) all_entries = changelog_transfer_entries(PACKAGED_TEMPLATE_ROOT) context = transfer_changelog_context(project_root, env: env) applicable = all_entries.select { |entry| transfer_changelog_entry_applies?(entry, context) } applicable_keys = applicable.map { |entry| entry.fetch(:key).to_s }.to_set applied_keys = changelog_transfer_applied_keys(project_root) missing = applicable.reject { |entry| applied_keys.include?(entry.fetch(:key).to_s) } excluded_present = changelog_transfer_applied_keys(project_root).reject { |key| applicable_keys.include?(key) } result = { total_count: all_entries.size, applicable_count: applicable.size, applied_count: applicable.size - missing.size, missing_count: missing.size, excluded_present_count: excluded_present.size }.compact result[:missing_entries] = missing if verbose result[:excluded_present_keys] = excluded_present if verbose result end |
.trim_trailing_blank_lines(content) ⇒ Object
16244 16245 16246 16247 16248 |
# File 'lib/kettle/jem.rb', line 16244 def trim_trailing_blank_lines(content) lines = content.to_s.lines lines.pop while lines.last&.strip == "" ensure_trailing_newline(lines.join) end |
.truthy_config?(value) ⇒ Boolean
18019 18020 18021 |
# File 'lib/kettle/jem.rb', line 18019 def truthy_config?(value) %w[true yes 1 on enabled].include?(value.to_s.strip.downcase) end |
.uncomment_ruby_comment_line(comment_source) ⇒ Object
9868 9869 9870 9871 9872 9873 9874 9875 |
# File 'lib/kettle/jem.rb', line 9868 def uncomment_ruby_comment_line(comment_source) text = comment_source.to_s return unless text.start_with?("#") uncommented = text[1..].to_s uncommented = uncommented[1..].to_s if uncommented.start_with?(" ") uncommented end |
.unresolved_template_scan?(recipe) ⇒ Boolean
18004 18005 18006 18007 18008 18009 |
# File 'lib/kettle/jem.rb', line 18004 def unresolved_template_scan?(recipe) return false if recipe.fetch(:target_path).to_s == KETTLE_CONFIG_PATH return false if recipe.dig(:template_preference, :skip_unresolved_scan) true end |
.update_github_actions_pins(content) ⇒ Object
19914 19915 19916 19917 19918 19919 19920 19921 19922 19923 19924 19925 19926 19927 19928 19929 19930 19931 19932 19933 19934 |
# File 'lib/kettle/jem.rb', line 19914 def update_github_actions_pins(content) lines = content.to_s.lines yaml_scalar_pairs(content).each do |key_node, value_node| next unless key_node.value.to_s == "uses" pinned_value = github_actions_step_pins.find do |action_prefix, _pin| value_node.value.to_s.start_with?("#{action_prefix}@") end&.last next unless pinned_value line_index = key_node.start_line line = lines[line_index].to_s key_index = line.index("uses:") next unless key_index lines[line_index] = "#{line[0...key_index]}uses: #{pinned_value}\n" end lines.join rescue Psych::Exception content end |
.valid_gem_version?(version) ⇒ Boolean
14658 14659 14660 14661 14662 14663 14664 14665 14666 |
# File 'lib/kettle/jem.rb', line 14658 def valid_gem_version?(version) text = version.to_s return false if text.empty? Gem::Version.new(text) true rescue ArgumentError false end |
.validate_changelog_transfer_entries!(entries, path) ⇒ Object
6523 6524 6525 6526 6527 |
# File 'lib/kettle/jem.rb', line 6523 def validate_changelog_transfer_entries!(entries, path) keys = entries.map { |entry| entry.fetch(:key).to_s } duplicates = keys.tally.select { |_key, count| count > 1 }.keys raise Error, "Duplicate transfer changelog key(s) in #{path}: #{duplicates.join(", ")}" if duplicates.any? end |
.validate_kettle_jem_config!(config) ⇒ Object
13736 13737 13738 13739 13740 13741 13742 13743 13744 13745 13746 13747 |
# File 'lib/kettle/jem.rb', line 13736 def validate_kettle_jem_config!(config) raise Error, "Invalid kettle-jem config: root must be a mapping" unless config.is_a?(Hash) templates = config["templates"] if templates && !templates.is_a?(Hash) raise Error, "Invalid kettle-jem config: templates must be a mapping" end return unless templates&.key?("entries") return if templates["entries"].is_a?(Array) raise Error, "Invalid kettle-jem config: templates.entries must be a list" end |
.validate_modular_dependency_conflicts!(project_root, recipe_reports) ⇒ Object
A dependency owned directly by the project must not also be introduced by a generated modular Gemfile. On first bootstrap, write a reviewable resolution list; later runs require an explicit removal operation.
9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 |
# File 'lib/kettle/jem.rb', line 9607 def validate_modular_dependency_conflicts!(project_root, recipe_reports) conflicts = modular_dependency_conflicts(project_root, recipe_reports) return if conflicts.empty? config = kettle_jem_config(project_root) decisions = modular_dependency_conflict_decisions(config) unresolved = conflicts.reject { |conflict| modular_dependency_conflict_decided?(decisions, conflict) } if unresolved.empty? return end bootstrap_report = recipe_reports.find { |report| report.fetch(:relative_path, "").to_s == KETTLE_CONFIG_PATH } if bootstrap_report && !modular_dependency_conflicts_reviewed?(config) bootstrap_report[:final_content] = add_dependency_conflict_review_list(bootstrap_report.fetch(:final_content, ""), conflicts) return end details = unresolved.sort_by { |conflict| conflict.values_at(:name, :direct, :modular) }.map do |conflict| "#{conflict.fetch(:name)} (#{conflict.fetch(:direct)} vs #{conflict.fetch(:modular)})" end.join(", ") raise Error, "direct dependencies also declared by templated modular Gemfiles: #{details}. " \ "Review dependency_conflicts.resolve in #{KETTLE_CONFIG_PATH}; each entry needs gem, direct, modular, action, and reason. " \ "Supported actions: remove_modular_gem, remove_x_std_lib_eval, keep_both. " \ "keep_both is valid only when the direct and modular requirements overlap." end |
.version_bootstrap_source_state(report, before_apply_files) ⇒ Object
4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 |
# File 'lib/kettle/jem.rb', line 4941 def version_bootstrap_source_state(report, before_apply_files) facts = report.fetch(:facts, {}) entrypoint_require = facts.dig(:rubygems, :entrypoint_require).to_s return {} if entrypoint_require.empty? version_path = File.join("lib", entrypoint_require, "version.rb") content = before_apply_files.fetch(version_path, nil) return {} unless content { preserve_version_module_include: version_file_includes_version_module?(content) } end |
.version_file_includes_version_module?(content) ⇒ Boolean
16396 16397 16398 16399 16400 16401 16402 16403 |
# File 'lib/kettle/jem.rb', line 16396 def version_file_includes_version_module?(content) ruby_call_records(content.to_s, :include).any? do |call| next false unless call.receiver.nil? arguments = call.arguments&.arguments || [] arguments.length == 1 && arguments.first.slice.to_s == "Version" end end |
.version_gem_bootstrap_entrypoint_content(content, namespace:, entrypoint_require:, namespace_superclasses: {}, version_require_path: nil) ⇒ Object
16013 16014 16015 16016 16017 16018 16019 16020 16021 16022 16023 16024 16025 16026 16027 16028 16029 16030 16031 16032 16033 16034 16035 16036 16037 16038 16039 16040 16041 16042 16043 16044 16045 16046 16047 16048 16049 16050 16051 16052 16053 16054 16055 |
# File 'lib/kettle/jem.rb', line 16013 def version_gem_bootstrap_entrypoint_content(content, namespace:, entrypoint_require:, namespace_superclasses: {}, version_require_path: nil) current = if namespace_superclasses.empty? # Preserve the existing relative-require position when there is no # declaration ordering constraint. normalize_entrypoint_version_require( content, entrypoint_require: entrypoint_require, version_require_path: version_require_path ) else # A namesake superclass is a declaration-order constraint: establish # the class, load version.rb, then extend its Version module. source = remove_version_gem_class_eval_references(content) source = ensure_entrypoint_namespace_superclass_declarations( source, namespace: namespace, namespace_superclasses: namespace_superclasses ) normalize_entrypoint_version_require( source, entrypoint_require: entrypoint_require, version_require_path: version_require_path, after_declarations: true ) end current = remove_version_gem_class_eval_references(current) lines = current.lines insert_lines = [] if File.basename(entrypoint_require) != "version_gem" && !ruby_top_level_require?(current, "require", "version_gem") insert_lines << "require \"version_gem\"\n" end if insert_lines.any? relative_path = version_require_path.to_s.empty? ? File.join(File.basename(entrypoint_require), "version") : version_require_path.to_s lines.insert(version_gem_require_insertion_index(current, before_relative_path: relative_path), *insert_lines) end updated = lines.join unless ruby_version_class_eval_namespaces(updated).include?(namespace.to_s) updated += "\n" unless updated.end_with?("\n") updated += "\n#{version_gem_class_eval_block(namespace)}" end collapse_excess_blank_lines(updated) end |
.version_gem_bootstrap_entrypoint_path(project_root, package_name, entrypoint_require, package_entrypoint_preexisting: true) ⇒ Object
15631 15632 15633 15634 15635 15636 15637 15638 15639 |
# File 'lib/kettle/jem.rb', line 15631 def version_gem_bootstrap_entrypoint_path(project_root, package_name, entrypoint_require, package_entrypoint_preexisting: true) default_path = File.join("lib", "#{entrypoint_require}.rb") package_path = File.join("lib", "#{package_name}.rb") return package_path if package_entrypoint_preexisting && package_path != default_path && File.file?(File.join(project_root, package_path)) default_path end |
.version_gem_bootstrap_step(project_root, facts) ⇒ Object
15472 15473 15474 |
# File 'lib/kettle/jem.rb', line 15472 def version_gem_bootstrap_step(project_root, facts) version_gem_bootstrap_step_for_paths(project_root, facts) end |
.version_gem_bootstrap_step_for_paths(project_root, facts, manage_version_file: true, manage_signature_file: true, package_entrypoint_preexisting: true, preserve_version_module_include: nil, namespace_kinds_override: {}) ⇒ Object
15476 15477 15478 15479 15480 15481 15482 15483 15484 15485 15486 15487 15488 15489 15490 15491 15492 15493 15494 15495 15496 15497 15498 15499 15500 15501 15502 15503 15504 15505 15506 15507 15508 15509 15510 15511 15512 15513 15514 15515 15516 15517 15518 15519 15520 15521 15522 15523 15524 15525 15526 15527 15528 15529 15530 15531 15532 15533 15534 15535 15536 15537 15538 15539 15540 15541 15542 15543 15544 15545 15546 15547 15548 15549 15550 15551 15552 15553 15554 15555 15556 15557 15558 15559 15560 15561 15562 15563 15564 15565 15566 15567 15568 15569 15570 15571 15572 15573 15574 15575 15576 15577 15578 15579 15580 15581 15582 15583 15584 15585 15586 15587 15588 15589 15590 15591 15592 15593 15594 15595 15596 15597 15598 15599 15600 15601 15602 15603 15604 15605 15606 15607 15608 15609 15610 15611 15612 15613 15614 15615 15616 15617 15618 15619 15620 15621 15622 15623 15624 15625 15626 15627 15628 15629 |
# File 'lib/kettle/jem.rb', line 15476 def version_gem_bootstrap_step_for_paths(project_root, facts, manage_version_file: true, manage_signature_file: true, package_entrypoint_preexisting: true, preserve_version_module_include: nil, namespace_kinds_override: {}) package_name = facts.dig(:package, :name).to_s return {name: "version_gem_bootstrap", status: "unavailable", reason: "missing_package_facts"} if package_name.empty? entrypoint_require = facts.dig(:rubygems, :entrypoint_require).to_s entrypoint_require = package_name.tr("-", "/") if entrypoint_require.empty? namespace = facts.dig(:rubygems, :namespace).to_s version_path = File.join("lib", entrypoint_require, "version.rb") entrypoint_path = version_gem_bootstrap_entrypoint_path( project_root, package_name, entrypoint_require, package_entrypoint_preexisting: package_entrypoint_preexisting ) default_entrypoint_path = File.join("lib", "#{entrypoint_require}.rb") default_entrypoint = read_project_file(project_root, default_entrypoint_path) version_spec_path = File.join("spec", entrypoint_require, "version_spec.rb") signature_path = File.join("sig", "#{entrypoint_require}.rbs") legacy_signature_paths = legacy_rbs_signature_paths(project_root, entrypoint_require) if namespace.empty? namespace = existing_entrypoint_version_namespace( project_root, entrypoint_path, expected_depth: classify_namespace(package_name).split("::").count { |segment| !segment.empty? } ).to_s end namespace = existing_version_namespace(project_root, version_path).to_s if namespace.empty? namespace = classify_namespace(package_name) if namespace.empty? return {name: "version_gem_bootstrap", status: "unavailable", reason: "missing_package_facts"} if namespace.empty? namespace_superclass_details = existing_namespace_superclass_details( project_root, namespace, preferred_path: entrypoint_path ) entrypoint_namespace_superclasses = version_namespace_superclasses_from_facts(facts).merge( namespace_superclass_details.fetch(:superclasses) ).merge( entrypoint_namespace_superclasses_from_facts(facts) ) fact_superclass_path = facts.dig(:rubygems, :entrypoint_namespace_superclass_path).to_s if entrypoint_namespace_superclasses.any? && File.file?(File.join(project_root, fact_superclass_path)) entrypoint_path = fact_superclass_path elsif namespace_superclass_details[:path] entrypoint_path = namespace_superclass_details[:path] end default_entrypoint_loads_version = entrypoint_path != default_entrypoint_path && entrypoint_loads_version_file?( default_entrypoint, project_root: project_root, entrypoint_path: default_entrypoint_path, version_path: version_path ) version = facts.dig(:project_runtime, :version).to_s version = project_gemspec_version(project_root) if version.empty? version = "0.0.1.pre" if version.empty? changes = [] current_entrypoint = read_project_file(project_root, entrypoint_path) discovered_namespace_kinds = existing_version_namespace_kinds( project_root, version_path, namespace, entrypoint_path: entrypoint_path ) namespace_kinds = version_namespace_kinds_from_facts(facts).merge(discovered_namespace_kinds) namespace_kinds = namespace_kinds.merge(namespace_kinds_override) outer_namespace_kind = namespace_kinds.fetch( namespace.split("::").length - 1, ruby_entrypoint_outer_namespace_kind(current_entrypoint, namespace) ) preserve_version_module_include = existing_version_file_includes_version_module?(project_root, version_path) if preserve_version_module_include.nil? if manage_version_file changes << write_if_changed( project_root, version_path, version_gem_version_file_content( existing_version: existing_version_file_value(project_root, version_path), namespace: namespace, version: version, outer_namespace_kind: outer_namespace_kind, namespace_kinds: namespace_kinds, preserve_version_module_include: preserve_version_module_include ) ) end non_default_version_gem = facts.dig(:version_gem, :non_default_entrypoint) || non_default_version_gem_entrypoint?(project_root, entrypoint_require) entrypoint_content = if non_default_version_gem version_gem_free_entrypoint_content( current_entrypoint, entrypoint_require: entrypoint_require, ensure_version_require: !default_entrypoint_loads_version, after_declarations: !entrypoint_namespace_superclasses.empty?, version_require_path: version_require_path_for_entrypoint(entrypoint_path, version_path) ) elsif current_entrypoint.empty? version_gem_entrypoint_file_content(namespace: namespace, entrypoint_require: entrypoint_require) else version_gem_bootstrap_entrypoint_content( current_entrypoint, namespace: namespace, entrypoint_require: entrypoint_require, namespace_superclasses: entrypoint_namespace_superclasses, version_require_path: version_require_path_for_entrypoint(entrypoint_path, version_path) ) end changes << write_if_changed(project_root, entrypoint_path, entrypoint_content) if entrypoint_path != default_entrypoint_path unless default_entrypoint.empty? cleaned_default_entrypoint = remove_version_gem_entrypoint_references(default_entrypoint) changes << write_if_changed(project_root, default_entrypoint_path, cleaned_default_entrypoint) end end if non_default_version_gem changes << write_if_changed( project_root, File.join("lib", entrypoint_require, "version_gem.rb"), version_gem_entrypoint_file_content(namespace: namespace, entrypoint_require: entrypoint_require, dedicated: true) ) end changes << normalize_version_gem_version_spec( project_root, version_spec_path, entrypoint_require, namespace, package_name: package_name, ensure_version_gem_require: non_default_version_gem, ensure_package_entrypoint_require: !non_default_version_gem ) if manage_signature_file || !legacy_signature_paths.empty? changes.concat( write_consolidated_version_signature( project_root, signature_path, legacy_signature_paths, namespace: namespace, outer_namespace_kind: outer_namespace_kind, namespace_kinds: namespace_kinds ) ) end changed_files = changes.compact { name: "version_gem_bootstrap", status: changed_files.empty? ? "already_current" : "applied", changed_files: changed_files, version_path: version_path, entrypoint_path: entrypoint_path, signature_path: signature_path } end |
.version_gem_class_eval_block(namespace) ⇒ Object
16250 16251 16252 16253 16254 16255 16256 |
# File 'lib/kettle/jem.rb', line 16250 def version_gem_class_eval_block(namespace) <<~RUBY #{namespace}::Version.class_eval do extend VersionGem::Basic end RUBY end |
.version_gem_class_eval_call?(call) ⇒ Boolean
16178 16179 16180 16181 16182 16183 16184 16185 |
# File 'lib/kettle/jem.rb', line 16178 def version_gem_class_eval_call?(call) call.receiver && call.block&.body&.body.to_a.any? do |child| child.is_a?(::Prism::CallNode) && child.receiver.nil? && child.name == :extend && child.arguments&.arguments&.first&.slice == "VersionGem::Basic" end end |
.version_gem_class_eval_selectors(content) ⇒ Object
16170 16171 16172 16173 16174 16175 16176 |
# File 'lib/kettle/jem.rb', line 16170 def version_gem_class_eval_selectors(content) top_level_ruby_call_records(content, :class_eval).filter_map do |call| next unless version_gem_class_eval_call?(call) {start_line: call.location.start_line, end_line: ruby_node_source_end_line(call)} end end |
.version_gem_cleanup_step(project_root, facts, cleanup_entrypoint: true, after_declarations: false, entrypoint_path: nil) ⇒ Object
5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 |
# File 'lib/kettle/jem.rb', line 5689 def version_gem_cleanup_step(project_root, facts, cleanup_entrypoint: true, after_declarations: false, entrypoint_path: nil) package_name = facts.dig(:package, :name).to_s return {name: "version_gem_cleanup", status: "unavailable", reason: "missing_package_facts"} if package_name.empty? entrypoint_require = facts.dig(:rubygems, :entrypoint_require).to_s entrypoint_require = package_name.tr("-", "/") if entrypoint_require.empty? entrypoint_path ||= File.join("lib", "#{entrypoint_require}.rb") dedicated_entrypoint_path = File.join("lib", entrypoint_require, "version_gem.rb") version_spec_path = File.join("spec", entrypoint_require, "version_spec.rb") changed_files = [] current = read_project_file(project_root, entrypoint_path) if cleanup_entrypoint && !current.empty? version_path = File.join(project_root, "lib", entrypoint_require, "version.rb") cleaned = version_gem_free_entrypoint_content( current, entrypoint_require: entrypoint_require, ensure_version_require: File.file?(version_path), after_declarations: after_declarations ) changed_files << write_if_changed(project_root, entrypoint_path, cleaned) end changed_files << cleanup_version_gem_entrypoint(project_root, dedicated_entrypoint_path) changed_files << cleanup_version_gem_version_spec(project_root, version_spec_path) changed_files.compact! { name: "version_gem_cleanup", status: changed_files.empty? ? "already_current" : "applied", changed_files: changed_files, entrypoint_path: entrypoint_path, dedicated_entrypoint_path: dedicated_entrypoint_path, version_spec_path: version_spec_path } end |
.version_gem_default_enabled_for_project?(rubygems_config, gemspec_metadata) ⇒ Boolean
15681 15682 15683 15684 15685 15686 15687 15688 15689 15690 |
# File 'lib/kettle/jem.rb', line 15681 def version_gem_default_enabled_for_project?(rubygems_config, ) configured_floor = rubygems_config.fetch("min_ruby", "").to_s.strip gemspec_floor = (, :required_ruby_version).to_s.strip floor = minimum_ruby_token(configured_floor.empty? ? gemspec_floor : configured_floor) return false if floor.empty? Gem::Version.new(floor) >= Gem::Version.new("2.2") rescue ArgumentError false end |
.version_gem_enabled?(facts) ⇒ Boolean
11032 11033 11034 11035 11036 11037 11038 11039 |
# File 'lib/kettle/jem.rb', line 11032 def version_gem_enabled?(facts) configured = facts.to_h.dig(:version_gem, :enabled) return configured if configured == true || configured == false return true if package_runtime_dependency_names(facts).include?("version_gem") facts.to_h.dig(:rubygems, :version_gem_default_enabled) == true end |
.version_gem_entrypoint_file_content(namespace:, entrypoint_require:, dedicated: false) ⇒ Object
15990 15991 15992 15993 15994 15995 15996 15997 15998 15999 16000 |
# File 'lib/kettle/jem.rb', line 15990 def version_gem_entrypoint_file_content(namespace:, entrypoint_require:, dedicated: false) sections = ["# frozen_string_literal: true"] requires = [] requires << 'require "version_gem"' unless File.basename(entrypoint_require) == "version_gem" version_require = dedicated ? "version" : File.join(File.basename(entrypoint_require), "version") requires << %(require_relative "#{version_require}") sections << requires.join("\n") sections << wrap_ruby_namespace(namespace, []).join("\n") unless dedicated sections << version_gem_class_eval_block(namespace).chomp "#{sections.reject(&:empty?).join("\n\n")}\n" end |
.version_gem_explicitly_disabled?(facts) ⇒ Boolean
10977 10978 10979 |
# File 'lib/kettle/jem.rb', line 10977 def version_gem_explicitly_disabled?(facts) facts.to_h.dig(:version_gem, :enabled) == false end |
.version_gem_facts_for_project(project_root, entrypoint_require, mode: "") ⇒ Object
15669 15670 15671 15672 15673 15674 15675 15676 15677 15678 15679 |
# File 'lib/kettle/jem.rb', line 15669 def version_gem_facts_for_project(project_root, entrypoint_require, mode: "") version_gem_path = File.join("lib", entrypoint_require.to_s, "version_gem.rb") normalized_mode = normalize_version_gem_entrypoint_mode(mode) return {enabled: false, mode: "disabled"} if normalized_mode == "disabled" dedicated = normalized_mode == "dedicated" || File.file?(File.join(project_root, version_gem_path)) return {enabled: true, mode: "inline"} if normalized_mode == "inline" return {} unless dedicated {enabled: true, mode: "dedicated", non_default_entrypoint: true, entrypoint_path: version_gem_path} end |
.version_gem_free_entrypoint_content(content, entrypoint_require:, ensure_version_require: true, after_declarations: false, version_require_path: nil) ⇒ Object
16085 16086 16087 16088 16089 16090 16091 16092 16093 16094 16095 16096 16097 16098 16099 16100 16101 16102 16103 |
# File 'lib/kettle/jem.rb', line 16085 def version_gem_free_entrypoint_content(content, entrypoint_require:, ensure_version_require: true, after_declarations: false, version_require_path: nil) current = remove_version_gem_entrypoint_references(content) unless ensure_version_require relative_path = version_require_path.to_s.empty? ? File.join(File.basename(entrypoint_require), "version") : version_require_path.to_s absolute_path = File.join(entrypoint_require, "version") legacy_relative_path = File.join(File.basename(entrypoint_require), "version") current = [relative_path, legacy_relative_path].uniq.reduce(current) do |value, path| remove_entrypoint_version_requires(value, relative_path: path, absolute_path: absolute_path) end return trim_trailing_blank_lines(collapse_excess_blank_lines(current)) end normalize_entrypoint_version_require( current, entrypoint_require: entrypoint_require, version_require_path: version_require_path, after_declarations: after_declarations ) end |
.version_gem_post_apply_selected?(report, entrypoint_require) ⇒ Boolean
5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 |
# File 'lib/kettle/jem.rb', line 5561 def version_gem_post_apply_selected?(report, entrypoint_require) selected = Array(report.dig(:template_selection, :only)).map(&:to_s) return true if selected.empty? package_name = report.dig(:facts, :package, :name).to_s managed_paths = [ "#{package_name}.gemspec", File.join("lib", "#{entrypoint_require}.rb"), File.join("lib", entrypoint_require, "version.rb"), File.join("lib", entrypoint_require, "version_gem.rb"), File.join("sig", "#{entrypoint_require}.rbs"), File.join("spec", entrypoint_require, "version_spec.rb") ] report.fetch(:recipe_reports, []).any? do |recipe_report| path = recipe_report.fetch(:relative_path, "").to_s managed_paths.include?(path) end end |
.version_gem_require_insertion_index(content, before_relative_path: nil) ⇒ Object
16187 16188 16189 16190 16191 16192 16193 16194 16195 16196 16197 16198 16199 16200 16201 16202 16203 |
# File 'lib/kettle/jem.rb', line 16187 def version_gem_require_insertion_index(content, before_relative_path: nil) ensure_runtime_dependencies! context = Ast::Crispr::Ruby::Prism.document_context(content: content.to_s, source_label: "entrypoint.rb") owners = context.structural_owners(owner_scope: :top_level_statements) if before_relative_path owner = owners.find { |candidate| ruby_require_call?(candidate, "require_relative", before_relative_path) } return owner.location.start_line - 1 if owner end initial_requires = owners.take_while do |candidate| candidate.is_a?(::Prism::CallNode) && %i[require require_relative].include?(candidate.name) end return initial_requires.last.location.end_line if initial_requires.any? first_owner = owners.first first_owner ? first_owner.location.start_line - 1 : ruby_parse_comments(context.ast).map { |comment| comment.location.end_line }.max.to_i end |
.version_gem_runtime_compatible?(facts) ⇒ Boolean
11023 11024 11025 11026 11027 11028 11029 11030 |
# File 'lib/kettle/jem.rb', line 11023 def version_gem_runtime_compatible?(facts) min_ruby = gemspec_runtime_floor_token(facts) return true if min_ruby.to_s.empty? Gem::Version.new(min_ruby) >= Gem::Version.new("2.2") rescue ArgumentError true end |
.version_gem_signature_file_content(namespace:, outer_namespace_kind: :module, namespace_kinds: {}) ⇒ Object
16002 16003 16004 16005 16006 16007 16008 16009 16010 16011 |
# File 'lib/kettle/jem.rb', line 16002 def version_gem_signature_file_content(namespace:, outer_namespace_kind: :module, namespace_kinds: {}) body = [ "module Version", " VERSION: String", "end", "VERSION: String" ] "#{wrap_ruby_namespace(namespace, body, outer_namespace_kind: outer_namespace_kind, namespace_kinds: namespace_kinds).join("\n")}\n" end |
.version_gem_template_entries(gemspec_path) ⇒ Object
12996 12997 12998 12999 13000 |
# File 'lib/kettle/jem.rb', line 12996 def version_gem_template_entries(gemspec_path) VERSION_GEM_TEMPLATE_SOURCES.map do |source| {"source" => source, "target" => version_gem_template_target_path(gemspec_path, source)} end end |
.version_gem_template_target_path(gemspec_path, source) ⇒ Object
13002 13003 13004 13005 13006 13007 13008 13009 13010 13011 13012 13013 13014 13015 13016 13017 13018 13019 13020 13021 |
# File 'lib/kettle/jem.rb', line 13002 def version_gem_template_target_path(gemspec_path, source) gemspec_reference = gemspec_path.to_s package_name = File.basename(gemspec_reference, ".gemspec") entrypoint_require = if File.dirname(gemspec_reference) == "." package_name.tr("-", "/") else project_root = File.dirname(File.(gemspec_reference)) project_entrypoint_require(project_root, package_name) end case source when "lib/gem/version.rb" File.join("lib", entrypoint_require, "version.rb") when "lib/gem/version_gem.rb" File.join("lib", entrypoint_require, "version_gem.rb") when "sig/gem.rbs" File.join("sig", "#{entrypoint_require}.rbs") else source end end |
.version_gem_template_target_path?(target_path) ⇒ Boolean
18426 18427 18428 18429 |
# File 'lib/kettle/jem.rb', line 18426 def version_gem_template_target_path?(target_path) target = target_path.to_s target.end_with?("/version.rb", "/version.rbs") end |
.version_gem_template_target_path_for_project(project_root, gemspec_path, source) ⇒ Object
13023 13024 13025 13026 13027 13028 13029 13030 13031 13032 13033 13034 13035 13036 13037 |
# File 'lib/kettle/jem.rb', line 13023 def version_gem_template_target_path_for_project(project_root, gemspec_path, source) config = kettle_jem_config(project_root) package_name = File.basename(gemspec_path.to_s, ".gemspec") entrypoint_require = project_entrypoint_require(project_root, package_name, config: config) case source when "lib/gem/version.rb" File.join("lib", entrypoint_require, "version.rb") when "lib/gem/version_gem.rb" File.join("lib", entrypoint_require, "version_gem.rb") when "sig/gem.rbs" File.join("sig", "#{entrypoint_require}.rbs") else source end end |
.version_gem_template_tokens(facts) ⇒ Object
14538 14539 14540 14541 14542 14543 14544 14545 14546 14547 14548 14549 14550 14551 14552 14553 14554 14555 14556 14557 14558 14559 14560 14561 14562 14563 14564 14565 14566 14567 14568 14569 14570 14571 14572 14573 14574 14575 14576 14577 |
# File 'lib/kettle/jem.rb', line 14538 def version_gem_template_tokens(facts) namespace = facts.dig(:rubygems, :namespace).to_s version = facts.dig(:project_runtime, :version).to_s version = "0.0.1.pre" if version.empty? return {} if namespace.empty? namespace_kinds = version_namespace_kinds_from_facts(facts) outer_namespace_kind = namespace_kinds.fetch(namespace.split("::").length - 1, :module) version_rb = if facts.dig(:shim, :version_strategy).to_s == "shim" shim_version_file_content( namespace: namespace, replacement_namespace: shim_replacement_namespace(facts.dig(:shim, :replacement_require)), replacement_require: facts.dig(:shim, :replacement_require) ) else version_gem_version_file_content( existing_version: "", namespace: namespace, version: version, outer_namespace_kind: outer_namespace_kind, namespace_kinds: namespace_kinds ) end { "KJ|GEM_VERSION" => version, "KJ|VERSION_GEM:VERSION_RB" => version_rb.chomp, "KJ|VERSION_GEM:VERSION_GEM_RB" => version_gem_entrypoint_file_content( namespace: namespace, entrypoint_require: facts.dig(:rubygems, :entrypoint_require).to_s, dedicated: true ).chomp, "KJ|VERSION_GEM:VERSION_RBS" => version_gem_signature_file_content( namespace: namespace, outer_namespace_kind: outer_namespace_kind, namespace_kinds: namespace_kinds ).chomp } end |
.version_gem_version_file_content(existing_version:, namespace:, version:, outer_namespace_kind: :module, namespace_kinds: {}, preserve_version_module_include: false) ⇒ Object
15970 15971 15972 15973 15974 15975 15976 15977 15978 15979 15980 15981 15982 15983 15984 15985 15986 15987 15988 |
# File 'lib/kettle/jem.rb', line 15970 def version_gem_version_file_content(existing_version:, namespace:, version:, outer_namespace_kind: :module, namespace_kinds: {}, preserve_version_module_include: false) resolved_version = existing_version.to_s.empty? ? version.to_s : existing_version.to_s body = [ "# Version namespace for this gem.", "module Version", " # Current gem version.", " VERSION = #{resolved_version.dump}", "end", "# Current gem version exposed at the traditional constant location.", "VERSION = Version::VERSION # Traditional Constant Location" ] body << "include Version" if preserve_version_module_include <<~RUBY # frozen_string_literal: true #{wrap_ruby_namespace(namespace, body, outer_namespace_kind: outer_namespace_kind, namespace_kinds: namespace_kinds).join("\n")} RUBY end |
.version_gem_version_spec_content(namespace:) ⇒ Object
15801 15802 15803 15804 15805 15806 15807 15808 15809 15810 |
# File 'lib/kettle/jem.rb', line 15801 def version_gem_version_spec_content(namespace:) clean_namespace = namespace.to_s.start_with?("::") ? namespace.to_s[2..] : namespace.to_s <<~RUBY # frozen_string_literal: true RSpec.describe #{clean_namespace}::Version do it_behaves_like "a Version module", described_class end RUBY end |
.version_namespace_kinds_from_facts(facts) ⇒ Object
16295 16296 16297 16298 16299 16300 16301 16302 16303 |
# File 'lib/kettle/jem.rb', line 16295 def version_namespace_kinds_from_facts(facts) raw = facts.dig(:rubygems, :version_namespace_kinds) return {} unless raw.is_a?(Hash) raw.each_with_object({}) do |(index, kind), kinds| normalized_kind = kind.to_s.to_sym kinds[index.to_i] = normalized_kind if %i[class module].include?(normalized_kind) end end |
.version_namespace_outer_kind(project_root, entrypoint_path, namespace) ⇒ Object
16276 16277 16278 |
# File 'lib/kettle/jem.rb', line 16276 def version_namespace_outer_kind(project_root, entrypoint_path, namespace) ruby_entrypoint_outer_namespace_kind(read_project_file(project_root, entrypoint_path), namespace) end |
.version_namespace_outer_kind_for_template(project_root, facts, entrypoint_path, version_path, namespace) ⇒ Object
16280 16281 16282 16283 16284 16285 16286 16287 16288 16289 16290 16291 16292 16293 |
# File 'lib/kettle/jem.rb', line 16280 def version_namespace_outer_kind_for_template(project_root, facts, entrypoint_path, version_path, namespace) kind = version_namespace_outer_kind(project_root, entrypoint_path, namespace) return kind if kind == :class entrypoint_kind = ruby_namespace_declaration_kind(read_project_file(project_root, entrypoint_path), namespace) return entrypoint_kind if entrypoint_kind == :class configured_kinds = version_namespace_kinds_from_facts(facts) target_index = namespace.to_s.split("::").count { |element| !element.empty? } - 1 configured_kind = configured_kinds[target_index] return configured_kind if configured_kind ruby_namespace_declaration_kind(read_project_file(project_root, version_path), namespace) || kind end |
.version_namespace_superclasses_from_facts(facts) ⇒ Object
16305 16306 16307 16308 16309 16310 16311 16312 16313 |
# File 'lib/kettle/jem.rb', line 16305 def version_namespace_superclasses_from_facts(facts) raw = facts.dig(:rubygems, :version_namespace_superclasses) return {} unless raw.is_a?(Hash) raw.each_with_object({}) do |(index, superclass), superclasses| value = superclass.to_s.strip superclasses[index.to_i] = value unless value.empty? end end |
.version_namespace_template_file?(relative_path) ⇒ Boolean
4216 4217 4218 4219 |
# File 'lib/kettle/jem.rb', line 4216 def version_namespace_template_file?(relative_path) basename = File.basename(relative_path.to_s) basename == "version.rb" || basename == "version_gem.rb" || basename.end_with?(".gemspec") end |
.version_require_path_for_entrypoint(entrypoint_path, version_path) ⇒ Object
15641 15642 15643 |
# File 'lib/kettle/jem.rb', line 15641 def version_require_path_for_entrypoint(entrypoint_path, version_path) Pathname(version_path).relative_path_from(Pathname(File.dirname(entrypoint_path))).to_s.delete_suffix(".rb") end |
.version_spec_anonymous_loader_call?(content) ⇒ Boolean
15877 15878 15879 |
# File 'lib/kettle/jem.rb', line 15877 def version_spec_anonymous_loader_call?(content) ruby_call_records(content, :load).any? { |call| call.receiver&.slice == "AnonymousLoader" } end |
.version_spec_package_entrypoint_require(project_root, package_name, entrypoint_require) ⇒ Object
15777 15778 15779 15780 15781 15782 15783 15784 15785 15786 15787 15788 15789 15790 15791 15792 15793 |
# File 'lib/kettle/jem.rb', line 15777 def version_spec_package_entrypoint_require(project_root, package_name, entrypoint_require) package_name = package_name.to_s.strip entrypoint_require = entrypoint_require.to_s.strip return entrypoint_require if package_name.empty? || package_name == entrypoint_require package_path = File.join("lib", "#{package_name}.rb") version_path = File.join("lib", "#{entrypoint_require}.rb") return entrypoint_require unless File.file?(File.join(project_root, package_path)) package_content = read_project_file(project_root, package_path) entrypoint_loads_version_file?( package_content, project_root: project_root, entrypoint_path: package_path, version_path: version_path ) ? package_name : entrypoint_require end |
.version_spec_relative_version_gem_path(version_spec_path, entrypoint_require) ⇒ Object
15892 15893 15894 15895 |
# File 'lib/kettle/jem.rb', line 15892 def version_spec_relative_version_gem_path(version_spec_path, entrypoint_require) spec_depth = File.dirname(version_spec_path.to_s).split(File::SEPARATOR).count { |part| !part.empty? } "#{"../" * spec_depth}lib/#{entrypoint_require}/version_gem.rb" end |
.version_spec_relative_version_path(version_spec_path, entrypoint_require) ⇒ Object
15887 15888 15889 15890 |
# File 'lib/kettle/jem.rb', line 15887 def version_spec_relative_version_path(version_spec_path, entrypoint_require) spec_depth = File.dirname(version_spec_path.to_s).split(File::SEPARATOR).count { |part| !part.empty? } "#{"../" * spec_depth}lib/#{entrypoint_require}/version.rb" end |
.version_spec_require_insertion_index(content) ⇒ Object
15960 15961 15962 15963 15964 15965 15966 15967 15968 |
# File 'lib/kettle/jem.rb', line 15960 def version_spec_require_insertion_index(content) ensure_runtime_dependencies! context = Ast::Crispr::Ruby::Prism.document_context(content: content.to_s, source_label: "version_spec.rb") owners = context.structural_owners(owner_scope: :top_level_statements) requires = owners.select { |owner| owner.is_a?(::Prism::CallNode) && owner.name == :require } return requires.last.location.end_line if requires.any? version_gem_require_insertion_index(content) end |
.version_spec_rspec_describe_call(content) ⇒ Object
15881 15882 15883 15884 15885 |
# File 'lib/kettle/jem.rb', line 15881 def version_spec_rspec_describe_call(content) top_level_ruby_call_records(content, :describe).find do |call| call.receiver&.slice == "RSpec" && call.block end end |
.versioned_gem_name_parts(name) ⇒ Object
9022 9023 9024 9025 9026 9027 9028 9029 9030 |
# File 'lib/kettle/jem.rb', line 9022 def versioned_gem_name_parts(name) match = name.to_s.match(/\A(.+?)(\d+(?:[_-]\d+)*)\z/) return unless match { prefix: match[1], versions: match[2].split(/[_-]/).map { |segment| Integer(segment, exception: false) } } end |
.versioned_gem_name_update_candidate?(destination_name, template_name) ⇒ Boolean
9012 9013 9014 9015 9016 9017 9018 9019 9020 |
# File 'lib/kettle/jem.rb', line 9012 def versioned_gem_name_update_candidate?(destination_name, template_name) destination = versioned_gem_name_parts(destination_name) template = versioned_gem_name_parts(template_name) return false unless destination && template return false unless destination.fetch(:prefix) == template.fetch(:prefix) return false if destination.fetch(:versions) == template.fetch(:versions) destination.fetch(:versions).length == template.fetch(:versions).length end |
.with_event_phase(events, phase, payload = {}) ⇒ Object
4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 |
# File 'lib/kettle/jem.rb', line 4726 def with_event_phase(events, phase, payload = {}) started_at = monotonic_time emit_phase_event(events, phase, status: "started", **payload) result = yield duration_ms = duration_ms_since(started_at) record_phase_timing(events, phase, status: "ok", duration_ms: duration_ms, payload: payload) emit_phase_event(events, phase, status: "ok", duration_ms: duration_ms, **payload) result rescue => error duration_ms = duration_ms_since(started_at) if started_at record_phase_timing(events, phase, status: "failed", duration_ms: duration_ms, payload: payload) emit_phase_event( events, phase, status: "failed", duration_ms: duration_ms, error_class: error.class.name, error_message: error., **payload ) raise end |
.with_git_operation_lock(env) ⇒ Object
13655 13656 13657 13658 13659 13660 13661 13662 13663 13664 13665 13666 |
# File 'lib/kettle/jem.rb', line 13655 def with_git_operation_lock(env) lock_path = git_operation_lock_path(env || {}) return yield if lock_path.to_s.empty? FileUtils.mkdir_p(File.dirname(lock_path)) File.open(lock_path, File::RDWR | File::CREAT, 0o644) do |lock| lock.flock(File::LOCK_EX) yield ensure lock&.flock(File::LOCK_UN) end end |
.with_readme_timing(name) ⇒ Object
4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 |
# File 'lib/kettle/jem.rb', line 4797 def with_readme_timing(name) timings = Thread.current[:kettle_jem_readme_timings] return yield unless timings started_at = monotonic_time result = yield timings << {name: name.to_s, status: "ok", duration_ms: duration_ms_since(started_at)} result rescue => error if timings && started_at timings << { name: name.to_s, status: "failed", duration_ms: duration_ms_since(started_at), error_class: error.class.name, error_message: error. } end raise end |
.with_readme_timing_context(relative_path, timings) ⇒ Object
4787 4788 4789 4790 4791 4792 4793 4794 4795 |
# File 'lib/kettle/jem.rb', line 4787 def with_readme_timing_context(relative_path, timings) return yield unless relative_path.to_s == "README.md" previous = Thread.current[:kettle_jem_readme_timings] Thread.current[:kettle_jem_readme_timings] = timings yield ensure Thread.current[:kettle_jem_readme_timings] = previous if relative_path.to_s == "README.md" end |
.word_array_assignment(content, name) ⇒ Object
9044 9045 9046 |
# File 'lib/kettle/jem.rb', line 9044 def word_array_assignment(content, name) word_array_assignment_record(content, name)&.fetch(:names) || [] end |
.word_array_assignment_record(content, name) ⇒ Object
9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 |
# File 'lib/kettle/jem.rb', line 9059 def word_array_assignment_record(content, name) result = prism_parse_success(content) return unless result result.value.breadth_first_search_all do |node| node.is_a?(::Prism::LocalVariableWriteNode) && node.name == name && ruby_word_array_node?(node.value) end.first&.then do |node| { names: ruby_word_array_names(node.value), start_line: node.location.start_line, end_line: node.location.end_line } end end |
.worker_safe_recipe?(recipe) ⇒ Boolean
4621 4622 4623 4624 4625 4626 |
# File 'lib/kettle/jem.rb', line 4621 def worker_safe_recipe?(recipe) name = recipe.fetch(:name).to_s return true if WORKER_SAFE_RECIPE_NAME_PATTERNS.any? { |pattern| pattern.match?(name) } template_source_application_worker_safe?(recipe) end |
.worker_safe_recipe_payload(recipe, project_root:, template_contents:) ⇒ Object
4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 |
# File 'lib/kettle/jem.rb', line 4593 def worker_safe_recipe_payload(recipe, project_root:, template_contents:) return recipe unless recipe.fetch(:primitive).to_s == "supplied_template_source_application" return recipe if recipe.dig(:template_preference, :strategy).to_s == "raw_copy" content = recipe_template_content(project_root, recipe, template_contents: template_contents) recipe.merge( resolved_template_content: resolve_template_tokens( content, recipe.fetch(:template_tokens, {}), scan_unresolved: unresolved_template_scan?(recipe) ) ) end |
.workflow_job_env_existing_keys(lines, bundle_index, indent_length) ⇒ Object
9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 |
# File 'lib/kettle/jem.rb', line 9199 def workflow_job_env_existing_keys(lines, bundle_index, indent_length) existing = Set.new ((bundle_index + 1)...lines.length).each do |index| line = lines.fetch(index) next if line.strip.empty? current_indent = line.match(/\A(\s*)/)[1].length break if current_indent < indent_length next unless current_indent == indent_length key = line.strip.split(":", 2).first.to_s existing << key unless key.empty? end existing end |
.workflow_matrix_env_indent(lines, mapping) ⇒ Object
9169 9170 9171 9172 9173 9174 9175 9176 |
# File 'lib/kettle/jem.rb', line 9169 def workflow_matrix_env_indent(lines, mapping) ((mapping.start_line - 1)...mapping.end_line).each do |index| line = lines[index].to_s match = line.match(/\A(\s+)appraisal:/) return match[1] if match end lines.fetch(mapping.start_line - 1, "").match(/\A(\s*)/)[1] + " " end |
.workflow_matrix_env_insert_index(lines, mapping) ⇒ Object
9162 9163 9164 9165 9166 9167 |
# File 'lib/kettle/jem.rb', line 9162 def workflow_matrix_env_insert_index(lines, mapping) ((mapping.start_line - 1)...mapping.end_line).each do |index| return index + 1 if lines[index].to_s.match?(/\A\s+appraisal:/) end mapping.start_line end |
.workflow_recipe_slug(workflow_path) ⇒ Object
13692 13693 13694 |
# File 'lib/kettle/jem.rb', line 13692 def workflow_recipe_slug(workflow_path) workflow_path.gsub(/[^a-zA-Z0-9]+/, "_").gsub(/\A_+|_+\z/, "") end |
.wrap_ruby_namespace(namespace, body_lines, outer_namespace_kind: :module, namespace_kinds: {}, namespace_superclasses: {}) ⇒ Object
16258 16259 16260 16261 16262 16263 16264 16265 16266 16267 16268 16269 16270 16271 16272 16273 16274 |
# File 'lib/kettle/jem.rb', line 16258 def wrap_ruby_namespace(namespace, body_lines, outer_namespace_kind: :module, namespace_kinds: {}, namespace_superclasses: {}) segments = namespace.to_s.split("::").reject(&:empty?) return body_lines if segments.empty? lines = [] segments.each_with_index do |segment, index| kind = namespace_kinds.fetch(index, index.zero? ? outer_namespace_kind : :module) keyword = (kind == :class) ? "class" : "module" superclass = namespace_superclasses[index].to_s declaration = "#{keyword} #{segment}" declaration += " < #{superclass}" if keyword == "class" && !superclass.empty? lines << (" " * index) + declaration end body_lines.each { |line| lines << (" " * segments.length) + line unless line.empty? } (segments.length - 1).downto(0) { |index| lines << (" " * index) + "end" } lines end |
.write_consolidated_version_signature(project_root, signature_path, legacy_signature_paths, namespace:, outer_namespace_kind: :module, namespace_kinds: {}) ⇒ Object
15906 15907 15908 15909 15910 15911 15912 15913 15914 15915 15916 15917 15918 15919 15920 15921 15922 15923 15924 15925 |
# File 'lib/kettle/jem.rb', line 15906 def write_consolidated_version_signature(project_root, signature_path, legacy_signature_paths, namespace:, outer_namespace_kind: :module, namespace_kinds: {}) template = version_gem_signature_file_content( namespace: namespace, outer_namespace_kind: outer_namespace_kind, namespace_kinds: namespace_kinds ) current = read_project_file(project_root, signature_path) merged = current legacy_signature_paths.each do |legacy_signature_path| legacy = read_project_file(project_root, legacy_signature_path) merged = merge_rbs_signature_sources(legacy, merged) unless legacy.empty? end merged = merge_rbs_signature_sources(template, merged) [ write_if_changed(project_root, signature_path, merged), legacy_signature_paths.map { |legacy_signature_path| delete_project_file(project_root, legacy_signature_path) } ].flatten.compact end |
.write_if_changed(project_root, relative_path, content) ⇒ Object
16597 16598 16599 16600 16601 16602 16603 16604 16605 |
# File 'lib/kettle/jem.rb', line 16597 def write_if_changed(project_root, relative_path, content) path = File.join(project_root, relative_path) current = File.file?(path) ? File.read(path) : "" return if current == content FileUtils.mkdir_p(File.dirname(path)) File.write(path, content) relative_path end |
.write_intent_from_recipe_report(project_root, recipe_report) ⇒ Object
13963 13964 13965 13966 13967 13968 13969 13970 13971 13972 13973 13974 13975 13976 13977 |
# File 'lib/kettle/jem.rb', line 13963 def write_intent_from_recipe_report(project_root, recipe_report) return unless recipe_report[:changed] relative_path = recipe_report.fetch(:relative_path) action = recipe_report.dig(:metadata, :delete_file) ? :delete : :write content = (action == :write) ? recipe_report.fetch(:final_content) : nil WriteIntent.new( relative_path: relative_path, absolute_path: File.join(project_root, relative_path), action: action, content: content, recipe_name: recipe_report[:recipe_name], metadata: recipe_report.fetch(:metadata, {}) ) end |
.write_intents_for_phase(project_root, recipe_reports) ⇒ Object
13932 13933 13934 |
# File 'lib/kettle/jem.rb', line 13932 def write_intents_for_phase(project_root, recipe_reports) recipe_reports.filter_map { |recipe_report| write_intent_from_recipe_report(project_root, recipe_report) } end |
.yaml_config_scalar_literal(value, path:) ⇒ Object
12797 12798 12799 12800 12801 12802 12803 |
# File 'lib/kettle/jem.rb', line 12797 def yaml_config_scalar_literal(value, path:) clean = value.to_s.strip return clean if path == ["project_emoji"] return clean if clean.match?(/\A\d+(?:\.\d+)?\z/) JSON.generate(clean) end |
.yaml_contains_key_value?(node, key, value) ⇒ Boolean
19775 19776 19777 19778 19779 19780 19781 19782 19783 19784 19785 19786 19787 |
# File 'lib/kettle/jem.rb', line 19775 def yaml_contains_key_value?(node, key, value) case node when Hash node.any? do |candidate_key, candidate_value| (candidate_key.to_s == key.to_s && candidate_value.to_s == value.to_s) || yaml_contains_key_value?(candidate_value, key, value) end when Array node.any? { |candidate| yaml_contains_key_value?(candidate, key, value) } else false end end |
.yaml_double_quoted_scalar(value) ⇒ Object
9178 9179 9180 |
# File 'lib/kettle/jem.rb', line 9178 def yaml_double_quoted_scalar(value) %("#{value.to_s.gsub("\\", "\\\\\\").gsub('"', '\"')}") end |
.yaml_line_comment_suffix(line, key_index) ⇒ Object
12758 12759 12760 12761 12762 12763 12764 12765 12766 12767 12768 12769 12770 12771 12772 12773 12774 12775 12776 12777 12778 12779 12780 12781 12782 12783 12784 12785 12786 12787 12788 12789 12790 12791 12792 12793 12794 12795 |
# File 'lib/kettle/jem.rb', line 12758 def yaml_line_comment_suffix(line, key_index) value_start = line.to_s.index(":", key_index).to_i + 1 in_single_quote = false in_double_quote = false escaped = false value_start.upto(line.length - 1) do |index| char = line[index] if in_double_quote if escaped escaped = false elsif char == "\\" escaped = true elsif char == "\"" in_double_quote = false end next end if in_single_quote in_single_quote = false if char == "'" next end case char when "\"" in_double_quote = true when "'" in_single_quote = true when "#" previous = index.zero? ? "" : line[index - 1] next unless previous == " " || previous == "\t" before_comment = line[(value_start...index)].to_s trailing_space = before_comment.reverse.each_char.take_while { |space| space == " " || space == "\t" }.join.reverse return "#{trailing_space}#{line[index..].to_s.chomp}" end end "" end |
.yaml_mapping_nodes(content) ⇒ Object
9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 |
# File 'lib/kettle/jem.rb', line 9215 def yaml_mapping_nodes(content) root = Psych.parse_stream(content.to_s) nodes = [] stack = [root] until stack.empty? node = stack.pop nodes << node if node.is_a?(Psych::Nodes::Mapping) stack.concat(Array(node.respond_to?(:children) ? node.children : nil)) end nodes end |
.yaml_mapping_path_entries(content) ⇒ Object
20057 20058 20059 20060 20061 20062 20063 20064 |
# File 'lib/kettle/jem.rb', line 20057 def yaml_mapping_path_entries(content) document = Psych.parse_stream(content.to_s) entries = [] document.children.each { |node| collect_yaml_mapping_path_entries(node, [], entries) } entries rescue Psych::Exception [] end |
.yaml_mapping_scalar_node(mapping, key) ⇒ Object
9241 9242 9243 9244 9245 9246 9247 9248 9249 |
# File 'lib/kettle/jem.rb', line 9241 def yaml_mapping_scalar_node(mapping, key) mapping.children.each_slice(2) do |key_node, value_node| next unless key_node.is_a?(Psych::Nodes::Scalar) && key_node.value.to_s == key.to_s next unless value_node.is_a?(Psych::Nodes::Scalar) return value_node end nil end |
.yaml_mapping_scalar_value(mapping, key) ⇒ Object
9237 9238 9239 |
# File 'lib/kettle/jem.rb', line 9237 def yaml_mapping_scalar_value(mapping, key) yaml_mapping_scalar_node(mapping, key)&.value.to_s end |
.yaml_mapping_value(mapping, key) ⇒ Object
7356 7357 7358 7359 7360 7361 7362 |
# File 'lib/kettle/jem.rb', line 7356 def yaml_mapping_value(mapping, key) mapping.children.each_slice(2) do |key_node, value_node| return value_node if key_node.value.to_s == key.to_s end nil end |
.yaml_mapping_value_node(content, key, node_class) ⇒ Object
20111 20112 20113 20114 20115 20116 20117 20118 20119 20120 |
# File 'lib/kettle/jem.rb', line 20111 def yaml_mapping_value_node(content, key, node_class) yaml_mapping_nodes(content).each do |mapping| mapping.children.each_slice(2) do |key_node, value_node| next unless key_node.is_a?(Psych::Nodes::Scalar) && key_node.value.to_s == key.to_s return value_node if value_node.is_a?(node_class) end end nil end |
.yaml_merge_options(recipe) ⇒ Object
10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 |
# File 'lib/kettle/jem.rb', line 10332 def (recipe) = { preference: (recipe.dig(:template_preference, :preference) || "destination").to_sym, add_template_only_nodes: true, freeze_token: recipe.dig(:template_preference, :freeze_token) || "kettle-jem" } if !recipe.dig(:template_preference, :add_template_only_nodes).nil? configured = DecisionPolicy.value_to_boolean(recipe.dig(:template_preference, :add_template_only_nodes)) [:add_template_only_nodes] = configured unless configured.nil? end policy = recipe.dig(:template_preference, :comment_merge_policy).to_s policy = DEFAULT_TEMPLATE_YAML_COMMENT_MERGE_POLICY if policy.empty? && recipe.fetch(:primitive) == "supplied_template_source_application" [:comment_merge_policy] = policy.to_sym unless policy.empty? end |
.yaml_process_result_adapter_failure?(merge_result) ⇒ Boolean
9271 9272 9273 |
# File 'lib/kettle/jem.rb', line 9271 def yaml_process_result_adapter_failure?(merge_result) process_result_adapter_failure?(merge_result) end |
.yaml_scalar_line_value(content, key) ⇒ Object
12413 12414 12415 12416 12417 12418 12419 12420 12421 12422 12423 |
# File 'lib/kettle/jem.rb', line 12413 def yaml_scalar_line_value(content, key) lines = content.to_s.lines yaml_scalar_pairs(content).each do |key_node, value_node| next unless key_node.value.to_s == key.to_s line = lines[value_node.start_line].to_s value_text = line.split(":", 2).last.to_s.strip return value_text unless value_text.empty? end nil end |
.yaml_scalar_pairs(content) ⇒ Object
20040 20041 20042 20043 20044 20045 20046 |
# File 'lib/kettle/jem.rb', line 20040 def yaml_scalar_pairs(content) yaml_mapping_nodes(content).flat_map do |mapping| mapping.children.each_slice(2).filter_map do |key_node, value_node| [key_node, value_node] if key_node.is_a?(Psych::Nodes::Scalar) && value_node.is_a?(Psych::Nodes::Scalar) end end end |
.yaml_scalar_path_entries(content) ⇒ Object
20048 20049 20050 20051 20052 20053 20054 20055 |
# File 'lib/kettle/jem.rb', line 20048 def yaml_scalar_path_entries(content) document = Psych.parse_stream(content.to_s) entries = [] document.children.each { |node| collect_yaml_scalar_path_entries(node, [], entries) } entries rescue Psych::Exception [] end |
.yaml_scalar_sequence_at_path(content, path) ⇒ Object
19750 19751 19752 19753 19754 19755 19756 19757 19758 19759 19760 19761 19762 19763 19764 19765 19766 19767 |
# File 'lib/kettle/jem.rb', line 19750 def yaml_scalar_sequence_at_path(content, path) document = Psych.parse_stream(content.to_s).children.first node = path.reduce(document&.root) do |current, key| break nil unless current.is_a?(Psych::Nodes::Mapping) pair = current.children.each_slice(2).find do |key_node, _value_node| key_node.is_a?(Psych::Nodes::Scalar) && key_node.value.to_s == key.to_s end pair&.last end return [] unless node.is_a?(Psych::Nodes::Sequence) node.children.filter_map do |child| child.value.to_s if child.is_a?(Psych::Nodes::Scalar) end rescue Psych::Exception [] end |
.yaml_scalar_value_template_tokens(content) ⇒ Object
17777 17778 17779 17780 17781 |
# File 'lib/kettle/jem.rb', line 17777 def yaml_scalar_value_template_tokens(content) yaml_scalar_pairs(content).flat_map do |_key_node, value_node| Token::Resolver::Document.new(value_node.value.to_s, config: TEMPLATE_TOKEN_CONFIG).token_keys.grep(/\AKJ\|/) end.uniq end |
.yaml_top_level_key_lines(content) ⇒ Object
19900 19901 19902 19903 19904 19905 19906 19907 19908 19909 19910 19911 19912 |
# File 'lib/kettle/jem.rb', line 19900 def yaml_top_level_key_lines(content) document = Psych.parse_stream(content.to_s).children.first root = document&.root return {} unless root.is_a?(Psych::Nodes::Mapping) root.children.each_slice(2).each_with_object({}) do |(key_node, _value_node), keys| next unless key_node.is_a?(Psych::Nodes::Scalar) keys[key_node.value.to_s] = key_node.start_line end rescue Psych::Exception {} end |