mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 03:26:06 +01:00
Feedback error in repository creation to users
This commit is contained in:
@@ -25,6 +25,7 @@ import org.eclipse.jgit.dircache.{DirCache, DirCacheBuilder}
|
||||
import org.eclipse.jgit.errors.MissingObjectException
|
||||
import org.eclipse.jgit.lib._
|
||||
import org.eclipse.jgit.transport.{ReceiveCommand, ReceivePack}
|
||||
import org.json4s.jackson.Serialization
|
||||
import org.scalatra._
|
||||
import org.scalatra.i18n.Messages
|
||||
|
||||
@@ -166,7 +167,11 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
ajaxGet("/:owner/:repository/creating") {
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
RepositoryCreationService.isCreating(owner, repository)
|
||||
contentType = formats("json")
|
||||
Serialization.write(Map(
|
||||
"creating" -> RepositoryCreationService.isCreating(owner, repository),
|
||||
"error" -> RepositoryCreationService.getCreationError(owner, repository)
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,7 +421,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
contentType = formats("json")
|
||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||
val last = git.log.add(git.getRepository.resolve(id)).addPath(path).setMaxCount(1).call.iterator.next.name
|
||||
Map(
|
||||
Serialization.write(Map(
|
||||
"root" -> s"${context.baseUrl}/${repository.owner}/${repository.name}",
|
||||
"id" -> id,
|
||||
"path" -> path,
|
||||
@@ -431,8 +436,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
"prevPath" -> blame.prevPath,
|
||||
"commited" -> blame.commitTime.getTime,
|
||||
"message" -> blame.message,
|
||||
"lines" -> blame.lines)
|
||||
})
|
||||
"lines" -> blame.lines
|
||||
)
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -19,18 +19,25 @@ import scala.concurrent.Future
|
||||
|
||||
object RepositoryCreationService {
|
||||
|
||||
private val Creating = new ConcurrentHashMap[String, Boolean]()
|
||||
private val Creating = new ConcurrentHashMap[String, Option[String]]()
|
||||
|
||||
def isCreating(owner: String, repository: String): Boolean = {
|
||||
Creating.containsKey(s"${owner}/${repository}")
|
||||
Option(Creating.get(s"${owner}/${repository}")).map(_.isEmpty).getOrElse(false)
|
||||
}
|
||||
|
||||
def startCreation(owner: String, repository: String): Unit = {
|
||||
Creating.put(s"${owner}/${repository}", true)
|
||||
Creating.put(s"${owner}/${repository}", None)
|
||||
}
|
||||
|
||||
def endCreation(owner: String, repository: String): Unit = {
|
||||
Creating.remove(s"${owner}/${repository}")
|
||||
def endCreation(owner: String, repository: String, error: Option[String]): Unit = {
|
||||
error match {
|
||||
case None => Creating.remove(s"${owner}/${repository}")
|
||||
case Some(error) => Creating.put(s"${owner}/${repository}", Some(error))
|
||||
}
|
||||
}
|
||||
|
||||
def getCreationError(owner: String, repository: String): Option[String] = {
|
||||
Option(Creating.get(s"${owner}/${repository}")).getOrElse(None)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,6 +58,15 @@ trait RepositoryCreationService {
|
||||
val ownerAccount = getAccountByUserName(owner).get
|
||||
val loginUserName = loginAccount.userName
|
||||
|
||||
val copyRepositoryDir = if (initOption == "COPY") {
|
||||
sourceUrl.flatMap { url =>
|
||||
val dir = Files.createTempDirectory(s"gitbucket-${owner}-${name}").toFile
|
||||
Git.cloneRepository().setBare(true).setURI(url).setDirectory(dir).setCloneAllBranches(true).call()
|
||||
Some(dir)
|
||||
}
|
||||
} else None
|
||||
|
||||
|
||||
// Insert to the database at first
|
||||
insertRepository(name, owner, description, isPrivate)
|
||||
|
||||
@@ -95,16 +111,12 @@ trait RepositoryCreationService {
|
||||
}
|
||||
}
|
||||
|
||||
if (initOption == "COPY") {
|
||||
sourceUrl.foreach { url =>
|
||||
// TODO How to feedback error in this block?
|
||||
val dir = Files.createTempDirectory(s"gitbucket-${owner}-${name}").toFile
|
||||
|
||||
Git.cloneRepository().setBare(true).setURI(url).setDirectory(dir).setCloneAllBranches(true).call()
|
||||
copyRepositoryDir.foreach { dir =>
|
||||
try {
|
||||
using(Git.open(dir)) { git =>
|
||||
git.push().setRemote(gitdir.toURI.toString).setPushAll().setPushTags().call()
|
||||
}
|
||||
|
||||
} finally {
|
||||
FileUtils.deleteQuietly(dir)
|
||||
}
|
||||
}
|
||||
@@ -115,8 +127,14 @@ trait RepositoryCreationService {
|
||||
// Record activity
|
||||
recordCreateRepositoryActivity(owner, name, loginUserName)
|
||||
}
|
||||
} finally {
|
||||
RepositoryCreationService.endCreation(owner, name)
|
||||
|
||||
RepositoryCreationService.endCreation(owner, name, None)
|
||||
|
||||
} catch {
|
||||
case ex: Exception => {
|
||||
ex.printStackTrace()
|
||||
RepositoryCreationService.endCreation(owner, name, Some(ex.toString))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,16 @@
|
||||
|
||||
function checkCreating() {
|
||||
$.get('@context.path/@owner/@repository/creating', function (data) {
|
||||
if (data == 'true') {
|
||||
console.log(data);
|
||||
if (data.creating == true) {
|
||||
setTimeout(checkCreating, 2000);
|
||||
} else {
|
||||
location.href = '@context.path/@owner/@repository';
|
||||
if (data.error) {
|
||||
alert(data.error);
|
||||
location.href = '@context.path/new';
|
||||
} else {
|
||||
location.href = '@context.path/@owner/@repository';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user