Skip to content

Use MixedCase constant names #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func parseCmd(cmd string) (string, string) {

var (
allowedCommands = map[string]models.AccessMode{
"git-upload-pack": models.ACCESS_MODE_READ,
"git-upload-archive": models.ACCESS_MODE_READ,
"git-receive-pack": models.ACCESS_MODE_WRITE,
"git-upload-pack": models.AccessModeRead,
"git-upload-archive": models.AccessModeRead,
"git-receive-pack": models.AccessModeWrite,
}
)

Expand Down Expand Up @@ -191,7 +191,7 @@ func runServ(c *cli.Context) error {
}

// Prohibit push to mirror repositories.
if requestedMode > models.ACCESS_MODE_READ && repo.IsMirror {
if requestedMode > models.AccessModeRead && repo.IsMirror {
fail("mirror repository is read-only", "")
}

Expand All @@ -200,7 +200,7 @@ func runServ(c *cli.Context) error {
keyID int64
user *models.User
)
if requestedMode == models.ACCESS_MODE_WRITE || repo.IsPrivate {
if requestedMode == models.AccessModeWrite || repo.IsPrivate {
keys := strings.Split(c.Args()[0], "-")
if len(keys) != 2 {
fail("Key ID format error", "Invalid key argument: %s", c.Args()[0])
Expand All @@ -213,7 +213,7 @@ func runServ(c *cli.Context) error {
keyID = key.ID

// Check deploy key or user key.
if key.Type == models.KEY_TYPE_DEPLOY {
if key.Type == models.KeyTypeDeploy {
if key.Mode < requestedMode {
fail("Key permission denied", "Cannot push with deployment key: %d", key.ID)
}
Expand Down Expand Up @@ -243,7 +243,7 @@ func runServ(c *cli.Context) error {
fail("Internal error", "Fail to check access: %v", err)
} else if mode < requestedMode {
clientMessage := accessDenied
if mode >= models.ACCESS_MODE_READ {
if mode >= models.AccessModeRead {
clientMessage = "You do not have sufficient authorization for this action"
}
fail(clientMessage,
Expand Down Expand Up @@ -276,7 +276,7 @@ func runServ(c *cli.Context) error {
fail("Internal error", "Failed to execute git command: %v", err)
}

if requestedMode == models.ACCESS_MODE_WRITE {
if requestedMode == models.AccessModeWrite {
handleUpdateTask(uuid, user, repoUser, reponame, isUncyclo)
}

Expand Down
38 changes: 19 additions & 19 deletions models/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ import (
type AccessMode int

const (
ACCESS_MODE_NONE AccessMode = iota // 0
ACCESS_MODE_READ // 1
ACCESS_MODE_WRITE // 2
ACCESS_MODE_ADMIN // 3
ACCESS_MODE_OWNER // 4
AccessModeNone AccessMode = iota // 0
AccessModeRead // 1
AccessModeWrite // 2
AccessModeAdmin // 3
AccessModeOwner // 4
)

func (mode AccessMode) String() string {
switch mode {
case ACCESS_MODE_READ:
case AccessModeRead:
return "read"
case ACCESS_MODE_WRITE:
case AccessModeWrite:
return "write"
case ACCESS_MODE_ADMIN:
case AccessModeAdmin:
return "admin"
case ACCESS_MODE_OWNER:
case AccessModeOwner:
return "owner"
default:
return "none"
Expand All @@ -39,11 +39,11 @@ func (mode AccessMode) String() string {
func ParseAccessMode(permission string) AccessMode {
switch permission {
case "write":
return ACCESS_MODE_WRITE
return AccessModeWrite
case "admin":
return ACCESS_MODE_ADMIN
return AccessModeAdmin
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not exactly related, but shouldn't this function have

case "owner":
    return AccessModeOwner

as well?

return ACCESS_MODE_READ
return AccessModeRead
}
}

Expand All @@ -58,17 +58,17 @@ type Access struct {
}

func accessLevel(e Engine, u *User, repo *Repository) (AccessMode, error) {
mode := ACCESS_MODE_NONE
mode := AccessModeNone
if !repo.IsPrivate {
mode = ACCESS_MODE_READ
mode = AccessModeRead
}

if u == nil {
return mode, nil
}

if u.ID == repo.OwnerID {
return ACCESS_MODE_OWNER, nil
return AccessModeOwner, nil
}

a := &Access{UserID: u.ID, RepoID: repo.ID}
Expand Down Expand Up @@ -135,7 +135,7 @@ func (user *User) GetAccessibleRepositories(limit int) (repos []*Repository, _ e
}

func maxAccessMode(modes ...AccessMode) AccessMode {
max := ACCESS_MODE_NONE
max := AccessModeNone
for _, mode := range modes {
if mode > max {
max = mode
Expand All @@ -146,9 +146,9 @@ func maxAccessMode(modes ...AccessMode) AccessMode {

// FIXME: do corss-comparison so reduce deletions and additions to the minimum?
func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]AccessMode) (err error) {
minMode := ACCESS_MODE_READ
minMode := AccessModeRead
if !repo.IsPrivate {
minMode = ACCESS_MODE_WRITE
minMode = AccessModeWrite
}

newAccesses := make([]Access, 0, len(accessMap))
Expand Down Expand Up @@ -212,7 +212,7 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err
// Owner team gets owner access, and skip for teams that do not
// have relations with repository.
if t.IsOwnerTeam() {
t.Authorize = ACCESS_MODE_OWNER
t.Authorize = AccessModeOwner
} else if !t.hasRepository(e, repo.ID) {
continue
}
Expand Down
52 changes: 26 additions & 26 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ import (
type ActionType int

const (
ACTION_CREATE_REPO ActionType = iota + 1 // 1
ACTION_RENAME_REPO // 2
ACTION_STAR_REPO // 3
ACTION_WATCH_REPO // 4
ACTION_COMMIT_REPO // 5
ACTION_CREATE_ISSUE // 6
ACTION_CREATE_PULL_REQUEST // 7
ACTION_TRANSFER_REPO // 8
ACTION_PUSH_TAG // 9
ACTION_COMMENT_ISSUE // 10
ACTION_MERGE_PULL_REQUEST // 11
ACTION_CLOSE_ISSUE // 12
ACTION_REOPEN_ISSUE // 13
ACTION_CLOSE_PULL_REQUEST // 14
ACTION_REOPEN_PULL_REQUEST // 15
ActionCreateRepo ActionType = iota + 1 // 1
ActionRenameRepo // 2
ActionStarRepo // 3
ActionWatchRepo // 4
ActionCommitRepo // 5
ActionCreateIssue // 6
ActionCreatePullRequest // 7
ActionTransferRepo // 8
ActionPushTag // 9
ActionCommentIssue // 10
ActionMergePullRequest // 11
ActionCloseIssue // 12
ActionReopenIssue // 13
ActionClosePullRequest // 14
ActionReopenPullRequest // 15
)

var (
Expand Down Expand Up @@ -176,7 +176,7 @@ func newRepoAction(e Engine, u *User, repo *Repository) (err error) {
if err = notifyWatchers(e, &Action{
ActUserID: u.ID,
ActUserName: u.Name,
OpType: ACTION_CREATE_REPO,
OpType: ActionCreateRepo,
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
Expand All @@ -198,7 +198,7 @@ func renameRepoAction(e Engine, actUser *User, oldRepoName string, repo *Reposit
if err = notifyWatchers(e, &Action{
ActUserID: actUser.ID,
ActUserName: actUser.Name,
OpType: ACTION_RENAME_REPO,
OpType: ActionRenameRepo,
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
Expand Down Expand Up @@ -454,10 +454,10 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
}

isNewBranch := false
opType := ACTION_COMMIT_REPO
opType := ActionCommitRepo
// Check it's tag push or branch.
if strings.HasPrefix(opts.RefFullName, git.TAG_PREFIX) {
opType = ACTION_PUSH_TAG
opType = ActionPushTag
opts.Commits = &PushCommits{}
} else {
// if not the first commit, set the compare URL.
Expand Down Expand Up @@ -503,8 +503,8 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
apiPusher := pusher.APIFormat()
apiRepo := repo.APIFormat(nil)
switch opType {
case ACTION_COMMIT_REPO: // Push
if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, &api.PushPayload{
case ActionCommitRepo: // Push
if err = PrepareWebhooks(repo, HookEventPush, &api.PushPayload{
Ref: opts.RefFullName,
Before: opts.OldCommitID,
After: opts.NewCommitID,
Expand All @@ -518,16 +518,16 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
}

if isNewBranch {
return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
return PrepareWebhooks(repo, HookEventCreate, &api.CreatePayload{
Ref: refName,
RefType: "branch",
Repo: apiRepo,
Sender: apiPusher,
})
}

case ACTION_PUSH_TAG: // Create
return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
case ActionPushTag: // Create
return PrepareWebhooks(repo, HookEventCreate, &api.CreatePayload{
Ref: refName,
RefType: "tag",
Repo: apiRepo,
Expand All @@ -542,7 +542,7 @@ func transferRepoAction(e Engine, doer, oldOwner *User, repo *Repository) (err e
if err = notifyWatchers(e, &Action{
ActUserID: doer.ID,
ActUserName: doer.Name,
OpType: ACTION_TRANSFER_REPO,
OpType: ActionTransferRepo,
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
Expand Down Expand Up @@ -572,7 +572,7 @@ func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue
return notifyWatchers(e, &Action{
ActUserID: doer.ID,
ActUserName: doer.Name,
OpType: ACTION_MERGE_PULL_REQUEST,
OpType: ActionMergePullRequest,
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
Expand Down
6 changes: 3 additions & 3 deletions models/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type NoticeType int

const (
NOTICE_REPOSITORY NoticeType = iota + 1
NoticeRepository NoticeType = iota + 1
)

// Notice represents a system notice for admin.
Expand Down Expand Up @@ -65,9 +65,9 @@ func CreateNotice(tp NoticeType, desc string) error {
return err
}

// CreateRepositoryNotice creates new system notice with type NOTICE_REPOSITORY.
// CreateRepositoryNotice creates new system notice with type NoticeRepository.
func CreateRepositoryNotice(desc string) error {
return CreateNotice(NOTICE_REPOSITORY, desc)
return CreateNotice(NoticeRepository, desc)
}

// RemoveAllWithNotice removes all directories in given path and
Expand Down
Loading