fix: handle 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 confidence in this patch, it was confirmed that this exact fix worked on Codeberg.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7210
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-03-14 16:03:22 +00:00 committed by Gusted
parent 7a19d3c2be
commit cbd772873a

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