GetUserMirrorRepositories returns mirror repositories of the organization which the user has access to.
(userID int64)
| 525 | |
| 526 | // GetUserMirrorRepositories returns mirror repositories of the organization which the user has access to. |
| 527 | func (org *User) GetUserMirrorRepositories(userID int64) ([]*Repository, error) { |
| 528 | teamIDs, err := org.GetUserTeamIDs(userID) |
| 529 | if err != nil { |
| 530 | return nil, errors.Newf("GetUserTeamIDs: %v", err) |
| 531 | } |
| 532 | if len(teamIDs) == 0 { |
| 533 | teamIDs = []int64{-1} |
| 534 | } |
| 535 | |
| 536 | var teamRepoIDs []int64 |
| 537 | err = x.Table("team_repo").In("team_id", teamIDs).Distinct("repo_id").Find(&teamRepoIDs) |
| 538 | if err != nil { |
| 539 | return nil, errors.Newf("get team repository ids: %v", err) |
| 540 | } |
| 541 | if len(teamRepoIDs) == 0 { |
| 542 | // team has no repo but "IN ()" is invalid SQL |
| 543 | teamRepoIDs = []int64{-1} // there is no repo with id=-1 |
| 544 | } |
| 545 | |
| 546 | repos := make([]*Repository, 0, 10) |
| 547 | if err = x.Where("owner_id = ?", org.ID). |
| 548 | And("is_private = ?", false). |
| 549 | Or(builder.In("id", teamRepoIDs)). |
| 550 | And("is_mirror = ?", true). // Don't move up because it's an independent condition |
| 551 | Desc("updated_unix"). |
| 552 | Find(&repos); err != nil { |
| 553 | return nil, errors.Newf("get user repositories: %v", err) |
| 554 | } |
| 555 | return repos, nil |
| 556 | } |
no test coverage detected