server

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanWorkspace

func CleanWorkspace(workspaceDir string) error

CleanWorkspace removes the workspace directory.

func CloneRepository

func CloneRepository(repo *GitHubRepo, workspaceDir string) error

CloneRepository clones a GitHub repository to the specified workspace directory. It performs a shallow clone for speed and minimal disk usage.

func GetRepoPath

func GetRepoPath(workspaceDir string) string

GetRepoPath returns the path where the repository was cloned.

func ProcessJob

func ProcessJob(ctx context.Context, job *Job, wm *WorkspaceManager) error

ProcessJob processes a single check job. This is the main worker function that clones the repo and runs checks.

func ValidateGitHubURL

func ValidateGitHubURL(u *url.URL) error

ValidateGitHubURL performs additional validation on parsed URLs.

func ValidateJobID

func ValidateJobID(id string) error

ValidateJobID checks if the job ID format is valid.

func ValidateWorkspacePath

func ValidateWorkspacePath(baseDir, workspaceDir string) error

ValidateWorkspacePath performs security validation of a workspace path.

Types

type CheckRequest

type CheckRequest struct {
	URL         string   `json:"url"`                    // GitHub URL (required)
	Languages   []string `json:"languages,omitempty"`    // Override auto-detection
	Profile     string   `json:"profile,omitempty"`      // Application profile (cli, api, library, desktop)
	Target      string   `json:"target,omitempty"`       // Maturity target (poc, production)
	SkipChecks  []string `json:"skip_checks,omitempty"`  // Checks to skip
	TimeoutSecs int      `json:"timeout_secs,omitempty"` // Per-check timeout (0 = no timeout)
	Verbose     bool     `json:"verbose,omitempty"`      // Show command output for failed/warning checks
}

CheckRequest is the request payload for submitting a check.

type CheckResponse

type CheckResponse struct {
	JobID   string `json:"job_id"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

CheckResponse is the response when a check is submitted.

type GitHubRepo

type GitHubRepo struct {
	Owner    string
	Repo     string
	Branch   string // Empty if using default branch
	IsSSH    bool
	Original string // Original URL for reference
}

GitHubRepo represents a parsed GitHub repository URL.

func ParseGitHubURL

func ParseGitHubURL(rawURL string) (*GitHubRepo, error)

ParseGitHubURL parses a GitHub URL and extracts owner, repo, and branch.

func (*GitHubRepo) CloneBranch

func (gr *GitHubRepo) CloneBranch() string

CloneBranch clones a specific branch if specified, otherwise default.

func (*GitHubRepo) CloneURL

func (gr *GitHubRepo) CloneURL() string

CloneURL returns the clone URL for the repo.

func (*GitHubRepo) Validate

func (gr *GitHubRepo) Validate() error

Validate validates the GitHubRepo fields.

type HealthResponse

type HealthResponse struct {
	Status  string `json:"status"`
	Version string `json:"version,omitempty"`
}

HealthResponse is the response for GET /health.

type Job

type Job struct {
	ID           string             `json:"id"`
	Status       JobStatus          `json:"status"`
	GitHubURL    string             `json:"github_url"`
	WorkspaceDir string             `json:"-"` // Not exposed in JSON
	Request      CheckRequest       `json:"request"`
	SubmittedAt  time.Time          `json:"submitted_at"`
	StartedAt    *time.Time         `json:"started_at,omitempty"`
	CompletedAt  *time.Time         `json:"completed_at,omitempty"`
	Result       *output.JSONOutput `json:"result,omitempty"`
	Error        string             `json:"error,omitempty"`
}

Job represents a single check job.

func (*Job) ToJobResponse

func (j *Job) ToJobResponse() JobResponse

ToJobResponse converts a Job to a JobResponse (excludes WorkspaceDir).

type JobProcessor

type JobProcessor func(ctx context.Context, job *Job) error

JobProcessor is the function that processes a single job.

type JobQueue

type JobQueue struct {
	// contains filtered or unexported fields
}

JobQueue manages job queuing and execution with a worker pool.

func NewJobQueue

func NewJobQueue(store *JobStore, maxWorkers int) *JobQueue

NewJobQueue creates a new job queue with the specified number of workers.

func (*JobQueue) Enqueue

func (q *JobQueue) Enqueue(job *Job) error

Enqueue adds a job to the queue. Returns an error if the queue is not running.

func (*JobQueue) RunningCount

func (q *JobQueue) RunningCount() int

RunningCount returns the approximate number of running jobs.

func (*JobQueue) Start

func (q *JobQueue) Start(processor JobProcessor) error

Start starts the worker pool.

func (*JobQueue) Stop

func (q *JobQueue) Stop()

Stop gracefully shuts down the queue.

type JobResponse

type JobResponse struct {
	JobID       string             `json:"job_id"`
	Status      JobStatus          `json:"status"`
	GitHubURL   string             `json:"github_url"`
	SubmittedAt time.Time          `json:"submitted_at"`
	StartedAt   *time.Time         `json:"started_at,omitempty"`
	CompletedAt *time.Time         `json:"completed_at,omitempty"`
	Request     CheckRequest       `json:"request"`
	Result      *output.JSONOutput `json:"result,omitempty"`
	Error       string             `json:"error,omitempty"`
}

JobResponse is the response for GET /api/check/{id}.

type JobStatus

type JobStatus string

JobStatus represents the current status of a job.

const (
	JobStatusPending   JobStatus = "pending"
	JobStatusRunning   JobStatus = "running"
	JobStatusCompleted JobStatus = "completed"
	JobStatusFailed    JobStatus = "failed"
)

type JobStore

type JobStore struct {
	// contains filtered or unexported fields
}

JobStore manages job storage with thread-safe access.

func NewJobStore

func NewJobStore() *JobStore

NewJobStore creates a new job store.

func (*JobStore) CleanupOldJobs

func (s *JobStore) CleanupOldJobs(maxAge time.Duration) int

CleanupOldJobs removes jobs older than the specified duration. Returns the number of jobs cleaned up.

func (*JobStore) CreateJob

func (s *JobStore) CreateJob(githubURL string, req CheckRequest, workspaceDir string) *Job

CreateJob creates a new job with a unique ID.

func (*JobStore) Delete

func (s *JobStore) Delete(id string)

Delete removes a job from the store.

func (*JobStore) Get

func (s *JobStore) Get(id string) (*Job, bool)

Get retrieves a job by ID.

func (*JobStore) List

func (s *JobStore) List() []*Job

List returns all jobs (for admin/debugging purposes).

func (*JobStore) SetError

func (s *JobStore) SetError(id string, err error)

SetError sets an error on a job and marks it as failed.

func (*JobStore) SetResult

func (s *JobStore) SetResult(id string, result *output.JSONOutput)

SetResult sets the result of a job and marks it as completed.

func (*JobStore) UpdateStatus

func (s *JobStore) UpdateStatus(id string, status JobStatus)

UpdateStatus updates the status of a job.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the HTTP server.

func NewServer

func NewServer(host string, port int, jobStore *JobStore, queue *JobQueue, workspaceDir string, cleanupAfter bool, apiToken string) *Server

NewServer creates a new HTTP server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the server.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server.

type WorkspaceManager

type WorkspaceManager struct {
	// contains filtered or unexported fields
}

WorkspaceManager manages temporary workspaces for cloning repositories.

func NewWorkspaceManager

func NewWorkspaceManager(baseDir string, cleanupAfter bool) *WorkspaceManager

NewWorkspaceManager creates a new workspace manager.

func (*WorkspaceManager) Cleanup

func (wm *WorkspaceManager) Cleanup(workspaceDir string) error

Cleanup removes a workspace directory.

func (*WorkspaceManager) CleanupOld

func (wm *WorkspaceManager) CleanupOld(maxAge time.Duration) (int, error)

CleanupOld removes workspace directories older than the specified duration.

func (*WorkspaceManager) CreateWorkspace

func (wm *WorkspaceManager) CreateWorkspace(jobID string) (string, error)

CreateWorkspace creates a new workspace directory for a job.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL