Skip to content

Fix bug in removeOrgRepo #839

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 1 commit into from
Feb 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import (

// Engine represents a xorm engine or session.
type Engine interface {
Decr(column string, arg ...interface{}) *xorm.Session
Delete(interface{}) (int64, error)
Exec(string, ...interface{}) (sql.Result, error)
Find(interface{}, ...interface{}) error
Get(interface{}) (bool, error)
Id(interface{}) *xorm.Session
In(string, ...interface{}) *xorm.Session
Incr(column string, arg ...interface{}) *xorm.Session
Insert(...interface{}) (int64, error)
InsertOne(interface{}) (int64, error)
Iterate(interface{}, xorm.IterFunc) error
Expand Down
22 changes: 20 additions & 2 deletions models/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,28 @@ func RemoveOrgUser(orgID, userID int64) error {
}

func removeOrgRepo(e Engine, orgID, repoID int64) error {
_, err := e.Delete(&TeamRepo{
teamRepos := make([]*TeamRepo, 0, 10)
if err := e.Find(&teamRepos, &TeamRepo{OrgID: orgID, RepoID: repoID}); err != nil {
return err
}

if len(teamRepos) == 0 {
return nil
}

if _, err := e.Delete(&TeamRepo{
OrgID: orgID,
RepoID: repoID,
})
}); err != nil {
return err
}

teamIDs := make([]int64, len(teamRepos))
for i, teamRepo := range teamRepos {
teamIDs[i] = teamRepo.ID
}

_, err := x.Decr("num_repos").In("id", teamIDs).Update(new(Team))
return err
}

Expand Down