@@ -40,19 +40,13 @@ type SearchRepoOption struct { // TODO: Move SearchRepoOption to Gitea SDK
40
40
//
41
41
// in: query
42
42
SearchMode string `json:"mode"`
43
+ // Search only owners repositories
44
+ // Has effect only if owner is provided and mode is not "collaborative"
45
+ //
46
+ // in: query
47
+ OwnerExclusive bool `json:"exclusive"`
43
48
}
44
49
45
- // searchMode is repository filtering mode identifier
46
- type searchMode int
47
-
48
- const (
49
- searchModeAny searchMode = iota + 1
50
- searchModeFork
51
- searchModeMirror
52
- searchModeSource
53
- searchModeCollaborative
54
- )
55
-
56
50
// Search repositories via options
57
51
func Search (ctx * context.APIContext ) {
58
52
// swagger:route GET /repos/search repository repoSearch
@@ -69,35 +63,32 @@ func Search(ctx *context.APIContext) {
69
63
Keyword : strings .Trim (ctx .Query ("q" ), " " ),
70
64
OwnerID : ctx .QueryInt64 ("uid" ),
71
65
PageSize : convert .ToCorrectPageSize (ctx .QueryInt ("limit" )),
72
- Collaborate : util .OptionalBoolFalse ,
66
+ Collaborate : util .OptionalBoolNone ,
73
67
}
74
68
75
- var modeQuery = ctx .Query ("mode" )
76
- var mode searchMode
77
- switch modeQuery {
69
+ if ctx .QueryBool ("exclusive" ) {
70
+ opts .Collaborate = util .OptionalBoolFalse
71
+ }
72
+
73
+ var mode = ctx .Query ("mode" )
74
+ switch mode {
78
75
case "source" :
79
- mode = searchModeSource
80
76
opts .Fork = util .OptionalBoolFalse
81
77
opts .Mirror = util .OptionalBoolFalse
82
78
case "fork" :
83
- mode = searchModeFork
84
79
opts .Fork = util .OptionalBoolTrue
85
80
case "mirror" :
86
- mode = searchModeMirror
87
81
opts .Mirror = util .OptionalBoolTrue
88
82
case "collaborative" :
89
- mode = searchModeCollaborative
90
83
opts .Mirror = util .OptionalBoolFalse
84
+ opts .Collaborate = util .OptionalBoolTrue
91
85
case "" :
92
- mode = searchModeAny
93
- }
94
-
95
- err := validateSearchInput (opts .OwnerID , modeQuery , mode )
96
- if err != nil {
97
- ctx .Error (http .StatusUnprocessableEntity , "" , err )
86
+ default :
87
+ ctx .Error (http .StatusUnprocessableEntity , "" , fmt .Errorf ("Invalid search mode: \" %s\" " , mode ))
98
88
return
99
89
}
100
90
91
+ var err error
101
92
if opts .OwnerID > 0 {
102
93
var repoOwner * models.User
103
94
if ctx .User != nil && ctx .User .ID == opts .OwnerID {
@@ -113,12 +104,8 @@ func Search(ctx *context.APIContext) {
113
104
}
114
105
}
115
106
116
- if ! repoOwner .IsOrganization () {
117
- if mode == searchModeCollaborative {
118
- opts .Collaborate = util .OptionalBoolTrue
119
- } else if mode != searchModeSource && mode != searchModeFork {
120
- opts .Collaborate = util .OptionalBoolNone
121
- }
107
+ if repoOwner .IsOrganization () {
108
+ opts .Collaborate = util .OptionalBoolFalse
122
109
}
123
110
124
111
// Check visibility.
@@ -168,22 +155,6 @@ func Search(ctx *context.APIContext) {
168
155
})
169
156
}
170
157
171
- func validateSearchInput (ownerID int64 , modeQuery string , mode searchMode ) error {
172
- var errors []string
173
- if mode == 0 {
174
- errors = append (errors , fmt .Sprintf ("Invalid search mode: \" %s\" " , modeQuery ))
175
- }
176
-
177
- if ownerID <= 0 && (mode == searchModeFork || mode == searchModeSource ) {
178
- errors = append (errors , fmt .Sprintf ("Invalid combination of input params: \" mode=%s\" has to be combined with \" uid\" " , modeQuery ))
179
- }
180
-
181
- if len (errors ) > 0 {
182
- return fmt .Errorf (strings .Join (errors , " " ))
183
- }
184
- return nil
185
- }
186
-
187
158
// CreateUserRepo create a repository for a user
188
159
func CreateUserRepo (ctx * context.APIContext , owner * models.User , opt api.CreateRepoOption ) {
189
160
repo , err := models .CreateRepository (ctx .User , owner , models.CreateRepoOptions {
0 commit comments