repository

package
v3.1.21 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 73 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAwaitGeneration = errors.New("generation took longer than ")
)
View Source
var ErrBranchIsDefault = util.ErrorWrap(util.ErrPermissionDenied, "branch is default")
View Source
var (
	LicenseFileName = "LICENSE"
)

Functions

func AcceptTransferOwnership

func AcceptTransferOwnership(ctx context.Context, repo *repo_model.Repository, doer *user_model.User) error

AcceptTransferOwnership transfers all corresponding setting from old user to new one.

func AddAllRepoBranchesToSyncQueue

func AddAllRepoBranchesToSyncQueue(ctx context.Context) error

func AddAllRepositoriesToTeam

func AddAllRepositoriesToTeam(ctx context.Context, t *organization.Team) error

AddAllRepositoriesToTeam adds all repositories to the team. If the team already has some repositories they will be left unchanged.

func AddOrUpdateCollaborator

func AddOrUpdateCollaborator(ctx context.Context, repo *repo_model.Repository, u *user_model.User, mode perm.AccessMode) error

func AddRepoToLicenseUpdaterQueue

func AddRepoToLicenseUpdaterQueue(opts *LicenseUpdaterOptions) error

func AdoptRepository

func AdoptRepository(ctx context.Context, doer, owner *user_model.User, opts CreateRepoOptions) (*repo_model.Repository, error)

AdoptRepository adopts pre-existing repository files for the user/organization.

func CacheRef

func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, fullRefName git.RefName) error

CacheRef cachhe last commit information of the branch or the tag

func CanDeleteBranch

func CanDeleteBranch(ctx context.Context, repo *repo_model.Repository, branchName string, doer *user_model.User) error

func CancelRepositoryTransfer

func CancelRepositoryTransfer(ctx context.Context, repoTransfer *repo_model.RepoTransfer, doer *user_model.User) error

CancelRepositoryTransfer cancels the repository transfer process. The sender or the users who have admin permission of the original repository can cancel the transfer

func ChangeRepositoryName

func ChangeRepositoryName(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, newRepoName string) error

ChangeRepositoryName changes all corresponding setting from old repository name to new one.

func CheckCreateRepository

func CheckCreateRepository(ctx context.Context, doer, owner *user_model.User, name string, overwriteOrAdopt bool) error

CheckCreateRepository check if doer could create a repository in new owner

func CheckDaemonExportOK

func CheckDaemonExportOK(ctx context.Context, repo *repo_model.Repository) error

CheckDaemonExportOK creates/removes git-daemon-export-ok for git-daemon...

func CleanUpMigrateInfo

func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo_model.Repository, error)

CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors.

func ConvertForkToNormalRepository

func ConvertForkToNormalRepository(ctx context.Context, repo *repo_model.Repository) error

ConvertForkToNormalRepository convert the provided repo from a forked repo to normal repo

func CreateNewBranch

func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldBranchName, branchName string) (err error)

CreateNewBranch creates a new repository branch

func CreateNewBranchFromCommit

func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commitID, branchName string) (err error)

CreateNewBranchFromCommit creates a new repository branch

func CreateRepository

func CreateRepository(ctx context.Context, doer, owner *user_model.User, opts CreateRepoOptions) (*repo_model.Repository, error)

CreateRepository creates a repository for the user/organization.

func CreateRepositoryDirectly

func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
	opts CreateRepoOptions, needsUpdateToReady bool,
) (*repo_model.Repository, error)

CreateRepositoryDirectly creates a repository for the user/organization. if needsUpdateToReady is true, it will update the repository status to ready when success

func DelDivergenceFromCache

func DelDivergenceFromCache(repoID int64, branchName string) error

func DelRepoDivergenceFromCache

func DelRepoDivergenceFromCache(ctx context.Context, repoID int64) error

DelRepoDivergenceFromCache deletes all divergence caches of a repository

func DeleteAvatar

func DeleteAvatar(ctx context.Context, repo *repo_model.Repository) error

DeleteAvatar deletes the repos's custom avatar.

func DeleteBranch

func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string, pr *issues_model.PullRequest) error

DeleteBranch delete branch

func DeleteBranchAfterMerge

func DeleteBranchAfterMerge(ctx context.Context, doer *user_model.User, prID int64, outFullBranchName *string) error

func DeleteCollaboration

func DeleteCollaboration(ctx context.Context, repo *repo_model.Repository, collaborator *user_model.User) (err error)

DeleteCollaboration removes collaboration relation between the user and repository.

func DeleteMissingRepositories

func DeleteMissingRepositories(ctx context.Context, doer *user_model.User) error

DeleteMissingRepositories deletes all repository records that lost Git files.

func DeleteOwnerRepositoriesDirectly

func DeleteOwnerRepositoriesDirectly(ctx context.Context, owner *user_model.User) error

DeleteOwnerRepositoriesDirectly calls DeleteRepositoryDirectly for all repos of the given owner

func DeleteRepository

func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, notify bool) error

DeleteRepository deletes a repository for a user or organization.

func DeleteRepositoryDirectly

func DeleteRepositoryDirectly(ctx context.Context, repoID int64, ignoreOrgTeams ...bool) error

DeleteRepository deletes a repository for a user or organization. make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock)

func DeleteUnadoptedRepository

func DeleteUnadoptedRepository(ctx context.Context, doer, u *user_model.User, repoName string) error

DeleteUnadoptedRepository deletes unadopted repository files from the filesystem

func FindForks

func FindForks(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, listOptions db.ListOptions) ([]*repo_model.Repository, int64, error)

FindForks returns all the forks of the repository

func ForkRepository

func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts ForkRepoOptions) (*repo_model.Repository, error)

ForkRepository forks a repository

func GarbageCollectLFSMetaObjects

func GarbageCollectLFSMetaObjects(ctx context.Context, opts GarbageCollectLFSMetaObjectsOptions) error

GarbageCollectLFSMetaObjects garbage collects LFS objects for all repositories

func GarbageCollectLFSMetaObjectsForRepo

func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.Repository, opts GarbageCollectLFSMetaObjectsOptions) error

GarbageCollectLFSMetaObjectsForRepo garbage collects LFS objects for a specific repository

func GenerateGitContent

func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) (err error)

GenerateGitContent generates git content from a template repository

func GenerateGitHooks

func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error

GenerateGitHooks generates git hooks from a template repository

func GenerateIssueLabels

func GenerateIssueLabels(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error

GenerateIssueLabels generates issue labels from a template repository

func GenerateProtectedBranch

func GenerateProtectedBranch(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error

func GenerateRepository

func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *repo_model.Repository, opts GenerateRepoOptions) (_ *repo_model.Repository, err error)

GenerateRepository generates a repository from a template

func GenerateWebhooks

func GenerateWebhooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error

GenerateWebhooks generates webhooks from a template repository

func GetContributorStats

func GetContributorStats(ctx context.Context, cache cache.StringCache, repo *repo_model.Repository, revision string) (map[string]*ContributorData, error)

GetContributorStats returns contributors stats for git commits for given revision or default branch

func GitFsckRepo

func GitFsckRepo(ctx context.Context, repo *repo_model.Repository, timeout time.Duration, args gitcmd.TrustedCmdArgs) error

GitFsckRepo calls 'git fsck' to check an individual repository's health.

func GitFsckRepos

func GitFsckRepos(ctx context.Context, timeout time.Duration, args gitcmd.TrustedCmdArgs) error

GitFsckRepos calls 'git fsck' to check repository health.

func GitGcRepo

func GitGcRepo(ctx context.Context, repo *repo_model.Repository, timeout time.Duration, args gitcmd.TrustedCmdArgs) error

GitGcRepo calls 'git gc' to remove unnecessary files and optimize the local repository

func GitGcRepos

func GitGcRepos(ctx context.Context, timeout time.Duration, args gitcmd.TrustedCmdArgs) error

GitGcRepos calls 'git gc' to remove unnecessary files and optimize the local repository

func HasRepository

func HasRepository(ctx context.Context, t *organization.Team, repoID int64) bool

HasRepository returns true if given repository belong to team.

func HasWiki

func HasWiki(ctx context.Context, repo *repo_model.Repository) bool

func Init

func Init(ctx context.Context) error

Init start repository service

func InitLicenseClassifier

func InitLicenseClassifier() error

func IsErrForkAlreadyExist

func IsErrForkAlreadyExist(err error) bool

IsErrForkAlreadyExist checks if an error is an ErrForkAlreadyExist.

func IsRepositoryLimitReached

func IsRepositoryLimitReached(err error) bool

func LinkedRepository

func LinkedRepository(ctx context.Context, a *repo_model.Attachment) (*repo_model.Repository, unit.Type, error)

LinkedRepository returns the linked repo if any

func ListUnadoptedRepositories

func ListUnadoptedRepositories(ctx context.Context, query string, opts *db.ListOptions) ([]string, int, error)

ListUnadoptedRepositories lists all the unadopted repositories that match the provided query

func LoadBranches

func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, isDeletedBranch optional.Option[bool], keyword string, page, pageSize int) (*Branch, []*Branch, int64, error)

LoadBranches loads branches from the repository limited by page & pageSize.

func MakeRepoPrivate

func MakeRepoPrivate(ctx context.Context, repo *repo_model.Repository) (err error)

func MakeRepoPublic

func MakeRepoPublic(ctx context.Context, repo *repo_model.Repository) (err error)

func MergeUpstream

func MergeUpstream(ctx reqctx.RequestContext, doer *user_model.User, repo *repo_model.Repository, branch string, ffOnly bool) (mergeStyle string, err error)

MergeUpstream merges the base repository's default branch into the fork repository's current branch.

func MigrateRepositoryGitData

func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
	repo *repo_model.Repository, opts migration.MigrateOptions,
	httpTransport *http.Transport,
) (*repo_model.Repository, error)

MigrateRepositoryGitData starts migrating git related data after created migrating repository

func PushCreateRepo

func PushCreateRepo(ctx context.Context, authUser, owner *user_model.User, repoName string) (*repo_model.Repository, error)

PushCreateRepo creates a repository when a new repository is pushed to an appropriate namespace

func PushUpdate

func PushUpdate(opts *repo_module.PushUpdateOptions) error

PushUpdate is an alias of PushUpdates for single push update options

func PushUpdateAddDeleteTags

func PushUpdateAddDeleteTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, pusher *user_model.User, addTags, delTags []string) error

PushUpdateAddDeleteTags updates a number of added and delete tags

func PushUpdates

func PushUpdates(opts []*repo_module.PushUpdateOptions) error

PushUpdates adds a push update to push queue

func ReconsiderRepoIssuesAssignee

func ReconsiderRepoIssuesAssignee(ctx context.Context, repo *repo_model.Repository, user *user_model.User) error

func ReconsiderWatches

func ReconsiderWatches(ctx context.Context, repo *repo_model.Repository, user *user_model.User) error

func ReinitMissingRepositories

func ReinitMissingRepositories(ctx context.Context) error

ReinitMissingRepositories reinitializes all repository records that lost Git files.

func RejectRepositoryTransfer

func RejectRepositoryTransfer(ctx context.Context, repo *repo_model.Repository, doer *user_model.User) error

RejectRepositoryTransfer marks the repository as ready and remove pending transfer entry, thus cancel the transfer process. The accepter can reject the transfer.

func RemoveAllRepositoriesFromTeam

func RemoveAllRepositoriesFromTeam(ctx context.Context, t *organization.Team) (err error)

RemoveAllRepositoriesFromTeam removes all repositories from team and recalculates access

func RemoveRandomAvatars

func RemoveRandomAvatars(ctx context.Context) error

RemoveRandomAvatars removes the randomly generated avatars that were created for repositories

func RemoveRepositoryFromTeam

func RemoveRepositoryFromTeam(ctx context.Context, t *organization.Team, repoID int64) error

RemoveRepositoryFromTeam removes repository from team of organization. If the team shall include all repositories the request is ignored.

func RenameBranch

func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, from, to string) (string, error)

RenameBranch rename a branch

func SetRepoDefaultBranch

func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, newBranchName string) error

func StartRepositoryTransfer

func StartRepositoryTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository, teams []*organization.Team) error

StartRepositoryTransfer transfer a repo from one owner to a new one. it make repository into pending transfer state, if doer can not create repo for new owner.

func SyncBranchesToDB

func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames, commitIDs []string, getCommit func(commitID string) (*git.Commit, error)) error

SyncBranchesToDB sync the branch information in the database. It will check whether the branches of the repository have never been synced before. If so, it will sync all branches of the repository. Otherwise, it will sync the branches that need to be updated.

func SyncRepoLicenses

func SyncRepoLicenses(ctx context.Context) error

func SyncRepositoryHooks

func SyncRepositoryHooks(ctx context.Context) error

SyncRepositoryHooks rewrites all repositories' pre-receive, update and post-receive hooks to make sure the binary and custom conf path are up-to-date.

func TeamAddRepository

func TeamAddRepository(ctx context.Context, t *organization.Team, repo *repo_model.Repository) (err error)

TeamAddRepository adds new repository to team of organization.

func UpdateBranch

func UpdateBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, doer *user_model.User, branchName, newCommitID, expectedOldCommitID string, force bool) error

UpdateBranch moves a branch reference to the provided commit. permission check should be done before calling this function.

func UpdateRepoLicenses

func UpdateRepoLicenses(ctx context.Context, repo *repo_model.Repository, commit *git.Commit) error

UpdateRepoLicenses will update repository licenses col if license file exists

func UpdateRepository

func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibilityChanged bool) (err error)

UpdateRepository updates a repository

func UpdateRepositoryUnits

func UpdateRepositoryUnits(ctx context.Context, repo *repo_model.Repository, units []repo_model.RepoUnit, deleteUnitTypes []unit.Type) (err error)

UpdateRepositoryUnits updates a repository's units

func UploadAvatar

func UploadAvatar(ctx context.Context, repo *repo_model.Repository, data []byte) error

UploadAvatar saves custom avatar for repository. FIXME: split uploads to different subdirs in case we have massive number of repos.

Types

type Branch

type Branch struct {
	DBBranch          *git_model.Branch
	IsProtected       bool
	IsIncluded        bool
	CommitsAhead      int
	CommitsBehind     int
	LatestPullRequest *issues_model.PullRequest
	MergeMovedOn      bool
}

Branch contains the branch information

type BranchDivergingInfo

type BranchDivergingInfo struct {
	// whether the base branch contains new commits which are not in the head branch
	BaseHasNewCommits bool

	// behind/after are number of commits that the head branch is behind/after the base branch, it's 0 if it's unable to calculate.
	// there could be a case that BaseHasNewCommits=true while the behind/after are both 0 (unable to calculate).
	HeadCommitsBehind int
	HeadCommitsAhead  int
}

BranchDivergingInfo contains the information about the divergence of a head branch to the base branch.

func GetBranchDivergingInfo

func GetBranchDivergingInfo(ctx reqctx.RequestContext, baseRepo *repo_model.Repository, baseBranch string, headRepo *repo_model.Repository, headBranch string) (*BranchDivergingInfo, error)

GetBranchDivergingInfo returns the information about the divergence of a patch branch to the base branch.

type BranchSyncOptions

type BranchSyncOptions struct {
	RepoID int64
}
type ContainedLinks struct {
	Branches      []*namedLink `json:"branches"`
	Tags          []*namedLink `json:"tags"`
	DefaultBranch string       `json:"default_branch"`
}

func LoadBranchesAndTags

func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, commitSHA string) (*ContainedLinks, error)

LoadBranchesAndTags creates a new repository branch

type ContributorData

type ContributorData struct {
	Name         string              `json:"name"`  // Display name of the contributor
	Login        string              `json:"login"` // Login name of the contributor in case it exists
	AvatarLink   string              `json:"avatar_link"`
	HomeLink     string              `json:"home_link"`
	TotalCommits int64               `json:"total_commits"`
	Weeks        map[int64]*WeekData `json:"weeks"`
}

ContributorData represents statistical git commit count data

type CreateRepoOptions

type CreateRepoOptions struct {
	Name             string
	Description      string
	OriginalURL      string
	GitServiceType   api.GitServiceType
	Gitignores       string
	IssueLabels      string
	License          string
	Readme           string
	DefaultBranch    string
	IsPrivate        bool
	IsMirror         bool
	IsTemplate       bool
	AutoInit         bool
	Status           repo_model.RepositoryStatus
	TrustModel       repo_model.TrustModelType
	MirrorInterval   string
	ObjectFormatName string
}

CreateRepoOptions contains the create repository options

type ErrForkAlreadyExist

type ErrForkAlreadyExist struct {
	Uname    string
	RepoName string
	ForkName string
}

ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error.

func (ErrForkAlreadyExist) Error

func (err ErrForkAlreadyExist) Error() string

func (ErrForkAlreadyExist) Unwrap

func (err ErrForkAlreadyExist) Unwrap() error

type ExtendedCommitStats

type ExtendedCommitStats struct {
	Author *api.CommitUser  `json:"author"`
	Stats  *api.CommitStats `json:"stats"`
}

ExtendedCommitStats contains information for commit stats with author data

type ForkRepoOptions

type ForkRepoOptions struct {
	BaseRepo     *repo_model.Repository
	Name         string
	Description  string
	SingleBranch string
}

ForkRepoOptions contains the fork repository options

type GarbageCollectLFSMetaObjectsOptions

type GarbageCollectLFSMetaObjectsOptions struct {
	LogDetail                func(format string, v ...any)
	AutoFix                  bool
	OlderThan                time.Time
	UpdatedLessRecentlyThan  time.Time
	NumberToCheckPerRepo     int64
	ProportionToCheckPerRepo float64
}

GarbageCollectLFSMetaObjectsOptions provides options for GarbageCollectLFSMetaObjects function

type GenerateRepoOptions

type GenerateRepoOptions struct {
	Name            string
	DefaultBranch   string
	Description     string
	Private         bool
	GitContent      bool
	Topics          bool
	GitHooks        bool
	Webhooks        bool
	Avatar          bool
	IssueLabels     bool
	ProtectedBranch bool
}

GenerateRepoOptions contains the template units to generate

func (GenerateRepoOptions) IsValid

func (gro GenerateRepoOptions) IsValid() bool

IsValid checks whether at least one option is chosen for generation

type LicenseUpdaterOptions

type LicenseUpdaterOptions struct {
	RepoID int64
}

type LimitReachedError

type LimitReachedError struct{ Limit int }

func (LimitReachedError) Error

func (LimitReachedError) Error() string

type UpstreamDivergingInfo

type UpstreamDivergingInfo struct {
	BaseBranchName          string
	BaseBranchHasNewCommits bool
	HeadBranchCommitsBehind int
}

UpstreamDivergingInfo is also used in templates, so it needs to search for all references before changing it.

func GetUpstreamDivergingInfo

func GetUpstreamDivergingInfo(ctx reqctx.RequestContext, forkRepo *repo_model.Repository, forkBranch string) (*UpstreamDivergingInfo, error)

GetUpstreamDivergingInfo returns the information about the divergence between the fork repository's branch and the base repository's default branch.

type WebSearchRepository

type WebSearchRepository struct {
	Repository               *structs.Repository `json:"repository"`
	LatestCommitStatus       *git.CommitStatus   `json:"latest_commit_status"`
	LocaleLatestCommitStatus string              `json:"locale_latest_commit_status"`
}

WebSearchRepository represents a repository returned by web search

type WebSearchResults

type WebSearchResults struct {
	OK   bool                   `json:"ok"`
	Data []*WebSearchRepository `json:"data"`
}

WebSearchResults results of a successful web search

type WeekData

type WeekData struct {
	Week      int64 `json:"week"`      // Starting day of the week as Unix timestamp
	Additions int   `json:"additions"` // Number of additions in that week
	Deletions int   `json:"deletions"` // Number of deletions in that week
	Commits   int   `json:"commits"`   // Number of commits in that week
}

Source Files

  • adopt.go
  • avatar.go
  • branch.go
  • cache.go
  • check.go
  • collaboration.go
  • commit.go
  • contributors_graph.go
  • create.go
  • delete.go
  • fork.go
  • generate.go
  • hooks.go
  • init.go
  • lfs.go
  • license.go
  • merge_upstream.go
  • migrate.go
  • push.go
  • repo_team.go
  • repository.go
  • setting.go
  • template.go
  • transfer.go

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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