Sfoglia il codice sorgente

Fix Go Report Card Issues in models #100

Yoginth 7 anni fa
parent
commit
89eb42a409

+ 11 - 5
models/access.go

@@ -14,14 +14,20 @@ import (
 	log "gopkg.in/clog.v1"
 )
 
+// AccessMode specifies the users access mode
 type AccessMode int
 
 const (
-	AccessModeNone  AccessMode = iota // 0
-	AccessModeRead                    // 1
-	AccessModeWrite                   // 2
-	AccessModeAdmin                   // 3
-	AccessModeOwner                   // 4
+	// AccessModeNone no access
+	AccessModeNone AccessMode = iota // 0
+	// AccessModeRead read access
+	AccessModeRead // 1
+	// AccessModeWrite write access
+	AccessModeWrite // 2
+	// AccessModeAdmin admin access
+	AccessModeAdmin // 3
+	// AccessModeOwner owner access
+	AccessModeOwner // 4
 )
 
 func (mode AccessMode) String() string {

+ 53 - 18
models/action.go

@@ -26,9 +26,10 @@ import (
 	log "gopkg.in/clog.v1"
 )
 
+// ActionType represents the type of an action.
 type ActionType int
 
-// Note: To maintain backward compatibility only append to the end of list
+// Possible action types.
 const (
 	ActionCreateRepo        ActionType = iota + 1 // 1
 	ActionRenameRepo                              // 2
@@ -55,12 +56,16 @@ const (
 )
 
 var (
-	// Same as Github. See https://help.github.com/articles/closing-issues-via-commit-messages
-	IssueCloseKeywords  = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"}
+	// IssueCloseKeywords Same as Github.
+	// See https://help.github.com/articles/closing-issues-via-commit-messages
+	IssueCloseKeywords = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"}
+	// IssueReopenKeywords Same as Github.
 	IssueReopenKeywords = []string{"reopen", "reopens", "reopened"}
-
-	IssueCloseKeywordsPat     = regexp.MustCompile(assembleKeywordsPattern(IssueCloseKeywords))
-	IssueReopenKeywordsPat    = regexp.MustCompile(assembleKeywordsPattern(IssueReopenKeywords))
+	// IssueCloseKeywordsPat close keyword pattern
+	IssueCloseKeywordsPat = regexp.MustCompile(assembleKeywordsPattern(IssueCloseKeywords))
+	// IssueReopenKeywordsPat reopen keyword pattern
+	IssueReopenKeywordsPat = regexp.MustCompile(assembleKeywordsPattern(IssueReopenKeywords))
+	// IssueReferenceKeywordsPat reference keyword pattern
 	IssueReferenceKeywordsPat = regexp.MustCompile(`(?i)(?:)(^| )\S+`)
 )
 
@@ -87,10 +92,12 @@ type Action struct {
 	CreatedUnix  int64
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (a *Action) BeforeInsert() {
 	a.CreatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (a *Action) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":
@@ -98,42 +105,56 @@ func (a *Action) AfterSet(colName string, _ xorm.Cell) {
 	}
 }
 
+// GetOpType gets the ActionType of this action.
 func (a *Action) GetOpType() int {
 	return int(a.OpType)
 }
 
+// GetActUserName gets the action's user name.
 func (a *Action) GetActUserName() string {
 	return a.ActUserName
 }
 
+// ShortActUserName gets the action's user name trimmed to max 20
+// chars.
 func (a *Action) ShortActUserName() string {
 	return tool.EllipsisString(a.ActUserName, 20)
 }
 
+// GetRepoUserName returns the name of the action repository owner.
 func (a *Action) GetRepoUserName() string {
 	return a.RepoUserName
 }
 
+// ShortRepoUserName returns the name of the action repository owner
+// trimmed to max 20 chars.
 func (a *Action) ShortRepoUserName() string {
 	return tool.EllipsisString(a.RepoUserName, 20)
 }
 
+// GetRepoName returns the name of the action repository.
 func (a *Action) GetRepoName() string {
 	return a.RepoName
 }
 
+// ShortRepoName returns the name of the action repository
+// trimmed to max 33 chars.
 func (a *Action) ShortRepoName() string {
 	return tool.EllipsisString(a.RepoName, 33)
 }
 
+// GetRepoPath returns the virtual path to the action repository.
 func (a *Action) GetRepoPath() string {
 	return path.Join(a.RepoUserName, a.RepoName)
 }
 
+// ShortRepoPath returns the virtual path to the action repository
+// trimmed to max 20 + 1 + 33 chars.
 func (a *Action) ShortRepoPath() string {
 	return path.Join(a.ShortRepoUserName(), a.ShortRepoName())
 }
 
+// GetRepoLink returns relative link to action repository.
 func (a *Action) GetRepoLink() string {
 	if len(setting.AppSubURL) > 0 {
 		return path.Join(setting.AppSubURL, a.GetRepoPath())
@@ -141,22 +162,29 @@ func (a *Action) GetRepoLink() string {
 	return "/" + a.GetRepoPath()
 }
 
+// GetBranch returns the action's repository branch.
 func (a *Action) GetBranch() string {
 	return a.RefName
 }
 
+// GetContent returns the action's content.
 func (a *Action) GetContent() string {
 	return a.Content
 }
 
+// GetCreate returns the action creation time.
 func (a *Action) GetCreate() time.Time {
 	return a.Created
 }
 
+// GetIssueInfos returns a list of issues associated with
+// the action.
 func (a *Action) GetIssueInfos() []string {
 	return strings.SplitN(a.Content, "|", 2)
 }
 
+// GetIssueTitle returns the title of first issue associated
+// with the action.
 func (a *Action) GetIssueTitle() string {
 	index := com.StrTo(a.GetIssueInfos()[0]).MustInt64()
 	issue, err := GetIssueByIndex(a.RepoID, index)
@@ -168,6 +196,8 @@ func (a *Action) GetIssueTitle() string {
 	return issue.Title
 }
 
+// GetIssueContent returns the content of first issue associated with
+// this action.
 func (a *Action) GetIssueContent() string {
 	index := com.StrTo(a.GetIssueInfos()[0]).MustInt64()
 	issue, err := GetIssueByIndex(a.RepoID, index)
@@ -228,6 +258,7 @@ func issueIndexTrimRight(c rune) bool {
 	return !unicode.IsDigit(c)
 }
 
+// PushCommit represents a commit in a push operation.
 type PushCommit struct {
 	Sha1           string
 	Message        string
@@ -238,12 +269,12 @@ type PushCommit struct {
 	Timestamp      time.Time
 }
 
+// PushCommits represents list of commits in a push operation.
 type PushCommits struct {
 	Len        int
 	Commits    []*PushCommit
 	CompareURL string
-
-	avatars map[string]string
+	avatars    map[string]string
 }
 
 // NewPushCommits returns new push commits
@@ -253,7 +284,9 @@ func NewPushCommits() *PushCommits {
 	}
 }
 
-func (pc *PushCommits) ToApiPayloadCommits(repoPath, repoURL string) ([]*api.PayloadCommit, error) {
+// ToAPIPayloadCommits converts a PushCommits object to
+// api.PayloadCommit format.
+func (pc *PushCommits) ToAPIPayloadCommits(repoPath, repoURL string) ([]*api.PayloadCommit, error) {
 	commits := make([]*api.PayloadCommit, len(pc.Commits))
 	for i, commit := range pc.Commits {
 		authorUsername := ""
@@ -302,22 +335,22 @@ func (pc *PushCommits) ToApiPayloadCommits(repoPath, repoURL string) ([]*api.Pay
 
 // AvatarLink tries to match user in database with e-mail
 // in order to show custom avatar, and falls back to general avatar link.
-func (push *PushCommits) AvatarLink(email string) string {
-	_, ok := push.avatars[email]
+func (pc *PushCommits) AvatarLink(email string) string {
+	_, ok := pc.avatars[email]
 	if !ok {
 		u, err := GetUserByEmail(email)
 		if err != nil {
-			push.avatars[email] = tool.AvatarLink(email)
+			pc.avatars[email] = tool.AvatarLink(email)
 			if !errors.IsUserNotExist(err) {
 				raven.CaptureErrorAndWait(err, nil)
 				log.Error(4, "GetUserByEmail: %v", err)
 			}
 		} else {
-			push.avatars[email] = u.RelAvatarLink()
+			pc.avatars[email] = u.RelAvatarLink()
 		}
 	}
 
-	return push.avatars[email]
+	return pc.avatars[email]
 }
 
 // UpdateIssuesCommit checks if issues are manipulated by commit message.
@@ -451,6 +484,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
 	return nil
 }
 
+// CommitRepoActionOptions represent options of a new commit action.
 type CommitRepoActionOptions struct {
 	PusherName  string
 	RepoOwnerID int64
@@ -564,9 +598,9 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
 			}
 		}
 
-		commits, err := opts.Commits.ToApiPayloadCommits(repo.RepoPath(), repo.HTMLURL())
+		commits, err := opts.Commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
 		if err != nil {
-			return fmt.Errorf("ToApiPayloadCommits: %v", err)
+			return fmt.Errorf("ToAPIPayloadCommits: %v", err)
 		}
 
 		if err = PrepareWebhooks(repo, HookEventPush, &api.PushPayload{
@@ -687,6 +721,7 @@ func mirrorSyncAction(opType ActionType, repo *Repository, refName string, data
 	})
 }
 
+// MirrorSyncPushActionOptions mirror synchronization action options.
 type MirrorSyncPushActionOptions struct {
 	RefName     string
 	OldCommitID string
@@ -700,9 +735,9 @@ func MirrorSyncPushAction(repo *Repository, opts MirrorSyncPushActionOptions) er
 		opts.Commits.Commits = opts.Commits.Commits[:setting.UI.FeedMaxCommitNum]
 	}
 
-	apiCommits, err := opts.Commits.ToApiPayloadCommits(repo.RepoPath(), repo.HTMLURL())
+	apiCommits, err := opts.Commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
 	if err != nil {
-		return fmt.Errorf("ToApiPayloadCommits: %v", err)
+		return fmt.Errorf("ToAPIPayloadCommits: %v", err)
 	}
 
 	opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID)

+ 4 - 0
models/admin.go

@@ -19,9 +19,11 @@ import (
 	log "gopkg.in/clog.v1"
 )
 
+//NoticeType describes the notice type
 type NoticeType int
 
 const (
+	//NoticeRepository type
 	NoticeRepository NoticeType = iota + 1
 )
 
@@ -34,10 +36,12 @@ type Notice struct {
 	CreatedUnix int64
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (n *Notice) BeforeInsert() {
 	n.CreatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (n *Notice) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":

+ 6 - 4
models/attachment.go

@@ -32,10 +32,12 @@ type Attachment struct {
 	CreatedUnix int64
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (a *Attachment) BeforeInsert() {
 	a.CreatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (a *Attachment) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":
@@ -164,8 +166,8 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
 }
 
 // DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
-func DeleteAttachmentsByIssue(issueId int64, remove bool) (int, error) {
-	attachments, err := GetAttachmentsByIssueID(issueId)
+func DeleteAttachmentsByIssue(issueID int64, remove bool) (int, error) {
+	attachments, err := GetAttachmentsByIssueID(issueID)
 	if err != nil {
 		return 0, err
 	}
@@ -174,8 +176,8 @@ func DeleteAttachmentsByIssue(issueId int64, remove bool) (int, error) {
 }
 
 // DeleteAttachmentsByComment deletes all attachments associated with the given comment.
-func DeleteAttachmentsByComment(commentId int64, remove bool) (int, error) {
-	attachments, err := GetAttachmentsByCommentID(commentId)
+func DeleteAttachmentsByComment(commentID int64, remove bool) (int, error) {
+	attachments, err := GetAttachmentsByCommentID(commentID)
 	if err != nil {
 		return 0, err
 	}

+ 21 - 11
models/comment.go

@@ -20,15 +20,18 @@ import (
 	log "gopkg.in/clog.v1"
 )
 
-// CommentType defines whether a comment is just a simple comment, an action (like close) or a reference.
+// CommentType defines whether a comment is just a simple comment,
+// an action (like close) or a reference.
 type CommentType int
 
 const (
-	// Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
+	// CommentTypeComment Plain comment, can be associated with a commit
+	// (CommitID > 0) and a line (LineNum > 0)
 	CommentTypeComment CommentType = iota
+	// CommentTypeReopen Reopen.
 	CommentTypeReopen
+	// CommentTypeClose Closes.
 	CommentTypeClose
-
 	// CommentTypeIssueRef References.
 	CommentTypeIssueRef
 	// CommentTypeCommitRef Reference from a commit (not part of a pull request)
@@ -39,8 +42,10 @@ const (
 	CommentTypePullRef
 )
 
+// CommentTag defines comment tag type
 type CommentTag int
 
+// Enumerate all the comment tag types
 const (
 	CommentTagNone CommentTag = iota
 	CommentTagPoster
@@ -75,15 +80,18 @@ type Comment struct {
 	ShowTag CommentTag `xorm:"-" json:"-"`
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (c *Comment) BeforeInsert() {
 	c.CreatedUnix = time.Now().Unix()
 	c.UpdatedUnix = c.CreatedUnix
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (c *Comment) BeforeUpdate() {
 	c.UpdatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (c *Comment) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":
@@ -129,16 +137,17 @@ func (c *Comment) loadAttributes(e Engine) (err error) {
 	return nil
 }
 
+// LoadAttributes loads all attributes
 func (c *Comment) LoadAttributes() error {
 	return c.loadAttributes(x)
 }
 
+// HTMLURL formats a URL-string to the issue-comment
 func (c *Comment) HTMLURL() string {
 	return fmt.Sprintf("%s#issuecomment-%d", c.Issue.HTMLURL(), c.ID)
 }
 
-// This method assumes following fields have been assigned with valid values:
-// Required - Poster, Issue
+// APIFormat converts a Comment to the api.Comment format
 func (c *Comment) APIFormat() *api.Comment {
 	return &api.Comment{
 		ID:      c.ID,
@@ -167,21 +176,21 @@ func (c *Comment) EventTag() string {
 
 // mailParticipants sends new comment emails to repository watchers
 // and mentioned people.
-func (cmt *Comment) mailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
-	mentions := markup.FindAllMentions(cmt.Content)
-	if err = updateIssueMentions(e, cmt.IssueID, mentions); err != nil {
-		return fmt.Errorf("UpdateIssueMentions [%d]: %v", cmt.IssueID, err)
+func (c *Comment) mailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
+	mentions := markup.FindAllMentions(c.Content)
+	if err = updateIssueMentions(e, c.IssueID, mentions); err != nil {
+		return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
 	}
 
 	switch opType {
 	case ActionCommentIssue:
-		issue.Content = cmt.Content
+		issue.Content = c.Content
 	case ActionCloseIssue:
 		issue.Content = fmt.Sprintf("Closed #%d", issue.Index)
 	case ActionReopenIssue:
 		issue.Content = fmt.Sprintf("Reopened #%d", issue.Index)
 	}
-	if err = mailIssueCommentToParticipants(issue, cmt.Poster, mentions); err != nil {
+	if err = mailIssueCommentToParticipants(issue, c.Poster, mentions); err != nil {
 		raven.CaptureErrorAndWait(err, nil)
 		log.Error(2, "mailIssueCommentToParticipants: %v", err)
 	}
@@ -310,6 +319,7 @@ func createStatusComment(e *xorm.Session, doer *User, repo *Repository, issue *I
 	})
 }
 
+// CreateCommentOptions defines options for creating comment
 type CreateCommentOptions struct {
 	Type  CommentType
 	Doer  *User

+ 34 - 0
models/error.go

@@ -10,6 +10,7 @@ import (
 	"fmt"
 )
 
+// ErrNameReserved represents a "reserved name" error.
 type ErrNameReserved struct {
 	Name string
 }
@@ -24,6 +25,7 @@ func (err ErrNameReserved) Error() string {
 	return fmt.Sprintf("name is reserved [name: %s]", err.Name)
 }
 
+// ErrNamePatternNotAllowed represents a "pattern not allowed" error.
 type ErrNamePatternNotAllowed struct {
 	Pattern string
 }
@@ -39,6 +41,7 @@ func (err ErrNamePatternNotAllowed) Error() string {
 	return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
 }
 
+// ErrUserAlreadyExist represents a "user already exists" error.
 type ErrUserAlreadyExist struct {
 	Name string
 }
@@ -53,6 +56,7 @@ func (err ErrUserAlreadyExist) Error() string {
 	return fmt.Sprintf("user already exists [name: %s]", err.Name)
 }
 
+// ErrEmailAlreadyUsed represents a "EmailAlreadyUsed" kind of error.
 type ErrEmailAlreadyUsed struct {
 	Email string
 }
@@ -67,6 +71,7 @@ func (err ErrEmailAlreadyUsed) Error() string {
 	return fmt.Sprintf("e-mail has been used [email: %s]", err.Email)
 }
 
+// ErrUserOwnRepos represents a "UserOwnRepos" kind of error.
 type ErrUserOwnRepos struct {
 	UID int64
 }
@@ -81,6 +86,7 @@ func (err ErrUserOwnRepos) Error() string {
 	return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID)
 }
 
+// ErrUserHasOrgs represents a "UserHasOrgs" kind of error.
 type ErrUserHasOrgs struct {
 	UID int64
 }
@@ -95,6 +101,7 @@ func (err ErrUserHasOrgs) Error() string {
 	return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
 }
 
+// ErrWikiAlreadyExist represents a "WikiAlreadyExist" kind of error.
 type ErrWikiAlreadyExist struct {
 	Title string
 }
@@ -109,6 +116,7 @@ func (err ErrWikiAlreadyExist) Error() string {
 	return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
 }
 
+// ErrKeyUnableVerify represents a "KeyUnableVerify" kind of error.
 type ErrKeyUnableVerify struct {
 	Result string
 }
@@ -123,6 +131,7 @@ func (err ErrKeyUnableVerify) Error() string {
 	return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
 }
 
+// ErrKeyNotExist represents a "KeyNotExist" kind of error.
 type ErrKeyNotExist struct {
 	ID int64
 }
@@ -137,6 +146,7 @@ func (err ErrKeyNotExist) Error() string {
 	return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
 }
 
+// ErrKeyAlreadyExist represents a "KeyAlreadyExist" kind of error.
 type ErrKeyAlreadyExist struct {
 	OwnerID int64
 	Content string
@@ -152,6 +162,7 @@ func (err ErrKeyAlreadyExist) Error() string {
 	return fmt.Sprintf("public key already exists [owner_id: %d, content: %s]", err.OwnerID, err.Content)
 }
 
+// ErrKeyNameAlreadyUsed represents a "KeyNameAlreadyUsed" kind of error.
 type ErrKeyNameAlreadyUsed struct {
 	OwnerID int64
 	Name    string
@@ -167,6 +178,7 @@ func (err ErrKeyNameAlreadyUsed) Error() string {
 	return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
 }
 
+// ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
 type ErrKeyAccessDenied struct {
 	UserID int64
 	KeyID  int64
@@ -184,6 +196,7 @@ func (err ErrKeyAccessDenied) Error() string {
 		err.UserID, err.KeyID, err.Note)
 }
 
+// ErrDeployKeyNotExist represents a "DeployKeyNotExist" kind of error.
 type ErrDeployKeyNotExist struct {
 	ID     int64
 	KeyID  int64
@@ -200,6 +213,7 @@ func (err ErrDeployKeyNotExist) Error() string {
 	return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
 }
 
+// ErrDeployKeyAlreadyExist represents a "DeployKeyAlreadyExist" kind of error.
 type ErrDeployKeyAlreadyExist struct {
 	KeyID  int64
 	RepoID int64
@@ -215,6 +229,7 @@ func (err ErrDeployKeyAlreadyExist) Error() string {
 	return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
 }
 
+// ErrDeployKeyNameAlreadyUsed represents a "DeployKeyNameAlreadyUsed" kind of error.
 type ErrDeployKeyNameAlreadyUsed struct {
 	RepoID int64
 	Name   string
@@ -230,6 +245,7 @@ func (err ErrDeployKeyNameAlreadyUsed) Error() string {
 	return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
 }
 
+// ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error.
 type ErrAccessTokenNotExist struct {
 	SHA string
 }
@@ -244,6 +260,7 @@ func (err ErrAccessTokenNotExist) Error() string {
 	return fmt.Sprintf("access token does not exist [sha: %s]", err.SHA)
 }
 
+// ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
 type ErrAccessTokenEmpty struct {
 }
 
@@ -257,6 +274,7 @@ func (err ErrAccessTokenEmpty) Error() string {
 	return fmt.Sprintf("access token is empty")
 }
 
+// ErrLastOrgOwner represents a "LastOrgOwner" kind of error.
 type ErrLastOrgOwner struct {
 	UID int64
 }
@@ -271,6 +289,7 @@ func (err ErrLastOrgOwner) Error() string {
 	return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
 }
 
+// ErrRepoAlreadyExist represents a "RepoAlreadyExist" kind of error.
 type ErrRepoAlreadyExist struct {
 	Uname string
 	Name  string
@@ -286,6 +305,7 @@ func (err ErrRepoAlreadyExist) Error() string {
 	return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
 }
 
+// ErrInvalidCloneAddr represents a "InvalidCloneAddr" kind of error.
 type ErrInvalidCloneAddr struct {
 	IsURLError         bool
 	IsInvalidPath      bool
@@ -303,6 +323,7 @@ func (err ErrInvalidCloneAddr) Error() string {
 		err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
 }
 
+// ErrUpdateTaskNotExist represents a "UpdateTaskNotExist" kind of error.
 type ErrUpdateTaskNotExist struct {
 	UUID string
 }
@@ -317,6 +338,7 @@ func (err ErrUpdateTaskNotExist) Error() string {
 	return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
 }
 
+// ErrReleaseAlreadyExist represents a "ReleaseAlreadyExist" kind of error.
 type ErrReleaseAlreadyExist struct {
 	TagName string
 }
@@ -331,6 +353,7 @@ func (err ErrReleaseAlreadyExist) Error() string {
 	return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
 }
 
+// ErrReleaseNotExist represents a "ReleaseNotExist" kind of error.
 type ErrReleaseNotExist struct {
 	ID      int64
 	TagName string
@@ -346,6 +369,7 @@ func (err ErrReleaseNotExist) Error() string {
 	return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
 }
 
+// ErrInvalidTagName represents a "InvalidTagName" kind of error.
 type ErrInvalidTagName struct {
 	TagName string
 }
@@ -360,6 +384,7 @@ func (err ErrInvalidTagName) Error() string {
 	return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
 }
 
+// ErrRepoFileAlreadyExist represents a "RepoFileAlreadyExist" kind of error.
 type ErrRepoFileAlreadyExist struct {
 	FileName string
 }
@@ -374,6 +399,7 @@ func (err ErrRepoFileAlreadyExist) Error() string {
 	return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
 }
 
+// ErrPullRequestNotExist represents a "PullRequestNotExist" kind of error.
 type ErrPullRequestNotExist struct {
 	ID         int64
 	IssueID    int64
@@ -394,6 +420,7 @@ func (err ErrPullRequestNotExist) Error() string {
 		err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBarcnh, err.BaseBranch)
 }
 
+// ErrCommentNotExist represents a "CommentNotExist" kind of error.
 type ErrCommentNotExist struct {
 	ID      int64
 	IssueID int64
@@ -409,6 +436,7 @@ func (err ErrCommentNotExist) Error() string {
 	return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
 }
 
+// ErrLabelNotExist represents a "LabelNotExist" kind of error.
 type ErrLabelNotExist struct {
 	LabelID int64
 	RepoID  int64
@@ -424,6 +452,7 @@ func (err ErrLabelNotExist) Error() string {
 	return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID)
 }
 
+// ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
 type ErrMilestoneNotExist struct {
 	ID     int64
 	RepoID int64
@@ -439,6 +468,7 @@ func (err ErrMilestoneNotExist) Error() string {
 	return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
 }
 
+// ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
 type ErrAttachmentNotExist struct {
 	ID   int64
 	UUID string
@@ -454,6 +484,7 @@ func (err ErrAttachmentNotExist) Error() string {
 	return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
 }
 
+// ErrLoginSourceAlreadyExist represents a "LoginSourceAlreadyExist" kind of error.
 type ErrLoginSourceAlreadyExist struct {
 	Name string
 }
@@ -468,6 +499,7 @@ func (err ErrLoginSourceAlreadyExist) Error() string {
 	return fmt.Sprintf("login source already exists [name: %s]", err.Name)
 }
 
+// ErrLoginSourceInUse represents a "LoginSourceInUse" kind of error.
 type ErrLoginSourceInUse struct {
 	ID int64
 }
@@ -482,6 +514,7 @@ func (err ErrLoginSourceInUse) Error() string {
 	return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
 }
 
+// ErrTeamAlreadyExist represents a "TeamAlreadyExist" kind of error.
 type ErrTeamAlreadyExist struct {
 	OrgID int64
 	Name  string
@@ -497,6 +530,7 @@ func (err ErrTeamAlreadyExist) Error() string {
 	return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
 }
 
+// ErrUploadNotExist represents a "UploadNotExist" kind of error.
 type ErrUploadNotExist struct {
 	ID   int64
 	UUID string

+ 4 - 0
models/git_diff.go

@@ -22,6 +22,7 @@ import (
 	"golang.org/x/text/transform"
 )
 
+// DiffSection represents a section of a DiffFile.
 type DiffSection struct {
 	*git.DiffSection
 }
@@ -104,15 +105,18 @@ func (diffSection *DiffSection) ComputedInlineDiffFor(diffLine *git.DiffLine) te
 	return diffToHTML(diffRecord, diffLine.Type)
 }
 
+// DiffFile represents a file diff.
 type DiffFile struct {
 	*git.DiffFile
 	Sections []*DiffSection
 }
 
+// HighlightClass returns highlight class for a filename.
 func (diffFile *DiffFile) HighlightClass() string {
 	return highlight.FileNameToHighlightClass(diffFile.Name)
 }
 
+// Diff represents a difference between two git trees.
 type Diff struct {
 	*git.Diff
 	Files []*DiffFile

+ 58 - 43
models/issue.go

@@ -22,6 +22,7 @@ import (
 )
 
 var (
+	// ErrMissingIssueNumber display error
 	ErrMissingIssueNumber = errors.New("No issue number specified")
 )
 
@@ -47,28 +48,29 @@ type Issue struct {
 	IsPull          bool         // Indicates whether is a pull request or not.
 	PullRequest     *PullRequest `xorm:"-" json:"-"`
 	NumComments     int
-
-	Deadline     time.Time `xorm:"-" json:"-"`
-	DeadlineUnix int64
-	Created      time.Time `xorm:"-" json:"-"`
-	CreatedUnix  int64
-	Updated      time.Time `xorm:"-" json:"-"`
-	UpdatedUnix  int64
-
-	Attachments []*Attachment `xorm:"-" json:"-"`
-	Comments    []*Comment    `xorm:"-" json:"-"`
+	Deadline        time.Time `xorm:"-" json:"-"`
+	DeadlineUnix    int64
+	Created         time.Time `xorm:"-" json:"-"`
+	CreatedUnix     int64
+	Updated         time.Time `xorm:"-" json:"-"`
+	UpdatedUnix     int64
+	Attachments     []*Attachment `xorm:"-" json:"-"`
+	Comments        []*Comment    `xorm:"-" json:"-"`
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (issue *Issue) BeforeInsert() {
 	issue.CreatedUnix = time.Now().Unix()
 	issue.UpdatedUnix = issue.CreatedUnix
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (issue *Issue) BeforeUpdate() {
 	issue.UpdatedUnix = time.Now().Unix()
 	issue.DeadlineUnix = issue.Deadline.Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (issue *Issue) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "deadline_unix":
@@ -146,10 +148,12 @@ func (issue *Issue) loadAttributes(e Engine) (err error) {
 	return nil
 }
 
+// LoadAttributes loads the attribute of this issue.
 func (issue *Issue) LoadAttributes() error {
 	return issue.loadAttributes(x)
 }
 
+// HTMLURL returns the absolute URL to this issue.
 func (issue *Issue) HTMLURL() string {
 	var path string
 	if issue.IsPull {
@@ -161,14 +165,14 @@ func (issue *Issue) HTMLURL() string {
 }
 
 // State returns string representation of issue status.
-func (i *Issue) State() api.StateType {
-	if i.IsClosed {
+func (issue *Issue) State() api.StateType {
+	if issue.IsClosed {
 		return api.STATE_CLOSED
 	}
 	return api.STATE_OPEN
 }
 
-// This method assumes some fields assigned with values:
+// APIFormat This method assumes some fields assigned with values:
 // Required - Poster, Labels,
 // Optional - Milestone, Assignee, PullRequest
 func (issue *Issue) APIFormat() *api.Issue {
@@ -209,22 +213,22 @@ func (issue *Issue) APIFormat() *api.Issue {
 }
 
 // HashTag returns unique hash tag for issue.
-func (i *Issue) HashTag() string {
-	return "issue-" + com.ToStr(i.ID)
+func (issue *Issue) HashTag() string {
+	return "issue-" + com.ToStr(issue.ID)
 }
 
 // IsPoster returns true if given user by ID is the poster.
-func (i *Issue) IsPoster(uid int64) bool {
-	return i.PosterID == uid
+func (issue *Issue) IsPoster(uid int64) bool {
+	return issue.PosterID == uid
 }
 
-func (i *Issue) hasLabel(e Engine, labelID int64) bool {
-	return hasIssueLabel(e, i.ID, labelID)
+func (issue *Issue) hasLabel(e Engine, labelID int64) bool {
+	return hasIssueLabel(e, issue.ID, labelID)
 }
 
 // HasLabel returns true if issue has been labeled by given ID.
-func (i *Issue) HasLabel(labelID int64) bool {
-	return i.hasLabel(x, labelID)
+func (issue *Issue) HasLabel(labelID int64) bool {
+	return issue.hasLabel(x, labelID)
 }
 
 func (issue *Issue) sendLabelUpdatedWebhook(doer *User) {
@@ -258,8 +262,8 @@ func (issue *Issue) sendLabelUpdatedWebhook(doer *User) {
 	}
 }
 
-func (i *Issue) addLabel(e *xorm.Session, label *Label) error {
-	return newIssueLabel(e, i, label)
+func (issue *Issue) addLabel(e *xorm.Session, label *Label) error {
+	return newIssueLabel(e, issue, label)
 }
 
 // AddLabel adds a new label to the issue.
@@ -331,6 +335,8 @@ func (issue *Issue) clearLabels(e *xorm.Session) (err error) {
 	return nil
 }
 
+// ClearLabels removes all issue labels as the given user.
+// Triggers appropriate WebHooks, if any.
 func (issue *Issue) ClearLabels(doer *User) (err error) {
 	sess := x.NewSession()
 	defer sess.Close()
@@ -394,12 +400,13 @@ func (issue *Issue) ReplaceLabels(labels []*Label) (err error) {
 	return sess.Commit()
 }
 
-func (i *Issue) GetAssignee() (err error) {
-	if i.AssigneeID == 0 || i.Assignee != nil {
+// GetAssignee get the assignee of the issue.
+func (issue *Issue) GetAssignee() (err error) {
+	if issue.AssigneeID == 0 || issue.Assignee != nil {
 		return nil
 	}
 
-	i.Assignee, err = GetUserByID(i.AssigneeID)
+	issue.Assignee, err = GetUserByID(issue.AssigneeID)
 	if errors.IsUserNotExist(err) {
 		return nil
 	}
@@ -407,8 +414,8 @@ func (i *Issue) GetAssignee() (err error) {
 }
 
 // ReadBy sets issue to be read by given user.
-func (i *Issue) ReadBy(uid int64) error {
-	return UpdateIssueUserByRead(uid, i.ID)
+func (issue *Issue) ReadBy(uid int64) error {
+	return UpdateIssueUserByRead(uid, issue.ID)
 }
 
 func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
@@ -421,41 +428,41 @@ func UpdateIssueCols(issue *Issue, cols ...string) error {
 	return updateIssueCols(x, issue, cols...)
 }
 
-func (i *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository, isClosed bool) (err error) {
+func (issue *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository, isClosed bool) (err error) {
 	// Nothing should be performed if current status is same as target status
-	if i.IsClosed == isClosed {
+	if issue.IsClosed == isClosed {
 		return nil
 	}
-	i.IsClosed = isClosed
+	issue.IsClosed = isClosed
 
-	if err = updateIssueCols(e, i, "is_closed"); err != nil {
+	if err = updateIssueCols(e, issue, "is_closed"); err != nil {
 		return err
-	} else if err = updateIssueUsersByStatus(e, i.ID, isClosed); err != nil {
+	} else if err = updateIssueUsersByStatus(e, issue.ID, isClosed); err != nil {
 		return err
 	}
 
 	// Update issue count of labels
-	if err = i.getLabels(e); err != nil {
+	if err = issue.getLabels(e); err != nil {
 		return err
 	}
-	for idx := range i.Labels {
-		if i.IsClosed {
-			i.Labels[idx].NumClosedIssues++
+	for idx := range issue.Labels {
+		if issue.IsClosed {
+			issue.Labels[idx].NumClosedIssues++
 		} else {
-			i.Labels[idx].NumClosedIssues--
+			issue.Labels[idx].NumClosedIssues--
 		}
-		if err = updateLabel(e, i.Labels[idx]); err != nil {
+		if err = updateLabel(e, issue.Labels[idx]); err != nil {
 			return err
 		}
 	}
 
 	// Update issue count of milestone
-	if err = changeMilestoneIssueStats(e, i); err != nil {
+	if err = changeMilestoneIssueStats(e, issue); err != nil {
 		return err
 	}
 
 	// New action comment
-	if _, err = createStatusComment(e, doer, repo, i); err != nil {
+	if _, err = createStatusComment(e, doer, repo, issue); err != nil {
 		return err
 	}
 
@@ -515,6 +522,7 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e
 	return nil
 }
 
+// ChangeTitle changes the title of this issue, as the given user.
 func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
 	oldTitle := issue.Title
 	issue.Title = title
@@ -558,6 +566,7 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
 	return nil
 }
 
+// ChangeContent changes issue content, as the given user.
 func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
 	oldContent := issue.Content
 	issue.Content = content
@@ -601,6 +610,7 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
 	return nil
 }
 
+// ChangeAssignee changes issue assignee.
 func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
 	issue.AssigneeID = assigneeID
 	if err = UpdateIssueUserByAssignee(issue); err != nil {
@@ -652,6 +662,7 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
 	return nil
 }
 
+// NewIssueOptions represents the options of a new issue.
 type NewIssueOptions struct {
 	Repo        *Repository
 	Issue       *Issue
@@ -883,6 +894,7 @@ func GetIssueByID(id int64) (*Issue, error) {
 	return getIssueByID(x, id)
 }
 
+// IssuesOptions represents options of an issue.
 type IssuesOptions struct {
 	UserID      int64
 	AssigneeID  int64
@@ -1091,9 +1103,9 @@ func NewIssueUsers(repo *Repository, issue *Issue) (err error) {
 }
 
 // PairsContains returns true when pairs list contains given issue.
-func PairsContains(ius []*IssueUser, issueId, uid int64) int {
+func PairsContains(ius []*IssueUser, issueID, uid int64) int {
 	for i := range ius {
-		if ius[i].IssueID == issueId &&
+		if ius[i].IssueID == issueID &&
 			ius[i].UID == uid {
 			return i
 		}
@@ -1192,8 +1204,10 @@ type IssueStats struct {
 	MentionCount           int64
 }
 
+// FilterMode represents an mode.
 type FilterMode string
 
+// Filter modes.
 const (
 	FilterModeYourRepos FilterMode = "your_repositories"
 	FilterModeAssign    FilterMode = "assigned"
@@ -1211,6 +1225,7 @@ func parseCountResult(results []map[string][]byte) int64 {
 	return 0
 }
 
+// IssueStatsOptions contains parameters accepted by GetIssueStats.
 type IssueStatsOptions struct {
 	RepoID      int64
 	UserID      int64

+ 4 - 3
models/issue_label.go

@@ -64,6 +64,7 @@ type Label struct {
 	IsChecked       bool `xorm:"-" json:"-"`
 }
 
+// APIFormat converts a Label to the api.Label format
 func (label *Label) APIFormat() *api.Label {
 	return &api.Label{
 		ID:    label.ID,
@@ -79,9 +80,9 @@ func (label *Label) CalOpenIssues() {
 
 // ForegroundColor calculates the text color for labels based
 // on their background color.
-func (l *Label) ForegroundColor() template.CSS {
-	if strings.HasPrefix(l.Color, "#") {
-		if color, err := strconv.ParseUint(l.Color[1:], 16, 64); err == nil {
+func (label *Label) ForegroundColor() template.CSS {
+	if strings.HasPrefix(label.Color, "#") {
+		if color, err := strconv.ParseUint(label.Color[1:], 16, 64); err == nil {
 			r := float32(0xFF & (color >> 16))
 			g := float32(0xFF & (color >> 8))
 			b := float32(0xFF & color)

+ 23 - 22
models/issue_mail.go

@@ -17,6 +17,7 @@ import (
 	log "gopkg.in/clog.v1"
 )
 
+// MailSubject returns subject of mail.
 func (issue *Issue) MailSubject() string {
 	return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.Name, issue.Title, issue.Index)
 }
@@ -26,24 +27,24 @@ type mailerUser struct {
 	user *User
 }
 
-func (this mailerUser) ID() int64 {
-	return this.user.ID
+func (t mailerUser) ID() int64 {
+	return t.user.ID
 }
 
-func (this mailerUser) DisplayName() string {
-	return this.user.DisplayName()
+func (t mailerUser) DisplayName() string {
+	return t.user.DisplayName()
 }
 
-func (this mailerUser) Email() string {
-	return this.user.Email
+func (t mailerUser) Email() string {
+	return t.user.Email
 }
 
-func (this mailerUser) GenerateActivateCode() string {
-	return this.user.GenerateActivateCode()
+func (t mailerUser) GenerateActivateCode() string {
+	return t.user.GenerateActivateCode()
 }
 
-func (this mailerUser) GenerateEmailActivateCode(email string) string {
-	return this.user.GenerateEmailActivateCode(email)
+func (t mailerUser) GenerateEmailActivateCode(email string) string {
+	return t.user.GenerateEmailActivateCode(email)
 }
 
 // NewMailerUser returns mailerUser
@@ -56,16 +57,16 @@ type mailerRepo struct {
 	repo *Repository
 }
 
-func (this mailerRepo) FullName() string {
-	return this.repo.FullName()
+func (t mailerRepo) FullName() string {
+	return t.repo.FullName()
 }
 
-func (this mailerRepo) HTMLURL() string {
-	return this.repo.HTMLURL()
+func (t mailerRepo) HTMLURL() string {
+	return t.repo.HTMLURL()
 }
 
-func (this mailerRepo) ComposeMetas() map[string]string {
-	return this.repo.ComposeMetas()
+func (t mailerRepo) ComposeMetas() map[string]string {
+	return t.repo.ComposeMetas()
 }
 
 // NewMailerRepo returns mailerRepo
@@ -78,16 +79,16 @@ type mailerIssue struct {
 	issue *Issue
 }
 
-func (this mailerIssue) MailSubject() string {
-	return this.issue.MailSubject()
+func (t mailerIssue) MailSubject() string {
+	return t.issue.MailSubject()
 }
 
-func (this mailerIssue) Content() string {
-	return this.issue.Content
+func (t mailerIssue) Content() string {
+	return t.issue.Content
 }
 
-func (this mailerIssue) HTMLURL() string {
-	return this.issue.HTMLURL()
+func (t mailerIssue) HTMLURL() string {
+	return t.issue.HTMLURL()
 }
 
 // NewMailerIssue returns mailerIssue

+ 38 - 1
models/login_source.go

@@ -4,7 +4,6 @@
 // This source code is licensed under the MIT license found in the
 // LICENSE file in the root directory of this source tree.
 
-// FIXME: Put this file into its own package and separate into different files based on login sources.
 package models
 
 import (
@@ -33,6 +32,7 @@ import (
 	"gopkg.in/ini.v1"
 )
 
+// LoginType represents an login type.
 type LoginType int
 
 // Note: new type must append to the end of list to maintain compatibility.
@@ -46,6 +46,7 @@ const (
 	LoginGitHub           // 6
 )
 
+// LoginNames contains the name of LoginType values.
 var LoginNames = map[LoginType]string{
 	LoginLDAP:   "LDAP (via BindDN)",
 	LoginDLDAP:  "LDAP (simple auth)", // Via direct bind
@@ -54,6 +55,7 @@ var LoginNames = map[LoginType]string{
 	LoginGitHub: "GitHub",
 }
 
+// SecurityProtocolNames contains the name of SecurityProtocol values.
 var SecurityProtocolNames = map[ldap.SecurityProtocol]string{
 	ldap.SECURITY_PROTOCOL_UNENCRYPTED: "Unencrypted",
 	ldap.SECURITY_PROTOCOL_LDAPS:       "LDAPS",
@@ -68,34 +70,43 @@ var (
 	_ core.Conversion = &GitHubConfig{}
 )
 
+// LDAPConfig holds configuration for LDAP login source.
 type LDAPConfig struct {
 	*ldap.Source `ini:"config"`
 }
 
+// FromDB fills up a LDAPConfig from serialized format.
 func (cfg *LDAPConfig) FromDB(bs []byte) error {
 	return jsoniter.Unmarshal(bs, &cfg)
 }
 
+// ToDB exports a LDAPConfig to a serialized format.
 func (cfg *LDAPConfig) ToDB() ([]byte, error) {
 	return jsoniter.Marshal(cfg)
 }
 
+// GitHubConfig holds configuration for GitHub login source.
 type GitHubConfig struct {
 	APIEndpoint string // GitHub service (e.g. https://api.github.com/)
 }
 
+// FromDB fills up a GitHubConfig from serialized format.
 func (cfg *GitHubConfig) FromDB(bs []byte) error {
 	return jsoniter.Unmarshal(bs, &cfg)
 }
 
+// ToDB exports a GitHubConfig to a serialized format.
 func (cfg *GitHubConfig) ToDB() ([]byte, error) {
 	return jsoniter.Marshal(cfg)
 }
 
+// SecurityProtocolName returns the name of configured security
+// protocol.
 func (cfg *LDAPConfig) SecurityProtocolName() string {
 	return SecurityProtocolNames[cfg.SecurityProtocol]
 }
 
+// SMTPConfig holds configuration for the SMTP login source.
 type SMTPConfig struct {
 	Auth           string
 	Host           string
@@ -105,22 +116,27 @@ type SMTPConfig struct {
 	SkipVerify     bool
 }
 
+// FromDB fills up an SMTPConfig from serialized format.
 func (cfg *SMTPConfig) FromDB(bs []byte) error {
 	return jsoniter.Unmarshal(bs, cfg)
 }
 
+// ToDB exports an SMTPConfig to a serialized format.
 func (cfg *SMTPConfig) ToDB() ([]byte, error) {
 	return jsoniter.Marshal(cfg)
 }
 
+// PAMConfig holds configuration for the PAM login source.
 type PAMConfig struct {
 	ServiceName string // PAM service (e.g. system-auth)
 }
 
+// FromDB fills up a PAMConfig from serialized format.
 func (cfg *PAMConfig) FromDB(bs []byte) error {
 	return jsoniter.Unmarshal(bs, &cfg)
 }
 
+// ToDB exports a PAMConfig to a serialized format.
 func (cfg *PAMConfig) ToDB() ([]byte, error) {
 	return jsoniter.Marshal(cfg)
 }
@@ -163,11 +179,13 @@ type LoginSource struct {
 	LocalFile *AuthSourceFile `xorm:"-" json:"-"`
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (s *LoginSource) BeforeInsert() {
 	s.CreatedUnix = time.Now().Unix()
 	s.UpdatedUnix = s.CreatedUnix
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (s *LoginSource) BeforeUpdate() {
 	s.UpdatedUnix = time.Now().Unix()
 }
@@ -183,6 +201,7 @@ func Cell2Int64(val xorm.Cell) int64 {
 	return (*val).(int64)
 }
 
+// BeforeSet is invoked from XORM before setting the value of a field of this object.
 func (s *LoginSource) BeforeSet(colName string, val xorm.Cell) {
 	switch colName {
 	case "type":
@@ -201,6 +220,7 @@ func (s *LoginSource) BeforeSet(colName string, val xorm.Cell) {
 	}
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (s *LoginSource) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":
@@ -210,36 +230,44 @@ func (s *LoginSource) AfterSet(colName string, _ xorm.Cell) {
 	}
 }
 
+// TypeName return name of this login source type.
 func (s *LoginSource) TypeName() string {
 	return LoginNames[s.Type]
 }
 
+// IsLDAP returns true of this source is of the LDAP type.
 func (s *LoginSource) IsLDAP() bool {
 	return s.Type == LoginLDAP
 }
 
+// IsDLDAP returns true of this source is of the DLDAP type.
 func (s *LoginSource) IsDLDAP() bool {
 	return s.Type == LoginDLDAP
 }
 
+// IsSMTP returns true of this source is of the SMTP type.
 func (s *LoginSource) IsSMTP() bool {
 	return s.Type == LoginSMTP
 }
 
+// IsPAM returns true of this source is of the PAM type.
 func (s *LoginSource) IsPAM() bool {
 	return s.Type == LoginPAM
 }
 
+// IsGitHub returns true of this source is of the GitHub type.
 func (s *LoginSource) IsGitHub() bool {
 	return s.Type == LoginGitHub
 }
 
+// HasTLS returns true of this source supports TLS.
 func (s *LoginSource) HasTLS() bool {
 	return ((s.IsLDAP() || s.IsDLDAP()) &&
 		s.LDAP().SecurityProtocol > ldap.SECURITY_PROTOCOL_UNENCRYPTED) ||
 		s.IsSMTP()
 }
 
+// UseTLS returns true of this source is configured to use TLS.
 func (s *LoginSource) UseTLS() bool {
 	switch s.Type {
 	case LoginLDAP, LoginDLDAP:
@@ -251,6 +279,8 @@ func (s *LoginSource) UseTLS() bool {
 	return false
 }
 
+// SkipVerify returns true if this source is configured to skip SSL
+// verification.
 func (s *LoginSource) SkipVerify() bool {
 	switch s.Type {
 	case LoginLDAP, LoginDLDAP:
@@ -262,18 +292,22 @@ func (s *LoginSource) SkipVerify() bool {
 	return false
 }
 
+// LDAP returns LDAPConfig for this source, if of LDAP type.
 func (s *LoginSource) LDAP() *LDAPConfig {
 	return s.Cfg.(*LDAPConfig)
 }
 
+// SMTP returns SMTPConfig for this source, if of SMTP type.
 func (s *LoginSource) SMTP() *SMTPConfig {
 	return s.Cfg.(*SMTPConfig)
 }
 
+// PAM returns PAMConfig for this source, if of PAM type.
 func (s *LoginSource) PAM() *PAMConfig {
 	return s.Cfg.(*PAMConfig)
 }
 
+// GitHub returns GitHubConfig for this source, if of GitHubConfig type.
 func (s *LoginSource) GitHub() *GitHubConfig {
 	return s.Cfg.(*GitHubConfig)
 }
@@ -396,6 +430,7 @@ type LocalLoginSources struct {
 	sources []*LoginSource
 }
 
+// Len returns length of local login sources.
 func (s *LocalLoginSources) Len() int {
 	return len(s.sources)
 }
@@ -622,11 +657,13 @@ func (auth *smtpLoginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
 	return nil, nil
 }
 
+// SMTP authentication type names.
 const (
 	SMTPPlain = "PLAIN"
 	SMTPLogin = "LOGIN"
 )
 
+// SMTPAuths contains available SMTP authentication type names.
 var SMTPAuths = []string{SMTPPlain, SMTPLogin}
 
 // SMTPAuth contains available SMTP authentication type names.

+ 6 - 0
models/milestone.go

@@ -38,10 +38,12 @@ type Milestone struct {
 	ClosedDateUnix int64
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (m *Milestone) BeforeInsert() {
 	m.DeadlineUnix = m.Deadline.Unix()
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (m *Milestone) BeforeUpdate() {
 	if m.NumIssues > 0 {
 		m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
@@ -53,6 +55,7 @@ func (m *Milestone) BeforeUpdate() {
 	m.ClosedDateUnix = m.ClosedDate.Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (m *Milestone) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "num_closed_issues":
@@ -82,10 +85,12 @@ func (m *Milestone) State() api.StateType {
 	return api.STATE_OPEN
 }
 
+// ChangeStatus changes milestone status to open or closed.
 func (m *Milestone) ChangeStatus(isClosed bool) error {
 	return ChangeMilestoneStatus(m, isClosed)
 }
 
+// APIFormat returns this Milestone in API format.
 func (m *Milestone) APIFormat() *api.Milestone {
 	apiMilestone := &api.Milestone{
 		ID:           m.ID,
@@ -104,6 +109,7 @@ func (m *Milestone) APIFormat() *api.Milestone {
 	return apiMilestone
 }
 
+// CountIssues counts issues in milestone.
 func (m *Milestone) CountIssues(isClosed, includePulls bool) int64 {
 	sess := x.Where("milestone_id = ?", m.ID).And("is_closed = ?", isClosed)
 	if !includePulls {

+ 6 - 1
models/mirror.go

@@ -25,6 +25,7 @@ import (
 	"gopkg.in/ini.v1"
 )
 
+// MirrorQueue holds an UniqueQueue object of the mirror
 var MirrorQueue = sync.NewUniqueQueue(setting.Repository.MirrorQueueLength)
 
 // Mirror represents mirror information of a repository.
@@ -44,15 +45,18 @@ type Mirror struct {
 	address string `xorm:"-" json:"-"`
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (m *Mirror) BeforeInsert() {
 	m.NextSyncUnix = m.NextSync.Unix()
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (m *Mirror) BeforeUpdate() {
 	m.LastSyncUnix = m.LastSync.Unix()
 	m.NextSyncUnix = m.NextSync.Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (m *Mirror) AfterSet(colName string, _ xorm.Cell) {
 	var err error
 	switch colName {
@@ -94,7 +98,7 @@ func findPasswordInMirrorAddress(addr string) (start int, end int, found bool) {
 	if delim == -1 {
 		return -1, -1, false
 	}
-	delim += 1
+	delim++
 
 	if start+delim >= end {
 		return -1, -1, false // No password portion presented
@@ -192,6 +196,7 @@ func (m *Mirror) SaveAddress(addr string) error {
 	return cfg.SaveToIndent(configPath, "\t")
 }
 
+// GitShortEmptySHA Git short empty SHA
 const GitShortEmptySHA = "0000000"
 
 // mirrorSyncResult contains information of a updated reference.

+ 16 - 6
models/models.go

@@ -17,12 +17,17 @@ import (
 	"path"
 	"strings"
 
+	// Needed for the MSSSQL driver
 	_ "github.com/denisenkom/go-mssqldb"
 	raven "github.com/getsentry/raven-go"
+
+	// Needed for the MySSQL driver
 	_ "github.com/go-sql-driver/mysql"
 	"github.com/go-xorm/core"
 	"github.com/go-xorm/xorm"
 	"github.com/json-iterator/go"
+
+	// Needed for the PostgreSQL driver
 	_ "github.com/lib/pq"
 	"gitlab.com/gitote/com"
 	log "gopkg.in/clog.v1"
@@ -45,14 +50,18 @@ type Engine interface {
 }
 
 var (
-	x         *xorm.Engine
-	tables    []interface{}
+	x      *xorm.Engine
+	tables []interface{}
+
+	// HasEngine specifies if we have a xorm.Engine
 	HasEngine bool
 
+	// DbCfg holds the database settings
 	DbCfg struct {
 		Type, Host, Name, User, Passwd, Path, SSLMode string
 	}
 
+	// EnableSQLite3 use SQLite3
 	EnableSQLite3 bool
 )
 
@@ -129,7 +138,7 @@ func parseMSSQLHostPort(info string) (string, string) {
 
 func getEngine() (*xorm.Engine, error) {
 	connStr := ""
-	var Param string = "?"
+	var Param = "?"
 	if strings.Contains(DbCfg.Name, Param) {
 		Param = "&"
 	}
@@ -158,7 +167,7 @@ func getEngine() (*xorm.Engine, error) {
 		connStr = fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;", host, port, DbCfg.Name, DbCfg.User, DbCfg.Passwd)
 	case "sqlite3":
 		if !EnableSQLite3 {
-			return nil, errors.New("This binary version does not build support for SQLite3.")
+			return nil, errors.New("this binary version does not build support for sqlite3")
 		}
 		if err := os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm); err != nil {
 			return nil, fmt.Errorf("Fail to create directories: %v", err)
@@ -220,12 +229,13 @@ func NewEngine() (err error) {
 	}
 
 	if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
-		return fmt.Errorf("sync database struct error: %v\n", err)
+		return fmt.Errorf("sync database struct error: %v", err)
 	}
 
 	return nil
 }
 
+// Statistic contains the database statistics
 type Statistic struct {
 	Counter struct {
 		User, Org, PublicKey,
@@ -271,7 +281,7 @@ func Ping() error {
 	return errors.New("database not configured")
 }
 
-// The version table. Should have only one row with id==1
+// Version The version table. Should have only one row with id==1
 type Version struct {
 	ID      int64
 	Version int64

+ 14 - 13
models/org.go

@@ -17,6 +17,7 @@ import (
 )
 
 var (
+	// ErrOrgNotExist displays error.
 	ErrOrgNotExist = errors.New("Organization does not exist")
 )
 
@@ -34,13 +35,13 @@ func (org *User) getTeam(e Engine, name string) (*Team, error) {
 	return getTeamOfOrgByName(e, org.ID, name)
 }
 
-// GetTeamOfOrgByName returns named team of organization.
+// GetTeam returns named team of organization.
 func (org *User) GetTeam(name string) (*Team, error) {
 	return org.getTeam(x, name)
 }
 
 func (org *User) getOwnerTeam(e Engine) (*Team, error) {
-	return org.getTeam(e, OwnerTeam)
+	return org.getTeam(e, ownerTeamName)
 }
 
 // GetOwnerTeam returns owner team of organization.
@@ -72,7 +73,7 @@ func (org *User) GetMembers() error {
 
 	org.Members = make([]*User, len(ous))
 	for i, ou := range ous {
-		org.Members[i], err = GetUserByID(ou.Uid)
+		org.Members[i], err = GetUserByID(ou.UID)
 		if err != nil {
 			return err
 		}
@@ -137,7 +138,7 @@ func CreateOrganization(org, owner *User) (err error) {
 
 	// Add initial creator to organization and owner team.
 	if _, err = sess.Insert(&OrgUser{
-		Uid:      owner.ID,
+		UID:      owner.ID,
 		OrgID:    org.ID,
 		IsOwner:  true,
 		NumTeams: 1,
@@ -148,8 +149,8 @@ func CreateOrganization(org, owner *User) (err error) {
 	// Create default owner team.
 	t := &Team{
 		OrgID:      org.ID,
-		LowerName:  strings.ToLower(OwnerTeam),
-		Name:       OwnerTeam,
+		LowerName:  strings.ToLower(ownerTeamName),
+		Name:       ownerTeamName,
 		Authorize:  AccessModeOwner,
 		NumMembers: 1,
 	}
@@ -232,7 +233,7 @@ func DeleteOrganization(org *User) (err error) {
 // OrgUser represents an organization-user relation.
 type OrgUser struct {
 	ID       int64
-	Uid      int64 `xorm:"INDEX UNIQUE(s)"`
+	UID      int64 `xorm:"INDEX UNIQUE(s)"`
 	OrgID    int64 `xorm:"INDEX UNIQUE(s)"`
 	IsPublic bool
 	IsOwner  bool
@@ -246,14 +247,14 @@ func IsOrganizationOwner(orgID, userID int64) bool {
 }
 
 // IsOrganizationMember returns true if given user is member of organization.
-func IsOrganizationMember(orgId, uid int64) bool {
-	has, _ := x.Where("uid=?", uid).And("org_id=?", orgId).Get(new(OrgUser))
+func IsOrganizationMember(orgID, uid int64) bool {
+	has, _ := x.Where("uid=?", uid).And("org_id=?", orgID).Get(new(OrgUser))
 	return has
 }
 
 // IsPublicMembership returns true if given user public his/her membership.
-func IsPublicMembership(orgId, uid int64) bool {
-	has, _ := x.Where("uid=?", uid).And("org_id=?", orgId).And("is_public=?", true).Get(new(OrgUser))
+func IsPublicMembership(orgID, uid int64) bool {
+	has, _ := x.Where("uid=?", uid).And("org_id=?", orgID).And("is_public=?", true).Get(new(OrgUser))
 	return has
 }
 
@@ -346,7 +347,7 @@ func AddOrgUser(orgID, uid int64) error {
 	}
 
 	ou := &OrgUser{
-		Uid:   uid,
+		UID:   uid,
 		OrgID: orgID,
 	}
 
@@ -474,7 +475,7 @@ func (org *User) GetUserTeamIDs(userID int64) ([]int64, error) {
 	return teamIDs, nil
 }
 
-// GetTeams returns all teams that belong to organization,
+// GetUserTeams returns all teams that belong to organization,
 // and that the user has joined.
 func (org *User) GetUserTeams(userID int64) ([]*Team, error) {
 	return org.getUserTeams(x, userID)

+ 4 - 3
models/org_team.go

@@ -14,7 +14,7 @@ import (
 	"github.com/go-xorm/xorm"
 )
 
-const OwnerTeam = "Owners"
+const ownerTeamName = "Owners"
 
 // Team represents a organization team.
 type Team struct {
@@ -30,6 +30,7 @@ type Team struct {
 	NumMembers  int
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (t *Team) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "num_repos":
@@ -41,7 +42,7 @@ func (t *Team) AfterSet(colName string, _ xorm.Cell) {
 
 // IsOwnerTeam returns true if team is owner team.
 func (t *Team) IsOwnerTeam() bool {
-	return t.Name == OwnerTeam
+	return t.Name == ownerTeamName
 }
 
 // HasWriteAccess returns true if team has at least write level access mode.
@@ -49,7 +50,7 @@ func (t *Team) HasWriteAccess() bool {
 	return t.Authorize >= AccessModeWrite
 }
 
-// IsTeamMember returns true if given user is a member of team.
+// IsMember returns true if given user is a member of team.
 func (t *Team) IsMember(userID int64) bool {
 	return IsTeamMember(t.OrgID, t.ID, userID)
 }

+ 28 - 19
models/pull.go

@@ -25,16 +25,20 @@ import (
 	log "gopkg.in/clog.v1"
 )
 
-var PullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength)
+var pullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength)
 
+// PullRequestType defines pull request type
 type PullRequestType int
 
+// Enumerate all the pull request types
 const (
 	PullRequestGitote PullRequestType = iota
 )
 
+// PullRequestStatus defines pull request status
 type PullRequestStatus int
 
+// Enumerate all the pull request status
 const (
 	PullRequestStatusConflict PullRequestStatus = iota
 	PullRequestStatusChecking
@@ -43,14 +47,12 @@ const (
 
 // PullRequest represents relation between pull request and repositories.
 type PullRequest struct {
-	ID     int64
-	Type   PullRequestType
-	Status PullRequestStatus
-
-	IssueID int64  `xorm:"INDEX"`
-	Issue   *Issue `xorm:"-" json:"-"`
-	Index   int64
-
+	ID             int64
+	Type           PullRequestType
+	Status         PullRequestStatus
+	IssueID        int64  `xorm:"INDEX"`
+	Issue          *Issue `xorm:"-" json:"-"`
+	Index          int64
 	HeadRepoID     int64
 	HeadRepo       *Repository `xorm:"-" json:"-"`
 	BaseRepoID     int64
@@ -67,11 +69,12 @@ type PullRequest struct {
 	MergedUnix     int64
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (pr *PullRequest) BeforeUpdate() {
 	pr.MergedUnix = pr.Merged.Unix()
 }
 
-// Note: don't try to get Issue because will end up recursive querying.
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (pr *PullRequest) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "merged_unix":
@@ -112,10 +115,12 @@ func (pr *PullRequest) loadAttributes(e Engine) (err error) {
 	return nil
 }
 
+// LoadAttributes loads pull request attributes from database
 func (pr *PullRequest) LoadAttributes() error {
 	return pr.loadAttributes(x)
 }
 
+// LoadIssue loads issue information from database
 func (pr *PullRequest) LoadIssue() (err error) {
 	if pr.Issue != nil {
 		return nil
@@ -125,7 +130,7 @@ func (pr *PullRequest) LoadIssue() (err error) {
 	return err
 }
 
-// This method assumes following fields have been assigned with valid values:
+// APIFormat This method assumes following fields have been assigned with valid values:
 // Required - Issue, BaseRepo
 // Optional - HeadRepo, Merger
 func (pr *PullRequest) APIFormat() *api.PullRequest {
@@ -186,8 +191,10 @@ func (pr *PullRequest) CanAutoMerge() bool {
 type MergeStyle string
 
 const (
+	// MergeStyleRegular create merge commit
 	MergeStyleRegular MergeStyle = "create_merge_commit"
-	MergeStyleRebase  MergeStyle = "rebase_before_merging"
+	// MergeStyleRebase rebase before merging
+	MergeStyleRebase MergeStyle = "rebase_before_merging"
 )
 
 // Merge merges pull request to base repository.
@@ -371,10 +378,10 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
 		l.PushFront(mergeCommit)
 	}
 
-	commits, err := ListToPushCommits(l).ToApiPayloadCommits(pr.BaseRepo.RepoPath(), pr.BaseRepo.HTMLURL())
+	commits, err := ListToPushCommits(l).ToAPIPayloadCommits(pr.BaseRepo.RepoPath(), pr.BaseRepo.HTMLURL())
 	if err != nil {
 		raven.CaptureErrorAndWait(err, nil)
-		log.Error(2, "ToApiPayloadCommits: %v", err)
+		log.Error(2, "ToAPIPayloadCommits: %v", err)
 		return nil
 	}
 
@@ -593,7 +600,7 @@ func (pr *PullRequest) Update() error {
 	return err
 }
 
-// Update updates specific fields of pull request.
+// UpdateCols updates specific fields of pull request.
 func (pr *PullRequest) UpdateCols(cols ...string) error {
 	_, err := x.Id(pr.ID).Cols(cols...).Update(pr)
 	return err
@@ -672,7 +679,7 @@ func (pr *PullRequest) PushToBaseRepo() (err error) {
 
 // AddToTaskQueue adds itself to pull request test task queue.
 func (pr *PullRequest) AddToTaskQueue() {
-	go PullRequestQueue.AddFunc(pr.ID, func() {
+	go pullRequestQueue.AddFunc(pr.ID, func() {
 		pr.Status = PullRequestStatusChecking
 		if err := pr.UpdateCols("status"); err != nil {
 			raven.CaptureErrorAndWait(err, nil)
@@ -681,6 +688,7 @@ func (pr *PullRequest) AddToTaskQueue() {
 	})
 }
 
+// PullRequestList defines a list of pull requests
 type PullRequestList []*PullRequest
 
 func (prs PullRequestList) loadAttributes(e Engine) (err error) {
@@ -718,6 +726,7 @@ func (prs PullRequestList) loadAttributes(e Engine) (err error) {
 	return nil
 }
 
+// LoadAttributes load all the prs attributes
 func (prs PullRequestList) LoadAttributes() error {
 	return prs.loadAttributes(x)
 }
@@ -811,7 +820,7 @@ func (pr *PullRequest) checkAndUpdateStatus() {
 	}
 
 	// Make sure there is no waiting test to process before levaing the checking status.
-	if !PullRequestQueue.Exist(pr.ID) {
+	if !pullRequestQueue.Exist(pr.ID) {
 		if err := pr.UpdateCols("status"); err != nil {
 			raven.CaptureErrorAndWait(err, nil)
 			log.Error(4, "Update[%d]: %v", pr.ID, err)
@@ -850,9 +859,9 @@ func TestPullRequests() {
 	}
 
 	// Start listening on new test requests.
-	for prID := range PullRequestQueue.Queue() {
+	for prID := range pullRequestQueue.Queue() {
 		log.Trace("TestPullRequests[%v]: processing test task", prID)
-		PullRequestQueue.Remove(prID)
+		pullRequestQueue.Remove(prID)
 
 		pr, err := GetPullRequestByID(com.StrTo(prID).MustInt64())
 		if err != nil {

+ 4 - 1
models/release.go

@@ -45,12 +45,14 @@ type Release struct {
 	Attachments []*Attachment `xorm:"-" json:"-"`
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (r *Release) BeforeInsert() {
 	if r.CreatedUnix == 0 {
 		r.CreatedUnix = time.Now().Unix()
 	}
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (r *Release) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":
@@ -88,11 +90,12 @@ func (r *Release) loadAttributes(e Engine) (err error) {
 	return nil
 }
 
+// LoadAttributes load repo and publisher attributes for a release
 func (r *Release) LoadAttributes() error {
 	return r.loadAttributes(x)
 }
 
-// This method assumes some fields assigned with values:
+// APIFormat This method assumes some fields assigned with values:
 // Required - Publisher
 func (r *Release) APIFormat() *api.Release {
 	return &api.Release{

+ 7 - 3
models/repo_branch.go

@@ -16,10 +16,10 @@ import (
 	"gitlab.com/gitote/git-module"
 )
 
+// Branch holds the branch information
 type Branch struct {
-	RepoPath string
-	Name     string
-
+	RepoPath    string
+	Name        string
 	IsProtected bool
 	Commit      *git.Commit
 }
@@ -46,6 +46,7 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
 	return branches, nil
 }
 
+// GetBranch returns a branch by it's name
 func (repo *Repository) GetBranch(br string) (*Branch, error) {
 	if !git.IsBranchExist(repo.RepoPath(), br) {
 		return nil, errors.ErrBranchNotExist{br}
@@ -56,10 +57,12 @@ func (repo *Repository) GetBranch(br string) (*Branch, error) {
 	}, nil
 }
 
+// GetBranches returns all the branches of a repository
 func (repo *Repository) GetBranches() ([]*Branch, error) {
 	return GetBranchesByPath(repo.RepoPath())
 }
 
+// GetCommit returns all the commits of a branch
 func (br *Branch) GetCommit() (*git.Commit, error) {
 	gitRepo, err := git.OpenRepository(br.RepoPath)
 	if err != nil {
@@ -68,6 +71,7 @@ func (br *Branch) GetCommit() (*git.Commit, error) {
 	return gitRepo.GetBranchCommit(br.Name)
 }
 
+// ProtectBranchWhitelist holds protect information.
 type ProtectBranchWhitelist struct {
 	ID              int64
 	ProtectBranchID int64

+ 4 - 0
models/repo_collaboration.go

@@ -22,6 +22,7 @@ type Collaboration struct {
 	Mode   AccessMode `xorm:"DEFAULT 2 NOT NULL"`
 }
 
+// ModeI18nKey returns the collaboration mode I18n Key
 func (c *Collaboration) ModeI18nKey() string {
 	switch c.Mode {
 	case AccessModeRead:
@@ -50,6 +51,7 @@ func IsCollaborator(repoID, userID int64) bool {
 	return has
 }
 
+// IsCollaborator check if a user is a collaborator of a repository
 func (repo *Repository) IsCollaborator(userID int64) bool {
 	return IsCollaborator(repo.ID, userID)
 }
@@ -95,6 +97,7 @@ type Collaborator struct {
 	Collaboration *Collaboration
 }
 
+// APIFormat for colloborator
 func (c *Collaborator) APIFormat() *api.Collaborator {
 	return &api.Collaborator{
 		User: c.User.APIFormat(),
@@ -224,6 +227,7 @@ func DeleteCollaboration(repo *Repository, userID int64) (err error) {
 	return sess.Commit()
 }
 
+// DeleteCollaboration removes collaboration relation between the user and repository.
 func (repo *Repository) DeleteCollaboration(userID int64) error {
 	return DeleteCollaboration(repo, userID)
 }

+ 10 - 0
models/repo_editor.go

@@ -27,6 +27,7 @@ import (
 	"gitlab.com/gitote/git-module"
 )
 
+// Enumerate all the env variable.
 const (
 	EnvAuthUserID         = "GITOTE_AUTH_USER_ID"
 	EnvAuthUsername       = "GITOTE_AUTH_USER_NAME"
@@ -38,6 +39,7 @@ const (
 	EnvRepoCustomHookPath = "GITOTE_REPO_CUSTOM_HOOKS_PATH"
 )
 
+// ComposeHookEnvsOptions holds hook envs.
 type ComposeHookEnvsOptions struct {
 	AuthUser  *User
 	OwnerName string
@@ -81,6 +83,8 @@ func discardLocalRepoBranchChanges(localPath, branch string) error {
 	return nil
 }
 
+// DiscardLocalRepoBranchChanges discards local commits/changes of
+// given branch to make sure it is even to remote branch.
 func (repo *Repository) DiscardLocalRepoBranchChanges(branch string) error {
 	return discardLocalRepoBranchChanges(repo.LocalCopyPath(), branch)
 }
@@ -97,10 +101,12 @@ func checkoutNewBranch(repoPath, localPath, oldBranch, newBranch string) error {
 	return nil
 }
 
+// CheckoutNewBranch checks out a new branch
 func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error {
 	return checkoutNewBranch(repo.RepoPath(), repo.LocalCopyPath(), oldBranch, newBranch)
 }
 
+// UpdateRepoFileOptions holds the repository file update options
 type UpdateRepoFileOptions struct {
 	LastCommitID string
 	OldBranch    string
@@ -236,6 +242,7 @@ func (repo *Repository) GetDiffPreview(branch, treePath, content string) (diff *
 	return diff, nil
 }
 
+// DeleteRepoFileOptions holds the repository delete file options
 type DeleteRepoFileOptions struct {
 	LastCommitID string
 	OldBranch    string
@@ -244,6 +251,7 @@ type DeleteRepoFileOptions struct {
 	Message      string
 }
 
+// DeleteRepoFile deletes a repository file
 func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (err error) {
 	repoWorkingPool.CheckIn(com.ToStr(repo.ID))
 	defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
@@ -413,6 +421,7 @@ func DeleteUploadByUUID(uuid string) error {
 	return nil
 }
 
+// UploadRepoFileOptions contains the uploaded repository file options
 type UploadRepoFileOptions struct {
 	LastCommitID string
 	OldBranch    string
@@ -422,6 +431,7 @@ type UploadRepoFileOptions struct {
 	Files        []string // In UUID format
 }
 
+// UploadRepoFiles uploads files to a repository
 func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions) (err error) {
 	if len(opts.Files) == 0 {
 		return nil