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)


203
204
205
# File 'lib/commenter/cli.rb', line 203

def self.exit_on_failure?
  true
end

Instance Method Details

#fill(input_yaml) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/commenter/cli.rb', line 46

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



78
79
80
81
82
83
84
85
86
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
# File 'lib/commenter/cli.rb', line 78

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



145
146
147
148
149
150
151
152
153
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
# File 'lib/commenter/cli.rb', line 145

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_docx) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/commenter/cli.rb', line 16

def import(input_docx)
  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 DOCX file
  parser = Parser.new
  comment_sheet = parser.parse(input_docx, options)

  # Write the YAML data file with schema reference
  yaml_content = generate_yaml_with_header(comment_sheet.to_yaml_h, schema_dir)
  File.write(output_yaml, yaml_content)

  # Copy schema file to output directory
  schema_source = File.join(__dir__, "../../schema/iso_comment_2012-03.yaml")
  schema_target = File.join(schema_dir, "iso_comment_2012-03.yaml")

  # 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_docx} to #{output_yaml}"
  puts "Schema file created at #{schema_target}"
end