Store the foreign ID of issues during migration (#18446)

Storing the foreign identifier of an imported issue in the database is a prerequisite to implement idempotent migrations or mirror for issues. It is a baby step towards mirroring that introduces a new table.

At the moment when an issue is created by the Gitea uploader, it fails if the issue already exists. The Gitea uploader could be modified so that, instead of failing, it looks up the database to find an existing issue. And if it does it would update the issue instead of creating a new one. However this is not currently possible because an information is missing from the database: the foreign identifier that uniquely represents the issue being migrated is not persisted. With this change, the foreign identifier is stored in the database and the Gitea uploader will then be able to run a query to figure out if a given issue being imported already exists.

The implementation of mirroring for issues, pull requests, releases, etc. can be done in three steps:

1. Store an identifier for the element being mirrored (issue, pull request...) in the database (this is the purpose of these changes)
2. Modify the Gitea uploader to be able to update an existing repository with all it contains (issues, pull request...) instead of failing if it exists
3. Optimize the Gitea uploader to speed up the updates, when possible.

The second step creates code that does not yet exist to enable idempotent migrations with the Gitea uploader. When a migration is done for the first time, the behavior is not changed. But when a migration is done for a repository that already exists, this new code is used to update it.

The third step can use the code created in the second step to optimize and speed up migrations. For instance, when a migration is resumed, an issue that has an update time that is not more recent can be skipped and only newly created issues or updated ones will be updated. Another example of optimization could be that a webhook notifies Gitea when an issue is updated. The code triggered by the webhook would download only this issue and call the code created in the second step to update the issue, as if it was in the process of an idempotent migration.

The ForeignReferences table is added to contain local and foreign ID pairs relative to a given repository. It can later be used for pull requests and other artifacts that can be mirrored. Although the foreign id could be added as a single field in issues or pull requests, it would need to be added to all tables that represent something that can be mirrored. Creating a new table makes for a simpler and more generic design. The drawback is that it requires an extra lookup to obtain the information. However, this extra information is only required during migration or mirroring and does not impact the way Gitea currently works.

The foreign identifier of an issue or pull request is similar to the identifier of an external user, which is stored in reactions, issues, etc. as OriginalPosterID and so on. The representation of a user is however different and the ability of users to link their account to an external user at a later time is also a logic that is different from what is involved in mirroring or migrations. For these reasons, despite some commonalities, it is unclear at this time how the two tables (foreign reference and external user) could be merged together.

The ForeignID field is extracted from the issue migration context so that it can be dumped in files with dump-repo and later restored via restore-repo.

The GetAllComments downloader method is introduced to simplify the implementation and not overload the Context for the purpose of pagination. It also clarifies in which context the comments are paginated and in which context they are not.

The Context interface is no longer useful for the purpose of retrieving the LocalID and ForeignID since they are now both available from the PullRequest and Issue struct. The Reviewable and Commentable interfaces replace and serve the same purpose.

The Context data member of PullRequest and Issue becomes a DownloaderContext to clarify that its purpose is not to support in memory operations while the current downloader is acting but is not otherwise persisted. It is, for instance, used by the GitLab downloader to store the IsMergeRequest boolean and sort out issues.

---
[source](https://lab.forgefriends.org/forgefriends/forgefriends/-/merge_requests/36)

Signed-off-by: Loïc Dachary <loic@dachary.org>
Co-authored-by: Loïc Dachary <loic@dachary.org>
tokarchuk/v1.17
Aravinth Manivannan 3 years ago committed by GitHub
parent a7de80db0d
commit fa73cbf5a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      models/fixtures/foreign_reference.yml
  2. 43
      models/foreignreference/error.go
  3. 32
      models/foreignreference/foreignreference.go
  4. 49
      models/issue.go
  5. 34
      models/issue_test.go
  6. 7
      models/migrate.go
  7. 12
      models/migrate_test.go
  8. 2
      models/migrations/migrations.go
  9. 26
      models/migrations/v211.go
  10. 7
      modules/migration/comment.go
  11. 15
      modules/migration/downloader.go
  12. 26
      modules/migration/issue.go
  13. 11
      modules/migration/null_downloader.go
  14. 7
      modules/migration/pullrequest.go
  15. 8
      modules/migration/retry_downloader.go
  16. 6
      modules/migration/review.go
  17. 32
      services/migrations/codebase.go
  18. 6
      services/migrations/codebase_test.go
  19. 5
      services/migrations/gitbucket.go
  20. 24
      services/migrations/gitea_downloader.go
  21. 6
      services/migrations/gitea_downloader_test.go
  22. 8
      services/migrations/gitea_uploader.go
  23. 26
      services/migrations/github.go
  24. 12
      services/migrations/github_test.go
  25. 44
      services/migrations/gitlab.go
  26. 24
      services/migrations/gitlab_test.go
  27. 8
      services/migrations/gogs.go
  28. 4
      services/migrations/gogs_test.go
  29. 15
      services/migrations/migrate.go
  30. 48
      services/migrations/onedev.go
  31. 36
      services/migrations/onedev_test.go
  32. 13
      services/migrations/restore.go

@ -0,0 +1,43 @@
// Copyright 2022 Gitea. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package foreignreference
import (
"fmt"
)
// ErrLocalIndexNotExist represents a "LocalIndexNotExist" kind of error.
type ErrLocalIndexNotExist struct {
RepoID int64
ForeignIndex int64
Type string
}
// ErrLocalIndexNotExist checks if an error is a ErrLocalIndexNotExist.
func IsErrLocalIndexNotExist(err error) bool {
_, ok := err.(ErrLocalIndexNotExist)
return ok
}
func (err ErrLocalIndexNotExist) Error() string {
return fmt.Sprintf("repository %d has no LocalIndex for ForeignIndex %d of type %s", err.RepoID, err.ForeignIndex, err.Type)
}
// ErrForeignIndexNotExist represents a "ForeignIndexNotExist" kind of error.
type ErrForeignIndexNotExist struct {
RepoID int64
LocalIndex int64
Type string
}
// ErrForeignIndexNotExist checks if an error is a ErrForeignIndexNotExist.
func IsErrForeignIndexNotExist(err error) bool {
_, ok := err.(ErrForeignIndexNotExist)
return ok
}
func (err ErrForeignIndexNotExist) Error() string {
return fmt.Sprintf("repository %d has no ForeignIndex for LocalIndex %d of type %s", err.RepoID, err.LocalIndex, err.Type)
}

@ -0,0 +1,32 @@
// Copyright 2022 Gitea. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package foreignreference
import (
"code.gitea.io/gitea/models/db"
)
// Type* are valid values for the Type field of ForeignReference
const (
TypeIssue = "issue"
TypePullRequest = "pull_request"
TypeComment = "comment"
TypeReview = "review"
TypeReviewComment = "review_comment"
TypeRelease = "release"
)
// ForeignReference represents external references
type ForeignReference struct {
// RepoID is the first column in all indices. now we only need 2 indices: (repo, local) and (repo, foreign, type)
RepoID int64 `xorm:"UNIQUE(repo_foreign_type) INDEX(repo_local)" `
LocalIndex int64 `xorm:"INDEX(repo_local)"` // the resource key inside Gitea, it can be IssueIndex, or some model ID.
ForeignIndex string `xorm:"INDEX UNIQUE(repo_foreign_type)"`
Type string `xorm:"VARCHAR(16) INDEX UNIQUE(repo_foreign_type)"`
}
func init() {
db.RegisterModel(new(ForeignReference))
}

@ -15,6 +15,7 @@ import (
admin_model "code.gitea.io/gitea/models/admin" admin_model "code.gitea.io/gitea/models/admin"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/foreignreference"
"code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/perm" "code.gitea.io/gitea/models/perm"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
@ -72,6 +73,7 @@ type Issue struct {
Reactions ReactionList `xorm:"-"` Reactions ReactionList `xorm:"-"`
TotalTrackedTime int64 `xorm:"-"` TotalTrackedTime int64 `xorm:"-"`
Assignees []*user_model.User `xorm:"-"` Assignees []*user_model.User `xorm:"-"`
ForeignReference *foreignreference.ForeignReference `xorm:"-"`
// IsLocked limits commenting abilities to users on an issue // IsLocked limits commenting abilities to users on an issue
// with write access // with write access
@ -271,6 +273,29 @@ func (issue *Issue) loadReactions(ctx context.Context) (err error) {
return nil return nil
} }
func (issue *Issue) loadForeignReference(ctx context.Context) (err error) {
if issue.ForeignReference != nil {
return nil
}
reference := &foreignreference.ForeignReference{
RepoID: issue.RepoID,
LocalIndex: issue.Index,
Type: foreignreference.TypeIssue,
}
has, err := db.GetEngine(ctx).Get(reference)
if err != nil {
return err
} else if !has {
return foreignreference.ErrForeignIndexNotExist{
RepoID: issue.RepoID,
LocalIndex: issue.Index,
Type: foreignreference.TypeIssue,
}
}
issue.ForeignReference = reference
return nil
}
func (issue *Issue) loadMilestone(e db.Engine) (err error) { func (issue *Issue) loadMilestone(e db.Engine) (err error) {
if (issue.Milestone == nil || issue.Milestone.ID != issue.MilestoneID) && issue.MilestoneID > 0 { if (issue.Milestone == nil || issue.Milestone.ID != issue.MilestoneID) && issue.MilestoneID > 0 {
issue.Milestone, err = getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID) issue.Milestone, err = getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID)
@ -332,6 +357,10 @@ func (issue *Issue) loadAttributes(ctx context.Context) (err error) {
} }
} }
if err = issue.loadForeignReference(ctx); err != nil && !foreignreference.IsErrForeignIndexNotExist(err) {
return err
}
return issue.loadReactions(ctx) return issue.loadReactions(ctx)
} }
@ -1110,6 +1139,26 @@ func GetIssueByIndex(repoID, index int64) (*Issue, error) {
return issue, nil return issue, nil
} }
// GetIssueByForeignIndex returns raw issue by foreign ID
func GetIssueByForeignIndex(ctx context.Context, repoID, foreignIndex int64) (*Issue, error) {
reference := &foreignreference.ForeignReference{
RepoID: repoID,
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
Type: foreignreference.TypeIssue,
}
has, err := db.GetEngine(ctx).Get(reference)
if err != nil {
return nil, err
} else if !has {
return nil, foreignreference.ErrLocalIndexNotExist{
RepoID: repoID,
ForeignIndex: foreignIndex,
Type: foreignreference.TypeIssue,
}
}
return GetIssueByIndex(repoID, reference.LocalIndex)
}
// GetIssueWithAttrsByIndex returns issue by index in a repository. // GetIssueWithAttrsByIndex returns issue by index in a repository.
func GetIssueWithAttrsByIndex(repoID, index int64) (*Issue, error) { func GetIssueWithAttrsByIndex(repoID, index int64) (*Issue, error) {
issue, err := GetIssueByIndex(repoID, index) issue, err := GetIssueByIndex(repoID, index)

@ -8,11 +8,13 @@ import (
"context" "context"
"fmt" "fmt"
"sort" "sort"
"strconv"
"sync" "sync"
"testing" "testing"
"time" "time"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/foreignreference"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
@ -534,3 +536,35 @@ func TestCorrectIssueStats(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, issueStats.OpenCount, issueAmount) assert.EqualValues(t, issueStats.OpenCount, issueAmount)
} }
func TestIssueForeignReference(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue)
assert.NotEqualValues(t, issue.Index, issue.ID) // make sure they are different to avoid false positive
// it is fine for an issue to not have a foreign reference
err := issue.LoadAttributes()
assert.NoError(t, err)
assert.Nil(t, issue.ForeignReference)
var foreignIndex int64 = 12345
_, err = GetIssueByForeignIndex(context.Background(), issue.RepoID, foreignIndex)
assert.True(t, foreignreference.IsErrLocalIndexNotExist(err))
_, err = db.GetEngine(db.DefaultContext).Insert(&foreignreference.ForeignReference{
LocalIndex: issue.Index,
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
RepoID: issue.RepoID,
Type: foreignreference.TypeIssue,
})
assert.NoError(t, err)
err = issue.LoadAttributes()
assert.NoError(t, err)
assert.EqualValues(t, issue.ForeignReference.ForeignIndex, strconv.FormatInt(foreignIndex, 10))
found, err := GetIssueByForeignIndex(context.Background(), issue.RepoID, foreignIndex)
assert.NoError(t, err)
assert.EqualValues(t, found.Index, issue.Index)
}

@ -83,6 +83,13 @@ func insertIssue(ctx context.Context, issue *Issue) error {
} }
} }
if issue.ForeignReference != nil {
issue.ForeignReference.LocalIndex = issue.Index
if _, err := sess.Insert(issue.ForeignReference); err != nil {
return err
}
}
return nil return nil
} }

@ -5,8 +5,10 @@
package models package models
import ( import (
"strconv"
"testing" "testing"
"code.gitea.io/gitea/models/foreignreference"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
@ -45,6 +47,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
UserID: owner.ID, UserID: owner.ID,
} }
foreignIndex := int64(12345)
title := "issuetitle1" title := "issuetitle1"
is := &Issue{ is := &Issue{
RepoID: repo.ID, RepoID: repo.ID,
@ -58,11 +61,20 @@ func assertCreateIssues(t *testing.T, isPull bool) {
IsClosed: true, IsClosed: true,
Labels: []*Label{label}, Labels: []*Label{label},
Reactions: []*Reaction{reaction}, Reactions: []*Reaction{reaction},
ForeignReference: &foreignreference.ForeignReference{
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
RepoID: repo.ID,
Type: foreignreference.TypeIssue,
},
} }
err := InsertIssues(is) err := InsertIssues(is)
assert.NoError(t, err) assert.NoError(t, err)
i := unittest.AssertExistsAndLoadBean(t, &Issue{Title: title}).(*Issue) i := unittest.AssertExistsAndLoadBean(t, &Issue{Title: title}).(*Issue)
assert.Nil(t, i.ForeignReference)
err = i.LoadAttributes()
assert.NoError(t, err)
assert.EqualValues(t, strconv.FormatInt(foreignIndex, 10), i.ForeignReference.ForeignIndex)
unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: owner.ID, IssueID: i.ID}) unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: owner.ID, IssueID: i.ID})
} }

@ -373,6 +373,8 @@ var migrations = []Migration{
NewMigration("Increase WebAuthentication CredentialID size to 410 - NO-OPED", increaseCredentialIDTo410), NewMigration("Increase WebAuthentication CredentialID size to 410 - NO-OPED", increaseCredentialIDTo410),
// v210 -> v211 // v210 -> v211
NewMigration("v208 was completely broken - remigrate", remigrateU2FCredentials), NewMigration("v208 was completely broken - remigrate", remigrateU2FCredentials),
// v211 -> v212
NewMigration("Create ForeignReference table", createForeignReferenceTable),
} }
// GetCurrentDBVersion returns the current db version // GetCurrentDBVersion returns the current db version

@ -0,0 +1,26 @@
// Copyright 2022 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 (
"fmt"
"xorm.io/xorm"
)
func createForeignReferenceTable(x *xorm.Engine) error {
type ForeignReference struct {
// RepoID is the first column in all indices. now we only need 2 indices: (repo, local) and (repo, foreign, type)
RepoID int64 `xorm:"UNIQUE(repo_foreign_type) INDEX(repo_local)" `
LocalIndex int64 `xorm:"INDEX(repo_local)"` // the resource key inside Gitea, it can be IssueIndex, or some model ID.
ForeignIndex string `xorm:"INDEX UNIQUE(repo_foreign_type)"`
Type string `xorm:"VARCHAR(16) INDEX UNIQUE(repo_foreign_type)"`
}
if err := x.Sync2(new(ForeignReference)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
}

@ -7,6 +7,13 @@ package migration
import "time" import "time"
// Commentable can be commented upon
type Commentable interface {
GetLocalIndex() int64
GetForeignIndex() int64
GetContext() DownloaderContext
}
// Comment is a standard comment information // Comment is a standard comment information
type Comment struct { type Comment struct {
IssueIndex int64 `yaml:"issue_index"` IssueIndex int64 `yaml:"issue_index"`

@ -11,13 +11,6 @@ import (
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
) )
// GetCommentOptions represents an options for get comment
type GetCommentOptions struct {
Context IssueContext
Page int
PageSize int
}
// Downloader downloads the site repo information // Downloader downloads the site repo information
type Downloader interface { type Downloader interface {
SetContext(context.Context) SetContext(context.Context)
@ -27,10 +20,11 @@ type Downloader interface {
GetReleases() ([]*Release, error) GetReleases() ([]*Release, error)
GetLabels() ([]*Label, error) GetLabels() ([]*Label, error)
GetIssues(page, perPage int) ([]*Issue, bool, error) GetIssues(page, perPage int) ([]*Issue, bool, error)
GetComments(opts GetCommentOptions) ([]*Comment, bool, error) GetComments(commentable Commentable) ([]*Comment, bool, error)
GetAllComments(page, perPage int) ([]*Comment, bool, error)
SupportGetRepoComments() bool SupportGetRepoComments() bool
GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error)
GetReviews(pullRequestContext IssueContext) ([]*Review, error) GetReviews(reviewable Reviewable) ([]*Review, error)
FormatCloneURL(opts MigrateOptions, remoteAddr string) (string, error) FormatCloneURL(opts MigrateOptions, remoteAddr string) (string, error)
} }
@ -39,3 +33,6 @@ type DownloaderFactory interface {
New(ctx context.Context, opts MigrateOptions) (Downloader, error) New(ctx context.Context, opts MigrateOptions) (Downloader, error)
GitServiceType() structs.GitServiceType GitServiceType() structs.GitServiceType
} }
// DownloaderContext has opaque information only relevant to a given downloader
type DownloaderContext interface{}

@ -7,25 +7,6 @@ package migration
import "time" import "time"
// IssueContext is used to map between local and foreign issue/PR ids.
type IssueContext interface {
LocalID() int64
ForeignID() int64
}
// BasicIssueContext is a 1:1 mapping between local and foreign ids.
type BasicIssueContext int64
// LocalID gets the local id.
func (c BasicIssueContext) LocalID() int64 {
return int64(c)
}
// ForeignID gets the foreign id.
func (c BasicIssueContext) ForeignID() int64 {
return int64(c)
}
// Issue is a standard issue information // Issue is a standard issue information
type Issue struct { type Issue struct {
Number int64 `json:"number"` Number int64 `json:"number"`
@ -44,7 +25,8 @@ type Issue struct {
Labels []*Label `json:"labels"` Labels []*Label `json:"labels"`
Reactions []*Reaction `json:"reactions"` Reactions []*Reaction `json:"reactions"`
Assignees []string `json:"assignees"` Assignees []string `json:"assignees"`
Context IssueContext `yaml:"-"` ForeignIndex int64 `json:"foreign_id"`
Context DownloaderContext `yaml:"-"`
} }
// GetExternalName ExternalUserMigrated interface // GetExternalName ExternalUserMigrated interface
@ -52,3 +34,7 @@ func (i *Issue) GetExternalName() string { return i.PosterName }
// GetExternalID ExternalUserMigrated interface // GetExternalID ExternalUserMigrated interface
func (i *Issue) GetExternalID() int64 { return i.PosterID } func (i *Issue) GetExternalID() int64 { return i.PosterID }
func (i *Issue) GetLocalIndex() int64 { return i.Number }
func (i *Issue) GetForeignIndex() int64 { return i.ForeignIndex }
func (i *Issue) GetContext() DownloaderContext { return i.Context }

@ -47,18 +47,23 @@ func (n NullDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
return nil, false, &ErrNotSupported{Entity: "Issues"} return nil, false, &ErrNotSupported{Entity: "Issues"}
} }
// GetComments returns comments according the options // GetComments returns comments of an issue or PR
func (n NullDownloader) GetComments(GetCommentOptions) ([]*Comment, bool, error) { func (n NullDownloader) GetComments(commentable Commentable) ([]*Comment, bool, error) {
return nil, false, &ErrNotSupported{Entity: "Comments"} return nil, false, &ErrNotSupported{Entity: "Comments"}
} }
// GetAllComments returns paginated comments
func (n NullDownloader) GetAllComments(page, perPage int) ([]*Comment, bool, error) {
return nil, false, &ErrNotSupported{Entity: "AllComments"}
}
// GetPullRequests returns pull requests according page and perPage // GetPullRequests returns pull requests according page and perPage
func (n NullDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) { func (n NullDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
return nil, false, &ErrNotSupported{Entity: "PullRequests"} return nil, false, &ErrNotSupported{Entity: "PullRequests"}
} }
// GetReviews returns pull requests review // GetReviews returns pull requests review
func (n NullDownloader) GetReviews(pullRequestContext IssueContext) ([]*Review, error) { func (n NullDownloader) GetReviews(reviewable Reviewable) ([]*Review, error) {
return nil, &ErrNotSupported{Entity: "Reviews"} return nil, &ErrNotSupported{Entity: "Reviews"}
} }

@ -35,9 +35,14 @@ type PullRequest struct {
Assignees []string Assignees []string
IsLocked bool `yaml:"is_locked"` IsLocked bool `yaml:"is_locked"`
Reactions []*Reaction Reactions []*Reaction
Context IssueContext `yaml:"-"` ForeignIndex int64
Context DownloaderContext `yaml:"-"`
} }
func (p *PullRequest) GetLocalIndex() int64 { return p.Number }
func (p *PullRequest) GetForeignIndex() int64 { return p.ForeignIndex }
func (p *PullRequest) GetContext() DownloaderContext { return p.Context }
// IsForkPullRequest returns true if the pull request from a forked repository but not the same repository // IsForkPullRequest returns true if the pull request from a forked repository but not the same repository
func (p *PullRequest) IsForkPullRequest() bool { func (p *PullRequest) IsForkPullRequest() bool {
return p.Head.RepoPath() != p.Base.RepoPath() return p.Head.RepoPath() != p.Base.RepoPath()

@ -148,7 +148,7 @@ func (d *RetryDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
} }
// GetComments returns a repository's comments with retry // GetComments returns a repository's comments with retry
func (d *RetryDownloader) GetComments(opts GetCommentOptions) ([]*Comment, bool, error) { func (d *RetryDownloader) GetComments(commentable Commentable) ([]*Comment, bool, error) {
var ( var (
comments []*Comment comments []*Comment
isEnd bool isEnd bool
@ -156,7 +156,7 @@ func (d *RetryDownloader) GetComments(opts GetCommentOptions) ([]*Comment, bool,
) )
err = d.retry(func() error { err = d.retry(func() error {
comments, isEnd, err = d.Downloader.GetComments(opts) comments, isEnd, err = d.Downloader.GetComments(commentable)
return err return err
}) })
@ -180,14 +180,14 @@ func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bo
} }
// GetReviews returns pull requests reviews // GetReviews returns pull requests reviews
func (d *RetryDownloader) GetReviews(pullRequestContext IssueContext) ([]*Review, error) { func (d *RetryDownloader) GetReviews(reviewable Reviewable) ([]*Review, error) {
var ( var (
reviews []*Review reviews []*Review
err error err error
) )
err = d.retry(func() error { err = d.retry(func() error {
reviews, err = d.Downloader.GetReviews(pullRequestContext) reviews, err = d.Downloader.GetReviews(reviewable)
return err return err
}) })

@ -6,6 +6,12 @@ package migration
import "time" import "time"
// Reviewable can be reviewed
type Reviewable interface {
GetLocalIndex() int64
GetForeignIndex() int64
}
// enumerate all review states // enumerate all review states
const ( const (
ReviewStatePending = "PENDING" ReviewStatePending = "PENDING"

@ -266,19 +266,9 @@ func (d *CodebaseDownloader) GetLabels() ([]*base.Label, error) {
} }
type codebaseIssueContext struct { type codebaseIssueContext struct {
foreignID int64
localID int64
Comments []*base.Comment Comments []*base.Comment
} }
func (c codebaseIssueContext) LocalID() int64 {
return c.localID
}
func (c codebaseIssueContext) ForeignID() int64 {
return c.foreignID
}
// GetIssues returns issues, limits are not supported // GetIssues returns issues, limits are not supported
// https://support.codebasehq.com/kb/tickets-and-milestones // https://support.codebasehq.com/kb/tickets-and-milestones
// https://support.codebasehq.com/kb/tickets-and-milestones/updating-tickets // https://support.codebasehq.com/kb/tickets-and-milestones/updating-tickets
@ -402,9 +392,8 @@ func (d *CodebaseDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool,
Labels: []*base.Label{ Labels: []*base.Label{
{Name: issue.Type.Name}, {Name: issue.Type.Name},
}, },
ForeignIndex: issue.TicketID.Value,
Context: codebaseIssueContext{ Context: codebaseIssueContext{
foreignID: issue.TicketID.Value,
localID: issue.TicketID.Value,
Comments: comments[1:], Comments: comments[1:],
}, },
}) })
@ -418,10 +407,10 @@ func (d *CodebaseDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool,
} }
// GetComments returns comments // GetComments returns comments
func (d *CodebaseDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { func (d *CodebaseDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
context, ok := opts.Context.(codebaseIssueContext) context, ok := commentable.GetContext().(codebaseIssueContext)
if !ok { if !ok {
return nil, false, fmt.Errorf("unexpected comment context: %+v", opts.Context) return nil, false, fmt.Errorf("unexpected context: %+v", commentable.GetContext())
} }
return context.Comments, true, nil return context.Comments, true, nil
@ -570,9 +559,8 @@ func (d *CodebaseDownloader) GetPullRequests(page, perPage int) ([]*base.PullReq
SHA: d.getHeadCommit(rawMergeRequest.TargetRef), SHA: d.getHeadCommit(rawMergeRequest.TargetRef),
RepoName: d.repoName, RepoName: d.repoName,
}, },
ForeignIndex: rawMergeRequest.ID.Value,
Context: codebaseIssueContext{ Context: codebaseIssueContext{
foreignID: rawMergeRequest.ID.Value,
localID: number,
Comments: comments[1:], Comments: comments[1:],
}, },
}) })
@ -581,16 +569,6 @@ func (d *CodebaseDownloader) GetPullRequests(page, perPage int) ([]*base.PullReq
return pullRequests, true, nil return pullRequests, true, nil
} }
// GetReviews returns pull requests reviews
func (d *CodebaseDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) {
return []*base.Review{}, nil
}
// GetTopics return repository topics
func (d *CodebaseDownloader) GetTopics() ([]string, error) {
return []string{}, nil
}
func (d *CodebaseDownloader) tryGetUser(userID int64) *codebaseUser { func (d *CodebaseDownloader) tryGetUser(userID int64) *codebaseUser {
if len(d.userMap) == 0 { if len(d.userMap) == 0 {
var rawUsers struct { var rawUsers struct {

@ -108,9 +108,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
}, },
}, issues) }, issues)
comments, _, err := downloader.GetComments(base.GetCommentOptions{ comments, _, err := downloader.GetComments(issues[0])
Context: issues[0].Context,
})
assert.NoError(t, err) assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{ assertCommentsEqual(t, []*base.Comment{
{ {
@ -148,7 +146,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
}, },
}, prs) }, prs)
rvs, err := downloader.GetReviews(prs[0].Context) rvs, err := downloader.GetReviews(prs[0])
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, rvs) assert.Empty(t, rvs)
} }

@ -64,8 +64,3 @@ func NewGitBucketDownloader(ctx context.Context, baseURL, userName, password, to
func (g *GitBucketDownloader) SupportGetRepoComments() bool { func (g *GitBucketDownloader) SupportGetRepoComments() bool {
return false return false
} }
// GetReviews is not supported
func (g *GitBucketDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) {
return nil, &base.ErrNotSupported{Entity: "Reviews"}
}

@ -430,7 +430,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
Labels: labels, Labels: labels,
Assignees: assignees, Assignees: assignees,
IsLocked: issue.IsLocked, IsLocked: issue.IsLocked,
Context: base.BasicIssueContext(issue.Index), ForeignIndex: issue.Index,
}) })
} }
@ -442,7 +442,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
} }
// GetComments returns comments according issueNumber // GetComments returns comments according issueNumber
func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { func (g *GiteaDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
allComments := make([]*base.Comment, 0, g.maxPerPage) allComments := make([]*base.Comment, 0, g.maxPerPage)
for i := 1; ; i++ { for i := 1; ; i++ {
@ -453,26 +453,26 @@ func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comm
default: default:
} }
comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID(), gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{ comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, commentable.GetForeignIndex(), gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{
PageSize: g.maxPerPage, PageSize: g.maxPerPage,
Page: i, Page: i,
}}) }})
if err != nil { if err != nil {
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", opts.Context.ForeignID(), err) return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", commentable.GetForeignIndex(), err)
} }
for _, comment := range comments { for _, comment := range comments {
reactions, err := g.getCommentReactions(comment.ID) reactions, err := g.getCommentReactions(comment.ID)
if err != nil { if err != nil {
log.Warn("Unable to load comment reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err) log.Warn("Unable to load comment reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", commentable.GetForeignIndex(), comment.ID, g.repoOwner, g.repoName, err)
if err2 := admin_model.CreateRepositoryNotice( if err2 := admin_model.CreateRepositoryNotice(
fmt.Sprintf("Unable to load reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)); err2 != nil { fmt.Sprintf("Unable to load reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", commentable.GetForeignIndex(), comment.ID, g.repoOwner, g.repoName, err)); err2 != nil {
log.Error("create repository notice failed: ", err2) log.Error("create repository notice failed: ", err2)
} }
} }
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: opts.Context.LocalID(), IssueIndex: commentable.GetLocalIndex(),
Index: comment.ID, Index: comment.ID,
PosterID: comment.Poster.ID, PosterID: comment.Poster.ID,
PosterName: comment.Poster.UserName, PosterName: comment.Poster.UserName,
@ -602,7 +602,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques
RepoName: g.repoName, RepoName: g.repoName,
OwnerName: g.repoOwner, OwnerName: g.repoOwner,
}, },
Context: base.BasicIssueContext(pr.Index), ForeignIndex: pr.Index,
}) })
} }
@ -614,7 +614,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques
} }
// GetReviews returns pull requests review // GetReviews returns pull requests review
func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) { func (g *GiteaDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
if err := g.client.CheckServerVersionConstraint(">=1.12"); err != nil { if err := g.client.CheckServerVersionConstraint(">=1.12"); err != nil {
log.Info("GiteaDownloader: instance to old, skip GetReviews") log.Info("GiteaDownloader: instance to old, skip GetReviews")
return nil, nil return nil, nil
@ -630,7 +630,7 @@ func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review,
default: default:
} }
prl, _, err := g.client.ListPullReviews(g.repoOwner, g.repoName, context.ForeignID(), gitea_sdk.ListPullReviewsOptions{ListOptions: gitea_sdk.ListOptions{ prl, _, err := g.client.ListPullReviews(g.repoOwner, g.repoName, reviewable.GetForeignIndex(), gitea_sdk.ListPullReviewsOptions{ListOptions: gitea_sdk.ListOptions{
Page: i, Page: i,
PageSize: g.maxPerPage, PageSize: g.maxPerPage,
}}) }})
@ -640,7 +640,7 @@ func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review,
for _, pr := range prl { for _, pr := range prl {
rcl, _, err := g.client.ListPullReviewComments(g.repoOwner, g.repoName, context.ForeignID(), pr.ID) rcl, _, err := g.client.ListPullReviewComments(g.repoOwner, g.repoName, reviewable.GetForeignIndex(), pr.ID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -666,7 +666,7 @@ func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review,
allReviews = append(allReviews, &base.Review{ allReviews = append(allReviews, &base.Review{
ID: pr.ID, ID: pr.ID,
IssueIndex: context.LocalID(), IssueIndex: reviewable.GetLocalIndex(),
ReviewerID: pr.Reviewer.ID, ReviewerID: pr.Reviewer.ID,
ReviewerName: pr.Reviewer.UserName, ReviewerName: pr.Reviewer.UserName,
Official: pr.Official, Official: pr.Official,

@ -198,9 +198,7 @@ func TestGiteaDownloadRepo(t *testing.T) {
}, },
}, issues) }, issues)
comments, _, err := downloader.GetComments(base.GetCommentOptions{ comments, _, err := downloader.GetComments(&base.Issue{Number: 4, ForeignIndex: 4})
Context: base.BasicIssueContext(4),
})
assert.NoError(t, err) assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{ assertCommentsEqual(t, []*base.Comment{
{ {
@ -265,7 +263,7 @@ func TestGiteaDownloadRepo(t *testing.T) {
PatchURL: "https://gitea.com/gitea/test_repo/pulls/12.patch", PatchURL: "https://gitea.com/gitea/test_repo/pulls/12.patch",
}, prs[1]) }, prs[1])
reviews, err := downloader.GetReviews(base.BasicIssueContext(7)) reviews, err := downloader.GetReviews(&base.Issue{Number: 7, ForeignIndex: 7})
assert.NoError(t, err) assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{ assertReviewsEqual(t, []*base.Review{
{ {

@ -11,11 +11,13 @@ import (
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"time" "time"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/foreignreference"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
@ -373,6 +375,12 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
Labels: labels, Labels: labels,
CreatedUnix: timeutil.TimeStamp(issue.Created.Unix()), CreatedUnix: timeutil.TimeStamp(issue.Created.Unix()),
UpdatedUnix: timeutil.TimeStamp(issue.Updated.Unix()), UpdatedUnix: timeutil.TimeStamp(issue.Updated.Unix()),
ForeignReference: &foreignreference.ForeignReference{
LocalIndex: issue.GetLocalIndex(),
ForeignIndex: strconv.FormatInt(issue.GetForeignIndex(), 10),
RepoID: g.repo.ID,
Type: foreignreference.TypeIssue,
},
} }
if err := g.remapUser(issue, &is); err != nil { if err := g.remapUser(issue, &is); err != nil {

@ -461,7 +461,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
Closed: issue.ClosedAt, Closed: issue.ClosedAt,
IsLocked: issue.GetLocked(), IsLocked: issue.GetLocked(),
Assignees: assignees, Assignees: assignees,
Context: base.BasicIssueContext(*issue.Number), ForeignIndex: int64(*issue.Number),
}) })
} }
@ -474,16 +474,12 @@ func (g *GithubDownloaderV3) SupportGetRepoComments() bool {
} }
// GetComments returns comments according issueNumber // GetComments returns comments according issueNumber
func (g *GithubDownloaderV3) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { func (g *GithubDownloaderV3) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
if opts.Context != nil { comments, err := g.getComments(commentable)
comments, err := g.getComments(opts.Context)
return comments, false, err return comments, false, err
} }
return g.GetAllComments(opts.Page, opts.PageSize) func (g *GithubDownloaderV3) getComments(commentable base.Commentable) ([]*base.Comment, error) {
}
func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*base.Comment, error) {
var ( var (
allComments = make([]*base.Comment, 0, g.maxPerPage) allComments = make([]*base.Comment, 0, g.maxPerPage)
created = "created" created = "created"
@ -498,7 +494,7 @@ func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*bas
} }
for { for {
g.waitAndPickClient() g.waitAndPickClient()
comments, resp, err := g.getClient().Issues.ListComments(g.ctx, g.repoOwner, g.repoName, int(issueContext.ForeignID()), opt) comments, resp, err := g.getClient().Issues.ListComments(g.ctx, g.repoOwner, g.repoName, int(commentable.GetForeignIndex()), opt)
if err != nil { if err != nil {
return nil, fmt.Errorf("error while listing repos: %v", err) return nil, fmt.Errorf("error while listing repos: %v", err)
} }
@ -531,7 +527,7 @@ func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*bas
} }
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: issueContext.LocalID(), IssueIndex: commentable.GetLocalIndex(),
Index: comment.GetID(), Index: comment.GetID(),
PosterID: comment.GetUser().GetID(), PosterID: comment.GetUser().GetID(),
PosterName: comment.GetUser().GetLogin(), PosterName: comment.GetUser().GetLogin(),
@ -711,7 +707,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
}, },
PatchURL: pr.GetPatchURL(), PatchURL: pr.GetPatchURL(),
Reactions: reactions, Reactions: reactions,
Context: base.BasicIssueContext(*pr.Number), ForeignIndex: int64(*pr.Number),
}) })
} }
@ -777,28 +773,28 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
} }
// GetReviews returns pull requests review // GetReviews returns pull requests review
func (g *GithubDownloaderV3) GetReviews(context base.IssueContext) ([]*base.Review, error) { func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
allReviews := make([]*base.Review, 0, g.maxPerPage) allReviews := make([]*base.Review, 0, g.maxPerPage)
opt := &github.ListOptions{ opt := &github.ListOptions{
PerPage: g.maxPerPage, PerPage: g.maxPerPage,
} }
for { for {
g.waitAndPickClient() g.waitAndPickClient()
reviews, resp, err := g.getClient().PullRequests.ListReviews(g.ctx, g.repoOwner, g.repoName, int(context.ForeignID()), opt) reviews, resp, err := g.getClient().PullRequests.ListReviews(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), opt)
if err != nil { if err != nil {
return nil, fmt.Errorf("error while listing repos: %v", err) return nil, fmt.Errorf("error while listing repos: %v", err)
} }
g.setRate(&resp.Rate) g.setRate(&resp.Rate)
for _, review := range reviews { for _, review := range reviews {
r := convertGithubReview(review) r := convertGithubReview(review)
r.IssueIndex = context.LocalID() r.IssueIndex = reviewable.GetLocalIndex()
// retrieve all review comments // retrieve all review comments
opt2 := &github.ListOptions{ opt2 := &github.ListOptions{
PerPage: g.maxPerPage, PerPage: g.maxPerPage,
} }
for { for {
g.waitAndPickClient() g.waitAndPickClient()
reviewComments, resp, err := g.getClient().PullRequests.ListReviewComments(g.ctx, g.repoOwner, g.repoName, int(context.ForeignID()), review.GetID(), opt2) reviewComments, resp, err := g.getClient().PullRequests.ListReviewComments(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), review.GetID(), opt2)
if err != nil { if err != nil {
return nil, fmt.Errorf("error while listing repos: %v", err) return nil, fmt.Errorf("error while listing repos: %v", err)
} }

@ -215,9 +215,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
}, issues) }, issues)
// downloader.GetComments() // downloader.GetComments()
comments, _, err := downloader.GetComments(base.GetCommentOptions{ comments, _, err := downloader.GetComments(&base.Issue{Number: 2, ForeignIndex: 2})
Context: base.BasicIssueContext(2),
})
assert.NoError(t, err) assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{ assertCommentsEqual(t, []*base.Comment{
{ {
@ -286,7 +284,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
Merged: true, Merged: true,
MergedTime: timePtr(time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)), MergedTime: timePtr(time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)),
MergeCommitSHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2", MergeCommitSHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
Context: base.BasicIssueContext(3), ForeignIndex: 3,
}, },
{ {
Number: 4, Number: 4,
@ -333,11 +331,11 @@ func TestGitHubDownloadRepo(t *testing.T) {
Content: "+1", Content: "+1",
}, },
}, },
Context: base.BasicIssueContext(4), ForeignIndex: 4,
}, },
}, prs) }, prs)
reviews, err := downloader.GetReviews(base.BasicIssueContext(3)) reviews, err := downloader.GetReviews(&base.PullRequest{Number: 3, ForeignIndex: 3})
assert.NoError(t, err) assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{ assertReviewsEqual(t, []*base.Review{
{ {
@ -369,7 +367,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
}, },
}, reviews) }, reviews)
reviews, err = downloader.GetReviews(base.BasicIssueContext(4)) reviews, err = downloader.GetReviews(&base.PullRequest{Number: 4, ForeignIndex: 4})
assert.NoError(t, err) assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{ assertReviewsEqual(t, []*base.Review{
{ {

@ -349,19 +349,9 @@ func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
} }
type gitlabIssueContext struct { type gitlabIssueContext struct {
foreignID int64
localID int64
IsMergeRequest bool IsMergeRequest bool
} }
func (c gitlabIssueContext) LocalID() int64 {
return c.localID
}
func (c gitlabIssueContext) ForeignID() int64 {
return c.foreignID
}
// GetIssues returns issues according start and limit // GetIssues returns issues according start and limit
// Note: issue label description and colors are not supported by the go-gitlab library at this time // Note: issue label description and colors are not supported by the go-gitlab library at this time
func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, error) { func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, error) {
@ -434,11 +424,8 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
Closed: issue.ClosedAt, Closed: issue.ClosedAt,
IsLocked: issue.DiscussionLocked, IsLocked: issue.DiscussionLocked,
Updated: *issue.UpdatedAt, Updated: *issue.UpdatedAt,
Context: gitlabIssueContext{ ForeignIndex: int64(issue.IID),
foreignID: int64(issue.IID), Context: gitlabIssueContext{IsMergeRequest: false},
localID: int64(issue.IID),
IsMergeRequest: false,
},
}) })
// increment issueCount, to be used in GetPullRequests() // increment issueCount, to be used in GetPullRequests()
@ -450,10 +437,10 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
// GetComments returns comments according issueNumber // GetComments returns comments according issueNumber
// TODO: figure out how to transfer comment reactions // TODO: figure out how to transfer comment reactions
func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { func (g *GitlabDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
context, ok := opts.Context.(gitlabIssueContext) context, ok := commentable.GetContext().(gitlabIssueContext)
if !ok { if !ok {
return nil, false, fmt.Errorf("unexpected context: %+v", opts.Context) return nil, false, fmt.Errorf("unexpected context: %+v", commentable.GetContext())
} }
allComments := make([]*base.Comment, 0, g.maxPerPage) allComments := make([]*base.Comment, 0, g.maxPerPage)
@ -465,12 +452,12 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
var resp *gitlab.Response var resp *gitlab.Response
var err error var err error
if !context.IsMergeRequest { if !context.IsMergeRequest {
comments, resp, err = g.client.Discussions.ListIssueDiscussions(g.repoID, int(context.ForeignID()), &gitlab.ListIssueDiscussionsOptions{ comments, resp, err = g.client.Discussions.ListIssueDiscussions(g.repoID, int(commentable.GetForeignIndex()), &gitlab.ListIssueDiscussionsOptions{
Page: page, Page: page,
PerPage: g.maxPerPage, PerPage: g.maxPerPage,
}, nil, gitlab.WithContext(g.ctx)) }, nil, gitlab.WithContext(g.ctx))
} else { } else {
comments, resp, err = g.client.Discussions.ListMergeRequestDiscussions(g.repoID, int(context.ForeignID()), &gitlab.ListMergeRequestDiscussionsOptions{ comments, resp, err = g.client.Discussions.ListMergeRequestDiscussions(g.repoID, int(commentable.GetForeignIndex()), &gitlab.ListMergeRequestDiscussionsOptions{
Page: page, Page: page,
PerPage: g.maxPerPage, PerPage: g.maxPerPage,
}, nil, gitlab.WithContext(g.ctx)) }, nil, gitlab.WithContext(g.ctx))
@ -484,7 +471,7 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
if !comment.IndividualNote { if !comment.IndividualNote {
for _, note := range comment.Notes { for _, note := range comment.Notes {
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: context.LocalID(), IssueIndex: commentable.GetLocalIndex(),
Index: int64(note.ID), Index: int64(note.ID),
PosterID: int64(note.Author.ID), PosterID: int64(note.Author.ID),
PosterName: note.Author.Username, PosterName: note.Author.Username,
@ -496,7 +483,7 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
} else { } else {
c := comment.Notes[0] c := comment.Notes[0]
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: context.LocalID(), IssueIndex: commentable.GetLocalIndex(),
Index: int64(c.ID), Index: int64(c.ID),
PosterID: int64(c.Author.ID), PosterID: int64(c.Author.ID),
PosterName: c.Author.Username, PosterName: c.Author.Username,
@ -620,11 +607,8 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
OwnerName: pr.Author.Username, OwnerName: pr.Author.Username,
}, },
PatchURL: pr.WebURL + ".patch", PatchURL: pr.WebURL + ".patch",
Context: gitlabIssueContext{ ForeignIndex: int64(pr.IID),
foreignID: int64(pr.IID), Context: gitlabIssueContext{IsMergeRequest: true},
localID: newPRNumber,
IsMergeRequest: true,
},
}) })
} }
@ -632,8 +616,8 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
} }
// GetReviews returns pull requests review // GetReviews returns pull requests review
func (g *GitlabDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) { func (g *GitlabDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
approvals, resp, err := g.client.MergeRequestApprovals.GetConfiguration(g.repoID, int(context.ForeignID()), gitlab.WithContext(g.ctx)) approvals, resp, err := g.client.MergeRequestApprovals.GetConfiguration(g.repoID, int(reviewable.GetForeignIndex()), gitlab.WithContext(g.ctx))
if err != nil { if err != nil {
if resp != nil && resp.StatusCode == 404 { if resp != nil && resp.StatusCode == 404 {
log.Error(fmt.Sprintf("GitlabDownloader: while migrating a error occurred: '%s'", err.Error())) log.Error(fmt.Sprintf("GitlabDownloader: while migrating a error occurred: '%s'", err.Error()))
@ -654,7 +638,7 @@ func (g *GitlabDownloader) GetReviews(context base.IssueContext) ([]*base.Review
reviews := make([]*base.Review, 0, len(approvals.ApprovedBy)) reviews := make([]*base.Review, 0, len(approvals.ApprovedBy))
for _, user := range approvals.ApprovedBy { for _, user := range approvals.ApprovedBy {
reviews = append(reviews, &base.Review{ reviews = append(reviews, &base.Review{
IssueIndex: context.LocalID(), IssueIndex: reviewable.GetLocalIndex(),
ReviewerID: int64(user.User.ID), ReviewerID: int64(user.User.ID),
ReviewerName: user.User.Username, ReviewerName: user.User.Username,
CreatedAt: createdAt, CreatedAt: createdAt,

@ -214,12 +214,10 @@ func TestGitlabDownloadRepo(t *testing.T) {
}, },
}, issues) }, issues)
comments, _, err := downloader.GetComments(base.GetCommentOptions{ comments, _, err := downloader.GetComments(&base.Issue{
Context: gitlabIssueContext{ Number: 2,
foreignID: 2, ForeignIndex: 2,
localID: 2, Context: gitlabIssueContext{IsMergeRequest: false},
IsMergeRequest: false,
},
}) })
assert.NoError(t, err) assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{ assertCommentsEqual(t, []*base.Comment{
@ -301,15 +299,12 @@ func TestGitlabDownloadRepo(t *testing.T) {
Merged: false, Merged: false,
MergedTime: nil, MergedTime: nil,
MergeCommitSHA: "", MergeCommitSHA: "",
Context: gitlabIssueContext{ ForeignIndex: 2,
foreignID: 2, Context: gitlabIssueContext{IsMergeRequest: true},
localID: 4,
IsMergeRequest: true,
},
}, },
}, prs) }, prs)
rvs, err := downloader.GetReviews(base.BasicIssueContext(1)) rvs, err := downloader.GetReviews(&base.PullRequest{Number: 1, ForeignIndex: 1})
assert.NoError(t, err) assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{ assertReviewsEqual(t, []*base.Review{
{ {
@ -328,7 +323,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
}, },
}, rvs) }, rvs)
rvs, err = downloader.GetReviews(base.BasicIssueContext(2)) rvs, err = downloader.GetReviews(&base.PullRequest{Number: 2, ForeignIndex: 2})
assert.NoError(t, err) assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{ assertReviewsEqual(t, []*base.Review{
{ {
@ -469,7 +464,8 @@ func TestGitlabGetReviews(t *testing.T) {
mock, review := convertTestCase(testCase) mock, review := convertTestCase(testCase)
mux.HandleFunc(fmt.Sprintf("/api/v4/projects/%d/merge_requests/%d/approvals", testCase.repoID, testCase.prID), mock) mux.HandleFunc(fmt.Sprintf("/api/v4/projects/%d/merge_requests/%d/approvals", testCase.repoID, testCase.prID), mock)
rvs, err := downloader.GetReviews(base.BasicIssueContext(testCase.prID)) id := int64(testCase.prID)
rvs, err := downloader.GetReviews(&base.Issue{Number: id, ForeignIndex: id})
assert.NoError(t, err) assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{&review}, rvs) assertReviewsEqual(t, []*base.Review{&review}, rvs)
} }

@ -223,10 +223,10 @@ func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool,
} }
// GetComments returns comments according issueNumber // GetComments returns comments according issueNumber
func (g *GogsDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { func (g *GogsDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
allComments := make([]*base.Comment, 0, 100) allComments := make([]*base.Comment, 0, 100)
comments, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID()) comments, err := g.client.ListIssueComments(g.repoOwner, g.repoName, commentable.GetForeignIndex())
if err != nil { if err != nil {
return nil, false, fmt.Errorf("error while listing repos: %v", err) return nil, false, fmt.Errorf("error while listing repos: %v", err)
} }
@ -235,7 +235,7 @@ func (g *GogsDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comme
continue continue
} }
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: opts.Context.LocalID(), IssueIndex: commentable.GetLocalIndex(),
Index: comment.ID, Index: comment.ID,
PosterID: comment.Poster.ID, PosterID: comment.Poster.ID,
PosterName: comment.Poster.Login, PosterName: comment.Poster.Login,
@ -300,7 +300,7 @@ func convertGogsIssue(issue *gogs.Issue) *base.Issue {
Updated: issue.Updated, Updated: issue.Updated,
Labels: labels, Labels: labels,
Closed: closed, Closed: closed,
Context: base.BasicIssueContext(issue.Index), ForeignIndex: issue.Index,
} }
} }

@ -111,9 +111,7 @@ func TestGogsDownloadRepo(t *testing.T) {
}, issues) }, issues)
// downloader.GetComments() // downloader.GetComments()
comments, _, err := downloader.GetComments(base.GetCommentOptions{ comments, _, err := downloader.GetComments(&base.Issue{Number: 1, ForeignIndex: 1})
Context: base.BasicIssueContext(1),
})
assert.NoError(t, err) assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{ assertCommentsEqual(t, []*base.Comment{
{ {

@ -325,9 +325,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
allComments := make([]*base.Comment, 0, commentBatchSize) allComments := make([]*base.Comment, 0, commentBatchSize)
for _, issue := range issues { for _, issue := range issues {
log.Trace("migrating issue %d's comments", issue.Number) log.Trace("migrating issue %d's comments", issue.Number)
comments, _, err := downloader.GetComments(base.GetCommentOptions{ comments, _, err := downloader.GetComments(issue)
Context: issue.Context,
})
if err != nil { if err != nil {
if !base.IsErrNotSupported(err) { if !base.IsErrNotSupported(err) {
return err return err
@ -383,9 +381,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
allComments := make([]*base.Comment, 0, commentBatchSize) allComments := make([]*base.Comment, 0, commentBatchSize)
for _, pr := range prs { for _, pr := range prs {
log.Trace("migrating pull request %d's comments", pr.Number) log.Trace("migrating pull request %d's comments", pr.Number)
comments, _, err := downloader.GetComments(base.GetCommentOptions{ comments, _, err := downloader.GetComments(pr)
Context: pr.Context,
})
if err != nil { if err != nil {
if !base.IsErrNotSupported(err) { if !base.IsErrNotSupported(err) {
return err return err
@ -412,7 +408,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
// migrate reviews // migrate reviews
allReviews := make([]*base.Review, 0, reviewBatchSize) allReviews := make([]*base.Review, 0, reviewBatchSize)
for _, pr := range prs { for _, pr := range prs {
reviews, err := downloader.GetReviews(pr.Context) reviews, err := downloader.GetReviews(pr)
if err != nil { if err != nil {
if !base.IsErrNotSupported(err) { if !base.IsErrNotSupported(err) {
return err return err
@ -446,10 +442,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
if opts.Comments && supportAllComments { if opts.Comments && supportAllComments {
log.Trace("migrating comments") log.Trace("migrating comments")
for i := 1; ; i++ { for i := 1; ; i++ {
comments, isEnd, err := downloader.GetComments(base.GetCommentOptions{ comments, isEnd, err := downloader.GetAllComments(i, commentBatchSize)
Page: i,
PageSize: commentBatchSize,
})
if err != nil { if err != nil {
return err return err
} }

@ -262,19 +262,9 @@ func (d *OneDevDownloader) GetLabels() ([]*base.Label, error) {
} }
type onedevIssueContext struct { type onedevIssueContext struct {
foreignID int64
localID int64
IsPullRequest bool IsPullRequest bool
} }
func (c onedevIssueContext) LocalID() int64 {
return c.localID
}
func (c onedevIssueContext) ForeignID() int64 {
return c.foreignID
}
// GetIssues returns issues // GetIssues returns issues
func (d *OneDevDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, error) { func (d *OneDevDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, error) {
rawIssues := make([]struct { rawIssues := make([]struct {
@ -356,11 +346,8 @@ func (d *OneDevDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
Created: issue.SubmitDate, Created: issue.SubmitDate,
Updated: issue.SubmitDate, Updated: issue.SubmitDate,
Labels: []*base.Label{label}, Labels: []*base.Label{label},
Context: onedevIssueContext{ ForeignIndex: issue.ID,
foreignID: issue.ID, Context: onedevIssueContext{IsPullRequest: false},
localID: issue.Number,
IsPullRequest: false,
},
}) })
if d.maxIssueIndex < issue.Number { if d.maxIssueIndex < issue.Number {
@ -372,10 +359,10 @@ func (d *OneDevDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
} }
// GetComments returns comments // GetComments returns comments
func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { func (d *OneDevDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
context, ok := opts.Context.(onedevIssueContext) context, ok := commentable.GetContext().(onedevIssueContext)
if !ok { if !ok {
return nil, false, fmt.Errorf("unexpected comment context: %+v", opts.Context) return nil, false, fmt.Errorf("unexpected context: %+v", commentable.GetContext())
} }
rawComments := make([]struct { rawComments := make([]struct {
@ -387,9 +374,9 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
var endpoint string var endpoint string
if context.IsPullRequest { if context.IsPullRequest {
endpoint = fmt.Sprintf("/api/pull-requests/%d/comments", context.ForeignID()) endpoint = fmt.Sprintf("/api/pull-requests/%d/comments", commentable.GetForeignIndex())
} else { } else {
endpoint = fmt.Sprintf("/api/issues/%d/comments", context.ForeignID()) endpoint = fmt.Sprintf("/api/issues/%d/comments", commentable.GetForeignIndex())
} }
err := d.callAPI( err := d.callAPI(
@ -408,9 +395,9 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
}, 0, 100) }, 0, 100)
if context.IsPullRequest { if context.IsPullRequest {
endpoint = fmt.Sprintf("/api/pull-requests/%d/changes", context.ForeignID()) endpoint = fmt.Sprintf("/api/pull-requests/%d/changes", commentable.GetForeignIndex())
} else { } else {
endpoint = fmt.Sprintf("/api/issues/%d/changes", context.ForeignID()) endpoint = fmt.Sprintf("/api/issues/%d/changes", commentable.GetForeignIndex())
} }
err = d.callAPI( err = d.callAPI(
@ -429,7 +416,7 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
} }
poster := d.tryGetUser(comment.UserID) poster := d.tryGetUser(comment.UserID)
comments = append(comments, &base.Comment{ comments = append(comments, &base.Comment{
IssueIndex: context.LocalID(), IssueIndex: commentable.GetLocalIndex(),
Index: comment.ID, Index: comment.ID,
PosterID: poster.ID, PosterID: poster.ID,
PosterName: poster.Name, PosterName: poster.Name,
@ -454,7 +441,7 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
poster := d.tryGetUser(change.UserID) poster := d.tryGetUser(change.UserID)
comments = append(comments, &base.Comment{ comments = append(comments, &base.Comment{
IssueIndex: context.LocalID(), IssueIndex: commentable.GetLocalIndex(),
PosterID: poster.ID, PosterID: poster.ID,
PosterName: poster.Name, PosterName: poster.Name,
PosterEmail: poster.Email, PosterEmail: poster.Email,
@ -552,11 +539,8 @@ func (d *OneDevDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
SHA: mergePreview.TargetHeadCommitHash, SHA: mergePreview.TargetHeadCommitHash,
RepoName: d.repoName, RepoName: d.repoName,
}, },
Context: onedevIssueContext{ ForeignIndex: pr.ID,
foreignID: pr.ID, Context: onedevIssueContext{IsPullRequest: true},
localID: number,
IsPullRequest: true,
},
}) })
} }
@ -564,7 +548,7 @@ func (d *OneDevDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
} }
// GetReviews returns pull requests reviews // GetReviews returns pull requests reviews
func (d *OneDevDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) { func (d *OneDevDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
rawReviews := make([]struct { rawReviews := make([]struct {
ID int64 `json:"id"` ID int64 `json:"id"`
UserID int64 `json:"userId"` UserID int64 `json:"userId"`
@ -576,7 +560,7 @@ func (d *OneDevDownloader) GetReviews(context base.IssueContext) ([]*base.Review
}, 0, 100) }, 0, 100)
err := d.callAPI( err := d.callAPI(
fmt.Sprintf("/api/pull-requests/%d/reviews", context.ForeignID()), fmt.Sprintf("/api/pull-requests/%d/reviews", reviewable.GetForeignIndex()),
nil, nil,
&rawReviews, &rawReviews,
) )
@ -600,7 +584,7 @@ func (d *OneDevDownloader) GetReviews(context base.IssueContext) ([]*base.Review
poster := d.tryGetUser(review.UserID) poster := d.tryGetUser(review.UserID)
reviews = append(reviews, &base.Review{ reviews = append(reviews, &base.Review{
IssueIndex: context.LocalID(), IssueIndex: reviewable.GetLocalIndex(),
ReviewerID: poster.ID, ReviewerID: poster.ID,
ReviewerName: poster.Name, ReviewerName: poster.Name,
Content: content, Content: content,

@ -74,11 +74,8 @@ func TestOneDevDownloadRepo(t *testing.T) {
Name: "Improvement", Name: "Improvement",
}, },
}, },
Context: onedevIssueContext{ ForeignIndex: 398,
foreignID: 398, Context: onedevIssueContext{IsPullRequest: false},
localID: 4,
IsPullRequest: false,
},
}, },
{ {
Number: 3, Number: 3,
@ -94,20 +91,15 @@ func TestOneDevDownloadRepo(t *testing.T) {
Name: "New Feature", Name: "New Feature",
}, },
}, },
Context: onedevIssueContext{ ForeignIndex: 397,
foreignID: 397, Context: onedevIssueContext{IsPullRequest: false},
localID: 3,
IsPullRequest: false,
},
}, },
}, issues) }, issues)
comments, _, err := downloader.GetComments(base.GetCommentOptions{ comments, _, err := downloader.GetComments(&base.Issue{
Context: onedevIssueContext{ Number: 4,
foreignID: 398, ForeignIndex: 398,
localID: 4, Context: onedevIssueContext{IsPullRequest: false},
IsPullRequest: false,
},
}) })
assert.NoError(t, err) assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{ assertCommentsEqual(t, []*base.Comment{
@ -141,18 +133,12 @@ func TestOneDevDownloadRepo(t *testing.T) {
SHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2", SHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
RepoName: "go-gitea-test_repo", RepoName: "go-gitea-test_repo",
}, },
Context: onedevIssueContext{ ForeignIndex: 186,
foreignID: 186, Context: onedevIssueContext{IsPullRequest: true},
localID: 5,
IsPullRequest: true,
},
}, },
}, prs) }, prs)
rvs, err := downloader.GetReviews(onedevIssueContext{ rvs, err := downloader.GetReviews(&base.PullRequest{Number: 5, ForeignIndex: 186})
foreignID: 186,
localID: 5,
})
assert.NoError(t, err) assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{ assertReviewsEqual(t, []*base.Review{
{ {

@ -193,17 +193,13 @@ func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool,
} }
return nil, false, err return nil, false, err
} }
for _, issue := range issues {
issue.Context = base.BasicIssueContext(issue.Number)
}
return issues, true, nil return issues, true, nil
} }
// GetComments returns comments according issueNumber // GetComments returns comments according issueNumber
func (r *RepositoryRestorer) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { func (r *RepositoryRestorer) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
comments := make([]*base.Comment, 0, 10) comments := make([]*base.Comment, 0, 10)
p := filepath.Join(r.commentDir(), fmt.Sprintf("%d.yml", opts.Context.ForeignID())) p := filepath.Join(r.commentDir(), fmt.Sprintf("%d.yml", commentable.GetForeignIndex()))
_, err := os.Stat(p) _, err := os.Stat(p)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
@ -247,15 +243,14 @@ func (r *RepositoryRestorer) GetPullRequests(page, perPage int) ([]*base.PullReq
} }
for _, pr := range pulls { for _, pr := range pulls {
pr.PatchURL = "file://" + filepath.Join(r.baseDir, pr.PatchURL) pr.PatchURL = "file://" + filepath.Join(r.baseDir, pr.PatchURL)
pr.Context = base.BasicIssueContext(pr.Number)
} }
return pulls, true, nil return pulls, true, nil
} }
// GetReviews returns pull requests review // GetReviews returns pull requests review
func (r *RepositoryRestorer) GetReviews(context base.IssueContext) ([]*base.Review, error) { func (r *RepositoryRestorer) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
reviews := make([]*base.Review, 0, 10) reviews := make([]*base.Review, 0, 10)
p := filepath.Join(r.reviewDir(), fmt.Sprintf("%d.yml", context.ForeignID())) p := filepath.Join(r.reviewDir(), fmt.Sprintf("%d.yml", reviewable.GetForeignIndex()))
_, err := os.Stat(p) _, err := os.Stat(p)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {

Loading…
Cancel
Save