app

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

README

app

import "github.com/Mgla96/snappr/internal/app"

Package app provides the main business logic for the snappr application.

Index

Constants

const (
    ErrUnmarshalLLMResponse = errors.New("error unmarshalling LLM response")
    ErrMissingGHToken       = errors.New("GH_TOKEN environment variable is required. Please set it before running this command")
    ErrMissingLLMToken      = errors.New("LLM_TOKEN environment variable is required. Please set it before running this command")
)

const (
    KnowledgeSourceTypeFile KnowledgeSourceType = "file"
    KnowledgeSourceTypeURL  KnowledgeSourceType = "url"
    KnowledgeSourceTypeAPI  KnowledgeSourceType = "api"
    KnowledgeSourceTypeText KnowledgeSourceType = "text"
    NotImplementedMessage   string              = "Not implemented"
)

func CheckGHToken

func CheckGHToken() error

CheckGHToken checks if the GH_TOKEN environment variable is set.

func CheckLLMToken

func CheckLLMToken() error

CheckLLMToken checks if the LLM_TOKEN environment variable is set.

func CheckTokens

func CheckTokens() error

func GetWorkflowByName

func GetWorkflowByName(name string, workflowList []config.PromptWorkflow) *config.PromptWorkflow

GetWorkflowByName returns workflow information by name from a list of workflows.

func NewDefaultPromptAndKnowledgeConfig

func NewDefaultPromptAndKnowledgeConfig(configPath string) error

NewDefaultPromptAndKnowledgeConfig creates a config.yaml file with the default prompt and knowledge config.

func RetrieveKnowledge

func RetrieveKnowledge(sourceName string, knowledgeSources []KnowledgeSource) (string, error)

type App

type App struct {
    // contains filtered or unexported fields
}

func New
func New(cfg *config.Config, githubClient githubClient, llmClient llmClient, logger zerolog.Logger) *App

New creates a new instance of the App.

func Setup
func Setup() (*App, error)

Setup sets up the application utilizing environment variables.

func SetupNoEnv
func SetupNoEnv(cfg *config.Config) *App

SetupNoEnv sets up the application from a config struct instead of utilizing environment variables.

func (*App) ExecuteCreatePR
func (a *App) ExecuteCreatePR(ctx context.Context, commitSHA, branch, workflowName, fileRegexPattern string, printOnly bool) error

ExecuteCreatePR executes the create PR workflow.

func (*App) ExecutePRReview
func (a *App) ExecutePRReview(ctx context.Context, commitSHA string, prNumber int, workflowName, fileRegexPattern string, printOnly bool) error

ExecutePRReview executes the PR review workflow.

type FileChange

type FileChange struct {
    Path        string `json:"path"`
    FullContent string `json:"full_content"`
    Patch       string `json:"patch"`
}

type KnowledgeSource

type KnowledgeSource struct {
    Name  string              `mapstructure:"name"`
    Type  KnowledgeSourceType `mapstructure:"type"`
    Value string              `mapstructure:"value"`
}

type KnowledgeSourceType

type KnowledgeSourceType string

type PRChanges

type PRChanges struct {
    Files []FileChange `json:"files"`
}

type PRCommentInfo

type PRCommentInfo struct {
    CommentBody string
    StartLine   int
    Line        int
}

type PRCreation

type PRCreation struct {
    // Title of the pull request
    Title string `json:"title"`
    // Body of the pull request
    Body string `json:"body"`
    // UpdatedFiles is a list of files that have been updated in the pull request
    UpdatedFiles []PRCreationFile `json:"updated_files"`
}

type PRCreationFile

type PRCreationFile struct {
    // Path is the file path of the file that has been updated
    Path string `json:"path"`
    // FullContent is the full content of the file that has been updated
    FullContent   string `json:"full_content"`
    CommitMessage string `json:"commit_message"`
}

type PRReviewMap

type PRReviewMap map[string][]PRCommentInfo

type SnapprUserConfig

type SnapprUserConfig struct {
    PromptWorkflows  []config.PromptWorkflow  `yaml:"promptWorkflows"`
    KnowledgeSources []config.KnowledgeSource `yaml:"knowledgeSources"`
}

Generated by gomarkdoc

Documentation

Overview

Package app provides the main business logic for the snappr application.

Index

Constants

View Source
const (
	ErrUnmarshalLLMResponse = errors.New("error unmarshalling LLM response")
	ErrMissingGHToken       = errors.New("GH_TOKEN environment variable is required. Please set it before running this command")
	ErrMissingLLMToken      = errors.New("LLM_TOKEN environment variable is required. Please set it before running this command")
)
View Source
const (
	NotImplementedMessage string = "Not implemented"
)

Variables

This section is empty.

Functions

func CheckGHToken

func CheckGHToken() error

CheckGHToken checks if the GH_TOKEN environment variable is set.

func CheckLLMToken

func CheckLLMToken() error

CheckLLMToken checks if the LLM_TOKEN environment variable is set.

func CheckTokens

func CheckTokens() error

func GetWorkflowByName

func GetWorkflowByName(name string, workflowList []config.PromptWorkflow) *config.PromptWorkflow

GetWorkflowByName returns workflow information by name from a list of workflows.

func NewDefaultPromptAndKnowledgeConfig

func NewDefaultPromptAndKnowledgeConfig(configPath string) error

NewDefaultPromptAndKnowledgeConfig creates a config.yaml file with the default prompt and knowledge config.

func RetrieveKnowledge

func RetrieveKnowledge(sourceName string, knowledgeSources []config.KnowledgeSource) (string, error)

RetrieveKnowledge retrieves knowledge from a knowledge source.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(
	cfg *config.Config, githubClient githubClient, llmClient llmClient, logger zerolog.Logger) *App

New creates a new instance of the App.

func Setup

func Setup() (*App, error)

Setup sets up the application utilizing environment variables.

func SetupNoEnv

func SetupNoEnv(cfg *config.Config) *App

SetupNoEnv sets up the application from a config struct instead of utilizing environment variables.

func (*App) ExecuteCreatePR

func (a *App) ExecuteCreatePR(ctx context.Context, commitSHA, branch, workflowName, knowledgeSources, fileRegexPattern string, printOnly bool) error

ExecuteCreatePR executes the create PR workflow.

func (*App) ExecutePRReview

func (a *App) ExecutePRReview(ctx context.Context, commitSHA string, prNumber int, workflowName, knowledgeSources, fileRegexPattern string, printOnly bool) error

ExecutePRReview executes the PR review workflow.

type FileChange

type FileChange struct {
	Path        string `json:"path"`
	FullContent string `json:"full_content"`
	Patch       string `json:"patch"`
}

type PRChanges

type PRChanges struct {
	Files []FileChange `json:"files"`
}

type PRCommentInfo

type PRCommentInfo struct {
	CommentBody string
	// The start_line is the first line in the pull request diff that your multi-line comment applies to.
	StartLine int
	// The line of the blob in the pull request diff that the comment applies to. For a multi-line comment, the last line of the range that your comment applies to.
	Line int
	// Side of the diff for the last line. Can be LEFT or RIGHT.
	Side clients.Side
	// The start_side is the starting side of the diff that the comment applies to. Can be LEFT or RIGHT.
	StartSide clients.Side
}

type PRCreation

type PRCreation struct {
	// Title of the pull request
	Title string `json:"title"`
	// Body of the pull request
	Body string `json:"body"`
	// UpdatedFiles is a list of files that have been updated in the pull request
	UpdatedFiles []PRCreationFile `json:"updated_files"`
}

type PRCreationFile

type PRCreationFile struct {
	// Path is the file path of the file that has been updated
	Path string `json:"path"`
	// FullContent is the full content of the file that has been updated
	FullContent   string `json:"full_content"`
	CommitMessage string `json:"commit_message"`
}

type PRReviewMap

type PRReviewMap map[string][]PRCommentInfo

PRReviewMap is a map of file paths to a list of PRCommentInfo

type SnapprUserConfig

type SnapprUserConfig struct {
	PromptWorkflows  []config.PromptWorkflow  `yaml:"promptWorkflows"`
	KnowledgeSources []config.KnowledgeSource `yaml:"knowledgeSources"`
}

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL