Skip to content

Commit 7197bf2

Browse files
Loïc Dacharyrealaravinth
Loïc Dachary
authored andcommitted
s/GlobalID/GlobalIndex/ s/LocalID/LocalIndex/
1 parent fdd4770 commit 7197bf2

23 files changed

+221
-221
lines changed

models/error.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,36 +1395,36 @@ func (err ErrNotValidReviewRequest) Error() string {
13951395
// \/ \/ /_____/ \/ \/ \/ \/ \/ \/ \/ \/
13961396
//
13971397

1398-
// ErrLocalIDNotExist represents a "LocalIDNotExist" kind of error.
1399-
type ErrLocalIDNotExist struct {
1400-
RepoID int64
1401-
ForeignID int64
1402-
Type string
1398+
// ErrLocalIndexNotExist represents a "LocalIndexNotExist" kind of error.
1399+
type ErrLocalIndexNotExist struct {
1400+
RepoID int64
1401+
ForeignIndex int64
1402+
Type string
14031403
}
14041404

1405-
// ErrLocalIDNotExist checks if an error is a ErrLocalIDNotExist.
1406-
func IsErrLocalIDNotExist(err error) bool {
1407-
_, ok := err.(ErrLocalIDNotExist)
1405+
// ErrLocalIndexNotExist checks if an error is a ErrLocalIndexNotExist.
1406+
func IsErrLocalIndexNotExist(err error) bool {
1407+
_, ok := err.(ErrLocalIndexNotExist)
14081408
return ok
14091409
}
14101410

1411-
func (err ErrLocalIDNotExist) Error() string {
1412-
return fmt.Sprintf("repository %d has no LocalID for ForeignID %d of type %s", err.RepoID, err.ForeignID, err.Type)
1411+
func (err ErrLocalIndexNotExist) Error() string {
1412+
return fmt.Sprintf("repository %d has no LocalIndex for ForeignIndex %d of type %s", err.RepoID, err.ForeignIndex, err.Type)
14131413
}
14141414

1415-
// ErrForeignIDNotExist represents a "ForeignIDNotExist" kind of error.
1416-
type ErrForeignIDNotExist struct {
1417-
RepoID int64
1418-
LocalID int64
1419-
Type string
1415+
// ErrForeignIndexNotExist represents a "ForeignIndexNotExist" kind of error.
1416+
type ErrForeignIndexNotExist struct {
1417+
RepoID int64
1418+
LocalIndex int64
1419+
Type string
14201420
}
14211421

1422-
// ErrForeignIDNotExist checks if an error is a ErrForeignIDNotExist.
1423-
func IsErrForeignIDNotExist(err error) bool {
1424-
_, ok := err.(ErrForeignIDNotExist)
1422+
// ErrForeignIndexNotExist checks if an error is a ErrForeignIndexNotExist.
1423+
func IsErrForeignIndexNotExist(err error) bool {
1424+
_, ok := err.(ErrForeignIndexNotExist)
14251425
return ok
14261426
}
14271427

1428-
func (err ErrForeignIDNotExist) Error() string {
1429-
return fmt.Sprintf("repository %d has no ForeignID for LocalID %d of type %s", err.RepoID, err.LocalID, err.Type)
1428+
func (err ErrForeignIndexNotExist) Error() string {
1429+
return fmt.Sprintf("repository %d has no ForeignIndex for LocalIndex %d of type %s", err.RepoID, err.LocalIndex, err.Type)
14301430
}

models/foreignreference.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ const ForeignTypeIssue = "issue"
1414
// ForeignReference represents external references
1515
type ForeignReference struct {
1616
// RepoID is the first column in all indices. now we only need 2 indices: (repo, local) and (repo, foreign, type)
17-
RepoID int64 `xorm:"UNIQUE(repo_foreign_type) INDEX(repo_local)" `
18-
LocalID int64 `xorm:"INDEX(repo_local)"` // the resource key inside Gitea, it can be IssueIndex, or some model ID.
19-
ForeignID string `xorm:"INDEX UNIQUE(repo_foreign_type)"`
20-
Type string `xorm:"VARCHAR(8) INDEX UNIQUE(repo_foreign_type)"`
17+
RepoID int64 `xorm:"UNIQUE(repo_foreign_type) INDEX(repo_local)" `
18+
LocalIndex int64 `xorm:"INDEX(repo_local)"` // the resource key inside Gitea, it can be IssueIndex, or some model ID.
19+
ForeignIndex string `xorm:"INDEX UNIQUE(repo_foreign_type)"`
20+
Type string `xorm:"VARCHAR(8) INDEX UNIQUE(repo_foreign_type)"`
2121
}
2222

2323
func init() {

models/issue.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,15 @@ func (issue *Issue) loadForeignReference(ctx context.Context) (err error) {
277277
return nil
278278
}
279279
reference := &ForeignReference{
280-
LocalID: issue.Index,
281-
RepoID: issue.RepoID,
282-
Type: ForeignTypeIssue,
280+
LocalIndex: issue.Index,
281+
RepoID: issue.RepoID,
282+
Type: ForeignTypeIssue,
283283
}
284284
has, err := db.GetEngine(ctx).Get(reference)
285285
if err != nil {
286286
return err
287287
} else if !has {
288-
return ErrForeignIDNotExist{issue.RepoID, issue.Index, ForeignTypeIssue}
288+
return ErrForeignIndexNotExist{issue.RepoID, issue.Index, ForeignTypeIssue}
289289
}
290290
issue.ForeignReference = reference
291291
return nil
@@ -352,7 +352,7 @@ func (issue *Issue) loadAttributes(ctx context.Context) (err error) {
352352
}
353353
}
354354

355-
if err = issue.loadForeignReference(ctx); err != nil && !IsErrForeignIDNotExist(err) {
355+
if err = issue.loadForeignReference(ctx); err != nil && !IsErrForeignIndexNotExist(err) {
356356
return err
357357
}
358358

@@ -1134,20 +1134,20 @@ func GetIssueByIndex(repoID, index int64) (*Issue, error) {
11341134
return issue, nil
11351135
}
11361136

1137-
// GetIssueByForeignID returns raw issue by foreign ID
1138-
func GetIssueByForeignID(ctx context.Context, repoID, foreignID int64) (*Issue, error) {
1137+
// GetIssueByForeignIndex returns raw issue by foreign ID
1138+
func GetIssueByForeignIndex(ctx context.Context, repoID, foreignIndex int64) (*Issue, error) {
11391139
reference := &ForeignReference{
1140-
RepoID: repoID,
1141-
ForeignID: strconv.FormatInt(foreignID, 10),
1142-
Type: ForeignTypeIssue,
1140+
RepoID: repoID,
1141+
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
1142+
Type: ForeignTypeIssue,
11431143
}
11441144
has, err := db.GetEngine(ctx).Get(reference)
11451145
if err != nil {
11461146
return nil, err
11471147
} else if !has {
1148-
return nil, ErrLocalIDNotExist{repoID, foreignID, ForeignTypeIssue}
1148+
return nil, ErrLocalIndexNotExist{repoID, foreignIndex, ForeignTypeIssue}
11491149
}
1150-
return GetIssueByIndex(repoID, reference.LocalID)
1150+
return GetIssueByIndex(repoID, reference.LocalIndex)
11511151
}
11521152

11531153
// GetIssueWithAttrsByIndex returns issue by index in a repository.

models/issue_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -546,24 +546,24 @@ func TestIssueForeignReference(t *testing.T) {
546546
assert.NoError(t, err)
547547
assert.Nil(t, issue.ForeignReference)
548548

549-
var foreignID int64 = 12345
550-
_, err = GetIssueByForeignID(context.Background(), issue.RepoID, foreignID)
551-
assert.True(t, IsErrLocalIDNotExist(err))
549+
var foreignIndex int64 = 12345
550+
_, err = GetIssueByForeignIndex(context.Background(), issue.RepoID, foreignIndex)
551+
assert.True(t, IsErrLocalIndexNotExist(err))
552552

553553
_, err = db.GetEngine(db.DefaultContext).Insert(&ForeignReference{
554-
LocalID: issue.Index,
555-
ForeignID: strconv.FormatInt(foreignID, 10),
556-
RepoID: issue.RepoID,
557-
Type: ForeignTypeIssue,
554+
LocalIndex: issue.Index,
555+
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
556+
RepoID: issue.RepoID,
557+
Type: ForeignTypeIssue,
558558
})
559559
assert.NoError(t, err)
560560

561561
err = issue.LoadAttributes()
562562
assert.NoError(t, err)
563563

564-
assert.EqualValues(t, issue.ForeignReference.ForeignID, strconv.FormatInt(foreignID, 10))
564+
assert.EqualValues(t, issue.ForeignReference.ForeignIndex, strconv.FormatInt(foreignIndex, 10))
565565

566-
found, err := GetIssueByForeignID(context.Background(), issue.RepoID, foreignID)
566+
found, err := GetIssueByForeignIndex(context.Background(), issue.RepoID, foreignIndex)
567567
assert.NoError(t, err)
568568
assert.EqualValues(t, found.Index, issue.Index)
569569
}

models/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func insertIssue(ctx context.Context, issue *Issue) error {
8484
}
8585

8686
if issue.ForeignReference != nil {
87-
issue.ForeignReference.LocalID = issue.Index
87+
issue.ForeignReference.LocalIndex = issue.Index
8888
if _, err := sess.Insert(issue.ForeignReference); err != nil {
8989
return err
9090
}

models/migrate_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
4646
UserID: owner.ID,
4747
}
4848

49-
foreignID := int64(12345)
49+
foreignIndex := int64(12345)
5050
title := "issuetitle1"
5151
is := &Issue{
5252
RepoID: repo.ID,
@@ -61,9 +61,9 @@ func assertCreateIssues(t *testing.T, isPull bool) {
6161
Labels: []*Label{label},
6262
Reactions: []*Reaction{reaction},
6363
ForeignReference: &ForeignReference{
64-
ForeignID: strconv.FormatInt(foreignID, 10),
65-
RepoID: repo.ID,
66-
Type: ForeignTypeIssue,
64+
ForeignIndex: strconv.FormatInt(foreignIndex, 10),
65+
RepoID: repo.ID,
66+
Type: ForeignTypeIssue,
6767
},
6868
}
6969
err := InsertIssues(is)
@@ -73,7 +73,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
7373
assert.Nil(t, i.ForeignReference)
7474
err = i.LoadAttributes()
7575
assert.NoError(t, err)
76-
assert.EqualValues(t, strconv.FormatInt(foreignID, 10), i.ForeignReference.ForeignID)
76+
assert.EqualValues(t, strconv.FormatInt(foreignIndex, 10), i.ForeignReference.ForeignIndex)
7777
unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: owner.ID, IssueID: i.ID})
7878
}
7979

modules/migration/comment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import "time"
99

1010
// Commentable can be commented upon
1111
type Commentable interface {
12-
GetLocalID() int64
13-
GetForeignID() int64
12+
GetLocalIndex() int64
13+
GetForeignIndex() int64
1414
GetContext() DownloaderContext
1515
}
1616

modules/migration/issue.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ import "time"
99

1010
// Issue is a standard issue information
1111
type Issue struct {
12-
Number int64 `json:"number"`
13-
PosterID int64 `yaml:"poster_id" json:"poster_id"`
14-
PosterName string `yaml:"poster_name" json:"poster_name"`
15-
PosterEmail string `yaml:"poster_email" json:"poster_email"`
16-
Title string `json:"title"`
17-
Content string `json:"content"`
18-
Ref string `json:"ref"`
19-
Milestone string `json:"milestone"`
20-
State string `json:"state"` // closed, open
21-
IsLocked bool `yaml:"is_locked" json:"is_locked"`
22-
Created time.Time `json:"created"`
23-
Updated time.Time `json:"updated"`
24-
Closed *time.Time `json:"closed"`
25-
Labels []*Label `json:"labels"`
26-
Reactions []*Reaction `json:"reactions"`
27-
Assignees []string `json:"assignees"`
28-
ForeignID int64 `json:"foreign_id"`
29-
Context DownloaderContext `yaml:"-"`
12+
Number int64 `json:"number"`
13+
PosterID int64 `yaml:"poster_id" json:"poster_id"`
14+
PosterName string `yaml:"poster_name" json:"poster_name"`
15+
PosterEmail string `yaml:"poster_email" json:"poster_email"`
16+
Title string `json:"title"`
17+
Content string `json:"content"`
18+
Ref string `json:"ref"`
19+
Milestone string `json:"milestone"`
20+
State string `json:"state"` // closed, open
21+
IsLocked bool `yaml:"is_locked" json:"is_locked"`
22+
Created time.Time `json:"created"`
23+
Updated time.Time `json:"updated"`
24+
Closed *time.Time `json:"closed"`
25+
Labels []*Label `json:"labels"`
26+
Reactions []*Reaction `json:"reactions"`
27+
Assignees []string `json:"assignees"`
28+
ForeignIndex int64 `json:"foreign_id"`
29+
Context DownloaderContext `yaml:"-"`
3030
}
3131

3232
// GetExternalName ExternalUserMigrated interface
@@ -35,6 +35,6 @@ func (i *Issue) GetExternalName() string { return i.PosterName }
3535
// GetExternalID ExternalUserMigrated interface
3636
func (i *Issue) GetExternalID() int64 { return i.PosterID }
3737

38-
func (i *Issue) GetLocalID() int64 { return i.Number }
39-
func (i *Issue) GetForeignID() int64 { return i.ForeignID }
38+
func (i *Issue) GetLocalIndex() int64 { return i.Number }
39+
func (i *Issue) GetForeignIndex() int64 { return i.ForeignIndex }
4040
func (i *Issue) GetContext() DownloaderContext { return i.Context }

modules/migration/pullrequest.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ type PullRequest struct {
3535
Assignees []string
3636
IsLocked bool `yaml:"is_locked"`
3737
Reactions []*Reaction
38-
ForeignID int64
38+
ForeignIndex int64
3939
Context DownloaderContext `yaml:"-"`
4040
}
4141

42-
func (p *PullRequest) GetLocalID() int64 { return p.Number }
43-
func (p *PullRequest) GetForeignID() int64 { return p.ForeignID }
42+
func (p *PullRequest) GetLocalIndex() int64 { return p.Number }
43+
func (p *PullRequest) GetForeignIndex() int64 { return p.ForeignIndex }
4444
func (p *PullRequest) GetContext() DownloaderContext { return p.Context }
4545

4646
// IsForkPullRequest returns true if the pull request from a forked repository but not the same repository

modules/migration/review.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import "time"
88

99
// Reviewable can be reviewed
1010
type Reviewable interface {
11-
GetLocalID() int64
12-
GetForeignID() int64
11+
GetLocalIndex() int64
12+
GetForeignIndex() int64
1313
}
1414

1515
// enumerate all review states

services/migrations/codebase.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func (d *CodebaseDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool,
392392
Labels: []*base.Label{
393393
{Name: issue.Type.Name},
394394
},
395-
ForeignID: issue.TicketID.Value,
395+
ForeignIndex: issue.TicketID.Value,
396396
Context: codebaseIssueContext{
397397
Comments: comments[1:],
398398
},
@@ -559,7 +559,7 @@ func (d *CodebaseDownloader) GetPullRequests(page, perPage int) ([]*base.PullReq
559559
SHA: d.getHeadCommit(rawMergeRequest.TargetRef),
560560
RepoName: d.repoName,
561561
},
562-
ForeignID: rawMergeRequest.ID.Value,
562+
ForeignIndex: rawMergeRequest.ID.Value,
563563
Context: codebaseIssueContext{
564564
Comments: comments[1:],
565565
},

0 commit comments

Comments
 (0)