Skip to content

Commit 7236a5d

Browse files
authored
Support Gitea in the indexserver (#988)
1 parent eab7bf4 commit 7236a5d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

cmd/zoekt-indexserver/config.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ type ConfigEntry struct {
3838
GitilesURL string
3939
CGitURL string
4040
BitBucketServerURL string
41+
GiteaURL string
42+
GiteaUser string
43+
GiteaOrg string
4144
DisableTLS bool
4245
CredentialPath string
4346
ProjectType string
@@ -54,6 +57,7 @@ type ConfigEntry struct {
5457
GerritFetchMetaConfig bool
5558
GerritRepoNameFormat string
5659
ExcludeUserRepos bool
60+
Forks bool
5761
}
5862

5963
func randomize(entries []ConfigEntry) []ConfigEntry {
@@ -200,6 +204,9 @@ func executeMirror(cfg []ConfigEntry, repoDir string, pendingRepos chan<- string
200204
if !c.KeepDeleted {
201205
cmd.Args = append(cmd.Args, "-delete")
202206
}
207+
if c.Forks {
208+
cmd.Args = append(cmd.Args, "-forks")
209+
}
203210
} else if c.GitilesURL != "" {
204211
cmd = exec.Command("zoekt-mirror-gitiles",
205212
"-dest", repoDir, "-name", c.Name)
@@ -288,6 +295,40 @@ func executeMirror(cfg []ConfigEntry, repoDir string, pendingRepos chan<- string
288295
cmd.Args = append(cmd.Args, "-delete")
289296
}
290297
cmd.Args = append(cmd.Args, c.GerritApiURL)
298+
} else if c.GiteaURL != "" {
299+
cmd = exec.Command("zoekt-mirror-gitea", "-dest", repoDir)
300+
if c.GiteaURL != "" {
301+
cmd.Args = append(cmd.Args, "-url", c.GiteaURL)
302+
}
303+
if c.GiteaUser != "" {
304+
cmd.Args = append(cmd.Args, "-user", c.GiteaUser)
305+
} else if c.GiteaOrg != "" {
306+
cmd.Args = append(cmd.Args, "-org", c.GiteaOrg)
307+
}
308+
if c.Name != "" {
309+
cmd.Args = append(cmd.Args, "-name", c.Name)
310+
}
311+
if c.Exclude != "" {
312+
cmd.Args = append(cmd.Args, "-exclude", c.Exclude)
313+
}
314+
if c.CredentialPath != "" {
315+
cmd.Args = append(cmd.Args, "-token", c.CredentialPath)
316+
}
317+
for _, topic := range c.Topics {
318+
cmd.Args = append(cmd.Args, "-topic", topic)
319+
}
320+
for _, topic := range c.ExcludeTopics {
321+
cmd.Args = append(cmd.Args, "-exclude_topic", topic)
322+
}
323+
if c.NoArchived {
324+
cmd.Args = append(cmd.Args, "-no_archived")
325+
}
326+
if !c.KeepDeleted {
327+
cmd.Args = append(cmd.Args, "-delete")
328+
}
329+
if c.Forks {
330+
cmd.Args = append(cmd.Args, "-forks")
331+
}
291332
} else {
292333
log.Printf("executeMirror: ignoring config, because it does not contain any valid repository definition: %v", c)
293334
continue

cmd/zoekt-mirror-gitea/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ func main() {
8989
if err != nil {
9090
log.Fatal(err)
9191
}
92-
clientOptions = append(clientOptions, gitea.SetToken(string(content)))
92+
contentStr := string(content)
93+
// Editors tend to insert newlines that make the token invalid, so clean it up
94+
contentStr = strings.TrimSpace(contentStr)
95+
clientOptions = append(clientOptions, gitea.SetToken(contentStr))
9396
}
9497
client, err := gitea.NewClient(*giteaURL, clientOptions...)
9598
if err != nil {

0 commit comments

Comments
 (0)