service

package
v0.0.0-...-c09d977 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeMessageForAI

func ComposeMessageForAI(title string, description string, diffs []*Diff) string

Types

type Diff

type Diff struct {
	Content     string
	NewPath     string
	OldPath     string
	NewFile     bool
	RenamedFile bool
	DeletedFile bool
}

type GitlabClient

type GitlabClient interface {
	MergeRequestsByProject(projectID int, createdAfter time.Time) ([]*ds.MergeRequest, error)
	MergeRequestApproves(projectID int, iid int) ([]*ds.BasicUser, error)
	GetMergeRequestDiff(projectID int, iid int) ([]*Diff, error)
	AddCommentToMergeRequests(projectID int, iid int, comment string) error

	CommitsByProject(projectID int, createdAfter time.Time) ([]*ds.Commit, error)
	GetCommitDiff(projectID int, commitID string) ([]*Diff, error)
	AddCommentToCommit(projectID int, commitID string, comment string) error
}

type OpenAIClient

type OpenAIClient interface {
	GenerateAICodeReviewComment(diff string) (string, error)
}

type Policy

type Policy interface {
	// ProcessChanges may add new reviewers or do some actions
	ProcessChanges(team *ds.Team, mr *ds.MergeRequest) (err error)
	// ApprovedByUser checks if merge request is approved by passed users
	ApprovedByUser(team *ds.Team, mr *ds.MergeRequest, byAll ...*ds.BasicUser) bool
	// ApprovedByPolicy checks if merge request is approved by policy conditions
	ApprovedByPolicy(team *ds.Team, mr *ds.MergeRequest) bool
}

type Repository

type Repository interface {
	Teams() ([]*ds.Team, error)
	Projects() ([]*ds.Project, error)
	MergeRequestByID(id int) (*ds.MergeRequest, error)
	MergeRequestsByProject(projectID int) ([]*ds.MergeRequest, error)
	MergeRequestsByAuthor(authorID []int) ([]*ds.MergeRequest, error)
	MergeRequestsByReviewer(reviewerID []int) ([]*ds.MergeRequest, error)
	UpsertMergeRequest(mr *ds.MergeRequest) error
	CommitByID(id string) (*ds.Commit, error)
	UpsertCommit(commit *ds.Commit) error
	UserBySlackID(slackID string) (*ds.User, *ds.Team, error)
}

type Service

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

func New

func New(r Repository, g GitlabClient, p map[ds.PolicyName]Policy, slack SlackClient, openai OpenAIClient) (*Service, error)

func (*Service) Close

func (s *Service) Close() error

func (*Service) GetAuthoredReviewedMRs

func (s *Service) GetAuthoredReviewedMRs(
	team *ds.Team,
	users []*ds.User,
) (authorToMR, reviewerToMR map[int][]*ds.MergeRequest, err error)

func (*Service) SubscribeOnProjects

func (s *Service) SubscribeOnProjects(pullPeriod time.Duration) error

SubscribeOnProjects Creates workers for each project and subscribe on merge requests changes

func (*Service) SubscribeOnSlack

func (s *Service) SubscribeOnSlack() error

func (*Service) TeamNotification

func (s *Service) TeamNotification(
	team *ds.Team,
	authorToMR, reviewerToMR map[int][]*ds.MergeRequest,
) (message string, err error)

func (*Service) UserNotification

func (s *Service) UserNotification(
	user *ds.User,
	team *ds.Team,
	authorToMR, reviewerToMR map[int][]*ds.MergeRequest,
) (message string, err error)

type SlackClient

type SlackClient interface {
	worker.SlackClient
	Subscribe() (chan ds.UserEvent, error)
}

type Worker

type Worker interface {
	Run()
	Close()
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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