File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
main/java/org/kohsuke/github
test/java/org/kohsuke/github Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ public GHRepositorySearchBuilder forks(String v) {
5555 /**
5656 * Searching in forks
5757 *
58+ * By default, forks are not shown in search results. Forks are only indexed for code search when they have more
59+ * stars than the parent repository. You will not be able to search the code in a fork that has less stars than its
60+ * parent. To show forks with more stars than the parent repository in code search results, add
61+ * Fork.ALL_INCLUDING_FORKS or Fork.FORKS_ONLY.
62+ *
5863 * @param fork
5964 * search mode for forks
6065 *
@@ -66,6 +71,11 @@ public GHRepositorySearchBuilder forks(String v) {
6671 *
6772 */
6873 public GHRepositorySearchBuilder fork (Fork fork ) {
74+ if (fork == Fork .DEFAULT ) {
75+ this .terms .removeIf (term -> term .contains ("fork:" ));
76+ return this ;
77+ }
78+
6979 return q ("fork:" + fork );
7080 }
7181
@@ -200,9 +210,14 @@ public enum Sort {
200210
201211 /**
202212 * The enum Fork.
213+ *
214+ * By default, forks are not shown in search results. Forks are only indexed for code search when they have more
215+ * stars than the parent repository. You will not be able to search the code in a fork that has less stars than its
216+ * parent. To show forks with more stars than the parent repository in code search results, add
217+ * Fork.ALL_INCLUDING_FORKS or Fork.FORKS_ONLY.
203218 */
204219 public enum Fork {
205- ALL_INCLUDING_FORKS ("true" ), FORKS_ONLY ("only" );
220+ ALL_INCLUDING_FORKS ("true" ), FORKS_ONLY ("only" ), DEFAULT ( "ignore" ) ;
206221
207222 private String filterMode ;
208223 Fork (String mode ) {
Original file line number Diff line number Diff line change @@ -459,6 +459,21 @@ public void ghRepositorySearchBuilderIgnoresUnknownVisibility() {
459459 assertThat (ghRepositorySearchBuilder .terms .stream ().filter (item -> item .contains ("is:" )).count (), is (1L ));
460460 }
461461
462+ @ Test
463+ public void ghRepositorySearchBuilderForkDefaultResetForksSearchTerms () {
464+ GHRepositorySearchBuilder ghRepositorySearchBuilder = new GHRepositorySearchBuilder (gitHub );
465+ ghRepositorySearchBuilder = ghRepositorySearchBuilder .fork (GHRepositorySearchBuilder .Fork .ALL_INCLUDING_FORKS );
466+ assertThat (ghRepositorySearchBuilder .terms .stream ().filter (item -> item .contains ("fork:true" )).count (), is (1L ));
467+ assertThat (ghRepositorySearchBuilder .terms .stream ().filter (item -> item .contains ("fork:" )).count (), is (1L ));
468+
469+ ghRepositorySearchBuilder = ghRepositorySearchBuilder .fork (GHRepositorySearchBuilder .Fork .FORKS_ONLY );
470+ assertThat (ghRepositorySearchBuilder .terms .stream ().filter (item -> item .contains ("fork:only" )).count (), is (1L ));
471+ assertThat (ghRepositorySearchBuilder .terms .stream ().filter (item -> item .contains ("fork:" )).count (), is (2L ));
472+
473+ ghRepositorySearchBuilder = ghRepositorySearchBuilder .fork (GHRepositorySearchBuilder .Fork .DEFAULT );
474+ assertThat (ghRepositorySearchBuilder .terms .stream ().filter (item -> item .contains ("fork:" )).count (), is (0L ));
475+ }
476+
462477 @ Test
463478 public void listCommitCommentsSomeComments () throws IOException {
464479 List <GHCommitComment > commitComments = getRepository ()
You can’t perform that action at this time.
0 commit comments