Documentation ¶
Index ¶
- Constants
- func ComposeHTTPSCloneURL(owner, repo string) string
- func ComposeSSHCloneURL(ownerName, repoName string) string
- func CountNullArchivedRepository(ctx context.Context) (int64, error)
- func CountRepositories(ctx context.Context, opts CountRepositoryOptions) (int64, error)
- func FixNullArchivedRepository(ctx context.Context) (int64, error)
- func GetRepositoriesMapByIDs(ids []int64) (map[int64]*Repository, error)
- func IsErrRepoNotExist(err error) bool
- func IsErrUserDoesNotHaveAccessToRepo(err error) bool
- func IsRepositoryModelExist(ctx context.Context, u *user_model.User, repoName string) (bool, error)
- func IsRepositoryModelOrDirExist(ctx context.Context, u *user_model.User, repoName string) (bool, error)
- func IsUsableRepoName(name string) error
- func RepoPath(userName, repoName string) string
- func UpdateRepoIssueNumbers(ctx context.Context, repoID int64, isPull, isClosed bool) error
- func UpdateRepositoryOwnerName(ctx context.Context, oldUserName, newUserName string) error
- type CloneLink
- type CountRepositoryOptions
- type ErrRepoNotExist
- type ErrUserDoesNotHaveAccessToRepo
- type Repository
- func GetRepositoryByID(ctx context.Context, id int64) (*Repository, error)
- func GetRepositoryByName(ownerID int64, name string) (*Repository, error)
- func GetRepositoryByOwnerAndName(ctx context.Context, ownerName, repoName string) (*Repository, error)
- func GetRepositoryByURL(ctx context.Context, repoURL string) (*Repository, error)
- func GetTemplateRepo(ctx context.Context, repo *Repository) (*Repository, error)
- func (repo *Repository) APIURL() string
- func (repo *Repository) AfterLoad()
- func (repo *Repository) CanCreateBranch() bool
- func (repo *Repository) CanEnablePulls() bool
- func (repo *Repository) CloneLink() (cl *CloneLink)
- func (repo *Repository) CommitLink(commitID string) (result string)
- func (repo *Repository) ComposeBranchCompareURL(baseRepo *Repository, branchName string) string
- func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) string
- func (repo *Repository) ComposeDocumentMetas() map[string]string
- func (repo *Repository) ComposeMetas() map[string]string
- func (repo *Repository) FullName() string
- func (repo *Repository) GetBaseRepo(ctx context.Context) (err error)
- func (repo *Repository) GetCommitsCountCacheKey(contextName string, isRef bool) string
- func (repo *Repository) GetOriginalURLHostname() string
- func (repo *Repository) GetTrustModel() TrustModelType
- func (repo *Repository) HTMLURL() string
- func (repo *Repository) IsBeingCreated() bool
- func (repo *Repository) IsBeingMigrated() bool
- func (repo *Repository) IsBroken() bool
- func (repo *Repository) IsGenerated() bool
- func (repo *Repository) IsOwnedBy(userID int64) bool
- func (repo *Repository) Link() string
- func (repo *Repository) LoadOwner(ctx context.Context) (err error)
- func (repo *Repository) LogString() string
- func (repo *Repository) MarkAsBrokenEmpty()
- func (repo *Repository) MustOwner(ctx context.Context) *user_model.User
- func (repo *Repository) RepoPath() string
- func (repo *Repository) SanitizedOriginalURL() string
- func (repo *Repository) SizeDetails() []SizeDetail
- func (repo *Repository) SizeDetailsString() string
- func (repo *Repository) TemplateRepo() *Repository
- type RepositoryStatus
- type SizeDetail
- type TrustModelType
Constants ¶
const ( SizeDetailNameGit = "git" SizeDetailNameLFS = "lfs" )
text representations to be returned in SizeDetail.Name
Variables ¶
This section is empty.
Functions ¶
func ComposeHTTPSCloneURL ¶
ComposeHTTPSCloneURL returns HTTPS clone URL based on given owner and repository name.
func ComposeSSHCloneURL ¶
func CountNullArchivedRepository ¶
CountNullArchivedRepository counts the number of repositories with is_archived is null
func CountRepositories ¶
func CountRepositories(ctx context.Context, opts CountRepositoryOptions) (int64, error)
CountRepositories returns number of repositories. Argument private only takes effect when it is false, set it true to count all repositories.
func FixNullArchivedRepository ¶
FixNullArchivedRepository sets is_archived to false where it is null
func GetRepositoriesMapByIDs ¶
func GetRepositoriesMapByIDs(ids []int64) (map[int64]*Repository, error)
GetRepositoriesMapByIDs returns the repositories by given id slice.
func IsErrRepoNotExist ¶
IsErrRepoNotExist checks if an error is a ErrRepoNotExist.
func IsErrUserDoesNotHaveAccessToRepo ¶
IsErrUserDoesNotHaveAccessToRepo checks if an error is a ErrRepoFileAlreadyExists.
func IsRepositoryModelExist ¶
func IsRepositoryModelOrDirExist ¶
func IsRepositoryModelOrDirExist(ctx context.Context, u *user_model.User, repoName string) (bool, error)
IsRepositoryModelOrDirExist returns true if the repository with given name under user has already existed.
func IsUsableRepoName ¶
IsUsableRepoName returns true when repository is usable
func UpdateRepoIssueNumbers ¶
UpdateRepoIssueNumbers updates one of a repositories amount of (open|closed) (issues|PRs) with the current count
Types ¶
type CloneLink ¶
AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
func (repo *Repository) AllowsPulls() bool { return repo.CanEnablePulls() && repo.UnitEnabled(db.DefaultContext, unit.TypePullRequests) }
// CanEnableEditor returns true if repository meets the requirements of web editor.
func (repo *Repository) CanEnableEditor() bool { return !repo.IsMirror }
// DescriptionHTML does special handles to description and return HTML string.
func (repo *Repository) DescriptionHTML(ctx context.Context) template.HTML { desc, err := markup.RenderDescriptionHTML(&markup.RenderContext{ Ctx: ctx, URLPrefix: repo.HTMLURL(), // Don't use Metas to speedup requests }, repo.Description) if err != nil { log.Error("Failed to render description for %s (ID: %d): %v", repo.Name, repo.ID, err) return template.HTML(markup.Sanitize(repo.Description)) } return template.HTML(markup.Sanitize(desc)) }
CloneLink represents different types of clone URLs of repository.
type CountRepositoryOptions ¶
type CountRepositoryOptions struct { OwnerID int64 Private util.OptionalBool }
type ErrRepoNotExist ¶
ErrRepoNotExist represents a "RepoNotExist" kind of error.
func (ErrRepoNotExist) Error ¶
func (err ErrRepoNotExist) Error() string
func (ErrRepoNotExist) Unwrap ¶
func (err ErrRepoNotExist) Unwrap() error
Unwrap unwraps this error as a ErrNotExist error
type ErrUserDoesNotHaveAccessToRepo ¶
ErrUserDoesNotHaveAccessToRepo represents an error where the user doesn't has access to a given repo.
func (ErrUserDoesNotHaveAccessToRepo) Error ¶
func (err ErrUserDoesNotHaveAccessToRepo) Error() string
func (ErrUserDoesNotHaveAccessToRepo) Unwrap ¶
func (err ErrUserDoesNotHaveAccessToRepo) Unwrap() error
type Repository ¶
type Repository struct { ID int64 `xorm:"pk autoincr"` OwnerID int64 `xorm:"UNIQUE(s) index"` OwnerName string Owner *user_model.User `xorm:"-"` LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` Name string `xorm:"INDEX NOT NULL"` Description string `xorm:"TEXT"` Website string `xorm:"VARCHAR(2048)"` //OriginalServiceType api.GitServiceType `xorm:"index"` OriginalURL string `xorm:"VARCHAR(2048)"` DefaultBranch string NumWatches int NumStars int NumForks int NumIssues int NumClosedIssues int NumOpenIssues int `xorm:"-"` NumPulls int NumClosedPulls int NumOpenPulls int `xorm:"-"` NumMilestones int `xorm:"NOT NULL DEFAULT 0"` NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"` NumOpenMilestones int `xorm:"-"` NumProjects int `xorm:"NOT NULL DEFAULT 0"` NumClosedProjects int `xorm:"NOT NULL DEFAULT 0"` NumOpenProjects int `xorm:"-"` NumActionRuns int `xorm:"NOT NULL DEFAULT 0"` NumClosedActionRuns int `xorm:"NOT NULL DEFAULT 0"` NumOpenActionRuns int `xorm:"-"` IsPrivate bool `xorm:"INDEX"` IsEmpty bool `xorm:"INDEX"` IsArchived bool `xorm:"INDEX"` IsMirror bool `xorm:"INDEX"` Status RepositoryStatus `xorm:"NOT NULL DEFAULT 0"` RenderingMetas map[string]string `xorm:"-"` DocumentRenderingMetas map[string]string `xorm:"-"` IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"` ForkID int64 `xorm:"INDEX"` BaseRepo *Repository `xorm:"-"` IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` TemplateID int64 `xorm:"INDEX"` Size int64 `xorm:"NOT NULL DEFAULT 0"` GitSize int64 `xorm:"NOT NULL DEFAULT 0"` LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` //CodeIndexerStatus *RepoIndexerStatus `xorm:"-"` //StatsIndexerStatus *RepoIndexerStatus `xorm:"-"` IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"` CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"` Topics []string `xorm:"TEXT JSON"` TrustModel TrustModelType // Avatar: ID(10-20)-md5(32) - must fit into 64 symbols Avatar string `xorm:"VARCHAR(64)"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"` }
Repository represents a git repository.
func GetRepositoryByID ¶
func GetRepositoryByID(ctx context.Context, id int64) (*Repository, error)
GetRepositoryByID returns the repository by given id if exists.
func GetRepositoryByName ¶
func GetRepositoryByName(ownerID int64, name string) (*Repository, error)
GetRepositoryByName returns the repository by given name under user if exists.
func GetRepositoryByOwnerAndName ¶
func GetRepositoryByOwnerAndName(ctx context.Context, ownerName, repoName string) (*Repository, error)
GetRepositoryByOwnerAndName returns the repository by given owner name and repo name
func GetRepositoryByURL ¶
func GetRepositoryByURL(ctx context.Context, repoURL string) (*Repository, error)
GetRepositoryByURL returns the repository by given url
func GetTemplateRepo ¶
func GetTemplateRepo(ctx context.Context, repo *Repository) (*Repository, error)
GetTemplateRepo populates repo.TemplateRepo for a generated repository and returns an error on failure (NOTE: no error is returned for non-generated repositories, and TemplateRepo will be left untouched)
func (*Repository) APIURL ¶
func (repo *Repository) APIURL() string
APIURL returns the repository API URL
func (*Repository) AfterLoad ¶
func (repo *Repository) AfterLoad()
AfterLoad is invoked from XORM after setting the values of all fields of this object.
func (*Repository) CanCreateBranch ¶
func (repo *Repository) CanCreateBranch() bool
CanCreateBranch returns true if repository meets the requirements for creating new branches.
func (*Repository) CanEnablePulls ¶
func (repo *Repository) CanEnablePulls() bool
CanEnablePulls returns true if repository meets the requirements of accepting pulls.
func (*Repository) CloneLink ¶
func (repo *Repository) CloneLink() (cl *CloneLink)
CloneLink returns clone URLs of repository.
func (*Repository) CommitLink ¶
func (repo *Repository) CommitLink(commitID string) (result string)
CommitLink make link to by commit full ID note: won't check whether it's an right id
func (*Repository) ComposeBranchCompareURL ¶
func (repo *Repository) ComposeBranchCompareURL(baseRepo *Repository, branchName string) string
func (*Repository) ComposeCompareURL ¶
func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) string
ComposeCompareURL returns the repository comparison URL
func (*Repository) ComposeDocumentMetas ¶
func (repo *Repository) ComposeDocumentMetas() map[string]string
ComposeDocumentMetas composes a map of metas for properly rendering documents
func (*Repository) ComposeMetas ¶
func (repo *Repository) ComposeMetas() map[string]string
ComposeMetas composes a map of metas for properly rendering issue links and external issue trackers.
func (*Repository) FullName ¶
func (repo *Repository) FullName() string
FullName returns the repository full name
func (*Repository) GetBaseRepo ¶
func (repo *Repository) GetBaseRepo(ctx context.Context) (err error)
GetBaseRepo populates repo.BaseRepo for a fork repository and returns an error on failure (NOTE: no error is returned for non-fork repositories, and BaseRepo will be left untouched)
func (*Repository) GetCommitsCountCacheKey ¶
func (repo *Repository) GetCommitsCountCacheKey(contextName string, isRef bool) string
GetCommitsCountCacheKey returns cache key used for commits count caching.
func (*Repository) GetOriginalURLHostname ¶
func (repo *Repository) GetOriginalURLHostname() string
GetOriginalURLHostname returns the hostname of a URL or the URL
func (*Repository) GetTrustModel ¶
func (repo *Repository) GetTrustModel() TrustModelType
GetTrustModel will get the TrustModel for the repo or the default trust model
func (*Repository) HTMLURL ¶
func (repo *Repository) HTMLURL() string
HTMLURL returns the repository HTML URL
func (*Repository) IsBeingCreated ¶
func (repo *Repository) IsBeingCreated() bool
IsBeingCreated indicates that repository is being migrated or forked
func (*Repository) IsBeingMigrated ¶
func (repo *Repository) IsBeingMigrated() bool
IsBeingMigrated indicates that repository is being migrated
func (*Repository) IsBroken ¶
func (repo *Repository) IsBroken() bool
IsBroken indicates that repository is broken
func (*Repository) IsGenerated ¶
func (repo *Repository) IsGenerated() bool
IsGenerated returns whether _this_ repository was generated from a template
func (*Repository) IsOwnedBy ¶
func (repo *Repository) IsOwnedBy(userID int64) bool
IsOwnedBy returns true when user owns this repository
func (*Repository) Link ¶
func (repo *Repository) Link() string
Link returns the repository relative url
func (*Repository) LoadOwner ¶
func (repo *Repository) LoadOwner(ctx context.Context) (err error)
// LoadUnits loads repo units into repo.Units
func (repo *Repository) LoadUnits(ctx context.Context) (err error) { if repo.Units != nil { return nil } repo.Units, err = getUnitsByRepoID(ctx, repo.ID) if log.IsTrace() { unitTypeStrings := make([]string, len(repo.Units)) for i, unit := range repo.Units { unitTypeStrings[i] = unit.Type.String() } log.Trace("repo.Units, ID=%d, Types: [%s]", repo.ID, strings.Join(unitTypeStrings, ", ")) } return err }
// UnitEnabled if this repository has the given unit enabled
func (repo *Repository) UnitEnabled(ctx context.Context, tp unit.Type) bool { if err := repo.LoadUnits(ctx); err != nil { log.Warn("Error loading repository (ID: %d) units: %s", repo.ID, err.Error()) } for _, unit := range repo.Units { if unit.Type == tp { return true } } return false }
// MustGetUnit always returns a RepoUnit object
func (repo *Repository) MustGetUnit(ctx context.Context, tp unit.Type) *RepoUnit { ru, err := repo.GetUnit(ctx, tp) if err == nil { return ru } if tp == unit.TypeExternalWiki { return &RepoUnit{ Type: tp, Config: new(ExternalWikiConfig), } } else if tp == unit.TypeExternalTracker { return &RepoUnit{ Type: tp, Config: new(ExternalTrackerConfig), } } else if tp == unit.TypePullRequests { return &RepoUnit{ Type: tp, Config: new(PullRequestsConfig), } } else if tp == unit.TypeIssues { return &RepoUnit{ Type: tp, Config: new(IssuesConfig), } } else if tp == unit.TypeActions { return &RepoUnit{ Type: tp, Config: new(ActionsConfig), } } return &RepoUnit{ Type: tp, Config: new(UnitConfig), } }
// GetUnit returns a RepoUnit object
func (repo *Repository) GetUnit(ctx context.Context, tp unit.Type) (*RepoUnit, error) { if err := repo.LoadUnits(ctx); err != nil { return nil, err } for _, unit := range repo.Units { if unit.Type == tp { return unit, nil } } return nil, ErrUnitTypeNotExist{tp} }
LoadOwner loads owner user
func (*Repository) LogString ¶
func (repo *Repository) LogString() string
func (*Repository) MarkAsBrokenEmpty ¶
func (repo *Repository) MarkAsBrokenEmpty()
MarkAsBrokenEmpty marks the repo as broken and empty
func (*Repository) MustOwner ¶
func (repo *Repository) MustOwner(ctx context.Context) *user_model.User
MustOwner always returns a valid *user_model.User object to avoid conceptually impossible error handling. It creates a fake object that contains error details when error occurs.
func (*Repository) RepoPath ¶
func (repo *Repository) RepoPath() string
RepoPath returns the repository path
func (*Repository) SanitizedOriginalURL ¶
func (repo *Repository) SanitizedOriginalURL() string
SanitizedOriginalURL returns a sanitized OriginalURL
func (*Repository) SizeDetails ¶
func (repo *Repository) SizeDetails() []SizeDetail
SizeDetails forms a struct with various size details about repository
func (*Repository) SizeDetailsString ¶
func (repo *Repository) SizeDetailsString() string
SizeDetailsString returns a concatenation of all repository size details as a string
func (*Repository) TemplateRepo ¶
func (repo *Repository) TemplateRepo() *Repository
TemplateRepo returns the repository, which is template of this repository
type RepositoryStatus ¶
type RepositoryStatus int
RepositoryStatus defines the status of repository
const ( RepositoryReady RepositoryStatus = iota // a normal repository RepositoryBeingMigrated // repository is migrating RepositoryPendingTransfer // repository pending in ownership transfer state RepositoryBroken // repository is in a permanently broken state )
all kinds of RepositoryStatus
type SizeDetail ¶
type TrustModelType ¶
type TrustModelType int
TrustModelType defines the types of trust model for this repository
const ( DefaultTrustModel TrustModelType = iota // default trust model CommitterTrustModel CollaboratorTrustModel CollaboratorCommitterTrustModel )
kinds of TrustModel
func ToTrustModel ¶
func ToTrustModel(model string) TrustModelType
ToTrustModel converts a string to a TrustModelType
func (TrustModelType) String ¶
func (t TrustModelType) String() string
String converts a TrustModelType to a string