Class: Commenter::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/commenter/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


212
213
214
# File 'lib/commenter/cli.rb', line 212

def self.exit_on_failure?
  true
end

Instance Method Details

#fill(input_yaml) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/commenter/cli.rb', line 55

def fill(input_yaml)
  output_docx = options[:output]

  # Load YAML data
  data = YAML.load_file(input_yaml)

  # Extract comments from the structure
  comments = if data.is_a?(Hash)
               data["comments"] || data[:comments] || []
             else
               data || []
             end

  raise "No comments found in YAML file" if comments.empty?

  # Use default template if none specified
  template_path = options[:template] || File.join(__dir__, "../../data/iso_comment_template_2012-03.docx")

  # Fill the template
  Filler.new.fill(template_path, output_docx, comments, options)
  puts "Filled template to #{output_docx}"
end

#github_create(input_yaml) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/commenter/cli.rb', line 87

def github_create(input_yaml)
  creator = GitHubIssueCreator.new(
    options[:config],
    options[:title_template],
    options[:body_template]
  )

  github_options = {
    stage: options[:stage],
    milestone: options[:milestone],
    assignee: options[:assignee],
    dry_run: options[:dry_run],
    output: options[:output]
  }.compact

  results = creator.create_issues_from_yaml(input_yaml, github_options)

  if options[:dry_run]
    puts "DRY RUN - Preview of issues to be created:"
    puts "=" * 50
    results.each do |result|
      puts "\nComment ID: #{result[:comment_id]}"
      puts "Title: #{result[:title]}"
      puts "Labels: #{result[:labels].join(", ")}" if result[:labels]&.any?
      puts "Assignees: #{result[:assignees].join(", ")}" if result[:assignees]&.any?
      puts "Milestone: #{result[:milestone]}" if result[:milestone]
      puts "\nBody preview (first 200 chars):"
      puts result[:body][0...200] + (result[:body].length > 200 ? "..." : "")
      puts "-" * 30
    end
  else
    puts "GitHub issue creation results:"
    puts "=" * 40

    created_count = 0
    skipped_count = 0
    error_count = 0

    results.each do |result|
      case result[:status]
      when :created
        created_count += 1
        puts "#{result[:comment_id]}: Created issue ##{result[:issue_number]}"
        puts "  URL: #{result[:issue_url]}"
      when :skipped
        skipped_count += 1
        puts "- #{result[:comment_id]}: Skipped (#{result[:message]})"
        puts "  URL: #{result[:issue_url]}" if result[:issue_url]
      when :error
        error_count += 1
        puts "#{result[:comment_id]}: Error - #{result[:message]}"
      end
    end

    puts "\nSummary:"
    puts "Created: #{created_count}, Skipped: #{skipped_count}, Errors: #{error_count}"
  end
rescue StandardError => e
  puts "Error: #{e.message}"
  exit 1
end

#github_retrieve(input_yaml) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/commenter/cli.rb', line 154

def github_retrieve(input_yaml)
  retriever = GitHubIssueRetriever.new(options[:config])

  retrieve_options = {
    output: options[:output],
    include_open: options[:include_open],
    dry_run: options[:dry_run]
  }.compact

  results = retriever.retrieve_observations_from_yaml(input_yaml, retrieve_options)

  if options[:dry_run]
    puts "DRY RUN - Preview of observations to be retrieved:"
    puts "=" * 50
    results.each do |result|
      puts "\nComment ID: #{result[:comment_id]}"
      puts "Issue ##{result[:issue_number]}: #{result[:status]}"
      if result[:observation]
        puts "Observation preview (first 200 chars):"
        puts result[:observation][0...200] + (result[:observation].length > 200 ? "..." : "")
      else
        puts "No observation found"
      end
      puts "-" * 30
    end
  else
    puts "GitHub observation retrieval results:"
    puts "=" * 40

    retrieved_count = 0
    skipped_count = 0
    error_count = 0

    results.each do |result|
      case result[:status]
      when :retrieved
        retrieved_count += 1
        puts "#{result[:comment_id]}: Retrieved observation from issue ##{result[:issue_number]}"
      when :skipped
        skipped_count += 1
        puts "- #{result[:comment_id]}: Skipped (#{result[:message]})"
      when :error
        error_count += 1
        puts "#{result[:comment_id]}: Error - #{result[:message]}"
      end
    end

    puts "\nSummary:"
    puts "Retrieved: #{retrieved_count}, Skipped: #{skipped_count}, Errors: #{error_count}"

    output_file = options[:output] || input_yaml
    puts "Updated YAML file: #{output_file}"
  end
rescue StandardError => e
  puts "Error: #{e.message}"
  exit 1
end

#import(input_file) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/commenter/cli.rb', line 23

def import(input_file)
  output_yaml = options[:output]
  schema_dir = options[:schema_dir]

  # Ensure schema directory exists
  FileUtils.mkdir_p(schema_dir) unless Dir.exist?(schema_dir)

  # Parse the input file
  parser = Parser.new
  comment_sheet = parser.parse(input_file, options)

  # Write the YAML data file with schema reference
  File.write(output_yaml, comment_sheet.to_yaml_document(schema_dir))

  # Copy schema file to output directory
  schema_name = comment_sheet.schema_name
  schema_source = File.join(__dir__, "../../schema/#{schema_name}")
  schema_target = File.join(schema_dir, schema_name)

  # Only copy if source and target are different
  FileUtils.cp(schema_source, schema_target) unless File.expand_path(schema_source) == File.expand_path(schema_target)

  puts "Converted #{input_file} to #{output_yaml}"
  puts "  Version: #{comment_sheet.version}"
  puts "  Comments: #{comment_sheet.comments.length}"
  puts "  Schema: #{schema_target}"
end