Fix missing repository status when migrating repository via API (#9511)
* Fix API migration wrong repository status * Force push for ci
This commit is contained in:
parent
f0bda12c49
commit
a3928fd820
2 changed files with 32 additions and 3 deletions
|
@ -1781,6 +1781,12 @@ func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
|
||||||
return sess.Commit()
|
return sess.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateRepositoryStatus updates a repository's status
|
||||||
|
func UpdateRepositoryStatus(repoID int64, status RepositoryStatus) error {
|
||||||
|
_, err := x.Exec("UPDATE repository SET status = ? WHERE id = ?", status, repoID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateRepositoryUpdatedTime updates a repository's updated time
|
// UpdateRepositoryUpdatedTime updates a repository's updated time
|
||||||
func UpdateRepositoryUpdatedTime(repoID int64, updateTime time.Time) error {
|
func UpdateRepositoryUpdatedTime(repoID int64, updateTime time.Time) error {
|
||||||
_, err := x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", updateTime.Unix(), repoID)
|
_, err := x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", updateTime.Unix(), repoID)
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -431,10 +433,31 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||||
opts.Releases = false
|
opts.Releases = false
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := migrations.MigrateRepository(ctx.User, ctxUser.Name, opts)
|
var repo *models.Repository
|
||||||
if err == nil {
|
defer func() {
|
||||||
notification.NotifyCreateRepository(ctx.User, ctxUser, repo)
|
if e := recover(); e != nil {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
fmt.Fprintf(&buf, "Handler crashed with error: %v", log.Stack(2))
|
||||||
|
err = errors.New(buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
repo.Status = models.RepositoryReady
|
||||||
|
if err := models.UpdateRepositoryStatus(repo.ID, repo.Status); err == nil {
|
||||||
|
notification.NotifyMigrateRepository(ctx.User, ctxUser, repo)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if repo != nil {
|
||||||
|
if errDelete := models.DeleteRepository(ctx.User, ctxUser.ID, repo.ID); errDelete != nil {
|
||||||
|
log.Error("DeleteRepository: %v", errDelete)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
repo, err = migrations.MigrateRepository(ctx.User, ctxUser.Name, opts)
|
||||||
|
if err == nil {
|
||||||
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
|
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
|
||||||
ctx.JSON(201, repo.APIFormat(models.AccessModeAdmin))
|
ctx.JSON(201, repo.APIFormat(models.AccessModeAdmin))
|
||||||
return
|
return
|
||||||
|
|
Reference in a new issue