Skip to content
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

Support a danger local command #40

Merged
merged 13 commits into from
Feb 12, 2016
2 changes: 1 addition & 1 deletion lib/danger.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "danger/version"
require "danger/dangerfile"
require "danger/environment_manager"
require "danger/runner"
require "danger/commands/runner"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried to make this work like cocoapods, but I'm missing something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CocoaPods shows the sub-commands

~/d/r/l/danger (local_test) ⏛  pod --help
Usage:

    $ pod COMMAND

      CocoaPods, the Cocoa library package manager.

Commands:

    + cache          Manipulate the CocoaPods cache
    + deintegrate    Deintegrate CocoaPods from your project.
    + dependencies   Show project's dependency graph.

Danger doesn't

~/d/r/l/danger (local_test) ⏛  bundle exec danger --help
Usage:

    $ danger COMMAND

      Run the Dangerfile.

Options:

    --version   Show the version of the tool
    --verbose   Show more debugging information

require "danger/init"
require "danger/available_values"

Expand Down
43 changes: 43 additions & 0 deletions lib/danger/ci_source/local_git_repo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# For more info see: https://github.com/schacon/ruby-git

require 'git'
require 'uri'

module Danger
module CISource
class LocalGitRepo < CI

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body beginning.

# Never validate, it's not useful in production
def self.validates?(env)
false
end

def initialize(env)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at method body beginning.

git = Git.open(".")
if git.remote("origin")
url = git.remote("origin").url
# deal with https://
if url.starts_with "https://github.com/"
self.repo_slug = url.replace("https://github.com/", "").replace(".git", '')

# deal with SSH origin
elsif url.starts_with "git@github.com:"
self.repo_slug = url.replace("git@github.com:", "").replace(".git", '')
end
end

logs = git.log.since('2 weeks ago')
# Look for something like
# "Merge pull request #38 from KrauseFx/funky_circles\n\nAdd support for GitHub compare URLs that don't conform
pr_merge = logs.detect { |log| (/Merge pull request #[0-9]* from/ =~ log.message) == 0 }
if pr_merge
# then pull out the 38, to_i
self.pull_request_id = pr_merge.replace("Merge pull request #", "").to_i
self.base_commit = pr_merge.parents.[0].sha

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token tLBRACK2
(Using Ruby 2.3 parser; configure using TargetRubyVersion parameter, under AllCops)

self.head_commit = pr_merge.parents.[1].sha

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token tLBRACK2
(Using Ruby 2.3 parser; configure using TargetRubyVersion parameter, under AllCops)

end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens on else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do a full pass on error reporting once I've got a working concept 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end
end
end
end
35 changes: 35 additions & 0 deletions lib/danger/commands/local.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Danger
class Local < Runner
self.description = 'Run the Dangerfile locally.'
self.command = 'local'

def initialize(argv)
@dangerfile_path = "Dangerfile" if File.exist? "Dangerfile"
super
end

def validate!
super
unless @dangerfile_path
help! "Could not find a Dangerfile."
end
end

def run
# The order of the following commands is *really* important
dm = Dangerfile.new
dm.env = EnvironmentManager.new(ENV)
dm.env.ci_source =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

dm.env.fill_environment_vars

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the first parameter one step more than the start of the previous line.
Indent the first line of the right-hand-side of a multi-line assignment.

dm.env.scm.diff_for_folder(".", dm.env.ci_source.base_commit, dm.env.ci_source.head_commit)
dm.parse Pathname.new(@dangerfile_path)

post_results(dm)
end

def post_results(dm)
gh = dm.env.request_source
gh.update_pull_request!(warnings: dm.warnings, errors: dm.errors, messages: dm.messages)
end
end
end
File renamed without changes.