models

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	I18nKeyMrNoteCommentCannotBeEmpty        = "mr.note.comment.cannot.be.empty"
	I18nKeyTemplateMrAICrTipForEachMaxLimit  = "template.mr.ai.cr.tip.reach.max.limit"
	I18nKeyMrAICrTitle                       = "mr.ai.cr.title"
	I18nKeyFile                              = "file"
	I18nKeyCodeSnippet                       = "snippet"
	I18nKeyMrAICrNoSuggestion                = "mr.ai.cr.no.suggestion"
	I18nKeyTemplateMrAICrFileContentMaxLimit = "template.mr.ai.cr.file.content.max.limit"
	I18nKeyMrAICrSessionTopic                = "mr.ai.cr.session.topic"
)
View Source
const (
	HOOK_TYPE_PROJECT string = "project"
	HOOK_TYPE_SYSTEM  string = "system"
)
View Source
const (
	HOOK_EVENT_PUSH string = "push_events"
)
View Source
const RelatedDiffLinesCountBefore = 3

Variables

View Source
var (
	MERGE_REQUEST_OPEN   = "open"
	MERGE_REQUEST_MERGED = "merged"
	MERGE_REQUEST_CLOSED = "closed"

	MERGE_STATUS_UNCHECKED   = "unchecked"
	MERGE_STATUS_CHECKING    = "checking"
	MERGE_STATUS_CONFLICT    = "conflict"
	MERGE_STATUS_NO_CONFLICT = "no_conflict"
)
View Source
var (
	NoteRoleAI   = NoteRole("AI")
	NoteRoleUser = NoteRole("USER")
)
View Source
var (
	NoteTypeNormal        = "normal"
	NoteTypeDiffNote      = "diff_note"
	NoteTypeDiffNoteReply = "diff_note_reply"
)
View Source
var CodeReviewerFactory = map[AICodeReviewType]CodeReviewerCreateFunc{}
View Source
var ERROR_REPO_LOCKED = errors.New("locked denied")
View Source
var HookTaskQueue = make(chan *WebHookTask, 300)
View Source
var MergeRequestStates = []MergeRequestState{"open", "closed", "merged"}
View Source
var ModeExternal = "external"
View Source
var NO_PERMISSION_ERROR = errors.New("no permission")

Functions

func AddToHookTaskQueue

func AddToHookTaskQueue(task *WebHookTask)

func Init

func Init(db *DBClient)

func RegisterCodeReviewer

func RegisterCodeReviewer(t AICodeReviewType, f CodeReviewerCreateFunc)

func StartHookTaskConsumer

func StartHookTaskConsumer(db *DBClient)

Types

type AICodeReviewNoteRequest

type AICodeReviewNoteRequest struct {
	NoteLocation NoteRequest `json:"noteLocation"`

	Type               AICodeReviewType                   `json:"type,omitempty"`
	CodeSnippetRelated *AICodeReviewRequestForCodeSnippet `json:"codeSnippetRelated,omitempty"`
}

type AICodeReviewRequestForCodeSnippet

type AICodeReviewRequestForCodeSnippet struct {
	CodeLanguage string `json:"codeLanguage,omitempty"` // if empty, will parse by newFilePath
	SelectedCode string `json:"selectedCode,omitempty"`
}

type AICodeReviewRequestForMR

type AICodeReviewRequestForMR struct{}

type AICodeReviewType

type AICodeReviewType string
var (
	AICodeReviewTypeMR            AICodeReviewType = "MR"
	AICodeReviewTypeMRFile        AICodeReviewType = "MR_FILE"
	AICodeReviewTypeMRCodeSnippet AICodeReviewType = "MR_CODE_SNIPPET"
)

type BaseModel

type BaseModel struct {
	ID        int64      `gorm:"primary_key" json:"id"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"-"`
	DeletedAt *time.Time `sql:"index" json:"-"`
}

Model base model definition, including fields `ID`, `CreatedAt`, `UpdatedAt`, `DeletedAt`, which could be embedded in your models

type User struct {
  gorm.Model
}

type BatchSearchMrCondition

type BatchSearchMrCondition struct {
	AppID int64 `json:"appID"`
	MrID  int64 `json:"mrID"`
}

type BatchSearchMrRequest

type BatchSearchMrRequest struct {
	Conditions []BatchSearchMrCondition `json:"conditions"`
}

type CheckRun

type CheckRun struct {
	ID          int64                     `json:"id"`
	MrID        int64                     `json:"mrId"`
	Name        string                    `json:"name"`       // 名称 golang-lint/test
	Type        string                    `json:"type"`       // 类型 CI
	ExternalID  string                    `json:"externalId"` // 外部系统 ID
	PipelineID  string                    `json:"pipelineId"` // 流水线 ID
	Commit      string                    `json:"commit"`
	Status      apistructs.CheckRunStatus `json:"status"` //progress/completed
	Result      apistructs.CheckRunResult `json:"result"` // success failed cancel
	Output      string                    `json:"output"`
	CreatedAt   time.Time                 `json:"createdAt"`
	CompletedAt *time.Time                `json:"completedAt"`
	RepoID      int64                     `json:"repoId"`
}

type CheckRuns

type CheckRuns struct {
	CheckRun []*CheckRun               `json:"checkrun"`
	Result   apistructs.CheckRunResult `json:"result"`
	Mergable bool                      `json:"mergable"`
}

type CodeReviewer

type CodeReviewer interface {
	CodeReview(i18n i18n.Translator, lang i18n.LanguageCodes, aiSessionID string) string
}

func NewCodeReviewer

func NewCodeReviewer(req AICodeReviewNoteRequest, repo *gitmodule.Repository, user *User, mr *apistructs.MergeRequestInfo) (cr CodeReviewer, err error)

type CodeReviewerCreateFunc

type CodeReviewerCreateFunc func(req AICodeReviewNoteRequest, repo *gitmodule.Repository, mr *apistructs.MergeRequestInfo, user *User) (CodeReviewer, error)

type DBClient

type DBClient struct {
	*dbengine.DBEngine
}

func OpenDB

func OpenDB() (*DBClient, error)

func (*DBClient) Close

func (db *DBClient) Close() error

type FileCodeReviewer

type FileCodeReviewer interface {
	CodeReviewer
	GetFileName() string
}

type MergeCount

type MergeCount struct {
	AppID uint64
	Count int
}

type MergeOptions

type MergeOptions struct {
	RemoveSourceBranch bool   `json:"removeSourceBranch"`
	CommitMessage      string `json:"CommitMessage"`
}

type MergeQueryCondition

type MergeQueryCondition struct {
	State string `json:"state"`
	Query string `json:"query"`
	Page  int    `json:"page"`
	Size  int    `json:"size"`
}

type MergeRequest

type MergeRequest struct {
	ID                   int64
	RepoID               int64 `gorm:"size:150;index:idx_repo_id"`
	Title                string
	Description          string `gorm:"type:text"`
	State                string `gorm:"size:150;index:idx_state"`
	AuthorId             string `gorm:"size:150;index:idx_author_id"`
	AssigneeId           string `gorm:"size:150;index:idx_assignee_id"`
	MergeUserId          string
	CloseUserId          string
	MergeCommitSha       string
	RepoMergeId          int
	SourceBranch         string
	SourceSha            string
	TargetBranch         string
	TargetSha            string
	RemoveSourceBranch   bool
	CreatedAt            time.Time
	UpdatedAt            *time.Time
	MergeAt              *time.Time
	CloseAt              *time.Time
	Score                int    `gorm:"size:150;index:idx_score"`
	ScoreNum             int    `gorm:"size:150;index:idx_score_num"`
	JoinTempBranchStatus string `gorm:"join_temp_branch_status"`
	IsJoinTempBranch     bool   `gorm:"is_join_temp_branch"`
}

MergeRequest model

func (*MergeRequest) ToInfo

func (mergeRequest *MergeRequest) ToInfo(repo *gitmodule.Repository) *apistructs.MergeRequestInfo

type MergeRequestState

type MergeRequestState string
const (
	OpenState   MergeRequestState = "open"
	ClosedState MergeRequestState = "closed"
	MergedState MergeRequestState = "merged"
)

func (MergeRequestState) String

func (s MergeRequestState) String() string

type MergeRequestsStats

type MergeRequestsStats struct {
	State MergeRequestState `json:"state"`
	Total int               `json:"total"`
}

type MrCheckRun

type MrCheckRun struct {
	ID     string `json:"id"`
	MRID   int64  `json:"mrId"`
	Status string `json:"status"`
	Name   string `json:"name"`
}

type Note

type Note struct {
	ID           int64                   `json:"id"`
	RepoID       int64                   `json:"repoId"`
	Type         string                  `json:"type" gorm:"size:150;index:idx_type"` // normal diff_note
	DiscussionId string                  `json:"discussionId"`                        //讨论id
	OldCommitId  string                  `json:"oldCommitId"`
	NewCommitId  string                  `json:"newCommitId"`
	MergeId      int64                   `json:"-" gorm:"index:idx_merge_id"`
	Note         string                  `json:"note" gorm:"type:text"`
	Data         string                  `json:"-" gorm:"type:text"`
	DataResult   NoteData                `json:"data" gorm:"-"`
	AuthorId     string                  `json:"authorId"`
	AuthorUser   *apistructs.UserInfoDto `json:"author" gorm:"-"`
	CreatedAt    time.Time               `json:"createdAt"`
	UpdatedAt    time.Time               `json:"updatedAt"`
	Score        int                     `json:"score" gorm:"size:150;index:idx_score"`
	Role         NoteRole                `json:"role"`
}

Note struct

type NoteData

type NoteData struct {
	DiffLines   []*gitmodule.DiffLine `json:"diffLines"`
	OldPath     string                `json:"oldPath"`
	NewPath     string                `json:"newPath"`
	OldLine     int                   `json:"oldLine"`
	NewLine     int                   `json:"newLine"`
	OldLineTo   int                   `json:"oldLineTo"`
	NewLineTo   int                   `json:"newLineTo"`
	OldCommitId string                `json:"oldCommitId"`
	NewCommitId string                `json:"newCommitId"`

	AICodeReviewType AICodeReviewType `json:"aiCodeReviewType,omitempty"`
	AISessionID      string           `json:"aiSessionID,omitempty"`
}

type NoteRequest

type NoteRequest struct {
	Note         string `json:"note"`
	Type         string `json:"type"`
	DiscussionId string `json:"discussionId"` //讨论id
	OldCommitId  string `json:"oldCommitId"`
	NewCommitId  string `json:"newCommitId"`
	OldPath      string `json:"oldPath"`
	NewPath      string `json:"newPath"`
	OldLine      int    `json:"oldLine"`
	NewLine      int    `json:"newLine"`
	OldLineTo    int    `json:"oldLineTo"`
	NewLineTo    int    `json:"newLineTo"` // these four index number must in a same section
	Score        int    `json:"score" default:"-1"`

	Role             NoteRole         `json:"role"`
	AICodeReviewType AICodeReviewType `json:"aiCodeReviewType,omitempty"`
	StartAISession   bool             `json:"startAISession,omitempty"`
}

type NoteRole

type NoteRole string

type PayloadCommit

type PayloadCommit struct {
	Id        string    `json:"id"`
	Author    *User     `json:"author"`
	Timestamp time.Time `json:"timestamp"`
	Message   string    `json:"message"`
	Added     []string  `json:"added"`
	Modified  []string  `json:"modified"`
	Removed   []string  `json:"removed"`
}

PayloadCommit struct for display

type PayloadPushEvent

type PayloadPushEvent struct {
	ObjectKind        string                `json:"object_kind"`
	IsTag             bool                  `json:"is_tag"`
	Ref               string                `json:"ref"`
	After             string                `json:"after"`
	Before            string                `json:"before"`
	IsDelete          bool                  `json:"is_delete"`
	Commits           []PayloadCommit       `json:"commits"`
	TotalCommitsCount int                   `json:"total_commits_count"`
	Pusher            *User                 `json:"pusher"`
	Repository        *gitmodule.Repository `json:"repository"`
}

func (*PayloadPushEvent) IsCreateNewBranch

func (p *PayloadPushEvent) IsCreateNewBranch() bool

func (*PayloadPushEvent) IsDeleteBranch

func (p *PayloadPushEvent) IsDeleteBranch() bool

type Permission

type Permission string
const (
	PermissionCreateBranch           Permission = "CREATE_BRANCH"
	PermissionDeleteBranch           Permission = "DELETE_BRANCH"
	PermissionCreateTAG              Permission = "CREATE_TAG"
	PermissionDeleteTAG              Permission = "DELETE_TAG"
	PermissionCloseMR                Permission = "CLOSE_MR"
	PermissionCreateMR               Permission = "CREATE_MR"
	PermissionMergeMR                Permission = "MERGE_MR"
	PermissionEditMR                 Permission = "EDIT_MR"
	PermissionArchive                Permission = "ARCHIVE"
	PermissionClone                  Permission = "CLONE"
	PermissionPush                   Permission = "PUSH"
	PermissionPushProtectBranch      Permission = "PUSH_PROTECT_BRANCH"
	PermissionPushProtectBranchForce Permission = "PUSH_PROTECT_BRANCH_FORCE"
	PermissionRepoLocked             Permission = "REPO_LOCKED"
)

type QueryMergeRequestsResult

type QueryMergeRequestsResult struct {
	List  []*apistructs.MergeRequestInfo `json:"list"`
	Total int                            `json:"total"`
}

type QueryMergeRequestsStatsResult

type QueryMergeRequestsStatsResult struct {
	Stats []MergeRequestsStats `json:"stats"`
}

type Repo

type Repo struct {
	ID          int64
	OrgID       int64
	ProjectID   int64
	AppID       int64
	OrgName     string `gorm:"size:150;index:idx_org_name"`
	ProjectName string `gorm:"size:150;index:idx_project_name"`
	AppName     string `gorm:"size:150;index:idx_app_name"`
	Path        string `gorm:"size:150;index:idx_path"`
	IsLocked    bool   `gorm:"size:150;index:idx_is_locked"`
	Size        int64
	IsExternal  bool
	Config      string
}

func (*Repo) DiskPath

func (r *Repo) DiskPath() string

func (Repo) TableName

func (Repo) TableName() string

type RepoCache

type RepoCache struct {
	ID        int64
	TypeName  string `gorm:"size:150;index:type_name"`
	KeyName   string `gorm:"size:150;index:key_name"`
	Value     string `gorm:"type:text"`
	CreatedAt time.Time
	UpdatedAt *time.Time
}

func (RepoCache) TableName

func (RepoCache) TableName() string

type Repository

type Repository struct {
	Organization string `json:"org"`
	Repository   string `json:"repo"`
	Url          string `json:"url"`
}

Repository struct

func (*Repository) CheckPath

func (r *Repository) CheckPath(file string) (string, error)

CheckPath for Repository

func (*Repository) FullName

func (r *Repository) FullName() string

func (*Repository) InfoPacksPath

func (r *Repository) InfoPacksPath() string

InfoPacksPath for Repository

func (*Repository) LooseObjectPath

func (r *Repository) LooseObjectPath(prefix string, suffix string) string

LooseObjectPath for Repository

func (*Repository) PackIdxPath

func (r *Repository) PackIdxPath(pack string) string

PackIdxPath for Repository

func (*Repository) Path

func (r *Repository) Path() string

DiskPath for Repository

func (*Repository) Root

func (r *Repository) Root() string

Root for Repository

type Service

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

func NewService

func NewService(dbClient *DBClient, bundle *bundle.Bundle, i18nTran i18n.Translator, lang i18n.LanguageCodes) *Service

func (*Service) AddBackupRecording

func (svc *Service) AddBackupRecording(repo *gitmodule.Repository, commitID, remark string) (*apistructs.RepoFiles, error)

添加备份记录

func (*Service) AddProjectHook

func (svc *Service) AddProjectHook(hook *WebHook) (*WebHook, error)

func (*Service) AddSystemHook

func (svc *Service) AddSystemHook(hook *WebHook) (*WebHook, error)

func (*Service) BatchGetMergeRequests

func (svc *Service) BatchGetMergeRequests(request *BatchSearchMrRequest) ([]apistructs.MergeRequestInfo, error)

func (*Service) CheckPermission

func (svc *Service) CheckPermission(repo *gitmodule.Repository, user *User, permission Permission, resourceRoleList []string) error

func (*Service) CloseMR

func (svc *Service) CloseMR(repo *gitmodule.Repository, user *User, mergeId int) (*apistructs.MergeRequestInfo, error)

func (*Service) CountMR

func (svc *Service) CountMR(repo *gitmodule.Repository, state string) (int, error)

func (*Service) CountMergeRequests

func (svc *Service) CountMergeRequests(appIDs []string, state string) (map[uint64]int, error)

func (*Service) CreateHookTask

func (svc *Service) CreateHookTask(task *WebHookTask) error

func (*Service) CreateMergeRequest

func (svc *Service) CreateMergeRequest(repo *gitmodule.Repository, user *User, info *apistructs.MergeRequestInfo) (*apistructs.MergeRequestInfo, error)

func (*Service) CreateNote

func (svc *Service) CreateNote(repo *gitmodule.Repository, user *User, mr *apistructs.MergeRequestInfo, req NoteRequest) (note *Note, err error)

func (*Service) CreateOrUpdateCheckRun

func (svc *Service) CreateOrUpdateCheckRun(repo *gitmodule.Repository, request *apistructs.CheckRun) (*apistructs.CheckRun, error)

func (*Service) CreateRepo

func (svc *Service) CreateRepo(request *apistructs.CreateRepoRequest) (*Repo, error)

func (*Service) DeleteBackupRecording

func (svc *Service) DeleteBackupRecording(uuid string) (*apistructs.RepoFiles, error)

删除备份记录

func (*Service) DeleteRepo

func (svc *Service) DeleteRepo(repo *Repo) error

func (*Service) GetBackupList

func (svc *Service) GetBackupList(pageNo, pageSize int, repo *gitmodule.Repository) (*apistructs.BackupListResponse, error)

获取备份列表

func (*Service) GetMergeRequestDetail

func (svc *Service) GetMergeRequestDetail(repo *gitmodule.Repository, mergeId int) (*apistructs.MergeRequestInfo, error)

func (*Service) GetProjectHooks

func (svc *Service) GetProjectHooks(repository *gitmodule.Repository) ([]WebHook, error)

func (*Service) GetProjectHooksByEvent

func (svc *Service) GetProjectHooksByEvent(repository *gitmodule.Repository, event string, active bool) ([]WebHook, error)

func (*Service) GetRepoByApp

func (svc *Service) GetRepoByApp(appId int64) (*Repo, error)

func (*Service) GetRepoById

func (svc *Service) GetRepoById(id int64) (*Repo, error)

func (*Service) GetRepoByNames

func (svc *Service) GetRepoByNames(orgID int64, project, app string) (*Repo, error)

func (*Service) GetRepoByPath

func (svc *Service) GetRepoByPath(path string) (*Repo, error)

func (*Service) GetRepoLocked

func (svc *Service) GetRepoLocked(project, app int64) (bool, error)

func (*Service) GetSystemHooksByEvent

func (svc *Service) GetSystemHooksByEvent(event string, active bool) ([]WebHook, error)

func (*Service) I18n

func (svc *Service) I18n(key string) string

func (*Service) IsCheckRunsValid

func (svc *Service) IsCheckRunsValid(repo *gitmodule.Repository, mrID int64) (bool, error)

func (*Service) ListAllRepos

func (svc *Service) ListAllRepos(req apistructs.GittarListRepoRequest) ([]*Repo, error)

func (*Service) Merge

func (svc *Service) Merge(repo *gitmodule.Repository, user *User, mergeId int, mergeOptions *MergeOptions) (*gitmodule.Commit, error)

func (*Service) QueryAllNotes

func (svc *Service) QueryAllNotes(repo *gitmodule.Repository, mergeId int64) ([]Note, error)

func (*Service) QueryCheckRuns

func (svc *Service) QueryCheckRuns(repo *gitmodule.Repository, mrID string) (apistructs.CheckRuns, error)

func (*Service) QueryDiffNotes

func (svc *Service) QueryDiffNotes(repo *gitmodule.Repository, mergeId int64, oldCommitId string, newCommitId string) ([]Note, error)

func (*Service) QueryMergeRequests

func (svc *Service) QueryMergeRequests(repo *gitmodule.Repository, queryCondition *apistructs.GittarQueryMrRequest) (*QueryMergeRequestsResult, error)

func (*Service) QueryMergeRequestsStats

func (svc *Service) QueryMergeRequestsStats(repo *gitmodule.Repository, queryCondition *apistructs.GittarQueryMrRequest) (*QueryMergeRequestsStatsResult, error)

func (*Service) RemoveCheckRuns

func (svc *Service) RemoveCheckRuns(mrID int64) error

func (*Service) RemoveMR

func (svc *Service) RemoveMR(repository *Repo) error

func (*Service) RemoveProjectHooks

func (svc *Service) RemoveProjectHooks(repository *Repo) error

func (*Service) ReopenMR

func (svc *Service) ReopenMR(repo *gitmodule.Repository, user *User, mergeId int) (*apistructs.MergeRequestInfo, error)

func (*Service) SetLocked

func (*Service) SyncMergeRequest

func (svc *Service) SyncMergeRequest(repo *gitmodule.Repository, branch string, commitID string, userID string, isHookExist bool) error

func (*Service) TriggerEvent

func (svc *Service) TriggerEvent(repository *gitmodule.Repository, eventName string, contentData interface{})

func (*Service) UpdateJoinTempBranchStatus

func (svc *Service) UpdateJoinTempBranchStatus(id int, status string, isJoinTempStatus *bool) error

func (*Service) UpdateMergeRequest

func (svc *Service) UpdateMergeRequest(repo *gitmodule.Repository, user *User, info *apistructs.MergeRequestInfo) (*apistructs.MergeRequestInfo, error)

func (*Service) UpdateRepo

func (svc *Service) UpdateRepo(repo *Repo, request *apistructs.UpdateRepoRequest) error

func (*Service) UpdateRepoSizeCache

func (svc *Service) UpdateRepoSizeCache(id int64, size int64) error

type User

type User struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	NickName string `json:"nickname"`
	Email    string `json:"email"`
}

User struct for sender pusher and more

func NewInnerUser

func NewInnerUser() *User

func (*User) IsInnerUser

func (user *User) IsInnerUser() bool

func (*User) ToGitSignature

func (user *User) ToGitSignature() *gitmodule.Signature

type WebHook

type WebHook struct {
	BaseModel
	HookType   string `json:"hook_type" gorm:"size:150;index:idx_hook_type"`
	Name       string `json:"name" gorm:"size:150;index:idx_hook_name"`
	RepoID     int64  `json:"repo" gorm:"size:150;index:idx_repo_id"`
	Token      string `json:"token"`
	Url        string `json:"url"`
	IsActive   bool   `json:"is_active"`
	PushEvents bool   `json:"push_events"`
}

type WebHookTask

type WebHookTask struct {
	BaseModel
	HookId          int64 `gorm:"index:idx_hook_id"`
	Url             string
	Event           string
	IsDelivered     bool
	IsSucceed       bool
	RequestContent  string `gorm:"type:text"`
	ResponseContent string `gorm:"type:text"`
	ResponseStatus  string
}

WebHookTask represents a hook task. todo 请求头 响应头

Jump to

Keyboard shortcuts

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