-
Notifications
You must be signed in to change notification settings - Fork 78
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
(RE-6200) URI parsing, Source handling, Git cloning #394
Conversation
@@ -317,11 +317,11 @@ def build_dir(path) | |||
|
|||
# This will add a source to the project and put it in the workdir alongside the other sources | |||
# | |||
# @param url [String] url of the source | |||
# @param uri [String] uri of the source |
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.
Update docs here
time bundle exec build puppet-agent el-7-x86_64 Error loading project 'puppet-agent' using '/home/stahnma/puppet-agent/configs/projects/puppet-agent.rb': undefined method `git_version' for Vanagon::Utilities:Module /home/stahnma/vanagon/lib/vanagon/project/dsl.rb:147:in `version_from_git' /home/stahnma/vanagon/lib/vanagon/project.rb:169:in `block in load_project' /home/stahnma/vanagon/lib/vanagon/project/dsl.rb:26:in `call' /home/stahnma/vanagon/lib/vanagon/project/dsl.rb:26:in `project' /home/stahnma/vanagon/lib/vanagon/project.rb:28:in `load_project' /home/stahnma/vanagon/lib/vanagon/project.rb:28:in `instance_eval' /home/stahnma/vanagon/lib/vanagon/project.rb:28:in `load_project' /home/stahnma/vanagon/lib/vanagon/driver.rb:26:in `initialize' /home/stahnma/vanagon/bin/build:27:in `new' /home/stahnma/vanagon/bin/build:27:in `block in ' /home/stahnma/vanagon/bin/build:25:in `each' /home/stahnma/vanagon/bin/build:25:in `' /home/stahnma/.gem/ruby/bin/build:23:in `load' /home/stahnma/.gem/ruby/bin/build:23:in `' /home/stahnma/vanagon/lib/vanagon/project/dsl.rb:147:in `version_from_git': undefined method `git_version' for Vanagon::Utilities:Module (NoMethodError) from /home/stahnma/vanagon/lib/vanagon/project.rb:169:in `block in load_project' from /home/stahnma/vanagon/lib/vanagon/project/dsl.rb:26:in `call' from /home/stahnma/vanagon/lib/vanagon/project/dsl.rb:26:in `project' from /home/stahnma/vanagon/lib/vanagon/project.rb:28:in `load_project' from /home/stahnma/vanagon/lib/vanagon/project.rb:28:in `instance_eval' from /home/stahnma/vanagon/lib/vanagon/project.rb:28:in `load_project' from /home/stahnma/vanagon/lib/vanagon/driver.rb:26:in `initialize' from /home/stahnma/vanagon/bin/build:27:in `new' from /home/stahnma/vanagon/bin/build:27:in `block in ' from /home/stahnma/vanagon/bin/build:25:in `each' from /home/stahnma/vanagon/bin/build:25:in `' from /home/stahnma/.gem/ruby/bin/build:23:in `load' from /home/stahnma/.gem/ruby/bin/build:23:in `' real 0m0.581s user 0m0.528s sys 0m0.050s I also had to update the vanagon.gemspec to include fuistigit |
def add_source(url, ref: nil, sum: nil) | ||
@component.sources << OpenStruct.new(:url => url, :ref => ref, :sum => sum) | ||
def add_source(uri, **options) | ||
@component.sources << OpenStruct.new(options) |
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.
I hate that we're using OpenStruct here, because it means that there's really no documentation about what kind of object (or structure) we SHOULD be pushing into @component.sources
here. I had to fish around for #add_source
to figure out what is expected of each source
we push into @component.sources
.
As a prelude to fixing RE-6200 (Unable to use https source of a github repo), Vanagon::Component::Source is being restructured. - Changed class variable to class instance variable - Added class accessor for @rewrite_rules - Updated spec test to use the accessor instead of directly calling the class var - Changed from self. method declaration to reopening the class (In preparation for adding private helper methods)
This should help clarify intent, and is done in preparation for rewriting the `git` utility.
This makes them easier to use from within classes without having to `include Vanagon::Utilities` to get access to them.
I don't know why we didn't do this sooner but this is a convenience alias. It's less typing and it's a name we'd expect that functionality to be exposed under,
In preparation for moving the Git functionality into the Vanagon::Component::Source::Git class, here's some new and interesting Error classes that will be used for meaningful error messages. * Vanagon::GitError * Vanagon::InvalidRepo * Vanagon::UnknownRef * Vanagon::UnknownSha * Vanagon::CheckoutFailed
`git` methods have been removed from Vanagon::Utilities, and confined to the Vanagon::Component::Source::Git class (nothing outside of the Source subclass uses them).
Still needs
I've decided that we don't need the |
def valid_remote?(url) | ||
!!::Git.ls_remote(url) | ||
rescue ::Git::GitExecuteError | ||
nil |
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.
Since you're making it a boolean (in the yard, and explicitly above), should this return false
instead?
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.
Yeah, that makes some sense.
did you consider using refinements instead of monkey patching? |
Ruby 2.2/2.3 docs state:
They might work for this particular use case but it's a crapshoot. EditNone of the monkey-patched methods are overwriting existing behaviors in this PR. It's worth investigating porting them to refinements, but they should be generally safe. |
This is part of a work-in-progress for Vanagon::Component::Source, which will remove the rewrite functionality. This involves stronger use of keyword arguments but should preserve the DSL. This commit also introduces a dependency on the Fustigit gem, which is a utility that makes parsing triplet-style git URIs viable.
Lower-case 'e' will only work on case-insensitive filesystems. Uppder-case 'E' is the case you want.
Fustigit has been updated, and moved to the Gemspec. Basic comments have been added to both the Gemspec and the Gemfile to clarify intent a little bit.
Gems should be in EITHER Gemfile or the Gemspec, but not both.
Ruby-Git might not be the One True Git Library that solves all of our needs but it's generally better than abstracting out "%x()"-wrapped calls to Git ourselves. I've extended it slightly to support Git submodules and unshallowing repos that were shallow-cloned but we're now using it basically as-is. In theory, this will potentially make porting to a different Git library (like Rugged) easier, since we've just got a handful of composed functions instead of an entire implementation to port.
Disable Metrics/AbcSize for a handful of functions, and add a target Ruby version to .rubocop.yml (Ruby 2.1 API compatibility is our target, by the way).
@mckern are you planning to squash/clean commits more than this or is this what you want for final review? |
@stahnma I want to add a doc commit today but I wasn't planning to squash/rebase any more than this. These commits have a fair amount of churn in them so the best I could probably do would be to flatten it into one commit. I think we lose some important history here but I am open to being persuaded. |
FWIW I really don't think we should squash most of these. In the near future we may need to fix/update major parts to fit our needs and having the commit history will allow us to understand the original iterations and thought process so we can avoid the process of making a decision Ryan already realized was not going to work. |
|
Trying to build el-7-x86_64 off of PA stable. https://gist.github.com/stahnma/9df32ad6a8a510abaa03eb98a9469ab2 |
@mckern yea, monkey patching the gem is pretty safe. if it were touching anything from ruby core i'd be much more interested in limiting the scope of the effect. |
@stahnma thanks for helping test things off the happy path. You caught a thing I'd missed. Fixed and testing now. |
Local sources have had some work done around how archives are handled and local files are moved around. HTTP and Local sources have a lot of overlap in their workflow, since HTTP sources are basically just Local sources with a remote fetch in the mix. As HTTP now inherits from Local, this should reduce a substantial amount of code duplication while letting HTTP sources benefit from the refactoring.
The original plan was to have a "best guess or specific definition" for initializing a new Source object. But the "best guess" functionality now relies on the Source subclasses providing some sort of "is this valid?" functionality that was not part of the original plan. With this new functionality the "best guess or specific definition" plan is abandoned.
The rewrite engine has a glaring flaw: it previous treated 'http' and 'https' sources as equivilent and applied all 'http' rules to any 'https' sources. This is dumb, but it's behavior we have to preserve until the engine is gone.
It's harder than you think it is.
# is not smart, and it has very poor support for submodule options. | ||
# For example, you can't pass any arguments to the handful of submodule | ||
# options that accept them (like --depth). We may extend it later, | ||
# but for rev. 0001, simply initializing them will suffice |
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.
It might be useful to have an example of how this method will be used
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.
Done.
Added a little yardoc to the extension for the Ruby-Git library.
High Level BreakdownGit
HTTP source handling
Local source handling
|
👍 on everything, I believe with spec tests and all, this is ready for merge |
(MAINT) Update CHANGELOG for PR #394
I started refactoring how
Vanagon::Component::Source
works... and wound up making sweeping revisions to source handling in general. There's probably more to come, but I wanted to get people looking at this before it gets even larger and more difficult to grok. Spec tests pass, but coverage is incomplete so I'd like to start testing this out before anyone even considers merging it.