|
| 1 | +package org.kohsuke.github; |
| 2 | + |
| 3 | +import java.util.Locale; |
| 4 | + |
| 5 | +/** |
| 6 | + * Search repositories. |
| 7 | + * |
| 8 | + * @author Kohsuke Kawaguchi |
| 9 | + * @see GitHub#searchRepositories() |
| 10 | + */ |
| 11 | +public class GHRepositorySearchBuilder extends GHSearchBuilder<GHRepository> { |
| 12 | + /*package*/ GHRepositorySearchBuilder(GitHub root) { |
| 13 | + super(root,RepositorySearchResult.class); |
| 14 | + } |
| 15 | + |
| 16 | + /** |
| 17 | + * Search terms. |
| 18 | + */ |
| 19 | + public GHRepositorySearchBuilder q(String term) { |
| 20 | + super.q(term); |
| 21 | + return this; |
| 22 | + } |
| 23 | + |
| 24 | + public GHRepositorySearchBuilder in(String v) { |
| 25 | + return q("in:"+v); |
| 26 | + } |
| 27 | + |
| 28 | + public GHRepositorySearchBuilder size(String v) { |
| 29 | + return q("size:"+v); |
| 30 | + } |
| 31 | + |
| 32 | + public GHRepositorySearchBuilder forks(String v) { |
| 33 | + return q("forks:"+v); |
| 34 | + } |
| 35 | + |
| 36 | + public GHRepositorySearchBuilder created(String v) { |
| 37 | + return q("created:"+v); |
| 38 | + } |
| 39 | + |
| 40 | + public GHRepositorySearchBuilder pushed(String v) { |
| 41 | + return q("pushed:"+v); |
| 42 | + } |
| 43 | + |
| 44 | + public GHRepositorySearchBuilder user(String v) { |
| 45 | + return q("user:"+v); |
| 46 | + } |
| 47 | + |
| 48 | + public GHRepositorySearchBuilder repo(String v) { |
| 49 | + return q("repo:"+v); |
| 50 | + } |
| 51 | + |
| 52 | + public GHRepositorySearchBuilder language(String v) { |
| 53 | + return q("language:"+v); |
| 54 | + } |
| 55 | + |
| 56 | + public GHRepositorySearchBuilder stars(String v) { |
| 57 | + return q("stars:"+v); |
| 58 | + } |
| 59 | + |
| 60 | + public GHRepositorySearchBuilder sort(Sort sort) { |
| 61 | + req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH)); |
| 62 | + return this; |
| 63 | + } |
| 64 | + |
| 65 | + public enum Sort { STARS, FORKS, UPDATED } |
| 66 | + |
| 67 | + private static class RepositorySearchResult extends SearchResult<GHRepository> { |
| 68 | + private GHRepository[] items; |
| 69 | + |
| 70 | + @Override |
| 71 | + /*package*/ GHRepository[] getItems(GitHub root) { |
| 72 | + for (GHRepository item : items) |
| 73 | + item.wrap(root); |
| 74 | + return items; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + protected String getApiUrl() { |
| 80 | + return "/search/repositories"; |
| 81 | + } |
| 82 | +} |
0 commit comments