1
0
Fork 0
mirror of https://github.com/imjasonh/terraform-playground synced 2026-07-06 23:12:22 +00:00

fix: resolve CI lint errors - remove unused function, fix deprecated calls, add error handling

This commit is contained in:
pr-reconciler 2026-02-04 19:05:12 +00:00
parent 4be99d04da
commit 80bb808366
4 changed files with 29 additions and 21 deletions

View file

@ -657,7 +657,11 @@ func (r *PRReconciler) runCIFixer(ctx context.Context, gh *github.Client, owner,
if err != nil {
return fmt.Errorf("cloning PR branch: %w", err)
}
defer clone.Close()
defer func() {
if err := clone.Close(); err != nil {
log.Warnf("failed to close clone: %v", err)
}
}()
// Create real filesystem for the clone
fs := cifixer.NewRealFileSystem(clone.Dir())

View file

@ -46,7 +46,7 @@ func DefaultConfig() AgentConfig {
func detectGCPProjectID() string {
// Try metadata service first (fast on GCP, quick timeout elsewhere)
if metadata.OnGCE() {
if project, err := metadata.ProjectID(); err == nil && project != "" {
if project, err := metadata.ProjectIDWithContext(context.Background()); err == nil && project != "" {
return project
}
}
@ -72,7 +72,7 @@ func detectGCPRegion() string {
// Try metadata service first
if metadata.OnGCE() {
// Zone is like "us-central1-a", we want "us-central1"
if zone, err := metadata.Zone(); err == nil && zone != "" {
if zone, err := metadata.ZoneWithContext(context.Background()); err == nil && zone != "" {
parts := strings.Split(zone, "-")
if len(parts) >= 2 {
return strings.Join(parts[:len(parts)-1], "-")
@ -174,4 +174,4 @@ func NewAgentWithClient(client anthropic.Client, cfg AgentConfig) (claudeexecuto
func ExecuteWithFS(ctx context.Context, agent claudeexecutor.Interface[*CIContext, *CIFixResult], fs FileSystem, ciCtx *CIContext) (*CIFixResult, error) {
tools := CreateTools(fs)
return agent.Execute(ctx, ciCtx, tools)
}
}

View file

@ -110,7 +110,11 @@ func TestRealFileSystemSecurity(t *testing.T) {
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
t.Errorf("failed to remove temp dir: %v", err)
}
}()
fs := NewRealFileSystem(tmpDir)
@ -145,7 +149,11 @@ func TestCommandRestrictions(t *testing.T) {
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
t.Errorf("failed to remove temp dir: %v", err)
}
}()
fs := NewRealFileSystem(tmpDir)
@ -273,14 +281,4 @@ func createToolUseBlock(name string, input map[string]any) anthropic.ToolUseBloc
Name: name,
Input: inputBytes,
}
}
// normalizeWhitespace normalizes whitespace for comparison.
func normalizeWhitespace(s string) string {
// Trim trailing whitespace from each line and normalize line endings
lines := strings.Split(s, "\n")
for i, line := range lines {
lines[i] = strings.TrimRight(line, " \t")
}
return strings.TrimSpace(strings.Join(lines, "\n"))
}
}

View file

@ -63,7 +63,9 @@ func (m *GitManager) ClonePRBranch(ctx context.Context, owner, repo, branch stri
// Get auth
auth, err := m.authForRemote()
if err != nil {
os.RemoveAll(dir)
if removeErr := os.RemoveAll(dir); removeErr != nil {
log.Warnf("failed to clean up temp dir after auth error: %v", removeErr)
}
return nil, fmt.Errorf("getting auth: %w", err)
}
@ -79,14 +81,18 @@ func (m *GitManager) ClonePRBranch(ctx context.Context, owner, repo, branch stri
Depth: 50, // Shallow clone for speed
})
if err != nil {
os.RemoveAll(dir)
if removeErr := os.RemoveAll(dir); removeErr != nil {
log.Warnf("failed to clean up temp dir after clone error: %v", removeErr)
}
return nil, fmt.Errorf("cloning repository: %w", err)
}
// Get the current HEAD SHA
head, err := gitRepo.Head()
if err != nil {
os.RemoveAll(dir)
if removeErr := os.RemoveAll(dir); removeErr != nil {
log.Warnf("failed to clean up temp dir after HEAD error: %v", removeErr)
}
return nil, fmt.Errorf("getting HEAD: %w", err)
}
@ -229,4 +235,4 @@ func (s *GitHubAppTokenSource) Token() (*oauth2.Token, error) {
AccessToken: token,
TokenType: "Bearer",
}, nil
}
}