88 "math"
99 "net/http"
1010 "strconv"
11+ "time"
1112
1213 issues_model "code.gitea.io/gitea/models/issues"
1314 user_model "code.gitea.io/gitea/models/user"
@@ -116,6 +117,16 @@ func GetAllCommits(ctx *context.APIContext) {
116117 // in: query
117118 // description: filepath of a file/dir
118119 // type: string
120+ // - name: since
121+ // in: query
122+ // description: Only commits after this date will be returned (ISO 8601 format)
123+ // type: string
124+ // format: date-time
125+ // - name: until
126+ // in: query
127+ // description: Only commits before this date will be returned (ISO 8601 format)
128+ // type: string
129+ // format: date-time
119130 // - name: stat
120131 // in: query
121132 // description: include diff stats for every commit (disable for speedup, default 'true')
@@ -148,6 +159,23 @@ func GetAllCommits(ctx *context.APIContext) {
148159 // "409":
149160 // "$ref": "#/responses/EmptyRepository"
150161
162+ since := ctx .FormString ("since" )
163+ until := ctx .FormString ("until" )
164+
165+ // Validate since/until as ISO 8601 (RFC3339)
166+ if since != "" {
167+ if _ , err := time .Parse (time .RFC3339 , since ); err != nil {
168+ ctx .APIError (http .StatusUnprocessableEntity , "invalid 'since' format, expected ISO 8601 (RFC3339)" )
169+ return
170+ }
171+ }
172+ if until != "" {
173+ if _ , err := time .Parse (time .RFC3339 , until ); err != nil {
174+ ctx .APIError (http .StatusUnprocessableEntity , "invalid 'until' format, expected ISO 8601 (RFC3339)" )
175+ return
176+ }
177+ }
178+
151179 if ctx .Repo .Repository .IsEmpty {
152180 ctx .JSON (http .StatusConflict , api.APIError {
153181 Message : "Git Repository is empty." ,
@@ -198,14 +226,16 @@ func GetAllCommits(ctx *context.APIContext) {
198226 RepoPath : ctx .Repo .GitRepo .Path ,
199227 Not : not ,
200228 Revision : []string {baseCommit .ID .String ()},
229+ Since : since ,
230+ Until : until ,
201231 })
202232 if err != nil {
203233 ctx .APIErrorInternal (err )
204234 return
205235 }
206236
207237 // Query commits
208- commits , err = baseCommit .CommitsByRange (listOptions .Page , listOptions .PageSize , not )
238+ commits , err = baseCommit .CommitsByRange (listOptions .Page , listOptions .PageSize , not , since , until )
209239 if err != nil {
210240 ctx .APIErrorInternal (err )
211241 return
@@ -221,6 +251,8 @@ func GetAllCommits(ctx *context.APIContext) {
221251 Not : not ,
222252 Revision : []string {sha },
223253 RelPath : []string {path },
254+ Since : since ,
255+ Until : until ,
224256 })
225257
226258 if err != nil {
@@ -237,6 +269,8 @@ func GetAllCommits(ctx *context.APIContext) {
237269 File : path ,
238270 Not : not ,
239271 Page : listOptions .Page ,
272+ Since : since ,
273+ Until : until ,
240274 })
241275 if err != nil {
242276 ctx .APIErrorInternal (err )
0 commit comments