Skip to content

Commit e688323

Browse files
authored
Merge branch 'main' into feat/allow_any_file_for_upload_object
2 parents 13f6718 + e3c4c8c commit e688323

File tree

4 files changed

+190
-68
lines changed

4 files changed

+190
-68
lines changed

api/jiaozifs.gen.go

Lines changed: 126 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/swagger.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ components:
4040
schema:
4141
type: string
4242
format: date-time
43+
44+
PaginationCommitAfter:
45+
in: query
46+
name: after
47+
description: return items after this value
48+
schema:
49+
type: string
50+
format: date-time-ns
4351

4452
PaginationAmount:
4553
in: query
@@ -1260,6 +1268,8 @@ paths:
12601268
operationId: getCommitsInRepository
12611269
summary: get commits in repository
12621270
parameters:
1271+
- $ref: "#/components/parameters/PaginationCommitAfter"
1272+
- $ref: "#/components/parameters/PaginationAmount"
12631273
- in: query
12641274
name: refName
12651275
description: ref(branch/tag) name

controller/repository_ctl.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ func (repositoryCtl RepositoryController) UpdateRepository(ctx context.Context,
348348
w.Error(err)
349349
return
350350
}
351+
w.OK()
351352
}
352353

353354
func (repositoryCtl RepositoryController) GetCommitsInRepository(ctx context.Context, w *api.JiaozifsResponse, _ *http.Request, ownerName string, repositoryName string, params api.GetCommitsInRepositoryParams) {
@@ -401,6 +402,19 @@ func (repositoryCtl RepositoryController) GetCommitsInRepository(ctx context.Con
401402
for {
402403
commit, err := iter.Next()
403404
if err == nil {
405+
if params.After != nil {
406+
parseTime, err := time.Parse(time.RFC3339Nano, *params.After)
407+
if err != nil {
408+
w.Error(err)
409+
return
410+
}
411+
if commit.Commit().Committer.When.Add(time.Nanosecond).After(parseTime) {
412+
continue
413+
}
414+
}
415+
if params.Amount != nil && len(commits) == *params.Amount {
416+
break
417+
}
404418
modelCommit := commit.Commit()
405419
commits = append(commits, api.Commit{
406420
RepositoryId: modelCommit.RepositoryID,

integrationtest/repo_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"time"
78

89
"github.com/jiaozifs/jiaozifs/api"
910
apiimpl "github.com/jiaozifs/jiaozifs/api/api_impl"
@@ -394,6 +395,45 @@ func RepoSpec(ctx context.Context, urlStr string) func(c convey.C) {
394395
convey.So(*result.JSON200, convey.ShouldHaveLength, 1)
395396
convey.So((*result.JSON200)[0].Message, convey.ShouldEqual, "first commit")
396397
})
398+
399+
uploadObject(ctx, c, client, "add sec object", userName, repoName, controller.DefaultBranchName, "b.txt")
400+
commitWip(ctx, c, client, "commit sec object", userName, repoName, controller.DefaultBranchName, "second commit")
401+
uploadObject(ctx, c, client, "add third object", userName, repoName, controller.DefaultBranchName, "c.txt")
402+
commitWip(ctx, c, client, "commit third object", userName, repoName, controller.DefaultBranchName, "third commit")
403+
c.Convey("success get commits by params", func() {
404+
resp, err := client.GetCommitsInRepository(ctx, userName, repoName, &api.GetCommitsInRepositoryParams{
405+
RefName: utils.String(controller.DefaultBranchName),
406+
})
407+
convey.So(err, convey.ShouldBeNil)
408+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusOK)
409+
410+
result, err := api.ParseGetCommitsInRepositoryResponse(resp)
411+
convey.So(err, convey.ShouldBeNil)
412+
convey.So(*result.JSON200, convey.ShouldHaveLength, 3)
413+
convey.So((*result.JSON200)[0].Message, convey.ShouldEqual, "third commit")
414+
415+
newResp, err := client.GetCommitsInRepository(ctx, userName, repoName, &api.GetCommitsInRepositoryParams{
416+
After: utils.String((*result.JSON200)[0].Committer.When.Format(time.RFC3339Nano)),
417+
Amount: utils.Int(1),
418+
RefName: utils.String(controller.DefaultBranchName),
419+
})
420+
convey.So(err, convey.ShouldBeNil)
421+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusOK)
422+
423+
newResult, err := api.ParseGetCommitsInRepositoryResponse(newResp)
424+
convey.So(err, convey.ShouldBeNil)
425+
convey.So(*newResult.JSON200, convey.ShouldHaveLength, 1)
426+
convey.So((*newResult.JSON200)[0].Message, convey.ShouldEqual, "second commit")
427+
})
428+
429+
c.Convey("failed get commits by wrong params", func() {
430+
resp, err := client.GetCommitsInRepository(ctx, userName, repoName, &api.GetCommitsInRepositoryParams{
431+
After: utils.String("123"),
432+
RefName: utils.String(controller.DefaultBranchName),
433+
})
434+
convey.So(err, convey.ShouldBeNil)
435+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusInternalServerError)
436+
})
397437
})
398438

399439
c.Convey("delete repository", func(c convey.C) {

0 commit comments

Comments
 (0)