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
utils/github: set default args to search_code #10363
utils/github: set default args to search_code #10363
Conversation
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.
Nice work so far @hyuraku!
Library/Homebrew/utils/github.rb
Outdated
@@ -309,8 +309,8 @@ def repository(user, repo) | |||
open_api(url_to("repos", user, repo)) | |||
end | |||
|
|||
def search_code(**qualifiers) | |||
matches = search("code", **qualifiers) | |||
def search_code(user: "Homebrew", path: ["Formula", "Casks", "."], filename: nil, extension: "rb") |
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 think these defaults except filename: nil
are better kept in the search.rb
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 don't think it makes sense to use keyword arguments here since this should support all fields supported by GitHub search. Also I think there may definitely be some places in other repos where repo
is 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.
I think Homebrew::Search.search_taps
can pass only query
to GitHub.search_code
and it easier to read when I set default keyword args.
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.
While I couldn't seem to find usage of search_code
with the repo
field (in Homebrew/brew), I agree with @reitermarkus that the method should support all fields that GitHub's search does. We probably shouldn't be removing the ability to use these keys based on just the usage in search_taps
.
Library/Homebrew/utils/github.rb
Outdated
def search_code(**qualifiers) | ||
matches = search("code", **qualifiers) | ||
def search_code(user: "Homebrew", path: ["Formula", "Casks", "."], filename: nil, extension: "rb") | ||
matches = search("code", **{ user: user, path: path, filename: filename, extension: extension }) |
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.
Would be nicer to pass these as actual keyword arguments too, perhaps?
Library/Homebrew/utils/github.rb
Outdated
@@ -309,8 +309,8 @@ def repository(user, repo) | |||
open_api(url_to("repos", user, repo)) | |||
end | |||
|
|||
def search_code(**qualifiers) | |||
matches = search("code", **qualifiers) | |||
def search_code(user: "Homebrew", path: ["Formula", "Casks", "."], filename: nil, extension: "rb") |
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 think these defaults except filename: nil
are better kept in the search.rb
c40305a
to
6fcb74d
Compare
@@ -6,8 +6,7 @@ | |||
describe GitHub do | |||
describe "::search_code", :needs_network do | |||
it "queries GitHub code with the passed parameters" do | |||
results = described_class.search_code(repo: "Homebrew/brew", path: "/", |
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.
remove repo
and language
because these keywords are not used in search.rb
@hyuraku Can you try to fix up the |
Yes, I'll fix and |
352e023
to
f54ef29
Compare
expect(results.count).to eq(1) | ||
expect(results.count).to eq(29) |
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.
Hmm, this looks like it's changed behaviour if the results count has increased by so much?
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.
This change retrieves README.md files (present at /README.md) from the 29 public repositories rather than just from Homebrew/brew.
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 think the previous test was more in line with real-world usage. It's more likely that we search a specific repo rather than all in the org.
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.
@hyuraku Please update this so the test no longer requires eq(29)
, thanks!
f54ef29
to
b997e7e
Compare
expect(results.first["name"]).to eq("README.md") | ||
expect(results.first["path"]).to eq("README.md") | ||
expect(results.first["name"]).to eq("1password-cli.rb") | ||
expect(results.first["path"]).to eq("Casks/1password-cli.rb") |
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.
Please leave this as-is; I'd like to see this PR not require any test changes.
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.
Sorry, I'll reset this test.
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.
No problem!
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.
@hyuraku Any news here?
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.
@MikeMcQuaid
I just updated!
b997e7e
to
defa4af
Compare
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.
Looks like test still failing unfortunately 😭
defa4af
to
178ae75
Compare
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.
LGTM, thanks @hyuraku!
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?brew man
locally and committed any changes?set default args to
def search_code
inutils/github