Fix assignment to cm.AssigneeID when importing comments (#22528)

This is a fix for https://github.com/go-gitea/gitea/pull/22510

The code assumed that the `AssigneeID` from the comment YAML was an
`int64`, but it is actually an `int`, causing a panic. It also had no
check on whether the type cast was actually valid, so badly formatted
YAML could also cause a panic.

Both these issues have been fixed.
This commit is contained in:
Sybren 2023-01-19 19:24:40 +01:00 committed by GitHub
parent 9f919cf083
commit b383652e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -468,7 +468,9 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
switch cm.Type {
case issues_model.CommentTypeAssignees:
cm.AssigneeID = comment.Meta["AssigneeID"].(int64)
if assigneeID, ok := comment.Meta["AssigneeID"].(int); ok {
cm.AssigneeID = int64(assigneeID)
}
if comment.Meta["RemovedAssigneeID"] != nil {
cm.RemovedAssignee = true
}