diff options
author | singuliere <35190819+singuliere@users.noreply.github.com> | 2022-02-01 19:20:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-01 13:20:28 -0500 |
commit | 367894adc820964135095e50c1ae6d6a0b2b0310 (patch) | |
tree | 6b773809f2c3c722251e902b244a074bdf8ec1a5 /models | |
parent | 6f6b8491da0d98121c8cab5c48f95425efa9606d (diff) | |
download | gitea-367894adc820964135095e50c1ae6d6a0b2b0310.tar.gz gitea-367894adc820964135095e50c1ae6d6a0b2b0310.zip |
add test coverage for original author conversion during migrations (#18506)
* add test coverage for original author conversion during migrations
And create a function to factorize a code snippet that is repeated
five times and would otherwise be more difficult to test and maintain
consistently.
Signed-off-by: Loïc Dachary <loic@dachary.org>
* fix variable scope and int64 formatting
* add missing calls to remapExternalUser and fix misplaced %d
Co-authored-by: Loïc Dachary <loic@dachary.org>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models')
-rw-r--r-- | models/fixtures/external_login_user.yml | 1 | ||||
-rw-r--r-- | models/issue.go | 17 | ||||
-rw-r--r-- | models/issue_comment.go | 17 | ||||
-rw-r--r-- | models/issue_reaction.go | 17 | ||||
-rw-r--r-- | models/release.go | 17 | ||||
-rw-r--r-- | models/review.go | 17 | ||||
-rw-r--r-- | models/user/external_login_user.go | 11 |
7 files changed, 97 insertions, 0 deletions
diff --git a/models/fixtures/external_login_user.yml b/models/fixtures/external_login_user.yml new file mode 100644 index 0000000000..ca780a73aa --- /dev/null +++ b/models/fixtures/external_login_user.yml @@ -0,0 +1 @@ +[] # empty diff --git a/models/issue.go b/models/issue.go index 8eb61f2050..91d4df32d1 100644 --- a/models/issue.go +++ b/models/issue.go @@ -2329,3 +2329,20 @@ func deleteIssuesByRepoID(sess db.Engine, repoID int64) (attachmentPaths []strin return } + +// RemapExternalUser ExternalUserRemappable interface +func (issue *Issue) RemapExternalUser(externalName string, externalID, userID int64) error { + issue.OriginalAuthor = externalName + issue.OriginalAuthorID = externalID + issue.PosterID = userID + return nil +} + +// GetUserID ExternalUserRemappable interface +func (issue *Issue) GetUserID() int64 { return issue.PosterID } + +// GetExternalName ExternalUserRemappable interface +func (issue *Issue) GetExternalName() string { return issue.OriginalAuthor } + +// GetExternalID ExternalUserRemappable interface +func (issue *Issue) GetExternalID() int64 { return issue.OriginalAuthorID } diff --git a/models/issue_comment.go b/models/issue_comment.go index 34541dc3cd..31bd041ca7 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -1464,3 +1464,20 @@ func commitBranchCheck(gitRepo *git.Repository, startCommit *git.Commit, endComm } return nil } + +// RemapExternalUser ExternalUserRemappable interface +func (c *Comment) RemapExternalUser(externalName string, externalID, userID int64) error { + c.OriginalAuthor = externalName + c.OriginalAuthorID = externalID + c.PosterID = userID + return nil +} + +// GetUserID ExternalUserRemappable interface +func (c *Comment) GetUserID() int64 { return c.PosterID } + +// GetExternalName ExternalUserRemappable interface +func (c *Comment) GetExternalName() string { return c.OriginalAuthor } + +// GetExternalID ExternalUserRemappable interface +func (c *Comment) GetExternalID() int64 { return c.OriginalAuthorID } diff --git a/models/issue_reaction.go b/models/issue_reaction.go index 2e0ab07db7..45b1d64fe1 100644 --- a/models/issue_reaction.go +++ b/models/issue_reaction.go @@ -343,3 +343,20 @@ func (list ReactionList) GetMoreUserCount() int { } return len(list) - setting.UI.ReactionMaxUserNum } + +// RemapExternalUser ExternalUserRemappable interface +func (r *Reaction) RemapExternalUser(externalName string, externalID, userID int64) error { + r.OriginalAuthor = externalName + r.OriginalAuthorID = externalID + r.UserID = userID + return nil +} + +// GetUserID ExternalUserRemappable interface +func (r *Reaction) GetUserID() int64 { return r.UserID } + +// GetExternalName ExternalUserRemappable interface +func (r *Reaction) GetExternalName() string { return r.OriginalAuthor } + +// GetExternalID ExternalUserRemappable interface +func (r *Reaction) GetExternalID() int64 { return r.OriginalAuthorID } diff --git a/models/release.go b/models/release.go index 51ac0426ac..0285f6bd5e 100644 --- a/models/release.go +++ b/models/release.go @@ -456,3 +456,20 @@ func SaveOrUpdateTag(repo *repo_model.Repository, newRel *Release) error { } return nil } + +// RemapExternalUser ExternalUserRemappable interface +func (r *Release) RemapExternalUser(externalName string, externalID, userID int64) error { + r.OriginalAuthor = externalName + r.OriginalAuthorID = externalID + r.PublisherID = userID + return nil +} + +// UserID ExternalUserRemappable interface +func (r *Release) GetUserID() int64 { return r.PublisherID } + +// ExternalName ExternalUserRemappable interface +func (r *Release) GetExternalName() string { return r.OriginalAuthor } + +// ExternalID ExternalUserRemappable interface +func (r *Release) GetExternalID() int64 { return r.OriginalAuthorID } diff --git a/models/review.go b/models/review.go index 8b0092b1ed..22c47486a1 100644 --- a/models/review.go +++ b/models/review.go @@ -987,3 +987,20 @@ func (r *Review) HTMLURL() string { } return comment.HTMLURL() } + +// RemapExternalUser ExternalUserRemappable interface +func (r *Review) RemapExternalUser(externalName string, externalID, userID int64) error { + r.OriginalAuthor = externalName + r.OriginalAuthorID = externalID + r.ReviewerID = userID + return nil +} + +// GetUserID ExternalUserRemappable interface +func (r *Review) GetUserID() int64 { return r.ReviewerID } + +// GetExternalName ExternalUserRemappable interface +func (r *Review) GetExternalName() string { return r.OriginalAuthor } + +// GetExternalID ExternalUserRemappable interface +func (r *Review) GetExternalID() int64 { return r.OriginalAuthorID } diff --git a/models/user/external_login_user.go b/models/user/external_login_user.go index d1abe292f5..422823b89c 100644 --- a/models/user/external_login_user.go +++ b/models/user/external_login_user.go @@ -68,6 +68,17 @@ type ExternalLoginUser struct { ExpiresAt time.Time } +type ExternalUserMigrated interface { + GetExternalName() string + GetExternalID() int64 +} + +type ExternalUserRemappable interface { + GetUserID() int64 + RemapExternalUser(externalName string, externalID, userID int64) error + ExternalUserMigrated +} + func init() { db.RegisterModel(new(ExternalLoginUser)) } |