unit

package
v1.18.0-dev Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2022 License: MIT Imports: 5 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,
	}

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

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

	// MustRepoUnits contains the units could not be disabled currently
	MustRepoUnits = []Type{
		TypeCode,
		TypeReleases,
	}

	// 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,
	}

	// 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,
	}
)

Enumerate all the units

Functions

func AllUnitKeyNames

func AllUnitKeyNames() []string

AllUnitKeyNames returns all unit key names

func LoadUnitConfig

func LoadUnitConfig()

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
)

Enumerate all the unit types

func FindUnitTypes

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

FindUnitTypes give the unit key names and return unit

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) CanDisable

func (u *Type) CanDisable() bool

CanDisable checks if this unit type can be disabled.

func (Type) ColorFormat

func (u Type) ColorFormat(s fmt.State)

ColorFormat provides a ColorFormatted version of this Type

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) CanDisable

func (u *Unit) CanDisable() bool

CanDisable returns if this unit could be disabled.

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