Skip to content

Commit

Permalink
Change GHRepository#searchPullRequests to return buider
Browse files Browse the repository at this point in the history
  • Loading branch information
kgromov committed Nov 11, 2023
1 parent e0cb1b2 commit 8d9b194
Show file tree
Hide file tree
Showing 98 changed files with 2,831 additions and 2,831 deletions.
17 changes: 11 additions & 6 deletions src/main/java/org/kohsuke/github/GHPullRequestSearchBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ public class GHPullRequestSearchBuilder extends GHSearchBuilder<GHPullRequest> {
super(root, PullRequestSearchResult.class);
}

/**
* Instantiates a new GH search builder from repository.
*
* @param repository
* the gh repository
*/
GHPullRequestSearchBuilder(GHRepository repository) {
super(repository.root(), PullRequestSearchResult.class);
this.repo(repository);
}

/**
* Repository gh pull request search builder.
*
Expand Down Expand Up @@ -472,12 +483,6 @@ public enum Sort {

}

static GHPullRequestSearchBuilder from(GHPullRequestSearchBuilder searchBuilder) {
GHPullRequestSearchBuilder builder = new GHPullRequestSearchBuilder(searchBuilder.root());
searchBuilder.terms.forEach(builder::q);
return builder;
}

private static class PullRequestSearchResult extends SearchResult<GHPullRequest> {

private GHPullRequest[] items;
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1704,12 +1704,10 @@ public GHPullRequestQueryBuilder queryPullRequests() {
/**
* Retrieves pull requests according to search terms.
*
* @param search
* {@link GHPullRequestSearchBuilder}
* @return pull requests as the paged iterable
* @return gh pull request search builder for current repository
*/
public PagedSearchIterable<GHPullRequest> searchPullRequests(GHPullRequestSearchBuilder search) {
return GHPullRequestSearchBuilder.from(search).repo(this).list();
public GHPullRequestSearchBuilder searchPullRequests() {
return new GHPullRequestSearchBuilder(this);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kohsuke/github/GHSearchBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
Expand All @@ -19,7 +19,7 @@
public abstract class GHSearchBuilder<T> extends GHQueryBuilder<T> {

/** The terms. */
protected final List<String> terms = new ArrayList<String>();
protected final Set<String> terms = new LinkedHashSet<>();

/**
* Data transfer object that receives the result of search.
Expand Down
57 changes: 27 additions & 30 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1753,76 +1753,73 @@ public void testSearchPullRequests() throws Exception {
Thread.sleep(1000);

// search by states
GHPullRequestSearchBuilder search = gitHub.searchPullRequests().repo(repository).isOpen().isDraft();
PagedSearchIterable<GHPullRequest> searchResult = repository.searchPullRequests(search);
GHPullRequestSearchBuilder search = repository.searchPullRequests().isOpen().isDraft();
PagedSearchIterable<GHPullRequest> searchResult = search.list();
this.verifySingleResult(searchResult, draftPR);

search = gitHub.searchPullRequests().repo(repository).isClosed().isMerged();
searchResult = repository.searchPullRequests(search);
search = repository.searchPullRequests().isClosed().isMerged();
searchResult = search.list();
this.verifySingleResult(searchResult, mergedPR);

// search by dates
LocalDate from = LocalDate.parse("2023-09-01");
LocalDate to = LocalDate.parse("2023-09-12");
LocalDate afterRange = LocalDate.parse("2023-09-14");
LocalDate from = LocalDate.parse("2023-11-01");
LocalDate to = LocalDate.parse("2023-11-11");
LocalDate afterRange = LocalDate.parse("2023-11-12");

search = gitHub.searchPullRequests()
.repo(repository)
search = repository.searchPullRequests()
.created(from, to)
.updated(from, to)
.sort(GHPullRequestSearchBuilder.Sort.UPDATED);
searchResult = repository.searchPullRequests(search);
searchResult = search.list();
this.verifyPluralResult(searchResult, mergedPR, draftPR);

search = gitHub.searchPullRequests().repo(repository).merged(from, to).closed(from, to);
searchResult = repository.searchPullRequests(search);
search = repository.searchPullRequests().merged(from, to).closed(from, to);
searchResult = search.list();
this.verifySingleResult(searchResult, mergedPR);

search = gitHub.searchPullRequests().repo(repository).created(to).updated(to).closed(to).merged(to);
searchResult = repository.searchPullRequests(search);
search = repository.searchPullRequests().created(to).updated(to).closed(to).merged(to);
searchResult = search.list();
this.verifySingleResult(searchResult, mergedPR);

search = gitHub.searchPullRequests()
.repo(repository)
search = repository.searchPullRequests()
.createdAfter(from, false)
.updatedAfter(from, false)
.mergedAfter(from, true)
.closedAfter(from, true);
searchResult = repository.searchPullRequests(search);
searchResult = search.list();
this.verifySingleResult(searchResult, mergedPR);

search = gitHub.searchPullRequests()
.repo(repository)
search = repository.searchPullRequests()
.createdBefore(afterRange, false)
.updatedBefore(afterRange, false)
.closedBefore(afterRange, true)
.mergedBefore(afterRange, false);
searchResult = repository.searchPullRequests(search);
searchResult = search.list();
this.verifySingleResult(searchResult, mergedPR);

// search by version control
Map<String, GHBranch> branches = repository.getBranches();
search = gitHub.searchPullRequests()
search = repository.searchPullRequests()
.base(branches.get("main"))
.head(branches.get("branchToMerge"))
.commit(commit.getCommit().getSha());
searchResult = repository.searchPullRequests(search);
searchResult = search.list();
this.verifySingleResult(searchResult, mergedPR);

// search by remaining filters
search = gitHub.searchPullRequests()
.repo(repository)
search = repository.searchPullRequests()
.titleLike("Temp")
.sort(GHPullRequestSearchBuilder.Sort.CREATED);
searchResult = repository.searchPullRequests(search);
.sort(GHPullRequestSearchBuilder.Sort.CREATED)
.order(GHDirection.ASC);
searchResult = search.list();
this.verifyPluralResult(searchResult, draftPR, mergedPR);

search = gitHub.searchPullRequests().repo(repository).inLabels(Arrays.asList("test")).order(GHDirection.DESC);
searchResult = repository.searchPullRequests(search);
search = repository.searchPullRequests().inLabels(Arrays.asList("test")).order(GHDirection.DESC);
searchResult = search.list();
this.verifyPluralResult(searchResult, mergedPR, draftPR);

search = gitHub.searchPullRequests().repo(repository).assigned(myself).mentions(myself);
searchResult = repository.searchPullRequests(search);
search = repository.searchPullRequests().assigned(myself).mentions(myself);
searchResult = search.list();
this.verifySingleResult(searchResult, mergedPR);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": 690788336,
"node_id": "R_kgDOKSyX8A",
"id": 717269122,
"node_id": "R_kgDOKsCogg",
"name": "temp-testSearchPullRequests",
"full_name": "kgromov/temp-testSearchPullRequests",
"private": false,
Expand Down Expand Up @@ -64,9 +64,9 @@
"labels_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/labels{/name}",
"releases_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/releases{/id}",
"deployments_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/deployments",
"created_at": "2023-09-12T22:06:32Z",
"updated_at": "2023-09-12T22:06:33Z",
"pushed_at": "2023-09-12T22:06:33Z",
"created_at": "2023-11-11T00:45:13Z",
"updated_at": "2023-11-11T00:45:13Z",
"pushed_at": "2023-11-11T00:45:13Z",
"git_url": "git://github.com/kgromov/temp-testSearchPullRequests.git",
"ssh_url": "[email protected]:kgromov/temp-testSearchPullRequests.git",
"clone_url": "https://github.com/kgromov/temp-testSearchPullRequests.git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
"name": "branchToMerge",
"commit": {
"sha": "e70ac92dc8a342daed5784b3bd54c1185813b982",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/commits/e70ac92dc8a342daed5784b3bd54c1185813b982"
"sha": "f06ea132e5c97d4237ac3ff717944791eb142ff1",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/commits/f06ea132e5c97d4237ac3ff717944791eb142ff1"
},
"protected": false,
"protection": {
Expand All @@ -19,8 +19,8 @@
{
"name": "draft",
"commit": {
"sha": "6fd9e8a226f0f48a6ac203adc8f13abca5afe875",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/commits/6fd9e8a226f0f48a6ac203adc8f13abca5afe875"
"sha": "030821b0eeed4bdaa271ad36ab1c7c20b778a7aa",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/commits/030821b0eeed4bdaa271ad36ab1c7c20b778a7aa"
},
"protected": false,
"protection": {
Expand All @@ -36,8 +36,8 @@
{
"name": "main",
"commit": {
"sha": "ce18a7029a8faa65ccced3c22eff7235fdc14887",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/commits/ce18a7029a8faa65ccced3c22eff7235fdc14887"
"sha": "5316172f4450c481017e8c4ef2b299da23ee1c6c",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/commits/5316172f4450c481017e8c4ef2b299da23ee1c6c"
},
"protected": false,
"protection": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
}
},
"commit": {
"sha": "e70ac92dc8a342daed5784b3bd54c1185813b982",
"node_id": "C_kwDOKSyX8NoAKGU3MGFjOTJkYzhhMzQyZGFlZDU3ODRiM2JkNTRjMTE4NTgxM2I5ODI",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/e70ac92dc8a342daed5784b3bd54c1185813b982",
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests/commit/e70ac92dc8a342daed5784b3bd54c1185813b982",
"sha": "f06ea132e5c97d4237ac3ff717944791eb142ff1",
"node_id": "C_kwDOKsCogtoAKGYwNmVhMTMyZTVjOTdkNDIzN2FjM2ZmNzE3OTQ0NzkxZWIxNDJmZjE",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/f06ea132e5c97d4237ac3ff717944791eb142ff1",
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests/commit/f06ea132e5c97d4237ac3ff717944791eb142ff1",
"author": {
"name": "Konstantin Gromov",
"email": "[email protected]",
"date": "2023-09-12T22:06:39Z"
"date": "2023-11-11T00:45:19Z"
},
"committer": {
"name": "Konstantin Gromov",
"email": "[email protected]",
"date": "2023-09-12T22:06:39Z"
"date": "2023-11-11T00:45:19Z"
},
"tree": {
"sha": "4ee65e01709145c6b4bf30792e9a3c233433eb8e",
Expand All @@ -37,9 +37,9 @@
"message": "test search",
"parents": [
{
"sha": "33d4c1629baf1fc0c127839c7d605547daece11e",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/33d4c1629baf1fc0c127839c7d605547daece11e",
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests/commit/33d4c1629baf1fc0c127839c7d605547daece11e"
"sha": "34b361864cacfbd165af1b06a659113099da1f38",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/34b361864cacfbd165af1b06a659113099da1f38",
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests/commit/34b361864cacfbd165af1b06a659113099da1f38"
}
],
"verification": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
}
},
"commit": {
"sha": "6fd9e8a226f0f48a6ac203adc8f13abca5afe875",
"node_id": "C_kwDOKSyX8NoAKDZmZDllOGEyMjZmMGY0OGE2YWMyMDNhZGM4ZjEzYWJjYTVhZmU4NzU",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/6fd9e8a226f0f48a6ac203adc8f13abca5afe875",
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests/commit/6fd9e8a226f0f48a6ac203adc8f13abca5afe875",
"sha": "030821b0eeed4bdaa271ad36ab1c7c20b778a7aa",
"node_id": "C_kwDOKsCogtoAKDAzMDgyMWIwZWVlZDRiZGFhMjcxYWQzNmFiMWM3YzIwYjc3OGE3YWE",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/030821b0eeed4bdaa271ad36ab1c7c20b778a7aa",
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests/commit/030821b0eeed4bdaa271ad36ab1c7c20b778a7aa",
"author": {
"name": "Konstantin Gromov",
"email": "[email protected]",
"date": "2023-09-12T22:06:38Z"
"date": "2023-11-11T00:45:18Z"
},
"committer": {
"name": "Konstantin Gromov",
"email": "[email protected]",
"date": "2023-09-12T22:06:38Z"
"date": "2023-11-11T00:45:18Z"
},
"tree": {
"sha": "9b8530865b0a85f155bc5637a0a066995e518cc2",
Expand All @@ -37,9 +37,9 @@
"message": "test search",
"parents": [
{
"sha": "33d4c1629baf1fc0c127839c7d605547daece11e",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/33d4c1629baf1fc0c127839c7d605547daece11e",
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests/commit/33d4c1629baf1fc0c127839c7d605547daece11e"
"sha": "34b361864cacfbd165af1b06a659113099da1f38",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/34b361864cacfbd165af1b06a659113099da1f38",
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests/commit/34b361864cacfbd165af1b06a659113099da1f38"
}
],
"verification": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ref": "refs/heads/branchToMerge",
"node_id": "REF_kwDOKSyX8LhyZWZzL2hlYWRzL2JyYW5jaFRvTWVyZ2U",
"node_id": "REF_kwDOKsCogrhyZWZzL2hlYWRzL2JyYW5jaFRvTWVyZ2U",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/refs/heads/branchToMerge",
"object": {
"sha": "33d4c1629baf1fc0c127839c7d605547daece11e",
"sha": "34b361864cacfbd165af1b06a659113099da1f38",
"type": "commit",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/33d4c1629baf1fc0c127839c7d605547daece11e"
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/34b361864cacfbd165af1b06a659113099da1f38"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ref": "refs/heads/draft",
"node_id": "REF_kwDOKSyX8LByZWZzL2hlYWRzL2RyYWZ0",
"node_id": "REF_kwDOKsCogrByZWZzL2hlYWRzL2RyYWZ0",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/refs/heads/draft",
"object": {
"sha": "33d4c1629baf1fc0c127839c7d605547daece11e",
"sha": "34b361864cacfbd165af1b06a659113099da1f38",
"type": "commit",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/33d4c1629baf1fc0c127839c7d605547daece11e"
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/34b361864cacfbd165af1b06a659113099da1f38"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"ref": "refs/heads/main",
"node_id": "REF_kwDOKSyX8K9yZWZzL2hlYWRzL21haW4",
"node_id": "REF_kwDOKsCogq9yZWZzL2hlYWRzL21haW4",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/refs/heads/main",
"object": {
"sha": "33d4c1629baf1fc0c127839c7d605547daece11e",
"sha": "34b361864cacfbd165af1b06a659113099da1f38",
"type": "commit",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/33d4c1629baf1fc0c127839c7d605547daece11e"
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits/34b361864cacfbd165af1b06a659113099da1f38"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"comments_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/issues/1/comments",
"events_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/issues/1/events",
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests/pull/1",
"id": 1893366188,
"node_id": "PR_kwDOKSyX8M5aLLl0",
"id": 1988611948,
"node_id": "PR_kwDOKsCogs5fMcXi",
"number": 1,
"title": "Temp draft PR",
"user": {
Expand All @@ -31,8 +31,8 @@
},
"labels": [
{
"id": 5955577634,
"node_id": "LA_kwDOKSyX8M8AAAABYvrnIg",
"id": 6195477233,
"node_id": "LA_kwDOKsCogs8AAAABcUd68Q",
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/labels/test",
"name": "test",
"color": "ededed",
Expand All @@ -46,8 +46,8 @@
"assignees": [],
"milestone": null,
"comments": 0,
"created_at": "2023-09-12T22:06:40Z",
"updated_at": "2023-09-12T22:06:41Z",
"created_at": "2023-11-11T00:45:20Z",
"updated_at": "2023-11-11T00:45:21Z",
"closed_at": null,
"author_association": "OWNER",
"active_lock_reason": null,
Expand Down
Loading

0 comments on commit 8d9b194

Please sign in to comment.