* use e if it is an option * potential nil so check err first * check err first * m == nil already checked
This commit is contained in:
parent
c6b78c3d31
commit
11300ee582
6 changed files with 13 additions and 9 deletions
|
@ -215,7 +215,7 @@ func (a *Action) getCommentLink(e Engine) string {
|
||||||
return "#"
|
return "#"
|
||||||
}
|
}
|
||||||
if a.Comment == nil && a.CommentID != 0 {
|
if a.Comment == nil && a.CommentID != 0 {
|
||||||
a.Comment, _ = GetCommentByID(a.CommentID)
|
a.Comment, _ = getCommentByID(e, a.CommentID)
|
||||||
}
|
}
|
||||||
if a.Comment != nil {
|
if a.Comment != nil {
|
||||||
return a.Comment.HTMLURL()
|
return a.Comment.HTMLURL()
|
||||||
|
|
|
@ -199,7 +199,7 @@ func GetAttachmentsByCommentID(commentID int64) ([]*Attachment, error) {
|
||||||
|
|
||||||
func getAttachmentsByCommentID(e Engine, commentID int64) ([]*Attachment, error) {
|
func getAttachmentsByCommentID(e Engine, commentID int64) ([]*Attachment, error) {
|
||||||
attachments := make([]*Attachment, 0, 10)
|
attachments := make([]*Attachment, 0, 10)
|
||||||
return attachments, x.Where("comment_id=?", commentID).Find(&attachments)
|
return attachments, e.Where("comment_id=?", commentID).Find(&attachments)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getAttachmentByReleaseIDFileName return a file based on the the following infos:
|
// getAttachmentByReleaseIDFileName return a file based on the the following infos:
|
||||||
|
|
|
@ -749,8 +749,12 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi
|
||||||
|
|
||||||
// GetCommentByID returns the comment by given ID.
|
// GetCommentByID returns the comment by given ID.
|
||||||
func GetCommentByID(id int64) (*Comment, error) {
|
func GetCommentByID(id int64) (*Comment, error) {
|
||||||
|
return getCommentByID(x, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCommentByID(e Engine, id int64) (*Comment, error) {
|
||||||
c := new(Comment)
|
c := new(Comment)
|
||||||
has, err := x.ID(id).Get(c)
|
has, err := e.ID(id).Get(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
|
|
|
@ -108,7 +108,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
|
||||||
}
|
}
|
||||||
at := bytes.IndexByte(line, '@')
|
at := bytes.IndexByte(line, '@')
|
||||||
m = []int{0, stop, at, stop - 1}
|
m = []int{0, stop, at, stop - 1}
|
||||||
if m == nil || bytes.IndexByte(line[m[2]:m[3]], '.') < 0 {
|
if bytes.IndexByte(line[m[2]:m[3]], '.') < 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
lastChar := line[m[1]-1]
|
lastChar := line[m[1]-1]
|
||||||
|
|
|
@ -70,14 +70,14 @@ func UploadAttachment(ctx *context.Context) {
|
||||||
func DeleteAttachment(ctx *context.Context) {
|
func DeleteAttachment(ctx *context.Context) {
|
||||||
file := ctx.Query("file")
|
file := ctx.Query("file")
|
||||||
attach, err := models.GetAttachmentByUUID(file)
|
attach, err := models.GetAttachmentByUUID(file)
|
||||||
if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) {
|
|
||||||
ctx.Error(403)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(400, err.Error())
|
ctx.Error(400, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) {
|
||||||
|
ctx.Error(403)
|
||||||
|
return
|
||||||
|
}
|
||||||
err = models.DeleteAttachment(attach, true)
|
err = models.DeleteAttachment(attach, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err))
|
ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err))
|
||||||
|
|
|
@ -237,11 +237,11 @@ func Diff(ctx *context.Context) {
|
||||||
parents := make([]string, commit.ParentCount())
|
parents := make([]string, commit.ParentCount())
|
||||||
for i := 0; i < commit.ParentCount(); i++ {
|
for i := 0; i < commit.ParentCount(); i++ {
|
||||||
sha, err := commit.ParentID(i)
|
sha, err := commit.ParentID(i)
|
||||||
parents[i] = sha.String()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound("repo.Diff", err)
|
ctx.NotFound("repo.Diff", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
parents[i] = sha.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["CommitID"] = commitID
|
ctx.Data["CommitID"] = commitID
|
||||||
|
|
Reference in a new issue