mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-04 22:58:43 +00:00
parent
86bb8f195c
commit
4891f104f0
2 changed files with 28 additions and 7 deletions
|
@ -95,10 +95,17 @@ func (s storage) RepoBatch(repos []*model.Repo) error {
|
||||||
if exist {
|
if exist {
|
||||||
if _, err := sess.
|
if _, err := sess.
|
||||||
Where("repo_owner = ? AND repo_name = ?", repos[i].Owner, repos[i].Name).
|
Where("repo_owner = ? AND repo_name = ?", repos[i].Owner, repos[i].Name).
|
||||||
AllCols().
|
Cols("repo_scm", "repo_avatar", "repo_link", "repo_private", "repo_clone", "repo_branch").
|
||||||
Update(repos[i]); err != nil {
|
Update(repos[i]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err := sess.
|
||||||
|
Where("repo_owner = ? AND repo_name = ?", repos[i].Owner, repos[i].Name).
|
||||||
|
Get(repos[i])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// only Insert on single object ref set auto created ID back to object
|
// only Insert on single object ref set auto created ID back to object
|
||||||
if _, err := sess.Insert(repos[i]); err != nil {
|
if _, err := sess.Insert(repos[i]); err != nil {
|
||||||
|
|
|
@ -153,10 +153,12 @@ func TestRepoList(t *testing.T) {
|
||||||
assert.NoError(t, store.CreateRepo(repo2))
|
assert.NoError(t, store.CreateRepo(repo2))
|
||||||
assert.NoError(t, store.CreateRepo(repo3))
|
assert.NoError(t, store.CreateRepo(repo3))
|
||||||
|
|
||||||
assert.NoError(t, store.PermBatch([]*model.Perm{
|
for _, perm := range []*model.Perm{
|
||||||
{UserID: user.ID, Repo: repo1.FullName},
|
{UserID: user.ID, Repo: repo1.FullName},
|
||||||
{UserID: user.ID, Repo: repo2.FullName},
|
{UserID: user.ID, Repo: repo2.FullName},
|
||||||
}))
|
} {
|
||||||
|
assert.NoError(t, store.PermUpsert(perm))
|
||||||
|
}
|
||||||
|
|
||||||
repos, err := store.RepoList(user, false)
|
repos, err := store.RepoList(user, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -210,12 +212,14 @@ func TestOwnedRepoList(t *testing.T) {
|
||||||
assert.NoError(t, store.CreateRepo(repo3))
|
assert.NoError(t, store.CreateRepo(repo3))
|
||||||
assert.NoError(t, store.CreateRepo(repo4))
|
assert.NoError(t, store.CreateRepo(repo4))
|
||||||
|
|
||||||
assert.NoError(t, store.PermBatch([]*model.Perm{
|
for _, perm := range []*model.Perm{
|
||||||
{UserID: user.ID, Repo: repo1.FullName, Push: true, Admin: false},
|
{UserID: user.ID, Repo: repo1.FullName, Push: true, Admin: false},
|
||||||
{UserID: user.ID, Repo: repo2.FullName, Push: false, Admin: true},
|
{UserID: user.ID, Repo: repo2.FullName, Push: false, Admin: true},
|
||||||
{UserID: user.ID, Repo: repo3.FullName},
|
{UserID: user.ID, Repo: repo3.FullName},
|
||||||
{UserID: user.ID, Repo: repo4.FullName},
|
{UserID: user.ID, Repo: repo4.FullName},
|
||||||
}))
|
} {
|
||||||
|
assert.NoError(t, store.PermUpsert(perm))
|
||||||
|
}
|
||||||
|
|
||||||
repos, err := store.RepoList(user, true)
|
repos, err := store.RepoList(user, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -313,9 +317,19 @@ func TestRepoBatch(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
allRepos := make([]*model.Repo, 0, 4)
|
repo := &model.Repo{
|
||||||
err := store.engine.Find(&allRepos)
|
FullName: "foo/bar",
|
||||||
|
Owner: "foo",
|
||||||
|
Name: "bar",
|
||||||
|
}
|
||||||
|
assert.NoError(t, store.RepoBatch([]*model.Repo{repo}))
|
||||||
|
assert.EqualValues(t, repos[0].ID, repo.ID)
|
||||||
|
_, err := store.engine.ID(repo.ID).Get(repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, repo.IsActive)
|
||||||
|
|
||||||
|
allRepos := make([]*model.Repo, 0, 4)
|
||||||
|
assert.NoError(t, store.engine.Find(&allRepos))
|
||||||
assert.Len(t, allRepos, 4)
|
assert.Len(t, allRepos, 4)
|
||||||
|
|
||||||
count, err := store.GetRepoCount()
|
count, err := store.GetRepoCount()
|
||||||
|
|
Loading…
Reference in a new issue