Skip to content

Commit 1f704e3

Browse files
committed
Reinstated the old methods for backward compatibility
1 parent 98dafb3 commit 1f704e3

9 files changed

Lines changed: 3860 additions & 3926 deletions

File tree

src/main/java/org/kohsuke/github/GHContentSearchBuilder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ public GHContentSearchBuilder language(String v) {
4141
return q("language:" + v);
4242
}
4343

44+
/**
45+
* Fork gh content search builder.
46+
*
47+
* @param v
48+
* the v
49+
* @return the gh content search builder
50+
*/
51+
@Deprecated
52+
public GHContentSearchBuilder fork(String v) {
53+
return q("fork:" + v);
54+
}
55+
4456
/**
4557
* Fork gh content search builder.
4658
*

src/main/java/org/kohsuke/github/GHRepositorySearchBuilder.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,40 @@ public GHRepositorySearchBuilder forks(String v) {
5252
return q("forks:" + v);
5353
}
5454

55+
/**
56+
* Searching in forks
57+
*
58+
* The default search mode is {@link Fork#PARENT_ONLY}. In that mode, forks are not included in search results.
59+
*
60+
* <p>
61+
* Passing {@link Fork#PARENT_AND_FORKS} or {@link Fork#FORKS_ONLY} will show results from forks, but only if they
62+
* have more stars than the parent repository.
63+
*
64+
* <p>
65+
* IMPORTANT: Regardless of this setting, no search results will ever be returned for forks with equal or fewer
66+
* stars than the parent repository. Forks with less stars than the parent repository are not included in the index
67+
* for code searching.
68+
*
69+
* @param fork
70+
* search mode for forks
71+
*
72+
* @return the gh repository search builder
73+
*
74+
* @see <a href=
75+
* "https://docs.github.com/en/github/searching-for-information-on-github/searching-on-github/searching-in-forks">Searching
76+
* in forks</a>
77+
*
78+
*/
79+
@Deprecated
80+
public GHRepositorySearchBuilder fork(Fork fork) {
81+
if (Fork.PARENT_ONLY.equals(fork)) {
82+
this.terms.removeIf(term -> term.contains("fork:"));
83+
return this;
84+
}
85+
86+
return q("fork:" + fork);
87+
}
88+
5589
/**
5690
* Searching in forks
5791
*
@@ -216,6 +250,45 @@ public enum Sort {
216250
STARS, FORKS, UPDATED
217251
}
218252

253+
/**
254+
* The enum for Fork search mode
255+
* Note: Kept for backward compatibility. Use GHFork instead.
256+
*/
257+
@Deprecated
258+
public enum Fork {
259+
260+
/**
261+
* Search in the parent repository and in forks with more stars than the parent repository.
262+
*
263+
* Forks with the same or fewer stars than the parent repository are still ignored.
264+
*/
265+
PARENT_AND_FORKS("true"),
266+
267+
/**
268+
* Search only in forks with more stars than the parent repository.
269+
*
270+
* The parent repository is ignored. If no forks have more stars than the parent, no results will be returned.
271+
*/
272+
FORKS_ONLY("only"),
273+
274+
/**
275+
* (Default) Search only the parent repository.
276+
*
277+
* Forks are ignored.
278+
*/
279+
PARENT_ONLY("");
280+
281+
private String filterMode;
282+
Fork(final String mode) {
283+
this.filterMode = mode;
284+
}
285+
286+
@Override
287+
public String toString() {
288+
return filterMode;
289+
}
290+
}
291+
219292
private static class RepositorySearchResult extends SearchResult<GHRepository> {
220293
private GHRepository[] items;
221294

src/test/java/org/kohsuke/github/GitHubTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public void searchContentWithForks() {
161161
.language("js")
162162
.sort(GHContentSearchBuilder.Sort.INDEXED)
163163
.order(GHDirection.DESC)
164+
.fork(GHFork.PARENT_ONLY)
164165
.list();
165166

166167
final PagedSearchIterable<GHContent> resultsWithForks = gitHub.searchContent()

src/test/resources/org/kohsuke/github/GitHubTest/wiremock/searchContentWithForks/__files/search_code-2.json

Lines changed: 1877 additions & 1953 deletions
Large diffs are not rendered by default.

src/test/resources/org/kohsuke/github/GitHubTest/wiremock/searchContentWithForks/__files/search_code-3.json

Lines changed: 1878 additions & 1954 deletions
Large diffs are not rendered by default.

src/test/resources/org/kohsuke/github/GitHubTest/wiremock/searchContentWithForks/__files/user-1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"private_gists": 7,
3535
"total_private_repos": 25,
3636
"owned_private_repos": 25,
37-
"disk_usage": 505415,
37+
"disk_usage": 505417,
3838
"collaborators": 1,
3939
"two_factor_authentication": true,
4040
"plan": {

src/test/resources/org/kohsuke/github/GitHubTest/wiremock/searchContentWithForks/mappings/search_code-2.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "b264f2c8-9780-4d39-8f59-39adb461e042",
2+
"id": "e66f46d2-2827-412a-a0c6-89f8370c34ac",
33
"name": "search_code",
44
"request": {
55
"url": "/search/code?sort=indexed&order=desc&q=addClass+language%3Ajs",
@@ -15,7 +15,7 @@
1515
"bodyFileName": "search_code-2.json",
1616
"headers": {
1717
"Server": "GitHub.com",
18-
"Date": "Sun, 21 Nov 2021 13:04:45 GMT",
18+
"Date": "Mon, 22 Nov 2021 10:03:26 GMT",
1919
"Content-Type": "application/json; charset=utf-8",
2020
"Cache-Control": "no-cache",
2121
"Vary": [
@@ -28,7 +28,7 @@
2828
"X-GitHub-Media-Type": "github.v3; format=json",
2929
"X-RateLimit-Limit": "30",
3030
"X-RateLimit-Remaining": "29",
31-
"X-RateLimit-Reset": "1637499943",
31+
"X-RateLimit-Reset": "1637575463",
3232
"X-RateLimit-Used": "1",
3333
"X-RateLimit-Resource": "search",
3434
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
@@ -37,11 +37,11 @@
3737
"X-XSS-Protection": "0",
3838
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
3939
"Content-Security-Policy": "default-src 'none'",
40-
"X-GitHub-Request-Id": "D5C0:1F74:CD3CA9:DC0F7D:619A43EA",
40+
"X-GitHub-Request-Id": "EB6C:1F74:1390213:14C0A7E:619B6AEB",
4141
"Link": "<https://api.github.com/search/code?sort=indexed&order=desc&q=addClass+language%3Ajs&page=2>; rel=\"next\", <https://api.github.com/search/code?sort=indexed&order=desc&q=addClass+language%3Ajs&page=34>; rel=\"last\""
4242
}
4343
},
44-
"uuid": "b264f2c8-9780-4d39-8f59-39adb461e042",
44+
"uuid": "e66f46d2-2827-412a-a0c6-89f8370c34ac",
4545
"persistent": true,
4646
"insertionIndex": 2
4747
}

src/test/resources/org/kohsuke/github/GitHubTest/wiremock/searchContentWithForks/mappings/search_code-3.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "e8cbb690-9c42-4a75-83c8-65a3dc22c263",
2+
"id": "67436d53-afd1-4df2-8f10-734b45b4abed",
33
"name": "search_code",
44
"request": {
55
"url": "/search/code?sort=indexed&order=desc&q=addClass+language%3Ajs+fork%3Atrue",
@@ -15,7 +15,7 @@
1515
"bodyFileName": "search_code-3.json",
1616
"headers": {
1717
"Server": "GitHub.com",
18-
"Date": "Sun, 21 Nov 2021 13:04:48 GMT",
18+
"Date": "Mon, 22 Nov 2021 10:03:29 GMT",
1919
"Content-Type": "application/json; charset=utf-8",
2020
"Cache-Control": "no-cache",
2121
"Vary": [
@@ -28,7 +28,7 @@
2828
"X-GitHub-Media-Type": "github.v3; format=json",
2929
"X-RateLimit-Limit": "30",
3030
"X-RateLimit-Remaining": "28",
31-
"X-RateLimit-Reset": "1637499943",
31+
"X-RateLimit-Reset": "1637575463",
3232
"X-RateLimit-Used": "2",
3333
"X-RateLimit-Resource": "search",
3434
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
@@ -37,11 +37,11 @@
3737
"X-XSS-Protection": "0",
3838
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
3939
"Content-Security-Policy": "default-src 'none'",
40-
"X-GitHub-Request-Id": "D5C1:1F74:CD3D28:DC100B:619A43EE",
40+
"X-GitHub-Request-Id": "EB6D:7D60:761E32:7C4B93:619B6AEE",
4141
"Link": "<https://api.github.com/search/code?sort=indexed&order=desc&q=addClass+language%3Ajs+fork%3Atrue&page=2>; rel=\"next\", <https://api.github.com/search/code?sort=indexed&order=desc&q=addClass+language%3Ajs+fork%3Atrue&page=34>; rel=\"last\""
4242
}
4343
},
44-
"uuid": "e8cbb690-9c42-4a75-83c8-65a3dc22c263",
44+
"uuid": "67436d53-afd1-4df2-8f10-734b45b4abed",
4545
"persistent": true,
4646
"insertionIndex": 3
4747
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "117d529c-d4aa-46ea-8b5b-c07ea58ee7be",
2+
"id": "8794a2f3-d6de-4578-8f68-33dbec02760d",
33
"name": "user",
44
"request": {
55
"url": "/user",
@@ -15,34 +15,34 @@
1515
"bodyFileName": "user-1.json",
1616
"headers": {
1717
"Server": "GitHub.com",
18-
"Date": "Sun, 21 Nov 2021 13:04:41 GMT",
18+
"Date": "Mon, 22 Nov 2021 10:03:22 GMT",
1919
"Content-Type": "application/json; charset=utf-8",
2020
"Cache-Control": "private, max-age=60, s-maxage=60",
2121
"Vary": [
2222
"Accept, Authorization, Cookie, X-GitHub-OTP",
2323
"Accept-Encoding, Accept, X-Requested-With"
2424
],
25-
"ETag": "W/\"274b7a0391a4d8ec088bc09c2ea4493111a73618dc4f9b76977913c0187d8e4b\"",
25+
"ETag": "W/\"423eec8cb3dd36cf77abae8e76b77dd64a32ff8cecee5af3e3e25ccf8fea4459\"",
2626
"Last-Modified": "Thu, 18 Nov 2021 15:29:00 GMT",
2727
"X-OAuth-Scopes": "admin:org, delete_repo, repo, user",
2828
"X-Accepted-OAuth-Scopes": "",
2929
"github-authentication-token-expiration": "2022-01-30 03:21:12 UTC",
3030
"X-GitHub-Media-Type": "github.v3; format=json",
3131
"X-RateLimit-Limit": "5000",
32-
"X-RateLimit-Remaining": "4793",
33-
"X-RateLimit-Reset": "1637502525",
34-
"X-RateLimit-Used": "207",
32+
"X-RateLimit-Remaining": "4973",
33+
"X-RateLimit-Reset": "1637576004",
34+
"X-RateLimit-Used": "27",
3535
"X-RateLimit-Resource": "core",
3636
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
3737
"X-Frame-Options": "deny",
3838
"X-Content-Type-Options": "nosniff",
3939
"X-XSS-Protection": "0",
4040
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
4141
"Content-Security-Policy": "default-src 'none'",
42-
"X-GitHub-Request-Id": "D5BE:1F74:CD3C84:DC0F57:619A43E9"
42+
"X-GitHub-Request-Id": "EB6A:7D60:761CE4:7C4A2D:619B6AEA"
4343
}
4444
},
45-
"uuid": "117d529c-d4aa-46ea-8b5b-c07ea58ee7be",
45+
"uuid": "8794a2f3-d6de-4578-8f68-33dbec02760d",
4646
"persistent": true,
4747
"insertionIndex": 1
4848
}

0 commit comments

Comments
 (0)