Skip to content

Commit 734b4a1

Browse files
committed
Follow wxiaoguang's suggestion
1 parent 448d0a0 commit 734b4a1

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

models/repo/pushmirror.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ func GetPushMirrorsByRepoID(ctx context.Context, repoID int64, listOptions db.Li
122122
})
123123
}
124124

125+
func GetPushMirrorByIDAndRepoID(ctx context.Context, id, repoID int64) (*PushMirror, error) {
126+
var pushMirror PushMirror
127+
has, err := db.GetEngine(ctx).Where("id = ?", id).And("repo_id = ?", repoID).Get(&pushMirror)
128+
if err != nil {
129+
return nil, err
130+
} else if !has {
131+
return nil, ErrPushMirrorNotExist
132+
}
133+
return &pushMirror, nil
134+
}
135+
125136
func GetPushMirrorByID(ctx context.Context, id int64) (*PushMirror, error) {
126137
mirror, has, err := db.GetByID[PushMirror](ctx, id)
127138
if err != nil {

routers/web/repo/setting/setting.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,14 +1000,14 @@ func selectPushMirrorByForm(ctx *context.Context, form *forms.RepoSettingForm, r
10001000
return nil, err
10011001
}
10021002

1003-
pushMirror, err := repo_model.GetPushMirrorByID(ctx, id)
1003+
pushMirror, err := repo_model.GetPushMirrorByIDAndRepoID(ctx, id, repo.ID)
10041004
if err != nil {
1005+
if err == repo_model.ErrPushMirrorNotExist {
1006+
return nil, fmt.Errorf("PushMirror[%v] not associated to repository %v", id, repo)
1007+
}
10051008
return nil, err
10061009
}
10071010

1008-
if pushMirror.RepoID != repo.ID {
1009-
return nil, fmt.Errorf("PushMirror[%v] not associated to repository %v", id, repo)
1010-
}
10111011
pushMirror.Repo = repo
10121012
return pushMirror, nil
10131013
}

tests/integration/mirror_push_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@ func TestRepoSettingPushMirror(t *testing.T) {
141141
resp := session.MakeRequest(t, req, http.StatusOK)
142142
htmlDoc := NewHTMLParser(t, resp.Body)
143143

144-
defer func() {
145-
// avoid dirty mirror data once test failure
146-
repo_model.DeletePushMirrors(db.DefaultContext, repo_model.PushMirrorOptions{
147-
RepoID: repo2.ID,
148-
})
149-
}()
150-
151144
onGiteaRun(t, func(t *testing.T, u *url.URL) {
152145
t.Run("Push Mirror Add", func(t *testing.T) {
153146
req = NewRequestWithValues(t, "POST", repoPrefix+"/settings", map[string]string{

0 commit comments

Comments
 (0)