feat: pull request generation
This commit is contained in:
@ -12,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
func NewIssueHandlerFromConfig(ctx context.Context, conf *config.Config) (*issue.Handler, error) {
|
||||
issueManager, err := NewIssueManagerFromConfig(ctx, conf)
|
||||
forgeManager, err := NewForgeManagerFromConfig(ctx, conf)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return issue.NewHandler(issueManager), nil
|
||||
return issue.NewHandler(forgeManager), nil
|
||||
}
|
||||
|
||||
type authProviderBasedForgeFactory struct {
|
||||
|
@ -5,14 +5,16 @@ import (
|
||||
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/config"
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/core/service"
|
||||
"github.com/bornholm/genai/llm"
|
||||
"github.com/bornholm/genai/llm/provider"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
_ "github.com/bornholm/genai/llm/provider/openai"
|
||||
"github.com/bornholm/genai/llm/provider/openrouter"
|
||||
_ "github.com/bornholm/genai/llm/provider/openrouter"
|
||||
)
|
||||
|
||||
func NewIssueManagerFromConfig(ctx context.Context, conf *config.Config) (*service.IssueManager, error) {
|
||||
func NewForgeManagerFromConfig(ctx context.Context, conf *config.Config) (*service.ForgeManager, error) {
|
||||
client, err := provider.Create(ctx,
|
||||
provider.WithConfig(&provider.Config{
|
||||
Provider: provider.Name(conf.LLM.Provider.Name),
|
||||
@ -24,12 +26,42 @@ func NewIssueManagerFromConfig(ctx context.Context, conf *config.Config) (*servi
|
||||
return nil, errors.Wrapf(err, "could not create llm client '%s'", conf.LLM.Provider.Name)
|
||||
}
|
||||
|
||||
if conf.LLM.Provider.Name == string(openrouter.Name) {
|
||||
client = &extendedContextClient{
|
||||
client: client,
|
||||
extend: func(ctx context.Context) context.Context {
|
||||
// Automatically "compress" prompts when using openrouter
|
||||
// See https://openrouter.ai/docs/features/message-transforms
|
||||
ctx = openrouter.WithTransforms(ctx, []string{"middle-out"})
|
||||
return ctx
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
forgeFactories, err := getForgeFactories(conf)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not get forge factories")
|
||||
}
|
||||
|
||||
issueManager := service.NewIssueManager(client, forgeFactories...)
|
||||
forgeManager := service.NewForgeManager(client, forgeFactories...)
|
||||
|
||||
return issueManager, nil
|
||||
return forgeManager, nil
|
||||
}
|
||||
|
||||
type extendedContextClient struct {
|
||||
client llm.Client
|
||||
extend func(ctx context.Context) context.Context
|
||||
}
|
||||
|
||||
// ChatCompletion implements llm.Client.
|
||||
func (c *extendedContextClient) ChatCompletion(ctx context.Context, funcs ...llm.ChatCompletionOptionFunc) (llm.CompletionResponse, error) {
|
||||
ctx = c.extend(ctx)
|
||||
return c.client.ChatCompletion(ctx, funcs...)
|
||||
}
|
||||
|
||||
// Model implements llm.Client.
|
||||
func (c *extendedContextClient) Model() string {
|
||||
return c.Model()
|
||||
}
|
||||
|
||||
var _ llm.Client = &extendedContextClient{}
|
||||
|
18
internal/setup/pullrequest_handler.go
Normal file
18
internal/setup/pullrequest_handler.go
Normal file
@ -0,0 +1,18 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/config"
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/http/handler/webui/pullrequest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func NewPullRequestHandlerFromConfig(ctx context.Context, conf *config.Config) (*pullrequest.Handler, error) {
|
||||
forgeManager, err := NewForgeManagerFromConfig(ctx, conf)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return pullrequest.NewHandler(forgeManager), nil
|
||||
}
|
@ -2,6 +2,7 @@ package setup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/config"
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/http/handler/webui"
|
||||
@ -22,13 +23,27 @@ func NewWebUIHandlerFromConfig(ctx context.Context, conf *config.Config) (*webui
|
||||
|
||||
opts = append(opts, webui.WithMount("/auth/", authHandler))
|
||||
|
||||
// Configure index redirect
|
||||
|
||||
opts = append(opts, webui.WithMount("/", authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/issue", http.StatusTemporaryRedirect)
|
||||
}))))
|
||||
|
||||
// Configure issue handler
|
||||
issueHandler, err := NewIssueHandlerFromConfig(ctx, conf)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not configure issue handler from config")
|
||||
}
|
||||
|
||||
opts = append(opts, webui.WithMount("/", authMiddleware(issueHandler)))
|
||||
opts = append(opts, webui.WithMount("/issue/", authMiddleware(issueHandler)))
|
||||
|
||||
// Configure pull request handler
|
||||
pullRequestHandler, err := NewPullRequestHandlerFromConfig(ctx, conf)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not configure pull request handler from config")
|
||||
}
|
||||
|
||||
opts = append(opts, webui.WithMount("/pullrequest/", authMiddleware(pullRequestHandler)))
|
||||
|
||||
// Configure common handler
|
||||
commonHandler, err := NewCommonHandlerFromConfig(ctx, conf)
|
||||
|
Reference in New Issue
Block a user