Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dipjyotimetia committed Mar 8, 2024
1 parent 715444f commit bdca809
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 88 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ARG TARGETARCH

RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/server ./cmd
CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/app ./cmd

FROM alpine:latest AS final

Expand All @@ -35,4 +35,4 @@ RUN adduser \
USER appuser

COPY --from=build /bin/app /bin/
ENTRYPOINT [ "/bin/app" ]
ENTRYPOINT [ "/bin/app" ]
35 changes: 16 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/dipjyotimetia/jarvis
go 1.22

require (
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.4.1
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.5.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0
github.com/Masterminds/semver/v3 v3.2.1
github.com/briandowns/spinner v1.23.0
github.com/ctreminiom/go-atlassian v1.5.1
github.com/ctreminiom/go-atlassian v1.6.0
github.com/fatih/color v1.16.0
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.11.0
Expand All @@ -16,15 +16,15 @@ require (
github.com/manifoldco/promptui v0.9.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.8.0
golang.org/x/oauth2 v0.17.0
google.golang.org/api v0.167.0
google.golang.org/protobuf v1.32.0
golang.org/x/oauth2 v0.18.0
google.golang.org/api v0.169.0
google.golang.org/protobuf v1.33.0
gopkg.in/yaml.v3 v3.0.1
)

require (
cloud.google.com/go/ai v0.3.2 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute v1.25.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/longrunning v0.5.5 // indirect
dario.cat/mergo v1.0.0 // indirect
Expand All @@ -40,21 +40,18 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/imdario/mergo v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
Expand All @@ -70,19 +67,19 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.20.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.18.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240228224816-df926f6c8641 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240228224816-df926f6c8641 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8 // indirect
google.golang.org/grpc v1.62.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)

Expand Down
80 changes: 34 additions & 46 deletions go.sum

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions pkg/commands/genai.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -54,6 +55,9 @@ func GenerateTestModule() *cobra.Command {
if err != nil {
return fmt.Errorf("failed to identify spec types: %w", err)
}
if len(file) == 0 {
return errors.New("no files found")
}

reader, err := files.ReadFile(file[0])
if err != nil {
Expand Down Expand Up @@ -107,6 +111,9 @@ func GenerateTestScenarios() *cobra.Command {
if err != nil {
return fmt.Errorf("failed to identify spec types: %w", err)
}
if len(file) == 0 {
return errors.New("no files found")
}

reader, err := files.ReadFile(file[0])
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/commands/local.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package commands

import (
"errors"

"github.com/dipjyotimetia/jarvis/pkg/engine/files"
"github.com/dipjyotimetia/jarvis/pkg/engine/prompt"
"github.com/dipjyotimetia/jarvis/pkg/engine/utils"
Expand Down Expand Up @@ -32,7 +34,7 @@ func SpecAnalyzer() *cobra.Command {
return err
}
if len(specs) == 0 {
return nil
return errors.New("no files found")
}
switch spec {
case "protobuf":
Expand Down
23 changes: 17 additions & 6 deletions pkg/engine/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"io/fs"
"log"
"os"
"path/filepath"
"regexp"
Expand All @@ -24,7 +25,18 @@ func ListFiles(dir string) ([]string, error) {
return nil
}
paths = append(paths, path)
fmt.Println(d.Name())

// Read the file
data, err := os.ReadFile(path)
if err != nil {
log.Printf("Error reading file %s: %v", path, err)
return nil
}

// Identify the file type
fileType := identifyFileType(data)
fmt.Printf("File: %s, Type: %s\n", d.Name(), fileType)

return nil
})
return paths, nil
Expand Down Expand Up @@ -57,11 +69,10 @@ func identifyFileType(data []byte) string {
return "Unknown"
}

func ReadFile(spec string) ([]genai.Text, error) {
file, err := os.Open(spec)
func ReadFile(path string) ([]genai.Text, error) {
file, err := os.Open(path)
if err != nil {
fmt.Println("Error opening file:", err)
return nil, nil
return nil, err
}
defer file.Close()
var lines []genai.Text
Expand All @@ -74,7 +85,7 @@ func ReadFile(spec string) ([]genai.Text, error) {
bytesRead, err := reader.Read(buffer)
if err != nil {
if err != io.EOF {
fmt.Errorf("Error reading file:", err)
return nil, fmt.Errorf("Error reading file: %v", err)
}
break
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/engine/gemini/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gemini

import (
"context"
"errors"
"os"

"github.com/google/generative-ai-go/genai"
Expand All @@ -26,7 +27,11 @@ type client struct {
client *genai.Client
}

// New creates a new Gemini client.
func New(ctx context.Context) (Client, error) {
if apiKey == "" {
return nil, errors.New("GEMINI_API_KEY is not set")
}
ai, err := genai.NewClient(ctx, option.WithAPIKey(apiKey))
if err != nil {
return nil, err
Expand All @@ -36,6 +41,7 @@ func New(ctx context.Context) (Client, error) {
}, nil
}

// Close closes the Gemini client.
func (c *client) Close() {
c.client.Close()
}
9 changes: 5 additions & 4 deletions pkg/engine/gemini/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ func (c *client) GenerateTextStreamWriter(ctx context.Context, specs []genai.Tex
return nil
}
for _, candidate := range resp.Candidates {
go func(parts []genai.Part) {
for _, c := range parts {
fmt.Fprintln(writer, c)
for _, c := range candidate.Content.Parts {
_, err := fmt.Fprintln(writer, c)
if err != nil {
return err
}
}(candidate.Content.Parts)
}
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func setFrameworksForLanguage(language string) []string {
return []string{"Gin", "Echo", "Fiber", "gRPC"}
case "Python":
return []string{"Django", "Flask", "FastAPI", "gRPC"}
case "java":
case "Java":
return []string{"Spring", "JAX-RS", "restassured", "gRPC"}
case "JavaScript":
return []string{"supertest", "axios", "http", "gRPC"}
Expand Down
9 changes: 4 additions & 5 deletions pkg/engine/utils/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,19 @@ func OpenApiAnalyzer(specFiles []string) {
table.Render()
}

func ProtoAnalyzer(protoFiles []string) {
func ProtoAnalyzer(protoFiles []string) error {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"File", "Service", "Method", "Input Type", "Output Type", "Streaming"})

for _, protoFile := range protoFiles {
data, err := os.ReadFile(protoFile)
if err != nil {
fmt.Println("Error reading file:", err)
continue
return fmt.Errorf("error reading file %s: %v", protoFile, err)
}

fds := &descriptorpb.FileDescriptorSet{}
if err := proto.Unmarshal(data, fds); err != nil {
fmt.Println("Error parsing Proto:", err)
continue
return fmt.Errorf("error parsing Proto file %s: %v", protoFile, err)
}

for _, file := range fds.File {
Expand All @@ -104,4 +102,5 @@ func ProtoAnalyzer(protoFiles []string) {
}

table.Render()
return nil
}
9 changes: 5 additions & 4 deletions pkg/github/pr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package github

import (
"errors"
"fmt"
"os"

Expand All @@ -22,7 +23,7 @@ func (c *Client) ChekPR() (string, error) {
return "", err
}
if len(pr) == 0 {
return "", err
return "", errors.New("no pull requests found")
}
for _, p := range pr {
ok, err := checkPrReference(p)
Expand All @@ -35,7 +36,7 @@ func (c *Client) ChekPR() (string, error) {
return "", err
}
if prDetails.GetMerged() {
return "", err
return "", errors.New("pull request already merged")
}
diff, _, err := c.client.PullRequests.GetRaw(c.ctx, owner, repo, *prDetails.Number, github.RawOptions{
Type: github.Diff,
Expand All @@ -45,12 +46,12 @@ func (c *Client) ChekPR() (string, error) {
return "", err
}
if len(diff) == 0 {
return "", err
return "", errors.New("no diff found")
}
return diff, nil
}
}
return "", err
return "", errors.New("no suitable pull request found")
}

func checkPrReference(pr *github.PullRequest) (bool, error) {
Expand Down

0 comments on commit bdca809

Please sign in to comment.