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

fix: make bake cmd use default brownie-mix branch #917

Merged
merged 6 commits into from
Jan 3, 2021
Merged

fix: make bake cmd use default brownie-mix branch #917

merged 6 commits into from
Jan 3, 2021

Conversation

skellet0r
Copy link
Collaborator

Previously, brownie bake would assume the master branch was in each
brownie-mix repository. Now it checks the github api to verify the
default branch first.

Resolves #915

What I did

  • Modified MIXES_URL to now require 2 arguments when formatting the string, the project_name and default_branch
  • Created a function _get_mix_default_branch(mix_name: str) -> str, which given the brownie-mix name, returns the default branch for the repository
  • Modified from_brownie_mix function to call _get_mix_default_branch, and include the returned value when formatting MIXES_URL

Related issue: #915

How I did it

I checked stackoverflow for how to find the default branch of a repository. Using the github api docs and curl, I verified that endpoint worked and that default_branch was a key in the json returned. I then created the function _get_mix_default_branch to encapsulate the github api request, and then implemented it in the from_brownie_mix function.

How to verify it

Currently, there are no brownie-mix repositories with a default branch not named master. However, the implementation does not break tests/project/test_brownie_mix.py.

Checklist

  • I have confirmed that my PR passes all linting checks
  • I have included test cases
  • I have updated the documentation
  • I have added an entry to the changelog

Previously, `brownie bake` would assume the master branch was in each
brownie-mix repository. Now it checks the github api to verify the
default branch first.

Resolves #915
Copy link
Collaborator

@matnad matnad left a comment

Choose a reason for hiding this comment

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

Looking good so far, thanks!

@skellet0r
Copy link
Collaborator Author

@matnad Thank you for those reviews, very good catches. Definitely will have to get more acquainted with the code base and customs when contributing. I made those changes with the commits cfc73a1 and 2e16fa5.

matnad
matnad previously approved these changes Jan 1, 2021
Copy link
Collaborator

@matnad matnad left a comment

Choose a reason for hiding this comment

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

Thanks a lot for implementing the requested changes and thanks so much for contributing!
Code-wise this lgtm, but I do have some remarks on style, see below.

Maybe @iamdefinitelyahuman can give some input as well on the style policy and if this needs to be changed. Approval from me 💯

Comment on lines 601 to 603
project_path.parent.joinpath(project_name + "-mix-{}".format(default_branch)).rename(
project_path
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Style wise we generally use f-strings over .format() wherever possible and only use the latter when the string needs to be changed at a later point (as in line 56 and then 592). A simple string such as here should be written as f-string like f"{project_name}-mix-{default_branch}". It helps with readability.

There are more strings in the PR further down that should also be changed from .format() to f-strings.

Comment on lines 986 to 990
msg += (
"\n\nIf this issue persists, generate a Github API token and store"
" it as the environment variable `GITHUB_TOKEN`:\n"
"https://github.blog/2013-05-16-personal-api-tokens/"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid string concatenations with + (this can have unwanted side effects due to not being type safe). Instead use f-strings like msg = f"{msg}\n\nIf...".
I am fully aware that this is not done as rigorous as it should be throughout the code base and you can feel free to change any instances you come accross ;-).

"https://github.blog/2013-05-16-personal-api-tokens/"
)
raise ConnectionError(msg)
elif r.json().get("default_branch") is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer elif "default_branch" not in r.json():

@skellet0r
Copy link
Collaborator Author

@matnad thanks for the remarks, I definitely agree with them as they help with readability down the line, and are in line with the style of the project. I implemented the corrections via d860bb5.
Would be happy to hear @iamdefinitelyahuman's remarks as well, more input is always appreciated.

Copy link
Member

@iamdefinitelyahuman iamdefinitelyahuman left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! Overall I'm happy with the implementation, just a couple places where I'd echo @matnad 's comments re: preference for f-strings over .format. Once those are modified I'm happy to see this merge 🚀

skellet0r and others added 2 commits January 1, 2021 21:11
Corrected by @iamdefinitelyahuman

Co-authored-by: Ben Hauser <35276322+iamdefinitelyahuman@users.noreply.github.com>
Corrected by @iamdefinitelyahuman

Co-authored-by: Ben Hauser <35276322+iamdefinitelyahuman@users.noreply.github.com>
Copy link
Collaborator

@matnad matnad left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks again for the contribution and the prompt changes.
I will add a test for this once we have a new mix repo that doesn't use master.

@iamdefinitelyahuman iamdefinitelyahuman merged commit 4b12faa into eth-brownie:master Jan 3, 2021
@skellet0r skellet0r deleted the fix-mix-branch branch February 12, 2021 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Brownie mixes are assumed to use "master" as primary branch
3 participants