mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-03 12:05:59 +01:00
update scalafmt
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
version = "1.5.1"
|
version = "3.7.15"
|
||||||
project.git = true
|
project.git = true
|
||||||
|
|
||||||
maxColumn = 120
|
maxColumn = 120
|
||||||
docstrings = JavaDoc
|
docstrings.style = keep
|
||||||
|
|
||||||
align.tokens = ["%", "%%", {code = "=>", owner = "Case"}]
|
align.tokens = ["%", "%%", {code = "=>", owner = "Case"}]
|
||||||
align.openParenCallSite = false
|
align.openParenCallSite = false
|
||||||
align.openParenDefnSite = false
|
align.openParenDefnSite = false
|
||||||
continuationIndent.callSite = 2
|
continuationIndent.callSite = 2
|
||||||
continuationIndent.defnSite = 2
|
continuationIndent.defnSite = 2
|
||||||
danglingParentheses = true
|
danglingParentheses.preset = true
|
||||||
|
runner.dialect = scala213source3
|
||||||
|
rewrite.trailingCommas.style = keep
|
||||||
|
|||||||
@@ -115,8 +115,8 @@ assembly / assemblyMergeStrategy := {
|
|||||||
|
|
||||||
// Exclude a war file from published artifacts
|
// Exclude a war file from published artifacts
|
||||||
signedArtifacts := {
|
signedArtifacts := {
|
||||||
signedArtifacts.value.filterNot {
|
signedArtifacts.value.filterNot { case (_, file) =>
|
||||||
case (_, file) => file.getName.endsWith(".war") || file.getName.endsWith(".war.asc")
|
file.getName.endsWith(".war") || file.getName.endsWith(".war.asc")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,8 +205,7 @@ executableKey := {
|
|||||||
"md5" -> "MD5",
|
"md5" -> "MD5",
|
||||||
"sha1" -> "SHA-1",
|
"sha1" -> "SHA-1",
|
||||||
"sha256" -> "SHA-256"
|
"sha256" -> "SHA-256"
|
||||||
).foreach {
|
).foreach { case (extension, algorithm) =>
|
||||||
case (extension, algorithm) =>
|
|
||||||
val checksumFile = workDir / (warName + "." + extension)
|
val checksumFile = workDir / (warName + "." + extension)
|
||||||
Checksums generate (outputFile, checksumFile, algorithm)
|
Checksums generate (outputFile, checksumFile, algorithm)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,8 +76,7 @@ object GitBucketCoreModule
|
|||||||
import JDBCUtil._
|
import JDBCUtil._
|
||||||
|
|
||||||
val conn = context.get(Solidbase.CONNECTION).asInstanceOf[Connection]
|
val conn = context.get(Solidbase.CONNECTION).asInstanceOf[Connection]
|
||||||
val list = conn.select("SELECT * FROM ACTIVITY ORDER BY ACTIVITY_ID") {
|
val list = conn.select("SELECT * FROM ACTIVITY ORDER BY ACTIVITY_ID") { rs =>
|
||||||
rs =>
|
|
||||||
Activity(
|
Activity(
|
||||||
activityId = UUID.randomUUID().toString,
|
activityId = UUID.randomUUID().toString,
|
||||||
userName = rs.getString("USER_NAME"),
|
userName = rs.getString("USER_NAME"),
|
||||||
|
|||||||
@@ -66,15 +66,16 @@ object ApiBranchProtection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit val enforcementLevelSerializer: CustomSerializer[EnforcementLevel] = new CustomSerializer[EnforcementLevel](
|
implicit val enforcementLevelSerializer: CustomSerializer[EnforcementLevel] =
|
||||||
format =>
|
new CustomSerializer[EnforcementLevel](format =>
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
case JString("off") => Off
|
case JString("off") => Off
|
||||||
case JString("non_admins") => NonAdmins
|
case JString("non_admins") => NonAdmins
|
||||||
case JString("everyone") => Everyone
|
case JString("everyone") => Everyone
|
||||||
}, {
|
},
|
||||||
case x: EnforcementLevel => JString(x.name)
|
{ case x: EnforcementLevel =>
|
||||||
|
JString(x.name)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ case class ApiComment(id: Int, user: ApiUser, body: String, created_at: Date, up
|
|||||||
isPullRequest: Boolean
|
isPullRequest: Boolean
|
||||||
) {
|
) {
|
||||||
val html_url = ApiPath(
|
val html_url = ApiPath(
|
||||||
s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" } else { "issues" }}/${issueId}#comment-${id}"
|
s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" }
|
||||||
|
else { "issues" }}/${issueId}#comment-${id}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ object ApiCommits {
|
|||||||
}
|
}
|
||||||
|
|
||||||
File(
|
File(
|
||||||
filename = if (diff.changeType == ChangeType.DELETE) { diff.oldPath } else { diff.newPath },
|
filename = if (diff.changeType == ChangeType.DELETE) { diff.oldPath }
|
||||||
|
else { diff.newPath },
|
||||||
additions = additions,
|
additions = additions,
|
||||||
deletions = deletions,
|
deletions = deletions,
|
||||||
changes = additions + deletions,
|
changes = additions + deletions,
|
||||||
@@ -106,7 +107,9 @@ object ApiCommits {
|
|||||||
message = commitInfo.shortMessage,
|
message = commitInfo.shortMessage,
|
||||||
comment_count = commentCount,
|
comment_count = commentCount,
|
||||||
tree = Tree(
|
tree = Tree(
|
||||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/tree/${commitInfo.id}"), // TODO This endpoint has not been implemented yet.
|
url = ApiPath(
|
||||||
|
s"/api/v3/repos/${repositoryName.fullName}/tree/${commitInfo.id}"
|
||||||
|
), // TODO This endpoint has not been implemented yet.
|
||||||
sha = commitInfo.id
|
sha = commitInfo.id
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@@ -114,7 +117,9 @@ object ApiCommits {
|
|||||||
committer = ApiUser(committer),
|
committer = ApiUser(committer),
|
||||||
parents = commitInfo.parents.map { parent =>
|
parents = commitInfo.parents.map { parent =>
|
||||||
Tree(
|
Tree(
|
||||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/tree/${parent}"), // TODO This endpoint has not been implemented yet.
|
url = ApiPath(
|
||||||
|
s"/api/v3/repos/${repositoryName.fullName}/tree/${parent}"
|
||||||
|
), // TODO This endpoint has not been implemented yet.
|
||||||
sha = parent
|
sha = parent
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ object ApiContents {
|
|||||||
ApiContents("dir", fileInfo.name, fileInfo.path, fileInfo.commitId, None, None)(repositoryName)
|
ApiContents("dir", fileInfo.name, fileInfo.path, fileInfo.commitId, None, None)(repositoryName)
|
||||||
} else {
|
} else {
|
||||||
content
|
content
|
||||||
.map(
|
.map(arr =>
|
||||||
arr =>
|
|
||||||
ApiContents(
|
ApiContents(
|
||||||
"file",
|
"file",
|
||||||
fileInfo.name,
|
fileInfo.name,
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ case class ApiIssue(
|
|||||||
val id = 0 // dummy id
|
val id = 0 // dummy id
|
||||||
val assignee = assignees.headOption
|
val assignee = assignees.headOption
|
||||||
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments")
|
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments")
|
||||||
val html_url = ApiPath(s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" } else { "issues" }}/${number}")
|
val html_url = ApiPath(s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" }
|
||||||
|
else { "issues" }}/${number}")
|
||||||
val pull_request = if (isPullRequest) {
|
val pull_request = if (isPullRequest) {
|
||||||
Some(
|
Some(
|
||||||
Map(
|
Map(
|
||||||
@@ -54,7 +55,8 @@ object ApiIssue {
|
|||||||
assignees = assignees,
|
assignees = assignees,
|
||||||
labels = labels,
|
labels = labels,
|
||||||
milestone = milestone,
|
milestone = milestone,
|
||||||
state = if (issue.closed) { "closed" } else { "open" },
|
state = if (issue.closed) { "closed" }
|
||||||
|
else { "open" },
|
||||||
body = issue.content.getOrElse(""),
|
body = issue.content.getOrElse(""),
|
||||||
created_at = issue.registeredDate,
|
created_at = issue.registeredDate,
|
||||||
updated_at = issue.updatedDate
|
updated_at = issue.updatedDate
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ object ApiPullRequest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
case class Commit(sha: String, ref: String, repo: ApiRepository)(baseOwner: String) {
|
case class Commit(sha: String, ref: String, repo: ApiRepository)(baseOwner: String) {
|
||||||
val label = if (baseOwner == repo.owner.login) { ref } else { s"${repo.owner.login}:${ref}" }
|
val label = if (baseOwner == repo.owner.login) { ref }
|
||||||
|
else { s"${repo.owner.login}:${ref}" }
|
||||||
val user = repo.owner
|
val user = repo.owner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ object ApiUser {
|
|||||||
def apply(user: Account): ApiUser = ApiUser(
|
def apply(user: Account): ApiUser = ApiUser(
|
||||||
login = user.userName,
|
login = user.userName,
|
||||||
email = user.mailAddress,
|
email = user.mailAddress,
|
||||||
`type` = if (user.isGroupAccount) { "Organization" } else { "User" },
|
`type` = if (user.isGroupAccount) { "Organization" }
|
||||||
|
else { "User" },
|
||||||
site_admin = user.isAdmin,
|
site_admin = user.isAdmin,
|
||||||
created_at = user.registeredDate
|
created_at = user.registeredDate
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,13 +15,12 @@ object JsonFormat {
|
|||||||
|
|
||||||
val parserISO = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
val parserISO = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
||||||
|
|
||||||
val jsonFormats = Serialization.formats(NoTypeHints) + new CustomSerializer[Date](
|
val jsonFormats = Serialization.formats(NoTypeHints) + new CustomSerializer[Date](format =>
|
||||||
format =>
|
|
||||||
(
|
(
|
||||||
{
|
{ case JString(s) =>
|
||||||
case JString(s) =>
|
|
||||||
Try(Date.from(Instant.parse(s))).getOrElse(throw new MappingException("Can't convert " + s + " to Date"))
|
Try(Date.from(Instant.parse(s))).getOrElse(throw new MappingException("Can't convert " + s + " to Date"))
|
||||||
}, { case x: Date => JString(OffsetDateTime.ofInstant(x.toInstant, ZoneId.of("UTC")).format(parserISO)) }
|
},
|
||||||
|
{ case x: Date => JString(OffsetDateTime.ofInstant(x.toInstant, ZoneId.of("UTC")).format(parserISO)) }
|
||||||
)
|
)
|
||||||
) + FieldSerializer[ApiUser]() +
|
) + FieldSerializer[ApiUser]() +
|
||||||
FieldSerializer[ApiGroup]() +
|
FieldSerializer[ApiGroup]() +
|
||||||
@@ -48,29 +47,32 @@ object JsonFormat {
|
|||||||
ApiBranchProtection.enforcementLevelSerializer
|
ApiBranchProtection.enforcementLevelSerializer
|
||||||
|
|
||||||
def apiPathSerializer(c: Context) =
|
def apiPathSerializer(c: Context) =
|
||||||
new CustomSerializer[ApiPath](
|
new CustomSerializer[ApiPath](_ =>
|
||||||
_ =>
|
(
|
||||||
({
|
{
|
||||||
case JString(s) if s.startsWith(c.baseUrl) => ApiPath(s.substring(c.baseUrl.length))
|
case JString(s) if s.startsWith(c.baseUrl) => ApiPath(s.substring(c.baseUrl.length))
|
||||||
case JString(s) => throw new MappingException("Can't convert " + s + " to ApiPath")
|
case JString(s) => throw new MappingException("Can't convert " + s + " to ApiPath")
|
||||||
}, {
|
},
|
||||||
case ApiPath(path) => JString(c.baseUrl + path)
|
{ case ApiPath(path) =>
|
||||||
})
|
JString(c.baseUrl + path)
|
||||||
|
}
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def sshPathSerializer(c: Context) =
|
def sshPathSerializer(c: Context) =
|
||||||
new CustomSerializer[SshPath](
|
new CustomSerializer[SshPath](_ =>
|
||||||
_ =>
|
(
|
||||||
({
|
{
|
||||||
case JString(s) if c.sshUrl.exists(sshUrl => s.startsWith(sshUrl)) =>
|
case JString(s) if c.sshUrl.exists(sshUrl => s.startsWith(sshUrl)) =>
|
||||||
SshPath(s.substring(c.sshUrl.get.length))
|
SshPath(s.substring(c.sshUrl.get.length))
|
||||||
case JString(s) => throw new MappingException("Can't convert " + s + " to ApiPath")
|
case JString(s) => throw new MappingException("Can't convert " + s + " to ApiPath")
|
||||||
}, {
|
},
|
||||||
case SshPath(path) =>
|
{ case SshPath(path) =>
|
||||||
c.sshUrl.map { sshUrl =>
|
c.sshUrl.map { sshUrl =>
|
||||||
JString(sshUrl + path)
|
JString(sshUrl + path)
|
||||||
} getOrElse JNothing
|
} getOrElse JNothing
|
||||||
})
|
}
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -215,9 +215,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"events" -> accountWebhookEvents,
|
"events" -> accountWebhookEvents,
|
||||||
"ctype" -> label("ctype", text()),
|
"ctype" -> label("ctype", text()),
|
||||||
"token" -> optional(trim(label("token", text(maxlength(100)))))
|
"token" -> optional(trim(label("token", text(maxlength(100)))))
|
||||||
)(
|
)((url, events, ctype, token) => AccountWebHookForm(url, events, WebHookContentType.valueOf(ctype), token))
|
||||||
(url, events, ctype, token) => AccountWebHookForm(url, events, WebHookContentType.valueOf(ctype), token)
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides duplication check for web hook url. duplicated from RepositorySettingsController.scala
|
* Provides duplication check for web hook url. duplicated from RepositorySettingsController.scala
|
||||||
@@ -340,8 +338,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
post("/:userName/_edit", editForm)(oneselfOnly { form =>
|
post("/:userName/_edit", editForm)(oneselfOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).map {
|
getAccountByUserName(userName).map { account =>
|
||||||
account =>
|
|
||||||
updateAccount(
|
updateAccount(
|
||||||
account.copy(
|
account.copy(
|
||||||
password = form.password.map(pbkdf2_sha256).getOrElse(account.password),
|
password = form.password.map(pbkdf2_sha256).getOrElse(account.password),
|
||||||
@@ -363,8 +360,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:userName/_delete")(oneselfOnly {
|
get("/:userName/_delete")(oneselfOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
|
|
||||||
getAccountByUserName(userName, true).map {
|
getAccountByUserName(userName, true).map { account =>
|
||||||
account =>
|
|
||||||
if (isLastAdministrator(account)) {
|
if (isLastAdministrator(account)) {
|
||||||
flash.update("error", "Account can't be removed because this is last one administrator.")
|
flash.update("error", "Account can't be removed because this is last one administrator.")
|
||||||
redirect(s"/${userName}/_edit")
|
redirect(s"/${userName}/_edit")
|
||||||
@@ -525,8 +521,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:userName/_hooks/edit")(managersOnly {
|
get("/:userName/_hooks/edit")(managersOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).flatMap { account =>
|
getAccountByUserName(userName).flatMap { account =>
|
||||||
getAccountWebHook(userName, params("url")).map {
|
getAccountWebHook(userName, params("url")).map { case (webhook, events) =>
|
||||||
case (webhook, events) =>
|
|
||||||
html.edithook(webhook, events, account, false)
|
html.edithook(webhook, events, account, false)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -584,8 +579,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"url" -> url,
|
"url" -> url,
|
||||||
"request" -> Await.result(
|
"request" -> Await.result(
|
||||||
reqFuture
|
reqFuture
|
||||||
.map(
|
.map(req =>
|
||||||
req =>
|
|
||||||
Map(
|
Map(
|
||||||
"headers" -> _headers(req.getAllHeaders),
|
"headers" -> _headers(req.getAllHeaders),
|
||||||
"payload" -> json
|
"payload" -> json
|
||||||
@@ -596,8 +590,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
),
|
),
|
||||||
"response" -> Await.result(
|
"response" -> Await.result(
|
||||||
resFuture
|
resFuture
|
||||||
.map(
|
.map(res =>
|
||||||
res =>
|
|
||||||
Map(
|
Map(
|
||||||
"status" -> res.getStatusLine(),
|
"status" -> res.getStatusLine(),
|
||||||
"body" -> EntityUtils.toString(res.getEntity()),
|
"body" -> EntityUtils.toString(res.getEntity()),
|
||||||
@@ -788,8 +781,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
* Create new repository.
|
* Create new repository.
|
||||||
*/
|
*/
|
||||||
post("/new", newRepositoryForm)(usersOnly { form =>
|
post("/new", newRepositoryForm)(usersOnly { form =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (context.settings.basicBehavior.repositoryOperation.create || loginAccount.isAdmin) {
|
if (context.settings.basicBehavior.repositoryOperation.create || loginAccount.isAdmin) {
|
||||||
LockUtil.lock(s"${form.owner}/${form.name}") {
|
LockUtil.lock(s"${form.owner}/${form.name}") {
|
||||||
if (getRepository(form.owner, form.name).isDefined) {
|
if (getRepository(form.owner, form.name).isDefined) {
|
||||||
@@ -819,17 +811,17 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
if (
|
||||||
if (repository.repository.options.allowFork && (context.settings.basicBehavior.repositoryOperation.fork || loginAccount.isAdmin)) {
|
repository.repository.options.allowFork && (context.settings.basicBehavior.repositoryOperation.fork || loginAccount.isAdmin)
|
||||||
|
) {
|
||||||
val loginUserName = loginAccount.userName
|
val loginUserName = loginAccount.userName
|
||||||
val groups = getGroupsByUserName(loginUserName)
|
val groups = getGroupsByUserName(loginUserName)
|
||||||
groups match {
|
groups match {
|
||||||
case _: List[String] =>
|
case _: List[String] =>
|
||||||
val managerPermissions = groups.map { group =>
|
val managerPermissions = groups.map { group =>
|
||||||
val members = getGroupMembers(group)
|
val members = getGroupMembers(group)
|
||||||
context.loginAccount.exists(
|
context.loginAccount.exists(x =>
|
||||||
x =>
|
|
||||||
members.exists { member =>
|
members.exists { member =>
|
||||||
member.userName == x.userName && member.isManager
|
member.userName == x.userName && member.isManager
|
||||||
}
|
}
|
||||||
@@ -846,9 +838,10 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
if (
|
||||||
if (repository.repository.options.allowFork && (context.settings.basicBehavior.repositoryOperation.fork || loginAccount.isAdmin)) {
|
repository.repository.options.allowFork && (context.settings.basicBehavior.repositoryOperation.fork || loginAccount.isAdmin)
|
||||||
|
) {
|
||||||
val loginUserName = loginAccount.userName
|
val loginUserName = loginAccount.userName
|
||||||
val accountName = form.accountName
|
val accountName = form.accountName
|
||||||
|
|
||||||
@@ -891,9 +884,11 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
private def members: Constraint = new Constraint() {
|
private def members: Constraint = new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
if (value.split(",").exists {
|
if (
|
||||||
|
value.split(",").exists {
|
||||||
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
||||||
}) None
|
}
|
||||||
|
) None
|
||||||
else Some("Must select one manager at least.")
|
else Some("Must select one manager at least.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -423,10 +423,11 @@ trait AccountManagementControllerBase extends ControllerBase {
|
|||||||
messages: Messages
|
messages: Messages
|
||||||
): Option[String] = {
|
): Option[String] = {
|
||||||
val extraMailAddresses = params.view.filterKeys(k => k.startsWith("extraMailAddresses"))
|
val extraMailAddresses = params.view.filterKeys(k => k.startsWith("extraMailAddresses"))
|
||||||
if (extraMailAddresses.exists {
|
if (
|
||||||
case (k, v) =>
|
extraMailAddresses.exists { case (k, v) =>
|
||||||
v.contains(value)
|
v.contains(value)
|
||||||
}) {
|
}
|
||||||
|
) {
|
||||||
Some("These mail addresses are duplicated.")
|
Some("These mail addresses are duplicated.")
|
||||||
} else {
|
} else {
|
||||||
getAccountByMailAddress(value, true)
|
getAccountByMailAddress(value, true)
|
||||||
@@ -446,10 +447,11 @@ trait AccountManagementControllerBase extends ControllerBase {
|
|||||||
messages: Messages
|
messages: Messages
|
||||||
): Option[String] = {
|
): Option[String] = {
|
||||||
val extraMailAddresses = params.view.filterKeys(k => k.startsWith("extraMailAddresses"))
|
val extraMailAddresses = params.view.filterKeys(k => k.startsWith("extraMailAddresses"))
|
||||||
if (Some(value) == params.optionValue("mailAddress") || extraMailAddresses.count {
|
if (
|
||||||
case (k, v) =>
|
Some(value) == params.optionValue("mailAddress") || extraMailAddresses.count { case (k, v) =>
|
||||||
v.contains(value)
|
v.contains(value)
|
||||||
} > 1) {
|
} > 1
|
||||||
|
) {
|
||||||
Some("These mail addresses are duplicated.")
|
Some("These mail addresses are duplicated.")
|
||||||
} else {
|
} else {
|
||||||
getAccountByMailAddress(value, true)
|
getAccountByMailAddress(value, true)
|
||||||
|
|||||||
@@ -75,8 +75,7 @@ class FileUploadController
|
|||||||
post("/wiki/:owner/:repository") {
|
post("/wiki/:owner/:repository") {
|
||||||
setMultipartConfig()
|
setMultipartConfig()
|
||||||
// Don't accept not logged-in users
|
// Don't accept not logged-in users
|
||||||
session.get(Keys.Session.LoginAccount).collect {
|
session.get(Keys.Session.LoginAccount).collect { case loginAccount: Account =>
|
||||||
case loginAccount: Account =>
|
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
|
|
||||||
@@ -86,8 +85,7 @@ class FileUploadController
|
|||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
val fileName = file.getName
|
val fileName = file.getName
|
||||||
LockUtil.lock(s"${owner}/${repository}/wiki") {
|
LockUtil.lock(s"${owner}/${repository}/wiki") {
|
||||||
Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) {
|
Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) { git =>
|
||||||
git =>
|
|
||||||
val builder = DirCache.newInCore.builder()
|
val builder = DirCache.newInCore.builder()
|
||||||
val inserter = git.getRepository.newObjectInserter()
|
val inserter = git.getRepository.newObjectInserter()
|
||||||
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
||||||
@@ -135,8 +133,7 @@ class FileUploadController
|
|||||||
setMultipartConfigForLargeFile()
|
setMultipartConfigForLargeFile()
|
||||||
session
|
session
|
||||||
.get(Keys.Session.LoginAccount)
|
.get(Keys.Session.LoginAccount)
|
||||||
.collect {
|
.collect { case _: Account =>
|
||||||
case _: Account =>
|
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val tag = multiParams("splat").head
|
val tag = multiParams("splat").head
|
||||||
@@ -158,9 +155,12 @@ class FileUploadController
|
|||||||
setMultipartConfig()
|
setMultipartConfig()
|
||||||
session.get(Keys.Session.LoginAccount).collect {
|
session.get(Keys.Session.LoginAccount).collect {
|
||||||
case loginAccount: Account if loginAccount.isAdmin =>
|
case loginAccount: Account if loginAccount.isAdmin =>
|
||||||
execute({ (file, fileId) =>
|
execute(
|
||||||
|
{ (file, fileId) =>
|
||||||
request2Session(request).conn.importAsSQL(file.getInputStream)
|
request2Session(request).conn.importAsSQL(file.getInputStream)
|
||||||
}, _ => true)
|
},
|
||||||
|
_ => true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
redirect("/admin/data")
|
redirect("/admin/data")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,8 +151,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
val redirectURI = new URI(s"$baseUrl/signin/oidc")
|
val redirectURI = new URI(s"$baseUrl/signin/oidc")
|
||||||
session.get(Keys.Session.OidcAuthContext) match {
|
session.get(Keys.Session.OidcAuthContext) match {
|
||||||
case Some(context: OidcAuthContext) =>
|
case Some(context: OidcAuthContext) =>
|
||||||
authenticate(params.toMap, redirectURI, context.state, context.nonce, oidc).map {
|
authenticate(params.toMap, redirectURI, context.state, context.nonce, oidc).map { case (jwt, account) =>
|
||||||
case (jwt, account) =>
|
|
||||||
session.setAttribute(Keys.Session.OidcSessionContext, OidcSessionContext(jwt))
|
session.setAttribute(Keys.Session.OidcSessionContext, OidcSessionContext(jwt))
|
||||||
signin(account, context.redirectBackURI)
|
signin(account, context.redirectBackURI)
|
||||||
} orElse {
|
} orElse {
|
||||||
@@ -172,8 +171,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/signout") {
|
get("/signout") {
|
||||||
context.settings.oidc.foreach { oidc =>
|
context.settings.oidc.foreach { oidc =>
|
||||||
session.get(Keys.Session.OidcSessionContext).foreach {
|
session.get(Keys.Session.OidcSessionContext).foreach { case context: OidcSessionContext =>
|
||||||
case context: OidcSessionContext =>
|
|
||||||
val redirectURI = new URI(baseUrl)
|
val redirectURI = new URI(baseUrl)
|
||||||
val authenticationRequest = createOIDLogoutRequest(oidc.issuer, oidc.clientID, redirectURI, context.token)
|
val authenticationRequest = createOIDLogoutRequest(oidc.issuer, oidc.clientID, redirectURI, context.token)
|
||||||
session.invalidate()
|
session.invalidate()
|
||||||
@@ -269,7 +267,8 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/search")(referrersOnly { repository =>
|
get("/:owner/:repository/search")(referrersOnly { repository =>
|
||||||
val query = params.getOrElse("q", "").trim
|
val query = params.getOrElse("q", "").trim
|
||||||
val target = params.getOrElse("type", "code")
|
val target = params.getOrElse("type", "code")
|
||||||
val page = try {
|
val page =
|
||||||
|
try {
|
||||||
val i = params.getOrElse("page", "1").toInt
|
val i = params.getOrElse("page", "1").toInt
|
||||||
if (i <= 0) 1 else i
|
if (i <= 0) 1 else i
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -101,8 +101,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/issues/:id")(referrersOnly { repository =>
|
get("/:owner/:repository/issues/:id")(referrersOnly { repository =>
|
||||||
val issueId = params("id")
|
val issueId = params("id")
|
||||||
getIssue(repository.owner, repository.name, issueId) map {
|
getIssue(repository.owner, repository.name, issueId) map { issue =>
|
||||||
issue =>
|
|
||||||
if (issue.isPullRequest) {
|
if (issue.isPullRequest) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
} else {
|
} else {
|
||||||
@@ -142,8 +141,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/new", issueCreateForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/issues/new", issueCreateForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
||||||
val issue = createIssue(
|
val issue = createIssue(
|
||||||
repository,
|
repository,
|
||||||
@@ -157,8 +155,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Insert custom field values
|
// Insert custom field values
|
||||||
params.toMap.foreach {
|
params.toMap.foreach { case (key, value) =>
|
||||||
case (key, value) =>
|
|
||||||
if (key.startsWith("custom-field-")) {
|
if (key.startsWith("custom-field-")) {
|
||||||
getCustomField(
|
getCustomField(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
@@ -180,10 +177,8 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/edit_title/:id", issueTitleEditForm)(readableUsersOnly { (title, repository) =>
|
ajaxPost("/:owner/:repository/issues/edit_title/:id", issueTitleEditForm)(readableUsersOnly { (title, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
getIssue(repository.owner, repository.name, params("id")).map { issue =>
|
||||||
getIssue(repository.owner, repository.name, params("id")).map {
|
|
||||||
issue =>
|
|
||||||
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
||||||
if (issue.title != title) {
|
if (issue.title != title) {
|
||||||
// update issue
|
// update issue
|
||||||
@@ -206,8 +201,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
|
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
getIssue(repository.owner, repository.name, params("id")).map { issue =>
|
getIssue(repository.owner, repository.name, params("id")).map { issue =>
|
||||||
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
||||||
// update issue
|
// update issue
|
||||||
@@ -222,15 +216,13 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||||
val actionOpt =
|
val actionOpt =
|
||||||
params
|
params
|
||||||
.get("action")
|
.get("action")
|
||||||
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
||||||
handleComment(issue, Some(form.content), repository, actionOpt) map {
|
handleComment(issue, Some(form.content), repository, actionOpt) map { case (issue, id) =>
|
||||||
case (issue, id) =>
|
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
||||||
)
|
)
|
||||||
@@ -240,15 +232,13 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issue_comments/state", issueStateForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/issue_comments/state", issueStateForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||||
val actionOpt =
|
val actionOpt =
|
||||||
params
|
params
|
||||||
.get("action")
|
.get("action")
|
||||||
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
||||||
handleComment(issue, form.content, repository, actionOpt) map {
|
handleComment(issue, form.content, repository, actionOpt) map { case (issue, id) =>
|
||||||
case (issue, id) =>
|
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
||||||
)
|
)
|
||||||
@@ -258,8 +248,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issue_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
ajaxPost("/:owner/:repository/issue_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
getComment(repository.owner, repository.name, params("id")).map { comment =>
|
getComment(repository.owner, repository.name, params("id")).map { comment =>
|
||||||
if (isEditableContent(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
if (isEditableContent(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
||||||
updateComment(repository.owner, repository.name, comment.issueId, comment.commentId, form.content)
|
updateComment(repository.owner, repository.name, comment.issueId, comment.commentId, form.content)
|
||||||
@@ -280,10 +269,8 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/issues/_data/:id")(readableUsersOnly { repository =>
|
ajaxGet("/:owner/:repository/issues/_data/:id")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
getIssue(repository.owner, repository.name, params("id")) map { x =>
|
||||||
getIssue(repository.owner, repository.name, params("id")) map {
|
|
||||||
x =>
|
|
||||||
if (isEditableContent(x.userName, x.repositoryName, x.openedUserName, loginAccount)) {
|
if (isEditableContent(x.userName, x.repositoryName, x.openedUserName, loginAccount)) {
|
||||||
params.get("dataType") collect {
|
params.get("dataType") collect {
|
||||||
case t if t == "html" => html.editissue(x.content, x.issueId, repository)
|
case t if t == "html" => html.editissue(x.content, x.issueId, repository)
|
||||||
@@ -312,10 +299,8 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/issue_comments/_data/:id")(readableUsersOnly { repository =>
|
ajaxGet("/:owner/:repository/issue_comments/_data/:id")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
getComment(repository.owner, repository.name, params("id")) map { x =>
|
||||||
getComment(repository.owner, repository.name, params("id")) map {
|
|
||||||
x =>
|
|
||||||
if (isEditableContent(x.userName, x.repositoryName, x.commentedUserName, loginAccount)) {
|
if (isEditableContent(x.userName, x.repositoryName, x.commentedUserName, loginAccount)) {
|
||||||
params.get("dataType") collect {
|
params.get("dataType") collect {
|
||||||
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
||||||
@@ -377,8 +362,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
milestoneId("milestoneId").map { milestoneId =>
|
milestoneId("milestoneId").map { milestoneId =>
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name)
|
getMilestonesWithIssueCount(repository.owner, repository.name)
|
||||||
.find(_._1.milestoneId == milestoneId)
|
.find(_._1.milestoneId == milestoneId)
|
||||||
.map {
|
.map { case (_, openCount, closeCount) =>
|
||||||
case (_, openCount, closeCount) =>
|
|
||||||
gitbucket.core.issues.milestones.html.progress(openCount + closeCount, closeCount)
|
gitbucket.core.issues.milestones.html.progress(openCount + closeCount, closeCount)
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
} getOrElse Ok()
|
} getOrElse Ok()
|
||||||
@@ -565,8 +549,8 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* Tests whether an issue or a comment is editable by a logged-in user.
|
* Tests whether an issue or a comment is editable by a logged-in user.
|
||||||
*/
|
*/
|
||||||
private def isEditableContent(owner: String, repository: String, author: String, loginAccount: Account)(
|
private def isEditableContent(owner: String, repository: String, author: String, loginAccount: Account)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == loginAccount.userName
|
hasDeveloperRole(owner, repository, context.loginAccount) || author == loginAccount.userName
|
||||||
}
|
}
|
||||||
@@ -574,8 +558,8 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* Tests whether an issue comment is deletable by a logged-in user.
|
* Tests whether an issue comment is deletable by a logged-in user.
|
||||||
*/
|
*/
|
||||||
private def isDeletableComment(owner: String, repository: String, author: String, loginAccount: Account)(
|
private def isDeletableComment(owner: String, repository: String, author: String, loginAccount: Account)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
hasOwnerRole(owner, repository, context.loginAccount) || author == loginAccount.userName
|
hasOwnerRole(owner, repository, context.loginAccount) || author == loginAccount.userName
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,14 @@ trait PreProcessControllerBase extends ControllerBase {
|
|||||||
* But if it's not allowed, demands authentication except some paths.
|
* But if it's not allowed, demands authentication except some paths.
|
||||||
*/
|
*/
|
||||||
get(!context.settings.basicBehavior.allowAnonymousAccess, context.loginAccount.isEmpty) {
|
get(!context.settings.basicBehavior.allowAnonymousAccess, context.loginAccount.isEmpty) {
|
||||||
if (!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") &&
|
if (
|
||||||
|
!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") &&
|
||||||
!context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs") &&
|
!context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs") &&
|
||||||
!context.currentPath.startsWith("/plugin-assets") &&
|
!context.currentPath.startsWith("/plugin-assets") &&
|
||||||
!PluginRegistry().getAnonymousAccessiblePaths().exists { path =>
|
!PluginRegistry().getAnonymousAccessiblePaths().exists { path =>
|
||||||
context.currentPath.startsWith(path)
|
context.currentPath.startsWith(path)
|
||||||
}) {
|
}
|
||||||
|
) {
|
||||||
Unauthorized()
|
Unauthorized()
|
||||||
} else {
|
} else {
|
||||||
pass()
|
pass()
|
||||||
|
|||||||
@@ -113,10 +113,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/pull/:id")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap { issueId =>
|
||||||
issueId =>
|
getPullRequest(repository.owner, repository.name, issueId) map { case (issue, pullreq) =>
|
||||||
getPullRequest(repository.owner, repository.name, issueId) map {
|
|
||||||
case (issue, pullreq) =>
|
|
||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(
|
getRequestCompareInfo(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
@@ -152,10 +150,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/pull/:id/commits")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id/commits")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap { issueId =>
|
||||||
issueId =>
|
getPullRequest(repository.owner, repository.name, issueId) map { case (issue, pullreq) =>
|
||||||
getPullRequest(repository.owner, repository.name, issueId) map {
|
|
||||||
case (issue, pullreq) =>
|
|
||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(
|
getRequestCompareInfo(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
@@ -186,10 +182,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/pull/:id/files")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id/files")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap { issueId =>
|
||||||
issueId =>
|
getPullRequest(repository.owner, repository.name, issueId) map { case (issue, pullreq) =>
|
||||||
getPullRequest(repository.owner, repository.name, issueId) map {
|
|
||||||
case (issue, pullreq) =>
|
|
||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(
|
getRequestCompareInfo(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
@@ -214,10 +208,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/pull/:id/mergeguide")(referrersOnly { repository =>
|
ajaxGet("/:owner/:repository/pull/:id/mergeguide")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap { issueId =>
|
||||||
issueId =>
|
getPullRequest(repository.owner, repository.name, issueId) map { case (issue, pullreq) =>
|
||||||
getPullRequest(repository.owner, repository.name, issueId) map {
|
|
||||||
case (issue, pullreq) =>
|
|
||||||
val conflictMessage = LockUtil.lock(s"${repository.owner}/${repository.name}") {
|
val conflictMessage = LockUtil.lock(s"${repository.owner}/${repository.name}") {
|
||||||
checkConflict(repository.owner, repository.name, pullreq.branch, issueId)
|
checkConflict(repository.owner, repository.name, pullreq.branch, issueId)
|
||||||
}
|
}
|
||||||
@@ -314,7 +306,9 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
} else {
|
} else {
|
||||||
LockUtil.lock(s"${owner}/${name}") {
|
LockUtil.lock(s"${owner}/${name}") {
|
||||||
val alias =
|
val alias =
|
||||||
if (pullreq.repositoryName == pullreq.requestRepositoryName && pullreq.userName == pullreq.requestUserName) {
|
if (
|
||||||
|
pullreq.repositoryName == pullreq.requestRepositoryName && pullreq.userName == pullreq.requestUserName
|
||||||
|
) {
|
||||||
pullreq.branch
|
pullreq.branch
|
||||||
} else {
|
} else {
|
||||||
s"${pullreq.userName}:${pullreq.branch}"
|
s"${pullreq.userName}:${pullreq.branch}"
|
||||||
@@ -383,8 +377,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val headBranch = params.get("head")
|
val headBranch = params.get("head")
|
||||||
(forkedRepository.repository.originUserName, forkedRepository.repository.originRepositoryName) match {
|
(forkedRepository.repository.originUserName, forkedRepository.repository.originRepositoryName) match {
|
||||||
case (Some(originUserName), Some(originRepositoryName)) =>
|
case (Some(originUserName), Some(originRepositoryName)) =>
|
||||||
getRepository(originUserName, originRepositoryName).map {
|
getRepository(originUserName, originRepositoryName).map { originRepository =>
|
||||||
originRepository =>
|
|
||||||
Using.resources(
|
Using.resources(
|
||||||
Git.open(getRepositoryDir(originUserName, originRepositoryName)),
|
Git.open(getRepositoryDir(originUserName, originRepositoryName)),
|
||||||
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
||||||
@@ -401,8 +394,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
case _ =>
|
case _ =>
|
||||||
Using.resource(Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))) { git =>
|
||||||
JGitUtil.getDefaultBranch(git, forkedRepository).map {
|
JGitUtil.getDefaultBranch(git, forkedRepository).map { case (_, defaultBranch) =>
|
||||||
case (_, defaultBranch) =>
|
|
||||||
redirect(
|
redirect(
|
||||||
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/${defaultBranch}...${headBranch.getOrElse(defaultBranch)}"
|
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/${defaultBranch}...${headBranch.getOrElse(defaultBranch)}"
|
||||||
)
|
)
|
||||||
@@ -445,8 +437,10 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val (originOwner, originId) = parseCompareIdentifier(origin, forkedRepository.owner)
|
val (originOwner, originId) = parseCompareIdentifier(origin, forkedRepository.owner)
|
||||||
val (forkedOwner, forkedId) = parseCompareIdentifier(forked, forkedRepository.owner)
|
val (forkedOwner, forkedId) = parseCompareIdentifier(forked, forkedRepository.owner)
|
||||||
|
|
||||||
(for (originRepositoryName <- getOriginRepositoryName(originOwner, forkedOwner, forkedRepository);
|
(for (
|
||||||
originRepository <- getRepository(originOwner, originRepositoryName)) yield {
|
originRepositoryName <- getOriginRepositoryName(originOwner, forkedOwner, forkedRepository);
|
||||||
|
originRepository <- getRepository(originOwner, originRepositoryName)
|
||||||
|
) yield {
|
||||||
val (oldId, newId) =
|
val (oldId, newId) =
|
||||||
getPullRequestCommitFromTo(originRepository, forkedRepository, originId, forkedId)
|
getPullRequestCommitFromTo(originRepository, forkedRepository, originId, forkedId)
|
||||||
|
|
||||||
@@ -566,7 +560,9 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val (originOwner, tmpOriginBranch) = parseCompareIdentifier(origin, forkedRepository.owner)
|
val (originOwner, tmpOriginBranch) = parseCompareIdentifier(origin, forkedRepository.owner)
|
||||||
val (forkedOwner, tmpForkedBranch) = parseCompareIdentifier(forked, forkedRepository.owner)
|
val (forkedOwner, tmpForkedBranch) = parseCompareIdentifier(forked, forkedRepository.owner)
|
||||||
|
|
||||||
(for (originRepositoryName <- if (originOwner == forkedOwner) {
|
(for (
|
||||||
|
originRepositoryName <-
|
||||||
|
if (originOwner == forkedOwner) {
|
||||||
Some(forkedRepository.name)
|
Some(forkedRepository.name)
|
||||||
} else {
|
} else {
|
||||||
forkedRepository.repository.originRepositoryName.orElse {
|
forkedRepository.repository.originRepositoryName.orElse {
|
||||||
@@ -575,12 +571,12 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
.map(_.repositoryName)
|
.map(_.repositoryName)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
originRepository <- getRepository(originOwner, originRepositoryName)) yield {
|
originRepository <- getRepository(originOwner, originRepositoryName)
|
||||||
|
) yield {
|
||||||
Using.resources(
|
Using.resources(
|
||||||
Git.open(getRepositoryDir(originRepository.owner, originRepository.name)),
|
Git.open(getRepositoryDir(originRepository.owner, originRepository.name)),
|
||||||
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
||||||
) {
|
) { case (oldGit, newGit) =>
|
||||||
case (oldGit, newGit) =>
|
|
||||||
val originBranch = JGitUtil.getDefaultBranch(oldGit, originRepository, tmpOriginBranch).get._2
|
val originBranch = JGitUtil.getDefaultBranch(oldGit, originRepository, tmpOriginBranch).get._2
|
||||||
val forkedBranch = JGitUtil.getDefaultBranch(newGit, forkedRepository, tmpForkedBranch).get._2
|
val forkedBranch = JGitUtil.getDefaultBranch(newGit, forkedRepository, tmpForkedBranch).get._2
|
||||||
val conflict = LockUtil.lock(s"${originRepository.owner}/${originRepository.name}") {
|
val conflict = LockUtil.lock(s"${originRepository.owner}/${originRepository.name}") {
|
||||||
@@ -599,8 +595,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/pulls/new", pullRequestForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/pulls/new", pullRequestForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
val manageable = isManageable(repository)
|
val manageable = isManageable(repository)
|
||||||
|
|
||||||
val issueId = insertIssue(
|
val issueId = insertIssue(
|
||||||
@@ -656,8 +651,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
context.loginAccount.map(x => Seq(x.mailAddress) ++ getAccountExtraMailAddresses(x.userName)).getOrElse(Nil)
|
context.loginAccount.map(x => Seq(x.mailAddress) ++ getAccountExtraMailAddresses(x.userName)).getOrElse(Nil)
|
||||||
|
|
||||||
val branches =
|
val branches =
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
JGitUtil
|
JGitUtil
|
||||||
.getBranches(
|
.getBranches(
|
||||||
git = git,
|
git = git,
|
||||||
|
|||||||
@@ -106,8 +106,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/releases/*/create", releaseForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/releases/*/create", releaseForm)(writableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
val tagName = multiParams("splat").head
|
val tagName = multiParams("splat").head
|
||||||
|
|
||||||
// Insert into RELEASE
|
// Insert into RELEASE
|
||||||
@@ -119,8 +118,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
val Array(_, fileId) = name.split(":")
|
val Array(_, fileId) = name.split(":")
|
||||||
(fileId, value)
|
(fileId, value)
|
||||||
}
|
}
|
||||||
files.foreach {
|
files.foreach { case (fileId, fileName) =>
|
||||||
case (fileId, fileName) =>
|
|
||||||
val size =
|
val size =
|
||||||
new File(
|
new File(
|
||||||
getReleaseFilesDir(repository.owner, repository.name),
|
getReleaseFilesDir(repository.owner, repository.name),
|
||||||
@@ -171,13 +169,11 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/releases/*/edit", releaseForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/releases/*/edit", releaseForm)(writableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
val tagName = multiParams("splat").head
|
val tagName = multiParams("splat").head
|
||||||
|
|
||||||
getRelease(repository.owner, repository.name, tagName)
|
getRelease(repository.owner, repository.name, tagName)
|
||||||
.map {
|
.map { release =>
|
||||||
release =>
|
|
||||||
// Update RELEASE
|
// Update RELEASE
|
||||||
updateRelease(repository.owner, repository.name, tagName, form.name, form.content)
|
updateRelease(repository.owner, repository.name, tagName, form.name, form.content)
|
||||||
|
|
||||||
@@ -190,8 +186,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
val Array(_, fileId) = name.split(":")
|
val Array(_, fileId) = name.split(":")
|
||||||
(fileId, value)
|
(fileId, value)
|
||||||
}
|
}
|
||||||
files.foreach {
|
files.foreach { case (fileId, fileName) =>
|
||||||
case (fileId, fileName) =>
|
|
||||||
val size =
|
val size =
|
||||||
new File(
|
new File(
|
||||||
getReleaseFilesDir(repository.owner, repository.name),
|
getReleaseFilesDir(repository.owner, repository.name),
|
||||||
@@ -237,9 +232,12 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
val assets = getReleaseAssetsMap(repository.owner, repository.name, releases)
|
val assets = getReleaseAssetsMap(repository.owner, repository.name, releases)
|
||||||
|
|
||||||
val tagsWithReleases = tagsToDisplay.map { tag =>
|
val tagsWithReleases = tagsToDisplay.map { tag =>
|
||||||
(tag, releases.find(_.tag == tag.name).map { release =>
|
(
|
||||||
|
tag,
|
||||||
|
releases.find(_.tag == tag.name).map { release =>
|
||||||
(release, assets(release))
|
(release, assets(release))
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
tagsWithReleases
|
tagsWithReleases
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -286,8 +286,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
Array(h.getName, h.getValue)
|
Array(h.getName, h.getValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
import scala.jdk.CollectionConverters._
|
import scala.jdk.CollectionConverters._
|
||||||
@@ -348,8 +347,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
"url" -> url,
|
"url" -> url,
|
||||||
"request" -> Await.result(
|
"request" -> Await.result(
|
||||||
reqFuture
|
reqFuture
|
||||||
.map(
|
.map(req =>
|
||||||
req =>
|
|
||||||
Map(
|
Map(
|
||||||
"headers" -> _headers(req.getAllHeaders),
|
"headers" -> _headers(req.getAllHeaders),
|
||||||
"payload" -> json
|
"payload" -> json
|
||||||
@@ -360,8 +358,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
),
|
),
|
||||||
"response" -> Await.result(
|
"response" -> Await.result(
|
||||||
resFuture
|
resFuture
|
||||||
.map(
|
.map(res =>
|
||||||
res =>
|
|
||||||
Map(
|
Map(
|
||||||
"status" -> res.getStatusLine.getStatusCode,
|
"status" -> res.getStatusLine.getStatusCode,
|
||||||
"body" -> EntityUtils.toString(res.getEntity()),
|
"body" -> EntityUtils.toString(res.getEntity()),
|
||||||
@@ -380,8 +377,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Display the web hook edit page.
|
* Display the web hook edit page.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/hooks/edit")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/hooks/edit")(ownerOnly { repository =>
|
||||||
getWebHook(repository.owner, repository.name, params("url")).map {
|
getWebHook(repository.owner, repository.name, params("url")).map { case (webhook, events) =>
|
||||||
case (webhook, events) =>
|
|
||||||
html.edithook(webhook, events, repository, false)
|
html.edithook(webhook, events, repository, false)
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
@@ -406,8 +402,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Rename repository.
|
* Rename repository.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/rename", renameForm)(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/rename", renameForm)(ownerOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (context.settings.basicBehavior.repositoryOperation.rename || loginAccount.isAdmin) {
|
if (context.settings.basicBehavior.repositoryOperation.rename || loginAccount.isAdmin) {
|
||||||
if (repository.name != form.repositoryName) {
|
if (repository.name != form.repositoryName) {
|
||||||
// Update database and move git repository
|
// Update database and move git repository
|
||||||
@@ -430,8 +425,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Transfer repository ownership.
|
* Transfer repository ownership.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/transfer", transferForm)(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/transfer", transferForm)(ownerOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (context.settings.basicBehavior.repositoryOperation.transfer || loginAccount.isAdmin) {
|
if (context.settings.basicBehavior.repositoryOperation.transfer || loginAccount.isAdmin) {
|
||||||
// Change repository owner
|
// Change repository owner
|
||||||
if (repository.owner != form.newOwner) {
|
if (repository.owner != form.newOwner) {
|
||||||
|
|||||||
@@ -257,8 +257,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val (branchName, path) = repository.splitPath(multiParams("splat").head)
|
val (branchName, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val page = params.get("page").flatMap(_.toIntOpt).getOrElse(1)
|
val page = params.get("page").flatMap(_.toIntOpt).getOrElse(1)
|
||||||
|
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
JGitUtil.getCommitLog(git, branchName, page, 30, path) match {
|
JGitUtil.getCommitLog(git, branchName, page, 30, path) match {
|
||||||
case Right((logs, hasNext)) =>
|
case Right((logs, hasNext)) =>
|
||||||
html.commits(
|
html.commits(
|
||||||
@@ -273,8 +272,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
getCommitStatusWithSummary(repository.owner, repository.name, commit.id)
|
getCommitStatusWithSummary(repository.owner, repository.name, commit.id)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.splitWith {
|
.splitWith { case ((commit1, _, _), (commit2, _, _)) =>
|
||||||
case ((commit1, _, _), (commit2, _, _)) =>
|
|
||||||
view.helpers.date(commit1.commitTime) == view.helpers.date(commit2.commitTime)
|
view.helpers.date(commit1.commitTime) == view.helpers.date(commit2.commitTime)
|
||||||
},
|
},
|
||||||
page,
|
page,
|
||||||
@@ -287,8 +285,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/new/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/new/*")(writableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
.needStatusCheck(loginAccount.userName)
|
.needStatusCheck(loginAccount.userName)
|
||||||
@@ -310,8 +307,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/upload/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/upload/*")(writableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
.needStatusCheck(loginAccount.userName)
|
.needStatusCheck(loginAccount.userName)
|
||||||
@@ -340,8 +336,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
message = form.message.getOrElse("Add files via upload"),
|
message = form.message.getOrElse("Add files via upload"),
|
||||||
loginAccount = loginAccount,
|
loginAccount = loginAccount,
|
||||||
settings = context.settings
|
settings = context.settings
|
||||||
) {
|
) { case (git, headTip, builder, inserter) =>
|
||||||
case (git, headTip, builder, inserter) =>
|
|
||||||
JGitUtil.processTree(git, headTip) { (path, tree) =>
|
JGitUtil.processTree(git, headTip) { (path, tree) =>
|
||||||
if (!newFiles.exists(_.name.contains(path))) {
|
if (!newFiles.exists(_.name.contains(path))) {
|
||||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||||
@@ -359,8 +354,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
val files = form.uploadFiles
|
val files = form.uploadFiles
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map { line =>
|
.map { line =>
|
||||||
@@ -407,19 +401,16 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/edit/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/edit/*")(writableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
.needStatusCheck(loginAccount.userName)
|
.needStatusCheck(loginAccount.userName)
|
||||||
|
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
|
|
||||||
getPathObjectId(git, path, revCommit)
|
getPathObjectId(git, path, revCommit)
|
||||||
.map {
|
.map { objectId =>
|
||||||
objectId =>
|
|
||||||
val paths = path.split("/")
|
val paths = path.split("/")
|
||||||
val info = EditorConfigUtil.getEditorConfigInfo(git, branch, path)
|
val info = EditorConfigUtil.getEditorConfigInfo(git, branch, path)
|
||||||
|
|
||||||
@@ -442,8 +433,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/remove/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/remove/*")(writableUsersOnly { repository =>
|
||||||
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
|
|
||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
@@ -477,8 +467,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
).map(_._1)
|
).map(_._1)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (form.newBranch) {
|
if (form.newBranch) {
|
||||||
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
||||||
_commit(newBranchName, loginAccount) match {
|
_commit(newBranchName, loginAccount) match {
|
||||||
@@ -535,8 +524,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
).map(_._1)
|
).map(_._1)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (form.newBranch) {
|
if (form.newBranch) {
|
||||||
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
||||||
_commit(newBranchName, loginAccount) match {
|
_commit(newBranchName, loginAccount) match {
|
||||||
@@ -589,8 +577,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
).map(_._1)
|
).map(_._1)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (form.newBranch) {
|
if (form.newBranch) {
|
||||||
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
||||||
_commit(newBranchName, loginAccount) match {
|
_commit(newBranchName, loginAccount) match {
|
||||||
@@ -714,11 +701,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val (id, path) = repository.splitPath(multiParams("splat").head)
|
val (id, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val raw = params.get("raw").getOrElse("false").toBoolean
|
val raw = params.get("raw").getOrElse("false").toBoolean
|
||||||
val highlighterTheme = getSyntaxHighlighterTheme()
|
val highlighterTheme = getSyntaxHighlighterTheme()
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||||
getPathObjectId(git, path, revCommit).map {
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
objectId =>
|
|
||||||
if (raw) {
|
if (raw) {
|
||||||
// Download (This route is left for backward compatibility)
|
// Download (This route is left for backward compatibility)
|
||||||
responseRawFile(git, objectId, path, repository)
|
responseRawFile(git, objectId, path, repository)
|
||||||
@@ -766,8 +751,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
ajaxGet("/:owner/:repository/get-blame/*")(referrersOnly { repository =>
|
ajaxGet("/:owner/:repository/get-blame/*")(referrersOnly { repository =>
|
||||||
val (id, path) = repository.splitPath(multiParams("splat").head)
|
val (id, path) = repository.splitPath(multiParams("splat").head)
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
val last = git.log.add(git.getRepository.resolve(id)).addPath(path).setMaxCount(1).call.iterator.next.name
|
val last = git.log.add(git.getRepository.resolve(id)).addPath(path).setMaxCount(1).call.iterator.next.name
|
||||||
Serialization.write(
|
Serialization.write(
|
||||||
Map(
|
Map(
|
||||||
@@ -775,8 +759,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
"id" -> id,
|
"id" -> id,
|
||||||
"path" -> path,
|
"path" -> path,
|
||||||
"last" -> last,
|
"last" -> last,
|
||||||
"blame" -> JGitUtil.getBlame(git, id, path).map {
|
"blame" -> JGitUtil.getBlame(git, id, path).map { blame =>
|
||||||
blame =>
|
|
||||||
Map(
|
Map(
|
||||||
"id" -> blame.id,
|
"id" -> blame.id,
|
||||||
"author" -> view.helpers.user(blame.authorName, blame.authorEmailAddress).toString,
|
"author" -> view.helpers.user(blame.authorName, blame.authorEmailAddress).toString,
|
||||||
@@ -801,8 +784,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val id = params("id")
|
val id = params("id")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||||
val diffs = JGitUtil.getDiffs(git, None, id, true, false)
|
val diffs = JGitUtil.getDiffs(git, None, id, true, false)
|
||||||
val oldCommitId = JGitUtil.getParentCommitId(git, id)
|
val oldCommitId = JGitUtil.getParentCommitId(git, id)
|
||||||
@@ -890,8 +872,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/commit/:id/comment/_data/new", commentForm)(readableUsersOnly { (form, repository) =>
|
ajaxPost("/:owner/:repository/commit/:id/comment/_data/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
val id = params("id")
|
val id = params("id")
|
||||||
val commentId = createCommitComment(
|
val commentId = createCommitComment(
|
||||||
repository,
|
repository,
|
||||||
@@ -912,10 +893,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/commit_comments/_data/:id")(readableUsersOnly { repository =>
|
ajaxGet("/:owner/:repository/commit_comments/_data/:id")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
getCommitComment(repository.owner, repository.name, params("id")) map { x =>
|
||||||
getCommitComment(repository.owner, repository.name, params("id")) map {
|
|
||||||
x =>
|
|
||||||
if (isEditable(x.userName, x.repositoryName, x.commentedUserName, loginAccount)) {
|
if (isEditable(x.userName, x.repositoryName, x.commentedUserName, loginAccount)) {
|
||||||
params.get("dataType") collect {
|
params.get("dataType") collect {
|
||||||
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
||||||
@@ -943,8 +922,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/commit_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
ajaxPost("/:owner/:repository/commit_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
getCommitComment(repository.owner, repository.name, params("id")).map { comment =>
|
getCommitComment(repository.owner, repository.name, params("id")).map { comment =>
|
||||||
if (isEditable(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
if (isEditable(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
||||||
updateCommitComment(comment.commentId, form.content)
|
updateCommitComment(comment.commentId, form.content)
|
||||||
@@ -969,8 +947,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
get("/:owner/:repository/branches")(referrersOnly { repository =>
|
get("/:owner/:repository/branches")(referrersOnly { repository =>
|
||||||
val protectedBranches = getProtectedBranchList(repository.owner, repository.name).toSet
|
val protectedBranches = getProtectedBranchList(repository.owner, repository.name).toSet
|
||||||
val branches = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
val branches = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
JGitUtil
|
JGitUtil
|
||||||
.getBranches(
|
.getBranches(
|
||||||
git = git,
|
git = git,
|
||||||
@@ -978,8 +955,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
origin = repository.repository.originUserName.isEmpty
|
origin = repository.repository.originUserName.isEmpty
|
||||||
)
|
)
|
||||||
.sortBy(branch => (branch.mergeInfo.isEmpty, branch.commitTime))
|
.sortBy(branch => (branch.mergeInfo.isEmpty, branch.commitTime))
|
||||||
.map(
|
.map(branch =>
|
||||||
branch =>
|
|
||||||
(
|
(
|
||||||
branch,
|
branch,
|
||||||
getPullRequestByRequestCommit(
|
getPullRequestByRequestCommit(
|
||||||
@@ -1028,8 +1004,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
post("/:owner/:repository/branches")(writableUsersOnly { repository =>
|
post("/:owner/:repository/branches")(writableUsersOnly { repository =>
|
||||||
val newBranchName = params.getOrElse("new", halt(400))
|
val newBranchName = params.getOrElse("new", halt(400))
|
||||||
val fromBranchName = params.getOrElse("from", halt(400))
|
val fromBranchName = params.getOrElse("from", halt(400))
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
JGitUtil.createBranch(git, fromBranchName, newBranchName) match {
|
JGitUtil.createBranch(git, fromBranchName, newBranchName) match {
|
||||||
case Right(message) =>
|
case Right(message) =>
|
||||||
flash.update("info", message)
|
flash.update("info", message)
|
||||||
@@ -1083,8 +1058,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
* Deletes branch.
|
* Deletes branch.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/delete/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/delete/*")(writableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
val branchName = multiParams("splat").head
|
val branchName = multiParams("splat").head
|
||||||
if (repository.repository.defaultBranch != branchName) {
|
if (repository.repository.defaultBranch != branchName) {
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
@@ -1179,8 +1153,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
html.guide(repository, hasDeveloperRole(repository.owner, repository.name, context.loginAccount))
|
html.guide(repository, hasDeveloperRole(repository.owner, repository.name, context.loginAccount))
|
||||||
} else {
|
} else {
|
||||||
// get specified commit
|
// get specified commit
|
||||||
JGitUtil.getDefaultBranch(git, repository, revstr).map {
|
JGitUtil.getDefaultBranch(git, repository, revstr).map { case (objectId, revision) =>
|
||||||
case (objectId, revision) =>
|
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, objectId)
|
val revCommit = JGitUtil.getRevCommitFromId(git, objectId)
|
||||||
val lastModifiedCommit =
|
val lastModifiedCommit =
|
||||||
if (path == ".") revCommit else JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
if (path == ".") revCommit else JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
||||||
|
|||||||
@@ -55,15 +55,13 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
"bindAddress" -> mapping(
|
"bindAddress" -> mapping(
|
||||||
"host" -> trim(label("Bind SSH host", optional(text()))),
|
"host" -> trim(label("Bind SSH host", optional(text()))),
|
||||||
"port" -> trim(label("Bind SSH port", optional(number()))),
|
"port" -> trim(label("Bind SSH port", optional(number()))),
|
||||||
)(
|
)((hostOption, portOption) =>
|
||||||
(hostOption, portOption) =>
|
|
||||||
hostOption.map(h => SshAddress(h, portOption.getOrElse(DefaultSshPort), GenericSshUser))
|
hostOption.map(h => SshAddress(h, portOption.getOrElse(DefaultSshPort), GenericSshUser))
|
||||||
),
|
),
|
||||||
"publicAddress" -> mapping(
|
"publicAddress" -> mapping(
|
||||||
"host" -> trim(label("Public SSH host", optional(text()))),
|
"host" -> trim(label("Public SSH host", optional(text()))),
|
||||||
"port" -> trim(label("Public SSH port", optional(number()))),
|
"port" -> trim(label("Public SSH port", optional(number()))),
|
||||||
)(
|
)((hostOption, portOption) =>
|
||||||
(hostOption, portOption) =>
|
|
||||||
hostOption.map(h => SshAddress(h, portOption.getOrElse(PublicSshPort), GenericSshUser))
|
hostOption.map(h => SshAddress(h, portOption.getOrElse(PublicSshPort), GenericSshUser))
|
||||||
),
|
),
|
||||||
)(Ssh.apply),
|
)(Ssh.apply),
|
||||||
@@ -251,8 +249,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
val conn = request2Session(request).conn
|
val conn = request2Session(request).conn
|
||||||
val meta = conn.getMetaData
|
val meta = conn.getMetaData
|
||||||
val tables = ListBuffer[Table]()
|
val tables = ListBuffer[Table]()
|
||||||
Using.resource(meta.getTables(null, "%", "%", Array("TABLE", "VIEW"))) {
|
Using.resource(meta.getTables(null, "%", "%", Array("TABLE", "VIEW"))) { rs =>
|
||||||
rs =>
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
val tableName = rs.getString("TABLE_NAME")
|
val tableName = rs.getString("TABLE_NAME")
|
||||||
|
|
||||||
@@ -285,11 +282,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
if (trimmedQuery.nonEmpty) {
|
if (trimmedQuery.nonEmpty) {
|
||||||
try {
|
try {
|
||||||
val conn = request2Session(request).conn
|
val conn = request2Session(request).conn
|
||||||
Using.resource(conn.prepareStatement(query)) {
|
Using.resource(conn.prepareStatement(query)) { stmt =>
|
||||||
stmt =>
|
|
||||||
if (trimmedQuery.toUpperCase.startsWith("SELECT")) {
|
if (trimmedQuery.toUpperCase.startsWith("SELECT")) {
|
||||||
Using.resource(stmt.executeQuery()) {
|
Using.resource(stmt.executeQuery()) { rs =>
|
||||||
rs =>
|
|
||||||
val meta = rs.getMetaData
|
val meta = rs.getMetaData
|
||||||
val columns = for (i <- 1 to meta.getColumnCount) yield {
|
val columns = for (i <- 1 to meta.getColumnCount) yield {
|
||||||
meta.getColumnName(i)
|
meta.getColumnName(i)
|
||||||
@@ -323,7 +318,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
post("/admin/system", form)(adminOnly { form =>
|
post("/admin/system", form)(adminOnly { form =>
|
||||||
saveSystemSettings(form)
|
saveSystemSettings(form)
|
||||||
|
|
||||||
if (form.ssh.bindAddress != context.settings.sshBindAddress || form.ssh.publicAddress != context.settings.sshPublicAddress) {
|
if (
|
||||||
|
form.ssh.bindAddress != context.settings.sshBindAddress || form.ssh.publicAddress != context.settings.sshPublicAddress
|
||||||
|
) {
|
||||||
SshServer.stop()
|
SshServer.stop()
|
||||||
for {
|
for {
|
||||||
bindAddress <- form.ssh.bindAddress
|
bindAddress <- form.ssh.bindAddress
|
||||||
@@ -420,8 +417,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
post("/admin/users/:name/_edituser", editUserForm)(adminOnly { form =>
|
post("/admin/users/:name/_edituser", editUserForm)(adminOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName, true).map {
|
getAccountByUserName(userName, true).map { account =>
|
||||||
account =>
|
|
||||||
if (account.isAdmin && (form.isRemoved || !form.isAdmin) && isLastAdministrator(account)) {
|
if (account.isAdmin && (form.isRemoved || !form.isAdmin) && isLastAdministrator(account)) {
|
||||||
flash.update("error", "Account can't be turned off because this is last one administrator.")
|
flash.update("error", "Account can't be turned off because this is last one administrator.")
|
||||||
redirect(s"/admin/users/${userName}/_edituser")
|
redirect(s"/admin/users/${userName}/_edituser")
|
||||||
@@ -498,8 +494,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
.toList
|
.toList
|
||||||
|
|
||||||
getAccountByUserName(groupName, true).map {
|
getAccountByUserName(groupName, true).map { account =>
|
||||||
account =>
|
|
||||||
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
||||||
|
|
||||||
if (form.isRemoved) {
|
if (form.isRemoved) {
|
||||||
@@ -565,9 +560,11 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
private def members: Constraint =
|
private def members: Constraint =
|
||||||
new Constraint() {
|
new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
if (value.split(",").exists {
|
if (
|
||||||
|
value.split(",").exists {
|
||||||
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
||||||
}) None
|
}
|
||||||
|
) None
|
||||||
else Some("Must select one manager at least.")
|
else Some("Must select one manager at least.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ trait ValidationSupport extends FormSupport { self: ServletBase with JacksonJson
|
|||||||
* Converts errors to JSON.
|
* Converts errors to JSON.
|
||||||
*/
|
*/
|
||||||
private def toJson(errors: Seq[(String, String)]): JObject =
|
private def toJson(errors: Seq[(String, String)]): JObject =
|
||||||
JObject(errors.map {
|
JObject(errors.map { case (key, value) =>
|
||||||
case (key, value) =>
|
|
||||||
JField(key, JString(value))
|
JField(key, JString(value))
|
||||||
}.toList)
|
}.toList)
|
||||||
|
|
||||||
|
|||||||
@@ -146,8 +146,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/:page/_revert/:commitId")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_revert/:commitId")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (isEditable(repository)) {
|
if (isEditable(repository)) {
|
||||||
val pageName = StringUtil.urlDecode(params("page"))
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
@@ -166,8 +165,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_revert/:commitId")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/_revert/:commitId")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (isEditable(repository)) {
|
if (isEditable(repository)) {
|
||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
val branch = getWikiBranch(repository.owner, repository.name)
|
val branch = getWikiBranch(repository.owner, repository.name)
|
||||||
@@ -192,8 +190,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_edit", editForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_edit", editForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (isEditable(repository)) {
|
if (isEditable(repository)) {
|
||||||
saveWikiPage(
|
saveWikiPage(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
@@ -204,8 +201,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
loginAccount,
|
loginAccount,
|
||||||
form.message.getOrElse(""),
|
form.message.getOrElse(""),
|
||||||
Some(form.id)
|
Some(form.id)
|
||||||
).foreach {
|
).foreach { commitId =>
|
||||||
commitId =>
|
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
val wikiEditInfo =
|
val wikiEditInfo =
|
||||||
EditWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName, commitId)
|
EditWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName, commitId)
|
||||||
@@ -232,8 +228,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (isEditable(repository)) {
|
if (isEditable(repository)) {
|
||||||
saveWikiPage(
|
saveWikiPage(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
@@ -244,8 +239,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
loginAccount,
|
loginAccount,
|
||||||
form.message.getOrElse(""),
|
form.message.getOrElse(""),
|
||||||
None
|
None
|
||||||
).foreach {
|
).foreach { commitId =>
|
||||||
commitId =>
|
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
val createWikiPageInfo =
|
val createWikiPageInfo =
|
||||||
CreateWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
CreateWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
||||||
@@ -267,8 +261,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/:page/_delete")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_delete")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
if (isEditable(repository)) {
|
if (isEditable(repository)) {
|
||||||
val pageName = StringUtil.urlDecode(params("page"))
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
deleteWikiPage(
|
deleteWikiPage(
|
||||||
|
|||||||
@@ -58,10 +58,8 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#create-a-reference
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#create-a-reference
|
||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/git/refs")(writableUsersOnly { repository =>
|
post("/api/v3/repos/:owner/:repository/git/refs")(writableUsersOnly { repository =>
|
||||||
extractFromJsonBody[CreateARef].map {
|
extractFromJsonBody[CreateARef].map { data =>
|
||||||
data =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
|
||||||
git =>
|
|
||||||
val ref = git.getRepository.findRef(data.ref)
|
val ref = git.getRepository.findRef(data.ref)
|
||||||
if (ref == null) {
|
if (ref == null) {
|
||||||
val update = git.getRepository.updateRef(data.ref)
|
val update = git.getRepository.updateRef(data.ref)
|
||||||
@@ -88,8 +86,7 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
patch("/api/v3/repos/:owner/:repository/git/refs/*")(writableUsersOnly { repository =>
|
patch("/api/v3/repos/:owner/:repository/git/refs/*")(writableUsersOnly { repository =>
|
||||||
val refName = multiParams("splat").mkString("/")
|
val refName = multiParams("splat").mkString("/")
|
||||||
extractFromJsonBody[UpdateARef].map {
|
extractFromJsonBody[UpdateARef].map { data =>
|
||||||
data =>
|
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val ref = git.getRepository.findRef(refName)
|
val ref = git.getRepository.findRef(refName)
|
||||||
if (ref == null) {
|
if (ref == null) {
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
|
|||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
comments = getCommentsForApi(repository.owner, repository.name, issueId)
|
comments = getCommentsForApi(repository.owner, repository.name, issueId)
|
||||||
} yield {
|
} yield {
|
||||||
JsonFormat(comments.map {
|
JsonFormat(comments.map { case (issueComment, user, issue) =>
|
||||||
case (issueComment, user, issue) =>
|
|
||||||
ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(user), issue.isPullRequest)
|
ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(user), issue.isPullRequest)
|
||||||
})
|
})
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
repos = repository.owner -> repository.name
|
repos = repository.owner -> repository.name
|
||||||
)
|
)
|
||||||
|
|
||||||
JsonFormat(issues.map {
|
JsonFormat(issues.map { case (issue, issueUser, assigneeUsers) =>
|
||||||
case (issue, issueUser, assigneeUsers) =>
|
|
||||||
ApiIssue(
|
ApiIssue(
|
||||||
issue = issue,
|
issue = issue,
|
||||||
repositoryName = RepositoryName(repository),
|
repositoryName = RepositoryName(repository),
|
||||||
|
|||||||
@@ -69,8 +69,7 @@ trait ApiIssueLabelControllerBase extends ControllerBase {
|
|||||||
data <- extractFromJsonBody[CreateALabel] if data.isValid
|
data <- extractFromJsonBody[CreateALabel] if data.isValid
|
||||||
} yield {
|
} yield {
|
||||||
LockUtil.lock(RepositoryName(repository).fullName) {
|
LockUtil.lock(RepositoryName(repository).fullName) {
|
||||||
getLabel(repository.owner, repository.name, params("labelName")).map {
|
getLabel(repository.owner, repository.name, params("labelName")).map { label =>
|
||||||
label =>
|
|
||||||
if (getLabel(repository.owner, repository.name, data.name).isEmpty) {
|
if (getLabel(repository.owner, repository.name, data.name).isEmpty) {
|
||||||
updateLabel(repository.owner, repository.name, label.labelId, data.name, data.color)
|
updateLabel(repository.owner, repository.name, label.labelId, data.name, data.color)
|
||||||
JsonFormat(
|
JsonFormat(
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ trait ApiIssueMilestoneControllerBase extends ControllerBase {
|
|||||||
get("/api/v3/repos/:owner/:repository/milestones")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/milestones")(referrersOnly { repository =>
|
||||||
val state = params.getOrElse("state", "all")
|
val state = params.getOrElse("state", "all")
|
||||||
// TODO "sort", "direction" params should be implemented.
|
// TODO "sort", "direction" params should be implemented.
|
||||||
val apiMilestones = (for (milestoneWithIssue <- getMilestonesWithIssueCount(repository.owner, repository.name)
|
val apiMilestones = (for (
|
||||||
.sortBy(p => p._1.milestoneId))
|
milestoneWithIssue <- getMilestonesWithIssueCount(repository.owner, repository.name)
|
||||||
|
.sortBy(p => p._1.milestoneId)
|
||||||
|
)
|
||||||
yield {
|
yield {
|
||||||
ApiMilestone(
|
ApiMilestone(
|
||||||
repository.repository,
|
repository.repository,
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
repos = repository.owner -> repository.name
|
repos = repository.owner -> repository.name
|
||||||
)
|
)
|
||||||
|
|
||||||
JsonFormat(issues.map {
|
JsonFormat(issues.map { case (issue, issueUser, commentCount, pullRequest, headRepo, headOwner, assignees) =>
|
||||||
case (issue, issueUser, commentCount, pullRequest, headRepo, headOwner, assignees) =>
|
|
||||||
ApiPullRequest(
|
ApiPullRequest(
|
||||||
issue = issue,
|
issue = issue,
|
||||||
pullRequest = pullRequest,
|
pullRequest = pullRequest,
|
||||||
@@ -89,8 +88,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
case Left(createPullReq) =>
|
case Left(createPullReq) =>
|
||||||
val (reqOwner, reqBranch) = parseCompareIdentifier(createPullReq.head, repository.owner)
|
val (reqOwner, reqBranch) = parseCompareIdentifier(createPullReq.head, repository.owner)
|
||||||
getRepository(reqOwner, repository.name)
|
getRepository(reqOwner, repository.name)
|
||||||
.flatMap {
|
.flatMap { forkedRepository =>
|
||||||
forkedRepository =>
|
|
||||||
getPullRequestCommitFromTo(repository, forkedRepository, createPullReq.base, reqBranch) match {
|
getPullRequestCommitFromTo(repository, forkedRepository, createPullReq.base, reqBranch) match {
|
||||||
case (Some(commitIdFrom), Some(commitIdTo)) =>
|
case (Some(commitIdFrom), Some(commitIdTo)) =>
|
||||||
val issueId = insertIssue(
|
val issueId = insertIssue(
|
||||||
@@ -128,8 +126,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
case Right(createPullReqAlt) =>
|
case Right(createPullReqAlt) =>
|
||||||
val (reqOwner, reqBranch) = parseCompareIdentifier(createPullReqAlt.head, repository.owner)
|
val (reqOwner, reqBranch) = parseCompareIdentifier(createPullReqAlt.head, repository.owner)
|
||||||
getRepository(reqOwner, repository.name)
|
getRepository(reqOwner, repository.name)
|
||||||
.flatMap {
|
.flatMap { forkedRepository =>
|
||||||
forkedRepository =>
|
|
||||||
getPullRequestCommitFromTo(repository, forkedRepository, createPullReqAlt.base, reqBranch) match {
|
getPullRequestCommitFromTo(repository, forkedRepository, createPullReqAlt.base, reqBranch) match {
|
||||||
case (Some(commitIdFrom), Some(commitIdTo)) =>
|
case (Some(commitIdFrom), Some(commitIdTo)) =>
|
||||||
changeIssueToPullRequest(repository.owner, repository.name, createPullReqAlt.issue)
|
changeIssueToPullRequest(repository.owner, repository.name, createPullReqAlt.issue)
|
||||||
@@ -190,10 +187,8 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
get("/api/v3/repos/:owner/:repository/pulls/:id/commits")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/pulls/:id/commits")(referrersOnly { repository =>
|
||||||
val owner = repository.owner
|
val owner = repository.owner
|
||||||
val name = repository.name
|
val name = repository.name
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap { issueId =>
|
||||||
issueId =>
|
getPullRequest(owner, name, issueId) map { case (issue, pullreq) =>
|
||||||
getPullRequest(owner, name, issueId) map {
|
|
||||||
case (issue, pullreq) =>
|
|
||||||
Using.resource(Git.open(getRepositoryDir(owner, name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(owner, name))) { git =>
|
||||||
val oldId = git.getRepository.resolve(pullreq.commitIdFrom)
|
val oldId = git.getRepository.resolve(pullreq.commitIdFrom)
|
||||||
val newId = git.getRepository.resolve(pullreq.commitIdTo)
|
val newId = git.getRepository.resolve(pullreq.commitIdTo)
|
||||||
|
|||||||
@@ -119,8 +119,7 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
|||||||
* ix. Upload a release asset
|
* ix. Upload a release asset
|
||||||
* https://developer.github.com/v3/repos/releases/#upload-a-release-asset
|
* https://developer.github.com/v3/repos/releases/#upload-a-release-asset
|
||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/releases/:tag/assets")(writableUsersOnly {
|
post("/api/v3/repos/:owner/:repository/releases/:tag/assets")(writableUsersOnly { repository =>
|
||||||
repository =>
|
|
||||||
val name = params("name")
|
val name = params("name")
|
||||||
val tag = params("tag")
|
val tag = params("tag")
|
||||||
getRelease(repository.owner, repository.name, tag)
|
getRelease(repository.owner, repository.name, tag)
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
|||||||
* https://docs.github.com/en/rest/reference/repos#get-a-branch
|
* https://docs.github.com/en/rest/reference/repos#get-a-branch
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/branches/*")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/branches/*")(referrersOnly { repository =>
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
(for {
|
(for {
|
||||||
branch <- params.get("splat") if repository.branchList.contains(branch)
|
branch <- params.get("splat") if repository.branchList.contains(branch)
|
||||||
br <- getBranches(
|
br <- getBranches(
|
||||||
@@ -275,8 +274,7 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
patch("/api/v3/repos/:owner/:repository/branches/*")(ownerOnly { repository =>
|
patch("/api/v3/repos/:owner/:repository/branches/*")(ownerOnly { repository =>
|
||||||
import gitbucket.core.api._
|
import gitbucket.core.api._
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git =>
|
|
||||||
(for {
|
(for {
|
||||||
branch <- params.get("splat") if repository.branchList.contains(branch)
|
branch <- params.get("splat") if repository.branchList.contains(branch)
|
||||||
protection <- extractFromJsonBody[ApiBranchProtection.EnablingAndDisabling].map(_.protection)
|
protection <- extractFromJsonBody[ApiBranchProtection.EnablingAndDisabling].map(_.protection)
|
||||||
|
|||||||
@@ -43,11 +43,9 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
val path = params.get("path").filter(_.nonEmpty)
|
val path = params.get("path").filter(_.nonEmpty)
|
||||||
val since = params.get("since").filter(_.nonEmpty)
|
val since = params.get("since").filter(_.nonEmpty)
|
||||||
val until = params.get("until").filter(_.nonEmpty)
|
val until = params.get("until").filter(_.nonEmpty)
|
||||||
Using.resource(Git.open(getRepositoryDir(owner, name))) {
|
Using.resource(Git.open(getRepositoryDir(owner, name))) { git =>
|
||||||
git =>
|
|
||||||
val repo = git.getRepository
|
val repo = git.getRepository
|
||||||
Using.resource(new RevWalk(repo)) {
|
Using.resource(new RevWalk(repo)) { revWalk =>
|
||||||
revWalk =>
|
|
||||||
val objectId = repo.resolve(sha)
|
val objectId = repo.resolve(sha)
|
||||||
revWalk.markStart(revWalk.parseCommit(objectId))
|
revWalk.markStart(revWalk.parseCommit(objectId))
|
||||||
if (path.nonEmpty) {
|
if (path.nonEmpty) {
|
||||||
@@ -80,8 +78,7 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
revfilters(0)
|
revfilters(0)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
JsonFormat(revWalk.asScala.map {
|
JsonFormat(revWalk.asScala.map { commit =>
|
||||||
commit =>
|
|
||||||
val commitInfo = new CommitInfo(commit)
|
val commitInfo = new CommitInfo(commit)
|
||||||
ApiCommits(
|
ApiCommits(
|
||||||
repositoryName = RepositoryName(repository),
|
repositoryName = RepositoryName(repository),
|
||||||
@@ -105,8 +102,7 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
val name = repository.name
|
val name = repository.name
|
||||||
val sha = params("sha")
|
val sha = params("sha")
|
||||||
|
|
||||||
Using.resource(Git.open(getRepositoryDir(owner, name))) {
|
Using.resource(Git.open(getRepositoryDir(owner, name))) { git =>
|
||||||
git =>
|
|
||||||
val repo = git.getRepository
|
val repo = git.getRepository
|
||||||
val objectId = repo.resolve(sha)
|
val objectId = repo.resolve(sha)
|
||||||
val commitInfo = Using.resource(new RevWalk(repo)) { revWalk =>
|
val commitInfo = Using.resource(new RevWalk(repo)) { revWalk =>
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
* https://docs.github.com/en/rest/reference/repos#get-a-repository-readme
|
* https://docs.github.com/en/rest/reference/repos#get-a-repository-readme
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/readme")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/readme")(referrersOnly { repository =>
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) {
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
git =>
|
|
||||||
val refStr = params.getOrElse("ref", repository.repository.defaultBranch)
|
val refStr = params.getOrElse("ref", repository.repository.defaultBranch)
|
||||||
val files = getFileList(git, refStr, ".", maxFiles = context.settings.repositoryViewer.maxFiles)
|
val files = getFileList(git, refStr, ".", maxFiles = context.settings.repositoryViewer.maxFiles)
|
||||||
files // files should be sorted alphabetically.
|
files // files should be sorted alphabetically.
|
||||||
@@ -134,8 +133,7 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
* requested #2112
|
* requested #2112
|
||||||
*/
|
*/
|
||||||
put("/api/v3/repos/:owner/:repository/contents/*")(writableUsersOnly { repository =>
|
put("/api/v3/repos/:owner/:repository/contents/*")(writableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
context.withLoginAccount { loginAccount =>
|
||||||
loginAccount =>
|
|
||||||
JsonFormat(for {
|
JsonFormat(for {
|
||||||
data <- extractFromJsonBody[CreateAFile]
|
data <- extractFromJsonBody[CreateAFile]
|
||||||
} yield {
|
} yield {
|
||||||
@@ -146,8 +144,7 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
val paths = multiParams("splat").head.split("/")
|
val paths = multiParams("splat").head.split("/")
|
||||||
val path = paths.take(paths.size - 1).toList.mkString("/")
|
val path = paths.take(paths.size - 1).toList.mkString("/")
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) {
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
git =>
|
|
||||||
val fileInfo = getFileInfo(git, commit, path, false)
|
val fileInfo = getFileInfo(git, commit, path, false)
|
||||||
|
|
||||||
fileInfo match {
|
fileInfo match {
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ trait ApiRepositoryStatusControllerBase extends ControllerBase {
|
|||||||
ref <- params.get("ref")
|
ref <- params.get("ref")
|
||||||
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
||||||
} yield {
|
} yield {
|
||||||
JsonFormat(getCommitStatusesWithCreator(repository.owner, repository.name, sha).map {
|
JsonFormat(getCommitStatusesWithCreator(repository.owner, repository.name, sha).map { case (status, creator) =>
|
||||||
case (status, creator) =>
|
|
||||||
ApiCommitStatus(status, ApiUser(creator))
|
ApiCommitStatus(status, ApiUser(creator))
|
||||||
})
|
})
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ case class CustomField(
|
|||||||
)
|
)
|
||||||
|
|
||||||
trait CustomFieldBehavior {
|
trait CustomFieldBehavior {
|
||||||
def createHtml(repository: RepositoryInfo, fieldId: Int, fieldName: String, constraints: Option[String])(
|
def createHtml(repository: RepositoryInfo, fieldId: Int, fieldName: String, constraints: Option[String])(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): String
|
): String
|
||||||
def fieldHtml(
|
def fieldHtml(
|
||||||
repository: RepositoryInfo,
|
repository: RepositoryInfo,
|
||||||
@@ -51,8 +51,8 @@ trait CustomFieldBehavior {
|
|||||||
constraints: Option[String],
|
constraints: Option[String],
|
||||||
value: String,
|
value: String,
|
||||||
editable: Boolean
|
editable: Boolean
|
||||||
)(
|
)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): String
|
): String
|
||||||
def validate(name: String, constraints: Option[String], value: String, messages: Messages): Option[String]
|
def validate(name: String, constraints: Option[String], value: String, messages: Messages): Option[String]
|
||||||
}
|
}
|
||||||
@@ -181,10 +181,8 @@ object CustomFieldBehavior {
|
|||||||
s"""<li><a href="javascript:void(0);" class="custom-field-option-$fieldId" data-value=""><i class="octicon octicon-x"></i> Clear ${StringUtil
|
s"""<li><a href="javascript:void(0);" class="custom-field-option-$fieldId" data-value=""><i class="octicon octicon-x"></i> Clear ${StringUtil
|
||||||
.escapeHtml(fieldName)}</a></li>"""
|
.escapeHtml(fieldName)}</a></li>"""
|
||||||
)
|
)
|
||||||
constraints.foreach {
|
constraints.foreach { x =>
|
||||||
x =>
|
x.split(",").map(_.trim).foreach { item =>
|
||||||
x.split(",").map(_.trim).foreach {
|
|
||||||
item =>
|
|
||||||
options.append(s"""<li>
|
options.append(s"""<li>
|
||||||
| <a href="javascript:void(0);" class="custom-field-option-$fieldId" data-value="${StringUtil
|
| <a href="javascript:void(0);" class="custom-field-option-$fieldId" data-value="${StringUtil
|
||||||
.escapeHtml(item)}">
|
.escapeHtml(item)}">
|
||||||
@@ -296,8 +294,8 @@ object CustomFieldBehavior {
|
|||||||
constraints: Option[String],
|
constraints: Option[String],
|
||||||
value: String,
|
value: String,
|
||||||
editable: Boolean
|
editable: Boolean
|
||||||
)(
|
)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): String = {
|
): String = {
|
||||||
val sb = new StringBuilder
|
val sb = new StringBuilder
|
||||||
if (value.nonEmpty) {
|
if (value.nonEmpty) {
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
safeMode
|
safeMode
|
||||||
)
|
)
|
||||||
).shaped.<>(
|
).shaped.<>(
|
||||||
{
|
{ case (repository, options) =>
|
||||||
case (repository, options) =>
|
|
||||||
Repository(
|
Repository(
|
||||||
repository._1,
|
repository._1,
|
||||||
repository._2,
|
repository._2,
|
||||||
@@ -70,7 +69,8 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
repository._12,
|
repository._12,
|
||||||
RepositoryOptions.tupled.apply(options)
|
RepositoryOptions.tupled.apply(options)
|
||||||
)
|
)
|
||||||
}, { (r: Repository) =>
|
},
|
||||||
|
{ (r: Repository) =>
|
||||||
Some(
|
Some(
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ trait GitRepositoryFilter {
|
|||||||
* @param session the database session
|
* @param session the database session
|
||||||
* @return true if allow accessing to repository, otherwise false.
|
* @return true if allow accessing to repository, otherwise false.
|
||||||
*/
|
*/
|
||||||
def filter(path: String, userName: Option[String], settings: SystemSettings, isUpdating: Boolean)(
|
def filter(path: String, userName: Option[String], settings: SystemSettings, isUpdating: Boolean)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): Boolean
|
): Boolean
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ import profile.api._
|
|||||||
trait IssueHook {
|
trait IssueHook {
|
||||||
|
|
||||||
def created(issue: Issue, repository: RepositoryInfo)(implicit session: Session, context: Context): Unit = ()
|
def created(issue: Issue, repository: RepositoryInfo)(implicit session: Session, context: Context): Unit = ()
|
||||||
def addedComment(commentId: Int, content: String, issue: Issue, repository: RepositoryInfo)(
|
def addedComment(commentId: Int, content: String, issue: Issue, repository: RepositoryInfo)(implicit
|
||||||
implicit session: Session,
|
session: Session,
|
||||||
context: Context
|
context: Context
|
||||||
): Unit = ()
|
): Unit = ()
|
||||||
def deletedComment(commentId: Int, issue: Issue, repository: RepositoryInfo)(
|
def deletedComment(commentId: Int, issue: Issue, repository: RepositoryInfo)(implicit
|
||||||
implicit session: Session,
|
session: Session,
|
||||||
context: Context
|
context: Context
|
||||||
): Unit = ()
|
): Unit = ()
|
||||||
def updatedComment(commentId: Int, content: String, issue: Issue, repository: RepositoryInfo)(
|
def updatedComment(commentId: Int, content: String, issue: Issue, repository: RepositoryInfo)(implicit
|
||||||
implicit session: Session,
|
session: Session,
|
||||||
context: Context
|
context: Context
|
||||||
): Unit = ()
|
): Unit = ()
|
||||||
def closed(issue: Issue, repository: RepositoryInfo)(implicit session: Session, context: Context): Unit = ()
|
def closed(issue: Issue, repository: RepositoryInfo)(implicit session: Session, context: Context): Unit = ()
|
||||||
@@ -29,12 +29,12 @@ trait IssueHook {
|
|||||||
assigner: Option[String],
|
assigner: Option[String],
|
||||||
assigned: Option[String],
|
assigned: Option[String],
|
||||||
oldAssigned: Option[String]
|
oldAssigned: Option[String]
|
||||||
)(
|
)(implicit
|
||||||
implicit session: Session,
|
session: Session,
|
||||||
context: Context
|
context: Context
|
||||||
): Unit = ()
|
): Unit = ()
|
||||||
def closedByCommitComment(issue: Issue, repository: RepositoryInfo, message: String, pusher: Account)(
|
def closedByCommitComment(issue: Issue, repository: RepositoryInfo, message: String, pusher: Account)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): Unit = ()
|
): Unit = ()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -340,24 +340,19 @@ abstract class Plugin {
|
|||||||
* Register plugin functionality to PluginRegistry.
|
* Register plugin functionality to PluginRegistry.
|
||||||
*/
|
*/
|
||||||
def initialize(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Unit = {
|
def initialize(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Unit = {
|
||||||
(images ++ images(registry, context, settings)).foreach {
|
(images ++ images(registry, context, settings)).foreach { case (id, in) =>
|
||||||
case (id, in) =>
|
|
||||||
registry.addImage(id, in)
|
registry.addImage(id, in)
|
||||||
}
|
}
|
||||||
(controllers ++ controllers(registry, context, settings)).foreach {
|
(controllers ++ controllers(registry, context, settings)).foreach { case (path, controller) =>
|
||||||
case (path, controller) =>
|
|
||||||
registry.addController(path, controller)
|
registry.addController(path, controller)
|
||||||
}
|
}
|
||||||
(anonymousAccessiblePaths ++ anonymousAccessiblePaths(registry, context, settings)).foreach {
|
(anonymousAccessiblePaths ++ anonymousAccessiblePaths(registry, context, settings)).foreach { case (path) =>
|
||||||
case (path) =>
|
|
||||||
registry.addAnonymousAccessiblePath(path)
|
registry.addAnonymousAccessiblePath(path)
|
||||||
}
|
}
|
||||||
(javaScripts ++ javaScripts(registry, context, settings)).foreach {
|
(javaScripts ++ javaScripts(registry, context, settings)).foreach { case (path, script) =>
|
||||||
case (path, script) =>
|
|
||||||
registry.addJavaScript(path, script)
|
registry.addJavaScript(path, script)
|
||||||
}
|
}
|
||||||
(renderers ++ renderers(registry, context, settings)).foreach {
|
(renderers ++ renderers(registry, context, settings)).foreach { case (extension, renderer) =>
|
||||||
case (extension, renderer) =>
|
|
||||||
registry.addRenderer(extension, renderer)
|
registry.addRenderer(extension, renderer)
|
||||||
}
|
}
|
||||||
(repositoryRoutings ++ repositoryRoutings(registry, context, settings)).foreach { routing =>
|
(repositoryRoutings ++ repositoryRoutings(registry, context, settings)).foreach { routing =>
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ trait ReceiveHook {
|
|||||||
command: ReceiveCommand,
|
command: ReceiveCommand,
|
||||||
pusher: String,
|
pusher: String,
|
||||||
mergePullRequest: Boolean
|
mergePullRequest: Boolean
|
||||||
)(
|
)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): Option[String] = None
|
): Option[String] = None
|
||||||
|
|
||||||
def postReceive(
|
def postReceive(
|
||||||
@@ -24,8 +24,8 @@ trait ReceiveHook {
|
|||||||
command: ReceiveCommand,
|
command: ReceiveCommand,
|
||||||
pusher: String,
|
pusher: String,
|
||||||
mergePullRequest: Boolean
|
mergePullRequest: Boolean
|
||||||
)(
|
)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): Unit = ()
|
): Unit = ()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ trait AccessTokenService {
|
|||||||
def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] =
|
def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] =
|
||||||
Accounts
|
Accounts
|
||||||
.join(AccessTokens)
|
.join(AccessTokens)
|
||||||
.filter {
|
.filter { case (ac, t) =>
|
||||||
case (ac, t) =>
|
|
||||||
(ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind)
|
(ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind)
|
||||||
}
|
}
|
||||||
.map { case (ac, t) => ac }
|
.map { case (ac, t) => ac }
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ trait AccountFederationService {
|
|||||||
* @param preferredUserName Username
|
* @param preferredUserName Username
|
||||||
* @return Available username
|
* @return Available username
|
||||||
*/
|
*/
|
||||||
def findAvailableUserName(preferredUserName: Option[String], mailAddress: String)(
|
def findAvailableUserName(preferredUserName: Option[String], mailAddress: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[String] = {
|
): Option[String] = {
|
||||||
preferredUserName
|
preferredUserName
|
||||||
.flatMap(n => extractSafeStringForUserName(n))
|
.flatMap(n => extractSafeStringForUserName(n))
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ trait AccountService {
|
|||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(classOf[AccountService])
|
private val logger = LoggerFactory.getLogger(classOf[AccountService])
|
||||||
|
|
||||||
def authenticate(settings: SystemSettings, userName: String, password: String)(
|
def authenticate(settings: SystemSettings, userName: String, password: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[Account] = {
|
): Option[Account] = {
|
||||||
val account = if (password.isEmpty) {
|
val account = if (password.isEmpty) {
|
||||||
None
|
None
|
||||||
@@ -58,8 +58,8 @@ trait AccountService {
|
|||||||
/**
|
/**
|
||||||
* Authenticate by LDAP.
|
* Authenticate by LDAP.
|
||||||
*/
|
*/
|
||||||
private def ldapAuthentication(settings: SystemSettings, userName: String, password: String)(
|
private def ldapAuthentication(settings: SystemSettings, userName: String, password: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[Account] = {
|
): Option[Account] = {
|
||||||
LDAPUtil.authenticate(settings.ldap.get, userName, password) match {
|
LDAPUtil.authenticate(settings.ldap.get, userName, password) match {
|
||||||
case Right(ldapUserInfo) => {
|
case Right(ldapUserInfo) => {
|
||||||
@@ -112,15 +112,15 @@ trait AccountService {
|
|||||||
def getAccountByUserName(userName: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
|
def getAccountByUserName(userName: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
|
||||||
Accounts filter (t => (t.userName === userName.bind).&&(t.removed === false.bind, !includeRemoved)) firstOption
|
Accounts filter (t => (t.userName === userName.bind).&&(t.removed === false.bind, !includeRemoved)) firstOption
|
||||||
|
|
||||||
def getAccountByUserNameIgnoreCase(userName: String, includeRemoved: Boolean = false)(
|
def getAccountByUserNameIgnoreCase(userName: String, includeRemoved: Boolean = false)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[Account] =
|
): Option[Account] =
|
||||||
Accounts filter (
|
Accounts filter (t =>
|
||||||
t => (t.userName.toLowerCase === userName.toLowerCase.bind).&&(t.removed === false.bind, !includeRemoved)
|
(t.userName.toLowerCase === userName.toLowerCase.bind).&&(t.removed === false.bind, !includeRemoved)
|
||||||
) firstOption
|
) firstOption
|
||||||
|
|
||||||
def getAccountsByUserNames(userNames: Set[String], knowns: Set[Account], includeRemoved: Boolean = false)(
|
def getAccountsByUserNames(userNames: Set[String], knowns: Set[Account], includeRemoved: Boolean = false)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Map[String, Account] = {
|
): Map[String, Account] = {
|
||||||
val map = knowns.map(a => a.userName -> a).toMap
|
val map = knowns.map(a => a.userName -> a).toMap
|
||||||
val needs = userNames -- map.keySet
|
val needs = userNames -- map.keySet
|
||||||
@@ -135,17 +135,15 @@ trait AccountService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getAccountByMailAddress(mailAddress: String, includeRemoved: Boolean = false)(
|
def getAccountByMailAddress(mailAddress: String, includeRemoved: Boolean = false)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[Account] =
|
): Option[Account] =
|
||||||
(Accounts joinLeft AccountExtraMailAddresses on { case (a, e) => a.userName === e.userName })
|
(Accounts joinLeft AccountExtraMailAddresses on { case (a, e) => a.userName === e.userName })
|
||||||
.filter {
|
.filter { case (a, x) =>
|
||||||
case (a, x) =>
|
|
||||||
((a.mailAddress.toLowerCase === mailAddress.toLowerCase.bind) ||
|
((a.mailAddress.toLowerCase === mailAddress.toLowerCase.bind) ||
|
||||||
(x.map { e =>
|
(x.map { e =>
|
||||||
e.extraMailAddress.toLowerCase === mailAddress.toLowerCase.bind
|
e.extraMailAddress.toLowerCase === mailAddress.toLowerCase.bind
|
||||||
}
|
}.getOrElse(false.bind))).&&(a.removed === false.bind, !includeRemoved)
|
||||||
.getOrElse(false.bind))).&&(a.removed === false.bind, !includeRemoved)
|
|
||||||
}
|
}
|
||||||
.map { case (a, e) => a } firstOption
|
.map { case (a, e) => a } firstOption
|
||||||
|
|
||||||
@@ -267,8 +265,8 @@ trait AccountService {
|
|||||||
group
|
group
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateGroup(groupName: String, description: Option[String], url: Option[String], removed: Boolean)(
|
def updateGroup(groupName: String, description: Option[String], url: Option[String], removed: Boolean)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit =
|
): Unit =
|
||||||
Accounts
|
Accounts
|
||||||
.filter(_.userName === groupName.bind)
|
.filter(_.userName === groupName.bind)
|
||||||
@@ -277,8 +275,7 @@ trait AccountService {
|
|||||||
|
|
||||||
def updateGroupMembers(groupName: String, members: List[(String, Boolean)])(implicit s: Session): Unit = {
|
def updateGroupMembers(groupName: String, members: List[(String, Boolean)])(implicit s: Session): Unit = {
|
||||||
GroupMembers.filter(_.groupName === groupName.bind).delete
|
GroupMembers.filter(_.groupName === groupName.bind).delete
|
||||||
members.foreach {
|
members.foreach { case (userName, isManager) =>
|
||||||
case (userName, isManager) =>
|
|
||||||
GroupMembers insert GroupMember(groupName, userName, isManager)
|
GroupMembers insert GroupMember(groupName, userName, isManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,8 +315,8 @@ trait AccountService {
|
|||||||
/*
|
/*
|
||||||
* For account preference
|
* For account preference
|
||||||
*/
|
*/
|
||||||
def getAccountPreference(userName: String)(
|
def getAccountPreference(userName: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[AccountPreference] = {
|
): Option[AccountPreference] = {
|
||||||
AccountPreferences filter (_.byPrimaryKey(userName)) firstOption
|
AccountPreferences filter (_.byPrimaryKey(userName)) firstOption
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ trait ActivityService {
|
|||||||
|
|
||||||
def getRecentActivitiesByRepos(repos: Set[(String, String)])(implicit context: Context): List[Activity] = {
|
def getRecentActivitiesByRepos(repos: Set[(String, String)])(implicit context: Context): List[Activity] = {
|
||||||
getActivities(includePublic = true) { activity =>
|
getActivities(includePublic = true) { activity =>
|
||||||
repos.exists {
|
repos.exists { case (userName, repositoryName) =>
|
||||||
case (userName, repositoryName) =>
|
|
||||||
activity.userName == userName && activity.repositoryName == repositoryName
|
activity.userName == userName && activity.repositoryName == repositoryName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,10 +64,12 @@ trait ActivityService {
|
|||||||
.get()
|
.get()
|
||||||
) { reader =>
|
) { reader =>
|
||||||
var json: String = null
|
var json: String = null
|
||||||
while (list.length < 50 && {
|
while (
|
||||||
|
list.length < 50 && {
|
||||||
json = reader.readLine();
|
json = reader.readLine();
|
||||||
json
|
json
|
||||||
} != null) {
|
} != null
|
||||||
|
) {
|
||||||
val activity = read[Activity](json)
|
val activity = read[Activity](json)
|
||||||
if (filter(activity)) {
|
if (filter(activity)) {
|
||||||
list += activity
|
list += activity
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ trait CommitStatusService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getCommitStatusWithSummary(userName: String, repositoryName: String, sha: String)(
|
def getCommitStatusWithSummary(userName: String, repositoryName: String, sha: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[(CommitState, List[CommitStatus])] = {
|
): Option[(CommitState, List[CommitStatus])] = {
|
||||||
val statuses = getCommitStatuses(userName, repositoryName, sha)
|
val statuses = getCommitStatuses(userName, repositoryName, sha)
|
||||||
if (statuses.isEmpty) {
|
if (statuses.isEmpty) {
|
||||||
@@ -62,18 +62,18 @@ trait CommitStatusService {
|
|||||||
def getCommitStatus(userName: String, repositoryName: String, id: Int)(implicit s: Session): Option[CommitStatus] =
|
def getCommitStatus(userName: String, repositoryName: String, id: Int)(implicit s: Session): Option[CommitStatus] =
|
||||||
CommitStatuses.filter(t => t.byPrimaryKey(id) && t.byRepository(userName, repositoryName)).firstOption
|
CommitStatuses.filter(t => t.byPrimaryKey(id) && t.byRepository(userName, repositoryName)).firstOption
|
||||||
|
|
||||||
def getCommitStatus(userName: String, repositoryName: String, sha: String, context: String)(
|
def getCommitStatus(userName: String, repositoryName: String, sha: String, context: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[CommitStatus] =
|
): Option[CommitStatus] =
|
||||||
CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) && t.context === context.bind).firstOption
|
CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) && t.context === context.bind).firstOption
|
||||||
|
|
||||||
def getCommitStatuses(userName: String, repositoryName: String, sha: String)(
|
def getCommitStatuses(userName: String, repositoryName: String, sha: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[CommitStatus] =
|
): List[CommitStatus] =
|
||||||
byCommitStatus(userName, repositoryName, sha).list
|
byCommitStatus(userName, repositoryName, sha).list
|
||||||
|
|
||||||
def getRecentStatusContexts(userName: String, repositoryName: String, time: java.util.Date)(
|
def getRecentStatusContexts(userName: String, repositoryName: String, time: java.util.Date)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[String] =
|
): List[String] =
|
||||||
CommitStatuses
|
CommitStatuses
|
||||||
.filter(t => t.byRepository(userName, repositoryName))
|
.filter(t => t.byRepository(userName, repositoryName))
|
||||||
@@ -82,8 +82,8 @@ trait CommitStatusService {
|
|||||||
.map(_._1)
|
.map(_._1)
|
||||||
.list
|
.list
|
||||||
|
|
||||||
def getCommitStatusesWithCreator(userName: String, repositoryName: String, sha: String)(
|
def getCommitStatusesWithCreator(userName: String, repositoryName: String, sha: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[(CommitStatus, Account)] =
|
): List[(CommitStatus, Account)] =
|
||||||
byCommitStatus(userName, repositoryName, sha)
|
byCommitStatus(userName, repositoryName, sha)
|
||||||
.join(Accounts)
|
.join(Accounts)
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ import org.apache.commons.io.FileUtils
|
|||||||
trait CommitsService {
|
trait CommitsService {
|
||||||
self: ActivityService with PullRequestService with WebHookPullRequestReviewCommentService =>
|
self: ActivityService with PullRequestService with WebHookPullRequestReviewCommentService =>
|
||||||
|
|
||||||
def getCommitComments(owner: String, repository: String, commitId: String, includePullRequest: Boolean)(
|
def getCommitComments(owner: String, repository: String, commitId: String, includePullRequest: Boolean)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
) =
|
) =
|
||||||
CommitComments filter { t =>
|
CommitComments filter { t =>
|
||||||
t.byCommit(owner, repository, commitId) && (t.issueId.isEmpty || includePullRequest)
|
t.byCommit(owner, repository, commitId) && (t.issueId.isEmpty || includePullRequest)
|
||||||
@@ -79,8 +79,7 @@ trait CommitsService {
|
|||||||
val comment = getCommitComment(repository.owner, repository.name, commentId.toString).get
|
val comment = getCommitComment(repository.owner, repository.name, commentId.toString).get
|
||||||
issueId match {
|
issueId match {
|
||||||
case Some(issueId) =>
|
case Some(issueId) =>
|
||||||
getPullRequest(repository.owner, repository.name, issueId).foreach {
|
getPullRequest(repository.owner, repository.name, issueId).foreach { case (issue, pullRequest) =>
|
||||||
case (issue, pullRequest) =>
|
|
||||||
val pullRequestCommentInfo =
|
val pullRequestCommentInfo =
|
||||||
PullRequestCommentInfo(repository.owner, repository.name, loginAccount.userName, content, issueId)
|
PullRequestCommentInfo(repository.owner, repository.name, loginAccount.userName, content, issueId)
|
||||||
recordActivity(pullRequestCommentInfo)
|
recordActivity(pullRequestCommentInfo)
|
||||||
@@ -104,8 +103,8 @@ trait CommitsService {
|
|||||||
commentId
|
commentId
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateCommitCommentPosition(commentId: Int, commitId: String, oldLine: Option[Int], newLine: Option[Int])(
|
def updateCommitCommentPosition(commentId: Int, commitId: String, oldLine: Option[Int], newLine: Option[Int])(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit =
|
): Unit =
|
||||||
CommitComments
|
CommitComments
|
||||||
.filter(_.byPrimaryKey(commentId))
|
.filter(_.byPrimaryKey(commentId))
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ trait CustomFieldsService {
|
|||||||
def getCustomFields(owner: String, repository: String)(implicit s: Session): List[CustomField] =
|
def getCustomFields(owner: String, repository: String)(implicit s: Session): List[CustomField] =
|
||||||
CustomFields.filter(_.byRepository(owner, repository)).sortBy(_.fieldId asc).list
|
CustomFields.filter(_.byRepository(owner, repository)).sortBy(_.fieldId asc).list
|
||||||
|
|
||||||
def getCustomFieldsWithValue(owner: String, repository: String, issueId: Int)(
|
def getCustomFieldsWithValue(owner: String, repository: String, issueId: Int)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[(CustomField, Option[IssueCustomField])] = {
|
): List[(CustomField, Option[IssueCustomField])] = {
|
||||||
CustomFields
|
CustomFields
|
||||||
.filter(_.byRepository(owner, repository))
|
.filter(_.byRepository(owner, repository))
|
||||||
@@ -52,8 +52,8 @@ trait CustomFieldsService {
|
|||||||
constraints: Option[String],
|
constraints: Option[String],
|
||||||
enableForIssues: Boolean,
|
enableForIssues: Boolean,
|
||||||
enableForPullRequests: Boolean
|
enableForPullRequests: Boolean
|
||||||
)(
|
)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit =
|
): Unit =
|
||||||
CustomFields
|
CustomFields
|
||||||
.filter(_.byPrimaryKey(owner, repository, fieldId))
|
.filter(_.byPrimaryKey(owner, repository, fieldId))
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ trait GpgKeyService {
|
|||||||
|
|
||||||
def addGpgPublicKey(userName: String, title: String, publicKey: String)(implicit s: Session): Unit = {
|
def addGpgPublicKey(userName: String, title: String, publicKey: String)(implicit s: Session): Unit = {
|
||||||
val pubKeyOf = new BcPGPObjectFactory(new ArmoredInputStream(new ByteArrayInputStream(publicKey.getBytes)))
|
val pubKeyOf = new BcPGPObjectFactory(new ArmoredInputStream(new ByteArrayInputStream(publicKey.getBytes)))
|
||||||
pubKeyOf.iterator().asScala.foreach {
|
pubKeyOf.iterator().asScala.foreach { case keyRing: PGPPublicKeyRing =>
|
||||||
case keyRing: PGPPublicKeyRing =>
|
|
||||||
val key = keyRing.getPublicKey()
|
val key = keyRing.getPublicKey()
|
||||||
GpgKeys.insert(GpgKey(userName = userName, gpgKeyId = key.getKeyID, title = title, publicKey = publicKey))
|
GpgKeys.insert(GpgKey(userName = userName, gpgKeyId = key.getKeyID, title = title, publicKey = publicKey))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ trait HandleCommentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def deleteCommentByApi(repoInfo: RepositoryInfo, comment: IssueComment, issue: Issue)(
|
def deleteCommentByApi(repoInfo: RepositoryInfo, comment: IssueComment, issue: Issue)(implicit
|
||||||
implicit context: Context,
|
context: Context,
|
||||||
s: Session
|
s: Session
|
||||||
): Option[IssueComment] = context.loginAccount.flatMap { _ =>
|
): Option[IssueComment] = context.loginAccount.flatMap { _ =>
|
||||||
comment.action match {
|
comment.action match {
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ trait IssuesService {
|
|||||||
IssueComments filter (_.byIssue(owner, repository, issueId)) sortBy (_.commentId asc) list
|
IssueComments filter (_.byIssue(owner, repository, issueId)) sortBy (_.commentId asc) list
|
||||||
|
|
||||||
/** @return IssueComment and commentedUser and Issue */
|
/** @return IssueComment and commentedUser and Issue */
|
||||||
def getCommentsForApi(owner: String, repository: String, issueId: Int)(
|
def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[(IssueComment, Account, Issue)] =
|
): List[(IssueComment, Account, Issue)] =
|
||||||
IssueComments
|
IssueComments
|
||||||
.filter(_.byIssue(owner, repository, issueId))
|
.filter(_.byIssue(owner, repository, issueId))
|
||||||
@@ -54,8 +54,8 @@ trait IssuesService {
|
|||||||
.map { case t1 ~ t2 ~ t3 => (t1, t2, t3) }
|
.map { case t1 ~ t2 ~ t3 => (t1, t2, t3) }
|
||||||
.list
|
.list
|
||||||
|
|
||||||
def getMergedComment(owner: String, repository: String, issueId: Int)(
|
def getMergedComment(owner: String, repository: String, issueId: Int)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[(IssueComment, Account)] = {
|
): Option[(IssueComment, Account)] = {
|
||||||
IssueComments
|
IssueComments
|
||||||
.filter(_.byIssue(owner, repository, issueId))
|
.filter(_.byIssue(owner, repository, issueId))
|
||||||
@@ -74,8 +74,8 @@ trait IssuesService {
|
|||||||
else None
|
else None
|
||||||
}
|
}
|
||||||
|
|
||||||
def getCommentForApi(owner: String, repository: String, commentId: Int)(
|
def getCommentForApi(owner: String, repository: String, commentId: Int)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[(IssueComment, Account, Issue)] =
|
): Option[(IssueComment, Account, Issue)] =
|
||||||
IssueComments
|
IssueComments
|
||||||
.filter(_.byRepository(owner, repository))
|
.filter(_.byRepository(owner, repository))
|
||||||
@@ -91,8 +91,7 @@ trait IssuesService {
|
|||||||
def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session): List[Label] = {
|
def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session): List[Label] = {
|
||||||
IssueLabels
|
IssueLabels
|
||||||
.join(Labels)
|
.join(Labels)
|
||||||
.on {
|
.on { case t1 ~ t2 =>
|
||||||
case t1 ~ t2 =>
|
|
||||||
t1.byLabel(t2.userName, t2.repositoryName, t2.labelId)
|
t1.byLabel(t2.userName, t2.repositoryName, t2.labelId)
|
||||||
}
|
}
|
||||||
.filter { case t1 ~ t2 => t1.byIssue(owner, repository, issueId) }
|
.filter { case t1 ~ t2 => t1.byIssue(owner, repository, issueId) }
|
||||||
@@ -100,8 +99,8 @@ trait IssuesService {
|
|||||||
.list
|
.list
|
||||||
}
|
}
|
||||||
|
|
||||||
def getIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(
|
def getIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[IssueLabel] = {
|
): Option[IssueLabel] = {
|
||||||
IssueLabels filter (_.byPrimaryKey(owner, repository, issueId, labelId)) firstOption
|
IssueLabels filter (_.byPrimaryKey(owner, repository, issueId, labelId)) firstOption
|
||||||
}
|
}
|
||||||
@@ -114,8 +113,8 @@ trait IssuesService {
|
|||||||
* @param repos Tuple of the repository owner and the repository name
|
* @param repos Tuple of the repository owner and the repository name
|
||||||
* @return the count of the search result
|
* @return the count of the search result
|
||||||
*/
|
*/
|
||||||
def countIssue(condition: IssueSearchCondition, searchOption: IssueSearchOption, repos: (String, String)*)(
|
def countIssue(condition: IssueSearchCondition, searchOption: IssueSearchOption, repos: (String, String)*)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
Query(searchIssueQuery(repos, condition, searchOption).length).first
|
Query(searchIssueQuery(repos, condition, searchOption).length).first
|
||||||
}
|
}
|
||||||
@@ -136,21 +135,17 @@ trait IssuesService {
|
|||||||
|
|
||||||
searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), IssueSearchOption.Issues)
|
searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), IssueSearchOption.Issues)
|
||||||
.join(IssueLabels)
|
.join(IssueLabels)
|
||||||
.on {
|
.on { case t1 ~ t2 =>
|
||||||
case t1 ~ t2 =>
|
|
||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.join(Labels)
|
.join(Labels)
|
||||||
.on {
|
.on { case t1 ~ t2 ~ t3 =>
|
||||||
case t1 ~ t2 ~ t3 =>
|
|
||||||
t2.byLabel(t3.userName, t3.repositoryName, t3.labelId)
|
t2.byLabel(t3.userName, t3.repositoryName, t3.labelId)
|
||||||
}
|
}
|
||||||
.groupBy {
|
.groupBy { case t1 ~ t2 ~ t3 =>
|
||||||
case t1 ~ t2 ~ t3 =>
|
|
||||||
t3.labelName
|
t3.labelName
|
||||||
}
|
}
|
||||||
.map {
|
.map { case (labelName, t) =>
|
||||||
case (labelName, t) =>
|
|
||||||
labelName -> t.length
|
labelName -> t.length
|
||||||
}
|
}
|
||||||
.list
|
.list
|
||||||
@@ -173,16 +168,13 @@ trait IssuesService {
|
|||||||
|
|
||||||
searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), IssueSearchOption.Issues)
|
searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), IssueSearchOption.Issues)
|
||||||
.join(Priorities)
|
.join(Priorities)
|
||||||
.on {
|
.on { case t1 ~ t2 =>
|
||||||
case t1 ~ t2 =>
|
|
||||||
t1.byPriority(t2.userName, t2.repositoryName, t2.priorityId)
|
t1.byPriority(t2.userName, t2.repositoryName, t2.priorityId)
|
||||||
}
|
}
|
||||||
.groupBy {
|
.groupBy { case t1 ~ t2 =>
|
||||||
case t1 ~ t2 =>
|
|
||||||
t2.priorityName
|
t2.priorityName
|
||||||
}
|
}
|
||||||
.map {
|
.map { case (priorityName, t) =>
|
||||||
case (priorityName, t) =>
|
|
||||||
priorityName -> t.length
|
priorityName -> t.length
|
||||||
}
|
}
|
||||||
.list
|
.list
|
||||||
@@ -221,8 +213,7 @@ trait IssuesService {
|
|||||||
.joinLeft(IssueAssignees)
|
.joinLeft(IssueAssignees)
|
||||||
.on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 => t1.byIssue(t8.userName, t8.repositoryName, t8.issueId) }
|
.on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 => t1.byIssue(t8.userName, t8.repositoryName, t8.issueId) }
|
||||||
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 => i asc }
|
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 => i asc }
|
||||||
.map {
|
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 =>
|
||||||
case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 =>
|
|
||||||
(
|
(
|
||||||
t1,
|
t1,
|
||||||
t2.commentCount,
|
t2.commentCount,
|
||||||
@@ -264,8 +255,8 @@ trait IssuesService {
|
|||||||
/** for api
|
/** for api
|
||||||
* @return (issue, issueUser, Seq(assigneeUsers))
|
* @return (issue, issueUser, Seq(assigneeUsers))
|
||||||
*/
|
*/
|
||||||
def searchIssueByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*)(
|
def searchIssueByApi(condition: IssueSearchCondition, offset: Int, limit: Int, repos: (String, String)*)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[(Issue, Account, List[Account])] = {
|
): List[(Issue, Account, List[Account])] = {
|
||||||
// get issues and comment count and labels
|
// get issues and comment count and labels
|
||||||
searchIssueQueryBase(condition, IssueSearchOption.Issues, offset, limit, repos)
|
searchIssueQueryBase(condition, IssueSearchOption.Issues, offset, limit, repos)
|
||||||
@@ -278,12 +269,10 @@ trait IssuesService {
|
|||||||
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => i asc }
|
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => i asc }
|
||||||
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => (t1, t3, t5) }
|
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => (t1, t3, t5) }
|
||||||
.list
|
.list
|
||||||
.groupBy {
|
.groupBy { case (issue, account, _) =>
|
||||||
case (issue, account, _) =>
|
|
||||||
(issue, account)
|
(issue, account)
|
||||||
}
|
}
|
||||||
.map {
|
.map { case (_, values) =>
|
||||||
case (_, values) =>
|
|
||||||
(values.head._1, values.head._2, values.flatMap(_._3))
|
(values.head._1, values.head._2, values.flatMap(_._3))
|
||||||
}
|
}
|
||||||
.toList
|
.toList
|
||||||
@@ -312,12 +301,10 @@ trait IssuesService {
|
|||||||
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 => i asc }
|
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 => i asc }
|
||||||
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 => (t1, t5, t2.commentCount, t3, t4, t6, t8) }
|
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 ~ t7 ~ t8 => (t1, t5, t2.commentCount, t3, t4, t6, t8) }
|
||||||
.list
|
.list
|
||||||
.groupBy {
|
.groupBy { case (issue, openedUser, commentCount, pullRequest, repository, account, assignedUser) =>
|
||||||
case (issue, openedUser, commentCount, pullRequest, repository, account, assignedUser) =>
|
|
||||||
(issue, openedUser, commentCount, pullRequest, repository, account)
|
(issue, openedUser, commentCount, pullRequest, repository, account)
|
||||||
}
|
}
|
||||||
.map {
|
.map { case (_, values) =>
|
||||||
case (_, values) =>
|
|
||||||
(
|
(
|
||||||
values.head._1,
|
values.head._1,
|
||||||
values.head._2,
|
values.head._2,
|
||||||
@@ -344,8 +331,7 @@ trait IssuesService {
|
|||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.sortBy { case (t1, t2) => t1.issueId desc }
|
.sortBy { case (t1, t2) => t1.issueId desc }
|
||||||
.sortBy {
|
.sortBy { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
condition.sort match {
|
condition.sort match {
|
||||||
case "created" =>
|
case "created" =>
|
||||||
condition.direction match {
|
condition.direction match {
|
||||||
@@ -380,8 +366,8 @@ trait IssuesService {
|
|||||||
repos: Seq[(String, String)],
|
repos: Seq[(String, String)],
|
||||||
condition: IssueSearchCondition,
|
condition: IssueSearchCondition,
|
||||||
searchOption: IssueSearchOption
|
searchOption: IssueSearchOption
|
||||||
)(
|
)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
) = {
|
) = {
|
||||||
val query = Issues filter { t1 =>
|
val query = Issues filter { t1 =>
|
||||||
(if (repos.sizeIs == 1) {
|
(if (repos.sizeIs == 1) {
|
||||||
@@ -451,17 +437,24 @@ trait IssuesService {
|
|||||||
// Mentioned filter
|
// Mentioned filter
|
||||||
.&&(
|
.&&(
|
||||||
(t1.openedUserName === condition.mentioned.get.bind) || (IssueAssignees filter { t1 =>
|
(t1.openedUserName === condition.mentioned.get.bind) || (IssueAssignees filter { t1 =>
|
||||||
t1.byIssue(t1.userName, t1.repositoryName, t1.issueId) && t1.assigneeUserName === condition.mentioned.get.bind
|
t1.byIssue(
|
||||||
|
t1.userName,
|
||||||
|
t1.repositoryName,
|
||||||
|
t1.issueId
|
||||||
|
) && t1.assigneeUserName === condition.mentioned.get.bind
|
||||||
} exists) ||
|
} exists) ||
|
||||||
(IssueComments filter { t2 =>
|
(IssueComments filter { t2 =>
|
||||||
(t2.byIssue(t1.userName, t1.repositoryName, t1.issueId)) && (t2.commentedUserName === condition.mentioned.get.bind)
|
(t2.byIssue(
|
||||||
|
t1.userName,
|
||||||
|
t1.repositoryName,
|
||||||
|
t1.issueId
|
||||||
|
)) && (t2.commentedUserName === condition.mentioned.get.bind)
|
||||||
} exists),
|
} exists),
|
||||||
condition.mentioned.isDefined
|
condition.mentioned.isDefined
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
condition.others.foldLeft(query) {
|
condition.others.foldLeft(query) { case (query, cond) =>
|
||||||
case (query, cond) =>
|
|
||||||
def condQuery(f: Rep[String] => Rep[Boolean]): Query[Profile.Issues, Issue, Seq] = {
|
def condQuery(f: Rep[String] => Rep[Boolean]): Query[Profile.Issues, Issue, Seq] = {
|
||||||
query.filter { t1 =>
|
query.filter { t1 =>
|
||||||
IssueCustomFields
|
IssueCustomFields
|
||||||
@@ -469,8 +462,7 @@ trait IssuesService {
|
|||||||
.on { (t2, t3) =>
|
.on { (t2, t3) =>
|
||||||
t2.userName === t3.userName && t2.repositoryName === t3.repositoryName && t2.fieldId === t3.fieldId
|
t2.userName === t3.userName && t2.repositoryName === t3.repositoryName && t2.fieldId === t3.fieldId
|
||||||
}
|
}
|
||||||
.filter {
|
.filter { case (t2, t3) =>
|
||||||
case (t2, t3) =>
|
|
||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) && t3.fieldName === cond.name.bind && f(
|
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) && t3.fieldName === cond.name.bind && f(
|
||||||
t2.value
|
t2.value
|
||||||
)
|
)
|
||||||
@@ -527,7 +519,8 @@ trait IssuesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int, insertComment: Boolean = false)(
|
def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int, insertComment: Boolean = false)(
|
||||||
implicit context: Context,
|
implicit
|
||||||
|
context: Context,
|
||||||
s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
if (insertComment) {
|
if (insertComment) {
|
||||||
@@ -546,7 +539,8 @@ trait IssuesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def deleteIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int, insertComment: Boolean = false)(
|
def deleteIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int, insertComment: Boolean = false)(
|
||||||
implicit context: Context,
|
implicit
|
||||||
|
context: Context,
|
||||||
s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
if (insertComment) {
|
if (insertComment) {
|
||||||
@@ -564,8 +558,8 @@ trait IssuesService {
|
|||||||
IssueLabels filter (_.byPrimaryKey(owner, repository, issueId, labelId)) delete
|
IssueLabels filter (_.byPrimaryKey(owner, repository, issueId, labelId)) delete
|
||||||
}
|
}
|
||||||
|
|
||||||
def deleteAllIssueLabels(owner: String, repository: String, issueId: Int, insertComment: Boolean = false)(
|
def deleteAllIssueLabels(owner: String, repository: String, issueId: Int, insertComment: Boolean = false)(implicit
|
||||||
implicit context: Context,
|
context: Context,
|
||||||
s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
if (insertComment) {
|
if (insertComment) {
|
||||||
@@ -604,8 +598,8 @@ trait IssuesService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateIssue(owner: String, repository: String, issueId: Int, title: String, content: Option[String])(
|
def updateIssue(owner: String, repository: String, issueId: Int, title: String, content: Option[String])(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
Issues
|
Issues
|
||||||
.filter(_.byPrimaryKey(owner, repository, issueId))
|
.filter(_.byPrimaryKey(owner, repository, issueId))
|
||||||
@@ -624,8 +618,8 @@ trait IssuesService {
|
|||||||
.update(true)
|
.update(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getIssueAssignees(owner: String, repository: String, issueId: Int)(
|
def getIssueAssignees(owner: String, repository: String, issueId: Int)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[IssueAssignee] = {
|
): List[IssueAssignee] = {
|
||||||
IssueAssignees.filter(_.byIssue(owner, repository, issueId)).sortBy(_.assigneeUserName).list
|
IssueAssignees.filter(_.byIssue(owner, repository, issueId)).sortBy(_.assigneeUserName).list
|
||||||
}
|
}
|
||||||
@@ -636,8 +630,8 @@ trait IssuesService {
|
|||||||
issueId: Int,
|
issueId: Int,
|
||||||
assigneeUserName: String,
|
assigneeUserName: String,
|
||||||
insertComment: Boolean = false
|
insertComment: Boolean = false
|
||||||
)(
|
)(implicit
|
||||||
implicit context: Context,
|
context: Context,
|
||||||
s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
val assigner = context.loginAccount.map(_.userName)
|
val assigner = context.loginAccount.map(_.userName)
|
||||||
@@ -665,8 +659,8 @@ trait IssuesService {
|
|||||||
issueId: Int,
|
issueId: Int,
|
||||||
assigneeUserName: String,
|
assigneeUserName: String,
|
||||||
insertComment: Boolean = false
|
insertComment: Boolean = false
|
||||||
)(
|
)(implicit
|
||||||
implicit context: Context,
|
context: Context,
|
||||||
s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
val assigner = context.loginAccount.map(_.userName)
|
val assigner = context.loginAccount.map(_.userName)
|
||||||
@@ -688,8 +682,8 @@ trait IssuesService {
|
|||||||
IssueAssignees filter (_.byPrimaryKey(owner, repository, issueId, assigneeUserName)) delete
|
IssueAssignees filter (_.byPrimaryKey(owner, repository, issueId, assigneeUserName)) delete
|
||||||
}
|
}
|
||||||
|
|
||||||
def deleteAllIssueAssignees(owner: String, repository: String, issueId: Int, insertComment: Boolean = false)(
|
def deleteAllIssueAssignees(owner: String, repository: String, issueId: Int, insertComment: Boolean = false)(implicit
|
||||||
implicit context: Context,
|
context: Context,
|
||||||
s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
val assigner = context.loginAccount.map(_.userName)
|
val assigner = context.loginAccount.map(_.userName)
|
||||||
@@ -773,15 +767,15 @@ trait IssuesService {
|
|||||||
.update(priorityId, currentDate)
|
.update(priorityId, currentDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateComment(owner: String, repository: String, issueId: Int, commentId: Int, content: String)(
|
def updateComment(owner: String, repository: String, issueId: Int, commentId: Int, content: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
Issues.filter(_.byPrimaryKey(owner, repository, issueId)).map(_.updatedDate).update(currentDate)
|
Issues.filter(_.byPrimaryKey(owner, repository, issueId)).map(_.updatedDate).update(currentDate)
|
||||||
IssueComments.filter(_.byPrimaryKey(commentId)).map(t => (t.content, t.updatedDate)).update(content, currentDate)
|
IssueComments.filter(_.byPrimaryKey(commentId)).map(t => (t.content, t.updatedDate)).update(content, currentDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
def deleteComment(owner: String, repository: String, issueId: Int, commentId: Int)(
|
def deleteComment(owner: String, repository: String, issueId: Int, commentId: Int)(implicit
|
||||||
implicit context: Context,
|
context: Context,
|
||||||
s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
Issues.filter(_.byPrimaryKey(owner, repository, issueId)).map(_.updatedDate).update(currentDate)
|
Issues.filter(_.byPrimaryKey(owner, repository, issueId)).map(_.updatedDate).update(currentDate)
|
||||||
@@ -820,8 +814,8 @@ trait IssuesService {
|
|||||||
* @param query the keywords separated by whitespace.
|
* @param query the keywords separated by whitespace.
|
||||||
* @return issues with comment count and matched content of issue or comment
|
* @return issues with comment count and matched content of issue or comment
|
||||||
*/
|
*/
|
||||||
def searchIssuesByKeyword(owner: String, repository: String, query: String, pullRequest: Boolean)(
|
def searchIssuesByKeyword(owner: String, repository: String, query: String, pullRequest: Boolean)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[(Issue, Int, String)] = {
|
): List[(Issue, Int, String)] = {
|
||||||
// import slick.driver.JdbcDriver.likeEncode
|
// import slick.driver.JdbcDriver.likeEncode
|
||||||
val keywords = splitWords(query.toLowerCase)
|
val keywords = splitWords(query.toLowerCase)
|
||||||
@@ -832,12 +826,10 @@ trait IssuesService {
|
|||||||
t.byRepository(owner, repository) && t.pullRequest === pullRequest.bind
|
t.byRepository(owner, repository) && t.pullRequest === pullRequest.bind
|
||||||
}
|
}
|
||||||
.join(IssueOutline)
|
.join(IssueOutline)
|
||||||
.on {
|
.on { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.filter {
|
.filter { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
keywords
|
keywords
|
||||||
.map { keyword =>
|
.map { keyword =>
|
||||||
(t1.title.toLowerCase.like(s"%${likeEncode(keyword)}%", '^')) ||
|
(t1.title.toLowerCase.like(s"%${likeEncode(keyword)}%", '^')) ||
|
||||||
@@ -845,8 +837,7 @@ trait IssuesService {
|
|||||||
}
|
}
|
||||||
.reduceLeft(_ && _)
|
.reduceLeft(_ && _)
|
||||||
}
|
}
|
||||||
.map {
|
.map { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
(t1, 0, t1.content.?, t2.commentCount)
|
(t1, 0, t1.content.?, t2.commentCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -854,17 +845,14 @@ trait IssuesService {
|
|||||||
val comments = IssueComments
|
val comments = IssueComments
|
||||||
.filter(_.byRepository(owner, repository))
|
.filter(_.byRepository(owner, repository))
|
||||||
.join(Issues)
|
.join(Issues)
|
||||||
.on {
|
.on { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.join(IssueOutline)
|
.join(IssueOutline)
|
||||||
.on {
|
.on { case ((t1, t2), t3) =>
|
||||||
case ((t1, t2), t3) =>
|
|
||||||
t2.byIssue(t3.userName, t3.repositoryName, t3.issueId)
|
t2.byIssue(t3.userName, t3.repositoryName, t3.issueId)
|
||||||
}
|
}
|
||||||
.filter {
|
.filter { case ((t1, t2), t3) =>
|
||||||
case ((t1, t2), t3) =>
|
|
||||||
t2.pullRequest === pullRequest.bind &&
|
t2.pullRequest === pullRequest.bind &&
|
||||||
keywords
|
keywords
|
||||||
.map { query =>
|
.map { query =>
|
||||||
@@ -872,20 +860,17 @@ trait IssuesService {
|
|||||||
}
|
}
|
||||||
.reduceLeft(_ && _)
|
.reduceLeft(_ && _)
|
||||||
}
|
}
|
||||||
.map {
|
.map { case ((t1, t2), t3) =>
|
||||||
case ((t1, t2), t3) =>
|
|
||||||
(t2, t1.commentId, t1.content.?, t3.commentCount)
|
(t2, t1.commentId, t1.content.?, t3.commentCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
issues
|
issues
|
||||||
.union(comments)
|
.union(comments)
|
||||||
.sortBy {
|
.sortBy { case (issue, commentId, _, _) =>
|
||||||
case (issue, commentId, _, _) =>
|
|
||||||
issue.issueId.desc -> commentId
|
issue.issueId.desc -> commentId
|
||||||
}
|
}
|
||||||
.list
|
.list
|
||||||
.splitWith {
|
.splitWith { case ((issue1, _, _, _), (issue2, _, _, _)) =>
|
||||||
case ((issue1, _, _, _), (issue2, _, _, _)) =>
|
|
||||||
issue1.issueId == issue2.issueId
|
issue1.issueId == issue2.issueId
|
||||||
}
|
}
|
||||||
.map {
|
.map {
|
||||||
@@ -896,8 +881,8 @@ trait IssuesService {
|
|||||||
.toList
|
.toList
|
||||||
}
|
}
|
||||||
|
|
||||||
def closeIssuesFromMessage(message: String, userName: String, owner: String, repository: String)(
|
def closeIssuesFromMessage(message: String, userName: String, owner: String, repository: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Seq[Int] = {
|
): Seq[Int] = {
|
||||||
extractCloseId(message).flatMap { issueId =>
|
extractCloseId(message).flatMap { issueId =>
|
||||||
for (issue <- getIssue(owner, repository, issueId) if !issue.closed) yield {
|
for (issue <- getIssue(owner, repository, issueId) if !issue.closed) yield {
|
||||||
@@ -911,8 +896,7 @@ trait IssuesService {
|
|||||||
def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String, loginAccount: Account)(
|
def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String, loginAccount: Account)(
|
||||||
implicit s: Session
|
implicit s: Session
|
||||||
): Unit = {
|
): Unit = {
|
||||||
extractGlobalIssueId(message).foreach {
|
extractGlobalIssueId(message).foreach { case (_referredOwner, _referredRepository, referredIssueId) =>
|
||||||
case (_referredOwner, _referredRepository, referredIssueId) =>
|
|
||||||
val referredOwner = _referredOwner.getOrElse(owner)
|
val referredOwner = _referredOwner.getOrElse(owner)
|
||||||
val referredRepository = _referredRepository.getOrElse(repository)
|
val referredRepository = _referredRepository.getOrElse(repository)
|
||||||
getRepository(referredOwner, referredRepository).foreach { repo =>
|
getRepository(referredOwner, referredRepository).foreach { repo =>
|
||||||
@@ -923,12 +907,13 @@ trait IssuesService {
|
|||||||
} else {
|
} else {
|
||||||
(s"${fromIssue.issueId}:${owner}:${repository}:${fromIssue.title}", "refer_global")
|
(s"${fromIssue.issueId}:${owner}:${repository}:${fromIssue.title}", "refer_global")
|
||||||
}
|
}
|
||||||
referredIssueId.foreach(
|
referredIssueId.foreach(x =>
|
||||||
x =>
|
|
||||||
// Not add if refer comment already exist.
|
// Not add if refer comment already exist.
|
||||||
if (!getComments(referredOwner, referredRepository, x.toInt).exists { x =>
|
if (
|
||||||
|
!getComments(referredOwner, referredRepository, x.toInt).exists { x =>
|
||||||
(x.action == "refer" || x.action == "refer_global") && x.content == content
|
(x.action == "refer" || x.action == "refer_global") && x.content == content
|
||||||
}) {
|
}
|
||||||
|
) {
|
||||||
createComment(
|
createComment(
|
||||||
referredOwner,
|
referredOwner,
|
||||||
referredRepository,
|
referredRepository,
|
||||||
@@ -1090,8 +1075,7 @@ object IssuesService {
|
|||||||
dim(0) -> dim(1)
|
dim(0) -> dim(1)
|
||||||
}
|
}
|
||||||
.groupBy(_._1)
|
.groupBy(_._1)
|
||||||
.map {
|
.map { case (key, values) =>
|
||||||
case (key, values) =>
|
|
||||||
key -> values.map(_._2).toSeq
|
key -> values.map(_._2).toSeq
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1123,8 +1107,7 @@ object IssuesService {
|
|||||||
val dim = x.split(">")
|
val dim = x.split(">")
|
||||||
dim(0) -> ("gt", dim(1))
|
dim(0) -> ("gt", dim(1))
|
||||||
}
|
}
|
||||||
.map {
|
.map { case (key, (operator, value)) =>
|
||||||
case (key, (operator, value)) =>
|
|
||||||
CustomFieldCondition(key.stripPrefix("custom."), value, operator)
|
CustomFieldCondition(key.stripPrefix("custom."), value, operator)
|
||||||
}
|
}
|
||||||
.toSeq
|
.toSeq
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ trait LabelsService {
|
|||||||
createLabel(owner, repository, labelName, color)
|
createLabel(owner, repository, labelName, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String)(
|
def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit =
|
): Unit =
|
||||||
Labels
|
Labels
|
||||||
.filter(_.byPrimaryKey(owner, repository, labelId))
|
.filter(_.byPrimaryKey(owner, repository, labelId))
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ trait MergeService {
|
|||||||
afterCommitId: ObjectId,
|
afterCommitId: ObjectId,
|
||||||
loginAccount: Account,
|
loginAccount: Account,
|
||||||
settings: SystemSettings
|
settings: SystemSettings
|
||||||
)(
|
)(implicit
|
||||||
implicit s: Session,
|
s: Session,
|
||||||
c: JsonFormat.Context
|
c: JsonFormat.Context
|
||||||
): Unit = {
|
): Unit = {
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.Push, settings) {
|
callWebHookOf(repository.owner, repository.name, WebHook.Push, settings) {
|
||||||
@@ -220,7 +220,14 @@ trait MergeService {
|
|||||||
requestRepositoryName: String,
|
requestRepositoryName: String,
|
||||||
requestBranch: String
|
requestBranch: String
|
||||||
): Option[String] =
|
): Option[String] =
|
||||||
tryMergeRemote(userName, repositoryName, branch, requestUserName, requestRepositoryName, requestBranch).left.toOption
|
tryMergeRemote(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
branch,
|
||||||
|
requestUserName,
|
||||||
|
requestRepositoryName,
|
||||||
|
requestBranch
|
||||||
|
).left.toOption
|
||||||
|
|
||||||
def pullRemote(
|
def pullRemote(
|
||||||
localRepository: RepositoryInfo,
|
localRepository: RepositoryInfo,
|
||||||
@@ -236,8 +243,14 @@ trait MergeService {
|
|||||||
val localRepositoryName = localRepository.name
|
val localRepositoryName = localRepository.name
|
||||||
val remoteUserName = remoteRepository.owner
|
val remoteUserName = remoteRepository.owner
|
||||||
val remoteRepositoryName = remoteRepository.name
|
val remoteRepositoryName = remoteRepository.name
|
||||||
tryMergeRemote(localUserName, localRepositoryName, localBranch, remoteUserName, remoteRepositoryName, remoteBranch).map {
|
tryMergeRemote(
|
||||||
case (newTreeId, oldBaseId, oldHeadId) =>
|
localUserName,
|
||||||
|
localRepositoryName,
|
||||||
|
localBranch,
|
||||||
|
remoteUserName,
|
||||||
|
remoteRepositoryName,
|
||||||
|
remoteBranch
|
||||||
|
).map { case (newTreeId, oldBaseId, oldHeadId) =>
|
||||||
Using.resource(Git.open(getRepositoryDir(localUserName, localRepositoryName))) { git =>
|
Using.resource(Git.open(getRepositoryDir(localUserName, localRepositoryName))) { git =>
|
||||||
val existIds = JGitUtil.getAllCommitIds(git).toSet
|
val existIds = JGitUtil.getAllCommitIds(git).toSet
|
||||||
|
|
||||||
@@ -621,7 +634,8 @@ object MergeService {
|
|||||||
|
|
||||||
def checkConflictForce(): Option[String] = {
|
def checkConflictForce(): Option[String] = {
|
||||||
val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true)
|
val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true)
|
||||||
val conflicted = try {
|
val conflicted =
|
||||||
|
try {
|
||||||
!merger.merge(mergeBaseTip, mergeTip)
|
!merger.merge(mergeBaseTip, mergeTip)
|
||||||
} catch {
|
} catch {
|
||||||
case e: NoMergeBaseException => true
|
case e: NoMergeBaseException => true
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ trait MilestonesService {
|
|||||||
def getMilestone(owner: String, repository: String, milestoneId: Int)(implicit s: Session): Option[Milestone] =
|
def getMilestone(owner: String, repository: String, milestoneId: Int)(implicit s: Session): Option[Milestone] =
|
||||||
Milestones.filter(_.byPrimaryKey(owner, repository, milestoneId)).firstOption
|
Milestones.filter(_.byPrimaryKey(owner, repository, milestoneId)).firstOption
|
||||||
|
|
||||||
def getMilestonesWithIssueCount(owner: String, repository: String)(
|
def getMilestonesWithIssueCount(owner: String, repository: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[(Milestone, Int, Int)] = {
|
): List[(Milestone, Int, Int)] = {
|
||||||
val counts = Issues
|
val counts = Issues
|
||||||
.filter { t =>
|
.filter { t =>
|
||||||
@@ -78,8 +78,7 @@ trait MilestonesService {
|
|||||||
def getApiMilestone(repository: RepositoryInfo, milestoneId: Int)(implicit s: Session): Option[ApiMilestone] = {
|
def getApiMilestone(repository: RepositoryInfo, milestoneId: Int)(implicit s: Session): Option[ApiMilestone] = {
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name)
|
getMilestonesWithIssueCount(repository.owner, repository.name)
|
||||||
.find(p => p._1.milestoneId == milestoneId)
|
.find(p => p._1.milestoneId == milestoneId)
|
||||||
.map(
|
.map(milestoneWithIssue =>
|
||||||
milestoneWithIssue =>
|
|
||||||
ApiMilestone(
|
ApiMilestone(
|
||||||
repository.repository,
|
repository.repository,
|
||||||
milestoneWithIssue._1,
|
milestoneWithIssue._1,
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ trait PrioritiesService {
|
|||||||
Priorities
|
Priorities
|
||||||
.filter(_.byRepository(owner, repository))
|
.filter(_.byRepository(owner, repository))
|
||||||
.list
|
.list
|
||||||
.foreach(
|
.foreach(p =>
|
||||||
p =>
|
|
||||||
Priorities
|
Priorities
|
||||||
.filter(_.byPrimaryKey(owner, repository, p.priorityId))
|
.filter(_.byPrimaryKey(owner, repository, p.priorityId))
|
||||||
.map(_.ordering)
|
.map(_.ordering)
|
||||||
@@ -93,8 +92,7 @@ trait PrioritiesService {
|
|||||||
.map(_.isDefault)
|
.map(_.isDefault)
|
||||||
.update(false)
|
.update(false)
|
||||||
|
|
||||||
priorityId.foreach(
|
priorityId.foreach(id =>
|
||||||
id =>
|
|
||||||
Priorities
|
Priorities
|
||||||
.filter(_.byPrimaryKey(owner, repository, id))
|
.filter(_.byPrimaryKey(owner, repository, id))
|
||||||
.map(_.isDefault)
|
.map(_.isDefault)
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import org.eclipse.jgit.transport.{ReceiveCommand, ReceivePack}
|
|||||||
|
|
||||||
trait ProtectedBranchService {
|
trait ProtectedBranchService {
|
||||||
import ProtectedBranchService._
|
import ProtectedBranchService._
|
||||||
private def getProtectedBranchInfoOpt(owner: String, repository: String, branch: String)(
|
private def getProtectedBranchInfoOpt(owner: String, repository: String, branch: String)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): Option[ProtectedBranchInfo] =
|
): Option[ProtectedBranchInfo] =
|
||||||
ProtectedBranches
|
ProtectedBranches
|
||||||
.joinLeft(ProtectedBranchContexts)
|
.joinLeft(ProtectedBranchContexts)
|
||||||
@@ -22,13 +22,12 @@ trait ProtectedBranchService {
|
|||||||
.map { p =>
|
.map { p =>
|
||||||
p._1 -> p._2.flatMap(_._2)
|
p._1 -> p._2.flatMap(_._2)
|
||||||
}
|
}
|
||||||
.map {
|
.map { case (t1, contexts) =>
|
||||||
case (t1, contexts) =>
|
|
||||||
new ProtectedBranchInfo(t1.userName, t1.repositoryName, t1.branch, true, contexts, t1.statusCheckAdmin)
|
new ProtectedBranchInfo(t1.userName, t1.repositoryName, t1.branch, true, contexts, t1.statusCheckAdmin)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getProtectedBranchInfo(owner: String, repository: String, branch: String)(
|
def getProtectedBranchInfo(owner: String, repository: String, branch: String)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): ProtectedBranchInfo =
|
): ProtectedBranchInfo =
|
||||||
getProtectedBranchInfoOpt(owner, repository, branch).getOrElse(
|
getProtectedBranchInfoOpt(owner, repository, branch).getOrElse(
|
||||||
ProtectedBranchInfo.disabled(owner, repository, branch)
|
ProtectedBranchInfo.disabled(owner, repository, branch)
|
||||||
@@ -88,9 +87,11 @@ object ProtectedBranchService {
|
|||||||
val branch = command.getRefName.stripPrefix("refs/heads/")
|
val branch = command.getRefName.stripPrefix("refs/heads/")
|
||||||
if (branch != command.getRefName) {
|
if (branch != command.getRefName) {
|
||||||
val repositoryInfo = getRepository(owner, repository)
|
val repositoryInfo = getRepository(owner, repository)
|
||||||
if (command.getType == ReceiveCommand.Type.DELETE && repositoryInfo.exists(
|
if (
|
||||||
|
command.getType == ReceiveCommand.Type.DELETE && repositoryInfo.exists(
|
||||||
_.repository.defaultBranch == branch
|
_.repository.defaultBranch == branch
|
||||||
)) {
|
)
|
||||||
|
) {
|
||||||
Some(s"refusing to delete the branch: ${command.getRefName}.")
|
Some(s"refusing to delete the branch: ${command.getRefName}.")
|
||||||
} else {
|
} else {
|
||||||
getProtectedBranchInfo(owner, repository, branch).getStopReason(
|
getProtectedBranchInfo(owner, repository, branch).getStopReason(
|
||||||
@@ -128,8 +129,7 @@ object ProtectedBranchService {
|
|||||||
|
|
||||||
def isAdministrator(pusher: String)(implicit session: Session): Boolean =
|
def isAdministrator(pusher: String)(implicit session: Session): Boolean =
|
||||||
pusher == owner || getGroupMembers(owner).exists(gm => gm.userName == pusher && gm.isManager) ||
|
pusher == owner || getGroupMembers(owner).exists(gm => gm.userName == pusher && gm.isManager) ||
|
||||||
getCollaborators(owner, repository).exists {
|
getCollaborators(owner, repository).exists { case (collaborator, isGroup) =>
|
||||||
case (collaborator, isGroup) =>
|
|
||||||
if (collaborator.role == Role.ADMIN.name) {
|
if (collaborator.role == Role.ADMIN.name) {
|
||||||
if (isGroup) {
|
if (isGroup) {
|
||||||
getGroupMembers(collaborator.collaboratorName).exists(gm => gm.userName == pusher)
|
getGroupMembers(collaborator.collaboratorName).exists(gm => gm.userName == pusher)
|
||||||
@@ -144,8 +144,8 @@ object ProtectedBranchService {
|
|||||||
* Can't be deleted
|
* Can't be deleted
|
||||||
* Can't have changes merged into them until required status checks pass
|
* Can't have changes merged into them until required status checks pass
|
||||||
*/
|
*/
|
||||||
def getStopReason(isAllowNonFastForwards: Boolean, command: ReceiveCommand, pusher: String)(
|
def getStopReason(isAllowNonFastForwards: Boolean, command: ReceiveCommand, pusher: String)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): Option[String] = {
|
): Option[String] = {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
command.getType() match {
|
command.getType() match {
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ trait PullRequestService {
|
|||||||
with ActivityService =>
|
with ActivityService =>
|
||||||
import PullRequestService._
|
import PullRequestService._
|
||||||
|
|
||||||
def getPullRequest(owner: String, repository: String, issueId: Int)(
|
def getPullRequest(owner: String, repository: String, issueId: Int)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[(Issue, PullRequest)] =
|
): Option[(Issue, PullRequest)] =
|
||||||
getIssue(owner, repository, issueId.toString).flatMap { issue =>
|
getIssue(owner, repository, issueId.toString).flatMap { issue =>
|
||||||
PullRequests.filter(_.byPrimaryKey(owner, repository, issueId)).firstOption.map { pullreq =>
|
PullRequests.filter(_.byPrimaryKey(owner, repository, issueId)).firstOption.map { pullreq =>
|
||||||
@@ -43,24 +43,24 @@ trait PullRequestService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateCommitId(owner: String, repository: String, issueId: Int, commitIdTo: String, commitIdFrom: String)(
|
def updateCommitId(owner: String, repository: String, issueId: Int, commitIdTo: String, commitIdFrom: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit =
|
): Unit =
|
||||||
PullRequests
|
PullRequests
|
||||||
.filter(_.byPrimaryKey(owner, repository, issueId))
|
.filter(_.byPrimaryKey(owner, repository, issueId))
|
||||||
.map(pr => pr.commitIdTo -> pr.commitIdFrom)
|
.map(pr => pr.commitIdTo -> pr.commitIdFrom)
|
||||||
.update((commitIdTo, commitIdFrom))
|
.update((commitIdTo, commitIdFrom))
|
||||||
|
|
||||||
def updateDraftToPullRequest(owner: String, repository: String, issueId: Int)(
|
def updateDraftToPullRequest(owner: String, repository: String, issueId: Int)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit =
|
): Unit =
|
||||||
PullRequests
|
PullRequests
|
||||||
.filter(_.byPrimaryKey(owner, repository, issueId))
|
.filter(_.byPrimaryKey(owner, repository, issueId))
|
||||||
.map(pr => pr.isDraft)
|
.map(pr => pr.isDraft)
|
||||||
.update(false)
|
.update(false)
|
||||||
|
|
||||||
def updateBaseBranch(owner: String, repository: String, issueId: Int, baseBranch: String, commitIdTo: String)(
|
def updateBaseBranch(owner: String, repository: String, issueId: Int, baseBranch: String, commitIdTo: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit = {
|
): Unit = {
|
||||||
PullRequests
|
PullRequests
|
||||||
.filter(_.byPrimaryKey(owner, repository, issueId))
|
.filter(_.byPrimaryKey(owner, repository, issueId))
|
||||||
@@ -68,16 +68,15 @@ trait PullRequestService {
|
|||||||
.update((baseBranch, commitIdTo))
|
.update((baseBranch, commitIdTo))
|
||||||
}
|
}
|
||||||
|
|
||||||
def getPullRequestCountGroupByUser(closed: Boolean, owner: Option[String], repository: Option[String])(
|
def getPullRequestCountGroupByUser(closed: Boolean, owner: Option[String], repository: Option[String])(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[PullRequestCount] =
|
): List[PullRequestCount] =
|
||||||
PullRequests
|
PullRequests
|
||||||
.join(Issues)
|
.join(Issues)
|
||||||
.on { (t1, t2) =>
|
.on { (t1, t2) =>
|
||||||
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.filter {
|
.filter { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
(t2.closed === closed.bind)
|
(t2.closed === closed.bind)
|
||||||
.&&(t1.userName === owner.get.bind, owner.isDefined)
|
.&&(t1.userName === owner.get.bind, owner.isDefined)
|
||||||
.&&(t1.repositoryName === repository.get.bind, repository.isDefined)
|
.&&(t1.repositoryName === repository.get.bind, repository.isDefined)
|
||||||
@@ -182,8 +181,7 @@ trait PullRequestService {
|
|||||||
.on { (t1, t2) =>
|
.on { (t1, t2) =>
|
||||||
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.filter {
|
.filter { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
(t1.requestUserName === userName.bind)
|
(t1.requestUserName === userName.bind)
|
||||||
.&&(t1.requestRepositoryName === repositoryName.bind)
|
.&&(t1.requestRepositoryName === repositoryName.bind)
|
||||||
.&&(t1.requestBranch === branch.bind)
|
.&&(t1.requestBranch === branch.bind)
|
||||||
@@ -200,8 +198,7 @@ trait PullRequestService {
|
|||||||
.on { (t1, t2) =>
|
.on { (t1, t2) =>
|
||||||
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.filter {
|
.filter { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
(t1.requestUserName === userName.bind)
|
(t1.requestUserName === userName.bind)
|
||||||
.&&(t1.requestRepositoryName === repositoryName.bind)
|
.&&(t1.requestRepositoryName === repositoryName.bind)
|
||||||
.&&(t1.branch === branch.bind)
|
.&&(t1.branch === branch.bind)
|
||||||
@@ -217,16 +214,15 @@ trait PullRequestService {
|
|||||||
* 2. return if exists pull request to other branch
|
* 2. return if exists pull request to other branch
|
||||||
* 2. return None
|
* 2. return None
|
||||||
*/
|
*/
|
||||||
def getPullRequestFromBranch(userName: String, repositoryName: String, branch: String, defaultBranch: String)(
|
def getPullRequestFromBranch(userName: String, repositoryName: String, branch: String, defaultBranch: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[(PullRequest, Issue)] =
|
): Option[(PullRequest, Issue)] =
|
||||||
PullRequests
|
PullRequests
|
||||||
.join(Issues)
|
.join(Issues)
|
||||||
.on { (t1, t2) =>
|
.on { (t1, t2) =>
|
||||||
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.filter {
|
.filter { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
(t1.requestUserName === userName.bind) &&
|
(t1.requestUserName === userName.bind) &&
|
||||||
(t1.requestRepositoryName === repositoryName.bind) &&
|
(t1.requestRepositoryName === repositoryName.bind) &&
|
||||||
(t1.requestBranch === branch.bind) &&
|
(t1.requestBranch === branch.bind) &&
|
||||||
@@ -247,8 +243,8 @@ trait PullRequestService {
|
|||||||
pusherAccount: Account,
|
pusherAccount: Account,
|
||||||
action: String,
|
action: String,
|
||||||
settings: SystemSettings
|
settings: SystemSettings
|
||||||
)(
|
)(implicit
|
||||||
implicit s: Session,
|
s: Session,
|
||||||
c: JsonFormat.Context
|
c: JsonFormat.Context
|
||||||
): Unit = {
|
): Unit = {
|
||||||
getPullRequestsByRequest(owner, repository, branch, Some(false)).foreach { pullreq =>
|
getPullRequestsByRequest(owner, repository, branch, Some(false)).foreach { pullreq =>
|
||||||
@@ -273,8 +269,7 @@ trait PullRequestService {
|
|||||||
(file, commentId, Left(oldLine))
|
(file, commentId, Left(oldLine))
|
||||||
}
|
}
|
||||||
.groupBy { case (file, _, _) => file }
|
.groupBy { case (file, _, _) => file }
|
||||||
.map {
|
.map { case (file, comments) =>
|
||||||
case (file, comments) =>
|
|
||||||
file ->
|
file ->
|
||||||
comments.map { case (_, commentId, lineNumber) => (commentId, lineNumber) }
|
comments.map { case (_, commentId, lineNumber) => (commentId, lineNumber) }
|
||||||
}
|
}
|
||||||
@@ -312,12 +307,11 @@ trait PullRequestService {
|
|||||||
body: Option[String],
|
body: Option[String],
|
||||||
state: Option[String],
|
state: Option[String],
|
||||||
base: Option[String]
|
base: Option[String]
|
||||||
)(
|
)(implicit
|
||||||
implicit s: Session,
|
s: Session,
|
||||||
c: JsonFormat.Context
|
c: JsonFormat.Context
|
||||||
): Unit = {
|
): Unit = {
|
||||||
getPullRequest(repository.owner, repository.name, issueId).foreach {
|
getPullRequest(repository.owner, repository.name, issueId).foreach { case (issue, pr) =>
|
||||||
case (issue, pr) =>
|
|
||||||
if (Repositories.filter(_.byRepository(pr.userName, pr.repositoryName)).exists.run) {
|
if (Repositories.filter(_.byRepository(pr.userName, pr.repositoryName)).exists.run) {
|
||||||
// Update base branch
|
// Update base branch
|
||||||
base.foreach { _base =>
|
base.foreach { _base =>
|
||||||
@@ -388,8 +382,7 @@ trait PullRequestService {
|
|||||||
.on { (t1, t2) =>
|
.on { (t1, t2) =>
|
||||||
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
.filter {
|
.filter { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
(t1.userName === userName.bind) &&
|
(t1.userName === userName.bind) &&
|
||||||
(t1.repositoryName === repositoryName.bind) &&
|
(t1.repositoryName === repositoryName.bind) &&
|
||||||
(t1.branch === toBranch.bind) &&
|
(t1.branch === toBranch.bind) &&
|
||||||
@@ -412,8 +405,7 @@ trait PullRequestService {
|
|||||||
|
|
||||||
val (_, diffs) = getRequestCompareInfo(userName, repositoryName, oldCommitId, userName, repositoryName, newCommitId)
|
val (_, diffs) = getRequestCompareInfo(userName, repositoryName, oldCommitId, userName, repositoryName, newCommitId)
|
||||||
|
|
||||||
val patchs = positions.map {
|
val patchs = positions.map { case (file, _) =>
|
||||||
case (file, _) =>
|
|
||||||
diffs
|
diffs
|
||||||
.find(x => x.oldPath == file)
|
.find(x => x.oldPath == file)
|
||||||
.map { diff =>
|
.map { diff =>
|
||||||
@@ -432,12 +424,10 @@ trait PullRequestService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
positions.foreach {
|
positions.foreach { case (file, comments) =>
|
||||||
case (file, comments) =>
|
|
||||||
patchs(file) match {
|
patchs(file) match {
|
||||||
case Some(patch) =>
|
case Some(patch) =>
|
||||||
file -> comments.foreach {
|
file -> comments.foreach { case (commentId, lineNumber) =>
|
||||||
case (commentId, lineNumber) =>
|
|
||||||
lineNumber match {
|
lineNumber match {
|
||||||
case Left(oldLine) => updateCommitCommentPosition(commentId, newCommitId, Some(oldLine), None)
|
case Left(oldLine) => updateCommitCommentPosition(commentId, newCommitId, Some(oldLine), None)
|
||||||
case Right(newLine) =>
|
case Right(newLine) =>
|
||||||
@@ -445,7 +435,9 @@ trait PullRequestService {
|
|||||||
patch.getDeltas.asScala.filter(_.getSource.getPosition < newLine).foreach { delta =>
|
patch.getDeltas.asScala.filter(_.getSource.getPosition < newLine).foreach { delta =>
|
||||||
delta.getType match {
|
delta.getType match {
|
||||||
case DeltaType.CHANGE =>
|
case DeltaType.CHANGE =>
|
||||||
if (delta.getSource.getPosition <= newLine - 1 && newLine <= delta.getSource.getPosition + delta.getTarget.getLines.size) {
|
if (
|
||||||
|
delta.getSource.getPosition <= newLine - 1 && newLine <= delta.getSource.getPosition + delta.getTarget.getLines.size
|
||||||
|
) {
|
||||||
counter = -1
|
counter = -1
|
||||||
} else {
|
} else {
|
||||||
counter = counter + (delta.getTarget.getLines.size - delta.getSource.getLines.size)
|
counter = counter + (delta.getTarget.getLines.size - delta.getSource.getLines.size)
|
||||||
@@ -461,8 +453,7 @@ trait PullRequestService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
comments.foreach {
|
comments.foreach { case (commentId, lineNumber) =>
|
||||||
case (commentId, lineNumber) =>
|
|
||||||
lineNumber match {
|
lineNumber match {
|
||||||
case Right(oldLine) => updateCommitCommentPosition(commentId, newCommitId, Some(oldLine), None)
|
case Right(oldLine) => updateCommitCommentPosition(commentId, newCommitId, Some(oldLine), None)
|
||||||
case Left(newLine) => updateCommitCommentPosition(commentId, newCommitId, None, Some(newLine))
|
case Left(newLine) => updateCommitCommentPosition(commentId, newCommitId, None, Some(newLine))
|
||||||
@@ -540,8 +531,8 @@ trait PullRequestService {
|
|||||||
(commits, diffs)
|
(commits, diffs)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getPullRequestComments(userName: String, repositoryName: String, issueId: Int, commits: Seq[CommitInfo])(
|
def getPullRequestComments(userName: String, repositoryName: String, issueId: Int, commits: Seq[CommitInfo])(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Seq[Comment] = {
|
): Seq[Comment] = {
|
||||||
(commits.flatMap(commit => getCommitComments(userName, repositoryName, commit.id, true)) ++ getComments(
|
(commits.flatMap(commit => getCommitComments(userName, repositoryName, commit.id, true)) ++ getComments(
|
||||||
userName,
|
userName,
|
||||||
@@ -552,8 +543,7 @@ trait PullRequestService {
|
|||||||
case x: CommitComment if x.fileName.isEmpty => (Some(x.commentId), None, None, None)
|
case x: CommitComment if x.fileName.isEmpty => (Some(x.commentId), None, None, None)
|
||||||
case x: CommitComment => (None, x.fileName, x.originalOldLine, x.originalNewLine)
|
case x: CommitComment => (None, x.fileName, x.originalOldLine, x.originalNewLine)
|
||||||
case x => throw new MatchError(x)
|
case x => throw new MatchError(x)
|
||||||
}
|
}.toSeq
|
||||||
.toSeq
|
|
||||||
.map {
|
.map {
|
||||||
// Normal comment
|
// Normal comment
|
||||||
case ((Some(_), _, _, _), comments) =>
|
case ((Some(_), _, _, _), comments) =>
|
||||||
@@ -578,8 +568,8 @@ trait PullRequestService {
|
|||||||
.sortWith(_.registeredDate before _.registeredDate)
|
.sortWith(_.registeredDate before _.registeredDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
def markMergeAndClosePullRequest(userName: String, owner: String, repository: String, pull: PullRequest)(
|
def markMergeAndClosePullRequest(userName: String, owner: String, repository: String, pull: PullRequest)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit = {
|
): Unit = {
|
||||||
createComment(owner, repository, userName, pull.issueId, "Merged by user", "merge")
|
createComment(owner, repository, userName, pull.issueId, "Merged by user", "merge")
|
||||||
createComment(owner, repository, userName, pull.issueId, "Close", "close")
|
createComment(owner, repository, userName, pull.issueId, "Close", "close")
|
||||||
@@ -609,8 +599,7 @@ trait PullRequestService {
|
|||||||
Using.resources(
|
Using.resources(
|
||||||
Git.open(getRepositoryDir(originRepository.owner, originRepository.name)),
|
Git.open(getRepositoryDir(originRepository.owner, originRepository.name)),
|
||||||
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
||||||
) {
|
) { case (oldGit, newGit) =>
|
||||||
case (oldGit, newGit) =>
|
|
||||||
if (originRepository.branchList.contains(originId)) {
|
if (originRepository.branchList.contains(originId)) {
|
||||||
val forkedId2 =
|
val forkedId2 =
|
||||||
forkedRepository.tags.collectFirst { case x if x.name == forkedId => x.commitId }.getOrElse(forkedId)
|
forkedRepository.tags.collectFirst { case x if x.name == forkedId => x.commitId }.getOrElse(forkedId)
|
||||||
@@ -661,8 +650,8 @@ object PullRequestService {
|
|||||||
val statuses: List[CommitStatus] =
|
val statuses: List[CommitStatus] =
|
||||||
commitStatuses ++ (branchProtection.contexts.toSet -- commitStatuses.map(_.context).toSet)
|
commitStatuses ++ (branchProtection.contexts.toSet -- commitStatuses.map(_.context).toSet)
|
||||||
.map(CommitStatus.pending(branchProtection.owner, branchProtection.repository, _))
|
.map(CommitStatus.pending(branchProtection.owner, branchProtection.repository, _))
|
||||||
val hasRequiredStatusProblem = needStatusCheck && branchProtection.contexts.exists(
|
val hasRequiredStatusProblem = needStatusCheck && branchProtection.contexts.exists(context =>
|
||||||
context => statuses.find(_.context == context).map(_.state) != Some(CommitState.SUCCESS)
|
statuses.find(_.context == context).map(_.state) != Some(CommitState.SUCCESS)
|
||||||
)
|
)
|
||||||
val hasProblem = hasRequiredStatusProblem || hasConflict || (statuses.nonEmpty && CommitState.combine(
|
val hasProblem = hasRequiredStatusProblem || hasConflict || (statuses.nonEmpty && CommitState.combine(
|
||||||
statuses.map(_.state).toSet
|
statuses.map(_.state).toSet
|
||||||
|
|||||||
@@ -36,14 +36,14 @@ trait ReleaseService {
|
|||||||
ReleaseAssets.filter(x => x.byTag(owner, repository, tag)).list
|
ReleaseAssets.filter(x => x.byTag(owner, repository, tag)).list
|
||||||
}
|
}
|
||||||
|
|
||||||
def getReleaseAssetsMap(owner: String, repository: String, releases: Seq[ReleaseTag])(
|
def getReleaseAssetsMap(owner: String, repository: String, releases: Seq[ReleaseTag])(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Map[ReleaseTag, Seq[ReleaseAsset]] = {
|
): Map[ReleaseTag, Seq[ReleaseAsset]] = {
|
||||||
releases.map(rel => (rel -> getReleaseAssets(owner, repository, rel.tag))).toMap
|
releases.map(rel => (rel -> getReleaseAssets(owner, repository, rel.tag))).toMap
|
||||||
}
|
}
|
||||||
|
|
||||||
def getReleaseAsset(owner: String, repository: String, tag: String, fileId: String)(
|
def getReleaseAsset(owner: String, repository: String, tag: String, fileId: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[ReleaseAsset] = {
|
): Option[ReleaseAsset] = {
|
||||||
ReleaseAssets.filter(x => x.byPrimaryKey(owner, repository, tag, fileId)) firstOption
|
ReleaseAssets.filter(x => x.byPrimaryKey(owner, repository, tag, fileId)) firstOption
|
||||||
}
|
}
|
||||||
@@ -76,8 +76,8 @@ trait ReleaseService {
|
|||||||
ReleaseTags.filter(x => x.byRepository(owner, repository)).sortBy(x => x.updatedDate).list
|
ReleaseTags.filter(x => x.byRepository(owner, repository)).sortBy(x => x.updatedDate).list
|
||||||
}
|
}
|
||||||
|
|
||||||
def getReleases(owner: String, repository: String, tags: Seq[JGitUtil.TagInfo])(
|
def getReleases(owner: String, repository: String, tags: Seq[JGitUtil.TagInfo])(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Seq[ReleaseTag] = {
|
): Seq[ReleaseTag] = {
|
||||||
ReleaseTags
|
ReleaseTags
|
||||||
.filter(x => x.byRepository(owner, repository))
|
.filter(x => x.byRepository(owner, repository))
|
||||||
@@ -89,8 +89,8 @@ trait ReleaseService {
|
|||||||
ReleaseTags.filter(_.byTag(owner, repository, tag)).firstOption
|
ReleaseTags.filter(_.byTag(owner, repository, tag)).firstOption
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateRelease(owner: String, repository: String, tag: String, title: String, content: Option[String])(
|
def updateRelease(owner: String, repository: String, tag: String, title: String, content: Option[String])(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
ReleaseTags
|
ReleaseTags
|
||||||
.filter(_.byPrimaryKey(owner, repository, tag))
|
.filter(_.byPrimaryKey(owner, repository, tag))
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ trait RepositoryCommitFileService {
|
|||||||
path,
|
path,
|
||||||
newFileName,
|
newFileName,
|
||||||
oldFileName,
|
oldFileName,
|
||||||
if (content.nonEmpty) { content.getBytes(charset) } else { Array.emptyByteArray },
|
if (content.nonEmpty) { content.getBytes(charset) }
|
||||||
|
else { Array.emptyByteArray },
|
||||||
message,
|
message,
|
||||||
commit,
|
commit,
|
||||||
loginAccount,
|
loginAccount,
|
||||||
|
|||||||
@@ -214,8 +214,7 @@ trait RepositoryCreationService {
|
|||||||
// Set default collaborators for the private fork
|
// Set default collaborators for the private fork
|
||||||
if (repository.repository.isPrivate) {
|
if (repository.repository.isPrivate) {
|
||||||
// Copy collaborators from the source repository
|
// Copy collaborators from the source repository
|
||||||
getCollaborators(repository.owner, repository.name).foreach {
|
getCollaborators(repository.owner, repository.name).foreach { case (collaborator, _) =>
|
||||||
case (collaborator, _) =>
|
|
||||||
addCollaborator(accountName, repository.name, collaborator.collaboratorName, collaborator.role)
|
addCollaborator(accountName, repository.name, collaborator.collaboratorName, collaborator.role)
|
||||||
}
|
}
|
||||||
// Register an owner of the source repository as a collaborator
|
// Register an owner of the source repository as a collaborator
|
||||||
|
|||||||
@@ -14,16 +14,15 @@ import scala.util.Using
|
|||||||
trait RepositorySearchService { self: IssuesService =>
|
trait RepositorySearchService { self: IssuesService =>
|
||||||
import RepositorySearchService._
|
import RepositorySearchService._
|
||||||
|
|
||||||
def countIssues(owner: String, repository: String, query: String, pullRequest: Boolean)(
|
def countIssues(owner: String, repository: String, query: String, pullRequest: Boolean)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): Int =
|
): Int =
|
||||||
searchIssuesByKeyword(owner, repository, query, pullRequest).length
|
searchIssuesByKeyword(owner, repository, query, pullRequest).length
|
||||||
|
|
||||||
def searchIssues(owner: String, repository: String, query: String, pullRequest: Boolean)(
|
def searchIssues(owner: String, repository: String, query: String, pullRequest: Boolean)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): List[IssueSearchResult] =
|
): List[IssueSearchResult] =
|
||||||
searchIssuesByKeyword(owner, repository, query, pullRequest).map {
|
searchIssuesByKeyword(owner, repository, query, pullRequest).map { case (issue, commentCount, content) =>
|
||||||
case (issue, commentCount, content) =>
|
|
||||||
IssueSearchResult(
|
IssueSearchResult(
|
||||||
issue.issueId,
|
issue.issueId,
|
||||||
issue.isPullRequest,
|
issue.isPullRequest,
|
||||||
@@ -48,8 +47,7 @@ trait RepositorySearchService { self: IssuesService =>
|
|||||||
} else {
|
} else {
|
||||||
val files = searchRepositoryFiles(git, query)
|
val files = searchRepositoryFiles(git, query)
|
||||||
val commits = JGitUtil.getLatestCommitFromPaths(git, files.map(_._1), "HEAD")
|
val commits = JGitUtil.getLatestCommitFromPaths(git, files.map(_._1), "HEAD")
|
||||||
files.map {
|
files.map { case (path, text) =>
|
||||||
case (path, text) =>
|
|
||||||
val (highlightText, lineNumber) = getHighlightText(text, query)
|
val (highlightText, lineNumber) = getHighlightText(text, query)
|
||||||
FileSearchResult(path, commits(path).getCommitterIdent.getWhen, highlightText, lineNumber)
|
FileSearchResult(path, commits(path).getCommitterIdent.getWhen, highlightText, lineNumber)
|
||||||
}
|
}
|
||||||
@@ -68,8 +66,7 @@ trait RepositorySearchService { self: IssuesService =>
|
|||||||
} else {
|
} else {
|
||||||
val files = searchRepositoryFiles(git, query)
|
val files = searchRepositoryFiles(git, query)
|
||||||
val commits = JGitUtil.getLatestCommitFromPaths(git, files.map(_._1), "HEAD")
|
val commits = JGitUtil.getLatestCommitFromPaths(git, files.map(_._1), "HEAD")
|
||||||
files.map {
|
files.map { case (path, text) =>
|
||||||
case (path, text) =>
|
|
||||||
val (highlightText, lineNumber) = getHighlightText(text, query)
|
val (highlightText, lineNumber) = getHighlightText(text, query)
|
||||||
FileSearchResult(
|
FileSearchResult(
|
||||||
path.stripSuffix(".md"),
|
path.stripSuffix(".md"),
|
||||||
|
|||||||
@@ -187,8 +187,7 @@ trait RepositoryService {
|
|||||||
val newLabelMap =
|
val newLabelMap =
|
||||||
Labels.filter(_.byRepository(newUserName, newRepositoryName)).map(x => (x.labelName, x.labelId)).list.toMap
|
Labels.filter(_.byRepository(newUserName, newRepositoryName)).map(x => (x.labelName, x.labelId)).list.toMap
|
||||||
IssueLabels.insertAll(
|
IssueLabels.insertAll(
|
||||||
issueLabels.map(
|
issueLabels.map(x =>
|
||||||
x =>
|
|
||||||
x.copy(
|
x.copy(
|
||||||
labelId = newLabelMap(oldLabelMap(x.labelId)),
|
labelId = newLabelMap(oldLabelMap(x.labelId)),
|
||||||
userName = newUserName,
|
userName = newUserName,
|
||||||
@@ -275,8 +274,7 @@ trait RepositoryService {
|
|||||||
(x.userName, x.repositoryName)
|
(x.userName, x.repositoryName)
|
||||||
}
|
}
|
||||||
.list
|
.list
|
||||||
.foreach {
|
.foreach { case (userName, repositoryName) =>
|
||||||
case (userName, repositoryName) =>
|
|
||||||
Repositories
|
Repositories
|
||||||
.filter(_.byRepository(userName, repositoryName))
|
.filter(_.byRepository(userName, repositoryName))
|
||||||
.map(x => (x.originUserName ?, x.originRepositoryName ?))
|
.map(x => (x.originUserName ?, x.originRepositoryName ?))
|
||||||
@@ -292,8 +290,7 @@ trait RepositoryService {
|
|||||||
(x.userName, x.repositoryName)
|
(x.userName, x.repositoryName)
|
||||||
}
|
}
|
||||||
.list
|
.list
|
||||||
.foreach {
|
.foreach { case (userName, repositoryName) =>
|
||||||
case (userName, repositoryName) =>
|
|
||||||
Repositories
|
Repositories
|
||||||
.filter(_.byRepository(userName, repositoryName))
|
.filter(_.byRepository(userName, repositoryName))
|
||||||
.map(x => (x.parentUserName ?, x.parentRepositoryName ?))
|
.map(x => (x.parentUserName ?, x.parentRepositoryName ?))
|
||||||
@@ -321,11 +318,9 @@ trait RepositoryService {
|
|||||||
(Repositories
|
(Repositories
|
||||||
.join(Accounts)
|
.join(Accounts)
|
||||||
.on(_.userName === _.userName)
|
.on(_.userName === _.userName)
|
||||||
.filter {
|
.filter { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
t1.byRepository(userName, repositoryName) && t2.removed === false.bind
|
t1.byRepository(userName, repositoryName) && t2.removed === false.bind
|
||||||
} firstOption) map {
|
} firstOption) map { case (repository, account) =>
|
||||||
case (repository, account) =>
|
|
||||||
// for getting issue count and pull request count
|
// for getting issue count and pull request count
|
||||||
val issues = Issues
|
val issues = Issues
|
||||||
.filter { t =>
|
.filter { t =>
|
||||||
@@ -396,8 +391,8 @@ trait RepositoryService {
|
|||||||
* Returns the list of repositories which are owned by the specified user.
|
* Returns the list of repositories which are owned by the specified user.
|
||||||
* This list includes group repositories if the specified user is a member of the group.
|
* This list includes group repositories if the specified user is a member of the group.
|
||||||
*/
|
*/
|
||||||
def getUserRepositories(userName: String, withoutPhysicalInfo: Boolean = false)(
|
def getUserRepositories(userName: String, withoutPhysicalInfo: Boolean = false)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[RepositoryInfo] = {
|
): List[RepositoryInfo] = {
|
||||||
Repositories
|
Repositories
|
||||||
.filter { t1 =>
|
.filter { t1 =>
|
||||||
@@ -464,8 +459,7 @@ trait RepositoryService {
|
|||||||
Repositories
|
Repositories
|
||||||
.join(Accounts)
|
.join(Accounts)
|
||||||
.on(_.userName === _.userName)
|
.on(_.userName === _.userName)
|
||||||
.filter {
|
.filter { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
(t2.removed === false.bind) && ((t1.isPrivate === false.bind && !limit.bind) || (t1.userName === x.userName) ||
|
(t2.removed === false.bind) && ((t1.isPrivate === false.bind && !limit.bind) || (t1.userName === x.userName) ||
|
||||||
(t1.userName in GroupMembers.filter(_.userName === x.userName.bind).map(_.groupName)) ||
|
(t1.userName in GroupMembers.filter(_.userName === x.userName.bind).map(_.groupName)) ||
|
||||||
(Collaborators.filter { t3 =>
|
(Collaborators.filter { t3 =>
|
||||||
@@ -486,14 +480,13 @@ trait RepositoryService {
|
|||||||
repositoryUserName.map { userName =>
|
repositoryUserName.map { userName =>
|
||||||
t.userName === userName.bind
|
t.userName === userName.bind
|
||||||
} getOrElse LiteralColumn(true)
|
} getOrElse LiteralColumn(true)
|
||||||
}
|
}.sortBy(_.lastActivityDate desc)
|
||||||
.sortBy(_.lastActivityDate desc)
|
|
||||||
.list
|
.list
|
||||||
.map(createRepositoryInfo(_, withoutPhysicalInfo))
|
.map(createRepositoryInfo(_, withoutPhysicalInfo))
|
||||||
}
|
}
|
||||||
|
|
||||||
private def createRepositoryInfo(repository: Repository, withoutPhysicalInfo: Boolean = false)(
|
private def createRepositoryInfo(repository: Repository, withoutPhysicalInfo: Boolean = false)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): RepositoryInfo = {
|
): RepositoryInfo = {
|
||||||
new RepositoryInfo(
|
new RepositoryInfo(
|
||||||
if (withoutPhysicalInfo) {
|
if (withoutPhysicalInfo) {
|
||||||
@@ -586,8 +579,8 @@ trait RepositoryService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
def saveRepositoryDefaultBranch(userName: String, repositoryName: String, defaultBranch: String)(
|
def saveRepositoryDefaultBranch(userName: String, repositoryName: String, defaultBranch: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit =
|
): Unit =
|
||||||
Repositories
|
Repositories
|
||||||
.filter(_.byRepository(userName, repositoryName))
|
.filter(_.byRepository(userName, repositoryName))
|
||||||
@@ -599,16 +592,16 @@ trait RepositoryService {
|
|||||||
/**
|
/**
|
||||||
* Add collaborator (user or group) to the repository.
|
* Add collaborator (user or group) to the repository.
|
||||||
*/
|
*/
|
||||||
def addCollaborator(userName: String, repositoryName: String, collaboratorName: String, role: String)(
|
def addCollaborator(userName: String, repositoryName: String, collaboratorName: String, role: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit =
|
): Unit =
|
||||||
Collaborators insert Collaborator(userName, repositoryName, collaboratorName, role)
|
Collaborators insert Collaborator(userName, repositoryName, collaboratorName, role)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove specified collaborator from the repository.
|
* Remove specified collaborator from the repository.
|
||||||
*/
|
*/
|
||||||
def removeCollaborator(userName: String, repositoryName: String, collaboratorName: String)(
|
def removeCollaborator(userName: String, repositoryName: String, collaboratorName: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Unit =
|
): Unit =
|
||||||
Collaborators.filter(_.byPrimaryKey(userName, repositoryName, collaboratorName)).delete
|
Collaborators.filter(_.byPrimaryKey(userName, repositoryName, collaboratorName)).delete
|
||||||
|
|
||||||
@@ -634,8 +627,8 @@ trait RepositoryService {
|
|||||||
* Returns the list of all collaborator name and permission which is sorted with ascending order.
|
* Returns the list of all collaborator name and permission which is sorted with ascending order.
|
||||||
* If a group is added as a collaborator, this method returns users who are belong to that group.
|
* If a group is added as a collaborator, this method returns users who are belong to that group.
|
||||||
*/
|
*/
|
||||||
def getCollaboratorUserNames(userName: String, repositoryName: String, filter: Seq[Role] = Nil)(
|
def getCollaboratorUserNames(userName: String, repositoryName: String, filter: Seq[Role] = Nil)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[String] = {
|
): List[String] = {
|
||||||
val q1 = Collaborators
|
val q1 = Collaborators
|
||||||
.join(Accounts)
|
.join(Accounts)
|
||||||
@@ -669,8 +662,8 @@ trait RepositoryService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def hasDeveloperRole(owner: String, repository: String, loginAccount: Option[Account])(
|
def hasDeveloperRole(owner: String, repository: String, loginAccount: Option[Account])(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
loginAccount match {
|
loginAccount match {
|
||||||
case Some(a) if (a.isAdmin) => true
|
case Some(a) if (a.isAdmin) => true
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ trait RequestCache
|
|||||||
private implicit def context2Session(implicit context: Context): Session =
|
private implicit def context2Session(implicit context: Context): Session =
|
||||||
request2Session(context.request)
|
request2Session(context.request)
|
||||||
|
|
||||||
def getIssueFromCache(userName: String, repositoryName: String, issueId: String)(
|
def getIssueFromCache(userName: String, repositoryName: String, issueId: String)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): Option[Issue] = {
|
): Option[Issue] = {
|
||||||
context.cache(s"issue.${userName}/${repositoryName}#${issueId}") {
|
context.cache(s"issue.${userName}/${repositoryName}#${issueId}") {
|
||||||
super.getIssue(userName, repositoryName, issueId)
|
super.getIssue(userName, repositoryName, issueId)
|
||||||
@@ -45,19 +45,18 @@ trait RequestCache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getRepositoryInfoFromCache(userName: String, repositoryName: String)(
|
def getRepositoryInfoFromCache(userName: String, repositoryName: String)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): Option[Repository] = {
|
): Option[Repository] = {
|
||||||
context.cache(s"repository.${userName}/${repositoryName}") {
|
context.cache(s"repository.${userName}/${repositoryName}") {
|
||||||
Repositories
|
Repositories
|
||||||
.join(Accounts)
|
.join(Accounts)
|
||||||
.on(_.userName === _.userName)
|
.on(_.userName === _.userName)
|
||||||
.filter {
|
.filter { case (t1, t2) =>
|
||||||
case (t1, t2) =>
|
|
||||||
t1.byRepository(userName, repositoryName) && t2.removed === false.bind
|
t1.byRepository(userName, repositoryName) && t2.removed === false.bind
|
||||||
}
|
}
|
||||||
.map {
|
.map { case (t1, t2) =>
|
||||||
case (t1, t2) => t1
|
t1
|
||||||
}
|
}
|
||||||
.firstOption
|
.firstOption
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ trait WebHookService {
|
|||||||
private val logger = LoggerFactory.getLogger(classOf[WebHookService])
|
private val logger = LoggerFactory.getLogger(classOf[WebHookService])
|
||||||
|
|
||||||
/** get All WebHook informations of repository */
|
/** get All WebHook informations of repository */
|
||||||
def getWebHooks(owner: String, repository: String)(
|
def getWebHooks(owner: String, repository: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[(RepositoryWebHook, Set[WebHook.Event])] =
|
): List[(RepositoryWebHook, Set[WebHook.Event])] =
|
||||||
RepositoryWebHooks
|
RepositoryWebHooks
|
||||||
.filter(_.byRepository(owner, repository))
|
.filter(_.byRepository(owner, repository))
|
||||||
@@ -63,8 +63,8 @@ trait WebHookService {
|
|||||||
.sortBy(_._1.url)
|
.sortBy(_._1.url)
|
||||||
|
|
||||||
/** get All WebHook informations of repository event */
|
/** get All WebHook informations of repository event */
|
||||||
def getWebHooksByEvent(owner: String, repository: String, event: WebHook.Event)(
|
def getWebHooksByEvent(owner: String, repository: String, event: WebHook.Event)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): List[RepositoryWebHook] =
|
): List[RepositoryWebHook] =
|
||||||
RepositoryWebHooks
|
RepositoryWebHooks
|
||||||
.filter(_.byRepository(owner, repository))
|
.filter(_.byRepository(owner, repository))
|
||||||
@@ -78,8 +78,8 @@ trait WebHookService {
|
|||||||
.distinct
|
.distinct
|
||||||
|
|
||||||
/** get All WebHook information from repository to url */
|
/** get All WebHook information from repository to url */
|
||||||
def getWebHook(owner: String, repository: String, url: String)(
|
def getWebHook(owner: String, repository: String, url: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[(RepositoryWebHook, Set[WebHook.Event])] =
|
): Option[(RepositoryWebHook, Set[WebHook.Event])] =
|
||||||
RepositoryWebHooks
|
RepositoryWebHooks
|
||||||
.filter(_.byRepositoryUrl(owner, repository, url))
|
.filter(_.byRepositoryUrl(owner, repository, url))
|
||||||
@@ -95,8 +95,8 @@ trait WebHookService {
|
|||||||
.headOption
|
.headOption
|
||||||
|
|
||||||
/** get All WebHook informations of repository */
|
/** get All WebHook informations of repository */
|
||||||
def getWebHookById(id: Int)(
|
def getWebHookById(id: Int)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[(RepositoryWebHook, Set[WebHook.Event])] =
|
): Option[(RepositoryWebHook, Set[WebHook.Event])] =
|
||||||
RepositoryWebHooks
|
RepositoryWebHooks
|
||||||
.filter(_.byId(id))
|
.filter(_.byId(id))
|
||||||
@@ -451,8 +451,8 @@ trait WebHookPullRequestService extends WebHookService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return Map[(issue, issueUser, pullRequest, baseOwner, headOwner), webHooks] */
|
/** @return Map[(issue, issueUser, pullRequest, baseOwner, headOwner), webHooks] */
|
||||||
def getPullRequestsByRequestForWebhook(userName: String, repositoryName: String, branch: String)(
|
def getPullRequestsByRequestForWebhook(userName: String, repositoryName: String, branch: String)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Map[(Issue, Account, PullRequest, Account, Account), List[RepositoryWebHook]] =
|
): Map[(Issue, Account, PullRequest, Account, Account), List[RepositoryWebHook]] =
|
||||||
(for {
|
(for {
|
||||||
is <- Issues if is.closed === false.bind
|
is <- Issues if is.closed === false.bind
|
||||||
@@ -878,8 +878,7 @@ object WebHookService {
|
|||||||
sender: Account
|
sender: Account
|
||||||
): WebHookGollumPayload = {
|
): WebHookGollumPayload = {
|
||||||
WebHookGollumPayload(
|
WebHookGollumPayload(
|
||||||
pages = pages.map {
|
pages = pages.map { case (action, pageName, sha) =>
|
||||||
case (action, pageName, sha) =>
|
|
||||||
WebHookGollumPagePayload(
|
WebHookGollumPagePayload(
|
||||||
action = action,
|
action = action,
|
||||||
page_name = pageName,
|
page_name = pageName,
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ abstract class ControllerFilter extends Filter {
|
|||||||
requestPath + "/"
|
requestPath + "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkPath.startsWith("/upload/") && !checkPath.startsWith("/git/") && !checkPath.startsWith("/git-lfs/") &&
|
if (
|
||||||
!checkPath.startsWith("/assets/") && !checkPath.startsWith("/plugin-assets/")) {
|
!checkPath.startsWith("/upload/") && !checkPath.startsWith("/git/") && !checkPath.startsWith("/git-lfs/") &&
|
||||||
|
!checkPath.startsWith("/assets/") && !checkPath.startsWith("/plugin-assets/")
|
||||||
|
) {
|
||||||
val continue = process(request, response, checkPath)
|
val continue = process(request, response, checkPath)
|
||||||
if (!continue) {
|
if (!continue) {
|
||||||
return ()
|
return ()
|
||||||
@@ -41,28 +43,24 @@ class CompositeScalatraFilter extends ControllerFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override def init(filterConfig: FilterConfig): Unit = {
|
override def init(filterConfig: FilterConfig): Unit = {
|
||||||
filters.foreach {
|
filters.foreach { case (filter, _) =>
|
||||||
case (filter, _) =>
|
|
||||||
filter.init(filterConfig)
|
filter.init(filterConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def destroy(): Unit = {
|
override def destroy(): Unit = {
|
||||||
filters.foreach {
|
filters.foreach { case (filter, _) =>
|
||||||
case (filter, _) =>
|
|
||||||
filter.destroy()
|
filter.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def process(request: ServletRequest, response: ServletResponse, checkPath: String): Boolean = {
|
override def process(request: ServletRequest, response: ServletResponse, checkPath: String): Boolean = {
|
||||||
filters
|
filters
|
||||||
.filter {
|
.filter { case (_, path) =>
|
||||||
case (_, path) =>
|
|
||||||
val start = path.replaceFirst("/\\*$", "/")
|
val start = path.replaceFirst("/\\*$", "/")
|
||||||
checkPath.startsWith(start)
|
checkPath.startsWith(start)
|
||||||
}
|
}
|
||||||
.foreach {
|
.foreach { case (filter, _) =>
|
||||||
case (filter, _) =>
|
|
||||||
val mockChain = new MockFilterChain()
|
val mockChain = new MockFilterChain()
|
||||||
filter.doFilter(request, response, mockChain)
|
filter.doFilter(request, response, mockChain)
|
||||||
if (mockChain.continue == false) {
|
if (mockChain.continue == false) {
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ class GitAuthenticationFilter extends Filter with RepositoryService with Account
|
|||||||
try {
|
try {
|
||||||
PluginRegistry()
|
PluginRegistry()
|
||||||
.getRepositoryRouting(request.gitRepositoryPath)
|
.getRepositoryRouting(request.gitRepositoryPath)
|
||||||
.map {
|
.map { case GitRepositoryRouting(_, _, filter) =>
|
||||||
case GitRepositoryRouting(_, _, filter) =>
|
|
||||||
// served by plug-ins
|
// served by plug-ins
|
||||||
pluginRepository(request, wrappedResponse, chain, settings, isUpdating, filter)
|
pluginRepository(request, wrappedResponse, chain, settings, isUpdating, filter)
|
||||||
|
|
||||||
@@ -130,16 +129,14 @@ class GitAuthenticationFilter extends Filter with RepositoryService with Account
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case None =>
|
case None =>
|
||||||
() =>
|
() => {
|
||||||
{
|
|
||||||
logger.debug(s"Repository ${repositoryOwner}/${repositoryName} is not found.")
|
logger.debug(s"Repository ${repositoryOwner}/${repositoryName} is not found.")
|
||||||
response.sendError(HttpServletResponse.SC_NOT_FOUND)
|
response.sendError(HttpServletResponse.SC_NOT_FOUND)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
() =>
|
() => {
|
||||||
{
|
|
||||||
logger.debug(s"Not enough path arguments: ${request.paths.mkString(", ")}")
|
logger.debug(s"Not enough path arguments: ${request.paths.mkString(", ")}")
|
||||||
response.sendError(HttpServletResponse.SC_NOT_FOUND)
|
response.sendError(HttpServletResponse.SC_NOT_FOUND)
|
||||||
}
|
}
|
||||||
@@ -159,8 +156,8 @@ class GitAuthenticationFilter extends Filter with RepositoryService with Account
|
|||||||
* @param s database session
|
* @param s database session
|
||||||
* @return an account or none
|
* @return an account or none
|
||||||
*/
|
*/
|
||||||
private def authenticateByHeader(authorizationHeader: String, settings: SystemSettings)(
|
private def authenticateByHeader(authorizationHeader: String, settings: SystemSettings)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Option[Account] = {
|
): Option[Account] = {
|
||||||
val Array(username, password) = AuthUtil.decodeAuthHeader(authorizationHeader).split(":", 2)
|
val Array(username, password) = AuthUtil.decodeAuthHeader(authorizationHeader).split(":", 2)
|
||||||
authenticate(settings, username, password).orElse {
|
authenticate(settings, username, password).orElse {
|
||||||
|
|||||||
@@ -171,8 +171,7 @@ class GitBucketRepositoryResolver extends RepositoryResolver[HttpServletRequest]
|
|||||||
// Rewrite repository path if routing is marched
|
// Rewrite repository path if routing is marched
|
||||||
PluginRegistry()
|
PluginRegistry()
|
||||||
.getRepositoryRouting("/" + name)
|
.getRepositoryRouting("/" + name)
|
||||||
.map {
|
.map { case GitRepositoryRouting(urlPattern, localPath, _) =>
|
||||||
case GitRepositoryRouting(urlPattern, localPath, _) =>
|
|
||||||
val path = urlPattern.r.replaceFirstIn(name, localPath)
|
val path = urlPattern.r.replaceFirstIn(name, localPath)
|
||||||
new FileRepository(new File(Directory.GitBucketHome, path))
|
new FileRepository(new File(Directory.GitBucketHome, path))
|
||||||
}
|
}
|
||||||
@@ -341,7 +340,11 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
|||||||
pushedIds.add(commit.id)
|
pushedIds.add(commit.id)
|
||||||
createIssueComment(owner, repository, commit)
|
createIssueComment(owner, repository, commit)
|
||||||
// close issues
|
// close issues
|
||||||
if (refName(1) == "heads" && branchName == defaultBranch && command.getType == ReceiveCommand.Type.UPDATE) {
|
if (
|
||||||
|
refName(
|
||||||
|
1
|
||||||
|
) == "heads" && branchName == defaultBranch && command.getType == ReceiveCommand.Type.UPDATE
|
||||||
|
) {
|
||||||
getAccountByUserName(pusher).foreach { pusherAccount =>
|
getAccountByUserName(pusher).foreach { pusherAccount =>
|
||||||
closeIssuesFromMessage(commit.fullMessage, pusher, owner, repository).foreach { issueId =>
|
closeIssuesFromMessage(commit.fullMessage, pusher, owner, repository).foreach { issueId =>
|
||||||
getIssue(owner, repository, issueId.toString).foreach { issue =>
|
getIssue(owner, repository, issueId.toString).foreach { issue =>
|
||||||
@@ -362,9 +365,11 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
|||||||
// set PR as merged
|
// set PR as merged
|
||||||
val pulls = getPullRequestsByBranch(owner, repository, branchName, Some(false))
|
val pulls = getPullRequestsByBranch(owner, repository, branchName, Some(false))
|
||||||
pulls.foreach { pull =>
|
pulls.foreach { pull =>
|
||||||
if (commits.exists { c =>
|
if (
|
||||||
|
commits.exists { c =>
|
||||||
c.id == pull.commitIdTo
|
c.id == pull.commitIdTo
|
||||||
}) {
|
}
|
||||||
|
) {
|
||||||
markMergeAndClosePullRequest(pusher, owner, repository, pull)
|
markMergeAndClosePullRequest(pusher, owner, repository, pull)
|
||||||
getAccountByUserName(pusher).foreach { pusherAccount =>
|
getAccountByUserName(pusher).foreach { pusherAccount =>
|
||||||
callPullRequestWebHook("closed", repositoryInfo, pull.issueId, pusherAccount, settings)
|
callPullRequestWebHook("closed", repositoryInfo, pull.issueId, pusherAccount, settings)
|
||||||
@@ -490,8 +495,7 @@ class WikiCommitHook(owner: String, repository: String, pusher: String, baseUrl:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commitIds.foreach {
|
commitIds.foreach { case (oldCommitId, newCommitId) =>
|
||||||
case (oldCommitId, newCommitId) =>
|
|
||||||
val commits = Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) { git =>
|
val commits = Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) { git =>
|
||||||
JGitUtil.getCommitLog(git, oldCommitId, newCommitId).flatMap { commit =>
|
JGitUtil.getCommitLog(git, oldCommitId, newCommitId).flatMap { commit =>
|
||||||
val diffs = JGitUtil.getDiffs(git, None, commit.id, false, false)
|
val diffs = JGitUtil.getDiffs(git, None, commit.id, false, false)
|
||||||
@@ -508,8 +512,7 @@ class WikiCommitHook(owner: String, repository: String, pusher: String, baseUrl:
|
|||||||
|
|
||||||
val pages = commits
|
val pages = commits
|
||||||
.groupBy { case (_, fileName, _) => fileName }
|
.groupBy { case (_, fileName, _) => fileName }
|
||||||
.map {
|
.map { case (fileName, commits) =>
|
||||||
case (fileName, commits) =>
|
|
||||||
val (commitHeadAction, _, _) = commits.head
|
val (commitHeadAction, _, _) = commits.head
|
||||||
val (_, _, commitLastId) = commits.last
|
val (_, _, commitLastId) = commits.last
|
||||||
(commitHeadAction, fileName, commitLastId)
|
(commitHeadAction, fileName, commitLastId)
|
||||||
|
|||||||
@@ -153,8 +153,8 @@ class InitializeListener extends ServletContextListener with SystemSettingsServi
|
|||||||
logger.info(s"Extract to ${file.getAbsolutePath}")
|
logger.info(s"Extract to ${file.getAbsolutePath}")
|
||||||
|
|
||||||
FileUtils.forceMkdirParent(file)
|
FileUtils.forceMkdirParent(file)
|
||||||
Using.resources(in, new FileOutputStream(file)) {
|
Using.resources(in, new FileOutputStream(file)) { case (in, out) =>
|
||||||
case (in, out) => IOUtils.copy(in, out)
|
IOUtils.copy(in, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case _ => ()
|
case _ => ()
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ class PluginAssetsServlet extends HttpServlet {
|
|||||||
|
|
||||||
assetsMappings
|
assetsMappings
|
||||||
.find { case (prefix, _, _) => path.startsWith("/plugin-assets" + prefix) }
|
.find { case (prefix, _, _) => path.startsWith("/plugin-assets" + prefix) }
|
||||||
.foreach {
|
.foreach { case (prefix, resourcePath, classLoader) =>
|
||||||
case (prefix, resourcePath, classLoader) =>
|
|
||||||
val ifNoneMatch = req.getHeader("If-None-Match")
|
val ifNoneMatch = req.getHeader("If-None-Match")
|
||||||
PluginRegistry.getPluginInfoFromClassLoader(classLoader).map { info =>
|
PluginRegistry.getPluginInfoFromClassLoader(classLoader).map { info =>
|
||||||
val etag = s""""${info.pluginJar.lastModified}"""" // ETag must wrapped with double quote
|
val etag = s""""${info.pluginJar.lastModified}"""" // ETag must wrapped with double quote
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ class PluginControllerFilter extends ControllerFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override def destroy(): Unit = {
|
override def destroy(): Unit = {
|
||||||
PluginRegistry().getControllers().foreach {
|
PluginRegistry().getControllers().foreach { case (controller, _) =>
|
||||||
case (controller, _) =>
|
|
||||||
controller.destroy()
|
controller.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,13 +22,11 @@ class PluginControllerFilter extends ControllerFilter {
|
|||||||
override def process(request: ServletRequest, response: ServletResponse, checkPath: String): Boolean = {
|
override def process(request: ServletRequest, response: ServletResponse, checkPath: String): Boolean = {
|
||||||
PluginRegistry()
|
PluginRegistry()
|
||||||
.getControllers()
|
.getControllers()
|
||||||
.filter {
|
.filter { case (_, path) =>
|
||||||
case (_, path) =>
|
|
||||||
val start = path.replaceFirst("/\\*$", "/")
|
val start = path.replaceFirst("/\\*$", "/")
|
||||||
checkPath.startsWith(start)
|
checkPath.startsWith(start)
|
||||||
}
|
}
|
||||||
.foreach {
|
.foreach { case (controller, _) =>
|
||||||
case (controller, _) =>
|
|
||||||
controller match {
|
controller match {
|
||||||
case x: ControllerBase if (x.config == null) => x.init(filterConfig)
|
case x: ControllerBase if (x.config == null) => x.init(filterConfig)
|
||||||
case _ => ()
|
case _ => ()
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ abstract class DefaultGitCommand(val owner: String, val repoName: String) extend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def isReadableUser(authType: AuthType, repositoryInfo: RepositoryService.RepositoryInfo)(
|
protected def isReadableUser(authType: AuthType, repositoryInfo: RepositoryService.RepositoryInfo)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
authType match {
|
authType match {
|
||||||
case AuthType.UserAuthType(username) => {
|
case AuthType.UserAuthType(username) => {
|
||||||
@@ -120,8 +120,8 @@ abstract class DefaultGitCommand(val owner: String, val repoName: String) extend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def isWritableUser(authType: AuthType, repositoryInfo: RepositoryService.RepositoryInfo)(
|
protected def isWritableUser(authType: AuthType, repositoryInfo: RepositoryService.RepositoryInfo)(implicit
|
||||||
implicit session: Session
|
session: Session
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
authType match {
|
authType match {
|
||||||
case AuthType.UserAuthType(username) => {
|
case AuthType.UserAuthType(username) => {
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ class PublicKeyAuthenticator(genericUser: String)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def authenticateLoginUser(userName: String, key: PublicKey, session: ServerSession)(
|
private def authenticateLoginUser(userName: String, key: PublicKey, session: ServerSession)(implicit
|
||||||
implicit s: Session
|
s: Session
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
val authenticated = getPublicKeys(userName).map(_.publicKey).flatMap(SshUtil.str2PublicKey).contains(key)
|
val authenticated = getPublicKeys(userName).map(_.publicKey).flatMap(SshUtil.str2PublicKey).contains(key)
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider
|
|||||||
object GpgUtil {
|
object GpgUtil {
|
||||||
def str2GpgKeyId(keyStr: String): Option[Long] = {
|
def str2GpgKeyId(keyStr: String): Option[Long] = {
|
||||||
val pubKeyOf = new BcPGPObjectFactory(new ArmoredInputStream(new ByteArrayInputStream(keyStr.getBytes)))
|
val pubKeyOf = new BcPGPObjectFactory(new ArmoredInputStream(new ByteArrayInputStream(keyStr.getBytes)))
|
||||||
pubKeyOf.iterator().asScala.collectFirst {
|
pubKeyOf.iterator().asScala.collectFirst { case keyRing: PGPPublicKeyRing =>
|
||||||
case keyRing: PGPPublicKeyRing =>
|
|
||||||
keyRing.getPublicKey().getKeyID
|
keyRing.getPublicKey().getKeyID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,8 +36,7 @@ object GpgUtil {
|
|||||||
new BcPGPObjectFactory(new ArmoredInputStream(new ByteArrayInputStream(signInfo.signArmored)))
|
new BcPGPObjectFactory(new ArmoredInputStream(new ByteArrayInputStream(signInfo.signArmored)))
|
||||||
.iterator()
|
.iterator()
|
||||||
.asScala
|
.asScala
|
||||||
.flatMap {
|
.flatMap { case signList: PGPSignatureList =>
|
||||||
case signList: PGPSignatureList =>
|
|
||||||
signList
|
signList
|
||||||
.iterator()
|
.iterator()
|
||||||
.asScala
|
.asScala
|
||||||
|
|||||||
@@ -54,8 +54,7 @@ object JDBCUtil {
|
|||||||
|
|
||||||
private def execute[T](sql: String, params: Any*)(f: (PreparedStatement) => T): T = {
|
private def execute[T](sql: String, params: Any*)(f: (PreparedStatement) => T): T = {
|
||||||
Using.resource(conn.prepareStatement(sql)) { stmt =>
|
Using.resource(conn.prepareStatement(sql)) { stmt =>
|
||||||
params.zipWithIndex.foreach {
|
params.zipWithIndex.foreach { case (p, i) =>
|
||||||
case (p, i) =>
|
|
||||||
p match {
|
p match {
|
||||||
case x: Int => stmt.setInt(i + 1, x)
|
case x: Int => stmt.setInt(i + 1, x)
|
||||||
case x: String => stmt.setString(i + 1, x)
|
case x: String => stmt.setString(i + 1, x)
|
||||||
@@ -136,8 +135,7 @@ object JDBCUtil {
|
|||||||
sb.append(columns.map(_._1).mkString(", "))
|
sb.append(columns.map(_._1).mkString(", "))
|
||||||
sb.append(") VALUES (")
|
sb.append(") VALUES (")
|
||||||
|
|
||||||
val values = columns.map {
|
val values = columns.map { case (columnName, columnType) =>
|
||||||
case (columnName, columnType) =>
|
|
||||||
if (rs.getObject(columnName) == null) {
|
if (rs.getObject(columnName) == null) {
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -454,8 +454,7 @@ object JGitUtil {
|
|||||||
def appendLastCommits(
|
def appendLastCommits(
|
||||||
fileList: List[(ObjectId, FileMode, String, String, Option[String])]
|
fileList: List[(ObjectId, FileMode, String, String, Option[String])]
|
||||||
): List[(ObjectId, FileMode, String, String, Option[String], Option[RevCommit])] = {
|
): List[(ObjectId, FileMode, String, String, Option[String], Option[RevCommit])] = {
|
||||||
fileList.map {
|
fileList.map { case (id, mode, name, path, opt) =>
|
||||||
case (id, mode, name, path, opt) =>
|
|
||||||
if (maxFiles > 0 && fileList.size >= maxFiles) {
|
if (maxFiles > 0 && fileList.size >= maxFiles) {
|
||||||
// Don't attempt to get the last commit if the number of files is very large.
|
// Don't attempt to get the last commit if the number of files is very large.
|
||||||
(id, mode, name, path, opt, None)
|
(id, mode, name, path, opt, None)
|
||||||
@@ -503,8 +502,7 @@ object JGitUtil {
|
|||||||
|
|
||||||
appendLastCommits(fileList)
|
appendLastCommits(fileList)
|
||||||
.map(simplifyPath)
|
.map(simplifyPath)
|
||||||
.map {
|
.map { case (objectId, fileMode, name, path, linkUrl, commit) =>
|
||||||
case (objectId, fileMode, name, path, linkUrl, commit) =>
|
|
||||||
FileInfo(
|
FileInfo(
|
||||||
objectId,
|
objectId,
|
||||||
fileMode == FileMode.TREE || fileMode == FileMode.GITLINK,
|
fileMode == FileMode.TREE || fileMode == FileMode.GITLINK,
|
||||||
@@ -716,8 +714,7 @@ object JGitUtil {
|
|||||||
df.scan(
|
df.scan(
|
||||||
new EmptyTreeIterator(),
|
new EmptyTreeIterator(),
|
||||||
new CanonicalTreeParser(null, git.getRepository.newObjectReader(), toCommit.getTree)
|
new CanonicalTreeParser(null, git.getRepository.newObjectReader(), toCommit.getTree)
|
||||||
)
|
).asScala
|
||||||
.asScala
|
|
||||||
case _ => df.scan(toCommit.getParent(0), toCommit.getTree).asScala
|
case _ => df.scan(toCommit.getParent(0), toCommit.getTree).asScala
|
||||||
}
|
}
|
||||||
case Some(from) =>
|
case Some(from) =>
|
||||||
@@ -788,8 +785,10 @@ object JGitUtil {
|
|||||||
} else {
|
} else {
|
||||||
val oldIsImage = FileUtil.isImage(diff.getOldPath)
|
val oldIsImage = FileUtil.isImage(diff.getOldPath)
|
||||||
val newIsImage = FileUtil.isImage(diff.getNewPath)
|
val newIsImage = FileUtil.isImage(diff.getNewPath)
|
||||||
val patch = if (oldIsImage || newIsImage) None else Some(makePatchFromDiffEntry(git, diff)) // TODO use DiffFormatter
|
val patch =
|
||||||
val tooLarge = patch.exists(_.count(_ == '\n') > 1000) // Don't show diff if the file has more than 1000 lines diff
|
if (oldIsImage || newIsImage) None else Some(makePatchFromDiffEntry(git, diff)) // TODO use DiffFormatter
|
||||||
|
val tooLarge =
|
||||||
|
patch.exists(_.count(_ == '\n') > 1000) // Don't show diff if the file has more than 1000 lines diff
|
||||||
val includeContent = tooLarge || !fetchContent || oldIsImage || newIsImage
|
val includeContent = tooLarge || !fetchContent || oldIsImage || newIsImage
|
||||||
DiffInfo(
|
DiffInfo(
|
||||||
changeType = diff.getChangeType,
|
changeType = diff.getChangeType,
|
||||||
@@ -923,8 +922,7 @@ object JGitUtil {
|
|||||||
).flatMap {
|
).flatMap {
|
||||||
case Some(rev) => Some((git.getRepository.resolve(rev), rev))
|
case Some(rev) => Some((git.getRepository.resolve(rev), rev))
|
||||||
case None => None
|
case None => None
|
||||||
}
|
}.find(_._1 != null)
|
||||||
.find(_._1 != null)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def createTag(git: Git, name: String, message: Option[String], commitId: String) = {
|
def createTag(git: Git, name: String, message: Option[String], commitId: String) = {
|
||||||
@@ -1301,7 +1299,8 @@ object JGitUtil {
|
|||||||
c.getAuthorIdent.getWhen,
|
c.getAuthorIdent.getWhen,
|
||||||
Option(git.log.add(c).addPath(blame.getSourcePath(i)).setSkip(1).setMaxCount(2).call.iterator.next)
|
Option(git.log.add(c).addPath(blame.getSourcePath(i)).setSkip(1).setMaxCount(2).call.iterator.next)
|
||||||
.map(_.name),
|
.map(_.name),
|
||||||
if (blame.getSourcePath(i) == path) { None } else { Some(blame.getSourcePath(i)) },
|
if (blame.getSourcePath(i) == path) { None }
|
||||||
|
else { Some(blame.getSourcePath(i)) },
|
||||||
c.getCommitterIdent.getWhen,
|
c.getCommitterIdent.getWhen,
|
||||||
c.getShortMessage,
|
c.getShortMessage,
|
||||||
Set.empty
|
Set.empty
|
||||||
|
|||||||
@@ -128,7 +128,8 @@ object LDAPUtil {
|
|||||||
|
|
||||||
val cachedInstance = provider.get()
|
val cachedInstance = provider.get()
|
||||||
if (cachedInstance == null) {
|
if (cachedInstance == null) {
|
||||||
val cls = try {
|
val cls =
|
||||||
|
try {
|
||||||
Class.forName("com.sun.net.ssl.internal.ssl.Provider")
|
Class.forName("com.sun.net.ssl.internal.ssl.Provider")
|
||||||
} catch {
|
} catch {
|
||||||
case e: ClassNotFoundException =>
|
case e: ClassNotFoundException =>
|
||||||
@@ -234,8 +235,8 @@ object LDAPUtil {
|
|||||||
case x => "(&(" + x + ")(" + userNameAttribute + "=" + userName + "))"
|
case x => "(&(" + x + ")(" + userNameAttribute + "=" + userName + "))"
|
||||||
}
|
}
|
||||||
|
|
||||||
getEntries(conn.search(baseDN, LDAPConnection.SCOPE_SUB, filterCond, null, false)).collectFirst {
|
getEntries(conn.search(baseDN, LDAPConnection.SCOPE_SUB, filterCond, null, false)).collectFirst { case x =>
|
||||||
case x => x.getDN
|
x.getDN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ class Mailer(settings: SystemSettings) {
|
|||||||
smtp.fromAddress
|
smtp.fromAddress
|
||||||
.map(_ -> smtp.fromName.getOrElse(loginAccount.map(_.userName).getOrElse("GitBucket")))
|
.map(_ -> smtp.fromName.getOrElse(loginAccount.map(_.userName).getOrElse("GitBucket")))
|
||||||
.orElse(Some("notifications@gitbucket.com" -> loginAccount.map(_.userName).getOrElse("GitBucket")))
|
.orElse(Some("notifications@gitbucket.com" -> loginAccount.map(_.userName).getOrElse("GitBucket")))
|
||||||
.foreach {
|
.foreach { case (address, name) =>
|
||||||
case (address, name) =>
|
|
||||||
email.setFrom(address, name)
|
email.setFrom(address, name)
|
||||||
}
|
}
|
||||||
email.setCharset("UTF-8")
|
email.setCharset("UTF-8")
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ trait AvatarImageProvider { self: RequestCache =>
|
|||||||
// by user name
|
// by user name
|
||||||
getAccountByUserNameFromCache(userName).map { account =>
|
getAccountByUserNameFromCache(userName).map { account =>
|
||||||
if (account.image.isEmpty && context.settings.basicBehavior.gravatar) {
|
if (account.image.isEmpty && context.settings.basicBehavior.gravatar) {
|
||||||
s"""https://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress.toLowerCase)}?s=${size}&d=retro&r=g"""
|
s"""https://www.gravatar.com/avatar/${StringUtil.md5(
|
||||||
|
account.mailAddress.toLowerCase
|
||||||
|
)}?s=${size}&d=retro&r=g"""
|
||||||
} else {
|
} else {
|
||||||
s"""${context.path}/${account.userName}/_avatar?${helpers.hashDate(account.updatedDate)}"""
|
s"""${context.path}/${account.userName}/_avatar?${helpers.hashDate(account.updatedDate)}"""
|
||||||
}
|
}
|
||||||
@@ -30,7 +32,9 @@ trait AvatarImageProvider { self: RequestCache =>
|
|||||||
// by mail address
|
// by mail address
|
||||||
getAccountByMailAddressFromCache(mailAddress).map { account =>
|
getAccountByMailAddressFromCache(mailAddress).map { account =>
|
||||||
if (account.image.isEmpty && context.settings.basicBehavior.gravatar) {
|
if (account.image.isEmpty && context.settings.basicBehavior.gravatar) {
|
||||||
s"""https://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress.toLowerCase)}?s=${size}&d=retro&r=g"""
|
s"""https://www.gravatar.com/avatar/${StringUtil.md5(
|
||||||
|
account.mailAddress.toLowerCase
|
||||||
|
)}?s=${size}&d=retro&r=g"""
|
||||||
} else {
|
} else {
|
||||||
s"""${context.path}/${account.userName}/_avatar?${helpers.hashDate(account.updatedDate)}"""
|
s"""${context.path}/${account.userName}/_avatar?${helpers.hashDate(account.updatedDate)}"""
|
||||||
}
|
}
|
||||||
@@ -45,13 +49,15 @@ trait AvatarImageProvider { self: RequestCache =>
|
|||||||
|
|
||||||
if (tooltip) {
|
if (tooltip) {
|
||||||
Html(
|
Html(
|
||||||
s"""<img src="${src}" class="${if (size > 20) { "avatar" } else { "avatar-mini" }}" style="width: ${size}px; height: ${size}px;"
|
s"""<img src="${src}" class="${if (size > 20) { "avatar" }
|
||||||
|
else { "avatar-mini" }}" style="width: ${size}px; height: ${size}px;"
|
||||||
| alt="@${StringUtil.escapeHtml(userName)}"
|
| alt="@${StringUtil.escapeHtml(userName)}"
|
||||||
| data-toggle="tooltip" title="${StringUtil.escapeHtml(userName)}" />""".stripMargin
|
| data-toggle="tooltip" title="${StringUtil.escapeHtml(userName)}" />""".stripMargin
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Html(
|
Html(
|
||||||
s"""<img src="${src}" class="${if (size > 20) { "avatar" } else { "avatar-mini" }}" style="width: ${size}px; height: ${size}px;"
|
s"""<img src="${src}" class="${if (size > 20) { "avatar" }
|
||||||
|
else { "avatar-mini" }}" style="width: ${size}px; height: ${size}px;"
|
||||||
| alt="@${StringUtil.escapeHtml(userName)}" />""".stripMargin
|
| alt="@${StringUtil.escapeHtml(userName)}" />""".stripMargin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,13 @@ trait LinkConverter { self: RequestCache =>
|
|||||||
/**
|
/**
|
||||||
* Creates a link to the issue or the pull request from the issue id.
|
* Creates a link to the issue or the pull request from the issue id.
|
||||||
*/
|
*/
|
||||||
protected def createIssueLink(owner: String, repository: String, issueId: Int, title: String)(
|
protected def createIssueLink(owner: String, repository: String, issueId: Int, title: String)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): String = {
|
): String = {
|
||||||
getIssueFromCache(owner, repository, issueId.toString) match {
|
getIssueFromCache(owner, repository, issueId.toString) match {
|
||||||
case Some(issue) =>
|
case Some(issue) =>
|
||||||
s"""<a href="${context.path}/${owner}/${repository}/${if (issue.isPullRequest) "pull" else "issues"}/${issueId}"><strong>${StringUtil
|
s"""<a href="${context.path}/${owner}/${repository}/${if (issue.isPullRequest) "pull"
|
||||||
|
else "issues"}/${issueId}"><strong>${StringUtil
|
||||||
.escapeHtml(title)}</strong> #${issueId}</a>"""
|
.escapeHtml(title)}</strong> #${issueId}</a>"""
|
||||||
case None =>
|
case None =>
|
||||||
s"Unknown #${issueId}"
|
s"Unknown #${issueId}"
|
||||||
@@ -25,12 +26,13 @@ trait LinkConverter { self: RequestCache =>
|
|||||||
/**
|
/**
|
||||||
* Creates a global link to the issue or the pull request from the issue id.
|
* Creates a global link to the issue or the pull request from the issue id.
|
||||||
*/
|
*/
|
||||||
protected def createGlobalIssueLink(owner: String, repository: String, issueId: Int, title: String)(
|
protected def createGlobalIssueLink(owner: String, repository: String, issueId: Int, title: String)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): String = {
|
): String = {
|
||||||
getIssueFromCache(owner, repository, issueId.toString) match {
|
getIssueFromCache(owner, repository, issueId.toString) match {
|
||||||
case Some(issue) =>
|
case Some(issue) =>
|
||||||
s"""<a href="${context.path}/${owner}/${repository}/${if (issue.isPullRequest) "pull" else "issues"}/${issueId}"><strong>${StringUtil
|
s"""<a href="${context.path}/${owner}/${repository}/${if (issue.isPullRequest) "pull"
|
||||||
|
else "issues"}/${issueId}"><strong>${StringUtil
|
||||||
.escapeHtml(title)}</strong> ${owner}/${repository}#${issueId}</a>"""
|
.escapeHtml(title)}</strong> ${owner}/${repository}#${issueId}</a>"""
|
||||||
case None =>
|
case None =>
|
||||||
s"Unknown ${owner}/${repository}#${issueId}"
|
s"Unknown ${owner}/${repository}#${issueId}"
|
||||||
|
|||||||
@@ -160,8 +160,8 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
/**
|
/**
|
||||||
* Creates a link to the issue or the pull request from the issue id.
|
* Creates a link to the issue or the pull request from the issue id.
|
||||||
*/
|
*/
|
||||||
def issueLink(owner: String, repository: String, issueId: Int, title: String)(
|
def issueLink(owner: String, repository: String, issueId: Int, title: String)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): Html = {
|
): Html = {
|
||||||
Html(createIssueLink(owner, repository, issueId, title))
|
Html(createIssueLink(owner, repository, issueId, title))
|
||||||
}
|
}
|
||||||
@@ -169,8 +169,8 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
/**
|
/**
|
||||||
* Creates a global link to the issue or the pull request from the issue id.
|
* Creates a global link to the issue or the pull request from the issue id.
|
||||||
*/
|
*/
|
||||||
def issueGlobalLink(owner: String, repository: String, issueId: Int, title: String)(
|
def issueGlobalLink(owner: String, repository: String, issueId: Int, title: String)(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): Html = {
|
): Html = {
|
||||||
Html(createGlobalIssueLink(owner, repository, issueId, title))
|
Html(createGlobalIssueLink(owner, repository, issueId, title))
|
||||||
}
|
}
|
||||||
@@ -179,8 +179,8 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
* Returns <img> which displays the avatar icon for the given user name.
|
* Returns <img> which displays the avatar icon for the given user name.
|
||||||
* This method looks up Gravatar if avatar icon has not been configured in user settings.
|
* This method looks up Gravatar if avatar icon has not been configured in user settings.
|
||||||
*/
|
*/
|
||||||
def avatar(userName: String, size: Int, tooltip: Boolean = false, mailAddress: String = "")(
|
def avatar(userName: String, size: Int, tooltip: Boolean = false, mailAddress: String = "")(implicit
|
||||||
implicit context: Context
|
context: Context
|
||||||
): Html =
|
): Html =
|
||||||
getAvatarImageHtml(userName, size, mailAddress, tooltip)
|
getAvatarImageHtml(userName, size, mailAddress, tooltip)
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,19 @@ import MergeServiceSpec._
|
|||||||
import org.json4s.JsonAST.{JArray, JString}
|
import org.json4s.JsonAST.{JArray, JString}
|
||||||
|
|
||||||
class MergeServiceSpec extends AnyFunSpec with ServiceSpecBase {
|
class MergeServiceSpec extends AnyFunSpec with ServiceSpecBase {
|
||||||
val service = new MergeService with AccountService with ActivityService with IssuesService with LabelsService
|
val service = new MergeService
|
||||||
with MilestonesService with RepositoryService with PrioritiesService with PullRequestService with CommitsService
|
with AccountService
|
||||||
with WebHookPullRequestService with WebHookPullRequestReviewCommentService with RequestCache {
|
with ActivityService
|
||||||
|
with IssuesService
|
||||||
|
with LabelsService
|
||||||
|
with MilestonesService
|
||||||
|
with RepositoryService
|
||||||
|
with PrioritiesService
|
||||||
|
with PullRequestService
|
||||||
|
with CommitsService
|
||||||
|
with WebHookPullRequestService
|
||||||
|
with WebHookPullRequestReviewCommentService
|
||||||
|
with RequestCache {
|
||||||
override protected def getReceiveHooks(): Seq[ReceiveHook] = Nil
|
override protected def getReceiveHooks(): Seq[ReceiveHook] = Nil
|
||||||
}
|
}
|
||||||
val branch = "master"
|
val branch = "master"
|
||||||
|
|||||||
@@ -33,7 +33,11 @@ class PullRequestServiceSpec
|
|||||||
generateNewUserWithDBRepository("user1", "repo2")
|
generateNewUserWithDBRepository("user1", "repo2")
|
||||||
generateNewUserWithDBRepository("user2", "repo1")
|
generateNewUserWithDBRepository("user2", "repo1")
|
||||||
generateNewPullRequest("user1/repo1/master", "user1/repo1/head2", loginUser = "root") // not target branch
|
generateNewPullRequest("user1/repo1/master", "user1/repo1/head2", loginUser = "root") // not target branch
|
||||||
generateNewPullRequest("user1/repo1/head1", "user1/repo1/master", loginUser = "root") // not target branch ( swap from, to )
|
generateNewPullRequest(
|
||||||
|
"user1/repo1/head1",
|
||||||
|
"user1/repo1/master",
|
||||||
|
loginUser = "root"
|
||||||
|
) // not target branch ( swap from, to )
|
||||||
generateNewPullRequest("user1/repo1/master", "user2/repo1/head1", loginUser = "root") // other user
|
generateNewPullRequest("user1/repo1/master", "user2/repo1/head1", loginUser = "root") // other user
|
||||||
generateNewPullRequest("user1/repo1/master", "user1/repo2/head1", loginUser = "root") // other repository
|
generateNewPullRequest("user1/repo1/master", "user1/repo2/head1", loginUser = "root") // other repository
|
||||||
val r1 = swap(generateNewPullRequest("user1/repo1/master2", "user1/repo1/head1", loginUser = "root"))
|
val r1 = swap(generateNewPullRequest("user1/repo1/master2", "user1/repo1/head1", loginUser = "root"))
|
||||||
|
|||||||
@@ -108,10 +108,21 @@ trait ServiceSpecBase {
|
|||||||
|
|
||||||
def user(name: String)(implicit s: Session): Account = AccountService.getAccountByUserName(name).get
|
def user(name: String)(implicit s: Session): Account = AccountService.getAccountByUserName(name).get
|
||||||
|
|
||||||
lazy val dummyService = new RepositoryService with AccountService with ActivityService with IssuesService
|
lazy val dummyService = new RepositoryService
|
||||||
with MergeService with PullRequestService with CommitsService with CommitStatusService with LabelsService
|
with AccountService
|
||||||
with MilestonesService with PrioritiesService with WebHookService with WebHookPullRequestService
|
with ActivityService
|
||||||
with WebHookPullRequestReviewCommentService with RequestCache {
|
with IssuesService
|
||||||
|
with MergeService
|
||||||
|
with PullRequestService
|
||||||
|
with CommitsService
|
||||||
|
with CommitStatusService
|
||||||
|
with LabelsService
|
||||||
|
with MilestonesService
|
||||||
|
with PrioritiesService
|
||||||
|
with WebHookService
|
||||||
|
with WebHookPullRequestService
|
||||||
|
with WebHookPullRequestReviewCommentService
|
||||||
|
with RequestCache {
|
||||||
override def fetchAsPullRequest(
|
override def fetchAsPullRequest(
|
||||||
userName: String,
|
userName: String,
|
||||||
repositoryName: String,
|
repositoryName: String,
|
||||||
@@ -133,8 +144,7 @@ trait ServiceSpecBase {
|
|||||||
ac
|
ac
|
||||||
}
|
}
|
||||||
|
|
||||||
def generateNewIssue(userName: String, repositoryName: String, loginUser: String = "root")(
|
def generateNewIssue(userName: String, repositoryName: String, loginUser: String = "root")(implicit
|
||||||
implicit
|
|
||||||
s: Session
|
s: Session
|
||||||
): Int = {
|
): Int = {
|
||||||
dummyService.insertIssue(
|
dummyService.insertIssue(
|
||||||
@@ -149,8 +159,7 @@ trait ServiceSpecBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
def generateNewPullRequest(base: String, request: String, loginUser: String)(
|
def generateNewPullRequest(base: String, request: String, loginUser: String)(implicit
|
||||||
implicit
|
|
||||||
s: Session
|
s: Session
|
||||||
): (Issue, PullRequest) = {
|
): (Issue, PullRequest) = {
|
||||||
implicit val context = Context(createSystemSettings(), None, this.request)
|
implicit val context = Context(createSystemSettings(), None, this.request)
|
||||||
|
|||||||
@@ -5,9 +5,19 @@ import org.scalatest.funsuite.AnyFunSuite
|
|||||||
import gitbucket.core.model.WebHookContentType
|
import gitbucket.core.model.WebHookContentType
|
||||||
|
|
||||||
class WebHookServiceSpec extends AnyFunSuite with ServiceSpecBase {
|
class WebHookServiceSpec extends AnyFunSuite with ServiceSpecBase {
|
||||||
lazy val service = new WebHookPullRequestService with AccountService with ActivityService with RepositoryService
|
lazy val service = new WebHookPullRequestService
|
||||||
with MergeService with PullRequestService with IssuesService with CommitsService with LabelsService
|
with AccountService
|
||||||
with MilestonesService with PrioritiesService with WebHookPullRequestReviewCommentService with RequestCache
|
with ActivityService
|
||||||
|
with RepositoryService
|
||||||
|
with MergeService
|
||||||
|
with PullRequestService
|
||||||
|
with IssuesService
|
||||||
|
with CommitsService
|
||||||
|
with LabelsService
|
||||||
|
with MilestonesService
|
||||||
|
with PrioritiesService
|
||||||
|
with WebHookPullRequestReviewCommentService
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
test("WebHookPullRequestService.getPullRequestsByRequestForWebhook") {
|
test("WebHookPullRequestService.getPullRequestsByRequestForWebhook") {
|
||||||
withTestDB { implicit session =>
|
withTestDB { implicit session =>
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ object GitSpecUtil {
|
|||||||
val merger = MergeStrategy.RECURSIVE.newMerger(repository, true)
|
val merger = MergeStrategy.RECURSIVE.newMerger(repository, true)
|
||||||
val mergeBaseTip = repository.resolve(into)
|
val mergeBaseTip = repository.resolve(into)
|
||||||
val mergeTip = repository.resolve(branch)
|
val mergeTip = repository.resolve(branch)
|
||||||
val conflicted = try {
|
val conflicted =
|
||||||
|
try {
|
||||||
!merger.merge(mergeBaseTip, mergeTip)
|
!merger.merge(mergeBaseTip, mergeTip)
|
||||||
} catch {
|
} catch {
|
||||||
case e: NoMergeBaseException => true
|
case e: NoMergeBaseException => true
|
||||||
|
|||||||
@@ -88,41 +88,65 @@ class StringUtilSpec extends AnyFunSpec {
|
|||||||
it("should convert GitBucket repository url") {
|
it("should convert GitBucket repository url") {
|
||||||
assert(
|
assert(
|
||||||
StringUtil
|
StringUtil
|
||||||
.getRepositoryViewerUrl("http://localhost:8080/git/root/gitbucket.git", baseUrl) == "http://localhost:8080/root/gitbucket"
|
.getRepositoryViewerUrl(
|
||||||
|
"http://localhost:8080/git/root/gitbucket.git",
|
||||||
|
baseUrl
|
||||||
|
) == "http://localhost:8080/root/gitbucket"
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
StringUtil
|
StringUtil
|
||||||
.getRepositoryViewerUrl("http://root@localhost:8080/git/root/gitbucket.git", baseUrl) == "http://localhost:8080/root/gitbucket"
|
.getRepositoryViewerUrl(
|
||||||
|
"http://root@localhost:8080/git/root/gitbucket.git",
|
||||||
|
baseUrl
|
||||||
|
) == "http://localhost:8080/root/gitbucket"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
it("should convert GitHub repository url") {
|
it("should convert GitHub repository url") {
|
||||||
assert(
|
assert(
|
||||||
StringUtil
|
StringUtil
|
||||||
.getRepositoryViewerUrl("https://github.com/root/gitbucket.git", baseUrl) == "https://github.com/root/gitbucket"
|
.getRepositoryViewerUrl(
|
||||||
|
"https://github.com/root/gitbucket.git",
|
||||||
|
baseUrl
|
||||||
|
) == "https://github.com/root/gitbucket"
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
StringUtil
|
StringUtil
|
||||||
.getRepositoryViewerUrl("https://root@github.com/root/gitbucket.git", baseUrl) == "https://github.com/root/gitbucket"
|
.getRepositoryViewerUrl(
|
||||||
|
"https://root@github.com/root/gitbucket.git",
|
||||||
|
baseUrl
|
||||||
|
) == "https://github.com/root/gitbucket"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
it("should convert BitBucket repository url") {
|
it("should convert BitBucket repository url") {
|
||||||
assert(
|
assert(
|
||||||
StringUtil
|
StringUtil
|
||||||
.getRepositoryViewerUrl("https://bitbucket.org/root/gitbucket.git", baseUrl) == "https://bitbucket.org/root/gitbucket"
|
.getRepositoryViewerUrl(
|
||||||
|
"https://bitbucket.org/root/gitbucket.git",
|
||||||
|
baseUrl
|
||||||
|
) == "https://bitbucket.org/root/gitbucket"
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
StringUtil
|
StringUtil
|
||||||
.getRepositoryViewerUrl("https://root@bitbucket.org/root/gitbucket.git", baseUrl) == "https://bitbucket.org/root/gitbucket"
|
.getRepositoryViewerUrl(
|
||||||
|
"https://root@bitbucket.org/root/gitbucket.git",
|
||||||
|
baseUrl
|
||||||
|
) == "https://bitbucket.org/root/gitbucket"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
it("should convert GitLab repository url") {
|
it("should convert GitLab repository url") {
|
||||||
assert(
|
assert(
|
||||||
StringUtil
|
StringUtil
|
||||||
.getRepositoryViewerUrl("https://gitlab.com/root/gitbucket.git", baseUrl) == "https://gitlab.com/root/gitbucket"
|
.getRepositoryViewerUrl(
|
||||||
|
"https://gitlab.com/root/gitbucket.git",
|
||||||
|
baseUrl
|
||||||
|
) == "https://gitlab.com/root/gitbucket"
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
StringUtil
|
StringUtil
|
||||||
.getRepositoryViewerUrl("https://root@gitlab.com/root/gitbucket.git", baseUrl) == "https://gitlab.com/root/gitbucket"
|
.getRepositoryViewerUrl(
|
||||||
|
"https://root@gitlab.com/root/gitbucket.git",
|
||||||
|
baseUrl
|
||||||
|
) == "https://gitlab.com/root/gitbucket"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,8 +202,7 @@ class AvatarImageProviderSpec extends AnyFunSpec {
|
|||||||
*/
|
*/
|
||||||
class AvatarImageProviderImpl(account: Option[Account]) extends AvatarImageProvider with RequestCache {
|
class AvatarImageProviderImpl(account: Option[Account]) extends AvatarImageProvider with RequestCache {
|
||||||
|
|
||||||
def toHtml(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)(
|
def toHtml(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)(implicit
|
||||||
implicit
|
|
||||||
context: Context
|
context: Context
|
||||||
): Html = getAvatarImageHtml(userName, size, mailAddress, tooltip)
|
): Html = getAvatarImageHtml(userName, size, mailAddress, tooltip)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user