fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Add ability to filter out archived repositories (#370)

Two changes in this PR:

1. Store the archived status of mirrored repositories in zoekt-mirror-{gerrit,gitlab,github}
- the archive status is stored in the `zoekt.archived` field of the git config of the cloned repository
- this approach is in line with how the existing `zoekt-sourcegraph-indexserver` represents archived repositories
- the other zoekt-mirror binaries are for upstreams that don't have the notion of an archived repository, so I have not changed them

2. Add a new query option, `archived:` which accepts `yes`, `no`. `archived:yes` will mean only results from archived repositories are returned. `archived:no` will mean results from archived repositories are excluded.
- this is achieved by constructing a query using the `RawConfig` query type

+61 -14
+8
cmd/zoekt-mirror-gerrit/main.go
··· 166 166 "zoekt.name": name, 167 167 "zoekt.gerrit-project": k, 168 168 "zoekt.gerrit-host": rootURL.String(), 169 + "zoekt.archived": marshalBool(v.State == "READ_ONLY"), 169 170 } 170 171 171 172 for _, wl := range v.WebLinks { ··· 215 216 } 216 217 return nil 217 218 } 219 + 220 + func marshalBool(b bool) string { 221 + if b { 222 + return "1" 223 + } 224 + return "0" 225 + }
+15
cmd/zoekt-mirror-github/main.go
··· 295 295 if err != nil { 296 296 return err 297 297 } 298 + 299 + archived := false 300 + if r.Archived != nil { 301 + archived = *r.Archived 302 + } 303 + 298 304 config := map[string]string{ 299 305 "zoekt.web-url-type": "github", 300 306 "zoekt.web-url": *r.HTMLURL, ··· 304 310 "zoekt.github-watchers": itoa(r.WatchersCount), 305 311 "zoekt.github-subscribers": itoa(r.SubscribersCount), 306 312 "zoekt.github-forks": itoa(r.ForksCount), 313 + 314 + "zoekt.archived": marshalBool(archived), 307 315 } 308 316 dest, err := gitindex.CloneRepo(destDir, *r.FullName, *r.CloneURL, config) 309 317 if err != nil { ··· 317 325 318 326 return nil 319 327 } 328 + 329 + func marshalBool(b bool) string { 330 + if b { 331 + return "1" 332 + } 333 + return "0" 334 + }
+9
cmd/zoekt-mirror-gitlab/main.go
··· 174 174 175 175 "zoekt.gitlab-stars": strconv.Itoa(p.StarCount), 176 176 "zoekt.gitlab-forks": strconv.Itoa(p.ForksCount), 177 + 178 + "zoekt.archived": marshalBool(p.Archived), 177 179 } 178 180 179 181 cloneURL := p.HTTPURLToRepo ··· 187 189 } 188 190 } 189 191 } 192 + 193 + func marshalBool(b bool) string { 194 + if b { 195 + return "1" 196 + } 197 + return "0" 198 + }
+26 -14
query/parse.go
··· 125 125 } 126 126 127 127 expr = &Repo{r} 128 + case tokArchived: 129 + switch text { 130 + case "yes": 131 + expr = RawConfig(RcOnlyArchived) 132 + case "no": 133 + expr = RawConfig(RcNoArchived) 134 + default: 135 + return nil, 0, fmt.Errorf("query: unknown archived argument %q, want {yes,no}", text) 136 + } 128 137 case tokBranch: 129 138 expr = &Branch{Pattern: text} 130 139 case tokText, tokRegex: ··· 364 373 tokLang = 12 365 374 tokSym = 13 366 375 tokType = 14 376 + tokArchived = 15 367 377 ) 368 378 369 379 var tokNames = map[int]string{ 380 + tokArchived: "Archived", 370 381 tokBranch: "Branch", 371 382 tokCase: "Case", 372 383 tokError: "Error", ··· 384 395 } 385 396 386 397 var prefixes = map[string]int{ 387 - "b:": tokBranch, 388 - "branch:": tokBranch, 389 - "c:": tokContent, 390 - "case:": tokCase, 391 - "content:": tokContent, 392 - "f:": tokFile, 393 - "file:": tokFile, 394 - "r:": tokRepo, 395 - "regex:": tokRegex, 396 - "repo:": tokRepo, 397 - "lang:": tokLang, 398 - "sym:": tokSym, 399 - "t:": tokType, 400 - "type:": tokType, 398 + "archived:": tokArchived, 399 + "b:": tokBranch, 400 + "branch:": tokBranch, 401 + "c:": tokContent, 402 + "case:": tokCase, 403 + "content:": tokContent, 404 + "f:": tokFile, 405 + "file:": tokFile, 406 + "r:": tokRepo, 407 + "regex:": tokRegex, 408 + "repo:": tokRepo, 409 + "lang:": tokLang, 410 + "sym:": tokSym, 411 + "t:": tokType, 412 + "type:": tokType, 401 413 } 402 414 403 415 var reservedWords = map[string]int{
+2
query/parse_test.go
··· 65 65 {"file:abc", &Substring{Pattern: "abc", FileName: true}}, 66 66 {"branch:pqr", &Branch{Pattern: "pqr"}}, 67 67 {"((x|y) )", &Regexp{Regexp: mustParseRE("[xy]")}}, 68 + {"archived:yes", RawConfig(RcOnlyArchived)}, 69 + {"archived:no", RawConfig(RcNoArchived)}, 68 70 {"file:helpers\\.go byte", NewAnd( 69 71 &Substring{Pattern: "helpers.go", FileName: true}, 70 72 &Substring{Pattern: "byte"})},
+1
web/templates.go
··· 170 170 <dt><a href="search?q=-Path%5c+file+Stream">-Path\ file Stream</a></dt><dd>search "Stream", but exclude files containing "Path File"</dd> 171 171 <dt><a href="search?q=sym:data">sym:data</a></span></dt><dd>search for symbol definitions containing "data"</dd> 172 172 <dt><a href="search?q=phone+r:droid">phone r:droid</a></dt><dd>search for "phone" in repositories whose name contains "droid"</dd> 173 + <dt><a href="search?q=phone+archived:no">phone archived:no</a></dt><dd>search for "phone" in repositories that are not archived</dd> 173 174 <dt><a href="search?q=phone+b:master">phone b:master</a></dt><dd>for Git repos, find "phone" in files in branches whose name contains "master".</dd> 174 175 <dt><a href="search?q=phone+b:HEAD">phone b:HEAD</a></dt><dd>for Git repos, find "phone" in the default ('HEAD') branch.</dd> 175 176 </dl>