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

add bitbucket repo url handling #1866

Merged
merged 5 commits into from
Jun 5, 2017
Merged

add bitbucket repo url handling #1866

merged 5 commits into from
Jun 5, 2017

Conversation

stubblyhead
Copy link
Contributor

The current master is smart enough to recognize urls for githib repositories/branches/commits and transform them into the url for the corresponding gzip, but it doesn't know how to handle bitbucket urls. I've added a couple of regexes to recognize these patterns, and a few additional elsifs to make the necessary modifications when they're used.

Signed-off-by: Mike Stevenson <Mike.Stevenson@us.logicalis.com>
Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

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

Hey @stubblyhead! Thanks for your first contribution to InSpec!

This seems like a pretty reasonable addition. Could you please add some unit tests to test this new functionality? They would look something like this, which is what we do for GitHub:

https://github.com/chef/inspec/blob/master/test/unit/fetchers/url_test.rb#L61-L91

.gitignore Outdated
@@ -22,7 +22,9 @@ habitat/results
/.direnv
/.envrc
results/

.vagrant/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove changes to the .gitignore file from this PR? If we feel these changes are necessary, I'd like to address them separately. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes definitely. My intent was that my changes to .gitignore would themselves be ignored, but it didn't seem to work out that way. I'll have a go at the unit tests as well.

@stubblyhead
Copy link
Contributor Author

A quick question about the unit tests--I'm not familiar with some of the gems being used in the tests, but if I'm reading things correctly it doesn't actually do an HTTP GET. Assuming that's correct, would that mean it doesn't really matter what urls are being used since it's just testing that the transformations are being applied correctly?

@adamleff
Copy link
Contributor

@stubblyhead did you mean to close this PR?

re: your question, that's correct - the actual outbound HTTP GET is intercepted with these lines:

res = fetcher.resolve(url)
res.expects(:open).returns(mock_open)

That returned a Mock called mock_open that is created here: https://github.com/chef/inspec/blob/master/test/unit/fetchers/url_test.rb#L29-L34

That will prevent the outbound connection and instead leave you free to check that the transformed URL is correct.

@stubblyhead stubblyhead reopened this May 31, 2017
@stubblyhead
Copy link
Contributor Author

Oops sure didn't mean to close this, hit the wrong button when adding my comment. I'll commit my unit tests momentarily.

Signed-off-by: Mike Stevenson <Mike.Stevenson@us.logicalis.com>
Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

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

@stubblyhead awesome tests, thank you! Just need to fix one indentation issue and then I think this is good to go.

http://bitbucket.org/chef/inspec.git
http://www.bitbucket.org/chef/inspec.git}.each do |bitbucket|
it "resolves a bitbucket url #{bitbucket}" do
res = fetcher.resolve(bitbucket)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines 99-104 are indented too far. I realize this is a slight nitpick, but I was initially confused where the enumerator loop ended (i.e. was the test starting at line 106 part of the loop and just outdented incorrectly?) and that shows how important indentation should be :)

99-102 should be indented 2 spaces in from the it in line 98, the end on 103 should line up with the it on 98, and the end on 104 should line up with the %w on 92.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Mike Stevenson added 2 commits June 1, 2017 08:30
Signed-off-by: Mike Stevenson <Mike.Stevenson@us.logicalis.com>
Signed-off-by: Mike Stevenson <Mike.Stevenson@us.logicalis.com>
@adamleff
Copy link
Contributor

adamleff commented Jun 5, 2017

@stubblyhead this looks great, thank you for your contribution! I'm rerunning the two failed Travis tests now which should go green - the failures are unrelated to your changes.

NOTE TO NEXT APPROVER: this should be squashed via GitHub instead of merged.

@adamleff adamleff self-assigned this Jun 5, 2017
Copy link
Contributor

@arlimus arlimus left a comment

Choose a reason for hiding this comment

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

Well done, thank you @stubblyhead for adding Bitbucket support!!
Kudos @adamleff for the review and support

@arlimus arlimus merged commit ba0a1ea into inspec:master Jun 5, 2017
@adamleff adamleff added the Type: Enhancement Improves an existing feature label Jun 5, 2017
aaronlippold pushed a commit to aaronlippold/inspec that referenced this pull request Jun 8, 2017
* add bitbucket repo url handling

Signed-off-by: Mike Stevenson <Mike.Stevenson@us.logicalis.com>

* backout changes to .gitignore

* adding unit tests for bitbucket url transformers

Signed-off-by: Mike Stevenson <Mike.Stevenson@us.logicalis.com>

* fixing some indents

Signed-off-by: Mike Stevenson <Mike.Stevenson@us.logicalis.com>

* fix some indents

Signed-off-by: Mike Stevenson <Mike.Stevenson@us.logicalis.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants