From 0bfa496a2538117428af63de7f0160148995fb4f Mon Sep 17 00:00:00 2001 From: Michael Hohn Date: Wed, 8 May 2024 16:04:59 -0700 Subject: [PATCH] wip --- cmd/commander/main.go | 8 ++-- lib/commander/{ => lcmem}/lcmem.go | 0 lib/lcmem.go | 67 ------------------------------ 3 files changed, 4 insertions(+), 71 deletions(-) rename lib/commander/{ => lcmem}/lcmem.go (100%) delete mode 100644 lib/lcmem.go diff --git a/cmd/commander/main.go b/cmd/commander/main.go index 09cdab0..61cc79b 100644 --- a/cmd/commander/main.go +++ b/cmd/commander/main.go @@ -17,9 +17,9 @@ import ( "github.com/spf13/cobra" ) -// startCmd represents the start command -var startCmd = &cobra.Command{ - Use: "start", +// StartCmd represents the Start command +var StartCmd = &cobra.Command{ + Use: "Start", Short: "A brief description of your command", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your command. For example: @@ -180,7 +180,7 @@ func MirvaRequest(w http.ResponseWriter, r *http.Request) { } func init() { - rootCmd.AddCommand(startCmd) + rootCmd.AddCommand(StartCmd) // Here you will define your flags and configuration settings. diff --git a/lib/commander/lcmem.go b/lib/commander/lcmem/lcmem.go similarity index 100% rename from lib/commander/lcmem.go rename to lib/commander/lcmem/lcmem.go diff --git a/lib/lcmem.go b/lib/lcmem.go deleted file mode 100644 index 1197615..0000000 --- a/lib/lcmem.go +++ /dev/null @@ -1,67 +0,0 @@ -// The in-memory implementation of the mrva commander library -package lcmem - -import ( - "encoding/json" - "fmt" - "log/slog" - "net/http" - - "github.com/hohn/ghes-mirva-server/api" - co "github.com/hohn/ghes-mirva-server/common" - "github.com/hohn/ghes-mirva-server/store" -) - -func StatusResponse(w http.ResponseWriter, js co.JobSpec, ji co.JobInfo, vaid int) { - slog.Debug("Submitting status response", "session", vaid) - - all_scanned := []api.ScannedRepo{} - jobs := store.GetJobList(js.ID) - for _, job := range jobs { - astat := store.GetStatus(js.ID, job.ORL).ToExternalString() - all_scanned = append(all_scanned, - api.ScannedRepo{ - Repository: api.Repository{ - ID: 0, - Name: job.ORL.Repo, - FullName: fmt.Sprintf("%s/%s", job.ORL.Owner, job.ORL.Repo), - Private: false, - StargazersCount: 0, - UpdatedAt: ji.UpdatedAt, - }, - AnalysisStatus: astat, - ResultCount: 123, // FIXME 123 is a lie so the client downloads - ArtifactSizeBytes: 123, // FIXME - }, - ) - } - - astat := store.GetStatus(js.ID, js.OwnerRepo).ToExternalString() - - status := api.StatusResponse{ - SessionId: js.ID, - ControllerRepo: api.ControllerRepo{}, - Actor: api.Actor{}, - QueryLanguage: ji.QueryLanguage, - QueryPackURL: "", // FIXME - CreatedAt: ji.CreatedAt, - UpdatedAt: ji.UpdatedAt, - ActionsWorkflowRunID: 0, // FIXME - Status: astat, - ScannedRepositories: all_scanned, - SkippedRepositories: ji.SkippedRepositories, - } - - // Encode the response as JSON - submitStatus, err := json.Marshal(status) - if err != nil { - slog.Error("Error encoding response as JSON:", - "error", err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // Send analysisReposJSON via ResponseWriter - w.Header().Set("Content-Type", "application/json") - w.Write(submitStatus) -}