Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test coverage for original author conversion during migrations #18506

Merged
merged 8 commits into from
Feb 1, 2022
1 change: 1 addition & 0 deletions models/fixtures/external_login_user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[] # empty
17 changes: 17 additions & 0 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2323,3 +2323,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 }
17 changes: 17 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
17 changes: 17 additions & 0 deletions models/issue_reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
17 changes: 17 additions & 0 deletions models/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
17 changes: 17 additions & 0 deletions models/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
11 changes: 11 additions & 0 deletions models/user/external_login_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
6 changes: 6 additions & 0 deletions modules/migration/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ type Comment struct {
Content string
Reactions []*Reaction
}

// GetExternalName ExternalUserMigrated interface
func (c *Comment) GetExternalName() string { return c.PosterName }

// ExternalID ExternalUserMigrated interface
func (c *Comment) GetExternalID() int64 { return c.PosterID }
6 changes: 6 additions & 0 deletions modules/migration/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ type Issue struct {
Assignees []string `json:"assignees"`
Context IssueContext `yaml:"-"`
}

// GetExternalName ExternalUserMigrated interface
func (i *Issue) GetExternalName() string { return i.PosterName }

// GetExternalID ExternalUserMigrated interface
func (i *Issue) GetExternalID() int64 { return i.PosterID }
6 changes: 6 additions & 0 deletions modules/migration/reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ type Reaction struct {
UserName string `yaml:"user_name" json:"user_name"`
Content string `json:"content"`
}

// GetExternalName ExternalUserMigrated interface
func (r *Reaction) GetExternalName() string { return r.UserName }

// GetExternalID ExternalUserMigrated interface
func (r *Reaction) GetExternalID() int64 { return r.UserID }
6 changes: 6 additions & 0 deletions modules/migration/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ type Release struct {
Created time.Time
Published time.Time
}

// GetExternalName ExternalUserMigrated interface
func (r *Release) GetExternalName() string { return r.PublisherName }

// GetExternalID ExternalUserMigrated interface
func (r *Release) GetExternalID() int64 { return r.PublisherID }
6 changes: 6 additions & 0 deletions modules/migration/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ type Review struct {
Comments []*ReviewComment
}

// GetExternalName ExternalUserMigrated interface
func (r *Review) GetExternalName() string { return r.ReviewerName }

// ExternalID ExternalUserMigrated interface
func (r *Review) GetExternalID() int64 { return r.ReviewerID }

// ReviewComment represents a review comment
type ReviewComment struct {
ID int64
Expand Down
Loading