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

Display original author and URL information when showing migrated issues/comments #7352

Merged
merged 14 commits into from
Jul 8, 2019
Merged
44 changes: 23 additions & 21 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
6 changes: 4 additions & 2 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions models/migrations/v89.go
Original file line number Diff line number Diff line change
@@ -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))
}
5 changes: 5 additions & 0 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ type Repository struct {
Name string `xorm:"INDEX NOT NULL"`
Description string
Website string
OriginalURL string
DefaultBranch string

NumWatches int
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions modules/migrations/base/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/migrations/base/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/migrations/base/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type MigrateOptions struct {
AuthPassword string
Name string
Description string
OriginalURL string

Wiki bool
Issues bool
Expand Down
1 change: 1 addition & 0 deletions modules/migrations/base/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ type Repository struct {
AuthUsername string
AuthPassword string
CloneURL string
OriginalURL string
}
37 changes: 21 additions & 16 deletions modules/migrations/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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,
Expand Down Expand Up @@ -228,17 +229,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())
Expand Down Expand Up @@ -274,11 +277,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
Expand Down
4 changes: 3 additions & 1 deletion modules/migrations/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions modules/migrations/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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.
Expand Down
11 changes: 1 addition & 10 deletions modules/migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
if err != nil {
return err
}
for _, issue := range issues {
mrsdizzie marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -147,11 +142,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) >= 100 {
Expand Down
21 changes: 11 additions & 10 deletions modules/structs/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ 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"`
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
Expand Down
13 changes: 7 additions & 6 deletions modules/structs/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ 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"`
Body string `json:"body"`
// swagger:strfmt date-time
Created time.Time `json:"created_at"`
// swagger:strfmt date-time
Expand Down
Loading