repo

package
v0.0.0-...-495e01f Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SizeDetailNameGit = "git"
	SizeDetailNameLFS = "lfs"
)

text representations to be returned in SizeDetail.Name

Variables

This section is empty.

Functions

func ComposeHTTPSCloneURL

func ComposeHTTPSCloneURL(owner, repo string) string

ComposeHTTPSCloneURL returns HTTPS clone URL based on given owner and repository name.

func ComposeSSHCloneURL

func ComposeSSHCloneURL(ownerName, repoName string) string

func CountNullArchivedRepository

func CountNullArchivedRepository(ctx context.Context) (int64, error)

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

func FixNullArchivedRepository(ctx context.Context) (int64, error)

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

func IsErrRepoNotExist(err error) bool

IsErrRepoNotExist checks if an error is a ErrRepoNotExist.

func IsErrUserDoesNotHaveAccessToRepo

func IsErrUserDoesNotHaveAccessToRepo(err error) bool

IsErrUserDoesNotHaveAccessToRepo checks if an error is a ErrRepoFileAlreadyExists.

func IsRepositoryModelExist

func IsRepositoryModelExist(ctx context.Context, u *user_model.User, repoName string) (bool, error)

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

func IsUsableRepoName(name string) error

IsUsableRepoName returns true when repository is usable

func RepoPath

func RepoPath(userName, repoName string) string

RepoPath returns repository path by given user and repository name.

func UpdateRepoIssueNumbers

func UpdateRepoIssueNumbers(ctx context.Context, repoID int64, isPull, isClosed bool) error

UpdateRepoIssueNumbers updates one of a repositories amount of (open|closed) (issues|PRs) with the current count

func UpdateRepositoryOwnerName

func UpdateRepositoryOwnerName(ctx context.Context, oldUserName, newUserName string) error

UpdateRepositoryOwnerName updates the owner name of all repositories owned by the user

Types

type CloneLink struct {
	SSH   string
	HTTPS string
}

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

type ErrRepoNotExist struct {
	ID        int64
	UID       int64
	OwnerName string
	Name      string
}

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

type ErrUserDoesNotHaveAccessToRepo struct {
	UserID   int64
	RepoName string
}

ErrUserDoesNotHaveAccessToRepo represents an error where the user doesn't has access to a given repo.

func (ErrUserDoesNotHaveAccessToRepo) Error

func (ErrUserDoesNotHaveAccessToRepo) Unwrap

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 (repo *Repository) CloneLink() (cl *CloneLink)

CloneLink returns clone URLs of repository.

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 (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 SizeDetail struct {
	Name string
	Size int64
}

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

Jump to

Keyboard shortcuts

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