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))
}
15 changes: 15 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 Expand Up @@ -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
}
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
20 changes: 10 additions & 10 deletions modules/migrations/base/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions modules/migrations/base/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type PullRequest struct {
Number int64
Title string
PosterName string
PosterID int64
PosterEmail string
Content string
Milestone string
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
}
63 changes: 35 additions & 28 deletions modules/migrations/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()),
},
}

Expand Down
19 changes: 9 additions & 10 deletions modules/migrations/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 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 Expand Up @@ -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,
Expand Down
Loading