repository

package
v3.1.17 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	EnvRepoName     = "GITEA_REPO_NAME"
	EnvRepoUsername = "GITEA_REPO_USER_NAME"
	EnvRepoID       = "GITEA_REPO_ID"
	EnvRepoIsWiki   = "GITEA_REPO_IS_WIKI"
	EnvPusherName   = "GITEA_PUSHER_NAME"
	EnvPusherEmail  = "GITEA_PUSHER_EMAIL"
	EnvPusherID     = "GITEA_PUSHER_ID"
	EnvKeyID        = "GITEA_KEY_ID" // public key ID
	EnvDeployKeyID  = "GITEA_DEPLOY_KEY_ID"
	EnvPRID         = "GITEA_PR_ID"
	EnvPRIndex      = "GITEA_PR_INDEX" // not used by Gitea at the moment, it is for custom git hooks
	EnvPushTrigger  = "GITEA_PUSH_TRIGGER"
	EnvIsInternal   = "GITEA_INTERNAL_PUSH"
	EnvAppURL       = "GITEA_ROOT_URL"
	EnvActionPerm   = "GITEA_ACTION_PERM"
)

env keys for git hooks need

Variables

View Source
var (
	// Gitignores contains the gitiginore files
	Gitignores []string

	// Licenses contains the license files
	Licenses []string

	// Readmes contains the readme files
	Readmes []string

	// LabelTemplateFiles contains the label template files, each item has its DisplayName and Description
	LabelTemplateFiles []OptionFile
)

Functions

func CanUserDelete

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

CanUserDelete returns true if user could delete the repository

func CanUserForkBetweenOwners

func CanUserForkBetweenOwners(id1, id2 int64) bool

CanUserForkBetweenOwners returns true if user can fork between owners. By default, a user can fork a repository from another owner, but not from themselves. Many users really like to fork their own repositories, so add an experimental setting to allow this.

func CanUserForkRepo

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

CanUserForkRepo returns true if specified user can fork repository.

func CreateTemporaryPath

func CreateTemporaryPath(prefix string) (string, context.CancelFunc, error)

CreateTemporaryPath creates a temporary path

func FullPushingEnvironment

func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model.Repository, repoName string, prID, prIndex int64) []string

FullPushingEnvironment returns an os environment to allow hooks to work on push

func GetLicense

func GetLicense(name string, values *LicenseValues) ([]byte, error)

func InitializeLabels

func InitializeLabels(ctx context.Context, id int64, labelTemplate string, isOrg bool) error

InitializeLabels adds a label set to a repository using a template

func InternalPushingEnvironment

func InternalPushingEnvironment(doer *user_model.User, repo *repo_model.Repository) []string

InternalPushingEnvironment returns an os environment to switch off hooks on push It is recommended to avoid using this unless you are pushing within a transaction or if you absolutely are sure that post-receive and pre-receive will do nothing We provide the full pushing-environment for other hook providers

func LoadRepoConfig

func LoadRepoConfig() error

LoadRepoConfig loads the repository config

func LoadTemplateLabelsByDisplayName

func LoadTemplateLabelsByDisplayName(displayName string) ([]*label.Label, error)

LoadTemplateLabelsByDisplayName loads a label template by its display name

func PushingEnvironment

func PushingEnvironment(doer *user_model.User, repo *repo_model.Repository) []string

PushingEnvironment returns an os environment to allow hooks to work on push

func StoreMissingLfsObjectsInRepository

func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, lfsClient lfs.Client) error

StoreMissingLfsObjectsInRepository downloads missing LFS objects

func SyncReleasesWithTags

func SyncReleasesWithTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository) error

SyncReleasesWithTags is a tag<->release table synchronization which overwrites all Releases from the repository tags. This can be relied on since a pull-mirror is always identical to its upstream. Hence, after each sync we want the release set to be identical to the upstream tag set. This is much more efficient for repositories like https://github.com/vim/vim (with over 13000 tags).

func SyncRepoBranches

func SyncRepoBranches(ctx context.Context, repoID, doerID int64) (int64, error)

SyncRepoBranches synchronizes branch table with repository branches

func SyncRepoBranchesWithRepo

func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, doerID int64) (int64, error)

func SyncRepoTags

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

SyncRepoTags synchronizes releases table with repository tags

func ToAPIPayloadCommit

func ToAPIPayloadCommit(ctx context.Context, emailUsers map[string]*user_model.User, repo *repo_model.Repository, commit *PushCommit) (*api.PayloadCommit, error)

ToAPIPayloadCommit converts a single PushCommit to an api.PayloadCommit object.

func UpdateRepoSize

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

UpdateRepoSize updates the repository size, calculating it using getDirectorySize

func WikiRemoteURL

func WikiRemoteURL(ctx context.Context, remote string) string

WikiRemoteURL returns accessible repository URL for wiki if exists. Otherwise, it returns an empty string.

Types

type LicenseValues

type LicenseValues struct {
	Owner string
	Email string
	Repo  string
	Year  string
}

type OptionFile

type OptionFile struct {
	DisplayName string
	Description string
}

type PushCommit

type PushCommit struct {
	Sha1           string
	Message        string
	AuthorEmail    string
	AuthorName     string
	CommitterEmail string
	CommitterName  string
	Timestamp      time.Time
}

PushCommit represents a commit in a push operation.

func CommitToPushCommit

func CommitToPushCommit(commit *git.Commit) *PushCommit

CommitToPushCommit transforms a git.Commit to PushCommit type.

type PushCommits

type PushCommits struct {
	Commits    []*PushCommit
	HeadCommit *PushCommit
	CompareURL string
	Len        int
}

PushCommits represents list of commits in a push operation.

func GitToPushCommits

func GitToPushCommits(gitCommits []*git.Commit) *PushCommits

GitToPushCommits transforms a list of git.Commits to PushCommits type.

func NewPushCommits

func NewPushCommits() *PushCommits

NewPushCommits creates a new PushCommits object.

func (pc *PushCommits) AvatarLink(ctx context.Context, email string) string

AvatarLink tries to match user in database with e-mail in order to show custom avatar, and falls back to general avatar link.

func (*PushCommits) ToAPIPayloadCommits

func (pc *PushCommits) ToAPIPayloadCommits(ctx context.Context, repo *repo_model.Repository) ([]*api.PayloadCommit, *api.PayloadCommit, error)

ToAPIPayloadCommits converts a PushCommits object to api.PayloadCommit format. It returns all converted commits and, if provided, the head commit or an error otherwise.

type PushTrigger

type PushTrigger string
const (
	PushTriggerPRMergeToBase    PushTrigger = "pr-merge-to-base"
	PushTriggerPRUpdateWithBase PushTrigger = "pr-update-with-base"
)

type PushUpdateOptions

type PushUpdateOptions struct {
	PusherID     int64
	PusherName   string
	RepoUserName string
	RepoName     string
	RefFullName  git.RefName // branch, tag or other name to push
	OldCommitID  string
	NewCommitID  string
}

PushUpdateOptions defines the push update options

func (*PushUpdateOptions) IsDelBranch

func (opts *PushUpdateOptions) IsDelBranch() bool

IsDelBranch return true if it's a deletion to a branch

func (*PushUpdateOptions) IsDelRef

func (opts *PushUpdateOptions) IsDelRef() bool

IsDelRef return true if it's a deletion to a branch or tag

func (*PushUpdateOptions) IsDelTag

func (opts *PushUpdateOptions) IsDelTag() bool

IsDelTag return true if it's a deletion to a tag

func (*PushUpdateOptions) IsNewBranch

func (opts *PushUpdateOptions) IsNewBranch() bool

IsNewBranch return true if it's the first-time push to a branch

func (*PushUpdateOptions) IsNewRef

func (opts *PushUpdateOptions) IsNewRef() bool

IsNewRef return true if it's a first-time push to a branch, tag or etc.

func (*PushUpdateOptions) IsNewTag

func (opts *PushUpdateOptions) IsNewTag() bool

IsNewTag return true if it's a creation to a tag

func (*PushUpdateOptions) IsUpdateBranch

func (opts *PushUpdateOptions) IsUpdateBranch() bool

IsUpdateBranch return true if it's not the first push to a branch

func (*PushUpdateOptions) IsUpdateRef

func (opts *PushUpdateOptions) IsUpdateRef() bool

IsUpdateRef return true if it's an update operation

func (*PushUpdateOptions) RefName

func (opts *PushUpdateOptions) RefName() string

RefName returns simple name for ref

func (*PushUpdateOptions) RepoFullName

func (opts *PushUpdateOptions) RepoFullName() string

RepoFullName returns repo full name

Source Files

  • branch.go
  • commits.go
  • create.go
  • delete.go
  • env.go
  • fork.go
  • init.go
  • license.go
  • push.go
  • repo.go
  • temp.go

Jump to

Keyboard shortcuts

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