-
Notifications
You must be signed in to change notification settings - Fork 770
feat: limit searching issues based on type #2186
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,15 @@ public GHIssueSearchBuilder isClosed() { | |
| return q("is:closed"); | ||
| } | ||
|
|
||
| /** | ||
| * Filters results to only include issues (excludes pull requests). | ||
| * | ||
| * @return the gh issue search builder | ||
| */ | ||
| public GHIssueSearchBuilder isIssue() { | ||
| return q("is:issue"); | ||
| } | ||
|
|
||
| /** | ||
| * Is merged gh issue search builder. | ||
| * | ||
|
|
@@ -75,6 +84,15 @@ public GHIssueSearchBuilder isOpen() { | |
| return q("is:open"); | ||
| } | ||
|
|
||
| /** | ||
| * Filters results to only include pull requests (excludes issues). | ||
| * | ||
| * @return the gh issue search builder | ||
| */ | ||
| public GHIssueSearchBuilder isPullRequest() { | ||
| return q("is:pr"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method should also ensure that |
||
| } | ||
|
|
||
| /** | ||
| * Mentions gh issue search builder. | ||
| * | ||
|
|
@@ -121,6 +139,19 @@ public GHIssueSearchBuilder q(String term) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Filters results to a specific repository. | ||
| * | ||
| * @param owner | ||
| * the repository owner | ||
| * @param name | ||
| * the repository name | ||
| * @return the gh issue search builder | ||
| */ | ||
| public GHIssueSearchBuilder repo(String owner, String name) { | ||
| return q("repo:" + owner + "/" + name); | ||
| } | ||
|
|
||
| /** | ||
| * Sort gh issue search builder. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -855,6 +855,44 @@ public void testIssueSearch() { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Test issue search with isIssue filter to exclude pull requests. | ||||||||
| */ | ||||||||
| @Test | ||||||||
| public void testIssueSearchIssuesOnly() { | ||||||||
| PagedSearchIterable<GHIssue> r = gitHub.searchIssues() | ||||||||
| .repo("hub4j", "github-api") | ||||||||
| .isIssue() | ||||||||
| .isOpen() | ||||||||
| .sort(GHIssueSearchBuilder.Sort.UPDATED) | ||||||||
| .list(); | ||||||||
| assertThat(r.getTotalCount(), greaterThan(0)); | ||||||||
| for (GHIssue issue : r) { | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway to shorten the return list? If we can test this without storing several pages of json that we don't really care about. |
||||||||
| assertThat(issue.getTitle(), notNullValue()); | ||||||||
| // Verify it's not a PR (pull_request field should be null) | ||||||||
| assertThat(issue.getPullRequest(), nullValue()); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Test issue search with isPullRequest filter to only return pull requests. | ||||||||
| */ | ||||||||
| @Test | ||||||||
| public void testIssueSearchPullRequestsOnly() { | ||||||||
| PagedSearchIterable<GHIssue> r = gitHub.searchIssues() | ||||||||
| .repo("hub4j", "github-api") | ||||||||
| .isPullRequest() | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure that last called wins
Suggested change
|
||||||||
| .isOpen() | ||||||||
| .sort(GHIssueSearchBuilder.Sort.UPDATED) | ||||||||
| .list(); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway to shorten the return list? If we can test this without storing several pages of json that we don't really care about. Maybe |
||||||||
| assertThat(r.getTotalCount(), greaterThan(0)); | ||||||||
| for (GHIssue issue : r) { | ||||||||
| assertThat(issue.getTitle(), notNullValue()); | ||||||||
| // Verify it's a PR (pull_request field should not be null) | ||||||||
| assertThat(issue.getPullRequest(), notNullValue()); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Test issue with comment. | ||||||||
| * | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "login": "Anonycoders", | ||
| "id": 40047636, | ||
| "node_id": "MDQ6VXNlcjQwMDQ3NjM2", | ||
| "avatar_url": "https://avatars.githubusercontent.com/u/40047636?v=4", | ||
| "gravatar_id": "", | ||
| "url": "https://api.github.com/users/Anonycoders", | ||
| "html_url": "https://github.com/Anonycoders", | ||
| "followers_url": "https://api.github.com/users/Anonycoders/followers", | ||
| "following_url": "https://api.github.com/users/Anonycoders/following{/other_user}", | ||
| "gists_url": "https://api.github.com/users/Anonycoders/gists{/gist_id}", | ||
| "starred_url": "https://api.github.com/users/Anonycoders/starred{/owner}{/repo}", | ||
| "subscriptions_url": "https://api.github.com/users/Anonycoders/subscriptions", | ||
| "organizations_url": "https://api.github.com/users/Anonycoders/orgs", | ||
| "repos_url": "https://api.github.com/users/Anonycoders/repos", | ||
| "events_url": "https://api.github.com/users/Anonycoders/events{/privacy}", | ||
| "received_events_url": "https://api.github.com/users/Anonycoders/received_events", | ||
| "type": "User", | ||
| "user_view_type": "public", | ||
| "site_admin": false, | ||
| "name": "Sorena Sarabadani", | ||
| "company": "@Adevinta", | ||
| "blog": "", | ||
| "location": "Berlin, Germany", | ||
| "email": "sorena.sarabadani@gmail.com", | ||
| "hireable": null, | ||
| "bio": "Ex-Shopifyer - Adevinta/Kleinanzeigen", | ||
| "twitter_username": "sorena_s", | ||
| "notification_email": "sorena.sarabadani@gmail.com", | ||
| "public_repos": 12, | ||
| "public_gists": 0, | ||
| "followers": 38, | ||
| "following": 4, | ||
| "created_at": "2018-06-08T02:07:15Z", | ||
| "updated_at": "2026-01-24T22:07:12Z" | ||
| } |
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 method should also ensure that
is:pris removed if present.