Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions internal/checks/binary.go → internal/check/binary.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package checks
package check

import (
"context"
"fmt"
"os/exec"

"github.com/vidya381/devcheck/internal/check"
)

type BinaryCheck struct {
Expand All @@ -16,19 +14,19 @@ func (c *BinaryCheck) Name() string {
return fmt.Sprintf("%s installed", c.Binary)
}

func (c *BinaryCheck) Run(_ context.Context) check.Result {
func (c *BinaryCheck) Run(_ context.Context) Result {
_, err := exec.LookPath(c.Binary)
if err != nil {
return check.Result{
return Result{
Name: c.Name(),
Status: check.StatusFail,
Status: StatusFail,
Message: fmt.Sprintf("%s not found on PATH", c.Binary),
Fix: fmt.Sprintf("Install %s and make sure it is on your PATH", c.Binary),
}
}
return check.Result{
return Result{
Name: c.Name(),
Status: check.StatusPass,
Status: StatusPass,
Message: fmt.Sprintf("%s is installed", c.Binary),
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package checks
package check

import (
"context"
"testing"

"github.com/vidya381/devcheck/internal/check"
)

func TestBinaryCheck_Pass(t *testing.T) {
c := &BinaryCheck{Binary: "go"}
result := c.Run(context.Background())
if result.Status != check.StatusPass {
if result.Status != StatusPass {
t.Errorf("expected pass, got %v: %s", result.Status, result.Message)
}
}

func TestBinaryCheck_Fail(t *testing.T) {
c := &BinaryCheck{Binary: "definitelynotabinary12345"}
result := c.Run(context.Background())
if result.Status != check.StatusFail {
if result.Status != StatusFail {
t.Errorf("expected fail, got %v", result.Status)
}
}
22 changes: 15 additions & 7 deletions internal/check/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@ package check
import "github.com/vidya381/devcheck/internal/detector"

func Build(stack detector.DetectedStack) []Check {
var checks []Check
var cs []Check

if stack.Go {
// add Go checks
cs = append(cs, &BinaryCheck{Binary: "go"})
}
if stack.Node {
// add Node checks
cs = append(cs, &BinaryCheck{Binary: "node"})
cs = append(cs, &BinaryCheck{Binary: "npm"})
}
if stack.Python {
// add Python checks
cs = append(cs, &BinaryCheck{Binary: "python3"})
cs = append(cs, &BinaryCheck{Binary: "pip"})
}
if stack.Java {
// add Java checks
cs = append(cs, &BinaryCheck{Binary: "java"})
if stack.Maven {
cs = append(cs, &BinaryCheck{Binary: "mvn"})
}
if stack.Gradle {
cs = append(cs, &BinaryCheck{Binary: "gradle"})
}
}
if stack.Docker {
// add Docker checks
Expand All @@ -28,7 +36,7 @@ func Build(stack detector.DetectedStack) []Check {
}

// always run env check if .env.example exists
// checks = append(checks, &EnvCheck{})
// cs = append(cs, &EnvCheck{})

return checks
return cs
}
7 changes: 5 additions & 2 deletions internal/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type DetectedStack struct {
Node bool
Python bool
Java bool
Maven bool
Gradle bool
Docker bool
Postgres bool
Redis bool
Expand All @@ -25,8 +27,9 @@ func Detect(dir string) DetectedStack {
stack.Node = fileExists(filepath.Join(dir, "package.json"))
stack.Python = fileExists(filepath.Join(dir, "requirements.txt")) ||
fileExists(filepath.Join(dir, "pyproject.toml"))
stack.Java = fileExists(filepath.Join(dir, "pom.xml")) ||
fileExists(filepath.Join(dir, "build.gradle"))
stack.Maven = fileExists(filepath.Join(dir, "pom.xml"))
stack.Gradle = fileExists(filepath.Join(dir, "build.gradle"))
stack.Java = stack.Maven || stack.Gradle
stack.Docker = fileExists(filepath.Join(dir, "Dockerfile")) ||
fileExists(filepath.Join(dir, "docker-compose.yml")) ||
fileExists(filepath.Join(dir, "docker-compose.yaml"))
Expand Down