Skip to content

Commit

Permalink
Use named ActionType constants in template helper (#2545)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethantkoenig authored and lunny committed Sep 20, 2017
1 parent 4eed85d commit acecedc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
5 changes: 2 additions & 3 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ func (a *Action) AfterSet(colName string, _ xorm.Cell) {
}

// GetOpType gets the ActionType of this action.
// TODO: change return type to ActionType ?
func (a *Action) GetOpType() int {
return int(a.OpType)
func (a *Action) GetOpType() ActionType {
return a.OpType
}

func (a *Action) loadActUser() {
Expand Down
23 changes: 11 additions & 12 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func RenderCommitMessage(full bool, msg, urlPrefix string, metas map[string]stri

// Actioner describes an action
type Actioner interface {
GetOpType() int
GetOpType() models.ActionType
GetActUserName() string
GetRepoUserName() string
GetRepoName() string
Expand All @@ -289,25 +289,24 @@ type Actioner interface {
GetIssueInfos() []string
}

// ActionIcon accepts a int that represents action operation type
// and returns a icon class name.
func ActionIcon(opType int) string {
// ActionIcon accepts an action operation type and returns an icon class name.
func ActionIcon(opType models.ActionType) string {
switch opType {
case 1, 8: // Create and transfer repository
case models.ActionCreateRepo, models.ActionTransferRepo:
return "repo"
case 5, 9: // Commit repository
case models.ActionCommitRepo, models.ActionPushTag:
return "git-commit"
case 6: // Create issue
case models.ActionCreateIssue:
return "issue-opened"
case 7: // New pull request
case models.ActionCreatePullRequest:
return "git-pull-request"
case 10: // Comment issue
case models.ActionCommentIssue:
return "comment-discussion"
case 11: // Merge pull request
case models.ActionMergePullRequest:
return "git-merge"
case 12, 14: // Close issue or pull request
case models.ActionCloseIssue, models.ActionClosePullRequest:
return "issue-closed"
case 13, 15: // Reopen issue or pull request
case models.ActionReopenIssue, models.ActionReopenPullRequest:
return "issue-reopened"
default:
return "invalid type"
Expand Down

0 comments on commit acecedc

Please sign in to comment.