services

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package services provides implementations for various service integrations including GitHub, GitLab, OpenAI, and SCM operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineSimilarity added in v0.5.0

func CosineSimilarity(v1, v2 []float32) float64

CosineSimilarity calculates the cosine similarity between two vectors

func EstimateTokenCount added in v0.5.0

func EstimateTokenCount(text string) int

EstimateTokenCount roughly estimates token count (4 chars ~= 1 token)

func GenerateIssueDescriptionWithOptions added in v0.5.0

func GenerateIssueDescriptionWithOptions(ctx context.Context, client *openai.Client, diff string, currentTitle string, forceRAG *bool) (string, string, error)

GenerateIssueDescriptionWithOptions generates an issue description with optional RAG override

func GenerateMRDescriptionWithOptions added in v0.5.0

func GenerateMRDescriptionWithOptions(ctx context.Context, client *openai.Client, diff string, forceRAG *bool) (string, error)

GenerateMRDescriptionWithOptions generates a description with optional RAG override

func NewOpenAIClient added in v0.2.0

func NewOpenAIClient() (*openai.Client, error)

NewOpenAIClient creates and validates the OpenAI client

Types

type Chunk added in v0.5.0

type Chunk struct {
	Content  string
	Index    int
	FilePath string
	Lines    int
}

Chunk represents a segment of a diff with metadata

func ChunkDiff added in v0.5.0

func ChunkDiff(diff string) []Chunk

ChunkDiff splits a diff into manageable chunks Each chunk is ~500-1000 lines or represents a complete file if smaller

type CreateMergeRequestOptions added in v0.2.0

type CreateMergeRequestOptions struct {
	IsDraft            bool
	IssueLabels        []string
	MilestoneID        int
	RemoveSourceBranch bool
	Squash             bool
	AutoMerge          bool
}

CreateMergeRequestOptions contains the optional parameters for creating a merge request

type CreateMergeRequestParams added in v0.3.0

type CreateMergeRequestParams struct {
	Provider           SCMProvider
	GitRepo            GitPusher
	CurrentBranch      string
	Remote             string
	TargetBranch       string
	IssueNumber        int
	IsDraft            bool
	RemoveSourceBranch bool
	Squash             bool
	AutoMerge          bool
	// IssueProvider is optional - if set, used to fetch issue details (for cross-repo scenarios)
	IssueProvider SCMProvider
	// CrossRepoIssueRef is optional - if set, used in MR description instead of simple "#123"
	CrossRepoIssueRef string
}

CreateMergeRequestParams is a convenience struct for CreateMergeRequest parameters

type EmbeddingVector added in v0.5.0

type EmbeddingVector struct {
	Chunk     *Chunk
	Embedding []float32
}

EmbeddingVector represents a chunk with its embedding vector

func GenerateEmbeddings added in v0.5.0

func GenerateEmbeddings(ctx context.Context, client *openai.Client, chunks []Chunk) ([]EmbeddingVector, error)

GenerateEmbeddings creates embeddings for all chunks using OpenAI's API

type GitHubProvider added in v0.2.0

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

GitHubProvider adapts GithubProject to the SCMProvider interface

func NewGitHubProvider added in v0.2.0

func NewGitHubProvider(repo string) (*GitHubProvider, error)

NewGitHubProvider creates a new GitHub provider

func (*GitHubProvider) AddLabelsToIssue added in v0.4.0

func (p *GitHubProvider) AddLabelsToIssue(issueNumber int, labels []string) error

AddLabelsToIssue implements the SCMProvider interface

func (*GitHubProvider) CreateIssue added in v0.3.0

func (p *GitHubProvider) CreateIssue(params IssueParams) (*IssueResult, error)

CreateIssue implements the SCMProvider interface

func (*GitHubProvider) CreateMergeRequest added in v0.2.0

func (p *GitHubProvider) CreateMergeRequest(params MergeRequestParams) (*RequestResult, error)

CreateMergeRequest implements the SCMProvider interface

func (*GitHubProvider) GetCrossRepoIssueRef added in v0.6.1

func (p *GitHubProvider) GetCrossRepoIssueRef(issueNumber int) string

GetCrossRepoIssueRef returns a cross-repo issue reference for GitHub

func (*GitHubProvider) GetIssue added in v0.2.0

func (p *GitHubProvider) GetIssue(issueNumber int) (*IssueResult, error)

GetIssue implements the SCMProvider interface

func (*GitHubProvider) GetOpenRequests added in v0.2.0

func (p *GitHubProvider) GetOpenRequests(issueNumber int) ([]RequestResult, error)

GetOpenRequests returns the open pull requests related to an issue

func (*GitHubProvider) GetOpenRequestsByBranch added in v0.6.5

func (p *GitHubProvider) GetOpenRequestsByBranch(branchName string) ([]RequestResult, error)

GetOpenRequestsByBranch returns the open pull requests for a specific head branch

func (*GitHubProvider) GetRequestDiff added in v0.10.2

func (p *GitHubProvider) GetRequestDiff(requestID int) (string, error)

GetRequestDiff implements the SCMProvider interface

func (*GitHubProvider) RemoveLabelsFromIssue added in v0.4.0

func (p *GitHubProvider) RemoveLabelsFromIssue(issueNumber int, labels []string) error

RemoveLabelsFromIssue implements the SCMProvider interface

func (*GitHubProvider) UpdateIssueDescription added in v0.10.2

func (p *GitHubProvider) UpdateIssueDescription(issueNumber int, description string) error

UpdateIssueDescription implements the SCMProvider interface

func (*GitHubProvider) UpdateIssueStatus added in v0.4.1

func (p *GitHubProvider) UpdateIssueStatus(issueNumber int, status string) error

UpdateIssueStatus implements the SCMProvider interface (no-op for GitHub)

func (*GitHubProvider) UpdateIssueTitle added in v0.10.2

func (p *GitHubProvider) UpdateIssueTitle(issueNumber int, title string) error

UpdateIssueTitle implements the SCMProvider interface

func (*GitHubProvider) UpdateRequestDescription added in v0.10.2

func (p *GitHubProvider) UpdateRequestDescription(requestID int, description string) error

UpdateRequestDescription implements the SCMProvider interface

type GitLabProvider added in v0.2.0

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

GitLabProvider adapts GitlabProject to the SCMProvider interface

func NewGitLabProvider added in v0.2.0

func NewGitLabProvider(repo string) (*GitLabProvider, error)

NewGitLabProvider creates a new GitLab provider

func (*GitLabProvider) AddLabelsToIssue added in v0.4.0

func (p *GitLabProvider) AddLabelsToIssue(issueNumber int, labels []string) error

AddLabelsToIssue implements the SCMProvider interface

func (*GitLabProvider) CreateIssue added in v0.3.0

func (p *GitLabProvider) CreateIssue(params IssueParams) (*IssueResult, error)

CreateIssue implements the SCMProvider interface

func (*GitLabProvider) CreateMergeRequest added in v0.2.0

func (p *GitLabProvider) CreateMergeRequest(params MergeRequestParams) (*RequestResult, error)

CreateMergeRequest implements the SCMProvider interface

func (*GitLabProvider) GetCrossRepoIssueRef added in v0.6.1

func (p *GitLabProvider) GetCrossRepoIssueRef(issueNumber int) string

GetCrossRepoIssueRef returns a cross-repo issue reference for GitLab

func (*GitLabProvider) GetIssue added in v0.2.0

func (p *GitLabProvider) GetIssue(issueNumber int) (*IssueResult, error)

GetIssue implements the SCMProvider interface

func (*GitLabProvider) GetOpenRequests added in v0.2.0

func (p *GitLabProvider) GetOpenRequests(issueNumber int) ([]RequestResult, error)

GetOpenRequests returns the open merge requests related to an issue

func (*GitLabProvider) GetOpenRequestsByBranch added in v0.6.5

func (p *GitLabProvider) GetOpenRequestsByBranch(branchName string) ([]RequestResult, error)

GetOpenRequestsByBranch returns the open merge requests for a specific source branch

func (*GitLabProvider) GetRequestDiff added in v0.10.2

func (p *GitLabProvider) GetRequestDiff(requestID int) (string, error)

GetRequestDiff implements the SCMProvider interface

func (*GitLabProvider) RemoveLabelsFromIssue added in v0.4.0

func (p *GitLabProvider) RemoveLabelsFromIssue(issueNumber int, labels []string) error

RemoveLabelsFromIssue implements the SCMProvider interface

func (*GitLabProvider) UpdateIssueDescription added in v0.10.2

func (p *GitLabProvider) UpdateIssueDescription(issueNumber int, description string) error

UpdateIssueDescription implements the SCMProvider interface

func (*GitLabProvider) UpdateIssueStatus added in v0.4.1

func (p *GitLabProvider) UpdateIssueStatus(issueNumber int, status string) error

UpdateIssueStatus implements the SCMProvider interface

func (*GitLabProvider) UpdateIssueTitle added in v0.10.2

func (p *GitLabProvider) UpdateIssueTitle(issueNumber int, title string) error

UpdateIssueTitle implements the SCMProvider interface

func (*GitLabProvider) UpdateRequestDescription added in v0.10.2

func (p *GitLabProvider) UpdateRequestDescription(requestID int, description string) error

UpdateRequestDescription implements the SCMProvider interface

type GitPusher added in v0.9.1

type GitPusher interface {
	Push(remoteName string, branchName string) error
}

GitPusher is the subset of git repository behavior that CreateMergeRequest needs. *git.Repository satisfies it; tests can supply a fake.

type GithubIssue

type GithubIssue struct {
	Number         int
	Title          string
	Labels         []string
	HTMLURL        string
	MilestoneTitle string
}

GithubIssue represents a GitHub issue

type GithubProject

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

GithubProject represents a GitHub repository

func NewGithubProject

func NewGithubProject(repoName string) (*GithubProject, error)

NewGithubProject creates a new GitHub project client

func (*GithubProject) AddLabelsToIssue added in v0.4.0

func (p *GithubProject) AddLabelsToIssue(issueNumber int, labels []string) error

AddLabelsToIssue adds labels to an existing issue

func (*GithubProject) CreateIssue

func (p *GithubProject) CreateIssue(title, labels string, selfAssign bool, milestoneTitle ...string) (*GithubIssue, error)

CreateIssue creates a new issue in the repository

func (*GithubProject) CreatePullRequest

func (p *GithubProject) CreatePullRequest(title, sourceBranch, targetBranch string, issueNumber int, isDraft bool, autoMerge bool, issueLabels []string, descriptionOverride string) (*GithubPullRequest, error)

CreatePullRequest creates a new pull request in the repository

func (*GithubProject) EnableAutoMerge added in v0.8.0

func (p *GithubProject) EnableAutoMerge(prNodeID string) error

EnableAutoMerge enables auto-merge for a pull request via GitHub's GraphQL API

func (*GithubProject) GetIssue

func (p *GithubProject) GetIssue(issueNumber int) (*GithubIssue, error)

GetIssue returns an issue by its number

func (*GithubProject) GetOpenPullRequestsByBranch added in v0.6.5

func (p *GithubProject) GetOpenPullRequestsByBranch(branchName string) ([]*GithubPullRequest, error)

GetOpenPullRequestsByBranch returns all open pull requests for a specific head branch

func (*GithubProject) GetOpenPullRequestsForIssue

func (p *GithubProject) GetOpenPullRequestsForIssue(issueNumber int) ([]*GithubPullRequest, error)

GetOpenPullRequestsForIssue returns all open pull requests related to an issue

func (*GithubProject) GetPullRequestDiff added in v0.2.0

func (p *GithubProject) GetPullRequestDiff(prNumber int) (string, error)

GetPullRequestDiff returns the diff of a pull request

func (*GithubProject) RemoveLabelsFromIssue added in v0.4.0

func (p *GithubProject) RemoveLabelsFromIssue(issueNumber int, labels []string) error

RemoveLabelsFromIssue removes labels from an existing issue

func (*GithubProject) UpdateIssueDescription added in v0.2.0

func (p *GithubProject) UpdateIssueDescription(issueNumber int, description string) error

UpdateIssueDescription updates the description of an issue

func (*GithubProject) UpdateIssueTitle added in v0.2.0

func (p *GithubProject) UpdateIssueTitle(issueNumber int, title string) error

UpdateIssueTitle updates the title of an issue

func (*GithubProject) UpdatePullRequestDescription added in v0.2.0

func (p *GithubProject) UpdatePullRequestDescription(prNumber int, description string) error

UpdatePullRequestDescription updates the description of a pull request

type GithubPullRequest

type GithubPullRequest struct {
	Number  int
	Title   string
	HTMLURL string
	IsDraft bool
	NodeID  string
}

GithubPullRequest represents a GitHub pull request

type GitlabIssue

type GitlabIssue struct {
	IID            int
	Title          string
	Labels         []string
	MilestoneID    int
	MilestoneTitle string
	WebURL         string
}

GitlabIssue represents a GitLab issue

type GitlabMergeRequest

type GitlabMergeRequest struct {
	IID     int
	Title   string
	WebURL  string
	IsDraft bool
}

GitlabMergeRequest represents a GitLab merge request

type GitlabProject

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

GitlabProject represents a GitLab repository

func NewGitlabProject

func NewGitlabProject(repoName string) (*GitlabProject, error)

NewGitlabProject creates a new GitLab project client

func (*GitlabProject) AddLabelsToIssue added in v0.4.0

func (p *GitlabProject) AddLabelsToIssue(issueIID int, labels []string) error

AddLabelsToIssue adds labels to an existing issue

func (*GitlabProject) CreateIssue

func (p *GitlabProject) CreateIssue(title, labels string, selfAssign bool, milestoneTitle ...string) (*GitlabIssue, error)

CreateIssue creates a new issue in the repository

func (*GitlabProject) CreateMergeRequest

func (p *GitlabProject) CreateMergeRequest(title, sourceBranch, targetBranch string, issueIID int, options CreateMergeRequestOptions, descriptionOverride string) (*GitlabMergeRequest, error)

CreateMergeRequest creates a new merge request in the repository

func (*GitlabProject) EnableAutoMerge added in v0.8.0

func (p *GitlabProject) EnableAutoMerge(mrIID int) error

EnableAutoMerge sets the MR to merge automatically when its pipeline succeeds

func (*GitlabProject) GetIssue

func (p *GitlabProject) GetIssue(issueNumber int) (*GitlabIssue, error)

GetIssue returns an issue by its number

func (*GitlabProject) GetMergeRequestDiff added in v0.2.0

func (p *GitlabProject) GetMergeRequestDiff(mrIID int) (string, error)

GetMergeRequestDiff returns the diff of a merge request

func (*GitlabProject) GetMilestoneID

func (p *GitlabProject) GetMilestoneID(title string) (int, error)

GetMilestoneID returns the ID of a milestone by title

func (*GitlabProject) GetOpenMergeRequestsByBranch added in v0.6.5

func (p *GitlabProject) GetOpenMergeRequestsByBranch(branchName string) ([]*GitlabMergeRequest, error)

GetOpenMergeRequestsByBranch returns all open merge requests for a specific source branch

func (*GitlabProject) GetOpenMergeRequestsForIssue

func (p *GitlabProject) GetOpenMergeRequestsForIssue(issueID int) ([]*GitlabMergeRequest, error)

GetOpenMergeRequestsForIssue returns all open merge requests related to an issue

func (*GitlabProject) RemoveLabelsFromIssue added in v0.4.0

func (p *GitlabProject) RemoveLabelsFromIssue(issueIID int, labels []string) error

RemoveLabelsFromIssue removes labels from an existing issue

func (*GitlabProject) UpdateIssueDescription added in v0.2.0

func (p *GitlabProject) UpdateIssueDescription(issueIID int, description string) error

UpdateIssueDescription updates the description of an issue

func (*GitlabProject) UpdateIssueStatus added in v0.4.1

func (p *GitlabProject) UpdateIssueStatus(issueIID int, status string) error

UpdateIssueStatus updates the status of an issue using GraphQL

func (*GitlabProject) UpdateIssueTitle added in v0.2.0

func (p *GitlabProject) UpdateIssueTitle(issueIID int, title string) error

UpdateIssueTitle updates the title of an issue

func (*GitlabProject) UpdateMergeRequestDescription added in v0.2.0

func (p *GitlabProject) UpdateMergeRequestDescription(mrIID int, description string) error

UpdateMergeRequestDescription updates the description of a merge request

type GraphQLRequest added in v0.4.1

type GraphQLRequest struct {
	Query     string         `json:"query"`
	Variables map[string]any `json:"variables"`
}

GraphQL structures for issue status update

type GraphQLResponse added in v0.4.1

type GraphQLResponse struct {
	Data   any `json:"data"`
	Errors []struct {
		Message string `json:"message"`
	} `json:"errors"`
}

type IssueParams added in v0.3.0

type IssueParams struct {
	Title          string
	Labels         string
	SelfAssign     bool
	MilestoneTitle string
}

IssueParams holds parameters for creating an issue

type IssueResult added in v0.2.0

type IssueResult struct {
	Number         int
	Title          string
	URL            string
	Labels         []string
	MilestoneID    int
	MilestoneTitle string
}

IssueResult represents an issue from either system

type MRInfo added in v0.2.0

type MRInfo struct {
	OpenRequests []RequestResult
	SelectedID   int
	Diff         string
	WebURL       string
	IssueURL     string
}

MRInfo holds information about a merge/pull request

func GetMRInfo added in v0.2.0

func GetMRInfo(provider SCMProvider, issueNumber int) (*MRInfo, error)

GetMRInfo retrieves the open merge/pull requests for an issue

func GetMRInfoByBranch added in v0.6.5

func GetMRInfoByBranch(provider SCMProvider, branchName string) (*MRInfo, error)

GetMRInfoByBranch retrieves the open merge/pull requests for a branch. This is useful in cross-repo scenarios where the issue doesn't exist in the code repo.

type MergeRequestParams added in v0.3.0

type MergeRequestParams struct {
	Title              string
	SourceBranch       string
	TargetBranch       string
	IssueNumber        int
	IsDraft            bool
	Labels             []string
	MilestoneID        int
	RemoveSourceBranch bool
	Squash             bool
	AutoMerge          bool
	Description        string // Optional description - if empty, will use default "Closes #X" format
}

MergeRequestParams holds parameters for creating a merge request

type RequestResult added in v0.2.0

type RequestResult struct {
	ID      int
	Title   string
	URL     string
	IsDraft bool
	Squash  bool
}

RequestResult represents a merge/pull request result

func CreateMergeRequest added in v0.2.0

func CreateMergeRequest(params CreateMergeRequestParams) (*RequestResult, error)

CreateMergeRequest contains the common flow for creating a merge/pull request

type SCMProvider added in v0.2.0

type SCMProvider interface {
	// CreateMergeRequest creates a merge/pull request and returns its details
	CreateMergeRequest(params MergeRequestParams) (*RequestResult, error)

	// CreateIssue creates a new issue in the repository
	CreateIssue(params IssueParams) (*IssueResult, error)

	// GetOpenRequests returns the open merge/pull requests for an issue
	GetOpenRequests(issueNumber int) ([]RequestResult, error)

	// GetOpenRequestsByBranch returns the open merge/pull requests for a specific source branch
	// This is useful in cross-repo scenarios where the issue doesn't exist in the code repo
	GetOpenRequestsByBranch(branchName string) ([]RequestResult, error)

	// GetIssue returns an issue by its number
	GetIssue(issueNumber int) (*IssueResult, error)

	// GetRequestDiff gets the diff for a merge/pull request
	GetRequestDiff(requestID int) (string, error)

	// UpdateRequestDescription updates the description of a merge/pull request
	UpdateRequestDescription(requestID int, description string) error

	// UpdateIssueDescription updates the description of an issue
	UpdateIssueDescription(issueNumber int, description string) error

	// UpdateIssueTitle updates the title of an issue
	UpdateIssueTitle(issueNumber int, title string) error

	// AddLabelsToIssue adds labels to an existing issue
	AddLabelsToIssue(issueNumber int, labels []string) error

	// RemoveLabelsFromIssue removes labels from an existing issue
	RemoveLabelsFromIssue(issueNumber int, labels []string) error

	// UpdateIssueStatus updates the status of an issue (GitLab only, no-op for GitHub)
	UpdateIssueStatus(issueNumber int, status string) error

	// GetCrossRepoIssueRef returns a cross-repo issue reference string
	// For GitHub: returns "owner/repo#123"
	// For GitLab: returns "group/project#123"
	GetCrossRepoIssueRef(issueNumber int) string
}

SCMProvider represents a source code management system (GitHub, GitLab, etc.)

type SearchResult added in v0.5.0

type SearchResult struct {
	Vector     *EmbeddingVector
	Similarity float64
}

SearchResult represents a search result with similarity score

type VectorStore added in v0.5.0

type VectorStore struct {
	Vectors []EmbeddingVector
}

VectorStore holds embeddings and provides similarity search

func NewVectorStore added in v0.5.0

func NewVectorStore(vectors []EmbeddingVector) *VectorStore

NewVectorStore creates a new vector store with the given embeddings

func (*VectorStore) Search added in v0.5.0

func (vs *VectorStore) Search(queryEmbedding []float32, topK int) []SearchResult

Search finds the top-K most similar chunks to the query embedding

type WorkflowStatus added in v0.9.0

type WorkflowStatus struct {
	Branch        string
	IssueNumber   int
	IssueTitle    string
	IssueLabels   []string
	Milestone     string
	MRURL         string
	MRNumber      int
	MRIsDraft     bool
	SuggestedNext string
	MRLookupErr   error
}

WorkflowStatus represents the current state of a ticket branch in the tix workflow.

func GetWorkflowStatus added in v0.9.0

func GetWorkflowStatus(codeProvider SCMProvider, issueProvider SCMProvider, branch string, issueNumber int, readyLabel string) (*WorkflowStatus, error)

GetWorkflowStatus resolves the current state of a ticket branch. codeProvider is used for MR lookup (the repo where the MR lives). issueProvider is used for issue lookup (may be the same as codeProvider). readyLabel is the configured label that marks an issue ready for review ("" means not configured). MR lookup failure is treated as a soft error — the function returns the issue info with MRLookupErr set.

Jump to

Keyboard shortcuts

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