scm

package
v0.1.8-rc.21 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package scm provides a single DataSource connector backed by go-scm for all SCM providers (GitHub, GitLab, Bitbucket). It lists pull requests, issues, repo metadata and recent commit authors for each repo in scope and returns them as NormalizedItems for vectorization. One adapter serves all providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllTools

func AllTools(s Service) []tool.Tool

func NewCommitAndPRTool

func NewCommitAndPRTool(s Service) tool.CallableTool

NewCommitAndPRTool creates a tool that commits multiple file changes to a branch and optionally opens a Pull Request.

func NewCreatePRCommentTool

func NewCreatePRCommentTool(s Service) tool.CallableTool

func NewCreatePullRequestTool

func NewCreatePullRequestTool(s Service) tool.CallableTool

func NewGetPullRequestTool

func NewGetPullRequestTool(s Service) tool.CallableTool

func NewGetRepoContentTool

func NewGetRepoContentTool(s Service) tool.CallableTool

NewGetRepoContentTool creates a tool that retrieves the content of a file in a repository.

func NewListPRChangesTool

func NewListPRChangesTool(s Service) tool.CallableTool

func NewListPRCommentsTool

func NewListPRCommentsTool(s Service) tool.CallableTool

func NewListPRCommitsTool

func NewListPRCommitsTool(s Service) tool.CallableTool

func NewListPullRequestsTool

func NewListPullRequestsTool(s Service) tool.CallableTool

func NewListReposTool

func NewListReposTool(s Service) tool.CallableTool

func NewMergePRTool

func NewMergePRTool(s Service) tool.CallableTool

func RegisterDataSource

func RegisterDataSource(svc Service)

Types

type ChangeSummary

type ChangeSummary struct {
	Path    string `json:"path"`
	Added   bool   `json:"added,omitempty"`
	Deleted bool   `json:"deleted,omitempty"`
	Renamed bool   `json:"renamed,omitempty"`
}

ChangeSummary is a simplified file-change response.

type CommentSummary

type CommentSummary struct {
	ID     int    `json:"id"`
	Body   string `json:"body"`
	Author string `json:"author"`
}

CommentSummary is a simplified comment response.

type CommitAndPRRequest

type CommitAndPRRequest struct {
	Repo          string       `json:"repo" jsonschema:"description=Repository name (e.g. owner/name),required"`
	Branch        string       `json:"branch" jsonschema:"description=Target branch for commits,required"`
	BaseBranch    string       `json:"base_branch" jsonschema:"description=Base branch to create the target branch from (default: main)"`
	CommitMessage string       `json:"commit_message" jsonschema:"description=Commit message for the file changes,required"`
	Files         []FileChange `json:"files" jsonschema:"description=List of files to create or update,required"`
	CreatePR      bool         `json:"create_pr" jsonschema:"description=If true also open a Pull Request against the base branch"`
	PRTitle       string       `json:"pr_title" jsonschema:"description=PR title (required when create_pr is true)"`
	PRBody        string       `json:"pr_body" jsonschema:"description=PR description"`
}

CommitAndPRRequest is the input for the uber commit-and-PR tool.

type CommitAndPRResponse

type CommitAndPRResponse struct {
	CommittedFiles []string `json:"committed_files"`
	Branch         string   `json:"branch"`
	PRNumber       int      `json:"pr_number,omitempty"`
	PRLink         string   `json:"pr_link,omitempty"`
}

CommitAndPRResponse is the output of the uber commit-and-PR tool.

type CommitSummary

type CommitSummary struct {
	Sha     string `json:"sha"`
	Message string `json:"message"`
	Author  string `json:"author"`
}

CommitSummary is a simplified commit response.

type Config

type Config struct {
	Provider string `json:"provider" yaml:"Provider,omitempty" toml:"Provider,omitempty"` // github, gitlab, etc.
	Token    string `json:"token" yaml:"Token,omitempty" toml:"Token,omitempty"`
	BaseURL  string `json:"base_url" yaml:"BaseURL,omitempty" toml:"BaseURL,omitempty"` // for enterprise instances

	DoNotLearn bool `json:"do_not_learn" yaml:"DoNotLearn,omitempty" toml:"DoNotLearn,omitempty"`
}

Config holds configuration for SCM providers

type CreatePRCommentRequest

type CreatePRCommentRequest struct {
	Repo   string `json:"repo" jsonschema:"description=Repository name (e.g. owner/name),required"`
	Number int    `json:"number" jsonschema:"description=Pull Request number,required"`
	Body   string `json:"body" jsonschema:"description=Comment body text,required"`
}

type CreatePullRequestRequest

type CreatePullRequestRequest struct {
	Repo  string `json:"repo" jsonschema:"description=Repository name (e.g. owner/name),required"`
	Title string `json:"title" jsonschema:"description=PR Title,required"`
	Body  string `json:"body" jsonschema:"description=PR Description"`
	Head  string `json:"head" jsonschema:"description=Source branch,required"`
	Base  string `json:"base" jsonschema:"description=Target branch,required"`
}

type FileChange

type FileChange struct {
	Path    string `json:"path" jsonschema:"description=File path in the repository (e.g. pkg/main.go),required"`
	Content string `json:"content" jsonschema:"description=Full file content as plain text,required"`
}

FileChange describes a single file to create or update.

type GetPullRequestRequest

type GetPullRequestRequest struct {
	Repo string `json:"repo" jsonschema:"description=Repository name (e.g. owner/name),required"`
	ID   []int  `json:"id" jsonschema:"description=Pull Request ID,required"`
}

type GetRepoContentRequest

type GetRepoContentRequest struct {
	Repo string `json:"repo" jsonschema:"description=Repository name (e.g. owner/name),required"`
	Path string `json:"path" jsonschema:"description=Path to the file,required"`
	Ref  string `json:"ref" jsonschema:"description=Branch,tag, or commit SHA,required"`
}

type ListPullRequestsRequest

type ListPullRequestsRequest struct {
	Repo  string `json:"repo" jsonschema:"description=Repository name (e.g. owner/name),required"`
	State string `json:"state" jsonschema:"description=Filter by state: open (default) or closed"`
}

type ListReposResponse

type ListReposResponse struct {
	Repositories []string `json:"repositories"`
}

type PRNumberRequest

type PRNumberRequest struct {
	Repo   string `json:"repo" jsonschema:"description=Repository name (e.g. owner/name),required"`
	Number int    `json:"number" jsonschema:"description=Pull Request number,required"`
}

type PullRequestSummary

type PullRequestSummary struct {
	Number int    `json:"number"`
	Title  string `json:"title"`
	State  string `json:"state"`
	Source string `json:"source"`
	Target string `json:"target"`
	Author string `json:"author"`
}

PullRequestSummary is a simplified PR response for listing.

type SCMConnector

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

SCMConnector implements datasource.DataSource for any go-scm provider (GitHub, GitLab, Bitbucket). It is parameterized by sourceName so one implementation serves all; scope.Get(sourceName) supplies the repo list per provider.

func NewSCMConnector

func NewSCMConnector(svc Service) *SCMConnector

NewSCMConnector returns a DataSource that uses the go-scm Service to list repo metadata, pull requests, issues and recent authors. The datasource identifier (e.g. "github", "gitlab") is derived from svc.Provider(), and scope.Get(sourceName) defines which repos to include.

func NewSCMConnectorWithOptions

func NewSCMConnectorWithOptions(svc Service, recentCommitCount int) *SCMConnector

NewSCMConnectorWithOptions returns an SCMConnector where callers can override the number of recent commits inspected for author extraction.

func (*SCMConnector) ListItems

ListItems lists repo metadata, pull requests, issues and recent commit authors for each repo in scope. All four data types are fetched concurrently per repo. Errors inside individual fetchers are logged and treated as partial failures so that one unavailable resource does not block the rest.

func (*SCMConnector) Name

func (c *SCMConnector) Name() string

Name returns the source identifier (e.g. "github", "gitlab").

type Service

type Service interface {
	Provider() string

	ListRepos(ctx context.Context, opts go_scm.ListOptions) ([]*go_scm.Repository, error)
	// FindRepo returns a single repository by name (e.g. owner/repo). Used for data ingestion to get description, link, language.
	FindRepo(ctx context.Context, repo string) (*go_scm.Repository, error)
	ListPullRequests(ctx context.Context, repo string, opts go_scm.PullRequestListOptions) ([]*go_scm.PullRequest, error)
	// ListIssues returns open (or closed) issues for the given repo. Used by the datasource to surface issue context.
	ListIssues(ctx context.Context, repo string, opts go_scm.IssueListOptions) ([]*go_scm.Issue, error)
	// ListCommits returns the most-recent commits for the given repo. Used by the datasource to extract recent authors.
	ListCommits(ctx context.Context, repo string, opts go_scm.CommitListOptions) ([]*go_scm.Commit, error)
	GetPullRequest(ctx context.Context, repo string, id int) (*go_scm.PullRequest, error)
	CreatePullRequest(ctx context.Context, repo string, input *go_scm.PullRequestInput) (*go_scm.PullRequest, error)
	ListPullRequestChanges(ctx context.Context, repo string, number int, opts go_scm.ListOptions) ([]*go_scm.Change, error)
	ListPullRequestComments(ctx context.Context, repo string, number int, opts go_scm.ListOptions) ([]*go_scm.Comment, error)
	CreatePullRequestComment(ctx context.Context, repo string, number int, input *go_scm.CommentInput) (*go_scm.Comment, error)
	ListPullRequestCommits(ctx context.Context, repo string, number int, opts go_scm.ListOptions) ([]*go_scm.Commit, error)
	MergePullRequest(ctx context.Context, repo string, number int) error
	CreateOrUpdateFile(ctx context.Context, repo, path string, params *go_scm.ContentParams) error
	FindBranch(ctx context.Context, repo, name string) (*go_scm.Reference, error)
	CreateBranch(ctx context.Context, repo string, params *go_scm.ReferenceInput) error

	// Tool-facing methods: these accept a single request struct and return
	// tool-friendly responses so that each NewXTool constructor can simply
	// pass the method reference to NewFunctionTool.
	ListReposTool(ctx context.Context, req go_scm.ListOptions) (ListReposResponse, error)
	ListPullRequestsTool(ctx context.Context, req ListPullRequestsRequest) ([]PullRequestSummary, error)
	GetPullRequestTool(ctx context.Context, req GetPullRequestRequest) (map[int]*go_scm.PullRequest, error)
	CreatePullRequestTool(ctx context.Context, req CreatePullRequestRequest) (*go_scm.PullRequest, error)
	ListPRChangesTool(ctx context.Context, req PRNumberRequest) ([]ChangeSummary, error)
	ListPRCommentsTool(ctx context.Context, req PRNumberRequest) ([]CommentSummary, error)
	CreatePRCommentTool(ctx context.Context, req CreatePRCommentRequest) (*go_scm.Comment, error)
	ListPRCommitsTool(ctx context.Context, req PRNumberRequest) ([]CommitSummary, error)
	MergePRTool(ctx context.Context, req PRNumberRequest) (string, error)
	GetRepoContent(ctx context.Context, req GetRepoContentRequest) (*go_scm.Content, error)
	CommitAndPRTool(ctx context.Context, req CommitAndPRRequest) (CommitAndPRResponse, error)

	// Validate performs a lightweight health check to verify that the
	// provider's token is valid and the endpoint is reachable.
	Validate(ctx context.Context) error
}

Service defines the capabilities of the SCM provider.

func New

func New(cfg Config) (Service, error)

New creates a new SCM Service based on the configuration. It dispatches to the appropriate provider constructor based on cfg.Provider. Without this factory, callers would need to know about each provider's internal constructor, coupling them to implementation details.

type ToolProvider

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

ToolProvider wraps an SCM Service and satisfies the tools.ToolProviders interface so SCM tools can be passed directly to tools.NewRegistry. Without this, SCM tool construction would be inlined in the registry.

func NewToolProvider

func NewToolProvider(svc Service) *ToolProvider

NewToolProvider creates a ToolProvider from an already-initialised SCM service. Callers are responsible for creating and validating the service beforehand.

func (*ToolProvider) GetTools

func (p *ToolProvider) GetTools(_ context.Context) []tool.Tool

GetTools returns all SCM tools wired to the underlying service.

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