|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package migrations |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"context" |
|
|
|
|
"fmt" |
|
|
|
|
"regexp" |
|
|
|
@ -19,6 +20,8 @@ type FetchMigratory struct { |
|
|
|
|
GHClient *github.Client |
|
|
|
|
RepoOwner string |
|
|
|
|
RepoName string |
|
|
|
|
Logger *logrus.Logger |
|
|
|
|
LogOutput *bytes.Buffer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (fm *FetchMigratory) ctx() context.Context { |
|
|
|
@ -30,7 +33,8 @@ func (fm *FetchMigratory) MigrateFromGitHub() error { |
|
|
|
|
fm.Status = &MigratoryStatus{ |
|
|
|
|
Stage: Importing, |
|
|
|
|
} |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
|
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
}).Info("migrating git repository") |
|
|
|
|
ghRepo, _, err := fm.GHClient.Repositories.Get(fm.ctx(), fm.RepoOwner, fm.RepoName) |
|
|
|
@ -45,7 +49,7 @@ func (fm *FetchMigratory) MigrateFromGitHub() error { |
|
|
|
|
fm.Status.FatalError = err |
|
|
|
|
return fmt.Errorf("Repository migration: %v", err) |
|
|
|
|
} |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
}).Info("git repository migrated") |
|
|
|
|
if fm.Options.Issues || fm.Options.PullRequests { |
|
|
|
@ -57,9 +61,9 @@ func (fm *FetchMigratory) MigrateFromGitHub() error { |
|
|
|
|
if err != nil { |
|
|
|
|
fm.Status.Stage = Failed |
|
|
|
|
fm.Status.FatalError = err |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
}).Fatalf("migration failed: %v", fm.Status.FatalError) |
|
|
|
|
}).Errorf("migration failed: %v", fm.Status.FatalError) |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
fm.Status.Stage = Migrating |
|
|
|
@ -71,14 +75,14 @@ func (fm *FetchMigratory) MigrateFromGitHub() error { |
|
|
|
|
migratedIssues[issue.GetNumber()], err = fm.Issue(issue) |
|
|
|
|
if err != nil { |
|
|
|
|
fm.Status.IssuesError++ |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
"issue": issue.GetNumber(), |
|
|
|
|
}).Warnf("error while migrating: %v", err) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
fm.Status.IssuesMigrated++ |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
"issue": issue.GetNumber(), |
|
|
|
|
}).Info("issue migrated") |
|
|
|
@ -91,9 +95,9 @@ func (fm *FetchMigratory) MigrateFromGitHub() error { |
|
|
|
|
if cmts := <-commentsChan; cmts == nil { |
|
|
|
|
fm.Status.Stage = Failed |
|
|
|
|
err := fmt.Errorf("error while fetching issue comments") |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
}).Fatalf("migration failed: %v", fm.Status.FatalError) |
|
|
|
|
}).Errorf("migration failed: %v", fm.Status.FatalError) |
|
|
|
|
return err |
|
|
|
|
} else { |
|
|
|
|
comments = *cmts |
|
|
|
@ -102,9 +106,9 @@ func (fm *FetchMigratory) MigrateFromGitHub() error { |
|
|
|
|
if err != nil { |
|
|
|
|
fm.Status.Stage = Failed |
|
|
|
|
fm.Status.FatalError = err |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
}).Fatalf("migration failed: %v", fm.Status.FatalError) |
|
|
|
|
}).Errorf("migration failed: %v", fm.Status.FatalError) |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
fm.Status.Comments = int64(len(comments)) |
|
|
|
@ -113,7 +117,7 @@ func (fm *FetchMigratory) MigrateFromGitHub() error { |
|
|
|
|
issueIndex, err := getIssueIndexFromHTMLURL(comment.GetHTMLURL()) |
|
|
|
|
if err != nil { |
|
|
|
|
fm.Status.CommentsError++ |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
"issue": issueIndex, |
|
|
|
|
"comment": comment.GetID(), |
|
|
|
@ -138,14 +142,14 @@ func (fm *FetchMigratory) MigrateFromGitHub() error { |
|
|
|
|
for _, comm := range cs { |
|
|
|
|
if _, err := fm.IssueComment(i, comm); err != nil { |
|
|
|
|
fm.Status.CommentsError++ |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
"comment": comm.GetID(), |
|
|
|
|
}).Warnf("error while migrating comment: %v", err) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
fm.Status.CommentsMigrated++ |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
"comment": comm.GetID(), |
|
|
|
|
}).Info("comment migrated") |
|
|
|
@ -158,13 +162,13 @@ func (fm *FetchMigratory) MigrateFromGitHub() error { |
|
|
|
|
} |
|
|
|
|
if fm.Status.FatalError != nil { |
|
|
|
|
fm.Status.Stage = Failed |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
}).Fatalf("migration failed: %v", fm.Status.FatalError) |
|
|
|
|
}).Errorf("migration failed: %v", fm.Status.FatalError) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
fm.Status.Stage = Finished |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
}).Info("migration successful") |
|
|
|
|
return nil |
|
|
|
@ -252,9 +256,9 @@ func (fm *FetchMigratory) fetchCommentsAsync() chan *[]*github.IssueComment { |
|
|
|
|
if err != nil { |
|
|
|
|
f.Status.FatalError = err |
|
|
|
|
ret <- nil |
|
|
|
|
logrus.WithFields(logrus.Fields{ |
|
|
|
|
fm.Logger.WithFields(logrus.Fields{ |
|
|
|
|
"repo": fmt.Sprintf("%s/%s", fm.RepoOwner, fm.RepoName), |
|
|
|
|
}).Fatalf("fetching comments failed: %v", fm.Status.FatalError) |
|
|
|
|
}).Errorf("fetching comments failed: %v", fm.Status.FatalError) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
f.Status.Comments = int64(len(comments)) |
|
|
|
|