Skip to content

Commit 21161b4

Browse files
authored
Merge pull request #87 from cbullinger/qa-fixes
Copier Tool: QA fixes post-testing for sample app usage
2 parents 04cd544 + b67027f commit 21161b4

24 files changed

+1821
-897
lines changed

examples-copier/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Binaries
22
examples-copier
3+
code-copier
34
*.exe
45
*.exe~
56
*.dll

examples-copier/QUICK-REFERENCE.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,25 @@ commit_strategy:
108108
## Message Templates
109109

110110
### Available Variables
111-
- `${rule_name}` - Copy rule name
112-
- `${source_repo}` - Source repository
113-
- `${target_repo}` - Target repository
114-
- `${source_branch}` - Source branch
115-
- `${target_branch}` - Target branch
116-
- `${file_count}` - Number of files
117-
- Custom variables from regex patterns
111+
- `${rule_name}` - Copy rule name (e.g., "java-aggregation-examples")
112+
- `${source_repo}` - Source repository (e.g., "mongodb/aggregation-tasks")
113+
- `${target_repo}` - Target repository (e.g., "mongodb/vector-search")
114+
- `${source_branch}` - Source branch (e.g., "main")
115+
- `${target_branch}` - Target branch (e.g., "main")
116+
- `${file_count}` - Number of files (e.g., "3")
117+
- `${pr_number}` - Source PR number (e.g., "42")
118+
- `${commit_sha}` - Source commit SHA (e.g., "abc123")
119+
- Custom variables from regex patterns (e.g., `${lang}`, `${file}`)
118120

119121
### Examples
120122
```yaml
121123
commit_message: "Update ${category} examples from ${lang}"
122-
pr_title: "Update ${category} examples"
123-
pr_body: "Copying ${file_count} files from ${source_repo}"
124+
pr_title: "Update ${lang} examples"
125+
pr_body: |
126+
Files updated: ${file_count} using ${rule_name} match pattern
127+
128+
Source: ${source_repo}
129+
PR: #${pr_number}
124130
```
125131

126132
## API Endpoints

examples-copier/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,15 +458,13 @@ docker run -p 8080:8080 --env-file .env examples-copier
458458

459459
### Getting Started
460460

461-
- **[Configuration Guide](docs/CONFIGURATION-GUIDE.md)** - Complete configuration reference ⭐ NEW
461+
- **[Configuration Guide](docs/CONFIGURATION-GUIDE.md)** - Complete configuration reference
462462
- **[Pattern Matching Guide](docs/PATTERN-MATCHING-GUIDE.md)** - Pattern matching with examples
463463
- **[Local Testing](docs/LOCAL-TESTING.md)** - Test locally before deploying
464464
- **[Deployment Guide](docs/DEPLOYMENT.md)** - Deploy to production
465-
- **[Deployment Checklist](docs/DEPLOYMENT-CHECKLIST.md)** - Step-by-step deployment checklist
466465

467466
### Reference
468467

469-
- **[Pattern Matching Cheat Sheet](docs/PATTERN-MATCHING-CHEATSHEET.md)** - Quick pattern syntax reference
470468
- **[Architecture](docs/ARCHITECTURE.md)** - System design and components
471469
- **[Troubleshooting](docs/TROUBLESHOOTING.md)** - Common issues and solutions
472470
- **[FAQ](docs/FAQ.md)** - Frequently asked questions

examples-copier/cmd/test-webhook/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,5 @@ jobs:
414414
- [Webhook Testing Guide](../../docs/WEBHOOK-TESTING.md) - Comprehensive testing guide
415415
- [Local Testing](../../docs/LOCAL-TESTING.md) - Local development
416416
- [Test Payloads](../../test-payloads/README.md) - Example payloads
417-
- [Quick Reference](../../docs/QUICK-REFERENCE.md) - All commands
417+
- [Quick Reference](../../QUICK-REFERENCE.md) - All commands
418418

examples-copier/configs/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,5 @@ examples-copier/
267267
268268
- [CONFIGURATION-GUIDE.md](../docs/CONFIGURATION-GUIDE.md) - Variable validation and reference
269269
- [DEPLOYMENT.md](../docs/DEPLOYMENT.md) - Complete deployment guide
270-
- [DEPLOYMENT-CHECKLIST.md](../docs/DEPLOYMENT-CHECKLIST.md) - Step-by-step checklist
271270
- [LOCAL-TESTING.md](../docs/LOCAL-TESTING.md) - Local development guide
272271

examples-copier/configs/env.yaml.example

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,27 @@ env_variables:
111111
# DEFAULT BEHAVIORS (OPTIONAL)
112112
# =============================================================================
113113
# System-wide defaults that individual config rules can override
114-
114+
115115
DEFAULT_RECURSIVE_COPY: "true" # Default recursive copy behavior (default: true)
116116
DEFAULT_PR_MERGE: "false" # Default auto-merge PRs without review (default: false)
117117
DEFAULT_COMMIT_MESSAGE: "Automated PR with updated examples" # Default commit message (default: shown)
118+
119+
# =============================================================================
120+
# GITHUB API CONFIGURATION (OPTIONAL)
121+
# =============================================================================
122+
# Fine-tune GitHub API retry and polling behavior
123+
124+
# GitHub API Retry Configuration
125+
# Controls retry behavior when GitHub API calls fail due to eventual consistency
126+
# GITHUB_API_MAX_RETRIES: "3" # Number of retry attempts (default: 3)
127+
# GITHUB_API_INITIAL_RETRY_DELAY: "500" # Initial retry delay in milliseconds (default: 500)
128+
# # Uses exponential backoff: 500ms, 1s, 2s, etc.
129+
130+
# PR Merge Polling Configuration
131+
# Controls how long to wait for GitHub to compute PR mergeability
132+
# PR_MERGE_POLL_MAX_ATTEMPTS: "20" # Max polling attempts (default: 20)
133+
# PR_MERGE_POLL_INTERVAL: "500" # Polling interval in milliseconds (default: 500)
134+
# # Total wait time = attempts × interval (default: ~10 seconds)
118135

119136
# =============================================================================
120137
# TESTING / DEVELOPMENT OVERRIDES (DO NOT USE IN PRODUCTION)

examples-copier/configs/environment.go

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ type Config struct {
4747
SlackUsername string
4848
SlackIconEmoji string
4949
SlackEnabled bool
50+
51+
// GitHub API retry configuration
52+
GitHubAPIMaxRetries int
53+
GitHubAPIInitialRetryDelay int // in milliseconds
54+
55+
// PR merge polling configuration
56+
PRMergePollMaxAttempts int
57+
PRMergePollInterval int // in milliseconds
5058
}
5159

5260
const (
@@ -78,11 +86,15 @@ const (
7886
AuditDatabase = "AUDIT_DATABASE"
7987
AuditCollection = "AUDIT_COLLECTION"
8088
MetricsEnabled = "METRICS_ENABLED"
81-
SlackWebhookURL = "SLACK_WEBHOOK_URL"
82-
SlackChannel = "SLACK_CHANNEL"
83-
SlackUsername = "SLACK_USERNAME"
84-
SlackIconEmoji = "SLACK_ICON_EMOJI"
85-
SlackEnabled = "SLACK_ENABLED"
89+
SlackWebhookURL = "SLACK_WEBHOOK_URL"
90+
SlackChannel = "SLACK_CHANNEL"
91+
SlackUsername = "SLACK_USERNAME"
92+
SlackIconEmoji = "SLACK_ICON_EMOJI"
93+
SlackEnabled = "SLACK_ENABLED"
94+
GitHubAPIMaxRetries = "GITHUB_API_MAX_RETRIES"
95+
GitHubAPIInitialRetryDelay = "GITHUB_API_INITIAL_RETRY_DELAY"
96+
PRMergePollMaxAttempts = "PR_MERGE_POLL_MAX_ATTEMPTS"
97+
PRMergePollInterval = "PR_MERGE_POLL_INTERVAL"
8698
)
8799

88100
// NewConfig returns a new Config instance with default values
@@ -99,9 +111,13 @@ func NewConfig() *Config {
99111
WebhookSecretName: "projects/1054147886816/secrets/webhook-secret/versions/latest", // default webhook secret name for GCP Secret Manager
100112
CopierLogName: "copy-copier-log", // default log name for logging to GCP
101113
GoogleCloudProjectId: "github-copy-code-examples", // default project ID for logging to GCP
102-
DefaultRecursiveCopy: true, // system-wide default for recursive copying that individual config entries can override.
103-
DefaultPRMerge: false, // system-wide default for PR merge without review that individual config entries can override.
104-
DefaultCommitMessage: "Automated PR with updated examples", // default commit message used when per-config commit_message is absent.
114+
DefaultRecursiveCopy: true, // system-wide default for recursive copying that individual config entries can override.
115+
DefaultPRMerge: false, // system-wide default for PR merge without review that individual config entries can override.
116+
DefaultCommitMessage: "Automated PR with updated examples", // default commit message used when per-config commit_message is absent.
117+
GitHubAPIMaxRetries: 3, // default number of retry attempts for GitHub API calls
118+
GitHubAPIInitialRetryDelay: 500, // default initial retry delay in milliseconds (exponential backoff)
119+
PRMergePollMaxAttempts: 20, // default max attempts to poll PR for mergeability (~10 seconds with 500ms interval)
120+
PRMergePollInterval: 500, // default polling interval in milliseconds
105121
}
106122
}
107123

@@ -173,6 +189,14 @@ func LoadEnvironment(envFile string) (*Config, error) {
173189
config.SlackIconEmoji = getEnvWithDefault(SlackIconEmoji, ":robot_face:")
174190
config.SlackEnabled = getBoolEnvWithDefault(SlackEnabled, config.SlackWebhookURL != "")
175191

192+
// GitHub API retry configuration
193+
config.GitHubAPIMaxRetries = getIntEnvWithDefault(GitHubAPIMaxRetries, config.GitHubAPIMaxRetries)
194+
config.GitHubAPIInitialRetryDelay = getIntEnvWithDefault(GitHubAPIInitialRetryDelay, config.GitHubAPIInitialRetryDelay)
195+
196+
// PR merge polling configuration
197+
config.PRMergePollMaxAttempts = getIntEnvWithDefault(PRMergePollMaxAttempts, config.PRMergePollMaxAttempts)
198+
config.PRMergePollInterval = getIntEnvWithDefault(PRMergePollInterval, config.PRMergePollInterval)
199+
176200
// Export resolved values back into environment so downstream os.Getenv sees defaults
177201
_ = os.Setenv(Port, config.Port)
178202
_ = os.Setenv(RepoName, config.RepoName)
@@ -218,6 +242,19 @@ func getBoolEnvWithDefault(key string, defaultValue bool) bool {
218242
return strings.ToLower(value) == "true"
219243
}
220244

245+
// getIntEnvWithDefault returns the integer environment variable value or default if not set
246+
func getIntEnvWithDefault(key string, defaultValue int) int {
247+
value := os.Getenv(key)
248+
if value == "" {
249+
return defaultValue
250+
}
251+
var intValue int
252+
if _, err := fmt.Sscanf(value, "%d", &intValue); err != nil {
253+
return defaultValue
254+
}
255+
return intValue
256+
}
257+
221258
// validateConfig checks if all required configuration values are set
222259
func validateConfig(config *Config) error {
223260
var missingVars []string

0 commit comments

Comments
 (0)