@@ -109,8 +109,28 @@ type SearchRepoOptions struct {
109
109
// maximum: setting.ExplorePagingNum
110
110
// in: query
111
111
PageSize int `json:"limit"` // Can be smaller than or equal to setting.ExplorePagingNum
112
+ // Type of repository to search (related to owner if present)
113
+ //
114
+ // in: query
115
+ RepoType RepoType `json:"type"`
112
116
}
113
117
118
+ // RepoType is repository filtering type identifier
119
+ type RepoType string
120
+
121
+ const (
122
+ // RepoTypeAny any type (default)
123
+ RepoTypeAny RepoType = ""
124
+ // RepoTypeFork fork type
125
+ RepoTypeFork = "FORK"
126
+ // RepoTypeMirror mirror type
127
+ RepoTypeMirror = "MIRROR"
128
+ // RepoTypeSource source type
129
+ RepoTypeSource = "SOURCE"
130
+ // RepoTypeCollaborative collaborative type
131
+ RepoTypeCollaborative = "COLLABORATIVE"
132
+ )
133
+
114
134
//SearchOrderBy is used to sort the result
115
135
type SearchOrderBy string
116
136
@@ -172,11 +192,15 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, _ in
172
192
}
173
193
} else {
174
194
// Set user access conditions
195
+ var accessCond builder.Cond = builder .NewCond ()
196
+
175
197
// Add Owner ID to access conditions
176
- var accessCond builder.Cond = builder.Eq {"owner_id" : opts .OwnerID }
198
+ if opts .RepoType != RepoTypeCollaborative {
199
+ accessCond = accessCond .Or (builder.Eq {"owner_id" : opts .OwnerID })
200
+ }
177
201
178
202
// Include collaborative repositories
179
- if opts .Collaborate {
203
+ if opts .Collaborate && ( opts . RepoType == RepoTypeAny || opts . RepoType == RepoTypeMirror || opts . RepoType == RepoTypeCollaborative ) {
180
204
// Add repositories where user is set as collaborator directly
181
205
accessCond = accessCond .Or (builder .And (
182
206
builder .Expr ("id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?)" , opts .OwnerID ),
@@ -192,6 +216,18 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, _ in
192
216
opts .OrderBy = SearchOrderByAlphabetically
193
217
}
194
218
219
+ // Add general filters for repository
220
+ if opts .RepoType != RepoTypeAny {
221
+ cond = cond .And (builder.Eq {"is_mirror" : opts .RepoType == RepoTypeMirror })
222
+
223
+ switch opts .RepoType {
224
+ case RepoTypeFork :
225
+ cond = cond .And (builder.Eq {"is_fork" : true })
226
+ case RepoTypeSource :
227
+ cond = cond .And (builder.Eq {"is_fork" : false })
228
+ }
229
+ }
230
+
195
231
sess := x .NewSession ()
196
232
defer sess .Close ()
197
233
0 commit comments