mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-03-13 23:32:41 +00:00
fix: hanndle deleted user modifying event state in gitlab migration
- In the case that a deleted user modified the state of an issue or pull request, the user field in the API response for that state event will be `null`. Handle this by falling back to Forgejo's internal Ghost user. - No testing, this bug was hit on Codeberg with a instance that is only IPv6-accessible and otherwise might be phased out. So I will do some mental gymnastics and argue, migration feature will someday be replaced by F3 and considering the logic that was added its not worth the tradeoff to add testing for this by trying to recreate the same scenario on another Gitlab instance and then use that as a testing vector. To still give some confindence in this patch, it was confirmed that this exact fix worked on Codeberg.
This commit is contained in:
parent
534d3ca93e
commit
813ece0f5d
1 changed files with 11 additions and 2 deletions
|
@ -16,6 +16,7 @@ import (
|
|||
"time"
|
||||
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
base "code.gitea.io/gitea/modules/migration"
|
||||
|
@ -543,11 +544,19 @@ func (g *GitlabDownloader) GetComments(commentable base.Commentable) ([]*base.Co
|
|||
}
|
||||
|
||||
for _, stateEvent := range stateEvents {
|
||||
// If the user is deleted, then `stateEvent.User == nil` holds. Fallback
|
||||
// to the Ghost user in that case.
|
||||
posterID := int64(user_model.GhostUserID)
|
||||
posterName := user_model.GhostUserName
|
||||
if stateEvent.User != nil {
|
||||
posterID = int64(stateEvent.User.ID)
|
||||
posterName = stateEvent.User.Username
|
||||
}
|
||||
comment := &base.Comment{
|
||||
IssueIndex: commentable.GetLocalIndex(),
|
||||
Index: int64(stateEvent.ID),
|
||||
PosterID: int64(stateEvent.User.ID),
|
||||
PosterName: stateEvent.User.Username,
|
||||
PosterID: posterID,
|
||||
PosterName: posterName,
|
||||
Content: "",
|
||||
Created: *stateEvent.CreatedAt,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue