mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 04:10:32 +00:00
Fix reggression, save not activated repos to database on sync again (#510)
* Fix #508 * Add testcase Unrelated nits: * Rm one index (unique will already create an index) * Do not drop on UpdateUser
This commit is contained in:
parent
c28f7cb29f
commit
2524c6900c
4 changed files with 42 additions and 28 deletions
|
@ -93,7 +93,10 @@ func GetRepos(c *gin.Context) {
|
||||||
if flush || time.Unix(user.Synced, 0).Add(time.Hour*72).Before(time.Now()) {
|
if flush || time.Unix(user.Synced, 0).Add(time.Hour*72).Before(time.Now()) {
|
||||||
log.Debug().Msgf("sync begin: %s", user.Login)
|
log.Debug().Msgf("sync begin: %s", user.Login)
|
||||||
user.Synced = time.Now().Unix()
|
user.Synced = time.Now().Unix()
|
||||||
store_.UpdateUser(user)
|
if err := store_.UpdateUser(user); err != nil {
|
||||||
|
log.Err(err).Msgf("update user '%s'", user.Login)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
config := ToConfig(c)
|
config := ToConfig(c)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ type ConfigStore interface {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ID int64 `json:"-" xorm:"pk autoincr 'config_id'"`
|
ID int64 `json:"-" xorm:"pk autoincr 'config_id'"`
|
||||||
RepoID int64 `json:"-" xorm:"UNIQUE(s) 'config_repo_id'"`
|
RepoID int64 `json:"-" xorm:"UNIQUE(s) 'config_repo_id'"`
|
||||||
Hash string `json:"hash" xorm:"UNIQUE(s) INDEX 'config_hash'"`
|
Hash string `json:"hash" xorm:"UNIQUE(s) 'config_hash'"`
|
||||||
Name string `json:"name" xorm:"config_name"`
|
Name string `json:"name" xorm:"config_name"`
|
||||||
Data []byte `json:"data" xorm:"config_data"`
|
Data []byte `json:"data" xorm:"config_data"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,8 +82,8 @@ func (s storage) RepoBatch(repos []*model.Repo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range repos {
|
for i := range repos {
|
||||||
if repos[i].UserID == 0 || len(repos[i].Owner) == 0 || len(repos[i].Name) == 0 || len(repos[i].FullName) == 0 {
|
if len(repos[i].Owner) == 0 || len(repos[i].Name) == 0 || len(repos[i].FullName) == 0 {
|
||||||
log.Debug().Msgf("skip insert/update repo: %v", repos[i])
|
log.Debug().Msgf("skip insert/update repo: %#v", repos[i])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
exist, err := sess.
|
exist, err := sess.
|
||||||
|
|
|
@ -279,34 +279,45 @@ func TestRepoBatch(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !assert.NoError(t, store.RepoBatch(
|
repos := []*model.Repo{
|
||||||
[]*model.Repo{
|
{
|
||||||
{
|
UserID: 1,
|
||||||
UserID: 1,
|
FullName: "foo/bar",
|
||||||
FullName: "foo/bar",
|
Owner: "foo",
|
||||||
Owner: "foo",
|
Name: "bar",
|
||||||
Name: "bar",
|
IsActive: true,
|
||||||
IsActive: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
UserID: 1,
|
|
||||||
FullName: "bar/baz",
|
|
||||||
Owner: "bar",
|
|
||||||
Name: "baz",
|
|
||||||
IsActive: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
UserID: 1,
|
|
||||||
FullName: "baz/qux",
|
|
||||||
Owner: "baz",
|
|
||||||
Name: "qux",
|
|
||||||
IsActive: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)) {
|
{
|
||||||
|
UserID: 1,
|
||||||
|
FullName: "bar/baz",
|
||||||
|
Owner: "bar",
|
||||||
|
Name: "baz",
|
||||||
|
IsActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UserID: 1,
|
||||||
|
FullName: "baz/qux",
|
||||||
|
Owner: "baz",
|
||||||
|
Name: "qux",
|
||||||
|
IsActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UserID: 0, // not activated repos do hot have a user id assigned
|
||||||
|
FullName: "baz/notes",
|
||||||
|
Owner: "baz",
|
||||||
|
Name: "notes",
|
||||||
|
IsActive: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if !assert.NoError(t, store.RepoBatch(repos)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allRepos := make([]*model.Repo, 0, 4)
|
||||||
|
err := store.engine.Find(&allRepos)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Len(t, allRepos, 4)
|
||||||
|
|
||||||
count, err := store.GetRepoCount()
|
count, err := store.GetRepoCount()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 3, count)
|
assert.EqualValues(t, 3, count)
|
||||||
|
|
Loading…
Reference in a new issue