models

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2014 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AU_READABLE = iota + 1
	AU_WRITABLE
)

Access types.

View Source
const (
	OP_CREATE_REPO = iota + 1
	OP_DELETE_REPO
	OP_STAR_REPO
	OP_FOLLOW_REPO
	OP_COMMIT_REPO
	OP_CREATE_ISSUE
	OP_PULL_REQUEST
)

Operation types of user action.

View Source
const (
	DIFF_LINE_PLAIN = iota + 1
	DIFF_LINE_ADD
	DIFF_LINE_DEL
	DIFF_LINE_SECTION
)

Diff line types.

View Source
const (
	DIFF_FILE_ADD = iota + 1
	DIFF_FILE_CHANGE
	DIFF_FILE_DEL
)
View Source
const (
	IT_PLAIN  = iota // Pure comment.
	IT_REOPEN        // Issue reopen status change prompt.
	IT_CLOSE         // Issue close status change prompt.
)

Issue types.

View Source
const (
	UT_INDIVIDUAL = iota + 1
	UT_ORGANIZATION
)

User types.

View Source
const (
	LT_PLAIN = iota + 1
	LT_LDAP
)

Login types.

View Source
const DIFF_HEAD = "diff --git "
View Source
const (
	// "### autogenerated by gitgos, DO NOT EDIT\n"
	TPL_PUBLICK_KEY = `command="%s serv key-%d",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s`
)

Variables

View Source
var (
	HasEngine bool

	DbCfg struct {
		Type, Host, Name, User, Pwd, Path, SslMode string
	}

	UseSQLite3 bool
)
View Source
var (
	ErrRepoAlreadyExist  = errors.New("Repository already exist")
	ErrRepoNotExist      = errors.New("Repository does not exist")
	ErrRepoFileNotExist  = errors.New("Target Repo file does not exist")
	ErrRepoNameIllegal   = errors.New("Repository name contains illegal characters")
	ErrRepoFileNotLoaded = fmt.Errorf("repo file not loaded")
)
View Source
var (
	ErrUserOwnRepos     = errors.New("User still have ownership of repositories")
	ErrUserAlreadyExist = errors.New("User already exist")
	ErrUserNotExist     = errors.New("User does not exist")
	ErrEmailAlreadyUsed = errors.New("E-mail already used")
	ErrUserNameIllegal  = errors.New("User name contains illegal characters")
	ErrKeyNotExist      = errors.New("Public key does not exist")
)
View Source
var (
	ErrIssueNotExist = errors.New("Issue does not exist")
)
View Source
var (
	ErrKeyAlreadyExist = errors.New("Public key already exist")
)
View Source
var (
	LanguageIgns, Licenses []string
)

Functions

func AddAccess

func AddAccess(access *Access) error

AddAccess adds new access record.

func AddPublicKey

func AddPublicKey(key *PublicKey) (err error)

AddPublicKey adds new public key to database and SSH key file.

func CommitRepoAction

func CommitRepoAction(userId int64, userName, actEmail string,
	repoId int64, repoName string, refName string, commit *base.PushCommits) error

CommitRepoAction adds new action for committing repository.

func CreateComment

func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, content string) error

CreateComment creates comment of issue or commit.

func DeletePublicKey

func DeletePublicKey(key *PublicKey) (err error)

DeletePublicKey deletes SSH key information both in database and authorized_keys file.

func DeleteRepository

func DeleteRepository(userId, repoId int64, userName string) (err error)

DeleteRepository deletes a repository for a user or orgnaztion.

func DeleteUser

func DeleteUser(user *User) error

DeleteUser completely deletes everything of the user.

func FollowUser

func FollowUser(userId int64, followId int64) (err error)

FollowUser marks someone be another's follower.

func ForkRepository

func ForkRepository(reposName string, userId int64)

func GenAuthorizedKey

func GenAuthorizedKey(keyId int64, key string) string

GenAuthorizedKey returns formatted public key string.

func GetBranches

func GetBranches(userName, repoName string) ([]string, error)

GetBranches returns all branches of given repository.

func GetCommit

func GetCommit(userName, repoName, commitId string) (*git.Commit, error)

func GetCommitsByBranch

func GetCommitsByBranch(userName, repoName, branchName string) (*list.List, error)

GetCommitsByBranch returns all commits of given branch of repository.

func GetCommitsByCommitId

func GetCommitsByCommitId(userName, repoName, commitId string) (*list.List, error)

GetCommitsByCommitId returns all commits of given commitId of repository.

func GetRepositoryCount

func GetRepositoryCount(user *User) (int64, error)

func GetUserIssueCount

func GetUserIssueCount(userId, repoId int64) int64

GetUserIssueCount returns the number of issues that were created by given user in repository.

func GetUserSalt

func GetUserSalt() string

return a user salt token

func HasAccess

func HasAccess(userName, repoName string, mode int) (bool, error)

HasAccess returns true if someone can read or write to given repository.

func IsBranchExist

func IsBranchExist(userName, repoName, branchName string) bool

func IsEmailUsed

func IsEmailUsed(email string) (bool, error)

IsEmailUsed returns true if the e-mail has been used.

func IsLegalName

func IsLegalName(repoName string) bool

IsLegalName returns false if name contains illegal characters.

func IsRepositoryExist

func IsRepositoryExist(user *User, repoName string) (bool, error)

IsRepositoryExist returns true if the repository with given name under user has already existed.

func IsUserExist

func IsUserExist(name string) (bool, error)

IsUserExist checks if given user name exist, the user name should be noncased unique.

func IsWatching

func IsWatching(userId, repoId int64) bool

IsWatching checks if user has watched given repository.

func LoadModelsConfig

func LoadModelsConfig()

func LoadRepoConfig

func LoadRepoConfig()

func NewEngine

func NewEngine() (err error)

func NewRepoAction

func NewRepoAction(user *User, repo *Repository) (err error)

NewRepoAction adds new action for creating repository.

func NewRepoContext

func NewRepoContext()

func NewTestEngine

func NewTestEngine(x *xorm.Engine) (err error)

func NotifyWatchers

func NotifyWatchers(act *Action) error

NotifyWatchers creates batch of actions for every watcher.

func RepoPath

func RepoPath(userName, repoName string) string

func SaveAuthorizedKeyFile

func SaveAuthorizedKeyFile(key *PublicKey) error

SaveAuthorizedKeyFile writes SSH key content to SSH key file.

func SetEngine

func SetEngine() (err error)

func UnFollowUser

func UnFollowUser(userId int64, unFollowId int64) (err error)

UnFollowUser unmarks someone be another's follower.

func UpdateIssue

func UpdateIssue(issue *Issue) error

UpdateIssue updates information of issue.

func UpdateRepository

func UpdateRepository(repo *Repository) error

func UpdateUser

func UpdateUser(user *User) (err error)

UpdateUser updates user's information.

func UserPath

func UserPath(userName string) string

UserPath returns the path absolute path of user repositories.

func WatchRepo

func WatchRepo(userId, repoId int64, watch bool) (err error)

Watch or unwatch repository.

Types

type Access

type Access struct {
	Id       int64
	UserName string    `xorm:"unique(s)"`
	RepoName string    `xorm:"unique(s)"`
	Mode     int       `xorm:"unique(s)"`
	Created  time.Time `xorm:"created"`
}

Access represents the accessibility of user to repository.

type Action

type Action struct {
	Id          int64
	UserId      int64  // Receiver user id.
	OpType      int    // Operations: CREATE DELETE STAR ...
	ActUserId   int64  // Action user id.
	ActUserName string // Action user name.
	ActEmail    string
	RepoId      int64
	RepoName    string
	RefName     string
	Content     string    `xorm:"TEXT"`
	Created     time.Time `xorm:"created"`
}

Action represents user operation type and other information to repository., it implemented interface base.Actioner so that can be used in template render.

func GetFeeds

func GetFeeds(userid, offset int64, isProfile bool) ([]Action, error)

GetFeeds returns action list of given user in given context.

func (Action) GetActEmail

func (a Action) GetActEmail() string

func (Action) GetActUserName

func (a Action) GetActUserName() string

func (Action) GetBranch

func (a Action) GetBranch() string

func (Action) GetContent

func (a Action) GetContent() string

func (Action) GetOpType

func (a Action) GetOpType() int

func (Action) GetRepoName

func (a Action) GetRepoName() string

type Comment

type Comment struct {
	Id       int64
	Type     int
	PosterId int64
	Poster   *User `xorm:"-"`
	IssueId  int64
	CommitId int64
	Line     int64
	Content  string
	Created  time.Time `xorm:"created"`
}

Comment represents a comment in commit and issue page.

func GetIssueComments

func GetIssueComments(issueId int64) ([]Comment, error)

GetIssueComments returns list of comment by given issue id.

type Diff

type Diff struct {
	TotalAddition, TotalDeletion int
	Files                        []*DiffFile
}

func GetDiff

func GetDiff(repoPath, commitid string) (*Diff, error)

func ParsePatch

func ParsePatch(reader io.Reader) (*Diff, error)

func (*Diff) NumFiles

func (diff *Diff) NumFiles() int

type DiffFile

type DiffFile struct {
	Name               string
	Addition, Deletion int
	Type               int
	Sections           []*DiffSection
}

type DiffLine

type DiffLine struct {
	LeftIdx  int
	RightIdx int
	Type     int
	Content  string
}

func (DiffLine) GetType

func (d DiffLine) GetType() int

type DiffSection

type DiffSection struct {
	Name  string
	Lines []*DiffLine
}

type Follow

type Follow struct {
	Id       int64
	UserId   int64 `xorm:"unique(follow)"`
	FollowId int64 `xorm:"unique(follow)"`
}

Follow is connection request for receiving user notifycation.

type Issue

type Issue struct {
	Id              int64
	Index           int64 // Index in one repository.
	Name            string
	RepoId          int64       `xorm:"index"`
	Repo            *Repository `xorm:"-"`
	PosterId        int64
	Poster          *User `xorm:"-"`
	MilestoneId     int64
	AssigneeId      int64
	IsPull          bool // Indicates whether is a pull request or not.
	IsClosed        bool
	Labels          string `xorm:"TEXT"`
	Mentions        string `xorm:"TEXT"`
	Content         string `xorm:"TEXT"`
	RenderedContent string `xorm:"-"`
	NumComments     int
	Created         time.Time `xorm:"created"`
	Updated         time.Time `xorm:"updated"`
}

Issue represents an issue or pull request of repository.

func CreateIssue

func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int, name, labels, content string, isPull bool) (issue *Issue, err error)

CreateIssue creates new issue for repository.

func GetIssueByIndex

func GetIssueByIndex(repoId, index int64) (*Issue, error)

GetIssueById returns issue object by given id.

func GetIssues

func GetIssues(userId, repoId, posterId, milestoneId int64, page int, isClosed, isMention bool, labels, sortType string) ([]Issue, error)

GetIssues returns a list of issues by given conditions.

type Label

type Label struct {
	Id     int64
	RepoId int64 `xorm:"index"`
	Names  string
	Colors string
}

Label represents a list of labels of repository for issues.

type Member

type Member struct {
	Id     int64
	OrgId  int64 `xorm:"unique(member) index"`
	UserId int64 `xorm:"unique(member)"`
}

Member represents user is member of organization.

type Milestone

type Milestone struct {
	Id        int64
	Name      string
	RepoId    int64 `xorm:"index"`
	IsClosed  bool
	Content   string
	NumIssues int
	DueDate   time.Time
	Created   time.Time `xorm:"created"`
}

Milestone represents a milestone of repository.

type PublicKey

type PublicKey struct {
	Id          int64
	OwnerId     int64  `xorm:"index"`
	Name        string `xorm:"unique not null"`
	Fingerprint string
	Content     string    `xorm:"TEXT not null"`
	Created     time.Time `xorm:"created"`
	Updated     time.Time `xorm:"updated"`
}

PublicKey represents a SSH key of user.

func ListPublicKey

func ListPublicKey(userId int64) ([]PublicKey, error)

ListPublicKey returns a list of public keys that user has.

type RepoFile

type RepoFile struct {
	*git.TreeEntry
	Path   string
	Size   int64
	Repo   *git.Repository
	Commit *git.Commit
}

RepoFile represents a file object in git repository.

func GetReposFiles

func GetReposFiles(userName, repoName, commitId, rpath string) ([]*RepoFile, error)

GetReposFiles returns a list of file object in given directory of repository.

func GetTargetFile

func GetTargetFile(userName, repoName, branchName, commitId, rpath string) (*RepoFile, error)

func (*RepoFile) LookupBlob

func (file *RepoFile) LookupBlob() (*git.Blob, error)

LookupBlob returns the content of an object.

type Repository

type Repository struct {
	Id              int64
	OwnerId         int64 `xorm:"unique(s)"`
	ForkId          int64
	LowerName       string `xorm:"unique(s) index not null"`
	Name            string `xorm:"index not null"`
	Description     string
	Website         string
	NumWatches      int
	NumStars        int
	NumForks        int
	NumIssues       int
	NumClosedIssues int
	NumOpenIssues   int `xorm:"-"`
	IsPrivate       bool
	IsBare          bool
	Created         time.Time `xorm:"created"`
	Updated         time.Time `xorm:"updated"`
}

Repository represents a git repository.

func CreateRepository

func CreateRepository(user *User, repoName, desc, repoLang, license string, private bool, initReadme bool) (*Repository, error)

CreateRepository creates a repository for given user or orgnaziation.

func GetRepositories

func GetRepositories(user *User) ([]Repository, error)

GetRepositories returns the list of repositories of given user.

func GetRepositoryById

func GetRepositoryById(id int64) (*Repository, error)

GetRepositoryById returns the repository by given id if exists.

func GetRepositoryByName

func GetRepositoryByName(userId int64, repoName string) (*Repository, error)

GetRepositoryByName returns the repository by given name under user if exists.

type Statistic

type Statistic struct {
	Counter struct {
		User, PublicKey, Repo, Watch, Action, Access int64
	}
}

func GetStatistic

func GetStatistic() (stats Statistic)

type User

type User struct {
	Id            int64
	LowerName     string `xorm:"unique not null"`
	Name          string `xorm:"unique not null"`
	Email         string `xorm:"unique not null"`
	Passwd        string `xorm:"not null"`
	LoginType     int
	Type          int
	NumFollowers  int
	NumFollowings int
	NumStars      int
	NumRepos      int
	Avatar        string `xorm:"varchar(2048) not null"`
	AvatarEmail   string `xorm:"not null"`
	Location      string
	Website       string
	IsActive      bool
	IsAdmin       bool
	Rands         string    `xorm:"VARCHAR(10)"`
	Created       time.Time `xorm:"created"`
	Updated       time.Time `xorm:"updated"`
}

User represents the object of individual and member of organization.

func GetUserById

func GetUserById(id int64) (*User, error)

GetUserById returns the user object by given id if exists.

func GetUserByKeyId

func GetUserByKeyId(keyId int64) (*User, error)

func GetUserByName

func GetUserByName(name string) (*User, error)

GetUserByName returns the user object by given name if exists.

func GetUsers

func GetUsers(num, offset int) ([]User, error)

GetUsers returns given number of user objects with offset.

func LoginUserPlain

func LoginUserPlain(name, passwd string) (*User, error)

LoginUserPlain validates user by raw user name and password.

func RegisterUser

func RegisterUser(user *User) (*User, error)

RegisterUser creates record of a new user.

func VerifyUserActiveCode

func VerifyUserActiveCode(code string) (user *User)

verify active code when active account

func (user *User) AvatarLink() string

AvatarLink returns the user gravatar link.

func (*User) EncodePasswd

func (user *User) EncodePasswd() error

EncodePasswd encodes password to safe format.

func (user *User) HomeLink() string

HomeLink returns the user home page link.

func (*User) NewGitSig

func (user *User) NewGitSig() *git.Signature

NewGitSig generates and returns the signature of given user.

type UserRepo

type UserRepo struct {
	*Repository
	UserName string
}

UserRepo reporesents a repository with user name.

func GetRepos

func GetRepos(num, offset int) ([]UserRepo, error)

GetRepos returns given number of repository objects with offset.

type Watch

type Watch struct {
	Id     int64
	RepoId int64 `xorm:"UNIQUE(watch)"`
	UserId int64 `xorm:"UNIQUE(watch)"`
}

Watch is connection request for receiving repository notifycation.

func GetWatches

func GetWatches(repoId int64) ([]Watch, error)

GetWatches returns all watches of given repository.

Jump to

Keyboard shortcuts

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