Add gerrit implementation

Change-Id: I293cea35572b051cd1d4a0466fe2fd5a06e81ad9
diff --git a/server/config/config.go b/server/config/config.go
index 421e861..86dd7a5 100644
--- a/server/config/config.go
+++ b/server/config/config.go
@@ -12,6 +12,7 @@
 type Config struct {
 	OpenAI OpenAIConfig  `yaml:"openai"`
 	GitHub GitHubConfig  `yaml:"github"`
+	Gerrit GerritConfig  `yaml:"gerrit"`
 	Agents []AgentConfig `yaml:"agents"`
 	Tasks  TasksConfig   `yaml:"tasks"`
 	Git    GitConfig     `yaml:"git"`
@@ -33,6 +34,14 @@
 	Repo  string `yaml:"repo"`
 }
 
+// GerritConfig represents Gerrit integration configuration
+type GerritConfig struct {
+	Username string `yaml:"username"`
+	Password string `yaml:"password"` // HTTP password or API token
+	BaseURL  string `yaml:"base_url"` // Gerrit server URL (e.g. https://gerrit.example.com)
+	Project  string `yaml:"project"`  // Gerrit project name
+}
+
 // AgentConfig represents individual agent configuration
 type AgentConfig struct {
 	Name             string   `yaml:"name"`
@@ -103,6 +112,18 @@
 	if repo := os.Getenv("GITHUB_REPO"); repo != "" {
 		config.GitHub.Repo = repo
 	}
+	if gerritUsername := os.Getenv("GERRIT_USERNAME"); gerritUsername != "" {
+		config.Gerrit.Username = gerritUsername
+	}
+	if gerritPassword := os.Getenv("GERRIT_PASSWORD"); gerritPassword != "" {
+		config.Gerrit.Password = gerritPassword
+	}
+	if gerritBaseURL := os.Getenv("GERRIT_BASE_URL"); gerritBaseURL != "" {
+		config.Gerrit.BaseURL = gerritBaseURL
+	}
+	if gerritProject := os.Getenv("GERRIT_PROJECT"); gerritProject != "" {
+		config.Gerrit.Project = gerritProject
+	}
 
 	// Re-validate after env overrides
 	if err := validateConfig(*config); err != nil {
@@ -183,15 +204,35 @@
 		return fmt.Errorf("openai.model is required")
 	}
 
-	// Validate GitHub config
-	if config.GitHub.Token == "" {
-		return fmt.Errorf("github.token is required")
+	// Validate that at least one Git provider is configured
+	hasGitHub := config.GitHub.Token != "" && config.GitHub.Owner != "" && config.GitHub.Repo != ""
+	hasGerrit := config.Gerrit.Username != "" && config.Gerrit.Password != "" && config.Gerrit.BaseURL != "" && config.Gerrit.Project != ""
+	
+	if !hasGitHub && !hasGerrit {
+		return fmt.Errorf("either GitHub or Gerrit configuration is required")
 	}
-	if config.GitHub.Owner == "" {
-		return fmt.Errorf("github.owner is required")
+	
+	// Validate GitHub config if provided
+	if config.GitHub.Token != "" {
+		if config.GitHub.Owner == "" {
+			return fmt.Errorf("github.owner is required when github.token is provided")
+		}
+		if config.GitHub.Repo == "" {
+			return fmt.Errorf("github.repo is required when github.token is provided")
+		}
 	}
-	if config.GitHub.Repo == "" {
-		return fmt.Errorf("github.repo is required")
+	
+	// Validate Gerrit config if provided
+	if config.Gerrit.Username != "" {
+		if config.Gerrit.Password == "" {
+			return fmt.Errorf("gerrit.password is required when gerrit.username is provided")
+		}
+		if config.Gerrit.BaseURL == "" {
+			return fmt.Errorf("gerrit.base_url is required when gerrit.username is provided")
+		}
+		if config.Gerrit.Project == "" {
+			return fmt.Errorf("gerrit.project is required when gerrit.username is provided")
+		}
 	}
 
 	// Validate agents
@@ -232,3 +273,25 @@
 	}
 	return names
 }
+
+// HasGitHubConfig returns true if GitHub is properly configured
+func (c *Config) HasGitHubConfig() bool {
+	return c.GitHub.Token != "" && c.GitHub.Owner != "" && c.GitHub.Repo != ""
+}
+
+// HasGerritConfig returns true if Gerrit is properly configured
+func (c *Config) HasGerritConfig() bool {
+	return c.Gerrit.Username != "" && c.Gerrit.Password != "" && c.Gerrit.BaseURL != "" && c.Gerrit.Project != ""
+}
+
+// GetPrimaryGitProvider returns the primary git provider type ("github" or "gerrit")
+// If both are configured, GitHub takes precedence for backward compatibility
+func (c *Config) GetPrimaryGitProvider() string {
+	if c.HasGitHubConfig() {
+		return "github"
+	}
+	if c.HasGerritConfig() {
+		return "gerrit"
+	}
+	return ""
+}