mirror of https://github.com/harness/drone.git
feat: [ML-338]: Simplify HarnessIntelligence struct dependencies (#2700)
* Simplify HarnessIntelligence struct dependenciesCODE-2402
parent
25ca720888
commit
cb616e48a7
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue