Fix critical issues in WHOOSH Gitea issue monitoring and task creation

This commit resolves multiple blocking issues that were preventing WHOOSH from
properly detecting and converting bzzz-task labeled issues from Gitea:

## Issues Fixed:

1. **JSON Parsing Error**: Gitea API returns repository owner as string in issue
   responses, but code expected User object. Added IssueRepository struct to
   handle this API response format difference.

2. **Database Error Handling**: Code was using database/sql.ErrNoRows but
   system uses pgx driver. Updated imports and error constants to use
   pgx.ErrNoRows consistently.

3. **NULL Value Scanning**: Database fields (repository, project_id,
   estimated_hours, complexity_score) can be NULL but Go structs used
   non-pointer types. Added proper NULL handling with pointer scanning
   and safe conversion.

## Results:
-  WHOOSH now successfully detects bzzz-task labeled issues
-  Task creation pipeline working end-to-end
-  Tasks API functioning properly
-  First bzzz-task converted: "Logic around registered agents faulty"

The core issue monitoring workflow is now fully operational and ready for
CHORUS integration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Code
2025-09-10 12:57:11 +10:00
parent 4173c0c8c8
commit b5c0deb6bc
3 changed files with 58 additions and 30 deletions

View File

@@ -2,7 +2,6 @@ package monitor
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"strconv"
@@ -11,6 +10,7 @@ import (
"github.com/chorus-services/whoosh/internal/config"
"github.com/chorus-services/whoosh/internal/gitea"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/rs/zerolog/log"
)
@@ -202,11 +202,14 @@ func (m *Monitor) syncRepository(ctx context.Context, repo RepositoryConfig) {
// createOrUpdateTask creates a new task or updates an existing one from a Gitea issue
func (m *Monitor) createOrUpdateTask(ctx context.Context, repo RepositoryConfig, issue gitea.Issue) (string, bool, error) {
// Check if task already exists
var existingTaskID sql.NullString
var existingTaskID string
query := `SELECT id FROM tasks WHERE external_id = $1 AND source_type = $2`
err := m.db.QueryRow(ctx, query, strconv.FormatInt(issue.Number, 10), repo.SourceType).Scan(&existingTaskID)
if err != nil && err != sql.ErrNoRows {
taskExists := err == nil
// Handle errors other than "no rows found"
if err != nil && err != pgx.ErrNoRows {
return "", false, fmt.Errorf("failed to check existing task: %w", err)
}
@@ -230,8 +233,8 @@ func (m *Monitor) createOrUpdateTask(ctx context.Context, repo RepositoryConfig,
techStack := m.extractTechStackFromIssue(issue)
techStackJSON, _ := json.Marshal(techStack)
if existingTaskID.Valid {
// Update existing task
if taskExists {
// Task exists - update it
updateQuery := `
UPDATE tasks SET
title = $1,
@@ -253,14 +256,14 @@ func (m *Monitor) createOrUpdateTask(ctx context.Context, repo RepositoryConfig,
labelsJSON,
techStackJSON,
issue.UpdatedAt,
existingTaskID.String,
existingTaskID,
)
if err != nil {
return "", false, fmt.Errorf("failed to update task: %w", err)
}
return existingTaskID.String, false, nil
return existingTaskID, false, nil
} else {
// Create new task
var taskID string
@@ -440,10 +443,10 @@ func (m *Monitor) getMonitoredRepositories(ctx context.Context) ([]RepositoryCon
// updateRepositoryStatus updates the sync status of a repository
func (m *Monitor) updateRepositoryStatus(ctx context.Context, repoID, status string, err error) error {
var errorMsg sql.NullString
var errorMsg *string
if err != nil {
errorMsg.String = err.Error()
errorMsg.Valid = true
errStr := err.Error()
errorMsg = &errStr
}
query := `
@@ -555,7 +558,7 @@ func (m *Monitor) getRepositoryByID(ctx context.Context, repoID string) (*Reposi
&chorusLabelsJSON, &repo.LastSync, &repo.LastIssueSync, &repo.SyncStatus,
)
if err != nil {
if err == sql.ErrNoRows {
if err == pgx.ErrNoRows {
return nil, fmt.Errorf("repository not found: %s", repoID)
}
return nil, fmt.Errorf("failed to query repository: %w", err)