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 /modules | |
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 'modules')
-rw-r--r-- | modules/migrations/base/comment.go | 1 | ||||
-rw-r--r-- | modules/migrations/base/issue.go | 1 | ||||
-rw-r--r-- | modules/migrations/base/options.go | 20 | ||||
-rw-r--r-- | modules/migrations/base/pullrequest.go | 1 | ||||
-rw-r--r-- | modules/migrations/base/repo.go | 1 | ||||
-rw-r--r-- | modules/migrations/gitea.go | 63 | ||||
-rw-r--r-- | modules/migrations/gitea_test.go | 19 | ||||
-rw-r--r-- | modules/migrations/github.go | 5 | ||||
-rw-r--r-- | modules/migrations/github_test.go | 10 | ||||
-rw-r--r-- | modules/migrations/migrate.go | 23 | ||||
-rw-r--r-- | modules/structs/issue.go | 22 | ||||
-rw-r--r-- | modules/structs/issue_comment.go | 14 | ||||
-rw-r--r-- | modules/structs/repo.go | 1 | ||||
-rw-r--r-- | modules/templates/helper.go | 11 |
14 files changed, 105 insertions, 87 deletions
diff --git a/modules/migrations/base/comment.go b/modules/migrations/base/comment.go index d89ec3a3f5..38c544d6e0 100644 --- a/modules/migrations/base/comment.go +++ b/modules/migrations/base/comment.go @@ -10,6 +10,7 @@ import "time" // Comment is a standard comment information type Comment struct { IssueIndex int64 + PosterID int64 PosterName string PosterEmail string Created time.Time diff --git a/modules/migrations/base/issue.go b/modules/migrations/base/issue.go index ddadd0c2b3..08d947b05d 100644 --- a/modules/migrations/base/issue.go +++ b/modules/migrations/base/issue.go @@ -10,6 +10,7 @@ import "time" // Issue is a standard issue information type Issue struct { Number int64 + PosterID int64 PosterName string PosterEmail string Title string diff --git a/modules/migrations/base/options.go b/modules/migrations/base/options.go index 262981b933..ba7fdc6815 100644 --- a/modules/migrations/base/options.go +++ b/modules/migrations/base/options.go @@ -12,15 +12,15 @@ type MigrateOptions struct { AuthPassword string Name string Description string + OriginalURL string - Wiki bool - Issues bool - Milestones bool - Labels bool - Releases bool - Comments bool - PullRequests bool - Private bool - Mirror bool - IgnoreIssueAuthor bool // if true will not add original author information before issues or comments content. + Wiki bool + Issues bool + Milestones bool + Labels bool + Releases bool + Comments bool + PullRequests bool + Private bool + Mirror bool } diff --git a/modules/migrations/base/pullrequest.go b/modules/migrations/base/pullrequest.go index 515cab3f91..42456fd314 100644 --- a/modules/migrations/base/pullrequest.go +++ b/modules/migrations/base/pullrequest.go @@ -15,6 +15,7 @@ type PullRequest struct { Number int64 Title string PosterName string + PosterID int64 PosterEmail string Content string Milestone string diff --git a/modules/migrations/base/repo.go b/modules/migrations/base/repo.go index 907d8fc09e..5cfb0de920 100644 --- a/modules/migrations/base/repo.go +++ b/modules/migrations/base/repo.go @@ -15,4 +15,5 @@ type Repository struct { AuthUsername string AuthPassword string CloneURL string + OriginalURL string } diff --git a/modules/migrations/gitea.go b/modules/migrations/gitea.go index 1df824c94f..b15aed5f4b 100644 --- a/modules/migrations/gitea.go +++ b/modules/migrations/gitea.go @@ -82,6 +82,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate r, err := models.MigrateRepository(g.doer, owner, models.MigrateRepoOptions{ Name: g.repoName, Description: repo.Description, + OriginalURL: repo.OriginalURL, IsMirror: repo.IsMirror, RemoteAddr: repo.CloneURL, IsPrivate: repo.IsPrivate, @@ -247,17 +248,19 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error { } var is = models.Issue{ - RepoID: g.repo.ID, - Repo: g.repo, - Index: issue.Number, - PosterID: g.doer.ID, - Title: issue.Title, - Content: issue.Content, - IsClosed: issue.State == "closed", - IsLocked: issue.IsLocked, - MilestoneID: milestoneID, - Labels: labels, - CreatedUnix: util.TimeStamp(issue.Created.Unix()), + RepoID: g.repo.ID, + Repo: g.repo, + Index: issue.Number, + PosterID: g.doer.ID, + OriginalAuthor: issue.PosterName, + OriginalAuthorID: issue.PosterID, + Title: issue.Title, + Content: issue.Content, + IsClosed: issue.State == "closed", + IsLocked: issue.IsLocked, + MilestoneID: milestoneID, + Labels: labels, + CreatedUnix: util.TimeStamp(issue.Created.Unix()), } if issue.Closed != nil { is.ClosedUnix = util.TimeStamp(issue.Closed.Unix()) @@ -293,11 +296,13 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { } cms = append(cms, &models.Comment{ - IssueID: issueID, - Type: models.CommentTypeComment, - PosterID: g.doer.ID, - Content: comment.Content, - CreatedUnix: util.TimeStamp(comment.Created.Unix()), + IssueID: issueID, + Type: models.CommentTypeComment, + PosterID: g.doer.ID, + OriginalAuthor: comment.PosterName, + OriginalAuthorID: comment.PosterID, + Content: comment.Content, + CreatedUnix: util.TimeStamp(comment.Created.Unix()), }) // TODO: Reactions @@ -430,18 +435,20 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR HasMerged: pr.Merged, Issue: &models.Issue{ - RepoID: g.repo.ID, - Repo: g.repo, - Title: pr.Title, - Index: pr.Number, - PosterID: g.doer.ID, - Content: pr.Content, - MilestoneID: milestoneID, - IsPull: true, - IsClosed: pr.State == "closed", - IsLocked: pr.IsLocked, - Labels: labels, - CreatedUnix: util.TimeStamp(pr.Created.Unix()), + RepoID: g.repo.ID, + Repo: g.repo, + Title: pr.Title, + Index: pr.Number, + PosterID: g.doer.ID, + OriginalAuthor: pr.PosterName, + OriginalAuthorID: pr.PosterID, + Content: pr.Content, + MilestoneID: milestoneID, + IsPull: true, + IsClosed: pr.State == "closed", + IsLocked: pr.IsLocked, + Labels: labels, + CreatedUnix: util.TimeStamp(pr.Created.Unix()), }, } diff --git a/modules/migrations/gitea_test.go b/modules/migrations/gitea_test.go index 22da7da171..88a3a6d218 100644 --- a/modules/migrations/gitea_test.go +++ b/modules/migrations/gitea_test.go @@ -34,16 +34,15 @@ func TestGiteaUploadRepo(t *testing.T) { Name: repoName, AuthUsername: "", - Wiki: true, - Issues: true, - Milestones: true, - Labels: true, - Releases: true, - Comments: true, - PullRequests: true, - Private: true, - Mirror: false, - IgnoreIssueAuthor: false, + Wiki: true, + Issues: true, + Milestones: true, + Labels: true, + Releases: true, + Comments: true, + PullRequests: true, + Private: true, + Mirror: false, }) assert.NoError(t, err) diff --git a/modules/migrations/github.go b/modules/migrations/github.go index e6b532df9c..93ba108548 100644 --- a/modules/migrations/github.go +++ b/modules/migrations/github.go @@ -107,13 +107,13 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) { if err != nil { return nil, err } - // convert github repo to stand Repo return &base.Repository{ Owner: g.repoOwner, Name: gr.GetName(), IsPrivate: *gr.Private, Description: gr.GetDescription(), + OriginalURL: gr.GetHTMLURL(), CloneURL: gr.GetCloneURL(), }, nil } @@ -317,6 +317,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool, allIssues = append(allIssues, &base.Issue{ Title: *issue.Title, Number: int64(*issue.Number), + PosterID: *issue.User.ID, PosterName: *issue.User.Login, PosterEmail: email, Content: body, @@ -359,6 +360,7 @@ func (g *GithubDownloaderV3) GetComments(issueNumber int64) ([]*base.Comment, er } allComments = append(allComments, &base.Comment{ IssueIndex: issueNumber, + PosterID: *comment.User.ID, PosterName: *comment.User.Login, PosterEmail: email, Content: *comment.Body, @@ -451,6 +453,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq Title: *pr.Title, Number: int64(*pr.Number), PosterName: *pr.User.Login, + PosterID: *pr.User.ID, PosterEmail: email, Content: body, Milestone: milestone, diff --git a/modules/migrations/github_test.go b/modules/migrations/github_test.go index 700183bdc1..0f52a62eb2 100644 --- a/modules/migrations/github_test.go +++ b/modules/migrations/github_test.go @@ -68,6 +68,7 @@ func TestGitHubDownloadRepo(t *testing.T) { Owner: "go-gitea", Description: "Git with a cup of tea, painless self-hosted git service", CloneURL: "https://github.com/go-gitea/gitea.git", + OriginalURL: "https://github.com/go-gitea/gitea", }, repo) milestones, err := downloader.GetMilestones() @@ -180,6 +181,7 @@ func TestGitHubDownloadRepo(t *testing.T) { Title: "Contribution system: History heatmap for user", Content: "Hi guys,\r\n\r\nI think that is a possible feature, a history heatmap similar to github or gitlab.\r\nActually exists a plugin called Calendar HeatMap. I used this on mine project to heat application log and worked fine here.\r\nThen, is only a idea, what you think? :)\r\n\r\nhttp://cal-heatmap.com/\r\nhttps://github.com/wa0x6e/cal-heatmap\r\n\r\nReference: https://github.com/gogits/gogs/issues/1640", Milestone: "1.7.0", + PosterID: 1520407, PosterName: "joubertredrat", State: "closed", Created: time.Date(2016, 11, 02, 18, 51, 55, 0, time.UTC), @@ -209,6 +211,7 @@ func TestGitHubDownloadRepo(t *testing.T) { Title: "display page revisions on wiki", Content: "Hi guys,\r\n\r\nWiki on Gogs is very fine, I liked a lot, but I think that is good idea to be possible see other revisions from page as a page history.\r\n\r\nWhat you think?\r\n\r\nReference: https://github.com/gogits/gogs/issues/2991", Milestone: "1.x.x", + PosterID: 1520407, PosterName: "joubertredrat", State: "open", Created: time.Date(2016, 11, 02, 18, 57, 32, 0, time.UTC), @@ -238,6 +241,7 @@ func TestGitHubDownloadRepo(t *testing.T) { Title: "audit logs", Content: "Hi,\r\n\r\nI think that is good idea to have user operation log to admin see what the user is doing at Gogs. Similar to example below\r\n\r\n| user | operation | information |\r\n| --- | --- | --- |\r\n| joubertredrat | repo.create | Create repo MyProjectData |\r\n| joubertredrat | user.settings | Edit settings |\r\n| tboerger | repo.fork | Create Fork from MyProjectData to ForkMyProjectData |\r\n| bkcsoft | repo.remove | Remove repo MySource |\r\n| tboerger | admin.auth | Edit auth LDAP org-connection |\r\n\r\nThis resource can be used on user page too, as user activity, set that log row is public (repo._) or private (user._, admin.*) and display only public activity.\r\n\r\nWhat you think?\r\n\r\n[Chat summary from March 14, 2017](https://github.com/go-gitea/gitea/issues/8#issuecomment-286463807)\r\n\r\nReferences:\r\nhttps://github.com/gogits/gogs/issues/3016", Milestone: "1.x.x", + PosterID: 1520407, PosterName: "joubertredrat", State: "open", Created: time.Date(2016, 11, 02, 18, 59, 20, 0, time.UTC), @@ -270,6 +274,7 @@ func TestGitHubDownloadRepo(t *testing.T) { assert.EqualValues(t, []*base.Comment{ { IssueIndex: 6, + PosterID: 4726179, PosterName: "bkcsoft", Created: time.Date(2016, 11, 02, 18, 59, 48, 0, time.UTC), Content: `I would prefer a solution that is in the backend, unless it's required to have it update without reloading. Unfortunately I can't seem to find anything that does that :unamused: @@ -288,6 +293,7 @@ Also this would _require_ caching, since it will fetch huge amounts of data from }, { IssueIndex: 6, + PosterID: 1520407, PosterName: "joubertredrat", Created: time.Date(2016, 11, 02, 19, 16, 56, 0, time.UTC), Content: `Yes, this plugin build on front-end, with backend I don't know too, but we can consider make component for this. @@ -306,6 +312,7 @@ In my case I use ajax to get data, but build on frontend anyway }, { IssueIndex: 6, + PosterID: 1799009, PosterName: "xinity", Created: time.Date(2016, 11, 03, 13, 04, 56, 0, time.UTC), Content: `following @bkcsoft retention strategy in cache is a must if we don't want gitea to waste ressources. @@ -345,6 +352,7 @@ something like in the latest 15days could be enough don't you think ? Title: "Rename import paths: \"github.com/gogits/gogs\" -> \"github.com/go-gitea/gitea\"", Content: "", Milestone: "1.0.0", + PosterID: 7011819, PosterName: "andreynering", State: "closed", Created: time.Date(2016, 11, 02, 17, 01, 19, 0, time.UTC), @@ -380,6 +388,7 @@ something like in the latest 15days could be enough don't you think ? Title: "Fix sender of issue notifications", Content: "It is the FROM field in mailer configuration that needs be used,\r\nnot the USER field, which is for authentication.\r\n\r\nMigrated from https://github.com/gogits/gogs/pull/3616\r\n", Milestone: "1.0.0", + PosterID: 289678, PosterName: "strk", State: "closed", Created: time.Date(2016, 11, 02, 17, 24, 19, 0, time.UTC), @@ -417,6 +426,7 @@ something like in the latest 15days could be enough don't you think ? Title: "Use proper url for libravatar dep", Content: "Fetch go-libravatar from its official source, rather than from an unmaintained fork\r\n", Milestone: "1.0.0", + PosterID: 289678, PosterName: "strk", State: "closed", Created: time.Date(2016, 11, 02, 17, 34, 31, 0, time.UTC), diff --git a/modules/migrations/migrate.go b/modules/migrations/migrate.go index 7fc7911f21..a86614c317 100644 --- a/modules/migrations/migrate.go +++ b/modules/migrations/migrate.go @@ -6,8 +6,6 @@ package migrations import ( - "fmt" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/migrations/base" @@ -155,11 +153,6 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if err != nil { return err } - for _, issue := range issues { - if !opts.IgnoreIssueAuthor { - issue.Content = fmt.Sprintf("Author: @%s \n\n%s", issue.PosterName, issue.Content) - } - } if err := uploader.CreateIssues(issues...); err != nil { return err @@ -175,11 +168,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if err != nil { return err } - for _, comment := range comments { - if !opts.IgnoreIssueAuthor { - comment.Content = fmt.Sprintf("Author: @%s \n\n%s", comment.PosterName, comment.Content) - } - } + allComments = append(allComments, comments...) if len(allComments) >= commentBatchSize { @@ -212,11 +201,6 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts return err } - for _, pr := range prs { - if !opts.IgnoreIssueAuthor { - pr.Content = fmt.Sprintf("Author: @%s \n\n%s", pr.PosterName, pr.Content) - } - } if err := uploader.CreatePullRequests(prs...); err != nil { return err } @@ -231,11 +215,6 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if err != nil { return err } - for _, comment := range comments { - if !opts.IgnoreIssueAuthor { - comment.Content = fmt.Sprintf("Author: @%s \n\n%s", comment.PosterName, comment.Content) - } - } allComments = append(allComments, comments...) diff --git a/modules/structs/issue.go b/modules/structs/issue.go index 6d7517bdc7..58fd7344b4 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -29,16 +29,18 @@ type PullRequestMeta struct { // Issue represents an issue in a repository // swagger:model type Issue struct { - ID int64 `json:"id"` - URL string `json:"url"` - Index int64 `json:"number"` - Poster *User `json:"user"` - Title string `json:"title"` - Body string `json:"body"` - Labels []*Label `json:"labels"` - Milestone *Milestone `json:"milestone"` - Assignee *User `json:"assignee"` - Assignees []*User `json:"assignees"` + ID int64 `json:"id"` + URL string `json:"url"` + Index int64 `json:"number"` + Poster *User `json:"user"` + OriginalAuthor string `json:"original_author"` + OriginalAuthorID int64 `json:"original_author_id"` + Title string `json:"title"` + Body string `json:"body"` + Labels []*Label `json:"labels"` + Milestone *Milestone `json:"milestone"` + Assignee *User `json:"assignee"` + Assignees []*User `json:"assignees"` // Whether the issue is open or closed // // type: string diff --git a/modules/structs/issue_comment.go b/modules/structs/issue_comment.go index 185f3910ed..0c8ac20017 100644 --- a/modules/structs/issue_comment.go +++ b/modules/structs/issue_comment.go @@ -10,12 +10,14 @@ import ( // Comment represents a comment on a commit or issue type Comment struct { - ID int64 `json:"id"` - HTMLURL string `json:"html_url"` - PRURL string `json:"pull_request_url"` - IssueURL string `json:"issue_url"` - Poster *User `json:"user"` - Body string `json:"body"` + ID int64 `json:"id"` + HTMLURL string `json:"html_url"` + PRURL string `json:"pull_request_url"` + IssueURL string `json:"issue_url"` + Poster *User `json:"user"` + OriginalAuthor string `json:"original_author"` + OriginalAuthorID int64 `json:"original_author_id"` + Body string `json:"body"` // swagger:strfmt date-time Created time.Time `json:"created_at"` // swagger:strfmt date-time diff --git a/modules/structs/repo.go b/modules/structs/repo.go index b4d162b776..81203319e0 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -31,6 +31,7 @@ type Repository struct { HTMLURL string `json:"html_url"` SSHURL string `json:"ssh_url"` CloneURL string `json:"clone_url"` + OriginalURL string `json:"original_url"` Website string `json:"website"` Stars int `json:"stars_count"` Forks int `json:"forks_count"` diff --git a/modules/templates/helper.go b/modules/templates/helper.go index c4551bb4be..5a3969c098 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -82,6 +82,7 @@ func NewFuncMap() []template.FuncMap { "FileSize": base.FileSize, "Subtract": base.Subtract, "EntryIcon": base.EntryIcon, + "MigrationIcon": MigrationIcon, "Add": func(a, b int) int { return a + b }, @@ -540,3 +541,13 @@ func TrN(lang string, cnt interface{}, key1, keyN string) string { } return keyN } + +// MigrationIcon returns a Font Awesome name matching the service an issue/comment was migrated from +func MigrationIcon(hostname string) string { + switch hostname { + case "github.com": + return "fa-github" + default: + return "fa-git-alt" + } +} |