Skip to content

Commit

Permalink
Use string enums
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 committed Dec 22, 2021
1 parent e8b65b3 commit 4dd46ef
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 46 deletions.
39 changes: 39 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,45 @@ const (
CommentTypeChangeIssueRef
)

func (t CommentType) String() string {
return []string{
"comment",
"reopen",
"close",
"issue_ref",
"commit_ref",
"comment_ref",
"pull_ref",
"label",
"milestone",
"assignees",
"change_title",
"delete_branch",
"start_tracking",
"stop_tracking",
"add_time_manual",
"cancel_tracking",
"added_deadline",
"modified_deadline",
"removed_deadline",
"add_dependency",
"remove_dependency",
"code",
"review",
"lock",
"unlock",
"change_target_branch",
"delete_time_manual",
"review_request",
"merge_pull",
"pull_push",
"project",
"project_board",
"dismiss_review",
"change_issue_ref",
}[t]
}

// RoleDescriptor defines comment tag type
type RoleDescriptor int

Expand Down
4 changes: 2 additions & 2 deletions modules/convert/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineCo

comment := &api.TimelineComment{
ID: c.ID,
Type: int64(c.Type),
Type: c.Type.String(),
Poster: ToUser(c.Poster, nil),
HTMLURL: c.HTMLURL(),
IssueURL: c.IssueURL(),
Expand All @@ -84,7 +84,7 @@ func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineCo
OldRef: c.OldRef,
NewRef: c.NewRef,

RefAction: int64(c.RefAction),
RefAction: c.RefAction.String(),
RefCommitSHA: c.CommitSHA,

ReviewID: c.ReviewID,
Expand Down
9 changes: 9 additions & 0 deletions modules/references/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ const (
XRefActionNeutered // 3
)

func (a XRefAction) String() string {
return []string{
"none",
"closes",
"reopens",
"neutered",
}[a]
}

// IssueReference contains an unverified cross-reference to a local issue or pull request
type IssueReference struct {
Index int64
Expand Down
47 changes: 3 additions & 44 deletions modules/structs/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,8 @@ type EditIssueCommentOption struct {

// TimelineComment represents a timeline comment (comment of any type) on a commit or issue
type TimelineComment struct {
ID int64 `json:"id"`

// Type specifies the type of an event.
// 0 Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
// 1 Reopen issue/pull request
// 2 Close issue/pull request
// 3 References.
// 4 Reference from a commit (not part of a pull request)
// 5 Reference from a comment
// 6 Reference from a pull request
// 7 Labels changed (if Body is "1", label was added, if not it was removed)
// 8 Milestone changed
// 9 Assignees changed
// 10 Change Title
// 11 Delete Branch
// 12 Start a stopwatch for time tracking
// 13 Stop a stopwatch for time tracking
// 14 Add time manual for time tracking
// 15 Cancel a stopwatch for time tracking
// 16 Added a due date
// 17 Modified the due date
// 18 Removed a due date
// 19 Dependency added
// 20 Dependency removed
// 21 Not returned; use review API to get more information
// 22 Reviews a pull request by giving general feedback; use review API to get more information
// 23 Lock an issue, giving only collaborators access
// 24 Unlocks a previously locked issue
// 25 Change pull request's target branch
// 26 Delete time manual for time tracking
// 27 add or remove Request from one
// 28 merge pull request
// 29 push to PR head branch (information about the push is included in Body)
// 30 Project changed
// 31 Project board changed
// 32 Dismiss Review
// 33 Change issue ref
Type int64 `json:"type"`
ID int64 `json:"id"`
Type string `json:"type"`

HTMLURL string `json:"html_url"`
PRURL string `json:"pull_request_url"`
Expand All @@ -99,12 +63,7 @@ type TimelineComment struct {

RefIssue *Issue `json:"ref_issue"`
RefComment *Comment `json:"ref_comment"`
// action that was used to reference issue/PR
// 0 means the cross-reference is simply a comment
// 1 means the cross-reference should close an issue if it is resolved
// 2 means the cross-reference should reopen an issue if it is resolved
// 3 means the cross-reference will no longer affect the source
RefAction int64 `json:"ref_action"`
RefAction string `json:"ref_action"`
// commit SHA where issue/PR was referenced
RefCommitSHA string `json:"ref_commit_sha"`

Expand Down

0 comments on commit 4dd46ef

Please sign in to comment.