-
Notifications
You must be signed in to change notification settings - Fork 475
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
Changes from 2 commits
fa09e05
d8d1f2d
7d0b4be
171293c
32bc182
6f29ae0
c132d74
6458ab4
95d56c6
0719140
b730589
456ff79
41a5939
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 |
---|---|---|
@@ -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 | ||
|
||
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. 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) | ||
|
||
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. 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 | ||
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. unexpected token tLBRACK2 |
||
self.head_commit = pr_merge.parents.[1].sha | ||
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. unexpected token tLBRACK2 |
||
end | ||
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. What happens on 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'll do a full pass on error reporting once I've got a working concept 👍 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. 👍 |
||
end | ||
end | ||
end | ||
end |
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 = | ||
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. Trailing whitespace detected. |
||
dm.env.fill_environment_vars | ||
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. Indent the first parameter one step more than the start of the previous line. |
||
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 |
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.
tried to make this work like cocoapods, but I'm missing something
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.
CocoaPods shows the sub-commands
Danger doesn't