Skip to content

Commit 103e9be

Browse files
committed
feat: add api for revert wip changes
1 parent d22c66e commit 103e9be

File tree

9 files changed

+445
-184
lines changed

9 files changed

+445
-184
lines changed

api/jiaozifs.gen.go

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

api/swagger.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,8 @@ paths:
10701070
description: Unauthorized
10711071
403:
10721072
description: Forbidden
1073+
500:
1074+
description: Server Internal Error
10731075

10741076
/wip/{owner}/{repository}/changes:
10751077
parameters:

integrationtest/helper_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ func deleteObject(ctx context.Context, c convey.C, client *api.Client, title str
184184
})
185185
}
186186

187+
func createWip(ctx context.Context, c convey.C, client *api.Client, title string, user string, repoName string, refName string) {
188+
c.Convey("create wip "+title, func() {
189+
resp, err := client.GetWip(ctx, user, repoName, &api.GetWipParams{
190+
RefName: refName,
191+
})
192+
convey.So(err, convey.ShouldBeNil)
193+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusCreated)
194+
})
195+
}
196+
187197
func commitWip(ctx context.Context, c convey.C, client *api.Client, title string, user string, repoName string, refName string, msg string) {
188198
c.Convey("commit wip "+title, func() {
189199
resp, err := client.CommitWip(ctx, user, repoName, &api.CommitWipParams{

integrationtest/wip_object_test.go

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ func WipObjectSpec(ctx context.Context, urlStr string) func(c convey.C) {
312312
})
313313

314314
c.Convey("get wip changes", func(c convey.C) {
315-
316315
c.Convey("no auth", func() {
317316
re := client.RequestEditors
318317
client.RequestEditors = nil
@@ -381,5 +380,80 @@ func WipObjectSpec(ctx context.Context, urlStr string) func(c convey.C) {
381380
convey.So(*result.JSON200, convey.ShouldHaveLength, 4)
382381
})
383382
})
383+
384+
c.Convey("revert wip changes", func(c convey.C) {
385+
c.Convey("no auth", func() {
386+
re := client.RequestEditors
387+
client.RequestEditors = nil
388+
resp, err := client.RevertWipChanges(ctx, userName, repoName, &api.RevertWipChangesParams{
389+
RefName: branchName,
390+
})
391+
client.RequestEditors = re
392+
convey.So(err, convey.ShouldBeNil)
393+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusUnauthorized)
394+
})
395+
396+
c.Convey("fail to revert changes in non exit user", func() {
397+
resp, err := client.RevertWipChanges(ctx, "mockUser", repoName, &api.RevertWipChangesParams{
398+
RefName: branchName,
399+
})
400+
convey.So(err, convey.ShouldBeNil)
401+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusNotFound)
402+
})
403+
404+
c.Convey("fail to revert changes in non exit repo", func() {
405+
resp, err := client.RevertWipChanges(ctx, userName, "fakeRepo", &api.RevertWipChangesParams{
406+
RefName: branchName,
407+
})
408+
convey.So(err, convey.ShouldBeNil)
409+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusNotFound)
410+
})
411+
412+
c.Convey("fail to revert changes in non exit branch", func() {
413+
resp, err := client.RevertWipChanges(ctx, userName, repoName, &api.RevertWipChangesParams{
414+
RefName: "mockref",
415+
})
416+
convey.So(err, convey.ShouldBeNil)
417+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusNotFound)
418+
})
419+
420+
c.Convey("forbidden revert changes in others", func() {
421+
resp, err := client.RevertWipChanges(ctx, "jimmy", "happygo", &api.RevertWipChangesParams{
422+
RefName: branchName,
423+
})
424+
convey.So(err, convey.ShouldBeNil)
425+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusForbidden)
426+
})
427+
428+
c.Convey("not exit path", func() {
429+
resp, err := client.RevertWipChanges(ctx, userName, repoName, &api.RevertWipChangesParams{
430+
RefName: branchName,
431+
PathPrefix: utils.String("a/b/c/d"),
432+
})
433+
convey.So(err, convey.ShouldBeNil)
434+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusNotFound)
435+
})
436+
437+
c.Convey("success to revert changes", func() {
438+
resp, err := client.RevertWipChanges(ctx, userName, repoName, &api.RevertWipChangesParams{
439+
RefName: branchName,
440+
})
441+
convey.So(err, convey.ShouldBeNil)
442+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusOK)
443+
444+
{
445+
resp, err = client.GetWipChanges(ctx, userName, repoName, &api.GetWipChangesParams{
446+
RefName: branchName,
447+
})
448+
convey.So(err, convey.ShouldBeNil)
449+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusOK)
450+
451+
result, err := api.ParseGetWipChangesResponse(resp)
452+
convey.So(err, convey.ShouldBeNil)
453+
convey.So(*result.JSON200, convey.ShouldHaveLength, 0)
454+
}
455+
})
456+
})
457+
384458
}
385459
}

integrationtest/wip_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,3 @@ func WipSpec(ctx context.Context, urlStr string) func(c convey.C) {
189189
})
190190
}
191191
}
192-
193-
func createWip(ctx context.Context, c convey.C, client *api.Client, title string, user string, repoName string, refName string) {
194-
c.Convey("create wip "+title, func() {
195-
resp, err := client.GetWip(ctx, user, repoName, &api.GetWipParams{
196-
RefName: refName,
197-
})
198-
convey.So(err, convey.ShouldBeNil)
199-
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusCreated)
200-
})
201-
}

0 commit comments

Comments
 (0)