Handle empty OriginalURL in migration failure notices

Check if opts.OriginalURL is empty and adapt the notice message accordingly to avoid printing "from  failed" when OriginalURL is not set (e.g., when using the API).

Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>

Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-30 06:08:05 +00:00
co-authored by silverwind
parent 8c7a6a07d4
commit 83445551a0
+7 -1
View File
@@ -131,7 +131,13 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str
if err1 := uploader.Rollback(); err1 != nil {
log.Error("rollback failed: %v", err1)
}
if err2 := system_model.CreateRepositoryNotice(fmt.Sprintf("Migrate repository (%s/%s) from %s failed: %v", ownerName, opts.RepoName, opts.OriginalURL, err)); err2 != nil {
var noticeMsg string
if opts.OriginalURL != "" {
noticeMsg = fmt.Sprintf("Migrate repository (%s/%s) from %s failed: %v", ownerName, opts.RepoName, opts.OriginalURL, err)
} else {
noticeMsg = fmt.Sprintf("Migrate repository (%s/%s) failed: %v", ownerName, opts.RepoName, err)
}
if err2 := system_model.CreateRepositoryNotice(noticeMsg); err2 != nil {
log.Error("create repository notice failed: ", err2)
}
return nil, err