2023-04-22 16:23:56 -04:00
|
|
|
package vc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/go-git/go-git/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Issue represents an issue on a version control server.
|
|
|
|
type Issue struct {
|
|
|
|
ID string
|
|
|
|
Subject string
|
|
|
|
Body string
|
|
|
|
URL string
|
|
|
|
Author Author
|
|
|
|
}
|
|
|
|
|
2023-04-24 19:49:10 -04:00
|
|
|
func (i Issue) String() string {
|
|
|
|
return fmt.Sprintf("Issue ID: %s\nAuthor: %s\nSubject: %s\nBody:\n%s\nURL: %s\n", i.ID, i.Author.Handle, i.Subject, i.Body, i.URL)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-04-24 20:28:27 -04:00
|
|
|
ID string
|
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
|
|
|
|
DiffHunk string
|
|
|
|
URL string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Comment) String() string {
|
|
|
|
return fmt.Sprintf("Comment ID: %s\nAuthor: %s\nBody: %s\nPosition: %d\n\nDiffHunk:\n%s\n\nURL: %s\n", c.ID, c.Author.Handle, c.Body, c.Position, c.DiffHunk, c.URL)
|
2023-04-24 19:49:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListCommentOptions defines options for listing comments.
|
|
|
|
type ListCommentOptions struct {
|
|
|
|
// ChangeID is the local identifier for the code change request to list comments from (e.g. Github PR number)
|
|
|
|
ChangeID string
|
|
|
|
// 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)
|
|
|
|
}
|