unit

package
v1.21.11 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 7 Imported by: 29

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllRepoUnitTypes contains all the unit types
	AllRepoUnitTypes = []Type{
		TypeCode,
		TypeIssues,
		TypePullRequests,
		TypeReleases,
		TypeWiki,
		TypeExternalWiki,
		TypeExternalTracker,
		TypeProjects,
		TypePackages,
		TypeActions,
	}

	// DefaultRepoUnits contains the default unit types
	DefaultRepoUnits = []Type{
		TypeCode,
		TypeIssues,
		TypePullRequests,
		TypeReleases,
		TypeWiki,
		TypeProjects,
		TypePackages,
	}

	// ForkRepoUnits contains the default unit types for forks
	DefaultForkRepoUnits = []Type{
		TypeCode,
		TypePullRequests,
	}

	// NotAllowedDefaultRepoUnits contains units that can't be default
	NotAllowedDefaultRepoUnits = []Type{
		TypeExternalWiki,
		TypeExternalTracker,
	}

	// DisabledRepoUnits contains the units that have been globally disabled
	DisabledRepoUnits = []Type{}
)
View Source
var (
	UnitCode = Unit{
		TypeCode,
		"repo.code",
		"/",
		"repo.code.desc",
		0,
		perm.AccessModeOwner,
	}

	UnitIssues = Unit{
		TypeIssues,
		"repo.issues",
		"/issues",
		"repo.issues.desc",
		1,
		perm.AccessModeOwner,
	}

	UnitExternalTracker = Unit{
		TypeExternalTracker,
		"repo.ext_issues",
		"/issues",
		"repo.ext_issues.desc",
		1,
		perm.AccessModeRead,
	}

	UnitPullRequests = Unit{
		TypePullRequests,
		"repo.pulls",
		"/pulls",
		"repo.pulls.desc",
		2,
		perm.AccessModeOwner,
	}

	UnitReleases = Unit{
		TypeReleases,
		"repo.releases",
		"/releases",
		"repo.releases.desc",
		3,
		perm.AccessModeOwner,
	}

	UnitWiki = Unit{
		TypeWiki,
		"repo.wiki",
		"/wiki",
		"repo.wiki.desc",
		4,
		perm.AccessModeOwner,
	}

	UnitExternalWiki = Unit{
		TypeExternalWiki,
		"repo.ext_wiki",
		"/wiki",
		"repo.ext_wiki.desc",
		4,
		perm.AccessModeRead,
	}

	UnitProjects = Unit{
		TypeProjects,
		"repo.projects",
		"/projects",
		"repo.projects.desc",
		5,
		perm.AccessModeOwner,
	}

	UnitPackages = Unit{
		TypePackages,
		"repo.packages",
		"/packages",
		"packages.desc",
		6,
		perm.AccessModeRead,
	}

	UnitActions = Unit{
		TypeActions,
		"repo.actions",
		"/actions",
		"actions.unit.desc",
		7,
		perm.AccessModeOwner,
	}

	// Units contains all the units
	Units = map[Type]Unit{
		TypeCode:            UnitCode,
		TypeIssues:          UnitIssues,
		TypeExternalTracker: UnitExternalTracker,
		TypePullRequests:    UnitPullRequests,
		TypeReleases:        UnitReleases,
		TypeWiki:            UnitWiki,
		TypeExternalWiki:    UnitExternalWiki,
		TypeProjects:        UnitProjects,
		TypePackages:        UnitPackages,
		TypeActions:         UnitActions,
	}
)

Enumerate all the units

Functions

func AllUnitKeyNames

func AllUnitKeyNames() []string

AllUnitKeyNames returns all unit key names

func LoadUnitConfig

func LoadUnitConfig() error

LoadUnitConfig load units from settings

func MinUnitAccessMode

func MinUnitAccessMode(unitsMap map[Type]perm.AccessMode) perm.AccessMode

MinUnitAccessMode returns the minial permission of the permission map

Types

type Type

type Type int

Type is Unit's Type

const (
	TypeInvalid         Type = iota // 0 invalid
	TypeCode                        // 1 code
	TypeIssues                      // 2 issues
	TypePullRequests                // 3 PRs
	TypeReleases                    // 4 Releases
	TypeWiki                        // 5 Wiki
	TypeExternalWiki                // 6 ExternalWiki
	TypeExternalTracker             // 7 ExternalTracker
	TypeProjects                    // 8 Kanban board
	TypePackages                    // 9 Packages
	TypeActions                     // 10 Actions
)

Enumerate all the unit types

func FindUnitTypes

func FindUnitTypes(nameKeys ...string) (res []Type, invalidKeys []string)

FindUnitTypes give the unit key names and return valid unique units and invalid keys

func TypeFromKey

func TypeFromKey(nameKey string) Type

TypeFromKey give the unit key name and return unit

func (*Type) CanBeDefault

func (u *Type) CanBeDefault() bool

CanBeDefault checks if the unit type can be a default repo unit

func (Type) LogString added in v1.20.0

func (u Type) LogString() string

func (Type) String

func (u Type) String() string

func (Type) UnitGlobalDisabled

func (u Type) UnitGlobalDisabled() bool

UnitGlobalDisabled checks if unit type is global disabled

func (Type) Value

func (u Type) Value() int

Value returns integer value for unit type

type Unit

type Unit struct {
	Type          Type
	NameKey       string
	URI           string
	DescKey       string
	Idx           int
	MaxAccessMode perm.AccessMode // The max access mode of the unit. i.e. Read means this unit can only be read.
}

Unit is a section of one repository

func (Unit) IsLessThan

func (u Unit) IsLessThan(unit Unit) bool

IsLessThan compares order of two units

func (Unit) MaxPerm

func (u Unit) MaxPerm() perm.AccessMode

MaxPerm returns the max perms of this unit

Jump to

Keyboard shortcuts

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