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:
Gusted 2025-03-12 13:30:38 +01:00
parent 534d3ca93e
commit 813ece0f5d
No known key found for this signature in database
GPG key ID: FD821B732837125F

View file

@ -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,
}