Skip to content
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

Use named ActionType constants in template helper #2545

Merged
merged 2 commits into from
Sep 20, 2017
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
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