Skip to content

Commit 4dd46ef

Browse files
committed
Use string enums
1 parent e8b65b3 commit 4dd46ef

File tree

4 files changed

+53
-46
lines changed

4 files changed

+53
-46
lines changed

models/issue_comment.go

+39
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,45 @@ const (
110110
CommentTypeChangeIssueRef
111111
)
112112

113+
func (t CommentType) String() string {
114+
return []string{
115+
"comment",
116+
"reopen",
117+
"close",
118+
"issue_ref",
119+
"commit_ref",
120+
"comment_ref",
121+
"pull_ref",
122+
"label",
123+
"milestone",
124+
"assignees",
125+
"change_title",
126+
"delete_branch",
127+
"start_tracking",
128+
"stop_tracking",
129+
"add_time_manual",
130+
"cancel_tracking",
131+
"added_deadline",
132+
"modified_deadline",
133+
"removed_deadline",
134+
"add_dependency",
135+
"remove_dependency",
136+
"code",
137+
"review",
138+
"lock",
139+
"unlock",
140+
"change_target_branch",
141+
"delete_time_manual",
142+
"review_request",
143+
"merge_pull",
144+
"pull_push",
145+
"project",
146+
"project_board",
147+
"dismiss_review",
148+
"change_issue_ref",
149+
}[t]
150+
}
151+
113152
// RoleDescriptor defines comment tag type
114153
type RoleDescriptor int
115154

modules/convert/issue_comment.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineCo
6666

6767
comment := &api.TimelineComment{
6868
ID: c.ID,
69-
Type: int64(c.Type),
69+
Type: c.Type.String(),
7070
Poster: ToUser(c.Poster, nil),
7171
HTMLURL: c.HTMLURL(),
7272
IssueURL: c.IssueURL(),
@@ -84,7 +84,7 @@ func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineCo
8484
OldRef: c.OldRef,
8585
NewRef: c.NewRef,
8686

87-
RefAction: int64(c.RefAction),
87+
RefAction: c.RefAction.String(),
8888
RefCommitSHA: c.CommitSHA,
8989

9090
ReviewID: c.ReviewID,

modules/references/references.go

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ const (
6565
XRefActionNeutered // 3
6666
)
6767

68+
func (a XRefAction) String() string {
69+
return []string{
70+
"none",
71+
"closes",
72+
"reopens",
73+
"neutered",
74+
}[a]
75+
}
76+
6877
// IssueReference contains an unverified cross-reference to a local issue or pull request
6978
type IssueReference struct {
7079
Index int64

modules/structs/issue_comment.go

+3-44
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,8 @@ type EditIssueCommentOption struct {
3838

3939
// TimelineComment represents a timeline comment (comment of any type) on a commit or issue
4040
type TimelineComment struct {
41-
ID int64 `json:"id"`
42-
43-
// Type specifies the type of an event.
44-
// 0 Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
45-
// 1 Reopen issue/pull request
46-
// 2 Close issue/pull request
47-
// 3 References.
48-
// 4 Reference from a commit (not part of a pull request)
49-
// 5 Reference from a comment
50-
// 6 Reference from a pull request
51-
// 7 Labels changed (if Body is "1", label was added, if not it was removed)
52-
// 8 Milestone changed
53-
// 9 Assignees changed
54-
// 10 Change Title
55-
// 11 Delete Branch
56-
// 12 Start a stopwatch for time tracking
57-
// 13 Stop a stopwatch for time tracking
58-
// 14 Add time manual for time tracking
59-
// 15 Cancel a stopwatch for time tracking
60-
// 16 Added a due date
61-
// 17 Modified the due date
62-
// 18 Removed a due date
63-
// 19 Dependency added
64-
// 20 Dependency removed
65-
// 21 Not returned; use review API to get more information
66-
// 22 Reviews a pull request by giving general feedback; use review API to get more information
67-
// 23 Lock an issue, giving only collaborators access
68-
// 24 Unlocks a previously locked issue
69-
// 25 Change pull request's target branch
70-
// 26 Delete time manual for time tracking
71-
// 27 add or remove Request from one
72-
// 28 merge pull request
73-
// 29 push to PR head branch (information about the push is included in Body)
74-
// 30 Project changed
75-
// 31 Project board changed
76-
// 32 Dismiss Review
77-
// 33 Change issue ref
78-
Type int64 `json:"type"`
41+
ID int64 `json:"id"`
42+
Type string `json:"type"`
7943

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

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

0 commit comments

Comments
 (0)