Class: Danger::DangerComposeCompilerMetrics

Inherits:
Plugin
  • Object
show all
Includes:
Helper
Defined in:
lib/compose_compiler_metrics/plugin.rb

Instance Method Summary collapse

Methods included from Helper

#build_markdown_table, #build_variants, #class_report_path, #composable_report_path, #composable_stats_report_path, #folding, #installed?, #metrics_filename

Instance Method Details

#report(metrics_dir) ⇒ Object



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
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/compose_compiler_metrics/plugin.rb', line 73

def report(metrics_dir)
  markdown('# Compose Compiler Metrics Report')
  build_variants(metrics_dir).each do |module_name, build_variant|
    markdown("## #{module_name} - #{build_variant}")

    # Metrics Report
    metrics_path = File.join(metrics_dir, metrics_filename(module_name, build_variant))
    table_headers = %w[name value]
    table_rows = JSON.load_file(metrics_path).to_a

    markdown(
      folding(
        '### Metrics',
        build_markdown_table(table_headers, table_rows)
      )
    )

    # Composable Stats Report
    composable_stats_report_path = File.join(metrics_dir, composable_stats_report_path(module_name, build_variant))
    csv = CSV.read(composable_stats_report_path, headers: true)

    markdown(
      folding(
        '### Composable Stats Report',
        build_markdown_table(csv.headers, csv.map(&:fields))
      )
    )

    # Composable Report
    composable_report_path = File.join(metrics_dir, composable_report_path(module_name, build_variant))
    markdown(
      folding(
        '### Composable Report',
        "        ```kotlin\n        \#{File.read(composable_report_path)}\n        ```\n        MARKDOWN\n      )\n    )\n\n    # Class Report\n    class_report_path = File.join(metrics_dir, class_report_path(module_name, build_variant))\n    markdown(\n      folding(\n        '### Class Report',\n        <<~MARKDOWN\n        ```kotlin\n        \#{File.read(class_report_path)}\n        ```\n        MARKDOWN\n      )\n    )\n  end\nend\n"

#report_difference(metrics_dir, base_metrics_dir) ⇒ Object



12
13
14
15
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
41
42
# File 'lib/compose_compiler_metrics/plugin.rb', line 12

def report_difference(metrics_dir, base_metrics_dir)
  unless installed?("diff")
    error "diff command not found. Please install diff command."
    return
  end

  markdown("# Compose Compiler Metrics Difference Report")
  build_variants(metrics_dir).each do |module_name, build_variant|
    markdown("## #{module_name} - #{build_variant}")

    # Metrics Report
    metrics_path = File.join(metrics_dir, metrics_filename(module_name, build_variant))
    base_metrics_path = File.join(base_metrics_dir, metrics_filename(module_name, build_variant))
    report_file_difference("Metrics", metrics_path, base_metrics_path)

    # Composable Stats Report
    composable_stats_report_path = File.join(metrics_dir, composable_stats_report_path(module_name, build_variant))
    base_composable_stats_report_path = File.join(base_metrics_dir, composable_stats_report_path(module_name, build_variant))
    report_file_difference("Composable Stats Report", composable_stats_report_path, base_composable_stats_report_path)

    # Composable Report
    composable_report_path = File.join(metrics_dir, composable_report_path(module_name, build_variant))
    base_composable_report_path = File.join(base_metrics_dir, composable_report_path(module_name, build_variant))
    report_file_difference("Composable Report", composable_report_path, base_composable_report_path)

    # Class Report
    class_report_path = File.join(metrics_dir, class_report_path(module_name, build_variant))
    base_class_report_path = File.join(base_metrics_dir, class_report_path(module_name, build_variant))
    report_file_difference("Composable Report", class_report_path, base_class_report_path)
  end
end

#report_file_difference(title, metrics_path, base_metrics_path) ⇒ Object



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
# File 'lib/compose_compiler_metrics/plugin.rb', line 44

def report_file_difference(title, metrics_path, base_metrics_path)
  unless File.exist?(metrics_path)
    warn "DangerComposeCompilerMetrics: new file not found at #{metrics_path}. Skipping file difference report."
    return
  end

  unless File.exist?(base_metrics_path)
    warn "DangerComposeCompilerMetrics: reference file not found at #{base_metrics_path}. Skipping file difference report."
    return
  end

  report = `diff -u #{base_metrics_path} #{metrics_path}`

  markdown(
    folding(
      "### #{title}",
      if report.empty?
        "No difference found."
      else
        "        ```diff\n        \#{report}\n        ```\n        MARKDOWN\n      end\n    )\n  )\nend\n"