### Environment Variables Setup (Bash) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Sets environment variables for API keys required by Codry for OpenAI and Azure OpenAI integrations. Also shows how to start the Codry service. ```bash # For Standard OpenAI export OPENAI_API_KEY="sk-your-openai-api-key" # For Azure OpenAI export AZURE_OPENAI_API_KEY="your-azure-api-key" # Start the service ./codry --config config.yaml ``` -------------------------------- ### Start Codry Service with Configuration Source: https://github.com/maxbolgarin/codry/blob/main/docs/CLAUDE_SETUP.md Launches the Codry service using a specified configuration file. This command assumes the `CLAUDE_API_KEY` environment variable is already set. ```bash # Start the service ./codry --config config.yaml ``` -------------------------------- ### Test Codry Connection with Debug Logging Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md Demonstrates how to start the Codry CLI with debug logging enabled to verify the Bitbucket provider initialization. Successful initialization will be indicated by a specific log message. ```bash # Start with debug logging LOG_LEVEL=debug ./codry --config config.yaml # Should see in logs: # "Bitbucket provider initialized successfully" ``` -------------------------------- ### Setup Go Webhook Server Source: https://context7.com/maxbolgarin/codry/llms.txt Sets up and starts an HTTP webhook server in Go. It initializes the necessary provider and reviewer components, configures the server, and handles graceful shutdown. This server listens for incoming events from VCS platforms. ```go package main import ( "context" "net/http" "github.com/maxbolgarin/codry/internal/server" "github.com/maxbolgarin/codry/internal/reviewer" "github.com/maxbolgarin/codry/internal/provider/github" ) func setupWebhookServer() { // Create provider and reviewer (see previous examples) provider, _ := github.New(providerConfig) reviewerInstance, _ := reviewer.New(reviewerConfig, provider, aiAgent) serverConfig := server.Config{ Address: ":8080", Endpoint: "/webhook", Timeout: 30 * time.Second, EnableHTTPS: false, } webhookServer, err := server.New(serverConfig, provider, reviewerInstance) if err != nil { panic(err) } ctx := context.Background() // Start HTTP server go func() { if err := webhookServer.Start(ctx); err != nil { log.Printf("Server error: %v", err) } }() // Graceful shutdown defer webhookServer.Stop(ctx) } ``` -------------------------------- ### Startup Configuration for Codry with Claude Haiku (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/CLAUDE_SETUP.md Example YAML configuration for Codry using the Claude 3.5 Haiku model, optimized for cost-effectiveness in regular code reviews. Sets specific parameters like max_tokens and temperature. ```yaml # Cost-optimized for regular reviews agent: type: "claude" model: "claude-3-5-haiku-20241022" max_tokens: 2500 temperature: 0.1 ``` -------------------------------- ### Test Service Connection and Review Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Demonstrates how to start the Codry service with debug logging to test its connection and review capabilities. It includes steps for checking logs and verifying API calls and token usage during a test review. ```bash # Start the service with debug logging LOG_LEVEL=debug ./codry --config config.yaml # Check logs for connection test # You should see: "OpenAI connection test successful" ``` -------------------------------- ### Create PR with Reviewer via GitHub CLI Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md Shows how to create a new pull request with a reviewer already specified. This streamlines the process when the reviewer is known at creation time. ```bash # Create PR with bot already as reviewer gh pr create --title "Fix bug" --body "Bug fix" --reviewer your-bot-username ``` -------------------------------- ### Assign Reviewer to PR via GitHub CLI Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md Demonstrates how to create a pull request and add a reviewer using the GitHub CLI. This is useful for automating review assignments. ```bash # Via GitHub CLI gh pr create --title "Add feature" --body "New feature implementation" gh pr edit 123 --add-reviewer your-bot-username ``` -------------------------------- ### Download and Configure Codry Service Source: https://github.com/maxbolgarin/codry/blob/main/README.md This snippet shows the bash commands to download the Codry executable, make it executable, and copy an example configuration file. It's the initial setup step before configuring the service. ```bash # Download the latest release wget https://github.com/maxbolgarin/codry/releases/latest/download/codry # Make it executable chmod +x codry # Copy example configuration cp config.example.yaml config.yaml # Edit configuration nano config.yaml ``` -------------------------------- ### Enable Debug Logging Configuration Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md Provides the YAML configuration snippet to enable debug logging for the service. This is essential for troubleshooting detailed operational issues. ```yaml # Add to your configuration for verbose logging logging: level: debug ``` -------------------------------- ### Environment Variables Setup (Bash) Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md Sets up essential environment variables required for Codry to authenticate with Bitbucket and its AI provider. This includes tokens for Bitbucket, webhook secrets, and API keys for AI services like Claude, OpenAI, or Gemini. ```bash # For Bitbucket export BITBUCKET_TOKEN="your-app-password-here" export BITBUCKET_WEBHOOK_SECRET="your-webhook-secret" # For AI provider (choose one) export CLAUDE_API_KEY="sk-ant-your-claude-api-key" export OPENAI_API_KEY="sk-your-openai-api-key" export GEMINI_API_KEY="your-gemini-api-key" # Start the service ./codry --config config.yaml ``` -------------------------------- ### Initialize and Start Code Review Service (Go) Source: https://github.com/maxbolgarin/codry/blob/main/docs/REFACTORING.md This Go code snippet demonstrates how to initialize and start the refactored code review service. It shows loading configuration for various providers and AI models, creating the service instance, and running its lifecycle methods. Dependencies include the 'config', 'service', and 'logze' packages. ```go package main import ( "context" "github.com/maxbolgarin/codry/internal/config" "github.com/maxbolgarin/codry/internal/service" "github.com/maxbolgarin/logze/v2" "log" "os" ) func main() { // Load configuration - supports multiple platforms and AI models cfg := &config.Config{ Provider: config.ProviderConfig{ Type: "github", // or "gitlab" Token: os.Getenv("GITHUB_TOKEN"), // ... other settings }, Agent: config.AgentConfig{ Type: "claude", // or "openai", "gemini" APIKey: os.Getenv("CLAUDE_API_KEY"), Model: "claude-3-5-haiku-20241022", // ... other settings }, } // Create and start service logger := logze.Default() svc, err := service.NewCodeReviewService(cfg, logger) if err != nil { log.Fatal(err) } ctx := context.Background() if err := svc.Initialize(ctx); err != nil { log.Fatal(err) } if err := svc.Start(ctx); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Start Codry Service with Debug Logging (Bash) Source: https://github.com/maxbolgarin/codry/blob/main/docs/CLAUDE_SETUP.md Starts the Codry service with debug logging enabled to monitor connection tests. This command helps in diagnosing connection issues by providing detailed output in the logs. ```bash # Start the service with debug logging LOG_LEVEL=debug ./codry --config config.yaml # Check logs for connection test # You should see: "Claude connection test successful" ``` -------------------------------- ### Configure GitHub Enterprise Server URL Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md This YAML snippet shows how to configure the `base_url` for the GitHub provider when using GitHub Enterprise Server. Replace `https://github.your-company.com` with your actual GitHub Enterprise instance URL. ```yaml provider: type: "github" base_url: "https://github.your-company.com" # ... other settings ``` -------------------------------- ### Customize Webhook Trigger Actions in Go Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md This Go code snippet demonstrates how to customize the list of GitHub webhook actions that trigger reviews within the service. You can add or remove actions from the `relevantActions` slice as needed. ```go // In internal/webhook/handler.go relevantActions := []string{ "opened", "reopened", "synchronize", "review_requested", "ready_for_review", // Add custom actions here } ``` -------------------------------- ### Code Reviews Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Optimizes OpenAI model settings for code reviews, recommending 'gpt-4o-mini' with low temperature for consistency and a sufficient token limit. ```yaml agent: type: "openai" model: "gpt-4o-mini" temperature: 0.1 # More consistent reviews max_tokens: 2000 # Sufficient for most reviews ``` -------------------------------- ### Run Multi-Agent Instances Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Demonstrates how to run multiple instances of the Codry service concurrently, each configured with different agents (e.g., OpenAI for GitHub, Gemini for GitLab). This allows for specialized configurations. ```bash # Instance 1: OpenAI for GitHub OPENAI_API_KEY=sk-... ./codry --config config-github-openai.yaml # Instance 2: Gemini for GitLab GEMINI_API_KEY=... ./codry --config config-gitlab-gemini.yaml ``` -------------------------------- ### Set GitHub Environment Variables Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md These bash commands export the necessary environment variables for the GitHub provider to authenticate and communicate with the GitHub API. Ensure these variables are set in your environment before running the service. ```bash export GITHUB_TOKEN="ghp_xxxxxxxxxxxxxxxxxxxx" export GITHUB_WEBHOOK_SECRET="your-webhook-secret" export GEMINI_API_KEY="your-gemini-api-key" ``` -------------------------------- ### Enterprise Codry Configuration for Bitbucket Server Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md An example of Codry configuration for an enterprise using Bitbucket Server. It includes the server's base URL, a specific bot username, a higher `rate_limit_wait`, and selects the OpenAI GPT-4o agent. ```yaml # Enterprise server setup provider: type: "bitbucket" base_url: "https://bitbucket.company.com/rest/api/1.0" token: "${BITBUCKET_SERVER_TOKEN}" bot_username: "code-review-bot" rate_limit_wait: 2m agent: type: "openai" model: "gpt-4o" max_tokens: 4000 ``` -------------------------------- ### Migrate from Gemini to OpenAI Configuration Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Provides a YAML configuration snippet illustrating the transition from using the Gemini agent to the OpenAI agent. It highlights the necessary changes in `agent.type` and `agent.model`. ```yaml # Change this: agent: type: "gemini" api_key: "${GEMINI_API_KEY}" model: "gemini-2.5-flash-preview-05-20" # To this: agent: type: "openai" api_key: "${OPENAI_API_KEY}" model: "gpt-4o-mini" ``` -------------------------------- ### Startup Codry Configuration for Bitbucket Cloud Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md A basic Codry configuration for a startup using Bitbucket Cloud. It specifies the Bitbucket provider with a token and bot username, and selects the Claude agent with a specific model. ```yaml # Simple cloud setup provider: type: "bitbucket" token: "${BITBUCKET_TOKEN}" bot_username: "ai-reviewer" agent: type: "claude" model: "claude-3-5-haiku-20241022" max_tokens: 2500 ``` -------------------------------- ### Configure GitHub Provider in config.yaml Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md This YAML configuration defines the settings for the GitHub provider, including the server address, webhook endpoint, timeout, GitHub API base URL, authentication token, webhook secret, bot username, and rate limit wait time. It also includes settings for the review agent. ```yaml server: address: ":8080" endpoint: "/webhook" timeout: 30s provider: type: "github" base_url: "https://github.com" # or your GitHub Enterprise URL token: "${GITHUB_TOKEN}" webhook_secret: "${GITHUB_WEBHOOK_SECRET}" bot_username: "your-bot-username" rate_limit_wait: 1m agent: type: "gemini" api_key: "${GEMINI_API_KEY}" # ... other agent settings review: enable_description_generation: true enable_code_review: true # ... other review settings ``` -------------------------------- ### Start Codry Service Source: https://github.com/maxbolgarin/codry/blob/main/README.md This bash command initiates the Codry service, specifying the path to the configuration file. It assumes the 'codry' executable has been downloaded and made executable. ```bash ./codry --config config.yaml ``` -------------------------------- ### Migrate from GitHub to Bitbucket Configuration Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md Shows the configuration changes required to switch from using GitHub as a provider to Bitbucket. This involves updating the `provider.type` and the relevant API `base_url` and `token`. ```yaml # Change this: provider: type: "github" token: "${GITHUB_TOKEN}" base_url: "https://github.com" # To this: provider: type: "bitbucket" token: "${BITBUCKET_TOKEN}" base_url: "https://api.bitbucket.org" ``` -------------------------------- ### Enterprise Configuration for Codry with Claude Sonnet (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/CLAUDE_SETUP.md Example YAML configuration for Codry using the Claude 3.5 Sonnet model, focused on quality for critical reviews. Includes settings for max_tokens and temperature suitable for complex tasks. ```yaml # Quality-focused for critical reviews agent: type: "claude" model: "claude-3-5-sonnet-20241022" max_tokens: 6000 temperature: 0.05 ``` -------------------------------- ### Add New Provider Implementation (Go) Source: https://github.com/maxbolgarin/codry/blob/main/docs/REFACTORING.md Example Go code demonstrating how to create a new provider implementation for Bitbucket. This involves defining a Provider struct and implementing the necessary methods from the CodeProvider interface. ```go // internal/providers/bitbucket/provider.go type Provider struct { ... } func (p *Provider) GetMergeRequest(...) { ... } // Implement all CodeProvider interface methods ``` -------------------------------- ### LocalAI Custom Endpoint Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Sets up Codry to connect to a local LocalAI instance. Requires a dummy API key and the LocalAI endpoint URL. ```yaml agent: type: "openai" api_key: "dummy" model: "gpt-3.5-turbo" base_url: "http://localhost:8080" ``` -------------------------------- ### Detailed Analysis Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Configures OpenAI settings for detailed analysis, using 'gpt-4o' with a very low temperature for maximum consistency and a large token limit for extensive output. ```yaml agent: type: "openai" model: "gpt-4o" temperature: 0.05 # Very consistent max_tokens: 8000 # Detailed analysis ``` -------------------------------- ### Bitbucket Project Identification Format Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md Illustrates the standard Bitbucket format for identifying repositories using the workspace/repository structure. This format is used in API calls to reference specific repositories. ```bash # Repository URL: https://bitbucket.org/myworkspace/myrepo # Project ID: myworkspace/myrepo # API calls use this format: # GET /2.0/repositories/myworkspace/myrepo/pullrequests/123 ``` -------------------------------- ### Configure Debug Logging Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Shows how to enable debug logging for OpenAI API interactions by adding a logging configuration to the `config.yaml` file. This is useful for troubleshooting and monitoring API calls. ```yaml # Add to your config for detailed OpenAI API logs logging: level: debug ``` -------------------------------- ### Add New AI Agent Implementation (Go) Source: https://github.com/maxbolgarin/codry/blob/main/docs/REFACTORING.md Example Go code for implementing a new AI agent, such as Cohere. This includes defining the Agent struct and its methods like GenerateDescription, ReviewCode, and SummarizeChanges. ```go // internal/agents/cohere/agent.go type Agent struct { ... } func (a *Agent) GenerateDescription(...) { ... } func (a *Agent) ReviewCode(...) { ... } func (a *Agent) SummarizeChanges(...) { ... } ``` -------------------------------- ### Migrate from GitLab to Bitbucket Configuration Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md Details the configuration adjustments needed to migrate from GitLab to Bitbucket. Similar to GitHub migration, this involves changing the `provider.type` and updating the `base_url` and `token`. ```yaml # Change this: provider: type: "gitlab" token: "${GITLAB_TOKEN}" base_url: "https://gitlab.com" # To this: provider: type: "bitbucket" token: "${BITBUCKET_TOKEN}" base_url: "https://api.bitbucket.org" ``` -------------------------------- ### Azure OpenAI Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Sets up Codry to use Azure OpenAI Service. Requires an Azure API key, the deployment name as the model, and the Azure OpenAI endpoint. ```yaml agent: type: "openai" api_key: "${AZURE_OPENAI_API_KEY}" model: "gpt-4o" # Your deployment name base_url: "https://your-resource.openai.azure.com" max_retries: 3 retry_delay: 5s temperature: 0.1 max_tokens: 4000 ``` -------------------------------- ### Standard OpenAI Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Configures the Codry agent to use the standard OpenAI API. Requires an API key and specifies the model, retry settings, temperature, and token limits. ```yaml agent: type: "openai" api_key: "${OPENAI_API_KEY}" # Your OpenAI API key model: "gpt-4o-mini" # Recommended for cost-effectiveness max_retries: 3 retry_delay: 5s temperature: 0.1 # Lower = more consistent, higher = more creative max_tokens: 4000 # Adjust based on your needs ``` -------------------------------- ### Configure Codry Agent for Claude (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/CLAUDE_SETUP.md Demonstrates how to configure the Codry agent to use Claude models, migrating from OpenAI or Gemini. This involves changing the agent type and specifying the appropriate Claude model. ```yaml # Change this: agent: type: "openai" api_key: "${OPENAI_API_KEY}" model: "gpt-4o-mini" # To this: agent: type: "claude" api_key: "${CLAUDE_API_KEY}" model: "claude-3-5-haiku-20241022" ``` ```yaml # Change this: agent: type: "gemini" api_key: "${GEMINI_API_KEY}" model: "gemini-2.5-flash-preview-05-20" # To this: agent: type: "claude" api_key: "${CLAUDE_API_KEY}" model: "claude-3-5-haiku-20241022" ``` -------------------------------- ### Creative Descriptions Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Adjusts OpenAI model settings for generating creative descriptions, using 'gpt-4o' with a slightly higher temperature for more varied output and a smaller token limit. ```yaml agent: type: "openai" model: "gpt-4o" temperature: 0.3 # More creative descriptions max_tokens: 1000 # Concise descriptions ``` -------------------------------- ### Enable Debug Logging in Codry Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md This configuration snippet enables debug logging for the Codry service, providing more detailed logs for troubleshooting. It should be added to the application's configuration file. ```yaml logging: level: debug ``` -------------------------------- ### Configure Claude for Budget-Conscious Usage in Codry Source: https://github.com/maxbolgarin/codry/blob/main/docs/CLAUDE_SETUP.md An advanced configuration for Codry's agent focused on cost-effectiveness when using Claude. It selects a cost-efficient model with a moderate temperature and a reduced token limit for concise reviews. ```yaml agent: type: "claude" model: "claude-3-5-haiku-20241022" temperature: 0.2 # Slightly more creative max_tokens: 2000 # Concise reviews ``` -------------------------------- ### Configure Standard Claude Agent in Codry Source: https://github.com/maxbolgarin/codry/blob/main/docs/CLAUDE_SETUP.md Sets up the Codry agent to use Claude models with standard parameters. It specifies the agent type, API key, model, retry settings, temperature, and maximum tokens. ```yaml agent: type: "claude" api_key: "${CLAUDE_API_KEY}" # Your Anthropic API key model: "claude-3-5-haiku-20241022" # Recommended for cost-effectiveness max_retries: 3 retry_delay: 5s temperature: 0.1 # Lower = more consistent, higher = more creative max_tokens: 4000 # Adjust based on your needs ``` -------------------------------- ### Setup and Run Reviewer Component in Go Source: https://context7.com/maxbolgarin/codry/llms.txt This Go code demonstrates how to set up and use the Reviewer component. It configures review parameters, initializes the reviewer with a code provider and AI agent, and shows how to review merge requests by IID, by MergeRequest object, or by handling webhook events. Dependencies include the internal reviewer, model, and agent packages. ```go package main import ( "context" "github.com/maxbolgarin/codry/internal/reviewer" "github.com/maxbolgarin/codry/internal/model" ) func setupReviewer(provider interfaces.CodeProvider, aiAgent *agent.Agent) { config := reviewer.Config{ MaxFilesPerMR: 50, MinFilesForDescription: 3, ProcessingDelay: 5 * time.Second, UpdateDescriptionOnMR: true, EnableDescriptionGeneration: true, EnableChangesOverviewGeneration: true, EnableArchitectureReview: true, EnableCodeReview: true, Language: "en", Verbose: true, FileFilter: reviewer.FileFilter{ MaxFileSize: 1000000, AllowedExtensions: []string{'.go', '.js', '.ts', '.py'}, ExcludedPaths: []string{"vendor/", "node_modules/", "*.min.js"}, IncludeOnlyCode: false, }, } rev, err := reviewer.New(config, provider, aiAgent) if err != nil { panic(err) } ctx := context.Background() // Review a specific merge request by IID err = rev.GetAndReviewMergeRequest(ctx, "owner/repo", 123) // Or review with an existing MergeRequest object mr := &model.MergeRequest{ IID: 123, Title: "Add authentication", SourceBranch: "feature/auth", TargetBranch: "main", SHA: "abc123def", } err = rev.ReviewMergeRequest(ctx, "owner/repo", mr) // Handle webhook event event := &model.CodeEvent{ Type: "pull_request", Action: "opened", ProjectID: "owner/repo", MergeRequest: mr, User: &model.User{Username: "developer"}, } err = rev.HandleEvent(ctx, event) } ``` -------------------------------- ### Minimal Codry Configuration Source: https://github.com/maxbolgarin/codry/blob/main/README.md This YAML snippet provides a minimal configuration for the Codry service, defining server address, VCS provider details (type, token, webhook secret, bot username), and AI agent settings (type, API key, model). It serves as a basic setup for getting started. ```yaml server: address: ":8080" provider: type: "github" # or "gitlab", "bitbucket" token: "${GITHUB_TOKEN}" webhook_secret: "${GITHUB_WEBHOOK_SECRET}" bot_username: "codry-bot" agent: type: "claude" # or "openai", "gemini" api_key: "${CLAUDE_API_KEY}" model: "claude-3-5-haiku-20241022" ``` -------------------------------- ### Initialize Codry Application Service in Go Source: https://context7.com/maxbolgarin/codry/llms.txt This Go code snippet demonstrates the main entry point for the Codry application. It initializes a context, loads configuration from a file or environment variables, creates the Codry service instance, and starts the webhook server to listen for incoming Version Control System (VCS) events. Error handling is included for configuration loading and service initialization. ```go package main import ( "github.com/maxbolgarin/codry/internal/app" "github.com/maxbolgarin/contem" "github.com/maxbolgarin/logze/v2" ) func main() { var err error ctx := contem.New(contem.WithLogger(logze.DefaultPtr()), contem.Exit(&err)) defer ctx.Shutdown() // Load configuration from file or environment cfg, err := app.LoadConfig("config.yaml") if err != nil { logze.DefaultPtr().Error("cannot load config", "error", err) return } // Initialize the Codry service codry, err := app.New(ctx, cfg) if err != nil { logze.DefaultPtr().Error("cannot create service", "error", err) return } // Start webhook server for receiving VCS events if err := codry.StartWebhook(ctx); err != nil { logze.DefaultPtr().Error("webhook server failed", "error", err) } } ``` -------------------------------- ### GitHub Webhook Payload for Review Requested Event Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md Illustrates the JSON structure of a GitHub webhook payload for the 'review_requested' event. This helps in understanding the data received when a review is requested. ```json { "action": "review_requested", "pull_request": { "id": 123, "number": 456, "requested_reviewers": [ {"login": "your-bot-username"} ] } } ``` -------------------------------- ### Create and Use AI Agent with Multiple Providers (Go) Source: https://context7.com/maxbolgarin/codry/llms.txt Demonstrates how to initialize an AI agent using different providers (Claude, OpenAI, Gemini) with their respective configurations. It then shows how to use the agent to generate pull request descriptions and architecture reviews from a given code diff. ```go package main import ( "context" "fmt" "github.com/maxbolgarin/codry/internal/agent" "github.com/maxbolgarin/contem" "time" ) func createAIAgent() { ctx := contem.New() // Claude configuration claudeConfig := agent.Config{ Type: agent.Claude, APIKey: "sk-ant-your-claude-api-key", Model: "claude-3-5-haiku-20241022", Temperature: 0.5, MaxTokens: 10000, Timeout: 30 * time.Second, MaxRetries: 5, RetryDelay: 5 * time.Second, } // OpenAI configuration openaiConfig := agent.Config{ Type: agent.OpenAI, APIKey: "sk-your-openai-api-key", Model: "gpt-4o-mini", Temperature: 0.5, MaxTokens: 10000, } // Gemini configuration geminiConfig := agent.Config{ Type: agent.Gemini, APIKey: "your-gemini-api-key", Model: "gemini-2.5-flash-preview-05-20", Temperature: 0.5, MaxTokens: 10000, } // Create the agent with your preferred AI provider aiAgent, err := agent.New(ctx, claudeConfig) if err != nil { panic(err) } // Generate PR description from diff diff := `--- a/main.go +++ b/main.go @@ -10,6 +10,12 @@ func main() { + // New feature: Add user authentication + auth := NewAuthHandler() + router.Use(auth.Middleware()) ` description, err := aiAgent.GenerateDescription(ctx, diff) if err != nil { panic(err) } fmt.Println("Generated description:", description) // Generate architecture review architectureReview, err := aiAgent.GenerateArchitectureReview(ctx, diff) if err != nil { panic(err) } fmt.Println("Architecture review:", architectureReview) } ``` -------------------------------- ### GitHub Webhook Payload for Opened Event Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md Shows the JSON structure of a GitHub webhook payload for the 'opened' event when a pull request is created. This is useful for tracking new pull requests. ```json { "action": "opened", "pull_request": { "id": 123, "number": 456, "state": "open" } } ``` -------------------------------- ### Create and Use GitHub Provider in Go Source: https://context7.com/maxbolgarin/codry/llms.txt This Go code demonstrates how to create a GitHub provider instance using a configuration object and interact with its methods. It shows examples of fetching pull request details, retrieving file diffs, creating inline comments, and updating a pull request's description. ```go package main import ( "context" "fmt" "github.com/maxbolgarin/codry/internal/model" "github.com/maxbolgarin/codry/internal/provider/github" ) func createGitHubProvider() { config := model.ProviderConfig{ BaseURL: "https://github.com", // Or GitHub Enterprise URL Token: "ghp_your_github_token", WebhookSecret: "your_webhook_secret", BotUsername: "codry-bot", } provider, err := github.New(config) if err != nil { panic(err) } ctx := context.Background() // Get a specific pull request pr, err := provider.GetMergeRequest(ctx, "owner/repo", 123) if err != nil { panic(err) } fmt.Printf("PR: %s (branch: %s -> %s)\n", pr.Title, pr.SourceBranch, pr.TargetBranch) // Get file diffs for the pull request diffs, err := provider.GetMergeRequestDiffs(ctx, "owner/repo", 123) if err != nil { panic(err) } for _, diff := range diffs { fmt.Printf("File: %s (new: %v, deleted: %v)\n", diff.NewPath, diff.IsNew, diff.IsDeleted) } // Create an inline code comment comment := &model.Comment{ Body: "Consider using a constant here for better maintainability.", FilePath: "src/main.go", Line: 42, Type: model.CommentTypeInline, } err = provider.CreateComment(ctx, "owner/repo", 123, comment) // Update PR description err = provider.UpdateMergeRequestDescription(ctx, "owner/repo", 123, "## Summary\nUpdated description with AI-generated content") } ``` -------------------------------- ### Check Service Health Endpoint Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md This bash command demonstrates how to perform a health check on the running service. Accessing the `/health` endpoint on the specified port (defaulting to 8080) can help verify if the service is operational. ```bash curl http://localhost:8080/health ``` -------------------------------- ### Perform Code Review with and without Context (Go) Source: https://context7.com/maxbolgarin/codry/llms.txt Illustrates how to perform a code review using the AI agent, analyzing a given file's content and its changes (diff). It also shows an enhanced review process that incorporates additional context such as dependencies and project coding patterns. ```go package main import ( "context" "fmt" "github.com/maxbolgarin/codry/internal/agent" "github.com/maxbolgarin/codry/internal/model" "github.com/maxbolgarin/codry/internal/prompts" ) func performCodeReview(aiAgent *agent.Agent) { ctx := context.Background() filename := "internal/handler/user.go" fullFileContent := `package handler import "net/http" func GetUser(w http.ResponseWriter, r *http.Request) { userID := r.URL.Query().Get("id") user, err := db.FindUser(userID) if err != nil { http.Error(w, err.Error(), 500) return } json.NewEncoder(w).Encode(user)` cleanDiff := `@@ -5,6 +5,11 @@ func GetUser(w http.ResponseWriter, r *http.Request) { + userID := r.URL.Query().Get("id") + user, err := db.FindUser(userID) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + json.NewEncoder(w).Encode(user)` // Simple code review review, err := aiAgent.ReviewCode(ctx, filename, fullFileContent, cleanDiff) if err != nil { panic(err) } // Result structure: model.FileReviewResult fmt.Printf("File: %s\n", review.File) for _, comment := range review.Comments { fmt.Printf("Line %d [%s]: %s\n", comment.Line, comment.Severity, comment.Message) fmt.Printf(" Suggestion: %s\n", comment.Suggestion) } // Enhanced review with context (dependencies, project style, etc.) enhancedCtx := &prompts.EnhancedContext{ CleanDiff: cleanDiff, FullFileContent: fullFileContent, Dependencies: []string{"net/http", "encoding/json"}, ProjectPatterns: "Use structured logging, wrap errors with context", } enhancedReview, err := aiAgent.ReviewCodeWithContext(ctx, filename, enhancedCtx) if err != nil { panic(err) } // Process enhancedReview results... } ``` -------------------------------- ### Configure Rate Limiting and Retries Source: https://github.com/maxbolgarin/codry/blob/main/docs/GITHUB_SETUP.md This YAML configuration specifies settings related to rate limiting and retries for interacting with the GitHub API and the review agent. `rate_limit_wait` defines the delay when rate limits are hit, and `max_retries` and `retry_delay` configure the agent's retry behavior. ```yaml provider: rate_limit_wait: 1m # Wait time when rate limited agent: max_retries: 3 retry_delay: 5s ``` -------------------------------- ### Building and Running Codry from Source Source: https://github.com/maxbolgarin/codry/blob/main/README.md This Bash script outlines the steps to clone the Codry repository, build the executable, run tests, and start the application in development mode. It utilizes `make` commands for streamlined development workflows. ```bash # Clone repository git clone https://github.com/maxbolgarin/codry.git cd codry # Build make build # Run tests make test # Run with development config make dev ``` -------------------------------- ### Test Bitbucket Webhook Delivery Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md Outlines the steps to test webhook delivery to Codry by creating a test pull request in Bitbucket and then checking the Codry logs for incoming webhook processing. This confirms that Bitbucket events are reaching the service. ```bash # Test webhook delivery # Create a test PR and check logs for webhook processing ``` -------------------------------- ### Set Claude API Key Environment Variable Source: https://github.com/maxbolgarin/codry/blob/main/docs/CLAUDE_SETUP.md Exports the Anthropic API key as an environment variable for Codry to use. This is a crucial step for authenticating with the Claude API. ```bash # For Claude export CLAUDE_API_KEY="sk-ant-your-claude-api-key" ``` -------------------------------- ### Local Model Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Configures Codry to use a local OpenAI-compatible API, such as Ollama or LocalAI. Uses a dummy API key and the local endpoint URL. ```yaml agent: type: "openai" api_key: "dummy" # Not used for local models model: "llama3" # Your model name base_url: "http://localhost:11434" # Ollama default endpoint max_retries: 3 retry_delay: 5s temperature: 0.1 max_tokens: 4000 ``` -------------------------------- ### Distinguish User vs. Workspace Repositories Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md Explains the difference between user repositories (username/repo-name) and workspace repositories (workspace-name/repo-name) in Bitbucket. It clarifies that both formats are handled identically by the API. ```yaml # User repositories: username/repo-name # Example: john-doe/my-project # Workspace repositories: workspace-name/repo-name # Example: acme-corp/payment-service # Both work the same way with the API ``` -------------------------------- ### OpenRouter Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Configures Codry to use OpenRouter as a proxy for OpenAI models. Requires an OpenRouter API key and specifies the OpenRouter API base URL. ```yaml agent: type: "openai" api_key: "${OPENROUTER_API_KEY}" model: "openai/gpt-4o-mini" base_url: "https://openrouter.ai/api" ``` -------------------------------- ### Secure Token Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/BITBUCKET_SETUP.md Illustrates a security best practice for configuring the provider token in `config.yaml`. It emphasizes using environment variables for sensitive information like app passwords, enhancing security by avoiding hardcoding credentials. ```yaml # Use app passwords instead of OAuth for simpler setup provider: token: "${BITBUCKET_APP_PASSWORD}" # More secure than password ``` -------------------------------- ### Ollama Custom Endpoint Configuration (YAML) Source: https://github.com/maxbolgarin/codry/blob/main/docs/OPENAI_SETUP.md Configures Codry to use a local Ollama instance as an OpenAI-compatible API. Uses a dummy API key and the default Ollama endpoint. ```yaml agent: type: "openai" api_key: "dummy" model: "codellama:7b" base_url: "http://localhost:11434" ```