GetUserAndCollaborativeRepositories returns list of repositories the user owns and collaborates.
(userID int64)
| 1846 | |
| 1847 | // GetUserAndCollaborativeRepositories returns list of repositories the user owns and collaborates. |
| 1848 | func GetUserAndCollaborativeRepositories(userID int64) ([]*Repository, error) { |
| 1849 | repos := make([]*Repository, 0, 10) |
| 1850 | if err := x.Alias("repo"). |
| 1851 | Join("INNER", "collaboration", "collaboration.repo_id = repo.id"). |
| 1852 | Where("collaboration.user_id = ?", userID). |
| 1853 | Find(&repos); err != nil { |
| 1854 | return nil, errors.Newf("select collaborative repositories: %v", err) |
| 1855 | } |
| 1856 | |
| 1857 | ownRepos := make([]*Repository, 0, 10) |
| 1858 | if err := x.Where("owner_id = ?", userID).Find(&ownRepos); err != nil { |
| 1859 | return nil, errors.Newf("select own repositories: %v", err) |
| 1860 | } |
| 1861 | |
| 1862 | return append(repos, ownRepos...), nil |
| 1863 | } |
| 1864 | |
| 1865 | type SearchRepoOptions struct { |
| 1866 | Keyword string |
no test coverage detected