-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for running metrics against a particular git hash #188
base: main
Are you sure you want to change the base?
Changes from 3 commits
5aee045
223780e
419a6e4
97d8552
02822a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'git' | ||
MetricFu.configure | ||
module MetricFu | ||
class Run | ||
|
@@ -7,6 +8,7 @@ def initialize | |
def run(options={}) | ||
configure_run(options) | ||
measure | ||
reset_git(options) if git_configured? options | ||
display_results if options[:open] | ||
end | ||
|
||
|
@@ -28,6 +30,7 @@ def display_results | |
private | ||
def configure_run(options) | ||
disable_metrics(options) | ||
configure_git(options) | ||
configure_formatters(options) | ||
end | ||
def disable_metrics(options) | ||
|
@@ -55,20 +58,51 @@ def configure_metric(metric, metric_options) | |
end | ||
end | ||
def configure_formatters(options) | ||
filename = options[:githash] # Set the filename for the output; nil is a valid value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a little misleading, no? Why not just do metric_filename = options.fetch(:githash) { filename_timestamp(Time.now) }
def filename_timestamp(time)
time.strftime("%Y%m%d")
end |
||
|
||
# Configure from command line if any. | ||
if options[:format] | ||
MetricFu.configuration.formatters.clear # Command-line format takes precedence. | ||
Array(options[:format]).each do |format, o| | ||
MetricFu.configuration.configure_formatter(format, o) | ||
MetricFu.configuration.configure_formatter(format, o, filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to pass the filename if we combine its logic with the default filename (filenamed_timestamp) |
||
end | ||
end | ||
# If no formatters specified, use defaults. | ||
if MetricFu.configuration.formatters.empty? | ||
Array(MetricFu::Formatter::DEFAULT).each do |format, o| | ||
MetricFu.configuration.configure_formatter(format, o) | ||
MetricFu.configuration.configure_formatter(format, o, filename) | ||
end | ||
end | ||
end | ||
def configure_git(options) | ||
return unless git_configured? options | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you'd want to use a version-control adapter that can require and use arbitrary library code. See comment below re: gem dependency |
||
begin | ||
@git ||= Git.init | ||
@orig_branch ||= @git.current_branch | ||
|
||
mf_log "CHECKING OUT '#{options[:githash]}'" | ||
@git.checkout(options[:githash]) | ||
rescue Git::GitExecuteError => e | ||
mf_log "Unable to checkout githash: #{options[:githash]}" | ||
raise "Unable to checkout githash: #{options[:githash]}: #{e}" | ||
end | ||
end | ||
def reset_git(options) | ||
return unless git_configured? options | ||
|
||
begin | ||
@git ||= Git.init | ||
mf_log "CHECKING OUT ORIGINAL BRANCH '#{@orig_branch}'" | ||
@git.checkout(@orig_branch) | ||
rescue Git::GitExecuteError => e | ||
mf_log "Unable to reset git status to branch '#{@orig_branch}'" | ||
raise "Unable to reset git status to branch '#{@orig_branch}'" | ||
end | ||
end | ||
def git_configured?(options) | ||
options.size > 0 && options.has_key?(:githash) | ||
end | ||
def reporter | ||
MetricFu::Reporter.new(MetricFu.configuration.formatters) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
require 'yaml' | ||
require 'fileutils' | ||
require 'git' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove per other comments |
||
module MetricFu | ||
module Utility | ||
module_function | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,8 @@ Gem::Specification.new do |s| | |
s.authors = File.readlines(author_file, :encoding => Encoding::UTF_8).map(&:strip) | ||
|
||
# used with gem i metric_fu -P HighSecurity | ||
s.cert_chain = ['certs/bf4.pem'] | ||
s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/ | ||
#s.cert_chain = ['certs/bf4.pem'] | ||
#s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing you didn't mean to include this in the PR, but I understand why you made it :) |
||
|
||
s.rubyforge_project = 'metric_fu' | ||
s.license = 'MIT' | ||
|
@@ -55,6 +55,8 @@ Gem::Specification.new do |s| | |
s.add_runtime_dependency 'coderay' | ||
# to_json support | ||
s.add_runtime_dependency 'multi_json' | ||
# git support | ||
s.add_runtime_dependency 'git' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather not add a hard dependency on the def select_git_hash
require 'git'
# do stuff
rescue LoadError
STDERR.puts "Cannot select git hash; please install git gem"
exit(1)
end |
||
|
||
# temporary filesystem to act on | ||
s.add_development_dependency 'test-construct' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you feel ambitious, this would be a good place to factor out the notion of "Report Time" (what time in the code the reported metrics were run).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also seems mis-named. It's the filename, not the prefix.