Class: Fp::Commands::Report
Overview
fp report
Constant Summary collapse
- KNOWN_FLAGS =
{ project: :string, surface: :string, file: :string, repo: :string, pr: :string, sha: :string, work_item: :string, ci_url: :string, title: :string, state: :string }.freeze
- VALID_STATES =
%w[present stub].freeze
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Fp::Commands::Base
Instance Method Details
#run(args) ⇒ Object
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 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 |
# File 'lib/fp/commands/report.rb', line 24 def run(args) opts, positional = parse_flags(args, KNOWN_FLAGS) slug = positional.first unless slug output.error('Requirement slug is required. Usage: fp report <slug> --project <project> --surface <surface> --file <path> --repo <org/repo>') exit 1 end require_flag(opts, :project) require_flag(opts, :surface) require_flag(opts, :file) require_flag(opts, :repo) # Validate state state = opts[:state] || 'present' unless VALID_STATES.include?(state) output.error("Invalid state '#{state}'. Must be one of: #{VALID_STATES.join(', ')}") output.error('Note: Agents report present or stub. Only CI (#1222) can report passing or failing.') exit 1 end workspace_id = resolve_workspace_id(opts[:project]) # Find the requirement by slug req_result = client.find_requirement_by_slug(workspace_id, slug) unless req_result[:ok] output.error(req_result[:error], status: req_result[:status]) exit 1 end requirement = req_result[:data]['requirement'] # Build evidence payload params = { requirement_id: requirement['id'], surface: opts[:surface], file: opts[:file], repo: opts[:repo], state: state } params[:pr_url] = opts[:pr] if opts[:pr] params[:sha] = opts[:sha] if opts[:sha] params[:work_item_url] = opts[:work_item] if opts[:work_item] params[:ci_url] = opts[:ci_url] if opts[:ci_url] params[:example_title] = opts[:title] if opts[:title] # Try to report evidence result = client.report_evidence(params) # Evidence API may not exist yet (#1214) if !result[:ok] && result[:status] == 404 output.success(params, summary: nil) do puts "Evidence for '#{slug}' on surface '#{opts[:surface]}':" puts " State: #{state}" puts " File: #{opts[:file]}" puts " Repo: #{opts[:repo]}" puts " PR: #{opts[:pr]}" if opts[:pr] puts " SHA: #{opts[:sha]}" if opts[:sha] puts " Work Item: #{opts[:work_item]}" if opts[:work_item] puts " CI URL: #{opts[:ci_url]}" if opts[:ci_url] puts " Title: #{opts[:title]}" if opts[:title] puts puts '⚠️ Evidence API not available yet. This will be recorded when #1214 is complete.' end return end unless result[:ok] output.error(result[:error], status: result[:status]) exit 1 end output.success(result[:data]) do puts "Evidence reported for '#{slug}' on surface '#{opts[:surface]}'." puts " State: #{state}" puts " File: #{opts[:file]}" if opts[:pr] puts " PR: #{opts[:pr]}" end if opts[:work_item] puts " Work: #{opts[:work_item]}" end if opts[:ci_url] puts " CI: #{opts[:ci_url]}" end if opts[:title] puts " Title: #{opts[:title]}" end end end |