feat: include file content in llm prompt context (#13)
This commit is contained in:
@ -18,14 +18,28 @@ type Forge struct {
|
||||
client *gitea.Client
|
||||
}
|
||||
|
||||
// GetProject implements port.Forge.
|
||||
func (f *Forge) GetProject(ctx context.Context, rawProjectID string) (*model.Project, error) {
|
||||
projectID, err := strconv.ParseInt(rawProjectID, 10, 64)
|
||||
// GetFile implements port.Forge.
|
||||
func (f *Forge) GetFile(ctx context.Context, rawProjectID string, path string) ([]byte, error) {
|
||||
project, err := f.getProject(rawProjectID)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
project, _, err := f.client.GetRepoByID(projectID)
|
||||
data, res, err := f.client.GetFile(project.Owner.UserName, project.Name, project.DefaultBranch, path)
|
||||
if err != nil {
|
||||
if res.StatusCode == http.StatusNotFound {
|
||||
return nil, errors.WithStack(port.ErrFileNotFound)
|
||||
}
|
||||
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// GetProject implements port.Forge.
|
||||
func (f *Forge) GetProject(ctx context.Context, rawProjectID string) (*model.Project, error) {
|
||||
project, err := f.getProject(rawProjectID)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
@ -39,12 +53,7 @@ func (f *Forge) GetProject(ctx context.Context, rawProjectID string) (*model.Pro
|
||||
|
||||
// GetProjectLanguages implements port.Forge.
|
||||
func (f *Forge) GetProjectLanguages(ctx context.Context, rawProjectID string) ([]string, error) {
|
||||
projectID, err := strconv.ParseInt(rawProjectID, 10, 64)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
project, _, err := f.client.GetRepoByID(projectID)
|
||||
project, err := f.getProject(rawProjectID)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
@ -65,12 +74,7 @@ func (f *Forge) GetProjectLanguages(ctx context.Context, rawProjectID string) ([
|
||||
|
||||
// CreateIssue implements port.Forge.
|
||||
func (f *Forge) CreateIssue(ctx context.Context, rawProjectID string, title string, body string) (string, error) {
|
||||
projectID, err := strconv.ParseInt(rawProjectID, 10, 64)
|
||||
if err != nil {
|
||||
return "", errors.WithStack(err)
|
||||
}
|
||||
|
||||
project, _, err := f.client.GetRepoByID(projectID)
|
||||
project, err := f.getProject(rawProjectID)
|
||||
if err != nil {
|
||||
return "", errors.WithStack(err)
|
||||
}
|
||||
@ -88,36 +92,17 @@ func (f *Forge) CreateIssue(ctx context.Context, rawProjectID string, title stri
|
||||
|
||||
// GetIssueTemplate implements port.Forge.
|
||||
func (f *Forge) GetIssueTemplate(ctx context.Context, rawProjectID string) (string, error) {
|
||||
projectID, err := strconv.ParseInt(rawProjectID, 10, 64)
|
||||
data, err := f.GetFile(ctx, rawProjectID, ".gitea/issue_template.md")
|
||||
if err != nil {
|
||||
return "", errors.WithStack(err)
|
||||
}
|
||||
|
||||
project, _, err := f.client.GetRepoByID(projectID)
|
||||
if err != nil {
|
||||
return "", errors.WithStack(err)
|
||||
}
|
||||
|
||||
data, res, err := f.client.GetFile(project.Owner.UserName, project.Name, project.DefaultBranch, ".gitea/issue_template.md")
|
||||
if err != nil {
|
||||
if res.StatusCode == http.StatusNotFound {
|
||||
return "", errors.WithStack(port.ErrFileNotFound)
|
||||
}
|
||||
|
||||
return "", errors.WithStack(err)
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// GetIssues implements port.Forge.
|
||||
func (f *Forge) GetIssues(ctx context.Context, rawProjectID string, issueIDs ...string) ([]*model.Issue, error) {
|
||||
projectID, err := strconv.ParseInt(rawProjectID, 10, 64)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
project, _, err := f.client.GetRepoByID(projectID)
|
||||
project, err := f.getProject(rawProjectID)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
@ -186,6 +171,20 @@ func (f *Forge) GetAllProjects(ctx context.Context) ([]*model.Project, error) {
|
||||
return projects, nil
|
||||
}
|
||||
|
||||
func (f *Forge) getProject(rawProjectID string) (*gitea.Repository, error) {
|
||||
projectID, err := strconv.ParseInt(rawProjectID, 10, 64)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
project, _, err := f.client.GetRepoByID(projectID)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return project, nil
|
||||
}
|
||||
|
||||
func NewForge(client *gitea.Client) *Forge {
|
||||
return &Forge{client: client}
|
||||
}
|
||||
|
Reference in New Issue
Block a user