diff options
author | mrsdizzie <info@mrsdizzie.com> | 2019-07-07 22:14:12 -0400 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-07-08 10:14:12 +0800 |
commit | 1f1ecda541d7f526c004e7bfabab814dbc84dc2c (patch) | |
tree | b53d4e692de9b4a5cc0ebfebf09a4cb5d8d5880f /models | |
parent | fcda2d5b35ec9bec9a8e8fa0a0fb04cb21593648 (diff) | |
download | gitea-1f1ecda541d7f526c004e7bfabab814dbc84dc2c.tar.gz gitea-1f1ecda541d7f526c004e7bfabab814dbc84dc2c.zip |
Display original author and URL information when showing migrated issues/comments (#7352)
* Store original author info for migrated issues and comments
Keep original author name for displaying in Gitea interface and also
store original author user ID for potential future use in linking
accounts from old location.
* Add original_url for repo
Store the original URL for a migrated repo
Clean up migrations/tests
* fix migration
* fix golangci-lint
* make 'make revive' happy also
* Modify templates to use OriginalAuthor if set
Use the original author name in templates if it is set rather than the
user who migrated/currently owns the issues
* formatting fixes
* make generate-swagger
* Use default avatar for imported comments
* Remove no longer used IgnoreIssueAuthor option
* Add OriginalAuthorID to swagger also
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 44 | ||||
-rw-r--r-- | models/issue_comment.go | 6 | ||||
-rw-r--r-- | models/migrations/migrations.go | 2 | ||||
-rw-r--r-- | models/migrations/v89.go | 36 | ||||
-rw-r--r-- | models/repo.go | 15 |
5 files changed, 80 insertions, 23 deletions
diff --git a/models/issue.go b/models/issue.go index b5504beb71..63074cd40c 100644 --- a/models/issue.go +++ b/models/issue.go @@ -25,27 +25,29 @@ import ( // Issue represents an issue or pull request of repository. type Issue struct { - ID int64 `xorm:"pk autoincr"` - RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"` - Repo *Repository `xorm:"-"` - Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository. - PosterID int64 `xorm:"INDEX"` - Poster *User `xorm:"-"` - Title string `xorm:"name"` - Content string `xorm:"TEXT"` - RenderedContent string `xorm:"-"` - Labels []*Label `xorm:"-"` - MilestoneID int64 `xorm:"INDEX"` - Milestone *Milestone `xorm:"-"` - Priority int - AssigneeID int64 `xorm:"-"` - Assignee *User `xorm:"-"` - IsClosed bool `xorm:"INDEX"` - IsRead bool `xorm:"-"` - IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not. - PullRequest *PullRequest `xorm:"-"` - NumComments int - Ref string + ID int64 `xorm:"pk autoincr"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"` + Repo *Repository `xorm:"-"` + Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository. + PosterID int64 `xorm:"INDEX"` + Poster *User `xorm:"-"` + OriginalAuthor string + OriginalAuthorID int64 + Title string `xorm:"name"` + Content string `xorm:"TEXT"` + RenderedContent string `xorm:"-"` + Labels []*Label `xorm:"-"` + MilestoneID int64 `xorm:"INDEX"` + Milestone *Milestone `xorm:"-"` + Priority int + AssigneeID int64 `xorm:"-"` + Assignee *User `xorm:"-"` + IsClosed bool `xorm:"INDEX"` + IsRead bool `xorm:"-"` + IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not. + PullRequest *PullRequest `xorm:"-"` + NumComments int + Ref string DeadlineUnix util.TimeStamp `xorm:"INDEX"` diff --git a/models/issue_comment.go b/models/issue_comment.go index c9f1bd9d5f..b930b0b12a 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -101,8 +101,10 @@ const ( type Comment struct { ID int64 `xorm:"pk autoincr"` Type CommentType - PosterID int64 `xorm:"INDEX"` - Poster *User `xorm:"-"` + PosterID int64 `xorm:"INDEX"` + Poster *User `xorm:"-"` + OriginalAuthor string + OriginalAuthorID int64 IssueID int64 `xorm:"INDEX"` Issue *Issue `xorm:"-"` LabelID int64 diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index ef43b0453b..62fadf5f36 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -232,6 +232,8 @@ var migrations = []Migration{ NewMigration("add avatar field to repository", addAvatarFieldToRepository), // v88 -> v89 NewMigration("add commit status context field to commit_status", addCommitStatusContext), + // v89 -> v90 + NewMigration("add original author/url migration info to issues, comments, and repo ", addOriginalMigrationInfo), } // Migrate database to current version diff --git a/models/migrations/v89.go b/models/migrations/v89.go new file mode 100644 index 0000000000..83d0b1a8b9 --- /dev/null +++ b/models/migrations/v89.go @@ -0,0 +1,36 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import "github.com/go-xorm/xorm" + +func addOriginalMigrationInfo(x *xorm.Engine) error { + // Issue see models/issue.go + type Issue struct { + OriginalAuthor string + OriginalAuthorID int64 + } + + if err := x.Sync2(new(Issue)); err != nil { + return err + } + + // Issue see models/issue_comment.go + type Comment struct { + OriginalAuthor string + OriginalAuthorID int64 + } + + if err := x.Sync2(new(Comment)); err != nil { + return err + } + + // Issue see models/repo.go + type Repository struct { + OriginalURL string + } + + return x.Sync2(new(Repository)) +} diff --git a/models/repo.go b/models/repo.go index 59ce18fa88..9bedeba952 100644 --- a/models/repo.go +++ b/models/repo.go @@ -136,6 +136,7 @@ type Repository struct { Name string `xorm:"INDEX NOT NULL"` Description string Website string + OriginalURL string DefaultBranch string NumWatches int @@ -847,6 +848,7 @@ func (repo *Repository) CloneLink() (cl *CloneLink) { type MigrateRepoOptions struct { Name string Description string + OriginalURL string IsPrivate bool IsMirror bool RemoteAddr string @@ -878,6 +880,7 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err repo, err := CreateRepository(doer, u, CreateRepoOptions{ Name: opts.Name, Description: opts.Description, + OriginalURL: opts.OriginalURL, IsPrivate: opts.IsPrivate, IsMirror: opts.IsMirror, }) @@ -1092,6 +1095,7 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) { type CreateRepoOptions struct { Name string Description string + OriginalURL string Gitignores string License string Readme string @@ -1358,6 +1362,7 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err Name: opts.Name, LowerName: strings.ToLower(opts.Name), Description: opts.Description, + OriginalURL: opts.OriginalURL, IsPrivate: opts.IsPrivate, IsFsckEnabled: !opts.IsMirror, CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch, @@ -2678,3 +2683,13 @@ func (repo *Repository) DeleteAvatar() error { } return sess.Commit() } + +// GetOriginalURLHostname returns the hostname of a URL or the URL +func (repo *Repository) GetOriginalURLHostname() string { + u, err := url.Parse(repo.OriginalURL) + if err != nil { + return repo.OriginalURL + } + + return u.Host +} |