models

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

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 MAX_NOTE_DIFF_LINE_COUNT = 15

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 (
	NoteTypeNormal        = "normal"
	NoteTypeDiffNote      = "diff_note"
	NoteTypeDiffNoteReply = "diff_note_reply"
)
View Source
var ERROR_REPO_LOCKED = errors.New("locked denied")
View Source
var HookTaskQueue = make(chan *WebHookTask, 300)
View Source
var ModeExternal = "external"
View Source
var NO_PERMISSION_ERROR = errors.New("no permission")

Functions

func AddToHookTaskQueue

func AddToHookTaskQueue(task *WebHookTask)

func Init added in v1.3.0

func Init(db *DBClient)

func StartHookTaskConsumer

func StartHookTaskConsumer(db *DBClient)

Types

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 DBClient

type DBClient struct {
	*dbengine.DBEngine
}

func OpenDB

func OpenDB() (*DBClient, error)

func (*DBClient) Close

func (db *DBClient) Close() error

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"`
}

MergeRequest model

func (*MergeRequest) ToInfo

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

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"`
}

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"`
	OldCommitId string                `json:"oldCommitId"`
	NewCommitId string                `json:"newCommitId"`
}

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"`
	Score        int    `json:"score" default:"-1"`
}

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"`
}

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 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) *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) CreateDiscussionNote

func (svc *Service) CreateDiscussionNote(repo *gitmodule.Repository, user *User, mergeId int64, request NoteRequest) (*Note, 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) CreateNormalNote

func (svc *Service) CreateNormalNote(repo *gitmodule.Repository, user *User, mergeId int64, note NoteRequest) (*Note, error)

func (*Service) CreateNote

func (svc *Service) CreateNote(repo *gitmodule.Repository, user *User, mergeId int64, note NoteRequest) (*Note, 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) IsCheckRunsValid

func (svc *Service) IsCheckRunsValid(repo *gitmodule.Repository, mrID int64) (bool, 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) 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) ReplyDiscussionNote

func (svc *Service) ReplyDiscussionNote(repo *gitmodule.Repository, user *User, mergeId int64, request NoteRequest) (*Note, 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) 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