-
Notifications
You must be signed in to change notification settings - Fork 144
Add Code Search #120
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 Code Search #120
Conversation
Is this ready to merge? |
Not yet, I'd like to make a code search example and verify everything works as expected. |
@Pacane @georgelesica-wf Ready for review and testing |
don't merge yet .. reworking catching rate limit errors |
example/index.html
Outdated
<p> | ||
Github Token: <input type="text" id="token" size="50"> | ||
<button id=removeTokenBtn>Clear Github Token</button> | ||
</p> |
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.
Switched to localStorage to preserve your token longer and provide a clear button to remove it.
Ok, cleaned up and now using json_serializable. I tested rate limiting and searching with all the options. Ready for review again. |
lib/src/common/search_service.dart
Outdated
// into the first CodeSearchResults and complete with the combined results | ||
if (results.length > 1) { | ||
for (int i = 1; i < results.length; i++) { | ||
results[0].items.addAll(results[i].items); |
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 know much about the context, but this doesn't look right..?
You have a list of CodeSearchResults and you always add them to the same index. Does that mean we could return a single CodeSearchResult?
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.
That's right. The code search results can be multiple pages of responses, so up on L123 each CodeSearchResults is added to a list. Then once all the page responses are done and added to the list, in this onDone handler it takes all of the items from each CodeSearchResults "page" and appends them onto the first one. Then we complete the future on L132 with just the first CodeSearchResult in the list. That's the one that has the complete list of items returned from all pages.
Maybe all this would make a good code comment? ^
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.
Oh, you know what .. your question made me think more about this. Having it iterate and accumulate the responses internally means it will eagerly fetch all the pages. To be more consistent with other parts of the API, I think the code search should return Stream<CodeSearchResults>
instead and leave it up to the consumer to pull as many responses from the stream as they want.
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.
That's what I was thinking about. I was gonna write an example of how I'd see this done, but yeah.
@Pacane Another consideration is the default number of pages (2) and results per page (30) mean that, by default, you will only get 60 results even if there are more matches. I'm not happy with the API at this point. Ideally, I'd like to not have to specify the number of pages up front and be limited in the results. I'd prefer to get back a controlling "search" object that you can simply ask for more results if you want them and cancel and bail if you don't .. but not have to start over with a whole new search. |
@Pacane @georgelesica-wf I'm ok with this API. How do you feel about it? |
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.
That looks much better! Great job
Can this be merged or do you still have stuff to do on this PR? |
We should squash-merge this so the history stays pretty 😄 |
@robbecker-wf – would you rebase and clean up this PR? you mixed some tweaks to the HTML example w/ the cod search changes |
@robbecker-wf – you'll have to rebase anyway, since I pulled in pkg:meta, too 😄 |
Sure, I'll pull out the example changes to a new PR and squish things. |
# Conflicts: # lib/src/common.dart # lib/src/common.g.dart # pubspec.yaml
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 version?
@@ -9,6 +9,10 @@ | |||
- Made associated classes `ContributorStatistics` and | |||
`ContributorWeekStatistics` immutable. Since these classes are only meant as | |||
return values, we're not treating this as a breaking change. | |||
- Added `Stream<CodeSearchResults> github.search.code(...)` search API |
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 there are new changes, this should be 4.1, right?
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.
Squash is best – or do the rebase locally to create one commit
…On Wed, Jan 9, 2019 at 8:43 PM Rob Becker ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In CHANGELOG.md
<#120 (comment)>
:
> @@ -9,6 +9,10 @@
- Made associated classes `ContributorStatistics` and
`ContributorWeekStatistics` immutable. Since these classes are only meant as
return values, we're not treating this as a breaking change.
+- Added `Stream<CodeSearchResults> github.search.code(...)` search API
Yeah, I suppose it should be 4.1. I'll bump the version in this PR.
Whoever merges are you ok using the github squash or rebase and merge
functionality or would you rather I squash and forcepush?
[image: image]
<https://user-images.githubusercontent.com/6053699/50946617-7b9b5b00-1457-11e9-98d4-f50d0d8d55cf.png>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#120 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABCihKnBVlahjy9bZ6NahkwNfF-4O03ks5vBsTagaJpZM4YRUFC>
.
|
@@ -1,5 +1,5 @@ | |||
name: github | |||
version: 4.0.2-dev | |||
version: 4.1.0 |
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.
...and in the changelog!
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.
🤦♂️
rock! |
Thank you! |
Overview
This adds support for code search to finish the code search part of #92
https://developer.github.com/v3/search/#search-code
Testing
pub run build_runner serve example
http://localhost:8080/search.html