chore(log): migrate pkg/errors imports to pkg/log
Migrates all internal packages from pkg/errors to pkg/log: - internal/cmd/monitor - internal/cmd/qa - internal/cmd/dev - pkg/agentic Closes #130 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
144cda8181
commit
f709b4fb81
11 changed files with 106 additions and 106 deletions
|
|
@ -15,7 +15,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/host-uk/core/pkg/cli"
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"github.com/host-uk/core/pkg/git"
|
||||
"github.com/host-uk/core/pkg/i18n"
|
||||
"github.com/host-uk/core/pkg/repos"
|
||||
|
|
@ -65,19 +65,19 @@ func runApply() error {
|
|||
|
||||
// Validate inputs
|
||||
if applyCommand == "" && applyScript == "" {
|
||||
return errors.E("dev.apply", i18n.T("cmd.dev.apply.error.no_command"), nil)
|
||||
return log.E("dev.apply", i18n.T("cmd.dev.apply.error.no_command"), nil)
|
||||
}
|
||||
if applyCommand != "" && applyScript != "" {
|
||||
return errors.E("dev.apply", i18n.T("cmd.dev.apply.error.both_command_script"), nil)
|
||||
return log.E("dev.apply", i18n.T("cmd.dev.apply.error.both_command_script"), nil)
|
||||
}
|
||||
if applyCommit && applyMessage == "" {
|
||||
return errors.E("dev.apply", i18n.T("cmd.dev.apply.error.commit_needs_message"), nil)
|
||||
return log.E("dev.apply", i18n.T("cmd.dev.apply.error.commit_needs_message"), nil)
|
||||
}
|
||||
|
||||
// Validate script exists
|
||||
if applyScript != "" {
|
||||
if _, err := os.Stat(applyScript); err != nil {
|
||||
return errors.E("dev.apply", "script not found: "+applyScript, err)
|
||||
return log.E("dev.apply", "script not found: "+applyScript, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ func runApply() error {
|
|||
}
|
||||
|
||||
if len(targetRepos) == 0 {
|
||||
return errors.E("dev.apply", i18n.T("cmd.dev.apply.error.no_repos"), nil)
|
||||
return log.E("dev.apply", i18n.T("cmd.dev.apply.error.no_repos"), nil)
|
||||
}
|
||||
|
||||
// Show plan
|
||||
|
|
@ -226,12 +226,12 @@ func getApplyTargetRepos() ([]*repos.Repo, error) {
|
|||
// Load registry
|
||||
registryPath, err := repos.FindRegistry()
|
||||
if err != nil {
|
||||
return nil, errors.E("dev.apply", "failed to find registry", err)
|
||||
return nil, log.E("dev.apply", "failed to find registry", err)
|
||||
}
|
||||
|
||||
registry, err := repos.LoadRegistry(registryPath)
|
||||
if err != nil {
|
||||
return nil, errors.E("dev.apply", "failed to load registry", err)
|
||||
return nil, log.E("dev.apply", "failed to load registry", err)
|
||||
}
|
||||
|
||||
// If --repos specified, filter to those
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/host-uk/core/pkg/cli"
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"github.com/host-uk/core/pkg/git"
|
||||
"github.com/host-uk/core/pkg/i18n"
|
||||
"github.com/host-uk/core/pkg/repos"
|
||||
|
|
@ -59,13 +59,13 @@ func runFileSync(source string) error {
|
|||
|
||||
// Security: Reject path traversal attempts
|
||||
if strings.Contains(source, "..") {
|
||||
return errors.E("dev.sync", "path traversal not allowed", nil)
|
||||
return log.E("dev.sync", "path traversal not allowed", nil)
|
||||
}
|
||||
|
||||
// Validate source exists
|
||||
sourceInfo, err := os.Stat(source)
|
||||
if err != nil {
|
||||
return errors.E("dev.sync", i18n.T("cmd.dev.file_sync.error.source_not_found", map[string]interface{}{"Path": source}), err)
|
||||
return log.E("dev.sync", i18n.T("cmd.dev.file_sync.error.source_not_found", map[string]interface{}{"Path": source}), err)
|
||||
}
|
||||
|
||||
// Find target repos
|
||||
|
|
@ -186,12 +186,12 @@ func resolveTargetRepos(pattern string) ([]*repos.Repo, error) {
|
|||
// Load registry
|
||||
registryPath, err := repos.FindRegistry()
|
||||
if err != nil {
|
||||
return nil, errors.E("dev.sync", "failed to find registry", err)
|
||||
return nil, log.E("dev.sync", "failed to find registry", err)
|
||||
}
|
||||
|
||||
registry, err := repos.LoadRegistry(registryPath)
|
||||
if err != nil {
|
||||
return nil, errors.E("dev.sync", "failed to load registry", err)
|
||||
return nil, log.E("dev.sync", "failed to load registry", err)
|
||||
}
|
||||
|
||||
// Match pattern against repo names
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/host-uk/core/pkg/cli"
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"github.com/host-uk/core/pkg/i18n"
|
||||
"github.com/host-uk/core/pkg/repos"
|
||||
)
|
||||
|
|
@ -107,7 +107,7 @@ type SecretScanningAlert struct {
|
|||
func runMonitor() error {
|
||||
// Check gh is available
|
||||
if _, err := exec.LookPath("gh"); err != nil {
|
||||
return errors.E("monitor", i18n.T("error.gh_not_found"), err)
|
||||
return log.E("monitor", i18n.T("error.gh_not_found"), err)
|
||||
}
|
||||
|
||||
// Determine repos to scan
|
||||
|
|
@ -117,7 +117,7 @@ func runMonitor() error {
|
|||
}
|
||||
|
||||
if len(repoList) == 0 {
|
||||
return errors.E("monitor", i18n.T("cmd.monitor.error.no_repos"), nil)
|
||||
return log.E("monitor", i18n.T("cmd.monitor.error.no_repos"), nil)
|
||||
}
|
||||
|
||||
// Collect all findings and errors
|
||||
|
|
@ -179,12 +179,12 @@ func resolveRepos() ([]string, error) {
|
|||
// All repos from registry
|
||||
registry, err := repos.FindRegistry()
|
||||
if err != nil {
|
||||
return nil, errors.E("monitor", "failed to find registry", err)
|
||||
return nil, log.E("monitor", "failed to find registry", err)
|
||||
}
|
||||
|
||||
loaded, err := repos.LoadRegistry(registry)
|
||||
if err != nil {
|
||||
return nil, errors.E("monitor", "failed to load registry", err)
|
||||
return nil, log.E("monitor", "failed to load registry", err)
|
||||
}
|
||||
|
||||
var repoList []string
|
||||
|
|
@ -253,12 +253,12 @@ func fetchCodeScanningAlerts(repoFullName string) ([]Finding, error) {
|
|||
return nil, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.E("monitor.fetchCodeScanning", "API request failed", err)
|
||||
return nil, log.E("monitor.fetchCodeScanning", "API request failed", err)
|
||||
}
|
||||
|
||||
var alerts []CodeScanningAlert
|
||||
if err := json.Unmarshal(output, &alerts); err != nil {
|
||||
return nil, errors.E("monitor.fetchCodeScanning", "failed to parse response", err)
|
||||
return nil, log.E("monitor.fetchCodeScanning", "failed to parse response", err)
|
||||
}
|
||||
|
||||
repoName := strings.Split(repoFullName, "/")[1]
|
||||
|
|
@ -307,12 +307,12 @@ func fetchDependabotAlerts(repoFullName string) ([]Finding, error) {
|
|||
return nil, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.E("monitor.fetchDependabot", "API request failed", err)
|
||||
return nil, log.E("monitor.fetchDependabot", "API request failed", err)
|
||||
}
|
||||
|
||||
var alerts []DependabotAlert
|
||||
if err := json.Unmarshal(output, &alerts); err != nil {
|
||||
return nil, errors.E("monitor.fetchDependabot", "failed to parse response", err)
|
||||
return nil, log.E("monitor.fetchDependabot", "failed to parse response", err)
|
||||
}
|
||||
|
||||
repoName := strings.Split(repoFullName, "/")[1]
|
||||
|
|
@ -358,12 +358,12 @@ func fetchSecretScanningAlerts(repoFullName string) ([]Finding, error) {
|
|||
return nil, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.E("monitor.fetchSecretScanning", "API request failed", err)
|
||||
return nil, log.E("monitor.fetchSecretScanning", "API request failed", err)
|
||||
}
|
||||
|
||||
var alerts []SecretScanningAlert
|
||||
if err := json.Unmarshal(output, &alerts); err != nil {
|
||||
return nil, errors.E("monitor.fetchSecretScanning", "failed to parse response", err)
|
||||
return nil, log.E("monitor.fetchSecretScanning", "failed to parse response", err)
|
||||
}
|
||||
|
||||
repoName := strings.Split(repoFullName, "/")[1]
|
||||
|
|
@ -447,7 +447,7 @@ func sortBySeverity(findings []Finding) {
|
|||
func outputJSON(findings []Finding) error {
|
||||
data, err := json.MarshalIndent(findings, "", " ")
|
||||
if err != nil {
|
||||
return errors.E("monitor", "failed to marshal findings", err)
|
||||
return log.E("monitor", "failed to marshal findings", err)
|
||||
}
|
||||
cli.Print("%s\n", string(data))
|
||||
return nil
|
||||
|
|
@ -547,7 +547,7 @@ func detectRepoFromGit() (string, error) {
|
|||
cmd := exec.Command("git", "remote", "get-url", "origin")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", errors.E("monitor", i18n.T("cmd.monitor.error.not_git_repo"), err)
|
||||
return "", log.E("monitor", i18n.T("cmd.monitor.error.not_git_repo"), err)
|
||||
}
|
||||
|
||||
url := strings.TrimSpace(string(output))
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/host-uk/core/pkg/cli"
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"github.com/host-uk/core/pkg/i18n"
|
||||
"github.com/host-uk/core/pkg/repos"
|
||||
)
|
||||
|
|
@ -63,7 +63,7 @@ func addHealthCommand(parent *cli.Command) {
|
|||
func runHealth() error {
|
||||
// Check gh is available
|
||||
if _, err := exec.LookPath("gh"); err != nil {
|
||||
return errors.E("qa.health", i18n.T("error.gh_not_found"), nil)
|
||||
return log.E("qa.health", i18n.T("error.gh_not_found"), nil)
|
||||
}
|
||||
|
||||
// Load registry
|
||||
|
|
@ -75,12 +75,12 @@ func runHealth() error {
|
|||
} else {
|
||||
registryPath, findErr := repos.FindRegistry()
|
||||
if findErr != nil {
|
||||
return errors.E("qa.health", i18n.T("error.registry_not_found"), nil)
|
||||
return log.E("qa.health", i18n.T("error.registry_not_found"), nil)
|
||||
}
|
||||
reg, err = repos.LoadRegistry(registryPath)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.E("qa.health", "failed to load registry", err)
|
||||
return log.E("qa.health", "failed to load registry", err)
|
||||
}
|
||||
|
||||
// Fetch CI status from all repos
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/host-uk/core/pkg/cli"
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"github.com/host-uk/core/pkg/i18n"
|
||||
"github.com/host-uk/core/pkg/repos"
|
||||
)
|
||||
|
|
@ -92,7 +92,7 @@ func addIssuesCommand(parent *cli.Command) {
|
|||
func runQAIssues() error {
|
||||
// Check gh is available
|
||||
if _, err := exec.LookPath("gh"); err != nil {
|
||||
return errors.E("qa.issues", i18n.T("error.gh_not_found"), nil)
|
||||
return log.E("qa.issues", i18n.T("error.gh_not_found"), nil)
|
||||
}
|
||||
|
||||
// Load registry
|
||||
|
|
@ -104,12 +104,12 @@ func runQAIssues() error {
|
|||
} else {
|
||||
registryPath, findErr := repos.FindRegistry()
|
||||
if findErr != nil {
|
||||
return errors.E("qa.issues", i18n.T("error.registry_not_found"), nil)
|
||||
return log.E("qa.issues", i18n.T("error.registry_not_found"), nil)
|
||||
}
|
||||
reg, err = repos.LoadRegistry(registryPath)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.E("qa.issues", "failed to load registry", err)
|
||||
return log.E("qa.issues", "failed to load registry", err)
|
||||
}
|
||||
|
||||
// Fetch issues from all repos
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/host-uk/core/pkg/cli"
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"github.com/host-uk/core/pkg/i18n"
|
||||
)
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ func addReviewCommand(parent *cli.Command) {
|
|||
func runReview() error {
|
||||
// Check gh is available
|
||||
if _, err := exec.LookPath("gh"); err != nil {
|
||||
return errors.E("qa.review", i18n.T("error.gh_not_found"), nil)
|
||||
return log.E("qa.review", i18n.T("error.gh_not_found"), nil)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
|
|
@ -114,7 +114,7 @@ func runReview() error {
|
|||
var err error
|
||||
repoFullName, err = detectRepoFromGit()
|
||||
if err != nil {
|
||||
return errors.E("qa.review", i18n.T("cmd.qa.review.error.no_repo"), nil)
|
||||
return log.E("qa.review", i18n.T("cmd.qa.review.error.no_repo"), nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ func runReview() error {
|
|||
func showMyPRs(ctx context.Context, repo string) error {
|
||||
prs, err := fetchPRs(ctx, repo, "author:@me")
|
||||
if err != nil {
|
||||
return errors.E("qa.review", "failed to fetch your PRs", err)
|
||||
return log.E("qa.review", "failed to fetch your PRs", err)
|
||||
}
|
||||
|
||||
if len(prs) == 0 {
|
||||
|
|
@ -165,7 +165,7 @@ func showMyPRs(ctx context.Context, repo string) error {
|
|||
func showRequestedReviews(ctx context.Context, repo string) error {
|
||||
prs, err := fetchPRs(ctx, repo, "review-requested:@me")
|
||||
if err != nil {
|
||||
return errors.E("qa.review", "failed to fetch review requests", err)
|
||||
return log.E("qa.review", "failed to fetch review requests", err)
|
||||
}
|
||||
|
||||
if len(prs) == 0 {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/host-uk/core/pkg/cli"
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"github.com/host-uk/core/pkg/i18n"
|
||||
)
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ func addWatchCommand(parent *cli.Command) {
|
|||
func runWatch() error {
|
||||
// Check gh is available
|
||||
if _, err := exec.LookPath("gh"); err != nil {
|
||||
return errors.E("qa.watch", i18n.T("error.gh_not_found"), nil)
|
||||
return log.E("qa.watch", i18n.T("error.gh_not_found"), nil)
|
||||
}
|
||||
|
||||
// Determine repo
|
||||
|
|
@ -115,12 +115,12 @@ func runWatch() error {
|
|||
// Check if context deadline exceeded
|
||||
if ctx.Err() != nil {
|
||||
cli.Blank()
|
||||
return errors.E("qa.watch", i18n.T("cmd.qa.watch.timeout", map[string]interface{}{"Duration": watchTimeout}), nil)
|
||||
return log.E("qa.watch", i18n.T("cmd.qa.watch.timeout", map[string]interface{}{"Duration": watchTimeout}), nil)
|
||||
}
|
||||
|
||||
runs, err := fetchWorkflowRunsForCommit(ctx, repoFullName, commitSha)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "qa.watch", "failed to fetch workflow runs")
|
||||
return log.Wrap(err, "qa.watch", "failed to fetch workflow runs")
|
||||
}
|
||||
|
||||
if len(runs) == 0 {
|
||||
|
|
@ -195,7 +195,7 @@ func resolveRepo(specified string) (string, error) {
|
|||
if org != "" {
|
||||
return org + "/" + specified, nil
|
||||
}
|
||||
return "", errors.E("qa.watch", i18n.T("cmd.qa.watch.error.repo_format"), nil)
|
||||
return "", log.E("qa.watch", i18n.T("cmd.qa.watch.error.repo_format"), nil)
|
||||
}
|
||||
|
||||
// Detect from current directory
|
||||
|
|
@ -212,7 +212,7 @@ func resolveCommit(specified string) (string, error) {
|
|||
cmd := exec.Command("git", "rev-parse", "HEAD")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "qa.watch", "failed to get HEAD commit")
|
||||
return "", log.Wrap(err, "qa.watch", "failed to get HEAD commit")
|
||||
}
|
||||
|
||||
return strings.TrimSpace(string(output)), nil
|
||||
|
|
@ -223,7 +223,7 @@ func detectRepoFromGit() (string, error) {
|
|||
cmd := exec.Command("git", "remote", "get-url", "origin")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", errors.E("qa.watch", i18n.T("cmd.qa.watch.error.not_git_repo"), nil)
|
||||
return "", log.E("qa.watch", i18n.T("cmd.qa.watch.error.not_git_repo"), nil)
|
||||
}
|
||||
|
||||
url := strings.TrimSpace(string(output))
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
)
|
||||
|
||||
// Client is the API client for the core-agentic service.
|
||||
|
|
@ -77,24 +77,24 @@ func (c *Client) ListTasks(ctx context.Context, opts ListOptions) ([]Task, error
|
|||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, errors.E(op, "failed to create request", err)
|
||||
return nil, log.E(op, "failed to create request", err)
|
||||
}
|
||||
|
||||
c.setHeaders(req)
|
||||
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, errors.E(op, "request failed", err)
|
||||
return nil, log.E(op, "request failed", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := c.checkResponse(resp); err != nil {
|
||||
return nil, errors.E(op, "API error", err)
|
||||
return nil, log.E(op, "API error", err)
|
||||
}
|
||||
|
||||
var tasks []Task
|
||||
if err := json.NewDecoder(resp.Body).Decode(&tasks); err != nil {
|
||||
return nil, errors.E(op, "failed to decode response", err)
|
||||
return nil, log.E(op, "failed to decode response", err)
|
||||
}
|
||||
|
||||
return tasks, nil
|
||||
|
|
@ -105,31 +105,31 @@ func (c *Client) GetTask(ctx context.Context, id string) (*Task, error) {
|
|||
const op = "agentic.Client.GetTask"
|
||||
|
||||
if id == "" {
|
||||
return nil, errors.E(op, "task ID is required", nil)
|
||||
return nil, log.E(op, "task ID is required", nil)
|
||||
}
|
||||
|
||||
endpoint := fmt.Sprintf("%s/api/tasks/%s", c.BaseURL, url.PathEscape(id))
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, errors.E(op, "failed to create request", err)
|
||||
return nil, log.E(op, "failed to create request", err)
|
||||
}
|
||||
|
||||
c.setHeaders(req)
|
||||
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, errors.E(op, "request failed", err)
|
||||
return nil, log.E(op, "request failed", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := c.checkResponse(resp); err != nil {
|
||||
return nil, errors.E(op, "API error", err)
|
||||
return nil, log.E(op, "API error", err)
|
||||
}
|
||||
|
||||
var task Task
|
||||
if err := json.NewDecoder(resp.Body).Decode(&task); err != nil {
|
||||
return nil, errors.E(op, "failed to decode response", err)
|
||||
return nil, log.E(op, "failed to decode response", err)
|
||||
}
|
||||
|
||||
return &task, nil
|
||||
|
|
@ -140,7 +140,7 @@ func (c *Client) ClaimTask(ctx context.Context, id string) (*Task, error) {
|
|||
const op = "agentic.Client.ClaimTask"
|
||||
|
||||
if id == "" {
|
||||
return nil, errors.E(op, "task ID is required", nil)
|
||||
return nil, log.E(op, "task ID is required", nil)
|
||||
}
|
||||
|
||||
endpoint := fmt.Sprintf("%s/api/tasks/%s/claim", c.BaseURL, url.PathEscape(id))
|
||||
|
|
@ -154,7 +154,7 @@ func (c *Client) ClaimTask(ctx context.Context, id string) (*Task, error) {
|
|||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, body)
|
||||
if err != nil {
|
||||
return nil, errors.E(op, "failed to create request", err)
|
||||
return nil, log.E(op, "failed to create request", err)
|
||||
}
|
||||
|
||||
c.setHeaders(req)
|
||||
|
|
@ -164,18 +164,18 @@ func (c *Client) ClaimTask(ctx context.Context, id string) (*Task, error) {
|
|||
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, errors.E(op, "request failed", err)
|
||||
return nil, log.E(op, "request failed", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := c.checkResponse(resp); err != nil {
|
||||
return nil, errors.E(op, "API error", err)
|
||||
return nil, log.E(op, "API error", err)
|
||||
}
|
||||
|
||||
// Read body once to allow multiple decode attempts
|
||||
bodyData, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, errors.E(op, "failed to read response", err)
|
||||
return nil, log.E(op, "failed to read response", err)
|
||||
}
|
||||
|
||||
// Try decoding as ClaimResponse first
|
||||
|
|
@ -187,7 +187,7 @@ func (c *Client) ClaimTask(ctx context.Context, id string) (*Task, error) {
|
|||
// Try decoding as just a Task for simpler API responses
|
||||
var task Task
|
||||
if err := json.Unmarshal(bodyData, &task); err != nil {
|
||||
return nil, errors.E(op, "failed to decode response", err)
|
||||
return nil, log.E(op, "failed to decode response", err)
|
||||
}
|
||||
|
||||
return &task, nil
|
||||
|
|
@ -198,19 +198,19 @@ func (c *Client) UpdateTask(ctx context.Context, id string, update TaskUpdate) e
|
|||
const op = "agentic.Client.UpdateTask"
|
||||
|
||||
if id == "" {
|
||||
return errors.E(op, "task ID is required", nil)
|
||||
return log.E(op, "task ID is required", nil)
|
||||
}
|
||||
|
||||
endpoint := fmt.Sprintf("%s/api/tasks/%s", c.BaseURL, url.PathEscape(id))
|
||||
|
||||
data, err := json.Marshal(update)
|
||||
if err != nil {
|
||||
return errors.E(op, "failed to marshal update", err)
|
||||
return log.E(op, "failed to marshal update", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint, bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return errors.E(op, "failed to create request", err)
|
||||
return log.E(op, "failed to create request", err)
|
||||
}
|
||||
|
||||
c.setHeaders(req)
|
||||
|
|
@ -218,12 +218,12 @@ func (c *Client) UpdateTask(ctx context.Context, id string, update TaskUpdate) e
|
|||
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return errors.E(op, "request failed", err)
|
||||
return log.E(op, "request failed", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := c.checkResponse(resp); err != nil {
|
||||
return errors.E(op, "API error", err)
|
||||
return log.E(op, "API error", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -234,19 +234,19 @@ func (c *Client) CompleteTask(ctx context.Context, id string, result TaskResult)
|
|||
const op = "agentic.Client.CompleteTask"
|
||||
|
||||
if id == "" {
|
||||
return errors.E(op, "task ID is required", nil)
|
||||
return log.E(op, "task ID is required", nil)
|
||||
}
|
||||
|
||||
endpoint := fmt.Sprintf("%s/api/tasks/%s/complete", c.BaseURL, url.PathEscape(id))
|
||||
|
||||
data, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
return errors.E(op, "failed to marshal result", err)
|
||||
return log.E(op, "failed to marshal result", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return errors.E(op, "failed to create request", err)
|
||||
return log.E(op, "failed to create request", err)
|
||||
}
|
||||
|
||||
c.setHeaders(req)
|
||||
|
|
@ -254,12 +254,12 @@ func (c *Client) CompleteTask(ctx context.Context, id string, result TaskResult)
|
|||
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return errors.E(op, "request failed", err)
|
||||
return log.E(op, "request failed", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := c.checkResponse(resp); err != nil {
|
||||
return errors.E(op, "API error", err)
|
||||
return log.E(op, "API error", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -303,19 +303,19 @@ func (c *Client) Ping(ctx context.Context) error {
|
|||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return errors.E(op, "failed to create request", err)
|
||||
return log.E(op, "failed to create request", err)
|
||||
}
|
||||
|
||||
c.setHeaders(req)
|
||||
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return errors.E(op, "request failed", err)
|
||||
return log.E(op, "request failed", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
return errors.E(op, fmt.Sprintf("server returned status %d", resp.StatusCode), nil)
|
||||
return log.E(op, fmt.Sprintf("server returned status %d", resp.StatusCode), nil)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
)
|
||||
|
||||
// PROptions contains options for creating a pull request.
|
||||
|
|
@ -36,11 +36,11 @@ func AutoCommit(ctx context.Context, task *Task, dir string, message string) err
|
|||
const op = "agentic.AutoCommit"
|
||||
|
||||
if task == nil {
|
||||
return errors.E(op, "task is required", nil)
|
||||
return log.E(op, "task is required", nil)
|
||||
}
|
||||
|
||||
if message == "" {
|
||||
return errors.E(op, "commit message is required", nil)
|
||||
return log.E(op, "commit message is required", nil)
|
||||
}
|
||||
|
||||
// Build full commit message
|
||||
|
|
@ -48,12 +48,12 @@ func AutoCommit(ctx context.Context, task *Task, dir string, message string) err
|
|||
|
||||
// Stage all changes
|
||||
if _, err := runGitCommandCtx(ctx, dir, "add", "-A"); err != nil {
|
||||
return errors.E(op, "failed to stage changes", err)
|
||||
return log.E(op, "failed to stage changes", err)
|
||||
}
|
||||
|
||||
// Create commit
|
||||
if _, err := runGitCommandCtx(ctx, dir, "commit", "-m", fullMessage); err != nil {
|
||||
return errors.E(op, "failed to create commit", err)
|
||||
return log.E(op, "failed to create commit", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -83,7 +83,7 @@ func CreatePR(ctx context.Context, task *Task, dir string, opts PROptions) (stri
|
|||
const op = "agentic.CreatePR"
|
||||
|
||||
if task == nil {
|
||||
return "", errors.E(op, "task is required", nil)
|
||||
return "", log.E(op, "task is required", nil)
|
||||
}
|
||||
|
||||
// Build title if not provided
|
||||
|
|
@ -116,7 +116,7 @@ func CreatePR(ctx context.Context, task *Task, dir string, opts PROptions) (stri
|
|||
// Run gh pr create
|
||||
output, err := runCommandCtx(ctx, dir, "gh", args...)
|
||||
if err != nil {
|
||||
return "", errors.E(op, "failed to create PR", err)
|
||||
return "", log.E(op, "failed to create PR", err)
|
||||
}
|
||||
|
||||
// Extract PR URL from output
|
||||
|
|
@ -158,11 +158,11 @@ func SyncStatus(ctx context.Context, client *Client, task *Task, update TaskUpda
|
|||
const op = "agentic.SyncStatus"
|
||||
|
||||
if client == nil {
|
||||
return errors.E(op, "client is required", nil)
|
||||
return log.E(op, "client is required", nil)
|
||||
}
|
||||
|
||||
if task == nil {
|
||||
return errors.E(op, "task is required", nil)
|
||||
return log.E(op, "task is required", nil)
|
||||
}
|
||||
|
||||
return client.UpdateTask(ctx, task.ID, update)
|
||||
|
|
@ -174,7 +174,7 @@ func CommitAndSync(ctx context.Context, client *Client, task *Task, dir string,
|
|||
|
||||
// Create commit
|
||||
if err := AutoCommit(ctx, task, dir, message); err != nil {
|
||||
return errors.E(op, "failed to commit", err)
|
||||
return log.E(op, "failed to commit", err)
|
||||
}
|
||||
|
||||
// Sync status if client provided
|
||||
|
|
@ -187,7 +187,7 @@ func CommitAndSync(ctx context.Context, client *Client, task *Task, dir string,
|
|||
|
||||
if err := SyncStatus(ctx, client, task, update); err != nil {
|
||||
// Log but don't fail on sync errors
|
||||
return errors.E(op, "commit succeeded but sync failed", err)
|
||||
return log.E(op, "commit succeeded but sync failed", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ func PushChanges(ctx context.Context, dir string) error {
|
|||
|
||||
_, err := runGitCommandCtx(ctx, dir, "push")
|
||||
if err != nil {
|
||||
return errors.E(op, "failed to push changes", err)
|
||||
return log.E(op, "failed to push changes", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -211,7 +211,7 @@ func CreateBranch(ctx context.Context, task *Task, dir string) (string, error) {
|
|||
const op = "agentic.CreateBranch"
|
||||
|
||||
if task == nil {
|
||||
return "", errors.E(op, "task is required", nil)
|
||||
return "", log.E(op, "task is required", nil)
|
||||
}
|
||||
|
||||
// Generate branch name from task
|
||||
|
|
@ -220,7 +220,7 @@ func CreateBranch(ctx context.Context, task *Task, dir string) (string, error) {
|
|||
// Create and checkout branch
|
||||
_, err := runGitCommandCtx(ctx, dir, "checkout", "-b", branchName)
|
||||
if err != nil {
|
||||
return "", errors.E(op, "failed to create branch", err)
|
||||
return "", log.E(op, "failed to create branch", err)
|
||||
}
|
||||
|
||||
return branchName, nil
|
||||
|
|
@ -302,7 +302,7 @@ func GetCurrentBranch(ctx context.Context, dir string) (string, error) {
|
|||
|
||||
output, err := runGitCommandCtx(ctx, dir, "rev-parse", "--abbrev-ref", "HEAD")
|
||||
if err != nil {
|
||||
return "", errors.E(op, "failed to get current branch", err)
|
||||
return "", log.E(op, "failed to get current branch", err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(output), nil
|
||||
|
|
@ -314,7 +314,7 @@ func HasUncommittedChanges(ctx context.Context, dir string) (bool, error) {
|
|||
|
||||
output, err := runGitCommandCtx(ctx, dir, "status", "--porcelain")
|
||||
if err != nil {
|
||||
return false, errors.E(op, "failed to get git status", err)
|
||||
return false, log.E(op, "failed to get git status", err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(output) != "", nil
|
||||
|
|
@ -331,7 +331,7 @@ func GetDiff(ctx context.Context, dir string, staged bool) (string, error) {
|
|||
|
||||
output, err := runGitCommandCtx(ctx, dir, args...)
|
||||
if err != nil {
|
||||
return "", errors.E(op, "failed to get diff", err)
|
||||
return "", log.E(op, "failed to get diff", err)
|
||||
}
|
||||
|
||||
return output, nil
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
|
@ -74,12 +74,12 @@ func LoadConfig(dir string) (*Config, error) {
|
|||
// Try loading from ~/.core/agentic.yaml
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return nil, errors.E("agentic.LoadConfig", "failed to get home directory", err)
|
||||
return nil, log.E("agentic.LoadConfig", "failed to get home directory", err)
|
||||
}
|
||||
|
||||
configPath := filepath.Join(homeDir, ".core", configFileName)
|
||||
if err := loadYAMLConfig(configPath, cfg); err != nil && !os.IsNotExist(err) {
|
||||
return nil, errors.E("agentic.LoadConfig", "failed to load config", err)
|
||||
return nil, log.E("agentic.LoadConfig", "failed to load config", err)
|
||||
}
|
||||
|
||||
// Apply environment variable overrides
|
||||
|
|
@ -87,7 +87,7 @@ func LoadConfig(dir string) (*Config, error) {
|
|||
|
||||
// Validate configuration
|
||||
if cfg.Token == "" {
|
||||
return nil, errors.E("agentic.LoadConfig", "no authentication token configured", nil)
|
||||
return nil, log.E("agentic.LoadConfig", "no authentication token configured", nil)
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
|
|
@ -167,23 +167,23 @@ func applyEnvOverrides(cfg *Config) {
|
|||
func SaveConfig(cfg *Config) error {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return errors.E("agentic.SaveConfig", "failed to get home directory", err)
|
||||
return log.E("agentic.SaveConfig", "failed to get home directory", err)
|
||||
}
|
||||
|
||||
configDir := filepath.Join(homeDir, ".core")
|
||||
if err := os.MkdirAll(configDir, 0755); err != nil {
|
||||
return errors.E("agentic.SaveConfig", "failed to create config directory", err)
|
||||
return log.E("agentic.SaveConfig", "failed to create config directory", err)
|
||||
}
|
||||
|
||||
configPath := filepath.Join(configDir, configFileName)
|
||||
|
||||
data, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
return errors.E("agentic.SaveConfig", "failed to marshal config", err)
|
||||
return log.E("agentic.SaveConfig", "failed to marshal config", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(configPath, data, 0600); err != nil {
|
||||
return errors.E("agentic.SaveConfig", "failed to write config file", err)
|
||||
return log.E("agentic.SaveConfig", "failed to write config file", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -193,7 +193,7 @@ func SaveConfig(cfg *Config) error {
|
|||
func ConfigPath() (string, error) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", errors.E("agentic.ConfigPath", "failed to get home directory", err)
|
||||
return "", log.E("agentic.ConfigPath", "failed to get home directory", err)
|
||||
}
|
||||
return filepath.Join(homeDir, ".core", configFileName), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/host-uk/core/pkg/errors"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
)
|
||||
|
||||
// FileContent represents the content of a file for AI context.
|
||||
|
|
@ -41,13 +41,13 @@ func BuildTaskContext(task *Task, dir string) (*TaskContext, error) {
|
|||
const op = "agentic.BuildTaskContext"
|
||||
|
||||
if task == nil {
|
||||
return nil, errors.E(op, "task is required", nil)
|
||||
return nil, log.E(op, "task is required", nil)
|
||||
}
|
||||
|
||||
if dir == "" {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, errors.E(op, "failed to get working directory", err)
|
||||
return nil, log.E(op, "failed to get working directory", err)
|
||||
}
|
||||
dir = cwd
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ func GatherRelatedFiles(task *Task, dir string) ([]FileContent, error) {
|
|||
const op = "agentic.GatherRelatedFiles"
|
||||
|
||||
if task == nil {
|
||||
return nil, errors.E(op, "task is required", nil)
|
||||
return nil, log.E(op, "task is required", nil)
|
||||
}
|
||||
|
||||
var files []FileContent
|
||||
|
|
@ -117,7 +117,7 @@ func findRelatedCode(task *Task, dir string) ([]FileContent, error) {
|
|||
const op = "agentic.findRelatedCode"
|
||||
|
||||
if task == nil {
|
||||
return nil, errors.E(op, "task is required", nil)
|
||||
return nil, log.E(op, "task is required", nil)
|
||||
}
|
||||
|
||||
// Extract keywords from title and description
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue