Skip to content

Commit

Permalink
Moar data in issue-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bkcsoft committed Dec 22, 2016
1 parent 8c6c1b3 commit d1b9b8c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
51 changes: 46 additions & 5 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,55 @@ func (c *Comment) AfterDelete() {
}
}

// HTMLURL formats a URL-string to the issue-comment
func (c *Comment) HTMLURL() string {
issue, err := GetIssueByID(c.IssueID)
if err != nil { // Silently dropping errors :unamused:
log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
return ""
}
return fmt.Sprintf("%s#issuecomment-%d", issue.HTMLURL(), c.ID)
}

// IssueURL formats a URL-string to the issue
func (c *Comment) IssueURL() string {
issue, err := GetIssueByID(c.IssueID)
if err != nil { // Silently dropping errors :unamused:
log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
return ""
}

if issue.IsPull {
return ""
}
return issue.HTMLURL()
}

// PRURL formats a URL-string to the pull-request
func (c *Comment) PRURL() string {
issue, err := GetIssueByID(c.IssueID)
if err != nil { // Silently dropping errors :unamused:
log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
return ""
}

if !issue.IsPull {
return ""
}
return issue.HTMLURL()
}

// APIFormat converts a Comment to the api.Comment format
func (c *Comment) APIFormat() *api.Comment {
return &api.Comment{
ID: c.ID,
Poster: c.Poster.APIFormat(),
Body: c.Content,
Created: c.Created,
Updated: c.Updated,
ID: c.ID,
Poster: c.Poster.APIFormat(),
HTMLURL: c.HTMLURL(),
IssueURL: c.IssueURL(),
PRURL: c.PRURL(),
Body: c.Content,
Created: c.Created,
Updated: c.Updated,
}
}

Expand Down
3 changes: 2 additions & 1 deletion routers/api/v1/repo/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
ctx.JSON(200, comment.APIFormat())
}

// DeleteIssueComment delete a comment from an issue
func DeleteIssueComment(ctx *context.APIContext) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil {
Expand All @@ -119,7 +120,7 @@ func DeleteIssueComment(ctx *context.APIContext) {
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
ctx.Status(403)
return
} else if comment.Type != models.COMMENT_TYPE_COMMENT {
} else if comment.Type != models.CommentTypeComment {
ctx.Status(204)
return
}
Expand Down

0 comments on commit d1b9b8c

Please sign in to comment.