Skip to content

Commit 308be11

Browse files
committed
feat: add test for wip
1 parent 93abc50 commit 308be11

File tree

18 files changed

+547
-212
lines changed

18 files changed

+547
-212
lines changed

api/jiaozifs.gen.go

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

api/swagger.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,6 @@ paths:
855855
- wip
856856
operationId: createWip
857857
summary: create working in process
858-
parameters:
859-
- in: query
860-
name: name
861-
description: wip name
862-
required: true
863-
schema:
864-
type: string
865858
responses:
866859
201:
867860
description: working in process created

controller/branch_ctl.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,14 @@ func (bct BranchController) DeleteBranch(ctx context.Context, w *api.JiaozifsRes
192192
return
193193
}
194194

195-
_, err = bct.Repo.RefRepo().Get(ctx, models.NewGetRefParams().SetName(params.RefName).SetRepositoryID(repository.ID))
195+
// Delete branch
196+
affectedRows, err := bct.Repo.RefRepo().Delete(ctx, models.NewDeleteRefParams().SetName(params.RefName).SetRepositoryID(repository.ID))
196197
if err != nil {
197198
w.Error(err)
198199
return
199200
}
200-
201-
// Delete branch
202-
err = bct.Repo.RefRepo().Delete(ctx, models.NewDeleteRefParams().SetName(params.RefName).SetRepositoryID(repository.ID))
203-
if err != nil {
204-
w.Error(err)
201+
if affectedRows == 0 {
202+
w.NotFound()
205203
return
206204
}
207205
w.OK()

controller/repository_ctl.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (repositoryCtl RepositoryController) ListRepositoryOfAuthenticatedUser(ctx
6161
return
6262
}
6363

64-
repositories, err := repositoryCtl.Repo.RepositoryRepo().List(ctx, models.NewListRepoParams().SetOwnerID(operator.ID))
64+
repositories, err := repositoryCtl.Repo.RepositoryRepo().List(ctx, models.NewListRepoParams().SetOwnerID(operator.ID)) //operator is owner
6565
if err != nil {
6666
w.Error(err)
6767
return
@@ -131,7 +131,7 @@ func (repositoryCtl RepositoryController) CreateRepository(ctx context.Context,
131131
Name: body.Name,
132132
Description: body.Description,
133133
HEAD: defaultRef.Name,
134-
OwnerID: operator.ID,
134+
OwnerID: operator.ID, // this api only create repo for operator
135135
CreatorID: operator.ID,
136136
CreatedAt: time.Now(),
137137
UpdatedAt: time.Now(),
@@ -174,17 +174,22 @@ func (repositoryCtl RepositoryController) DeleteRepository(ctx context.Context,
174174
return
175175
}
176176

177-
repo, err := repositoryCtl.Repo.RepositoryRepo().Get(ctx, models.NewGetRepoParams().SetName(repositoryName).SetOwnerID(operator.ID))
177+
repo, err := repositoryCtl.Repo.RepositoryRepo().Get(ctx, models.NewGetRepoParams().SetName(repositoryName).SetOwnerID(owner.ID))
178178
if err != nil {
179179
w.Error(err)
180180
return
181181
}
182182

183-
err = repositoryCtl.Repo.RepositoryRepo().Delete(ctx, models.NewDeleteRepoParams().SetID(repo.ID))
183+
affectRows, err := repositoryCtl.Repo.RepositoryRepo().Delete(ctx, models.NewDeleteRepoParams().SetID(repo.ID))
184184
if err != nil {
185185
w.Error(err)
186186
return
187187
}
188+
189+
if affectRows == 0 {
190+
w.NotFound()
191+
return
192+
}
188193
w.OK()
189194
}
190195

@@ -247,7 +252,7 @@ func (repositoryCtl RepositoryController) UpdateRepository(ctx context.Context,
247252
}
248253

249254
func (repositoryCtl RepositoryController) GetCommitsInRepository(ctx context.Context, w *api.JiaozifsResponse, _ *http.Request, ownerName string, repositoryName string, params api.GetCommitsInRepositoryParams) {
250-
user, err := auth.GetOperator(ctx)
255+
operator, err := auth.GetOperator(ctx)
251256
if err != nil {
252257
w.Error(err)
253258
return
@@ -259,7 +264,7 @@ func (repositoryCtl RepositoryController) GetCommitsInRepository(ctx context.Con
259264
return
260265
}
261266

262-
if user.Name != ownerName { //todo check public or private
267+
if operator.Name != ownerName { //todo check public or private
263268
w.Forbidden()
264269
return
265270
}

0 commit comments

Comments
 (0)