Skip to content

Commit 83e8d8b

Browse files
committed
refactor: rename env vars to clarify they're for config repo
- Renamed REPO_OWNER → CONFIG_REPO_OWNER - Renamed REPO_NAME → CONFIG_REPO_NAME - Renamed SRC_BRANCH → CONFIG_REPO_BRANCH This makes it clear these variables are for the config repository (where copier-config.yaml is stored), not for source code repos. Updated: - Config struct and constants in environment.go - All service files that reference these variables - All test files - All config examples (.env.local.example, env.yaml.example, env.yaml.production) Breaking change: Deployments must update their env.yaml files with new variable names.
1 parent ac5819a commit 83e8d8b

13 files changed

+124
-116
lines changed

examples-copier/configs/.env.local.example

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
# REQUIRED FOR LOCAL TESTING
1616
# ============================================================================
1717

18-
# Source Repository Configuration (Required)
19-
REPO_NAME="<source-repo-name>"
20-
REPO_OWNER="<github-username-or-org>"
21-
# Source Branch (Optional - default: main)
22-
SRC_BRANCH="test"
18+
# Config Repository Configuration (Required)
19+
# This is where your copier-config.yaml file is stored
20+
CONFIG_REPO_NAME="<config-repo-name>"
21+
CONFIG_REPO_OWNER="<github-username-or-org>"
22+
# Config Branch (Optional - default: main)
23+
CONFIG_REPO_BRANCH="main"
2324

2425
# Configuration Files
2526
CONFIG_FILE=copier-config.yaml

examples-copier/configs/env.yaml.example

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ env_variables:
55

66
# GitHub App Configuration
77
GITHUB_APP_ID: "YOUR_GITHUB_APP_ID" # Your GitHub App ID (required)
8-
INSTALLATION_ID: "YOUR_INSTALLATION_ID" # GitHub App Installation ID (required)
9-
REPO_OWNER: "your-org" # Source repository owner (required)
10-
REPO_NAME: "your-repo" # Source repository name (required)
8+
INSTALLATION_ID: "YOUR_INSTALLATION_ID" # GitHub App Installation ID (optional - can auto-discover)
9+
10+
# Config Repository (where copier-config.yaml is stored)
11+
CONFIG_REPO_OWNER: "your-org" # Config repository owner (required)
12+
CONFIG_REPO_NAME: "your-config-repo" # Config repository name (required)
13+
CONFIG_REPO_BRANCH: "main" # Config file branch (default: main)
1114

1215
# =============================================================================
1316
# SECRET MANAGER REFERENCES (RECOMMENDED - Most Secure)
@@ -42,12 +45,9 @@ env_variables:
4245
WEBSERVER_PATH: "/events" # Webhook endpoint path (default: /webhook)
4346

4447
# Configuration Files
45-
CONFIG_FILE: "copier-config.yaml" # Config file name in source repo (default: copier-config.yaml)
48+
CONFIG_FILE: "copier-config.yaml" # Config file name in config repo (default: copier-config.yaml)
4649
DEPRECATION_FILE: "deprecated_examples.json" # Deprecation tracking file (default: deprecated_examples.json)
4750

48-
# Source Branch
49-
SRC_BRANCH: "main" # Branch to copy from (default: main)
50-
5151
# =============================================================================
5252
# COMMITTER INFORMATION
5353
# =============================================================================

examples-copier/configs/env.yaml.production

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
# =============================================================================
44
GITHUB_APP_ID: "1166559"
55
INSTALLATION_ID: "62138132"
6-
REPO_OWNER: "mongodb"
7-
REPO_NAME: "docs-mongodb-internal"
8-
SRC_BRANCH: "main"
6+
7+
# Config Repository (where copier-config.yaml is stored)
8+
CONFIG_REPO_OWNER: "mongodb"
9+
CONFIG_REPO_NAME: "docs-mongodb-internal"
10+
CONFIG_REPO_BRANCH: "main"
911

1012
# =============================================================================
1113
# Secret Manager References (Sensitive Data - SECURE!)

examples-copier/configs/environment.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
type Config struct {
1313
EnvFile string
1414
Port string
15-
RepoName string
16-
RepoOwner string
15+
ConfigRepoName string // Repository where config file is stored
16+
ConfigRepoOwner string // Owner of repository where config file is stored
1717
AppId string
1818
AppClientId string
1919
InstallationId string
@@ -22,7 +22,7 @@ type Config struct {
2222
ConfigFile string
2323
DeprecationFile string
2424
WebserverPath string
25-
SrcBranch string
25+
ConfigRepoBranch string // Branch to fetch config file from
2626
PEMKeyName string
2727
WebhookSecretName string
2828
WebhookSecret string
@@ -60,8 +60,8 @@ type Config struct {
6060
const (
6161
EnvFile = "ENV"
6262
Port = "PORT"
63-
RepoName = "REPO_NAME"
64-
RepoOwner = "REPO_OWNER"
63+
ConfigRepoName = "CONFIG_REPO_NAME"
64+
ConfigRepoOwner = "CONFIG_REPO_OWNER"
6565
AppId = "GITHUB_APP_ID"
6666
AppClientId = "GITHUB_APP_CLIENT_ID"
6767
InstallationId = "INSTALLATION_ID"
@@ -70,7 +70,7 @@ const (
7070
ConfigFile = "CONFIG_FILE"
7171
DeprecationFile = "DEPRECATION_FILE"
7272
WebserverPath = "WEBSERVER_PATH"
73-
SrcBranch = "SRC_BRANCH"
73+
ConfigRepoBranch = "CONFIG_REPO_BRANCH"
7474
PEMKeyName = "PEM_NAME"
7575
WebhookSecretName = "WEBHOOK_SECRET_NAME"
7676
WebhookSecret = "WEBHOOK_SECRET"
@@ -106,7 +106,7 @@ func NewConfig() *Config {
106106
ConfigFile: "copier-config.yaml",
107107
DeprecationFile: "deprecated_examples.json",
108108
WebserverPath: "/webhook",
109-
SrcBranch: "main", // Default branch to copy from (NOTE: we are purposefully only allowing copying from `main` branch right now)
109+
ConfigRepoBranch: "main", // Default branch to fetch config file from
110110
PEMKeyName: "projects/1054147886816/secrets/CODE_COPIER_PEM/versions/latest", // default secret name for GCP Secret Manager
111111
WebhookSecretName: "projects/1054147886816/secrets/webhook-secret/versions/latest", // default webhook secret name for GCP Secret Manager
112112
CopierLogName: "copy-copier-log", // default log name for logging to GCP
@@ -152,8 +152,8 @@ func LoadEnvironment(envFile string) (*Config, error) {
152152

153153
// Populate config from environment variables, with defaults where applicable
154154
config.Port = getEnvWithDefault(Port, config.Port)
155-
config.RepoName = os.Getenv(RepoName)
156-
config.RepoOwner = os.Getenv(RepoOwner)
155+
config.ConfigRepoName = os.Getenv(ConfigRepoName)
156+
config.ConfigRepoOwner = os.Getenv(ConfigRepoOwner)
157157
config.AppId = os.Getenv(AppId)
158158
config.AppClientId = os.Getenv(AppClientId)
159159
config.InstallationId = os.Getenv(InstallationId)
@@ -162,7 +162,7 @@ func LoadEnvironment(envFile string) (*Config, error) {
162162
config.ConfigFile = getEnvWithDefault(ConfigFile, config.ConfigFile)
163163
config.DeprecationFile = getEnvWithDefault(DeprecationFile, config.DeprecationFile)
164164
config.WebserverPath = getEnvWithDefault(WebserverPath, config.WebserverPath)
165-
config.SrcBranch = getEnvWithDefault(SrcBranch, config.SrcBranch)
165+
config.ConfigRepoBranch = getEnvWithDefault(ConfigRepoBranch, config.ConfigRepoBranch)
166166
config.PEMKeyName = getEnvWithDefault(PEMKeyName, config.PEMKeyName)
167167
config.WebhookSecretName = getEnvWithDefault(WebhookSecretName, config.WebhookSecretName)
168168
config.WebhookSecret = os.Getenv(WebhookSecret)
@@ -199,8 +199,8 @@ func LoadEnvironment(envFile string) (*Config, error) {
199199

200200
// Export resolved values back into environment so downstream os.Getenv sees defaults
201201
_ = os.Setenv(Port, config.Port)
202-
_ = os.Setenv(RepoName, config.RepoName)
203-
_ = os.Setenv(RepoOwner, config.RepoOwner)
202+
_ = os.Setenv(ConfigRepoName, config.ConfigRepoName)
203+
_ = os.Setenv(ConfigRepoOwner, config.ConfigRepoOwner)
204204
_ = os.Setenv(AppId, config.AppId)
205205
_ = os.Setenv(AppClientId, config.AppClientId)
206206
_ = os.Setenv(InstallationId, config.InstallationId)
@@ -209,7 +209,7 @@ func LoadEnvironment(envFile string) (*Config, error) {
209209
_ = os.Setenv(ConfigFile, config.ConfigFile)
210210
_ = os.Setenv(DeprecationFile, config.DeprecationFile)
211211
_ = os.Setenv(WebserverPath, config.WebserverPath)
212-
_ = os.Setenv(SrcBranch, config.SrcBranch)
212+
_ = os.Setenv(ConfigRepoBranch, config.ConfigRepoBranch)
213213
_ = os.Setenv(PEMKeyName, config.PEMKeyName)
214214
_ = os.Setenv(CopierLogName, config.CopierLogName)
215215
_ = os.Setenv(GoogleCloudProjectId, config.GoogleCloudProjectId)
@@ -260,10 +260,10 @@ func validateConfig(config *Config) error {
260260
var missingVars []string
261261

262262
requiredVars := map[string]string{
263-
RepoName: config.RepoName,
264-
RepoOwner: config.RepoOwner,
265-
AppId: config.AppId,
266-
InstallationId: config.InstallationId,
263+
ConfigRepoName: config.ConfigRepoName,
264+
ConfigRepoOwner: config.ConfigRepoOwner,
265+
AppId: config.AppId,
266+
InstallationId: config.InstallationId,
267267
}
268268

269269
for name, value := range requiredVars {

examples-copier/services/config_loader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ func retrieveConfigFileContent(ctx context.Context, filePath string, config *con
8181
// Fetch file content
8282
fileContent, _, _, err := client.Repositories.GetContents(
8383
ctx,
84-
config.RepoOwner,
85-
config.RepoName,
84+
config.ConfigRepoOwner,
85+
config.ConfigRepoName,
8686
filePath,
8787
&github.RepositoryContentGetOptions{
88-
Ref: config.SrcBranch,
88+
Ref: config.ConfigRepoBranch,
8989
},
9090
)
9191
if err != nil {

examples-copier/services/github_read.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func GetFilesChangedInPr(pr_number int) ([]ChangedFile, error) {
2222

2323
var prQuery PullRequestQuery
2424
variables := map[string]interface{}{
25-
"owner": githubv4.String(os.Getenv(configs.RepoOwner)),
26-
"name": githubv4.String(os.Getenv(configs.RepoName)),
25+
"owner": githubv4.String(os.Getenv(configs.ConfigRepoOwner)),
26+
"name": githubv4.String(os.Getenv(configs.ConfigRepoName)),
2727
"number": githubv4.Int(pr_number),
2828
}
2929

@@ -72,18 +72,18 @@ func GetFilesChangedInPr(pr_number int) ([]ChangedFile, error) {
7272
return changedFiles, nil
7373
}
7474

75-
// RetrieveFileContents fetches the contents of a file from the repository at the specified path.
75+
// RetrieveFileContents fetches the contents of a file from the config repository at the specified path.
7676
// It returns a github.RepositoryContent object containing the file details.
7777
func RetrieveFileContents(filePath string) (github.RepositoryContent, error) {
78-
owner := os.Getenv(configs.RepoOwner)
79-
repo := os.Getenv(configs.RepoName)
78+
owner := os.Getenv(configs.ConfigRepoOwner)
79+
repo := os.Getenv(configs.ConfigRepoName)
8080
client := GetRestClient()
8181
ctx := context.Background()
8282

8383
fileContent, _, _, err :=
8484
client.Repositories.GetContents(ctx, owner, repo,
8585
filePath, &github.RepositoryContentGetOptions{
86-
Ref: os.Getenv(configs.SrcBranch),
86+
Ref: os.Getenv(configs.ConfigRepoBranch),
8787
})
8888

8989
if err != nil {

examples-copier/services/github_write_to_source.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ func UpdateDeprecationFile() {
2525

2626
fileContent, _, _, err := client.Repositories.GetContents(
2727
ctx,
28-
os.Getenv(configs.RepoOwner),
29-
os.Getenv(configs.RepoName),
28+
os.Getenv(configs.ConfigRepoOwner),
29+
os.Getenv(configs.ConfigRepoName),
3030
os.Getenv(configs.DeprecationFile),
3131
&github.RepositoryContentGetOptions{
32-
Ref: os.Getenv(configs.SrcBranch),
32+
Ref: os.Getenv(configs.ConfigRepoBranch),
3333
},
3434
)
3535
if err != nil {
@@ -75,8 +75,8 @@ func uploadDeprecationFileChanges(message string, newDeprecationFileContents str
7575
client := GetRestClient()
7676
ctx := context.Background()
7777

78-
targetFileContent, _, _, err := client.Repositories.GetContents(ctx, os.Getenv(configs.RepoOwner), os.Getenv(configs.RepoName),
79-
os.Getenv(configs.DeprecationFile), &github.RepositoryContentGetOptions{Ref: os.Getenv(configs.SrcBranch)})
78+
targetFileContent, _, _, err := client.Repositories.GetContents(ctx, os.Getenv(configs.ConfigRepoOwner), os.Getenv(configs.ConfigRepoName),
79+
os.Getenv(configs.DeprecationFile), &github.RepositoryContentGetOptions{Ref: os.Getenv(configs.ConfigRepoBranch)})
8080

8181
if err != nil {
8282
LogError(fmt.Sprintf("Error getting deprecation file contents: %v", err))
@@ -85,13 +85,13 @@ func uploadDeprecationFileChanges(message string, newDeprecationFileContents str
8585
options := &github.RepositoryContentFileOptions{
8686
Message: github.String(message),
8787
Content: []byte(newDeprecationFileContents),
88-
Branch: github.String(os.Getenv(configs.SrcBranch)),
88+
Branch: github.String(os.Getenv(configs.ConfigRepoBranch)),
8989
Committer: &github.CommitAuthor{Name: github.String(os.Getenv(configs.CommitterName)),
9090
Email: github.String(os.Getenv(configs.CommitterEmail))},
9191
}
9292

9393
options.SHA = targetFileContent.SHA
94-
_, _, err = client.Repositories.UpdateFile(ctx, os.Getenv(configs.RepoOwner), os.Getenv(configs.RepoName), os.Getenv(configs.DeprecationFile), options)
94+
_, _, err = client.Repositories.UpdateFile(ctx, os.Getenv(configs.ConfigRepoOwner), os.Getenv(configs.ConfigRepoName), os.Getenv(configs.DeprecationFile), options)
9595
if err != nil {
9696
LogError(fmt.Sprintf("Cannot update deprecation file: %v", err))
9797
}

examples-copier/services/github_write_to_target.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var FilesToDeprecate map[string]Configs
2424

2525

2626

27-
// repoOwner returns the repository owner from environment variables.
28-
func repoOwner() string { return os.Getenv(configs.RepoOwner) }
27+
// repoOwner returns the config repository owner from environment variables.
28+
func repoOwner() string { return os.Getenv(configs.ConfigRepoOwner) }
2929

3030
// parseRepoPath parses a repository path in the format "owner/repo" and returns owner and repo separately.
3131
// If the path doesn't contain a slash, it returns the source repo owner from env and the path as repo name.

examples-copier/services/github_write_to_target_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ import (
2727

2828
func TestMain(m *testing.M) {
2929
// Minimal env so init() and any env readers are happy.
30-
os.Setenv(configs.RepoOwner, "my-org")
31-
os.Setenv(configs.RepoName, "target-repo")
30+
os.Setenv(configs.ConfigRepoOwner, "my-org")
31+
os.Setenv(configs.ConfigRepoName, "config-repo")
3232
os.Setenv(configs.InstallationId, "12345")
3333
os.Setenv(configs.AppId, "1166559")
3434
os.Setenv(configs.AppClientId, "IvTestClientId")
3535
os.Setenv("SKIP_SECRET_MANAGER", "true")
36-
os.Setenv("SRC_BRANCH", "main")
36+
os.Setenv(configs.ConfigRepoBranch, "main")
3737

3838
// Provide an RSA private key (both raw and b64) so ConfigurePermissions can parse.
3939
key, _ := rsa.GenerateKey(rand.Reader, 1024)
@@ -45,8 +45,8 @@ func TestMain(m *testing.M) {
4545
code := m.Run()
4646

4747
// Cleanup
48-
os.Unsetenv(configs.RepoOwner)
49-
os.Unsetenv(configs.RepoName)
48+
os.Unsetenv(configs.ConfigRepoOwner)
49+
os.Unsetenv(configs.ConfigRepoName)
5050
os.Unsetenv(configs.InstallationId)
5151
os.Unsetenv(configs.AppId)
5252
os.Unsetenv(configs.AppClientId)

0 commit comments

Comments
 (0)