Skip to content

Commit 54dd0fc

Browse files
authored
migrations: remove dead code in gitea uploader (#18725)
When migrating, g.issues is a map with all issues created during the migration. If an issue is not found in g.issues when inserting a comment or a review, it cannot exist in the database and trying to get it via GetIssueByIndex() will always fail and return an error. Signed-off-by: singuliere <[email protected]>
1 parent 15a4b1d commit 54dd0fc

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

services/migrations/gitea_uploader.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
416416
var issue *models.Issue
417417
issue, ok := g.issues[comment.IssueIndex]
418418
if !ok {
419-
var err error
420-
issue, err = models.GetIssueByIndex(g.repo.ID, comment.IssueIndex)
421-
if err != nil {
422-
return err
423-
}
424-
g.issues[comment.IssueIndex] = issue
419+
return fmt.Errorf("comment references non existent IssueIndex %d", comment.IssueIndex)
425420
}
426421

427422
if comment.Created.IsZero() {
@@ -685,19 +680,14 @@ func convertReviewState(state string) models.ReviewType {
685680
}
686681
}
687682

688-
// CreateReviews create pull request reviews
683+
// CreateReviews create pull request reviews of currently migrated issues
689684
func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
690685
cms := make([]*models.Review, 0, len(reviews))
691686
for _, review := range reviews {
692687
var issue *models.Issue
693688
issue, ok := g.issues[review.IssueIndex]
694689
if !ok {
695-
var err error
696-
issue, err = models.GetIssueByIndex(g.repo.ID, review.IssueIndex)
697-
if err != nil {
698-
return err
699-
}
700-
g.issues[review.IssueIndex] = issue
690+
return fmt.Errorf("review references non existent IssueIndex %d", review.IssueIndex)
701691
}
702692
if review.CreatedAt.IsZero() {
703693
review.CreatedAt = time.Unix(int64(issue.CreatedUnix), 0)

0 commit comments

Comments
 (0)