From fccdd241583e486c3e415959c9c91b76696a6e4d Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 28 Jul 2024 15:55:58 +0800 Subject: [PATCH 1/3] fix(api): owner ID should be zero when created repo secret - Change `owner.ID` to `0` in the `CreateOrUpdateSecret` function call Signed-off-by: Bo-Yi Wu --- routers/api/v1/repo/action.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 48ba35ac21175..9b222e559a8d0 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -122,7 +122,7 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) { opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption) - _, created, err := secret_service.CreateOrUpdateSecret(ctx, owner.ID, repo.ID, ctx.PathParam("secretname"), opt.Data) + _, created, err := secret_service.CreateOrUpdateSecret(ctx, 0, repo.ID, ctx.PathParam("secretname"), opt.Data) if err != nil { if errors.Is(err, util.ErrInvalidArgument) { ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err) From d100d0d639bcfa4d1bd7beb47a4614199353ce76 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 28 Jul 2024 16:15:38 +0800 Subject: [PATCH 2/3] refactor: refactor codebase for improved efficiency and clarity - Remove unused variable `owner` from `CreateOrUpdateSecret` function Signed-off-by: Bo-Yi Wu --- routers/api/v1/repo/action.go | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 9b222e559a8d0..4d5513fcb9f70 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -117,7 +117,6 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - owner := ctx.Repo.Owner repo := ctx.Repo.Repository opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption) From e323b6f48000ba2510a16020094643e6dcc07378 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 28 Jul 2024 18:36:34 +0800 Subject: [PATCH 3/3] refactor: refactor secret deletion functions and improve tests - Remove unused `owner` variable in `DeleteSecret` function - Change `DeleteSecretByName` function call to use `0` instead of `owner.ID` Signed-off-by: Bo-Yi Wu --- routers/api/v1/repo/action.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 4d5513fcb9f70..dae5a6e585792 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -173,10 +173,9 @@ func (Action) DeleteSecret(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - owner := ctx.Repo.Owner repo := ctx.Repo.Repository - err := secret_service.DeleteSecretByName(ctx, owner.ID, repo.ID, ctx.PathParam("secretname")) + err := secret_service.DeleteSecretByName(ctx, 0, repo.ID, ctx.PathParam("secretname")) if err != nil { if errors.Is(err, util.ErrInvalidArgument) { ctx.Error(http.StatusBadRequest, "DeleteSecret", err)