Class: Makit::Configuration::GitLabHelper
- Inherits:
-
Object
- Object
- Makit::Configuration::GitLabHelper
- Defined in:
- lib/makit/configuration/gitlab_helper.rb
Overview
Helper for GitLab CI YAML conversion
Class Method Summary collapse
Class Method Details
.from_yaml(path) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/makit/configuration/gitlab_helper.rb', line 14 def self.from_yaml(path) content = File.read(path) data = YAML.safe_load(content, symbolize_names: true, permitted_classes: [Symbol]) project = Project.new(name: data[:name] || "Unknown", version: data[:version] || "1.0.0") # Extract steps from GitLab CI jobs data.each do |key, value| next unless value.is_a?(Hash) && value[:script] step_name = key.to_s.gsub(/_job$/, "") step = Step.new( name: step_name, description: value[:description] || "GitLab CI job: #{step_name}", commands: value[:script], ) project.add_step(step) end project end |
.generate_yaml(project) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/makit/configuration/gitlab_helper.rb', line 36 def self.generate_yaml(project) yaml = { stages: project.steps.map(&:name), variables: { project_name: project.name, project_version: project.version, }, } project.steps.each do |step| job_name = "#{step.name}_job" yaml[job_name.to_sym] = { stage: step.name, script: step.commands, description: step.description, } end yaml.to_yaml end |
.to_yaml(project, path) ⇒ Object
9 10 11 12 |
# File 'lib/makit/configuration/gitlab_helper.rb', line 9 def self.to_yaml(project, path) yaml_content = generate_yaml(project) File.write(path, yaml_content) end |