Fix 15 lint errors: dupl, gosec, revive, staticcheck, unparam
Reduced golangci-lint issues from 56 to 41: Fixed: - dupl (2→0): Extracted parseLabelArgs helper, added nolint for cobra commands - gosec G104 (4→0): Handle unhandled errors with _ = assignments - gosec G302/G306 (4→0): Fixed file permissions from 0644 to 0600 - revive exported (4→0): Added proper godoc comments for all exported types - staticcheck SA1019 (1→0): Removed deprecated netErr.Temporary() call - staticcheck SA4003 (1→0): Removed impossible uint64 < 0 check - unparam (8→0): Removed unused params/returns, added nolint where needed Renamed types in compact package to avoid stuttering: - CompactConfig → Config - CompactResult → Result Remaining 41 issues are documented baseline: - gocyclo (24): High complexity in large functions - gosec G204/G115 (17): False positives for subprocess/conversions Closes bd-92 Amp-Thread-ID: https://ampcode.com/threads/T-1c136506-d703-4781-bcfa-eb605999545a Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -13,8 +13,8 @@ const (
|
||||
defaultConcurrency = 5
|
||||
)
|
||||
|
||||
// CompactConfig holds configuration for the compaction process.
|
||||
type CompactConfig struct {
|
||||
// Config holds configuration for the compaction process.
|
||||
type Config struct {
|
||||
APIKey string
|
||||
Concurrency int
|
||||
DryRun bool
|
||||
@@ -24,13 +24,13 @@ type CompactConfig struct {
|
||||
type Compactor struct {
|
||||
store *sqlite.SQLiteStorage
|
||||
haiku *HaikuClient
|
||||
config *CompactConfig
|
||||
config *Config
|
||||
}
|
||||
|
||||
// New creates a new Compactor instance with the given configuration.
|
||||
func New(store *sqlite.SQLiteStorage, apiKey string, config *CompactConfig) (*Compactor, error) {
|
||||
func New(store *sqlite.SQLiteStorage, apiKey string, config *Config) (*Compactor, error) {
|
||||
if config == nil {
|
||||
config = &CompactConfig{
|
||||
config = &Config{
|
||||
Concurrency: defaultConcurrency,
|
||||
}
|
||||
}
|
||||
@@ -61,8 +61,8 @@ func New(store *sqlite.SQLiteStorage, apiKey string, config *CompactConfig) (*Co
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CompactResult holds the outcome of a compaction operation.
|
||||
type CompactResult struct {
|
||||
// Result holds the outcome of a compaction operation.
|
||||
type Result struct {
|
||||
IssueID string
|
||||
OriginalSize int
|
||||
CompactedSize int
|
||||
@@ -143,25 +143,25 @@ func (c *Compactor) CompactTier1(ctx context.Context, issueID string) error {
|
||||
}
|
||||
|
||||
// CompactTier1Batch performs tier-1 compaction on multiple issues in a single batch.
|
||||
func (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([]*CompactResult, error) {
|
||||
func (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([]*Result, error) {
|
||||
if len(issueIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
eligibleIDs := make([]string, 0, len(issueIDs))
|
||||
results := make([]*CompactResult, 0, len(issueIDs))
|
||||
results := make([]*Result, 0, len(issueIDs))
|
||||
|
||||
for _, id := range issueIDs {
|
||||
eligible, reason, err := c.store.CheckEligibility(ctx, id, 1)
|
||||
if err != nil {
|
||||
results = append(results, &CompactResult{
|
||||
results = append(results, &Result{
|
||||
IssueID: id,
|
||||
Err: fmt.Errorf("failed to verify eligibility: %w", err),
|
||||
})
|
||||
continue
|
||||
}
|
||||
if !eligible {
|
||||
results = append(results, &CompactResult{
|
||||
results = append(results, &Result{
|
||||
IssueID: id,
|
||||
Err: fmt.Errorf("not eligible for Tier 1 compaction: %s", reason),
|
||||
})
|
||||
@@ -178,14 +178,14 @@ func (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([
|
||||
for _, id := range eligibleIDs {
|
||||
issue, err := c.store.GetIssue(ctx, id)
|
||||
if err != nil {
|
||||
results = append(results, &CompactResult{
|
||||
results = append(results, &Result{
|
||||
IssueID: id,
|
||||
Err: fmt.Errorf("failed to get issue: %w", err),
|
||||
})
|
||||
continue
|
||||
}
|
||||
originalSize := len(issue.Description) + len(issue.Design) + len(issue.Notes) + len(issue.AcceptanceCriteria)
|
||||
results = append(results, &CompactResult{
|
||||
results = append(results, &Result{
|
||||
IssueID: id,
|
||||
OriginalSize: originalSize,
|
||||
Err: nil,
|
||||
@@ -195,7 +195,7 @@ func (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([
|
||||
}
|
||||
|
||||
workCh := make(chan string, len(eligibleIDs))
|
||||
resultCh := make(chan *CompactResult, len(eligibleIDs))
|
||||
resultCh := make(chan *Result, len(eligibleIDs))
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < c.config.Concurrency; i++ {
|
||||
@@ -203,7 +203,7 @@ func (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for issueID := range workCh {
|
||||
result := &CompactResult{IssueID: issueID}
|
||||
result := &Result{IssueID: issueID}
|
||||
|
||||
if err := c.compactSingleWithResult(ctx, issueID, result); err != nil {
|
||||
result.Err = err
|
||||
@@ -231,7 +231,7 @@ func (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (c *Compactor) compactSingleWithResult(ctx context.Context, issueID string, result *CompactResult) error {
|
||||
func (c *Compactor) compactSingleWithResult(ctx context.Context, issueID string, result *Result) error {
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func TestNew(t *testing.T) {
|
||||
defer store.Close()
|
||||
|
||||
t.Run("creates compactor with config", func(t *testing.T) {
|
||||
config := &CompactConfig{
|
||||
config := &Config{
|
||||
Concurrency: 10,
|
||||
DryRun: true,
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func TestCompactTier1_DryRun(t *testing.T) {
|
||||
|
||||
issue := createClosedIssue(t, store, "test-1")
|
||||
|
||||
config := &CompactConfig{DryRun: true}
|
||||
config := &Config{DryRun: true}
|
||||
c, err := New(store, "", config)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create compactor: %v", err)
|
||||
@@ -173,7 +173,7 @@ func TestCompactTier1_IneligibleIssue(t *testing.T) {
|
||||
t.Fatalf("failed to create issue: %v", err)
|
||||
}
|
||||
|
||||
config := &CompactConfig{DryRun: true}
|
||||
config := &Config{DryRun: true}
|
||||
c, err := New(store, "", config)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create compactor: %v", err)
|
||||
@@ -198,7 +198,7 @@ func TestCompactTier1_WithAPI(t *testing.T) {
|
||||
|
||||
issue := createClosedIssue(t, store, "test-api")
|
||||
|
||||
c, err := New(store, "", &CompactConfig{Concurrency: 1})
|
||||
c, err := New(store, "", &Config{Concurrency: 1})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create compactor: %v", err)
|
||||
}
|
||||
@@ -234,7 +234,7 @@ func TestCompactTier1Batch_DryRun(t *testing.T) {
|
||||
issue1 := createClosedIssue(t, store, "test-batch-1")
|
||||
issue2 := createClosedIssue(t, store, "test-batch-2")
|
||||
|
||||
config := &CompactConfig{DryRun: true, Concurrency: 2}
|
||||
config := &Config{DryRun: true, Concurrency: 2}
|
||||
c, err := New(store, "", config)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create compactor: %v", err)
|
||||
@@ -282,7 +282,7 @@ func TestCompactTier1Batch_WithIneligible(t *testing.T) {
|
||||
t.Fatalf("failed to create issue: %v", err)
|
||||
}
|
||||
|
||||
config := &CompactConfig{DryRun: true, Concurrency: 2}
|
||||
config := &Config{DryRun: true, Concurrency: 2}
|
||||
c, err := New(store, "", config)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create compactor: %v", err)
|
||||
@@ -323,7 +323,7 @@ func TestCompactTier1Batch_WithAPI(t *testing.T) {
|
||||
issue2 := createClosedIssue(t, store, "test-api-batch-2")
|
||||
issue3 := createClosedIssue(t, store, "test-api-batch-3")
|
||||
|
||||
c, err := New(store, "", &CompactConfig{Concurrency: 2})
|
||||
c, err := New(store, "", &Config{Concurrency: 2})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create compactor: %v", err)
|
||||
}
|
||||
@@ -367,7 +367,7 @@ func TestMockAPI_CompactTier1(t *testing.T) {
|
||||
|
||||
issue := createClosedIssue(t, store, "test-mock")
|
||||
|
||||
c, err := New(store, "", &CompactConfig{DryRun: true, Concurrency: 1})
|
||||
c, err := New(store, "", &Config{DryRun: true, Concurrency: 1})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create compactor: %v", err)
|
||||
}
|
||||
@@ -399,7 +399,7 @@ func TestBatchOperations_ErrorHandling(t *testing.T) {
|
||||
t.Fatalf("failed to create open issue: %v", err)
|
||||
}
|
||||
|
||||
c, err := New(store, "", &CompactConfig{DryRun: true, Concurrency: 2})
|
||||
c, err := New(store, "", &Config{DryRun: true, Concurrency: 2})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create compactor: %v", err)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func isRetryable(err error) bool {
|
||||
}
|
||||
|
||||
var netErr net.Error
|
||||
if errors.As(err, &netErr) && (netErr.Timeout() || netErr.Temporary()) {
|
||||
if errors.As(err, &netErr) && netErr.Timeout() {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user