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

utils/github: set default args to search_code #10363

Merged
merged 1 commit into from Feb 26, 2021

Conversation

hyuraku
Copy link
Contributor

@hyuraku hyuraku commented Jan 19, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?
  • Have you successfully run brew man locally and committed any changes?

set default args to def search_code in utils/github

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a 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!

@@ -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")
Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

@hyuraku hyuraku Jan 22, 2021

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.

Copy link
Member

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.

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 })
Copy link
Member

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?

@@ -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")
Copy link
Member

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

@hyuraku hyuraku force-pushed the utils/github_set_default_args branch from c40305a to 6fcb74d Compare January 19, 2021 15:18
@@ -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: "/",
Copy link
Contributor Author

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

@MikeMcQuaid
Copy link
Member

@hyuraku Can you try to fix up the brew tests failures? Thanks!

@hyuraku
Copy link
Contributor Author

hyuraku commented Feb 2, 2021

@hyuraku Can you try to fix up the brew tests failures? Thanks!

Yes, I'll fix and brew tests --online

@hyuraku hyuraku force-pushed the utils/github_set_default_args branch from 352e023 to f54ef29 Compare February 2, 2021 13:10
Comment on lines 12 to 11
expect(results.count).to eq(1)
expect(results.count).to eq(29)
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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!

@hyuraku hyuraku force-pushed the utils/github_set_default_args branch from f54ef29 to b997e7e Compare February 8, 2021 11:37
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")
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

No problem!

Copy link
Member

Choose a reason for hiding this comment

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

@hyuraku Any news here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MikeMcQuaid
I just updated!

@hyuraku hyuraku force-pushed the utils/github_set_default_args branch from b997e7e to defa4af Compare February 26, 2021 12:10
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a 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 😭

@hyuraku hyuraku force-pushed the utils/github_set_default_args branch from defa4af to 178ae75 Compare February 26, 2021 12:43
Copy link
Member

@MikeMcQuaid MikeMcQuaid 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 @hyuraku!

@MikeMcQuaid MikeMcQuaid merged commit f698bb1 into Homebrew:master Feb 26, 2021
@hyuraku hyuraku deleted the utils/github_set_default_args branch February 27, 2021 03:40
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Mar 29, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Mar 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants