Skip to content

Commit d1b9b8c

Browse files
committed
Moar data in issue-comments
1 parent 8c6c1b3 commit d1b9b8c

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

Diff for: models/issue_comment.go

+46-5
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,55 @@ func (c *Comment) AfterDelete() {
123123
}
124124
}
125125

126+
// HTMLURL formats a URL-string to the issue-comment
127+
func (c *Comment) HTMLURL() string {
128+
issue, err := GetIssueByID(c.IssueID)
129+
if err != nil { // Silently dropping errors :unamused:
130+
log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
131+
return ""
132+
}
133+
return fmt.Sprintf("%s#issuecomment-%d", issue.HTMLURL(), c.ID)
134+
}
135+
136+
// IssueURL formats a URL-string to the issue
137+
func (c *Comment) IssueURL() string {
138+
issue, err := GetIssueByID(c.IssueID)
139+
if err != nil { // Silently dropping errors :unamused:
140+
log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
141+
return ""
142+
}
143+
144+
if issue.IsPull {
145+
return ""
146+
}
147+
return issue.HTMLURL()
148+
}
149+
150+
// PRURL formats a URL-string to the pull-request
151+
func (c *Comment) PRURL() string {
152+
issue, err := GetIssueByID(c.IssueID)
153+
if err != nil { // Silently dropping errors :unamused:
154+
log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
155+
return ""
156+
}
157+
158+
if !issue.IsPull {
159+
return ""
160+
}
161+
return issue.HTMLURL()
162+
}
163+
126164
// APIFormat converts a Comment to the api.Comment format
127165
func (c *Comment) APIFormat() *api.Comment {
128166
return &api.Comment{
129-
ID: c.ID,
130-
Poster: c.Poster.APIFormat(),
131-
Body: c.Content,
132-
Created: c.Created,
133-
Updated: c.Updated,
167+
ID: c.ID,
168+
Poster: c.Poster.APIFormat(),
169+
HTMLURL: c.HTMLURL(),
170+
IssueURL: c.IssueURL(),
171+
PRURL: c.PRURL(),
172+
Body: c.Content,
173+
Created: c.Created,
174+
Updated: c.Updated,
134175
}
135176
}
136177

Diff for: routers/api/v1/repo/issue_comment.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
105105
ctx.JSON(200, comment.APIFormat())
106106
}
107107

108+
// DeleteIssueComment delete a comment from an issue
108109
func DeleteIssueComment(ctx *context.APIContext) {
109110
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
110111
if err != nil {
@@ -119,7 +120,7 @@ func DeleteIssueComment(ctx *context.APIContext) {
119120
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
120121
ctx.Status(403)
121122
return
122-
} else if comment.Type != models.COMMENT_TYPE_COMMENT {
123+
} else if comment.Type != models.CommentTypeComment {
123124
ctx.Status(204)
124125
return
125126
}

0 commit comments

Comments
 (0)