2023-04-22 16:23:56 -04:00
|
|
|
package vc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-05-12 00:59:21 -04:00
|
|
|
"strings"
|
2023-04-22 16:23:56 -04:00
|
|
|
|
|
|
|
"github.com/go-git/go-git/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Issue represents an issue on a version control server.
|
|
|
|
type Issue struct {
|
2023-05-12 00:59:21 -04:00
|
|
|
Number int
|
2023-04-22 16:23:56 -04:00
|
|
|
Subject string
|
|
|
|
Body string
|
|
|
|
URL string
|
|
|
|
Author Author
|
|
|
|
}
|
|
|
|
|
2023-04-24 19:49:10 -04:00
|
|
|
func (i Issue) String() string {
|
2023-05-12 00:59:21 -04:00
|
|
|
return fmt.Sprintf("Issue #: %d\nAuthor: %s\nSubject: %s\nBody:\n%s\nURL: %s\n", i.Number, i.Author.Handle, i.Subject, i.Body, i.URL)
|
2023-04-24 19:49:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListIssueOptions defines options for listing issues.
|
|
|
|
type ListIssueOptions struct {
|
|
|
|
// Labels defines the list of labels an issue must have in order to be listed
|
|
|
|
// The issue must have *every* label provided.
|
|
|
|
Labels []string
|
|
|
|
// Handles defines the list of usernames to list issues from
|
|
|
|
// The issue can be created by *any* user provided.
|
|
|
|
Handles []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Comment represents a comment on a code change request.
|
|
|
|
// TODO comments on issue?
|
|
|
|
type Comment struct {
|
2023-05-08 20:14:19 -04:00
|
|
|
ID int64
|
2023-04-24 19:49:10 -04:00
|
|
|
// ChangeID is the local identifier for the code change request this comment was left on (e.g. Github PR number)
|
|
|
|
ChangeID string
|
2023-04-24 20:28:27 -04:00
|
|
|
Author Author
|
|
|
|
Body string
|
|
|
|
Position int
|
2023-05-08 20:14:19 -04:00
|
|
|
FilePath string
|
2023-04-24 20:28:27 -04:00
|
|
|
DiffHunk string
|
|
|
|
URL string
|
2023-05-08 20:14:19 -04:00
|
|
|
Branch string
|
|
|
|
PRNumber int
|
2023-04-24 20:28:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c Comment) String() string {
|
2023-05-08 20:14:19 -04:00
|
|
|
return fmt.Sprintf("Comment ID: %d\nAuthor: %s\nBody: %s\nPosition: %d\n\nDiffHunk:\n%s\n\nURL: %s\nBranch:\n%s\n\nFilePath:\n%s\n\n", c.ID, c.Author.Handle, c.Body, c.Position, c.DiffHunk, c.URL, c.Branch, c.FilePath)
|
2023-04-24 19:49:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListCommentOptions defines options for listing comments.
|
|
|
|
type ListCommentOptions struct {
|
|
|
|
// Handles defines the list of usernames to list comments from
|
|
|
|
// The comment can be created by *any* user provided.
|
|
|
|
Handles []string
|
|
|
|
}
|
|
|
|
|
2023-04-22 16:23:56 -04:00
|
|
|
// Author represents a commit, issue, or code change request author on a version control server.
|
|
|
|
type Author struct {
|
|
|
|
Email string
|
|
|
|
Handle string
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Repository represents a version control repository and its local path.
|
|
|
|
type Repository struct {
|
|
|
|
LocalPath string
|
|
|
|
HostDomain string
|
|
|
|
Name string
|
|
|
|
Owner Author
|
|
|
|
localRepo *git.Repository
|
|
|
|
}
|
|
|
|
|
|
|
|
// SSH returns the SSH connection string for the repository.
|
|
|
|
func (repo Repository) SSH() string {
|
2023-04-22 21:41:28 -04:00
|
|
|
return fmt.Sprintf("git@%s:%s/%s.git", repo.HostDomain, repo.Owner.Handle, repo.Name)
|
2023-04-22 16:23:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// HTTPS returns the HTTPS representation of the remote repository.
|
|
|
|
func (repo Repository) HTTPS() string {
|
|
|
|
return fmt.Sprintf("https://%s/%s/%s.git", repo.HostDomain, repo.Owner.Handle, repo.Name)
|
|
|
|
}
|
2023-05-12 00:59:21 -04:00
|
|
|
|
|
|
|
type IssueBody struct {
|
|
|
|
PromptBody string
|
|
|
|
FilePaths []string
|
|
|
|
BaseBranch string
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseIssueBody(body string) IssueBody {
|
|
|
|
issueBody := IssueBody{
|
|
|
|
BaseBranch: "main",
|
|
|
|
}
|
2023-09-04 16:44:59 -04:00
|
|
|
// TODO get rid of parsing like this - "---" may occur in the normal issue body
|
2023-05-12 00:59:21 -04:00
|
|
|
divider := "---"
|
|
|
|
|
|
|
|
parts := strings.Split(body, divider)
|
|
|
|
issueBody.PromptBody = strings.TrimSpace(parts[0])
|
|
|
|
// if there was nothing to split, no additional configuration was provided
|
|
|
|
if len(parts) <= 1 {
|
|
|
|
return issueBody
|
|
|
|
}
|
|
|
|
|
|
|
|
configStr := parts[1]
|
|
|
|
configLines := strings.Split(configStr, "\n")
|
|
|
|
for _, line := range configLines {
|
|
|
|
lineParts := strings.Split(line, ":")
|
|
|
|
if len(lineParts) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
key := strings.ToLower(strings.TrimSpace(lineParts[0]))
|
|
|
|
if key == "base" {
|
|
|
|
issueBody.BaseBranch = strings.TrimSpace(lineParts[1])
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if key == "files" {
|
|
|
|
filePaths := strings.Split(lineParts[1], ",")
|
|
|
|
for _, p := range filePaths {
|
|
|
|
issueBody.FilePaths = append(issueBody.FilePaths, strings.TrimSpace(p))
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return issueBody
|
|
|
|
}
|