/
GHCommitQueryBuilder.java
139 lines (127 loc) · 3.42 KB
/
GHCommitQueryBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package org.kohsuke.github;
import java.util.Date;
// TODO: Auto-generated Javadoc
/**
* Builds up query for listing commits.
*
* <p>
* Call various methods that set the filter criteria, then {@link #list()} method to actually list up the commit.
*
* <pre>
* GHRepository r = ...;
* for (GHCommit c : r.queryCommits().since(x).until(y).author("kohsuke")) {
* ...
* }
* </pre>
*
* @author Kohsuke Kawaguchi
* @see GHRepository#queryCommits() GHRepository#queryCommits()
*/
public class GHCommitQueryBuilder {
private final Requester req;
private final GHRepository repo;
/**
* Instantiates a new GH commit query builder.
*
* @param repo
* the repo
*/
GHCommitQueryBuilder(GHRepository repo) {
this.repo = repo;
this.req = repo.root().createRequest(); // requester to build up
}
/**
* GItHub login or email address by which to filter by commit author.
*
* @param author
* the author
* @return the gh commit query builder
*/
public GHCommitQueryBuilder author(String author) {
req.with("author", author);
return this;
}
/**
* Only commits containing this file path will be returned.
*
* @param path
* the path
* @return the gh commit query builder
*/
public GHCommitQueryBuilder path(String path) {
req.with("path", path);
return this;
}
/**
* Specifies the SHA1 commit / tag / branch / etc to start listing commits from.
*
* @param ref
* the ref
* @return the gh commit query builder
*/
public GHCommitQueryBuilder from(String ref) {
req.with("sha", ref);
return this;
}
/**
* Page size gh commit query builder.
*
* @param pageSize
* the page size
* @return the gh commit query builder
*/
public GHCommitQueryBuilder pageSize(int pageSize) {
req.with("per_page", pageSize);
return this;
}
/**
* Only commits after this date will be returned.
*
* @param dt
* the dt
* @return the gh commit query builder
*/
public GHCommitQueryBuilder since(Date dt) {
req.with("since", GitHubClient.printDate(dt));
return this;
}
/**
* Only commits after this date will be returned.
*
* @param timestamp
* the timestamp
* @return the gh commit query builder
*/
public GHCommitQueryBuilder since(long timestamp) {
return since(new Date(timestamp));
}
/**
* Only commits before this date will be returned.
*
* @param dt
* the dt
* @return the gh commit query builder
*/
public GHCommitQueryBuilder until(Date dt) {
req.with("until", GitHubClient.printDate(dt));
return this;
}
/**
* Only commits before this date will be returned.
*
* @param timestamp
* the timestamp
* @return the gh commit query builder
*/
public GHCommitQueryBuilder until(long timestamp) {
return until(new Date(timestamp));
}
/**
* Lists up the commits with the criteria built so far.
*
* @return the paged iterable
*/
public PagedIterable<GHCommit> list() {
return req.withUrlPath(repo.getApiTailUrl("commits")).toIterable(GHCommit[].class, item -> item.wrapUp(repo));
}
}