瀏覽代碼

Update GRC #100

Yoginth 7 年之前
父節點
當前提交
8c5dbd839f

+ 3 - 3
models/access.go

@@ -136,15 +136,15 @@ func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
 
 // GetAccessibleRepositories finds repositories which the user has access but does not own.
 // If limit is smaller than 1 means returns all found results.
-func (user *User) GetAccessibleRepositories(limit int) (repos []*Repository, _ error) {
-	sess := x.Where("owner_id !=? ", user.ID).Desc("updated_unix")
+func (u *User) GetAccessibleRepositories(limit int) (repos []*Repository, _ error) {
+	sess := x.Where("owner_id !=? ", u.ID).Desc("updated_unix")
 	if limit > 0 {
 		sess.Limit(limit)
 		repos = make([]*Repository, 0, limit)
 	} else {
 		repos = make([]*Repository, 0, 10)
 	}
-	return repos, sess.Join("INNER", "access", "access.user_id = ? AND access.repo_id = repository.id", user.ID).Find(&repos)
+	return repos, sess.Join("INNER", "access", "access.user_id = ? AND access.repo_id = repository.id", u.ID).Find(&repos)
 }
 
 func maxAccessMode(modes ...AccessMode) AccessMode {

+ 2 - 2
models/attachment.go

@@ -51,8 +51,8 @@ func AttachmentLocalPath(uuid string) string {
 }
 
 // LocalPath returns where attachment is stored in local file system.
-func (attach *Attachment) LocalPath() string {
-	return AttachmentLocalPath(attach.UUID)
+func (a *Attachment) LocalPath() string {
+	return AttachmentLocalPath(a.UUID)
 }
 
 // NewAttachment creates a new attachment object.

+ 1 - 3
models/login_source.go

@@ -388,10 +388,8 @@ func UpdateLoginSource(source *LoginSource) error {
 	if source.LocalFile == nil {
 		if _, err := x.Id(source.ID).AllCols().Update(source); err != nil {
 			return err
-		} else {
-			return ResetNonDefaultLoginSources(source)
 		}
-
+		return ResetNonDefaultLoginSources(source)
 	}
 
 	source.LocalFile.SetGeneral("name", source.Name)

+ 1 - 0
models/release.go

@@ -259,6 +259,7 @@ func GetDraftReleasesByRepoID(repoID int64) ([]*Release, error) {
 	return releases, x.Where("repo_id = ?", repoID).And("is_draft = ?", true).Find(&releases)
 }
 
+// ReleaseSorter represents release sorter
 type ReleaseSorter struct {
 	releases []*Release
 }

+ 21 - 9
models/repo.go

@@ -17,6 +17,8 @@ import (
 	"gitote/gitote/pkg/setting"
 	"gitote/gitote/pkg/sync"
 	"image"
+	
+	// Package jpeg implements a JPEG image decoder and encoder.
 	_ "image/jpeg"
 	"image/png"
 	"io/ioutil"
@@ -592,11 +594,13 @@ func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) strin
 	return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
 }
 
+// HasAccess returns if the user has access to the repository
 func (repo *Repository) HasAccess(userID int64) bool {
 	has, _ := HasAccess(userID, repo, AccessModeRead)
 	return has
 }
 
+// IsOwnedBy returns true when user owns this repository
 func (repo *Repository) IsOwnedBy(userID int64) bool {
 	return repo.OwnerID == userID
 }
@@ -611,11 +615,12 @@ func (repo *Repository) CanEnablePulls() bool {
 	return !repo.IsMirror && !repo.IsBare
 }
 
-// AllowPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
+// AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
 func (repo *Repository) AllowsPulls() bool {
 	return repo.CanEnablePulls() && repo.EnablePulls
 }
 
+// IsBranchRequirePullRequest returns true if brach require pull requests.
 func (repo *Repository) IsBranchRequirePullRequest(name string) bool {
 	return IsBranchOfRepoRequirePullRequest(repo.ID, name)
 }
@@ -625,12 +630,14 @@ func (repo *Repository) CanEnableEditor() bool {
 	return !repo.IsMirror
 }
 
+// NextIssueIndex returns the next issue index
 // FIXME: should have a mutex to prevent producing same index for two issues that are created
 // closely enough.
 func (repo *Repository) NextIssueIndex() int64 {
 	return int64(repo.NumIssues+repo.NumPulls) + 1
 }
 
+// LocalCopyPath returns the local repository copy path.
 func (repo *Repository) LocalCopyPath() string {
 	return path.Join(setting.AppDataPath, "tmp/local-repo", com.ToStr(repo.ID))
 }
@@ -749,6 +756,7 @@ func (repo *Repository) CloneLink() (cl *CloneLink) {
 	return repo.cloneLink(false)
 }
 
+// MigrateRepoOptions represents migrate repo options
 type MigrateRepoOptions struct {
 	Name        string
 	Description string
@@ -955,6 +963,7 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
 	return nil
 }
 
+// CreateRepoOptions contains the create repository options
 type CreateRepoOptions struct {
 	Name        string
 	Description string
@@ -1692,6 +1701,7 @@ func GetRepositoryByID(id int64) (*Repository, error) {
 	return getRepositoryByID(x, id)
 }
 
+// UserRepoOptions represents user repo options.
 type UserRepoOptions struct {
 	UserID   int64
 	Private  bool
@@ -1754,6 +1764,7 @@ func GetRepositoryCount(u *User) (int64, error) {
 	return getRepositoryCount(x, u)
 }
 
+// SearchRepoOptions represents search repo options.
 type SearchRepoOptions struct {
 	Keyword  string
 	OwnerID  int64
@@ -2140,6 +2151,7 @@ func CheckRepoStats() {
 	// ***** END: Repository.NumForks *****
 }
 
+// RepositoryList holds repository list
 type RepositoryList []*Repository
 
 func (repos RepositoryList) loadAttributes(e Engine) error {
@@ -2194,10 +2206,12 @@ func (repos RepositoryList) loadAttributes(e Engine) error {
 	return nil
 }
 
+// LoadAttributes loads all attributes
 func (repos RepositoryList) LoadAttributes() error {
 	return repos.loadAttributes(x)
 }
 
+// MirrorRepositoryList holds mirror repository list
 type MirrorRepositoryList []*Repository
 
 func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
@@ -2229,6 +2243,7 @@ func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
 	return nil
 }
 
+// LoadAttributes loads all attributes
 func (repos MirrorRepositoryList) LoadAttributes() error {
 	return repos.loadAttributes(x)
 }
@@ -2286,7 +2301,7 @@ func GetWatchers(repoID int64) ([]*Watch, error) {
 	return getWatchers(x, repoID)
 }
 
-// Repository.GetWatchers returns range of users watching given repository.
+// GetWatchers returns range of users watching given repository.
 func (repo *Repository) GetWatchers(page int) ([]*User, error) {
 	users := make([]*User, 0, ItemsPerPage)
 	sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("watch.repo_id=?", repo.ID)
@@ -2333,6 +2348,7 @@ func NotifyWatchers(act *Action) error {
 	return notifyWatchers(x, act)
 }
 
+// Star represents star onformation of repository.
 type Star struct {
 	ID     int64
 	UID    int64 `xorm:"UNIQUE(s)"`
@@ -2371,6 +2387,7 @@ func IsStaring(userID, repoID int64) bool {
 	return has
 }
 
+// GetStargazers returns the repository stars
 func (repo *Repository) GetStargazers(page int) ([]*User, error) {
 	users := make([]*User, 0, ItemsPerPage)
 	sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("star.repo_id=?", repo.ID)
@@ -2382,13 +2399,6 @@ func (repo *Repository) GetStargazers(page int) ([]*User, error) {
 	return users, sess.Find(&users)
 }
 
-// ___________           __
-// \_   _____/__________|  | __
-//  |    __)/  _ \_  __ \  |/ /
-//  |     \(  <_> )  | \/    <
-//  \___  / \____/|__|  |__|_ \
-//      \/                   \/
-
 // HasForkedRepo checks if given user has already forked a repository.
 // When user has already forked, it returns true along with the repository.
 func HasForkedRepo(ownerID, repoID int64) (*Repository, bool, error) {
@@ -2472,6 +2482,7 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string)
 	return repo, nil
 }
 
+// GetForks returns all the forks of the repository
 func (repo *Repository) GetForks() ([]*Repository, error) {
 	forks := make([]*Repository, 0, repo.NumForks)
 	if err := x.Find(&forks, &Repository{ForkID: repo.ID}); err != nil {
@@ -2484,6 +2495,7 @@ func (repo *Repository) GetForks() ([]*Repository, error) {
 	return forks, nil
 }
 
+// CreateNewBranch creates new branch
 func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName string) (err error) {
 	repoWorkingPool.CheckIn(com.ToStr(repo.ID))
 	defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))

+ 11 - 0
models/ssh_key.go

@@ -30,15 +30,20 @@ import (
 )
 
 const (
+	// TPLPublicKey specified template public key
 	TPLPublicKey = `command="%s serv key-%d --config='%s'",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s` + "\n"
 )
 
 var sshOpLocker sync.Mutex
 
+// KeyType specifies the key type
 type KeyType int
 
 const (
+	// KeyTypeUser specifies the user key
 	KeyTypeUser = iota + 1
+
+	// KeyTypeDeploy specifies the deploy key
 	KeyTypeDeploy
 )
 
@@ -60,14 +65,17 @@ type PublicKey struct {
 	HasUsed           bool `xorm:"-" json:"-"`
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (k *PublicKey) BeforeInsert() {
 	k.CreatedUnix = time.Now().Unix()
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (k *PublicKey) BeforeUpdate() {
 	k.UpdatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (k *PublicKey) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":
@@ -573,14 +581,17 @@ type DeployKey struct {
 	HasUsed           bool `xorm:"-" json:"-"`
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (k *DeployKey) BeforeInsert() {
 	k.CreatedUnix = time.Now().Unix()
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (k *DeployKey) BeforeUpdate() {
 	k.UpdatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (k *DeployKey) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":

+ 3 - 0
models/token.go

@@ -29,14 +29,17 @@ type AccessToken struct {
 	HasUsed           bool `xorm:"-" json:"-"`
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (t *AccessToken) BeforeInsert() {
 	t.CreatedUnix = time.Now().Unix()
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (t *AccessToken) BeforeUpdate() {
 	t.UpdatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (t *AccessToken) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":

+ 2 - 0
models/two_factor.go

@@ -30,10 +30,12 @@ type TwoFactor struct {
 	CreatedUnix int64
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (t *TwoFactor) BeforeInsert() {
 	t.CreatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (t *TwoFactor) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":

+ 1 - 0
models/update.go

@@ -46,6 +46,7 @@ func ListToPushCommits(l *list.List) *PushCommits {
 	return &PushCommits{l.Len(), commits, "", nil}
 }
 
+// PushUpdateOptions defines the push update options
 type PushUpdateOptions struct {
 	OldCommitID  string
 	NewCommitID  string

+ 27 - 10
models/user.go

@@ -18,6 +18,8 @@ import (
 	"gitote/gitote/pkg/setting"
 	"gitote/gitote/pkg/tool"
 	"image"
+
+	// Package jpeg implements a JPEG image decoder and encoder.
 	_ "image/jpeg"
 	"image/png"
 	"os"
@@ -39,10 +41,14 @@ import (
 // UserAvatarURLPrefix is used to identify a URL is to access user avatar.
 const UserAvatarURLPrefix = "avatars"
 
+// UserType defines the user type
 type UserType int
 
 const (
+	// UserTypeIndividual defines an individual user
 	UserTypeIndividual UserType = iota // Historic reason to make it starts at 0.
+
+	// UserTypeOrganization defines an organization
 	UserTypeOrganization
 )
 
@@ -138,11 +144,13 @@ type User struct {
 	ShowAds bool
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (u *User) BeforeInsert() {
 	u.CreatedUnix = time.Now().Unix()
 	u.UpdatedUnix = u.CreatedUnix
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (u *User) BeforeUpdate() {
 	if u.MaxRepoCreation < -1 {
 		u.MaxRepoCreation = -1
@@ -150,6 +158,7 @@ func (u *User) BeforeUpdate() {
 	u.UpdatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (u *User) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "created_unix":
@@ -164,6 +173,7 @@ func (u *User) IDStr() string {
 	return com.ToStr(u.ID)
 }
 
+// APIFormat converts a User to api.User
 func (u *User) APIFormat() *api.User {
 	return &api.User{
 		Login:        u.Name,
@@ -185,7 +195,7 @@ func (u *User) APIFormat() *api.User {
 	}
 }
 
-// returns true if user login type is LoginPlain.
+// IsLocal returns true if user login type is LoginPlain.
 func (u *User) IsLocal() bool {
 	return u.LoginType <= LoginPlain
 }
@@ -196,6 +206,7 @@ func (u *User) HasForkedRepo(repoID int64) bool {
 	return has
 }
 
+// RepoCreationNum returns the number of repositories a user is allowed to create
 func (u *User) RepoCreationNum() int {
 	if u.MaxRepoCreation <= -1 {
 		return setting.Repository.MaxCreationLimit
@@ -203,6 +214,7 @@ func (u *User) RepoCreationNum() int {
 	return u.MaxRepoCreation
 }
 
+// CanCreateRepo returns if user login can create a repository
 func (u *User) CanCreateRepo() bool {
 	if u.MaxRepoCreation <= -1 {
 		if setting.Repository.MaxCreationLimit <= -1 {
@@ -213,6 +225,7 @@ func (u *User) CanCreateRepo() bool {
 	return u.NumRepos < u.MaxRepoCreation
 }
 
+// CanCreateOrganization returns true if user can create organisation.
 func (u *User) CanCreateOrganization() bool {
 	return !setting.Admin.DisableRegularOrgCreation || u.IsAdmin
 }
@@ -240,6 +253,7 @@ func (u *User) HomeLink() string {
 	return setting.AppSubURL + "/" + u.Name
 }
 
+// HTMLURL returns the user or organization's full link.
 func (u *User) HTMLURL() string {
 	return setting.AppURL + u.Name
 }
@@ -297,15 +311,15 @@ func (u *User) GenerateRandomAvatar() error {
 // which includes app sub-url as prefix. However, it is possible
 // to return full URL if user enables Gravatar-like service.
 func (u *User) RelAvatarLink() string {
-	defaultImgUrl := "https://cdn.gitote.in/img/avatar_default.png"
+	defaultImgURL := "https://cdn.gitote.in/img/avatar_default.png"
 	if u.ID == -1 {
-		return defaultImgUrl
+		return defaultImgURL
 	}
 
 	switch {
 	case u.UseCustomAvatar:
 		if !com.IsExist(u.CustomAvatarPath()) {
-			return defaultImgUrl
+			return defaultImgURL
 		}
 		return fmt.Sprintf("%s/%s/%d", setting.AppSubURL, UserAvatarURLPrefix, u.ID)
 	case setting.DisableGravatar, setting.OfflineMode:
@@ -330,7 +344,7 @@ func (u *User) AvatarLink() string {
 	return link
 }
 
-// User.GetFollwoers returns range of user's followers.
+// GetFollowers returns range of user's followers.
 func (u *User) GetFollowers(page int) ([]*User, error) {
 	users := make([]*User, 0, ItemsPerPage)
 	sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("follow.follow_id=?", u.ID)
@@ -342,6 +356,7 @@ func (u *User) GetFollowers(page int) ([]*User, error) {
 	return users, sess.Find(&users)
 }
 
+// IsFollowing returns true if user is following followID.
 func (u *User) IsFollowing(followID int64) bool {
 	return IsFollowing(u.ID, followID)
 }
@@ -440,13 +455,13 @@ func (u *User) IsOrganization() bool {
 }
 
 // IsUserOrgOwner returns true if user is in the owner team of given organization.
-func (u *User) IsUserOrgOwner(orgId int64) bool {
-	return IsOrganizationOwner(orgId, u.ID)
+func (u *User) IsUserOrgOwner(orgID int64) bool {
+	return IsOrganizationOwner(orgID, u.ID)
 }
 
 // IsPublicMember returns true if user public his/her membership in give organization.
-func (u *User) IsPublicMember(orgId int64) bool {
-	return IsPublicMembership(orgId, u.ID)
+func (u *User) IsPublicMember(orgID int64) bool {
+	return IsPublicMembership(orgID, u.ID)
 }
 
 // IsEnabledTwoFactor returns true if user has enabled two-factor authentication.
@@ -474,7 +489,7 @@ func (u *User) GetRepositories(page, pageSize int) (err error) {
 	return err
 }
 
-// GetRepositories returns mirror repositories that user owns, including private repositories.
+// GetMirrorRepositories returns mirror repositories that user owns, including private repositories.
 func (u *User) GetMirrorRepositories() ([]*Repository, error) {
 	return GetUserMirrorRepositories(u.ID)
 }
@@ -511,6 +526,7 @@ func (u *User) DisplayName() string {
 	return u.Name
 }
 
+// ShortName ellipses username to length
 func (u *User) ShortName(length int) string {
 	return tool.EllipsisString(u.Name, length)
 }
@@ -1065,6 +1081,7 @@ func GetUserByEmail(email string) (*User, error) {
 	return nil, errors.UserNotExist{0, email}
 }
 
+// SearchUserOptions contains the options for searching
 type SearchUserOptions struct {
 	Keyword  string
 	Type     UserType

+ 2 - 1
models/user_mail.go

@@ -12,7 +12,7 @@ import (
 	"strings"
 )
 
-// EmailAdresses is the list of all email addresses of a user. Can contain the
+// EmailAddress is the list of all email addresses of a user. Can contain the
 // primary email address, but is not obligatory.
 type EmailAddress struct {
 	ID          int64
@@ -119,6 +119,7 @@ func AddEmailAddresses(emails []*EmailAddress) error {
 	return nil
 }
 
+// Activate activates the email address to given user.
 func (email *EmailAddress) Activate() error {
 	user, err := GetUserByID(email.UID)
 	if err != nil {

+ 31 - 9
models/webhook.go

@@ -28,18 +28,23 @@ import (
 	log "gopkg.in/clog.v1"
 )
 
+// HookQueue is a global queue of web hooks
 var HookQueue = sync.NewUniqueQueue(setting.Webhook.QueueLength)
 
+// HookContentType is the content type of a web hook
 type HookContentType int
 
 const (
-	JSON HookContentType = iota + 1
-	FORM
+	// ContentTypeJSON is a JSON payload for web hooks
+	ContentTypeJSON HookContentType = iota + 1
+
+	// ContentTypeForm is an url-encoded form payload for web hook
+	ContentTypeForm
 )
 
 var hookContentTypes = map[string]HookContentType{
-	"json": JSON,
-	"form": FORM,
+	"json": ContentTypeJSON,
+	"form": ContentTypeForm,
 }
 
 // ToHookContentType returns HookContentType by given name.
@@ -47,11 +52,12 @@ func ToHookContentType(name string) HookContentType {
 	return hookContentTypes[name]
 }
 
+// Name returns the name of a given web hook's content type
 func (t HookContentType) Name() string {
 	switch t {
-	case JSON:
+	case ContentTypeJSON:
 		return "json"
-	case FORM:
+	case ContentTypeForm:
 		return "form"
 	}
 	return ""
@@ -63,6 +69,7 @@ func IsValidHookContentType(name string) bool {
 	return ok
 }
 
+// HookEvents is a set of web hook events
 type HookEvents struct {
 	Create       bool `json:"create"`
 	Delete       bool `json:"delete"`
@@ -83,8 +90,10 @@ type HookEvent struct {
 	HookEvents `json:"events"`
 }
 
+// HookStatus is the status of a web hook
 type HookStatus int
 
+// Possible statuses of a web hook
 const (
 	HookStatusNone = iota
 	HookStatusSucceed
@@ -100,7 +109,7 @@ type Webhook struct {
 	ContentType  HookContentType
 	Secret       string     `xorm:"TEXT"`
 	Events       string     `xorm:"TEXT"`
-	*HookEvent   `xorm:"-"` // LEGACY [1.0]: Cannot ignore JSON here, it breaks old backup archive
+	*HookEvent   `xorm:"-"` // LEGACY [1.0]: Cannot ignore ContentTypeJSON here, it breaks old backup archive
 	IsSSL        bool       `xorm:"is_ssl"`
 	IsActive     bool
 	HookTaskType HookTaskType
@@ -113,15 +122,18 @@ type Webhook struct {
 	UpdatedUnix int64
 }
 
+// BeforeInsert will be invoked by XORM before inserting a record
 func (w *Webhook) BeforeInsert() {
 	w.CreatedUnix = time.Now().Unix()
 	w.UpdatedUnix = w.CreatedUnix
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (w *Webhook) BeforeUpdate() {
 	w.UpdatedUnix = time.Now().Unix()
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (w *Webhook) AfterSet(colName string, _ xorm.Cell) {
 	var err error
 	switch colName {
@@ -138,6 +150,7 @@ func (w *Webhook) AfterSet(colName string, _ xorm.Cell) {
 	}
 }
 
+// GetSlackHook returns slack metadata
 func (w *Webhook) GetSlackHook() *SlackMeta {
 	s := &SlackMeta{}
 	if err := jsoniter.Unmarshal([]byte(w.Meta), s); err != nil {
@@ -212,6 +225,7 @@ type eventChecker struct {
 	typ     HookEventType
 }
 
+// EventsArray returns an array of hook events
 func (w *Webhook) EventsArray() []string {
 	events := make([]string, 0, 8)
 	eventCheckers := []eventChecker{
@@ -339,8 +353,10 @@ func getActiveWebhooksByOrgID(e Engine, orgID int64) ([]*Webhook, error) {
 	return ws, e.Where("org_id=?", orgID).And("is_active=?", true).Find(&ws)
 }
 
+// HookTaskType is the type of an hook task
 type HookTaskType int
 
+// Types of hook tasks
 const (
 	GITOTE HookTaskType = iota + 1
 	SLACK
@@ -358,6 +374,7 @@ func ToHookTaskType(name string) HookTaskType {
 	return hookTaskTypes[name]
 }
 
+// Name returns the name of an hook task type
 func (t HookTaskType) Name() string {
 	switch t {
 	case GITOTE:
@@ -376,8 +393,10 @@ func IsValidHookTaskType(name string) bool {
 	return ok
 }
 
+// HookEventType is the type of an hook event
 type HookEventType string
 
+// Types of hook events
 const (
 	HookEventCreate       HookEventType = "create"
 	HookEventDelete       HookEventType = "delete"
@@ -427,6 +446,7 @@ type HookTask struct {
 	ResponseInfo    *HookResponse `xorm:"-" json:"-"`
 }
 
+// BeforeUpdate is invoked from XORM before updating this object.
 func (t *HookTask) BeforeUpdate() {
 	if t.RequestInfo != nil {
 		t.RequestContent = t.MarshalJSON(t.RequestInfo)
@@ -436,6 +456,7 @@ func (t *HookTask) BeforeUpdate() {
 	}
 }
 
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
 func (t *HookTask) AfterSet(colName string, _ xorm.Cell) {
 	var err error
 	switch colName {
@@ -466,6 +487,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) {
 	}
 }
 
+// MarshalJSON encode to JSON
 func (t *HookTask) MarshalJSON(v interface{}) string {
 	p, err := jsoniter.Marshal(v)
 	if err != nil {
@@ -653,9 +675,9 @@ func (t *HookTask) deliver() {
 		SetTLSClientConfig(&tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify})
 
 	switch t.ContentType {
-	case JSON:
+	case ContentTypeJSON:
 		req = req.Header("Content-Type", "application/json").Body(t.PayloadContent)
-	case FORM:
+	case ContentTypeForm:
 		req.Param("payload", t.PayloadContent)
 	}
 

+ 6 - 0
models/webhook_discord.go

@@ -17,21 +17,25 @@ import (
 	api "gitlab.com/gitote/go-gitote-client"
 )
 
+// DiscordEmbedFooterObject for Embed Footer Structure.
 type DiscordEmbedFooterObject struct {
 	Text string `json:"text"`
 }
 
+// DiscordEmbedAuthorObject for Embed Author Structure.
 type DiscordEmbedAuthorObject struct {
 	Name    string `json:"name"`
 	URL     string `json:"url"`
 	IconURL string `json:"icon_url"`
 }
 
+// DiscordEmbedFieldObject for Embed Field Structure
 type DiscordEmbedFieldObject struct {
 	Name  string `json:"name"`
 	Value string `json:"value"`
 }
 
+// DiscordEmbedObject is for Embed Structure
 type DiscordEmbedObject struct {
 	Title       string                     `json:"title"`
 	Description string                     `json:"description"`
@@ -42,6 +46,7 @@ type DiscordEmbedObject struct {
 	Fields      []*DiscordEmbedFieldObject `json:"fields"`
 }
 
+// DiscordPayload represents
 type DiscordPayload struct {
 	Content   string                `json:"content"`
 	Username  string                `json:"username"`
@@ -49,6 +54,7 @@ type DiscordPayload struct {
 	Embeds    []*DiscordEmbedObject `json:"embeds"`
 }
 
+// JSONPayload Marshals the DiscordPayload to json
 func (p *DiscordPayload) JSONPayload() ([]byte, error) {
 	data, err := jsoniter.MarshalIndent(p, "", "  ")
 	if err != nil {

+ 4 - 0
models/webhook_slack.go

@@ -16,6 +16,7 @@ import (
 	api "gitlab.com/gitote/go-gitote-client"
 )
 
+// SlackMeta contains the slack metadata
 type SlackMeta struct {
 	Channel  string `json:"channel"`
 	Username string `json:"username"`
@@ -23,6 +24,7 @@ type SlackMeta struct {
 	Color    string `json:"color"`
 }
 
+// SlackAttachment contains the slack message
 type SlackAttachment struct {
 	Fallback string `json:"fallback"`
 	Color    string `json:"color"`
@@ -30,6 +32,7 @@ type SlackAttachment struct {
 	Text     string `json:"text"`
 }
 
+// SlackPayload contains the information about the slack channel
 type SlackPayload struct {
 	Channel     string             `json:"channel"`
 	Text        string             `json:"text"`
@@ -40,6 +43,7 @@ type SlackPayload struct {
 	Attachments []*SlackAttachment `json:"attachments"`
 }
 
+// JSONPayload Marshals the SlackPayload to json
 func (p *SlackPayload) JSONPayload() ([]byte, error) {
 	data, err := jsoniter.MarshalIndent(p, "", "  ")
 	if err != nil {

+ 6 - 0
models/wiki.go

@@ -46,6 +46,7 @@ func WikiPath(userName, repoName string) string {
 	return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".wiki.git")
 }
 
+// WikiPath returns wiki data path for given repository.
 func (repo *Repository) WikiPath() string {
 	return WikiPath(repo.MustOwner().Name, repo.Name)
 }
@@ -70,6 +71,7 @@ func (repo *Repository) InitWiki() error {
 	return nil
 }
 
+// LocalWikiPath returns the path to the local wiki repository (?).
 func (repo *Repository) LocalWikiPath() string {
 	return path.Join(setting.AppDataPath, "tmp/local-wiki", com.ToStr(repo.ID))
 }
@@ -139,14 +141,18 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes
 	return nil
 }
 
+// AddWikiPage adds a new wiki page with a given wikiPath.
 func (repo *Repository) AddWikiPage(doer *User, title, content, message string) error {
 	return repo.updateWikiPage(doer, "", title, content, message, true)
 }
 
+// EditWikiPage updates a wiki page identified by its wikiPath,
+// optionally also changing wikiPath.
 func (repo *Repository) EditWikiPage(doer *User, oldTitle, title, content, message string) error {
 	return repo.updateWikiPage(doer, oldTitle, title, content, message, false)
 }
 
+// DeleteWikiPage deletes a wiki page identified by its path.
 func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) {
 	wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
 	defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))

+ 8 - 8
routes/repo/webhook.go

@@ -148,9 +148,9 @@ func WebHooksNewPost(c *context.Context, f form.NewWebhook) {
 		return
 	}
 
-	contentType := models.JSON
-	if models.HookContentType(f.ContentType) == models.FORM {
-		contentType = models.FORM
+	contentType := models.ContentTypeJSON
+	if models.HookContentType(f.ContentType) == models.ContentTypeForm {
+		contentType = models.ContentTypeForm
 	}
 
 	w := &models.Webhook{
@@ -207,7 +207,7 @@ func SlackHooksNewPost(c *context.Context, f form.NewSlackHook) {
 	w := &models.Webhook{
 		RepoID:       orCtx.RepoID,
 		URL:          f.PayloadURL,
-		ContentType:  models.JSON,
+		ContentType:  models.ContentTypeJSON,
 		HookEvent:    ParseHookEvent(f.Webhook),
 		IsActive:     f.Active,
 		HookTaskType: models.SLACK,
@@ -257,7 +257,7 @@ func DiscordHooksNewPost(c *context.Context, f form.NewDiscordHook) {
 	w := &models.Webhook{
 		RepoID:       orCtx.RepoID,
 		URL:          f.PayloadURL,
-		ContentType:  models.JSON,
+		ContentType:  models.ContentTypeJSON,
 		HookEvent:    ParseHookEvent(f.Webhook),
 		IsActive:     f.Active,
 		HookTaskType: models.DISCORD,
@@ -346,9 +346,9 @@ func WebHooksEditPost(c *context.Context, f form.NewWebhook) {
 		return
 	}
 
-	contentType := models.JSON
-	if models.HookContentType(f.ContentType) == models.FORM {
-		contentType = models.FORM
+	contentType := models.ContentTypeJSON
+	if models.HookContentType(f.ContentType) == models.ContentTypeForm {
+		contentType = models.ContentTypeForm
 	}
 
 	w.URL = f.PayloadURL