-
Notifications
You must be signed in to change notification settings - Fork 458
Replace lint-monster path literals with repository constants in CLI/workflow codepaths #41611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
|
|
||
| "github.com/goccy/go-yaml" | ||
|
|
||
| "github.com/github/gh-aw/pkg/constants" | ||
| "github.com/github/gh-aw/pkg/logger" | ||
| "github.com/github/gh-aw/pkg/parser" | ||
| "github.com/github/gh-aw/pkg/semverutil" | ||
|
|
@@ -30,7 +31,7 @@ var getRepositoryPackageDefaultBranch = resolveRepositoryPackageDefaultBranch | |
| var getRepositoryPackageLatestRelease = resolveRepositoryPackageLatestRelease | ||
| var addPackageManifestLog = logger.New("cli:add_package_manifest") | ||
|
|
||
| var packageSourceDirectories = []string{"workflows", ".github/workflows"} | ||
| var packageSourceDirectories = []string{"workflows", constants.WorkflowsDir} | ||
|
|
||
| const repositoryPackageManifestFileName = "aw.yml" | ||
| const repositoryPackageManifestVersion = "1" | ||
|
|
@@ -496,27 +497,27 @@ func isSupportedManifestIncludePath(p string) bool { | |
|
|
||
| func isSupportedSkillDirectoryPrefix(cleaned string) bool { | ||
| return strings.HasPrefix(cleaned, packageSkillsDirectory+"/") || | ||
| strings.HasPrefix(cleaned, ".github/"+packageSkillsDirectory+"/") | ||
| strings.HasPrefix(cleaned, constants.GithubDir+packageSkillsDirectory+"/") | ||
| } | ||
|
|
||
| func skillDirectoryRoot(cleaned string) string { | ||
| switch { | ||
| case strings.HasPrefix(cleaned, ".github/"+packageSkillsDirectory+"/"): | ||
| return ".github/" + packageSkillsDirectory | ||
| case strings.HasPrefix(cleaned, constants.GithubDir+packageSkillsDirectory+"/"): | ||
| return constants.GithubDir + packageSkillsDirectory | ||
| default: | ||
| return packageSkillsDirectory | ||
| } | ||
| } | ||
|
|
||
| func isSupportedAgentDirectoryPrefix(cleaned string) bool { | ||
| return strings.HasPrefix(cleaned, packageAgentsDirectory+"/") || | ||
| strings.HasPrefix(cleaned, ".github/"+packageAgentsDirectory+"/") | ||
| strings.HasPrefix(cleaned, constants.GithubDir+packageAgentsDirectory+"/") | ||
| } | ||
|
|
||
| func agentDirectoryRoot(cleaned string) string { | ||
| switch { | ||
| case strings.HasPrefix(cleaned, ".github/"+packageAgentsDirectory+"/"): | ||
| return ".github/" + packageAgentsDirectory | ||
| case strings.HasPrefix(cleaned, constants.GithubDir+packageAgentsDirectory+"/"): | ||
| return constants.GithubDir + packageAgentsDirectory | ||
| default: | ||
| return packageAgentsDirectory | ||
| } | ||
|
|
@@ -620,7 +621,7 @@ func resolvePackageAgentFiles(owner, repo, packagePath, ref, host string, explic | |
| } | ||
|
|
||
| var agentFiles []string | ||
| for _, root := range []string{packageAgentsDirectory, ".github/" + packageAgentsDirectory} { | ||
| for _, root := range []string{packageAgentsDirectory, constants.GithubDir + packageAgentsDirectory} { | ||
| agentsDir := joinRepositoryPackagePath(packagePath, root) | ||
| files, err := listPackageDirFilesForHost(owner, repo, ref, agentsDir, host) | ||
| if err != nil { | ||
|
|
@@ -642,7 +643,7 @@ func resolvePackageAgentFiles(owner, repo, packagePath, ref, host string, explic | |
| // of skill subdirectories (those that contain a SKILL.md file). | ||
| func scanPackageSkillDirs(owner, repo, packagePath, ref, host string) ([]string, error) { | ||
| var skillDirs []string | ||
| for _, root := range []string{packageSkillsDirectory, ".github/" + packageSkillsDirectory} { | ||
| for _, root := range []string{packageSkillsDirectory, constants.GithubDir + packageSkillsDirectory} { | ||
| skillsDir := joinRepositoryPackagePath(packagePath, root) | ||
| subdirs, err := listPackageDirSubdirsForHost(owner, repo, ref, skillsDir, host) | ||
| if err != nil { | ||
|
|
@@ -755,14 +756,14 @@ func isSupportedPackageInstallablePath(p string) bool { | |
| if strings.HasSuffix(lowerCleaned, ".md") { | ||
| return strings.HasPrefix(cleaned, "workflows/") || | ||
| strings.HasPrefix(cleaned, "agentic-workflows/") || | ||
| strings.HasPrefix(cleaned, ".github/workflows/") | ||
| strings.HasPrefix(cleaned, constants.WorkflowsDirSlash) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/zoom-out] Good — 💡 OptionsEither:
The current mix of constants and literals at the same call site makes it easy to miss if one prefix needs updating. |
||
| } | ||
| if isActionWorkflowPath(cleaned) { | ||
| if !strings.HasPrefix(cleaned, ".github/workflows/") { | ||
| if !strings.HasPrefix(cleaned, constants.WorkflowsDirSlash) { | ||
| return false | ||
| } | ||
| // Reject nested subdirectories: only direct children of .github/workflows/ are allowed. | ||
| remaining := strings.TrimPrefix(cleaned, ".github/workflows/") | ||
| remaining := strings.TrimPrefix(cleaned, constants.WorkflowsDirSlash) | ||
| return !strings.Contains(remaining, "/") | ||
| } | ||
| return false | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "slices" | ||
| "strings" | ||
|
|
||
| "github.com/github/gh-aw/pkg/constants" | ||
| "github.com/github/gh-aw/pkg/fileutil" | ||
| "github.com/github/gh-aw/pkg/logger" | ||
| ) | ||
|
|
@@ -464,7 +465,7 @@ func detectFirewallAuditArtifacts(runDir string) (manifestPath, auditJSONLPath s | |
| if !checkDir(filepath.Join(agentDir, "sandbox", "firewall", "audit"), agentBase+"/sandbox/firewall/audit") { | ||
| // Old artifact structure (/tmp/gh-aw/ prefix preserved inside the artifact): | ||
| // <agentDir>/tmp/gh-aw/sandbox/firewall/audit/ | ||
| checkDir(filepath.Join(agentDir, "tmp", "gh-aw", "sandbox", "firewall", "audit"), agentBase+"/tmp/gh-aw/sandbox/firewall/audit") | ||
| checkDir(filepath.Join(agentDir, "tmp", "gh-aw", "sandbox", "firewall", "audit"), agentBase+constants.AWFAuditDir) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Semantic mismatch: 💡 Details
agentBase + constants.AWFAuditDir // → "<base>/tmp/gh-aw/sandbox/firewall/audit"This produces the right output only because the constant starts with The old literal |
||
| } | ||
| if manifestPath != "" && auditJSONLPath != "" { | ||
| return manifestPath, auditJSONLPath, nil | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,7 +119,7 @@ func (e *OpenCodeEngine) GetExecutionSteps(workflowData *WorkflowData, logFile s | |
| modelConfigured := workflowData.EngineConfig != nil && workflowData.EngineConfig.Model != "" | ||
|
|
||
| openCodeArgs = append(openCodeArgs, "--print-logs", "--log-level", "DEBUG") | ||
| promptArg := "\"$(cat /tmp/gh-aw/aw-prompts/prompt.txt)\"" | ||
| promptArg := fmt.Sprintf("\"$(cat %s)\"", constants.AwPromptsFile) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
💡 Details
The original literal was unambiguous — it was obviously a static string. The new form looks like it was designed to accept a variable path, which it wasn't. Prefer: promptArg := `""`Or, if the escape-heavy form is needed for readability: promptArg := "\"\""`This makes the static nature explicit and removes the |
||
|
|
||
| commandName := "opencode" | ||
| if workflowData.EngineConfig != nil && workflowData.EngineConfig.Command != "" { | ||
|
|
@@ -173,7 +173,7 @@ func (e *OpenCodeEngine) GetExecutionSteps(workflowData *WorkflowData, logFile s | |
| } | ||
|
|
||
| env := map[string]string{ | ||
| "GH_AW_PROMPT": "/tmp/gh-aw/aw-prompts/prompt.txt", | ||
| "GH_AW_PROMPT": constants.AwPromptsFile, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] 💡 Suggested additions to spec_test.goassert.Equal(t, ".github/", constants.GithubDir,
"GithubDir must carry trailing slash — callers depend on direct concatenation")
assert.Equal(t, ".github/workflows/", constants.WorkflowsDirSlash,
"WorkflowsDirSlash must end with '/' for HasPrefix path checks")
assert.Equal(t, "/tmp/gh-aw/aw-prompts/prompt.txt", constants.AwPromptsFile,
"AwPromptsFile is wired into GH_AW_PROMPT and the opencode CLI arg")This mirrors the existing |
||
| "GITHUB_WORKSPACE": "${{ github.workspace }}", | ||
| "RUNNER_TEMP": "${{ runner.temp }}", | ||
| "NO_PROXY": "localhost,127.0.0.1", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/improve-codebase-architecture] The expressions
constants.GithubDir + packageSkillsDirectoryandconstants.GithubDir + packageAgentsDirectoryare now repeated 3–4 times each. Consider hoisting them into package-level vars to reduce silent coupling.💡 Suggested refactor
Add two vars near the existing constants:
Then use
githubSkillsDir/githubAgentsDirthroughoutisSupportedSkillDirectoryPrefix,skillDirectoryRoot,scanPackageSkillDirs, etc.If
GithubDirever changes, there would be one correction point instead of eight.