feat: [ML-338]: Simplify HarnessIntelligence struct dependencies (#2700)

* Simplify HarnessIntelligence struct dependencies
CODE-2402
Yogesh Chauhan 2024-09-24 06:25:03 +00:00 committed by Harness
parent 25ca720888
commit cb616e48a7
7 changed files with 37 additions and 53 deletions

View File

@ -24,14 +24,14 @@ import (
)
type Controller struct {
authorizer authz.Authorizer
pipeline *aiagent.HarnessIntelligence
repoStore store.RepoStore
pipelineStore store.PipelineStore
executionStore store.ExecutionStore
git git.Interface
urlProvider url.Provider
slackbot *messaging.Slack
authorizer authz.Authorizer
intelligenceService *aiagent.HarnessIntelligence
repoStore store.RepoStore
pipelineStore store.PipelineStore
executionStore store.ExecutionStore
git git.Interface
urlProvider url.Provider
slackbot *messaging.Slack
}
func NewController(
@ -45,13 +45,13 @@ func NewController(
slackbot *messaging.Slack,
) *Controller {
return &Controller{
authorizer: authorizer,
pipeline: pipeline,
repoStore: repoStore,
pipelineStore: pipelineStore,
executionStore: executionStore,
git: git,
urlProvider: urlProvider,
slackbot: slackbot,
authorizer: authorizer,
intelligenceService: pipeline,
repoStore: repoStore,
pipelineStore: pipelineStore,
executionStore: executionStore,
git: git,
urlProvider: urlProvider,
slackbot: slackbot,
}
}

View File

@ -44,7 +44,13 @@ func (c *Controller) GeneratePipeline(
RepoRef: in.RepoRef,
}
output, err := c.pipeline.Generate(ctx, generateRequest)
// do permission check on repo here?
repo, err := c.repoStore.FindByRef(ctx, in.RepoRef)
if err != nil {
return nil, fmt.Errorf("failed to find repo by ref: %w", err)
}
output, err := c.intelligenceService.Generate(ctx, generateRequest, repo)
if err != nil {
return nil, fmt.Errorf("generate pipeline: %w", err)
}

View File

@ -35,7 +35,7 @@ func (c *Controller) SuggestPipeline(
Pipeline: in.Pipeline,
}
output, err := c.pipeline.Suggest(ctx, suggestionRequest)
output, err := c.intelligenceService.Suggest(ctx, suggestionRequest)
if err != nil {
return nil, fmt.Errorf("suggest pipeline: %w", err)
}

View File

@ -42,7 +42,13 @@ func (c *Controller) UpdatePipeline(
Pipeline: in.Pipeline,
}
output, err := c.pipeline.Update(ctx, generateRequest)
// do permission check on repo here?
repo, err := c.repoStore.FindByRef(ctx, in.RepoRef)
if err != nil {
return nil, fmt.Errorf("failed to find repo by ref: %w", err)
}
output, err := c.intelligenceService.Update(ctx, generateRequest, repo)
if err != nil {
return nil, fmt.Errorf("update pipeline: %w", err)
}

View File

@ -21,9 +21,7 @@ import (
capabilitiesctrl "github.com/harness/gitness/app/api/controller/capabilities"
"github.com/harness/gitness/app/auth/authz"
"github.com/harness/gitness/app/services/capabilities"
"github.com/harness/gitness/app/store"
"github.com/harness/gitness/genai"
"github.com/harness/gitness/git"
"github.com/harness/gitness/types"
capabilitytypes "github.com/harness/gitness/types/capabilities"
@ -31,8 +29,6 @@ import (
)
type HarnessIntelligence struct {
repoStore store.RepoStore
git git.Interface
authorizer authz.Authorizer
cr *capabilities.Registry
cc *capabilitiesctrl.Controller
@ -57,15 +53,12 @@ func capabilityResponseToChatContext(
}
func (s *HarnessIntelligence) Generate(
ctx context.Context, req *types.PipelineGenerateRequest) (*types.PipelineGenerateResponse, error) {
ctx context.Context,
req *types.PipelineGenerateRequest,
repo *types.Repository) (*types.PipelineGenerateResponse, error) {
if req.RepoRef == "" {
return nil, fmt.Errorf("no repo ref specified")
}
// do permission check on repo here?
repo, err := s.repoStore.FindByRef(ctx, req.RepoRef)
if err != nil {
return nil, fmt.Errorf("failed to find repo by ref: %w", err)
}
conversationID := uuid.New()
chatRequest := &genai.ChatRequest{
@ -137,15 +130,10 @@ func (s *HarnessIntelligence) CapabilitiesLoop(
func (s *HarnessIntelligence) Update(
ctx context.Context,
req *types.PipelineUpdateRequest) (*types.PipelineUpdateResponse, error) {
req *types.PipelineUpdateRequest, repo *types.Repository) (*types.PipelineUpdateResponse, error) {
if req.RepoRef == "" {
return nil, fmt.Errorf("no repo ref specified")
}
// do permission check on repo here?
repo, err := s.repoStore.FindByRef(ctx, req.RepoRef)
if err != nil {
return nil, fmt.Errorf("failed to find repo by ref: %w", err)
}
conversationID := uuid.New()
chatRequest := &genai.ChatRequest{
@ -186,16 +174,6 @@ func (s *HarnessIntelligence) Suggest(
_ context.Context,
_ *types.PipelineSuggestionsRequest) (*types.PipelineSuggestionsResponse, error) {
return &types.PipelineSuggestionsResponse{
// TODO Update to be V0 Yaml
Suggestions: []types.Suggestion{
{
ID: "add-testing-stage",
Prompt: "add a testing stage",
UserSuggestion: "You should follow best practices by adding a testing stage",
Suggestion: "kind: pipeline\nstages:\n - steps:\n - name: build\n " +
"timeout: 10m\n run:\n script: go build\n - run:\n " +
"script: go test\n on-failure:\n errors: all\n action: ignore",
},
},
Suggestions: []types.Suggestion{},
}, nil
}

View File

@ -18,8 +18,6 @@ import (
capabilitiesctrl "github.com/harness/gitness/app/api/controller/capabilities"
"github.com/harness/gitness/app/auth/authz"
"github.com/harness/gitness/app/services/capabilities"
"github.com/harness/gitness/app/store"
"github.com/harness/gitness/git"
"github.com/google/wire"
)
@ -29,15 +27,11 @@ var WireSet = wire.NewSet(
)
func ProvideAiAgent(
repoStore store.RepoStore,
git git.Interface,
authorizer authz.Authorizer,
cr *capabilities.Registry,
cc *capabilitiesctrl.Controller,
) (*HarnessIntelligence, error) {
return &HarnessIntelligence{
repoStore,
git,
authorizer,
cr,
cc,

View File

@ -414,7 +414,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
return nil, err
}
capabilitiesController := capabilities2.ProvideController(registry)
harnessIntelligence, err := aiagent.ProvideAiAgent(repoStore, gitInterface, authorizer, registry, capabilitiesController)
harnessIntelligence, err := aiagent.ProvideAiAgent(authorizer, registry, capabilitiesController)
if err != nil {
return nil, err
}