Skip to content

Refactor push mirror find and add check for updating push mirror #32539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Follow wxiaoguang's suggestion
  • Loading branch information
lunny committed Nov 17, 2024
commit 734b4a161f70fc8639be8287f24e5852240525f2
11 changes: 11 additions & 0 deletions models/repo/pushmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ func GetPushMirrorsByRepoID(ctx context.Context, repoID int64, listOptions db.Li
})
}

func GetPushMirrorByIDAndRepoID(ctx context.Context, id, repoID int64) (*PushMirror, error) {
var pushMirror PushMirror
has, err := db.GetEngine(ctx).Where("id = ?", id).And("repo_id = ?", repoID).Get(&pushMirror)
if err != nil {
return nil, err
} else if !has {
return nil, ErrPushMirrorNotExist
}
return &pushMirror, nil
}

func GetPushMirrorByID(ctx context.Context, id int64) (*PushMirror, error) {
mirror, has, err := db.GetByID[PushMirror](ctx, id)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions routers/web/repo/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,14 +1000,14 @@ func selectPushMirrorByForm(ctx *context.Context, form *forms.RepoSettingForm, r
return nil, err
}

pushMirror, err := repo_model.GetPushMirrorByID(ctx, id)
pushMirror, err := repo_model.GetPushMirrorByIDAndRepoID(ctx, id, repo.ID)
if err != nil {
if err == repo_model.ErrPushMirrorNotExist {
return nil, fmt.Errorf("PushMirror[%v] not associated to repository %v", id, repo)
}
return nil, err
}

if pushMirror.RepoID != repo.ID {
return nil, fmt.Errorf("PushMirror[%v] not associated to repository %v", id, repo)
}
pushMirror.Repo = repo
return pushMirror, nil
}
7 changes: 0 additions & 7 deletions tests/integration/mirror_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ func TestRepoSettingPushMirror(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)

defer func() {
// avoid dirty mirror data once test failure
repo_model.DeletePushMirrors(db.DefaultContext, repo_model.PushMirrorOptions{
RepoID: repo2.ID,
})
}()

onGiteaRun(t, func(t *testing.T, u *url.URL) {
t.Run("Push Mirror Add", func(t *testing.T) {
req = NewRequestWithValues(t, "POST", repoPrefix+"/settings", map[string]string{
Expand Down
Loading