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

Split pull request search from issue; extend with filters #1693

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d9c5958
Split pull request search from issue; extend with filters
kgromov Aug 11, 2023
e145af8
Apply spotless updates
bitwiseman Aug 16, 2023
eec7479
Merge branch 'main' into feature/extend-pull-requests-query-search
bitwiseman Aug 16, 2023
bdc3866
Apply suggestions from code review
bitwiseman Aug 16, 2023
4d02a3c
Update src/main/java/org/kohsuke/github/GHPullRequestSearchBuilder.java
bitwiseman Aug 17, 2023
321b6ea
Update src/test/java/org/kohsuke/github/GHRepositoryTest.java
bitwiseman Aug 17, 2023
8b59aa4
Update src/test/java/org/kohsuke/github/AppTest.java
bitwiseman Aug 17, 2023
c355a14
Update snapshots fot GHRepository#testPullRequestSearch and AppTest#t…
kgromov Aug 22, 2023
02325be
Merge branch 'main' into feature/extend-pull-requests-query-search
bitwiseman Aug 24, 2023
e933b4c
Change target to wiremock files explicitly to custom repo
kgromov Aug 25, 2023
7d8ca89
Fix creationDate timezone issue for test data
kgromov Aug 25, 2023
f2c5149
Update CONTRIBUTING.md with small tips for snapshots taken from perso…
kgromov Aug 25, 2023
9e03957
Fix created search param caused by timezone diff
kgromov Aug 27, 2023
74f407a
Fix code coverage
kgromov Aug 31, 2023
7c98382
Cover pull request search builder more than 90%
kgromov Sep 12, 2023
4c613ba
Merge branch 'main' into feature/extend-pull-requests-query-search
kgromov Sep 12, 2023
dc0a8fa
Fix for java 8 build - remove factory method for Set
kgromov Sep 14, 2023
ea17ade
Merge branch 'main' into feature/extend-pull-requests-query-search
bitwiseman Oct 20, 2023
e0cb1b2
Merge branch 'main' into feature/extend-pull-requests-query-search
kgromov Nov 10, 2023
8d9b194
Change GHRepository#searchPullRequests to return buider
kgromov Nov 11, 2023
0859587
Merge branch 'main' into feature/extend-pull-requests-query-search
kgromov Nov 11, 2023
a82c15e
Rollback optimimzation for unique search terms to satisfy japicmp typ…
kgromov Nov 12, 2023
586f89e
Remove extra constructor from GHPullRequestSearchBuilder
bitwiseman Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
623 changes: 623 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequestSearchBuilder.java

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,17 @@ public GHPullRequestQueryBuilder queryPullRequests() {
return new GHPullRequestQueryBuilder(this);
}

/**
* Retrieves pull requests according to search terms.
*
* @param search
* {@link GHPullRequestSearchBuilder}
* @return pull requests as the paged iterable
*/
public PagedSearchIterable<GHPullRequest> searchPullRequests(GHPullRequestSearchBuilder search) {
return GHPullRequestSearchBuilder.from(search).repo(this).list();
}

bitwiseman marked this conversation as resolved.
Show resolved Hide resolved
/**
* Creates a new pull request.
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,15 @@ public GHIssueSearchBuilder searchIssues() {
return new GHIssueSearchBuilder(this);
}

/**
* Search for pull requests.
*
* @return gh pull request search builder
*/
public GHPullRequestSearchBuilder searchPullRequests() {
return new GHPullRequestSearchBuilder(this);
}

/**
* Search users.
*
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -1429,6 +1431,46 @@ public void testIssueSearch() throws IOException {
}
}

@Test
public void testPullRequestSearch() throws Exception {
bitwiseman marked this conversation as resolved.
Show resolved Hide resolved
GHRepository repository = getTestRepository();
String mainHead = repository.getRef("heads/main").getObject().getSha();
GHRef devBranch = repository.createRef("refs/heads/kgromov-test", mainHead);
repository.createContent()
.content("Empty content")
.message("test search")
.path(devBranch.getRef())
.branch(devBranch.getRef())
.commit();
LocalDate createdDate = LocalDate.now();
GHPullRequest newPR = repository
.createPullRequest("New PR", devBranch.getRef(), "refs/heads/main", "Hello, merged PR");
Thread.sleep(1000);
List<GHPullRequest> pullRequests = gitHub.searchPullRequests()
.createdByMe()
.isOpen()
.created(createdDate, LocalDate.now())
.list()
.toList();
assertThat(pullRequests.size(), greaterThan(0));
for (GHPullRequest pullRequest : pullRequests) {
assertThat(pullRequest.getTitle(), is("New PR"));
assertThat(pullRequest.getUser().getLogin(), is(repository.getOwner().getLogin()));
assertThat(pullRequest.getState(), is(GHIssueState.OPEN));
LocalDate createdAt = pullRequest.getCreatedAt().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
assertThat(createdAt, greaterThanOrEqualTo(createdDate));
}

LocalDate newPrCreatedAt = newPR.getCreatedAt().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
int totalCount = gitHub.searchPullRequests()
.createdByMe()
.isOpen()
.createdAfter(newPrCreatedAt, false)
.list()
.getTotalCount();
assertThat(totalCount, is(0));
}

/**
* Test readme.
*
Expand Down
52 changes: 45 additions & 7 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertThrows;
import static org.kohsuke.github.GHVerification.Reason.*;
import static org.kohsuke.github.GHVerification.Reason.GPGVERIFY_ERROR;
import static org.kohsuke.github.GHVerification.Reason.UNKNOWN_SIGNATURE_TYPE;

// TODO: Auto-generated Javadoc
/**
Expand Down Expand Up @@ -1709,4 +1707,44 @@ public void cannotRetrievePermissionMaintainUser() throws IOException {
GHPermissionType permission = r.getPermission("alecharp");
assertThat(permission.toString(), is("UNKNOWN"));
}

@Test
public void testSearchPullRequests() throws Exception {
bitwiseman marked this conversation as resolved.
Show resolved Hide resolved
GHRepository repository = getTempRepository();
String mainHead = repository.getRef("heads/main").getObject().getSha();
GHRef devBranch = repository.createRef("refs/heads/dev", mainHead);
repository.createContent()
.content("Empty content")
.message("test search")
.path(devBranch.getRef())
.branch(devBranch.getRef())
.commit();

GHPullRequest ghPullRequest = repository
.createPullRequest("Temp PR", devBranch.getRef(), "refs/heads/main", "Hello, merged PR");
ghPullRequest.merge("Merged test PR");
Thread.sleep(1000);
LocalDate from = LocalDate.parse("2023-08-01");
LocalDate to = LocalDate.now();
GHPullRequestSearchBuilder searchBuilder = gitHub.searchPullRequests()
.createdByMe()
.isMerged()
.merged(from, to)
.sort(GHPullRequestSearchBuilder.Sort.CREATED);
PagedSearchIterable<GHPullRequest> pullRequests = repository.searchPullRequests(searchBuilder);
assertThat(pullRequests.getTotalCount(), greaterThan(0));
for (GHPullRequest pullRequest : pullRequests) {
assertThat(pullRequest.getTitle(), is("Temp PR"));
assertThat(pullRequest.getRepository(), is(repository));
assertThat(pullRequest.getUser().getLogin(), is(repository.getOwner().getLogin()));
assertThat(pullRequest.getState(), is(GHIssueState.CLOSED));
LocalDate closedAt = pullRequest.getClosedAt().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
assertThat(closedAt, greaterThanOrEqualTo(from));
assertThat(closedAt, lessThanOrEqualTo(to));
}

searchBuilder = gitHub.searchPullRequests().createdByMe().isOpen().createdAfter(from, true);
pullRequests = repository.searchPullRequests(searchBuilder);
assertThat(pullRequests.getTotalCount(), is(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void BasicBehaviors_whenProxying() throws Exception {
assertThat(e, Matchers.<Exception>instanceOf(GHFileNotFoundException.class));
assertThat(e.getMessage(),
containsString(
"{\"message\":\"Not Found\",\"documentation_url\":\"https://docs.github.com/rest/reference/repos#get-a-repository\"}"));
"{\"message\":\"Not Found\",\"documentation_url\":\"https://docs.github.com/rest/repos/repos#get-a-repository\"}"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"id": 677534369,
"node_id": "R_kgDOKGJaoQ",
"name": "temp-testSearchPullRequests",
"full_name": "kgromov/temp-testSearchPullRequests",
"private": false,
"owner": {
"login": "kgromov",
"id": 9352794,
"node_id": "MDQ6VXNlcjkzNTI3OTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/9352794?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kgromov",
"html_url": "https://github.com/kgromov",
"followers_url": "https://api.github.com/users/kgromov/followers",
"following_url": "https://api.github.com/users/kgromov/following{/other_user}",
"gists_url": "https://api.github.com/users/kgromov/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kgromov/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kgromov/subscriptions",
"organizations_url": "https://api.github.com/users/kgromov/orgs",
"repos_url": "https://api.github.com/users/kgromov/repos",
"events_url": "https://api.github.com/users/kgromov/events{/privacy}",
"received_events_url": "https://api.github.com/users/kgromov/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/kgromov/temp-testSearchPullRequests",
"description": "A test repository for testing the github-api project: temp-testSearchPullRequests",
"fork": false,
"url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests",
"forks_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/forks",
"keys_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/teams",
"hooks_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/hooks",
"issue_events_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/issues/events{/number}",
"events_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/events",
"assignees_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/assignees{/user}",
"branches_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/branches{/branch}",
"tags_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/tags",
"blobs_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/statuses/{sha}",
"languages_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/languages",
"stargazers_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/stargazers",
"contributors_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/contributors",
"subscribers_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/subscribers",
"subscription_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/subscription",
"commits_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/contents/{+path}",
"compare_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/merges",
"archive_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/downloads",
"issues_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/issues{/number}",
"pulls_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/pulls{/number}",
"milestones_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/milestones{/number}",
"notifications_url": "https://api.github.com/repos/kgromov/temp-testSearchPullRequests/notifications{?since,all,participating}",
"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-08-11T20:36:47Z",
"updated_at": "2023-08-11T20:36:48Z",
"pushed_at": "2023-08-11T20:36:55Z",
"git_url": "git://github.com/kgromov/temp-testSearchPullRequests.git",
"ssh_url": "git@github.com:kgromov/temp-testSearchPullRequests.git",
"clone_url": "https://github.com/kgromov/temp-testSearchPullRequests.git",
"svn_url": "https://github.com/kgromov/temp-testSearchPullRequests",
"homepage": "http://github-api.kohsuke.org/",
"size": 0,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": true,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [],
"visibility": "public",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": false,
"allow_update_branch": false,
"use_squash_pr_title_as_default": false,
"squash_merge_commit_message": "COMMIT_MESSAGES",
"squash_merge_commit_title": "COMMIT_OR_PR_TITLE",
"merge_commit_message": "PR_TITLE",
"merge_commit_title": "MERGE_MESSAGE",
"security_and_analysis": {
"secret_scanning": {
"status": "disabled"
},
"secret_scanning_push_protection": {
"status": "disabled"
},
"dependabot_security_updates": {
"status": "disabled"
}
},
"network_count": 0,
"subscribers_count": 1
}
Loading
Loading